Skip to content

Commit

Permalink
Merge pull request #21 from petrasvestartas/compas_namespace
Browse files Browse the repository at this point in the history
CHANGE main types like Point, Vector, Polyline are moved to compas na…
  • Loading branch information
tomvanmele authored Jan 11, 2024
2 parents 4c07730 + 8839ff5 commit 3363f2a
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 104 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
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 */
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
68 changes: 34 additions & 34 deletions src/compas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ class Build_polyhedron : public CGAL::Modifier_base<HDS>
*
* @param V vx3 matrix of vertex coordinates.
* @param F fx3 matrix of face vertex indices.
* @return Polyhedron
* @return compas::Polyhedron
*
* @todo: add support for Ngon faces.
*/
Polyhedron polyhedron_from_vertices_and_faces(
compas::Polyhedron compas::polyhedron_from_vertices_and_faces(
const compas::RowMatrixXd &V,
const compas::RowMatrixXi &F)
{
Polyhedron polyhedron;
Build_polyhedron<Polyhedron::HalfedgeDS> build(V, F);
compas::Polyhedron polyhedron;
Build_polyhedron<compas::Polyhedron::HalfedgeDS> build(V, F);
polyhedron.delegate(build);
return polyhedron;
}
Expand All @@ -65,31 +65,31 @@ Polyhedron polyhedron_from_vertices_and_faces(
*
* @param V vx3 matrix of vertex coordinates.
* @param F fx3 matrix of face vertex indices.
* @return Mesh
* @return compas::Mesh
*
* @todo: change name to trimesh_from_vertices_and_faces.
* @todo: check that all faces are triangles.
* @todo: add error message if not all faces are triangles.
*
*/
Mesh compas::mesh_from_vertices_and_faces(
compas::Mesh compas::mesh_from_vertices_and_faces(
const compas::RowMatrixXd &V,
const compas::RowMatrixXi &F)
{
int v = V.rows();
int f = F.rows();

Mesh mesh;
std::vector<Mesh::Vertex_index> index_descriptor(v);
compas::Mesh mesh;
std::vector<compas::Mesh::Vertex_index> index_descriptor(v);

for (int i = 0; i < v; i++)
{
index_descriptor[i] = mesh.add_vertex(Kernel::Point_3(V(i, 0), V(i, 1), V(i, 2)));
index_descriptor[i] = mesh.add_vertex(compas::Kernel::Point_3(V(i, 0), V(i, 1), V(i, 2)));
}

Mesh::Vertex_index a;
Mesh::Vertex_index b;
Mesh::Vertex_index c;
compas::Mesh::Vertex_index a;
compas::Mesh::Vertex_index b;
compas::Mesh::Vertex_index c;

for (int i = 0; i < f; i++)
{
Expand All @@ -107,27 +107,27 @@ Mesh compas::mesh_from_vertices_and_faces(
*
* @param V nx3 matrix of vertex coordinates.
* @param faces list of list of vertex indices.
* @return Mesh
* @return compas::Mesh
*
* @todo: rename to mesh_from_vertices_and_faces.
*/
Mesh compas::ngon_from_vertices_and_faces(
compas::Mesh compas::ngon_from_vertices_and_faces(
const compas::RowMatrixXd &V,
const std::vector<std::vector<int>> &faces)
{
int v = V.rows();

Mesh mesh;
std::vector<Mesh::Vertex_index> index_descriptor(v);
compas::Mesh mesh;
std::vector<compas::Mesh::Vertex_index> index_descriptor(v);

for (int i = 0; i < v; i++)
{
index_descriptor[i] = mesh.add_vertex(Kernel::Point_3(V(i, 0), V(i, 1), V(i, 2)));
index_descriptor[i] = mesh.add_vertex(compas::Kernel::Point_3(V(i, 0), V(i, 1), V(i, 2)));
}

for (std::size_t i = 0; i < faces.size(); i++)
{
std::vector<Mesh::Vertex_index> face;
std::vector<compas::Mesh::Vertex_index> face;

for (std::size_t j = 0; j < faces[i].size(); j++)
{
Expand All @@ -153,27 +153,27 @@ Mesh compas::ngon_from_vertices_and_faces(
*/
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
compas::mesh_to_vertices_and_faces(
const Mesh &mesh)
const compas::Mesh &mesh)
{
std::size_t v = mesh.number_of_vertices();
std::size_t f = mesh.number_of_faces();

compas::RowMatrixXd V(v, 3);
compas::RowMatrixXi F(f, 3);

Mesh::Property_map<Mesh::Vertex_index, Kernel::Point_3> location = mesh.points();
compas::Mesh::Property_map<compas::Mesh::Vertex_index, compas::Kernel::Point_3> location = mesh.points();

for (Mesh::Vertex_index vd : mesh.vertices())
for (compas::Mesh::Vertex_index vd : mesh.vertices())
{
V(vd, 0) = (double)location[vd][0];
V(vd, 1) = (double)location[vd][1];
V(vd, 2) = (double)location[vd][2];
}

for (Mesh::Face_index fd : mesh.faces())
for (compas::Mesh::Face_index fd : mesh.faces())
{
int i = 0;
for (Mesh::Vertex_index vd : vertices_around_face(mesh.halfedge(fd), mesh))
for (compas::Mesh::Vertex_index vd : vertices_around_face(mesh.halfedge(fd), mesh))
{
F(fd, i) = (int)vd;
i++;
Expand All @@ -196,27 +196,27 @@ compas::mesh_to_vertices_and_faces(
*/
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
compas::quadmesh_to_vertices_and_faces(
const Mesh &mesh)
const compas::Mesh &mesh)
{
std::size_t v = mesh.number_of_vertices();
std::size_t f = mesh.number_of_faces();

compas::RowMatrixXd V(v, 3);
compas::RowMatrixXi F(f, 4);

Mesh::Property_map<Mesh::Vertex_index, Kernel::Point_3> vertex_location = mesh.points();
compas::Mesh::Property_map<compas::Mesh::Vertex_index, compas::Kernel::Point_3> vertex_location = mesh.points();

for (Mesh::Vertex_index vd : mesh.vertices())
for (compas::Mesh::Vertex_index vd : mesh.vertices())
{
V(vd, 0) = (double)vertex_location[vd][0];
V(vd, 1) = (double)vertex_location[vd][1];
V(vd, 2) = (double)vertex_location[vd][2];
}

for (Mesh::Face_index fd : mesh.faces())
for (compas::Mesh::Face_index fd : mesh.faces())
{
int i = 0;
for (Mesh::Vertex_index vd : vertices_around_face(mesh.halfedge(fd), mesh))
for (compas::Mesh::Vertex_index vd : vertices_around_face(mesh.halfedge(fd), mesh))
{
F(fd, i) = (int)vd;
i++;
Expand All @@ -235,13 +235,13 @@ compas::quadmesh_to_vertices_and_faces(
*/
std::vector<compas::RowMatrixXd>
compas::polylines_to_lists_of_points(
Polylines polylines)
compas::Polylines polylines)
{
std::vector<compas::RowMatrixXd> pointsets;

for (auto i = polylines.begin(); i != polylines.end(); i++)
{
const Polyline &poly = *i;
const compas::Polyline &poly = *i;
std::size_t n = poly.size();
compas::RowMatrixXd points(n, 3);

Expand All @@ -268,7 +268,7 @@ compas::polylines_to_lists_of_points(
*/
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
compas::polyhedron_to_vertices_and_faces(
Polyhedron polyhedron)
compas::Polyhedron polyhedron)
{
std::size_t v = polyhedron.size_of_vertices();
std::size_t f = polyhedron.size_of_facets();
Expand All @@ -278,7 +278,7 @@ compas::polyhedron_to_vertices_and_faces(

std::size_t i = 0;

for (Polyhedron::Vertex_handle vh : polyhedron.vertex_handles())
for (compas::Polyhedron::Vertex_handle vh : polyhedron.vertex_handles())
{
V(i, 0) = (double)vh->point().x();
V(i, 1) = (double)vh->point().y();
Expand All @@ -291,11 +291,11 @@ compas::polyhedron_to_vertices_and_faces(

i = 0;

for (Polyhedron::Facet_handle fh : polyhedron.facet_handles())
for (compas::Polyhedron::Facet_handle fh : polyhedron.facet_handles())
{
std::size_t j = 0;

Polyhedron::Halfedge_handle start = fh->halfedge(), h = start;
compas::Polyhedron::Halfedge_handle start = fh->halfedge(), h = start;
do
{
F(i, j) = h->vertex()->id();
Expand Down
6 changes: 3 additions & 3 deletions src/intersections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pmp_intersection_mesh_mesh(
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);

Polylines polylines;
compas::Polylines polylines;

PMP::surface_intersection(A, B, std::back_inserter(polylines));

Expand Down
8 changes: 4 additions & 4 deletions src/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pmp_area(
Eigen::Ref<const compas::RowMatrixXd> &V,
Eigen::Ref<const compas::RowMatrixXi> &F)
{
Mesh mesh = compas::mesh_from_vertices_and_faces(V, F);
compas::Mesh mesh = compas::mesh_from_vertices_and_faces(V, F);

double area = PMP::area(mesh);

Expand All @@ -21,7 +21,7 @@ pmp_volume(
Eigen::Ref<const compas::RowMatrixXd> &V,
Eigen::Ref<const compas::RowMatrixXi> &F)
{
Mesh mesh = compas::mesh_from_vertices_and_faces(V, F);
compas::Mesh mesh = compas::mesh_from_vertices_and_faces(V, F);

double volume = PMP::volume(mesh);

Expand All @@ -33,9 +33,9 @@ pmp_centroid(
Eigen::Ref<const compas::RowMatrixXd> &V,
Eigen::Ref<const compas::RowMatrixXi> &F)
{
Mesh mesh = compas::mesh_from_vertices_and_faces(V, F);
compas::Mesh mesh = compas::mesh_from_vertices_and_faces(V, F);

Kernel::Point_3 centroid = PMP::centroid(mesh);
compas::Kernel::Point_3 centroid = PMP::centroid(mesh);

return std::vector<double>{centroid.x(), centroid.y(), centroid.z()};
};
Expand Down
4 changes: 2 additions & 2 deletions src/meshing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pmp_remesh(
unsigned int number_of_iterations,
bool do_project)
{
Mesh mesh = compas::mesh_from_vertices_and_faces(V, F);
compas::Mesh mesh = compas::mesh_from_vertices_and_faces(V, F);

// protect sharp features

// typedef boost::property_map<Mesh, CGAL::edge_is_feature_t>::type EIFMap;
// typedef boost::property_map<compas::Mesh, CGAL::edge_is_feature_t>::type EIFMap;
// EIFMap eif = get(CGAL::edge_is_feature, mesh);
// PMP::detect_sharp_edges(mesh, 60, eif);

Expand Down
Loading

0 comments on commit 3363f2a

Please sign in to comment.