// Begin License: // Copyright (C) 2006-2008 Tobias Sargeant (tobias.sargeant@gmail.com). // All rights reserved. // // This file is part of the Carve CSG Library (http://carve-csg.com/) // // This file may be used under the terms of the GNU General Public // License version 2.0 as published by the Free Software Foundation // and appearing in the file LICENSE.GPL2 included in the packaging of // this file. // // This file is provided "AS IS" with NO WARRANTY OF ANY KIND, // INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE. // End: #pragma once #include #include #include #include #include #include #include #include #include #include namespace carve { namespace poly { struct Object; template class Edge; template struct p2_adapt_project { typedef carve::geom2d::P2 (*proj_t)(const carve::geom::vector &); proj_t proj; p2_adapt_project(proj_t _proj) : proj(_proj) { } carve::geom2d::P2 operator()(const carve::geom::vector &v) const { return proj(v); } carve::geom2d::P2 operator()(const carve::geom::vector *v) const { return proj(*v); } carve::geom2d::P2 operator()(const Vertex &v) const { return proj(v.v); } carve::geom2d::P2 operator()(const Vertex *v) const { return proj(v->v); } }; template class Face : public tagable { public: typedef Vertex vertex_t; typedef typename Vertex::vector_t vector_t; typedef Edge edge_t; typedef Object obj_t; typedef carve::geom::aabb aabb_t; typedef carve::geom::plane plane_t; typedef carve::geom2d::P2 (*project_t)(const vector_t &); typedef vector_t (*unproject_t)(const carve::geom2d::P2 &, const plane_t &); public: std::vector vertices; // pointer into polyhedron.vertices std::vector edges; // pointer into polyhedron.edges project_t getProjector(bool positive_facing, int axis); unproject_t getUnprojector(bool positive_facing, int axis); public: typedef typename std::vector::iterator vertex_iter_t; typedef typename std::vector::const_iterator const_vertex_iter_t; typedef typename std::vector::iterator edge_iter_t; typedef typename std::vector::const_iterator const_edge_iter_t; obj_t *owner; aabb_t aabb; plane_t plane_eqn; int manifold_id; int group_id; project_t project; unproject_t unproject; Face(const std::vector &_vertices, bool delay_recalc = false); Face(const vertex_t *v1, const vertex_t *v2, const vertex_t *v3, bool delay_recalc = false); Face(const vertex_t *v1, const vertex_t *v2, const vertex_t *v3, const vertex_t *v4, bool delay_recalc = false); Face(const Face *base, const std::vector &_vertices, bool flipped) { init(base, _vertices, flipped); } Face() {} ~Face() {} bool recalc(); template Face *init(const Face *base, iter_t vbegin, iter_t vend, bool flipped); Face *init(const Face *base, const std::vector &_vertices, bool flipped); template Face *create(iter_t vbegin, iter_t vend, bool flipped) const; Face *create(const std::vector &_vertices, bool flipped) const; Face *clone(bool flipped = false) const; void invert(); void getVertexLoop(std::vector &loop) const; const vertex_t *&vertex(size_t idx); const vertex_t *vertex(size_t idx) const; size_t nVertices() const; vertex_iter_t vbegin() { return vertices.begin(); } vertex_iter_t vend() { return vertices.end(); } const_vertex_iter_t vbegin() const { return vertices.begin(); } const_vertex_iter_t vend() const { return vertices.end(); } std::vector > projectedVertices() const; const edge_t *&edge(size_t idx); const edge_t *edge(size_t idx) const; size_t nEdges() const; edge_iter_t ebegin() { return edges.begin(); } edge_iter_t eend() { return edges.end(); } const_edge_iter_t ebegin() const { return edges.begin(); } const_edge_iter_t eend() const { return edges.end(); } bool containsPoint(const vector_t &p) const; bool containsPointInProjection(const vector_t &p) const; bool simpleLineSegmentIntersection(const carve::geom::linesegment &line, vector_t &intersection) const; IntersectionClass lineSegmentIntersection(const carve::geom::linesegment &line, vector_t &intersection) const; vector_t centroid() const; p2_adapt_project projector() const { return p2_adapt_project(project); } void swap(Face &other); }; struct hash_face_ptr { template size_t operator()(const Face * const &f) const { return (size_t)f; } }; namespace face { template static inline carve::geom2d::P2 project(const Face *f, const typename Face::vector_t &v) { return f->project(v); } template static inline carve::geom2d::P2 project(const Face &f, const typename Face::vector_t &v) { return f.project(v); } template static inline typename Face::vector_t unproject(const Face *f, const carve::geom2d::P2 &p) { return f->unproject(p, f->plane_eqn); } template static inline typename Face::vector_t unproject(const Face &f, const carve::geom2d::P2 &p) { return f.unproject(p, f.plane_eqn); } } } }