]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkBooleanOperationPolyDataFilter.cxx
3daea3442b25456357365b688b0ef28ffb411ff2
[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
10 #include "vtkCleanPolyData.h"
11 #include "vtkTriangleFilter.h"
12
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         if ((bbGetInputIn1()!=NULL)  && (bbGetInputIn2()!=NULL) )
40         {
41
42 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
43 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
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                 vtkCleanPolyData *clean1 = vtkCleanPolyData::New();
51                 vtkCleanPolyData *clean2 = vtkCleanPolyData::New();
52                 clean1->SetInputData( bbGetInputIn1() );
53                 clean2->SetInputData( bbGetInputIn2() );
54                 clean1->Update();
55                 clean2->Update();
56                 vtkTriangleFilter *triangle1 = vtkTriangleFilter::New();
57                 vtkTriangleFilter *triangle2 = vtkTriangleFilter::New();
58                 triangle1->SetInputData( clean1->GetOutput() );
59                 triangle2->SetInputData( clean2->GetOutput() );
60                 triangle1->Update();
61                 triangle2->Update();
62
63         vtkPolyDataBooleanFilter *booleanOperation = vtkPolyDataBooleanFilter::New();
64         booleanOperation->SetInputData(0, triangle1->GetOutput() );
65         booleanOperation->SetInputData(1, triangle2->GetOutput() );
66         if (bbGetInputOperation()==0 )
67         {
68             booleanOperation->SetOperModeToUnion();
69         }
70         if (bbGetInputOperation()==1 )
71         {
72             booleanOperation->SetOperModeToIntersection();
73         }
74         if (bbGetInputOperation()==2 )
75         {
76             booleanOperation->SetOperModeToDifference();
77         }
78
79 /*
80                 vtkBooleanOperationPolyDataFilter *booleanOperation = vtkBooleanOperationPolyDataFilter::New();
81                 booleanOperation->SetInputData(0, triangle1->GetOutput() );
82                 booleanOperation->SetInputData(1, triangle2->GetOutput() );
83                 if (bbGetInputOperation()==0 )
84                 {
85                         booleanOperation->SetOperationToUnion();
86                 }
87                 if (bbGetInputOperation()==1 )
88                 {
89             booleanOperation->SetOperationToIntersection();
90                 }
91                 if (bbGetInputOperation()==2 )
92                 {
93             booleanOperation->SetOperationToDifference();
94             booleanOperation->SetReorientDifferenceCells( bbGetInputReorientDifferenceCells() );
95         }
96  */
97         
98                 booleanOperation->Update();
99                 bbSetOutputOut( booleanOperation->GetOutput() );
100         } else {
101                 printf("EED Warnning!  BooleanOperationPolyDataFilter::Process   vtkPolyData In1 or In2  is EMPTY\n");
102         } // if In1 In2 != NULL
103 }
104
105 //===== 
106 // 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)
107 //===== 
108 void BooleanOperationPolyDataFilter::bbUserSetDefaultValues()
109 {
110 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
111 //    Here we initialize the input 'In' to 0
112    bbSetInputIn1(NULL);
113    bbSetInputIn2(NULL);
114    bbSetInputOperation(0);
115    bbSetInputReorientDifferenceCells(true);
116    bbSetOutputOut(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::bbUserInitializeProcessing()
123 {
124 //  THE INITIALIZATION METHOD BODY :
125 //    Here does nothing 
126 //    but this is where you should allocate the internal/output pointers 
127 //    if any
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::bbUserFinalizeProcessing()
134 {
135 //  THE FINALIZATION METHOD BODY :
136 //    Here does nothing 
137 //    but this is where you should desallocate the internal/output pointers 
138 //    if any
139 }
140
141 } // EO namespace bbcreaVtk
142
143