]> Creatis software - clitk.git/blob - vv/vvLandmarksPanel.cxx
Fixed compilation with VC++ 9
[clitk.git] / vv / vvLandmarksPanel.cxx
1 #ifndef _vvLandmarksPanel_CXX
2 #define _vvLandmarksPanel_CXX
3
4 /*=========================================================================
5
6  Program:   vv
7  Language:  C++
8  Author :   Pierre Seroul (pierre.seroul@gmail.com)
9
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
13
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.
17
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.
22
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/>.
25
26 =========================================================================*/
27
28 #include "vvLandmarksPanel.h"
29
30 #include <QtGui>
31 #include <Qt>
32 #include "QTreePushButton.h"
33 #include "vvLandmarks.h"
34
35 #include <vtksys/SystemTools.hxx>
36
37 //====================================================================
38 vvLandmarksPanel::vvLandmarksPanel(QWidget * parent):QWidget(parent)
39 {
40     setupUi(this);
41
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)));
50 }
51
52 void vvLandmarksPanel::Load()
53 {
54     QString file = QFileDialog::getOpenFileName(this,tr("Load Landmarks"),
55                    mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
56     if (!file.isEmpty())
57         mCurrentLandmarks->LoadFile(file.toStdString());
58     SetCurrentLandmarks(mCurrentLandmarks,2);
59     emit UpdateRenderWindows();
60 }
61
62 void vvLandmarksPanel::Save()
63 {
64     QString file = QFileDialog::getSaveFileName(this,
65                    tr("Save Landmarks"),
66                    mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
67     if (!file.isEmpty())
68     {
69         std::string filename = vtksys::SystemTools::GetFilenamePath(file.toStdString());
70         filename += "/" + vtksys::SystemTools::GetFilenameWithoutLastExtension(file.toStdString());
71         filename += ".txt";
72         mCurrentLandmarks->SaveFile(filename.c_str());
73     }
74 }
75
76 void vvLandmarksPanel::RemoveLastPoint()
77 {
78     if (tableWidget->rowCount() > 0)
79     {
80         tableWidget->removeRow(tableWidget->rowCount()-1);
81         mCurrentLandmarks->RemoveLastLandmark();
82         emit UpdateRenderWindows();
83     }
84 }
85
86 void vvLandmarksPanel::AddPoint()
87 {
88     AddPoint(mCurrentLandmarks->GetNumberOfPoints()-1);
89 }
90
91 void vvLandmarksPanel::AddPoint(int landmarksIndex)
92 {
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);
99
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);
104
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);
109
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);
114
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);
119
120
121     QTableWidgetItem* vItem = new QTableWidgetItem(
122         QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1));
123     vItem->setFlags(Qt::NoItemFlags);
124     tableWidget->setItem(rowIndex,5,vItem);
125
126     tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str()));
127 }
128
129 void vvLandmarksPanel::SetCurrentLandmarks(vvLandmarks* lm,int time)
130 {
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++)
138         AddPoint(i);
139     //if (time > 1)
140         //tableWidget->setColumnHidden(4,1);
141     //else
142         //tableWidget->setColumnHidden(4,0);
143     tableWidget->resizeColumnsToContents();
144 }
145
146 void vvLandmarksPanel::SetCurrentImage(std::string filename)
147 {
148     QString image = "<b>CurrentImage : </b>";
149     image += vtksys::SystemTools::GetFilenameWithoutLastExtension(filename).c_str();
150     nameLabel->setText(image);
151 }
152
153 void vvLandmarksPanel::CommentsChanged(int row, int column)
154 {
155     if (column == 6)
156     {
157         mCurrentLandmarks->ChangeComments(row,std::string(tableWidget->item(row,column)->text().toStdString()));
158         tableWidget->resizeColumnsToContents();
159     }
160 }
161
162 #endif /* end #define _vvLandmarksPanel_CXX */
163