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 "bbcreaVtkCreateMeshFromPoints.h"
5 #include "bbcreaVtkPackage.h"
8 #include "vtkTriangleStrip.h"
9 #include "vtkCellArray.h"
11 #include "vtkCleanPolyData.h"
17 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,CreateMeshFromPoints)
18 BBTK_BLACK_BOX_IMPLEMENTATION(CreateMeshFromPoints,bbtk::AtomicBlackBox);
20 // 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)
22 void CreateMeshFromPoints::Process()
25 // THE MAIN PROCESSING METHOD BODY
26 // Here we simply set the input 'In' value to the output 'Out'
27 // And print out the output value
28 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
29 // void bbSet{Input|Output}NAME(const TYPE&)
30 // const TYPE& bbGet{Input|Output}NAME() const
32 // * NAME is the name of the input/output
33 // (the one provided in the attribute 'name' of the tag 'input')
34 // * TYPE is the C++ type of the input/output
35 // (the one provided in the attribute 'type' of the tag 'input')
37 // bbSetOutputOut( bbGetInputIn() );
38 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
41 printf("EED CreateMeshFromPoints::Process Start\n");
44 std::vector<double> lstX = bbGetInputLstX();
45 std::vector<double> lstY = bbGetInputLstY();
46 std::vector<double> lstZ = bbGetInputLstZ();
47 std::vector<int> lstIndexs = bbGetInputLstIndexs();
50 if ( (lstIndexs.size()<=1) || (lstX.size()==0) || (lstX.size()!=lstY.size()) || (lstY.size()!=lstZ.size()) )
52 printf("Warnning! CreateMeshFromPoints::Process: List of points X Y Z and LstIndexes is not correct\n");
55 int ii,sizeSegment1,sizeSegment2;
58 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
59 int i,sizeLstX = lstX.size();
60 for (i=0;i<sizeLstX;i++)
62 points->InsertNextPoint(lstX[i],lstY[i],lstZ[i]);
65 vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
67 int maxSegment1,maxSegment2;
71 int sizeLstIdexes=lstIndexs.size();
72 for (i=0; i<sizeLstIdexes-1;i++)
74 sizeSegment1=lstIndexs[i];
75 sizeSegment2=lstIndexs[i+1];
77 vtkSmartPointer<vtkTriangleStrip> triangleStrip = vtkSmartPointer<vtkTriangleStrip>::New();
78 triangleStrip->GetPointIds()->SetNumberOfIds(sizeSegment1+sizeSegment2);
80 maxElements=sizeSegment1;
81 if (maxElements<sizeSegment2) maxElements=sizeSegment2;
82 maxSegment1=iGeneral+sizeSegment1;
83 maxSegment2=iGeneral+sizeSegment1+sizeSegment2;
85 iSeg2=iGeneral+sizeSegment1;
86 for (ii=0; ii<maxElements; ii++)
88 triangleStrip->GetPointIds()->SetId(ii*2 ,iSeg1);
89 triangleStrip->GetPointIds()->SetId(ii*2+1,iSeg2);
92 if (iSeg1>=maxSegment1) iSeg1=maxSegment1-1;
93 if (iSeg2>=maxSegment2) iSeg2=maxSegment2-1;
95 iGeneral=iGeneral+sizeSegment1;
96 cells->InsertNextCell(triangleStrip);
100 vtkPolyData *polydata = vtkPolyData::New();
101 polydata->SetPoints(points);
102 polydata->SetStrips(cells);
104 vtkCleanPolyData *clean=vtkCleanPolyData::New();
105 clean->SetInputData(polydata);
108 bbSetOutputOut( clean->GetOutput() );
112 printf("EED CreateMeshFromPoints::Process End\n");
117 // 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)
119 void CreateMeshFromPoints::bbUserSetDefaultValues()
122 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
123 // Here we initialize the input 'In' to 0
128 // 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)
130 void CreateMeshFromPoints::bbUserInitializeProcessing()
133 // THE INITIALIZATION METHOD BODY :
135 // but this is where you should allocate the internal/output pointers
141 // 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)
143 void CreateMeshFromPoints::bbUserFinalizeProcessing()
146 // THE FINALIZATION METHOD BODY :
148 // but this is where you should desallocate the internal/output pointers
153 // EO namespace bbcreaVtk