From 8e35d3afc7b626ac517905e7f8b846d94894110c Mon Sep 17 00:00:00 2001 From: tbaudier Date: Wed, 20 Jan 2016 12:00:11 +0100 Subject: [PATCH] Display a line between Profile points vvSlicer has to inherit from QObject to send signals --- vv/CMakeLists.txt | 1 + vv/vvSlicer.cxx | 2 + vv/vvSlicer.h | 15 ++- vv/vvSlicerManager.cxx | 4 +- vv/vvToolProfile.cxx | 212 +++++++++++++++++++++++++++-------------- vv/vvToolProfile.h | 9 +- 6 files changed, 164 insertions(+), 79 deletions(-) diff --git a/vv/CMakeLists.txt b/vv/CMakeLists.txt index 4b0932d..5b5f7c0 100644 --- a/vv/CMakeLists.txt +++ b/vv/CMakeLists.txt @@ -123,6 +123,7 @@ qt5_wrap_cpp(vv_SRCS vvHelpDialog.h vvQDicomSeriesSelector.h vvSlicerManager.h + vvSlicer.h vvStructureSetActor.h vvROIActor.h vvToolCreatorBase.h diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index d7caa17..4bad01b 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -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); } //---------------------------------------------------------------------------- diff --git a/vv/vvSlicer.h b/vv/vvSlicer.h index 43e0854..e5d7922 100644 --- a/vv/vvSlicer.h +++ b/vv/vvSlicer.h @@ -20,6 +20,7 @@ #include #include +#include #include //TODO delete #include @@ -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 legend; std::vector mSurfaceCutActors; + int mSlicerNumber; int mCurrentTSlice; int mCurrentFusionTSlice; int mCurrentOverlayTSlice; diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index b2855d1..82d6508 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -79,8 +79,10 @@ vvSlicerManager::vvSlicerManager(int numberOfSlicers) mLandmarks = NULL; mLinkedId.resize(0); - for ( int i = 0; i < numberOfSlicers; i++) + for ( int i = 0; i < numberOfSlicers; i++) { mSlicers.push_back(vtkSmartPointer::New()); + mSlicers[i]->SetSlicerNumber(i); + } mSelectedSlicer = -1; mPreviousSlice.resize(numberOfSlicers, 0); diff --git a/vv/vvToolProfile.cxx b/vv/vvToolProfile.cxx index f0fbf8c..40c6a5d 100644 --- a/vv/vvToolProfile.cxx +++ b/vv/vvToolProfile.cxx @@ -35,6 +35,14 @@ #include #include +#include +#include +#include +#include +#include +#include +#include + //------------------------------------------------------------------------------ // 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;iGetNumberOfSlicers(); 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;iGetNumberOfSlicers(); 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;iGetNumberOfSlicers(); 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 clippingBox = vtkSmartPointer::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 clipper = vtkSmartPointer::New(); + clipper->SetClipFunction(clippingBox); +#if VTK_MAJOR_VERSION <= 5 + clipper->SetInput(mLinesPolyData); +#else + clipper->SetInputData(mLinesPolyData); +#endif + clipper->InsideOutOff(); + clipper->Update(); + vtkSmartPointer lineMapper = vtkSmartPointer::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::New(); + + vtkSmartPointer pts = vtkSmartPointer::New(); + double pos[4]; + pos[0] = pos[1] = pos[2] = pos[3] = 0; + pts->InsertNextPoint(pos); + pts->InsertNextPoint(pos); + mLinesPolyData->SetPoints(pts); + + vtkSmartPointer lines = vtkSmartPointer::New(); + vtkSmartPointer line = vtkSmartPointer::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 colors = vtkSmartPointer::New(); + colors->SetNumberOfComponents(3); + colors->InsertNextTupleValue(red); + mLinesPolyData->GetCellData()->SetScalars(colors); + + for(int i=0;iGetNumberOfSlicers(); i++) { + mLineActors.push_back(vtkSmartPointer::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 pts = vtkSmartPointer::New(); - pts->InsertNextPoint(p0); - pts->InsertNextPoint(pos); - - vtkSmartPointer linesPolyData = vtkSmartPointer::New(); - linesPolyData->SetPoints(pts); - - vtkSmartPointer line = vtkSmartPointer::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 lines = vtkSmartPointer::New(); - lines->InsertNextCell(line); - - linesPolyData->SetLines(lines); - - unsigned char red[3] = { 255, 0, 0 }; - - vtkSmartPointer colors = vtkSmartPointer::New(); - colors->SetNumberOfComponents(3); - colors->InsertNextTupleValue(red); - - linesPolyData->GetCellData()->SetScalars(colors); - - - vtkSmartPointer lineMapper = vtkSmartPointer::New(); -#if VTK_MAJOR_VERSION <= 5 - lineMapper->SetInput(linesPolyData); -#else - lineMapper->SetInputData(linesPolyData); -#endif - vtkSmartPointer lineActor = vtkSmartPointer::New(); - lineActor->SetMapper(lineMapper); - lineActor->GetProperty()->SetOpacity(0.995); - - for(int i=0;iGetNumberOfSlicers(); i++) { - mCurrentSlicerManager->GetSlicer(i)->GetRenderer()->AddActor(lineActor); - }*/ - - mOverlayActors.clear(); - for(int i=0;iGetNumberOfSlicers(); 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 pts = mLinesPolyData->GetPoints(); + pts->SetPoint(0,p0); + pts->SetPoint(1,p1); + } } - mCurrentSlicerManager->Render(); } //------------------------------------------------------------------------------ + diff --git a/vv/vvToolProfile.h b/vv/vvToolProfile.h index 1f5d6c9..7467cf4 100644 --- a/vv/vvToolProfile.h +++ b/vv/vvToolProfile.h @@ -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 mView; clitk::ProfileImageGenericFilter::Pointer mFilter; std::string mTextFileName; - vvImage::Pointer mImageLine; - std::vector< vvBinaryImageOverlayActor::Pointer > mOverlayActors; + std::vector > mLineActors; + vtkSmartPointer mLinesPolyData; }; // end class vvToolProfile -- 2.47.1