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>
30 #include <vtkDataObject.h>
31 #include <vtkStreamingDemandDrivenPipeline.h>
32 #include <vtkInformation.h>
33 #include <vtkVersion.h>
38 //--------------------------------------------------------------------
43 //--------------------------------------------------------------------
46 //--------------------------------------------------------------------
52 mrange[0] = std::numeric_limits<int>::max();;//min
53 mrange[1] = std::numeric_limits<int>::min();;//max
55 //--------------------------------------------------------------------
57 //--------------------------------------------------------------------
62 //--------------------------------------------------------------------
64 //--------------------------------------------------------------------
70 //--------------------------------------------------------------------
72 //--------------------------------------------------------------------
73 void vvImage::AddVtkImage(vtkImageData* input)
76 // Note that we're simply adding a new image to the vector.
77 // mItkToVtkConverters is therefore not being updated, but
78 // up to here it's not being used anyway...
80 #if VTK_MAJOR_VERSION <= 5
81 int* extent = input->GetWholeExtent();
83 int* extent = input->GetInformation()->Get(vtkDataObject::DATA_EXTENT());
85 if (extent[4] != extent[5])
87 else if (extent[3] != extent[4])
89 else if (extent[0] != extent[1])
92 mVtkImages.push_back(input);
95 //--------------------------------------------------------------------
97 //--------------------------------------------------------------------
98 int vvImage::GetNumberOfSpatialDimensions()
100 return mImageDimension;
102 //--------------------------------------------------------------------
104 //--------------------------------------------------------------------
105 int vvImage::GetNumberOfDimensions() const
107 if (mVtkImages.size()) {
108 if (IsTimeSequence())
109 return mImageDimension+1;
111 return mImageDimension;
115 //--------------------------------------------------------------------
117 //--------------------------------------------------------------------
118 void vvImage::GetScalarRange(double* range)
123 //--------------------------------------------------------------------
125 //--------------------------------------------------------------------
126 std::string vvImage::GetScalarTypeAsITKString()
128 // WARNING VTK pixel type different from ITK Pixel type
129 std::string vtktype = mVtkImages[0]->GetScalarTypeAsString();
130 if (vtktype == "unsigned char") return "unsigned_char";
131 if (vtktype == "unsigned short") return "unsigned_short";
132 if (vtktype == "unsigned int") return "unsigned_int";
135 //--------------------------------------------------------------------
137 //--------------------------------------------------------------------
138 int vvImage::GetNumberOfScalarComponents()
140 return mVtkImages[0]->GetNumberOfScalarComponents();
142 //--------------------------------------------------------------------
144 //--------------------------------------------------------------------
145 int vvImage::GetScalarSize()
147 return mVtkImages[0]->GetScalarSize();
149 //--------------------------------------------------------------------
151 //--------------------------------------------------------------------
152 std::vector<double> vvImage::GetSpacing()
154 std::vector<double> spacing;
155 int dim = this->GetNumberOfDimensions();
156 for (int i = 0; i < dim; i++) {
158 spacing.push_back(mTimeSpacing);
160 spacing.push_back(mVtkImages[0]->GetSpacing()[i]);
164 //--------------------------------------------------------------------
165 std::vector<double> vvImage::GetOrigin() const
167 std::vector<double> origin;
168 int dim = this->GetNumberOfDimensions();
169 for (int i = 0; i < dim; i++) {
171 origin.push_back(mTimeOrigin);
173 origin.push_back(mVtkImages[0]->GetOrigin()[i]);
177 //--------------------------------------------------------------------
179 //--------------------------------------------------------------------
180 std::vector<int> vvImage::GetSize()
182 std::vector<int> size0;
183 int dim = this->GetNumberOfDimensions();
184 for (int i = 0; i < dim; i++) {
186 size0.push_back(mVtkImages.size());
188 size0.push_back(mVtkImages[0]->GetDimensions()[i]);
192 //--------------------------------------------------------------------
194 //--------------------------------------------------------------------
195 unsigned long vvImage::GetActualMemorySize()
197 unsigned long size = 0;
198 for (unsigned int i = 0; i < mVtkImages.size(); i++) {
199 size += mVtkImages[i]->GetActualMemorySize();
203 //--------------------------------------------------------------------
206 //--------------------------------------------------------------------
207 bool vvImage::IsTimeSequence() const
209 return mVtkImages.size()>1;
211 //--------------------------------------------------------------------
214 //--------------------------------------------------------------------
215 const std::vector<vtkImageData*>& vvImage::GetVTKImages()
219 //--------------------------------------------------------------------
221 //--------------------------------------------------------------------
222 vtkImageData* vvImage::GetFirstVTKImageData()
224 return mVtkImages[0];
226 //--------------------------------------------------------------------
228 //--------------------------------------------------------------------
229 bool vvImage::IsScalarTypeInteger()
231 assert(mVtkImages.size()> 0);
232 int t = mVtkImages[0]->GetScalarType();
233 return IsScalarTypeInteger(t);
235 //--------------------------------------------------------------------
237 //--------------------------------------------------------------------
238 bool vvImage::IsScalarTypeInteger(int t)
240 if ((t == VTK_BIT) ||
242 (t == VTK_UNSIGNED_CHAR) ||
244 (t == VTK_UNSIGNED_SHORT) ||
246 (t == VTK_UNSIGNED_INT) ||
248 (t == VTK_UNSIGNED_LONG)) {
254 //--------------------------------------------------------------------
256 //--------------------------------------------------------------------
257 const std::vector< vtkSmartPointer<vtkTransform> >& vvImage::GetTransform()
259 return this->mTransform;
261 //--------------------------------------------------------------------
264 //--------------------------------------------------------------------
265 bool vvImage::HaveSameSizeAndSpacingThan(vvImage * other)
268 for(int i=0; i<GetNumberOfDimensions(); i++) {
269 if ( GetSize()[i] != other->GetSize()[i]) same = false;
270 if ( GetSpacing()[i] != other->GetSpacing()[i]) same = false;
274 //--------------------------------------------------------------------
275 itk::MetaDataDictionary* vvImage::GetFirstMetaDataDictionary()
277 return mDictionary[0];
279 //--------------------------------------------------------------------
282 #endif // VVIMAGE_CXX