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://oncora1.lyon.fnclcc.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 <vtkImageReslice.h>
30 #include <vtkTransform.h>
37 //--------------------------------------------------------------------
38 vvImage::vvImage():mTransform(vtkSmartPointer<vtkTransform>::New())
42 //--------------------------------------------------------------------
45 //--------------------------------------------------------------------
52 //--------------------------------------------------------------------
54 //--------------------------------------------------------------------
57 // DD("vvImage got deleted!");
60 //--------------------------------------------------------------------
62 //--------------------------------------------------------------------
66 mVtkImageReslice.resize(0);
70 //--------------------------------------------------------------------
72 //--------------------------------------------------------------------
73 int vvImage::GetNumberOfSpatialDimensions()
75 return mImageDimension;
76 // int dim=GetNumberOfDimensions();
77 // if (IsTimeSequence())
82 //--------------------------------------------------------------------
84 //--------------------------------------------------------------------
85 int vvImage::GetNumberOfDimensions() const
87 if (mVtkImages.size()) {
89 return mImageDimension+1;
91 return mImageDimension;
94 // mVtkImages[0]->GetWholeExtent(extent);
95 // if (extent[5] - extent[4] >= 1)
97 // // if (mVtkImages.size() > 1)
103 //--------------------------------------------------------------------
105 //--------------------------------------------------------------------
106 void vvImage::GetScalarRange(double* range)
108 assert(mVtkImages.size());
109 double * temp = mVtkImages[0]->GetScalarRange();
112 for (unsigned int i=1; i<mVtkImages.size(); i++) {
113 temp = mVtkImages[i]->GetScalarRange();
114 if (temp[0] < range[0]) range[0]=temp[0];
115 if (temp[1] > range[1]) range[1]=temp[1];
118 //--------------------------------------------------------------------
120 //--------------------------------------------------------------------
121 std::string vvImage::GetScalarTypeAsITKString()
123 // WARNING VTK pixel type different from ITK Pixel type
124 std::string vtktype = mVtkImages[0]->GetScalarTypeAsString();
125 if (vtktype == "unsigned char") return "unsigned_char";
126 if (vtktype == "unsigned short") return "unsigned_short";
127 if (vtktype == "unsigned int") return "unsigned_int";
130 //--------------------------------------------------------------------
132 //--------------------------------------------------------------------
133 int vvImage::GetNumberOfScalarComponents()
135 return mVtkImages[0]->GetNumberOfScalarComponents();
137 //--------------------------------------------------------------------
139 //--------------------------------------------------------------------
140 int vvImage::GetScalarSize()
142 return mVtkImages[0]->GetScalarSize();
144 //--------------------------------------------------------------------
146 //--------------------------------------------------------------------
147 std::vector<double> vvImage::GetSpacing()
149 std::vector<double> spacing;
150 int dim = this->GetNumberOfDimensions();
151 for (int i = 0; i < dim; i++) {
153 spacing.push_back(mTimeSpacing);
155 spacing.push_back(mVtkImages[0]->GetSpacing()[i]);
159 //--------------------------------------------------------------------
160 std::vector<double> vvImage::GetOrigin() const
162 std::vector<double> origin;
163 int dim = this->GetNumberOfDimensions();
164 for (int i = 0; i < dim; i++) {
166 origin.push_back(mTimeOrigin);
168 origin.push_back(mVtkImages[0]->GetOrigin()[i]);
172 //--------------------------------------------------------------------
174 //--------------------------------------------------------------------
175 std::vector<int> vvImage::GetSize()
177 std::vector<int> size0;
178 int dim = this->GetNumberOfDimensions();
179 for (int i = 0; i < dim; i++) {
181 size0.push_back(mVtkImages.size());
183 size0.push_back(mVtkImages[0]->GetDimensions()[i]);
187 //--------------------------------------------------------------------
189 //--------------------------------------------------------------------
190 unsigned long vvImage::GetActualMemorySize()
192 unsigned long size = 0;
193 for (unsigned int i = 0; i < mVtkImages.size(); i++) {
194 size += mVtkImages[i]->GetActualMemorySize();
198 //--------------------------------------------------------------------
201 //--------------------------------------------------------------------
202 bool vvImage::IsTimeSequence() const
204 return mVtkImages.size()>1;
206 //--------------------------------------------------------------------
209 //--------------------------------------------------------------------
210 const std::vector<vtkImageData*>& vvImage::GetVTKImages()
214 //--------------------------------------------------------------------
216 //--------------------------------------------------------------------
217 vtkImageData* vvImage::GetFirstVTKImageData()
219 return mVtkImages[0];
221 //--------------------------------------------------------------------
223 //--------------------------------------------------------------------
224 bool vvImage::IsScalarTypeInteger()
226 assert(mVtkImages.size()> 0);
227 int t = mVtkImages[0]->GetScalarType();
228 return IsScalarTypeInteger(t);
230 //--------------------------------------------------------------------
232 //--------------------------------------------------------------------
233 bool vvImage::IsScalarTypeInteger(int t)
235 if ((t == VTK_BIT) ||
237 (t == VTK_UNSIGNED_CHAR) ||
239 (t == VTK_UNSIGNED_SHORT) ||
241 (t == VTK_UNSIGNED_INT) ||
243 (t == VTK_UNSIGNED_LONG)) {
250 //--------------------------------------------------------------------
252 //--------------------------------------------------------------------
253 vtkSmartPointer<vtkTransform> vvImage::GetTransform()
255 return this->mTransform;
257 //--------------------------------------------------------------------
259 //--------------------------------------------------------------------
260 void vvImage::UpdateReslice()
262 for (unsigned int i=0; i<mVtkImageReslice.size(); i++) {
263 mVtkImageReslice[i]->Update();
266 //--------------------------------------------------------------------
268 #endif // VVIMAGE_CXX