Replaced iterator-based constructor with one that takes either vector or array.

Refactored TriangleMesh constructor to use raw pointer (C-style semantics) and pointer vector/array.
This commit is contained in:
Joseph Lenox 2018-07-12 23:26:07 -05:00
parent ee208ddc73
commit f0ba8a2340
3 changed files with 9 additions and 6 deletions

View File

@ -12,7 +12,7 @@ SCENARIO( "TriangleMesh: Basic mesh statistics") {
GIVEN( "A 20mm cube, built from constexpr std::array" ) {
constexpr std::array<Pointf3, 8> vertices { Pointf3(20,20,0), Pointf3(20,0,0), Pointf3(0,0,0), Pointf3(0,20,0), Pointf3(20,20,20), Pointf3(0,20,20), Pointf3(0,0,20), Pointf3(20,0,20) };
constexpr std::array<Point3, 12> facets { Point3(0,1,2), Point3(0,2,3), Point3(4,5,6), Point3(4,6,7), Point3(0,4,7), Point3(0,7,1), Point3(1,7,6), Point3(1,6,2), Point3(2,6,5), Point3(2,5,3), Point3(4,0,3), Point3(4,3,5) };
auto cube {TriangleMesh(vertices.cbegin(), vertices.cend(), facets.cbegin(), facets.cend())};
auto cube {TriangleMesh(vertices, facets)};
cube.repair();
THEN( "Volume is appropriate for 20mm square cube.") {

View File

@ -28,7 +28,8 @@ TriangleMesh::TriangleMesh()
stl_initialize(&this->stl);
}
TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector<Point3>& facets )
TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector<Point3>& facets ) : TriangleMesh(points.data(), facets.data(), facets.size()) {}
TriangleMesh::TriangleMesh(const Pointf3* points, const Point3* facets, size_t n_facets)
: repaired(false)
{
stl_initialize(&this->stl);
@ -37,7 +38,7 @@ TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector<Point3>& fa
stl.stats.type = inmemory;
// count facets and allocate memory
stl.stats.number_of_facets = facets.size();
stl.stats.number_of_facets = n_facets;
stl.stats.original_num_facets = stl.stats.number_of_facets;
stl_allocate(&stl);

View File

@ -36,11 +36,13 @@ class TriangleMesh
{
public:
TriangleMesh();
TriangleMesh(const Pointf3* points, const Point3* facets, size_t n_facets);
TriangleMesh(const Pointf3s &points, const std::vector<Point3> &facets);
/// Templated constructor that takes a pair of iterators to build a TriangleMesh.
template <typename Iter_vert, typename Iter_fac>
TriangleMesh(Iter_vert p_begin, Iter_vert p_end, Iter_fac f_begin, Iter_fac f_end) : TriangleMesh(Pointf3s(p_begin, p_end), Point3s(f_begin, f_end)) {}
/// Templated constructor to adapt containers that offer .data() and .size()
template <typename Vertex_Cont, typename Facet_Cont>
TriangleMesh(const Vertex_Cont& vertices, const Facet_Cont& facets) : TriangleMesh(vertices.data(), facets.data(), facets.size()) {}
TriangleMesh(const TriangleMesh &other);
TriangleMesh& operator= (TriangleMesh other);
void swap(TriangleMesh &other);