Skip to content

Commit

Permalink
use regular inheritance (so in bindings functions from base class Mod…
Browse files Browse the repository at this point in the history
…el can be used); clean code
  • Loading branch information
LiangliangNan committed Jan 1, 2025
1 parent c573d40 commit 5dc5e01
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 170 deletions.
2 changes: 1 addition & 1 deletion easy3d/core/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace easy3d {
* https://opensource.cit-ec.de/projects/surface_mesh
*/

class Graph : public virtual Model
class Graph : public Model
{

public: //------------------------------------------------------ topology types
Expand Down
2 changes: 1 addition & 1 deletion easy3d/core/point_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace easy3d {
* This implementation is inspired by Surface_mesh
* https://opensource.cit-ec.de/projects/surface_mesh
*/
class PointCloud : public virtual Model
class PointCloud : public Model
{

public: //------------------------------------------------------ topology types
Expand Down
2 changes: 1 addition & 1 deletion easy3d/core/poly_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace easy3d {
* https://opensource.cit-ec.de/projects/surface_mesh
*/

class PolyMesh : public virtual Model
class PolyMesh : public Model
{

public: //------------------------------------------------------ topology types
Expand Down
2 changes: 1 addition & 1 deletion easy3d/core/surface_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace easy3d {
* \sa SurfaceMeshBuilder.
*/

class SurfaceMesh : public virtual Model
class SurfaceMesh : public Model
{

public: //------------------------------------------------------ topology types
Expand Down
2 changes: 1 addition & 1 deletion easy3d/util/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace easy3d {
#define EASY3D_VERSION_NR 1020504

/// Easy3D release date, in the format YYYYMMDD.
#define EASY3D_RELEASE_DATE 20241231
#define EASY3D_RELEASE_DATE 20250101


#endif // EASY3D_UTIL_VERSION_H
24 changes: 12 additions & 12 deletions python/bindings/easy3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
#include <pybind11/pybind11.h>


void bind_easy3d_core_vec(pybind11::module_ &m);
void bind_easy3d_core_box(pybind11::module_ &m);
void bind_easy3d_core_constant(pybind11::module_ &m);
void bind_easy3d_core_graph(pybind11::module_ &m);
void bind_easy3d_core_line(pybind11::module_ &m);
void bind_easy3d_core_quat(pybind11::module_ &m);
void bind_easy3d_core_random(pybind11::module_ &m);
void bind_easy3d_core_mat(pybind11::module_ &m);
void bind_easy3d_core_model(pybind11::module_ &m);
void bind_easy3d_core_plane(pybind11::module_ &m);
void bind_easy3d_core_types(pybind11::module_ &m);
void bind_easy3d_core_model(pybind11::module_ &m);
void bind_easy3d_core_property(pybind11::module_ &m);
void bind_easy3d_core_graph(pybind11::module_ &m);
void bind_easy3d_core_point_cloud(pybind11::module_ &m);
void bind_easy3d_core_poly_mesh(pybind11::module_ &m);
void bind_easy3d_core_property(pybind11::module_ &m);
void bind_easy3d_core_quat(pybind11::module_ &m);
void bind_easy3d_core_random(pybind11::module_ &m);
void bind_easy3d_core_surface_mesh(pybind11::module_ &m);
void bind_easy3d_core_surface_mesh_builder(pybind11::module_ &m);
void bind_easy3d_core_types(pybind11::module_ &m);
void bind_easy3d_core_vec(pybind11::module_ &m);

void bind_easy3d_algo_collider(pybind11::module_ &m);
void bind_easy3d_algo_delaunay(pybind11::module_ &m);
Expand Down Expand Up @@ -95,21 +95,21 @@ void bind_easy3d_video_video_encoder(pybind11::module_ &m);

// Submodule declarations
void bind_core(pybind11::module_ &m) {
bind_easy3d_core_vec(m);
bind_easy3d_core_box(m);
bind_easy3d_core_constant(m);
bind_easy3d_core_line(m);
bind_easy3d_core_mat(m);
bind_easy3d_core_plane(m);
bind_easy3d_core_property(m);
bind_easy3d_core_quat(m);
bind_easy3d_core_random(m);
bind_easy3d_core_mat(m);
bind_easy3d_core_plane(m);
bind_easy3d_core_types(m);
bind_easy3d_core_vec(m);

bind_easy3d_core_model(m);
bind_easy3d_core_property(m);
bind_easy3d_core_graph(m);
bind_easy3d_core_surface_mesh(m);
bind_easy3d_core_point_cloud(m);
bind_easy3d_core_surface_mesh(m);
bind_easy3d_core_poly_mesh(m);

bind_easy3d_core_surface_mesh_builder(m);
Expand Down
48 changes: 48 additions & 0 deletions python/bindings/easy3d/core/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,54 @@
PYBIND11_MAKE_OPAQUE(std::shared_ptr<void>)
#endif

//struct PyCallBack_easy3d_Model : public easy3d::Model {
// using easy3d::Model::Model; // Inherit constructors
//
// // Override pure virtual function `points()`
// std::vector<easy3d::vec3>& points() override {
// pybind11::gil_scoped_acquire gil;
// pybind11::function overload = pybind11::get_overload(static_cast<const easy3d::Model*>(this), "points");
// if (overload) {
// auto o = overload.operator()<pybind11::return_value_policy::reference>();
// if (pybind11::detail::cast_is_temporary_value_reference<std::vector<easy3d::vec3>&>::value) {
// static pybind11::detail::override_caster_t<std::vector<easy3d::vec3>&> caster;
// return pybind11::detail::cast_ref<std::vector<easy3d::vec3>&>(std::move(o), caster);
// }
// return pybind11::detail::cast_safe<std::vector<easy3d::vec3>&>(std::move(o));
// }
// pybind11::pybind11_fail("Tried to call pure virtual function \"Model::points\"");
// }
//
// const std::vector<easy3d::vec3>& points() const override {
// pybind11::gil_scoped_acquire gil;
// pybind11::function overload = pybind11::get_overload(static_cast<const easy3d::Model*>(this), "points");
// if (overload) {
// auto o = overload.operator()<pybind11::return_value_policy::reference>();
// if (pybind11::detail::cast_is_temporary_value_reference<const std::vector<easy3d::vec3>&>::value) {
// static pybind11::detail::override_caster_t<const std::vector<easy3d::vec3>&> caster;
// return pybind11::detail::cast_ref<const std::vector<easy3d::vec3>&>(std::move(o), caster);
// }
// return pybind11::detail::cast_safe<const std::vector<easy3d::vec3>&>(std::move(o));
// }
// pybind11::pybind11_fail("Tried to call pure virtual function \"Model::points\"");
// }
//
// void property_stats(std::ostream& output) const override {
// pybind11::gil_scoped_acquire gil;
// pybind11::function overload = pybind11::get_overload(static_cast<const easy3d::Model*>(this), "property_stats");
// if (overload) {
// auto o = overload.operator()<pybind11::return_value_policy::reference>(output);
// if (pybind11::detail::cast_is_temporary_value_reference<void>::value) {
// static pybind11::detail::override_caster_t<void> caster;
// return pybind11::detail::cast_ref<void>(std::move(o), caster);
// }
// return pybind11::detail::cast_safe<void>(std::move(o));
// }
// pybind11::pybind11_fail("Tried to call pure virtual function \"Model::property_stats\"");
// }
//
//};


void bind_easy3d_core_model(pybind11::module_& m)
{
Expand Down
77 changes: 7 additions & 70 deletions python/bindings/easy3d/viewer/multi_viewer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include <easy3d/core/vec.h>
#include <easy3d/core/point_cloud.h>
#include <easy3d/core/surface_mesh.h>
#include <easy3d/core/graph.h>
#include <easy3d/core/poly_mesh.h>
#include <easy3d/core/model.h>
#include <easy3d/renderer/camera.h>
#include <easy3d/renderer/drawable.h>
#include <easy3d/viewer/multi_viewer.h>
Expand Down Expand Up @@ -374,74 +371,14 @@ void bind_easy3d_viewer_multi_viewer(pybind11::module_& m)
cl.def( pybind11::init( [](int const & a0, int const & a1){ return new easy3d::MultiViewer(a0, a1); }, [](int const & a0, int const & a1){ return new PyCallBack_easy3d_MultiViewer(a0, a1); } ), "doc");
cl.def( pybind11::init<int, int, const std::string &>(), pybind11::arg("rows"), pybind11::arg("cols"), pybind11::arg("title") );

// cl.def( pybind11::init( [](PyCallBack_easy3d_MultiViewer const &o){ return new PyCallBack_easy3d_MultiViewer(o); } ) );
// cl.def( pybind11::init( [](easy3d::MultiViewer const &o){ return new easy3d::MultiViewer(o); } ) );

cl.def("add_model", [](easy3d::MultiViewer& self, const std::string& file_name, bool create_default_drawables = true)
{
return self.add_model(file_name, create_default_drawables);
},
pybind11::arg("file_name"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add a model from a file to the viewer.");
cl.def("add_model", [](easy3d::MultiViewer& self, std::shared_ptr<easy3d::PointCloud> point_cloud, bool create_default_drawables = true)
{
return self.add_model(point_cloud, create_default_drawables);
},
pybind11::arg("point_cloud"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add an existing point cloud to the viewer.");
cl.def("add_model", [](easy3d::MultiViewer& self, std::shared_ptr<easy3d::SurfaceMesh> surface_mesh, bool create_default_drawables = true)
{
return self.add_model(surface_mesh, create_default_drawables);
},
pybind11::arg("surface_mesh"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add an existing surface mesh to the viewer."
);
cl.def("add_model", [](easy3d::MultiViewer& self, std::shared_ptr<easy3d::Graph> graph, bool create_default_drawables = true)
{
return self.add_model(graph, create_default_drawables);
},
pybind11::arg("graph"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add an existing graph to the viewer."
);
cl.def("add_model", [](easy3d::MultiViewer& self, std::shared_ptr<easy3d::PolyMesh> poly_mesh, bool create_default_drawables = true)
{
return self.add_model(poly_mesh, create_default_drawables);
},
pybind11::arg("poly_mesh"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add an existing polyhedral mesh to the viewer."
);

// Assign Model to specific view (overloaded)
cl.def("assign", [](easy3d::MultiViewer &self, int row, int col, const easy3d::PointCloud *point_cloud) {
self.assign(row, col, point_cloud);
},
"Assign a point cloud to the view at position (row, col)",
pybind11::arg("row"), pybind11::arg("col"), pybind11::arg("point_cloud")
);
cl.def("assign", [](easy3d::MultiViewer &self, int row, int col, const easy3d::SurfaceMesh *surface_mesh) {
self.assign(row, col, surface_mesh);
},
"Assign a surface mesh to the view at position (row, col)",
pybind11::arg("row"), pybind11::arg("col"), pybind11::arg("surface_mesh")
);
cl.def("assign", [](easy3d::MultiViewer &self, int row, int col, const easy3d::PolyMesh *poly_mesh) {
self.assign(row, col, poly_mesh);
},
"Assign a polyhedral mesh to the view at position (row, col)",
pybind11::arg("row"), pybind11::arg("col"), pybind11::arg("poly_mesh")
);
cl.def("assign", [](easy3d::MultiViewer &self, int row, int col, const easy3d::Graph *graph) {
self.assign(row, col, graph);
// Assign a model to specific view
cl.def("assign", [](easy3d::MultiViewer &self, int row, int col, const easy3d::Model *model) {
self.assign(row, col, model);
},
"Assign a graph to the view at position (row, col)",
pybind11::arg("row"), pybind11::arg("col"), pybind11::arg("graph")
"Assign a model to the view at position (row, col)",
pybind11::arg("row"), pybind11::arg("col"), pybind11::arg("model")
);
// Assign Drawable to specific view (overloaded)
// Assign a drawable to specific view
cl.def("assign", [](easy3d::MultiViewer &self, int row, int col, const easy3d::Drawable *drawable) {
self.assign(row, col, drawable);
},
Expand Down
59 changes: 24 additions & 35 deletions python/bindings/easy3d/viewer/offscreen.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include <easy3d/core/vec.h>
#include <easy3d/core/model.h>
#include <easy3d/core/point_cloud.h>
#include <easy3d/core/surface_mesh.h>
#include <easy3d/core/graph.h>
#include <easy3d/core/poly_mesh.h>
#include <easy3d/renderer/drawable.h>
#include <easy3d/renderer/camera.h>
#include <easy3d/viewer/offscreen.h>
Expand Down Expand Up @@ -387,37 +383,30 @@ void bind_easy3d_viewer_offscreen(pybind11::module_& m)
pybind11::arg("file_name"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add a model from a file to the viewer.");
cl.def("add_model", [](easy3d::OffScreen& self, std::shared_ptr<easy3d::PointCloud> point_cloud, bool create_default_drawables = true)
{
return self.add_model(point_cloud, create_default_drawables);
},
pybind11::arg("point_cloud"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add an existing point cloud to the viewer.");
cl.def("add_model", [](easy3d::OffScreen& self, std::shared_ptr<easy3d::SurfaceMesh> surface_mesh, bool create_default_drawables = true)
{
return self.add_model(surface_mesh, create_default_drawables);
},
pybind11::arg("surface_mesh"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add an existing surface mesh to the viewer."
);
cl.def("add_model", [](easy3d::OffScreen& self, std::shared_ptr<easy3d::Graph> graph, bool create_default_drawables = true)
{
return self.add_model(graph, create_default_drawables);
},
pybind11::arg("graph"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add an existing graph to the viewer."
);
cl.def("add_model", [](easy3d::OffScreen& self, std::shared_ptr<easy3d::PolyMesh> poly_mesh, bool create_default_drawables = true)
{
return self.add_model(poly_mesh, create_default_drawables);
},
pybind11::arg("poly_mesh"), pybind11::arg("create_default_drawables") = true,
pybind11::return_value_policy::reference_internal,
"Add an existing polyhedral mesh to the viewer."
);

cl.def("add_model", [](easy3d::OffScreen &self, std::shared_ptr<easy3d::Model> model) {
return self.add_model(model); // Call the C++ function
}, pybind11::arg("model"),
pybind11::return_value_policy::automatic,
R"doc(
Add an existing model to the viewer to be visualized.
Parameters:
model (Model): The pointer to the model.
Returns:
Model: The pointer of the model added to the viewer.
)doc");

cl.def("add_drawable", [](easy3d::OffScreen &self, std::shared_ptr<easy3d::Drawable> drawable) {
return self.add_drawable(drawable); // Call the C++ function
}, pybind11::arg("drawable"),
pybind11::return_value_policy::automatic,
R"doc(
Add a drawable to the viewer to be visualized.
Parameters:
drawable (Drawable): The pointer to the drawable.
Returns:
Drawable: The pointer of the drawable added to the viewer.
)doc");

cl.def("camera", (class easy3d::Camera* (easy3d::OffScreen::*)()) &easy3d::OffScreen::camera, "Returns the camera used by the offscreen renderer", pybind11::return_value_policy::reference_internal);
cl.def("camera", (const class easy3d::Camera* (easy3d::OffScreen::*)() const) &easy3d::OffScreen::camera, "Returns the camera used by the offscreen renderer", pybind11::return_value_policy::reference_internal);
Expand Down
Loading

0 comments on commit 5dc5e01

Please sign in to comment.