Cogs.Core
Namespaces | Classes | Typedefs | Enumerations | Functions
Cogs::Geometry Namespace Reference

Contains geometry calculations and generation. More...

Namespaces

namespace  ProfileGenerator
 Contains functionality for generating extrusion profiles.
 

Classes

struct  AdjacencyList_T
 Utility class for storing the face indexes a vertex belongs to. More...
 
struct  CrossSectionGenerator
 
struct  ExtrusionGenerator
 
class  Polygon
 Generic 2D concave or convex polygon. More...
 
struct  Vertex
 

Typedefs

typedef AdjacencyList_T< int32_t, 8 > AdjacencyList
 

Enumerations

enum  Location { Inside = -1 , Outside = 1 }
 

Functions

template<class IndexType , class AdjacencyListType , bool quads>
void generateAdjacencyInfo (const size_t numFaces, const IndexType *indices, const size_t positionOffset, std::vector< AdjacencyListType > &adjacencyList)
 Generates vertex adjacency info for the list of faces given by indices.
 
template<class PositionType , class IndexType , class NormalType , bool quads>
void calculateFaceNormals (const size_t numFaces, const PositionType *positions, const IndexType *indices, std::vector< NormalType > &faceNormals)
 Calculates face normals for the list of faces given.
 
template<class NormalType , class AdjacencyListType >
void calculateSmoothVertexNormals (NormalType *normals, const size_t numNormals, const std::vector< NormalType > &faceNormals, const size_t positionOffset, const std::vector< AdjacencyListType > &adjacencyList)
 Calculates smooth vertex normals from the list of face normals and adjacency info given.
 
template<class NormalType , class AdjacencyListType , class IndexType >
void calculateFacetVertexNormals (const std::vector< NormalType > &faceNormals, const std::vector< AdjacencyListType > &adjacencyList, const IndexType *indexes, const float creaseAngle, bool quads, NormalType *normals)
 Calculates per vertex facet normals.
 
template<class IndexType , bool quads>
void generateLinearIndexes (const size_t numFaces, IndexType *indexes)
 Generates a set of indexes from zero upwards for the amount of faces given.
 
template<class ValueType , class IndexType >
void reindexValues (const ValueType *inputValues, const IndexType *indexes, const size_t numFaces, const size_t numIndexesPerFace, ValueType *outputValues)
 Reindexes the input values into the output values based on the index array given.
 
template<class NormalType >
void correctZeroLengthNormals (NormalType *normals, const size_t numNormals)
 Corrects invalid normals (zero length) by setting them to the unit Z vector.
 
template<class NormalType >
void reverseNormalDirections (NormalType *normals, const size_t numNormals)
 Reverse the set of normals given.
 
template<class AdjacencyListType >
void addExtrusionSeamFaces (const size_t numFaces, size_t segmentCount, std::vector< AdjacencyListType > &adjacencyList)
 Adds the faces along the seam of an extrusion to the adjacency list of the seam vertexes.
 
template<class AdjacencyListType >
void addTriangleExtrusionSeamFaces (const size_t numFaces, size_t segmentCount, std::vector< AdjacencyListType > &adjacencyList)
 
template<typename VectorType , typename IndexType >
void generateNormals (VectorType *positions, const size_t numVertexes, IndexType *indexes, const size_t numIndexes, bool quads, bool flipNormals, bool correctNormals, std::vector< VectorType > &normals)
 Generate normals for the given shape.
 
template<typename VectorType , typename IndexType >
void generateNormals (const VectorType *positions, VectorType *normals, const size_t numPositions, const IndexType *indices, const size_t numIndices, bool flipNormals, bool correctNormals, bool quads, size_t positionOffset)
 Generate normals for the given faces.
 
template<typename VectorType , typename IndexType >
void generateExtrusionNormals (VectorType *positions, const size_t numVertexes, IndexType *indexes, const size_t numIndexes, int segmentCount, bool quads, bool flipNormals, std::vector< VectorType > &normals)
 Generate normals for an extrusion shape.
 
