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 132 133 134 135 136
|
/*
//
// Copyright 2010-2012 SRI International
//
// Copyright 2010 Torsten Rohlfing
//
// 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 __cmtkRegion_h_included_
#define __cmtkRegion_h_included_
#include <cmtkconfig.h>
#include <Base/cmtkFixedVector.h>
#include <System/cmtkSmartPtr.h>
#include <System/cmtkSmartConstPtr.h>
#include <fstream>
namespace
cmtk
{
/// Class for n-dimensional image index.
template<size_t NDIM,typename T=int>
class Region
{
public:
/// This class.
typedef Region<NDIM,T> Self;
/// The region dimension.
static const size_t Dimension = NDIM;
/// The region index variable type.
typedef T ScalarType;
/// Index type.
typedef FixedVector<NDIM,T> IndexType;
/// Smart pointer to this class.
typedef SmartPointer<Self> SmartPtr;
/// Smart pointer-to-const to this class.
typedef SmartConstPointer<Self> SmartConstPtr;
/// Default constructor.
Region() {}
/// Constructor from two indexes, from and to.
Region( const typename Self::IndexType& fromIndex /*!< Region goes from this index. */,
const typename Self::IndexType& toIndex /*!< Region goes to this index. */ )
{
this->m_RegionFrom = fromIndex;
this->m_RegionTo = toIndex;
}
/// Get "from".
typename Self::IndexType& From()
{
return this->m_RegionFrom;
}
/// Get const "from".
const typename Self::IndexType& From() const
{
return this->m_RegionFrom;
}
/// Get "from".
typename Self::IndexType& To()
{
return this->m_RegionTo;
}
/// Get const "from".
const typename Self::IndexType& To() const
{
return this->m_RegionTo;
}
/// Compute region size (e.g., number of pixels for grid regions).
T Size() const
{
T size = std::max<T>( 0, (this->m_RegionTo[0]-this->m_RegionFrom[0]) );
for ( size_t i = 1; i < NDIM; ++i )
size *= std::max<T>( 0, (this->m_RegionTo[i]-this->m_RegionFrom[i]) );
return size;
}
/// Check if an index is inside region.
bool IsInside( const typename Self::IndexType idx ) const
{
return (this->m_RegionFrom <= idx) && (idx < this->m_RegionTo);
}
/// Get one face of the region, as a region
const Self GetFaceRegion( const int dim /*!< Returned face is orthogonal to this index dimension */, const bool upper = false /*!< If true, upper face is returned, otherwise lower face.*/ ) const;
private:
/// Lower limit of the region.
typename Self::IndexType m_RegionFrom;
/// Upper limit of the region.
typename Self::IndexType m_RegionTo;
};
} // namespace cmtk
#include "cmtkRegion.txx"
#endif // #ifndef __cmtkRegion_h_included_
|