]> Creatis software - clitk.git/commitdiff
Changed mVtkImageReslice strategy: one filter per vtkImage
authorsrit <srit>
Wed, 28 Apr 2010 09:41:23 +0000 (09:41 +0000)
committersrit <srit>
Wed, 28 Apr 2010 09:41:23 +0000 (09:41 +0000)
common/vvImage.cxx
common/vvImage.h

index 2a47a99d6463989ff9157009aa6057f87f509b0a..a394c7608456b9d0de2f06f88ceeb3a7bfbd993c 100644 (file)
@@ -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
 #include <cassert>
 
 //--------------------------------------------------------------------
-vvImage::vvImage() {
+vvImage::vvImage()
+{
   Init();
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-void vvImage::Init() {
-    mTimeSpacing = 1;
-    mTimeOrigin = 0;
-    
-    if (CLITK_EXPERIMENTAL)
-    {
-        mVtkImageReslice = vtkSmartPointer<vtkImageReslice>::New();
-       transform = vtkSmartPointer<vtkTransform>::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<vtkTransform>::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<vtkImageReslice>::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;i<mVtkImages.size();i++)
-    {
-        temp = mVtkImages[i]->GetScalarRange();
-        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; i<mVtkImages.size(); i++) {
+    temp = mVtkImages[i]->GetScalarRange();
+    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<double> vvImage::GetSpacing() {
-    std::vector<double> 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<double> vvImage::GetSpacing()
+{
+  std::vector<double> 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<double> vvImage::GetOrigin() const {
-    std::vector<double> 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<double> vvImage::GetOrigin() const
+{
+  std::vector<double> 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<int> vvImage::GetSize() {
-    std::vector<int> 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<int> vvImage::GetSize()
+{
+  std::vector<int> 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<vtkImageData*>& vvImage::GetVTKImages() {
+const std::vector<vtkImageData*>& 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;
 }
 //--------------------------------------------------------------------
 
index 0aa33a44c31ceb1efa1cd7a87e2b96fcdefe9f07..49695bb106286a1f5ba4c557d26369319c3dd07f 100644 (file)
@@ -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<Self> Pointer;
@@ -42,7 +43,7 @@ public :
   void AddImage(vtkImageData* image);
   const std::vector<vtkImageData*>& 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<vtkImageData*> mVtkImages;
-  vtkSmartPointer<vtkImageReslice> mVtkImageReslice;
-  vtkSmartPointer<vtkTransform> transform;
+  std::vector< vtkSmartPointer<vtkImageReslice> > mVtkImageReslice;
+  vtkSmartPointer<vtkTransform> mTransform;
   double mTimeOrigin;
   double mTimeSpacing;
   double * origin;