]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkBooleanOperationPolyDataFilter.cxx
#3493 MeshManager
[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 Start In1=%p     In2=%p\n", bbGetInputIn1(), bbGetInputIn2() );
42
43     
44
45         if ((bbGetInputIn1()!=NULL)  && (bbGetInputIn2()!=NULL) )
46         {
47         
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 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
53 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
54 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
55 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
56     
57         vtkCleanPolyData *clean1 = vtkCleanPolyData::New();
58                 vtkCleanPolyData *clean2 = vtkCleanPolyData::New();
59                 clean1->SetInputData( bbGetInputIn1() );
60                 clean2->SetInputData( bbGetInputIn2() );
61                 clean1->Update();
62                 clean2->Update();
63                 vtkTriangleFilter *triangle1 = vtkTriangleFilter::New();
64                 vtkTriangleFilter *triangle2 = vtkTriangleFilter::New();
65                 triangle1->SetInputData( clean1->GetOutput() );
66                 triangle2->SetInputData( clean2->GetOutput() );
67                 triangle1->Update();
68                 triangle2->Update();
69
70 //  vtkPolyDataBooleanFilter  is not a vtk filter   (this one yes: vtkBooleanOperationPolyDataFilter )
71 //   https://github.com/zippy84/vtkbool
72         //  vtkPolyDataBooleanFilter is a local code creaVtk lib
73         vtkPolyDataBooleanFilter *booleanOperation = vtkPolyDataBooleanFilter::New();
74
75         booleanOperation->SetInputData(0, triangle1->GetOutput() );
76         booleanOperation->SetInputData(1, triangle2->GetOutput() );
77
78 //        booleanOperation->SetInputData(0, bbGetInputIn1() );
79 //        booleanOperation->SetInputData(1, bbGetInputIn2() );
80
81         if (bbGetInputOperation()==0 )
82         {
83             booleanOperation->SetOperModeToUnion();
84         }
85         if (bbGetInputOperation()==1 )
86         {
87             booleanOperation->SetOperModeToIntersection();
88         }
89         if (bbGetInputOperation()==2 )
90         {
91             booleanOperation->SetOperModeToDifference();
92         }
93
94 /*
95                 vtkBooleanOperationPolyDataFilter *booleanOperation = vtkBooleanOperationPolyDataFilter::New();
96                 booleanOperation->SetInputData(0, triangle1->GetOutput() );
97                 booleanOperation->SetInputData(1, triangle2->GetOutput() );
98                 if (bbGetInputOperation()==0 )
99                 {
100                         booleanOperation->SetOperationToUnion();
101                 }
102                 if (bbGetInputOperation()==1 )
103                 {
104             booleanOperation->SetOperationToIntersection();
105                 }
106                 if (bbGetInputOperation()==2 )
107                 {
108             booleanOperation->SetOperationToDifference();
109             booleanOperation->SetReorientDifferenceCells( bbGetInputReorientDifferenceCells() );
110         }
111  */
112         
113         booleanOperation->Update();
114
115         vtkPoints *points = booleanOperation->GetOutput()->GetPoints();
116         if (points!=NULL)
117         {
118             vtkFillHolesFilter *fillHolesFilter = vtkFillHolesFilter::New();
119             fillHolesFilter->SetInputData( booleanOperation->GetOutput() );
120             fillHolesFilter->SetHoleSize(100000.0);
121             fillHolesFilter->Update();
122             bbSetOutputOut( fillHolesFilter->GetOutput() );
123 //          bbSetOutputOut( booleanOperation->GetOutput() );
124         } else {
125             bbSetOutputOut( NULL );
126         } // if points!=NULL
127         
128         } else {
129         bbSetOutputOut( NULL );
130                 printf("EED Warnning!  BooleanOperationPolyDataFilter::Process   vtkPolyData In1 or In2  is EMPTY\n");
131         } // if In1 In2 != NULL
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 BooleanOperationPolyDataFilter::bbUserSetDefaultValues()
138 {
139 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
140 //    Here we initialize the input 'In' to 0
141    bbSetInputIn1(NULL);
142    bbSetInputIn2(NULL);
143    bbSetInputOperation(0);
144    bbSetInputReorientDifferenceCells(true);
145    bbSetOutputOut(NULL);
146 }
147
148 //===== 
149 // 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)
150 //===== 
151 void BooleanOperationPolyDataFilter::bbUserInitializeProcessing()
152 {
153 //  THE INITIALIZATION METHOD BODY :
154 //    Here does nothing 
155 //    but this is where you should allocate the internal/output pointers 
156 //    if any
157 }
158
159 //===== 
160 // 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)
161 //===== 
162 void BooleanOperationPolyDataFilter::bbUserFinalizeProcessing()
163 {
164 //  THE FINALIZATION METHOD BODY :
165 //    Here does nothing 
166 //    but this is where you should desallocate the internal/output pointers 
167 //    if any
168 }
169
170 } // EO namespace bbcreaVtk
171
172