cmtkQtTriplanarViewer.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include "cmtkQtTriplanarViewer.h"
00034 
00035 #include <qmenu.h>
00036 #include <qmenubar.h>
00037 #include <qapplication.h>
00038 #include <qfiledialog.h>
00039 #include <qlayout.h>
00040 #include <QVBoxLayout>
00041 
00042 #include <Qt/cmtkQtImageOperators.h>
00043 #include <Base/cmtkAnatomicalOrientation.h>
00044 #include <IO/cmtkStudy.h>
00045 
00046 namespace
00047 cmtk
00048 {
00049 
00052 
00053 QtTriplanarViewer::QtTriplanarViewer()
00054   : WindowLevel( NULL )
00055 {
00056   this->setWindowTitle( "Triplanar Image Viewer" );
00057 
00058   QMenu* StudyMenu = new QMenu();
00059   StudyMenu->setTitle( "&Study" );
00060   StudyMenu->addAction( "&Load...", this, SLOT( slotLoadFile() )  );
00061   StudyMenu->addAction( "&Reload Data...", this, SLOT( slotReloadData() )  );
00062   StudyMenu->addSeparator();
00063   StudyMenu->addAction( "&Save" );
00064   StudyMenu->addAction( "Save &as..." );
00065   StudyMenu->addAction( "&Export landmarks..." );
00066   StudyMenu->addSeparator();
00067   StudyMenu->addAction( "&Quit", qApp, SLOT( quit() ) );
00068   
00069   QtImageOperators* imageOperators = new QtImageOperators( &this->m_Study, this, NULL /*progressInstance*/ );
00070   QObject::connect( imageOperators, SIGNAL( dataChanged( Study::SmartPtr& ) ), this, SLOT( slotDataChanged( Study::SmartPtr& ) ) );
00071   
00072   // insert "Study" as first menu.
00073   MenuBar->insertMenu( this->ViewMenu->menuAction(), StudyMenu );
00074   // insert "Operators" after "View".
00075   MenuBar->addMenu( imageOperators->CreatePopupMenu() );
00076   MenuBar->show();
00077   
00078   this->m_ImagesTab = new QWidget( this->m_ControlsTab );
00079   this->m_ControlsTab->addTab( this->m_ImagesTab, "Images" );
00080   this->m_ControlsTab->setTabEnabled( this->m_ControlsTab->indexOf( this->m_ImagesTab ), false );
00081 
00082   this->m_StudiesListBox = new QListWidget( this->m_ImagesTab );
00083   this->m_StudiesListBox->setSelectionMode( QAbstractItemView::SingleSelection );
00084 //  this->m_StudiesListBox->setColumnMode( QListWidget::FixedNumber );
00085   QObject::connect( this->m_StudiesListBox, SIGNAL( currentTextChanged( const QString& ) ), this, SLOT( slotSwitchStudy( const QString& ) ) );
00086 
00087   QVBoxLayout* studiesLayout = new QVBoxLayout( this->m_ImagesTab );
00088   studiesLayout->setContentsMargins( 5, 5, 5, 5 );
00089   studiesLayout->setSpacing( 5 );
00090 
00091   studiesLayout->addWidget( this->m_StudiesListBox );
00092 
00093   QPushButton* copyColormapButton = new QPushButton( this->m_ImagesTab );
00094   copyColormapButton->setText( "Copy Colormap to Other Images" );
00095   studiesLayout->addWidget( copyColormapButton );
00096 
00097   QObject::connect( copyColormapButton, SIGNAL( clicked() ), this, SLOT( slotCopyColormapToOtherImages() ) );
00098 }
00099 
00100 void
00101 QtTriplanarViewer::slotAddStudy( const char* fname )
00102 {
00103   Study::SmartPtr newStudy( new Study( fname ) );
00104   this->m_StudiesListBox->addItem( QString( newStudy->GetFileSystemPath() ) );
00105 
00106   this->m_Studies.push_back( newStudy );
00107   this->m_ControlsTab->setTabEnabled( this->m_ControlsTab->indexOf( this->m_ImagesTab ), this->m_Studies.size() > 1 );
00108 
00109   this->slotSwitchToStudy( newStudy );
00110   this->slotCenter();
00111 }
00112 
00113 void
00114 QtTriplanarViewer::slotLoadFile()
00115 {
00116 #ifdef CMTK_BUILD_NRRD
00117   QString path = QFileDialog::getOpenFileName( this, "Load File", QString(), "All image files (*.hdr *.nii *.nii.gz *.nrrd *.nhdr *.pic);; NIfTI / Analyze (*.hdr *.nii *.nii.gz);; Nrrd (*.nhdr *.nrrd);; BIORAD (*.pic)" );
00118 #else
00119   QString path = QFileDialog::getOpenFileName( this, "Load File", QString(), "All image files (*.hdr *.nii *.nii.gz *.pic);; NIfTI / Analyze (*.hdr *.nii *.nii.gz);; BIORAD (*.pic)" );
00120 #endif
00121   
00122   if ( ! (path.isEmpty() || path.isNull() ) ) 
00123     {
00124     Study::SmartPtr newStudy( new Study( path.toLatin1() ) );
00125 
00126     this->m_Studies.push_back( newStudy );
00127     this->m_ControlsTab->setTabEnabled( this->m_ControlsTab->indexOf( this->m_ImagesTab ), this->m_Studies.size() > 1 );
00128     
00129     this->m_StudiesListBox->addItem( QString( newStudy->GetFileSystemPath() ) );
00130     this->m_StudiesListBox->setCurrentItem( this->m_StudiesListBox->item( this->m_StudiesListBox->count()-1 ) );
00131 
00132     this->slotSwitchToStudy( newStudy );
00133     this->slotCenter();
00134     }
00135 }
00136 
00137 void
00138 QtTriplanarViewer::slotReloadData()
00139 {
00140   if ( this->m_Study ) 
00141     {
00142     this->m_Study->ReadVolume( true /* reload */, AnatomicalOrientation::ORIENTATION_STANDARD );
00143     }
00144 }
00145 
00146 void
00147 QtTriplanarViewer::slotSwitchStudy( const QString& study )
00148 {
00149   for ( size_t idx = 0; idx < this->m_Studies.size(); ++idx )
00150     {
00151     if ( study == QString( this->m_Studies[idx]->GetFileSystemPath() ) )
00152       {
00153       this->slotSwitchToStudyInternal( this->m_Studies[idx] );
00154       return;
00155       }
00156     }
00157 }
00158 
00159 void
00160 QtTriplanarViewer::slotCopyColormapToOtherImages()
00161 {
00162   if ( this->m_Study ) 
00163     {
00164     for ( size_t i = 0; i < this->m_Studies.size(); ++i )
00165       {
00166       if ( this->m_Studies[i] != this->m_Study )
00167         {
00168         this->m_Studies[i]->CopyColormap( this->m_Study );
00169         }
00170       }
00171     }
00172 }
00173 
00174 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines