xc
Polyhedron3d.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //POLYHEDRON3D.h
22 
23 #ifndef POLYHEDRON3D_H
24 #define POLYHEDRON3D_H
25 
26 #include <iostream>
27 #include "PolyhedronBase.h"
28 #include "../../cgal_types.h"
29 #include "PolygonMap.h"
30 #include "enriched_polyhedron.h"
31 
32 class Plane;
33 class HalfSpace3d;
34 class Triang3dMesh;
35 class Polygon3d;
36 
37 
39 //
42  {
43  protected:
44  CGPolyhedron_3 cgpolyhedron;
45 
46  explicit Polyhedron3d(const CGPolyhedron_3 &cgp)
47  : PolyhedronBase(), cgpolyhedron(cgp) {}
48  void make_tetrahedron(const Pos3d &p0, const Pos3d &p1,const Pos3d &p2, const Pos3d &p3);
49  void make_tetrahedron(const HalfSpace3d &, const HalfSpace3d &,const HalfSpace3d &, const HalfSpace3d &);
50  void make_polyhedron(const std::deque<HalfSpace3d> &);
51  //void halfSpaces(const std::string &,const bool &clear= true);
52 
53  public:
54  typedef CGPolyhedron_3::Vertex Vertex;
55  typedef CGPolyhedron_3::Facet Facet;
56 
57  typedef CGPolyhedron_3::Point_iterator Point_iterator;
58  typedef CGPolyhedron_3::Point_const_iterator Point_const_iterator;
59  typedef CGPolyhedron_3::Vertex_iterator Vertex_iterator;
60  typedef CGPolyhedron_3::Vertex_const_iterator Vertex_const_iterator;
61  typedef CGPolyhedron_3::Facet_iterator Facet_iterator;
62  typedef CGPolyhedron_3::Facet_const_iterator Facet_const_iterator;
63  typedef CGPolyhedron_3::Edge_iterator Edge_iterator;
64  typedef CGPolyhedron_3::Halfedge_iterator Halfedge_iterator;
65  typedef CGPolyhedron_3::Halfedge_around_facet_circulator Halfedge_around_facet_circulator;
66  typedef CGPolyhedron_3::Halfedge_around_vertex_circulator Halfedge_around_vertex_circulator;
67  typedef CGPolyhedron_3::Vertex_handle Vertex_handle;
68  typedef CGPolyhedron_3::Facet_handle Facet_handle;
69  typedef CGPolyhedron_3::Halfedge_handle Halfedge_handle;
70  typedef CGPolyhedron_3::HalfedgeDS HalfedgeDS;
71 
72  Polyhedron3d(void);
73  Polyhedron3d(const Pos3d &, const Pos3d &,const Pos3d &, const Pos3d &);
74  Polyhedron3d(const HalfSpace3d &, const HalfSpace3d &,const HalfSpace3d &, const HalfSpace3d &);
75  Polyhedron3d(const std::deque<HalfSpace3d> &);
76  Polyhedron3d(const Polyhedron3d &);
77  Polyhedron3d(const EPolyhedron &e);
79  virtual GeomObj *getCopy(void) const;
80 
81  Point_iterator points_begin(void)
82  { return cgpolyhedron.points_begin(); }
83  Point_iterator points_end(void)
84  { return cgpolyhedron.points_end(); }
85  Vertex_iterator vertices_begin(void)
86  { return cgpolyhedron.vertices_begin(); }
87  Vertex_iterator vertices_end(void)
88  { return cgpolyhedron.vertices_end(); }
89  Facet_iterator facets_begin(void)
90  { return cgpolyhedron.facets_begin(); }
91  Facet_iterator facets_end(void)
92  { return cgpolyhedron.facets_end(); }
93  Point_const_iterator points_begin(void) const
94  { return cgpolyhedron.points_begin(); }
95  Point_const_iterator points_end(void) const
96  { return cgpolyhedron.points_end(); }
97  Vertex_const_iterator vertices_begin(void) const
98  { return cgpolyhedron.vertices_begin(); }
99  Vertex_const_iterator vertices_end(void) const
100  { return cgpolyhedron.vertices_end(); }
101  Facet_const_iterator facets_begin(void) const
102  { return cgpolyhedron.facets_begin(); }
103  Facet_const_iterator facets_end(void) const
104  { return cgpolyhedron.facets_end(); }
105 
106  GEOM_FT GetMax(unsigned short int i) const;
107  GEOM_FT GetMin(unsigned short int i) const;
108  size_t getNumVertices(void) const
109  { return cgpolyhedron.size_of_vertices(); }
110  size_t getNumEdges(void) const
111  { return cgpolyhedron.size_of_halfedges(); }
112  size_t GetNumCaras(void) const
113  { return cgpolyhedron.size_of_facets(); }
114 
115  void clear(void)
116  { cgpolyhedron.clear(); }
117 
118  GeomObj::list_Pos3d GetVerticesCara(const Facet_const_iterator &f) const;
119  Plane getPlaneFromFace(const Facet_const_iterator &fi) const;
120  Polygon3d GetCara(const Facet_const_iterator &f) const;
121  std::deque<Polygon3d> GetCaras(void) const;
122 
123  GeomObj::list_Pos3d getVertices(void) const;
124 
125  virtual GEOM_FT getArea(void) const;
126 
127  bool TocaCuadrante(const int &) const;
128 
129  PolygonMap<CGPolyhedron_3> GetPolygonMap(void) const
130  { return getPolygonMap(cgpolyhedron); }
131  EPolyhedron GetEnriquecido(void) const;
132  Triang3dMesh Triangula(void) const;
133 
134  GEOM_FT PseudoDist(const Pos3d &p) const;
137  inline virtual GEOM_FT dist(const Pos3d &p) const
138  { return PseudoDist(p); }
139 
140  friend Polyhedron3d Union(const Polyhedron3d &a,const Polyhedron3d &b);
141  friend Polyhedron3d intersection(const Polyhedron3d &a,const Polyhedron3d &b);
142  friend Polyhedron3d Diferencia(const Polyhedron3d &a,const Polyhedron3d &b);
143  friend Polyhedron3d subdivide_quad_triangle(const Polyhedron3d &pol,bool smooth_boundary);
144  template <class InputIterator>
145  friend Polyhedron3d get_convex_hull(InputIterator first,InputIterator last);
146 
147  void Print(std::ostream &os) const;
148  void ReadOFF(std::istream &is);
149  };
150 
151 inline PolygonMap<CGPolyhedron_3> getPolygonMap(const Polyhedron3d &p)
152  { return p.GetPolygonMap(); }
153 inline EPolyhedron enriquece(const Polyhedron3d &p)
154  { return p.GetEnriquecido(); }
155 
156 Polyhedron3d subdivide_quad_triangle(const Polyhedron3d &pol,bool smooth_boundary= false);
157 
158 #endif
bool TocaCuadrante(const int &) const
Return verdadero si alguno de los vertices toca el cuadrante que se pasa como parámetro.
Definition: Polyhedron3d.cc:268
Definition: enriched_polyhedron.h:174
Plane polygon in a 3D space.
Definition: Polygon3d.h:35
std::deque< Polygon3d > GetCaras(void) const
Return the faces of the polyhedron.
Definition: Polyhedron3d.cc:175
virtual GEOM_FT dist(const Pos3d &p) const
Return the distance to the point (negative if the point is inside the solid).
Definition: Polyhedron3d.h:137
Base class for position lists.
Definition: PolyPos.h:35
Definition: PolygonMap.h:115
friend Polyhedron3d intersection(const Polyhedron3d &a, const Polyhedron3d &b)
Intersection of the polyhedrons.
Definition: polyhedron3d_bool_op.cc:117
Base class for polyhedrons in a three-dimensional space.
Definition: Polyhedron3d.h:41
virtual GeomObj * getCopy(void) const
Constructor virtual.
Definition: Polyhedron3d.cc:74
void Print(std::ostream &os) const
Print stuff.
Definition: Polyhedron3d.cc:184
Plane in a three-dimensional space.
Definition: Plane.h:49
virtual GEOM_FT getArea(void) const
Return the sum of the areas of the faces.
Definition: Polyhedron3d.cc:116
Polyhedron3d & operator=(const Polyhedron3d &)
Assignment operator.
Definition: Polyhedron3d.cc:66
void ReadOFF(std::istream &is)
Read the polyhedrom from an Object File Format file.
Definition: Polyhedron3d.cc:194
GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: Polyhedron3d.cc:132
Base class for the polyhedrons.
Definition: PolyhedronBase.h:35
friend Polyhedron3d Union(const Polyhedron3d &a, const Polyhedron3d &b)
Union of the polyhedron arguments.
Definition: polyhedron3d_bool_op.cc:110
Polygon3d GetCara(const Facet_const_iterator &f) const
Return la cara correspondiente al iterador.
Definition: Polyhedron3d.cc:167
friend Polyhedron3d Diferencia(const Polyhedron3d &a, const Polyhedron3d &b)
Difference of the polyhedrons.
Definition: polyhedron3d_bool_op.cc:124
GEOM_FT GetMax(unsigned short int i) const
Return the maximum value of the i-th coordinate.
Definition: Polyhedron3d.cc:124
Posición en tres dimensiones.
Definition: Pos3d.h:44
3D Triange mesh.
Definition: Triang3dMesh.h:37
Polyhedron3d(void)
Default constructor.
Definition: Polyhedron3d.cc:40
The points of the half space are those that line at the back of the plane, this being understood as t...
Definition: HalfSpace3d.h:42
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
GEOM_FT PseudoDist(const Pos3d &p) const
Return the SIGNED distance from the point to the tetrahedron.
Definition: Polyhedron3d.cc:246