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