1 #ifndef _vvLandmarksPanel_CXX
2 #define _vvLandmarksPanel_CXX
4 /*=========================================================================
8 Author : Pierre Seroul (pierre.seroul@gmail.com)
10 Copyright (C) 200COLUMN_IMAGE_NAME
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS-LRMN http://www.creatis.insa-lyon.fr
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, version 3 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 =========================================================================*/
28 #include "vvLandmarksPanel.h"
32 #include "QTreePushButton.h"
33 #include "vvLandmarks.h"
35 #include <vtksys/SystemTools.hxx>
37 //====================================================================
38 vvLandmarksPanel::vvLandmarksPanel(QWidget * parent):QWidget(parent)
42 tableWidget->verticalHeader()->hide();
43 loadButton->setEnabled(0);
44 saveButton->setEnabled(0);
45 removeButton->setEnabled(0);
46 connect(loadButton, SIGNAL(clicked()),this,SLOT(Load()));
47 connect(saveButton, SIGNAL(clicked()),this,SLOT(Save()));
48 connect(removeButton, SIGNAL(clicked()),this,SLOT(RemoveLastPoint()));
49 connect(tableWidget,SIGNAL(cellChanged(int,int)),this,SLOT(CommentsChanged(int,int)));
52 void vvLandmarksPanel::Load()
54 QString file = QFileDialog::getOpenFileName(this,tr("Load Landmarks"),
55 mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
57 mCurrentLandmarks->LoadFile(file.toStdString());
58 SetCurrentLandmarks(mCurrentLandmarks,2);
59 emit UpdateRenderWindows();
62 void vvLandmarksPanel::Save()
64 QString file = QFileDialog::getSaveFileName(this,
66 mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
69 std::string filename = vtksys::SystemTools::GetFilenamePath(file.toStdString());
70 filename += "/" + vtksys::SystemTools::GetFilenameWithoutLastExtension(file.toStdString());
72 mCurrentLandmarks->SaveFile(filename.c_str());
76 void vvLandmarksPanel::RemoveLastPoint()
78 if (tableWidget->rowCount() > 0)
80 tableWidget->removeRow(tableWidget->rowCount()-1);
81 mCurrentLandmarks->RemoveLastLandmark();
82 emit UpdateRenderWindows();
86 void vvLandmarksPanel::AddPoint()
88 AddPoint(mCurrentLandmarks->GetNumberOfPoints()-1);
91 void vvLandmarksPanel::AddPoint(int landmarksIndex)
93 int rowIndex = landmarksIndex; //tableWidget->rowCount();
94 tableWidget->setRowCount(rowIndex+1);
95 tableWidget->setRowHeight(rowIndex,20);
96 QTableWidgetItem* iItem = new QTableWidgetItem(QString::number(landmarksIndex));
97 iItem->setFlags(Qt::NoItemFlags);
98 tableWidget->setItem(rowIndex,0,iItem);
100 QTableWidgetItem* xItem = new QTableWidgetItem(
101 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[0],'f',1));
102 xItem->setFlags(Qt::NoItemFlags);
103 tableWidget->setItem(rowIndex,1,xItem);
105 QTableWidgetItem* yItem = new QTableWidgetItem(
106 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[1],'f',1));
107 yItem->setFlags(Qt::NoItemFlags);
108 tableWidget->setItem(rowIndex,2,yItem);
110 QTableWidgetItem* zItem = new QTableWidgetItem(
111 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[2],'f',1));
112 zItem->setFlags(Qt::NoItemFlags);
113 tableWidget->setItem(rowIndex,3,zItem);
115 QTableWidgetItem* tItem = new QTableWidgetItem(
116 QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[3],'f',1));
117 tItem->setFlags(Qt::NoItemFlags);
118 tableWidget->setItem(rowIndex,4,tItem);
121 QTableWidgetItem* vItem = new QTableWidgetItem(
122 QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1));
123 vItem->setFlags(Qt::NoItemFlags);
124 tableWidget->setItem(rowIndex,5,vItem);
126 tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str()));
129 void vvLandmarksPanel::SetCurrentLandmarks(vvLandmarks* lm,int time)
131 loadButton->setEnabled(1);
132 saveButton->setEnabled(1);
133 removeButton->setEnabled(1);
134 mCurrentLandmarks = lm;
135 tableWidget->clearContents();
136 tableWidget->setRowCount(mCurrentLandmarks->GetNumberOfPoints());
137 for (int i = 0; i < mCurrentLandmarks->GetNumberOfPoints(); i++)
140 //tableWidget->setColumnHidden(4,1);
142 //tableWidget->setColumnHidden(4,0);
143 tableWidget->resizeColumnsToContents();
146 void vvLandmarksPanel::SetCurrentImage(std::string filename)
148 QString image = "<b>CurrentImage : </b>";
149 image += vtksys::SystemTools::GetFilenameWithoutLastExtension(filename).c_str();
150 nameLabel->setText(image);
153 void vvLandmarksPanel::CommentsChanged(int row, int column)
157 mCurrentLandmarks->ChangeComments(row,std::string(tableWidget->item(row,column)->text().toStdString()));
158 tableWidget->resizeColumnsToContents();
162 #endif /* end #define _vvLandmarksPanel_CXX */