]> Creatis software - clitk.git/blob - vv/vvLandmarksPanel.cxx
Return 0.0 if libstatgrab is not used
[clitk.git] / vv / vvLandmarksPanel.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
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"
21
22 #include <QtGui>
23 #include <Qt>
24 #include "QTreePushButton.h"
25 #include "vvLandmarks.h"
26
27 #include <vtksys/SystemTools.hxx>
28
29 //====================================================================
30 vvLandmarksPanel::vvLandmarksPanel(QWidget * parent):QWidget(parent)
31 {
32   setupUi(this);
33
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)));
42 }
43
44 void vvLandmarksPanel::Load()
45 {
46   QString file = QFileDialog::getOpenFileName(this,tr("Load Landmarks"),
47                  mCurrentPath.c_str(),tr("Landmarks ( *.txt)"));
48   if (!file.isEmpty())
49     mCurrentLandmarks->LoadFile(file.toStdString());
50   SetCurrentLandmarks(mCurrentLandmarks,2);
51   emit UpdateRenderWindows();
52 }
53
54 void vvLandmarksPanel::Save()
55 {
56   QString file = QFileDialog::getSaveFileName(this,
57                  tr("Save Landmarks"),
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());
62     filename += ".txt";
63     mCurrentLandmarks->SaveFile(filename.c_str());
64   }
65 }
66
67 void vvLandmarksPanel::RemoveLastPoint()
68 {
69   if (tableWidget->rowCount() > 0) {
70     tableWidget->removeRow(tableWidget->rowCount()-1);
71     mCurrentLandmarks->RemoveLastLandmark();
72     emit UpdateRenderWindows();
73   }
74 }
75
76 void vvLandmarksPanel::AddPoint()
77 {
78   AddPoint(mCurrentLandmarks->GetNumberOfPoints()-1);
79 }
80
81 void vvLandmarksPanel::AddPoint(int landmarksIndex)
82 {
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);
89
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);
94
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);
99
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);
104
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);
109
110
111   QTableWidgetItem* vItem = new QTableWidgetItem(
112     QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1));
113   vItem->setFlags(Qt::NoItemFlags);
114   tableWidget->setItem(rowIndex,5,vItem);
115
116   tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str()));
117 }
118
119 void vvLandmarksPanel::SetCurrentLandmarks(vvLandmarks* lm,int time)
120 {
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++)
128     AddPoint(i);
129   //if (time > 1)
130   //tableWidget->setColumnHidden(4,1);
131   //else
132   //tableWidget->setColumnHidden(4,0);
133   tableWidget->resizeColumnsToContents();
134 }
135
136 void vvLandmarksPanel::SetCurrentImage(std::string filename)
137 {
138   QString image = "<b>CurrentImage : </b>";
139   image += vtksys::SystemTools::GetFilenameWithoutLastExtension(filename).c_str();
140   nameLabel->setText(image);
141 }
142
143 void vvLandmarksPanel::CommentsChanged(int row, int column)
144 {
145   if (column == 6) {
146     mCurrentLandmarks->ChangeComments(row,std::string(tableWidget->item(row,column)->text().toStdString()));
147     tableWidget->resizeColumnsToContents();
148   }
149 }
150
151 #endif /* end #define _vvLandmarksPanel_CXX */
152