Skip to content

Commit

Permalink
Add check that it faces are triangles
Browse files Browse the repository at this point in the history
  • Loading branch information
afabri committed Dec 12, 2023
1 parent 796188e commit 62a64ae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ int main(int argc, char* argv[])

std::vector<Point> points;

PMP::sample_triangle_mesh(mesh, std::back_inserter(points), CGAL::parameters::number_of_points_per_face(points_per_face));
PMP::sample_triangle_mesh(mesh,
std::back_inserter(points),
CGAL::parameters::number_of_points_per_face(points_per_face));

std::cout.precision(17);
for(const Point& p : points){
Expand All @@ -43,8 +45,7 @@ int main(int argc, char* argv[])

Point_set point_set;
PMP::sample_triangle_mesh(mesh,
point_set.point_back_inserter(),
CGAL::parameters::point_map(point_set.point_push_map()));
point_set.point_back_inserter());

std::cout << point_set.number_of_points() << std::endl;
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ struct Triangle_structure_sampler_for_triangle_soup
* @tparam TriangleMesh a model of the concepts `EdgeListGraph` and `FaceListGraph`
* @tparam PointOutputIterator a model of `OutputIterator`
* holding objects of the same point type as
* the value type of the point type associated to the mesh `tm`, i.e. the value type of the vertex
* the value type of the point type associated to the mesh `tm`, i.e., the value type of the vertex
* point map property map, if provided, or the value type of the internal point property map otherwise
* @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
*
Expand Down Expand Up @@ -1570,7 +1570,7 @@ bounded_error_squared_Hausdorff_distance_impl(const TriangleMesh1& tm1,
candidate_triangles.pop();

// Only process the triangle if it can contribute to the Hausdorff distance,
// i.e. if its upper bound is higher than the currently known best lower bound
// i.e., if its upper bound is higher than the currently known best lower bound
// and the difference between the bounds to be obtained is larger than the
// user-given error.
const auto& triangle_bounds = triangle_and_bounds.bounds;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

#include <CGAL/Three/Three.h>
#include <QApplication>
#include <QAction>
#include <QList>
Expand All @@ -14,6 +16,7 @@
#include "Messages_interface.h"

#include <CGAL/Polygon_mesh_processing/distance.h>
#include <CGAL/boost/graph/helpers.h>

using namespace CGAL::Three;
class Polyhedron_demo_point_set_from_sampling_plugin :
Expand Down Expand Up @@ -52,7 +55,7 @@ void Polyhedron_demo_point_set_from_sampling_plugin::init(QMainWindow* mainWindo
Messages_interface*)
{
scene = scene_interface;
actionPointSetFromSampling = new QAction(tr("&Create Point Set from Sampling"), mainWindow);
actionPointSetFromSampling = new QAction(tr("Create Point Set from Sampling"), mainWindow);
actionPointSetFromSampling->setObjectName("actionPointSetFromSampling");
connect(actionPointSetFromSampling, SIGNAL(triggered()),
this, SLOT(createPointSet()));
Expand All @@ -75,18 +78,24 @@ void Polyhedron_demo_point_set_from_sampling_plugin::createPointSet()
if (points){
points->setColor(Qt::blue);
}else{
QApplication::restoreOverrideCursor();
return;
}
Scene_surface_mesh_item* sm_item =
qobject_cast<Scene_surface_mesh_item*>(scene->item(index));

if (sm_item){
if(! CGAL::is_triangle_mesh(*sm_item->polyhedron())){
CGAL::Three::Three::error(QString("The mesh must have triangle faces"));
QApplication::restoreOverrideCursor();
return;
}
int nf = num_faces(*sm_item->polyhedron());

bool ok;
int nb = 0;
nb = QInputDialog::getInt(QApplication::activeWindow(), "Sampling",
"Enter number of sample points:",
"Number of sample points:",
nf , 0, (std::numeric_limits<int>::max)(), 1, &ok);

points->setName(QString("%1 (sampled)").arg(sm_item->name()));
Expand All @@ -95,9 +104,9 @@ void Polyhedron_demo_point_set_from_sampling_plugin::createPointSet()
CGAL::Polygon_mesh_processing::sample_triangle_mesh(*sm_item->polyhedron(),
points->point_set()->point_back_inserter(),
CGAL::parameters::number_of_points_on_faces(nb)
.point_map(points->point_set()->point_push_map())
.do_sample_vertices(false)
.do_sample_edges(false));
scene->addItem(points);
}
}

Expand All @@ -107,10 +116,18 @@ void Polyhedron_demo_point_set_from_sampling_plugin::createPointSet()
if (soup_item){
int nf = soup_item->polygons().size();

for(const auto& f : soup_item->polygons()){
if(f.size() != 3){
CGAL::Three::Three::error(QString("The polygons must be triangles"));
QApplication::restoreOverrideCursor();
return;
}
}

bool ok;
int nb = 0;
nb = QInputDialog::getInt(QApplication::activeWindow(), "Sampling",
"Enter number of sample points:",
"Number of sample points:",
nf , 0, (std::numeric_limits<int>::max)(), 1, &ok);
points->setName(QString("%1 (sampled)").arg(soup_item->name()));
if( ok & (nb > 0)){
Expand All @@ -119,13 +136,13 @@ void Polyhedron_demo_point_set_from_sampling_plugin::createPointSet()
soup_item->polygons(),
points->point_set()->point_back_inserter(),
CGAL::parameters::number_of_points_on_faces(nb)
.point_map(points->point_set()->point_push_map())
.do_sample_vertices(false)
.do_sample_edges(false));
scene->addItem(points);
}
}

scene->addItem(points);

QApplication::restoreOverrideCursor();
}

Expand Down

0 comments on commit 62a64ae

Please sign in to comment.