From 1cc90963e0fdb6e162a3858e4f4f5dd0d41c2939 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Tue, 24 Jan 2017 15:59:06 +0100 Subject: [PATCH] Update Landmark coordinates with transformation matrix --- vv/qt_ui/vvLandmarksPanel.ui | 33 ++++++++++++++++++++++----------- vv/vvLandmarks.cxx | 33 +++++++++++++++++++++++++++++++++ vv/vvLandmarks.h | 3 +++ vv/vvLandmarksPanel.cxx | 9 +++++++++ vv/vvLandmarksPanel.h | 2 ++ vv/vvMainWindow.cxx | 2 ++ vv/vvSlicerManager.cxx | 7 +++++++ vv/vvSlicerManager.h | 1 + 8 files changed, 79 insertions(+), 11 deletions(-) diff --git a/vv/qt_ui/vvLandmarksPanel.ui b/vv/qt_ui/vvLandmarksPanel.ui index 9337b52..8744627 100644 --- a/vv/qt_ui/vvLandmarksPanel.ui +++ b/vv/qt_ui/vvLandmarksPanel.ui @@ -6,7 +6,7 @@ 0 0 - 325 + 382 214 @@ -14,16 +14,6 @@ Form - - - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">CurrentImage :</span></p></body></html> - - - @@ -139,6 +129,27 @@ p, li { white-space: pre-wrap; } + + + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">CurrentImage :</span></p></body></html> + + + + + + + Update Coords. + + + + :/common/icons/rotateright.png:/common/icons/rotateright.png + + + diff --git a/vv/vvLandmarks.cxx b/vv/vvLandmarks.cxx index dc38cd2..a268683 100644 --- a/vv/vvLandmarks.cxx +++ b/vv/vvLandmarks.cxx @@ -35,11 +35,13 @@ vvLandmarks::vvLandmarks(int size) { mLandmarks.resize(size); + mLandmarksInitial.resize(size); mFilenames.resize(0); mTime = 0; for (int i = 0; i < size; i++) { mLandmarks[i].resize(0); + mLandmarksInitial[i].resize(0); vtkPoints *points = vtkPoints::New(); mPoints.push_back(points); mIds.push_back(vtkFloatArray::New()); @@ -79,6 +81,7 @@ void vvLandmarks::AddLandmark(float x,float y,float z,float t,double value) point.coordinates[3] = t; point.pixel_value=value; mLandmarks[mTime].push_back(point); + mLandmarksInitial[mTime].push_back(point); idPoint = mPoints[int(t)]->InsertNextPoint(x,y,z); std::string str_vtkIdType; // string which will contain the result @@ -103,6 +106,27 @@ void vvLandmarks::AddLandmark(float x,float y,float z,float t,double value) } //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +void vvLandmarks::TransformUpdate(vtkAbstractTransform* transform) +{ + //For all Time, For all landmarks, I apply the transform + for(int time=0; timeTransformPoint(ptBeforeTransform, ptAfterTransform); + + mLandmarks[time][landmark].coordinates[0]= ptAfterTransform[0]; + mLandmarks[time][landmark].coordinates[1]= ptAfterTransform[1]; + mLandmarks[time][landmark].coordinates[2]= ptAfterTransform[2]; + } + } +} +//-------------------------------------------------------------------- //-------------------------------------------------------------------- void vvLandmarks::RemoveLastLandmark() @@ -110,6 +134,7 @@ void vvLandmarks::RemoveLastLandmark() mPoints[mTime]->SetNumberOfPoints(mPoints[mTime]->GetNumberOfPoints()-1); // mText.pop_back(); mLandmarks[mTime].pop_back(); + mLandmarksInitial[mTime].pop_back(); mIds[mTime]->RemoveLastTuple(); mLabels[mTime]->SetNumberOfValues(mLabels[mTime]->GetNumberOfValues()-1); mLabels[mTime]->Modified(); @@ -148,6 +173,7 @@ void vvLandmarks::RemoveLandmarkWithLabel(vtkStdString label, int time) mPolyData->Modified(); mLandmarks[t].erase(mLandmarks[t].begin() + index); + mLandmarksInitial[t].erase(mLandmarksInitial[t].begin() + index); mIds[t]->RemoveLastTuple(); } //-------------------------------------------------------------------- @@ -175,6 +201,7 @@ void vvLandmarks::RemoveLandmark(int index) mPolyData->Modified(); mLandmarks[t].erase(mLandmarks[t].begin() + index); + mLandmarksInitial[t].erase(mLandmarksInitial[t].begin() + index); mIds[t]->RemoveLastTuple(); } //-------------------------------------------------------------------- @@ -184,6 +211,7 @@ void vvLandmarks::RemoveAll() { for (unsigned int i = 0; i < mLandmarks.size(); i++) { mLandmarks[i].clear(); + mLandmarksInitial[i].clear(); mPoints[i]->SetNumberOfPoints(0); mLabels[i]->SetNumberOfValues(0); mIds[i]->SetNumberOfValues(0); @@ -195,6 +223,7 @@ void vvLandmarks::RemoveAll() void vvLandmarks::ChangeComments(int index, std::string comments) { mLandmarks[mTime][index].comments = comments; + mLandmarksInitial[mTime][index].comments = comments; } //-------------------------------------------------------------------- @@ -242,6 +271,7 @@ bool vvLandmarks::LoadTxtFile(std::vector filenames) mFilenames = filenames; for (unsigned int i = 0; i < mPoints.size(); i++) { mLandmarks[i].clear(); + mLandmarksInitial[i].clear(); mPoints[i]->SetNumberOfPoints(0); } @@ -333,6 +363,7 @@ bool vvLandmarks::LoadTxtFile(std::vector filenames) } // DD(point.comments); mLandmarks[int(point.coordinates[3])].push_back(point); + mLandmarksInitial[int(point.coordinates[3])].push_back(point); mIds[int(point.coordinates[3])]->InsertNextTuple1(0.55); idPoint = mPoints[int(point.coordinates[3])]->InsertNextPoint( point.coordinates[0],point.coordinates[1],point.coordinates[2]); @@ -361,6 +392,7 @@ bool vvLandmarks::LoadPtsFile(std::vector filenames) for (unsigned int i = 0; i < mPoints.size(); i++) { mPoints[i]->SetNumberOfPoints(0); mLandmarks[i].clear(); + mLandmarksInitial[i].clear(); } int err = 0; @@ -415,6 +447,7 @@ bool vvLandmarks::LoadPtsFile(std::vector filenames) // DD(point.comments); mLandmarks[int(point.coordinates[3])].push_back(point); + mLandmarksInitial[int(point.coordinates[3])].push_back(point); mIds[int(point.coordinates[3])]->InsertNextTuple1(0.55); idPoint = mPoints[int(point.coordinates[3])]->InsertNextPoint( point.coordinates[0],point.coordinates[1],point.coordinates[2]); diff --git a/vv/vvLandmarks.h b/vv/vvLandmarks.h index 6f7e91f..285b24a 100644 --- a/vv/vvLandmarks.h +++ b/vv/vvLandmarks.h @@ -25,6 +25,7 @@ #include "vtkPoints.h" #include "vvLandmarksGlyph.h" #include "vtkStringArray.h" +#include //typedef struct vvLandmark { @@ -43,6 +44,7 @@ public : void SaveFile(std::string filename); void AddLandmark(float x,float y,float z,float t,double value); + void TransformUpdate(vtkAbstractTransform* transform); void RemoveLastLandmark(); void RemoveLandmarkWithLabel(vtkStdString, int); void RemoveLandmark(int index); @@ -71,6 +73,7 @@ private: typedef std::vector LandmarkContainerType; std::vector mLandmarks; + std::vector mLandmarksInitial; vtkPolyData *mPolyData; std::vector mPoints; diff --git a/vv/vvLandmarksPanel.cxx b/vv/vvLandmarksPanel.cxx index f23631c..827e391 100644 --- a/vv/vvLandmarksPanel.cxx +++ b/vv/vvLandmarksPanel.cxx @@ -38,9 +38,11 @@ vvLandmarksPanel::vvLandmarksPanel(QWidget * parent):QWidget(parent) tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); loadButton->setEnabled(0); saveButton->setEnabled(0); + updateTransformButton->setEnabled(0); removeButton->setEnabled(0); connect(loadButton, SIGNAL(clicked()),this,SLOT(Load())); connect(saveButton, SIGNAL(clicked()),this,SLOT(Save())); + connect(updateTransformButton, SIGNAL(clicked()),this,SLOT(UpdateTransform())); connect(removeButton, SIGNAL(clicked()),this,SLOT(RemoveSelectedPoints())); connect(removeAllButton, SIGNAL(clicked()),this,SLOT(RemoveAllPoints())); connect(tableWidget,SIGNAL(cellChanged(int,int)),this,SLOT(CommentsChanged(int,int))); @@ -80,6 +82,12 @@ void vvLandmarksPanel::Save() } } +void vvLandmarksPanel::UpdateTransform() +{ + emit UpdateLandmarkTransform(); + SetCurrentLandmarks(mCurrentLandmarks,mCurrentLandmarks->GetTime()); +} + void vvLandmarksPanel::SelectPoint() { if (tableWidget->rowCount() > 0) { @@ -181,6 +189,7 @@ void vvLandmarksPanel::SetCurrentLandmarks(vvLandmarks* lm,int time) return; loadButton->setEnabled(1); saveButton->setEnabled(1); + updateTransformButton->setEnabled(1); removeButton->setEnabled(1); mCurrentLandmarks = lm; tableWidget->clearContents(); diff --git a/vv/vvLandmarksPanel.h b/vv/vvLandmarksPanel.h index 01f5399..3d9b45c 100644 --- a/vv/vvLandmarksPanel.h +++ b/vv/vvLandmarksPanel.h @@ -44,6 +44,7 @@ public slots: void Load(); bool LoadFromFile(std::vector file); void Save(); + void UpdateTransform(); void RemoveSelectedPoints(); void RemoveAllPoints(); void AddPoint(); @@ -52,6 +53,7 @@ public slots: signals: void UpdateRenderWindows(); void SelectedPointChanged(); + void UpdateLandmarkTransform(); private: void AddPoint(int); diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index e70269c..a3d2000 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -984,6 +984,7 @@ void vvMainWindow::LoadImages(std::vector files, vvImageReader::Loa connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)), this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int))); connect(mSlicerManagers.back(),SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint())); + connect(landmarksPanel,SIGNAL(UpdateLandmarkTransform()), mSlicerManagers.back(), SLOT(UpdateLandmark())); InitSlicers(); numberofsuccesulreads++; } @@ -3697,6 +3698,7 @@ vvSlicerManager* vvMainWindow::AddImage(vvImage::Pointer image,std::string filen connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)), this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int))); connect(mSlicerManagers.back(), SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint())); + connect(landmarksPanel,SIGNAL(UpdateLandmarkTransform()), mSlicerManagers.back(), SLOT(UpdateLandmark())); diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index e9d1c21..139c808 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -1625,6 +1625,13 @@ void vvSlicerManager::AddLandmarkProfile(float x,float y,float z,float t) } //---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +void vvSlicerManager::UpdateLandmark() +{ + this->GetLandmarks()->TransformUpdate(mSlicers[mSelectedSlicer]->GetConcatenatedTransform()->GetInverse()); +} +//---------------------------------------------------------------------------- + //---------------------------------------------------------------------------- void vvSlicerManager::PrevImage(int slicer) { diff --git a/vv/vvSlicerManager.h b/vv/vvSlicerManager.h index e80ef48..0d5c9ae 100644 --- a/vv/vvSlicerManager.h +++ b/vv/vvSlicerManager.h @@ -285,6 +285,7 @@ class vvSlicerManager : public QObject { public slots: void AddLandmark(float x,float y,float z,float t); + void UpdateLandmark(); signals : void callAddLandmark(float x,float y,float z,float t); -- 2.47.1