From: Eduardo DAVILA Date: Tue, 12 Jul 2022 09:38:56 +0000 (+0200) Subject: #3485 ShowNPionts for Multiple Groups X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a7d6b190acd7febe8a61d8de129c4c3e48229f90;p=creaMaracasVisu.git #3485 ShowNPionts for Multiple Groups --- diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx index 5f16750..01ab191 100644 --- a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.cxx @@ -3,17 +3,120 @@ //===== #include "bbcreaMaracasVisuShowNPoints_Tools.h" #include "bbcreaMaracasVisuPackage.h" + + namespace bbcreaMaracasVisu { BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ShowNPoints_Tools) BBTK_BLACK_BOX_IMPLEMENTATION(ShowNPoints_Tools,bbtk::AtomicBlackBox); + + +void ShowNPoints_Tools::NearestPointToMesh( vtkPoints *points,vtkStaticPointLocator *pointLocator,double *spc,double *p,double *pM) +{ + + p[0] = p[0] * spc[0]; + p[1] = p[1] * spc[1]; + p[2] = p[2] * spc[2]; + points->GetPoint( pointLocator->FindClosestPoint(p) , pM ); + pM[0] = pM[0] / spc[0]; + pM[1] = pM[1] / spc[1]; + pM[2] = pM[2] / spc[2]; +} + void ShowNPoints_Tools::CreatePatch01() { - bbGetInputWidgetShowNPoints()->CreatePatch01( ); + WidgetShowNPoints* wsp = bbGetInputWidgetShowNPoints(); + if ( (wsp->GetLstModelShowNPointsSize()==1) && + (wsp->GetModelShowNPoints()->GetLstPointsSize()==4) && + (bbGetInputMesh()!=NULL ) ) + { + double spc[3]; + spc[0] = bbGetInputSpacing()[0]; + spc[1] = bbGetInputSpacing()[1]; + spc[2] = bbGetInputSpacing()[2]; + vtkPoints *points = bbGetInputMesh()->GetPoints(); + vtkStaticPointLocator *pointLocator = vtkStaticPointLocator::New(); + pointLocator->SetDataSet( bbGetInputMesh() ); + pointLocator->BuildLocator(); + + wsp->StopTrackPoint(); + double p[3],pM[3]; + double dx,dy,dz,s; + std::vector lstX = wsp->GetModelShowNPoints()->GetLstPointsX(); + std::vector lstY = wsp->GetModelShowNPoints()->GetLstPointsY(); + std::vector lstZ = wsp->GetModelShowNPoints()->GetLstPointsZ(); + + // --- Group 0 --- + wsp->ErasePoint( 2 ); + wsp->ErasePoint( 2 ); + dx = lstX[1]-lstX[0]; + dy = lstY[1]-lstY[0]; + dz = lstZ[1]-lstZ[0]; + s=0.33333; + p[0] = lstX[0] + dx*s; + p[1] = lstY[0] + dy*s; + p[2] = lstZ[0] + dz*s; + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); + s=s*2; + p[0] = lstX[0] + dx*s; + p[1] = lstY[0] + dy*s; + p[2] = lstZ[0] + dz*s; + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0],pM[1], pM[2],""); + + // --- Group 1 --- + wsp->OnInsertCollectionAfter_(); + p[0] = (lstX[0]+lstX[3])/2; + p[1] = (lstY[0]+lstY[3])/2; + p[2] = (lstZ[0]+lstZ[3])/2; + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); + p[0] = (lstX[1]+lstX[2])/2; + p[1] = (lstY[1]+lstY[2])/2; + p[2] = (lstZ[1]+lstZ[2])/2; + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); + p[0] = (lstX[0]+lstX[1]+lstX[2]+lstX[3])/4; p[1] = (lstY[0]+lstY[1]+lstY[2]+lstY[3])/4; p[2] = (lstZ[0]+lstZ[1]+lstZ[2]+lstZ[3])/4; + wsp->InsertPoint(p[0] ,p[1], p[2],""); + + // --- Group 2 --- + wsp->OnInsertCollectionAfter_(); + p[0] = lstX[3]; + p[1] = lstY[3]; + p[2] = lstZ[3]; + wsp->InsertPoint(p[0] ,p[1], p[2],""); + p[0] = lstX[2]; + p[1] = lstY[2]; + p[2] = lstZ[2]; + wsp->InsertPoint(p[0] ,p[1], p[2],""); + dx = lstX[2]-lstX[3]; + dy = lstY[2]-lstY[3]; + dz = lstZ[2]-lstZ[3]; + s=0.33333; + p[0] = lstX[3] + dx*s; + p[1] = lstY[3] + dy*s; + p[2] = lstZ[3] + dz*s; + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); + s=s*2; + p[0] = lstX[3] + dx*s; + p[1] = lstY[3] + dy*s; + p[2] = lstZ[3] + dz*s; + NearestPointToMesh(points, pointLocator, spc, p,pM); + wsp->InsertPoint(pM[0] ,pM[1], pM[2],""); + + wsp->SetOutputBox(); + pointLocator->Delete(); + } else { + printf("EED ShowNPoints_Tools::CreatePatch01 Warning patch not apply. Need juste one group with four points\n"); + } // if } + + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== @@ -80,6 +183,12 @@ void ShowNPoints_Tools::bbUserSetDefaultValues() bbSetInputType(0); bbSetInputMesh(NULL); bbSetInputWidgetShowNPoints(NULL); + + std::vector spc; + spc.push_back(1); + spc.push_back(1); + spc.push_back(1); + bbSetInputSpacing(spc); } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) diff --git a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h index d974669..d83ba3e 100644 --- a/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h +++ b/bbtk/src/bbcreaMaracasVisuShowNPoints_Tools.h @@ -9,7 +9,10 @@ #include "iostream" #include "WidgetShowNPoints.h" + + #include "vtkPolyData.h" +#include namespace bbcreaMaracasVisu { @@ -23,6 +26,7 @@ class bbcreaMaracasVisu_EXPORT ShowNPoints_Tools // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== BBTK_DECLARE_INPUT(WidgetShowNPoints,WidgetShowNPoints*); + BBTK_DECLARE_INPUT(Spacing,std::vector); BBTK_DECLARE_INPUT(Mesh,vtkPolyData*); BBTK_DECLARE_INPUT(Type,int); // BBTK_DECLARE_OUTPUT(Out,double); @@ -30,6 +34,8 @@ class bbcreaMaracasVisu_EXPORT ShowNPoints_Tools void Process(); void CreatePatch01(); + void NearestPointToMesh( vtkPoints *points, vtkStaticPointLocator *pointLocator, double *spc , double *p , double *pM ); + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== @@ -41,6 +47,7 @@ BBTK_AUTHOR("Info-Dev"); BBTK_DESCRIPTION("No Description."); BBTK_CATEGORY("empty"); BBTK_INPUT(ShowNPoints_Tools,WidgetShowNPoints,"WidgetShowNPoints",WidgetShowNPoints*,""); + BBTK_INPUT(ShowNPoints_Tools,Spacing,"(default [1,1,1] )Spacing",std::vector,""); BBTK_INPUT(ShowNPoints_Tools,Mesh,"Mesh en format vtkPolyData ",vtkPolyData*,""); BBTK_INPUT(ShowNPoints_Tools,Type,"(default 0) 0:Nothing 10:Insert Point 20:TrackPoint 30:Set nearest point 40:Erase point 50:Deleta all points 100:Insert group after 110:Delete group 200:Tool_1 - Create Mesh (based with one group and 4 points)",int,""); // BBTK_OUTPUT(ShowNPoints_Tools,Out,"First output",double,""); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx index 796ffb3..74d9e6f 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.cxx @@ -1250,78 +1250,8 @@ std::vector WidgetShowNPoints::GetLstIndexs() return lstIndexs; } - -void WidgetShowNPoints::CreatePatch01() +//------------------------------------------------------------------------ +int WidgetShowNPoints::GetLstModelShowNPointsSize() { - if ( (lstModelShowNPoints.size()==1) && (GetModelShowNPoints()->GetLstPointsSize()==4) ) - { - StopTrackPoint(); - double px,py,pz; - double dx,dy,dz,s; - std::vector lstX = GetModelShowNPoints()->GetLstPointsX(); - std::vector lstY = GetModelShowNPoints()->GetLstPointsY(); - std::vector lstZ = GetModelShowNPoints()->GetLstPointsZ(); - - // --- Group 0 --- - ErasePoint( 2 ); - ErasePoint( 2 ); - dx=lstX[1]-lstX[0]; - dy=lstY[1]-lstY[0]; - dz=lstZ[1]-lstZ[0]; - s=0.33333; - px = lstX[0] + dx*s; - py = lstY[0] + dy*s; - pz = lstZ[0] + dz*s; - InsertPoint(px ,py, pz,""); - s=s*2; - px = lstX[0] + dx*s; - py = lstY[0] + dy*s; - pz = lstZ[0] + dz*s; - InsertPoint(px ,py, pz,""); - - // --- Group 1 --- - OnInsertCollectionAfter_(); - px = (lstX[0]+lstX[3])/2; - py = (lstY[0]+lstY[3])/2; - pz = (lstZ[0]+lstZ[3])/2; - InsertPoint(px ,py, pz,""); - px = (lstX[1]+lstX[2])/2; - py = (lstY[1]+lstY[2])/2; - pz = (lstZ[1]+lstZ[2])/2; - InsertPoint(px ,py, pz,""); - px = (lstX[0]+lstX[1]+lstX[2]+lstX[3])/4; - py = (lstY[0]+lstY[1]+lstY[2]+lstY[3])/4; - pz = (lstZ[0]+lstZ[1]+lstZ[2]+lstZ[3])/4; - InsertPoint(px ,py, pz,""); - - - // --- Group 2 --- - OnInsertCollectionAfter_(); - px = lstX[3]; - py = lstY[3]; - pz = lstZ[3]; - InsertPoint(px ,py, pz,""); - px = lstX[2]; - py = lstY[2]; - pz = lstZ[2]; - InsertPoint(px ,py, pz,""); - dx=lstX[2]-lstX[3]; - dy=lstY[2]-lstY[3]; - dz=lstZ[2]-lstZ[3]; - s=0.33333; - px = lstX[3] + dx*s; - py = lstY[3] + dy*s; - pz = lstZ[3] + dz*s; - InsertPoint(px ,py, pz,""); - s=s*2; - px = lstX[3] + dx*s; - py = lstY[3] + dy*s; - pz = lstZ[3] + dz*s; - InsertPoint(px ,py, pz,""); - - - SetOutputBox(); - } else { - printf("EED WidgetShowNPoints::CreatePatch01 Warning patch not apply. Need juste one group with four points\n"); - } // if + return lstModelShowNPoints.size(); } diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h index 75776ad..4edd315 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/WidgetShowNPoints.h @@ -73,6 +73,7 @@ class WidgetShowNPoints : public wxPanel void InsertPoint(int x, int y, int z, std::string label);//CFT void DeleteAllPoints(); + int GetLstModelShowNPointsSize(); ModelShowNPoints* GetModelShowNPoints(); ViewShowNPoints* GetViewShowNPoints(); void SetInitLstPoints( std::vector initLstPointsX, std::vector initLstPointsY, std::vector initLstPointsZ, std::vector initLstLabels ); @@ -82,8 +83,11 @@ class WidgetShowNPoints : public wxPanel double GetRadio(); double GetOpacity(); + + virtual void SetOutputBox(); + void ErasePoint(int id); + - void CreatePatch01(); std::vector GetLstPointsX(); std::vector GetLstPointsY(); @@ -94,10 +98,8 @@ class WidgetShowNPoints : public wxPanel protected: - virtual void SetOutputBox(); private: - void ErasePoint(int id); // EED 2022-05-19 //vtkRenderer *renderer;