Allolib
1.0
C++ Components For Interactive Multimedia
|
Isosurface generated using marching cubes. More...
Classes | |
struct | EdgeTriangle |
struct | EdgeVertex |
struct | IsosurfaceHashInt |
struct | NoVertexAction |
struct | VertexAction |
Public Types | |
enum | Primitive : unsigned int { POINTS = GL_POINTS , LINES = GL_LINES , LINE_STRIP = GL_LINE_STRIP , LINE_LOOP = GL_LINE_LOOP , TRIANGLES = GL_TRIANGLES , TRIANGLE_STRIP = GL_TRIANGLE_STRIP , TRIANGLE_FAN = GL_TRIANGLE_FAN , LINES_ADJACENCY = GL_LINES_ADJACENCY , LINE_STRIP_ADJACENCY = GL_LINE_STRIP_ADJACENCY , TRIANGLES_ADJACENCY = GL_TRIANGLES_ADJACENCY , TRIANGLE_STRIP_ADJACENCY = GL_TRIANGLE_STRIP_ADJACENCY } |
typedef Vec3f | Vertex |
typedef Vec3f | Normal |
typedef float | TexCoord1 |
typedef Vec2f | TexCoord2 |
typedef Vec3f | TexCoord3 |
typedef unsigned int | Index |
typedef std::vector< Vertex > | Vertices |
typedef std::vector< Normal > | Normals |
typedef std::vector< Color > | Colors |
typedef std::vector< TexCoord1 > | TexCoord1s |
typedef std::vector< TexCoord2 > | TexCoord2s |
typedef std::vector< TexCoord3 > | TexCoord3s |
typedef std::vector< Index > | Indices |
Public Member Functions | |
Isosurface (float level=0, VertexAction &action=noVertexAction) | |
int | fieldDim (int i) const |
Get a field dimension. | |
float | level () const |
Get isolevel. | |
bool | validSurface () const |
Returns true if a valid surface has been generated. | |
bool | volumeLengths (double &volLengthX, double &volLengthY, double &volLengthZ) const |
Gets the length, width, and height of the isosurface volume. More... | |
int | posID (int ix, int iy, int iz) const |
template<class VEC3I > | |
int | posID (const VEC3I &i3) const |
int | cellID (int ix, int iy, int iz) const |
int | edgeID (int cellID, int edgeNo) const |
Isosurface & | fieldDims (int nx, int ny, int nz) |
Set individual dimensions of the scalar field. | |
Isosurface & | fieldDims (int n) |
Set all dimensions of the scalar field. | |
Isosurface & | cellLengths (double dx, double dy, double dz) |
Set individual lengths of cell. | |
Isosurface & | cellLengths (double v) |
Set all lengths of cell. | |
Isosurface & | level (float v) |
Set isolevel. | |
Isosurface & | normals (bool v) |
Set whether to compute normals. | |
Isosurface & | normalize (bool v) |
Set whether to normalize normals (if being computed) | |
void | begin () |
Begin cell-at-a-time mode. | |
void | end () |
End cell-at-a-time mode. | |
template<class T > | |
void | addCell (int ix, int iy, int iz, const T &xyz, const T &Xyz, const T &xYz, const T &XYz, const T &xyZ, const T &XyZ, const T &xYZ, const T &XYZ) |
Add a cell from a scalar field. More... | |
void | addCell (const int *indices3, const float *values8) |
Add a cell from a scalar field. | |
template<class T > | |
void | generate (const T *scalarField) |
Generate isosurface from scalar field. | |
template<class T > | |
void | generate (const T *scalarField, int nX, int nY, int nZ, float cellLengthX, float cellLengthY, float cellLengthZ) |
Generate isosurface from scalar field. More... | |
template<class T > | |
void | generate (const T *scalarField, int n, float cellLength) |
void | vertexAction (VertexAction &a) |
const bool | inBox () const |
Isosurface & | inBox (bool v) |
Set whether isosurface is assumed to fit snugly within a box. More... | |
void | copy (Mesh const &m) |
void | getBounds (Vec3f &min, Vec3f &max) const |
Get corners of bounding box of vertices. More... | |
Vec3f | getCenter () const |
Get center of vertices. | |
void | compress () |
Generates indices for a set of vertices. | |
void | decompress () |
Convert indices (if any) to flat vertex buffers. | |
void | equalizeBuffers () |
Extend buffers to match number of vertices. More... | |
void | merge (const Mesh &src) |
Append buffers from another mesh: | |
void | toTriangles () |
Convert triangle strip to triangles. | |
Mesh & | reset () |
Reset all buffers. | |
void | unitize (bool proportional=true) |
Scale all vertices to lie in [-1,1]. | |
Mesh & | scale (float x, float y, float z) |
Scale all vertices. | |
Mesh & | scale (float s) |
template<class T > | |
Mesh & | scale (const Vec< 3, T > &v) |
Mesh & | translate (float x, float y, float z) |
Translate all vertices. | |
template<class T > | |
Mesh & | translate (const Vec< 3, T > &v) |
template<class T > | |
Mesh & | translate (const T &v) |
template<class T > | |
Mesh & | transform (const Mat< 4, T > &m, int begin=0, int end=-1) |
Transform vertices by projective transform matrix. More... | |
void | generateNormals (bool normalize=true, bool equalWeightPerFace=false) |
Generates normals for a set of vertices. More... | |
void | invertNormals () |
Invert direction of normals. | |
void | createNormalsMesh (Mesh &mesh, float length=0.1, bool perFace=false) |
Creates a mesh filled with lines for each normal of the source. More... | |
void | ribbonize (float width=0.04, bool faceBinormal=false) |
Ribbonize curve. More... | |
void | ribbonize (float *widths, int widthsStride=1, bool faceBinormal=false) |
Ribbonize curve. More... | |
void | smooth (float amount=1, int weighting=0) |
Smooths a triangle mesh. More... | |
Primitive | primitive () const |
Mesh & | primitive (Primitive p) |
Set geometric primitive. | |
const std::vector< Vertex > & | vertices () const |
Vertices & | vertices () |
const std::vector< Normal > & | normals () const |
Normals & | normals () |
const std::vector< Color > & | colors () const |
Colors & | colors () |
const std::vector< TexCoord1 > & | texCoord1s () const |
TexCoord1s & | texCoord1s () |
const std::vector< TexCoord2 > & | texCoord2s () const |
TexCoord2s & | texCoord2s () |
const std::vector< TexCoord3 > & | texCoord3s () const |
TexCoord3s & | texCoord3s () |
const std::vector< Index > & | indices () const |
Indices & | indices () |
Mesh & | repeatLast () |
Repeat last vertex element(s) | |
void | index (unsigned int i) |
Append index to index buffer. | |
template<class Tindex > | |
void | index (const Tindex *buf, int size, Tindex indexOffset=0) |
Append indices to index buffer. | |
template<class... Indices> | |
void | index (unsigned i, Indices... indices) |
void | color (const Color &v) |
Append color to color buffer. | |
void | color (const HSV &v) |
Append color to color buffer. | |
void | color (const RGB &v) |
Append color to color buffer. | |
void | color (float r, float g, float b, float a=1) |
Append color to color buffer. | |
template<class T > | |
void | color (const Vec< 4, T > &v) |
Append color to color buffer. | |
template<class T > | |
void | color (const T *src, int numColors) |
Append colors from flat array. | |
void | normal (float x, float y, float z=0) |
Append normal to normal buffer. | |
void | normal (const Normal &v) |
Append normal to normal buffer. | |
template<class T > | |
void | normal (const Vec< 2, T > &v, float z=0) |
Append normal to normal buffer. | |
template<class T > | |
void | normal (const T *src, int numNormals) |
Append normals from flat array. | |
void | texCoord (float u) |
Append texture coordinate to 1D texture coordinate buffer. | |
void | texCoord (float u, float v) |
Append texture coordinate to 2D texture coordinate buffer. | |
template<class T > | |
void | texCoord (const Vec< 2, T > &v) |
Append texture coordinate to 2D texture coordinate buffer. | |
void | texCoord (float u, float v, float w) |
Append texture coordinate to 3D texture coordinate buffer. | |
template<class T > | |
void | texCoord (const Vec< 3, T > &v) |
Append texture coordinate to 3D texture coordinate buffer. | |
void | vertex (float x, float y, float z=0) |
Append vertex to vertex buffer. | |
void | vertex (const Vertex &v) |
Append vertex to vertex buffer. | |
template<class T > | |
void | vertex (const Vec< 2, T > &v, float z=0) |
Append vertex to vertex buffer. | |
template<class T > | |
void | vertex (const T *src, int numVerts) |
Append vertices from flat array. | |
template<class T > | |
void | vertex (const Vec< 3, T > *src, int numVerts) |
Append vertices to vertex buffer. | |
bool | save (const char *filePath, const char *solidName="", bool binary=true) const |
Save mesh to file. More... | |
bool | saveSTL (const char *filePath, const char *solidName="") const |
Save mesh to an STL file. More... | |
bool | savePLY (const char *filePath, const char *solidName="", bool binary=true) const |
Save mesh to a PLY file. More... | |
void | print (FILE *dst=stderr) const |
Print information about Mesh. | |
Static Public Attributes | |
static NoVertexAction | noVertexAction |
Protected Types | |
typedef std::unordered_map< int, int, IsosurfaceHashInt > | EdgeToVertex |
Protected Member Functions | |
EdgeVertex | calcIntersection (int nX, int nY, int nZ, int nEdgeNo, const float *vals) const |
void | addEdgeVertex (int x, int y, int z, int cellID, int edge, const float *vals) |
void | compressTriangles () |
Protected Attributes | |
EdgeToVertex | mEdgeToVertex |
std::vector< EdgeTriangle > | mEdgeTriangles |
std::vector< int > | mEdgeToVertexArray |
double | mL [3] |
int | mNF [3] |
int | mEdgeIDOffsets [12] |
float | mIsolevel |
VertexAction * | mVertexAction |
bool | mValidSurface |
bool | mComputeNormals |
bool | mNormalize |
bool | mInBox |
Vertices | mVertices |
Normals | mNormals |
Colors | mColors |
TexCoord1s | mTexCoord1s |
TexCoord2s | mTexCoord2s |
TexCoord3s | mTexCoord3s |
Indices | mIndices |
Primitive | mPrimitive |
Isosurface generated using marching cubes.
Definition at line 78 of file al_Isosurface.hpp.
al::Isosurface::Isosurface | ( | float | level = 0 , |
VertexAction & | action = noVertexAction |
||
) |
[in] | level | value to construct surface on |
[in] | action | user defined functor called upon adding a new edge vertex |
|
inline |
Add a cell from a scalar field.
This should be called in between calls to begin() and end().
Definition at line 186 of file al_Isosurface.hpp.
|
inherited |
Creates a mesh filled with lines for each normal of the source.
[out] | mesh | normal lines |
[in] | length | length of normals |
[in] | perFace | whether normals line should be generated per face rather than per vertex |
|
inherited |
Extend buffers to match number of vertices.
This will resize all populated buffers to match the size of the vertex buffer. Buffers are extended by copying their last element.
|
inline |
Generate isosurface from scalar field.
The total number of elements in the field is expected to be nX*nY*nZ. The field elements are located at the corners of the cuboidal cells used to generate the surface. Thus, the surface is evaluated on a total of (nX-1)*(nY-1)*(nZ-1) cells.
Definition at line 207 of file al_Isosurface.hpp.
|
inherited |
Generates normals for a set of vertices.
This method will generate a normal for each vertex in the buffer assuming the drawing primitive is either triangles or a triangle strip. Averaged vertex normals are generated if indices are present and, for triangles only, face normals are generated if no indices are present. This will replace any normals currently in use.
[in] | normalize | whether to normalize normals |
[in] | equalWeightPerFace | whether to use an equal weighting of face normals rather than a weighting based on face areas |
Get corners of bounding box of vertices.
[out] | min | minimum corner of bounding box |
[out] | max | maximum corner of bounding box |
Isosurface& al::Isosurface::inBox | ( | bool | v | ) |
Set whether isosurface is assumed to fit snugly within a box.
Setting this to true will speed up extraction when the isosurface is mostly dense and box shaped, i.e., a rectangular cuboid. If the isosurface is to be computed on sparse or irregularly shaped grid, then it is recommended to set this to false to save memory.
|
inherited |
Ribbonize curve.
This creates a two-dimensional ribbon from a one-dimensional space curve. The result is to be rendered with a triangle strip.
[in] | widths | Array specifying width of ribbon at each point along curve |
[in] | widthsStride | Stride factor of width array |
[in] | faceBinormal | If true, surface faces binormal vector of curve. If false, surface faces normal vector of curve. |
|
inlineinherited |
Ribbonize curve.
This creates a two-dimensional ribbon from a one-dimensional space curve. The result is to be rendered with a triangle strip.
[in] | width | Width of ribbon |
[in] | faceBinormal | If true, surface faces binormal vector of curve. If false, surface faces normal vector of curve. |
Definition at line 194 of file al_Mesh.hpp.
|
inherited |
Save mesh to file.
Currently supported are STL and PLY files.
[in] | filePath | path of file to save to |
[in] | solidName | solid name defined within the file (optional) |
[in] | binary | write data in binary form as opposed to ASCII |
|
inherited |
Save mesh to a PLY file.
This implementation saves an ASCII (as opposed to binary) PLY file.
[in] | filePath | path of file to save to |
[in] | solidName | solid name defined within the file (optional) |
[in] | binary | write data in binary form as opposed to ASCII |
|
inherited |
Save mesh to an STL file.
STL (STereoLithography) is a file format used widely for rapid prototyping. It contains only surface geometry (vertices and normals) as a list of triangular facets. This implementation saves an ASCII (as opposed to binary) STL file.
[in] | filePath | path of file to save to |
[in] | solidName | solid name defined within the file (optional) |
|
inherited |
Smooths a triangle mesh.
This smooths a triangle mesh using Laplacian (low-pass) filtering. New vertex positions are a weighted sum of their nearest neighbors. The number of vertices is not changed.
[in] | amount | interpolation fraction between original and smoothed result |
[in] | weighting | 0 = equal weight, 1 = inverse distance weight |
|
inherited |
Transform vertices by projective transform matrix.
[in] | m | projective transform matrix |
[in] | begin | beginning index of vertices |
[in] | end | ending index of vertices, negative amounts specify distance from one past last element |
Definition at line 398 of file al_Mesh.hpp.
bool al::Isosurface::volumeLengths | ( | double & | volLengthX, |
double & | volLengthY, | ||
double & | volLengthZ | ||
) | const |
Gets the length, width, and height of the isosurface volume.