]> Creatis software - clitk.git/commitdiff
Memory leak hunt: vvBinaryImageOverlayActor vvImageContour vVImageReader are now...
authorsrit <srit>
Mon, 28 Mar 2011 13:29:49 +0000 (13:29 +0000)
committersrit <srit>
Mon, 28 Mar 2011 13:29:49 +0000 (13:29 +0000)
13 files changed:
vv/vvBinaryImageOverlayActor.h
vv/vvDeformableRegistration.cxx
vv/vvImageContour.cxx
vv/vvImageContour.h
vv/vvImageReader.h
vv/vvROIActor.cxx
vv/vvROIActor.h
vv/vvSlicerManager.cxx
vv/vvSlicerManager.h
vv/vvToolBinarize.cxx
vv/vvToolBinarize.h
vv/vvToolStructureSetManager.cxx
vv/vvToolStructureSetManager.h

index 5893158fa3472c670894a5a06a0600c656d12f29..df9de09e270a4f415b756e42159430951075e2fd 100644 (file)
@@ -29,12 +29,13 @@ class vtkImageMapToRGBA;
 class vtkImageActor;
 
 //------------------------------------------------------------------------------
-class vvBinaryImageOverlayActor
+class vvBinaryImageOverlayActor : public itk::LightObject
 {
   //  Q_OBJECT
  public:
-  vvBinaryImageOverlayActor();
-  ~vvBinaryImageOverlayActor();
+  typedef vvBinaryImageOverlayActor Self;
+  typedef itk::SmartPointer<Self> Pointer;
+  itkNewMacro(Self);
 
   void SetSlicer(vvSlicer * slicer);
   void SetColor(double r, double g, double b);
@@ -77,6 +78,10 @@ class vvBinaryImageOverlayActor
                                         vtkImageActor * actor, 
                                         double position);
 
+private:
+  vvBinaryImageOverlayActor();
+  ~vvBinaryImageOverlayActor();
+    
 }; // end class vvBinaryImageOverlayActor
 //------------------------------------------------------------------------------
 
index a4d36f1e63876a2cb6dc45daff869d906a222542..1586808ed1271ae624dda2d6e8471a456292ff35 100644 (file)
@@ -180,10 +180,10 @@ void vvDeformableRegistration::run()
     std::system(("rm " + output_filename).c_str());
     return;
   }
-  vvImageReader reader;
-  reader.SetInputFilename(output_filename);
-  reader.Update(VECTORFIELD);
+  vvImageReader::Pointer reader = vvImageReader::New();
+  reader->SetInputFilename(output_filename);
+  reader->Update(VECTORFIELD);
   finish=clock();
   DD((finish - start)/static_cast<double>(CLOCKS_PER_SEC));
-  mOutput=reader.GetOutput();
+  mOutput = reader->GetOutput();
 }
index 5e50b06fd4032655e8eb2841c46e64263eea18fa..f0c11b6c710a4afa6e88dd176f163615b78c2070 100644 (file)
@@ -45,9 +45,6 @@ vvImageContour::~vvImageContour()
   for (unsigned int i = 0; i < mSlicer->GetImage()->GetVTKImages().size(); i++) {
     mSlicer->GetRenderer()->RemoveActor(mSquaresActorList[i]);
   }
- mSquaresActorList.clear();
- mSquaresList.clear();
- mClipperList.clear();
 }
 //------------------------------------------------------------------------------
 
@@ -57,13 +54,7 @@ void vvImageContour::SetSlicer(vvSlicer * slicer) {
   mSlicer = slicer;  
   // Create an actor for each time slice
   for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) {
-    vtkImageClip * mClipper;// = vtkImageClip::New();
-    vtkMarchingSquares * mSquares;// = vtkMarchingSquares::New();
-    vtkActor * mSquaresActor;// = vtkActor::New();
-    CreateNewActor(&mSquaresActor, &mSquares, &mClipper, numImage);
-    mSquaresActorList.push_back(mSquaresActor);
-    mSquaresList.push_back(mSquares);
-    mClipperList.push_back(mClipper);
+    CreateNewActor(numImage);
   }
 }
 //------------------------------------------------------------------------------
