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

Polyhedron Demo: Add sampling plugin #7910

Merged
merged 8 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@
\example Polygon_mesh_processing/cc_compatible_orientations.cpp
\example Polygon_mesh_processing/remesh_planar_patches.cpp
\example Polygon_mesh_processing/remesh_almost_planar_patches.cpp
\example Polygon_mesh_processing/sample_example.cpp
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project(Polygon_mesh_processing_Examples)
# CGAL and its components
find_package(CGAL REQUIRED)

create_single_source_cgal_program("sample_example.cpp" )
create_single_source_cgal_program("extrude.cpp" )
create_single_source_cgal_program("polyhedral_envelope.cpp" )
create_single_source_cgal_program("polyhedral_envelope_of_triangle_soup.cpp" )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/distance.h>

#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/Point_set_3.h>
#include <iostream>
#include <string>
#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 Point;

typedef CGAL::Point_set_3<Point> Point_set;

typedef CGAL::Surface_mesh<Point> Mesh;
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;

namespace PMP = CGAL::Polygon_mesh_processing;

int main(int argc, char* argv[])
{
const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/eight.off");

Mesh mesh;
if(!PMP::IO::read_polygon_mesh(filename, mesh))
{
std::cerr << "Invalid input." << std::endl;
return 1;
}

const double points_per_face = (argc > 2) ? atof(argv[2]) : 10;

std::vector<Point> points;

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){
std::cout << p << std::endl;
}

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

std::cout << point_set.number_of_points() << std::endl;
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ target_link_libraries(
PUBLIC scene_surface_mesh_item scene_polygon_soup_item
scene_points_with_normal_item)

polyhedron_demo_plugin(point_set_from_sampling_plugin
Point_set_from_sampling_plugin)
target_link_libraries(
point_set_from_sampling_plugin
PUBLIC scene_surface_mesh_item scene_polygon_soup_item
scene_points_with_normal_item)

polyhedron_demo_plugin(diff_between_meshes_plugin Diff_between_meshes_plugin)
target_link_libraries(diff_between_meshes_plugin PUBLIC scene_surface_mesh_item)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include <QApplication>
#include <QAction>
#include <QList>
#include <QMainWindow>
#include <QMessageBox>
#include <QtDebug>
#include <QInputDialog>

#include "Scene_points_with_normal_item.h"
#include "Scene_surface_mesh_item.h"
#include "Scene_polygon_soup_item.h"

#include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
#include "Messages_interface.h"

#include <CGAL/Polygon_mesh_processing/distance.h>

using namespace CGAL::Three;
class Polyhedron_demo_point_set_from_sampling_plugin :
public QObject,
public Polyhedron_demo_plugin_interface
{
Q_OBJECT
Q_INTERFACES(CGAL::Three::Polyhedron_demo_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0")

public:
void init(QMainWindow* mainWindow,
CGAL::Three::Scene_interface* scene_interface, Messages_interface*);

bool applicable(QAction*) const {
const CGAL::Three::Scene_interface::Item_id index = scene->mainSelectionIndex();

return qobject_cast<Scene_surface_mesh_item*>(scene->item(index))
|| qobject_cast<Scene_polygon_soup_item*>(scene->item(index));
}

QList<QAction*> actions() const;

public Q_SLOTS:
void createPointSet();

private:
CGAL::Three::Scene_interface* scene;
QAction* actionPointSetFromSampling;


}; // end Polyhedron_demo_point_set_from_sampling_plugin

void Polyhedron_demo_point_set_from_sampling_plugin::init(QMainWindow* mainWindow,
CGAL::Three::Scene_interface* scene_interface,
Messages_interface*)
{
scene = scene_interface;
actionPointSetFromSampling = new QAction(tr("&Create Point Set from Sampling"), mainWindow);
afabri marked this conversation as resolved.
Show resolved Hide resolved
actionPointSetFromSampling->setObjectName("actionPointSetFromSampling");
connect(actionPointSetFromSampling, SIGNAL(triggered()),
this, SLOT(createPointSet()));
}

QList<QAction*> Polyhedron_demo_point_set_from_sampling_plugin::actions() const {
return QList<QAction*>() << actionPointSetFromSampling;
}



void Polyhedron_demo_point_set_from_sampling_plugin::createPointSet()
{
QApplication::setOverrideCursor(Qt::WaitCursor);
const CGAL::Three::Scene_interface::Item_id index = scene->mainSelectionIndex();

Scene_points_with_normal_item* points = new Scene_points_with_normal_item();


if (points){
points->setColor(Qt::blue);
}else{
return;
}
Scene_surface_mesh_item* sm_item =
qobject_cast<Scene_surface_mesh_item*>(scene->item(index));

if (sm_item){
int nf = num_faces(*sm_item->polyhedron());

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

points->setName(QString("%1 (sampled)").arg(sm_item->name()));
if( ok & (nb > 0)){
points->point_set()->reserve(nb);
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_polygon_soup_item* soup_item =
qobject_cast<Scene_polygon_soup_item*>(scene->item(index));

if (soup_item){
int nf = soup_item->polygons().size();

bool ok;
int nb = 0;
nb = QInputDialog::getInt(QApplication::activeWindow(), "Sampling",
"Enter 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)){
points->point_set()->reserve(nb);
CGAL::Polygon_mesh_processing::sample_triangle_soup(soup_item->points(),
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())
afabri marked this conversation as resolved.
Show resolved Hide resolved
.do_sample_vertices(false)
.do_sample_edges(false));
}
}

scene->addItem(points);
QApplication::restoreOverrideCursor();
}


#include "Point_set_from_sampling_plugin.moc"