Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Add winding check in map_mesh function.

### Changed

* Added meshpatter unify_cycles from COMPAS, LIBIGL has only triangle BFS.

### Removed


Expand All @@ -29,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Removed C++ aliases to minimum.

### Removed

* Removed all the types_std imports from the code. Instead type casters are used: https://nanobind.readthedocs.io/en/latest/exchanging.html .
Expand Down
2 changes: 0 additions & 2 deletions docs/examples/example_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,5 @@
for i in range(mesh.number_of_vertices()):
mesh_flattened.vertex_attributes(i, "xyz", [uv[i][0], uv[i][1], 0])

json_dump([Mesh.from_vertices_and_faces(pv, pf), mesh_mapped, mesh_mapped_offset, boundaries, mesh_flattened], "mesh_flattened.json")

viewer.scene.add(mesh_flattened, name="mesh_flattened")
viewer.show()
1 change: 0 additions & 1 deletion mesh_flattened.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/boundaries.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "boundaries.hpp"

compas::VectorVectorInt trimesh_boundaries( Eigen::Ref<const compas::RowMatrixXi> F) {
compas::VectorVectorInt L;
std::vector<std::vector<int>> trimesh_boundaries(Eigen::Ref<const compas::RowMatrixXi> F) {
std::vector<std::vector<int>> L;
igl::boundary_loop(F, L);
return L;
}
Expand Down
2 changes: 1 addition & 1 deletion src/boundaries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
*
* @note The input mesh should be manifold for correct results.
*/
compas::VectorVectorInt trimesh_boundaries(Eigen::Ref<const compas::RowMatrixXi> F);
std::vector<std::vector<int>> trimesh_boundaries(Eigen::Ref<const compas::RowMatrixXi> F);
33 changes: 8 additions & 25 deletions src/compas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,25 @@
#include <tuple>
#include <iomanip>

// Nanobind includes
// Nanobind type casters: https://nanobind.readthedocs.io/en/latest/exchanging.html
// If you want to bind a vector on your own, do not include compas.h, it will conflict with nanobind stl bindings.
#include <nanobind/nanobind.h>
#include <nanobind/eigen/dense.h>
#include <nanobind/eigen/sparse.h>
#include <nanobind/stl/tuple.h>
#include <nanobind/stl/vector.h>
#include <nanobind/stl/string.h>


// Avoid any alias via using, unless really needed:
namespace nb = nanobind;

using namespace nb::literals;

// Nanobind type casters: https://nanobind.readthedocs.io/en/latest/exchanging.html

namespace compas {
// Basic Eigen types with clear naming
// Row-major matrix types for better interoperability with Python numpy arrays
using RowMatrixXd = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
using RowMatrixXi = Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
using VectorXi = Eigen::VectorXi;
using VectorXd = Eigen::VectorXd;

// STL containers with descriptive names
using VectorInt = std::vector<int>;
using VectorFloat = std::vector<float>;
using VectorBool = std::vector<bool>;
using VectorVectorInt = std::vector<VectorInt>;

// Complex types with descriptive names
using TupleIntFloatFloatFloat = std::tuple<int, float, float, float>; // face_id, u, v, t
using VectorTupleIntFloatFloatFloat = std::vector<TupleIntFloatFloatFloat>;
using VectorVectorTupleIntFloatFloatFloat = std::vector<VectorTupleIntFloatFloatFloat>;

// Tuple types with descriptive names
using IsolinesResult = std::tuple<RowMatrixXd, RowMatrixXi, RowMatrixXi>; // vertices, edges, indices
using RemeshIsolineResult = std::tuple<RowMatrixXd, RowMatrixXi, VectorXi>; // vertices, faces, labels
using RemeshIsolinesResult = std::tuple<RowMatrixXd, RowMatrixXi, VectorXd, VectorXi>; // vertices, faces, scalar_values, face_groups
using PrincipalCurvatureResult = std::tuple<RowMatrixXd, RowMatrixXd, VectorXd, VectorXd>; // PD1, PD2, PV1, PV2
using MeshMapResult = std::tuple<RowMatrixXd, VectorVectorInt, RowMatrixXd, VectorBool, VectorInt>; // pattern_vertices, pattern_faces, pattern_normals, is_boundary, groups
// Vector types that maintain row-major storage for consistency
using RowVectorXd = Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor>;
using RowVectorXi = Eigen::Matrix<int, 1, Eigen::Dynamic, Eigen::RowMajor>;
}
12 changes: 6 additions & 6 deletions src/compas_libigl/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def map_mesh(target_mesh, pattern_mesh, clip_boundaries=True, simplify_borders=T

Returns
-------
tuple[ndarray, VectorVectorInt, ndarray, VectorBool, VectorInt]
tuple[np.array, list[list[int]], np.array, list[bool], list[int]]
A tuple containing:

* vertices: ndarray - The 3D coordinates of the mapped mesh vertices
* faces: VectorVectorInt - The faces of the mapped mesh
* normals: ndarray - The normal vectors at each vertex
* boundary_flags: VectorBool - Boolean flags indicating if vertices are on the boundary
* polygon_groups: VectorInt - Grouping indices for polygons (to form holes)
* vertices: np.array - The 3D coordinates of the mapped mesh vertices
* faces: list[list[int]] - The faces of the mapped mesh
* normals: np.array - The normal vectors at each vertex
* boundary_flags: list[bool] - Boolean flags indicating if vertices are on the boundary
* polygon_groups: list[int] - Grouping indices for polygons (to form holes)
"""
# Unpack mesh tuples
v, f = target_mesh
Expand Down
11 changes: 7 additions & 4 deletions src/curvature.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#include "curvature.hpp"


compas::PrincipalCurvatureResult
std::tuple<compas::RowMatrixXd,
compas::RowMatrixXd,
Eigen::VectorXd,
Eigen::VectorXd>
trimesh_principal_curvature(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F,
int radius
) {
compas::RowMatrixXd PD1, PD2;
compas::VectorXd PV1, PV2;
Eigen::VectorXd PV1, PV2;
igl::principal_curvature(V, F, PD1, PD2, PV1, PV2, radius);
return std::make_tuple(PD1, PD2, PV1, PV2);
}

compas::VectorXd
Eigen::VectorXd
trimesh_gaussian_curvature(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F
) {
compas::VectorXd K;
Eigen::VectorXd K;
igl::gaussian_curvature(V, F, K);
return K;
}
Expand Down
7 changes: 5 additions & 2 deletions src/curvature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param F The face matrix of the triangle mesh (m x 3).
* @return A vector of gaussian curvature values per vertex.
*/
compas::VectorXd trimesh_gaussian_curvature(
Eigen::VectorXd trimesh_gaussian_curvature(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F
);
Expand All @@ -29,7 +29,10 @@ compas::VectorXd trimesh_gaussian_curvature(
* - PV1: principal curvature 1 per vertex (n x 1)
* - PV2: principal curvature 2 per vertex (n x 1)
*/
compas::PrincipalCurvatureResult
std::tuple<compas::RowMatrixXd,
compas::RowMatrixXd,
Eigen::VectorXd,
Eigen::VectorXd>
trimesh_principal_curvature(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F,
Expand Down
18 changes: 9 additions & 9 deletions src/geodistance.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "geodistance.hpp"

// Main entry points
compas::VectorXd trimesh_geodistance(
Eigen::VectorXd trimesh_geodistance(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F,
int source,
const std::string& method
) {
compas::VectorXi sources(1);
Eigen::VectorXi sources(1);
sources << source;

if (method == "exact") {
Expand All @@ -19,10 +19,10 @@ compas::VectorXd trimesh_geodistance(
throw std::runtime_error("Unknown method: " + method);
}

compas::VectorXd trimesh_geodistance_multiple(
Eigen::VectorXd trimesh_geodistance_multiple(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F,
Eigen::Ref<const compas::VectorXi> sources,
Eigen::Ref<const Eigen::VectorXi> sources,
const std::string& method
) {
if (sources.size() == 0) {
Expand Down Expand Up @@ -57,13 +57,13 @@ compas::VectorXd trimesh_geodistance_multiple(
}

// Implementation details
compas::VectorXd trimesh_geodistance_exact(
Eigen::VectorXd trimesh_geodistance_exact(
const compas::RowMatrixXd& V,
const compas::RowMatrixXi& F,
int vid)
{
compas::VectorXd D;
compas::VectorXi VS, FS, VT, FT;
Eigen::VectorXd D;
Eigen::VectorXi VS, FS, VT, FT;

VS.resize(1);
VS << vid;
Expand All @@ -75,12 +75,12 @@ compas::VectorXd trimesh_geodistance_exact(
return D;
}

compas::VectorXd trimesh_geodistance_heat(
Eigen::VectorXd trimesh_geodistance_heat(
const compas::RowMatrixXd& V,
const compas::RowMatrixXi& F,
int vid)
{
compas::VectorXi gamma;
Eigen::VectorXi gamma;
gamma.resize(1);
gamma << vid;

Expand Down
10 changes: 5 additions & 5 deletions src/geodistance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
/**
* Helper function to compute exact geodesic distances.
*/
compas::VectorXd trimesh_geodistance_exact(
Eigen::VectorXd trimesh_geodistance_exact(
const compas::RowMatrixXd& V,
const compas::RowMatrixXi& F,
int vid);

/**
* Helper function to compute heat method geodesic distances.
*/
compas::VectorXd trimesh_geodistance_heat(
Eigen::VectorXd trimesh_geodistance_heat(
const compas::RowMatrixXd& V,
const compas::RowMatrixXi& F,
int vid);
Expand All @@ -31,7 +31,7 @@ compas::VectorXd trimesh_geodistance_heat(
* @param method Method to use: "exact" or "heat".
* @return Vector of geodesic distances from source to all vertices.
*/
compas::VectorXd trimesh_geodistance(
Eigen::VectorXd trimesh_geodistance(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F,
int source,
Expand All @@ -47,9 +47,9 @@ compas::VectorXd trimesh_geodistance(
* @param method Method to use: "exact" or "heat".
* @return Vector of minimum geodesic distances from any source to all vertices.
*/
compas::VectorXd trimesh_geodistance_multiple(
Eigen::VectorXd trimesh_geodistance_multiple(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F,
Eigen::Ref<const compas::VectorXi> sources,
Eigen::Ref<const Eigen::VectorXi> sources,
const std::string& method
);
4 changes: 2 additions & 2 deletions src/intersections.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "intersections.hpp"

compas::VectorTupleIntFloatFloatFloat intersection_ray_mesh(const Eigen::Vector3d& point, const Eigen::Vector3d& direction,
std::vector<std::tuple<int, float, float, float>> intersection_ray_mesh(const Eigen::Vector3d& point, const Eigen::Vector3d& direction,
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F) {

Expand All @@ -18,7 +18,7 @@ compas::VectorTupleIntFloatFloatFloat intersection_ray_mesh(const Eigen::Vector3
return hits;
}

compas::VectorVectorTupleIntFloatFloatFloat intersection_rays_mesh(Eigen::Ref<const compas::RowMatrixXd> points,
std::vector<std::vector<std::tuple<int, float, float, float>>> intersection_rays_mesh(Eigen::Ref<const compas::RowMatrixXd> points,
Eigen::Ref<const compas::RowMatrixXd> directions,
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F) {
Expand Down
4 changes: 2 additions & 2 deletions src/intersections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* - u, v: barycentric coordinates of hit point
* - t: ray parameter at intersection
*/
compas::VectorTupleIntFloatFloatFloat intersection_ray_mesh(
std::vector<std::tuple<int, float, float, float>> intersection_ray_mesh(
const Eigen::Vector3d& point,
const Eigen::Vector3d& direction,
Eigen::Ref<const compas::RowMatrixXd> V,
Expand All @@ -32,7 +32,7 @@
* @param F #F x 3 matrix of triangle indices
* @return Vector of intersection hits per ray, each hit containing (face_id, u, v, t)
*/
compas::VectorVectorTupleIntFloatFloatFloat intersection_rays_mesh(
std::vector<std::vector<std::tuple<int, float, float, float>>> intersection_rays_mesh(
Eigen::Ref<const compas::RowMatrixXd> points,
Eigen::Ref<const compas::RowMatrixXd> directions,
Eigen::Ref<const compas::RowMatrixXd> V,
Expand Down
4 changes: 3 additions & 1 deletion src/isolines.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "isolines.hpp"

compas::IsolinesResult trimesh_isolines(
std::tuple<compas::RowMatrixXd,
compas::RowMatrixXi,
Eigen::VectorXi> trimesh_isolines(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F,
Eigen::Ref<const Eigen::VectorXd> isovalues,
Expand Down
4 changes: 3 additions & 1 deletion src/isolines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace compas_libigl {
* @param vals The isovalues at which to compute isolines.
* @return Tuple of (vertices, edges, indices) defining the isolines.
*/
compas::IsolinesResult trimesh_isolines(
std::tuple<compas::RowMatrixXd,
compas::RowMatrixXi,
Eigen::VectorXi> trimesh_isolines(
Eigen::Ref<const compas::RowMatrixXd> V,
Eigen::Ref<const compas::RowMatrixXi> F,
Eigen::Ref<const Eigen::VectorXd> isovalues,
Expand Down
Loading
Loading