KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gr_polymesh.h
Go to the documentation of this file.
1 /* $Id$ */
35 /* =========================================================================== *
36 |
37 | Copyright (c) 1994-2008 by Kobus Barnard (author).
38 |
39 | Personal and educational use of this code is granted, provided that this
40 | header is kept intact, and that the authorship is not misrepresented, that
41 | its use is acknowledged in publications, and relevant papers are cited.
42 |
43 | For other use contact the author (kobus AT cs DOT arizona DOT edu).
44 |
45 | Please note that the code in this file has not necessarily been adequately
46 | tested. Naturally, there is no guarantee of performance, support, or fitness
47 | for any particular task. Nonetheless, I am interested in hearing about
48 | problems that you encounter.
49 |
50 | Authors:
51 | Joseph Schlecht, Luca Del Pero
52 |
53 * =========================================================================== */
54 
64 #ifndef KJB_POLYMESH_H
65 #define KJB_POLYMESH_H
66 
67 #include <inttypes.h>
68 
69 #include <l_cpp/l_exception.h>
70 #include <gr_cpp/gr_polygon.h>
71 #include <gr_cpp/gr_rigid_object.h>
72 #include <vector>
73 #include <gr_cpp/gr_renderable.h>
74 
75 #include "l_cpp/l_readable.h"
76 #include "l_cpp/l_writeable.h"
77 
78 namespace kjb{
79 
80 
81 class Base_gl_interface;
90  public kjb::Rigid_object,
91  public kjb::Readable,
92  public kjb::Writeable
93 {
94  public:
95 
99  {
100 
101  }
102 
104  Polymesh(unsigned int n);
105 
106 
108  Polymesh(const char* fname) throw (kjb::Illegal_argument, kjb::IO_error);
109 
110 
112  Polymesh(std::istream& in) throw (kjb::Illegal_argument, kjb::IO_error);
113 
114 
116  Polymesh(const Polymesh& t);
117 
118 
120  virtual Polymesh& operator= (const Polymesh& t);
121 
123  virtual Polymesh * clone() const;
124 
126  virtual ~Polymesh();
127 
128 
130  unsigned int num_faces() const;
131 
133  const std::vector<kjb::Polygon>& get_faces() const;
134 
144  const kjb::Polygon& get_face(unsigned int i) const throw (kjb::Index_out_of_bounds);
145 
155  kjb::Polygon& get_face_ref(unsigned int i) throw (kjb::Index_out_of_bounds);
156 
157  //virtual void add_face(const Polygon & face, uint32_t id) throw (kjb::Illegal_argument);
158 
159  virtual void add_face(const Polygon & face) throw (kjb::Illegal_argument);
160 
162  virtual void read(std::istream & in)
164 
165 
167  virtual void write(std::ostream & ost)
168  const throw(kjb::IO_error);
169 
171  virtual void write(const char *filename) const throw (IO_error);
172 
173 
175  virtual void transform(const kjb::Matrix &) throw(kjb::Illegal_argument);
176 
177  /* @brief Translates this mesh */
178  virtual void translate(double x, double y, double z);
179 
180  /* @brief translates this mesh around an axis */
181  virtual void rotate(double phi, double x, double y, double z);
182 
183  virtual void rotate(double dpitch, double dyaw, double droll)
184  {
185  Rigid_object::rotate(dpitch, dyaw, droll);
186  }
187 
188  /* @brief scales this mesh */
189  virtual void scale(double scale_x, double scale_y, double scale_z);
190 
197  virtual unsigned int adjacent_face(unsigned int f, unsigned int e) const
199 
200  void get_faces(std::vector<const Polygon *> & ifaces) const;
201 
205  virtual void wire_render() const;
206 
213  unsigned int wire_render_with_sequential_ids(unsigned int start_id = 1) const;
214 
221  unsigned int solid_render_with_sequential_ids(unsigned int start_id = 1) const;
222 
228  virtual void wire_occlude_render() const;
229 
230  /*
231  * @brief Renders this mesh as a solid object
232  */
233  virtual void solid_render() const;
234 
236  virtual void silhouette_render(const kjb::Base_gl_interface & camera, double iwidth = 1.0) const;
237 
238  /*
239  * @brief Projects all the polygons in this mesh using
240  * onto the image plane
241  */
242  virtual void project();
243 
247  double compute_surface_area() const;
248 
252  void get_all_vertices(std::vector<Vector> & vertices) const;
253 
258  void get_all_edges(std::vector<std::vector<Vector> >& edges) const;
259 
260  void get_lines(std::vector<Line3d> & lines);
261 
262  /*
263  * @brief Iterates through all the vertices of the mesh and
264  * stores the smallest and largest x,y,z values.
265  */
266  void find_bounds();
267 
268  /*
269  * @brief Returns the center point of the mesh based on the
270  * midpoint of the smallest and largest bounds.
271  */
273 
274  /*
275  * @brief Returns the largest z-value of the points in the
276  * polymesh.
277  */
278  double get_largest_z_bound();
279 
280  /*
281  * @brief Returns the largest x, y, and z bounds in the polymesh.
282  */
284 
285  /*
286  * @brief Returns the smallest x, y, and z bounds in the polymesh.
287  */
289 
290 
291  protected:
293  std::vector<kjb::Polygon> _faces;
296 
298  inline bool is_same_vertex(const kjb::Vector& p1,const kjb::Vector& p2) const
299  {
300  return p1 == p2;
301  }
302 
304  bool is_shared_edge(const Polygon & f1, unsigned int e1, const Polygon & f2, unsigned int e2) const
305  throw (Index_out_of_bounds);
306 
307  /*
308  * @brief Returns true if face f2 contains contains edge e of face 1, false otherwise.
309  * If f2 contains the edge, index will contain the index of the shared edge in face f2.
310  */
311  bool edge_index_in_polygon(const Polygon &f1, unsigned int e, const Polygon &f2, unsigned int & index)
312  throw (Index_out_of_bounds);
313 
314  friend class GL_Polymesh_Renderer;
315 
316 };
317 
318 
319 }
320 
321 
322 #endif
void find_bounds()
Definition: gr_polymesh.cpp:766
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
virtual void translate(double x, double y, double z)
Translates this rigid object.
Definition: gr_polymesh.cpp:314
const std::vector< kjb::Polygon > & get_faces() const
Returns the faces of this mesh.
Definition: gr_polymesh.cpp:202
function lines
Definition: APPgetLargeConnectedEdges.m:1
Abstract class to read this object from an input stream.
Definition: l_readable.h:39
Object thrown when an index argument exceeds the size of a container.
Definition: l_exception.h:399
kjb::Vector get_center()
Definition: gr_polymesh.cpp:816
Vector smallest_bounds
Definition: gr_polymesh.h:294
unsigned int num_faces() const
Returns the number of faces in this mesh.
Definition: gr_polymesh.cpp:359
const kjb::Polygon & get_face(unsigned int i) const
Returns an indexed face.
Definition: gr_polymesh.cpp:173
virtual void transform(const kjb::Matrix &)
Applies a linear transformation to this parallelepiped.
Definition: gr_polymesh.cpp:292
virtual void silhouette_render(const kjb::Base_gl_interface &camera, double iwidth=1.0) const
Definition: gr_polymesh.cpp:592
bool edge_index_in_polygon(const Polygon &f1, unsigned int e, const Polygon &f2, unsigned int &index)
Definition: gr_polymesh.cpp:482
virtual void wire_occlude_render() const
Renders this mesh as a wire frame into the depth buffer. Use wire_render after this to render this me...
Definition: gr_polymesh.cpp:517
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
std::vector< kjb::Polygon > _faces
Polygons defining the mesh.
Definition: gr_polymesh.h:293
double get_largest_z_bound()
Definition: gr_polymesh.cpp:833
Definition: gr_polymesh_renderer.h:33
kjb::Polygon & get_face_ref(unsigned int i)
Returns an indexed face.
Definition: gr_polymesh.cpp:191
Vector largest_bounds
Definition: gr_polymesh.h:295
virtual void wire_render() const
Renders this mesh as a wire frame.
Definition: gr_polymesh.cpp:503
virtual Polymesh & operator=(const Polymesh &t)
Copies a triangular mesh into this one.
Definition: gr_polymesh.cpp:138
unsigned int wire_render_with_sequential_ids(unsigned int start_id=1) const
Render each edge of this polymesh with a different color. The first edge will be rendered using the i...
Definition: gr_polymesh.cpp:554
virtual unsigned int adjacent_face(unsigned int f, unsigned int e) const
returns the index of the face adjacent to face f along edge e This is a very inefficient implementati...
Definition: gr_polymesh.cpp:243
Abstract class to render this object with GL.
Definition: gr_renderable.h:151
Polymesh()
Constructs a triangular mesh.
Definition: gr_polymesh.h:97
virtual void project()
Definition: gr_polymesh.cpp:612
x
Definition: APPgetLargeConnectedEdges.m:100
virtual ~Polymesh()
Deletes this Polymesh.
Definition: gr_polymesh.cpp:160
virtual void scale(double scale_x, double scale_y, double scale_z)
Definition: gr_polymesh.cpp:345
virtual void solid_render() const
Renders this object with GL as a wire-frame.
Definition: gr_polymesh.cpp:531
Definition: gr_polygon.h:36
Abstract class of connected polygons (faces) forming a mesh. We assume that each edge is shared betwe...
Definition: gr_polymesh.h:89
Exception often thrown when wrapped C functions return error codes.
Definition: l_exception.h:262
double compute_surface_area() const
Returns the surface area of the mesh.
Definition: gr_polymesh.cpp:631
void get_lines(std::vector< Line3d > &lines)
Definition: gr_polymesh.cpp:723
Definition: gr_camera.h:103
kjb::Vector get_largest_bounds() const
Definition: gr_polymesh.cpp:842
virtual void add_face(const Polygon &face)
Definition: gr_polymesh.cpp:222
bool is_shared_edge(const Polygon &f1, unsigned int e1, const Polygon &f2, unsigned int e2) const
Checks whether edge e1 on face f1 is the same as edge e2 on face f2.
Definition: gr_polymesh.cpp:451
virtual void rotate(double dpitch, double dyaw, double droll)
rotate this object around its x-axis by dpitch, the y-axis by dyaw, and its z-axis by droll (in this ...
Definition: gr_rigid_object.cpp:105
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
virtual void read(std::istream &in)
Reads this polymesh from an input stream.
Definition: gr_polymesh.cpp:429
unsigned int solid_render_with_sequential_ids(unsigned int start_id=1) const
Render each polygon of this polymesh with a different color. The first polygon will be rendered using...
Definition: gr_polymesh.cpp:569
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
edges
Definition: APPgetLargeConnectedEdges.m:85
Object thrown when input or output fails.
Definition: l_exception.h:496
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Support for error handling exception classes in libKJB.
Definition: gr_rigid_object.h:87
bool is_same_vertex(const kjb::Vector &p1, const kjb::Vector &p2) const
Compares two points.
Definition: gr_polymesh.h:298
kjb::Vector get_smallest_bounds() const
Definition: gr_polymesh.cpp:851
void get_all_edges(std::vector< std::vector< Vector > > &edges) const
Stores all of the unique pairs of points that make up the edges of the polymesh in a vector...
Definition: gr_polymesh.cpp:678
virtual void rotate(double phi, double x, double y, double z)
Definition: gr_polymesh.cpp:330
virtual Polymesh * clone() const
Clones this mesh.
Definition: gr_polymesh.cpp:154
virtual void write(std::ostream &ost) const
Writes this mesh to an output stream.
Definition: gr_polymesh.cpp:402
void get_all_vertices(std::vector< Vector > &vertices) const
Stores the vertices of the mesh in a vector.
Definition: gr_polymesh.cpp:645