template<typename VectorType , typename IndexType , typename Vector2Type >
void generateFacetNormals (const VectorType *positions, const size_t numPositions, const IndexType *indexes, const size_t numIndexes, const Vector2Type *texCoords, bool quads, bool flipNormals, bool correctNormals, const float creaseAngle, bool createExtrusionSeam, const size_t segmentCount, std::vector< VectorType > &outputPositions, std::vector< VectorType > &outputNormals, std::vector< IndexType > &outputIndexes, std::vector< Vector2Type > *outputTexCoords)
 
bool projectToPlane (glm::vec3 rayOrigin, glm::vec3 rayDir, glm::vec3 planeOrigin, glm::vec3 planeDir, glm::vec3 &coordinates, float *pT=nullptr)
 
bool intersect (const Cogs::Geometry::BoundingBox &box, const glm::vec3 &origin, const glm::vec3 &direction, glm::vec3 &intersection, const bool)
 
bool intersect (const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &orig, const glm::vec3 &dir, glm::vec3 &intersection, glm::vec3 &barycentric, bool &front)
 Ray-Triangle intersection.
 
COGSFOUNDATION_API void generateQuadIndices (std::vector< uint32_t > &dest, size_t quadCount, uint32_t vertexNumber, bool sharedVertices)
 Generate indices for rendering the specified number of quads from four vertices starting from the given vertex number.
 
bool veryClose (const glm::vec3 &lhs, const glm::vec3 &rhs)
 Tests whether the two points are within one centimetre of each other.
 
void removeDuplicates (Vertex::List &vertices)
 Removes any adjacent vertices that are within five millimetres of their neighbours.
 
int calcLineSide (const glm::vec3 &start, const glm::vec3 &end, const glm::vec3 &point)
 Calculates which side of the line (start-end) the given point lies.
 
uint32_t findMatchingVertex (const glm::vec3 &vertex, const Vertex::List &vertices)
 Searches for the vertex at the specified location.
 
Location getVertexLocation (const Vertex &vertex, const Vertex::List &vertices)
 Determines whether the given vertex is located inside the polygon defined by the list of vertices.
 
Location findDivergenceForwards (const Vertex::List &mine, const Vertex::List &theirs, uint32_t myIdx, uint32_t theirIdx, uint32_t &myNextIdx, uint32_t &theirNextIdx)
 Trace a path from the two specified points (which are located at the same position) until they diverge.
 
bool generateIntersectionPoints (Vertex::List &mine, Vertex::List &theirs)
 Inserts additional vertices into the two provided lists at all the intersection points of the two polygons those lists represent.
 
bool findClosestVertices (const Vertex::List &mine, const Vertex::List &theirs, uint32_t &myPoint, uint32_t &theirPoint)
 Finds the closest vertices from the two polygons.
 
uint32_t findNextIntersection (const Vertex::List &vertices, uint32_t startIdx, bool wrap=true)
 Searches the provided list of vertices looking for the next one that is marked as being an intersection between the two polygons.
 

Detailed Description

Contains geometry calculations and generation.

Typedef Documentation

◆ AdjacencyList

Definition at line 88 of file NormalGenerator.h.

Enumeration Type Documentation

◆ Location

enum Cogs::Geometry::Location

Definition at line 10 of file Polygon.cpp.

Function Documentation

◆ addExtrusionSeamFaces()

template<class AdjacencyListType >
void Cogs::Geometry::addExtrusionSeamFaces ( const size_t  numFaces,
size_t  segmentCount,
std::vector< AdjacencyListType > &  adjacencyList 
)

Adds the faces along the seam of an extrusion to the adjacency list of the seam vertexes.

This ensures faces on ends of sections contribute to the normals of the face on the start of the section and vice versa.

Definition at line 273 of file NormalGenerator.h.

Referenced by generateExtrusionNormals().

◆ addTriangleExtrusionSeamFaces()

template<class AdjacencyListType >
void Cogs::Geometry::addTriangleExtrusionSeamFaces ( const size_t  numFaces,
size_t  segmentCount,
std::vector< AdjacencyListType > &  adjacencyList 
)

