Skip to content

Commit 6bce6c2

Browse files
committed
adding files
0 parents  commit 6bce6c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+80464
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pro*

BoundingBox.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
LibBoubek/BoundingBox.cpp
3+
Copyright (c) 2003-2008, Tamy Boubekeur
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
* The name of the source code copyright owner cannot be used to endorse or
18+
promote products derived from this software without specific prior
19+
written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
#include "BoundingBox.h"
35+

BoundingBox.h

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
LibBoubek/BoundingBox.h
3+
Copyright (c) 2003-2008, Tamy Boubekeur
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
* The name of the source code copyright owner cannot be used to endorse or
18+
promote products derived from this software without specific prior
19+
written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
#ifndef BOUNDINGBOX_H
35+
#define BOUNDINGBOX_H
36+
37+
#include <vector>
38+
#include <algorithm>
39+
40+
#include "Vec3D.h"
41+
42+
const float BOUNDINGBOX_EPSILON = 0.0001f;
43+
44+
class BoundingBox {
45+
public:
46+
BoundingBox () : minBb (Vec3Df (0.0f, 0.0f, 0.0f)), maxBb (Vec3Df (0.0f, 0.0f, 0.0f)) {}
47+
BoundingBox (const Vec3Df & p) : minBb (p), maxBb (p) {}
48+
BoundingBox (const Vec3Df & min, const Vec3Df & max) : minBb (min), maxBb (max) {}
49+
50+
inline void init (const Vec3Df & p) {
51+
minBb = maxBb = p;
52+
}
53+
inline void init (float x, float y, float z) {
54+
init (Vec3Df (x, y, z));
55+
}
56+
inline float getWidth () const {
57+
return (maxBb[0] - minBb[0]);
58+
}
59+
inline float getHeight () const {
60+
return (maxBb[1] - minBb[1]);
61+
}
62+
inline float getLength () const {
63+
return (maxBb[2] - minBb[2]);
64+
}
65+
inline float getSize () const {
66+
return std::max (getWidth (), std::max (getHeight (), getLength ()));
67+
}
68+
inline float getRadius () const {
69+
return Vec3Df::distance (minBb, maxBb) / 2.0;
70+
}
71+
inline void extendTo (const Vec3Df & p) {
72+
for (unsigned int i = 0; i < 3; i++) {
73+
if (p[i] > maxBb[i]) maxBb[i] = p[i];
74+
if (p[i] < minBb[i]) minBb[i] = p[i];
75+
}
76+
}
77+
inline void extendTo (const BoundingBox & b) {
78+
extendTo (b.minBb);
79+
extendTo (b.maxBb);
80+
}
81+
inline bool contains (const Vec3Df & p) const {
82+
for (unsigned int i = 0; i < 3; i++)
83+
if (!(p[i] >= minBb[i] && p[i] <= maxBb[i]))
84+
return false;
85+
return true;
86+
}
87+
inline bool contains (const BoundingBox & b) const {
88+
for (unsigned int i = 0; i < 3; i++)
89+
if (fabs (getMiddle (i) - b.getMiddle (i)) - BOUNDINGBOX_EPSILON > (getWHL (i) + b.getWHL (i)) / 2.0)
90+
return false;
91+
return true;
92+
}
93+
inline bool scaleContains (const Vec3Df & p, float scale) const {
94+
float limitW = scale * getWidth () / 2.0;
95+
float limitH = scale * getHeight () / 2.0;
96+
float limitL = scale * getLength () / 2.0;
97+
Vec3Df c = getCenter ();
98+
if ((fabs (c[0] - p[0]) <= limitW) && (fabs (c[1] - p[1]) <= limitH) && (fabs (c[2] - p[2]) <= limitL))
99+
return true;
100+
return false;
101+
}
102+
inline void scale (float factor) {
103+
Vec3Df center = getCenter ();
104+
Vec3Df diffMin, diffMax;
105+
diffMin.fromTo (center, minBb);
106+
diffMax.fromTo (center, maxBb);
107+
diffMin *= factor;
108+
diffMax *= factor;
109+
minBb = center + diffMin;
110+
maxBb = center + diffMax;
111+
}
112+
inline Vec3Df getCenter () const {
113+
return (minBb + maxBb) / 2;
114+
}
115+
inline const Vec3Df & getMin () const {
116+
return minBb;
117+
}
118+
inline const Vec3Df & getMax () const {
119+
return maxBb;
120+
}
121+
inline void subdivide (std::vector<BoundingBox> & splitBoundingBoxArray) const {
122+
Vec3Df med = (minBb + maxBb) / 2;
123+
float x_2 = (maxBb[0] - minBb [0]) / 2;
124+
float y_2 = (maxBb[1] - minBb [1]) / 2;
125+
float z_2 = (maxBb[2] - minBb [2]) / 2;
126+
splitBoundingBoxArray.resize (8);
127+
splitBoundingBoxArray[0] = BoundingBox (minBb, med);
128+
splitBoundingBoxArray[1] = BoundingBox (minBb + Vec3Df (x_2, 0.0, 0.0), med + Vec3Df (x_2, 0.0, 0.0));
129+
splitBoundingBoxArray[2] = BoundingBox (minBb + Vec3Df (0.0, y_2, 0.0), med + Vec3Df (0.0, y_2, 0.0));
130+
splitBoundingBoxArray[3] = BoundingBox (minBb + Vec3Df (x_2, y_2, 0.0), med + Vec3Df (x_2, y_2, 0.0));
131+
splitBoundingBoxArray[4] = BoundingBox (minBb + Vec3Df (0.0, 0.0, z_2), med + Vec3Df (0.0, 0.0, z_2));
132+
splitBoundingBoxArray[5] = BoundingBox (minBb + Vec3Df (x_2, 0.0, z_2), med + Vec3Df (x_2, 0.0, z_2));
133+
splitBoundingBoxArray[6] = BoundingBox (minBb + Vec3Df (0.0, y_2, z_2), med + Vec3Df (0.0, y_2, z_2));
134+
splitBoundingBoxArray[7] = BoundingBox (minBb + Vec3Df (x_2, y_2, z_2), med + Vec3Df (x_2, y_2, z_2));
135+
}
136+
bool intersectRay (const Vec3Df & origin, const Vec3Df & direction, Vec3Df & intersection) const;
137+
138+
private:
139+
inline float getWHL (unsigned int i) const {
140+
return (maxBb[i] - minBb[i]);
141+
}
142+
inline float getMiddle (unsigned int i) const {
143+
return ((minBb[i] + maxBb[i]) / 2.0);
144+
}
145+
static inline bool isIn (float x, float min, float max) {
146+
return (x >= min && x <= max);
147+
}
148+
149+
Vec3Df minBb, maxBb;
150+
};
151+
152+
#endif // BOUNDINGBOX_H
153+
154+
// Some Emacs-Hints -- please don't remove:
155+
//
156+
// Local Variables:
157+
// mode:C++
158+
// tab-width:4
159+
// End:

