1 #ifndef VTESTBED_GEOMETRY_POLYHEDRON_HH 2 #define VTESTBED_GEOMETRY_POLYHEDRON_HH 7 #include <vtestbed/base/bstream.hh> 8 #include <vtestbed/geometry/face.hh> 9 #include <vtestbed/geometry/rectangle.hh> 10 #include <vtestbed/geometry/triangle.hh> 11 #include <vtestbed/geometry/types.hh> 26 inline Bounds(T a, T b): _min(a), _max(b) {}
27 inline T min()
const {
return this->_min; }
28 inline T max()
const {
return this->_max; }
42 template <
class T,
int N=3>
46 static constexpr
const int dimensions = N;
47 using scalar_type = T;
48 using vertex_type = Vertex<T,N>;
52 using size_type = size_t;
53 using index_type =
typename face_type::value_type;
62 using blitz_vertex_array = blitz::Array<vertex_type,1>;
63 using blitz_face_array = blitz::Array<face_type,1>;
82 _vertices(vertices), _faces(faces) {}
91 _vertex_normals(vertex_normals),
96 const blitz_vertex_array& vertices,
97 const blitz_face_array& faces
107 vertices()
const noexcept {
108 return this->_vertices;
112 vertex_normals()
const noexcept {
113 return this->_vertex_normals;
117 face_normals()
const noexcept {
118 return this->_face_normals;
122 faces()
const noexcept {
127 void clear_normals();
128 void shrink_to_fit();
129 scalar_type average_face_area()
const;
130 scalar_type signed_volume()
const;
131 scalar_type signed_volume_below(
int dimension, scalar_type level)
const;
132 vertex_type centre()
const;
133 vertex_type centroid()
const;
134 vertex_type centroid_below(
int dimension, scalar_type level)
const;
140 signed_volume_below_centroid(
int dimension)
const {
141 return this->signed_volume_below(dimension,
142 this->centroid()(dimension));
206 void cut_duplicate_faces();
207 void remove_face(
const vertex_type& vertex);
208 void remove_face(index_type vertex);
212 return this->vertices().empty() &&
213 this->vertex_normals().empty() &&
214 this->faces().empty() &&
215 this->face_normals().empty();
219 blitz_vertex_array blitz_vertices()
const;
220 blitz_vertex_array blitz_vertex_normals()
const;
221 blitz_face_array blitz_faces()
const;
235 void move(
const vertex_type& delta);
238 void scale(
const vertex_type& ratio);
242 void wall(scalar_type thickness);
245 void flip(
int dimension);
248 void mirror(
int dimension);
261 void rotate(
int dimension,
int degrees);
281 vertex_faces()
const;
286 component_faces(
const index_array_2d& vf)
const;
290 reference_face_index(
291 const index_array& indices,
292 const vertex_type& origin
296 void reorder(index_type reference_face_index,
const vertex_type& origin);
297 void remove_duplicate_vertices();
298 void remove_duplicate_faces();
300 template <
class X,
int M>
306 template <
class T,
int N>
308 swap(Polyhedron<T,N>& lhs, Polyhedron<T,N>& rhs) {
312 template <
class T,
int N>
314 centroid(
const Polyhedron<T,N>& geometry) {
315 return geometry.centroid();
318 template <
class T,
int N>
320 signed_volume(
const Polyhedron<T,N>& geometry) {
321 return geometry.signed_volume();
324 template <
class T,
int N>
326 volume(
const Polyhedron<T,N>& geometry) {
327 return std::abs(signed_volume(geometry));
330 template <
class T,
int N>
331 inline Polyhedron<T,N>
332 operator+(
const Polyhedron<T,N>& lhs,
const Polyhedron<T,N>& rhs) {
333 return Polyhedron<T,N>(lhs) += rhs;
336 template <
class T,
int N>
340 template <
class T,
int N>
344 template <
class T,
int N>
346 winding_number(
const Polyhedron<T,N>& geometry,
const Vertex<T,N>& origin);
355 template <
class T,
int N>
368 #endif // vim:filetype=cpp void flip(int dimension)
Flip the geometry over specified axis.
Mass_moments< T, N > mass_moments() const
Calculate volume, centre of mass and inertia tensor.
void reorder()
Fix face indices winding order.
Inertia_tensor< T, N > inertia_tensor(const Polyhedron< T, N > &body)
Calculate inertia tensor (matrix) of a body as a sum of inertia tensors for tetrahedrons.
void normalise_faces()
Compute face normals only.
void move_to_centre_of_bounding_box()
Move origin to centre of bounding box.
void unique()
Remove duplicate vertices and faces.
void scale(const vertex_type &ratio)
Scale the geometry by specified ratio over each dimension.
void move_to_centre_of_mass()
Move origin to centre of mass.
Three-dimensional polyhedron.
void normalise()
Compute face and vertex normals in one loop.
void wall(scalar_type thickness)
Shrink or extend the geometry by thickness in the direction of centroid.
void mirror(int dimension)
Extend the geometry by mirroring it over the specified axis.
void merge(const Polyhedron &rhs)
Add all vertices, faces and normals from rhs.
void rotate(int dimension, int degrees)
Rotate the geometry by angle which is multiple of 90 degrees.