]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkVectorsTensorsVisuBase.cpp
2387 creaVtk Feature New Normal New box, lib, script ImageDataStructuredPoints
[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         printf("EED length %d  %p\n", length,input);
122 //      mag = new double[length];
123         for (i = 0; i < length; ++i)
124     {
125                 dirx    = 0;
126                 diry    = 0;
127                 dirz    = 0;
128                 sum             = 0;
129                 for (j = 0; j < inIncr; ++j)
130                 {
131                         if (j==0) dirx= static_cast<double>(*input);  
132                         if (j==1) diry= static_cast<double>(*input);  
133                         if (j==2) dirz= static_cast<double>(*input);  
134                         tmp = static_cast<double>(*input);  
135                         sum += (tmp * tmp);
136                         ++input;
137                 }
138                 sum=sqrt(sum);
139                 *output++ = (unsigned char) abs( (255*dirx/sum) );
140                 *output++ = (unsigned char) abs( (255*diry/sum) );
141                 *output++ = (unsigned char) abs( (255*dirz/sum) );
142                 *output++ = 255;
143 //              printf("%d %d %d   ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
144     }
145         
146 //      vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
147         
148 //      delete [] mag;
149 }
150
151
152
153 //----------------------------------------------------------------------------
154 void vtkLookupTableDirectionVector::MapScalarsThroughTable2(void *input, 
155                                              unsigned char *output,
156                                              int inputDataType, 
157                                              int numberOfValues,
158                                              int inputIncrement,
159                                              int outputFormat)
160 {
161   printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d   inputDataType=%d\n",inputIncrement,inputDataType);
162 // if (this->UseMagnitude && inputIncrement > 1)
163 // {
164      switch (inputDataType)
165      {
166        vtkTemplateMacro( vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
167                          numberOfValues,inputIncrement,outputFormat);
168                          return 
169                         );
170         case VTK_BIT:
171             vtkErrorMacro("Cannot comput magnitude of bit array.");
172             break;
173         default:
174             vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
175      } /// switch
176 // } //if
177 }  
178
179
180 //----------------------------------------------------------------------------
181 void vtkLookupTableDirectionVector::PrintSelf(ostream& os, vtkIndent indent)
182 {
183         this->Superclass::PrintSelf(os,indent); 
184 }
185
186
187
188
189 //----------------------------------
190 //----------------------------------
191 //----------------------------------
192 //----------------------------------
193 //----------------------------------
194
195
196
197
198
199
200
201
202 vtkVectorsTensorsVisuBase::vtkVectorsTensorsVisuBase()
203 {
204         _firsttime      = true;
205         _active         = false;
206         _scalefactor    = 1;
207         _opacity        = 1;
208         _dataobject     = NULL;
209         _renderer       = NULL;
210         _typeForm       = 0;
211
212         _LutEED         = vtkLookupTableDirectionVector::New();
213 //      _LutEED->SetVectorMode(0);
214 //_LutEED->SetVectorModeToMagnitude();
215 //_LutEED->SetVectorModeToComponent();
216 _LutEED->SetVectorModeToRGBColors();
217
218
219
220         _pdm            = vtkPolyDataMapper::New();
221         _actor          = vtkActor::New();
222         _actorAdded     = false;
223 }
224
225 vtkVectorsTensorsVisuBase::~vtkVectorsTensorsVisuBase()
226 {
227 }
228
229 //------------------------------------------------------------------------
230 void vtkVectorsTensorsVisuBase::SetDataObject(vtkDataObject *dataobject)
231 {
232         _dataobject = dataobject;
233 }
234
235 //------------------------------------------------------------------------
236 vtkDataObject* vtkVectorsTensorsVisuBase::GetDataObject()
237 {
238         return _dataobject;
239 }
240
241 //------------------------------------------------------------------------
242 void vtkVectorsTensorsVisuBase::SetRenderer(vtkRenderer *renderer)
243 {
244         _renderer=renderer;
245 }
246
247 //------------------------------------------------------------------------
248 vtkRenderer* vtkVectorsTensorsVisuBase::GetRenderer()
249 {
250         return _renderer;
251 }
252
253 //------------------------------------------------------------------------
254 void vtkVectorsTensorsVisuBase::SetScaleFactor(double scalefactor)
255 {
256         _scalefactor=scalefactor;
257 }
258
259 //------------------------------------------------------------------------
260 double vtkVectorsTensorsVisuBase::GetScaleFactor()
261 {
262         return _scalefactor;
263 }
264
265 //------------------------------------------------------------------------
266 void vtkVectorsTensorsVisuBase::SetActive(bool active)
267 {
268    _active = active;
269 }
270
271 //------------------------------------------------------------------------
272 bool vtkVectorsTensorsVisuBase::GetActive()
273 {
274    return _active;
275 }
276
277 //------------------------------------------------------------------------
278 void vtkVectorsTensorsVisuBase::SetOpacity(double opacity)
279 {
280    _opacity = opacity;
281 }
282
283 //------------------------------------------------------------------------
284 double vtkVectorsTensorsVisuBase::GetOpacity()
285 {
286    return _opacity;
287 }
288
289
290
291 //------------------------------------------------------------------------
292 vtkProp3D* vtkVectorsTensorsVisuBase::GetProp3D()
293 {
294    return _actor;
295 }
296
297 //------------------------------------------------------------------------
298 void vtkVectorsTensorsVisuBase::SetTypeForm(int typeForm)
299 {
300      _typeForm=typeForm;
301 }
302
303
304 //------------------------------------------------------------------------
305 int vtkVectorsTensorsVisuBase::GetTypeForm()
306 {
307         return _typeForm;
308 }
309
310 //------------------------------------------------------------------------
311 void vtkVectorsTensorsVisuBase::Process()    // virtual
312 {
313 }
314
315
316
317 //------------------------------------------------------------------------------
318 void vtkVectorsTensorsVisuBase::VisibilityActor()
319 {
320
321         if ( (_active==true) && (_actorAdded==false) ){
322                 if (GetRenderer()!=NULL)
323                 {
324                    GetRenderer()->AddActor(_actor);
325                    _actorAdded=true;
326                  } // if Renderer
327         } // if _active==true 
328
329         if ( (_active==false) && (_actorAdded==true) ){
330                 if (GetRenderer()!=NULL)
331                 {
332                    GetRenderer()->RemoveActor(_actor);
333                    _actorAdded=false;
334                  } // if Renderer
335         } // if _active==false  
336 }
337
338
339
340