X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=vv%2FvvLandmarksPanel.cxx;h=f23631cb1ca734fd41e3e946145c0bb64ceb6563;hb=b0f9ef265dbfc67374eaa989e606d2b00d634f76;hp=4ca9c351f44ff0df666b258e5fcca1311ed731ca;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git
diff --git a/vv/vvLandmarksPanel.cxx b/vv/vvLandmarksPanel.cxx
index 4ca9c35..f23631c 100644
--- a/vv/vvLandmarksPanel.cxx
+++ b/vv/vvLandmarksPanel.cxx
@@ -1,165 +1,214 @@
-#ifndef _vvLandmarksPanel_CXX
-#define _vvLandmarksPanel_CXX
-
/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Program: vv
- Module: $RCSfile: vvLandmarksPanel.cxx,v $
- Language: C++
- Date: $Date: 2010/01/06 13:31:58 $
- Version: $Revision: 1.1 $
- Author : Pierre Seroul (pierre.seroul@gmail.com)
-
-Copyright (C) 200COLUMN_IMAGE_NAME
-Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
-CREATIS-LRMN http://www.creatis.insa-lyon.fr
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ Authors belong to:
+ - University of LYON http://www.universite-lyon.fr/
+ - Léon Bérard cancer center http://www.centreleonberard.fr
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the copyright notices for more information.
-=========================================================================*/
+ It is distributed under dual licence
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
+#ifndef _vvLandmarksPanel_CXX
+#define _vvLandmarksPanel_CXX
#include "vvLandmarksPanel.h"
#include
#include
+#include
#include "QTreePushButton.h"
#include "vvLandmarks.h"
#include
+#include
//====================================================================
vvLandmarksPanel::vvLandmarksPanel(QWidget * parent):QWidget(parent)
-{
- setupUi(this);
-
- tableWidget->verticalHeader()->hide();
- loadButton->setEnabled(0);
- saveButton->setEnabled(0);
- removeButton->setEnabled(0);
- connect(loadButton, SIGNAL(clicked()),this,SLOT(Load()));
- connect(saveButton, SIGNAL(clicked()),this,SLOT(Save()));
- connect(removeButton, SIGNAL(clicked()),this,SLOT(RemoveLastPoint()));
- connect(tableWidget,SIGNAL(cellChanged(int,int)),this,SLOT(CommentsChanged(int,int)));
+{
+ setupUi(this);
+
+ tableWidget->verticalHeader()->hide();
+ tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
+ tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
+ loadButton->setEnabled(0);
+ saveButton->setEnabled(0);
+ removeButton->setEnabled(0);
+ connect(loadButton, SIGNAL(clicked()),this,SLOT(Load()));
+ connect(saveButton, SIGNAL(clicked()),this,SLOT(Save()));
+ 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)));
+ connect(tableWidget,SIGNAL(doubleClicked(const QModelIndex &)),this,SLOT(SelectPoint()));
}
void vvLandmarksPanel::Load()
-{
- QString file = QFileDialog::getOpenFileName(this,tr("Load Landmarks"),
- mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
- if (!file.isEmpty())
- mCurrentLandmarks->LoadFile(file.toStdString());
- SetCurrentLandmarks(mCurrentLandmarks,2);
- emit UpdateRenderWindows();
+{
+ QString file = QFileDialog::getOpenFileName(this,tr("Load Landmarks"),
+ mCurrentPath.c_str(),tr("Landmarks ( *.txt *.pts)"));
+ if (!file.isEmpty()) {
+ std::vector files(1, file.toStdString());
+ LoadFromFile(files);
+ }
+}
+
+bool vvLandmarksPanel::LoadFromFile(std::vector files)
+{
+ if (!mCurrentLandmarks->LoadFile(files))
+ return false;
+
+ SetCurrentLandmarks(mCurrentLandmarks,0);
+ emit UpdateRenderWindows();
+ return true;
}
void vvLandmarksPanel::Save()
-{
- QString file = QFileDialog::getSaveFileName(this,
- tr("Save Landmarks"),
- mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
- if (!file.isEmpty())
- {
- std::string filename = vtksys::SystemTools::GetFilenamePath(file.toStdString());
- filename += "/" + vtksys::SystemTools::GetFilenameWithoutLastExtension(file.toStdString());
- filename += ".txt";
- mCurrentLandmarks->SaveFile(filename.c_str());
+{
+ QString file = QFileDialog::getSaveFileName(this,
+ tr("Save Landmarks"),
+ mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
+ if (!file.isEmpty()) {
+ std::string filename = vtksys::SystemTools::GetFilenamePath(file.toStdString());
+ filename += "/" + vtksys::SystemTools::GetFilenameWithoutLastExtension(file.toStdString());
+ filename += ".txt";
+ mCurrentLandmarks->SaveFile(filename.c_str());
+ }
+}
+
+void vvLandmarksPanel::SelectPoint()
+{
+ if (tableWidget->rowCount() > 0) {
+ QList items = tableWidget->selectedItems();
+ if (!items.empty()) {
+ // we're using single-selection mode
+ int row = items[0]->row();
+ mSelectedPoint[0] = mCurrentLandmarks->GetCoordinates(row)[0];
+ mSelectedPoint[1] = mCurrentLandmarks->GetCoordinates(row)[1];
+ mSelectedPoint[2] = mCurrentLandmarks->GetCoordinates(row)[2];
+ mSelectedPoint[3] = mCurrentLandmarks->GetCoordinates(row)[3];
+
+ emit SelectedPointChanged();
}
+ }
+
}
-void vvLandmarksPanel::RemoveLastPoint()
-{
- if (tableWidget->rowCount() > 0)
- {
- tableWidget->removeRow(tableWidget->rowCount()-1);
- mCurrentLandmarks->RemoveLastLandmark();
- emit UpdateRenderWindows();
+
+void vvLandmarksPanel::RemoveSelectedPoints()
+{
+ if (tableWidget->rowCount() > 0) {
+ QList items = tableWidget->selectedItems();
+ if (items.empty()) {
+ tableWidget->removeRow(tableWidget->rowCount()-1);
+ mCurrentLandmarks->RemoveLastLandmark();
+ }
+ else {
+ // we're using single-selection mode
+ int row = items[0]->row();
+ mCurrentLandmarks->RemoveLandmark(row);
+ tableWidget->removeRow(row);
+
+ for (int i = row; i < tableWidget->rowCount(); i++) {
+ QTableWidgetItem* iItem = tableWidget->item(i, 0);
+ iItem->setText(QString::number(i));
+ }
+
}
+ emit UpdateRenderWindows();
+ }
+}
+
+void vvLandmarksPanel::RemoveAllPoints()
+{
+ mCurrentLandmarks->RemoveAll();
+ tableWidget->clearContents();
+ tableWidget->setRowCount(0);
+ emit UpdateRenderWindows();
}
void vvLandmarksPanel::AddPoint()
-{
- AddPoint(mCurrentLandmarks->GetNumberOfPoints()-1);
+{
+ AddPoint(mCurrentLandmarks->GetNumberOfPoints()-1);
}
void vvLandmarksPanel::AddPoint(int landmarksIndex)
-{
- int rowIndex = landmarksIndex; //tableWidget->rowCount();
- tableWidget->setRowCount(rowIndex+1);
- tableWidget->setRowHeight(rowIndex,20);
- QTableWidgetItem* iItem = new QTableWidgetItem(QString::number(landmarksIndex));
- iItem->setFlags(!Qt::ItemIsEditable);
- tableWidget->setItem(rowIndex,0,iItem);
-
- QTableWidgetItem* xItem = new QTableWidgetItem(
- QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[0],'f',1));
- xItem->setFlags(!Qt::ItemIsEditable);
- tableWidget->setItem(rowIndex,1,xItem);
-
- QTableWidgetItem* yItem = new QTableWidgetItem(
- QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[1],'f',1));
- yItem->setFlags(!Qt::ItemIsEditable);
- tableWidget->setItem(rowIndex,2,yItem);
-
- QTableWidgetItem* zItem = new QTableWidgetItem(
- QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[2],'f',1));
- zItem->setFlags(!Qt::ItemIsEditable);
- tableWidget->setItem(rowIndex,3,zItem);
-
- QTableWidgetItem* tItem = new QTableWidgetItem(
- QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[3],'f',1));
- tItem->setFlags(!Qt::ItemIsEditable);
- tableWidget->setItem(rowIndex,4,tItem);
-
-
- QTableWidgetItem* vItem = new QTableWidgetItem(
- QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1));
- vItem->setFlags(!Qt::ItemIsEditable);
- tableWidget->setItem(rowIndex,5,vItem);
-
- tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str()));
+{
+ int rowIndex = tableWidget->rowCount();
+// DD(rowIndex);
+ tableWidget->setRowCount(rowIndex+1);
+ tableWidget->setRowHeight(rowIndex,20);
+ QTableWidgetItem* iItem = new QTableWidgetItem(QString::number(rowIndex));
+ iItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ tableWidget->setItem(rowIndex,0,iItem);
+
+ QTableWidgetItem* xItem = new QTableWidgetItem(
+ QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[0],'f',1));
+ xItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ tableWidget->setItem(rowIndex,1,xItem);
+
+ QTableWidgetItem* yItem = new QTableWidgetItem(
+ QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[1],'f',1));
+ yItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ tableWidget->setItem(rowIndex,2,yItem);
+
+ QTableWidgetItem* zItem = new QTableWidgetItem(
+ QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[2],'f',1));
+ zItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ tableWidget->setItem(rowIndex,3,zItem);
+
+ QTableWidgetItem* tItem = new QTableWidgetItem(
+ QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[3],'f',1));
+ tItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ tableWidget->setItem(rowIndex,4,tItem);
+
+
+ QTableWidgetItem* vItem = new QTableWidgetItem(
+ QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1));
+ vItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ tableWidget->setItem(rowIndex,5,vItem);
+
+ tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str()));
}
void vvLandmarksPanel::SetCurrentLandmarks(vvLandmarks* lm,int time)
-{
- loadButton->setEnabled(1);
- saveButton->setEnabled(1);
- removeButton->setEnabled(1);
- mCurrentLandmarks = lm;
- tableWidget->clearContents();
- tableWidget->setRowCount(mCurrentLandmarks->GetNumberOfPoints());
- for (int i = 0; i < mCurrentLandmarks->GetNumberOfPoints(); i++)
+{
+ if (time != lm->GetTime())
+ return;
+ loadButton->setEnabled(1);
+ saveButton->setEnabled(1);
+ removeButton->setEnabled(1);
+ mCurrentLandmarks = lm;
+ tableWidget->clearContents();
+ tableWidget->setRowCount(0);
+ for (unsigned int i = 0; i < mCurrentLandmarks->GetNumberOfPoints(); i++) {
+ if ((mCurrentLandmarks->GetLabels()->GetValue(i) != "P1") && (mCurrentLandmarks->GetLabels()->GetValue(i) != "P2"))
AddPoint(i);
- //if (time > 1)
- //tableWidget->setColumnHidden(4,1);
- //else
- //tableWidget->setColumnHidden(4,0);
- tableWidget->resizeColumnsToContents();
+ }
+ //if (time > 1)
+ //tableWidget->setColumnHidden(4,1);
+ //else
+ //tableWidget->setColumnHidden(4,0);
+ tableWidget->resizeColumnsToContents();
}
void vvLandmarksPanel::SetCurrentImage(std::string filename)
-{
- QString image = "CurrentImage : ";
- image += vtksys::SystemTools::GetFilenameWithoutLastExtension(filename).c_str();
- nameLabel->setText(image);
+{
+ QString image = "CurrentImage : ";
+ image += vtksys::SystemTools::GetFilenameWithoutLastExtension(filename).c_str();
+ nameLabel->setText(image);
}
void vvLandmarksPanel::CommentsChanged(int row, int column)
-{
- if (column == 6)
- {
- mCurrentLandmarks->ChangeComments(row,std::string(tableWidget->item(row,column)->text().toStdString()));
- tableWidget->resizeColumnsToContents();
- }
+{
+ if (column == 6) {
+ mCurrentLandmarks->ChangeComments(row,std::string(tableWidget->item(row,column)->text().toStdString()));
+ tableWidget->resizeColumnsToContents();
+ }
}
#endif /* end #define _vvLandmarksPanel_CXX */