Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mitsuba::TriMesh Class Reference

Abstract triangle mesh base class. More...

#include <mitsuba/render/trimesh.h>

+ Inheritance diagram for mitsuba::TriMesh:

Public Member Functions

 TriMesh (const std::string &name, size_t triangleCount, size_t vertexCount, bool hasNormals=false, bool hasTexcoords=false, bool hasVertexColors=false, bool flipNormals=false, bool faceNormals=false)
 Create a new, empty triangle mesh with the specified state. More...
 
 TriMesh (Stream *stream, InstanceManager *manager)
 Unserialize a triangle mesh. More...
 
 TriMesh (Stream *stream, int idx=0)
 Unserialize a triangle mesh. More...
 
virtual const ClassgetClass () const
 Retrieve this object's class. More...
 
General query functions
Float getSurfaceArea () const
 Return the total surface area. More...
 
AABB getAABB () const
 Return a bounding box containing the mesh. More...
 
AABBgetAABB ()
 Return a bounding box containing the mesh. More...
 
ref< TriMeshcreateTriMesh ()
 Create a triangle mesh approximation of this shape. More...
 
Access to the stored triangle mesh
size_t getTriangleCount () const
 Return the number of triangles. More...
 
size_t getVertexCount () const
 Return the number of vertices. More...
 
const TrianglegetTriangles () const
 Return the triangle list (const version) More...
 
TrianglegetTriangles ()
 Return the triangle list. More...
 
const PointgetVertexPositions () const
 Return the vertex positions (const version) More...
 
PointgetVertexPositions ()
 Return the vertex positions. More...
 
const NormalgetVertexNormals () const
 Return the vertex normals (const version) More...
 
NormalgetVertexNormals ()
 Return the vertex normals. More...
 
bool hasVertexNormals () const
 Does the mesh have vertex normals? More...
 
const Color3getVertexColors () const
 Return the vertex colors (const version) More...
 
Color3getVertexColors ()
 Return the vertex colors. More...
 
bool hasVertexColors () const
 Does the mesh have vertex colors? More...
 
const Point2getVertexTexcoords () const
 Return the vertex texture coordinates (const version) More...
 
Point2getVertexTexcoords ()
 Return the vertex texture coordinates. More...
 
bool hasVertexTexcoords () const
 Does the mesh have vertex texture coordinates? More...
 
const TangentSpacegetUVTangents () const
 Return the per-triangle UV tangents (const version) More...
 
TangentSpacegetUVTangents ()
 Return the per-triangle UV tangents. More...
 
bool hasUVTangents () const
 Does the mesh have UV tangent information? More...
 
Sampling routines
void samplePosition (PositionSamplingRecord &pRec, const Point2 &sample) const
 Sample a point on the surface of this shape instance (with respect to the area measure) More...
 
Float pdfPosition (const PositionSamplingRecord &pRec) const
 Query the probability density of samplePosition() for a particular point on the surface. More...
 
- Public Member Functions inherited from mitsuba::Shape
virtual std::string getName () const
 Return the name of this shape (e.g. the filename) More...
 
virtual bool isCompound () const
 Is this a compound shape consisting of several sub-objects? More...
 
virtual ShapegetElement (int i)
 Return a sub-element of a compound shape. More...
 
virtual AABB getClippedAABB (const AABB &box) const
 Returns the minimal axis-aligned bounding box of this shape when clipped to another bounding box. More...
 
virtual bool rayIntersect (const Ray &ray, Float mint, Float maxt, Float &t, void *temp) const
 Fast ray intersection test. More...
 
virtual bool rayIntersect (const Ray &ray, Float mint, Float maxt) const
 Fast ray intersection test for visibility queries. More...
 
virtual void fillIntersectionRecord (const Ray &ray, const void *temp, Intersection &its) const
 Given that an intersection has been found, create a detailed intersection record. More...
 
void getCurvature (const Intersection &its, Float &H, Float &K, bool shadingFrame=true) const
 Compute the Gaussian and mean curvature at the given surface intersection. More...
 
virtual void adjustTime (Intersection &its, Float time) const
 
virtual const KDTreeBase< AABB > * getKDTree () const
 Return the internal kd-tree of this shape (if any) More...
 
virtual void sampleDirect (DirectSamplingRecord &dRec, const Point2 &sample) const
 Sample a point on the surface of this shape instance (with respect to the solid angle measure) More...
 
virtual Float pdfDirect (const DirectSamplingRecord &dRec) const
 Query the probability density of sampleDirect() for a particular point on the surface. More...
 
bool isMediumTransition () const
 Does the surface of this shape mark a medium transition? More...
 
MediumgetInteriorMedium ()
 Return the medium that lies on the interior of this shape (NULL == vacuum) More...
 
const MediumgetInteriorMedium () const
 Return the medium that lies on the interior of this shape (NULL == vacuum, const version) More...
 
MediumgetExteriorMedium ()
 Return the medium that lies on the exterior of this shape (NULL == vacuum) More...
 
const MediumgetExteriorMedium () const
 Return the medium that lies on the exterior of this shape (NULL == vacuum, const version) More...
 
bool hasSubsurface () const
 Does this shape have a sub-surface integrator? More...
 
SubsurfacegetSubsurface ()
 Return the associated sub-surface integrator. More...
 
const SubsurfacegetSubsurface () const
 Return the associated sub-surface integrator. More...
 
bool isEmitter () const
 Is this shape also an area emitter? More...
 
EmittergetEmitter ()
 Return the associated emitter (if any) More...
 
const EmittergetEmitter () const
 Return the associated emitter (if any) More...
 
void setEmitter (Emitter *emitter)
 Set the emitter of this shape. More...
 
bool isSensor () const
 Is this shape also an area sensor? More...
 
SensorgetSensor ()
 Return the associated sensor (if any) More...
 
const SensorgetSensor () const
 Return the associated sensor (if any) More...
 
bool hasBSDF () const
 Does the shape have a BSDF? More...
 
const BSDFgetBSDF () const
 Return the shape's BSDF. More...
 
BSDFgetBSDF ()
 Return the shape's BSDF. More...
 
void setBSDF (BSDF *bsdf)
 Set the BSDF of this shape. More...
 
void copyAttachments (Shape *shape)
 Copy attachments (BSDF, Emitter, ..) from another shape. More...
 
void addChild (const std::string &name, ConfigurableObject *child)
 Add a child (e.g. a emitter/sub surface integrator) to this shape. More...
 
void addChild (ConfigurableObject *child)
 Add an unnamed child. More...
 
- Public Member Functions inherited from mitsuba::ConfigurableObject
virtual void setParent (ConfigurableObject *parent)
 Notify the ConfigurableObject instance about its parent object. More...
 
void addChild (ConfigurableObject *child)
 Add an unnamed child. More...
 
const std::string & getID () const
 Return the identifier associated with this instance (or "unnamed") More...
 
void setID (const std::string &name)
 Set the identifier associated with this instance. More...
 
const PropertiesgetProperties () const
 Return the properties object that was originally used to create this instance. More...
 
- Public Member Functions inherited from mitsuba::SerializableObject
 SerializableObject (Stream *stream, InstanceManager *manager)
 Unserialize a serializable object. More...
 
- Public Member Functions inherited from Object
 Object ()
 Construct a new object. More...
 
int getRefCount () const
 Return the current reference count. More...
 
void incRef () const
 Increase the reference count of the object by one. More...
 
void decRef (bool autoDeallocate=true) const
 Decrease the reference count of the object and possibly deallocate it. More...
 

Static Public Attributes

static Classm_theClass
 
- Static Public Attributes inherited from mitsuba::Shape
static Classm_theClass
 
- Static Public Attributes inherited from mitsuba::ConfigurableObject
static Classm_theClass
 
- Static Public Attributes inherited from mitsuba::SerializableObject
static Classm_theClass
 
- Static Public Attributes inherited from Object
static Classm_theClass
 Pointer to the object's class descriptor. More...
 

Protected Member Functions

 TriMesh (const Properties &props)
 Create a new triangle mesh. More...
 
virtual ~TriMesh ()
 Virtual destructor. More...
 
void loadCompressed (Stream *stream, int idx=0)
 Load a Mitsuba compressed triangle mesh substream. More...
 
void prepareSamplingTable ()
 Prepare internal tables for sampling uniformly wrt. area. More...
 
- Protected Member Functions inherited from mitsuba::Shape
 Shape (const Properties &props)
 Create a new shape. More...
 
 Shape (Stream *stream, InstanceManager *manager)
 Unserialize a shape. More...
 
virtual ~Shape ()
 Virtual destructor. More...
 
- Protected Member Functions inherited from mitsuba::ConfigurableObject
virtual ~ConfigurableObject ()
 Virtual destructor. More...
 
 ConfigurableObject (const Properties &props)
 Construct a configurable object. More...
 
 ConfigurableObject (Stream *stream, InstanceManager *manager)
 Unserialize a configurable object. More...
 
- Protected Member Functions inherited from mitsuba::SerializableObject
 SerializableObject ()
 Construct a serializable object. More...
 
