Allolib  1.0
C++ Components For Interactive Multimedia
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
al::Isosurface Class Reference

Isosurface generated using marching cubes. More...

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/graphics/al_Isosurface.hpp>

Inheritance diagram for al::Isosurface:
al::Mesh

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< VertexVertices
 
typedef std::vector< NormalNormals
 
typedef std::vector< ColorColors
 
typedef std::vector< TexCoord1 > TexCoord1s
 
typedef std::vector< TexCoord2TexCoord2s
 
typedef std::vector< TexCoord3TexCoord3s
 
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
 
IsosurfacefieldDims (int nx, int ny, int nz)
 Set individual dimensions of the scalar field.
 
IsosurfacefieldDims (int n)
 Set all dimensions of the scalar field.
 
IsosurfacecellLengths (double dx, double dy, double dz)
 Set individual lengths of cell.
 
IsosurfacecellLengths (double v)
 Set all lengths of cell.
 
Isosurfacelevel (float v)
 Set isolevel.
 
Isosurfacenormals (bool v)
 Set whether to compute normals.
 
Isosurfacenormalize (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
 
IsosurfaceinBox (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.
 
Meshreset ()
 Reset all buffers.
 
void unitize (bool proportional=true)
 Scale all vertices to lie in [-1,1].
 
Meshscale (float x, float y, float z)
 Scale all vertices.
 
Meshscale (float s)
 
template<class T >
Meshscale (const Vec< 3, T > &v)
 
Meshtranslate (float x, float y, float z)
 Translate all vertices.
 
template<class T >
Meshtranslate (const Vec< 3, T > &v)
 
template<class T >
Meshtranslate (const T &v)
 
template<class T >
Meshtransform (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
 
Meshprimitive (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 ()
 
MeshrepeatLast ()
 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, IsosurfaceHashIntEdgeToVertex
 

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< EdgeTrianglemEdgeTriangles
 
std::vector< int > mEdgeToVertexArray
 
double mL [3]
 
int mNF [3]
 
int mEdgeIDOffsets [12]
 
float mIsolevel
 
VertexActionmVertexAction
 
bool mValidSurface
 
bool mComputeNormals
 
bool mNormalize
 
bool mInBox
 
Vertices mVertices
 
Normals mNormals
 
Colors mColors
 
TexCoord1s mTexCoord1s
 
TexCoord2s mTexCoord2s
 
TexCoord3s mTexCoord3s
 
Indices mIndices
 
Primitive mPrimitive
 

Detailed Description

Isosurface generated using marching cubes.

Definition at line 78 of file al_Isosurface.hpp.

Constructor & Destructor Documentation

◆ Isosurface()

al::Isosurface::Isosurface ( float  level = 0,
VertexAction action = noVertexAction 
)
Parameters
[in]levelvalue to construct surface on
[in]actionuser defined functor called upon adding a new edge vertex

Member Function Documentation

◆ addCell()

template<class T >
void al::Isosurface::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 
)
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.

◆ createNormalsMesh()

void al::Mesh::createNormalsMesh ( Mesh mesh,
float  length = 0.1,
bool  perFace = false 
)
inherited

Creates a mesh filled with lines for each normal of the source.

Parameters
[out]meshnormal lines
[in]lengthlength of normals
[in]perFacewhether normals line should be generated per face rather than per vertex

◆ equalizeBuffers()

void al::Mesh::equalizeBuffers ( )
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.

◆ generate()

template<class T >
void al::Isosurface::generate ( const T *  scalarField,
int  nX,
int  nY,
int  nZ,
float  cellLengthX,
float  cellLengthY,
float  cellLengthZ 
)
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.

◆ generateNormals()

void al::Mesh::generateNormals ( bool  normalize = true,
bool  equalWeightPerFace = false 
)
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.

Parameters
[in]normalizewhether to normalize normals
[in]equalWeightPerFacewhether to use an equal weighting of face normals rather than a weighting based on face areas

◆ getBounds()

void al::Mesh::getBounds ( Vec3f min,
Vec3f max 
) const
inherited

Get corners of bounding box of vertices.

Parameters
[out]minminimum corner of bounding box
[out]maxmaximum corner of bounding box

◆ inBox()

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.

◆ ribbonize() [1/2]

void al::Mesh::ribbonize ( float *  widths,
int  widthsStride = 1,
bool  faceBinormal = false 
)
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.

Parameters
[in]widthsArray specifying width of ribbon at each point along curve
[in]widthsStrideStride factor of width array
[in]faceBinormalIf true, surface faces binormal vector of curve. If false, surface faces normal vector of curve.

◆ ribbonize() [2/2]

void al::Mesh::ribbonize ( float  width = 0.04,
bool  faceBinormal = false 
)
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.

Parameters
[in]widthWidth of ribbon
[in]faceBinormalIf true, surface faces binormal vector of curve. If false, surface faces normal vector of curve.

Definition at line 194 of file al_Mesh.hpp.

◆ save()

bool al::Mesh::save ( const char *  filePath,
const char *  solidName = "",
bool  binary = true 
) const
inherited

Save mesh to file.

Currently supported are STL and PLY files.

Parameters
[in]filePathpath of file to save to
[in]solidNamesolid name defined within the file (optional)
[in]binarywrite data in binary form as opposed to ASCII
Returns
true on successful save, otherwise false

◆ savePLY()

bool al::Mesh::savePLY ( const char *  filePath,
const char *  solidName = "",
bool  binary = true 
) const
inherited

Save mesh to a PLY file.

This implementation saves an ASCII (as opposed to binary) PLY file.

Parameters
[in]filePathpath of file to save to
[in]solidNamesolid name defined within the file (optional)
[in]binarywrite data in binary form as opposed to ASCII
Returns
true on successful save, otherwise false

◆ saveSTL()

bool al::Mesh::saveSTL ( const char *  filePath,
const char *  solidName = "" 
) const
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.

Parameters
[in]filePathpath of file to save to
[in]solidNamesolid name defined within the file (optional)
Returns
true on successful save, otherwise false

◆ smooth()

void al::Mesh::smooth ( float  amount = 1,
int  weighting = 0 
)
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.

Parameters
[in]amountinterpolation fraction between original and smoothed result
[in]weighting0 = equal weight, 1 = inverse distance weight

◆ transform()

template<class T >
Mesh & al::Mesh::transform ( const Mat< 4, T > &  m,
int  begin = 0,
int  end = -1 
)
inherited

Transform vertices by projective transform matrix.

Parameters
[in]mprojective transform matrix
[in]beginbeginning index of vertices
[in]endending index of vertices, negative amounts specify distance from one past last element

Definition at line 398 of file al_Mesh.hpp.

◆ volumeLengths()

bool al::Isosurface::volumeLengths ( double &  volLengthX,
double &  volLengthY,
double &  volLengthZ 
) const

Gets the length, width, and height of the isosurface volume.

Returns
true upon success and false if the surface is not valid

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