Klamp't  0.9.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
Klampt::ManagedGeometry Class Reference

A "smart" geometry loading class that caches previous geometries and maintains shared collision detection / appearance information. This greatly speeds up loading time if multiple instances of the same geometry are loaded from disk, because multiple ManagedGeometry objects can share the same underlying data. It can also read from dynamic geometry sources (ROS point cloud topics, for now). More...

#include <ManagedGeometry.h>

Public Types

typedef std::shared_ptr< Geometry::AnyCollisionGeometry3D > GeometryPtr
 
typedef std::shared_ptr< GLDraw::GeometryAppearance > AppearancePtr
 

Public Member Functions

 ManagedGeometry (const ManagedGeometry &rhs)
 Copy constructor is a shallow copy.
 
void Clear ()
 Erases the items in this geometry.
 
bool Empty () const
 Returns true if the pointer is NULL or the geometry itself is empty.
 
GeometryPtr CreateEmpty ()
 Creates an empty geometry.
 
bool Load (const std::string &filename)
 Loads a geometry, with caching.
 
bool LoadNoCache (const std::string &filename)
 Loads a geometry, without caching.
 
bool IsCached () const
 Returns true if this instance is cached.
 
bool IsOriginal () const
 Returns true if this instance is cached and is identical to a file on disk.
 
void AddToCache (const std::string &filename)
 Adds to cache, if not already in it.
 
const std::string & CachedFilename () const
 Returns the filename to which this object is cached.
 
void RemoveFromCache ()
 Remove self from cache, if in it.
 
void TransformGeometry (const Math3D::Matrix4 &xform)
 
AppearancePtr Appearance () const
 Returns the shared appearance data.
 
bool IsAppearanceShared () const
 
void SetUnique ()
 
void SetUniqueAppearance ()
 
void OnGeometryChange ()
 If the geometry is changed, call this to update the appearance.
 
void DrawGL ()
 Renders the object using OpenGL.
 
void DrawGLOpaque (bool opaque)
 Renders the opaque parts of the object using OpenGL.
 
bool IsDynamicGeometry () const
 Returns true if this geometry is connected to a dynamic source.
 
bool DynamicGeometryUpdate ()
 
const ManagedGeometryoperator= (const ManagedGeometry &rhs)
 assignment is a shallow copy
 
 operator bool () const
 
bool operator! () const
 
 operator GeometryPtr ()
 Dereferencing by cast, pointer access ->, or *.
 
 operator GeometryPtr () const
 
GeometryPtr operator-> ()
 
const GeometryPtr operator-> () const
 
Geometry::AnyCollisionGeometry3D & operator* ()
 
const Geometry::AnyCollisionGeometry3D & operator* () const
 

Static Public Member Functions

static ManagedGeometryIsCached (const std::string &filename)
 

Static Public Attributes

static GeometryManager manager
 

Friends

class GeometryManager
 

Detailed Description

A "smart" geometry loading class that caches previous geometries and maintains shared collision detection / appearance information. This greatly speeds up loading time if multiple instances of the same geometry are loaded from disk, because multiple ManagedGeometry objects can share the same underlying data. It can also read from dynamic geometry sources (ROS point cloud topics, for now).

Shared geometries: The Load function will load a file normally if it hasn't been loaded before. But if it has, this geometry will simply refer to the existing geometry, collision detection data structures, and Appearance information. This leads to major speed ups in running time and lower memory consumption when multiple objects of the same geometry are loaded.

Caching can have some weird effects. If you change the geometry / appearance of a shared ManagedGeometry, then all of the other ManagedGeometrys' will receive the same changes. To avoid this, you can either 1) Call LoadNoCache or RemoveFromCache before the subsequent geometry is loaded, which avoids sharing geometries in the first place. 2) Call SetUnique after loading, which entirely breaks the connection between the object and the other shared geometries. 3) Call SetUniqueAppearance, which breaks the connection between the object's appearance and the appearances of other shared geometries. Note that this does not break the connection between geometries.

Transforming geometries:

Note: the Load / LoadNoCache functions can also accept non-file strings.

Member Function Documentation

bool Klampt::ManagedGeometry::DynamicGeometryUpdate ( )

Updates dynamic geometry, if an update is available. If no update, returns false

bool Klampt::ManagedGeometry::IsAppearanceShared ( ) const

Returns true if there are multiple objects sharing the appearance data. If it is shared, then changing one appearance affects multiple objects.

static ManagedGeometry* Klampt::ManagedGeometry::IsCached ( const std::string &  filename)
static

Returns NULL if the file hasn't been cached. Otherwise, returns a prior instance of the geometry.

void Klampt::ManagedGeometry::SetUnique ( )

Removes this geometry from the cache and separates its appearance data from all other instances of this object.

void Klampt::ManagedGeometry::SetUniqueAppearance ( )

Makes this item have its own appearance data separate from all other instances of this object.

void Klampt::ManagedGeometry::TransformGeometry ( const Math3D::Matrix4 &  xform)

Transforms the geometry (requires removing from cache, and re-initializing collision data).


The documentation for this class was generated from the following file: