Skip to content

Commit 1b56f92

Browse files
Merge pull request #33 from petrasvestartas/alias_and_unify_cycles
CHANGE aliases and unify_cycles.
2 parents eb76c80 + 765c75c commit 1b56f92

19 files changed

+123
-107
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
### Added
2020

21+
* Add winding check in map_mesh function.
22+
2123
### Changed
2224

25+
* Added meshpatter unify_cycles from COMPAS, LIBIGL has only triangle BFS.
26+
2327
### Removed
2428

2529

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

3034
### Changed
3135

36+
* Removed C++ aliases to minimum.
37+
3238
### Removed
3339

3440
* Removed all the types_std imports from the code. Instead type casters are used: https://nanobind.readthedocs.io/en/latest/exchanging.html .

docs/examples/example_mapping.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,5 @@
102102
for i in range(mesh.number_of_vertices()):
103103
mesh_flattened.vertex_attributes(i, "xyz", [uv[i][0], uv[i][1], 0])
104104

105-
json_dump([Mesh.from_vertices_and_faces(pv, pf), mesh_mapped, mesh_mapped_offset, boundaries, mesh_flattened], "mesh_flattened.json")
106-
107105
viewer.scene.add(mesh_flattened, name="mesh_flattened")
108106
viewer.show()

mesh_flattened.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/boundaries.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "boundaries.hpp"
22

3-
compas::VectorVectorInt trimesh_boundaries( Eigen::Ref<const compas::RowMatrixXi> F) {
4-
compas::VectorVectorInt L;
3+
std::vector<std::vector<int>> trimesh_boundaries(Eigen::Ref<const compas::RowMatrixXi> F) {
4+
std::vector<std::vector<int>> L;
55
igl::boundary_loop(F, L);
66
return L;
77
}

src/boundaries.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
*
1212
* @note The input mesh should be manifold for correct results.
1313
*/
14-
compas::VectorVectorInt trimesh_boundaries(Eigen::Ref<const compas::RowMatrixXi> F);
14+
std::vector<std::vector<int>> trimesh_boundaries(Eigen::Ref<const compas::RowMatrixXi> F);

src/compas.hpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,25 @@
1515
#include <tuple>
1616
#include <iomanip>
1717

18-
// Nanobind includes
18+
// Nanobind type casters: https://nanobind.readthedocs.io/en/latest/exchanging.html
19+
// If you want to bind a vector on your own, do not include compas.h, it will conflict with nanobind stl bindings.
1920
#include <nanobind/nanobind.h>
2021
#include <nanobind/eigen/dense.h>
2122
#include <nanobind/eigen/sparse.h>
2223
#include <nanobind/stl/tuple.h>
2324
#include <nanobind/stl/vector.h>
2425
#include <nanobind/stl/string.h>
25-
26+
27+
// Avoid any alias via using, unless really needed:
2628
namespace nb = nanobind;
27-
2829
using namespace nb::literals;
2930

30-
// Nanobind type casters: https://nanobind.readthedocs.io/en/latest/exchanging.html
31-
3231
namespace compas {
33-
// Basic Eigen types with clear naming
32+
// Row-major matrix types for better interoperability with Python numpy arrays
3433
using RowMatrixXd = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
3534
using RowMatrixXi = Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
36-
using VectorXi = Eigen::VectorXi;
37-
using VectorXd = Eigen::VectorXd;
38-
39-
// STL containers with descriptive names
40-
using VectorInt = std::vector<int>;
41-
using VectorFloat = std::vector<float>;
42-
using VectorBool = std::vector<bool>;
43-
using VectorVectorInt = std::vector<VectorInt>;
44-
45-
// Complex types with descriptive names
46-
using TupleIntFloatFloatFloat = std::tuple<int, float, float, float>; // face_id, u, v, t
47-
using VectorTupleIntFloatFloatFloat = std::vector<TupleIntFloatFloatFloat>;
48-
using VectorVectorTupleIntFloatFloatFloat = std::vector<VectorTupleIntFloatFloatFloat>;
4935

50-
// Tuple types with descriptive names
51-
using IsolinesResult = std::tuple<RowMatrixXd, RowMatrixXi, RowMatrixXi>; // vertices, edges, indices
52-
using RemeshIsolineResult = std::tuple<RowMatrixXd, RowMatrixXi, VectorXi>; // vertices, faces, labels
53-
using RemeshIsolinesResult = std::tuple<RowMatrixXd, RowMatrixXi, VectorXd, VectorXi>; // vertices, faces, scalar_values, face_groups
54-
using PrincipalCurvatureResult = std::tuple<RowMatrixXd, RowMatrixXd, VectorXd, VectorXd>; // PD1, PD2, PV1, PV2
55-
using MeshMapResult = std::tuple<RowMatrixXd, VectorVectorInt, RowMatrixXd, VectorBool, VectorInt>; // pattern_vertices, pattern_faces, pattern_normals, is_boundary, groups
36+
// Vector types that maintain row-major storage for consistency
37+
using RowVectorXd = Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor>;
38+
using RowVectorXi = Eigen::Matrix<int, 1, Eigen::Dynamic, Eigen::RowMajor>;
5639
}

src/compas_libigl/mapping.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def map_mesh(target_mesh, pattern_mesh, clip_boundaries=True, simplify_borders=T
6969
7070
Returns
7171
-------
72-
tuple[ndarray, VectorVectorInt, ndarray, VectorBool, VectorInt]
72+
tuple[np.array, list[list[int]], np.array, list[bool], list[int]]
7373
A tuple containing:
7474
75-
* vertices: ndarray - The 3D coordinates of the mapped mesh vertices
76-
* faces: VectorVectorInt - The faces of the mapped mesh
77-
* normals: ndarray - The normal vectors at each vertex
78-
* boundary_flags: VectorBool - Boolean flags indicating if vertices are on the boundary
79-
* polygon_groups: VectorInt - Grouping indices for polygons (to form holes)
75+
* vertices: np.array - The 3D coordinates of the mapped mesh vertices
76+
* faces: list[list[int]] - The faces of the mapped mesh
77+
* normals: np.array - The normal vectors at each vertex
78+
* boundary_flags: list[bool] - Boolean flags indicating if vertices are on the boundary
79+
* polygon_groups: list[int] - Grouping indices for polygons (to form holes)
8080
"""
8181
# Unpack mesh tuples
8282
v, f = target_mesh

src/curvature.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
#include "curvature.hpp"
22

33

4-
compas::PrincipalCurvatureResult
4+
std::tuple<compas::RowMatrixXd,
5+
compas::RowMatrixXd,
6+
Eigen::VectorXd,
7+
Eigen::VectorXd>
58
trimesh_principal_curvature(
69
Eigen::Ref<const compas::RowMatrixXd> V,
710
Eigen::Ref<const compas::RowMatrixXi> F,
811
int radius
912
) {
1013
compas::RowMatrixXd PD1, PD2;
11-
compas::VectorXd PV1, PV2;
14+
Eigen::VectorXd PV1, PV2;
1215
igl::principal_curvature(V, F, PD1, PD2, PV1, PV2, radius);
1316
return std::make_tuple(PD1, PD2, PV1, PV2);
1417
}
1518

16-
compas::VectorXd
19+
Eigen::VectorXd
1720
trimesh_gaussian_curvature(
1821
Eigen::Ref<const compas::RowMatrixXd> V,
1922
Eigen::Ref<const compas::RowMatrixXi> F
2023
) {
21-
compas::VectorXd K;
24+
Eigen::VectorXd K;
2225
igl::gaussian_curvature(V, F, K);
2326
return K;
2427
}

src/curvature.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @param F The face matrix of the triangle mesh (m x 3).
1313
* @return A vector of gaussian curvature values per vertex.
1414
*/
15-
compas::VectorXd trimesh_gaussian_curvature(
15+
Eigen::VectorXd trimesh_gaussian_curvature(
1616
Eigen::Ref<const compas::RowMatrixXd> V,
1717
Eigen::Ref<const compas::RowMatrixXi> F
1818
);
@@ -29,7 +29,10 @@ compas::VectorXd trimesh_gaussian_curvature(
2929
* - PV1: principal curvature 1 per vertex (n x 1)
3030
* - PV2: principal curvature 2 per vertex (n x 1)
3131
*/
32-
compas::PrincipalCurvatureResult
32+
std::tuple<compas::RowMatrixXd,
33+
compas::RowMatrixXd,
34+
Eigen::VectorXd,
35+
Eigen::VectorXd>
3336
trimesh_principal_curvature(
3437
Eigen::Ref<const compas::RowMatrixXd> V,
3538
Eigen::Ref<const compas::RowMatrixXi> F,

src/geodistance.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "geodistance.hpp"
22

33
// Main entry points
4-
compas::VectorXd trimesh_geodistance(
4+
Eigen::VectorXd trimesh_geodistance(
55
Eigen::Ref<const compas::RowMatrixXd> V,
66
Eigen::Ref<const compas::RowMatrixXi> F,
77
int source,
88
const std::string& method
99
) {
10-
compas::VectorXi sources(1);
10+
Eigen::VectorXi sources(1);
1111
sources << source;
1212

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

22-
compas::VectorXd trimesh_geodistance_multiple(
22+
Eigen::VectorXd trimesh_geodistance_multiple(
2323
Eigen::Ref<const compas::RowMatrixXd> V,
2424
Eigen::Ref<const compas::RowMatrixXi> F,
25-
Eigen::Ref<const compas::VectorXi> sources,
25+
Eigen::Ref<const Eigen::VectorXi> sources,
2626
const std::string& method
2727
) {
2828
if (sources.size() == 0) {
@@ -57,13 +57,13 @@ compas::VectorXd trimesh_geodistance_multiple(
5757
}
5858

5959
// Implementation details
60-
compas::VectorXd trimesh_geodistance_exact(
60+
Eigen::VectorXd trimesh_geodistance_exact(
6161
const compas::RowMatrixXd& V,
6262
const compas::RowMatrixXi& F,
6363
int vid)
6464
{
65-
compas::VectorXd D;
66-
compas::VectorXi VS, FS, VT, FT;
65+
Eigen::VectorXd D;
66+
Eigen::VectorXi VS, FS, VT, FT;
6767

6868
VS.resize(1);
6969
VS << vid;
@@ -75,12 +75,12 @@ compas::VectorXd trimesh_geodistance_exact(
7575
return D;
7676
}
7777

78-
compas::VectorXd trimesh_geodistance_heat(
78+
Eigen::VectorXd trimesh_geodistance_heat(
7979
const compas::RowMatrixXd& V,
8080
const compas::RowMatrixXi& F,
8181
int vid)
8282
{
83-
compas::VectorXi gamma;
83+
Eigen::VectorXi gamma;
8484
gamma.resize(1);
8585
gamma << vid;
8686

src/geodistance.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
/**
1010
* Helper function to compute exact geodesic distances.
1111
*/
12-
compas::VectorXd trimesh_geodistance_exact(
12+
Eigen::VectorXd trimesh_geodistance_exact(
1313
const compas::RowMatrixXd& V,
1414
const compas::RowMatrixXi& F,
1515
int vid);
1616

1717
/**
1818
* Helper function to compute heat method geodesic distances.
1919
*/
20-
compas::VectorXd trimesh_geodistance_heat(
20+
Eigen::VectorXd trimesh_geodistance_heat(
2121
const compas::RowMatrixXd& V,
2222
const compas::RowMatrixXi& F,
2323
int vid);
@@ -31,7 +31,7 @@ compas::VectorXd trimesh_geodistance_heat(
3131
* @param method Method to use: "exact" or "heat".
3232
* @return Vector of geodesic distances from source to all vertices.
3333
*/
34-
compas::VectorXd trimesh_geodistance(
34+
Eigen::VectorXd trimesh_geodistance(
3535
Eigen::Ref<const compas::RowMatrixXd> V,
3636
Eigen::Ref<const compas::RowMatrixXi> F,
3737
int source,
@@ -47,9 +47,9 @@ compas::VectorXd trimesh_geodistance(
4747
* @param method Method to use: "exact" or "heat".
4848
* @return Vector of minimum geodesic distances from any source to all vertices.
4949
*/
50-
compas::VectorXd trimesh_geodistance_multiple(
50+
Eigen::VectorXd trimesh_geodistance_multiple(
5151
Eigen::Ref<const compas::RowMatrixXd> V,
5252
Eigen::Ref<const compas::RowMatrixXi> F,
53-
Eigen::Ref<const compas::VectorXi> sources,
53+
Eigen::Ref<const Eigen::VectorXi> sources,
5454
const std::string& method
5555
);

src/intersections.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "intersections.hpp"
22

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

@@ -18,7 +18,7 @@ compas::VectorTupleIntFloatFloatFloat intersection_ray_mesh(const Eigen::Vector3
1818
return hits;
1919
}
2020

21-
compas::VectorVectorTupleIntFloatFloatFloat intersection_rays_mesh(Eigen::Ref<const compas::RowMatrixXd> points,
21+
std::vector<std::vector<std::tuple<int, float, float, float>>> intersection_rays_mesh(Eigen::Ref<const compas::RowMatrixXd> points,
2222
Eigen::Ref<const compas::RowMatrixXd> directions,
2323
Eigen::Ref<const compas::RowMatrixXd> V,
2424
Eigen::Ref<const compas::RowMatrixXi> F) {

src/intersections.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* - u, v: barycentric coordinates of hit point
1818
* - t: ray parameter at intersection
1919
*/
20-
compas::VectorTupleIntFloatFloatFloat intersection_ray_mesh(
20+
std::vector<std::tuple<int, float, float, float>> intersection_ray_mesh(
2121
const Eigen::Vector3d& point,
2222
const Eigen::Vector3d& direction,
2323
Eigen::Ref<const compas::RowMatrixXd> V,
@@ -32,7 +32,7 @@
3232
* @param F #F x 3 matrix of triangle indices
3333
* @return Vector of intersection hits per ray, each hit containing (face_id, u, v, t)
3434
*/
35-
compas::VectorVectorTupleIntFloatFloatFloat intersection_rays_mesh(
35+
std::vector<std::vector<std::tuple<int, float, float, float>>> intersection_rays_mesh(
3636
Eigen::Ref<const compas::RowMatrixXd> points,
3737
Eigen::Ref<const compas::RowMatrixXd> directions,
3838
Eigen::Ref<const compas::RowMatrixXd> V,

src/isolines.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "isolines.hpp"
22

3-
compas::IsolinesResult trimesh_isolines(
3+
std::tuple<compas::RowMatrixXd,
4+
compas::RowMatrixXi,
5+
Eigen::VectorXi> trimesh_isolines(
46
Eigen::Ref<const compas::RowMatrixXd> V,
57
Eigen::Ref<const compas::RowMatrixXi> F,
68
Eigen::Ref<const Eigen::VectorXd> isovalues,

src/isolines.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ namespace compas_libigl {
1515
* @param vals The isovalues at which to compute isolines.
1616
* @return Tuple of (vertices, edges, indices) defining the isolines.
1717
*/
18-
compas::IsolinesResult trimesh_isolines(
18+
std::tuple<compas::RowMatrixXd,
19+
compas::RowMatrixXi,
20+
Eigen::VectorXi> trimesh_isolines(
1921
Eigen::Ref<const compas::RowMatrixXd> V,
2022
Eigen::Ref<const compas::RowMatrixXi> F,
2123
Eigen::Ref<const Eigen::VectorXd> isovalues,

0 commit comments

Comments
 (0)