![]() |
CUGL 2.0
Cornell University Game Library
|
#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) |
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.
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.
|
default |
Disable the explicity Geomtry constructor
|
inlineconstexpr |
Construct a geometry with one of the enumeration values
val | The enumeration value |
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.
indices | The indices to process |
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.
indices | The indices to process |
size | The index 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.
indices | The indices to analyze |
|
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.
indices | The indices to analyze |
size | The index size |
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.
indices | The indices to process |
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.
indices | The indices to process |
size | The index size |
GLuint cugl::Geometry::glCommand | ( | ) | const |
Returns the OpenGL drawing code for this geometry
If the geometry is IMPLICIT, this method returns -1.
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.
vertices | The vertex list |
size | The number of vertices |
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.
vertices | The vertex list |
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.
vertices | The vertex list |
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.
indices | The indices to test |
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.
indices | The indices to test |
size | The index size |
|
explicitdelete |
Prevent usage: if(geom)
|
inline |
Returns the current value of this geometry.
This method enables both direct comparisons and swith statements.