]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkGlyphPolyDataNormals.cxx
#3501 new box GlyphPolyDataNormals (Pablo)
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkGlyphPolyDataNormals.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 "bbcreaVtkGlyphPolyDataNormals.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "vtkProperty.h"
8 #include <vtkMath.h>
9
10 namespace bbcreaVtk
11 {
12
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,GlyphPolyDataNormals)
14 BBTK_BLACK_BOX_IMPLEMENTATION(GlyphPolyDataNormals,bbtk::AtomicBlackBox);
15 //===== 
16 // 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)
17 //===== 
18 void GlyphPolyDataNormals::Process()
19 {
20
21 // THE MAIN PROCESSING METHOD BODY
22 //   Here we simply set the input 'In' value to the output 'Out'
23 //   And print out the output value
24 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
25 //    void bbSet{Input|Output}NAME(const TYPE&)
26 //    const TYPE& bbGet{Input|Output}NAME() const 
27 //    Where :
28 //    * NAME is the name of the input/output
29 //      (the one provided in the attribute 'name' of the tag 'input')
30 //    * TYPE is the C++ type of the input/output
31 //      (the one provided in the attribute 'type' of the tag 'input')
32
33
34         //Active bool Done
35         //Color vector Done
36         //Opacity 0-1 Done
37         //Mask Ratio 1-100 Done
38         //Type of Glyph 1-Arrow 2-Line
39         //size of glyph Done
40
41         if(bbGetInputIn() == NULL){
42                 printf("Warnning! GlyphPolyDataNormals::Process: Missing input PolyData\n");
43                 bbSetOutputOut( NULL );
44         }
45         else if(bbGetInputRenderer() == NULL){
46                 printf("Warnning! GlyphPolyDataNormals::Process: Missing Renderer\n");
47                 bbSetOutputOut( NULL );
48         }
49         else{
50                 //Arrow Source
51                 arrow->SetTipResolution(16);
52                 arrow->SetTipLength(0.5);
53                 arrow->SetTipRadius(0.2 * bbGetInputGlyphType());
54                 arrow->Update();
55                   
56                 //Mask Points
57                 ptMask->SetInputData(bbGetInputIn());
58                 ptMask->SetOnRatio(bbGetInputMaskRatio());
59                 ptMask->RandomModeOn();
60                 ptMask->Update();
61                 //Glyph
62                 glyph->SetSourceData(arrow->GetOutput());
63                 glyph->SetInputData(ptMask->GetOutput());
64                 glyph->Update();
65                 //glyph->SetInputData(bbGetInputIn());
66                 glyph->SetVectorModeToUseNormal();
67                 glyph->SetScaleFactor(bbGetInputSize());
68                 glyph->SetColorModeToColorByVector();
69                 glyph->SetScaleModeToScaleByVector();
70                 glyph->OrientOn();
71
72                 //Mapper y Actor
73                 normalsMapper->SetInputData(glyph->GetOutput());
74                 normalsActor->SetMapper(normalsMapper);
75                 normalsActor->GetProperty()->SetOpacity(bbGetInputOpacity());
76                 normalsActor->GetProperty()->SetColor(bbGetInputColor()[0],
77                                                         bbGetInputColor()[1],
78                                                         bbGetInputColor()[2]);
79                 
80                 if(bbGetInputRenderer() != NULL){
81                         if(actorAdded && !bbGetInputActive()){                          
82                                 bbGetInputRenderer()->RemoveActor(normalsActor);
83                                 actorAdded = false;
84                         }
85                         else if(bbGetInputActive() && !actorAdded){
86                                 bbGetInputRenderer()->AddActor(normalsActor);
87                                 actorAdded = true;      
88                         }       
89                 }
90
91                 bbSetOutputOut( normalsActor );
92         }
93   
94 }
95 //===== 
96 // 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)
97 //===== 
98 void GlyphPolyDataNormals::bbUserSetDefaultValues()
99 {
100
101 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
102 //    Here we initialize the input 'In' to 0
103    bbSetInputIn(NULL);
104    bbSetInputOpacity(1);
105    bbSetInputActive(true);
106    bbSetInputMaskRatio(10);
107    std::vector<double> color;
108    color.push_back(0.0);
109    color.push_back(0.0);
110    color.push_back(0.5);
111    bbSetInputColor(color);
112    bbSetInputSize(5);
113    bbSetInputGlyphType(1);
114    bbSetInputRenderer(NULL);
115    bbSetOutputOut(NULL);
116    actorAdded = false;
117 }
118 //===== 
119 // 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)
120 //===== 
121 void GlyphPolyDataNormals::bbUserInitializeProcessing()
122 {
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         arrow                   = vtkArrowSource::New();
129         ptMask                  = vtkMaskPoints::New();
130         glyph                   = vtkGlyph3D::New();
131         normalsMapper   = vtkPolyDataMapper::New();
132         normalsActor    = vtkActor::New();
133   
134 }
135 //===== 
136 // 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)
137 //===== 
138 void GlyphPolyDataNormals::bbUserFinalizeProcessing()
139 {
140
141 //  THE FINALIZATION METHOD BODY :
142 //    Here does nothing 
143 //    but this is where you should desallocate the internal/output pointers 
144 //    if any
145   arrow->Delete();
146   ptMask->Delete();
147   glyph->Delete();
148   normalsMapper->Delete();
149   normalsActor->Delete();
150   
151   arrow                 = NULL;
152   ptMask                = NULL;
153   glyph                 = NULL;
154   normalsMapper = NULL;
155   normalsActor  = NULL;
156 }
157 }
158 // EO namespace bbcreaVtk
159
160