Physsim::Primitive Class Reference

Defines an abstract primitive type used for inertial property calculation and geometry provisions. More...

#include <Primitive.h>

Inheritance diagram for Physsim::Primitive:

Physsim::Base Physsim::Box Physsim::Cylinder Physsim::Sphere Physsim::TriangleMesh List of all members.

Public Member Functions

 Primitive ()
 Constructs a primitive under the identity transformation.
 Primitive (const Matrix4 &T)
 Constructs a primitive with the specified transform.
virtual Matrix3 calc_inertia ()
 Default method for computing the inertia of this primitive.
virtual Vector3 calc_com ()
 Default method for computing the center-of-mass of this primitive.
virtual Real calc_mass ()
 Default method for computing the mass of this primitive.
virtual void load_from_xml (XMLTreeConstPtr node, std::map< std::string, BasePtr > &id_map)
 Implements Base::load_from_xml() for serialization.
virtual void save_to_xml (XMLTreePtr node, std::list< BaseConstPtr > &shared_objects) const
 Implements Base::save_to_xml() for serialization.
virtual void center ()
 Centers the geometry (specifically, the underlying array of triangles).
virtual SoNode * create_visualization ()
 Default method for creating the visualization data for this object.
void update_visualization ()
 Updates the visualization on the primitive.
SoSeparator * get_visualization ()
 Gets the visualization for this primitive, creating it if necessary.
TriangleArrayConstPtr get_tris () const
void set_transform (const Matrix4 &T)
 Sets the transform for this primitive -- transforms mesh and inertial properties (if calculated).
std::list< Vector3ConstPtr > get_vertices () const
 Gets the set of vertices in the triangle representation of this primitive.
void set_max_tri_area (Real max_tri_area)
 Sets the maximum area for triangles in the mesh.
Real get_max_tri_area () const
const Matrix4get_transform () const
 Gets the transform applied to this primitive.
std::vector< Real > det_indexed_mesh_vertices () const
 Converts the vertices used in the mesh into an array of Reals.
std::vector< int > det_indexed_mesh_indices (bool term) const
 Converts the mesh into an array of ints.
void set_mass (Real mass)
 Sets the mass of this primitive.
void set_density (Real density)
 Sets the density of this primitive.

Static Public Member Functions

static void transform_inertia (Real mass, const Matrix3 &J_in, const Vector3 &com_in, const Matrix4 &T, Matrix3 &J_out, Vector3 &com_out)
 Transforms the given inertial properties by the given transform.

Protected Member Functions

void transform_mesh ()
 Transforms the mesh to the given transformation.
void subdivide ()
 Subdivides the underlying mesh until all triangles are no greater than the given area.

Protected Attributes

Matrix4 _T
 The transform applied to this primitive.
Real _mass
 The mass of this primitive.
Real _density
 The density of this primitive.
TriangleArrayConstPtr _tris
 The geometry of this primitive, represented as triangles.

Detailed Description

Defines an abstract primitive type used for inertial property calculation and geometry provisions.

The center-of-mass of the derived types may be at the origin of the world, or not. Additionally, Primitive can take a transformation matrix in its constructor, with which the primitive data (com, inertia matrix, and geometry) can be transformed.


Member Function Documentation

Matrix3 Primitive::calc_inertia (  )  [virtual]

Default method for computing the inertia of this primitive.

This method is slow, but accurate, as it computes the inertia over the triangle mesh of the primitive.

Reimplemented in Physsim::Box, Physsim::Cylinder, and Physsim::Sphere.

Vector3 Primitive::calc_com (  )  [virtual]

Default method for computing the center-of-mass of this primitive.

This method is slow but accurate, as it uses the triangle mesh for computation. Derived classes should be able to speed this up quite a bit.

Returns:
the center-of-mass of the primitive (accounting for current transform)

Reimplemented in Physsim::Cylinder, and Physsim::Sphere.

Real Primitive::calc_mass (  )  [virtual]

Default method for computing the mass of this primitive.

This method is slow, but accurate, as it computes the mass over the triangle mesh of the primitive.

Reimplemented in Physsim::Box, Physsim::Cylinder, and Physsim::Sphere.

SoNode * Primitive::create_visualization (  )  [virtual]

Default method for creating the visualization data for this object.

This method creates visualization data using the underlying triangle mesh.

Note:
derived implementations of this method should create the visualization data without consideration of the primitive transform: the Primitive class applies the proper transformation to the visualization data.

Reimplemented in Physsim::Box, Physsim::Cylinder, and Physsim::Sphere.

void Primitive::transform_inertia ( Real  mass,
const Matrix3 J_in,
const Vector3 com_in,
const Matrix4 T,
Matrix3 J_out,
Vector3 com_out 
) [static]

Transforms the given inertial properties by the given transform.

Parameters:
mass the mass of the object
J_in the input inertia matrix
com_in the input center-of-mass
T the 4x4 transformation matrix
J_out the transformed inertia matrix, on return
com_out the transformed center-of-mass, on return
Note:
it is ok to call this method with J_in = J_out and/or com_in = com_out

void Primitive::set_max_tri_area ( Real  area  ) 

Sets the maximum area for triangles in the mesh.

Note:
this value can only be decreased, never increased, from its current value (default=infinity), because there is no mechanism in place for merging coplanar triangles.

std::vector< Real > Primitive::det_indexed_mesh_vertices (  )  const

Converts the vertices used in the mesh into an array of Reals.

An array of 3*n Reals is returned, where n is the number of vertices used in the mesh. This method allows the mesh to be converted into an indexed-face representation.

std::vector< int > Primitive::det_indexed_mesh_indices ( bool  term  )  const

Converts the mesh into an array of ints.

Parameters:
term determines whether an array of 3*n ints or an array of 4*n ints is returned; if the latter, each set of three indices is terminated by the value -1 An array of 3*n or 4*n ints is returned, where n is the number of faces used in the mesh. This method allows the mesh to be converted into an indexed-face representation. Each value returned is an index from zero to m-1, where m is the number of vertices used in the mesh.

void Primitive::transform_mesh (  )  [protected]

Transforms the mesh to the given transformation.

Note:
the mesh is cloned before it is transformed, in case the mesh is referenced by multiple objects

calls TriangleMesh::clone_mesh() and TriangleMesh::transform_mesh()


Member Data Documentation

TriangleArrayConstPtr Physsim::Primitive::_tris [protected]

The geometry of this primitive, represented as triangles.

The triangle mesh is updated as the primitive's transform changes.


The documentation for this class was generated from the following files:
Generated on Wed Oct 24 14:54:23 2007 for Physsim by  doxygen 1.5.1