Edge.h

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// *********************************************************
2+
// Edge Class
3+
// Author : Tamy Boubekeur ([email protected]).
4+
// Copyright (C) 2008 Tamy Boubekeur.
5+
// All rights reserved.
6+
// *********************************************************
7+
8+
#ifndef EDGE_H
9+
#define EDGE_H
10+
11+
#include <map>
12+
13+
// -------------------------------------------------
14+
// Intermediate Edge structure for hashed adjacency
15+
// -------------------------------------------------
16+
17+
struct Edge {
18+
public:
19+
inline Edge (unsigned int v0, unsigned int v1) {
20+
if (v0 < v1) {v[0] = v0; v[1] = v1; } else {v[0] = v1; v[1] = v0; }
21+
}
22+
inline Edge (const Edge & e) { v[0] = e.v[0]; v[1] = e.v[1]; }
23+
inline virtual ~Edge () {}
24+
inline Edge & operator= (const Edge & e) { v[0] = e.v[0]; v[1] = e.v[1]; return (*this); }
25+
inline bool operator== (const Edge & e) { return (v[0] == e.v[0] && v[1] == e.v[1]); }
26+
inline bool operator< (const Edge & e) { return (v[0] < e.v[0] || (v[0] == e.v[0] && v[1] < e.v[1])); }
27+
inline bool contains (unsigned int i) const { return (v[0] == i || v[1] == i); }
28+
unsigned int v[2];
29+
};
30+
31+
struct compareEdge {
32+
inline bool operator()(const Edge e1, const Edge e2) const {
33+
if (e1.v[0] < e2.v[0])
34+
return true;
35+
if (e1.v[0] > e2.v[0])
36+
return false;
37+
if (e1.v[1] > e2.v[1])
38+
return true;
39+
return false;
40+
}
41+
};
42+
43+
typedef std::map<Edge, unsigned int, compareEdge> EdgeMapIndex;
44+
45+
#endif // EDGE_H
46+
47+
// Some Emacs-Hints -- please don't remove:
48+
//
49+
// Local Variables:
50+
// mode:C++
51+
// tab-width:4
52+
// End:

0 commit comments

Comments
 (0)