]> Creatis software - clitk.git/commitdiff
Display a line between Profile points
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Wed, 20 Jan 2016 11:00:11 +0000 (12:00 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Wed, 20 Jan 2016 11:00:11 +0000 (12:00 +0100)
vvSlicer has to inherit from QObject to send signals

vv/CMakeLists.txt
vv/vvSlicer.cxx
vv/vvSlicer.h
vv/vvSlicerManager.cxx
vv/vvToolProfile.cxx
vv/vvToolProfile.h

index 4b0932de656d8fd004d1df5edc918fec74851d67..5b5f7c0a045fdf1beb4fe7938593dc37abf3656b 100644 (file)
@@ -123,6 +123,7 @@ qt5_wrap_cpp(vv_SRCS
   vvHelpDialog.h
   vvQDicomSeriesSelector.h
   vvSlicerManager.h
+  vvSlicer.h
   vvStructureSetActor.h
   vvROIActor.h
   vvToolCreatorBase.h
index d7caa177fcdbd2853fa8230c563a9b0bb960f641..4bad01b0a6819dbcd3d932b0962dc7299ac79572 100644 (file)
@@ -1070,6 +1070,7 @@ int vvSlicer::GetOrientation()
 //----------------------------------------------------------------------------
 void vvSlicer::UpdateDisplayExtent()
 { 
+  emit UpdateDisplayExtentBegin(mSlicerNumber);
   vtkImageData *input = this->GetInput();
   if (!input || !this->ImageActor) {
     return;
@@ -1222,6 +1223,7 @@ void vvSlicer::UpdateDisplayExtent()
       }
     }
   }
+  emit UpdateDisplayExtentEnd(mSlicerNumber);
 }
 //----------------------------------------------------------------------------
 
index 43e08541386109a9f0e0b0b520dae4b51f337ced..e5d79229c29e40a33bf37f005e6400f8beb78369 100644 (file)
@@ -20,6 +20,7 @@
 #include <iostream>
 #include <vector>
 
+#include <QObject>
 #include <QString> //TODO delete
 #include <QMessageBox>
 
@@ -58,8 +59,10 @@ class vtkScalarBarActor;
 class vtkTransform;
 class vtkImageReslice;
 
-class vvSlicer: public vtkImageViewer2
-{
+class vvSlicer: public QObject, public vtkImageViewer2 {
+  
+Q_OBJECT
+
 public:
   static vvSlicer *New();
   vtkTypeMacro(vvSlicer,vtkImageViewer2);
@@ -210,6 +213,13 @@ public:
   void SetRegisterExtent(int [6]);
   void GetRegisterExtent(int [6]);
   
+  void SetSlicerNumber(const int nbSlicer) {mSlicerNumber = nbSlicer;}
+  int GetSlicerNumber() const {return mSlicerNumber;}
+  
+signals:
+  void UpdateDisplayExtentBegin(int);
+  void UpdateDisplayExtentEnd(int);
+  
 protected:
   vvSlicer();
   ~vvSlicer();
@@ -266,6 +276,7 @@ protected:
   vtkSmartPointer<vtkScalarBarActor> legend;
   std::vector<vvMeshActor*> mSurfaceCutActors;
 
+  int mSlicerNumber;
   int mCurrentTSlice;
   int mCurrentFusionTSlice;
   int mCurrentOverlayTSlice;
index b2855d1765316acaf6d42570b6d375a5070f25aa..82d6508bf8445eed080b45706bb645cac50efa4a 100644 (file)
@@ -79,8 +79,10 @@ vvSlicerManager::vvSlicerManager(int numberOfSlicers)
   mLandmarks = NULL;\r
   mLinkedId.resize(0);\r
 \r
-  for ( int i = 0; i < numberOfSlicers; i++)\r
+  for ( int i = 0; i < numberOfSlicers; i++) {\r
     mSlicers.push_back(vtkSmartPointer<vvSlicer>::New());\r
+    mSlicers[i]->SetSlicerNumber(i);\r
+  }\r
   mSelectedSlicer = -1;\r
   \r
   mPreviousSlice.resize(numberOfSlicers, 0);\r
index f0fbf8c1fa2c1dcad1c19e54a958f8333578b1b2..40c6a5d5cb114fa5c58b8db2eeae23d5bcb2e29d 100644 (file)
 #include <vtkRendererCollection.h>
 #include <vtkRenderer.h>
 
+#include <vtkLine.h>
+#include <vtkCellArray.h>
+#include <vtkCellData.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkProperty.h>
+#include <vtkBox.h>
+#include <vtkInformation.h>
+
 //------------------------------------------------------------------------------
 // Create the tool and automagically (I like this word) insert it in
 // the main window menu.
@@ -218,11 +226,23 @@ bool vvToolProfile::isPointsSelected()
   if (mPoint1Selected && mPoint2Selected) {
       mSaveProfileButton->setEnabled(true);
       computeProfile();
-      //DisplayLine();
+      SetPoints();
+      for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
+        DisplayLine(i);
+        connect(mCurrentSlicerManager->GetSlicer(i), SIGNAL(UpdateDisplayExtentBegin(int)), this, SLOT(DeleteLine(int)));
+        connect(mCurrentSlicerManager->GetSlicer(i), SIGNAL(UpdateDisplayExtentEnd(int)), this, SLOT(DisplayLine(int)));
+      }
+      mCurrentSlicerManager->Render();
   }
-  else
+  else {
       mSaveProfileButton->setEnabled(false);
-  
+      for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
+        disconnect(mCurrentSlicerManager->GetSlicer(i), SIGNAL(UpdateDisplayExtentBegin(int)), this, SLOT(DeleteLine(int)));
+        disconnect(mCurrentSlicerManager->GetSlicer(i), SIGNAL(UpdateDisplayExtentEnd(int)), this, SLOT(DisplayLine(int)));
+        mCurrentSlicerManager->GetSlicer(i)->GetRenderer()->RemoveActor(mLineActors[i]);
+      }
+
+  }
   return (mPoint1Selected && mPoint2Selected);
 }
 //------------------------------------------------------------------------------
@@ -309,6 +329,10 @@ void vvToolProfile::cancelPoints()
 //------------------------------------------------------------------------------
 void vvToolProfile::RemoveVTKObjects()
 { 
+  for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
+    mCurrentSlicerManager->GetSlicer(i)->GetRenderer()->RemoveActor(mLineActors[i]);
+  }
+
   if (mPoint1Selected)
     mCurrentSlicerManager->GetLandmarks()->RemoveLandmarkWithLabel("P1", mPoint1[3]);
   if (mPoint2Selected)
@@ -364,7 +388,7 @@ void vvToolProfile::InputIsSelected(vvSlicerManager * m)
   
   mSaveProfileButton->setEnabled(false);
   mTextFileName = "Profile.txt";
-  mImageLine = vvImage::New();
+  InitializeLine();
   
   disconnect(mCurrentSlicerManager, SIGNAL(callAddLandmark(float,float,float,float)), mCurrentSlicerManager, SLOT(AddLandmark(float,float,float,float)));
 }
@@ -511,14 +535,106 @@ void vvToolProfile::SaveAs()
 
 
 //------------------------------------------------------------------------------
-void vvToolProfile::DisplayLine()
+void vvToolProfile::DeleteLine(int slicer)
+{
+  if (!mPoint1Selected && !mPoint2Selected)
+    return;
+  
+  if(mCurrentSlicerManager) {
+      if(mCurrentSlicerManager->GetSelectedSlicer() != -1) {
+          mCurrentSlicerManager->GetSlicer(slicer)->GetRenderer()->RemoveActor(mLineActors[slicer]);
+      }
+   }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::DisplayLine(int slicer)
 { 
   if (!mPoint1Selected && !mPoint2Selected)
     return;
   
   if(mCurrentSlicerManager) {
       if(mCurrentSlicerManager->GetSelectedSlicer() != -1) {
-          double *pos;
+            vtkSmartPointer<vtkBox> clippingBox = vtkSmartPointer<vtkBox>::New();
+            double extent[6];
+            for (int j=0; j<6; ++j) {
+                extent[j] = mCurrentSlicerManager->GetSlicer(slicer)->GetExtent()[j];
+            }
+            extent[2*mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()] = mCurrentSlicerManager->GetSlicer(slicer)->GetSlice();
+            extent[2*mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()+1] = mCurrentSlicerManager->GetSlicer(slicer)->GetSlice();
+            clippingBox->SetBounds(extent);
+            vtkSmartPointer<vtkClipPolyData> clipper = vtkSmartPointer<vtkClipPolyData>::New();
+            clipper->SetClipFunction(clippingBox);
+#if VTK_MAJOR_VERSION <= 5
+            clipper->SetInput(mLinesPolyData);
+#else
+            clipper->SetInputData(mLinesPolyData);
+#endif
+            clipper->InsideOutOff();
+            clipper->Update();        
+            vtkSmartPointer<vtkPolyDataMapper> lineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
+#if VTK_MAJOR_VERSION <= 5
+            lineMapper->SetInput(clipper->GetOutput());
+#else
+            lineMapper->SetInputData(clipper->GetOutput());
+#endif 
+            
+            mLineActors[slicer]->SetMapper(lineMapper);
+            mLineActors[slicer]->GetProperty()->SetOpacity(0.995);
+
+            mCurrentSlicerManager->GetSlicer(slicer)->GetRenderer()->AddActor(mLineActors[slicer]);
+      }
+  }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::InitializeLine()
+{ 
+  if(mCurrentSlicerManager) {
+      
+      mLinesPolyData = vtkSmartPointer<vtkPolyData>::New();
+      
+      vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
+      double pos[4];
+      pos[0] = pos[1] = pos[2] = pos[3] = 0;
+      pts->InsertNextPoint(pos);
+      pts->InsertNextPoint(pos);
+      mLinesPolyData->SetPoints(pts);
+      
+      vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
+      vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
+      line->GetPointIds()->SetId(0, 0); // the second 0 is the index of the 1st point in mLinesPolyData's points (pts)
+      line->GetPointIds()->SetId(1, 1); // the second 1 is the index of the 2nd point in mLinesPolyData's points (pts)
+      lines->InsertNextCell(line);
+      mLinesPolyData->SetLines(lines);
+       
+      unsigned char red[3] = { 255, 0, 0 };
+      vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
+      colors->SetNumberOfComponents(3);
+      colors->InsertNextTupleValue(red);
+      mLinesPolyData->GetCellData()->SetScalars(colors);
+      
+      for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
+        mLineActors.push_back(vtkSmartPointer<vtkActor>::New());
+      }
+   }       
+}    
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::SetPoints()
+{ 
+  if (!mPoint1Selected && !mPoint2Selected)
+    return;
+  
+  if(mCurrentSlicerManager) {
+      if(mCurrentSlicerManager->GetSelectedSlicer() != -1) {
+          /*double *pos;
           pos = new double [4];
           pos[0] = pos[1] = pos[2] = pos[3] = 0;
           
@@ -529,75 +645,25 @@ void vvToolProfile::DisplayLine()
           }
           if (mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() == 4) {
             pos[3] = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetTSlice();
-          }
+          } */
           
-          /*double p0[4];
-          if (mPoint1Selected) {
-              p0[0] = mPoint1[0]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[0] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[0];
-              p0[1] = mPoint1[1]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[1] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[1];
-              p0[2] = mPoint1[2]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[2] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[2];
-              p0[3] = mPoint1[3];
-          }
-          else {
-              p0[0] = mPoint2[0]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[0] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[0];
-              p0[1] = mPoint2[1]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[1] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[1];
-              p0[2] = mPoint2[2]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[2] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[2];
-              p0[3] = mPoint2[3];
-          }
-          vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
-          pts->InsertNextPoint(p0);
-          pts->InsertNextPoint(pos);
-          vtkSmartPointer<vtkPolyData> linesPolyData = vtkSmartPointer<vtkPolyData>::New();
-          linesPolyData->SetPoints(pts);
-          vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
-          line->GetPointIds()->SetId(0, 0); // the second 0 is the index of the Origin in linesPolyData's points
-          line->GetPointIds()->SetId(1, 1); // the second 1 is the index of P0 in linesPolyData's points
-          vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
-          lines->InsertNextCell(line);
-          linesPolyData->SetLines(lines);
-          unsigned char red[3] = { 255, 0, 0 };
-          vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
-          colors->SetNumberOfComponents(3);
-          colors->InsertNextTupleValue(red);
-          linesPolyData->GetCellData()->SetScalars(colors);
-          vtkSmartPointer<vtkPolyDataMapper> lineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
-#if VTK_MAJOR_VERSION <= 5
-          lineMapper->SetInput(linesPolyData);
-#else
-          lineMapper->SetInputData(linesPolyData);
-#endif
-          vtkSmartPointer<vtkActor> lineActor = vtkSmartPointer<vtkActor>::New();
-          lineActor->SetMapper(lineMapper);
-          lineActor->GetProperty()->SetOpacity(0.995);
-        
-          for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
-              mCurrentSlicerManager->GetSlicer(i)->GetRenderer()->AddActor(lineActor);
-          }*/
-          
-          mOverlayActors.clear();
-          for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
-              mOverlayActors.push_back(vvBinaryImageOverlayActor::New());
-              mOverlayActors[i]->SetImage(mImageLine, 0);
-              mOverlayActors[i]->SetColor(1,0,0);
-              mOverlayActors[i]->SetOpacity(0.995);
-              mOverlayActors[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
-              mOverlayActors[i]->Initialize(true);
-              mOverlayActors[i]->SetDepth(1);
-              mOverlayActors[i]->ShowActors();
-              mOverlayActors[i]->UpdateSlice(i, mCurrentSlicerManager->GetSlicer(i)->GetSlice(), false);
-          }
-      }
+          double p0[4], p1[4];
+          p0[0] = mPoint1[0]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[0] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[0];
+          p0[1] = mPoint1[1]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[1] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[1];
+          p0[2] = mPoint1[2]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[2] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[2];
+          p0[3] = mPoint1[3];
+
+          p1[0] = mPoint2[0]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[0] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[0];
+          p1[1] = mPoint2[1]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[1] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[1];
+          p1[2] = mPoint2[2]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[2] + mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[2];
+          p1[3] = mPoint2[3];
+              
+          vtkSmartPointer<vtkPoints> pts = mLinesPolyData->GetPoints();
+          pts->SetPoint(0,p0);
+          pts->SetPoint(1,p1);
+    }
   }
-  mCurrentSlicerManager->Render();
 }
 //------------------------------------------------------------------------------
 
