]> 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
14 namespace bbcreaVtk
15 {
16
17 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,BooleanOperationPolyDataFilter)
18 BBTK_BLACK_BOX_IMPLEMENTATION(BooleanOperationPolyDataFilter,bbtk::AtomicBlackBox);
19 //===== 
20 // 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)
21 //===== 
22 void BooleanOperationPolyDataFilter::Process()
23 {
24
25 // THE MAIN PROCESSING METHOD BODY
26 //   Here we simply set the input 'In' value to the output 'Out'
27 //   And print out the output value
28 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
29 //    void bbSet{Input|Output}NAME(const TYPE&)
30 //    const TYPE& bbGet{Input|Output}NAME() const 
31 //    Where :
32 //    * NAME is the name of the input/output
33 //      (the one provided in the attribute 'name' of the tag 'input')
34 //    * TYPE is the C++ type of the input/output
35 //      (the one provided in the attribute 'type' of the tag 'input')
36 //    bbSetOutputOut( bbGetInputIn() );
37 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
38   
39     printf("EED  BooleanOperationPolyDataFilter::Process Start In1=%p     In2=%p\n", bbGetInputIn1(), bbGetInputIn2() );
40
41     
42
43         if ((bbGetInputIn1()!=NULL)  && (bbGetInputIn2()!=NULL) )
44         {
45
46         vtkPoints               *points1         = bbGetInputIn1()->GetPoints();
47         vtkPoints               *points2         = bbGetInputIn2()->GetPoints();
48         printf("EED BooleanOperationPolyDataFilter::Process  Number of points 1  %ld\n", points1->GetNumberOfPoints() );
49         printf("EED BooleanOperationPolyDataFilter::Process  Number of points 2 %ld\n", points2->GetNumberOfPoints() );
50
51         
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 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
57 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
58 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
59 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
60                 vtkCleanPolyData *clean1 = vtkCleanPolyData::New();
61                 vtkCleanPolyData *clean2 = vtkCleanPolyData::New();
62                 clean1->SetInputData( bbGetInputIn1() );
63                 clean2->SetInputData( bbGetInputIn2() );
64                 clean1->Update();
65                 clean2->Update();
66                 vtkTriangleFilter *triangle1 = vtkTriangleFilter::New();
67                 vtkTriangleFilter *triangle2 = vtkTriangleFilter::New();
68                 triangle1->SetInputData( clean1->GetOutput() );
69                 triangle2->SetInputData( clean2->GetOutput() );
70                 triangle1->Update();
71                 triangle2->Update();
72
73         vtkPolyDataBooleanFilter *booleanOperation = vtkPolyDataBooleanFilter::New();
74         booleanOperation->SetInputData(0, triangle1->GetOutput() );
75         booleanOperation->SetInputData(1, triangle2->GetOutput() );
76         if (bbGetInputOperation()==0 )
77         {
78             booleanOperation->SetOperModeToUnion();
79         }
80         if (bbGetInputOperation()==1 )
81         {
82             booleanOperation->SetOperModeToIntersection();
83         }
84         if (bbGetInputOperation()==2 )
85         {
86             booleanOperation->SetOperModeToDifference();
87         }
88
89 /*
90                 vtkBooleanOperationPolyDataFilter *booleanOperation = vtkBooleanOperationPolyDataFilter::New();
91                 booleanOperation->SetInputData(0, triangle1->GetOutput() );
92                 booleanOperation->SetInputData(1, triangle2->GetOutput() );
93                 if (bbGetInputOperation()==0 )
94                 {
95                         booleanOperation->SetOperationToUnion();
96                 }
97                 if (bbGetInputOperation()==1 )
98                 {
99             booleanOperation->SetOperationToIntersection();
100                 }
101                 if (bbGetInputOperation()==2 )
102                 {
103             booleanOperation->SetOperationToDifference();
104             booleanOperation->SetReorientDifferenceCells( bbGetInputReorientDifferenceCells() );
105         }
106  */
107         
108         booleanOperation->Update();
109         vtkPoints *points = booleanOperation->GetOutput()->GetPoints();
110         if (points!=NULL)
111         {
112             bbSetOutputOut( booleanOperation->GetOutput() );
113         } else {
114             bbSetOutputOut( NULL );
115         } // if points!=NULL
116         } else {
117         bbSetOutputOut( NULL );
118                 printf("EED Warnning!  BooleanOperationPolyDataFilter::Process   vtkPolyData In1 or In2  is EMPTY\n");
119         } // if In1 In2 != NULL
120         
121     printf("EED  BooleanOperationPolyDataFilter::Process End \n" );
122 }
123
124 //===== 
125 // 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)
126 //===== 
127 void BooleanOperationPolyDataFilter::bbUserSetDefaultValues()
128 {
129 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
130 //    Here we initialize the input 'In' to 0
131    bbSetInputIn1(NULL);
132    bbSetInputIn2(NULL);
133    bbSetInputOperation(0);
134    bbSetInputReorientDifferenceCells(true);
135    bbSetOutputOut(NULL);
136 }
137
138 //===== 
139 // 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)
140 //===== 
141 void BooleanOperationPolyDataFilter::bbUserInitializeProcessing()
142 {
143 //  THE INITIALIZATION METHOD BODY :
144 //    Here does nothing 
145 //    but this is where you should allocate the internal/output pointers 
146 //    if any
147 }
148
149 //===== 
150 // 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)
151 //===== 
152 void BooleanOperationPolyDataFilter::bbUserFinalizeProcessing()
153 {
154 //  THE FINALIZATION METHOD BODY :
155 //    Here does nothing 
156 //    but this is where you should desallocate the internal/output pointers 
157 //    if any
158 }
159
160 } // EO namespace bbcreaVtk
161
162