Definition at line 292 of file NormalGenerator.h.

◆ calcLineSide()

int Cogs::Geometry::calcLineSide ( const glm::vec3 &  start,
const glm::vec3 &  end,
const glm::vec3 &  point 
)

Calculates which side of the line (start-end) the given point lies.

A positive value means the point is on the left of the line (when looking along the line from its start), while a negative value means the point is on the right. *============================================================================================

Definition at line 76 of file Polygon.cpp.

◆ calculateFaceNormals()

template<class PositionType , class IndexType , class NormalType , bool quads>
void Cogs::Geometry::calculateFaceNormals ( const size_t  numFaces,
const PositionType *  positions,
const IndexType *  indices,
std::vector< NormalType > &  faceNormals 
)

Calculates face normals for the list of faces given.

Definition at line 115 of file NormalGenerator.h.

◆ calculateFacetVertexNormals()

template<class NormalType , class AdjacencyListType , class IndexType >
void Cogs::Geometry::calculateFacetVertexNormals ( const std::vector< NormalType > &  faceNormals,
const std::vector< AdjacencyListType > &  adjacencyList,
const IndexType *  indexes,
const float  creaseAngle,
bool  quads,
NormalType *  normals 
)

Calculates per vertex facet normals.

The vertex normal is averaged between the face normal of the face the vertex belongs to and the normals of other faces the same vertex is used by.

Definition at line 172 of file NormalGenerator.h.

◆ calculateSmoothVertexNormals()

template<class NormalType , class AdjacencyListType >
void Cogs::Geometry::calculateSmoothVertexNormals ( NormalType *  normals,
const size_t  numNormals,
const std::vector< NormalType > &  faceNormals,
const size_t  positionOffset,
const std::vector< AdjacencyListType > &  adjacencyList 
)

Calculates smooth vertex normals from the list of face normals and adjacency info given.

The vertex normals are averaged from all the face normals of faces sharing the vertex.

Definition at line 143 of file NormalGenerator.h.

Referenced by generateExtrusionNormals(), and generateNormals().

◆ correctZeroLengthNormals()

template<class NormalType >
void Cogs::Geometry::correctZeroLengthNormals ( NormalType *  normals,
const size_t  numNormals 
)

Corrects invalid normals (zero length) by setting them to the unit Z vector.

This is not necessarily correct, but in most cases invalid normals are caused by invalid faces so the normal will not contribute to the visual output.

Definition at line 248 of file NormalGenerator.h.

Referenced by generateNormals().

◆ findClosestVertices()

bool Cogs::Geometry::findClosestVertices ( const Vertex::List &  mine,
const Vertex::List &  theirs,
uint32_t &  myPoint,
uint32_t &  theirPoint 
)

Finds the closest vertices from the two polygons.

*============================================================================================

Definition at line 371 of file Polygon.cpp.

Referenced by Cogs::Geometry::Polygon::subtract().

◆ findDivergenceForwards()

Location Cogs::Geometry::findDivergenceForwards ( const Vertex::List &  mine,
const Vertex::List &  theirs,
uint32_t  myIdx,
uint32_t  theirIdx,
uint32_t &  myNextIdx,
uint32_t &  theirNextIdx 
)

Trace a path from the two specified points (which are located at the same position) until they diverge.

The path will trace either backwards or forwards around their polygon, but always forwards around ours. When we encounter a divergence in the paths we determine whether my path diverges into their polygon, or out away from it. *============================================================================================

Definition at line 136 of file Polygon.cpp.

References getVertexLocation().

Referenced by generateIntersectionPoints().

◆ findMatchingVertex()

uint32_t Cogs::Geometry::findMatchingVertex ( const glm::vec3 &  vertex,
const Vertex::List &  vertices 
)

Searches for the vertex at the specified location.

Returns the index of that vertex. *============================================================================================

Definition at line 91 of file Polygon.cpp.

Referenced by generateIntersectionPoints(), and Cogs::Geometry::Polygon::subtract().

◆ findNextIntersection()

