]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuImageActor.cxx
#3196 creaMaracasVisu Feature New Normal - update ImageActor
[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                 if(img != NULL)
52                 {
53                         if (bbGetInputLookupTable()==NULL)
54                         {
55                                 imageactor->SetInput( img );    
56                         } else {
57 /*
58                                 vtkLookupTable *table = vtkLookupTable::New();
59                                 table->SetRange(0, 1000); // image intensity range
60                                 table->SetValueRange(0.0, 1.0); // from black to white
61                                 table->SetSaturationRange(0.0, 0.0); // no color saturation
62                                 table->SetRampToLinear();
63                                 table->Build();
64   double rgba[4];
65   table->GetTableValue(0,rgba);
66   rgba[3]=0;
67   table->SetTableValue(0,rgba);
68 */
69
70
71 /*
72         vtkLookupTable *table = vtkLookupTable::New();
73            table->SetTableRange (0, 2000);
74            table->SetHueRange (1, 0);
75            table->SetSaturationRange (1, 1);
76            table->SetValueRange (1, 1);
77            table->Build(); //effective built
78 */
79
80 /*
81 vtkColorTransferFunction *table = vtkColorTransferFunction::New();
82 table->SetColorSpaceToHSV();
83     table->HSVWrapOff();
84     table->AddHSVSegment(0.0, 0.6, 1.0, 1.0,
85                        1.0, 0.0, 1.0, 1.0);
86     table->SetNanColor(1.0, 0.0, 1.0);
87 */
88
89 /* 
90 printf("EED ImageActor::Process  Warnning ***************************Not here this code *");
91 vtkLookupTable *table = vtkLookupTable::New();
92   table->SetNumberOfTableValues(1000);
93   table->SetRange(0, 1000);
94   table->Build();
95   double rgba1[4];
96         double rgba2[4];
97         for (int iLookTable = 0; iLookTable<500; iLookTable++)
98                         {
99                                 table->GetTableValue(      iLookTable, rgba1);
100                                 table->GetTableValue(1000-1-iLookTable, rgba2);
101                                 table->SetTableValue(1000-1-iLookTable , rgba1[0],rgba1[1],rgba1[2],rgba1[3]);
102                                 table->SetTableValue(      iLookTable , rgba2[0],rgba2[1],rgba2[2],rgba2[3]);
103                         } // for iLookTable     
104   double rgba[4];
105   table->GetTableValue(0,rgba);
106   rgba[3]=0;
107   table->SetTableValue(0,rgba);
108 */
109                                 vtkImageMapToColors *color = vtkImageMapToColors::New();
110                                 color->SetLookupTable( bbGetInputLookupTable() );
111 //                              color->SetLookupTable( table );
112                                 color->PassAlphaToOutputOn();
113
114 //                              imageshiftscale->SetInput( img );
115 //                              imageshiftscale->SetOutputScalarTypeToUnsignedChar();
116
117 //                              color->SetInput( imageshiftscale->GetOutput() );
118                                 color->SetInput( img );
119                                 color->Update();
120                                 imageactor->GetMapper()->SetInput( color->GetOutput() );
121                                 imageactor->GetProperty()->SetInterpolationTypeToNearest();
122                         }
123
124                         if (transform!=NULL)
125                         {
126                           imageactor->SetUserTransform( transform );    
127                         } // transform
128                         if(render != NULL )
129                         {
130 //                              render->AddActor( imageactor );
131                         } // render
132                         bbSetOutputOut(imageactor);
133                 } // img
134                         
135                         
136                 // Interface Update
137                 if ((firsttime==true) && (bbGetInputRenderer()!=NULL ))
138                 {
139                                 firsttime=false;
140                                 bbGetInputRenderer()->AddActor( imageactor );
141                 }
142                 
143                 imageactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
144                 bbSetOutputOut(imageactor);
145
146
147 printf("EED ImageActor::Process End\n");
148
149         
150 }
151 void ImageActor::bbUserSetDefaultValues()
152 {
153     firsttime   = true;
154     imageactor  = NULL;
155     bbSetInputIn(NULL);
156 //    bbSetInputType(0);
157     bbSetInputOpacity(1);
158     bbSetInputTransform(NULL);
159     bbSetInputRenderer(NULL);
160     bbSetInputLookupTable(NULL);
161 }
162
163         
164         //-----------------------------------------------------------------     
165         void ImageActor::bbUserInitializeProcessing()
166         {
167                 imageactor              = vtkImageActor::New();
168                 imageshiftscale = vtkImageShiftScale::New();
169         }
170         
171         //-----------------------------------------------------------------     
172         void ImageActor::bbUserFinalizeProcessing()
173         {
174         }
175         
176         //-----------------------------------------------------------------     
177 }
178 // EO namespace bbcreaMaracasVisu
179
180