]> Creatis software - clitk.git/commitdiff
Added reslicing via the transform set with SetTransform. Only enabled when CLITK_EXPE...
authorsrit <srit>
Thu, 22 Apr 2010 13:10:06 +0000 (13:10 +0000)
committersrit <srit>
Thu, 22 Apr 2010 13:10:06 +0000 (13:10 +0000)
common/vvImage.cxx
common/vvImage.h

index 1d718bce26d6fb5d24498d02bbe01e5f3bddf5dc..77721079d57ad53d33bd3527910ae2883c460a7b 100644 (file)
 #ifndef VVIMAGE_CXX
 #define VVIMAGE_CXX
 #include "vvImage.h"
-#include "vtkImageData.h"
 #include "clitkCommon.h"
+
+#include <vtkImageData.h>
+#include <vtkImageReslice.h>
+
 #include <cassert>
 
 //--------------------------------------------------------------------
 vvImage::vvImage() {
-  mVtkImages.resize(0);
-  mTimeSpacing = 1;
-  mTimeOrigin = 0;
+    Init();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void vvImage::Init() {
+    mTimeSpacing = 1;
+    mTimeOrigin = 0;
+    if (CLITK_EXPERIMENTAL)
+    {
+        mVtkImageReslice = vtkSmartPointer<vtkImageReslice>::New();
+        mVtkImageReslice->SetInterpolationModeToLinear();
+        mVtkImageReslice->AutoCropOutputOn();
+    }
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
 vvImage::~vvImage() {
-  for (unsigned int i = 0; i < mVtkImages.size(); i++) {
-    if (mVtkImages[i] != NULL)
-      mVtkImages[i]->Delete();
-  }
+    Reset();
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-void vvImage::SetImage(std::vector<vtkImageData*> images) {
-  for (unsigned int i = 0; i < mVtkImages.size(); i++) {
-    if (mVtkImages[i] != NULL)
-      mVtkImages[i]->Delete();
-  }
-  mVtkImages.resize(0);
-  for (unsigned int i = 0; i < images.size(); i++) {
-    mVtkImages.push_back(images[i]);
-  }
+void vvImage::Reset() {
+    if (CLITK_EXPERIMENTAL)
+    {
+        for (unsigned int i = 0; i < mVtkImages.size(); i++)
+            mVtkImages[i] = (vtkImageData*)mVtkImageReslice->GetInput(i);
+        mVtkImageReslice->RemoveAllInputs();
+    }
+    for (unsigned int i = 0; i < mVtkImages.size(); i++)
+        mVtkImages[i]->Delete();
+    mVtkImages.resize(0);
+    Init();
 }
 //--------------------------------------------------------------------
 
+
 //--------------------------------------------------------------------
-void vvImage::AddImage(vtkImageData* image) {
-  mVtkImages.push_back(image);
+void vvImage::SetImage(std::vector< vtkImageData* > images) {
+    Reset();
+    for (unsigned int i = 0; i < images.size(); i++)
+        AddImage(images[i]);
 }
 //--------------------------------------------------------------------
 
+
 //--------------------------------------------------------------------
-void vvImage::Init() {
-  for (unsigned int i = 0; i < mVtkImages.size(); i++) {
-    if (mVtkImages[i] != NULL)
-      mVtkImages[i]->Delete();
-  }
-  mVtkImages.resize(0);
+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);
 }
 //--------------------------------------------------------------------
 
@@ -251,4 +272,11 @@ bool vvImage::IsScalarTypeInteger(int t) {
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+void vvImage::SetTransform(vtkAbstractTransform  *transform)
+{
+  mVtkImageReslice->SetResliceTransform(transform);
+}
+//--------------------------------------------------------------------
+
 #endif // VVIMAGE_CXX
index 7cb3e95a472faa85b16ac9d4c9b5093f9922d740..a0ab108b95e16a323f691b88ef87cd33ec5ef22f 100644 (file)
 #include <iostream>
 #include <vector>
 #include <itkObjectFactory.h>
+#include <vtkSmartPointer.h>
 
 class vtkImageData;
+class vtkImageReslice;
+class vtkAbstractTransform;
 
 class vvImage : public itk::LightObject {
 public :
@@ -31,6 +34,8 @@ public :
   itkNewMacro(Self);
 
   void Init();
+  void Reset();
+
   void SetImage(std::vector<vtkImageData*> images);
   void AddImage(vtkImageData* image);
   const std::vector<vtkImageData*>& GetVTKImages();
@@ -53,6 +58,7 @@ public :
 
   void SetTimeSpacing(double s) { mTimeSpacing = s; }
   void SetTimeOrigin(double o) { mTimeOrigin = o; }
+  void SetTransform(vtkAbstractTransform  *transform);
 
 private:
   vvImage();
@@ -60,7 +66,7 @@ private:
   std::vector<vtkImageData*> mVtkImages;
   double mTimeOrigin;
   double mTimeSpacing;
-
+  vtkSmartPointer<vtkImageReslice> mVtkImageReslice;
 };
 
 #endif