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