2
// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
3
// All rights reserved.
5
// This file is part of the Carve CSG Library (http://carve-csg.com/)
7
// This file may be used under the terms of the GNU General Public
8
// License version 2.0 as published by the Free Software Foundation
9
// and appearing in the file LICENSE.GPL2 included in the packaging of
12
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
13
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
14
// A PARTICULAR PURPOSE.
20
#include <carve/carve.hpp>
22
#include <carve/geom3d.hpp>
23
#include <carve/aabb.hpp>
25
#include <carve/polyhedron_base.hpp>
31
const double SLACK_FACTOR=1.0009765625;
32
const unsigned FACE_SPLIT_THRESHOLD=50U;
33
const unsigned EDGE_SPLIT_THRESHOLD=50U;
34
const unsigned POINT_SPLIT_THRESHOLD=20U;
35
const unsigned MAX_SPLIT_DEPTH=32;
42
Node(const Node &node); // undefined.
43
Node &operator=(const Node &node); // undefined.
50
carve::geom3d::Vector min;
51
carve::geom3d::Vector max;
53
std::vector<const carve::poly::Geometry<3>::face_t *> faces;
54
std::vector<const carve::poly::Geometry<3>::edge_t *> edges;
55
std::vector<const carve::poly::Geometry<3>::vertex_t *> vertices;
57
carve::geom3d::AABB aabb;
61
Node(const carve::geom3d::Vector &newMin, const carve::geom3d::Vector &newMax);
62
Node(Node *p, double x1, double y1, double z1, double x2, double y2, double z2);
66
bool mightContain(const carve::poly::Geometry<3>::face_t &face);
67
bool mightContain(const carve::poly::Geometry<3>::edge_t &edge);
68
bool mightContain(const carve::poly::Geometry<3>::vertex_t &p);
73
void putInside(const T &input, Node *child, T &output);
85
bool operator()(const carve::poly::Geometry<3>::edge_t *) { return true; }
86
bool operator()(const carve::poly::Geometry<3>::face_t *) { return true; }
97
void setBounds(const carve::geom3d::Vector &min, const carve::geom3d::Vector &max);
98
void setBounds(carve::geom3d::AABB aabb);
102
void addEdges(const std::vector<carve::poly::Geometry<3>::edge_t > &edges);
103
void addFaces(const std::vector<carve::poly::Geometry<3>::face_t > &faces);
104
void addVertices(const std::vector<const carve::poly::Geometry<3>::vertex_t *> &vertices);
108
static carve::geom3d::AABB makeAABB(const Node *node);
112
void doFindEdges(const carve::geom::aabb<3> &aabb,
114
std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
115
unsigned depth) const;
116
void doFindEdges(const carve::geom3d::LineSegment &l,
118
std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
119
unsigned depth) const;
120
void doFindEdges(const carve::geom3d::Vector &v,
122
std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
123
unsigned depth) const;
124
void doFindFaces(const carve::geom::aabb<3> &aabb,
126
std::vector<const carve::poly::Geometry<3>::face_t *> &out,
127
unsigned depth) const;
128
void doFindFaces(const carve::geom3d::LineSegment &l,
130
std::vector<const carve::poly::Geometry<3>::face_t *> &out,
131
unsigned depth) const;
135
void doFindVerticesAllowDupes(const carve::geom3d::Vector &v,
137
std::vector<const carve::poly::Geometry<3>::vertex_t *> &out,
138
unsigned depth) const;
140
void findVerticesNearAllowDupes(const carve::geom3d::Vector &v,
141
std::vector<const carve::poly::Geometry<3>::vertex_t *> &out) const;
145
template<typename filter_t>
146
void doFindEdges(const carve::poly::Geometry<3>::face_t &f, Node *node,
147
std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
149
filter_t filter) const;
151
template<typename filter_t>
152
void findEdgesNear(const carve::poly::Geometry<3>::face_t &f,
153
std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
154
filter_t filter) const;
156
void findEdgesNear(const carve::poly::Geometry<3>::face_t &f,
157
std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const {
158
return findEdgesNear(f, out, no_filter());
163
void findEdgesNear(const carve::geom::aabb<3> &aabb, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
164
void findEdgesNear(const carve::geom3d::LineSegment &l, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
165
void findEdgesNear(const carve::poly::Geometry<3>::edge_t &e, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
166
void findEdgesNear(const carve::geom3d::Vector &v, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
170
void findFacesNear(const carve::geom::aabb<3> &aabb, std::vector<const carve::poly::Geometry<3>::face_t *> &out) const;
171
void findFacesNear(const carve::geom3d::LineSegment &l, std::vector<const carve::poly::Geometry<3>::face_t *> &out) const;
172
void findFacesNear(const carve::poly::Geometry<3>::edge_t &e, std::vector<const carve::poly::Geometry<3>::face_t *> &out) const;
176
static void doSplit(int maxSplit, Node *node);
180
template <typename FUNC>
181
void doIterate(int level, Node *node, const FUNC &f) const;
183
template <typename FUNC>
184
void iterateNodes(const FUNC &f) const;