cisst-saw
Loading...
Searching...
No Matches
vctBoundingBox3.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Seth Billings, Russell Taylor, Anton Deguet
6 Created on: 2003-08-18
7
8 (C) Copyright 2014-2020 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#ifndef _vctBoundingBox3_h
20#define _vctBoundingBox3_h
21
23
24// Always include last!
26
27template <typename _elementType>
29{
30public:
31 typedef _elementType value_type;
34
35protected:
38 size_t mCounter;
39
40public:
41
45 mMinCorner(HUGE_VAL, HUGE_VAL, HUGE_VAL)
46 , mMaxCorner(-HUGE_VAL, -HUGE_VAL, -HUGE_VAL)
47 , mCounter(0)
48 {};
49
52 vctBoundingBox3Base(const PointType & pointA, const PointType & pointB)
53 {
54 Reset(pointA);
55 Expand(pointB);
56 }
57
61 , mMaxCorner(other.mMaxCorner)
62 , mCounter(other.mCounter)
63 {};
64
65 ThisType & operator=(const ThisType & other) {
66 mMinCorner = other.mMinCorner;
67 mMaxCorner = other.mMaxCorner;
68 mCounter = other.mCounter;
69 return *this;
70 }
71
75 ThisType & operator=(const PointType & point) {
76 Reset(point);
77 return *this;
78 }
79
81 void Reset(void) {
82 mMinCorner.SetAll(HUGE_VAL);
83 mMaxCorner.SetAll(-HUGE_VAL);
84 mCounter = 0;
85 }
86
90 void Reset(const PointType & point) {
91 mMinCorner = mMaxCorner = point;
92 mCounter = 1;
93 }
94
96 void Reset(const PointType & pointA, const PointType & pointB) {
97 Reset(pointA);
98 Expand(pointB);
99 }
100
102 const PointType & MinCorner(void) const {
103 return mMinCorner;
104 }
105
107 const PointType & MaxCorner(void) const {
108 return mMaxCorner;
109 }
110
116 size_t Counter(void) const {
117 return mCounter;
118 }
119
122 PointType Diagonal(void) const {
123 return mMaxCorner - mMinCorner;
124 }
125
126
127 double DiagonalLength(void) const {
128 return Diagonal().Norm();
129 }
130
132 PointType MidPoint(void) const {
133 return (mMinCorner + mMaxCorner) * 0.5;
134 }
135
137 ThisType & Include(const PointType & point) {
138 if (mMinCorner[0] > point[0]) mMinCorner[0] = point[0];
139 if (mMinCorner[1] > point[1]) mMinCorner[1] = point[1];
140 if (mMinCorner[2] > point[2]) mMinCorner[2] = point[2];
141 if (mMaxCorner[0] < point[0]) mMaxCorner[0] = point[0];
142 if (mMaxCorner[1] < point[1]) mMaxCorner[1] = point[1];
143 if (mMaxCorner[2] < point[2]) mMaxCorner[2] = point[2];
144 mCounter++;
145 return *this;
146 }
147
149 ThisType & Include(const ThisType & other) {
150 if (mMinCorner[0] > other.mMinCorner[0]) mMinCorner[0] = other.mMinCorner[0];
151 if (mMinCorner[1] > other.mMinCorner[1]) mMinCorner[1] = other.mMinCorner[1];
152 if (mMinCorner[2] > other.mMinCorner[2]) mMinCorner[2] = other.mMinCorner[2];
153 if (mMaxCorner[0] < other.mMaxCorner[0]) mMaxCorner[0] = other.mMaxCorner[0];
154 if (mMaxCorner[1] < other.mMaxCorner[1]) mMaxCorner[1] = other.mMaxCorner[1];
155 if (mMaxCorner[2] < other.mMaxCorner[2]) mMaxCorner[2] = other.mMaxCorner[2];
156 mCounter += other.mCounter;
157 return *this;
158 }
159
160
164 bool Expand(const value_type x, const value_type y, const value_type z) {
165 bool expanded = false;
166 if (x < mMinCorner.X()) {
167 mMinCorner.X() = x; expanded = true;
168 } else if (x > mMaxCorner.X()) {
169 mMaxCorner.X() = x; expanded = true;
170 }
171 if (y < mMinCorner.Y()) {
172 mMinCorner.Y() = y; expanded = true;
173 } else if (y > mMaxCorner.Y()) {
174 mMaxCorner.Y() = y; expanded = true;
175 }
176 if (z < mMinCorner.Z()) {
177 mMinCorner.Z() = z; expanded = true;
178 } else if (z > mMaxCorner.Z()) {
179 mMaxCorner.Z() = z; expanded = true;
180 }
181 mCounter++;
182 return expanded;
183 }
184
185 bool Expand(const PointType & point) {
186 return Expand(point.X(), point.Y(), point.Z());
187 }
188
189
191 bool Intersect(const ThisType & other) const {
192 // intersect if the max > other.min and min < other.max
193 if (mMaxCorner[0] >= other.mMinCorner[0]
194 && mMaxCorner[1] >= other.mMinCorner[1]
195 && mMaxCorner[2] >= other.mMinCorner[2]
196 && mMinCorner[0] <= other.mMaxCorner[0]
197 && mMinCorner[1] <= other.mMaxCorner[1]
198 && mMinCorner[2] <= other.mMaxCorner[2]) {
199 return true;
200 } else {
201 return false;
202 }
203 }
204
206 void EnlargeBy(const double dist) {
207 if (mCounter != 0) {
208 mMinCorner -= dist;
209 mMaxCorner+= dist;
210 }
211 }
212
215 int Includes(const PointType & point, const double dist = 0.0) const
216 {
217 if (point[0] + dist < mMinCorner[0]) return 0;
218 if (point[1] + dist < mMinCorner[1]) return 0;
219 if (point[2] + dist < mMinCorner[2]) return 0;
220 if (point[0] - dist > mMaxCorner[0]) return 0;
221 if (point[1] - dist > mMaxCorner[1]) return 0;
222 if (point[2] - dist > mMaxCorner[2]) return 0;
223 return 1; // point is within distance "dist" of this bounding box
224 }
225
228 int Includes(const ThisType & other, const double dist = 0.0) const
229 {
230 return Includes(other.mMinCorner, dist) && Includes(other.mMaxCorner, dist);
231 }
232
233};
234
235// typedefs for convenience
239
240#endif // _vctBoundingBox3_h
Definition vctBoundingBox3.h:29
void Reset(const PointType &pointA, const PointType &pointB)
Definition vctBoundingBox3.h:96
const PointType & MaxCorner(void) const
Definition vctBoundingBox3.h:107
bool Expand(const value_type x, const value_type y, const value_type z)
Definition vctBoundingBox3.h:164
void Reset(const PointType &point)
Definition vctBoundingBox3.h:90
void EnlargeBy(const double dist)
Definition vctBoundingBox3.h:206
double DiagonalLength(void) const
Definition vctBoundingBox3.h:127
PointType Diagonal(void) const
Definition vctBoundingBox3.h:122
bool Intersect(const ThisType &other) const
Definition vctBoundingBox3.h:191
vctFixedSizeVector< value_type, 3 > PointType
Definition vctBoundingBox3.h:33
ThisType & Include(const ThisType &other)
Definition vctBoundingBox3.h:149
PointType MidPoint(void) const
Definition vctBoundingBox3.h:132
ThisType & operator=(const ThisType &other)
Definition vctBoundingBox3.h:65
size_t mCounter
Definition vctBoundingBox3.h:38
int Includes(const ThisType &other, const double dist=0.0) const
Definition vctBoundingBox3.h:228
vctBoundingBox3Base(void)
Definition vctBoundingBox3.h:44
bool Expand(const PointType &point)
Definition vctBoundingBox3.h:185
size_t Counter(void) const
Definition vctBoundingBox3.h:116
vctBoundingBox3Base(const ThisType &other)
Definition vctBoundingBox3.h:59
vctBoundingBox3Base< value_type > ThisType
Definition vctBoundingBox3.h:32
const PointType & MinCorner(void) const
Definition vctBoundingBox3.h:102
int Includes(const PointType &point, const double dist=0.0) const
Definition vctBoundingBox3.h:215
vctBoundingBox3Base(const PointType &pointA, const PointType &pointB)
Definition vctBoundingBox3.h:52
_elementType value_type
Definition vctBoundingBox3.h:31
ThisType & operator=(const PointType &point)
Definition vctBoundingBox3.h:75
ThisType & Include(const PointType &point)
Definition vctBoundingBox3.h:137
PointType mMinCorner
Definition vctBoundingBox3.h:36
void Reset(void)
Definition vctBoundingBox3.h:81
PointType mMaxCorner
Definition vctBoundingBox3.h:37
NormType Norm(void) const
Definition vctFixedSizeConstVectorBase.h:453
value_type & Y(void)
Definition vctFixedSizeVectorBase.h:572
value_type & Z(void)
Definition vctFixedSizeVectorBase.h:585
value_type & X(void)
Definition vctFixedSizeVectorBase.h:559
value_type SetAll(const value_type &value)
Definition vctFixedSizeVectorBase.h:241
Implementation of a fixed-size vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
vctBoundingBox3Base< double > vctBoundingBox3
Definition vctBoundingBox3.h:236
vctBoundingBox3Base< float > vctBoundingBoxFloat3
Definition vctBoundingBox3.h:238
vctBoundingBox3Base< double > vctBoundingBoxDouble3
Definition vctBoundingBox3.h:237
Macros to export the symbols of cisstVector (in a Dll).
Typedef for fixed size vectors.