cmtkQtImageOperators.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 "cmtkQtImageOperators.h"
00034 
00035 #include <math.h>
00036 
00037 #include <qinputdialog.h>
00038 
00039 #include <Qt/cmtkQtProgress.h>
00040 
00041 #include <Base/cmtkTypedArrayFunctionHistogramEqualization.h>
00042 #include <Base/cmtkDataGridFilter.h>
00043 #include <Base/cmtkMathFunctionWrappers.h>
00044 
00045 namespace
00046 cmtk
00047 {
00048 
00051 
00052 QMenu*
00053 QtImageOperators::CreatePopupMenu()
00054 {
00055   QMenu* operatorsMenu = new QMenu;
00056   operatorsMenu->setTitle( "&Operators" );
00057   operatorsMenu->addAction( "&Median Filter...", this, SLOT( slotOperatorMedian() ) );
00058   operatorsMenu->addAction( "&Histogram Equalization...", this, SLOT( slotOperatorHistEq() ) );
00059   operatorsMenu->addAction( "&Sobel Edge Filter", this, SLOT( slotOperatorSobel() ) );
00060   operatorsMenu->addSeparator();
00061 
00062   QMenu* algOperatorsMenu = operatorsMenu->addMenu( "&Algebraic" );
00063   algOperatorsMenu->addAction( "&abs()", this, SLOT( slotOperatorAbs() ) );
00064   algOperatorsMenu->addAction( "&log()", this, SLOT( slotOperatorLog() ) );
00065   algOperatorsMenu->addAction( "&exp()", this, SLOT( slotOperatorExp() ) );
00066 
00067   return operatorsMenu;
00068 }
00069 
00070 void
00071 QtImageOperators::slotOperatorMedian()
00072 {
00073   if ( this->StudyDataValid() ) 
00074     {
00075     bool ok;
00076     int radius = QInputDialog::getInt( this->Parent, "Median Filter", "Neighborhood radius:",  1, 1, 5, 1, &ok );
00077     if ( ok )
00078       {
00079       // user entered something and pressed OK
00080       if ( this->ProgressInstance )
00081         this->ProgressInstance->SetProgressWidgetMode( QtProgress::PROGRESS_DIALOG );
00082 
00083       (*(this->CurrentStudy))->GetVolume()->SetData( DataGridFilter( (*(this->CurrentStudy))->GetVolume() ).GetDataMedianFiltered( radius ) );
00084       
00085       emit dataChanged( *(this->CurrentStudy) );
00086       } 
00087     else
00088       {
00089       // user pressed Cancel
00090       }
00091     }
00092 }
00093 
00094 void
00095 QtImageOperators::slotOperatorSobel()
00096 {
00097   if ( this->StudyDataValid() ) 
00098     {
00099     if ( this->ProgressInstance )
00100       this->ProgressInstance->SetProgressWidgetMode( QtProgress::PROGRESS_BAR );
00101 
00102     (*(this->CurrentStudy))->GetVolume()->SetData( DataGridFilter( (*(this->CurrentStudy))->GetVolume() ).GetDataSobelFiltered() );
00103 
00104     emit dataChanged( *(this->CurrentStudy) );
00105     }
00106 }
00107 
00108 void
00109 QtImageOperators::slotOperatorHistEq()
00110 {
00111   if ( this->StudyDataValid() ) 
00112     {
00113     if ( this->ProgressInstance )
00114       this->ProgressInstance->SetProgressWidgetMode( QtProgress::PROGRESS_BAR );
00115     bool ok;
00116     int bins = QInputDialog::getInt( this->Parent, "Histogram Equalization", "Number of Histogram Bins:", 256, 2, 256, 1, &ok );
00117     if ( ok ) 
00118       {
00119       // user entered something and pressed OK
00120       if ( this->ProgressInstance )
00121         this->ProgressInstance->SetProgressWidgetMode( QtProgress::PROGRESS_DIALOG );
00122       (*(this->CurrentStudy))->GetVolume()->GetData()->ApplyFunctionObject( TypedArrayFunctionHistogramEqualization( (*(*(this->CurrentStudy))->GetVolume()->GetData()), bins ) );
00123       emit dataChanged( *(this->CurrentStudy) );
00124       } 
00125     else
00126       {
00127       // user pressed Cancel
00128       }
00129     }
00130 }
00131 
00132 void
00133 QtImageOperators::slotOperatorAbs()
00134 {
00135   if ( this->StudyDataValid() ) 
00136     {
00137     (*(this->CurrentStudy))->GetVolume()->GetData()->ApplyFunctionDouble( cmtk::Wrappers::Abs );
00138     emit dataChanged( *(this->CurrentStudy) );
00139     }
00140 }
00141 
00142 void
00143 QtImageOperators::slotOperatorLog()
00144 {
00145   if ( this->StudyDataValid() ) 
00146     {
00147     (*(this->CurrentStudy))->GetVolume()->GetData()->ApplyFunctionDouble( cmtk::Wrappers::Log );
00148     emit dataChanged( *(this->CurrentStudy) );
00149     }
00150 }
00151 
00152 void
00153 QtImageOperators::slotOperatorExp()
00154 {
00155   if ( this->StudyDataValid() ) 
00156     {
00157     (*(this->CurrentStudy))->GetVolume()->GetData()->ApplyFunctionDouble( cmtk::Wrappers::Exp );
00158     emit dataChanged( *(this->CurrentStudy) );
00159     }
00160 }
00161 
00162 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines