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