virtual ~SerializableObject ()
 Virtual deconstructor. More...
 
- Protected Member Functions inherited from Object
virtual ~Object ()
 Virtual private deconstructor. (Will only be called by ref) More...
 

Static Protected Member Functions

static short readHeader (Stream *stream)
 Reads the header information of a compressed file, returning the version ID. More...
 
static size_t readOffset (Stream *stream, short version, int idx)
 Read the idx-th entry from the offset diccionary at the end of the stream, which has to be open already, given the file version tag. This function modifies the position of the stream. More...
 
static int readOffsetDictionary (Stream *stream, short version, std::vector< size_t > &outOffsets)
 Read the entirety of the end-of-file offset dictionary from the already open stream, replacing the contents of the input vector. If the file is not large enough the function returns -1 and does not modify the vector. This function modifies the position of the stream. More...
 

Protected Attributes

AABB m_aabb
 
Trianglem_triangles
 
Pointm_positions
 
Normalm_normals
 
Point2m_texcoords
 
TangentSpacem_tangents
 
Color3m_colors
 
size_t m_triangleCount
 
size_t m_vertexCount
 
bool m_flipNormals
 
bool m_faceNormals
 
DiscreteDistribution m_areaDistr
 
Float m_surfaceArea
 
Float m_invSurfaceArea
 
ref< Mutexm_mutex
 
- Protected Attributes inherited from mitsuba::Shape
std::string m_name
 
ref< BSDFm_bsdf
 
ref< Subsurfacem_subsurface
 
ref< Emitterm_emitter
 
ref< Sensorm_sensor
 
ref< Mediumm_interiorMedium
 
ref< Mediumm_exteriorMedium
 
- Protected Attributes inherited from mitsuba::ConfigurableObject
Properties m_properties
 

Miscellaneous

void computeUVTangents ()
 Generate per-triangle space basis vectors from a user-specified set of UV coordinates. More...
 
void computeNormals (bool force=false)
 Generate smooth vertex normals? More...
 
void rebuildTopology (Float maxAngle)
 Rebuild the mesh so that adjacent faces with a dihedral angle greater than maxAngle degrees are topologically disconnected. More...
 
void serialize (Stream *stream, InstanceManager *manager) const
 Serialize to a file/network stream. More...
 
void serialize (Stream *stream) const
 Serialize to a file/network stream. More...
 
virtual void configure ()
 Build a discrete probability distribution for sampling. More...
 
void getNormalDerivative (const Intersection &its, Vector &dndu, Vector &dndv, bool shadingFrame) const
 Return the derivative of the normal vector with respect to the UV parameterization. More...
 
size_t getPrimitiveCount () const
 Return the number of primitives (triangles, hairs, ..) contributed to the scene by this shape. More...
 
size_t getEffectivePrimitiveCount () const
 Return the number of primitives (triangles, hairs, ..) contributed to the scene by this shape. More...
 
void writeOBJ (const fs::path &path) const
 Export a Wavefront OBJ version of this file. More...
 
void writePLY (const fs::path &path) const
 Export a Stanford PLY version of this file. More...
 
std::string toString () const
 Return a string representation. More...
 
static ref< TriMeshfromBlender (const std::string &name, size_t faceCount, void *facePtr, size_t vertexCount, void *vertexPtr, void *uvPtr, void *colPtr, short matNr)
 Import a shape from the Blender in-memory representation. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static void staticInitialization ()
 Initializes the built-in reference count debugger (if enabled) More...
 
static void staticShutdown ()
 Free the memory taken by staticInitialization() More...
 

Detailed Description

Abstract triangle mesh base class.

Constructor & Destructor Documentation

mitsuba::TriMesh::TriMesh ( const std::string &  name,
size_t  triangleCount,
size_t  vertexCount,
bool  hasNormals = false,
bool  hasTexcoords = false,
bool  hasVertexColors = false,
bool  flipNormals = false,
bool  faceNormals = false 
)

Create a new, empty triangle mesh with the specified state.

mitsuba::TriMesh::TriMesh ( Stream stream,
InstanceManager manager 
)

Unserialize a triangle mesh.

mitsuba::TriMesh::TriMesh ( Stream stream,
int  idx = 0 
)

Unserialize a triangle mesh.

This is an alternative routine, which only loads triangle data (no BSDF, Sub-surface integrator, etc.) in a format that will remain stable as Mitsuba evolves. The files can optionally contain multiple meshes – in that case, the specified index determines which one to load.

mitsuba::TriMesh::TriMesh ( const Properties props)
protected

Create a new triangle mesh.

