]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkBooleanOperationPolyDataFilter.cxx
Clean code
[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     printf("EED BooleanOperationPolyDataFilter::Process \n");
42     
43         if ((bbGetInputIn1()!=NULL)  && (bbGetInputIn2()!=NULL) )
44         {
45         //TRIANGLE FILTER NOT NEEDED, this can handle non triangle meshes.
46         
47
48 //  vtkPolyDataBooleanFilter  is not a vtk filter   (this one yes: vtkBooleanOperationPolyDataFilter )
49 //   https://github.com/zippy84/vtkbool
50         //  vtkPolyDataBooleanFilter is a local code creaVtk lib
51         vtkPolyDataBooleanFilter *booleanOperation = vtkPolyDataBooleanFilter::New();
52
53 //        booleanOperation->SetInputData(0, triangle1->GetOutput() );
54 //        booleanOperation->SetInputData(1, triangle2->GetOutput() );
55
56         booleanOperation->SetInputData(0, bbGetInputIn1() );
57         booleanOperation->SetInputData(1, bbGetInputIn2() );
58
59         if (bbGetInputOperation()==0 )
60         {
61             booleanOperation->SetOperModeToUnion();
62         }
63         if (bbGetInputOperation()==1 )
64         {
65             booleanOperation->SetOperModeToIntersection();
66         }
67         if (bbGetInputOperation()==2 )
68         {
69             booleanOperation->SetOperModeToDifference();
70         }
71
72 /*
73                 vtkBooleanOperationPolyDataFilter *booleanOperation = vtkBooleanOperationPolyDataFilter::New();
74                 booleanOperation->SetInputData(0, triangle1->GetOutput() );
75                 booleanOperation->SetInputData(1, triangle2->GetOutput() );
76                 if (bbGetInputOperation()==0 )
77                 {
78                         booleanOperation->SetOperationToUnion();
79                 }
80                 if (bbGetInputOperation()==1 )
81                 {
82             booleanOperation->SetOperationToIntersection();
83                 }
84                 if (bbGetInputOperation()==2 )
85                 {
86             booleanOperation->SetOperationToDifference();
87             booleanOperation->SetReorientDifferenceCells( bbGetInputReorientDifferenceCells() );
88         }
89  */
90         
91         booleanOperation->Update();
92
93         vtkPoints *points = booleanOperation->GetOutput()->GetPoints();
94         if (points!=NULL)
95         {
96 //            vtkFillHolesFilter *fillHolesFilter = vtkFillHolesFilter::New();
97 //            fillHolesFilter->SetInputData( booleanOperation->GetOutput() );
98 //            fillHolesFilter->SetHoleSize(100000.0);
99 //            fillHolesFilter->Update();
100 //            bbSetOutputOut( fillHolesFilter->GetOutput() );
101                         
102                         /*
103                         *Added boxes(triangleFilter and CleanPolyData) to handle this outside the box
104                         *
105                         vtkTriangleFilter *triangleEnd = vtkTriangleFilter::New();
106                         vtkCleanPolyData *cleanEnd = vtkCleanPolyData::New();
107                         bbSetOutputOut( cleanEnd->GetOutput() );
108                         */
109                         
110             bbSetOutputOut( booleanOperation->GetOutput() );
111         } else {
112             bbSetOutputOut( NULL );
113         } // if points!=NULL
114         
115         } else {
116         bbSetOutputOut( NULL );
117                 printf("EED Warnning!  BooleanOperationPolyDataFilter::Process   vtkPolyData In1 or In2  is EMPTY\n");
118         } // if In1 In2 != NULL
119 }
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 BooleanOperationPolyDataFilter::bbUserSetDefaultValues()
125 {
126 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
127 //    Here we initialize the input 'In' to 0
128    bbSetInputIn1(NULL);
129    bbSetInputIn2(NULL);
130    bbSetInputOperation(0);
131    bbSetInputReorientDifferenceCells(true);
132    bbSetOutputOut(NULL);
133 }
134
135 //===== 
136 // 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)
137 //===== 
138 void BooleanOperationPolyDataFilter::bbUserInitializeProcessing()
139 {
140 //  THE INITIALIZATION METHOD BODY :
141 //    Here does nothing 
142 //    but this is where you should allocate the internal/output pointers 
143 //    if any
144 }
145
146 //===== 
147 // 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)
148 //===== 
149 void BooleanOperationPolyDataFilter::bbUserFinalizeProcessing()
150 {
151 //  THE FINALIZATION METHOD BODY :
152 //    Here does nothing 
153 //    but this is where you should desallocate the internal/output pointers 
154 //    if any
155 }
156
157 } // EO namespace bbcreaVtk
158
159