50 #ifndef MB_TRIANGLEBSP_HH 51 #define MB_TRIANGLEBSP_HH 56 #include "BSPTreeNode.hh" 57 #include "TriangleBSPCoreT.hh" 58 #include "BSPImplT.hh" 63 template <
class BSPTraits>
68 typedef typename Base::Scalar Scalar;
70 const Scalar& _infinity = std::numeric_limits<Scalar>::infinity()) : Base(_traits, _infinity) {}
75 template <
class Mesh,
class SpecificTraits>
80 typedef typename SpecificTraits::Point Point;
81 typedef typename SpecificTraits::Handle Handle;
82 typedef typename Point::value_type Scalar;
83 typedef std::vector<Handle> Handles;
84 typedef typename Handles::iterator HandleIter;
89 Scalar sqrdist(
const Handle _h,
const Point& _p)
const 92 this->points(_h, p0, p1, p2);
100 Point p0, p1, p2, bb_min, bb_max;
101 bb_min.vectorize(std::numeric_limits<typename Point::value_type>::infinity());
102 bb_max.vectorize(-std::numeric_limits<typename Point::value_type>::infinity());
103 std::list<Point> vertices;
105 for (it_h = _node->begin(); it_h != _node->end(); ++it_h) {
106 this->points(*it_h, p0, p1, p2);
115 vertices.push_back(p0);
116 vertices.push_back(p1);
117 vertices.push_back(p2);
119 bb_min = _node->bb_min;
120 bb_max = _node->bb_max;
123 Point bb = bb_max - bb_min;
124 Scalar length = bb[0];
127 length = bb[(axis = 1)];
129 length = bb[(axis = 2)];
134 vertices.sort(x_sort());
137 vertices.sort(y_sort());
140 vertices.sort(z_sort());
145 size_t size = vertices.size();
146 typename std::list<Point>::iterator it_v;
147 it_v = vertices.begin();
148 std::advance(it_v, size / 2);
153 void calculateBoundingBoxRoot(Node* _node)
156 Point p0, p1, p2, bb_min, bb_max;
157 bb_min.vectorize(FLT_MAX);
158 bb_max.vectorize(-FLT_MAX);
159 for (it = _node->begin(); it != _node->end(); ++it) {
160 this->points(*it, p0, p1, p2);
168 _node->bb_min = bb_min;
169 _node->bb_max = bb_max;
174 struct x_sort {
bool operator()(
const Point& first,
const Point& second) {
return (first[0] < second[0]); } };
175 struct y_sort {
bool operator()(
const Point& first,
const Point& second) {
return (first[1] < second[1]); } };
176 struct z_sort {
bool operator()(
const Point& first,
const Point& second) {
return (first[2] < second[2]); } };
182 template <
class Mesh>
187 typedef typename Mesh::FaceHandle Handle;
192 inline void points(
const Handle &_h, Point& _p0, Point& _p1, Point& _p2)
const 194 const auto &mesh = this->mesh_;
195 typename Mesh::CFVIter fv_it(mesh.cfv_iter(_h));
196 _p0 = mesh.point(*fv_it);
198 _p1 = mesh.point(*fv_it);
200 _p2 = mesh.point(*fv_it);
211 template <
class Mesh>
218 typedef typename Traits::Scalar Scalar;
220 const Scalar& _infinity = std::numeric_limits<Scalar>::infinity())
221 : Base(Traits(_mesh), _infinity) {}
225 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT 226 #include <OpenVolumeMesh/Core/PropertyHandles.hh> 230 template <
class Mesh>
231 class OVMSpecificTriangleBSPTraits
234 typedef typename Mesh::PointT Point;
237 explicit OVMSpecificTriangleBSPTraits(
const Mesh& _mesh) : mesh_(_mesh) {}
240 inline void points(
const Handle &_h, Point& _p0, Point& _p1, Point& _p2)
const 242 const auto &mesh = this->mesh_;
243 assert(mesh.valence(_h) == 3);
244 auto hfv_it (mesh.hfv_iter(mesh.halfface_handle(_h, 0)));
245 _p0 = mesh.vertex(*hfv_it++);
246 _p1 = mesh.vertex(*hfv_it++);
247 _p2 = mesh.vertex(*hfv_it++);
258 template <
class Mesh>
259 class OpenVolumeMeshTriangleBSPT
260 :
public TriangleBSPT<OpenVolumeMeshTriangleBSPTraits<Mesh> >
263 typedef OpenVolumeMeshTriangleBSPTraits<Mesh>
Traits;
265 typedef typename Traits::Scalar Scalar;
266 OpenVolumeMeshTriangleBSPT(
const Mesh& _mesh,
267 const Scalar& _infinity = std::numeric_limits<Scalar>::infinity())
268 : Base(Traits(_mesh), _infinity) {}
271 #endif // ENABLE_OPENVOLUMEMESH 275 #endif // MB_TRIANGLEBSP_HH defined
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.
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 calculateBoundingBox(Node *_node, Point &median, int &axis)