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"
7 #include "vtkTriangleStrip.h"
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,CreateMeshFromPoints)
13 BBTK_BLACK_BOX_IMPLEMENTATION(CreateMeshFromPoints,bbtk::AtomicBlackBox);
15 // 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)
17 void CreateMeshFromPoints::Process()
20 // THE MAIN PROCESSING METHOD BODY
21 // Here we simply set the input 'In' value to the output 'Out'
22 // And print out the output value
23 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
24 // void bbSet{Input|Output}NAME(const TYPE&)
25 // const TYPE& bbGet{Input|Output}NAME() const
27 // * NAME is the name of the input/output
28 // (the one provided in the attribute 'name' of the tag 'input')
29 // * TYPE is the C++ type of the input/output
30 // (the one provided in the attribute 'type' of the tag 'input')
32 // bbSetOutputOut( bbGetInputIn() );
33 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
34 std::vector<double> lstX = bbGetInputLstX();
35 std::vector<double> lstY = bbGetInputLstY();
36 std::vector<double> lstZ = bbGetInputLstZ();
37 std::vector<int> lstIndexs = bbGetInputLstIndexs();
38 if ( (lstIndexs.size()<=1) || (lstX.size()==0) || (lstX.size()!=lstY.size()) || (lstY.size()!=lstZ.size()) )
40 printf("Warnning! CreateMeshFromPoints::Process: List of points X Y Z and LstIndexes is not correct\n");
42 int ii,sizeSegment1,sizeSegment2;
44 // vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
45 if (points!=NULL) points->Delete();
46 points = vtkPoints::New();
47 int i,sizeLstX = lstX.size();
48 for (i=0;i<sizeLstX;i++)
50 points->InsertNextPoint(lstX[i],lstY[i],lstZ[i]);
52 // vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
53 if (cells!=NULL) cells->Delete();
54 cells = vtkCellArray::New();
56 int maxSegment1,maxSegment2;
59 int sizeLstIdexes=lstIndexs.size();
60 for (i=0; i<sizeLstIdexes-1;i++)
62 sizeSegment1 = lstIndexs[i];
63 sizeSegment2 = lstIndexs[i+1];
64 vtkSmartPointer<vtkTriangleStrip> triangleStrip = vtkSmartPointer<vtkTriangleStrip>::New();
65 triangleStrip->GetPointIds()->SetNumberOfIds(sizeSegment1+sizeSegment2);
66 maxElements=sizeSegment1;
67 if (maxElements<sizeSegment2) maxElements=sizeSegment2;
68 maxSegment1 = iGeneral+sizeSegment1;
69 maxSegment2 = iGeneral+sizeSegment1+sizeSegment2;
71 iSeg2 = iGeneral+sizeSegment1;
72 for (ii=0; ii<maxElements; ii++)
74 triangleStrip->GetPointIds()->SetId(ii*2 ,iSeg1);
75 triangleStrip->GetPointIds()->SetId(ii*2+1,iSeg2);
78 if (iSeg1>=maxSegment1) iSeg1=maxSegment1-1;
79 if (iSeg2>=maxSegment2) iSeg2=maxSegment2-1;
81 iGeneral=iGeneral+sizeSegment1;
82 cells->InsertNextCell(triangleStrip);
84 // vtkPolyData *polydata = vtkPolyData::New();
85 if (polydata!=NULL) polydata->Delete();
86 polydata = vtkPolyData::New();
87 polydata->SetPoints(points);
88 polydata->SetStrips(cells);
89 // vtkCleanPolyData *clean=vtkCleanPolyData::New();
90 if (clean!=NULL) clean->Delete();
91 clean = vtkCleanPolyData::New();
92 clean->SetInputData(polydata);
94 // vtkTriangleFilter *triangle = vtkTriangleFilter::New();
95 if (triangle!=NULL) triangle->Delete();
96 triangle = vtkTriangleFilter::New();
97 triangle->SetInputData( clean->GetOutput() );
99 bbSetOutputOut( clean->GetOutput() );
103 // 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)
105 void CreateMeshFromPoints::bbUserSetDefaultValues()
108 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
109 // Here we initialize the input 'In' to 0
118 // 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)
120 void CreateMeshFromPoints::bbUserInitializeProcessing()
123 // THE INITIALIZATION METHOD BODY :
125 // but this is where you should allocate the internal/output pointers
131 // 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)
133 void CreateMeshFromPoints::bbUserFinalizeProcessing()
136 // THE FINALIZATION METHOD BODY :
138 // but this is where you should desallocate the internal/output pointers
143 // EO namespace bbcreaVtk