cmtkSimpleLevelsetCommandLineBase.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2010 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 "cmtkSimpleLevelsetCommandLineBase.h"
00034 
00035 #include <System/cmtkConsole.h>
00036 
00037 #include <IO/cmtkVolumeIO.h>
00038 
00039 cmtk::SimpleLevelsetCommandLineBase::SimpleLevelsetCommandLineBase()
00040   : m_Verbose( false ),
00041     m_ScaleInitialSphere( 1.0 ),
00042     m_FilterSigma( 2.0 ),    
00043     m_TimeDelta( 0.1 ),
00044     m_LevelsetThreshold( 1.0 ),
00045     m_NumberOfIterations( 100 ),
00046     m_ForceIterations( false ),
00047     m_Binarize( false ),    
00048     m_InFile( NULL ),
00049     m_OutFile( NULL ),
00050     m_CommandLine( cmtk::CommandLine::PROPS_XML )
00051 {
00052 #ifdef CMTK_USE_SQLITE
00053   this->m_UpdateDB = NULL;
00054 #endif
00055 
00056   this->m_CommandLine.SetProgramInfo( CommandLine::PRG_TITLE, "Levelset segmentation" );
00057   this->m_CommandLine.SetProgramInfo( CommandLine::PRG_DESCR, "Levelset-type segmentation of foreground/background using minimum regional variance energy" );
00058   this->m_CommandLine.SetProgramInfo( CommandLine::PRG_CATEG, "CMTK.Segmentation" );
00059   
00060   typedef CommandLine::Key Key;
00061   this->m_CommandLine.AddSwitch( Key( 'v', "verbose" ), &this->m_Verbose, true, "Verbose mode" )->SetProperties( CommandLine::PROPS_NOXML );
00062   
00063   this->m_CommandLine.AddSwitch( Key( 'b', "binarize" ), &this->m_Binarize, true, "Binarize levelset and write as byte mask, rather than write floating-point levelset function itself." );
00064   
00065   this->m_CommandLine.BeginGroup( "Levelset Initialization", "These parameters control the initialization of the levelset function" )->SetProperties( CommandLine::PROPS_ADVANCED );
00066   this->m_CommandLine.AddOption( Key( "scale-initial-sphere" ), &this->m_ScaleInitialSphere, "Scale factor to reduce or increase the size of the initial foreground region sphere." );
00067   this->m_CommandLine.EndGroup();
00068 
00069   this->m_CommandLine.BeginGroup( "Levelset Evolution Parameters", "These parameters control the evolution of the levelset function" )->SetProperties( CommandLine::PROPS_ADVANCED );
00070   this->m_CommandLine.AddOption( Key( 'n', "iterations" ), &this->m_NumberOfIterations, "Maximum number of iterations" );
00071   this->m_CommandLine.AddSwitch( Key( 'f', "force-iterations" ), &this->m_ForceIterations, true, "Force given number of iterations, even when convergence has been detected" );
00072   
00073   this->m_CommandLine.AddOption( Key( 's', "filter-sigma" ), &this->m_FilterSigma, "Gaussian filter sigma in world coordinate units (e.g., mm)" );
00074   this->m_CommandLine.AddOption( Key( 'd', "delta" ), &this->m_TimeDelta, "Time constant for levelset evolution; must be > 0; larger is faster" );
00075   this->m_CommandLine.AddOption( Key( 't', "levelset-threshold" ), &this->m_LevelsetThreshold, "Levelset threshold: levelset function is truncated at +/- this value" );
00076   this->m_CommandLine.EndGroup();
00077   
00078 #ifdef CMTK_USE_SQLITE
00079   this->m_CommandLine.BeginGroup( "Database", "Image/Transformation Database" );
00080   this->m_CommandLine.AddOption( Key( "db" ), &this->m_UpdateDB, "Path to image/transformation database that should be updated with the newly created image." );
00081   this->m_CommandLine.EndGroup();
00082 #endif
00083   
00084   this->m_CommandLine.AddParameter( &this->m_InFile, "InputImage", "Input image path" )->SetProperties( CommandLine::PROPS_IMAGE );
00085   this->m_CommandLine.AddParameter( &this->m_OutFile, "OutputImage", "Output image path" )->SetProperties( CommandLine::PROPS_IMAGE | CommandLine::PROPS_LABELS | CommandLine::PROPS_OUTPUT );
00086 }
00087 
00088 int
00089 cmtk::SimpleLevelsetCommandLineBase::Init( const int argc, const char* argv[] )
00090 {
00091   try
00092     {
00093     this->m_CommandLine.Parse( argc, argv );
00094     }
00095   catch ( const cmtk::CommandLine::Exception& ex )
00096     {
00097     cmtk::StdErr << ex;
00098     return 1;
00099     }
00100   
00101   this->m_Volume = cmtk::VolumeIO::ReadOriented( this->m_InFile, this->m_Verbose );
00102 
00103   if ( !this->m_Volume )
00104     return 1;
00105 
00106   return 0;
00107 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines