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://oncora1.lyon.fnclcc.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)"));
61 std::string filename = vtksys::SystemTools::GetFilenamePath(file.toStdString());
62 filename += "/" + vtksys::SystemTools::GetFilenameWithoutLastExtension(file.toStdString());
64 mCurrentLandmarks->SaveFile(filename.c_str());
68 void vvLandmarksPanel::RemoveLastPoint()
70 if (tableWidget->rowCount() > 0)
72 tableWidget->removeRow(tableWidget->rowCount()-1);
73 mCurrentLandmarks->RemoveLastLandmark();
74 emit UpdateRenderWindows();
78 void vvLandmarksPanel::AddPoint()
80 AddPoint(mCurrentLandmarks->GetNumberOfPoints()-1);
83 void vvLandmarksPanel::AddPoint(int landmarksIndex)
85 int rowIndex = landmarksIndex; //tableWidget->rowCount();
86 tableWidget->setRowCount(rowIndex+1);
87 tableWidget->setRowHeight(rowIndex,20);
88 QTableWidgetItem* iItem = new QTableWidgetItem(QString::number(landmarksIndex));
89 iItem->setFlags(Qt::NoItemFlags);
90 tableWidget->setItem(rowIndex,0,iItem);
92 QTableWidgetItem* xItem = new QTableWidgetItem(
93 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[0],'f',1));
94 xItem->setFlags(Qt::NoItemFlags);
95 tableWidget->setItem(rowIndex,1,xItem);
97 QTableWidgetItem* yItem = new QTableWidgetItem(
98 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[1],'f',1));
99 yItem->setFlags(Qt::NoItemFlags);
100 tableWidget->setItem(rowIndex,2,yItem);
102 QTableWidgetItem* zItem = new QTableWidgetItem(
103 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[2],'f',1));
104 zItem->setFlags(Qt::NoItemFlags);
105 tableWidget->setItem(rowIndex,3,zItem);
107 QTableWidgetItem* tItem = new QTableWidgetItem(
108 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[3],'f',1));
109 tItem->setFlags(Qt::NoItemFlags);
110 tableWidget->setItem(rowIndex,4,tItem);
113 QTableWidgetItem* vItem = new QTableWidgetItem(
114 QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1));
115 vItem->setFlags(Qt::NoItemFlags);
116 tableWidget->setItem(rowIndex,5,vItem);
118 tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str()));
121 void vvLandmarksPanel::SetCurrentLandmarks(vvLandmarks* lm,int time)
123 loadButton->setEnabled(1);
124 saveButton->setEnabled(1);
125 removeButton->setEnabled(1);
126 mCurrentLandmarks = lm;
127 tableWidget->clearContents();
128 tableWidget->setRowCount(mCurrentLandmarks->GetNumberOfPoints());
129 for (int i = 0; i < mCurrentLandmarks->GetNumberOfPoints(); i++)
132 //tableWidget->setColumnHidden(4,1);
134 //tableWidget->setColumnHidden(4,0);
135 tableWidget->resizeColumnsToContents();
138 void vvLandmarksPanel::SetCurrentImage(std::string filename)
140 QString image = "<b>CurrentImage : </b>";
141 image += vtksys::SystemTools::GetFilenameWithoutLastExtension(filename).c_str();
142 nameLabel->setText(image);
145 void vvLandmarksPanel::CommentsChanged(int row, int column)
149 mCurrentLandmarks->ChangeComments(row,std::string(tableWidget->item(row,column)->text().toStdString()));
150 tableWidget->resizeColumnsToContents();
154 #endif /* end #define _vvLandmarksPanel_CXX */