From b77f305379850fd14f1d4fcda09d2f2a102b23d4 Mon Sep 17 00:00:00 2001 From: maxime Pech Date: Thu, 26 May 2011 15:17:03 +0200 Subject: [PATCH] fix crash due to clicking the reload button when we have a cropTool popup opened --- vv/vvMainWindow.cxx | 13 ++++++++----- vv/vvSlicer.cxx | 29 ++++++++-------------------- vv/vvSlicer.h | 6 +++++- vv/vvToolCropImage.cxx | 44 ++++++++++++++++++------------------------ 4 files changed, 40 insertions(+), 52 deletions(-) diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 995d3de..5353b6d 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -1614,15 +1614,18 @@ void vvMainWindow::ReloadImage(QTreeWidgetItem* item, int column) int index = GetSlicerIndexFromItem(item); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QString role=item->data(1,Qt::UserRole).toString(); - if ( role == "vector") + if ( role == "vector"){ mSlicerManagers[index]->ReloadVF(); - else if (role == "overlay") + } + else if (role == "overlay"){ mSlicerManagers[index]->ReloadOverlay(); - else if (role == "fusion") + } + else if (role == "fusion"){ mSlicerManagers[index]->ReloadFusion(); - else + } + else{ mSlicerManagers[index]->Reload(); - + } // Update view and info ImageInfoChanged(); mSlicerManagers[index]->Render(); diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index 47c2afd..6fd75df 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -67,24 +67,17 @@ #include #include -// template -// void print_vector(const char* pmsg, T* pvec) -// { -// std::cout << pmsg << ": "; -// for (unsigned int i = 0; i < dim; i++) -// std::cout << pvec[i] << " "; -// std::cout << std::endl; -// } - - vtkCxxRevisionMacro(vvSlicer, "DummyRevision"); vtkStandardNewMacro(vvSlicer); - +static void copyExtent(int* in, int* to){ + for(int i=0; i<6; ++i) to[i]=in[i]; +} //------------------------------------------------------------------------------ vvSlicer::vvSlicer() { this->UnInstallPipeline(); mImage = NULL; + mReducedExtent = new int[6]; mCurrentTSlice = 0; mUseReducedExtent = false; @@ -221,7 +214,7 @@ void vvSlicer::EnableReducedExtent(bool b) //------------------------------------------------------------------------------ void vvSlicer::SetReducedExtent(int * ext) { - mReducedExtent = ext; + copyExtent(ext, mReducedExtent); } //------------------------------------------------------------------------------ @@ -299,6 +292,7 @@ vvSlicer::~vvSlicer() for (std::vector::iterator i=mSurfaceCutActors.begin(); i!=mSurfaceCutActors.end(); i++) delete (*i); + delete [] mReducedExtent; } //------------------------------------------------------------------------------ @@ -771,8 +765,7 @@ void vvSlicer::AdjustResliceToSliceOrientation(vtkImageReslice *reslice) //------------------------------------------------------------------------------ //---------------------------------------------------------------------------- -int * vvSlicer::GetExtent() -{ +int * vvSlicer::GetExtent(){ int *w_ext; if (mUseReducedExtent) { w_ext = mReducedExtent; @@ -801,13 +794,7 @@ void vvSlicer::UpdateDisplayExtent() // Local copy of extent int w_ext[6]; - for(unsigned int i=0; i<6; i++){ - if (mUseReducedExtent) - w_ext[i] = mReducedExtent[i]; - else - w_ext[i] = input->GetWholeExtent()[i]; - } - + copyExtent(GetExtent(), w_ext); // Set slice value w_ext[ this->SliceOrientation*2 ] = this->Slice; w_ext[ this->SliceOrientation*2+1 ] = this->Slice; diff --git a/vv/vvSlicer.h b/vv/vvSlicer.h index 0246723..95ec75e 100644 --- a/vv/vvSlicer.h +++ b/vv/vvSlicer.h @@ -166,7 +166,11 @@ public: virtual void SetColorWindow(double s); virtual void SetColorLevel(double s); - + /** + * When it is enabled, beware of a call to GetExtent. + * we must have setted mReducedExtent otherwhise random values + * are returned by GetExtent + * */ void EnableReducedExtent(bool b); void SetReducedExtent(int * ext); diff --git a/vv/vvToolCropImage.cxx b/vv/vvToolCropImage.cxx index 41bb0ce..9d6d891 100644 --- a/vv/vvToolCropImage.cxx +++ b/vv/vvToolCropImage.cxx @@ -55,12 +55,6 @@ vvToolCropImage::vvToolCropImage(vvMainWindowBase * parent, Qt::WindowFlags f): // GUI Initialization Ui_vvToolCropImage::setupUi(mToolWidget); - // mTLabel2->setHidden(false); - // tminSlider->setHidden(false); - // tmaxSlider->setHidden(false); - // spin_tmin->setHidden(false); - // spin_tmax->setHidden(false); - // mLabelTimeCropping->setHidden(false); mTLabel1->setHidden(true); mTLabel2->setHidden(true); tminSlider->setHidden(true); @@ -80,6 +74,10 @@ vvToolCropImage::vvToolCropImage(vvMainWindowBase * parent, Qt::WindowFlags f): mSliders[zmax]=zmaxSlider; mSliders[tmin]=tminSlider; mSliders[tmax]=tmaxSlider; + + // Record initial extend + mReducedExtent = new int[6]; + mInitialExtent = new int[6]; } //------------------------------------------------------------------------------ @@ -87,7 +85,8 @@ vvToolCropImage::vvToolCropImage(vvMainWindowBase * parent, Qt::WindowFlags f): //------------------------------------------------------------------------------ vvToolCropImage::~vvToolCropImage() { - + delete [] mReducedExtent; + delete [] mInitialExtent; } //------------------------------------------------------------------------------ @@ -96,11 +95,13 @@ vvToolCropImage::~vvToolCropImage() void vvToolCropImage::closeEvent(QCloseEvent *event) { if(mCurrentSlicerManager){ - // Reset extends - for(int i=0; iaccept(); + vvToolWidgetBase::closeEvent(event); } //------------------------------------------------------------------------------ @@ -173,16 +174,17 @@ void vvToolCropImage::InputIsSelected(vvSlicerManager * slicer) spin_zmax->setHidden(true); } - // Record initial extend - mReducedExtent = new int[mExtentSize]; - mInitialExtent = new int[mExtentSize]; - mReducedExtent = mCurrentSlicerManager->GetImage()->GetFirstVTKImageData()->GetWholeExtent(); - for(int i=0; iGetFirstVTKImageData()->GetWholeExtent(); + for(int i=0; i<6; i++){ + mInitialExtent[i] = a[i]; + mReducedExtent[i] = a[i]; + } for(int i=0; iGetNumberOfSlicers(); i++) { mCurrentSlicerManager->GetSlicer(i)->EnableReducedExtent(true); + mCurrentSlicerManager->GetSlicer(i)->SetReducedExtent(mInitialExtent); } - // Set initial sliders values +// Set initial sliders values std::vector imsize = mCurrentSlicerManager->GetImage()->GetSize(); for(int dim=0; dimGetDimension() && dim<3; ++dim){ mSliders[dim*2]->setMaximum(imsize[dim]-1); @@ -215,14 +217,6 @@ void vvToolCropImage::InputIsSelected(vvSlicerManager * slicer) signalMapper->setMapping(mSliders[i], i); connect(mSliders[i], SIGNAL(valueChanged(int)), signalMapper, SLOT(map())); } - - - - - // connect(mCurrentSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateExtent())); - //connect(mCurrentSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateExtent())); - - // connect(mIntensitySlider, SIGNAL(valueChanged(double)), this, SLOT(autoCropValueChanged(double))); UpdateExtent(); } //------------------------------------------------------------------------------ -- 2.47.1