Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Jan 15, 2024
2 parents 88fd0b7 + 9f5d147 commit 077f851
Show file tree
Hide file tree
Showing 25 changed files with 10,580 additions and 129 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

## [0.5.0] 2024-01-10

### Added

### Changed
* The main include types like `Point`, `Vector`, `Polyline` and etc. are placed to the `compas` namespace because these names are very generic. For example if you want to run CGAL normal estimation, you get a clash with Windows Polyline class (the same name).

### Removed


## [0.5.0] 2022-10-07

Expand Down
10,011 changes: 10,011 additions & 0 deletions data/box.ply

Large diffs are not rendered by default.

Binary file added docs/_images/cgal_pointset_normal_estimation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/cgal_pointset_reduction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/cgal_pointset_smoothing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions docs/examples/pointset_reduction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from pathlib import Path
from compas.geometry import Pointcloud, Translation
from compas_view2.app import App
from compas_cgal.reconstruction import pointset_reduction

# Define the file path for the point cloud data
FILE = Path(__file__).parent.parent.parent / "data" / "forked_branch_1.ply"

# Load the original point cloud
original_points = Pointcloud.from_ply(FILE)

# Create a copy of the point cloud for processing
cloud = Pointcloud.from_ply(FILE)

# Translate the original point cloud
cloud.transform(Translation.from_vector([-1000, 0, 0]))

# Apply point set reduction to the translated point cloud
points = pointset_reduction(cloud, 50)
print(f"Original points: {len(cloud)}, Reduced points: {len(points)}")

# Initialize the COMPAS viewer
viewer = App(width=1600, height=900)

# Adjust viewer settings
viewer.view.camera.scale = 1000
viewer.view.grid.cell_size = 1000

# Add the reduced point cloud and the original point cloud to the viewer
viewer.add(Pointcloud(points))
viewer.add(Pointcloud(original_points))

# Set the camera to zoom to fit all points
viewer.view.camera.zoom_extents()

# Run the viewer
viewer.run()
11 changes: 11 additions & 0 deletions docs/examples/pointset_reduction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
********************************************************************************
Pointset Reduction
********************************************************************************

.. figure:: /_images/cgal_pointset_reduction.png
:figclass: figure
:class: figure-img img-fluid


.. literalinclude:: pointset_reduction.py
:language: python
51 changes: 51 additions & 0 deletions docs/examples/pointsets_normals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from pathlib import Path
from compas.geometry import Pointcloud, Point, Line
from compas_view2.app import App
from compas_view2.collections import Collection
from compas.colors import Color
from compas_cgal.reconstruction import pointset_normal_estimation

# Define the file path for the point cloud data
FILE = Path(__file__).parent.parent.parent / "data" / "forked_branch_1.ply"

# Load the point cloud data from the PLY file
cloud = Pointcloud.from_ply(FILE)

# Estimate normals for the point cloud
points, vectors = pointset_normal_estimation(cloud, 16, True)
print(f"Original points: {len(cloud)}, Points with normals: {len(points)}, Vectors: {len(vectors)}")

# Create lines and properties for visualizing normals
lines = []
line_properties = []
line_scale = 25

# Iterate over points and vectors to create lines and color properties
for p, v in zip(points, vectors):
lines.append(Line(Point(p[0], p[1], p[2]), Point(p[0] + v[0] * line_scale, p[1] + v[1] * line_scale, p[2] + v[2] * line_scale)))

# Normalize vector components to be in the range [0, 1] for color representation
r = (v[0] + 1) * 0.5
g = (v[1] + 1) * 0.5
b = (v[2] + 1) * 0.5

# Store line color properties
line_properties.append({'linecolor': Color(r, g, b)})

# Initialize the COMPAS viewer
viewer = App(width=1600, height=900)

# Adjust viewer settings
viewer.view.camera.scale = 1000
viewer.view.grid.cell_size = 1000

# Create a line collection and add it to the viewer
line_collection = Collection(lines, line_properties)
viewer.add(Pointcloud(points))
viewer.add(line_collection)

# Set the camera to zoom to fit all points and lines
viewer.view.camera.zoom_extents()

# Run the viewer
viewer.run()
11 changes: 11 additions & 0 deletions docs/examples/pointsets_normals.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
********************************************************************************
Pointset Normal Estimation
********************************************************************************

.. figure:: /_images/cgal_pointset_normal_estimation.png
:figclass: figure
:class: figure-img img-fluid


.. literalinclude:: pointsets_normals.py
:language: python
37 changes: 37 additions & 0 deletions docs/examples/pointsets_smoothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from pathlib import Path
from compas.geometry import Pointcloud, Translation
from compas_view2.app import App
from compas_cgal.reconstruction import pointset_smoothing

# Define the path to the PLY file
ply_file_path = Path(__file__).parent.parent.parent / "data" / "box.ply"

# Load the original point cloud and translate it
original_points = Pointcloud.from_ply(ply_file_path)
original_points.transform(Translation.from_vector([-10000, 0, 0]))

# Load another copy of the point cloud for comparison and translate it in the opposite direction
transformed_points = Pointcloud.from_ply(ply_file_path)
transformed_points.transform(Translation.from_vector([10000, 0, 0]))

# Apply point set smoothing to the transformed point cloud
smoothed_points = pointset_smoothing(transformed_points, 1000, 3)

# Create Pointcloud objects for visualization
cloud_original = Pointcloud(original_points)
cloud_transformed = Pointcloud(smoothed_points)

# Set up the viewer
viewer = App(width=1600, height=900)
viewer.view.camera.scale = 1000
viewer.view.grid.cell_size = 1000

# Add the Pointclouds to the viewer
viewer.add(cloud_original)
viewer.add(cloud_transformed)

# Adjust the camera and grid settings
viewer.view.camera.zoom_extents()

# Run the viewer
viewer.run()
11 changes: 11 additions & 0 deletions docs/examples/pointsets_smoothing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
********************************************************************************
Pointset Smoothing
********************************************************************************

.. figure:: /_images/cgal_pointset_smoothing.png
:figclass: figure
:class: figure-img img-fluid


.. literalinclude:: pointsets_smoothing.py
:language: python
22 changes: 11 additions & 11 deletions include/compas.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/Polyhedron_items_with_id_3.h>

using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point = Kernel::Point_3;
using Vector = Kernel::Vector_3;
using Polyline = std::vector<Point>;
using Polylines = std::list<Polyline>;
using Polyhedron = CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3>;
using Mesh = CGAL::Surface_mesh<Point>;

namespace compas
{
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point = Kernel::Point_3;
using Vector = Kernel::Vector_3;
using Polyline = std::vector<Point>;
using Polylines = std::list<Polyline>;
using Polyhedron = CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3>;
using Mesh = CGAL::Surface_mesh<Point>;
using RowMatrixXd = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
using RowMatrixXi = Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;

Expand All @@ -31,13 +31,13 @@ namespace compas

Mesh ngon_from_vertices_and_faces(const RowMatrixXd &V, const std::vector<std::vector<int>> &faces);

std::tuple<compas::RowMatrixXd, compas::RowMatrixXi> mesh_to_vertices_and_faces(const Mesh &mesh);
std::tuple< RowMatrixXd, RowMatrixXi> mesh_to_vertices_and_faces(const Mesh &mesh);

std::tuple<compas::RowMatrixXd, compas::RowMatrixXi> quadmesh_to_vertices_and_faces(const Mesh &mesh);
std::tuple< RowMatrixXd, RowMatrixXi> quadmesh_to_vertices_and_faces(const Mesh &mesh);

std::vector<compas::RowMatrixXd> polylines_to_lists_of_points(Polylines polylines);
std::vector< RowMatrixXd> polylines_to_lists_of_points(Polylines polylines);

std::tuple<compas::RowMatrixXd, compas::RowMatrixXi> polyhedron_to_vertices_and_faces(Polyhedron polyhedron);
std::tuple< RowMatrixXd, RowMatrixXi> polyhedron_to_vertices_and_faces(Polyhedron polyhedron);
}

#endif /* COMPAS_H */
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
compas>=2.0.0a2
compas>=2.0.0b1
nptyping
typing_extensions
22 changes: 11 additions & 11 deletions src/booleans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pmp_boolean_union(
Eigen::Ref<const compas::RowMatrixXd> &VB,
Eigen::Ref<const compas::RowMatrixXi> &FB)
{
Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
Mesh C;
compas::Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
compas::Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
compas::Mesh C;

PMP::corefine_and_compute_union(A, B, C);

Expand All @@ -31,9 +31,9 @@ pmp_boolean_difference(
Eigen::Ref<const compas::RowMatrixXd> &VB,
Eigen::Ref<const compas::RowMatrixXi> &FB)
{
Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
Mesh C;
compas::Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
compas::Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
compas::Mesh C;

PMP::corefine_and_compute_difference(A, B, C);

Expand All @@ -51,9 +51,9 @@ pmp_boolean_intersection(
Eigen::Ref<const compas::RowMatrixXd> &VB,
Eigen::Ref<const compas::RowMatrixXi> &FB)
{
Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
Mesh C;
compas::Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
compas::Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
compas::Mesh C;

PMP::corefine_and_compute_intersection(A, B, C);

Expand All @@ -71,8 +71,8 @@ pmp_split(
Eigen::Ref<const compas::RowMatrixXd> &VB,
Eigen::Ref<const compas::RowMatrixXi> &FB)
{
Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
compas::Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
compas::Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
PMP::split(A, B);

std::tuple<compas::RowMatrixXd, compas::RowMatrixXi> R = compas::mesh_to_vertices_and_faces(A);
Expand Down
Loading

0 comments on commit 077f851

Please sign in to comment.