virtual mitsuba::TriMesh::~TriMesh ( )
protectedvirtual

Virtual destructor.

Member Function Documentation

void mitsuba::TriMesh::computeNormals ( bool  force = false)

Generate smooth vertex normals?

Parameters
forceWhen this parameter is set to true, the function generates normals even when there are already existing ones.
void mitsuba::TriMesh::computeUVTangents ( )

Generate per-triangle space basis vectors from a user-specified set of UV coordinates.

Will throw an exception when no UV coordinates are associated with the mesh.

virtual void mitsuba::TriMesh::configure ( )
virtual

Build a discrete probability distribution for sampling.

Called once while loading the scene

Reimplemented from mitsuba::Shape.

ref<TriMesh> mitsuba::TriMesh::createTriMesh ( )
virtual

Create a triangle mesh approximation of this shape.

Since instances are already triangle meshes, the implementation just returns a pointer to this.

Reimplemented from mitsuba::Shape.

static ref<TriMesh> mitsuba::TriMesh::fromBlender ( const std::string &  name,
size_t  faceCount,
void *  facePtr,
size_t  vertexCount,
void *  vertexPtr,
void *  uvPtr,
void *  colPtr,
short  matNr 
)
static

Import a shape from the Blender in-memory representation.

AABB mitsuba::TriMesh::getAABB ( ) const
virtual

Return a bounding box containing the mesh.

Implements mitsuba::Shape.

AABB& mitsuba::TriMesh::getAABB ( )
inline

Return a bounding box containing the mesh.

virtual const Class* mitsuba::TriMesh::getClass ( ) const
virtual

Retrieve this object's class.

Reimplemented from mitsuba::Shape.

size_t mitsuba::TriMesh::getEffectivePrimitiveCount ( ) const
virtual

Return the number of primitives (triangles, hairs, ..) contributed to the scene by this shape.

Includes instanced geometry

Implements mitsuba::Shape.

void mitsuba::TriMesh::getNormalDerivative ( const Intersection its,
Vector dndu,
Vector dndv,
bool  shadingFrame 
) const
virtual

Return the derivative of the normal vector with respect to the UV parameterization.

This can be used to compute Gaussian and principal curvatures, amongst other things.

Parameters
itsIntersection record associated with the query
dnduParameter used to store the partial derivative of the normal vector with respect to u
dndvParameter used to store the partial derivative of the normal vector with respect to v
shadingFrameSpecifies whether to compute the derivative of the geometric or shading normal of the surface

Reimplemented from mitsuba::Shape.

size_t mitsuba::TriMesh::getPrimitiveCount ( ) const
virtual

Return the number of primitives (triangles, hairs, ..) contributed to the scene by this shape.

Does not include instanced geometry

Implements mitsuba::Shape.

Float mitsuba::TriMesh::getSurfaceArea ( ) const
virtual

Return the total surface area.

Reimplemented from mitsuba::Shape.

size_t mitsuba::TriMesh::getTriangleCount ( ) const
inline

Return the number of triangles.

const Triangle* mitsuba::TriMesh::getTriangles ( ) const
inline

Return the triangle list (const version)

Triangle* mitsuba::TriMesh::getTriangles ( )
inline

Return the triangle list.

const TangentSpace* mitsuba::TriMesh::getUVTangents ( ) const
inline

Return the per-triangle UV tangents (const version)

TangentSpace* mitsuba::TriMesh::getUVTangents ( )
inline

Return the per-triangle UV tangents.

const Color3* mitsuba::TriMesh::getVertexColors ( ) const
inline

Return the vertex colors (const version)

Color3* mitsuba::TriMesh::getVertexColors ( )
inline

Return the vertex colors.

size_t mitsuba::TriMesh::getVertexCount ( ) const
inline

Return the number of vertices.

const Normal* mitsuba::TriMesh::getVertexNormals ( ) const
inline

Return the vertex normals (const version)

Normal* mitsuba::TriMesh::getVertexNormals ( )
inline

Return the vertex normals.

const Point* mitsuba::TriMesh::getVertexPositions ( ) const
inline

Return the vertex positions (const version)

Point* mitsuba::TriMesh::getVertexPositions ( )
inline

Return the vertex positions.

const Point2* mitsuba::TriMesh::getVertexTexcoords ( ) const
inline

Return the vertex texture coordinates (const version)

Point2* mitsuba::TriMesh::getVertexTexcoords ( )
inline

Return the vertex texture coordinates.

bool mitsuba::TriMesh::hasUVTangents ( ) const
inline

Does the mesh have UV tangent information?

bool mitsuba::TriMesh::hasVertexColors ( ) const
inline

