]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx
Clean code
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkCreateMeshFromPoints.cxx
1 //===== 
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)
3 //===== 
4 #include "bbcreaVtkCreateMeshFromPoints.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "vtkTriangleStrip.h"
8
9 namespace bbcreaVtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,CreateMeshFromPoints)
13 BBTK_BLACK_BOX_IMPLEMENTATION(CreateMeshFromPoints,bbtk::AtomicBlackBox);
14 //===== 
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)
16 //===== 
17 void CreateMeshFromPoints::Process()
18 {
19
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 
26 //    Where :
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')
31
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     
39                 if ( (lstIndexs.size()<=1) || (lstX.size()==0) || (lstX.size()!=lstY.size()) || (lstY.size()!=lstZ.size()) )
40                 {
41                         printf("Warnning! CreateMeshFromPoints::Process: List of points X Y Z  and LstIndexes is not correct\n");
42                         bbSetOutputOut(NULL);
43                 } else  {
44             printf("EED CreateMeshFromPoints::Process  initial=%d  final=%d\n" ,  lstIndexs[0] ,   lstIndexs[  lstIndexs.size()-1 ] );
45                         int ii,sizeSegment1,sizeSegment2;
46                         int endSegment;
47 //                      vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
48                         if (points!=NULL) points->Delete();
49                         points = vtkPoints::New();
50                         int i,sizeLstX  =       lstX.size();
51                         for (i=0;i<sizeLstX;i++)
52                         {
53                                 points->InsertNextPoint(lstX[i],lstY[i],lstZ[i]);
54                         } // for i
55 //                      vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
56                         if (cells!=NULL) cells->Delete();
57                         cells = vtkCellArray::New();
58                         int maxElements;
59                         int maxSegment1,maxSegment2;
60                         int iSeg1,iSeg2;
61                         int iGeneral    =       0;
62                         int     sizeLstIdexes=lstIndexs.size();
63                         for (i=0; i<sizeLstIdexes-1; i++ )
64                         {
65                                 sizeSegment1 = lstIndexs[i];
66                                 sizeSegment2 = lstIndexs[i+1];
67                                 vtkSmartPointer<vtkTriangleStrip> triangleStrip = vtkSmartPointer<vtkTriangleStrip>::New();
68                                 triangleStrip->GetPointIds()->SetNumberOfIds(sizeSegment1+sizeSegment2);
69                                 maxElements=sizeSegment1;
70                                 if (maxElements<sizeSegment2) maxElements=sizeSegment2;
71                                 maxSegment1     = iGeneral+sizeSegment1;
72                                 maxSegment2     = iGeneral+sizeSegment1+sizeSegment2;
73                                 iSeg1           = iGeneral;
74                                 iSeg2           = iGeneral+sizeSegment1;
75                                 for (ii=0; ii<maxElements; ii++)
76                                 {
77                                         triangleStrip->GetPointIds()->SetId(ii*2  ,iSeg1);
78                                         triangleStrip->GetPointIds()->SetId(ii*2+1,iSeg2);
79                                         iSeg1++;
80                                         iSeg2++;
81                     if (iSeg1>=maxSegment1) { iSeg1=maxSegment1-1; }
82                     if (iSeg2>=maxSegment2) { iSeg2=maxSegment2-1; }
83                                 } // for ii 
84                                 iGeneral=iGeneral+sizeSegment1;
85                                 cells->InsertNextCell(triangleStrip);
86                         } //for  LstIndexs
87                         
88 //                      vtkPolyData *polydata = vtkPolyData::New();
89                         if (polydata!=NULL) polydata->Delete();
90                         polydata = vtkPolyData::New();
91                         polydata->SetPoints(points);
92                         polydata->SetStrips(cells);
93 //                      vtkCleanPolyData *clean=vtkCleanPolyData::New();
94                         if (clean!=NULL) clean->Delete();
95                         clean = vtkCleanPolyData::New();
96                         clean->SetInputData(polydata);
97                         clean->Update();
98 //                      vtkTriangleFilter *triangle = vtkTriangleFilter::New();
99                         if (triangle!=NULL) triangle->Delete();
100                         triangle = vtkTriangleFilter::New();
101                         triangle->SetInputData( clean->GetOutput() );
102                         triangle->Update();
103                         bbSetOutputOut( clean->GetOutput() );
104                 }// if listXYZ size
105 }
106 //===== 
107 // 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)
108 //===== 
109 void CreateMeshFromPoints::bbUserSetDefaultValues()
110 {
111
112 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
113 //    Here we initialize the input 'In' to 0
114 //   bbSetInputIn(0);
115         points          = NULL;
116         cells           = NULL;
117         polydata        = NULL;
118         clean           = NULL;
119         triangle        = NULL;
120 }
121 //===== 
122 // 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)
123 //===== 
124 void CreateMeshFromPoints::bbUserInitializeProcessing()
125 {
126
127 //  THE INITIALIZATION METHOD BODY :
128 //    Here does nothing 
129 //    but this is where you should allocate the internal/output pointers 
130 //    if any 
131
132   
133 }
134 //===== 
135 // 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)
136 //===== 
137 void CreateMeshFromPoints::bbUserFinalizeProcessing()
138 {
139
140 //  THE FINALIZATION METHOD BODY :
141 //    Here does nothing 
142 //    but this is where you should desallocate the internal/output pointers 
143 //    if any
144   
145 }
146 }
147 // EO namespace bbcreaVtk
148
149