cmtkProbeInfo.h

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: 2752 $
00026 //
00027 //  $LastChangedDate: 2011-01-17 11:33:31 -0800 (Mon, 17 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkProbeInfo_h_included_
00034 #define __cmtkProbeInfo_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Base/cmtkTypes.h>
00039 #include <Base/cmtkVector3D.h>
00040 
00041 namespace
00042 cmtk
00043 {
00044 
00047 
00053 class ProbeInfo 
00054 {
00055 public:
00060   Types::DataItem Values[8];
00061 
00064   Types::Coordinate Deltas[3];
00065 
00072   Types::Coordinate Offsets[6];
00073 
00076   Vector3D Location;
00077 
00081   Types::DataItem GetValueTrilinear () const 
00082   {
00083     return static_cast<Types::DataItem>( Offsets[2]*(Offsets[1]*(Offsets[0]*Values[0]+Offsets[3]*Values[1])+ 
00084                                              Offsets[4]*(Offsets[0]*Values[2]+Offsets[3]*Values[3]))+
00085                                  Offsets[5]*(Offsets[1]*(Offsets[0]*Values[4]+Offsets[3]*Values[5])+ 
00086                                              Offsets[4]*(Offsets[0]*Values[6]+Offsets[3]*Values[7]) ) );
00087   }
00088 
00091   Types::DataItem GetValueTrilinearAbove ( const Types::DataItem threshold ) const 
00092   {
00093     Types::DataItem result = 0;
00094     for ( int idx=0; idx<8; ++idx ) 
00095       {
00096       if ( Values[idx] >= threshold )
00097         result += static_cast<Types::DataItem>( GetWeight( idx ) * Values[idx] );
00098       }
00099     return result;
00100   }
00101 
00104   Types::DataItem GetValueTrilinearBelow ( const Types::DataItem threshold ) const 
00105   {
00106     Types::DataItem result = 0;
00107     for ( int idx=0; idx<8; ++idx ) {
00108       if ( Values[idx] < threshold )
00109         result += static_cast<Types::DataItem>( GetWeight( idx ) * Values[idx] );
00110     }
00111     return result;
00112   }
00113 
00116   byte GetNumberOfValuesAbove ( const Types::DataItem threshold ) const 
00117   {
00118     byte result = 0;
00119     for ( int idx=0; idx<8; ++idx )
00120       if ( Values[idx] >= threshold )
00121         ++result;
00122     return result;
00123   }
00124 
00127   byte GetNumberOfValuesBelow ( const Types::DataItem threshold ) const 
00128   {
00129     byte result = 0;
00130     for ( int idx=0; idx<8; ++idx )
00131       if ( Values[idx] < threshold )
00132         ++result;
00133     return result;
00134   }
00135 
00137   Types::Coordinate GetWeight( const int index ) const 
00138   {
00139     switch ( index ) 
00140       {
00141       case 0: return Offsets[2] * Offsets[1] * Offsets[0];
00142       case 1: return Offsets[2] * Offsets[1] * Offsets[3];
00143       case 2: return Offsets[2] * Offsets[4] * Offsets[0];
00144       case 3: return Offsets[2] * Offsets[4] * Offsets[3];
00145       case 4: return Offsets[5] * Offsets[1] * Offsets[0];
00146       case 5: return Offsets[5] * Offsets[1] * Offsets[3];
00147       case 6: return Offsets[5] * Offsets[4] * Offsets[0];
00148       case 7: return Offsets[5] * Offsets[4] * Offsets[3];
00149       }
00150     return 0;
00151   }
00152 
00159   Vector3D& GetPartialDerivatives ( Vector3D& d ) const 
00160   {
00161     d[0] = static_cast<Types::Coordinate>( Deltas[0] * 
00162                                            ( Offsets[2]*(Offsets[1]*Values[1]+Offsets[4]*Values[3])+
00163                                              Offsets[5]*(Offsets[1]*Values[5]+Offsets[4]*Values[7])-
00164                                              Offsets[2]*(Offsets[1]*Values[0]+Offsets[4]*Values[2])-
00165                                              Offsets[5]*(Offsets[1]*Values[4]+Offsets[4]*Values[6])) );
00166     
00167     d[1] = static_cast<Types::Coordinate>( Deltas[1] * 
00168                                            ( Offsets[2]*(Offsets[0]*Values[2]+Offsets[3]*Values[3])+
00169                                              Offsets[5]*(Offsets[0]*Values[6]+Offsets[3]*Values[7])-
00170                                              Offsets[2]*(Offsets[0]*Values[0]+Offsets[3]*Values[1])-
00171                                              Offsets[5]*(Offsets[0]*Values[4]+Offsets[3]*Values[5])) );
00172     
00173     d[2] = static_cast<Types::Coordinate>( Deltas[2] *
00174                                            ( Offsets[1]*(Offsets[0]*Values[4]+Offsets[3]*Values[5])+
00175                                              Offsets[4]*(Offsets[0]*Values[6]+Offsets[3]*Values[7])-
00176                                              Offsets[1]*(Offsets[0]*Values[0]+Offsets[3]*Values[1])-
00177                                              Offsets[4]*(Offsets[0]*Values[2]+Offsets[3]*Values[3])) );
00178     return d;
00179   }
00180 };
00181 
00183 
00184 } // namespace cmtk
00185 
00186 #endif // #ifndef __cmtkProbeInfo_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines