diff options
author | bubnikv <bubnikv@gmail.com> | 2019-06-13 17:33:50 +0300 |
---|---|---|
committer | bubnikv <bubnikv@gmail.com> | 2019-06-13 17:33:50 +0300 |
commit | 9379fedd439826846d97eb02c7d88455aa50c47e (patch) | |
tree | ba0a5682e6961b0605179284c37cca2dba27aab2 /src/admesh | |
parent | 3872b939e440421dec0fc2cee8fad40fba6f1c0c (diff) |
Further C++isation of the admesh library & TriangleMesh
(copy & move constructors / operators)
Diffstat (limited to 'src/admesh')
-rw-r--r-- | src/admesh/connect.cpp | 2 | ||||
-rw-r--r-- | src/admesh/stl.h | 26 | ||||
-rw-r--r-- | src/admesh/stlinit.cpp | 10 | ||||
-rw-r--r-- | src/admesh/util.cpp | 43 |
4 files changed, 63 insertions, 18 deletions
diff --git a/src/admesh/connect.cpp b/src/admesh/connect.cpp index 1a7b7965d..5afb85d2c 100644 --- a/src/admesh/connect.cpp +++ b/src/admesh/connect.cpp @@ -30,6 +30,8 @@ #include <boost/predef/other/endian.h> #include <boost/log/trivial.hpp> +// Boost pool: Don't use mutexes to synchronize memory allocation. +#define BOOST_POOL_NO_MT #include <boost/pool/object_pool.hpp> #include "stl.h" diff --git a/src/admesh/stl.h b/src/admesh/stl.h index 40bced2f4..87210b3c9 100644 --- a/src/admesh/stl.h +++ b/src/admesh/stl.h @@ -89,6 +89,8 @@ struct stl_neighbors { }; struct stl_stats { + stl_stats() { this->reset(); } + void reset() { memset(this, 0, sizeof(stl_stats)); this->volume = -1.0; } char header[81]; stl_type type; uint32_t number_of_facets; @@ -117,6 +119,18 @@ struct stl_stats { }; struct stl_file { + stl_file() {} + stl_file(const stl_file &rhs) : facet_start(rhs.facet_start), neighbors_start(rhs.neighbors_start), stats(rhs.stats) {} + stl_file(stl_file &&rhs) : facet_start(std::move(rhs.facet_start)), neighbors_start(std::move(rhs.neighbors_start)), stats(rhs.stats) {} + stl_file& operator=(const stl_file &rhs) { this->facet_start = rhs.facet_start; this->neighbors_start = rhs.neighbors_start; this->stats = rhs.stats; return *this; } + stl_file& operator=(stl_file &&rhs) { this->facet_start = std::move(rhs.facet_start); this->neighbors_start = std::move(rhs.neighbors_start); this->stats = rhs.stats; return *this; } + + void clear() { + this->facet_start.clear(); + this->neighbors_start.clear(); + this->stats.reset(); + } + std::vector<stl_facet> facet_start; std::vector<stl_neighbors> neighbors_start; // Statistics @@ -125,7 +139,14 @@ struct stl_file { struct indexed_triangle_set { + indexed_triangle_set() {} + indexed_triangle_set(const indexed_triangle_set &rhs) : indices(rhs.indices), vertices(rhs.vertices) {} + indexed_triangle_set(indexed_triangle_set &&rhs) : indices(std::move(rhs.indices)), vertices(std::move(rhs.vertices)) {} + indexed_triangle_set& operator=(const indexed_triangle_set &rhs) { this->indices = rhs.indices; this->vertices = rhs.vertices; return *this; } + indexed_triangle_set& operator=(indexed_triangle_set &&rhs) { this->indices = std::move(rhs.indices); this->vertices = std::move(rhs.vertices); return *this; } + void clear() { indices.clear(); vertices.clear(); } + std::vector<stl_triangle_vertex_indices> indices; std::vector<stl_vertex> vertices; //FIXME add normals once we get rid of the stl_file from TriangleMesh completely. @@ -238,6 +259,10 @@ inline void its_transform(indexed_triangle_set &its, const Eigen::Matrix<T, 3, 3 v = (m * v.template cast<T>()).template cast<float>().eval(); } +extern void its_rotate_x(indexed_triangle_set &its, float angle); +extern void its_rotate_y(indexed_triangle_set &its, float angle); +extern void its_rotate_z(indexed_triangle_set &its, float angle); + extern void stl_generate_shared_vertices(stl_file *stl, indexed_triangle_set &its); extern bool its_write_obj(const indexed_triangle_set &its, const char *file); extern bool its_write_off(const indexed_triangle_set &its, const char *file); @@ -258,7 +283,6 @@ extern void stl_calculate_volume(stl_file *stl); extern void stl_repair(stl_file *stl, bool fixall_flag, bool exact_flag, bool tolerance_flag, float tolerance, bool increment_flag, float increment, bool nearby_flag, int iterations, bool remove_unconnected_flag, bool fill_holes_flag, bool normal_directions_flag, bool normal_values_flag, bool reverse_all_flag, bool verbose_flag); -extern void stl_reset(stl_file *stl); extern void stl_allocate(stl_file *stl); extern void stl_read(stl_file *stl, int first_facet, bool first); extern void stl_facet_stats(stl_file *stl, stl_facet facet, bool &first); diff --git a/src/admesh/stlinit.cpp b/src/admesh/stlinit.cpp index 0cc6e50c7..a328baa75 100644 --- a/src/admesh/stlinit.cpp +++ b/src/admesh/stlinit.cpp @@ -221,7 +221,7 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first) bool stl_open(stl_file *stl, const char *file) { - stl_reset(stl); + stl->clear(); FILE *fp = stl_open_count_facets(stl, file); if (fp == nullptr) return false; @@ -231,14 +231,6 @@ bool stl_open(stl_file *stl, const char *file) return result; } -void stl_reset(stl_file *stl) -{ - stl->facet_start.clear(); - stl->neighbors_start.clear(); - memset(&stl->stats, 0, sizeof(stl_stats)); - stl->stats.volume = -1.0; -} - #ifndef BOOST_LITTLE_ENDIAN extern void stl_internal_reverse_quads(char *buf, size_t cnt); #endif /* BOOST_LITTLE_ENDIAN */ diff --git a/src/admesh/util.cpp b/src/admesh/util.cpp index 70f4ffc27..029e44a28 100644 --- a/src/admesh/util.cpp +++ b/src/admesh/util.cpp @@ -115,12 +115,12 @@ static void calculate_normals(stl_file *stl) } } -static void rotate_point_2d(float *x, float *y, const double c, const double s) +static inline void rotate_point_2d(float &x, float &y, const double c, const double s) { - double xold = *x; - double yold = *y; - *x = float(c * xold - s * yold); - *y = float(s * xold + c * yold); + double xold = x; + double yold = y; + x = float(c * xold - s * yold); + y = float(s * xold + c * yold); } void stl_rotate_x(stl_file *stl, float angle) @@ -130,7 +130,7 @@ void stl_rotate_x(stl_file *stl, float angle) double s = sin(radian_angle); for (uint32_t i = 0; i < stl->stats.number_of_facets; ++ i) for (int j = 0; j < 3; ++ j) - rotate_point_2d(&stl->facet_start[i].vertex[j](1), &stl->facet_start[i].vertex[j](2), c, s); + rotate_point_2d(stl->facet_start[i].vertex[j](1), stl->facet_start[i].vertex[j](2), c, s); stl_get_size(stl); calculate_normals(stl); } @@ -142,7 +142,7 @@ void stl_rotate_y(stl_file *stl, float angle) double s = sin(radian_angle); for (uint32_t i = 0; i < stl->stats.number_of_facets; ++ i) for (int j = 0; j < 3; ++ j) - rotate_point_2d(&stl->facet_start[i].vertex[j](2), &stl->facet_start[i].vertex[j](0), c, s); + rotate_point_2d(stl->facet_start[i].vertex[j](2), stl->facet_start[i].vertex[j](0), c, s); stl_get_size(stl); calculate_normals(stl); } @@ -154,11 +154,38 @@ void stl_rotate_z(stl_file *stl, float angle) double s = sin(radian_angle); for (uint32_t i = 0; i < stl->stats.number_of_facets; ++ i) for (int j = 0; j < 3; ++ j) - rotate_point_2d(&stl->facet_start[i].vertex[j](0), &stl->facet_start[i].vertex[j](1), c, s); + rotate_point_2d(stl->facet_start[i].vertex[j](0), stl->facet_start[i].vertex[j](1), c, s); stl_get_size(stl); calculate_normals(stl); } +void its_rotate_x(indexed_triangle_set &its, float angle) +{ + double radian_angle = (angle / 180.0) * M_PI; + double c = cos(radian_angle); + double s = sin(radian_angle); + for (stl_vertex &v : its.vertices) + rotate_point_2d(v(1), v(2), c, s); +} + +void its_rotate_y(indexed_triangle_set& its, float angle) +{ + double radian_angle = (angle / 180.0) * M_PI; + double c = cos(radian_angle); + double s = sin(radian_angle); + for (stl_vertex& v : its.vertices) + rotate_point_2d(v(2), v(0), c, s); +} + +void its_rotate_z(indexed_triangle_set& its, float angle) +{ + double radian_angle = (angle / 180.0) * M_PI; + double c = cos(radian_angle); + double s = sin(radian_angle); + for (stl_vertex& v : its.vertices) + rotate_point_2d(v(0), v(1), c, s); +} + void stl_get_size(stl_file *stl) { if (stl->stats.number_of_facets == 0) |