CUGL 2.0
Cornell University Game Library
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
cugl::Geometry Class Reference

#include <CUGeometry.h>

Public Types

enum  Value : uint8_t { IMPLICIT, POINTS, PATH, SOLID }
 

Public Member Functions

 Geometry ()=default
 
constexpr Geometry (Value val)
 
 operator Value () const
 
 operator bool ()=delete
 
GLuint glCommand () const
 
bool matches (const std::vector< Uint32 > &indices) const
 
bool matches (const Uint32 *indices, size_t size) const
 
std::vector< Uint32 > index (const std::vector< Vec2 > &vertices) const
 
std::vector< Uint32 > index (const std::vector< float > &vertices) const
 
std::vector< Uint32 > index (const float *vertices, size_t size) const
 
std::unordered_set< Uint32 > exterior (const std::vector< Uint32 > indices) const
 
std::unordered_set< Uint32 > exterior (const Uint32 *indices, size_t size) const
 
std::vector< std::vector< Uint32 > > boundaries (const std::vector< Uint32 > &indices) const
 
std::vector< std::vector< Uint32 > > boundaries (const Uint32 *indices, size_t size) const
 

Static Public Member Functions

static Geometry categorize (const std::vector< Uint32 > &indices)
 
static Geometry categorize (const Uint32 *indices, size_t size)
 

Detailed Description

This class (enum) is used to provide meaning to a set of vertex indices.

Rendering classes should use this type as a hint for how to render a polygon. In particular, the method glCommand() returns an OpenGL command corresponding the index geometry.

There is not a one-to-one correspondence between geometries and OpenGL drawing commands. Geometries are concerned with structure, not the optimal organization of indices. So we do not make a distinction between triangles, triangle strips, or triangle fans.

In fact, the geometries supported all correspond to decomposable indices. These are the OpenGL commands TRIANGLES, LINES, or POINTS. These correspond to indices that we can easily split and combine on vertex concatenation.

Member Enumeration Documentation

◆ Value

enum cugl::Geometry::Value : uint8_t

The geometry values

This enum provides the values for this enum class, but the code in this class allows us to "skip over" it. That is, we can write Geometry::IMPLICIT in place of Geometry::Value::IMPLICIT, and so on. So we can ignore this enum.

Enumerator
IMPLICIT 

This geometry corresponds to an empty set of vertices.

In this case the geometry is inferred from the vertex order. Such an object is useful for pure math computations, but has no drawing mesh.

POINTS 

This geometry corresponds to an unstructured set of indices..

In this case indices represent the vertices that are relevant. Vertices not in the index set are ignored.

PATH 

This geometry represents an open path outline.

The indices are a sequence of line segments. That is, the number of indices is divisible by two, with each pair forming a segment. These segments may or be linked to each other.

SOLID 

This geometry represents a solid shape with a triangulation.

The indices are a sequence of triangles. That is, the number of indices is divisible by three, with each triplet forming a triangle.

Constructor & Destructor Documentation

◆ Geometry() [1/2]

cugl::Geometry::Geometry ( )
default

Disable the explicity Geomtry constructor

◆ Geometry() [2/2]

constexpr cugl::Geometry::Geometry ( Value  val)
inlineconstexpr

Construct a geometry with one of the enumeration values

Parameters
valThe enumeration value

Member Function Documentation

◆ boundaries() [1/2]

std::vector<std::vector<Uint32> > cugl::Geometry::boundaries ( const std::vector< Uint32 > &  indices) const

Returns the connected boundary components for this geometry.

This method allows us to reconstruct the exterior boundary of a solid shape, or to compose a pathwise connected curve into components.

For the geometry PATH, the elements of the outer array are connected links of line segments, with the indices listed in order of the path traversal. A closed path only has one component, so the outer array will only have one element. An open path may have several components if there are discontinuities in the path. IMPLICIT geometries are treated as if they were closed a closed path.

For SOLID, this method detriangulates the mesh, returning the outer hull, and discarding any interior points. This hull need not be convex (as concave or convex cannot be inferred from indices alone). If the mesh represents a simple polygon, only one boundary will be returned. If the mesh is not continuous, the outer array will contain the boundary of each disjoint polygon. If the mesh has holes, each hole will be returned as a separate boundary. There is no guarantee on the order of boundaries returned.

