From: tbaudier Date: Fri, 5 Feb 2016 15:57:24 +0000 (+0100) Subject: Merge branch 'VTK6_Qt5' into VTK6_Qt5_LineProfile X-Git-Tag: v1.4.0~71 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=eab384b4509ea170c55a307b9eb484e70c636bba;hp=9bca3279547234921425e1311a118e1e3ad39568;p=clitk.git Merge branch 'VTK6_Qt5' into VTK6_Qt5_LineProfile Conflicts: vv/vvToolProfile.cxx --- diff --git a/vv/CMakeLists.txt b/vv/CMakeLists.txt index c49dae5..1d28f84 100644 --- a/vv/CMakeLists.txt +++ b/vv/CMakeLists.txt @@ -125,6 +125,7 @@ qt5_wrap_cpp(vv_SRCS vvHelpDialog.h vvQDicomSeriesSelector.h vvSlicerManager.h + vvSlicer.h vvStructureSetActor.h vvROIActor.h vvToolCreatorBase.h diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index f0b737a..be61470 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -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(); diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index b2f3969..f74bdb8 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; @@ -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(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;iRenderer->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(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; idGetOutput()->GetNumberOfPoints(); id++) { double *position = mLandClipper->GetOutput()->GetPoint(id); diff --git a/vv/vvSlicer.h b/vv/vvSlicer.h index 5b317b4..4fadb3e 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); @@ -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 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/vvSlicerManagerCommand.cxx b/vv/vvSlicerManagerCommand.cxx index 661dd21..07164f6 100644 --- a/vv/vvSlicerManagerCommand.cxx +++ b/vv/vvSlicerManagerCommand.cxx @@ -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) { diff --git a/vv/vvToolProfile.cxx b/vv/vvToolProfile.cxx index ff0e220..e269fff 100644 --- a/vv/vvToolProfile.cxx +++ b/vv/vvToolProfile.cxx @@ -17,6 +17,9 @@ ===========================================================================**/ #include +#include + +#include // vv #include "vvToolProfile.h" @@ -36,6 +39,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. @@ -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 chart = vtkSmartPointer::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 (iGetImage()->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 chart = vtkSmartPointer::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 (iGetImage()->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;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); } //------------------------------------------------------------------------------ @@ -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 table = vtkSmartPointer::New(); vtkSmartPointer arrX = vtkSmartPointer::New(); vtkSmartPointer arrY = vtkSmartPointer::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;iGetNumberOfSlicers(); 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 (iGetNumberOfTuples()) { - 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; jGetImage()->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 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)->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 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; @@ -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 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); //in order to get VTK to turn on the alpha-blending in OpenGL - - 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); //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 pts = mLinesPolyData->GetPoints(); + pts->SetPoint(0,p0); + pts->SetPoint(1,p1); + } } - mCurrentSlicerManager->Render(); } //------------------------------------------------------------------------------ + diff --git a/vv/vvToolProfile.h b/vv/vvToolProfile.h index d59e803..7faf803 100644 --- a/vv/vvToolProfile.h +++ b/vv/vvToolProfile.h @@ -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 mView; clitk::ProfileImageGenericFilter::Pointer mFilter; std::string mTextFileName; - vvImage::Pointer mImageLine; - std::vector< vvBinaryImageOverlayActor::Pointer > mOverlayActors; + std::vector > mLineActors; + vtkSmartPointer mLinesPolyData; }; // end class vvToolProfile