uint32_t Cogs::Geometry::findNextIntersection ( const Vertex::List &  vertices,
uint32_t  startIdx,
bool  wrap = true 
)

Searches the provided list of vertices looking for the next one that is marked as being an intersection between the two polygons.

*============================================================================================

Definition at line 398 of file Polygon.cpp.

Referenced by Cogs::Geometry::Polygon::subtract().

◆ generateAdjacencyInfo()

template<class IndexType , class AdjacencyListType , bool quads>
void Cogs::Geometry::generateAdjacencyInfo ( const size_t  numFaces,
const IndexType *  indices,
const size_t  positionOffset,
std::vector< AdjacencyListType > &  adjacencyList 
)

Generates vertex adjacency info for the list of faces given by indices.

Definition at line 94 of file NormalGenerator.h.

◆ generateExtrusionNormals()

template<typename VectorType , typename IndexType >
void Cogs::Geometry::generateExtrusionNormals ( VectorType *  positions,
const size_t  numVertexes,
IndexType *  indexes,
const size_t  numIndexes,
int  segmentCount,
bool  quads,
bool  flipNormals,
std::vector< VectorType > &  normals 
)

Generate normals for an extrusion shape.

This method performs the same type of normal generation as the generic normal generation method, but has some special handling for extrusion shapes. It assumes the extrusion shape has duplicate vertices running along the spine of the extrusion at index 0 and segmentCount. These vertices are duplicated in order to support having unique texture coordinates for the first and last vertex, making a texture wrap from 0 to 1 around the shape.

To generate smooth normals for such a shape, the adjacency lists of the spine vertices has the respective last and first faces added to the first and last vertex.

Definition at line 383 of file NormalGenerator.h.

References addExtrusionSeamFaces(), calculateSmoothVertexNormals(), and reverseNormalDirections().

◆ generateFacetNormals()

template<typename VectorType , typename IndexType , typename Vector2Type >
void Cogs::Geometry::generateFacetNormals ( const VectorType *  positions,
const size_t  numPositions,
const IndexType *  indexes,
const size_t  numIndexes,
const Vector2Type *  texCoords,
bool  quads,
bool  flipNormals,
bool  correctNormals,
const float  creaseAngle,
bool  createExtrusionSeam,
const size_t  segmentCount,
std::vector< VectorType > &  outputPositions,
std::vector< VectorType > &  outputNormals,
std::vector< IndexType > &  outputIndexes,
std::vector< Vector2Type > *  outputTexCoords 
)

Definition at line 423 of file NormalGenerator.h.

◆ generateIntersectionPoints()

bool Cogs::Geometry::generateIntersectionPoints ( Vertex::List &  mine,
Vertex::List &  theirs 
)

Inserts additional vertices into the two provided lists at all the intersection points of the two polygons those lists represent.

*============================================================================================

Definition at line 211 of file Polygon.cpp.

References findDivergenceForwards(), findMatchingVertex(), getVertexLocation(), removeDuplicates(), and veryClose().

Referenced by Cogs::Geometry::Polygon::subtract().

◆ generateLinearIndexes()

template<class IndexType , bool quads>
void Cogs::Geometry::generateLinearIndexes ( const size_t  numFaces,
IndexType *  indexes 
)

Generates a set of indexes from zero upwards for the amount of faces given.

No two indexes will point to the same data.

E.g for triangles the array will be [0, 1, 2, -1, 3, 4, 5, -1 ...].

Definition at line 210 of file NormalGenerator.h.

◆ generateNormals() [1/2]

template<typename VectorType , typename IndexType >
void Cogs::Geometry::generateNormals ( const VectorType *  positions,
VectorType *  normals,
const size_t  numPositions,
const IndexType *  indices,
const size_t  numIndices,
bool  flipNormals,
bool  correctNormals,
bool  quads,
size_t  positionOffset 
)

Generate normals for the given faces.

Definition at line 334 of file NormalGenerator.h.

References calculateSmoothVertexNormals(), correctZeroLengthNormals(), and reverseNormalDirections().

◆ generateNormals() [2/2]