For POINTS, there are no connected components, so this method returns an array of single-element arrays. IMPLICIT returns null, as it is impossible to infer the boundaries without the vertices.

Parameters
indicesThe indices to process
Returns
the connected boundary components for this geometry.

◆ boundaries() [2/2]

std::vector<std::vector<Uint32> > cugl::Geometry::boundaries ( const Uint32 *  indices,
size_t  size 
) const

Returns the connected boundary components for this geometry.

This method allows us to reconstruct the exterior boundary of a solid shape, or to compose a pathwise connected curve into components.

For the geometry PATH, the elements of the outer array are connected links of line segments, with the indices listed in order of the path traversal. A closed path only has one component, so the outer array will only have one element. An open path may have several components if there are discontinuities in the path. IMPLICIT geometries are treated as if they were closed a closed path.

For SOLID, this method detriangulates the mesh, returning the outer hull, and discarding any interior points. This hull need not be convex (as concave or convex cannot be inferred from indices alone). If the mesh represents a simple polygon, only one boundary will be returned. If the mesh is not continuous, the outer array will contain the boundary of each disjoint polygon. If the mesh has holes, each hole will be returned as a separate boundary. There is no guarantee on the order of boundaries returned.

For POINTS, there are no connected components, so this method returns an array of single-element arrays. IMPLICIT returns null, as it is impossible to infer the boundaries without the vertices.

Parameters
indicesThe indices to process
sizeThe index size
Returns
the connected boundary components for this geometry.

◆ categorize() [1/2]

static Geometry cugl::Geometry::categorize ( const std::vector< Uint32 > &  indices)
static

Returns the best guess for the geometry of these indices

If the indices form a continuous link of pairs, then it will identify them as a PATH. Otherwise, this method can only guess at the geometry from the parity. If the number of indices is a multiple of 3, it assumes it is SOLID. If it is a multiple of 2, it assumes it is a PATH. If neither is true, it identifies these as POINTS. It is only IMPLICIT if indices are null or empty.

Parameters
indicesThe indices to analyze
Returns
the best guess for the geometry of these indices

◆ categorize() [2/2]

static Geometry cugl::Geometry::categorize ( const Uint32 *  indices,
size_t  size 
)
static

Returns the best guess for the geometry of these indices

If the indices form a continuous link of pairs, then it will identify them as a PATH. Otherwise, this method can only guess at the geometry from the parity. If the number of indices is a multiple of 3, it assumes it is SOLID. If it is a multiple of 2, it assumes it is a PATH. If neither is true, it identifies these as POINTS. It is only IMPLICIT if indices are null or empty.

Parameters
indicesThe indices to analyze
sizeThe index size
Returns
the best guess for the geometry of these indices

◆ exterior() [1/2]

std::unordered_set<Uint32> cugl::Geometry::exterior ( const std::vector< Uint32 >  indices) const

Returns the set of indices that are on a boundary of this geometry

This method is really only relevant for SOLID geometry. For other geometries, it simply returns a set of the indices. In the case of solid geometries, it identifies the outer hull (not necessarily convex).

This method can identify the outer hull using the graph properties of the triangle mesh. An internal node if the number of neighbors is the same as the number of attached triangles. An index that is not internal is external.

Unlike boundaries, this method does not order the boundary indices or decompose them into connected components.

Parameters
indicesThe indices to process
Returns
the set of indices that are on a boundary of this geometry

◆ exterior() [2/2]

std::unordered_set<Uint32> cugl::Geometry::exterior ( const Uint32 *  indices,
size_t  size 
) const

Returns the set of indices that are on a boundary of this geometry

This method is really only relevant for SOLID geometry. For other geometries, it simply returns a set of the indices. In the case of solid geometries, it identifies the outer hull (not necessarily convex).

This method can identify the outer hull using the graph properties of the triangle mesh. An internal node if the number of neighbors is the same as the number of attached triangles. An index that is not internal is external.

