59 #ifndef MB_TRIANGLEBSP_HH
60 #define MB_TRIANGLEBSP_HH
65 #include "BSPTreeNode.hh"
66 #include "TriangleBSPCoreT.hh"
67 #include "BSPImplT.hh"
72 template <
class BSPTraits>
77 typedef typename Base::Scalar Scalar;
79 const Scalar& _infinity = std::numeric_limits<Scalar>::infinity()) : Base(_traits, _infinity) {}
84 template <
class Mesh,
class SpecificTraits>
89 typedef typename SpecificTraits::Point Point;
90 typedef typename SpecificTraits::Handle Handle;
91 typedef typename Point::value_type Scalar;
92 typedef std::vector<Handle> Handles;
93 typedef typename Handles::iterator HandleIter;
98 Scalar sqrdist(
const Handle _h,
const Point& _p)
const
101 this->points(_h, p0, p1, p2);
109 Point p0, p1, p2, bb_min, bb_max;
110 bb_min.vectorize(std::numeric_limits<typename Point::value_type>::infinity());
111 bb_max.vectorize(-std::numeric_limits<typename Point::value_type>::infinity());
112 std::list<Point> vertices;
114 for (it_h = _node->begin(); it_h != _node->end(); ++it_h) {
115 this->points(*it_h, p0, p1, p2);
124 vertices.push_back(p0);
125 vertices.push_back(p1);
126 vertices.push_back(p2);
128 bb_min = _node->bb_min;
129 bb_max = _node->bb_max;
132 Point bb = bb_max - bb_min;
133 Scalar length = bb[0];
136 length = bb[(axis = 1)];
138 length = bb[(axis = 2)];
143 vertices.sort(x_sort());
146 vertices.sort(y_sort());
149 vertices.sort(z_sort());
154 size_t size = vertices.size();
155 typename std::list<Point>::iterator it_v;
156 it_v = vertices.begin();
157 std::advance(it_v, size / 2);
162 void calculateBoundingBoxRoot(Node* _node)
165 Point p0, p1, p2, bb_min, bb_max;
166 bb_min.vectorize(FLT_MAX);
167 bb_max.vectorize(-FLT_MAX);
168 for (it = _node->begin(); it != _node->end(); ++it) {
169 this->points(*it, p0, p1, p2);
177 _node->bb_min = bb_min;
178 _node->bb_max = bb_max;
183 struct x_sort {
bool operator()(
const Point& first,
const Point& second) {
return (first[0] < second[0]); } };
184 struct y_sort {
bool operator()(
const Point& first,
const Point& second) {
return (first[1] < second[1]); } };
185 struct z_sort {
bool operator()(
const Point& first,
const Point& second) {
return (first[2] < second[2]); } };
191 template <
class Mesh>
196 typedef typename Mesh::FaceHandle Handle;
201 inline void points(
const Handle &_h, Point& _p0, Point& _p1, Point& _p2)
const
203 const auto &mesh = this->mesh_;
204 typename Mesh::CFVIter fv_it(mesh.cfv_iter(_h));
205 _p0 = mesh.point(*fv_it);
207 _p1 = mesh.point(*fv_it);
209 _p2 = mesh.point(*fv_it);
220 template <
class Mesh>
227 typedef typename Traits::Scalar Scalar;
229 const Scalar& _infinity = std::numeric_limits<Scalar>::infinity())
230 : Base(Traits(_mesh), _infinity) {}
234 #ifdef ENABLE_OPENVOLUMEMESH
244 template <
class Mesh>
245 class OVMSpecificTriangleBSPTraits
248 typedef typename Mesh::PointT Point;
251 OVMSpecificTriangleBSPTraits(
const Mesh& _mesh) : mesh_(_mesh) {}
254 inline void points(
const Handle &_h, Point& _p0, Point& _p1, Point& _p2)
const
256 const auto &mesh = this->mesh_;
257 assert(mesh.valence(_h) == 3);
258 auto hfv_it (mesh.hfv_iter(mesh.halfface_handle(_h, 0)));
259 _p0 = mesh.vertex(*hfv_it++);
260 _p1 = mesh.vertex(*hfv_it++);
261 _p2 = mesh.vertex(*hfv_it++);
272 template <
class Mesh>
273 class OpenVolumeMeshTriangleBSPT
274 :
public TriangleBSPT<OpenVolumeMeshTriangleBSPTraits<Mesh> >
277 typedef OpenVolumeMeshTriangleBSPTraits<Mesh> Traits;
279 typedef typename Traits::Scalar Scalar;
280 OpenVolumeMeshTriangleBSPT(
const Mesh& _mesh,
281 const Scalar& _infinity = std::numeric_limits<Scalar>::infinity())
282 : Base(Traits(_mesh), _infinity) {}
285 #endif // ENABLE_OPENVOLUMEMESH
289 #endif // MB_TRIANGLEBSP_HH defined
void calculateBoundingBox(Node *_node, Point &median, int &axis)
Vec::value_type distPointTriangleSquaredStable(const Vec &_p, const Vec &_v0, const Vec &_v1, const Vec &_v2, Vec &_nearestPoint)
squared distance from point _p to triangle (_v0, _v1, _v2)
void points(const Handle &_h, Point &_p0, Point &_p1, Point &_p2) const
Returns the points belonging to the face handle _h.
Kernel::Point Point
Coordinate type.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.