]> Creatis software - creaMaracasVisu.git/blob - lib/GUI/Base/VolumeRenderer/volumerendererdata.cxx
#3138 creaMaracasVisu Feature New Normal - branch vtk7itk4wx3
[creaMaracasVisu.git] / lib / GUI / Base / VolumeRenderer / volumerendererdata.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 "volumerendererdata.h"
27 #include "vtkObjectFactory.h"
28
29
30 //EED 2017-01-01 Migration VTK7
31 #if VTK_MAJOR_VERSION <= 5
32 vtkCxxRevisionMacro(VolumeRendererData, "$Revision: 1.11 $");
33 #else
34   //...
35 #endif
36
37 vtkStandardNewMacro(VolumeRendererData);
38
39 VolumeRendererData::VolumeRendererData()
40 {
41     VolRendManager      = NULL;
42     ImageData           = NULL;
43     Renderer            = NULL;
44     Interactor          = NULL;
45     LookUpTable         = NULL;
46     //ImageDataSeparateComponents = false;
47 }
48
49
50 void VolumeRendererData::ShowVolume(bool checked){
51     try{
52         if(checked){
53                 invariant();
54                 if(!VolRendManager){
55                     VolRendManager = new VolumeRendererManager();
56                     VolRendManager->addVolume(ImageData, Interactor);
57                 }
58                 if(LookUpTable)
59                                 {
60                     VolRendManager->SetLookupTable(LookUpTable);
61                                 }
62                 vector< vtkProp3D* > props = VolRendManager->getProps3D();
63                 for(unsigned i = 0; i < props.size(); i++){
64                     Renderer->AddActor(props[i]);
65                 }
66
67         }else{
68             vector< vtkProp3D* > props = VolRendManager->getProps3D();
69             for(unsigned i = 0; i < props.size(); i++){
70                 Renderer->RemoveActor(props[i]);
71             }
72             delete VolRendManager;
73             VolRendManager = 0;
74         }
75     }catch(char* e){
76         cout<<"Exception in: "<<e<<endl;
77     }catch(exception e){
78         cout<<"Exception in: "<<e.what()<<endl;
79     }
80
81 }
82
83 void VolumeRendererData::invariant()
84 {
85     if(!ImageData)
86         {
87         throw "Image data not set";
88     }
89     if(!Renderer)
90         {
91         throw "renderer not initialized";
92     }
93 }
94
95 void VolumeRendererData::OpacityChanged(vector<double> greyvalues, vector<double> values)
96 {
97     //invariant();
98     if(VolRendManager!=NULL)
99         {
100         ShowVolume(true);
101                 VolRendManager->setVolumeOpacity(greyvalues,values);
102         }       
103 }
104
105
106 void  VolumeRendererData::BoundingBoxChanged(bool checked){
107    // invariant();
108
109     if(VolRendManager==NULL)
110     {
111          ShowVolume(true);
112     }
113
114
115     if(VolRendManager && Interactor){
116         if(checked){
117             VolRendManager->EnableBoundingBox(Interactor);
118         }else{
119             VolRendManager->DisableBoundingBox();
120         }
121     }
122         
123 }
124
125
126 void VolumeRendererData::changeCompositeMIPFunction(int function){
127     invariant();
128     if(VolRendManager)
129         {
130         VolRendManager->changeCompositeMIPFunction(0, function);
131         }
132 }
133
134 /**
135   changes the interoplation type of the volume
136   type = 0 linear
137   type = 1 nearest
138    */
139 void VolumeRendererData::changeInterpolationType(int type){
140     invariant();
141     if(VolRendManager)
142         {
143         VolRendManager->changeInterpolationType(type);
144         }       
145 }