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