]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/marImageData.cpp
3dfa8d47c5428c1b8c748984d14f587a971ddd80
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / marImageData.cpp
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 /*=========================================================================
27
28
29 =========================================================================*/
30 #include "marImageData.h"
31
32 // ----------------------------------------------------------------------------------------------
33 marImageData::marImageData(vtkImageData *imagedata)
34 {
35         _spcOriginal[0] = 1;
36         _spcOriginal[1] = 1;
37         _spcOriginal[2] = 1;
38         _voiOriginal[0] = 0;
39         _voiOriginal[1] = 0;
40         _voiOriginal[2] = 0;
41         _voiOriginal[3] = 0;
42         _voiOriginal[4] = 0;
43         _voiOriginal[5] = 0;
44         if(imagedata!=NULL){
45                 AddImageData(imagedata);
46         }
47 }
48 // ----------------------------------------------------------------------------------------------
49 marImageData::~marImageData()
50 {
51         int i,size=_imagedataLST.size();
52         for (i=0;i<size;i++)
53         {
54         //      _imagedataLST[i]->Delete();
55         }
56         _imagedataLST.clear();
57 }
58
59 // ----------------------------------------------------------------------------------------------
60 void marImageData::SetSpcOriginal(double spc[3])
61 {
62         this->_spcOriginal[0]=spc[0];
63         this->_spcOriginal[1]=spc[1];
64         this->_spcOriginal[2]=spc[2];
65 }
66 // ----------------------------------------------------------------------------------------------
67 void marImageData::SetVoiOriginal(int voi[6])
68 {
69         int i;
70         for (i=0;i<6;i++)
71         {
72                 this->_voiOriginal[i] = voi[i];
73         }
74 }
75 // ----------------------------------------------------------------------------------------------
76 void marImageData::AddImageData(vtkImageData *imagedata)
77 {
78         if (imagedata!=NULL){
79                 _imagedataLST.push_back( imagedata );
80         }
81 }
82 // ----------------------------------------------------------------------------------------------
83 void marImageData::GetSpcOriginal(double spc[3])
84 {
85         spc[0] = this->_spcOriginal[0];
86         spc[1] = this->_spcOriginal[1];
87         spc[2] = this->_spcOriginal[2];
88 }
89 // ----------------------------------------------------------------------------------------------
90 void marImageData::GetVoiOriginal(int voi[6])
91 {
92         int i;
93         for (i=0;i<6;i++)
94         {
95                 voi[i] = this->_voiOriginal[i];
96         }
97 }
98 // ----------------------------------------------------------------------------------------------
99 vtkImageData *marImageData::GetImageDataT(int t)
100 {
101         if(_imagedataLST.size() > t){
102                 return _imagedataLST[t];
103         }
104         return NULL;
105 }
106 // ----------------------------------------------------------------------------------------------
107 vtkImageData *marImageData::GetImageData()
108 {
109         if(_imagedataLST.size()>0){
110                 return _imagedataLST[0];
111         }
112         return NULL;
113 }
114
115 void marImageData::removeImageData(int index)
116 {
117         if(index < _imagedataLST.size()){
118
119                 /*vtkImageData* img = _imagedataLST[index];
120                 if(img->GetReferenceCount()>1){
121                         img->SetReferenceCount(img->GetReferenceCount()-1);
122                         //img->Delete();
123                 }*/
124                 for(int i = index; i < _imagedataLST.size()-1; i++){                    
125                         _imagedataLST[i] = _imagedataLST[i+1];
126                 }
127                 _imagedataLST.pop_back();
128                 //delete img;
129         }       
130 }
131 // ----------------------------------------------------------------------------------------------
132 int marImageData::GetXOriginal(int value)
133 {
134         double min=_spcOriginal[0];
135         if (_spcOriginal[1]<min)
136         {
137                 min = _spcOriginal[1];
138         }
139         if (_spcOriginal[2]<min)
140         {
141                 min = _spcOriginal[2];
142         }
143         double result = value / (  _spcOriginal[0] / min ) ;
144         result=result + _voiOriginal[0];
145         return (int)result;
146 }
147 // ----------------------------------------------------------------------------------------------
148 int marImageData::GetYOriginal(int value)
149 {
150         double min=_spcOriginal[0];
151         if (_spcOriginal[1]<min)
152         {
153                 min = _spcOriginal[1];
154         }
155         if (_spcOriginal[2]<min)
156         {
157                 min = _spcOriginal[2];
158         }
159         double result = value / (  _spcOriginal[1] / min ) ;
160         result=result + _voiOriginal[2];
161         return (int)result;
162 }
163 // ----------------------------------------------------------------------------------------------
164 int marImageData::GetZOriginal(int value)
165 {
166         double min=_spcOriginal[0];
167         if (_spcOriginal[1]<min)
168         {
169                 min = _spcOriginal[1];
170         }
171         if (_spcOriginal[2]<min)
172         {
173                 min = _spcOriginal[2];
174         }
175         double result = value / (  _spcOriginal[2] / min ) ;
176         result=result + _voiOriginal[4];
177         return (int)result;
178 }
179 // ----------------------------------------------------------------------------------------------
180 int marImageData::GetMaxT()
181 {
182         return _imagedataLST.size();
183 }