]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkVectorsTensorsVisuBase.cpp
#3100 creaVtk Feature New Normal - Vectors Visu refresh
[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 //      double *mag;
109         int i, j;
110         double dirx,diry,dirz;
111         double angle;
112
113         printf("EED vtkLookupTableMapDirVectorEED inIncr=%d  \n", inIncr);
114
115
116 //      mag = new double[length];
117         for (i = 0; i < length; ++i)
118     {
119
120
121         if (1==1){
122                         dirx    = static_cast<T>(input[0]);
123                         diry    = static_cast<T>(input[1]);
124                         dirz    = static_cast<T>(input[2]);
125                         input   = input+inIncr;
126                         sum             = sqrt( dirx*dirx + diry*diry + dirz*dirz );
127
128         /*
129                         dirx    = 0;
130                         diry    = 0;
131                         dirz    = 0;
132                         sum             = 0;
133                         for (j = 0; j < inIncr; ++j)
134                         {
135                                 if (j==0) dirx= static_cast<T>(*input);  
136                                 if (j==1) diry= static_cast<T>(*input);  
137                                 if (j==2) dirz= static_cast<T>(*input);  
138                                 tmp = static_cast<T>(*input);  
139                                 sum += (tmp * tmp);
140                                 ++input;
141                         }
142                         sum=sqrt(sum);
143         */
144
145                         *output++ = (unsigned char) abs( (255*dirx/sum) );
146                         *output++ = (unsigned char) abs( (255*diry/sum) );
147                         *output++ = (unsigned char) abs( (255*dirz/sum) );
148                         *output++ = 255;
149         //              printf("%d %d %d   ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
150         //              printf(" C     %d        %f %f %f   \n",inIncr,dirx,diry,dirz);
151
152                 } // type 1 color vector by direction
153
154
155                 if (2==0){
156                                 angle   = static_cast<T>(input[0]);
157                                 input   = input+inIncr;
158
159                                 *output++ = (unsigned char) abs( 255*angle/90 );
160                                 *output++ = (unsigned char) abs( 0 );
161                                 *output++ = (unsigned char) abs( 0 );
162                                 *output++ = 255;
163                 //              printf("%d %d %d   ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
164                 //              printf(" C     %d        %f %f %f   \n",inIncr,dirx,diry,dirz);
165
166                 }// type 2 color vector by scalar
167         
168
169         } // for
170
171 //      vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
172         
173 //      delete [] mag;
174
175
176 }
177
178
179 //----------------------------------------------------------------------------
180 void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input, 
181                                              unsigned char *output,
182                                              int inputDataType, 
183                                              int numberOfValues,
184                                              int inputIncrement,
185                                              int outputFormat)
186 {
187   printf("vtkLookupTableEED::MapScalarsThroughTable2 \n");
188 // if (this->UseMagnitude && inputIncrement > 1)
189 // {
190      switch (inputDataType)
191      {
192        vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
193                          numberOfValues,inputIncrement,outputFormat);
194                          return 
195                         );
196         case VTK_BIT:
197             vtkErrorMacro("Cannot comput magnitude of bit array.");
198             break;
199         default:
200             vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
201      } /// switch
202 // } //if
203 }  
204
205
206 //----------------------------------------------------------------------------
207 void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent)
208 {
209         this->Superclass::PrintSelf(os,indent); 
210 }
211
212
213
214
215 //----------------------------------
216 //----------------------------------
217 //----------------------------------
218 //----------------------------------
219 //----------------------------------
220
221 vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase()
222 {
223      _firsttime         = true;
224         _active                 = false;
225         _scalefactor    = 1;
226         _opacity                = 1;
227         _dataobject             = NULL;
228         _renderer               = NULL;
229         _typeForm               = 0;
230         _orientation    = 0;
231
232         _LutEED                 = vtkLookupTableDirectionVector::New();
233         _externalLut    = NULL;
234         //_LutEED->SetVectorMode(0);
235         //_LutEED->SetVectorModeToMagnitude();
236         //_LutEED->SetVectorModeToComponent();
237         _LutEED->SetVectorModeToRGBColors();
238
239         _pdm                    = vtkPolyDataMapper::New();
240         _actor                  = vtkActor::New();
241         _actorAdded             = false;
242 }
243
244 vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase()
245 {
246 }
247
248 //------------------------------------------------------------------------
249 void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject)
250 {
251         _dataobject = dataobject;
252 }
253
254 //------------------------------------------------------------------------
255 vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject()
256 {
257         return _dataobject;
258 }
259
260 //------------------------------------------------------------------------
261 void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer)
262 {
263         _renderer=renderer;
264 }
265
266 //------------------------------------------------------------------------
267 vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer()
268 {
269         return _renderer;
270 }
271
272 //------------------------------------------------------------------------
273 void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor)
274 {
275         _scalefactor=scalefactor;
276 }
277
278 //------------------------------------------------------------------------
279 double vtkVectorsTensorsVisuBase::GetScaleFactor()
280 {
281         return _scalefactor;
282 }
283
284 //------------------------------------------------------------------------
285 void vtkVectorsTensorsVisuBase::SetActive(bool active)
286 {
287    _active = active;
288 }
289
290 //------------------------------------------------------------------------
291 bool vtkVectorsTensorsVisuBase::GetActive()
292 {
293    return _active;
294 }
295
296 //------------------------------------------------------------------------
297 void vtkVectorsTensorsVisuBase::SetOpacity(double opacity)
298 {
299    _opacity = opacity;
300 }
301
302 //------------------------------------------------------------------------
303 double vtkVectorsTensorsVisuBase::GetOpacity()
304 {
305    return _opacity;
306 }
307
308
309
310 //------------------------------------------------------------------------
311 vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D()
312 {
313    return _actor;
314 }
315
316 //------------------------------------------------------------------------
317 void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm)
318 {
319      _typeForm=typeForm;
320 }
321
322
323 //------------------------------------------------------------------------
324 int vtkVectorsTensorsVisuBase::GetTypeForm()
325 {
326         return _typeForm;
327 }
328
329 //------------------------------------------------------------------------
330 void vtkVectorsTensorsVisuBase::Process()    // virtual
331 {
332 }
333
334 //------------------------------------------------------------------------------
335 void vtkVectorsTensorsVisuBase::VisibilityActor()
336 {
337
338         if ( (_active==true) && (_actorAdded==false) ){
339                 if (GetRenderer()!=NULL)
340                 {
341               GetRenderer()->AddActor(_actor);
342                    _actorAdded=true;
343        } // if Renderer
344         } // if _active==true 
345
346         if ( (_active==false) && (_actorAdded==true) ){
347                 if (GetRenderer()!=NULL)
348                 {
349               GetRenderer()->RemoveActor(_actor);
350                    _actorAdded=false;
351       } // if Renderer
352         } // if _active==false  
353 }
354
355 //------------------------------------------------------------------------------
356 void vtkVectorsTensorsVisuBase::SetColorLaw(int colorlaw)
357 {
358         _colorlaw = colorlaw;
359 }
360
361 //------------------------------------------------------------------------------
362 void vtkVectorsTensorsVisuBase::SetColor(std::vector<double> rgb)
363 {
364         if (rgb.size()==3)
365         {
366                 _colorR=rgb[0];
367                 _colorG=rgb[1];
368                 _colorB=rgb[2];
369         } else {
370                 _colorR=1;
371                 _colorG=1;
372                 _colorB=1;
373         }
374 }
375
376 //------------------------------------------------------------------------------
377 void vtkVectorsTensorsVisuBase::SetOrientation(int orientation)
378 {
379         _orientation = orientation;
380 }
381
382 //------------------------------------------------------------------------------
383 int vtkVectorsTensorsVisuBase::GetOrientation()
384 {
385         return _orientation;
386 }
387
388 //------------------------------------------------------------------------------
389 void vtkVectorsTensorsVisuBase::SetExternalLut(vtkScalarsToColors* lut)
390 {
391 printf("EED vtkVectorsTensorsVisuBase::SetExternalLut C ptrlut %p  this:%p\n",lut, this);
392         _externalLut=lut;
393 printf("EED vtkVectorsTensorsVisuBase::SetExternalLut D ptrlut %p \n",_externalLut);
394 }
395