Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SbBox3d.h
1 #ifndef COIN_SBBOX3D_H
2 #define COIN_SBBOX3D_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <cstdio>
37 
38 #include <Inventor/SbVec3d.h>
39 
40 class SbBox3f;
41 class SbBox3s;
42 class SbBox3i32;
43 
44 class SbDPMatrix;
45 
46 class COIN_DLL_API SbBox3d {
47 public:
48  SbBox3d(void) { makeEmpty(); }
49  SbBox3d(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
50  : minpt(xmin, ymin, zmin), maxpt(xmax, ymax, zmax) { }
51  SbBox3d(const SbVec3d & minpoint, const SbVec3d & maxpoint)
52  : minpt(minpoint), maxpt(maxpoint) { }
53  explicit SbBox3d(const SbBox3f & box) { setBounds(box); }
54  explicit SbBox3d(const SbBox3s & box) { setBounds(box); }
55  explicit SbBox3d(const SbBox3i32 & box) { setBounds(box); }
56 
57  SbBox3d & setBounds(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
58  { minpt.setValue(xmin, ymin, zmin); maxpt.setValue(xmax, ymax, zmax); return *this; }
59  SbBox3d & setBounds(const SbVec3d & minpoint, const SbVec3d & maxpoint)
60  { minpt = minpoint; maxpt = maxpoint; return *this; }
61  SbBox3d & setBounds(const SbBox3f & box);
62  SbBox3d & setBounds(const SbBox3s & box);
63  SbBox3d & setBounds(const SbBox3i32 & box);
64 
65  void getBounds(double & xmin, double & ymin, double & zmin, double & xmax, double & ymax, double & zmax) const
66  { minpt.getValue(xmin, ymin, zmin); maxpt.getValue(xmax, ymax, zmax); }
67  void getBounds(SbVec3d & minpoint, SbVec3d & maxpoint) const
68  { minpoint = minpt; maxpoint = maxpt; }
69 
70  const SbVec3d & getMin(void) const { return minpt; }
71  SbVec3d & getMin(void) { return minpt; }
72  const SbVec3d & getMax(void) const { return maxpt; }
73  SbVec3d & getMax(void) { return maxpt; }
74 
75  void extendBy(const SbVec3d & pt);
76  void extendBy(const SbBox3d & box);
77  void transform(const SbDPMatrix & matrix);
78  void makeEmpty(void);
79  SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
80  SbBool hasVolume(void) const
81  { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1]) && (maxpt[2] > minpt[2])); }
82  double getVolume(void) const
83  { double dx = 0.0, dy = 0.0, dz = 0.0; getSize(dx, dy, dz); return (dx * dy * dz); }
84 
85  SbBool intersect(const SbVec3d & point) const;
86  SbBool intersect(const SbBox3d & box) const;
87  SbVec3d getClosestPoint(const SbVec3d & point) const;
88  SbBool outside(const SbDPMatrix & mvp, int & cullbits) const;
89 
90  SbVec3d getCenter(void) const { return (minpt + maxpt) * 0.5; }
91  void getOrigin(double & origoX, double & origoY, double & origoZ) const
92  { minpt.getValue(origoX, origoY, origoZ); }
93  void getSize(double & sizeX, double & sizeY, double & sizeZ) const
94  { if (isEmpty()) { sizeX = sizeY = sizeZ = 0.0; }
95  else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; sizeZ = maxpt[2] - minpt[2]; } }
96  SbVec3d getSize(void) const {
97  SbVec3d v;
98  this->getSize(v[0], v[1], v[2]);
99  return v;
100  }
101  void getSpan(const SbVec3d & dir, double & dmin, double & dmax) const;
102 
103  void print(FILE * file) const;
104 
105 protected:
106  SbVec3d minpt, maxpt;
107 
108 }; // SbBox3d
109 
110 COIN_DLL_API inline int operator == (const SbBox3d & b1, const SbBox3d & b2) {
111  return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
112 }
113 
114 COIN_DLL_API inline int operator != (const SbBox3d & b1, const SbBox3d & b2) {
115  return !(b1 == b2);
116 }
117 
118 #endif // !COIN_SBBOX3D_H
void getOrigin(double &origoX, double &origoY, double &origoZ) const
Definition: SbBox3d.h:91
The SbBox3s class is a 3 dimensional box with short integer coordinates.
Definition: SbBox3s.h:43
The SbVec3d class is a 3 dimensional vector with double precision floating point coordinates.
Definition: SbVec3d.h:50
SbBox3d & setBounds(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Definition: SbBox3d.h:57
SbBool isEmpty(void) const
Definition: SbBox3d.h:79
The SbBox3f class is an abstraction for an axis aligned 3 dimensional box.
Definition: SbBox3f.h:46
SbVec3d getSize(void) const
Definition: SbBox3d.h:96
SbBox3d(void)
Definition: SbBox3d.h:48
int operator==(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:102
SbBox3d & setBounds(const SbVec3d &minpoint, const SbVec3d &maxpoint)
Definition: SbBox3d.h:59
SbBox3d(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Definition: SbBox3d.h:49
void getBounds(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Definition: SbBox3d.h:65
SbVec3d & getMin(void)
Definition: SbBox3d.h:71
SbBox3d(const SbVec3d &minpoint, const SbVec3d &maxpoint)
Definition: SbBox3d.h:51
int operator!=(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:106
void getBounds(SbVec3d &minpoint, SbVec3d &maxpoint) const
Definition: SbBox3d.h:67
void getSize(double &sizeX, double &sizeY, double &sizeZ) const
Definition: SbBox3d.h:93
const SbVec3d & getMin(void) const
Definition: SbBox3d.h:70
double getVolume(void) const
Definition: SbBox3d.h:82
The SbBox3d class is an abstraction for an axis aligned 3 dimensional box.
Definition: SbBox3d.h:46
Definition: SbBox3i32.h:44
SbBool hasVolume(void) const
Definition: SbBox3d.h:80
SbVec3d & getMax(void)
Definition: SbBox3d.h:73
SbVec3d getCenter(void) const
Definition: SbBox3d.h:90
The SbDPMatrix class is a 4x4 dimensional representation of a double-precision matrix.
Definition: SbDPMatrix.h:47
const SbVec3d & getMax(void) const
Definition: SbBox3d.h:72