]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuImageActor.cxx
8dd6e609521117740806491c8b5dec91eb50d21b
[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                 vtkImageData *img                               = bbGetInputIn();
45                 vtkLinearTransform* transform   = bbGetInputTransform();
46                                 
47                                 
48         if(img != NULL)
49                 {
50                         if (bbGetInputLookupTable()==NULL)
51                         {
52 //EED 2017-01-01 Migration VTK7
53 #if VTK_MAJOR_VERSION <= 5
54                                 imageactor->SetInput( img );    
55 #else
56                                 imageactor->SetInputData( img );        
57 #endif
58                         } else {
59                                 vtkImageMapToColors *color = vtkImageMapToColors::New();
60                                 color->SetLookupTable( bbGetInputLookupTable() );
61                                 color->PassAlphaToOutputOn();
62
63 //EED 2017-01-01 Migration VTK7
64 #if VTK_MAJOR_VERSION <= 5
65                                 color->SetInput( img );
66                                 color->Update();
67                                 imageactor->GetMapper()->SetInput( color->GetOutput() );
68 #else
69                                 color->SetInputData( img );
70                                 color->Update();
71                                 imageactor->GetMapper()->SetInputData( color->GetOutput() );
72 #endif
73
74                                 if ( bbGetInputInterpolationMode()==0) { imageactor->GetProperty()->SetInterpolationTypeToNearest();    }
75                                 if ( bbGetInputInterpolationMode()==1) { imageactor->GetProperty()->SetInterpolationTypeToLinear();             }
76                                 if ( bbGetInputInterpolationMode()==2) { imageactor->GetProperty()->SetInterpolationTypeToCubic();              }
77                                 imageactor->SetForceOpaque(true);
78                         }
79
80                         if (transform!=NULL)
81                         {
82                           imageactor->SetUserTransform( transform );    
83                         } // transform
84                         bbSetOutputOut(imageactor);
85                 } // img
86                                 
87                 // Interface Update
88                 if ((firsttime==true) && (bbGetInputRenderer()!=NULL ))
89                 {
90                                 firsttime=false;
91                                 bbGetInputRenderer()->AddActor( imageactor );
92                 }
93                 imageactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
94                 bbSetOutputOut(imageactor);     
95 }
96
97 void ImageActor::bbUserSetDefaultValues()
98 {
99     firsttime   = true;
100     imageactor  = NULL;
101     bbSetInputIn(NULL);
102     bbSetInputOpacity(1);
103     bbSetInputTransform(NULL);
104     bbSetInputRenderer(NULL);
105     bbSetInputLookupTable(NULL);
106     bbSetInputInterpolationMode(0);
107 }
108
109         
110         //-----------------------------------------------------------------     
111         void ImageActor::bbUserInitializeProcessing()
112         {
113                 imageactor              = vtkImageActor::New();
114                 imageshiftscale = vtkImageShiftScale::New();
115         }
116         
117         //-----------------------------------------------------------------     
118         void ImageActor::bbUserFinalizeProcessing()
119         {
120         }
121         
122         //-----------------------------------------------------------------     
123 }
124 // EO namespace bbcreaMaracasVisu
125
126