#ifndef MEDUSA_BITS_DOMAINS_STLSHAPE_FWD_HPP_ #define MEDUSA_BITS_DOMAINS_STLSHAPE_FWD_HPP_ #include "DomainShape_fwd.hpp" #include #include /** * @file * Declaration of STLShape class. * * @example test/domains/STLShape_test.cpp */ namespace mm { /** * Class representing an object given by the STL file. * * This class offers basic support for STL files, with rudimentary surface discretization and * inexact geometry for the @ref contains method. For a more sophisticated class see the 3D version * of @ref PolygonShape, which uses the CGAL library that offers support for simple loading of * models from more file types, exact geometry for @ref contains and support for designating types * to faces. * * @snippet domains/STLShape_test.cpp STL shape usage example * @ingroup domains */ template class STLShape : public DomainShape { public: using typename DomainShape::scalar_t; using DomainShape::dim; private: static_assert(dim == 3, "STL files are for 3D models only."); std::vector vertices_; ///< 3d vertices. std::vector> faces_; ///< Faces, described with three indices of vertices. std::vector normals_; ///< Normals for each face. std::pair bbox_; ///< Bounding box. public: /// Create STLShape from triangles read from STL file. STLShape(const std::vector& stl); /** * Contains method is not supported and is approximated with a discrete version, which can * be wrong. * @sa DomainDiscretization::discreteContains. */ bool contains(const vec_t& /* point */) const override { return true; } bool hasContains() const override { return false; } std::pair bbox() const override { return bbox_; } using DomainShape::discretizeBoundaryWithDensity; DomainDiscretization discretizeBoundaryWithDensity( const std::function&, int) const override; std::ostream& print(std::ostream& ostream) const override { return ostream << "STL shape with " << vertices_.size() << " vertices and " << faces_.size() << " faces."; } STLShape* clone() const override { return new STLShape(*this); } private: /// Convert STL point to Vec3d. static vec_t v(const STL::Point& p) { return vec_t(p.x, p.y, p.z); } }; } // namespace mm #endif // MEDUSA_BITS_DOMAINS_STLSHAPE_FWD_HPP_