2 // 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)
4 #include "bbcreaVtkCleanMeshWithPatch.h"
5 #include "bbcreaVtkPackage.h"
7 #include <vtkAppendPolyData.h>
8 #include <vtkStaticPointLocator.h>
9 #include <vtkDijkstraGraphGeodesicPath.h>
10 #include <vtkImprintFilter.h>
15 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,CleanMeshWithPatch)
16 BBTK_BLACK_BOX_IMPLEMENTATION(CleanMeshWithPatch,bbtk::AtomicBlackBox);
18 // 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)
20 void CleanMeshWithPatch::Process()
22 // THE MAIN PROCESSING METHOD BODY
23 // Here we simply set the input 'In' value to the output 'Out'
24 // And print out the output value
25 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
26 // void bbSet{Input|Output}NAME(const TYPE&)
27 // const TYPE& bbGet{Input|Output}NAME() const
29 // * NAME is the name of the input/output
30 // (the one provided in the attribute 'name' of the tag 'input')
31 // * TYPE is the C++ type of the input/output
32 // (the one provided in the attribute 'type' of the tag 'input')
33 // bbSetOutputOut( bbGetInputIn() );
34 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
36 printf("EED CleanMeshWithPatch::Process Start \n");
37 std::vector<int> lstIndexs = bbGetInputLstIndexs();
38 if (( lstIndexs.size()>=3 ) && (bbGetInputMesh()!=NULL) ) {
40 // Step 1. ----Get perimeter CtrlPoints-----
41 std::vector<double> lstX = bbGetInputLstX();
42 std::vector<double> lstY = bbGetInputLstY();
43 std::vector<double> lstZ = bbGetInputLstZ();
44 std::vector<double> perimeterX;
45 std::vector<double> perimeterY;
46 std::vector<double> perimeterZ;
47 std::vector<double> tmpX;
48 std::vector<double> tmpY;
49 std::vector<double> tmpZ;
50 int iGroup,sizeGroups = lstIndexs.size();
51 int i,iGeneral=0,size;
52 for (iGroup=0 ; iGroup<sizeGroups ; iGroup++)
56 for (i=iGeneral ; i<iGeneral+lstIndexs[iGroup] ; i++)
58 perimeterX.push_back( lstX[i] );
59 perimeterY.push_back( lstY[i] );
60 perimeterZ.push_back( lstZ[i] );
63 if ((iGroup!=0) && (iGroup!=sizeGroups-1))
65 i=iGeneral+(lstIndexs[iGroup]-1);
66 perimeterX.push_back( lstX[i] );
67 perimeterY.push_back( lstY[i] );
68 perimeterZ.push_back( lstZ[i] );
69 tmpX.insert( tmpX.begin() , lstX[iGeneral] );
70 tmpY.insert( tmpY.begin() , lstY[iGeneral] );
71 tmpZ.insert( tmpZ.begin() , lstZ[iGeneral] );
73 if (iGroup==sizeGroups-1)
75 for (i=iGeneral+lstIndexs[iGroup]-1 ; i>=iGeneral ; i--)
77 perimeterX.push_back( lstX[i] );
78 perimeterY.push_back( lstY[i] );
79 perimeterZ.push_back( lstZ[i] );
82 iGeneral=iGeneral+lstIndexs[iGroup];
85 for (i=0; i<size ; i++)
87 perimeterX.push_back( tmpX[i] );
88 perimeterY.push_back( tmpY[i] );
89 perimeterZ.push_back( tmpZ[i] );
91 // Step 2. ----Get Ids in Mesh of perimeter CtrlPoints-----
92 std::vector<double> spc;
93 if (bbGetInputSpacing().size()<3)
99 spc = bbGetInputSpacing();
101 vtkStaticPointLocator *pointLocator;
102 pointLocator = vtkStaticPointLocator::New();
103 pointLocator->SetDataSet( bbGetInputMesh() );
104 pointLocator->BuildLocator();
106 size=perimeterX.size();
107 std::vector<long int> lstIds;
110 id = pointLocator->FindClosestPoint( perimeterX[i]*spc[0] ,perimeterY[i]*spc[1] , perimeterZ[i]*spc[2] ) ;
111 lstIds.push_back( id );
112 printf("EED id=%ld spc=%f %f %f point=%f %f %f \n",id, spc[0],spc[1],spc[2], perimeterX[i], perimeterY[i], perimeterZ[i] );
114 // Step 3 Get geodesic path from segments
116 vtkAppendPolyData* append = vtkAppendPolyData::New();
127 vtkDijkstraGraphGeodesicPath *pathFilter = vtkDijkstraGraphGeodesicPath::New();
128 pathFilter->SetInputData( bbGetInputMesh() );
129 pathFilter->SetStartVertex( id1 );
130 pathFilter->SetEndVertex( id2 );
131 pathFilter->Update();
132 append->AddInputData( pathFilter->GetOutput() );
135 points = pathFilter->GetOutput()->GetPoints();
136 printf("EED nrP=%d \n", points->GetNumberOfPoints() );
137 pathFilter->Delete();
138 // if (i==0) bbSetOutputOut( pathFilter->GetOutput() );
142 // Step 4. -- vtkImprintFilter ---
143 vtkImprintFilter *imp = vtkImprintFilter::New();
144 // imp->SetTargetData( append->GetOutput() );
145 // imp->SetImprintData( bbGetInputMesh() );
147 // imp->SetTargetData( bbGetInputMesh() );
148 // imp->SetImprintData( append->GetOutput() );
150 // imp->SetTargetData( bbGetInputMesh() );
151 // imp->SetImprintData( bbGetInputPatch() );
153 imp->SetTargetData( bbGetInputMesh() );
154 imp->SetImprintData( bbGetInputPatch() );
156 // imp->SetOutputTypeToProjectedImprint();
157 imp->SetOutputTypeToTargetCells();
158 // imp->SetOutputTypeToImprintedCells();
159 // imp->SetOutputTypeToImprintedRegion();
160 // imp->SetOutputTypeToMergedImprint();
162 imp->SetTolerance(500);
165 bbSetOutputOut( imp->GetOutput() );
166 printf("EED CleanMeshWithPatch::Process size=%d \n", perimeterX.size());
167 } // if LstIndexs size >=3
168 printf("EED CleanMeshWithPatch::Process End \n");
172 // 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)
174 void CleanMeshWithPatch::bbUserSetDefaultValues()
176 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
177 // Here we initialize the input 'In' to 0
178 bbSetInputMesh(NULL);
179 bbSetInputPatch(NULL);
180 bbSetOutputOut(NULL);
184 // 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)
186 void CleanMeshWithPatch::bbUserInitializeProcessing()
188 // THE INITIALIZATION METHOD BODY :
190 // but this is where you should allocate the internal/output pointers
195 // 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)
197 void CleanMeshWithPatch::bbUserFinalizeProcessing()
199 // THE FINALIZATION METHOD BODY :
201 // but this is where you should desallocate the internal/output pointers
205 } // EO namespace bbcreaVtk