template<typename VectorType , typename IndexType >
void Cogs::Geometry::generateNormals ( VectorType *  positions,
const size_t  numVertexes,
IndexType *  indexes,
const size_t  numIndexes,
bool  quads,
bool  flipNormals,
bool  correctNormals,
std::vector< VectorType > &  normals 
)

Generate normals for the given shape.

Definition at line 320 of file NormalGenerator.h.

References generateNormals().

Referenced by generateNormals().

◆ generateQuadIndices()

void Cogs::Geometry::generateQuadIndices ( std::vector< uint32_t > &  dest,
size_t  quadCount,
uint32_t  vertexNumber,
bool  sharedVertices 
)

Generate indices for rendering the specified number of quads from four vertices starting from the given vertex number.

Vertices can be shared between quads or not.

Shared NotShared

0 ____2____ 4 0 ____ 2 4 ____ 6 | /| /| | /| | /| | / | / | | / | | / | | / | / | | / | | / | |/___|/___| |/___| |/___| 1 3 5 1 3 5 7

Assumes counter-clockwise winding order.

Definition at line 3 of file IndicesGenerator.cpp.

Referenced by Cogs::Core::Text3DSystem::update().

◆ getVertexLocation()

Location Cogs::Geometry::getVertexLocation ( const Vertex vertex,
const Vertex::List &  vertices 
)

Determines whether the given vertex is located inside the polygon defined by the list of vertices.

*============================================================================================

Definition at line 104 of file Polygon.cpp.

Referenced by findDivergenceForwards(), generateIntersectionPoints(), and Cogs::Geometry::Polygon::subtract().

◆ intersect() [1/2]

bool Cogs::Geometry::intersect ( const Cogs::Geometry::BoundingBox &  box,
const glm::vec3 &  origin,
const glm::vec3 &  direction,
glm::vec3 &  intersection,
const bool   
)
inline

Definition at line 14 of file RayBoxIntersection.h.

◆ intersect() [2/2]

bool Cogs::Geometry::intersect ( const glm::vec3 &  v0,
const glm::vec3 &  v1,
const glm::vec3 &  v2,
const glm::vec3 &  orig,
const glm::vec3 &  dir,
glm::vec3 &  intersection,
glm::vec3 &  barycentric,
bool &  front 
)
inline

Ray-Triangle intersection.

Definition at line 13 of file RayTriangleIntersection.h.

◆ projectToPlane()

bool Cogs::Geometry::projectToPlane ( glm::vec3  rayOrigin,
glm::vec3  rayDir,
glm::vec3  planeOrigin,
glm::vec3  planeDir,
glm::vec3 &  coordinates,
float *  pT = nullptr 
)
inline

Definition at line 10 of file Projection.h.

◆ reindexValues()

template<class ValueType , class IndexType >
void Cogs::Geometry::reindexValues ( const ValueType *  inputValues,
const IndexType *  indexes,
const size_t  numFaces,
const size_t  numIndexesPerFace,
ValueType *  outputValues 
)

Reindexes the input values into the output values based on the index array given.

Definition at line 232 of file NormalGenerator.h.

◆ removeDuplicates()

void Cogs::Geometry::removeDuplicates ( Vertex::List &  vertices)

Removes any adjacent vertices that are within five millimetres of their neighbours.

*============================================================================================

Definition at line 43 of file Polygon.cpp.

References veryClose().

Referenced by generateIntersectionPoints().

◆ reverseNormalDirections()

template<class NormalType >
void Cogs::Geometry::reverseNormalDirections ( NormalType *  normals,
const size_t  numNormals 
)

Reverse the set of normals given.

Definition at line 261 of file NormalGenerator.h.

Referenced by generateExtrusionNormals(), and generateNormals().

◆ veryClose()

bool Cogs::Geometry::veryClose ( const glm::vec3 &  lhs,
const glm::vec3 &  rhs 
)

Tests whether the two points are within one centimetre of each other.

*============================================================================================

Definition at line 34 of file Polygon.cpp.

Referenced by generateIntersectionPoints(), and removeDuplicates().