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