From a97c480d25285a6d143bd035d6b5fa0804a7d068 Mon Sep 17 00:00:00 2001 From: srit Date: Wed, 28 Apr 2010 09:41:23 +0000 Subject: [PATCH] Changed mVtkImageReslice strategy: one filter per vtkImage --- common/vvImage.cxx | 331 ++++++++++++++++++++++----------------------- common/vvImage.h | 27 ++-- 2 files changed, 177 insertions(+), 181 deletions(-) diff --git a/common/vvImage.cxx b/common/vvImage.cxx index 2a47a99..a394c76 100644 --- a/common/vvImage.cxx +++ b/common/vvImage.cxx @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr @@ -25,217 +25,228 @@ #include //-------------------------------------------------------------------- -vvImage::vvImage() { +vvImage::vvImage() +{ Init(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void vvImage::Init() { - mTimeSpacing = 1; - mTimeOrigin = 0; - - if (CLITK_EXPERIMENTAL) - { - mVtkImageReslice = vtkSmartPointer::New(); - transform = vtkSmartPointer::New(); - mVtkImageReslice->SetInterpolationModeToLinear(); - mVtkImageReslice->AutoCropOutputOn(); - mVtkImageReslice->SetBackgroundColor(-1000,-1000,-1000,1); - mVtkImageReslice->SetResliceTransform(transform); - } +void vvImage::Init() +{ + mTimeSpacing = 1; + mTimeOrigin = 0; + + if (CLITK_EXPERIMENTAL) + mTransform = vtkSmartPointer::New(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -vvImage::~vvImage() { - Reset(); +vvImage::~vvImage() +{ + Reset(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void vvImage::Reset() { - if (CLITK_EXPERIMENTAL) - { - for (unsigned int i = 0; i < mVtkImages.size(); i++) - mVtkImages[i] = (vtkImageData*)mVtkImageReslice->GetInput(i); - mVtkImageReslice->RemoveAllInputs(); - } +void vvImage::Reset() +{ + if (CLITK_EXPERIMENTAL) + for (unsigned int i = 0; i < mVtkImages.size(); i++) + mVtkImageReslice[i]->GetInput(0)->Delete(); + else for (unsigned int i = 0; i < mVtkImages.size(); i++) - mVtkImages[i]->Delete(); - mVtkImages.resize(0); - Init(); + mVtkImages[i]->Delete(); + + mVtkImages.resize(0); + mVtkImageReslice.resize(0); + + Init(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void vvImage::SetImage(std::vector< vtkImageData* > images) { - Reset(); - for (unsigned int i = 0; i < images.size(); i++) - AddImage(images[i]); +void vvImage::SetImage(std::vector< vtkImageData* > images) +{ + Reset(); + for (unsigned int i = 0; i < images.size(); i++) + AddImage(images[i]); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void vvImage::AddImage(vtkImageData* image) { - if (CLITK_EXPERIMENTAL) - { - mVtkImageReslice->SetInput(mVtkImages.size(), image); - mVtkImageReslice->Update(); - mVtkImages.push_back( mVtkImageReslice->GetOutput( mVtkImages.size() ) ); - } - else - mVtkImages.push_back(image); +void vvImage::AddImage(vtkImageData* image) +{ + if (CLITK_EXPERIMENTAL) { + mVtkImageReslice.push_back(vtkSmartPointer::New()); + + mVtkImageReslice.back()->SetInterpolationModeToLinear(); + mVtkImageReslice.back()->AutoCropOutputOn(); + mVtkImageReslice.back()->SetBackgroundColor(-1000,-1000,-1000,1); + mVtkImageReslice.back()->SetResliceTransform(mTransform); + mVtkImageReslice.back()->SetInput(0, image); + mVtkImageReslice.back()->Update(); + + mVtkImages.push_back( mVtkImageReslice.back()->GetOutput(0) ); + } else + mVtkImages.push_back(image); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -int vvImage::GetNumberOfSpatialDimensions() { - int dim=GetNumberOfDimensions(); - if (IsTimeSequence()) - return dim-1; - else - return dim; +int vvImage::GetNumberOfSpatialDimensions() +{ + int dim=GetNumberOfDimensions(); + if (IsTimeSequence()) + return dim-1; + else + return dim; } //-------------------------------------------------------------------- // //-------------------------------------------------------------------- -int vvImage::GetNumberOfDimensions() const { - if (mVtkImages.size()) - { - int dimension = 2; - int extent[6]; - mVtkImages[0]->GetWholeExtent(extent); - if (extent[5] - extent[4] >= 1) - dimension++; - if (mVtkImages.size() > 1) - dimension++; - return dimension; - } - return 0; +int vvImage::GetNumberOfDimensions() const +{ + if (mVtkImages.size()) { + int dimension = 2; + int extent[6]; + mVtkImages[0]->GetWholeExtent(extent); + if (extent[5] - extent[4] >= 1) + dimension++; + if (mVtkImages.size() > 1) + dimension++; + return dimension; + } + return 0; } //-------------------------------------------------------------------- void vvImage::GetScalarRange(double* range) { - assert(mVtkImages.size()); - double * temp = mVtkImages[0]->GetScalarRange(); - range[0]=temp[0];range[1]=temp[1]; - for (unsigned int i=1;iGetScalarRange(); - if (temp[0] < range[0]) range[0]=temp[0]; - if (temp[1] > range[1]) range[1]=temp[1]; - } + assert(mVtkImages.size()); + double * temp = mVtkImages[0]->GetScalarRange(); + range[0]=temp[0]; + range[1]=temp[1]; + for (unsigned int i=1; iGetScalarRange(); + if (temp[0] < range[0]) range[0]=temp[0]; + if (temp[1] > range[1]) range[1]=temp[1]; + } } //-------------------------------------------------------------------- -std::string vvImage::GetScalarTypeAsString() { - return mVtkImages[0]->GetScalarTypeAsString(); +std::string vvImage::GetScalarTypeAsString() +{ + // WARNING VTK pixel type different from ITK Pixel type + std::string vtktype = mVtkImages[0]->GetScalarTypeAsString(); + if (vtktype == "unsigned char") return "unsigned_char"; + if (vtktype == "unsigned short") return "unsigned_short"; + if (vtktype == "unsigned int") return "unsigned_int"; + return vtktype; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -int vvImage::GetNumberOfScalarComponents() { - return mVtkImages[0]->GetNumberOfScalarComponents(); +int vvImage::GetNumberOfScalarComponents() +{ + return mVtkImages[0]->GetNumberOfScalarComponents(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -int vvImage::GetScalarSize() { - return mVtkImages[0]->GetScalarSize(); +int vvImage::GetScalarSize() +{ + return mVtkImages[0]->GetScalarSize(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -std::vector vvImage::GetSpacing() { - std::vector spacing; - int dim = this->GetNumberOfDimensions(); - for (int i = 0; i < dim; i++) - { - if (i == 3) - spacing.push_back(1); - else - spacing.push_back(mVtkImages[0]->GetSpacing()[i]); - if (i == 3) - spacing.push_back(mTimeSpacing); - else - spacing.push_back(mVtkImages[0]->GetSpacing()[i]); - } - return spacing; +std::vector vvImage::GetSpacing() +{ + std::vector spacing; + int dim = this->GetNumberOfDimensions(); + for (int i = 0; i < dim; i++) { + if (i == 3) + spacing.push_back(mTimeSpacing); + else + spacing.push_back(mVtkImages[0]->GetSpacing()[i]); + } + return spacing; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -std::vector vvImage::GetOrigin() const { - std::vector origin; - int dim = this->GetNumberOfDimensions(); - for (int i = 0; i < dim; i++) - { - if (i == 3) - origin.push_back(0); - else - origin.push_back(mVtkImages[0]->GetOrigin()[i]); - if (i == 3) - origin.push_back(mTimeOrigin); - else - origin.push_back(mVtkImages[0]->GetOrigin()[i]); - } - return origin; +std::vector vvImage::GetOrigin() const +{ + std::vector origin; + int dim = this->GetNumberOfDimensions(); + for (int i = 0; i < dim; i++) { + if (i == 3) + origin.push_back(mTimeOrigin); + else + origin.push_back(mVtkImages[0]->GetOrigin()[i]); + } + return origin; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -std::vector vvImage::GetSize() { - std::vector size0; - int dim = this->GetNumberOfDimensions(); - for (int i = 0; i < dim; i++) - { - if (i == 3) - size0.push_back(mVtkImages.size()); - else - size0.push_back(mVtkImages[0]->GetDimensions()[i]); - } - return size0; +std::vector vvImage::GetSize() +{ + std::vector size0; + int dim = this->GetNumberOfDimensions(); + for (int i = 0; i < dim; i++) { + if (i == 3) + size0.push_back(mVtkImages.size()); + else + size0.push_back(mVtkImages[0]->GetDimensions()[i]); + } + return size0; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -unsigned long vvImage::GetActualMemorySize() { - unsigned long size = 0; - for (unsigned int i = 0; i < mVtkImages.size(); i++) { - size += mVtkImages[i]->GetActualMemorySize(); - } - return size; +unsigned long vvImage::GetActualMemorySize() +{ + unsigned long size = 0; + for (unsigned int i = 0; i < mVtkImages.size(); i++) { + size += mVtkImages[i]->GetActualMemorySize(); + } + return size; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -bool vvImage::IsTimeSequence() { +bool vvImage::IsTimeSequence() +{ return mVtkImages.size()>1; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -const std::vector& vvImage::GetVTKImages() { +const std::vector& vvImage::GetVTKImages() +{ return mVtkImages; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -vtkImageData* vvImage::GetFirstVTKImageData() { - return mVtkImages[0]; +vtkImageData* vvImage::GetFirstVTKImageData() +{ + return mVtkImages[0]; } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -bool vvImage::IsScalarTypeInteger() { +bool vvImage::IsScalarTypeInteger() +{ assert(mVtkImages.size()> 0); int t = mVtkImages[0]->GetScalarType(); return IsScalarTypeInteger(t); @@ -243,7 +254,8 @@ bool vvImage::IsScalarTypeInteger() { //-------------------------------------------------------------------- //-------------------------------------------------------------------- -bool vvImage::IsScalarTypeInteger(int t) { +bool vvImage::IsScalarTypeInteger(int t) +{ if ((t == VTK_BIT) || (t == VTK_CHAR) || (t == VTK_UNSIGNED_CHAR) || @@ -254,8 +266,7 @@ bool vvImage::IsScalarTypeInteger(int t) { (t == VTK_LONG) || (t == VTK_UNSIGNED_LONG)) { return true; - } - else { + } else { return false; } } @@ -263,28 +274,19 @@ bool vvImage::IsScalarTypeInteger(int t) { //-------------------------------------------------------------------- //-------------------------------------------------------------------- - -void vvImage::SetVTKImageReslice(vtkImageReslice* reslice) { - mVtkImageReslice=reslice; - -} -//-------------------------------------------------------------------- - -//-------------------------------------------------------------------- -vtkAbstractTransform * vvImage::GetTransform() +vtkTransform * vvImage::GetTransform() { - return mVtkImageReslice->GetResliceTransform(); + return mTransform; } //-------------------------------------------------------------------- //------------------------------------------------------------------- void vvImage::SetRotateX(int xvalue) { - transform->PostMultiply(); - transform->Translate(-origin[0],-origin[1],-origin[2]); - transform->RotateX(xvalue); - transform->Translate(origin[0],origin[1],origin[2]); - mVtkImageReslice->Update(); + mTransform->PostMultiply(); + mTransform->Translate(-origin[0],-origin[1],-origin[2]); + mTransform->RotateX(xvalue); + mTransform->Translate(origin[0],origin[1],origin[2]); } //-------------------------------------------------------------------- @@ -292,64 +294,57 @@ void vvImage::SetRotateX(int xvalue) //------------------------------------------------------------------- void vvImage::SetRotateY(int yvalue) { - transform->PostMultiply(); - transform->Translate(-origin[0],-origin[1],-origin[2]); - transform->RotateY(yvalue); - transform->Translate(origin[0],origin[1],origin[2]); - mVtkImageReslice->Update(); + mTransform->PostMultiply(); + mTransform->Translate(-origin[0],-origin[1],-origin[2]); + mTransform->RotateY(yvalue); + mTransform->Translate(origin[0],origin[1],origin[2]); } //-------------------------------------------------------------------- //------------------------------------------------------------------- void vvImage::SetRotateZ(int zvalue) { - transform->PostMultiply(); - transform->Translate(-origin[0],-origin[1],-origin[2]); - transform->RotateZ(zvalue); - transform->Translate(origin[0],origin[1],origin[2]); - mVtkImageReslice->Update(); + mTransform->PostMultiply(); + mTransform->Translate(-origin[0],-origin[1],-origin[2]); + mTransform->RotateZ(zvalue); + mTransform->Translate(origin[0],origin[1],origin[2]); } //-------------------------------------------------------------------- //------------------------------------------------------------------- void vvImage::SetTranslationX(int xvalue) -{ - transform->Translate(xvalue,0,0); - mVtkImageReslice->Update(); +{ + mTransform->Translate(xvalue,0,0); } //-------------------------------------------------------------------- //------------------------------------------------------------------- void vvImage::SetTranslationY(int yvalue) -{ - transform->Translate(0,yvalue,0); - mVtkImageReslice->Update(); +{ + mTransform->Translate(0,yvalue,0); } //-------------------------------------------------------------------- //------------------------------------------------------------------- void vvImage::SetTranslationZ(int zvalue) -{ - transform->Translate(0,0,zvalue); - mVtkImageReslice->Update(); +{ + mTransform->Translate(0,0,zvalue); } //------------------------------------------------------------------- //------------------------------------------------------------------- void vvImage::SetOrigin(double value[3]) -{ - origin=new double[mVtkImageReslice->GetOutputDimensionality()]; +{ origin[0]=value[0]; origin[1]=value[1]; origin[2]=value[2]; } //-------------------------------------------------------------------- -void vvImage::SetTransform(vtkAbstractTransform *transform) +void vvImage::SetTransform(vtkTransform *transform) { - mVtkImageReslice->SetResliceTransform(transform); - mVtkImageReslice->Update(); + mTransform = transform; } //-------------------------------------------------------------------- diff --git a/common/vvImage.h b/common/vvImage.h index 0aa33a4..49695bb 100644 --- a/common/vvImage.h +++ b/common/vvImage.h @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr @@ -29,7 +29,8 @@ class vtkTransform; class vtkImageReslice; class vtkAbstractTransform; -class vvImage : public itk::LightObject { +class vvImage : public itk::LightObject +{ public : typedef vvImage Self; typedef itk::SmartPointer Pointer; @@ -42,7 +43,7 @@ public : void AddImage(vtkImageData* image); const std::vector& GetVTKImages(); vtkImageData* GetFirstVTKImageData(); - + int GetNumberOfDimensions() const; int GetNumberOfSpatialDimensions(); ///Writes the scalar range to the provided array, which must have room for two doubles @@ -57,29 +58,29 @@ public : bool IsTimeSequence(); bool IsScalarTypeInteger(); bool IsScalarTypeInteger(int t); - vtkAbstractTransform * GetTransform(); - void SetTransform(vtkAbstractTransform *transform); + vtkTransform * GetTransform(); + void SetTransform(vtkTransform *transform); vtkImageReslice* GetVTKImageReslice(); void SetVTKImageReslice(vtkImageReslice *reslice); - - void SetRotateX(int xvalue); - void SetRotateY(int yvalue); + + void SetRotateX(int xvalue); + void SetRotateY(int yvalue); void SetRotateZ(int zvalue); - void SetTranslationX(int xvalue); - void SetTranslationY(int yvalue); + void SetTranslationX(int xvalue); + void SetTranslationY(int yvalue); void SetTranslationZ(int zvalue); void SetOrigin(double value[3]); void SetTimeSpacing(double s) { mTimeSpacing = s; } void SetTimeOrigin(double o) { mTimeOrigin = o; } - private: +private: vvImage(); ~vvImage(); std::vector mVtkImages; - vtkSmartPointer mVtkImageReslice; - vtkSmartPointer transform; + std::vector< vtkSmartPointer > mVtkImageReslice; + vtkSmartPointer mTransform; double mTimeOrigin; double mTimeSpacing; double * origin; -- 2.47.1