Coin Logo http://www.sim.no
http://www.coin3d.org

SbBox3d.h
1#ifndef COIN_SBBOX3D_H
2#define COIN_SBBOX3D_H
3
4/**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) 1998-2007 by Systems in Motion. All rights reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * ("GPL") version 2 as published by the Free Software Foundation.
12 * See the file LICENSE.GPL at the root directory of this source
13 * distribution for additional information about the GNU GPL.
14 *
15 * For using Coin with software that can not be combined with the GNU
16 * GPL, and for taking advantage of the additional benefits of our
17 * support services, please contact Systems in Motion about acquiring
18 * a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25\**************************************************************************/
26
27#include <stdio.h>
28
29#include <Inventor/SbVec3d.h>
30
31class SbBox3f;
32class SbBox3s;
33class SbBox3i32;
34
35class SbDPMatrix;
36
37class COIN_DLL_API SbBox3d {
38public:
39 SbBox3d(void) { makeEmpty(); }
40 SbBox3d(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
41 : minpt(xmin, ymin, zmin), maxpt(xmax, ymax, zmax) { }
42 SbBox3d(const SbVec3d & minpoint, const SbVec3d & maxpoint)
43 : minpt(minpoint), maxpt(maxpoint) { }
44 explicit SbBox3d(const SbBox3f & box) { setBounds(box); }
45 explicit SbBox3d(const SbBox3s & box) { setBounds(box); }
46 explicit SbBox3d(const SbBox3i32 & box) { setBounds(box); }
47
48 SbBox3d & setBounds(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
49 { minpt.setValue(xmin, ymin, zmin); maxpt.setValue(xmax, ymax, zmax); return *this; }
50 SbBox3d & setBounds(const SbVec3d & minpoint, const SbVec3d & maxpoint)
51 { minpt = minpoint; maxpt = maxpoint; return *this; }
52 SbBox3d & setBounds(const SbBox3f & box);
53 SbBox3d & setBounds(const SbBox3s & box);
54 SbBox3d & setBounds(const SbBox3i32 & box);
55
56 void getBounds(double & xmin, double & ymin, double & zmin, double & xmax, double & ymax, double & zmax) const
57 { minpt.getValue(xmin, ymin, zmin); maxpt.getValue(xmax, ymax, zmax); }
58 void getBounds(SbVec3d & minpoint, SbVec3d & maxpoint) const
59 { minpoint = minpt; maxpoint = maxpt; }
60
61 const SbVec3d & getMin(void) const { return minpt; }
62 SbVec3d & getMin(void) { return minpt; }
63 const SbVec3d & getMax(void) const { return maxpt; }
64 SbVec3d & getMax(void) { return maxpt; }
65
66 void extendBy(const SbVec3d & pt);
67 void extendBy(const SbBox3d & box);
68 void transform(const SbDPMatrix & matrix);
69 void makeEmpty(void);
70 SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
71 SbBool hasVolume(void) const
72 { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1]) && (maxpt[2] > minpt[2])); }
73 double getVolume(void) const
74 { double dx = 0.0, dy = 0.0, dz = 0.0; getSize(dx, dy, dz); return (dx * dy * dz); }
75
76 SbBool intersect(const SbVec3d & point) const;
77 SbBool intersect(const SbBox3d & box) const;
78 SbVec3d getClosestPoint(const SbVec3d & point) const;
79 SbBool outside(const SbDPMatrix & mvp, int & cullbits) const;
80
81 SbVec3d getCenter(void) const { return (minpt + maxpt) * 0.5; }
82 void getOrigin(double & origoX, double & origoY, double & origoZ) const
83 { minpt.getValue(origoX, origoY, origoZ); }
84 void getSize(double & sizeX, double & sizeY, double & sizeZ) const
85 { if (isEmpty()) { sizeX = sizeY = sizeZ = 0.0; }
86 else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; sizeZ = maxpt[2] - minpt[2]; } }
87
88 void getSpan(const SbVec3d & dir, double & dmin, double & dmax) const;
89
90 void print(FILE * file) const;
91
92protected:
93 SbVec3d minpt, maxpt;
94
95}; // SbBox3d
96
97COIN_DLL_API inline int operator == (const SbBox3d & b1, const SbBox3d & b2) {
98 return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
99}
100
101COIN_DLL_API inline int operator != (const SbBox3d & b1, const SbBox3d & b2) {
102 return !(b1 == b2);
103}
104
105#endif // !COIN_SBBOX3D_H
int operator==(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.cpp:432
int operator!=(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.cpp:443
The SbBox3d class is an abstraction for an axis aligned 3 dimensional box.
Definition: SbBox3d.h:37
SbBox3d(const SbBox3i32 &box)
Definition: SbBox3d.h:46
SbVec3d getCenter(void) const
Definition: SbBox3d.h:81
SbBool hasVolume(void) const
Definition: SbBox3d.h:71
const SbVec3d & getMin(void) const
Definition: SbBox3d.h:61
SbBox3d(const SbBox3s &box)
Definition: SbBox3d.h:45
SbBox3d & setBounds(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Definition: SbBox3d.h:48
SbBool isEmpty(void) const
Definition: SbBox3d.h:70
SbBox3d(void)
Definition: SbBox3d.h:39
void getBounds(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Definition: SbBox3d.h:56
SbVec3d & getMin(void)
Definition: SbBox3d.h:62
SbBox3d & setBounds(const SbVec3d &minpoint, const SbVec3d &maxpoint)
Definition: SbBox3d.h:50
const SbVec3d & getMax(void) const
Definition: SbBox3d.h:63
void getOrigin(double &origoX, double &origoY, double &origoZ) const
Definition: SbBox3d.h:82
void getSize(double &sizeX, double &sizeY, double &sizeZ) const
Definition: SbBox3d.h:84
SbBox3d(const SbBox3f &box)
Definition: SbBox3d.h:44
SbVec3d & getMax(void)
Definition: SbBox3d.h:64
SbBox3d(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Definition: SbBox3d.h:40
SbBox3d(const SbVec3d &minpoint, const SbVec3d &maxpoint)
Definition: SbBox3d.h:42
double getVolume(void) const
Definition: SbBox3d.h:73
void getBounds(SbVec3d &minpoint, SbVec3d &maxpoint) const
Definition: SbBox3d.h:58
The SbBox3f class is an abstraction for an axis aligned 3 dimensional box.
Definition: SbBox3f.h:37
Definition: SbBox3i32.h:35
The SbBox3s class is a 3 dimensional box with short integer coordinates.
Definition: SbBox3s.h:34
The SbDPMatrix class is a 4x4 dimensional representation of a double-precision matrix.
Definition: SbDPMatrix.h:38
The SbVec3d class is a 3 dimensional vector with double precision floating point coordinates.
Definition: SbVec3d.h:35

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Wed Jul 20 2022 for Coin by Doxygen. 1.9.4