1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*
//
// Copyright 1997-2009 Torsten Rohlfing
//
// Copyright 2004-2011, 2013 SRI International
//
// This file is part of the Computational Morphometry Toolkit.
//
// http://www.nitrc.org/projects/cmtk/
//
// The Computational Morphometry Toolkit is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// The Computational Morphometry Toolkit is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with the Computational Morphometry Toolkit. If not, see
// <http://www.gnu.org/licenses/>.
//
// $Revision: 5436 $
//
// $LastChangedDate: 2018-12-10 19:01:20 -0800 (Mon, 10 Dec 2018) $
//
// $LastChangedBy: torstenrohlfing $
//
*/
#ifndef __cmtkTypedArraySimilarityMemory_h_included_
#define __cmtkTypedArraySimilarityMemory_h_included_
#include <cmtkconfig.h>
#include <Base/cmtkJointHistogram.h>
namespace
cmtk
{
/** \addtogroup Registration */
//@{
/** Memory for typed array similarity computation.
* This class provides for optional persistent memory between similarity
* computations. This ensures, for example, identical value ranges in
* histogram-based similarity measures.
*/
class TypedArraySimilarityMemory
{
public:
/** Initialize a similarity instance with memory.
* By instantiating a class object, the otherwise static member functions
* can be given a memory that coordinates their behaviour between calls. For
* example, we can make sure that all evaluations of Mutual Information use
* the same histogram resolution.
*\param repeatCheck If this flag is set, the object will repeat the range
* check for every call to GetRangeX or GetRangeY. If the current data
* range exceeds the one stored in this object, the latter will be adapted
* accordingly.
*/
TypedArraySimilarityMemory( const bool repeatCheck = true )
: ValidX( false ), RangeX( 0, 0 ), NumberBinsX( 0 ),
ValidY( false ), RangeY( 0, 0 ), NumberBinsY( 0 ),
MinNumBins( 8 ),
MaxNumBins( 128 )
{
RepeatCheck = repeatCheck;
}
/** Get range of X distribution.
* If this object is not yet initialized, the given array is queried for
* its value range, and this object is initialized accordingly.
*/
const Types::DataItemRange GetRangeX( const TypedArray* array, const size_t numBins );
/** Get range of Y distribution.
* If this object is not yet initialized, the given array is queried for
* its value range, and this object is initialized accordingly.
*/
const Types::DataItemRange GetRangeY( const TypedArray* array, const size_t numBins );
/// Set minimum number of histogram bins.
void SetMinNumBins( const size_t minNumBins ) { MinNumBins = minNumBins; }
/// Set maximum number of histogram bins.
void SetMaxNumBins( const size_t maxNumBins ) { MaxNumBins = maxNumBins; }
/// Create histogram based on memorized settings.
JointHistogram<unsigned int>::SmartPtr CreateHistogram( const TypedArray* array0, const TypedArray* array1 );
private:
/// Repeat range check with each call to GetRangeX and GetRangeY.
bool RepeatCheck;
/// Flag whether memory for X distribution is already initialized.
bool ValidX;
/// Remembered range of X values.
Types::DataItemRange RangeX;
/// Remembered number of bins for the X distribution.
size_t NumberBinsX;
/// Flag whether memory for X distribution is already initialized.
bool ValidY;
/// Remembered range of Y values.
Types::DataItemRange RangeY;
/// Remembered number of bins for the Y distribution.
size_t NumberBinsY;
/// Minimum number of histogram bins.
size_t MinNumBins;
/// Maximum number of histogram bins.
size_t MaxNumBins;
/// Allow similarity computation class access.
friend class TypedArraySimilarity;
};
//@}
} // namespace cmtk
#endif // #ifndef __cmtkTypedArraySimilarityMemory_h_included_
|