+
index 1f5d6c96ceb5ec077d68c5533f7990e4fb082df7..7467cf4c49455e9c9216a66793ef0d883c9cdc95 100644 (file)
@@ -46,11 +46,13 @@ class vvToolProfile:
 
   //-----------------------------------------------------
   static void Initialize();
+  void InitializeLine();
   void GetArgsInfoFromGUI();
   virtual void InputIsSelected(vvSlicerManager * m);
 
   bool isPointsSelected();
   void computeProfile();
+  void SetPoints();
 
   //-----------------------------------------------------
   public slots:
@@ -62,7 +64,8 @@ class vvToolProfile:
   void selectPoint2();
   void cancelPoints();
   void SaveAs();
-  void DisplayLine();
+  void DisplayLine(int);
+  void DeleteLine(int);
 
  protected:
   void RemoveVTKObjects();
@@ -77,8 +80,8 @@ class vvToolProfile:
   vtkSmartPointer<vtkContextView> mView;
   clitk::ProfileImageGenericFilter::Pointer mFilter;
   std::string mTextFileName;
-  vvImage::Pointer mImageLine;
-  std::vector< vvBinaryImageOverlayActor::Pointer > mOverlayActors;
+  std::vector<vtkSmartPointer<vtkActor> > mLineActors;
+  vtkSmartPointer<vtkPolyData> mLinesPolyData;
 
 
 }; // end class vvToolProfile