]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkVectorsTensorsVisuBase.cpp
c591a5f9beceaf7413a0cab2d0f1242756f1865d
[creaVtk.git] / lib / creaVtk / vtkVectorsTensorsVisuBase.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sante)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28 #include "vtkVectorsTensorsVisuBase.h"
29 #include "vtkObjectFactory.h"
30
31 vtkStandardNewMacro(vtkLookupTableDirectionVector);
32
33 // Construct with range=(0,1); and hsv ranges set up for rainbow color table 
34 // (from red to blue).
35 vtkLookupTableDirectionVector::vtkLookupTableDirectionVector(int sze, int ext)
36 {
37         this->TableRange[0] = 0.0;
38         this->TableRange[1] = 1.0;
39 }
40
41 //----------------------------------------------------------------------------
42 vtkLookupTableDirectionVector::~vtkLookupTableDirectionVector()
43 {
44 }
45
46 unsigned char *vtkLookupTableDirectionVector::MapValue(double v)
47 {
48         
49         //int idx = this->GetIndex(v);
50         //return (this->Table->GetPointer(0) + 4*idx);  
51         return 0;
52 }
53
54 void vtkLookupTableDirectionVector::GetColor(double v, double rgb[3])
55 {
56 //      unsigned char *rgb8 = this->MapValue(v);
57 //      rgb[0] = rgb8[0]/255.0;
58 //      rgb[1] = rgb8[1]/255.0;
59 //      rgb[2] = rgb8[2]/255.0;
60
61         rgb[0] = 1;
62         rgb[1] = 1;
63         rgb[2] = 0;
64 }
65
66
67 void vtkLookupTableDirectionVector::SetTableRange(double r[2])
68 {
69         this->SetTableRange(r[0],r[1]);
70 }
71
72 //----------------------------------------------------------------------------
73 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
74 // less than minimum range value are clamped to minimum range value.
75 // Scalar values greater than maximum range value are clamped to maximum
76 // range value.
77 void vtkLookupTableDirectionVector::SetTableRange(double rmin, double rmax)
78 {
79         if (rmax < rmin)
80     {
81                 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
82                 return;
83     }
84         
85         if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
86     {
87                 return;
88     }
89         
90         this->TableRange[0] = rmin;
91         this->TableRange[1] = rmax;
92         
93         this->Modified();
94 }
95
96
97
98 //----------------------------------------------------------------------------
99 // Although this is a relatively expensive calculation,
100 // it is only done on the first render. Colors are cached
101 // for subsequent renders.
102 template<class T>
103 void vtkLookupTableMapDirVectorEED(vtkLookupTableDirectionVector *self, T *input, 
104                           unsigned char *output, int length, 
105                           int inIncr, int outFormat)
106 {
107         double tmp,sum;
108         int i, j;
109         double dirx,diry,dirz;
110         double angle;
111         for (i = 0; i < length; ++i)
112     {
113                         dirx    = static_cast<T>(input[0]);
114                         diry    = static_cast<T>(input[1]);
115                         dirz    = static_cast<T>(input[2]);
116                         input   = input+inIncr;
117                         sum             = sqrt( dirx*dirx + diry*diry + dirz*dirz );
118                         *output++ = (unsigned char) abs( (255*dirx/sum) );
119                         *output++ = (unsigned char) abs( (255*diry/sum) );
120                         *output++ = (unsigned char) abs( (255*dirz/sum) );
121                         *output++ = 255;
122         //              printf("%d %d %d   ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
123         //              printf(" C     %d        %f %f %f   \n",inIncr,dirx,diry,dirz);
124
125         } // for
126 }
127
128
129 //----------------------------------------------------------------------------
130 void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input, 
131                                              unsigned char *output,
132                                              int inputDataType, 
133                                              int numberOfValues,
134                                              int inputIncrement,
135                                              int outputFormat)
136 {
137 // if (this->UseMagnitude && inputIncrement > 1)
138 // {
139      switch (inputDataType)
140      {
141        vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
142                          numberOfValues,inputIncrement,outputFormat);
143                          return 
144                         );
145         case VTK_BIT:
146             vtkErrorMacro("Cannot comput magnitude of bit array.");
147             break;
148         default:
149             vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
150      } /// switch
151 // } //if
152 }  
153
154
155 //----------------------------------------------------------------------------
156 void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent)
157 {
158         this->Superclass::PrintSelf(os,indent); 
159 }
160
161
162
163
164 //----------------------------------
165 //----------------------------------
166 //----------------------------------
167 //----------------------------------
168 //----------------------------------
169
170 vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase()
171 {
172      _firsttime         = true;
173         _active                 = false;
174         _scalefactor    = 1;
175         _opacity                = 1;
176         _dataobject             = NULL;
177         _renderer               = NULL;
178         _typeForm               = 0;
179         _orientation    = 0;
180
181         _LutEED                 = vtkLookupTableDirectionVector::New();
182         _externalLut    = NULL;
183         //_LutEED->SetVectorMode(0);
184         //_LutEED->SetVectorModeToMagnitude();
185         //_LutEED->SetVectorModeToComponent();
186         _LutEED->SetVectorModeToRGBColors();
187
188         _pdm                    = vtkPolyDataMapper::New();
189         _actor                  = vtkActor::New();
190         _actorAdded             = false;
191 }
192
193 vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase()
194 {
195 }
196
197 //------------------------------------------------------------------------
198 void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject)
199 {
200         _dataobject = dataobject;
201 }
202
203 //------------------------------------------------------------------------
204 vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject()
205 {
206         return _dataobject;
207 }
208
209 //------------------------------------------------------------------------
210 void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer)
211 {
212         _renderer=renderer;
213 }
214
215 //------------------------------------------------------------------------
216 vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer()
217 {
218         return _renderer;
219 }
220
221 //------------------------------------------------------------------------
222 void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor)
223 {
224         _scalefactor=scalefactor;
225 }
226
227 //------------------------------------------------------------------------
228 double vtkVectorsTensorsVisuBase::GetScaleFactor()
229 {
230         return _scalefactor;
231 }
232
233 //------------------------------------------------------------------------
234 void vtkVectorsTensorsVisuBase::SetActive(bool active)
235 {
236    _active = active;
237 }
238
239 //------------------------------------------------------------------------
240 bool vtkVectorsTensorsVisuBase::GetActive()
241 {
242    return _active;
243 }
244
245 //------------------------------------------------------------------------
246 void vtkVectorsTensorsVisuBase::SetOpacity(double opacity)
247 {
248    _opacity = opacity;
249 }
250
251 //------------------------------------------------------------------------
252 double vtkVectorsTensorsVisuBase::GetOpacity()
253 {
254    return _opacity;
255 }
256
257
258
259 //------------------------------------------------------------------------
260 vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D()
261 {
262    return _actor;
263 }
264
265 //------------------------------------------------------------------------
266 void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm)
267 {
268      _typeForm=typeForm;
269 }
270
271
272 //------------------------------------------------------------------------
273 int vtkVectorsTensorsVisuBase::GetTypeForm()
274 {
275         return _typeForm;
276 }
277
278 //------------------------------------------------------------------------
279 void vtkVectorsTensorsVisuBase::Process()    // virtual
280 {
281 }
282
283 //------------------------------------------------------------------------------
284 void vtkVectorsTensorsVisuBase::VisibilityActor()
285 {
286
287         if ( (_active==true) && (_actorAdded==false) ){
288                 if (GetRenderer()!=NULL)
289                 {
290               GetRenderer()->AddActor(_actor);
291                    _actorAdded=true;
292        } // if Renderer
293         } // if _active==true 
294
295         if ( (_active==false) && (_actorAdded==true) ){
296                 if (GetRenderer()!=NULL)
297                 {
298               GetRenderer()->RemoveActor(_actor);
299                    _actorAdded=false;
300       } // if Renderer
301         } // if _active==false  
302 }
303
304 //------------------------------------------------------------------------------
305 void vtkVectorsTensorsVisuBase::SetColorLaw(int colorlaw)
306 {
307         _colorlaw = colorlaw;
308 }
309
310 //------------------------------------------------------------------------------
311 void vtkVectorsTensorsVisuBase::SetColor(std::vector<double> rgb)
312 {
313         if (rgb.size()==3)
314         {
315                 _colorR=rgb[0];
316                 _colorG=rgb[1];
317                 _colorB=rgb[2];
318         } else {
319                 _colorR=1;
320                 _colorG=1;
321                 _colorB=1;
322         }
323 }
324
325 //------------------------------------------------------------------------------
326 void vtkVectorsTensorsVisuBase::SetOrientation(int orientation)
327 {
328         _orientation = orientation;
329 }
330
331 //------------------------------------------------------------------------------
332 int vtkVectorsTensorsVisuBase::GetOrientation()
333 {
334         return _orientation;
335 }
336
337 //------------------------------------------------------------------------------
338 void vtkVectorsTensorsVisuBase::SetExternalLut(vtkScalarsToColors* lut)
339 {
340         _externalLut=lut;
341 }
342