]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuImageActor.cxx
3219 creaMaracasVisu Feature New Normal - vtk8itk4wx3-mingw64
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuImageActor.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "bbmaracasvisuImageActor.h"
27 #include "bbcreaMaracasVisuPackage.h"
28
29 #include "vtkImageShiftScale.h" 
30 #include <vtkLookupTable.h>
31 #include <vtkColorTransferFunction.h>
32 #include <vtkImageMapToColors.h>
33 #include <vtkImageMapper3D.h>
34 #include <vtkImageProperty.h>
35
36 namespace bbcreaMaracasVisu
37 {
38
39 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ImageActor)
40 BBTK_BLACK_BOX_IMPLEMENTATION(ImageActor,bbtk::AtomicBlackBox);
41 void ImageActor::Process()
42 {
43
44 printf("EED ImageActor::Process Start\n");
45
46                 //JCP 04/04/09
47                 vtkRenderer *render                             = bbGetInputRenderer();
48                 vtkImageData *img                               = bbGetInputIn();
49                 vtkLinearTransform* transform   = bbGetInputTransform();
50                                 
51                                 
52         if(img != NULL)
53                 {
54                         if (bbGetInputLookupTable()==NULL)
55                         {
56 //EED 2017-01-01 Migration VTK7
57 #if VTK_MAJOR_VERSION <= 5
58                                 imageactor->SetInput( img );    
59 #else
60                                 imageactor->SetInputData( img );        
61 #endif
62                         } else {
63 /*
64                                 vtkLookupTable *table = vtkLookupTable::New();
65                                 table->SetRange(0, 1000); // image intensity range
66                                 table->SetValueRange(0.0, 1.0); // from black to white
67                                 table->SetSaturationRange(0.0, 0.0); // no color saturation
68                                 table->SetRampToLinear();
69                                 table->Build();
70   double rgba[4];
71   table->GetTableValue(0,rgba);
72   rgba[3]=0;
73   table->SetTableValue(0,rgba);
74 */
75
76
77 /*
78         vtkLookupTable *table = vtkLookupTable::New();
79            table->SetTableRange (0, 2000);
80            table->SetHueRange (1, 0);
81            table->SetSaturationRange (1, 1);
82            table->SetValueRange (1, 1);
83            table->Build(); //effective built
84 */
85
86 /*
87 vtkColorTransferFunction *table = vtkColorTransferFunction::New();
88 table->SetColorSpaceToHSV();
89     table->HSVWrapOff();
90     table->AddHSVSegment(0.0, 0.6, 1.0, 1.0,
91                        1.0, 0.0, 1.0, 1.0);
92     table->SetNanColor(1.0, 0.0, 1.0);
93 */
94
95 /* 
96 printf("EED ImageActor::Process  Warnning ***************************Not here this code *");
97 vtkLookupTable *table = vtkLookupTable::New();
98   table->SetNumberOfTableValues(1000);
99   table->SetRange(0, 1000);
100   table->Build();
101   double rgba1[4];
102         double rgba2[4];
103         for (int iLookTable = 0; iLookTable<500; iLookTable++)
104                         {
105                                 table->GetTableValue(      iLookTable, rgba1);
106                                 table->GetTableValue(1000-1-iLookTable, rgba2);
107                                 table->SetTableValue(1000-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
108                                 table->SetTableValue(      iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
109                         } // for iLookTable     
110   double rgba[4];
111   table->GetTableValue(0,rgba);
112   rgba[3]=0;
113   table->SetTableValue(0,rgba);
114 */
115                                 vtkImageMapToColors *color = vtkImageMapToColors::New();
116                                 color->SetLookupTable( bbGetInputLookupTable() );
117 //                              color->SetLookupTable( table );
118                                 color->PassAlphaToOutputOn();
119
120 //                              imageshiftscale->SetInput( img );
121 //                              imageshiftscale->SetOutputScalarTypeToUnsignedChar();
122
123 //                              color->SetInput( imageshiftscale->GetOutput() );
124
125
126 //EED 2017-01-01 Migration VTK7
127 #if VTK_MAJOR_VERSION <= 5
128                                 color->SetInput( img );
129                                 color->Update();
130                                 imageactor->GetMapper()->SetInput( color->GetOutput() );
131 #else
132                                 color->SetInputData( img );
133                                 imageactor->GetMapper()->SetInputData( color->GetOutput() );
134 #endif
135                                 imageactor->GetProperty()->SetInterpolationTypeToNearest();
136                         }
137
138                         if (transform!=NULL)
139                         {
140                           imageactor->SetUserTransform( transform );    
141                         } // transform
142                         if(render != NULL )
143                         {
144 //                              render->AddActor( imageactor );
145                         } // render
146                         bbSetOutputOut(imageactor);
147                 } // img
148                         
149                         
150                 // Interface Update
151                 if ((firsttime==true) && (bbGetInputRenderer()!=NULL ))
152                 {
153                                 firsttime=false;
154                                 bbGetInputRenderer()->AddActor( imageactor );
155                 }
156                 
157                 imageactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
158                 bbSetOutputOut(imageactor);
159
160
161 printf("EED ImageActor::Process End\n");
162
163         
164 }
165 void ImageActor::bbUserSetDefaultValues()
166 {
167     firsttime   = true;
168     imageactor  = NULL;
169     bbSetInputIn(NULL);
170 //    bbSetInputType(0);
171     bbSetInputOpacity(1);
172     bbSetInputTransform(NULL);
173     bbSetInputRenderer(NULL);
174     bbSetInputLookupTable(NULL);
175 }
176
177         
178         //-----------------------------------------------------------------     
179         void ImageActor::bbUserInitializeProcessing()
180         {
181                 imageactor              = vtkImageActor::New();
182                 imageshiftscale = vtkImageShiftScale::New();
183         }
184         
185         //-----------------------------------------------------------------     
186         void ImageActor::bbUserFinalizeProcessing()
187         {
188         }
189         
190         //-----------------------------------------------------------------     
191 }
192 // EO namespace bbcreaMaracasVisu
193
194