Virtual Testbed
Ship dynamics simulator for extreme conditions
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
vtb::geometry::Polyhedron< T, N > Class Template Reference

Three-dimensional polyhedron. More...

#include <polyhedron.hh>

Public Types

using scalar_type = T
 
using vertex_type = Vertex< T, N >
 
using face_type = Face< 3 >
 
using vertex_array = std::vector< vertex_type >
 
using face_array = std::vector< face_type >
 
using size_type = size_t
 
using index_type = typename face_type::value_type
 
using box_type = Rectangle< T, N >
 
using triangle_type = Triangle< T, N >
 
using triangle_array = std::vector< triangle_type >
 
using bsp_tree = BSP_tree< T, N >
 

Public Member Functions

 Polyhedron (const Polyhedron &)=default
 
Polyhedronoperator= (const Polyhedron &)=default
 
 Polyhedron (Polyhedron &&)=default
 
Polyhedronoperator= (Polyhedron &&)=default
 
 Polyhedron (const vertex_array &vertices, const face_array &faces)
 
 Polyhedron (const vertex_array &vertices, const vertex_array &vertex_normals, const face_array &faces)
 
 Polyhedron (const blitz_vertex_array &vertices, const blitz_face_array &faces)
 
 Polyhedron (const triangle_array &triangles)
 
 Polyhedron (const bsp_tree &tree)
 
const vertex_arrayvertices () const noexcept
 
const vertex_arrayvertex_normals () const noexcept
 
const vertex_arrayface_normals () const noexcept
 
const face_arrayfaces () const noexcept
 
void clear ()
 
void clear_normals ()
 
void shrink_to_fit ()
 
scalar_type average_face_area () const
 
scalar_type signed_volume () const
 
scalar_type signed_volume_below (int dimension, scalar_type level) const
 
vertex_type centre () const
 
vertex_type centroid () const
 
vertex_type centroid_below (int dimension, scalar_type level) const
 
box_type bounding_box () const
 
Bounds< T > bounds (int dimension) const
 
void swap (Polyhedron &rhs)
 
scalar_type signed_volume_below_centroid (int dimension) const
 
void normalise ()
 Compute face and vertex normals in one loop. More...
 
void normalise_faces ()
 Compute face normals only. More...
 
void reorder ()
 Fix face indices winding order. More...
 
void unique ()
 Remove duplicate vertices and faces. More...
 
void merge (const Polyhedron &rhs)
 Add all vertices, faces and normals from rhs. More...
 
Polyhedronoperator+= (const Polyhedron &rhs)
 
void cut_duplicate_faces ()
 
void remove_face (const vertex_type &vertex)
 
void remove_face (index_type vertex)
 
bool empty () const
 
triangle_array triangles () const
 
blitz_vertex_array blitz_vertices () const
 
blitz_vertex_array blitz_vertex_normals () const
 
blitz_face_array blitz_faces () const
 
void move_to_centre_of_mass ()
 Move origin to centre of mass.
 
void move_to_centre_of_mass (T draught)
 Move origin to centre of mass taking into account buoyancy and gravity forces. More...
 
void move_to_centre_of_bounding_box ()
 Move origin to centre of bounding box.
 
void move (const vertex_type &delta)
 
void scale (const vertex_type &ratio)
 Scale the geometry by specified ratio over each dimension.
 
void wall (scalar_type thickness)
 Shrink or extend the geometry by thickness in the direction of centroid.
 
void flip (int dimension)
 Flip the geometry over specified axis.
 
void mirror (int dimension)
 Extend the geometry by mirroring it over the specified axis.
 
void rotate (int dimension, int degrees)
 Rotate the geometry by angle which is multiple of 90 degrees. More...
 
Mass_moments< T, N > mass_moments () const
 Calculate volume, centre of mass and inertia tensor. More...
 
Mass_moments< T, N > mass_moments_below (int dimension, scalar_type level) const
 
void gnuplot (std::ostream &out) const
 
void object (std::ostream &out) const
 

Static Public Attributes

static constexpr const int dimensions = N
 

Friends

template<class X , int M>
vtb::core::bstreamoperator>> (vtb::core::bstream &in, Polyhedron< X, M > &rhs)
 

Detailed Description

template<class T, int N = 3>
class vtb::geometry::Polyhedron< T, N >

Three-dimensional polyhedron.

Date
2019-03-18
Author
Ivan Gankevich

Definition at line 43 of file polyhedron.hh.

Member Function Documentation

◆ mass_moments()

template<class T, int N = 3>
Mass_moments<T,N> vtb::geometry::Polyhedron< T, N >::mass_moments ( ) const
inline

Calculate volume, centre of mass and inertia tensor.

Date
2019-06-08
Author
Ivan Gankevich
  • Uses algorithm from [eberly2002polyhedral].

Definition at line 270 of file polyhedron.hh.

◆ merge()

template<class T , int N>
void vtb::geometry::Polyhedron< T, N >::merge ( const Polyhedron< T, N > &  rhs)

Add all vertices, faces and normals from rhs.

Date
2019-04-05
Author
Ivan Gankevich
  • Does not perform deduplication.

Definition at line 343 of file geometry/polyhedron.cc.

◆ move_to_centre_of_mass()

template<class T, int N>
void vtb::geometry::Polyhedron< T, N >::move_to_centre_of_mass ( draught)

Move origin to centre of mass taking into account buoyancy and gravity forces.

Parameters
[in]draught

Definition at line 628 of file geometry/polyhedron.cc.

◆ normalise()

template<class T , int N>
void vtb::geometry::Polyhedron< T, N >::normalise ( )

Compute face and vertex normals in one loop.

Date
2019-03-18
Author
Ivan Gankevich
See also
http://iquilezles.org/www/articles/normals/normals.htm

Definition at line 152 of file geometry/polyhedron.cc.

◆ normalise_faces()

template<class T , int N>
void vtb::geometry::Polyhedron< T, N >::normalise_faces ( )

Compute face normals only.

Date
2019-09-12
Author
Ivan Gankevich

Definition at line 180 of file geometry/polyhedron.cc.

◆ reorder()

template<class T , int N>
void vtb::geometry::Polyhedron< T, N >::reorder ( )

Fix face indices winding order.

Date
2019-03-18
Author
Vadim Petrunin
Ivan Gankevich

Definition at line 202 of file geometry/polyhedron.cc.

◆ rotate()

template<class T , int N>
void vtb::geometry::Polyhedron< T, N >::rotate ( int  dimension,
int  degrees 
)

Rotate the geometry by angle which is multiple of 90 degrees.

Date
2018-10-22
Author
Ivan Gankevich
Parameters
[in]dimdimensions over which rotation is done
[in]degreesHow many degrees to rotate. This should be a multiple of 90.
  • The rotation comes down to shuffling vector components and flipping signs, hence it is lossless.

Definition at line 818 of file geometry/polyhedron.cc.

◆ unique()

template<class T , int N>
void vtb::geometry::Polyhedron< T, N >::unique ( )

Remove duplicate vertices and faces.

Date
2019-03-18
Author
Ivan Gankevich
  • Removes faces with duplicate indices as a side effect.

Definition at line 234 of file geometry/polyhedron.cc.