cgv
Loading...
Searching...
No Matches
streaming_mesh.h
1#pragma once
2
3#include <vector>
4#include <deque>
5#include <cgv/math/fvec.h>
6
7namespace 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
23template <typename T>
25{
26public:
31protected:
35 unsigned int nr_faces;
37 std::deque<pnt_type> pnts;
39 std::deque<vec_type> nmls;
42public:
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)
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}
A vector with zero based index.
Definition fvec.h:26
class used to perform the marching cubes algorithm
void set_callback_handler(streaming_mesh_callback_handler *_smcbh)
set a new callback handler
vec_type & vertex_normal(unsigned int vi)
write access to vertex normals
unsigned int get_nr_vertices() const
return the number of vertices
unsigned int new_vertex(const pnt_type &p)
add a new vertex with the given location and call the callback of the callback handler
const vec_type & vertex_normal(unsigned int vi) const
read access to vertex normals
cgv::math::fvec< T, 3 > vec_type
type of vertex normals
streaming_mesh_callback_handler * smcbh
store a pointer to the callback handler
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
void drop_vertex()
drop the front most vertex from the deque
pnt_type & vertex_location(unsigned int vi)
write access to vertex locations
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
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
unsigned int nr_faces
count the number of faces
unsigned int get_nr_faces() const
return the number of faces
std::deque< vec_type > nmls
store currently used normals in deque
void new_polygon(const std::vector< unsigned int > &vertex_indices)
construct a new polygon by calling the new polygon method of the callback handler
void drop_vertices(unsigned int n)
drop n vertices from the front of the deque
int idx_off
offset used to address vertices in deque
streaming_mesh(streaming_mesh_callback_handler *_smcbh=0)
construct from callback handler
cgv::math::fvec< T, 3 > pnt_type
type of vertex locations
const pnt_type & vertex_location(unsigned int vi) const
read access to vertex locations
std::deque< pnt_type > pnts
store currently used points in deque
the cgv namespace
Definition print.h:11
pure abstract interface to handle callbacks of a streaming mesh
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
virtual void new_vertex(unsigned int vertex_index)=0
called when a new vertex is generated
virtual void before_drop_vertex(unsigned int vertex_index)=0
drop the currently first vertex that has the given global vertex index