1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "vtkImageViewer2_XYZ.h"
27 #include "vtkRenderer.h"
28 #include "vtkImageActor.h"
29 #include "vtkImageData.h"
33 #include "vtkLookupTable.h"
34 #include "vtkObjectFactory.h"
36 class /*VTK_COMMON_EXPORT*/ vtkLookupTableDirectionVector2 : public vtkScalarsToColors
40 // Construct with range=[0,1]; and hsv ranges set up for rainbow color table
41 // (from red to blue).
42 static vtkLookupTableDirectionVector2 *New();
44 vtkTypeMacro(vtkLookupTableDirectionVector2,vtkScalarsToColors);
45 void PrintSelf(ostream& os, vtkIndent indent);
47 double *GetRange() { return this->GetTableRange(); };
48 void SetRange(double min, double max) { this->SetTableRange(min, max); };
49 void SetRange(double rng[2]) { this->SetRange(rng[0], rng[1]); };
51 void SetTableRange(double r[2]);
52 virtual void SetTableRange(double min, double max);
53 vtkGetVectorMacro(TableRange,double,2);
55 unsigned char *MapValue(double v);
57 void GetColor(double x, double rgb[3]);
60 void MapScalarsThroughTable2(void *input, unsigned char *output,
61 int inputDataType, int numberOfValues,
62 int inputIncrement, int outputIncrement);
66 vtkLookupTableDirectionVector2(int sze=256, int ext=256);
67 ~vtkLookupTableDirectionVector2();
70 vtkLookupTableDirectionVector2(const vtkLookupTableDirectionVector2&); // Not implemented.
71 void operator=(const vtkLookupTableDirectionVector2&); // Not implemented.
77 vtkStandardNewMacro(vtkLookupTableDirectionVector2);
79 // Construct with range=(0,1); and hsv ranges set up for rainbow color table
80 // (from red to blue).
81 vtkLookupTableDirectionVector2::vtkLookupTableDirectionVector2(int sze, int ext)
83 this->TableRange[0] = 0.0;
84 this->TableRange[1] = 1.0;
87 //----------------------------------------------------------------------------
88 vtkLookupTableDirectionVector2::~vtkLookupTableDirectionVector2()
92 unsigned char *vtkLookupTableDirectionVector2::MapValue(double v)
95 //int idx = this->GetIndex(v);
96 //return (this->Table->GetPointer(0) + 4*idx);
100 void vtkLookupTableDirectionVector2::GetColor(double v, double rgb[3])
102 // unsigned char *rgb8 = this->MapValue(v);
103 // rgb[0] = rgb8[0]/255.0;
104 // rgb[1] = rgb8[1]/255.0;
105 // rgb[2] = rgb8[2]/255.0;
113 void vtkLookupTableDirectionVector2::SetTableRange(double r[2])
115 this->SetTableRange(r[0],r[1]);
118 //----------------------------------------------------------------------------
119 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
120 // less than minimum range value are clamped to minimum range value.
121 // Scalar values greater than maximum range value are clamped to maximum
123 void vtkLookupTableDirectionVector2::SetTableRange(double rmin, double rmax)
127 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
131 if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
136 this->TableRange[0] = rmin;
137 this->TableRange[1] = rmax;
144 //----------------------------------------------------------------------------
145 // Although this is a relatively expensive calculation,
146 // it is only done on the first render. Colors are cached
147 // for subsequent renders.
149 void vtkLookupTableMapDirVectorEED2(vtkLookupTableDirectionVector2 *self, T *input,
150 unsigned char *output, int length,
151 int inIncr, int outFormat)
154 for (i = 0; i < length; ++i)
156 *output++ = static_cast<T>(input[0]); // red
157 *output++ = static_cast<T>(input[1]); // green
158 *output++ = static_cast<T>(input[2]); // blue
160 input = input+inIncr;
166 //----------------------------------------------------------------------------
167 void vtkLookupTableDirectionVector2::MapScalarsThroughTable2(void *input,
168 unsigned char *output,
174 // if (this->UseMagnitude && inputIncrement > 1)
176 switch (inputDataType)
178 vtkTemplateMacro( vtkLookupTableMapDirVectorEED2(this,static_cast<VTK_TT*>(input),output,
179 numberOfValues,inputIncrement,outputFormat);
183 vtkErrorMacro("Cannot comput magnitude of bit array.");
186 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
192 //----------------------------------------------------------------------------
193 void vtkLookupTableDirectionVector2::PrintSelf(ostream& os, vtkIndent indent)
195 this->Superclass::PrintSelf(os,indent);
201 //-------------------------------------------------------------------
202 //-------------------------------------------------------------------
203 //-------------------------------------------------------------------
204 vtkImageViewer2_XYZ::vtkImageViewer2_XYZ()
206 _vtkimageviewer2 = vtkImageViewer2::New();
207 _vtkimageviewer2->GetRenderer()->GradientBackgroundOn();
208 _vtkimageviewer2->GetRenderer()->SetBackground( 0.33 , 0.33 , 0.33 );
209 _vtkimageviewer2->GetRenderer()->SetBackground2( 0.66 , 0.66 , 0.66 );
212 //-------------------------------------------------------------------
213 vtkImageViewer2_XYZ::~vtkImageViewer2_XYZ()
215 //_vtkimageviewer2->Delete();
217 //-------------------------------------------------------------------
218 void vtkImageViewer2_XYZ::SetExtentDimension(int x1,int x2,
230 //-------------------------------------------------------------------
231 void vtkImageViewer2_XYZ::SetXSlice(int slice)
233 vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
234 imageActor->SetDisplayExtent(slice, slice, _y1, _y2, _z1, _z2 );
237 //-------------------------------------------------------------------
238 void vtkImageViewer2_XYZ::SetYSlice(int slice)
240 vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
241 imageActor->SetDisplayExtent(_x1, _x2, slice, slice, _z1, _z2 );
244 //-------------------------------------------------------------------
245 void vtkImageViewer2_XYZ::SetZSlice(int slice)
247 #if (VTK_MAJOR_VERSION >= 5)
248 // _vtkimageviewer2->SetSlice( slice );
249 vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
250 imageActor->SetDisplayExtent(_x1, _x2, _y1, _y2, slice, slice );
252 _vtkimageviewer2->SetZSlice( slice );
255 //-------------------------------------------------------------------
256 int vtkImageViewer2_XYZ::GetXSlice()
258 vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
259 return imageActor->GetDisplayExtent()[0];
262 //-------------------------------------------------------------------
263 int vtkImageViewer2_XYZ::GetYSlice()
265 vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
266 return imageActor->GetDisplayExtent()[2];
269 //-------------------------------------------------------------------
270 int vtkImageViewer2_XYZ::GetZSlice()
273 #if (VTK_MAJOR_VERSION >= 5)
274 result= _vtkimageviewer2->GetSlice( );
276 result= _vtkimageviewer2->GetZSlice( );
281 //-------------------------------------------------------------------
282 vtkImageViewer2 *vtkImageViewer2_XYZ::GetVtkImageViewer2()
284 return _vtkimageviewer2;
287 //-------------------------------------------------------------------
288 void vtkImageViewer2_XYZ::setColorTransferFunction(vtkColorTransferFunction* colortable)
290 if(colortable!=NULL && colortable->GetSize()>0 && _colortable!=colortable)
292 _colortable = colortable;
293 vtkImageMapToWindowLevelColors* imagemaptowindowlevel = _vtkimageviewer2->GetWindowLevel();
294 imagemaptowindowlevel->SetLookupTable(_colortable);
298 //-------------------------------------------------------------------
299 void vtkImageViewer2_XYZ::setScalarsToColors(vtkScalarsToColors* colortable, int outputformat)
301 /* outputformat VTK-8.1.1/Common/Core/vtkSystemIncludes.h
303 VTK_LUMINANCE_ALPHA 2
307 if( _colortable!=colortable)
309 _colortable = colortable;
310 _vtkimageviewer2->GetWindowLevel()->SetOutputFormat( outputformat );
311 _vtkimageviewer2->GetWindowLevel()->SetLookupTable(colortable);
312 // _vtkimageviewer2->GetWindowLevel()->SetOutputFormatToRGB();
313 // vtkLookupTableDirectionVector2 *_LutEED = vtkLookupTableDirectionVector2::New();
314 // _LutEED->SetVectorModeToRGBColors();
315 // _vtkimageviewer2->GetWindowLevel()->SetLookupTable(_LutEED);