]> Creatis software - clitk.git/commitdiff
Add reference contour
authorDavid Sarrut <david.sarrut@gmail.com>
Thu, 12 Jul 2012 10:51:11 +0000 (12:51 +0200)
committerDavid Sarrut <david.sarrut@gmail.com>
Thu, 12 Jul 2012 10:51:11 +0000 (12:51 +0200)
vv/vvToolSegmentation.cxx
vv/vvToolSegmentation.h

index dea3513013aff27801512bdf4143ed40830bd990..0ceeb61ac50537301c16e10fb586435f5b494339 100644 (file)
@@ -72,6 +72,10 @@ vvToolSegmentation::vvToolSegmentation(vvMainWindowBase * parent, Qt::WindowFlag
 //------------------------------------------------------------------------------
 vvToolSegmentation::~vvToolSegmentation()
 {
+  DD("destructor");
+  mRefMaskActor->RemoveActors();
+  QWidget::close();  
+  mCurrentSlicerManager->Render();
 }
 //------------------------------------------------------------------------------
 
@@ -79,6 +83,7 @@ vvToolSegmentation::~vvToolSegmentation()
 //------------------------------------------------------------------------------
 bool vvToolSegmentation::close()
 {
+  DD("close");
   mRefMaskActor->RemoveActors();
   QWidget::close();  
   mCurrentSlicerManager->Render();
@@ -149,31 +154,46 @@ void vvToolSegmentation::OpenBinaryImage()
     return;
   }
 
-  mMaskImage = reader->GetOutput();
-  int dim = mMaskImage->GetNumberOfDimensions();
+  mRefMaskImage = reader->GetOutput();
+  int dim = mRefMaskImage->GetNumberOfDimensions();
   if (dim != 3 ) {
     QMessageBox::information(this,tr("Sorry only 3D yet"), tr("Sorry only 3D yet"));
     close();
     return;
   }
 
+  reader = vvImageReader::New();
+  reader->SetInputFilenames(filenames);
+  reader->Update(vvImageReader::IMAGE);
+  mCurrentMaskImage = reader->GetOutput();
+
   // Add a new roi actor
   mRefMaskActor = QSharedPointer<vvROIActor>(new vvROIActor);
+  mCurrentMaskActor = QSharedPointer<vvROIActor>(new vvROIActor);
   std::vector<double> color;
   color.push_back(1);
   color.push_back(0);
   color.push_back(0);
   clitk::DicomRT_ROI::Pointer roi = clitk::DicomRT_ROI::New();
-  roi->SetFromBinaryImage(mMaskImage, 1, std::string("toto"), color, filename.toStdString());
+  roi->SetFromBinaryImage(mRefMaskImage, 1, std::string("toto"), color, filename.toStdString());
   mRefMaskActor->SetBGMode(true);
   mRefMaskActor->SetROI(roi);
   mRefMaskActor->SetSlicerManager(mCurrentSlicerManager);
   mRefMaskActor->Initialize(10, true);
+  mRefMaskActor->SetContourVisible(true);
+  mRefMaskActor->SetVisible(false);
   mRefMaskActor->Update();
 
+  clitk::DicomRT_ROI::Pointer roi2 = clitk::DicomRT_ROI::New();
+  roi2->SetFromBinaryImage(mCurrentMaskImage, 1, std::string("toto"), color, filename.toStdString());
+  mCurrentMaskActor->SetBGMode(true);
+  mCurrentMaskActor->SetROI(roi2);
+  mCurrentMaskActor->SetSlicerManager(mCurrentSlicerManager);
+  mCurrentMaskActor->Initialize(10, true);
+  mCurrentMaskActor->Update();
+
   // Prepare widget to get keyboard event
-  grabKeyboard();
-  //connect(this, SIGNAL(keyPressEvent(QKeyEvent*)), this, SLOT(keyPressed(QKeyEvent*)));
+  grabKeyboard();  
 }
 //------------------------------------------------------------------------------
 
@@ -193,7 +213,7 @@ void vvToolSegmentation::keyPressEvent(QKeyEvent * event)
   if (event->text() == "s") {
     vvImageWriter::Pointer writer = vvImageWriter::New();
     writer->SetOutputFileName("a.mha");
-    writer->SetInput(mMaskImage);
+    writer->SetInput(mCurrentMaskImage);
     writer->Update();
   }
 }
@@ -206,7 +226,7 @@ void vvToolSegmentation::Erode()
   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
   vtkImageContinuousErode3D* erode = vtkImageContinuousErode3D::New();
   erode->SetKernelSize(mKernelValue,mKernelValue,mKernelValue);
-  vtkImageData* image = mMaskImage->GetVTKImages()[0];
+  vtkImageData* image = mCurrentMaskImage->GetVTKImages()[0];
   erode->SetInput(image);
   erode->Update();
   image->DeepCopy(erode->GetOutput());
@@ -224,7 +244,7 @@ void vvToolSegmentation::Dilate()
   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
   vtkImageContinuousDilate3D* dilate = vtkImageContinuousDilate3D::New();
   dilate->SetKernelSize(mKernelValue,mKernelValue,mKernelValue);
-  vtkImageData* image = mMaskImage->GetVTKImages()[0];
+  vtkImageData* image = mCurrentMaskImage->GetVTKImages()[0];
   dilate->SetInput(image);
   dilate->Update();
   image->DeepCopy(dilate->GetOutput());
@@ -239,16 +259,16 @@ void vvToolSegmentation::Dilate()
 //------------------------------------------------------------------------------
 void vvToolSegmentation::UpdateAndRender()
 {
-  bool visible = mRefMaskActor->IsVisible();
-  bool cvisible = mRefMaskActor->IsContourVisible();
-  mRefMaskActor->SetVisible(false);
-  mRefMaskActor->SetContourVisible(false);
-  mCurrentSlicerManager->Render();
-
-  //mRefMaskActor->RemoveActors();
-  mRefMaskActor->UpdateImage();
-  mRefMaskActor->SetVisible(visible);
-  mRefMaskActor->SetContourVisible(cvisible);
+  bool visible = mCurrentMaskActor->IsVisible();
+  bool cvisible = mCurrentMaskActor->IsContourVisible();
+  mCurrentMaskActor->SetVisible(false);
+  mCurrentMaskActor->SetContourVisible(false);
+  // mCurrentSlicerManager->Render();
+
+  //mCurrentMaskActor->RemoveActors();
+  mCurrentMaskActor->UpdateImage();
+  mCurrentMaskActor->SetVisible(visible);
+  mCurrentMaskActor->SetContourVisible(cvisible);
   mCurrentSlicerManager->Render();
 }
 //------------------------------------------------------------------------------
index 7b8bb8c49ae297d73cb659d780f8079ffc4bfc45..21cdaf65215477824aa83b215e7fc77c855a98ad 100644 (file)
@@ -55,7 +55,9 @@ class vvToolSegmentation:
   // virtual void closeEvent(QCloseEvent *event);
   Ui::vvToolSegmentation ui;
   QSharedPointer<vvROIActor> mRefMaskActor;
-  vvImage::Pointer mMaskImage;
+  QSharedPointer<vvROIActor> mCurrentMaskActor;
+  vvImage::Pointer mRefMaskImage;
+  vvImage::Pointer mCurrentMaskImage;
   int mKernelValue;
 
 }; // end class vvToolSegmentation