factorize the code when push_back is called for p.x(), p.y(), and p.z()

This commit is contained in:
Jane Tournois 2016-02-12 15:21:48 +01:00
parent d3ce97f566
commit 1ff1f566a0
1 changed files with 55 additions and 120 deletions

View File

@ -79,6 +79,15 @@ void delete_aabb_tree(Scene_polyhedron_item* item)
} }
} }
template<typename TypeWithXYZ, typename ContainerWithPushBack>
void push_back_xyz(const TypeWithXYZ& t,
ContainerWithPushBack& vector)
{
vector.push_back(t.x());
vector.push_back(t.y());
vector.push_back(t.z());
}
typedef Polyhedron::Traits Traits; typedef Polyhedron::Traits Traits;
typedef Polyhedron::Facet Facet; typedef Polyhedron::Facet Facet;
typedef CGAL::Triangulation_2_filtered_projection_traits_3<Traits> P_traits; typedef CGAL::Triangulation_2_filtered_projection_traits_3<Traits> P_traits;
@ -173,47 +182,27 @@ Scene_polyhedron_item::triangulate_facet(Facet_iterator fit,
if(ffit->info().is_external) if(ffit->info().is_external)
continue; continue;
positions_facets.push_back(ffit->vertex(0)->point().x()); push_back_xyz(ffit->vertex(0)->point(), positions_facets);
positions_facets.push_back(ffit->vertex(0)->point().y());
positions_facets.push_back(ffit->vertex(0)->point().z());
positions_facets.push_back(1.0); positions_facets.push_back(1.0);
positions_facets.push_back(ffit->vertex(1)->point().x()); push_back_xyz(ffit->vertex(1)->point(), positions_facets);
positions_facets.push_back(ffit->vertex(1)->point().y());
positions_facets.push_back(ffit->vertex(1)->point().z());
positions_facets.push_back(1.0); positions_facets.push_back(1.0);
positions_facets.push_back(ffit->vertex(2)->point().x()); push_back_xyz(ffit->vertex(3)->point(), positions_facets);
positions_facets.push_back(ffit->vertex(2)->point().y());
positions_facets.push_back(ffit->vertex(2)->point().z());
positions_facets.push_back(1.0); positions_facets.push_back(1.0);
normals_flat.push_back(normal.x()); push_back_xyz(normal, normals_flat);
normals_flat.push_back(normal.y()); push_back_xyz(normal, normals_flat);
normals_flat.push_back(normal.z()); push_back_xyz(normal, normals_flat);
normals_flat.push_back(normal.x());
normals_flat.push_back(normal.y());
normals_flat.push_back(normal.z());
normals_flat.push_back(normal.x());
normals_flat.push_back(normal.y());
normals_flat.push_back(normal.z());
Traits::Vector_3 ng = get(vnmap, v2v[ffit->vertex(0)]); Traits::Vector_3 ng = get(vnmap, v2v[ffit->vertex(0)]);
normals_gouraud.push_back(normal.x()); push_back_xyz(ng, normals_gouraud);
normals_gouraud.push_back(normal.y());
normals_gouraud.push_back(normal.z());
ng = get(vnmap, v2v[ffit->vertex(1)]); ng = get(vnmap, v2v[ffit->vertex(1)]);
normals_gouraud.push_back(normal.x()); push_back_xyz(ng, normals_gouraud);
normals_gouraud.push_back(normal.y());
normals_gouraud.push_back(normal.z());
ng = get(vnmap, v2v[ffit->vertex(2)]); ng = get(vnmap, v2v[ffit->vertex(2)]);
normals_gouraud.push_back(normal.x()); push_back_xyz(ng, normals_gouraud);
normals_gouraud.push_back(normal.y());
normals_gouraud.push_back(normal.z());
} }
} }
@ -482,25 +471,19 @@ Scene_polyhedron_item::compute_normals_and_vertices(void) const
HF_circulator end = he; HF_circulator end = he;
CGAL_For_all(he,end) CGAL_For_all(he,end)
{ {
// If Flat shading:1 normal per polygon added once per vertex // If Flat shading:1 normal per polygon added once per vertex
normals_flat.push_back(n.x()); push_back_xyz(n, normals_flat);
normals_flat.push_back(n.y());
normals_flat.push_back(n.z());
//// If Gouraud shading: 1 normal per vertex //// If Gouraud shading: 1 normal per vertex
Vector nv = get(nv_pmap, he->vertex()); Vector nv = get(nv_pmap, he->vertex());
normals_gouraud.push_back(nv.x()); push_back_xyz(nv, normals_gouraud);
normals_gouraud.push_back(nv.y());
normals_gouraud.push_back(nv.z());
//position //position
const Point& p = he->vertex()->point(); const Point& p = he->vertex()->point();
positions_facets.push_back(p.x()); push_back_xyz(p, positions_facets);
positions_facets.push_back(p.y()); positions_facets.push_back(1.0);
positions_facets.push_back(p.z()); i = (i+1) %3;
positions_facets.push_back(1.0); }
i = (i+1) %3;
}
} }
else if (is_quad(f->halfedge(), *poly)) else if (is_quad(f->halfedge(), *poly))
{ {
@ -511,94 +494,54 @@ Scene_polyhedron_item::compute_normals_and_vertices(void) const
Point p1 = f->halfedge()->next()->vertex()->point(); Point p1 = f->halfedge()->next()->vertex()->point();
Point p2 = f->halfedge()->next()->next()->vertex()->point(); Point p2 = f->halfedge()->next()->next()->vertex()->point();
positions_facets.push_back(p0.x()); push_back_xyz(p0, positions_facets);
positions_facets.push_back(p0.y());
positions_facets.push_back(p0.z());
positions_facets.push_back(1.0); positions_facets.push_back(1.0);
positions_facets.push_back(p1.x()); push_back_xyz(p1, positions_facets);
positions_facets.push_back(p1.y());
positions_facets.push_back(p1.z());
positions_facets.push_back(1.0); positions_facets.push_back(1.0);
positions_facets.push_back(p2.x()); push_back_xyz(p2, positions_facets);
positions_facets.push_back(p2.y());
positions_facets.push_back(p2.z());
positions_facets.push_back(1.0); positions_facets.push_back(1.0);
normals_flat.push_back(nf.x()); push_back_xyz(nf, normals_flat);
normals_flat.push_back(nf.y()); push_back_xyz(nf, normals_flat);
normals_flat.push_back(nf.z()); push_back_xyz(nf, normals_flat);
normals_flat.push_back(nf.x());
normals_flat.push_back(nf.y());
normals_flat.push_back(nf.z());
normals_flat.push_back(nf.x());
normals_flat.push_back(nf.y());
normals_flat.push_back(nf.z());
Vector nv = get(nv_pmap, f->halfedge()->vertex()); Vector nv = get(nv_pmap, f->halfedge()->vertex());
normals_gouraud.push_back(nv.x()); push_back_xyz(nv, normals_gouraud);
normals_gouraud.push_back(nv.y());
normals_gouraud.push_back(nv.z());
nv = get(nv_pmap, f->halfedge()->next()->vertex()); nv = get(nv_pmap, f->halfedge()->next()->vertex());
normals_gouraud.push_back(nv.x()); push_back_xyz(nv, normals_gouraud);
normals_gouraud.push_back(nv.y());
normals_gouraud.push_back(nv.z());
nv = get(nv_pmap, f->halfedge()->next()->next()->vertex()); nv = get(nv_pmap, f->halfedge()->next()->next()->vertex());
normals_gouraud.push_back(nv.x()); push_back_xyz(nv, normals_gouraud);
normals_gouraud.push_back(nv.y());
normals_gouraud.push_back(nv.z());
//2nd half-quad //2nd half-quad
p0 = f->halfedge()->next()->next()->vertex()->point(); p0 = f->halfedge()->next()->next()->vertex()->point();
p1 = f->halfedge()->prev()->vertex()->point(); p1 = f->halfedge()->prev()->vertex()->point();
p2 = f->halfedge()->vertex()->point(); p2 = f->halfedge()->vertex()->point();
positions_facets.push_back(p0.x()); push_back_xyz(p0, positions_facets);
positions_facets.push_back(p0.y());
positions_facets.push_back(p0.z());
positions_facets.push_back(1.0); positions_facets.push_back(1.0);
positions_facets.push_back(p1.x()); push_back_xyz(p1, positions_facets);
positions_facets.push_back(p1.y());
positions_facets.push_back(p1.z());
positions_facets.push_back(1.0); positions_facets.push_back(1.0);
positions_facets.push_back(p2.x()); push_back_xyz(p2, positions_facets);
positions_facets.push_back(p2.y());
positions_facets.push_back(p2.z());
positions_facets.push_back(1.0); positions_facets.push_back(1.0);
normals_flat.push_back(nf.x()); push_back_xyz(nf, normals_flat);
normals_flat.push_back(nf.y()); push_back_xyz(nf, normals_flat);
normals_flat.push_back(nf.z()); push_back_xyz(nf, normals_flat);
normals_flat.push_back(nf.x());
normals_flat.push_back(nf.y());
normals_flat.push_back(nf.z());
normals_flat.push_back(nf.x());
normals_flat.push_back(nf.y());
normals_flat.push_back(nf.z());
nv = get(nv_pmap, f->halfedge()->next()->next()->vertex()); nv = get(nv_pmap, f->halfedge()->next()->next()->vertex());
normals_gouraud.push_back(nv.x()); push_back_xyz(nv, normals_gouraud);
normals_gouraud.push_back(nv.y());
normals_gouraud.push_back(nv.z());
nv = get(nv_pmap, f->halfedge()->prev()->vertex()); nv = get(nv_pmap, f->halfedge()->prev()->vertex());
normals_gouraud.push_back(nv.x()); push_back_xyz(nv, normals_gouraud);
normals_gouraud.push_back(nv.y());
normals_gouraud.push_back(nv.z());
nv = get(nv_pmap, f->halfedge()->vertex()); nv = get(nv_pmap, f->halfedge()->vertex());
normals_gouraud.push_back(nv.x()); push_back_xyz(nv, normals_gouraud);
normals_gouraud.push_back(nv.y());
normals_gouraud.push_back(nv.z());
} }
else else
{ {
@ -618,27 +561,19 @@ Scene_polyhedron_item::compute_normals_and_vertices(void) const
const Point& b = he->opposite()->vertex()->point(); const Point& b = he->opposite()->vertex()->point();
if ( he->is_feature_edge()) if ( he->is_feature_edge())
{ {
positions_feature_lines.push_back(a.x()); push_back_xyz(a, positions_feature_lines);
positions_feature_lines.push_back(a.y()); positions_feature_lines.push_back(1.0);
positions_feature_lines.push_back(a.z());
positions_feature_lines.push_back(1.0);
positions_feature_lines.push_back(b.x()); push_back_xyz(b, positions_feature_lines);
positions_feature_lines.push_back(b.y()); positions_feature_lines.push_back(1.0);
positions_feature_lines.push_back(b.z());
positions_feature_lines.push_back(1.0);
} }
else else
{ {
positions_lines.push_back(a.x()); push_back_xyz(a, positions_lines);
positions_lines.push_back(a.y()); positions_lines.push_back(1.0);
positions_lines.push_back(a.z());
positions_lines.push_back(1.0);
positions_lines.push_back(b.x()); push_back_xyz(b, positions_lines);
positions_lines.push_back(b.y()); positions_lines.push_back(1.0);
positions_lines.push_back(b.z());
positions_lines.push_back(1.0);
} }
} }
//set the colors //set the colors