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