]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkMeshCutByAxis.cxx
Bug Modified pipeline
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkMeshCutByAxis.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 "bbcreaVtkMeshCutByAxis.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include <vtkBox.h>
8 #include <vtkPlane.h>
9 #include <vtkClipPolyData.h>
10 #include <vtkPolyDataNormals.h>
11 namespace bbcreaVtk
12 {
13
14 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,MeshCutByAxis)
15 BBTK_BLACK_BOX_IMPLEMENTATION(MeshCutByAxis,bbtk::AtomicBlackBox);
16 //===== 
17 // 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)
18 //===== 
19 void MeshCutByAxis::Process()
20 {
21
22 // THE MAIN PROCESSING METHOD BODY
23 //   Here we simply set the input 'In' value to the output 'Out'
24 //   And print out the output value
25 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
26 //    void bbSet{Input|Output}NAME(const TYPE&)
27 //    const TYPE& bbGet{Input|Output}NAME() const 
28 //    Where :
29 //    * NAME is the name of the input/output
30 //      (the one provided in the attribute 'name' of the tag 'input')
31 //    * TYPE is the C++ type of the input/output
32 //      (the one provided in the attribute 'type' of the tag 'input')
33
34 //    bbSetOutputOut( bbGetInputIn() );
35 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
36
37                 int ok=0;
38                 int sb=1000;
39                 vtkPlane                *clipPlane      = vtkPlane::New();      
40                 vtkBox                  *clipBox        = vtkBox::New();        
41                 vtkClipPolyData *clipper        = vtkClipPolyData::New();
42 //              clipper->GenerateClipScalarsOn();
43 //              clipper->GenerateClippedOutputOff();
44 //EED 2017-01-01 Migration VTK7
45 #if VTK_MAJOR_VERSION <= 5
46             clipper             -> SetInput( bbGetInputIn() );
47 #else
48 //              vtkPolyDataNormals *nn = vtkPolyDataNormals::New();
49 //              nn->SetInputData( bbGetInputIn() );
50 //          clipper             -> SetInputData( nn->GetOutput() );
51             clipper             -> SetInputData( bbGetInputIn() );
52 #endif
53                 clipper->SetInsideOut( bbGetInputInsideVol() );
54                 int a;  // correction border 
55                 if (bbGetInputInsideVol()==false)
56                 {
57                         a=1;
58                 } else {
59                         a=0;
60                 }
61                 int px=bbGetInputPoint()[0];
62                 int py=bbGetInputPoint()[1];
63                 int pz=bbGetInputPoint()[2];
64                 if ( bbGetInputType()=="x"              ) { clipPlane->SetNormal(1, 0, 0);                                                                              ok=1;   } else  
65                 if ( bbGetInputType()=="y"              ) { clipPlane->SetNormal(0, 1, 0);                                                                              ok=1;   } else
66                 if ( bbGetInputType()=="z"              ) { clipPlane->SetNormal(0, 0, 1);                                                                              ok=1;   } else
67                 if ( bbGetInputType()=="x+y+"   ) { clipBox->SetBounds(px       ,px+sb  ,py             ,py+sb  ,pz-sb  ,pz+sb  );      ok=2;   } else
68                 if ( bbGetInputType()=="x-y+"   ) { clipBox->SetBounds(px-sb,px+a       ,py             ,py+sb  ,pz-sb  ,pz+sb  );      ok=2;   } else
69                 if ( bbGetInputType()=="x+y-"   ) { clipBox->SetBounds(px       ,px+sb  ,py-sb  ,py+a   ,pz-sb  ,pz+sb  );      ok=2;   } else
70                 if ( bbGetInputType()=="x-y-"   ) { clipBox->SetBounds(px-sb,px+a       ,py-sb  ,py+a   ,pz-sb  ,pz+sb  );      ok=2;   } else
71
72                 if ( bbGetInputType()=="y+z+"   ) { clipBox->SetBounds(px-sb,px+sb      ,py             ,py+sb  ,pz             ,pz+sb  );      ok=2;   } else
73                 if ( bbGetInputType()=="y-z+"   ) { clipBox->SetBounds(px-sb,px+sb      ,py-sb  ,py+a   ,pz             ,pz+sb  );      ok=2;   } else
74                 if ( bbGetInputType()=="y+z-"   ) { clipBox->SetBounds(px-sb,px+sb      ,py             ,py+sb  ,pz-sb  ,pz+a   );      ok=2;   } else
75                 if ( bbGetInputType()=="y-z-"   ) { clipBox->SetBounds(px-sb,px+sb      ,py-sb  ,py+a   ,pz-sb  ,pz+a   );      ok=2;   } else
76
77                 if ( bbGetInputType()=="x+z+"   ) { clipBox->SetBounds(px       ,px+sb  ,py-sb  ,py+sb  ,pz             ,pz+sb  );      ok=2;   } else
78                 if ( bbGetInputType()=="x-z+"   ) { clipBox->SetBounds(px-sb,px+a       ,py-sb  ,py+sb  ,pz             ,pz+sb  );      ok=2;   } else
79                 if ( bbGetInputType()=="x+z-"   ) { clipBox->SetBounds(px       ,px+sb  ,py-sb  ,py+sb  ,pz-sb  ,pz+a   );      ok=2;   } else
80                 if ( bbGetInputType()=="x-z-"   ) { clipBox->SetBounds(px-sb,px+a       ,py-sb  ,py+sb  ,pz-sb  ,pz+a   );      ok=2;   } else
81
82                 if ( bbGetInputType()=="x+y+z+" ) { clipBox->SetBounds(px       ,px+sb  ,py             ,py+sb  ,pz     ,pz+sb  );      ok=2;   } else
83                 if ( bbGetInputType()=="x-y+z+" ) { clipBox->SetBounds(px-sb,px+a       ,py             ,py+sb  ,pz     ,pz+sb  );      ok=2;   } else
84                 if ( bbGetInputType()=="x+y-z+" ) { clipBox->SetBounds(px       ,px+sb  ,py-sb  ,py+a   ,pz     ,pz+sb  );      ok=2;   } else
85                 if ( bbGetInputType()=="x+y+z-" ) { clipBox->SetBounds(px       ,px+sb  ,py             ,py+sb  ,pz-sb  ,pz+a   );      ok=2;   } else
86                 if ( bbGetInputType()=="x-y-z+" ) { clipBox->SetBounds(px-sb,px+a       ,py-sb  ,py+a   ,pz     ,pz+sb  );      ok=2;   } else
87                 if ( bbGetInputType()=="x+y-z-" ) { clipBox->SetBounds(px       ,px+sb  ,py-sb  ,py+a   ,pz-sb  ,pz+a   );      ok=2;   } else
88                 if ( bbGetInputType()=="x-y+z-" ) { clipBox->SetBounds(px-sb,px+a       ,py             ,py+sb  ,pz-sb  ,pz+a   );      ok=2;   } else
89                 if ( bbGetInputType()=="x-y-z-" ) { clipBox->SetBounds(px-sb,px+a       ,py-sb  ,py+a   ,pz-sb  ,pz+a   );      ok=2;   } 
90
91                 if (ok==1) {
92                         clipPlane       -> SetOrigin(px,py,pz); 
93                         clipPlane       -> Modified();
94                         clipper         -> SetClipFunction(clipPlane);  
95                         clipper         -> Update();
96                         bbSetOutputOut( clipper->GetOutput() ); 
97                 } else          if (ok==2) {                    
98                         clipBox -> Modified();
99                         clipper -> SetClipFunction(clipBox); 
100                         clipper -> Update();
101                         bbSetOutputOut( clipper->GetOutput() ); 
102                 } else {
103                         bbSetOutputOut( bbGetInputIn() ); 
104                 } // ok
105 }
106 //===== 
107 // 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)
108 //===== 
109 void MeshCutByAxis::bbUserSetDefaultValues()
110 {
111
112 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
113 //    Here we initialize the input 'In' to 0
114    bbSetInputIn(NULL);
115    bbSetInputType("x+y+z+");
116    bbSetInputInsideVol(true);
117    std::vector<int> point;
118    point.push_back(0);
119    point.push_back(0);
120    point.push_back(0);
121    bbSetInputPoint(point);
122 }
123 //===== 
124 // 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)
125 //===== 
126 void MeshCutByAxis::bbUserInitializeProcessing()
127 {
128
129 //  THE INITIALIZATION METHOD BODY :
130 //    Here does nothing 
131 //    but this is where you should allocate the internal/output pointers 
132 //    if any 
133
134   
135 }
136 //===== 
137 // 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)
138 //===== 
139 void MeshCutByAxis::bbUserFinalizeProcessing()
140 {
141
142 //  THE FINALIZATION METHOD BODY :
143 //    Here does nothing 
144 //    but this is where you should desallocate the internal/output pointers 
145 //    if any
146   
147 }
148 }
149 // EO namespace bbcreaVtk
150
151