]> Creatis software - clitk.git/blob - vv/vvLandmarksPanel.cxx
added the new headers
[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     {
61         std::string filename = vtksys::SystemTools::GetFilenamePath(file.toStdString());
62         filename += "/" + vtksys::SystemTools::GetFilenameWithoutLastExtension(file.toStdString());
63         filename += ".txt";
64         mCurrentLandmarks->SaveFile(filename.c_str());
65     }
66 }
67
68 void vvLandmarksPanel::RemoveLastPoint()
69 {
70     if (tableWidget->rowCount() > 0)
71     {
72         tableWidget->removeRow(tableWidget->rowCount()-1);
73         mCurrentLandmarks->RemoveLastLandmark();
74         emit UpdateRenderWindows();
75     }
76 }
77
78 void vvLandmarksPanel::AddPoint()
79 {
80     AddPoint(mCurrentLandmarks->GetNumberOfPoints()-1);
81 }
82
83 void vvLandmarksPanel::AddPoint(int landmarksIndex)
84 {
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);
91
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);
96
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);
101
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);
106
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);
111
112
113     QTableWidgetItem* vItem = new QTableWidgetItem(
114         QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1));
115     vItem->setFlags(Qt::NoItemFlags);
116     tableWidget->setItem(rowIndex,5,vItem);
117
118     tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str()));
119 }
120
121 void vvLandmarksPanel::SetCurrentLandmarks(vvLandmarks* lm,int time)
122 {
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++)
130         AddPoint(i);
131     //if (time > 1)
132         //tableWidget->setColumnHidden(4,1);
133     //else
134         //tableWidget->setColumnHidden(4,0);
135     tableWidget->resizeColumnsToContents();
136 }
137
138 void vvLandmarksPanel::SetCurrentImage(std::string filename)
139 {
140     QString image = "<b>CurrentImage : </b>";
141     image += vtksys::SystemTools::GetFilenameWithoutLastExtension(filename).c_str();
142     nameLabel->setText(image);
143 }
144
145 void vvLandmarksPanel::CommentsChanged(int row, int column)
146 {
147     if (column == 6)
148     {
149         mCurrentLandmarks->ChangeComments(row,std::string(tableWidget->item(row,column)->text().toStdString()));
150         tableWidget->resizeColumnsToContents();
151     }
152 }
153
154 #endif /* end #define _vvLandmarksPanel_CXX */
155