| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkBoundingBox.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:33 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
Portions of this code are covered under the VTK copyright. |
| 13 |
|
See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. |
| 14 |
|
|
| 15 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 16 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 17 |
IND |
*****PURPOSE. See the above copyright notices for more information. |
| 18 |
|
|
| 19 |
|
=========================================================================*/ |
| 20 |
|
#ifndef __itkBoundingBox_h |
| 21 |
|
#define __itkBoundingBox_h |
| 22 |
|
|
| 23 |
|
#include "itkObject.h" |
| 24 |
|
#include "itkPoint.h" |
| 25 |
|
#include "itkNumericTraits.h" |
| 26 |
|
#include "itkVectorContainer.h" |
| 27 |
|
#include "itkFixedArray.h" |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
namespace itk |
| 31 |
|
{ |
| 32 |
|
|
| 33 |
|
/** \class BoundingBox |
| 34 |
|
* \brief Represent and compute information about bounding boxes. |
| 35 |
|
* |
| 36 |
|
* BoundingBox is a supporting class that represents, computes, and |
| 37 |
|
* caches information about bounding boxes. The bounding box can |
| 38 |
|
* be computed from several sources, including manual specification |
| 39 |
|
* and computation from an input points container. |
| 40 |
|
* |
| 41 |
|
* This is a templated, n-dimensional version of the bounding box. |
| 42 |
|
* Bounding boxes are represented by n pairs of (min,max) pairs, |
| 43 |
|
* where min is the minimum coordinate value and max is the |
| 44 |
|
* maximum coordinate value for coordinate axis i. |
| 45 |
|
* |
| 46 |
|
* Template parameters for BoundingBox: |
| 47 |
|
* |
| 48 |
|
* TPointIdentifier = |
| 49 |
|
* The type used to access a particular point (i.e., a point's id) |
| 50 |
|
* |
| 51 |
|
* TCoordRep = |
| 52 |
|
* Numerical type with which to represent each coordinate value. |
| 53 |
|
* |
| 54 |
|
* VPointDimension = |
| 55 |
|
* Geometric dimension of space. |
| 56 |
|
* |
| 57 |
|
* \ingroup DataRepresentation |
| 58 |
|
* \ingroup ImageObjects |
| 59 |
|
*/ |
| 60 |
|
|
| 61 |
|
template < |
| 62 |
|
typename TPointIdentifier = unsigned long, |
| 63 |
|
int VPointDimension = 3, |
| 64 |
|
typename TCoordRep = float, |
| 65 |
|
typename TPointsContainer = |
| 66 |
|
VectorContainer< TPointIdentifier,Point<TCoordRep, VPointDimension> > |
| 67 |
IND |
**> |
| 68 |
|
class ITK_EXPORT BoundingBox : public Object |
| 69 |
|
{ |
| 70 |
|
public: |
| 71 |
|
/** Standard class typedefs. */ |
| 72 |
|
typedef BoundingBox Self; |
| 73 |
TDA |
typedef Object Superclass; |
| 74 |
|
typedef SmartPointer<Self> Pointer; |
| 75 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 76 |
|
|
| 77 |
|
/** Method for creation through the object factory. */ |
| 78 |
|
itkNewMacro(Self); |
| 79 |
|
|
| 80 |
|
/** Hold on to the type information specified by the template parameters. */ |
| 81 |
|
typedef TPointIdentifier PointIdentifier; |
| 82 |
TDA |
typedef TCoordRep CoordRepType; |
| 83 |
|
typedef TPointsContainer PointsContainer; |
| 84 |
TDA |
typedef typename PointsContainer::Pointer PointsContainerPointer; |
| 85 |
TDA |
typedef typename PointsContainer::ConstPointer PointsContainerConstPointer; |
| 86 |
TDA |
typedef Point< CoordRepType, VPointDimension > PointType; |
| 87 |
TDA |
typedef FixedArray< CoordRepType, VPointDimension*2 > BoundsArrayType; |
| 88 |
|
|
| 89 |
|
/** Hold on to the dimensions specified by the template parameters. */ |
| 90 |
|
itkStaticConstMacro(PointDimension, unsigned int, VPointDimension); |
| 91 |
|
|
| 92 |
|
/** Convenient typedefs.*/ |
| 93 |
|
typedef typename |
| 94 |
IND |
**********PointsContainer::ConstIterator PointsContainerConstIterator; |
| 95 |
|
typedef typename |
| 96 |
IND |
**********PointsContainer::Iterator PointsContainerIterator; |
| 97 |
|
|
| 98 |
|
/** Set/Get the points from which the bounding box should be computed. The |
| 99 |
|
* bounding box is cached and is not recomputed if the points are not |
| 100 |
|
* changed. */ |
| 101 |
|
void SetPoints(const PointsContainer *); |
| 102 |
|
const PointsContainer * GetPoints(void) const; |
| 103 |
|
|
| 104 |
|
/** Compute and return the corners of the bounding box */ |
| 105 |
|
const PointsContainer * GetCorners(void); |
| 106 |
|
|
| 107 |
|
/** Method that actually computes bounding box. */ |
| 108 |
|
bool ComputeBoundingBox(void) const; |
| 109 |
|
|
| 110 |
|
/** Get the bounding box. This method should only be invoked after |
| 111 |
IND |
** ComputeBoundingBox(), otherwise the Bounds values will not be up to date. |
| 112 |
IND |
** Note that many methods in this class invoke ComputeBoundingBox() internally, |
| 113 |
IND |
** for example GetMinimum(), GetMaximum(), GetCenter(), GetDiagonalLength2(). |
| 114 |
IND |
** Therefore it is safe to invoke GetBounds() after any of those methods. */ |
| 115 |
|
itkGetConstReferenceMacro( Bounds, BoundsArrayType ); |
| 116 |
|
|
| 117 |
|
/** Get the center of the bounding box. Returns NULL if bounding box |
| 118 |
|
* cannot be computed. */ |
| 119 |
|
PointType GetCenter(void) const; |
| 120 |
|
|
| 121 |
|
/** Get the minimum point of the bounding box. Returns NULL if bounding box |
| 122 |
|
* cannot be computed. */ |
| 123 |
|
PointType GetMinimum(void) const; |
| 124 |
|
|
| 125 |
|
/** Set the minimum point of the bounding box. May not be valid for the given |
| 126 |
|
* set of points. Will be preserved until this filter's (i.e., the point |
| 127 |
|
* set's) modified time changes. */ |
| 128 |
|
void SetMinimum(const PointType & ); |
| 129 |
|
|
| 130 |
|
/** Get the maximum point of the bounding box. Returns NULL if bounding box |
| 131 |
|
* cannot be computed. */ |
| 132 |
|
PointType GetMaximum(void) const; |
| 133 |
|
|
| 134 |
|
/** Set the maximum point of the bounding box. May not be valid for the given |
| 135 |
|
* set of points. Will be preserved until this filter's (i.e., the point |
| 136 |
|
* set's) modified time changes. */ |
| 137 |
|
void SetMaximum(const PointType & ); |
| 138 |
|
|
| 139 |
|
/** Adjust bounds (if necessary) as if the given point was in the set |
| 140 |
|
* of points being considered. Does not add the given point to the set. |
| 141 |
|
* Therefore, this point not considered in future computeboundingbox/gets |
| 142 |
|
* once the point set is changed. */ |
| 143 |
|
void ConsiderPoint( const PointType & ); |
| 144 |
|
|
| 145 |
|
/** Get the length squared of the diagonal of the bounding box. |
| 146 |
|
* Returns zero if bounding box cannot be computed. Note that the |
| 147 |
|
* Accumulate type is used to represent the length. */ |
| 148 |
|
typedef typename NumericTraits<CoordRepType>::AccumulateType AccumulateType; |
| 149 |
|
AccumulateType GetDiagonalLength2(void) const; |
| 150 |
|
|
| 151 |
|
/** Method that checks if a point is inside the bounding box. */ |
| 152 |
|
bool IsInside( const PointType & ) const; |
| 153 |
|
|
| 154 |
|
/** Method Compute the Modified Time based on changed to the components. */ |
| 155 |
|
unsigned long GetMTime( void ) const; |
| 156 |
|
|
| 157 |
|
/** Duplicates this bounding box */ |
| 158 |
|
Pointer DeepCopy() const; |
| 159 |
|
|
| 160 |
|
#if 0 |
| 161 |
|
/** |
| 162 |
|
* Intersect this bounding box (bounds[PointDimension*2]) with a line |
| 163 |
|
* given by an origin (origin[PointDimension]) and direction |
| 164 |
|
* (direction[PointDimension]). Get the following results if the |
| 165 |
|
* corresponding pointers are not NULL: |
| 166 |
|
* |
| 167 |
|
* - The intersection point's geometric coordinates (returned through |
| 168 |
|
* pointer to array: coords[PointDimension]). |
| 169 |
|
* |
| 170 |
|
* - The line's parametric coordinate of the intersection point |
| 171 |
|
* (returned through "t" pointer). |
| 172 |
|
* |
| 173 |
|
* Returns whether an intersection exists. |
| 174 |
|
*/ |
| 175 |
|
bool IntersectWithLine(CoordRepType origin[PointDimension], |
| 176 |
|
CoordRepType direction[PointDimension], |
| 177 |
|
CoordRepType coords[PointDimension], |
| 178 |
|
CoordRepType* t); |
| 179 |
|
|
| 180 |
|
#endif |
| 181 |
|
|
| 182 |
|
protected: |
| 183 |
|
BoundingBox(); |
| 184 |
|
virtual ~BoundingBox(); |
| 185 |
|
void PrintSelf(std::ostream& os, Indent indent) const; |
| 186 |
|
|
| 187 |
|
typedef typename PointsContainer::ConstIterator ConstIterator; |
| 188 |
|
|
| 189 |
|
private: |
| 190 |
|
BoundingBox(const Self&); //purposely not implemented |
| 191 |
|
void operator=(const Self&); //purposely not implemented |
| 192 |
|
|
| 193 |
|
PointsContainerConstPointer m_PointsContainer; |
| 194 |
|
PointsContainerPointer m_CornersContainer; |
| 195 |
|
mutable BoundsArrayType m_Bounds; |
| 196 |
LEN |
mutable TimeStamp m_BoundsMTime; //The last time the bounds were computed. |
| 197 |
|
|
| 198 |
|
}; |
| 199 |
|
|
| 200 |
|
} // end namespace itk |
| 201 |
|
|
| 202 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 203 |
|
#include "itkBoundingBox.txx" |
| 204 |
|
#endif |
| 205 |
|
|
| 206 |
|
#endif |
| 207 |
|
|