@@ -186,7 +177,7 @@ void vvImageContour::UpdateWithPreserveMemoryMode() {
   int orientation = ComputeCurrentOrientation();
 
   UpdateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
-  mSquaresActorList[mTSlice]->VisibilityOn();
+  //mSquaresActorList[mTSlice]->VisibilityOn();
 
   if (mPreviousTslice != mTSlice) {
     if (mPreviousTslice != -1) mSquaresActorList[mPreviousTslice]->VisibilityOff();
@@ -244,13 +235,11 @@ clitkExceptionMacro("TODO : not implemented yet");
   if (actor != NULL) {
     mListOfCachedContourActors[orientation][mSlice]->VisibilityOn();
   } else {
-    vtkImageClip * mClipper;
-    vtkMarchingSquares * mSquares;
-    vtkActor * mSquaresActor;
-    CreateNewActor(&mSquaresActor, &mSquares, &mClipper, 0);
-    UpdateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
-    mListOfCachedContourActors[orientation][mSlice] = mSquaresActor;
-    mSquaresActor->VisibilityOn();
+    CreateNewActor(0);
+    //SR: commented out, this code is never reached anyway
+    //UpdateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
+    //mListOfCachedContourActors[orientation][mSlice] = mSquaresActor;
+    //mSquaresActor->VisibilityOn();
   }
 
   if (mListOfCachedContourActors[mPreviousOrientation][mPreviousSlice] != NULL)
@@ -262,27 +251,29 @@ clitkExceptionMacro("TODO : not implemented yet");
 
 
 //------------------------------------------------------------------------------
-void vvImageContour::CreateNewActor(vtkActor ** actor, 
-                                    vtkMarchingSquares ** squares, 
-                                    vtkImageClip ** clipper, 
-                                    int numImage) {
-  vtkSmartPointer<vtkActor> mSquaresActor = (*actor = vtkSmartPointer<vtkActor>::New());
-  vtkSmartPointer<vtkImageClip> mClipper = (*clipper = vtkSmartPointer<vtkImageClip>::New());
-  vtkSmartPointer<vtkMarchingSquares> mSquares = (*squares = vtkSmartPointer<vtkMarchingSquares>::New());
-  vtkSmartPointer<vtkPolyDataMapper> mSquaresMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
+void vvImageContour::CreateNewActor(int numImage) {
+  vtkSmartPointer<vtkActor> squaresActor = vtkSmartPointer<vtkActor>::New();
+  vtkSmartPointer<vtkImageClip> clipper = vtkSmartPointer<vtkImageClip>::New();
+  vtkSmartPointer<vtkMarchingSquares> squares = vtkSmartPointer<vtkMarchingSquares>::New();
+  vtkSmartPointer<vtkPolyDataMapper> squaresMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
 
   if (mHiddenImageIsUsed)
-    mClipper->SetInput(mHiddenImage->GetVTKImages()[0]);
+    clipper->SetInput(mHiddenImage->GetVTKImages()[0]);
   else
-    mClipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
-  mSquares->SetInput(mClipper->GetOutput());
-  mSquaresMapper->SetInput(mSquares->GetOutput());
-  mSquaresMapper->ScalarVisibilityOff();
-  mSquaresActor->SetMapper(mSquaresMapper);
-  mSquaresActor->GetProperty()->SetColor(1.0,0,0);
-  mSquaresActor->SetPickable(0);
-  mSquaresActor->VisibilityOff();
-  mSlicer->GetRenderer()->AddActor(mSquaresActor);
+    clipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
+  squares->SetInput(clipper->GetOutput());
+  squaresMapper->SetInput(squares->GetOutput());
+  squaresMapper->ScalarVisibilityOff();
+  squaresActor->SetMapper(squaresMapper);
+  squaresActor->GetProperty()->SetColor(1.0,0,0);
+  squaresActor->SetPickable(0);
+  squaresActor->VisibilityOff();
+  mSlicer->GetRenderer()->AddActor(squaresActor);
+
+  mSquaresActorList.push_back(squaresActor);
+  mClipperList.push_back(clipper);
+  mSquaresList.push_back(squares);
+  mSquaresMapperList.push_back(squaresMapper);
 }
 //------------------------------------------------------------------------------
 
@@ -333,7 +324,7 @@ void vvImageContour::UpdateActor(vtkActor * actor,
   clipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2],
                                 extent2[3],extent2[4],extent2[5]);
 
-  if (mHiddenImage) delete extent2;
+  if (mHiddenImageIsUsed) delete extent2;
 
   // Move the actor to be visible
   switch (orientation)  {
index 66473d37320063b456d9481c379f32e9f77d0476..2d5ca83cc940a7f64e3e0132701f95be1a63fad6 100644 (file)
@@ -27,12 +27,13 @@ class vtkActor;
 class vvImage;
 
 //------------------------------------------------------------------------------
-class vvImageContour
+class vvImageContour: public itk::LightObject
 {
   //  Q_OBJECT
- public:
-  vvImageContour();
-  ~vvImageContour();
+public:
+  typedef vvImageContour Self;
+  typedef itk::SmartPointer<Self> Pointer;
+  itkNewMacro(Self);
 
   void SetSlicer(vvSlicer * slicer);
   void Update(double value);
@@ -43,7 +44,7 @@ class vvImageContour
   void SetImage(vvImage * image);
   void SetPreserveMemoryModeEnabled(bool b);
 
- protected:
+protected:
   vvSlicer * mSlicer;
   int mSlice;
   int mTSlice;
@@ -55,9 +56,10 @@ class vvImageContour
   bool mDisplayModeIsPreserveMemory;
 
   // For preserveMemory mode
+  std::vector<vtkSmartPointer<vtkActor> > mSquaresActorList;
   std::vector<vtkSmartPointer<vtkImageClip> > mClipperList;
   std::vector<vtkSmartPointer<vtkMarchingSquares> > mSquaresList;
-  std::vector<vtkSmartPointer<vtkActor> > mSquaresActorList;
+  std::vector<vtkSmartPointer<vtkPolyDataMapper> > mSquaresMapperList;
 
   // For fast cache mode
   int mPreviousSlice;
@@ -68,17 +70,15 @@ class vvImageContour
   void InitializeCacheMode();
   void UpdateWithPreserveMemoryMode();
   void UpdateWithFastCacheMode();
-  void CreateNewActor(vtkActor ** actor, 
-                     vtkMarchingSquares ** squares, 
-                      vtkImageClip ** clipper, 
-                      int numImage);
-  void UpdateActor(vtkActor * actor, 
-                  vtkMarchingSquares * squares,
-                  vtkImageClip * clipper, 
-                  double threshold, int orientation, int slice);
+  void CreateNewActor(int numImage);
+  void UpdateActor(vtkActor * actor, vtkMarchingSquares * squares, vtkImageClip * clipper,
+                   double threshold, int orientation, int slice);
   void CreateActor(int orientation, int slice);
   int ComputeCurrentOrientation();
-  
+
+private:
+  vvImageContour();
+  ~vvImageContour();
 }; // end class vvImageContour
 //------------------------------------------------------------------------------
 
index b50d66b3be748c51208c537cfc4d001d4957402e..cbe7d1607e62b63c1bca49cdaeb93fd8cf8ed909 100644 (file)
 #include "vvImage.h"
 #include "vvConstants.h"
 
-class vvImageReader : public QThread {
+class vvImageReader : public itk::LightObject, public QThread {
 
 public:
-    vvImageReader();
-    ~vvImageReader();
+  typedef vvImageReader Self;
+  typedef itk::SmartPointer<Self> Pointer;
+  itkNewMacro(Self);
 
-    void SetInputFilename(const std::string & filename);
-    void SetInputFilenames(const std::vector<std::string> & filenames);
+  void SetInputFilename(const std::string & filename);
+  void SetInputFilenames(const std::vector<std::string> & filenames);
 
-    vvImage::Pointer GetOutput() {
-        return mImage;
-    }
+  vvImage::Pointer GetOutput() {
+      return mImage;
+  }
 
-    std::string GetLastError() {
-        return mLastError;
-    }
+  std::string GetLastError() {
+      return mLastError;
+  }
 
-    void SetSlice(unsigned int i) { mSlice = i; }
+  void SetSlice(unsigned int i) { mSlice = i; }
 
-    //====================================================================
-    // Main function
-    void Update();
-    void Update(LoadedImageType type);
-    void Update(int dim, std::string InputPixelType, LoadedImageType type);
+  //====================================================================
+  // Main function
+  void Update();
+  void Update(LoadedImageType type);
+  void Update(int dim, std::string InputPixelType, LoadedImageType type);
 
 protected:
-    void run();
-    //====================================================================
-    std::vector<std::string> mInputFilenames;
-    ///Method used to load the image, see vvConstants.h for definition
-    LoadedImageType mType;
-    unsigned int mSlice;
-    itk::Command::Pointer mObserver;
-
-    std::string mLastError;
-
-    //====================================================================
-    template<unsigned int VImageDimension>
-    void UpdateWithDim(std::string inputPixelType);
-
-    //====================================================================
-    /*template<unsigned int VImageDimension>
-    void ExtractWithDim(std::string inputPixelType, int slice);*/
-
-    //====================================================================
-    template<class InputPixelType, unsigned int VImageDimension>
-    void UpdateWithDimAndInputPixelType();
-    ///Input dimension and pixel type
-    int mDim;
-    std::string mInputPixelType;
-
-    //====================================================================
-    void ReadNkiImageTransform();
-    void ReadMatImageTransform();
+  void run();
+  //====================================================================
+  std::vector<std::string> mInputFilenames;
+  ///Method used to load the image, see vvConstants.h for definition
+  LoadedImageType mType;
+  unsigned int mSlice;
+  itk::Command::Pointer mObserver;
+
+  std::string mLastError;
+
+  //====================================================================
+  template<unsigned int VImageDimension>
+  void UpdateWithDim(std::string inputPixelType);
+
+  //====================================================================
+  /*template<unsigned int VImageDimension>
+  void ExtractWithDim(std::string inputPixelType, int slice);*/
+
+  //====================================================================
+  template<class InputPixelType, unsigned int VImageDimension>
+  void UpdateWithDimAndInputPixelType();
+  ///Input dimension and pixel type
+  int mDim;
+  std::string mInputPixelType;
+
+  //====================================================================
+  void ReadNkiImageTransform();
+  void ReadMatImageTransform();
 private:
-    vvImage::Pointer mImage;
+  vvImageReader();
+  ~vvImageReader();
 
+  vvImage::Pointer mImage;
 }; // end class vvImageReader
 
 #endif /* end #define CLITKvvImageReader_H */
index 582b0782520be38a468adcf393ed2f7514dd34d4..93bf44f497505e653958961c0d94d105ee9cf0b1 100644 (file)
@@ -18,9 +18,7 @@
 
 // vv
 #include "vvROIActor.h"
-#include "vvImageContour.h"
 #include "vvSlicerManager.h"
-#include "vvBinaryImageOverlayActor.h"
 
 // vtk
 #include <vtkImageActor.h>
@@ -35,8 +33,6 @@
 //------------------------------------------------------------------------------
 vvROIActor::vvROIActor()
 {
-  mImageContour.clear();
-  mOverlayActors.clear();
   mIsVisible = true;
   mIsContourVisible = false;
   mOpacity = 0.7;
@@ -51,8 +47,6 @@ vvROIActor::vvROIActor()
 //------------------------------------------------------------------------------
 vvROIActor::~vvROIActor()
 {
-  for(uint i= 0; i<mImageContour.size(); i++) delete mImageContour[i];
-  for(uint i= 0; i<mOverlayActors.size(); i++) delete mOverlayActors[i];
 }
 //------------------------------------------------------------------------------
 
@@ -82,14 +76,8 @@ void vvROIActor::SetSlicerManager(vvSlicerManager * s) {
 //------------------------------------------------------------------------------
 void vvROIActor::UpdateImage()
 {
-  for(unsigned int i= 0; i<mOverlayActors.size(); i++) {
-    mOverlayActors[i]->HideActors();
-    delete mOverlayActors[i];
-  }
-  for(unsigned int i= 0; i<mImageContour.size(); i++) {
-    mImageContour[i]->HideActors();
-    delete mImageContour[i];
-  }
+  mOverlayActors.clear();
+  mImageContour.clear();
   Initialize(mIsVisible);
   Update(); // No Render
 }
@@ -151,7 +139,7 @@ void vvROIActor::Initialize(bool IsVisible) {
     mOverlayActors.clear();
     for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
 
-      mImageContour.push_back(new vvImageContour);
+      mImageContour.push_back(vvImageContour::New());
       mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
       mImageContour[i]->SetImage(mROI->GetImage());
       mContourColor[0] = mROI->GetDisplayColor()[0];
@@ -164,7 +152,7 @@ void vvROIActor::Initialize(bool IsVisible) {
       mImageContour[i]->SetSlicer(mSlicerManager->GetSlicer(i));
       mImageContour[i]->HideActors();
       
-      mOverlayActors.push_back(new vvBinaryImageOverlayActor);
+      mOverlayActors.push_back(vvBinaryImageOverlayActor::New());
 
       // BG or FG
       if (m_modeBG) {
index 19aca3a4e4af5631fa7422820ee5b280a5b023cc..c690ae085953aa19a49f4b0d7a0aaecd4ad68fcd 100644 (file)
 #ifndef VVROIACTOR_H
 #define VVROIACTOR_H
 
+#include "vvBinaryImageOverlayActor.h"
+#include "vvImageContour.h"
 #include "clitkDicomRT_ROI.h"
 #include <QObject>
 
 class vvSlicerManager;
-class vvImageContour;
-class vvBinaryImageOverlayActor;
 class vtkActor;
 
 //------------------------------------------------------------------------------
@@ -60,8 +60,8 @@ public slots:
  protected:
   clitk::DicomRT_ROI::Pointer mROI;
   vvSlicerManager * mSlicerManager;
-  std::vector<vvImageContour *> mImageContour;
-  std::vector<vvBinaryImageOverlayActor *> mOverlayActors;
+  std::vector<vvImageContour::Pointer> mImageContour;
+  std::vector< vvBinaryImageOverlayActor::Pointer > mOverlayActors;
   
   bool mIsVisible;
   bool mIsContourVisible;
index 758fed79e7a4b44e657b3e7f99bd2b705a3ddb13..8a68f28ff83502573538d11e891751552f4f75eb 100644 (file)
@@ -22,8 +22,6 @@
 #include "vvSlicerManagerCommand.h"
 #include "vvInteractorStyleNavigator.h"
 #include "vvLandmarks.h"
-#include "vvImageReader.h"
-#include "vvImageReader.h"
 #include "vvMesh.h"
 #include "vvImageMapToWLColors.h"
 #include "vvBlendImageActor.h"
@@ -88,18 +86,6 @@ vvSlicerManager::~vvSlicerManager()
     if (mSlicers[i] != NULL)
       mSlicers[i]->Delete();
   }
-  if (mReader) {
-    delete mReader;
-  }
-  if (mVectorReader) {
-    delete mVectorReader;
-  }
-  if (mOverlayReader) {
-    delete mOverlayReader;
-  }
-  if (mFusionReader) {
-    delete mFusionReader;
-  }
   if (mLandmarks)
     delete mLandmarks;
 }
@@ -151,8 +137,8 @@ void vvSlicerManager::ToggleContourSuperposition()
 bool vvSlicerManager::SetImage(std::string filename, LoadedImageType type, int n, unsigned int slice)
 {
   mType = type;
-  if (mReader == NULL)
-    mReader = new vvImageReader;
+  if (mReader.IsNull())
+    mReader = vvImageReader::New();
   std::vector<std::string> filenames;
   filenames.push_back(filename);
   mReader->SetInputFilenames(filenames);
@@ -207,8 +193,8 @@ bool vvSlicerManager::SetImages(std::vector<std::string> filenames,LoadedImageTy
 
   mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
   mFileName = fileWithoutExtension + vtksys::SystemTools::GetFilenameExtension(filenames[0]);
-  if (mReader == NULL)
-    mReader = new vvImageReader;
+  if (mReader.IsNull())
+    mReader = vvImageReader::New();
   mReader->SetInputFilenames(filenames);
   mReader->Update(type);
 
@@ -242,8 +228,8 @@ bool vvSlicerManager::SetOverlay(std::string filename,int dim, std::string compo
     mLastError = " Overlay dimension cannot be greater then reference image!";
     return false;
   }
-  if (mOverlayReader == NULL)
-    mOverlayReader = new vvImageReader;
+  if (mOverlayReader.IsNull())
+    mOverlayReader = vvImageReader::New();
   std::vector<std::string> filenames;
   filenames.push_back(filename);
   mOverlayReader->SetInputFilenames(filenames);
@@ -270,8 +256,8 @@ bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string compon
     mLastError = " Overlay dimension cannot be greater then reference image!";
     return false;
   }
-  if (mFusionReader == NULL)
-    mFusionReader = new vvImageReader;
+  if (mFusionReader.IsNull())
+    mFusionReader = vvImageReader::New();
   std::vector<std::string> filenames;
   filenames.push_back(filename);
   mFusionReader->SetInputFilenames(filenames);
@@ -295,8 +281,8 @@ bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string compon
 //----------------------------------------------------------------------------
 bool vvSlicerManager::SetVF(std::string filename)
 {
-  if (mVectorReader == NULL)
-    mVectorReader = new vvImageReader;
+  if (mVectorReader.IsNull())
+    mVectorReader = vvImageReader::New();
   mVectorReader->SetInputFilename(filename);
   mVectorReader->Update(VECTORFIELD);
   if (mVectorReader->GetLastError().size() != 0) {
@@ -797,25 +783,18 @@ void vvSlicerManager::ReloadVF()
 //----------------------------------------------------------------------------
 void vvSlicerManager::RemoveActor(const std::string& actor_type, int overlay_index)
 {
-  if (actor_type =="overlay") {
-    delete mOverlayReader;
+  if (actor_type =="overlay")
     mOverlayReader = NULL;
-  }
 
-  if (actor_type =="fusion") {
-    delete mFusionReader;
+  if (actor_type =="fusion")
     mFusionReader = NULL;
-  }
 
-  for (unsigned int i = 0; i < mSlicers.size(); i++) {
+  for (unsigned int i = 0; i < mSlicers.size(); i++)
     mSlicers[i]->RemoveActor(actor_type,overlay_index);
-  }
+
   if (actor_type=="vector") {
     mVF=NULL;
-    if (mVectorReader) {
-      delete mVectorReader;
-      mVectorReader=NULL;
-    }
+    mVectorReader=NULL;
   }
 }
 //----------------------------------------------------------------------------
index 345bab8febbe94691d8c62304b45c55622da2cf6..10e9c9d021c2542134a9863913d3c309d2c88c3d 100644 (file)
@@ -40,6 +40,8 @@ class vtkPolyData;
 #include "clitkCommon.h"
 #include "vvImage.h"
 #include "vvMesh.h"
+#include "vvImageReader.h"
+
 class vvSlicer;
 class vvInteractorStyleNavigator;
 class vvImageReader;
@@ -213,12 +215,12 @@ signals :
 
 protected:
   std::vector<vvSlicer*> mSlicers;
-  vvImageReader* mReader;
-  vvImageReader* mOverlayReader;
-  vvImageReader* mFusionReader;
+  vvImageReader::Pointer mReader;
+  vvImageReader::Pointer mOverlayReader;
+  vvImageReader::Pointer mFusionReader;
+  vvImageReader::Pointer mVectorReader;
   vvImage::Pointer mImage;
   vvImage::Pointer mVF;
-  vvImageReader* mVectorReader;
   int mColorMap;
   int mOverlayColor;
 
index 83bf04c59927e0cda9fbb116d0e7bdfcf83ca0b2..325714a99e50a9ea73b29f1ff833a5dfccc9de12 100644 (file)
@@ -212,10 +212,10 @@ void vvToolBinarize::InputIsSelected(vvSlicerManager * m)
 
   // VTK objects for interactive display
   for(int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
-    mImageContour.push_back(new vvImageContour);
+    mImageContour.push_back(vvImageContour::New());
     mImageContour[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
     mImageContour[i]->SetColor(1.0, 0.0, 0.0);
-    mImageContourLower.push_back(new vvImageContour);
+    mImageContourLower.push_back(vvImageContour::New());
     mImageContourLower[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
     mImageContourLower[i]->SetColor(0.0, 0.0, 1.0);
   }
index 4487ae4d86d550f95e229b50a104fd662411e347..7a8140187ac361c70b0e032d804b00d275a9d701 100644 (file)
@@ -61,8 +61,8 @@ class vvToolBinarize:
   virtual void closeEvent(QCloseEvent *event);
   Ui::vvToolBinarize ui;
   args_info_clitkBinarizeImage mArgsInfo;
-  std::vector<vvImageContour*> mImageContour;
-  std::vector<vvImageContour*> mImageContourLower;
+  std::vector<vvImageContour::Pointer> mImageContour;
+  std::vector<vvImageContour::Pointer> mImageContourLower;
   bool mInteractiveDisplayIsEnabled;
 
 }; // end class vvToolBinarize
index c4f36033f9e1d09390560215edb3ded128d2fbbe..2d50d8a6d0b8836020bf196012d8fed2220baf72 100644 (file)
@@ -99,14 +99,8 @@ vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent,
 //------------------------------------------------------------------------------
 vvToolStructureSetManager::~vvToolStructureSetManager()
 {
+  disconnect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree()));
   m_NumberOfTool--;
-
-  std::map<clitk::DicomRT_ROI::Pointer, QTreeWidgetItem *>::iterator it;
-  for (it = mMapROIToTreeWidget.begin(); it!=mMapROIToTreeWidget.end(); it++)
-    delete it->second;
-  for(unsigned int i=0; i< mStructureSetActorsList.size(); i++)
-    delete mStructureSetActorsList[i];
-
 }
 //------------------------------------------------------------------------------
 
@@ -179,7 +173,8 @@ void vvToolStructureSetManager::Open(int type) {
 
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::AddRoiInTreeWidget(clitk::DicomRT_ROI * roi, QTreeWidget * ww) {
-  QTreeWidgetItem * w = new QTreeWidgetItem(ww);
+  mTreeWidgetList.push_back(QSharedPointer<QTreeWidgetItem>(new QTreeWidgetItem(ww)));
+  QTreeWidgetItem * w = mTreeWidgetList.back().data();
   w->setText(0, QString("%1").arg(roi->GetROINumber()));
   w->setText(1, QString("%1").arg(roi->GetName().c_str()));
   QBrush brush(QColor(roi->GetDisplayColor()[0]*255, roi->GetDisplayColor()[1]*255, roi->GetDisplayColor()[2]*255));
@@ -209,7 +204,7 @@ void vvToolStructureSetManager::UpdateStructureSetInTreeWidget(int index, clitk:
 int vvToolStructureSetManager::AddStructureSet(clitk::DicomRT_StructureSet * mStructureSet) {
   // Create actor for this SS
 
-  vvStructureSetActor * mStructureSetActor =  new vvStructureSetActor;
+  QSharedPointer<vvStructureSetActor> mStructureSetActor(new vvStructureSetActor);
   
   mStructureSetActor->SetStructureSet(mStructureSet);
   mStructureSetActor->SetSlicerManager(mCurrentSlicerManager);
@@ -239,7 +234,7 @@ void vvToolStructureSetManager::OpenBinaryImage()
     index = mCurrentStructureSetIndex;
   }
   mCurrentStructureSet = mStructureSetsList[index];
-  mCurrentStructureSetActor = mStructureSetActorsList[index];
+  mCurrentStructureSetActor = mStructureSetActorsList[index].data();
   mCurrentStructureSetIndex = index;
   // Open images
   QString Extensions = "Images files ( *.mhd *.hdr *.his)";
@@ -252,21 +247,21 @@ void vvToolStructureSetManager::OpenBinaryImage()
   for(int i=0; i<filename.size(); i++) {
     // Open Image
     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-    vvImageReader mReader;
+    vvImageReader::Pointer reader = vvImageReader::New();
     std::vector<std::string> filenames;
     filenames.push_back(filename[i].toStdString());
-    mReader.SetInputFilenames(filenames);
-    mReader.Update(IMAGE);
+    reader->SetInputFilenames(filenames);
+    reader->Update(IMAGE);
     QApplication::restoreOverrideCursor();
 
-    if (mReader.GetLastError().size() != 0) {
+    if (reader->GetLastError().size() != 0) {
       std::cerr << "Error while reading " << filename[i].toStdString() << std::endl;
       QString error = "Cannot open file \n";
-      error += mReader.GetLastError().c_str();
+      error += reader->GetLastError().c_str();
       QMessageBox::information(this,tr("Reading problem"),error);
       return;
     }
-    vvImage::Pointer binaryImage = mReader.GetOutput();
+    vvImage::Pointer binaryImage = reader->GetOutput();
     AddImage(binaryImage, filename[i].toStdString(), mBackgroundValueSpinBox->value());
     mOpenedBinaryImage.push_back(binaryImage);
   }
@@ -309,7 +304,7 @@ void vvToolStructureSetManager::AddImage(vvImage * binaryImage, std::string file
     index = mCurrentStructureSetIndex;
   }
   mCurrentStructureSet = mStructureSetsList[index];
-  mCurrentStructureSetActor = mStructureSetActorsList[index];
+  mCurrentStructureSetActor = mStructureSetActorsList[index].data();
   mCurrentStructureSetIndex = index;
 
   // Check Dimension
@@ -584,15 +579,15 @@ void vvToolStructureSetManager::ChangeContourWidth(int n) {
 //------------------------------------------------------------------------------
 void vvToolStructureSetManager::ReloadCurrentROI() {
   // Reload image
-  vvImageReader mReader;
-  mReader.SetInputFilename(mCurrentROI->GetFilename());
-  mReader.Update(IMAGE);
-  if (mReader.GetLastError() != "") {
-    QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), mReader.GetLastError().c_str());
+  vvImageReader::Pointer reader = vvImageReader::New();
+  reader->SetInputFilename(mCurrentROI->GetFilename());
+  reader->Update(IMAGE);
+  if (reader->GetLastError() != "") {
+    QMessageBox::information(mMainWindowBase, tr("Sorry, error. Could not reload"), reader->GetLastError().c_str());
     return;
   }
   mCurrentROI->GetImage()->GetFirstVTKImageData()->ReleaseData();
-  mCurrentROI->SetImage(mReader.GetOutput());
+  mCurrentROI->SetImage(reader->GetOutput());
   
   // Update visu"
   mCurrentROIActor->UpdateImage();
index 7ccb50f89d7ad1de34f43def7af1f677c00245d9..e768691955dcc459d8cfa8b5655543714664b8c1 100644 (file)
@@ -76,9 +76,9 @@ protected:
   bool mIsAllVisibleEnabled;
   int mNumberOfVisibleROI;
   int mNumberOfVisibleContourROI;
-  std::vector<clitk::DicomRT_StructureSet::Pointer >       mStructureSetsList;
-  std::vector<vvStructureSetActor *>               mStructureSetActorsList;
-  std::map<int, QTreeWidgetItem *>                 mMapStructureSetIndexToTreeWidget;
+  std::vector<clitk::DicomRT_StructureSet::Pointer > mStructureSetsList;
+  std::vector< QSharedPointer<vvStructureSetActor> > mStructureSetActorsList;
+  std::vector< QSharedPointer<QTreeWidgetItem> > mTreeWidgetList;
   std::map<clitk::DicomRT_ROI::Pointer, QTreeWidgetItem *> mMapROIToTreeWidget;
   std::map<QTreeWidgetItem *, clitk::DicomRT_ROI::Pointer> mMapTreeWidgetToROI;
   std::vector<int> mLoadedROIIndex;