]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkGlyphPolyDataNormals.cxx
#3506 JSON write box
[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     {
43                 printf("Warnning! GlyphPolyDataNormals::Process: Missing input PolyData\n");
44                 bbSetOutputOut( NULL );
45         
46         if(bbGetInputRenderer() != NULL)
47         {
48             if( (actorAdded==true) && (bbGetInputActive()==true) )
49             {
50                 bbGetInputRenderer()->RemoveActor(normalsActor);
51                 actorAdded = false;
52             }
53         } // if Renderer
54         
55         } else if(bbGetInputRenderer() == NULL) {
56                 printf("Warnning! GlyphPolyDataNormals::Process: Missing Renderer\n");
57                 bbSetOutputOut( NULL );
58         } else {
59                 //Arrow Source
60                 arrow->SetTipResolution(4);
61                 arrow->SetTipLength(0.5);
62                 arrow->SetTipRadius(0.2 * bbGetInputGlyphType());
63                 arrow->Update();
64                   
65                 //Mask Points
66                 ptMask->SetInputData(bbGetInputIn());
67                 ptMask->SetOnRatio(bbGetInputMaskRatio());
68                 ptMask->RandomModeOn();
69                 ptMask->Update();
70                 //Glyph
71                 glyph->SetSourceData(arrow->GetOutput());
72                 glyph->SetInputData(ptMask->GetOutput());
73                 glyph->Update();
74                 //glyph->SetInputData(bbGetInputIn());
75                 glyph->SetVectorModeToUseNormal();
76                 glyph->SetScaleFactor(bbGetInputSize());
77                 glyph->SetColorModeToColorByVector();
78                 glyph->SetScaleModeToScaleByVector();
79                 glyph->OrientOn();
80
81                 //Mapper y Actor
82                 normalsMapper->SetInputData(glyph->GetOutput());
83                 normalsActor->SetMapper(normalsMapper);
84                 normalsActor->GetProperty()->SetOpacity(bbGetInputOpacity());
85                 normalsActor->GetProperty()->SetColor(bbGetInputColor()[0],
86                                                         bbGetInputColor()[1],
87                                                         bbGetInputColor()[2]);
88                 
89                 if(bbGetInputRenderer() != NULL)
90         {
91                         if( (actorAdded==true) && !(bbGetInputActive()==true) )
92             {
93                                 bbGetInputRenderer()->RemoveActor(normalsActor);
94                                 actorAdded = false;
95                         } else if(bbGetInputActive() && !actorAdded) {
96                                 bbGetInputRenderer()->AddActor(normalsActor);
97                                 actorAdded = true;      
98                         }       
99                 } // if Renderer
100
101                 bbSetOutputOut( normalsActor );
102         } // if InputIn
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 GlyphPolyDataNormals::bbUserSetDefaultValues()
109 {
110
111 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
112 //    Here we initialize the input 'In' to 0
113    bbSetInputIn(NULL);
114    bbSetInputOpacity(1);
115    bbSetInputActive(true);
116    bbSetInputMaskRatio(10);
117    std::vector<double> color;
118    color.push_back(0.0);
119    color.push_back(0.0);
120    color.push_back(0.5);
121    bbSetInputColor(color);
122    bbSetInputSize(5);
123    bbSetInputGlyphType(1);
124    bbSetInputRenderer(NULL);
125    bbSetOutputOut(NULL);
126    actorAdded = false;
127 }
128 //===== 
129 // 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)
130 //===== 
131 void GlyphPolyDataNormals::bbUserInitializeProcessing()
132 {
133
134 //  THE INITIALIZATION METHOD BODY :
135 //    Here does nothing 
136 //    but this is where you should allocate the internal/output pointers 
137 //    if any 
138         arrow                   = vtkArrowSource::New();
139         ptMask                  = vtkMaskPoints::New();
140         glyph                   = vtkGlyph3D::New();
141         normalsMapper   = vtkPolyDataMapper::New();
142         normalsActor    = vtkActor::New();
143   
144 }
145 //===== 
146 // 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)
147 //===== 
148 void GlyphPolyDataNormals::bbUserFinalizeProcessing()
149 {
150
151 //  THE FINALIZATION METHOD BODY :
152 //    Here does nothing 
153 //    but this is where you should desallocate the internal/output pointers 
154 //    if any
155   arrow->Delete();
156   ptMask->Delete();
157   glyph->Delete();
158   normalsMapper->Delete();
159   normalsActor->Delete();
160   
161   arrow                 = NULL;
162   ptMask                = NULL;
163   glyph                 = NULL;
164   normalsMapper = NULL;
165   normalsActor  = NULL;
166 }
167 }
168 // EO namespace bbcreaVtk
169
170