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