Coin Logo http://www.coin3d.org/
http://www.kongsberg.com/kogt/

SbBox3i32.h
1 #ifndef COIN_SBBOX3I32_H
2 #define COIN_SBBOX3I32_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 <Inventor/SbVec3i32.h>
37 #include <Inventor/SbVec3f.h>
38 
39 class SbBox3s;
40 class SbBox3f;
41 class SbBox3d;
42 class SbMatrix;
43 
44 class COIN_DLL_API SbBox3i32 {
45 public:
46  SbBox3i32(void) { makeEmpty(); }
47  SbBox3i32(int32_t xmin, int32_t ymin, int32_t zmin, int32_t xmax, int32_t ymax, int32_t zmax)
48  : minpt(xmin, ymin, zmin), maxpt(xmax, ymax, zmax) { }
49  SbBox3i32(const SbVec3i32 & minpoint, const SbVec3i32 & maxpoint)
50  : minpt(minpoint), maxpt(maxpoint) { }
51  explicit SbBox3i32(const SbBox3s & box) { setBounds(box); }
52  explicit SbBox3i32(const SbBox3f & box) { setBounds(box); }
53  explicit SbBox3i32(const SbBox3d & box) { setBounds(box); }
54 
55  SbBox3i32 & setBounds(int32_t xmin, int32_t ymin, int32_t zmin, int32_t xmax, int32_t ymax, int32_t zmax)
56  { minpt.setValue(xmin, ymin, zmin); maxpt.setValue(xmax, ymax, zmax); return *this; }
57  SbBox3i32 & setBounds(const SbVec3i32 & minpoint, const SbVec3i32 & maxpoint)
58  { minpt = minpoint; maxpt = maxpoint; return *this; }
59  SbBox3i32 & setBounds(const SbBox3s & box);
60  SbBox3i32 & setBounds(const SbBox3f & box);
61  SbBox3i32 & setBounds(const SbBox3d & box);
62 
63  void getBounds(int32_t & xmin, int32_t & ymin, int32_t & zmin, int32_t & xmax, int32_t & ymax, int32_t & zmax) const
64  { minpt.getValue(xmin, ymin, zmin); maxpt.getValue(xmax, ymax, zmax); }
65  void getBounds(SbVec3i32 & minpoint, SbVec3i32 & maxpoint) const
66  { minpoint = minpt; maxpoint = maxpt; }
67 
68  const SbVec3i32 & getMin(void) const { return minpt; }
69  SbVec3i32 & getMin(void) { return minpt; }
70  const SbVec3i32 & getMax(void) const { return maxpt; }
71  SbVec3i32 & getMax(void) { return maxpt; }
72 
73  void extendBy(const SbVec3i32 & pt);
74  void extendBy(const SbBox3i32 & bb);
75  void extendBy(const SbVec3f & pt);
76  void transform(const SbMatrix & m);
77  void makeEmpty(void);
78  SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
79  SbBool hasVolume(void) const
80  { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1]) && (maxpt[2] > minpt[2])); }
81  float getVolume(void) const
82  { int32_t dx = 0, dy = 0, dz = 0; getSize(dx, dy, dz); return (float(dx) * float(dy) * float(dz)); }
83 
84  SbBool intersect(const SbVec3i32 & pt) const;
85  SbBool intersect(const SbBox3i32 & bb) const;
86  SbBool intersect(const SbVec3f & pt) const;
87 
88  SbBool outside(const SbMatrix & MVP, int & cullBits) const;
89  SbVec3f getClosestPoint(const SbVec3f & pt) const;
90 
91  SbVec3f getCenter(void) const { return SbVec3f(minpt + maxpt) * 0.5f; }
92  void getOrigin(int32_t & originX, int32_t & originY, int32_t & originZ) const
93  { minpt.getValue(originX, originY, originZ); }
94  void getSize(int32_t & sizeX, int32_t & sizeY, int32_t & sizeZ) const
95  { if (isEmpty()) { sizeX = sizeY = sizeZ = 0; }
96  else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; sizeZ = maxpt[2] - minpt[2]; } }
97 
98  SbVec3i32 getSize(void) const {
99  SbVec3i32 v;
100  this->getSize(v[0], v[1], v[2]);
101  return v;
102  }
103 
104  void getSpan(const SbVec3f & direction, float & dmin, float & dmax) const;
105 
106 protected:
107  SbVec3i32 minpt, maxpt;
108 
109 }; // SbBox3i32
110 
111 COIN_DLL_API inline int operator == (const SbBox3i32 & b1, const SbBox3i32 & b2)
112 {
113  return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
114 }
115 
116 COIN_DLL_API inline int operator != (const SbBox3i32 & b1, const SbBox3i32 & b2)
117 {
118  return !(b1 == b2);
119 }
120 
121 #endif // !COIN_SBBOX3I32_H
The SbBox3s class is a 3 dimensional box with short integer coordinates.This box class is used by oth...
Definition: SbBox3s.h:43
const float * getValue(void) const
Definition: SbVec3f.h:73
The SbBox3f class is an abstraction for an axis aligned 3 dimensional box.This box abstraction class ...
Definition: SbBox3f.h:46
The SbVec3f class is a 3 dimensional vector with floating point coordinates.This vector class is used...
Definition: SbVec3f.h:51
The SbMatrix class is a 4x4 dimensional representation of a matrix.SbMatrix is used by many other cla...
Definition: SbMatrix.h:46
Definition: SbVec3i32.h:48
The SbBox3d class is an abstraction for an axis aligned 3 dimensional box.This box abstraction class ...
Definition: SbBox3d.h:46

Copyright © by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated for Coin by Doxygen