Unlike boundaries, this method does not order the boundary indices or decompose them into connected components.

Parameters
indicesThe indices to process
sizeThe index size
Returns
the set of indices that are on a boundary of this geometry

◆ glCommand()

GLuint cugl::Geometry::glCommand ( ) const

Returns the OpenGL drawing code for this geometry

If the geometry is IMPLICIT, this method returns -1.

Returns
the OpenGL drawing code for this geometry

◆ index() [1/3]

std::vector<Uint32> cugl::Geometry::index ( const float *  vertices,
size_t  size 
) const

Returns a canonical set of indices for the given vertex list

This takes a vertex list and generates a canonical index list that matches this geometry. For IMPLICIT, this will return an empty index set. For POINTS it is the index of all the vertices. For PATH, it is a linked set of segment indices of the vertices in order.

For SOLID it triangulates the vertices. For simplicity, this method does not support vertex lists with self-crossings. Such polygons will need to be decomposed first. This method always uses a SimpleTriangulator. If you wish to use another algorithm (such as ComplexTriangulator), you will need to generate the indices separately.

Parameters
verticesThe vertex list
sizeThe number of vertices
Returns
a canonical set of indices for the given vertex list

◆ index() [2/3]

std::vector<Uint32> cugl::Geometry::index ( const std::vector< float > &  vertices) const

Returns a canonical set of indices for the given vertex list

This takes a vertex list and generates a canonical index list that matches this geometry. For IMPLICIT, this will return an empty index set. For POINTS it is the index of all the vertices. For PATH, it is a linked set of segment indices of the vertices in order.

For SOLID it triangulates the vertices. For simplicity, this method does not support vertex lists with self-crossings. Such polygons will need to be decomposed first. This method always uses a SimpleTriangulator. If you wish to use another algorithm (such as ComplexTriangulator), you will need to generate the indices separately.

Parameters
verticesThe vertex list
Returns
a canonical set of indices for the given vertex list

◆ index() [3/3]

std::vector<Uint32> cugl::Geometry::index ( const std::vector< Vec2 > &  vertices) const

Returns a canonical set of indices for the given vertex list

This takes a vertex list and generates a canonical index list that matches this geometry. For IMPLICIT, this will return an empty index set. For POINTS it is the index of all the vertices. For PATH, it is a linked set of segment indices of the vertices in order.

For SOLID it triangulates the vertices. For simplicity, this method does not support vertex lists with self-crossings. Such polygons will need to be decomposed first. This method always uses a SimpleTriangulator. If you wish to use another algorithm (such as ComplexTriangulator), you will need to generate the indices separately.

Parameters
verticesThe vertex list
Returns
a canonical set of indices for the given vertex list

◆ matches() [1/2]

bool cugl::Geometry::matches ( const std::vector< Uint32 > &  indices) const

Returns true if the indices match this geometry.

If the geometry is SOLID, this method will only detect if the number of indices is divisible by three. For PATH, it will detect if the number of indices is not divisible by 2. Finally, IMPLICIT requires the indices be empty, but the geometry POINTS matches anything.

This method does not validate that the indices are with in range, as that requires knowledge of the vertices.

Parameters
indicesThe indices to test
Returns
true if the indices match this geometry.

◆ matches() [2/2]

bool cugl::Geometry::matches ( const Uint32 *  indices,
size_t  size 
) const

Returns true if the indices match this geometry.

If the geometry is SOLID, this method will only detect if the number of indices is divisible by three. For PATH, it will detect if the number of indices is not divisible by 2. Finally, IMPLICIT requires the indices be empty, but the geometry POINTS matches anything.

This method does not validate that the indices are with in range, as that requires knowledge of the vertices.

Parameters
indicesThe indices to test
sizeThe index size
Returns
true if the indices match this geometry.

◆ operator bool()

cugl::Geometry::operator bool ( )
explicitdelete

Prevent usage: if(geom)

◆ operator Value()

cugl::Geometry::operator Value ( ) const
inline

Returns the current value of this geometry.

This method enables both direct comparisons and swith statements.

Returns
the current value of this geometry.

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