cmtkQtWindowLevelControls.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: 2675 $
00026 //
00027 //  $LastChangedDate: 2010-12-15 14:43:28 -0800 (Wed, 15 Dec 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include "cmtkQtWindowLevelControls.h"
00034 
00035 #include <Pipeline/cmtkColormap.h>
00036 
00037 #include <qcombobox.h>
00038 
00039 namespace
00040 cmtk
00041 {
00042 
00045 
00046 QtWindowLevelControls::QtWindowLevelControls
00047 ( QWidget *const parent )
00048   : QWidget( parent ),
00049     m_Study( NULL )
00050 {
00051   Layout = new QVBoxLayout( this );
00052   Layout->setContentsMargins( 5, 5, 5, 5 );
00053 
00054   QComboBox* colormapBox = new QComboBox( this );
00055   Layout->addWidget( colormapBox );
00056   
00057   for ( unsigned int colormapIndex = 0; Colormap::StandardColormaps[colormapIndex]; ++colormapIndex ) 
00058     {
00059     colormapBox->addItem( Colormap::StandardColormaps[colormapIndex] );
00060     }
00061   
00062   QObject::connect( colormapBox, SIGNAL( activated( int ) ), this, SLOT( slotSelectColormap( int ) ) );
00063 
00064   BlackWindowSlider = new QtSliderEntry( this );
00065   QObject::connect( BlackWindowSlider, SIGNAL( valueChanged( double ) ), this, SLOT( slotControlsChanged() ) );
00066   BlackWindowSlider->slotSetTitle( "Black" );
00067   BlackWindowSlider->slotSetMinMaxLabels( QString::null, QString::null );
00068   Layout->addWidget( BlackWindowSlider );
00069 
00070   WhiteLevelSlider = new QtSliderEntry( this );
00071   QObject::connect( WhiteLevelSlider, SIGNAL( valueChanged( double ) ), this, SLOT( slotControlsChanged() ) );
00072   WhiteLevelSlider->slotSetTitle( "White" );
00073   WhiteLevelSlider->slotSetMinMaxLabels( QString::null, QString::null );
00074   Layout->addWidget( WhiteLevelSlider );
00075 
00076   WindowLevelCheckBox = new QCheckBox( "Window/Level", this );
00077   QObject::connect( WindowLevelCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( slotSwitchModeWL( int ) ) );
00078   Layout->addWidget( WindowLevelCheckBox );
00079 
00080   GammaSlider = new QtSliderEntry( this );
00081   GammaSlider->slotSetPrecision( 1 );
00082   GammaSlider->slotSetRange( 0.1, 10 );
00083   GammaSlider->slotSetValue( 1 );
00084   GammaSlider->slotSetTitle( "Gamma Value" );
00085   GammaSlider->slotSetMinMaxLabels( QString::null, QString::null );
00086   QObject::connect( GammaSlider, SIGNAL( valueChanged( double ) ), this, SLOT( slotControlsChanged() ) );
00087   Layout->addWidget( GammaSlider );
00088 
00089   Layout->addItem( new QSpacerItem( 0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
00090 }
00091 
00092 void
00093 QtWindowLevelControls::slotSetStudy( Study::SmartPtr& study )
00094 {
00095   this->m_Study = study;
00096   RangeFrom = this->m_Study->GetMinimumValue();
00097   RangeTo = this->m_Study->GetMaximumValue();
00098 
00099   RangeWidth = RangeTo - RangeFrom;
00100 
00101   const Volume* volume = this->m_Study->GetVolume();
00102   if ( volume ) 
00103     {
00104     const TypedArray* volumeData = volume->GetData();
00105     if ( volumeData ) 
00106       {
00107       Types::DataItem mean, variance;
00108       volumeData->GetStatistics( mean, variance );
00109       RangeWidth = sqrt( variance );
00110       }
00111     }
00112   
00113   this->slotSwitchModeWL( WindowLevelCheckBox->isChecked() );
00114 }
00115 
00116 void 
00117 QtWindowLevelControls::slotSwitchModeWL( int modeWindowLevel )
00118 {
00119   if ( !this->m_Study ) return;
00120   
00121   const float black = this->m_Study->GetBlack();
00122   const float white = this->m_Study->GetWhite();
00123   
00124   unsigned int precision = 0;
00125   
00126   if ( RangeWidth > 0 ) 
00127     {
00128     precision = static_cast<unsigned int>( std::max( 0.0, (log( 1.0 / 256 ) + log( RangeWidth )) / log(0.1) ) );
00129     }
00130   
00131   WhiteLevelSlider->slotSetPrecision( precision );
00132   BlackWindowSlider->slotSetPrecision( precision );
00133 
00134   if ( modeWindowLevel ) 
00135     {
00136     BlackWindowSlider->slotSetRange( 0, RangeTo - RangeFrom );
00137     BlackWindowSlider->slotSetValue( white - black );
00138     BlackWindowSlider->slotSetTitle( "Window" );
00139     
00140     WhiteLevelSlider->slotSetRange( RangeFrom, RangeTo );
00141     WhiteLevelSlider->slotSetValue( (white + black) / 2 );
00142     WhiteLevelSlider->slotSetTitle( "Level" );
00143     } 
00144   else
00145     {
00146     BlackWindowSlider->slotSetRange( RangeFrom, RangeTo );
00147     BlackWindowSlider->slotSetValue( black );
00148     BlackWindowSlider->slotSetTitle( "Black" );
00149     
00150     WhiteLevelSlider->slotSetRange( RangeFrom, RangeTo );
00151     WhiteLevelSlider->slotSetValue( white );
00152     WhiteLevelSlider->slotSetTitle( "White" );
00153     }
00154 }
00155 
00156 void
00157 QtWindowLevelControls::slotControlsChanged()
00158 {
00159   if ( !this->m_Study ) return;
00160 
00161   float black, white;
00162   if ( WindowLevelCheckBox->isChecked() ) 
00163     {
00164     black = WhiteLevelSlider->GetValue() - BlackWindowSlider->GetValue() / 2;
00165     white = WhiteLevelSlider->GetValue() + BlackWindowSlider->GetValue() / 2;
00166     } 
00167   else
00168     {
00169     black = BlackWindowSlider->GetValue();
00170     white = WhiteLevelSlider->GetValue();
00171     }
00172 
00173   const float gamma = GammaSlider->GetValue();
00174  
00175   this->m_Study->SetBlack( black );
00176   this->m_Study->SetWhite( white );
00177   this->m_Study->SetGamma( gamma );
00178 
00179   emit colormap( this->m_Study );
00180 }
00181 
00182 void
00183 QtWindowLevelControls::slotSelectColormap( int colormapIndex )
00184 {
00185   if ( this->m_Study )
00186     {
00187     this->m_Study->SetStandardColormap( colormapIndex );
00188     emit colormap( this->m_Study );
00189     }
00190 }
00191 
00192 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines