1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
25 #include "clitkCommon.h"
28 #include <vtkImageData.h>
29 #include <vtkTransform.h>
34 //--------------------------------------------------------------------
39 //--------------------------------------------------------------------
42 //--------------------------------------------------------------------
49 //--------------------------------------------------------------------
51 //--------------------------------------------------------------------
56 //--------------------------------------------------------------------
58 //--------------------------------------------------------------------
64 //--------------------------------------------------------------------
66 //--------------------------------------------------------------------
67 void vvImage::AddVtkImage(vtkImageData* input)
70 // Note that we're simply adding a new image to the vector.
71 // mItkToVtkConverters is therefore not being updated, but
72 // up to here it's not being used anyway...
74 int* extent = input->GetWholeExtent();
75 if (extent[4] != extent[5])
77 else if (extent[3] != extent[4])
79 else if (extent[0] != extent[1])
82 mVtkImages.push_back(input);
85 //--------------------------------------------------------------------
87 //--------------------------------------------------------------------
88 int vvImage::GetNumberOfSpatialDimensions()
90 return mImageDimension;
92 //--------------------------------------------------------------------
94 //--------------------------------------------------------------------
95 int vvImage::GetNumberOfDimensions() const
97 if (mVtkImages.size()) {
99 return mImageDimension+1;
101 return mImageDimension;
105 //--------------------------------------------------------------------
107 //--------------------------------------------------------------------
108 void vvImage::GetScalarRange(double* range)
110 assert(mVtkImages.size());
111 double * temp = mVtkImages[0]->GetScalarRange();
114 for (unsigned int i=1; i<mVtkImages.size(); i++) {
115 temp = mVtkImages[i]->GetScalarRange();
116 if (temp[0] < range[0]) range[0]=temp[0];
117 if (temp[1] > range[1]) range[1]=temp[1];
120 //--------------------------------------------------------------------
122 //--------------------------------------------------------------------
123 std::string vvImage::GetScalarTypeAsITKString()
125 // WARNING VTK pixel type different from ITK Pixel type
126 std::string vtktype = mVtkImages[0]->GetScalarTypeAsString();
127 if (vtktype == "unsigned char") return "unsigned_char";
128 if (vtktype == "unsigned short") return "unsigned_short";
129 if (vtktype == "unsigned int") return "unsigned_int";
132 //--------------------------------------------------------------------
134 //--------------------------------------------------------------------
135 int vvImage::GetNumberOfScalarComponents()
137 return mVtkImages[0]->GetNumberOfScalarComponents();
139 //--------------------------------------------------------------------
141 //--------------------------------------------------------------------
142 int vvImage::GetScalarSize()
144 return mVtkImages[0]->GetScalarSize();
146 //--------------------------------------------------------------------
148 //--------------------------------------------------------------------
149 std::vector<double> vvImage::GetSpacing()
151 std::vector<double> spacing;
152 int dim = this->GetNumberOfDimensions();
153 for (int i = 0; i < dim; i++) {
155 spacing.push_back(mTimeSpacing);
157 spacing.push_back(mVtkImages[0]->GetSpacing()[i]);
161 //--------------------------------------------------------------------
162 std::vector<double> vvImage::GetOrigin() const
164 std::vector<double> origin;
165 int dim = this->GetNumberOfDimensions();
166 for (int i = 0; i < dim; i++) {
168 origin.push_back(mTimeOrigin);
170 origin.push_back(mVtkImages[0]->GetOrigin()[i]);
174 //--------------------------------------------------------------------
176 //--------------------------------------------------------------------
177 std::vector<int> vvImage::GetSize()
179 std::vector<int> size0;
180 int dim = this->GetNumberOfDimensions();
181 for (int i = 0; i < dim; i++) {
183 size0.push_back(mVtkImages.size());
185 size0.push_back(mVtkImages[0]->GetDimensions()[i]);
189 //--------------------------------------------------------------------
191 //--------------------------------------------------------------------
192 unsigned long vvImage::GetActualMemorySize()
194 unsigned long size = 0;
195 for (unsigned int i = 0; i < mVtkImages.size(); i++) {
196 size += mVtkImages[i]->GetActualMemorySize();
200 //--------------------------------------------------------------------
203 //--------------------------------------------------------------------
204 bool vvImage::IsTimeSequence() const
206 return mVtkImages.size()>1;
208 //--------------------------------------------------------------------
211 //--------------------------------------------------------------------
212 const std::vector<vtkImageData*>& vvImage::GetVTKImages()
216 //--------------------------------------------------------------------
218 //--------------------------------------------------------------------
219 vtkImageData* vvImage::GetFirstVTKImageData()
221 return mVtkImages[0];
223 //--------------------------------------------------------------------
225 //--------------------------------------------------------------------
226 bool vvImage::IsScalarTypeInteger()
228 assert(mVtkImages.size()> 0);
229 int t = mVtkImages[0]->GetScalarType();
230 return IsScalarTypeInteger(t);
232 //--------------------------------------------------------------------
234 //--------------------------------------------------------------------
235 bool vvImage::IsScalarTypeInteger(int t)
237 if ((t == VTK_BIT) ||
239 (t == VTK_UNSIGNED_CHAR) ||
241 (t == VTK_UNSIGNED_SHORT) ||
243 (t == VTK_UNSIGNED_INT) ||
245 (t == VTK_UNSIGNED_LONG)) {
251 //--------------------------------------------------------------------
253 //--------------------------------------------------------------------
254 const std::vector< vtkSmartPointer<vtkTransform> >& vvImage::GetTransform()
256 return this->mTransform;
258 //--------------------------------------------------------------------
261 //--------------------------------------------------------------------
262 bool vvImage::HaveSameSizeAndSpacingThan(vvImage * other)
265 for(int i=0; i<GetNumberOfDimensions(); i++) {
266 if ( GetSize()[i] != other->GetSize()[i]) same = false;
267 if ( GetSpacing()[i] != other->GetSpacing()[i]) same = false;
271 //--------------------------------------------------------------------
274 #endif // VVIMAGE_CXX