55 #include "BSPTreeNode.hh" 56 #include "TriangleBSPCoreT.hh" 57 #include "BSPImplT.hh" 62 template <
class BSPTraits>
67 typedef typename Base::Scalar Scalar;
69 const Scalar& _infinity = std::numeric_limits<Scalar>::infinity()) : Base(_traits, _infinity) {}
74 template <
class Mesh,
class SpecificTraits>
79 typedef typename SpecificTraits::Point Point;
80 typedef typename SpecificTraits::Handle Handle;
81 typedef typename Point::value_type Scalar;
82 typedef std::vector<Handle> Handles;
83 typedef typename Handles::iterator HandleIter;
88 Scalar sqrdist(
const Handle _h,
const Point& _p)
const 91 this->points(_h, p0, p1, p2);
99 Point p0, p1, p2, bb_min, bb_max;
100 bb_min.vectorize(std::numeric_limits<typename Point::value_type>::infinity());
101 bb_max.vectorize(-std::numeric_limits<typename Point::value_type>::infinity());
102 std::list<Point> vertices;
104 for (it_h = _node->begin(); it_h != _node->end(); ++it_h) {
105 this->points(*it_h, p0, p1, p2);
114 vertices.push_back(p0);
115 vertices.push_back(p1);
116 vertices.push_back(p2);
118 bb_min = _node->bb_min;
119 bb_max = _node->bb_max;
122 Point bb = bb_max - bb_min;
123 Scalar length = bb[0];
126 length = bb[(axis = 1)];
128 length = bb[(axis = 2)];
133 vertices.sort(x_sort());
136 vertices.sort(y_sort());
139 vertices.sort(z_sort());
144 size_t size = vertices.size();
145 typename std::list<Point>::iterator it_v;
146 it_v = vertices.begin();
147 std::advance(it_v, size / 2);
152 void calculateBoundingBoxRoot(Node* _node)
155 Point p0, p1, p2, bb_min, bb_max;
156 bb_min.vectorize(FLT_MAX);
157 bb_max.vectorize(-FLT_MAX);
158 for (it = _node->begin(); it != _node->end(); ++it) {
159 this->points(*it, p0, p1, p2);
167 _node->bb_min = bb_min;
168 _node->bb_max = bb_max;
173 struct x_sort {
bool operator()(
const Point& first,
const Point& second) {
return (first[0] < second[0]); } };
174 struct y_sort {
bool operator()(
const Point& first,
const Point& second) {
return (first[1] < second[1]); } };
175 struct z_sort {
bool operator()(
const Point& first,
const Point& second) {
return (first[2] < second[2]); } };
181 template <
class Mesh>
186 typedef typename Mesh::FaceHandle Handle;
191 inline void points(
const Handle &_h, Point& _p0, Point& _p1, Point& _p2)
const 193 const auto &mesh = this->mesh_;
194 typename Mesh::CFVIter fv_it(mesh.cfv_iter(_h));
195 _p0 = mesh.point(*fv_it);
197 _p1 = mesh.point(*fv_it);
199 _p2 = mesh.point(*fv_it);
210 template <
class Mesh>
217 typedef typename Traits::Scalar Scalar;
219 const Scalar& _infinity = std::numeric_limits<Scalar>::infinity())
220 : Base(Traits(_mesh), _infinity) {}
224 #if (defined ENABLE_POLYHEDRALMESH_SUPPORT) \ 225 || (defined ENABLE_HEXAHEDRALMESH_SUPPORT) \ 226 || (defined ENABLE_TETRAHEDRALMESH_SUPPORT) 228 #include <OpenVolumeMesh/Core/PropertyHandles.hh> 232 template <
class Mesh>
233 class OVMSpecificTriangleBSPTraits
236 typedef typename Mesh::PointT Point;
239 explicit OVMSpecificTriangleBSPTraits(
const Mesh& _mesh) : mesh_(_mesh) {}
242 inline void points(
const Handle &_h, Point& _p0, Point& _p1, Point& _p2)
const 244 const auto &mesh = this->mesh_;
245 assert(mesh.valence(_h) == 3);
246 auto hfv_it (mesh.hfv_iter(mesh.halfface_handle(_h, 0)));
247 _p0 = mesh.vertex(*hfv_it++);
248 _p1 = mesh.vertex(*hfv_it++);
249 _p2 = mesh.vertex(*hfv_it++);
260 template <
class Mesh>
261 class OpenVolumeMeshTriangleBSPT
262 :
public TriangleBSPT<OpenVolumeMeshTriangleBSPTraits<Mesh> >
265 typedef OpenVolumeMeshTriangleBSPTraits<Mesh>
Traits;
267 typedef typename Traits::Scalar Scalar;
268 OpenVolumeMeshTriangleBSPT(
const Mesh& _mesh,
269 const Scalar& _infinity = std::numeric_limits<Scalar>::infinity())
270 : Base(Traits(_mesh), _infinity) {}
Kernel::Point Point
Coordinate type.
void calculateBoundingBox(Node *_node, Point &median, int &axis)
void points(const Handle &_h, Point &_p0, Point &_p1, Point &_p2) const
Returns the points belonging to the face handle _h.
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)
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.