]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkBooleanOperationPolyDataFilter.cxx
#3503 Clean BooleanOperationPolyDataFilter
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkBooleanOperationPolyDataFilter.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 "bbcreaVtkBooleanOperationPolyDataFilter.h"
5 #include "bbcreaVtkPackage.h"
6
7 // #include "vtkBooleanOperationPolyDataFilter.h"
8 #include "vtkPolyDataBooleanFilter.h"
9 #include "vtkPoints.h"
10
11 #include "vtkCleanPolyData.h"
12 #include "vtkTriangleFilter.h"
13 #include "vtkFillHolesFilter.h"
14
15
16 namespace bbcreaVtk
17 {
18
19 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,BooleanOperationPolyDataFilter)
20 BBTK_BLACK_BOX_IMPLEMENTATION(BooleanOperationPolyDataFilter,bbtk::AtomicBlackBox);
21 //===== 
22 // 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)
23 //===== 
24 void BooleanOperationPolyDataFilter::Process()
25 {
26
27 // THE MAIN PROCESSING METHOD BODY
28 //   Here we simply set the input 'In' value to the output 'Out'
29 //   And print out the output value
30 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
31 //    void bbSet{Input|Output}NAME(const TYPE&)
32 //    const TYPE& bbGet{Input|Output}NAME() const 
33 //    Where :
34 //    * NAME is the name of the input/output
35 //      (the one provided in the attribute 'name' of the tag 'input')
36 //    * TYPE is the C++ type of the input/output
37 //      (the one provided in the attribute 'type' of the tag 'input')
38 //    bbSetOutputOut( bbGetInputIn() );
39 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
40   
41         if ((bbGetInputIn1()!=NULL)  && (bbGetInputIn2()!=NULL) )
42         {
43 /*        
44 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
45 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
46 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
47 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
48 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
49 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
50 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
51 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
52 */
53
54 /*    
55         vtkCleanPolyData *clean1 = vtkCleanPolyData::New();
56                 vtkCleanPolyData *clean2 = vtkCleanPolyData::New();
57                 clean1->SetInputData( bbGetInputIn1() );
58                 clean2->SetInputData( bbGetInputIn2() );
59                 clean1->Update();
60                 clean2->Update();
61                 vtkTriangleFilter *triangle1 = vtkTriangleFilter::New();
62                 vtkTriangleFilter *triangle2 = vtkTriangleFilter::New();
63                 triangle1->SetInputData( clean1->GetOutput() );
64                 triangle2->SetInputData( clean2->GetOutput() );
65                 triangle1->Update();
66                 triangle2->Update();
67 */
68         //TRIANGLE FILTER NOT NEEDED, this can handle non triangle meshes.
69         
70
71 //  vtkPolyDataBooleanFilter  is not a vtk filter   (this one yes: vtkBooleanOperationPolyDataFilter )
72 //   https://github.com/zippy84/vtkbool
73         //  vtkPolyDataBooleanFilter is a local code creaVtk lib
74         vtkPolyDataBooleanFilter *booleanOperation = vtkPolyDataBooleanFilter::New();
75
76 //        booleanOperation->SetInputData(0, triangle1->GetOutput() );
77 //        booleanOperation->SetInputData(1, triangle2->GetOutput() );
78
79         booleanOperation->SetInputData(0, bbGetInputIn1() );
80         booleanOperation->SetInputData(1, bbGetInputIn2() );
81
82         if (bbGetInputOperation()==0 )
83         {
84             booleanOperation->SetOperModeToUnion();
85         }
86         if (bbGetInputOperation()==1 )
87         {
88             booleanOperation->SetOperModeToIntersection();
89         }
90         if (bbGetInputOperation()==2 )
91         {
92             booleanOperation->SetOperModeToDifference();
93         }
94
95 /*
96                 vtkBooleanOperationPolyDataFilter *booleanOperation = vtkBooleanOperationPolyDataFilter::New();
97                 booleanOperation->SetInputData(0, triangle1->GetOutput() );
98                 booleanOperation->SetInputData(1, triangle2->GetOutput() );
99                 if (bbGetInputOperation()==0 )
100                 {
101                         booleanOperation->SetOperationToUnion();
102                 }
103                 if (bbGetInputOperation()==1 )
104                 {
105             booleanOperation->SetOperationToIntersection();
106                 }
107                 if (bbGetInputOperation()==2 )
108                 {
109             booleanOperation->SetOperationToDifference();
110             booleanOperation->SetReorientDifferenceCells( bbGetInputReorientDifferenceCells() );
111         }
112  */
113         
114         booleanOperation->Update();
115
116         vtkPoints *points = booleanOperation->GetOutput()->GetPoints();
117         if (points!=NULL)
118         {
119 //            vtkFillHolesFilter *fillHolesFilter = vtkFillHolesFilter::New();
120 //            fillHolesFilter->SetInputData( booleanOperation->GetOutput() );
121 //            fillHolesFilter->SetHoleSize(100000.0);
122 //            fillHolesFilter->Update();
123 //            bbSetOutputOut( fillHolesFilter->GetOutput() );
124                         
125                         /*
126                         *
127                         *Added boxes(triangleFilter and CleanPolyData) to handle this outside the box
128                         *
129                         
130                         //vtkTriangleFilter *triangleEnd = vtkTriangleFilter::New();
131                         //triangleEnd->SetInputData( booleanOperation->GetOutput() );
132                         //triangleEnd->Update();
133                         
134                         vtkCleanPolyData *cleanEnd = vtkCleanPolyData::New();
135                         cleanEnd->SetInputData( booleanOperation->GetOutput() );
136                         cleanEnd->Update();
137                         bbSetOutputOut( cleanEnd->GetOutput() );
138                         */
139                         
140             bbSetOutputOut( booleanOperation->GetOutput() );
141         } else {
142             bbSetOutputOut( NULL );
143         } // if points!=NULL
144         
145         } else {
146         bbSetOutputOut( NULL );
147                 printf("EED Warnning!  BooleanOperationPolyDataFilter::Process   vtkPolyData In1 or In2  is EMPTY\n");
148         } // if In1 In2 != NULL
149 }
150
151 //===== 
152 // 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)
153 //===== 
154 void BooleanOperationPolyDataFilter::bbUserSetDefaultValues()
155 {
156 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
157 //    Here we initialize the input 'In' to 0
158    bbSetInputIn1(NULL);
159    bbSetInputIn2(NULL);
160    bbSetInputOperation(0);
161    bbSetInputReorientDifferenceCells(true);
162    bbSetOutputOut(NULL);
163 }
164
165 //===== 
166 // 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)
167 //===== 
168 void BooleanOperationPolyDataFilter::bbUserInitializeProcessing()
169 {
170 //  THE INITIALIZATION METHOD BODY :
171 //    Here does nothing 
172 //    but this is where you should allocate the internal/output pointers 
173 //    if any
174 }
175
176 //===== 
177 // 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)
178 //===== 
179 void BooleanOperationPolyDataFilter::bbUserFinalizeProcessing()
180 {
181 //  THE FINALIZATION METHOD BODY :
182 //    Here does nothing 
183 //    but this is where you should desallocate the internal/output pointers 
184 //    if any
185 }
186
187 } // EO namespace bbcreaVtk
188
189