From fad7d69a7df544d05deaa19b81bd770aa4c7dd47 Mon Sep 17 00:00:00 2001 From: srit Date: Mon, 28 Mar 2011 13:29:49 +0000 Subject: [PATCH] Memory leak hunt: vvBinaryImageOverlayActor vvImageContour vVImageReader are now itk::LightObject, use QSharedPointer in vvToolStructureSetManager --- vv/vvBinaryImageOverlayActor.h | 11 +++- vv/vvDeformableRegistration.cxx | 8 +-- vv/vvImageContour.cxx | 65 ++++++++++------------ vv/vvImageContour.h | 30 +++++----- vv/vvImageReader.h | 95 ++++++++++++++++---------------- vv/vvROIActor.cxx | 20 ++----- vv/vvROIActor.h | 8 +-- vv/vvSlicerManager.cxx | 51 +++++------------ vv/vvSlicerManager.h | 10 ++-- vv/vvToolBinarize.cxx | 4 +- vv/vvToolBinarize.h | 4 +- vv/vvToolStructureSetManager.cxx | 41 ++++++-------- vv/vvToolStructureSetManager.h | 6 +- 13 files changed, 158 insertions(+), 195 deletions(-) diff --git a/vv/vvBinaryImageOverlayActor.h b/vv/vvBinaryImageOverlayActor.h index 5893158..df9de09 100644 --- a/vv/vvBinaryImageOverlayActor.h +++ b/vv/vvBinaryImageOverlayActor.h @@ -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 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 //------------------------------------------------------------------------------ diff --git a/vv/vvDeformableRegistration.cxx b/vv/vvDeformableRegistration.cxx index a4d36f1..1586808 100644 --- a/vv/vvDeformableRegistration.cxx +++ b/vv/vvDeformableRegistration.cxx @@ -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(CLOCKS_PER_SEC)); - mOutput=reader.GetOutput(); + mOutput = reader->GetOutput(); } diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx index 5e50b06..f0c11b6 100644 --- a/vv/vvImageContour.cxx +++ b/vv/vvImageContour.cxx @@ -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 mSquaresActor = (*actor = vtkSmartPointer::New()); - vtkSmartPointer mClipper = (*clipper = vtkSmartPointer::New()); - vtkSmartPointer mSquares = (*squares = vtkSmartPointer::New()); - vtkSmartPointer mSquaresMapper = vtkSmartPointer::New(); +void vvImageContour::CreateNewActor(int numImage) { + vtkSmartPointer squaresActor = vtkSmartPointer::New(); + vtkSmartPointer clipper = vtkSmartPointer::New(); + vtkSmartPointer squares = vtkSmartPointer::New(); + vtkSmartPointer squaresMapper = vtkSmartPointer::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) { diff --git a/vv/vvImageContour.h b/vv/vvImageContour.h index 66473d3..2d5ca83 100644 --- a/vv/vvImageContour.h +++ b/vv/vvImageContour.h @@ -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 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 > mSquaresActorList; std::vector > mClipperList; std::vector > mSquaresList; - std::vector > mSquaresActorList; + std::vector > 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 //------------------------------------------------------------------------------ diff --git a/vv/vvImageReader.h b/vv/vvImageReader.h index b50d66b..cbe7d16 100644 --- a/vv/vvImageReader.h +++ b/vv/vvImageReader.h @@ -25,63 +25,66 @@ #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 Pointer; + itkNewMacro(Self); - void SetInputFilename(const std::string & filename); - void SetInputFilenames(const std::vector & filenames); + void SetInputFilename(const std::string & filename); + void SetInputFilenames(const std::vector & 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 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 - void UpdateWithDim(std::string inputPixelType); - - //==================================================================== - /*template - void ExtractWithDim(std::string inputPixelType, int slice);*/ - - //==================================================================== - template - void UpdateWithDimAndInputPixelType(); - ///Input dimension and pixel type - int mDim; - std::string mInputPixelType; - - //==================================================================== - void ReadNkiImageTransform(); - void ReadMatImageTransform(); + void run(); + //==================================================================== + std::vector 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 + void UpdateWithDim(std::string inputPixelType); + + //==================================================================== + /*template + void ExtractWithDim(std::string inputPixelType, int slice);*/ + + //==================================================================== + template + 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 */ diff --git a/vv/vvROIActor.cxx b/vv/vvROIActor.cxx index 582b078..93bf44f 100644 --- a/vv/vvROIActor.cxx +++ b/vv/vvROIActor.cxx @@ -18,9 +18,7 @@ // vv #include "vvROIActor.h" -#include "vvImageContour.h" #include "vvSlicerManager.h" -#include "vvBinaryImageOverlayActor.h" // vtk #include @@ -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; iHideActors(); - delete mOverlayActors[i]; - } - for(unsigned int i= 0; iHideActors(); - 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; iGetNumberOfSlicers(); 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) { diff --git a/vv/vvROIActor.h b/vv/vvROIActor.h index 19aca3a..c690ae0 100644 --- a/vv/vvROIActor.h +++ b/vv/vvROIActor.h @@ -19,12 +19,12 @@ #ifndef VVROIACTOR_H #define VVROIACTOR_H +#include "vvBinaryImageOverlayActor.h" +#include "vvImageContour.h" #include "clitkDicomRT_ROI.h" #include class vvSlicerManager; -class vvImageContour; -class vvBinaryImageOverlayActor; class vtkActor; //------------------------------------------------------------------------------ @@ -60,8 +60,8 @@ public slots: protected: clitk::DicomRT_ROI::Pointer mROI; vvSlicerManager * mSlicerManager; - std::vector mImageContour; - std::vector mOverlayActors; + std::vector mImageContour; + std::vector< vvBinaryImageOverlayActor::Pointer > mOverlayActors; bool mIsVisible; bool mIsContourVisible; diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index 758fed7..8a68f28 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -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 filenames; filenames.push_back(filename); mReader->SetInputFilenames(filenames); @@ -207,8 +193,8 @@ bool vvSlicerManager::SetImages(std::vector 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 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 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; } } //---------------------------------------------------------------------------- diff --git a/vv/vvSlicerManager.h b/vv/vvSlicerManager.h index 345bab8..10e9c9d 100644 --- a/vv/vvSlicerManager.h +++ b/vv/vvSlicerManager.h @@ -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 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; diff --git a/vv/vvToolBinarize.cxx b/vv/vvToolBinarize.cxx index 83bf04c..325714a 100644 --- a/vv/vvToolBinarize.cxx +++ b/vv/vvToolBinarize.cxx @@ -212,10 +212,10 @@ void vvToolBinarize::InputIsSelected(vvSlicerManager * m) // VTK objects for interactive display for(int i=0; iGetNumberOfSlicers(); 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); } diff --git a/vv/vvToolBinarize.h b/vv/vvToolBinarize.h index 4487ae4..7a81401 100644 --- a/vv/vvToolBinarize.h +++ b/vv/vvToolBinarize.h @@ -61,8 +61,8 @@ class vvToolBinarize: virtual void closeEvent(QCloseEvent *event); Ui::vvToolBinarize ui; args_info_clitkBinarizeImage mArgsInfo; - std::vector mImageContour; - std::vector mImageContourLower; + std::vector mImageContour; + std::vector mImageContourLower; bool mInteractiveDisplayIsEnabled; }; // end class vvToolBinarize diff --git a/vv/vvToolStructureSetManager.cxx b/vv/vvToolStructureSetManager.cxx index c4f3603..2d50d8a 100644 --- a/vv/vvToolStructureSetManager.cxx +++ b/vv/vvToolStructureSetManager.cxx @@ -99,14 +99,8 @@ vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, //------------------------------------------------------------------------------ vvToolStructureSetManager::~vvToolStructureSetManager() { + disconnect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree())); m_NumberOfTool--; - - std::map::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(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 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 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(); diff --git a/vv/vvToolStructureSetManager.h b/vv/vvToolStructureSetManager.h index 7ccb50f..e768691 100644 --- a/vv/vvToolStructureSetManager.h +++ b/vv/vvToolStructureSetManager.h @@ -76,9 +76,9 @@ protected: bool mIsAllVisibleEnabled; int mNumberOfVisibleROI; int mNumberOfVisibleContourROI; - std::vector mStructureSetsList; - std::vector mStructureSetActorsList; - std::map mMapStructureSetIndexToTreeWidget; + std::vector mStructureSetsList; + std::vector< QSharedPointer > mStructureSetActorsList; + std::vector< QSharedPointer > mTreeWidgetList; std::map mMapROIToTreeWidget; std::map mMapTreeWidgetToROI; std::vector mLoadedROIIndex; -- 2.47.1