AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
agxOSG::PrimitiveSetTriangleSorter Class Reference

Checks all primitive sets of a render geometry for triangles and sort the triangles back to front given camera model view matrix and vertex depth reduce function [d1, d2, d3] -> d. More...

#include <TransparencyUtils.h>

Classes

struct  TriangleDepth
 

Public Types

using DepthReduceFunc = std::function< float(TriangleVertexDepths)>
 
using TriangleVertexDepths = const std::array< float, 3u > &
 

Static Public Member Functions

template<typename TriangleBuffer >
static bool impl (TriangleBuffer &triangles, const osg::Vec3Array &vertices, const osg::Matrixf &modelViewMatrix, const DepthReduceFunc &depthReduce)
 Implementation of the sorting when triangle primitive sets can be many things.
 
static float maxOf (TriangleVertexDepths depths)
 Depth reduce as max([d1, d2, d3]).
 
static float midOf (TriangleVertexDepths depths)
 Depth reduce as avg([d1, d2, d3]).
 
static float minOf (TriangleVertexDepths depths)
 Depth reduce as min([d1, d2, d3]).
 
static bool sort (osg::Geometry &geometry, const osg::Matrixf &modelViewMatrix, DepthReduceFunc depthReduce=midOf)
 Sort all triangle primitive sets of the given geometry.
 

Detailed Description

Checks all primitive sets of a render geometry for triangles and sort the triangles back to front given camera model view matrix and vertex depth reduce function [d1, d2, d3] -> d.

Default reduce is triangle centroid.

To get/find the model view matrix, the camera has to be given. If the camera is around, the model view matrix is:

const auto modelToWorld = osg::computeLocalToWorld( visualGeometryOrTransform->getParentalNodePaths()[ 0 ] );
const auto worldToEye = camera->getViewMatrix();
const auto modelViewMatrix = modelToWorld * worldToEye;
agxOSG::PrimitiveSetTriangleSorter::sort( *geometry, modelViewMatrix );

if the camera isn't around, use agxOSG::ModelViewMatrixFinder below like: geometry->setCullCallback( new agxOSG::ModelViewMatrixFinder( [geometry]( const osg::Matrixf& modelViewMatrix ) { agxOSG::PrimitiveSetTriangleSorter::sort( *geometry, modelViewMatrix ); } );

Definition at line 73 of file TransparencyUtils.h.

Member Typedef Documentation

◆ DepthReduceFunc

Definition at line 77 of file TransparencyUtils.h.

◆ TriangleVertexDepths

using agxOSG::PrimitiveSetTriangleSorter::TriangleVertexDepths = const std::array<float, 3u>&

Definition at line 76 of file TransparencyUtils.h.

Member Function Documentation

◆ impl()

template<typename TriangleBuffer >
static bool agxOSG::PrimitiveSetTriangleSorter::impl ( TriangleBuffer &  triangles,
const osg::Vec3Array &  vertices,
const osg::Matrixf &  modelViewMatrix,
const DepthReduceFunc depthReduce 
)
inlinestatic

Implementation of the sorting when triangle primitive sets can be many things.

E.g., osg::DrawElementsUByte osg::DrawElementsUShort osg::DrawElementsUInt

Requirements on the triangles container is that the triangles.size % 3 == 0, i.e., triangles.size / 3 == number of triangles, and typename TriangleBuffer::value_type is the index type.

Parameters
triangles- triangles container (size = 3 * vertices.size)
vertices- triangle vertices
modelViewMatrix- camera view of the triangles, the model view matrix
depthReduce- triangle vertex (camera) depth reduce function
Returns
true if sorting was performed and the drawable should be flagged dirty, otherwise false (not touched)

Definition at line 142 of file TransparencyUtils.h.

◆ maxOf()

float agxOSG::PrimitiveSetTriangleSorter::maxOf ( TriangleVertexDepths  depths)
inlinestatic

Depth reduce as max([d1, d2, d3]).

Parameters
depths- triangle vertex depths
Returns
maximum value of depths

Definition at line 204 of file TransparencyUtils.h.

◆ midOf()

float agxOSG::PrimitiveSetTriangleSorter::midOf ( TriangleVertexDepths  depths)
inlinestatic

Depth reduce as avg([d1, d2, d3]).

Parameters
depths- triangle vertex depths
Returns
average value of depths

Definition at line 199 of file TransparencyUtils.h.

◆ minOf()

float agxOSG::PrimitiveSetTriangleSorter::minOf ( TriangleVertexDepths  depths)
inlinestatic

Depth reduce as min([d1, d2, d3]).

Parameters
depths- triangle vertex depths
Returns
minimum value of depths

Definition at line 191 of file TransparencyUtils.h.

◆ sort()

static bool agxOSG::PrimitiveSetTriangleSorter::sort ( osg::Geometry &  geometry,
const osg::Matrixf &  modelViewMatrix,
DepthReduceFunc  depthReduce = midOf 
)
static

Sort all triangle primitive sets of the given geometry.

If only a specific set should be sorted, use: agxOSG::PrimitiveSetTriangleSorter::impl( dynamic_cast<TypeOfTheSet&>( *geometry->getPrimitiveSet( 7 ), mvm )

Parameters
geometry- geometry with triangles
modelViewMatrix- geometry to camera view matrix
depthReduce- triangle vertex depths (as seen from the camera) reduce function [d1, d2, d3] -> d, where d is sorted for, highest to lowest

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