1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef _vvLandmarksPanel_CXX
19 #define _vvLandmarksPanel_CXX
20 #include "vvLandmarksPanel.h"
24 #include "QTreePushButton.h"
25 #include "vvLandmarks.h"
27 #include <vtksys/SystemTools.hxx>
29 //====================================================================
30 vvLandmarksPanel::vvLandmarksPanel(QWidget * parent):QWidget(parent)
34 tableWidget->verticalHeader()->hide();
35 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
36 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
37 loadButton->setEnabled(0);
38 saveButton->setEnabled(0);
39 removeButton->setEnabled(0);
40 connect(loadButton, SIGNAL(clicked()),this,SLOT(Load()));
41 connect(saveButton, SIGNAL(clicked()),this,SLOT(Save()));
42 connect(removeButton, SIGNAL(clicked()),this,SLOT(RemoveSelectedPoints()));
43 connect(tableWidget,SIGNAL(cellChanged(int,int)),this,SLOT(CommentsChanged(int,int)));
46 void vvLandmarksPanel::Load()
48 QString file = QFileDialog::getOpenFileName(this,tr("Load Landmarks"),
49 mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
51 mCurrentLandmarks->LoadFile(file.toStdString());
52 SetCurrentLandmarks(mCurrentLandmarks,2);
53 emit UpdateRenderWindows();
56 void vvLandmarksPanel::Save()
58 QString file = QFileDialog::getSaveFileName(this,
60 mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
61 if (!file.isEmpty()) {
62 std::string filename = vtksys::SystemTools::GetFilenamePath(file.toStdString());
63 filename += "/" + vtksys::SystemTools::GetFilenameWithoutLastExtension(file.toStdString());
65 mCurrentLandmarks->SaveFile(filename.c_str());
69 void vvLandmarksPanel::RemoveSelectedPoints()
71 if (tableWidget->rowCount() > 0) {
72 QList<QTableWidgetItem *> items = tableWidget->selectedItems();
74 tableWidget->removeRow(tableWidget->rowCount()-1);
75 mCurrentLandmarks->RemoveLastLandmark();
78 // we're using single-selection mode
79 int row = items[0]->row();
80 mCurrentLandmarks->RemoveLandmark(row);
81 tableWidget->removeRow(row);
83 for (int i = row; i < tableWidget->rowCount(); i++) {
84 QTableWidgetItem* iItem = tableWidget->item(i, 0);
85 iItem->setText(QString::number(i));
89 emit UpdateRenderWindows();
93 void vvLandmarksPanel::AddPoint()
95 AddPoint(mCurrentLandmarks->GetNumberOfPoints()-1);
98 void vvLandmarksPanel::AddPoint(int landmarksIndex)
100 int rowIndex = landmarksIndex; //tableWidget->rowCount();
101 tableWidget->setRowCount(rowIndex+1);
102 tableWidget->setRowHeight(rowIndex,20);
103 QTableWidgetItem* iItem = new QTableWidgetItem(QString::number(landmarksIndex));
104 iItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
105 tableWidget->setItem(rowIndex,0,iItem);
107 QTableWidgetItem* xItem = new QTableWidgetItem(
108 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[0],'f',1));
109 xItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
110 tableWidget->setItem(rowIndex,1,xItem);
112 QTableWidgetItem* yItem = new QTableWidgetItem(
113 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[1],'f',1));
114 yItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
115 tableWidget->setItem(rowIndex,2,yItem);
117 QTableWidgetItem* zItem = new QTableWidgetItem(
118 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[2],'f',1));
119 zItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
120 tableWidget->setItem(rowIndex,3,zItem);
122 QTableWidgetItem* tItem = new QTableWidgetItem(
123 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[3],'f',1));
124 tItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
125 tableWidget->setItem(rowIndex,4,tItem);
128 QTableWidgetItem* vItem = new QTableWidgetItem(
129 QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1));
130 vItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
131 tableWidget->setItem(rowIndex,5,vItem);
133 tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str()));
136 void vvLandmarksPanel::SetCurrentLandmarks(vvLandmarks* lm,int time)
138 loadButton->setEnabled(1);
139 saveButton->setEnabled(1);
140 removeButton->setEnabled(1);
141 mCurrentLandmarks = lm;
142 tableWidget->clearContents();
143 tableWidget->setRowCount(mCurrentLandmarks->GetNumberOfPoints());
144 for (unsigned int i = 0; i < mCurrentLandmarks->GetNumberOfPoints(); i++)
147 //tableWidget->setColumnHidden(4,1);
149 //tableWidget->setColumnHidden(4,0);
150 tableWidget->resizeColumnsToContents();
153 void vvLandmarksPanel::SetCurrentImage(std::string filename)
155 QString image = "<b>CurrentImage : </b>";
156 image += vtksys::SystemTools::GetFilenameWithoutLastExtension(filename).c_str();
157 nameLabel->setText(image);
160 void vvLandmarksPanel::CommentsChanged(int row, int column)
163 mCurrentLandmarks->ChangeComments(row,std::string(tableWidget->item(row,column)->text().toStdString()));
164 tableWidget->resizeColumnsToContents();
168 #endif /* end #define _vvLandmarksPanel_CXX */