SOFA API  7226d276
Open source framework for multi-physics simuation
sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ > Class Template Reference

#include <DrawMesh.h>

Base class for mesh drawing using Curiously Recurring Template Pattern (CRTP) More...

Inheritance diagram for sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ >:

Detailed Description

template<class Derived, std::size_t NumberColors_>
class sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ >

Base class for mesh drawing using Curiously Recurring Template Pattern (CRTP)

Public Attributes

SReal elementSpace { 0.125_sreal }
 

Static Public Attributes

static constexpr std::size_t NumberColors { NumberColors_ }
 

Protected Attributes

std::array< sofa::type::vector< sofa::type::Vec3 >, NumberColors > renderedPoints
 Pre-allocated point buffers for rendering different color channels. More...
 

Public Member Functions

template<class PositionContainer >
void drawAllElements (sofa::helper::visual::DrawTool *drawTool, const PositionContainer &position, sofa::core::topology::BaseMeshTopology *topology, const ColorContainer &colors=Derived::defaultColors)
 Draws all elements of the mesh using provided colors. More...
 
template<class PositionContainer , class IndicesContainer >
void drawSomeElements (sofa::helper::visual::DrawTool *drawTool, const PositionContainer &position, sofa::core::topology::BaseMeshTopology *topology, const IndicesContainer &elementIndices, const ColorContainer &colors=Derived::defaultColors)
 Draws a subset of elements of the mesh using provided colors. More...
 

Protected Member Functions

template<class PositionType >
PositionType applyElementSpace (const PositionType &position, const PositionType &elementCenter) const
 

Static Protected Member Functions

template<class PositionContainer , class ElementType >
static PositionContainer::value_type elementCenter (const PositionContainer &position, const ElementType &element)
 

Attribute details

◆ elementSpace

template<class Derived , std::size_t NumberColors_>
SReal sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ >::elementSpace { 0.125_sreal }

◆ NumberColors

template<class Derived , std::size_t NumberColors_>
constexpr std::size_t sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ >::NumberColors { NumberColors_ }
staticconstexpr

◆ renderedPoints

template<class Derived , std::size_t NumberColors_>
std::array<sofa::type::vector< sofa::type::Vec3 >, NumberColors> sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ >::renderedPoints
protected

Pre-allocated point buffers for rendering different color channels.

This static array holds pre-allocated vertex position buffers for each color channel.

Key characteristics:

  • Each buffer corresponds to one of the NumberColors color channels (e.g., 3 for triangles)
  • Designed for efficient reuse across multiple drawing calls without reallocation

Function details

◆ applyElementSpace()

template<class Derived , std::size_t NumberColors_>
template<class PositionType >
PositionType sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ >::applyElementSpace ( const PositionType &  position,
const PositionType &  elementCenter 
) const
inlineprotected

◆ drawAllElements()

template<class Derived , std::size_t NumberColors_>
template<class PositionContainer >
void sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ >::drawAllElements ( sofa::helper::visual::DrawTool *  drawTool,
const PositionContainer &  position,
sofa::core::topology::BaseMeshTopology *  topology,
const ColorContainer &  colors = Derived::defaultColors 
)
inline

Draws all elements of the mesh using provided colors.

This function draws all elements of the mesh (from index 0 to the total number of elements) using the specified colors. It serves as a convenience wrapper that calls drawSomeElements with all element indices.

Template Parameters
PositionContainerThe type of the position container (e.g., sofa::type::vector<sofa::type::Vec3>)
Parameters
drawToolThe drawing tool to use for rendering
positionThe container of vertex positions
topologyThe mesh topology
colorsThe colors to use for each element. If not specified, the default colors of the derived class are used.

◆ drawSomeElements()

template<class Derived , std::size_t NumberColors_>
template<class PositionContainer , class IndicesContainer >
void sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ >::drawSomeElements ( sofa::helper::visual::DrawTool *  drawTool,
const PositionContainer &  position,
sofa::core::topology::BaseMeshTopology *  topology,
const IndicesContainer &  elementIndices,
const ColorContainer &  colors = Derived::defaultColors 
)
inline

Draws a subset of elements of the mesh using provided colors.

This function draws a specific subset of elements (specified by element indices) using the provided colors.

Template Parameters
PositionContainerThe type of the position container (e.g., sofa::type::vector<sofa::type::Vec3>)
IndicesContainerThe type of container holding element indices (e.g., sofa::type::vector<sofa::Index>)
Parameters
drawToolThe drawing tool to use for rendering
positionThe container of vertex positions
topologyThe mesh topology
elementIndicesThe indices of elements to draw
colorsThe colors to use for each element. If not specified, the default colors of the derived class are used.

◆ elementCenter()

template<class Derived , std::size_t NumberColors_>
template<class PositionContainer , class ElementType >
static PositionContainer::value_type sofa::core::visual::BaseDrawMesh< Derived, NumberColors_ >::elementCenter ( const PositionContainer &  position,
const ElementType &  element 
)
inlinestaticprotected