]> Creatis software - clitk.git/commitdiff
Merge branch 'VTK6_Qt5' into VTK6_Qt5_LineProfile
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Fri, 5 Feb 2016 15:57:24 +0000 (16:57 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Fri, 5 Feb 2016 15:57:24 +0000 (16:57 +0100)
Conflicts:
vv/vvToolProfile.cxx

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

index c49dae5f1da0178eea5f052669ababd0d612ba8f..1d28f84d1c0096279fb66be24be3c3ca2207c68c 100644 (file)
@@ -125,6 +125,7 @@ qt5_wrap_cpp(vv_SRCS
   vvHelpDialog.h
   vvQDicomSeriesSelector.h
   vvSlicerManager.h
+  vvSlicer.h
   vvStructureSetActor.h
   vvROIActor.h
   vvToolCreatorBase.h
index f0b737a6bcd0993f6d080269accc5ee44a928b5c..be61470145281553829a7a07d941f71727125983 100644 (file)
@@ -3552,10 +3552,10 @@ void vvMainWindow::ShowLastImage()
 void vvMainWindow::UpdateRenderWindows()
 { 
   for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
-    mSlicerManagers[i]->GetSlicer(0)->UpdateLandmarks();
-    mSlicerManagers[i]->GetSlicer(1)->UpdateLandmarks();
-    mSlicerManagers[i]->GetSlicer(2)->UpdateLandmarks();
-    mSlicerManagers[i]->GetSlicer(3)->UpdateLandmarks();
+      for (unsigned int j = 0; j < 4; ++j) {
+        mSlicerManagers[i]->GetSlicer(j)->RemoveLandmarks();
+        mSlicerManagers[i]->GetSlicer(j)->DisplayLandmarks();
+      }
   }
   if (NOViewWidget->GetRenderWindow()) NOViewWidget->GetRenderWindow()->Render();
   if (NEViewWidget->GetRenderWindow()) NEViewWidget->GetRenderWindow()->Render();
index b2f3969582480229524a31374d405c1cece85189..f74bdb8873559cf29a59548df95df303faacdcc7 100644 (file)
@@ -1070,6 +1070,7 @@ int vvSlicer::GetOrientation()
 //----------------------------------------------------------------------------
 void vvSlicer::UpdateDisplayExtent()
 { 
+  emit UpdateDisplayExtentBegin(mSlicerNumber);
   vtkImageData *input = this->GetInput();
   if (!input || !this->ImageActor) {
     return;
@@ -1190,17 +1191,19 @@ void vvSlicer::UpdateDisplayExtent()
   }
   else if(mVF)
     mVFActor->SetVisibility(false);
+    
+    
+    double boundsT [6];
+      for(unsigned int i=0; i<6; i++)
+        boundsT[i] = ImageActor->GetBounds()[i];
+      boundsT[ this->SliceOrientation*2   ] = ImageActor->GetBounds()[ this->SliceOrientation*2  ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
+      boundsT[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
+
 
   // Landmarks actor
   if (mLandActor) {
     if (mClipBox) {
-      double bounds [6];
-      for(unsigned int i=0; i<6; i++)
-        bounds[i] = ImageActor->GetBounds()[i];
-      bounds[ this->SliceOrientation*2   ] = ImageActor->GetBounds()[ this->SliceOrientation*2  ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
-      bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
-      mClipBox->SetBounds(bounds);
-      UpdateLandmarks();
+      RemoveLandmarks();
     }
     
     position[this->SliceOrientation] = offset;
@@ -1225,7 +1228,14 @@ void vvSlicer::UpdateDisplayExtent()
         cam->SetClippingRange(range - sumSpacing, range + sumSpacing);
       }
     }
+    
+    if (mLandActor) {
+        if (mClipBox) {
+            DisplayLandmarks();
+        }
+    }
   }
+  emit UpdateDisplayExtentEnd(mSlicerNumber);
 }
 //----------------------------------------------------------------------------
 
@@ -1757,8 +1767,10 @@ void vvSlicer::Render()
 #endif
     mFusionMapper->Update();
   }
-  if (mLandMapper)
-    UpdateLandmarks();
+  if (mLandMapper) {
+    RemoveLandmarks();
+    DisplayLandmarks();
+  }
 
     this->GetRenderWindow()->Render();
 }
@@ -1778,24 +1790,43 @@ void vvSlicer::UpdateCursorPosition()
 
 
 //----------------------------------------------------------------------------
-void vvSlicer::UpdateLandmarks()
+void vvSlicer::RemoveLandmarks()
 { 
   vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
   if (pd->GetPoints()) {
-    //mLandGlyph->SetRange(0,1);
-    //mLandGlyph->Modified();
-    //mLandGlyph->Update();
 
-    mClipBox->Modified();
-    mLandClipper->Update();
-    mLandMapper->Update();
-    //Let's add the captions
     //First remove all captions:
     for(unsigned int i=0;i<mLandLabelActors.size();i++) {
        this->Renderer->RemoveActor2D(mLandLabelActors[i]);
        //allActors2D->Remove (mLandLabelActors[i]);
     }
     mLandLabelActors.clear();
+  }
+}
+//----------------------------------------------------------------------------
+
+
+//----------------------------------------------------------------------------
+void vvSlicer::DisplayLandmarks()
+{ 
+
+  double bounds [6];
+  for(unsigned int i=0; i<6; i++)
+    bounds[i] = ImageActor->GetBounds()[i];
+  bounds[ this->SliceOrientation*2   ] = ImageActor->GetBounds()[ this->SliceOrientation*2  ]-fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
+  bounds[ this->SliceOrientation*2+1 ] = ImageActor->GetBounds()[ this->SliceOrientation*2+1 ]+fabs(this->GetInput()->GetSpacing()[this->SliceOrientation]);
+  mClipBox->SetBounds(bounds);
+
+
+  vtkPolyData *pd = static_cast<vtkPolyData*>(mLandClipper->GetInput());
+  if (pd->GetPoints()) {
+    //mLandGlyph->SetRange(0,1);
+    //mLandGlyph->Modified();
+    //mLandGlyph->Update();
+
+    mClipBox->Modified();
+    mLandClipper->Update();
+    mLandMapper->Update();
     //Next add the captions to the displayed points
     for (vtkIdType id=0; id<mLandClipper->GetOutput()->GetNumberOfPoints(); id++) {
          double *position = mLandClipper->GetOutput()->GetPoint(id);
index 5b317b40c74b4df4c312e7d3bcd691a95388c03a..4fadb3e775023661c0689b07e7a5f9075dce6324 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);
@@ -167,7 +170,8 @@ public:
 
   void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform);
 
-  void UpdateLandmarks();
+  void RemoveLandmarks();
+  void DisplayLandmarks();
   void ForceUpdateDisplayExtent();
 
   int* GetDisplayExtent();
@@ -210,6 +214,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 +277,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 661dd21141ec5998bb51ffffa4f7437ede99c4e7..07164f69ad56ed1a2073282fe3a235dc92a8fba5 100644 (file)
@@ -383,7 +383,8 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
       if (newLandmark) {
         this->SM->AddNewLandmark(xWorld,yWorld,zWorld,
                               this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
-        this->SM->GetSlicer(VisibleInWindow)->UpdateLandmarks();
+        this->SM->GetSlicer(VisibleInWindow)->RemoveLandmarks();
+        //this->SM->GetSlicer(VisibleInWindow)->DisplayLandmarks();
         this->SM->Render();
       }
       if (event == vtkCommand::PickEvent || event == vtkCommand::StartPickEvent) {
index ff0e220a7e9a70b81cee564d8eb08dee4ea44201..e269fff7aeacbd9f65c1a8fd259a747ee37650d8 100644 (file)
@@ -17,6 +17,9 @@
   ===========================================================================**/
 
 #include <QFileDialog>
+#include <QShortcut>
+
+#include <algorithm>
 
 // vv
 #include "vvToolProfile.h"
 #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.
@@ -63,6 +74,13 @@ vvToolProfile::vvToolProfile(vvMainWindowBase * parent, Qt::WindowFlags f)
 { 
   // GUI Initialization
   Ui_vvToolProfile::setupUi(mToolWidget);
+  
+  QShortcut *shortcutPoint1 = new QShortcut(QKeySequence("Ctrl+1"), parent);
+  shortcutPoint1->setContext(Qt::ApplicationShortcut);
+  QObject::connect(shortcutPoint1, SIGNAL(activated()), this, SLOT(selectPoint1()));
+  QShortcut *shortcutPoint2 = new QShortcut(QKeySequence("Ctrl+2"), parent);
+  shortcutPoint2->setContext(Qt::ApplicationShortcut);
+  QObject::connect(shortcutPoint2, SIGNAL(activated()), this, SLOT(selectPoint2()));
 
   // Connect signals & slots
   connect(mSelectPoint1Button, SIGNAL(clicked()), this, SLOT(selectPoint1()));
@@ -99,7 +117,8 @@ vvToolProfile::vvToolProfile(vvMainWindowBase * parent, Qt::WindowFlags f)
 //------------------------------------------------------------------------------
 vvToolProfile::~vvToolProfile()
 { 
-  connect(mCurrentSlicerManager, SIGNAL(callAddLandmark(float,float,float,float)), mCurrentSlicerManager, SLOT(AddLandmark(float,float,float,float)));
+  delete [] mPoint1;
+  delete [] mPoint2;
 }
 //------------------------------------------------------------------------------
 
@@ -109,6 +128,7 @@ void vvToolProfile::selectPoint1()
 {
   QString position = "";
   
+  if(mCurrentSlicerManager) {
     if (mPoint1Selected) {
       ProfileWidget->hide();
       vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
@@ -123,27 +143,23 @@ void vvToolProfile::selectPoint1()
   }
   
   mPoint1Selected = false;
-  if(mCurrentSlicerManager) {
+
       if(mCurrentSlicerManager->GetSelectedSlicer() != -1) {
           double *pos;
-          int *index;
           pos = new double [4];
           pos[0] = pos[1] = pos[2] = pos[3] = 0;
-          index = new int [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
           
           int i(0);
           while (i<mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() && i<3) {
             pos[i] = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[i];
-            index[i] = (int) (pos[i] - mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[i])/mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[i];
             position += QString::number(pos[i],'f',1) + " ";
-            mPoint1[i] = index[i];
+            mPoint1[i] = round((pos[i] - mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[i])/mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[i]);
             ++i;
           }
           if (mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() == 4) {
             pos[3] = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetTSlice();
-            index[3] = (int)pos[3];
             position += QString::number(pos[3],'f',1) + " ";
-            mPoint1[3] = index[3];
+            mPoint1[3] = round(pos[3]);
           }
           mPoint1Selected = true;
           mCurrentSlicerManager->AddLandmarkProfile(pos[0], pos[1], pos[2], pos[3]);
@@ -164,6 +180,7 @@ void vvToolProfile::selectPoint2()
 {
   QString position = "";
   
+  if(mCurrentSlicerManager) {
   if (mPoint2Selected) {
       ProfileWidget->hide();
       vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
@@ -178,27 +195,22 @@ void vvToolProfile::selectPoint2()
   }
   
   mPoint2Selected = false;
-  if(mCurrentSlicerManager) {
       if(mCurrentSlicerManager->GetSelectedSlicer() != -1) {
           double *pos;
-          int *index;
           pos = new double [4];
           pos[0] = pos[1] = pos[2] = pos[3] = 0;;
-          index = new int [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
           
           int i(0);
           while (i<mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() &&i<3) {
             pos[i] = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[i];
-            index[i] = (int) (pos[i] - mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[i])/mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[i];
             position += QString::number(pos[i],'f',1) + " ";
-            mPoint2[i] = index[i];
+            mPoint2[i] = round((pos[i] - mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[i])/mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[i]);
             ++i;
           }
           if (mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() == 4) {
             pos[3] = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetTSlice();
-            index[3] = (int)pos[3];
             position += QString::number(pos[3],'f',1) + " ";
-            mPoint2[3] = index[3];
+            mPoint2[3] = round(pos[3]);
           }
           mPoint2Selected = true;
           mCurrentSlicerManager->AddLandmarkProfile(pos[0], pos[1], pos[2], pos[3]);
@@ -219,11 +231,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);
 }
 //------------------------------------------------------------------------------
@@ -233,17 +257,16 @@ bool vvToolProfile::isPointsSelected()
 void vvToolProfile::computeProfile()
 {
     if (!mCurrentSlicerManager) close();
-
     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     GetArgsInfoFromGUI();
     ProfileWidget->hide();
-    
+   
     // Main filter
     mFilter->SetInputVVImage(mCurrentImage);
     mFilter->SetArgsInfo(mArgsInfo);
     mFilter->Update();
-    //mImageLine = mFilter->GetOutputVVImage();
     
+    //Creation of the XY chart
     vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New();
     vtkSmartPointer<vtkFloatArray> arrX = vtkSmartPointer<vtkFloatArray>::New();
     vtkSmartPointer<vtkFloatArray> arrY = vtkSmartPointer<vtkFloatArray>::New();
@@ -251,6 +274,7 @@ void vvToolProfile::computeProfile()
     arrY = mFilter->GetArrayY();
     arrX->SetName("Distance (mm)");
     arrY->SetName("Intensity");
+    
     table->AddColumn(arrX);
     table->AddColumn(arrY);
     
@@ -312,6 +336,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)
@@ -320,9 +348,6 @@ void vvToolProfile::RemoveVTKObjects()
     
   if (mCurrentSlicerManager)
     mCurrentSlicerManager->Render();
-    
-  delete [] mPoint1;
-  delete [] mPoint2;
 }
 //------------------------------------------------------------------------------
 
@@ -331,6 +356,8 @@ void vvToolProfile::RemoveVTKObjects()
 bool vvToolProfile::close()
 { 
   //RemoveVTKObjects();
+  
+  connect(mCurrentSlicerManager, SIGNAL(callAddLandmark(float,float,float,float)), mCurrentSlicerManager, SLOT(AddLandmark(float,float,float,float)));
   return vvToolWidgetBase::close();
 }
 //------------------------------------------------------------------------------
@@ -367,7 +394,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)));
 }
@@ -403,6 +430,8 @@ void vvToolProfile::GetArgsInfoFromGUI()
 
   mArgsInfo.input_arg = new char;
   mArgsInfo.output_arg = new char;
+  
+
 }
 //------------------------------------------------------------------------------
 
@@ -410,7 +439,7 @@ void vvToolProfile::GetArgsInfoFromGUI()
 //------------------------------------------------------------------------------
 void vvToolProfile::apply()
 { 
-  reject();
+  close();
 }
 //------------------------------------------------------------------------------
 
@@ -480,7 +509,7 @@ void vvToolProfile::SaveAs()
         fileOpen << endl;
    
         while (i<arrX->GetNumberOfTuples()) {
-            fileOpen << arrX->GetTuple(i)[0] << "\t" << arrY->GetTuple(i)[0] << "\t" ;
+            fileOpen << i << "\t" << arrY->GetTuple(i)[0] << "\t" ;
       
             coords->GetTuple(i, tuple);
             for (int j=0; j<mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() ; ++j) {
@@ -514,14 +543,109 @@ 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;
+          if (std::min(mPoint1[mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()],mPoint2[mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()]) <= mCurrentSlicerManager->GetSlicer(slicer)->GetSlice() && std::max(mPoint1[mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()],mPoint2[mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()]) >= mCurrentSlicerManager->GetSlicer(slicer)->GetSlice()) {
+            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)->GetImageActor()->GetBounds()[ mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()*2 ]-fabs(mCurrentSlicerManager->GetSlicer(slicer)->GetInput()->GetSpacing()[mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()]);
+            extent[2*mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()+1] = mCurrentSlicerManager->GetSlicer(slicer)->GetImageActor()->GetBounds()[ mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()*2+1 ]+fabs(mCurrentSlicerManager->GetSlicer(slicer)->GetInput()->GetSpacing()[mCurrentSlicerManager->GetSlicer(slicer)->GetOrientation()]);
+            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;
           
@@ -532,75 +656,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);  //in order to get VTK to turn on the alpha-blending in OpenGL
-        
-          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); //in order to get VTK to turn on the alpha-blending in OpenGL
-              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 d59e8035e0f3f1158d2fab1048f0a85e4e7e5411..7faf8035618e8744d5520c655bece0e9c9576608 100644 (file)
@@ -51,11 +51,13 @@ class vvToolProfile:
 
   //-----------------------------------------------------
   static void Initialize();
+  void InitializeLine();
   void GetArgsInfoFromGUI();
   virtual void InputIsSelected(vvSlicerManager * m);
 
   bool isPointsSelected();
   void computeProfile();
+  void SetPoints();
 
   //-----------------------------------------------------
   public slots:
@@ -67,7 +69,8 @@ class vvToolProfile:
   void selectPoint2();
   void cancelPoints();
   void SaveAs();
-  void DisplayLine();
+  void DisplayLine(int);
+  void DeleteLine(int);
 
  protected:
   void RemoveVTKObjects();
@@ -82,8 +85,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