cgv
streaming_mesh.h
1 #pragma once
2 
3 #include <vector>
4 #include <deque>
5 #include <cgv/math/fvec.h>
6 
7 namespace cgv {
8  namespace media {
9  namespace mesh {
10 
13 {
15  virtual void new_vertex(unsigned int vertex_index) = 0;
17  virtual void new_polygon(const std::vector<unsigned int>& vertex_indices) = 0;
19  virtual void before_drop_vertex(unsigned int vertex_index) = 0;
20 };
21 
23 template <typename T>
25 {
26 public:
31 protected:
33  int idx_off;
35  unsigned int nr_faces;
37  std::deque<pnt_type> pnts;
39  std::deque<vec_type> nmls;
42 public:
45  }
48  smcbh = _smcbh;
49  }
51  unsigned int get_nr_dropped_vertices() const { return idx_off; }
53  unsigned int get_nr_vertices() const { return (unsigned int) pnts.size()+idx_off; }
55  unsigned int get_nr_faces() const { return nr_faces; }
57  void drop_vertex() {
58  if (pnts.empty())
59  return;
60  if (smcbh)
62  pnts.pop_front();
63  nmls.pop_front();
64  ++idx_off;
65  }
67  void drop_vertices(unsigned int n) {
68  for (unsigned int i=0; i<n; ++i)
69  drop_vertex();
70  }
72  pnt_type& vertex_location(unsigned int vi) { return pnts[vi-idx_off]; }
74  const pnt_type& vertex_location(unsigned int vi) const { return pnts[vi-idx_off]; }
76  const vec_type& vertex_normal(unsigned int vi) const { return nmls[vi-idx_off]; }
78  vec_type& vertex_normal(unsigned int vi) { return nmls[vi-idx_off]; }
80  unsigned int new_vertex(const pnt_type& p) {
81  unsigned int vi = (int)pnts.size()+idx_off;
82  pnts.push_back(p);
83  nmls.push_back(vec_type(0,0,0));
84  if (smcbh)
85  smcbh->new_vertex(vi);
86  return vi;
87  }
89  void new_triangle(unsigned int vi, unsigned int vj, unsigned int vk) {
90  static std::vector<unsigned int> vis(3);
91  vis[0] = vi;
92  vis[1] = vj;
93  vis[2] = vk;
94  ++nr_faces;
95  if (smcbh)
96  smcbh->new_polygon(vis);
97  }
99  void new_quad(unsigned int vi, unsigned int vj, unsigned int vk, unsigned int vl) {
100  static std::vector<unsigned int> vis(4);
101  vis[0] = vi;
102  vis[1] = vj;
103  vis[2] = vk;
104  vis[3] = vl;
105  ++nr_faces;
106  if (smcbh)
107  smcbh->new_polygon(vis);
108  }
110  void new_polygon(const std::vector<unsigned int>& vertex_indices) {
111  ++nr_faces;
112  if (smcbh)
113  smcbh->new_polygon(vertex_indices);
114  }
115 };
116 
117  }
118  }
119 }
cgv::media::mesh::streaming_mesh::set_callback_handler
void set_callback_handler(streaming_mesh_callback_handler *_smcbh)
set a new callback handler
Definition: streaming_mesh.h:47
cgv::media::mesh::streaming_mesh::drop_vertex
void drop_vertex()
drop the front most vertex from the deque
Definition: streaming_mesh.h:57
cgv::media::mesh::streaming_mesh::vec_type
cgv::math::fvec< T, 3 > vec_type
type of vertex normals
Definition: streaming_mesh.h:30
cgv::media::mesh::streaming_mesh::vertex_normal
const vec_type & vertex_normal(unsigned int vi) const
read access to vertex normals
Definition: streaming_mesh.h:76
cgv::math::fvec< T, 3 >
cgv::media::mesh::streaming_mesh_callback_handler::before_drop_vertex
virtual void before_drop_vertex(unsigned int vertex_index)=0
drop the currently first vertex that has the given global vertex index
cgv::media::mesh::streaming_mesh::pnts
std::deque< pnt_type > pnts
store currently used points in deque
Definition: streaming_mesh.h:37
cgv::media::mesh::streaming_mesh::streaming_mesh
streaming_mesh(streaming_mesh_callback_handler *_smcbh=0)
construct from callback handler
Definition: streaming_mesh.h:44
cgv::media::mesh::streaming_mesh_callback_handler::new_vertex
virtual void new_vertex(unsigned int vertex_index)=0
called when a new vertex is generated
cgv::media::mesh::streaming_mesh::vertex_location
const pnt_type & vertex_location(unsigned int vi) const
read access to vertex locations
Definition: streaming_mesh.h:74
cgv::media::mesh::streaming_mesh_callback_handler
Definition: streaming_mesh.h:13
cgv::media::mesh::streaming_mesh::new_vertex
unsigned int new_vertex(const pnt_type &p)
add a new vertex with the given location and call the callback of the callback handler
Definition: streaming_mesh.h:80
cgv::media::mesh::streaming_mesh::vertex_normal
vec_type & vertex_normal(unsigned int vi)
write access to vertex normals
Definition: streaming_mesh.h:78
cgv::media::mesh::streaming_mesh::nr_faces
unsigned int nr_faces
count the number of faces
Definition: streaming_mesh.h:35
cgv::media::mesh::streaming_mesh::new_polygon
void new_polygon(const std::vector< unsigned int > &vertex_indices)
construct a new polygon by calling the new polygon method of the callback handler
Definition: streaming_mesh.h:110
cgv::media::mesh::streaming_mesh::vertex_location
pnt_type & vertex_location(unsigned int vi)
write access to vertex locations
Definition: streaming_mesh.h:72
cgv::media::mesh::streaming_mesh::nmls
std::deque< vec_type > nmls
store currently used normals in deque
Definition: streaming_mesh.h:39
cgv::media::mesh::streaming_mesh::new_triangle
void new_triangle(unsigned int vi, unsigned int vj, unsigned int vk)
construct a new triangle by calling the new polygon method of the callback handler
Definition: streaming_mesh.h:89
cgv::media::mesh::streaming_mesh::idx_off
int idx_off
offset used to address vertices in deque
Definition: streaming_mesh.h:33
cgv::media::mesh::streaming_mesh
class used to perform the marching cubes algorithm
Definition: streaming_mesh.h:25
cgv::media::mesh::streaming_mesh::smcbh
streaming_mesh_callback_handler * smcbh
store a pointer to the callback handler
Definition: streaming_mesh.h:41
cgv::media::mesh::streaming_mesh::pnt_type
cgv::math::fvec< T, 3 > pnt_type
type of vertex locations
Definition: streaming_mesh.h:28
cgv::media::mesh::streaming_mesh::new_quad
void new_quad(unsigned int vi, unsigned int vj, unsigned int vk, unsigned int vl)
construct a new quad by calling the new polygon method of the callback handler
Definition: streaming_mesh.h:99
cgv::media::mesh::streaming_mesh::get_nr_vertices
unsigned int get_nr_vertices() const
return the number of vertices
Definition: streaming_mesh.h:53
cgv::media::mesh::streaming_mesh_callback_handler::new_polygon
virtual void new_polygon(const std::vector< unsigned int > &vertex_indices)=0
announces a new polygon defines by the vertex indices stored in the given vector
cgv::media::mesh::streaming_mesh::get_nr_faces
unsigned int get_nr_faces() const
return the number of faces
Definition: streaming_mesh.h:55
cgv::media::mesh::streaming_mesh::drop_vertices
void drop_vertices(unsigned int n)
drop n vertices from the front of the deque
Definition: streaming_mesh.h:67
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::media::mesh::streaming_mesh::get_nr_dropped_vertices
unsigned int get_nr_dropped_vertices() const
return the number of vertices dropped from the front, what is used as index offset into a deque
Definition: streaming_mesh.h:51