]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkVectorsTensorsVisuBase.cpp
#2446 creaVtk Feature New Normal - Stream Tracer, Stream Line (interface, widget)
[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
30
31 #include "vtkObjectFactory.h"
32
33
34
35
36 vtkStandardNewMacro(vtkLookupTableDirectionVector);
37
38 // Construct with range=(0,1); and hsv ranges set up for rainbow color table 
39 // (from red to blue).
40 vtkLookupTableDirectionVector::vtkLookupTableDirectionVector(int sze, int ext)
41 {
42         this->TableRange[0] = 0.0;
43         this->TableRange[1] = 1.0;
44 }
45
46 //----------------------------------------------------------------------------
47 vtkLookupTableDirectionVector::~vtkLookupTableDirectionVector()
48 {
49 }
50
51
52
53 unsigned char *vtkLookupTableDirectionVector::MapValue(double v)
54 {
55         
56         //int idx = this->GetIndex(v);
57         //return (this->Table->GetPointer(0) + 4*idx);
58         
59         return 0;
60 }
61
62 void vtkLookupTableDirectionVector::GetColor(double v, double rgb[3])
63 {
64 //      unsigned char *rgb8 = this->MapValue(v);
65 //      rgb[0] = rgb8[0]/255.0;
66 //      rgb[1] = rgb8[1]/255.0;
67 //      rgb[2] = rgb8[2]/255.0;
68
69         rgb[0] = 1;
70         rgb[1] = 1;
71         rgb[2] = 0;
72 }
73
74
75 void vtkLookupTableDirectionVector::SetTableRange(double r[2])
76 {
77         this->SetTableRange(r[0],r[1]);
78 }
79
80 //----------------------------------------------------------------------------
81 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
82 // less than minimum range value are clamped to minimum range value.
83 // Scalar values greater than maximum range value are clamped to maximum
84 // range value.
85 void vtkLookupTableDirectionVector::SetTableRange(double rmin, double rmax)
86 {
87         if (rmax < rmin)
88     {
89                 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
90                 return;
91     }
92         
93         if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
94     {
95                 return;
96     }
97         
98         this->TableRange[0] = rmin;
99         this->TableRange[1] = rmax;
100         
101         this->Modified();
102 }
103
104
105
106 //----------------------------------------------------------------------------
107 // Although this is a relatively expensive calculation,
108 // it is only done on the first render. Colors are cached
109 // for subsequent renders.
110 template<class T>
111 void vtkLookupTableMapDirVectorEED(vtkLookupTableDirectionVector *self, T *input, 
112                           unsigned char *output, int length, 
113                           int inIncr, int outFormat)
114 {
115         double tmp,sum;
116 //      double *mag;
117         int i, j;
118         double dirx,diry,dirz;
119         
120         
121 inIncr=3;
122         printf("EED length %d  %p\n", length,input);
123 //      mag = new double[length];
124         for (i = 0; i < length; ++i)
125     {
126                 dirx    = 0;
127                 diry    = 0;
128                 dirz    = 0;
129                 sum     = 0;
130                 for (j = 0; j < inIncr; ++j)
131                 {
132                         if (j==0) dirx= static_cast<double>(*input);  
133                         if (j==1) diry= static_cast<double>(*input);  
134                         if (j==2) dirz= static_cast<double>(*input);  
135                         tmp = static_cast<double>(*input);  
136                         sum += (tmp * tmp);
137                         ++input;
138                 }
139                 sum=sqrt(sum);
140                 *output++ = (unsigned char) abs( (255*dirx/sum) );
141                 *output++ = (unsigned char) abs( (255*diry/sum) );
142                 *output++ = (unsigned char) abs( (255*dirz/sum) );
143                 *output++ = 255;
144 //              printf("%d %d %d   ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
145 //              printf(" C     %d        %f %f %f   \n",inIncr,dirx,diry,dirz);
146     }
147         
148 //      vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
149         
150 //      delete [] mag;
151 }
152
153
154
155 //----------------------------------------------------------------------------
156 void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input, 
157                                              unsigned char *output,
158                                              int inputDataType, 
159                                              int numberOfValues,
160                                              int inputIncrement,
161                                              int outputFormat)
162 {
163   printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d   inputDataType=%d\n",inputIncrement,inputDataType);
164 // if (this->UseMagnitude && inputIncrement > 1)
165 // {
166      switch (inputDataType)
167      {
168        vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
169                          numberOfValues,inputIncrement,outputFormat);
170                          return 
171                         );
172         case VTK_BIT:
173             vtkErrorMacro("Cannot comput magnitude of bit array.");
174             break;
175         default:
176             vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
177      } /// switch
178 // } //if
179 }  
180
181
182 //----------------------------------------------------------------------------
183 void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent)
184 {
185         this->Superclass::PrintSelf(os,indent); 
186 }
187
188
189
190
191 //----------------------------------
192 //----------------------------------
193 //----------------------------------
194 //----------------------------------
195 //----------------------------------
196
197 vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase()
198 {
199       _firsttime        = true;
200         _active         = false;
201         _scalefactor= 1;
202         _opacity                = 1;
203         _dataobject     = NULL;
204         _renderer       = NULL;
205                 _typeForm       = 0;
206
207         _LutEED         = vtkLookupTableDirectionVector::New();
208 //      _LutEED->SetVectorMode(0);
209 //_LutEED->SetVectorModeToMagnitude();
210 //_LutEED->SetVectorModeToComponent();
211 _LutEED->SetVectorModeToRGBColors();
212
213         _pdm            = vtkPolyDataMapper::New();
214         _actor          = vtkActor::New();
215         _actorAdded     = false;
216 }
217
218 vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase()
219 {
220 }
221
222 //------------------------------------------------------------------------
223 void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject)
224 {
225         _dataobject = dataobject;
226 }
227
228 //------------------------------------------------------------------------
229 vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject()
230 {
231         return _dataobject;
232 }
233
234 //------------------------------------------------------------------------
235 void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer)
236 {
237         _renderer=renderer;
238 }
239
240 //------------------------------------------------------------------------
241 vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer()
242 {
243         return _renderer;
244 }
245
246 //------------------------------------------------------------------------
247 void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor)
248 {
249         _scalefactor=scalefactor;
250 }
251
252 //------------------------------------------------------------------------
253 double vtkVectorsTensorsVisuBase::GetScaleFactor()
254 {
255         return _scalefactor;
256 }
257
258 //------------------------------------------------------------------------
259 void vtkVectorsTensorsVisuBase::SetActive(bool active)
260 {
261    _active = active;
262 }
263
264 //------------------------------------------------------------------------
265 bool vtkVectorsTensorsVisuBase::GetActive()
266 {
267    return _active;
268 }
269
270 //------------------------------------------------------------------------
271 void vtkVectorsTensorsVisuBase::SetOpacity(double opacity)
272 {
273    _opacity = opacity;
274 }
275
276 //------------------------------------------------------------------------
277 double vtkVectorsTensorsVisuBase::GetOpacity()
278 {
279    return _opacity;
280 }
281
282
283
284 //------------------------------------------------------------------------
285 vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D()
286 {
287    return _actor;
288 }
289
290 //------------------------------------------------------------------------
291 void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm)
292 {
293      _typeForm=typeForm;
294 }
295
296
297 //------------------------------------------------------------------------
298 int vtkVectorsTensorsVisuBase::GetTypeForm()
299 {
300         return _typeForm;
301 }
302
303 //------------------------------------------------------------------------
304 void vtkVectorsTensorsVisuBase::Process()    // virtual
305 {
306 }
307
308
309
310 //------------------------------------------------------------------------------
311 void vtkVectorsTensorsVisuBase::VisibilityActor()
312 {
313
314         if ( (_active==true) && (_actorAdded==false) ){
315                 if (GetRenderer()!=NULL)
316                 {
317               GetRenderer()->AddActor(_actor);
318                    _actorAdded=true;
319        } // if Renderer
320         } // if _active==true 
321
322         if ( (_active==false) && (_actorAdded==true) ){
323                 if (GetRenderer()!=NULL)
324                 {
325               GetRenderer()->RemoveActor(_actor);
326                    _actorAdded=false;
327       } // if Renderer
328         } // if _active==false  
329 }
330
331
332 //------------------------------------------------------------------------------
333 void vtkVectorsTensorsVisuBase::SetColorLaw(int colorlaw)
334 {
335         _colorlaw = colorlaw;
336 }
337
338 //------------------------------------------------------------------------------
339 void vtkVectorsTensorsVisuBase::SetColor(std::vector<double> rgb)
340 {
341         if (rgb.size()==3)
342         {
343                 _colorR=rgb[0];
344                 _colorG=rgb[1];
345                 _colorB=rgb[2];
346         } else {
347                 _colorR=1;
348                 _colorG=1;
349                 _colorB=1;
350         }
351 }
352
353