4 /*=========================================================================
8 Author : Pierre Seroul (pierre.seroul@gmail.com)
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS-LRMN http://www.creatis.insa-lyon.fr
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, version 3 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 =========================================================================*/
29 #include "vtkImageData.h"
30 #include "clitkCommon.h"
33 //====================================================================
37 //====================================================================
39 //====================================================================
41 for (unsigned int i = 0; i < mVtkImages.size(); i++) {
42 if (mVtkImages[i] != NULL)
43 mVtkImages[i]->Delete();
46 //====================================================================
48 //====================================================================
49 void vvImage::SetImage(std::vector<vtkImageData*> images) {
50 for (unsigned int i = 0; i < mVtkImages.size(); i++) {
51 if (mVtkImages[i] != NULL)
52 mVtkImages[i]->Delete();
55 for (unsigned int i = 0; i < images.size(); i++) {
56 mVtkImages.push_back(images[i]);
59 //====================================================================
61 //====================================================================
62 void vvImage::AddImage(vtkImageData* image) {
63 mVtkImages.push_back(image);
65 //====================================================================
67 //====================================================================
68 void vvImage::Init() {
69 for (unsigned int i = 0; i < mVtkImages.size(); i++) {
70 if (mVtkImages[i] != NULL)
71 mVtkImages[i]->Delete();
75 //====================================================================
77 //====================================================================
78 int vvImage::GetNumberOfSpatialDimensions() {
79 int dim=GetNumberOfDimensions();
85 //====================================================================
87 //====================================================================
88 int vvImage::GetNumberOfDimensions() const {
89 if (mVtkImages.size())
93 mVtkImages[0]->GetWholeExtent(extent);
94 if (extent[5] - extent[4] >= 1)
96 if (mVtkImages.size() > 1)
102 //====================================================================
103 void vvImage::GetScalarRange(double* range)
105 assert(mVtkImages.size());
106 double * temp = mVtkImages[0]->GetScalarRange();
107 range[0]=temp[0];range[1]=temp[1];
108 for (unsigned int i=1;i<mVtkImages.size();i++)
110 temp = mVtkImages[i]->GetScalarRange();
111 if (temp[0] < range[0]) range[0]=temp[0];
112 if (temp[1] > range[1]) range[1]=temp[1];
116 //====================================================================
117 std::string vvImage::GetScalarTypeAsString() {
118 return mVtkImages[0]->GetScalarTypeAsString();
120 //====================================================================
122 //====================================================================
123 int vvImage::GetNumberOfScalarComponents() {
124 return mVtkImages[0]->GetNumberOfScalarComponents();
126 //====================================================================
128 //====================================================================
129 int vvImage::GetScalarSize() {
130 return mVtkImages[0]->GetScalarSize();
132 //====================================================================
134 //====================================================================
135 std::vector<double> vvImage::GetSpacing() {
136 std::vector<double> spacing;
137 int dim = this->GetNumberOfDimensions();
138 for (int i = 0; i < dim; i++)
141 spacing.push_back(1);
143 spacing.push_back(mVtkImages[0]->GetSpacing()[i]);
147 //====================================================================
149 //====================================================================
150 std::vector<double> vvImage::GetOrigin() const {
151 std::vector<double> origin;
152 int dim = this->GetNumberOfDimensions();
153 for (int i = 0; i < dim; i++)
158 origin.push_back(mVtkImages[0]->GetOrigin()[i]);
162 //====================================================================
164 //====================================================================
165 std::vector<int> vvImage::GetSize() {
166 std::vector<int> size0;
167 int dim = this->GetNumberOfDimensions();
168 for (int i = 0; i < dim; i++)
171 size0.push_back(mVtkImages.size());
173 size0.push_back(mVtkImages[0]->GetDimensions()[i]);
177 //====================================================================
179 //====================================================================
180 unsigned long vvImage::GetActualMemorySize() {
181 unsigned long size = 0;
182 for (unsigned int i = 0; i < mVtkImages.size(); i++) {
183 size += mVtkImages[i]->GetActualMemorySize();
187 //====================================================================
189 #endif // VVIMAGE_CXX