Does the mesh have vertex colors?

bool mitsuba::TriMesh::hasVertexNormals ( ) const
inline

Does the mesh have vertex normals?

bool mitsuba::TriMesh::hasVertexTexcoords ( ) const
inline

Does the mesh have vertex texture coordinates?

void mitsuba::TriMesh::loadCompressed ( Stream stream,
int  idx = 0 
)
protected

Load a Mitsuba compressed triangle mesh substream.

Float mitsuba::TriMesh::pdfPosition ( const PositionSamplingRecord pRec) const
virtual

Query the probability density of samplePosition() for a particular point on the surface.

This method will generally return the inverse of the surface area.

Parameters
pRecA position record, which will be used to return the sampled position, as well as auxilary information about the sample.

Reimplemented from mitsuba::Shape.

void mitsuba::TriMesh::prepareSamplingTable ( )
protected

Prepare internal tables for sampling uniformly wrt. area.

static short mitsuba::TriMesh::readHeader ( Stream stream)
staticprotected

Reads the header information of a compressed file, returning the version ID.

This function assumes the stream is at the beginning of the compressed file and leaves the stream located right after the header.

static size_t mitsuba::TriMesh::readOffset ( Stream stream,
short  version,
int  idx 
)
staticprotected

Read the idx-th entry from the offset diccionary at the end of the stream, which has to be open already, given the file version tag. This function modifies the position of the stream.

static int mitsuba::TriMesh::readOffsetDictionary ( Stream stream,
short  version,
std::vector< size_t > &  outOffsets 
)
staticprotected

Read the entirety of the end-of-file offset dictionary from the already open stream, replacing the contents of the input vector. If the file is not large enough the function returns -1 and does not modify the vector. This function modifies the position of the stream.

void mitsuba::TriMesh::rebuildTopology ( Float  maxAngle)

Rebuild the mesh so that adjacent faces with a dihedral angle greater than maxAngle degrees are topologically disconnected.

On the other hand, if the angle is less than maxAngle, the code ensures that the faces reference the same vertices. This step is very useful as a pre-process when generating high-quality smooth shading normals on meshes with creases. Note: this function is fairly memory intensive and will require approximately three 3x the storate used by the input mesh. It will never try to merge vertices with equal positions but different UV coordinates or vertex colors.

void mitsuba::TriMesh::samplePosition ( PositionSamplingRecord pRec,
const Point2 sample 
) const
virtual

Sample a point on the surface of this shape instance (with respect to the area measure)

The returned sample density will be uniform over the surface.

Parameters
pRecA position record, which will be used to return the sampled position, as well as auxilary information about the sample.
sampleA uniformly distributed 2D vector

Reimplemented from mitsuba::Shape.

void mitsuba::TriMesh::serialize ( Stream stream,
InstanceManager manager 
) const
virtual

Serialize to a file/network stream.

Reimplemented from mitsuba::Shape.

void mitsuba::TriMesh::serialize ( Stream stream) const

Serialize to a file/network stream.

This is an alternative routine, which only loads triangle data (no BSDF, Sub-surface integrator, etc.) in a format that will remain stable as Mitsuba evolves.

std::string mitsuba::TriMesh::toString ( ) const
virtual

Return a string representation.

Reimplemented from Object.

void mitsuba::TriMesh::writeOBJ ( const fs::path &  path) const

Export a Wavefront OBJ version of this file.

void mitsuba::TriMesh::writePLY ( const fs::path &  path) const

Export a Stanford PLY version of this file.

Member Data Documentation

AABB mitsuba::TriMesh::m_aabb
protected
DiscreteDistribution mitsuba::TriMesh::m_areaDistr
protected
Color3* mitsuba::TriMesh::m_colors
protected
bool mitsuba::TriMesh::m_faceNormals
protected
bool mitsuba::TriMesh::m_flipNormals
protected
Float mitsuba::TriMesh::m_invSurfaceArea
protected
ref<Mutex> mitsuba::TriMesh::m_mutex
protected
Normal* mitsuba::TriMesh::m_normals
protected
Point* mitsuba::TriMesh::m_positions
protected
Float mitsuba::TriMesh::m_surfaceArea
protected
TangentSpace* mitsuba::TriMesh::m_tangents
protected
Point2* mitsuba::TriMesh::m_texcoords
protected
Class* mitsuba::TriMesh::m_theClass
static
size_t mitsuba::TriMesh::m_triangleCount
protected
Triangle* mitsuba::TriMesh::m_triangles
protected
size_t mitsuba::TriMesh::m_vertexCount
protected

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