Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGAL Lab: Rendering polygons with ghost edges #7898

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions Polyhedron/demo/Polyhedron/Plugins/PMP/Distance_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,10 @@ class Scene_distance_polyhedron_item: public Scene_item_rendering_helper

for(boost::graph_traits<Face_graph>::face_descriptor f : faces(*poly)) {
Vector nf = get(nf_pmap, f);
typedef FacetTriangulator<Face_graph, Kernel, boost::graph_traits<Face_graph>::vertex_descriptor> FT;

//compute distance with other polyhedron
//sample facet
std::vector<Kernel::Point_3> sampled_points;
std::size_t nb_points = (std::max)((int)std::ceil(nb_pts_per_face * PMP::face_area(f,*poly,CGAL::parameters::geom_traits(Kernel()))),
1);
std::size_t nb_points = (std::max)((int)std::ceil(nb_pts_per_face * PMP::face_area(f,*poly,CGAL::parameters::geom_traits(Kernel()))), 1);
Kernel::Point_3 &p = get(vpmap,target(halfedge(f,*poly),*poly));
Kernel::Point_3 &q = get(vpmap,target(next(halfedge(f,*poly),*poly),*poly));
Kernel::Point_3 &r = get(vpmap,target(next(next(halfedge(f,*poly),*poly),*poly),*poly));
Expand All @@ -207,36 +204,42 @@ class Scene_distance_polyhedron_item: public Scene_item_rendering_helper
sampled_points.push_back(r);

//triangle facets with sample points for color display
FT triangulation(f,sampled_points,nf,poly);

if(triangulation.cdt->dimension() != 2 )
{
qDebug()<<"Error : cdt not right (dimension != 2). Facet not displayed";
continue;
}

//iterates on the internal faces to add the vertices to the positions
//and the normals to the appropriate vectors
auto func = [&](auto& ffit, auto&) {
if (ffit.info().is_external)
return;

for(FT::CDT::Finite_faces_iterator
ffit = triangulation.cdt->finite_faces_begin(),
end = triangulation.cdt->finite_faces_end();
ffit != end; ++ffit)
{
if(ffit->info().is_external)
continue;

for (int i = 0; i<3; ++i)
for (int i = 0; i < 3; ++i)
{
total_points.push_back(ffit->vertex(i)->point());
m_vertices.push_back(ffit->vertex(i)->point().x());
m_vertices.push_back(ffit->vertex(i)->point().y());
m_vertices.push_back(ffit->vertex(i)->point().z());
total_points.push_back(ffit.vertex(i)->point());
m_vertices.push_back(ffit.vertex(i)->point().x());
m_vertices.push_back(ffit.vertex(i)->point().y());
m_vertices.push_back(ffit.vertex(i)->point().z());

normals.push_back(nf.x());
normals.push_back(nf.y());
normals.push_back(nf.z());
}
};

try {
FacetTriangulator<Face_graph, Kernel, boost::graph_traits<Face_graph>::vertex_descriptor> triangulation(f, sampled_points, nf, poly);

if (triangulation.cdt->dimension() != 2)
{
qDebug() << "Error : cdt not right (dimension != 2). Facet not displayed";
continue;
}
triangulation.per_face(func);
}
catch (...) {
FacetTriangulator<Face_graph, Kernel, boost::graph_traits<Face_graph>::vertex_descriptor, CGAL::Exact_intersections_tag> triangulation(f, sampled_points, nf, poly);

if (triangulation.cdt->dimension() != 2)
{
qDebug() << "Error : cdt not right (dimension != 2). Facet not displayed";
continue;
}
triangulation.per_face(func);
}
}
//compute the distances
Expand Down
105 changes: 48 additions & 57 deletions Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,80 +137,71 @@ Scene_polygon_soup_item_priv::triangulate_polygon(Polygons_iterator pit, int pol
if (normal == CGAL::NULL_VECTOR) // No normal could be computed, return
return;

typedef FacetTriangulator<SMesh, EPICK, std::size_t> FT;
typedef std::pair<EPICK::Point_3, std::size_t> PointAndId;

std::size_t it = 0;
std::size_t it_end =pit->size();
std::vector<FT::PointAndId> pointIds;
std::vector<PointAndId> pointIds;
do {
FT::PointAndId pointId;
PointAndId pointId;

pointId.point = soup->points[pit->at(it)]+offset;
pointId.id = pit->at(it);
pointId.first = soup->points[pit->at(it)]+offset;
pointId.second = pit->at(it);
pointIds.push_back(pointId);
} while( ++it != it_end );
//detect degenerated faces
std::vector<FT::PointAndId> pid_stack = pointIds;
for(std::size_t i = 0; i< pointIds.size(); ++i)
{
FT::PointAndId pid = pid_stack.back();
pid_stack.pop_back();
for(FT::PointAndId poai : pid_stack)
{
if (pid.point== poai.point)
{
return;
}
}
}
FT triangulation(pointIds,normal);

//iterates on the internal faces to add the vertices to the positions
//and the normals to the appropriate vectors
for(FT::CDT::Finite_faces_iterator
ffit = triangulation.cdt->finite_faces_begin(),
end = triangulation.cdt->finite_faces_end();
ffit != end; ++ffit)
{
if(ffit->info().is_external)
continue;

positions_poly.push_back(ffit->vertex(0)->point().x());
positions_poly.push_back(ffit->vertex(0)->point().y());
positions_poly.push_back(ffit->vertex(0)->point().z());
auto f = [&](auto& ffit, auto& v2v) {
if (ffit.info().is_external)
return;

positions_poly.push_back(ffit.vertex(0)->point().x());
positions_poly.push_back(ffit.vertex(0)->point().y());
positions_poly.push_back(ffit.vertex(0)->point().z());

positions_poly.push_back(ffit->vertex(1)->point().x());
positions_poly.push_back(ffit->vertex(1)->point().y());
positions_poly.push_back(ffit->vertex(1)->point().z());
positions_poly.push_back(ffit.vertex(1)->point().x());
positions_poly.push_back(ffit.vertex(1)->point().y());
positions_poly.push_back(ffit.vertex(1)->point().z());

positions_poly.push_back(ffit->vertex(2)->point().x());
positions_poly.push_back(ffit->vertex(2)->point().y());
positions_poly.push_back(ffit->vertex(2)->point().z());
positions_poly.push_back(ffit.vertex(2)->point().x());
positions_poly.push_back(ffit.vertex(2)->point().y());
positions_poly.push_back(ffit.vertex(2)->point().z());

CGAL::IO::Color color;
if(!soup->fcolors.empty())
color = soup->fcolors[polygon_id];
for(int i=0; i<3; i++)
CGAL::IO::Color color;
if (!soup->fcolors.empty())
color = soup->fcolors[polygon_id];
for (int i = 0; i < 3; i++)
{
normals.push_back(normal.x());
normals.push_back(normal.y());
normals.push_back(normal.z());
if (!soup->fcolors.empty())
{
normals.push_back(normal.x());
normals.push_back(normal.y());
normals.push_back(normal.z());
if(!soup->fcolors.empty())
{
f_colors.push_back(static_cast<float>(color.red())/255);
f_colors.push_back(static_cast<float>(color.green())/255);
f_colors.push_back(static_cast<float>(color.blue())/255);
}
if(!soup->vcolors.empty())
{
CGAL::IO::Color vcolor = soup->vcolors[triangulation.v2v[ffit->vertex(i)]];
v_colors.push_back(static_cast<float>(vcolor.red())/255);
v_colors.push_back(static_cast<float>(vcolor.green())/255);
v_colors.push_back(static_cast<float>(vcolor.blue())/255);
}
f_colors.push_back(static_cast<float>(color.red()) / 255);
f_colors.push_back(static_cast<float>(color.green()) / 255);
f_colors.push_back(static_cast<float>(color.blue()) / 255);
}
if (!soup->vcolors.empty())
{
CGAL::IO::Color vcolor = soup->vcolors[v2v[ffit.vertex(i)]];
v_colors.push_back(static_cast<float>(vcolor.red()) / 255);
v_colors.push_back(static_cast<float>(vcolor.green()) / 255);
v_colors.push_back(static_cast<float>(vcolor.blue()) / 255);
}
}
};

try {
FacetTriangulator<SMesh, EPICK, std::size_t> triangulation(pointIds, normal);
triangulation.per_face(f);
}
catch (...) {
FacetTriangulator<SMesh, EPICK, std::size_t, CGAL::Exact_intersections_tag> triangulation(pointIds, normal);
triangulation.per_face(f);
}
}

void
Scene_polygon_soup_item_priv::compute_normals_and_vertices() const{

Expand Down
39 changes: 21 additions & 18 deletions Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,26 +282,29 @@ Scene_polyhedron_selection_item_priv::triangulate_facet(fg_face_descriptor fit,c
const CGAL::qglviewer::Vec off = Three::mainViewer()->offset();
EPICK::Vector_3 offset(off.x,off.y,off.z);

typedef FacetTriangulator<Face_graph, EPICK, fg_vertex_descriptor> FT;
FT triangulation(fit,normal,poly, offset);
//iterates on the internal faces to add the vertices to the positions
//and the normals to the appropriate vectors
for(FT::CDT::Finite_faces_iterator
ffit = triangulation.cdt->finite_faces_begin(),
end = triangulation.cdt->finite_faces_end();
ffit != end; ++ffit)
{
if(ffit->info().is_external)
continue;
//iterates on the internal faces to add the vertices to the positions
//and the normals to the appropriate vectors
auto f = [&](auto& ffit, auto& /* v2v */) {
if (ffit.info().is_external)
return;

push_back_xyz(ffit->vertex(0)->point(), p_facets);
push_back_xyz(ffit->vertex(1)->point(), p_facets);
push_back_xyz(ffit->vertex(2)->point(), p_facets);
push_back_xyz(ffit.vertex(0)->point(), p_facets);
push_back_xyz(ffit.vertex(1)->point(), p_facets);
push_back_xyz(ffit.vertex(2)->point(), p_facets);

push_back_xyz(normal, p_normals);
push_back_xyz(normal, p_normals);
push_back_xyz(normal, p_normals);
}
push_back_xyz(normal, p_normals);
push_back_xyz(normal, p_normals);
push_back_xyz(normal, p_normals);
};

try {
FacetTriangulator<Face_graph, EPICK, fg_vertex_descriptor> triangulation(fit, normal, poly, offset);
triangulation.per_face(f);
}
catch (...) {
FacetTriangulator<Face_graph, EPICK, fg_vertex_descriptor, CGAL::Exact_intersections_tag> triangulation(fit, normal, poly, offset);
triangulation.per_face(f);
}
}


Expand Down
Loading