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 loadButton->setEnabled(0);
36 saveButton->setEnabled(0);
37 removeButton->setEnabled(0);
38 connect(loadButton, SIGNAL(clicked()),this,SLOT(Load()));
39 connect(saveButton, SIGNAL(clicked()),this,SLOT(Save()));
40 connect(removeButton, SIGNAL(clicked()),this,SLOT(RemoveLastPoint()));
41 connect(tableWidget,SIGNAL(cellChanged(int,int)),this,SLOT(CommentsChanged(int,int)));
44 void vvLandmarksPanel::Load()
46 QString file = QFileDialog::getOpenFileName(this,tr("Load Landmarks"),
47 mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
49 mCurrentLandmarks->LoadFile(file.toStdString());
50 SetCurrentLandmarks(mCurrentLandmarks,2);
51 emit UpdateRenderWindows();
54 void vvLandmarksPanel::Save()
56 QString file = QFileDialog::getSaveFileName(this,
58 mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
59 if (!file.isEmpty()) {
60 std::string filename = vtksys::SystemTools::GetFilenamePath(file.toStdString());
61 filename += "/" + vtksys::SystemTools::GetFilenameWithoutLastExtension(file.toStdString());
63 mCurrentLandmarks->SaveFile(filename.c_str());
67 void vvLandmarksPanel::RemoveLastPoint()
69 if (tableWidget->rowCount() > 0) {
70 tableWidget->removeRow(tableWidget->rowCount()-1);
71 mCurrentLandmarks->RemoveLastLandmark();
72 emit UpdateRenderWindows();
76 void vvLandmarksPanel::AddPoint()
78 AddPoint(mCurrentLandmarks->GetNumberOfPoints()-1);
81 void vvLandmarksPanel::AddPoint(int landmarksIndex)
83 int rowIndex = landmarksIndex; //tableWidget->rowCount();
84 tableWidget->setRowCount(rowIndex+1);
85 tableWidget->setRowHeight(rowIndex,20);
86 QTableWidgetItem* iItem = new QTableWidgetItem(QString::number(landmarksIndex));
87 iItem->setFlags(Qt::NoItemFlags);
88 tableWidget->setItem(rowIndex,0,iItem);
90 QTableWidgetItem* xItem = new QTableWidgetItem(
91 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[0],'f',1));
92 xItem->setFlags(Qt::NoItemFlags);
93 tableWidget->setItem(rowIndex,1,xItem);
95 QTableWidgetItem* yItem = new QTableWidgetItem(
96 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[1],'f',1));
97 yItem->setFlags(Qt::NoItemFlags);
98 tableWidget->setItem(rowIndex,2,yItem);
100 QTableWidgetItem* zItem = new QTableWidgetItem(
101 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[2],'f',1));
102 zItem->setFlags(Qt::NoItemFlags);
103 tableWidget->setItem(rowIndex,3,zItem);
105 QTableWidgetItem* tItem = new QTableWidgetItem(
106 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[3],'f',1));
107 tItem->setFlags(Qt::NoItemFlags);
108 tableWidget->setItem(rowIndex,4,tItem);
111 QTableWidgetItem* vItem = new QTableWidgetItem(
112 QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1));
113 vItem->setFlags(Qt::NoItemFlags);
114 tableWidget->setItem(rowIndex,5,vItem);
116 tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str()));
119 void vvLandmarksPanel::SetCurrentLandmarks(vvLandmarks* lm,int time)
121 loadButton->setEnabled(1);
122 saveButton->setEnabled(1);
123 removeButton->setEnabled(1);
124 mCurrentLandmarks = lm;
125 tableWidget->clearContents();
126 tableWidget->setRowCount(mCurrentLandmarks->GetNumberOfPoints());
127 for (unsigned int i = 0; i < mCurrentLandmarks->GetNumberOfPoints(); i++)
130 //tableWidget->setColumnHidden(4,1);
132 //tableWidget->setColumnHidden(4,0);
133 tableWidget->resizeColumnsToContents();
136 void vvLandmarksPanel::SetCurrentImage(std::string filename)
138 QString image = "<b>CurrentImage : </b>";
139 image += vtksys::SystemTools::GetFilenameWithoutLastExtension(filename).c_str();
140 nameLabel->setText(image);
143 void vvLandmarksPanel::CommentsChanged(int row, int column)
146 mCurrentLandmarks->ChangeComments(row,std::string(tableWidget->item(row,column)->text().toStdString()));
147 tableWidget->resizeColumnsToContents();
151 #endif /* end #define _vvLandmarksPanel_CXX */