Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::TypedMesh< BufferTraits > Class Template Reference

#include <typedmesh.h>

+ Inheritance diagram for inviwo::TypedMesh< BufferTraits >:

Public Types

using Vertex = std::tuple<typename BufferTraits::type...>
 
using Traits = std::tuple<BufferTraits...>
 
- Public Types inherited from inviwo::Mesh
using IndexVector = std::vector<std::pair<MeshInfo, std::shared_ptr<IndexBuffer>>>
 
using BufferVector = std::vector<std::pair<BufferInfo, std::shared_ptr<BufferBase>>>
 
- Public Types inherited from inviwo::DataGroup< Mesh, MeshRepresentation >
using self
 
using repr
 

Public Member Functions

 TypedMesh (DrawType dt=DrawType::Points, ConnectivityType ct=ConnectivityType::None)
 
 TypedMesh (DrawType dt, ConnectivityType ct, const std::vector< Vertex > &vertices, std::vector< std::uint32_t > &&indices)
 
 TypedMesh (DrawType dt, ConnectivityType ct, const std::vector< Vertex > &vertices, const std::vector< std::uint32_t > &indices)
 
 TypedMesh (const TypedMesh &rhs)
 
TypedMeshoperator= (const TypedMesh &that)
 
virtual TypedMeshclone () const override
 
void append (const TypedMesh *mesh)
 Append another TypedMesh to the current TypedMesh.
 
void addVertices (const std::vector< Vertex > &vertices)
 Adds a vector of vertices to the mesh.
 
uint32_t addVertex (const Vertex &vertex)
 
void setVertex (size_t index, const Vertex &vertex)
 
template<typename... Args>
uint32_t addVertex (Args &&... args)
 Adds a vertex.
 
template<typename... Args>
void setVertex (size_t index, Args &&... args)
 Sets a specific vertex.
 
template<typename BT >
void setVertex (size_t index, const typename BT::type &v)
 Updates the a specific value in specific buffer.
 
template<typename BT >
auto getTypedBuffer ()
 Returns a specific buffer. The following example shows how to get the color buffer:
 
template<typename BT >
auto getTypedBuffer () const
 
template<typename BT >
auto getTypedRAMRepresentation () const
 
template<typename BT >
auto getTypedEditableRAMRepresentation ()
 
template<typename BT >
auto & getTypedDataContainer () const
 
template<typename BT >
auto & getTypedDataContainer ()
 
- Public Member Functions inherited from inviwo::Mesh
 Mesh (DrawType dt, ConnectivityType ct)
 
 Mesh (Mesh::MeshInfo meshInfo)
 
 Mesh (const BufferVector &buffers, const IndexVector &indices)
 
 Mesh (const Mesh &rhs)
 
 Mesh (const Mesh &rhs, NoData)
 
Meshoperator= (const Mesh &that)
 
virtual Document getInfo () const
 
void addBuffer (BufferInfo info, std::shared_ptr< BufferBase > buffer)
 
void addBuffer (BufferType type, std::shared_ptr< BufferBase > buffer)
 
void addBuffers (const BufferVector &buffers)
 
std::pair< BufferInfo, std::shared_ptr< BufferBase > > removeBuffer (size_t idx)
 
std::pair< BufferInfo, std::shared_ptr< BufferBase > > removeBuffer (BufferBase *buffer)
 
std::pair< BufferInfo, std::shared_ptr< BufferBase > > replaceBuffer (size_t idx, BufferInfo info, std::shared_ptr< BufferBase > buffer)
 
std::pair< BufferInfo, std::shared_ptr< BufferBase > > replaceBuffer (BufferBase *old, BufferInfo info, std::shared_ptr< BufferBase > buffer)
 
void setBuffer (size_t idx, BufferInfo info, std::shared_ptr< BufferBase > buffer)
 
void addIndices (MeshInfo info, std::shared_ptr< IndexBuffer > ind)
 
void addIndices (const IndexVector &indices)
 
void addIndicies (MeshInfo info, std::shared_ptr< IndexBuffer > ind)
 
std::shared_ptr< IndexBufferRAMaddIndexBuffer (DrawType dt, ConnectivityType ct)
 
void removeIndexBuffer (size_t idx)
 
void reserveSizeInVertexBuffer (size_t size)
 
void reserveIndexBuffers (size_t size)
 
const BufferVector & getBuffers () const
 
const IndexVector & getIndexBuffers () const
 
const BufferBasegetBuffer (size_t idx) const
 
BufferInfo getBufferInfo (size_t idx) const
 
BufferInfo getBufferInfo (BufferBase *buffer) const
 
void setBufferInfo (size_t idx, BufferInfo info)
 
void setBufferInfo (BufferBase *buffer, BufferInfo info)
 
const IndexBuffergetIndices (size_t idx) const
 
std::pair< const BufferBase *, int > findBuffer (BufferType type) const
 
std::pair< BufferBase *, int > findBuffer (BufferType type)
 
bool hasBuffer (BufferType type) const
 
BufferBasegetBuffer (size_t idx)
 
BufferBasegetBuffer (BufferType type)
 
IndexBuffergetIndices (size_t idx)
 
MeshInfo getDefaultMeshInfo () const
 
MeshInfo getIndexMeshInfo (size_t idx) const
 
size_t getNumberOfBuffers () const
 
size_t getNumberOfIndicies () const
 
void append (const Mesh &mesh)
 Append another mesh to this mesh.
 
virtual const AxisgetAxis (size_t index) const override
 
- Public Member Functions inherited from inviwo::DataGroup< Mesh, MeshRepresentation >
const T * getRepresentation () const
 
T * getEditableRepresentation ()
 
bool hasRepresentation () const
 
bool hasRepresentations () const
 
void clearRepresentations ()
 
- Public Member Functions inherited from inviwo::SpatialEntity
 SpatialEntity (const glm::mat4 &modelMatrix)
 
 SpatialEntity (const glm::mat4 &modelMatrix, const glm::mat4 &worldMatrix)
 
 SpatialEntity (const SpatialEntity &rhs)
 
SpatialEntityoperator= (const SpatialEntity &that)
 
glm::vec3 getOffset () const
 
void setOffset (const glm::vec3 &offset)
 
glm::mat3 getBasis () const
 
void setBasis (const glm::mat3 &basis)
 
glm::mat4 getModelMatrix () const
 
void setModelMatrix (const glm::mat4 &modelMatrix)
 
glm::mat4 getWorldMatrix () const
 
void setWorldMatrix (const glm::mat4 &worldMatrix)
 
virtual const SpatialCoordinateTransformergetCoordinateTransformer () const
 
virtual const SpatialCameraCoordinateTransformergetCoordinateTransformer (const Camera &camera) const
 
- Public Member Functions inherited from inviwo::MetaDataOwner
 MetaDataOwner (const MetaDataOwner &rhs)=default
 
 MetaDataOwner (MetaDataOwner &rhs)=default
 
MetaDataOwneroperator= (const MetaDataOwner &rhs)=default
 
MetaDataOwneroperator= (MetaDataOwner &)=default
 
void copyMetaDataFrom (const MetaDataOwner &src)
 
void copyMetaDataTo (MetaDataOwner &dst)
 
template<typename T >
requires std::derived_from<T, MetaData>
T * createMetaData (std::string_view key)
 
template<typename T , typename U >
requires std::derived_from<T, MetaData> && Settable<T, U>
void setMetaData (std::string_view key, U value)
 
template<typename T >
requires std::derived_from<T, MetaData>
bool unsetMetaData (std::string_view key)
 unset, i.e. remove the metadata entry matching the given key and type
 
template<typename T , typename U >
requires std::derived_from<T, MetaData> && Gettable<T, U>
getMetaData (std::string_view key, U val) const
 
template<typename T >
requires std::derived_from<T, MetaData>
T * getMetaData (std::string_view key)
 
template<typename T >
requires std::derived_from<T, MetaData>
const T * getMetaData (std::string_view key) const
 
MetaDataMapgetMetaDataMap ()
 
const MetaDataMapgetMetaDataMap () const
 
bool hasMetaData (std::string_view key) const
 
template<typename T >
requires std::derived_from<T, MetaData>
bool hasMetaData (std::string_view key) const
 
void serialize (Serializer &s) const
 
void deserialize (Deserializer &d)
 

Additional Inherited Members

- Public Attributes inherited from inviwo::Mesh
std::array< Axis, 3 > axes
 
- Static Public Attributes inherited from inviwo::Mesh
static constexpr uvec3 colorCode {188, 188, 101}
 
static constexpr std::string_view classIdentifier {"org.inviwo.Mesh"}
 
static constexpr std::string_view dataName {"Mesh"}
 
- Protected Member Functions inherited from inviwo::DataGroup< Mesh, MeshRepresentation >
 DataGroup (const DataGroup< Mesh, MeshRepresentation > &rhs)
 
DataGroup< Mesh, MeshRepresentation > & operator= (const DataGroup< Mesh, MeshRepresentation > &rhs)
 
- Protected Attributes inherited from inviwo::Mesh
BufferVector buffers_
 
IndexVector indices_
 
MeshInfo meshInfo_
 
- Protected Attributes inherited from inviwo::DataGroup< Mesh, MeshRepresentation >
std::mutex mutex_
 
std::unordered_map< std::type_index, std::shared_ptr< MeshRepresentation > > representations_
 
- Protected Attributes inherited from inviwo::SpatialEntity
std::unique_ptr< SpatialCoordinateTransformertransformer_
 
std::unique_ptr< SpatialCameraCoordinateTransformercameraTransformer_
 
glm::mat4 modelMatrix_
 
glm::mat4 worldMatrix_
 
- Protected Attributes inherited from inviwo::MetaDataOwner
MetaDataMap metaData_
 

Detailed Description

template<typename... BufferTraits>
class inviwo::TypedMesh< BufferTraits >

TypedMesh is a templated data structure for creating meshes with a custom amount of vertex buffers. It uses a variadic set of BufferTraits to define its interface. For example, a Mesh with a position and color per vertex would be defined as TypedMesh<PositionsBufferTrait,ColorsBufferTrait>. Depending on the Traits specified in the declaration the interface towards the class is updated.

Simple Usage

MyMesh mesh;
mesh.addVertex(vec3(0.0f), vec4(1,0,0,1) );
mesh.addVertex(vec3(1.0f), vec4(0,1,0,1) );
Definition typedmesh.h:340

If texture coordinates are also needed for each vertex in the mesh then one could instead use:

MyMesh mesh;
mesh.addVertex(vec3(0.0f), vec3(0.0f), vec4(1,0,0,1) );
mesh.addVertex(vec3(1.0f), vec3(1.0f), vec4(0,1,0,1) );
Definition typedmesh.h:137
Definition typedmesh.h:156

For meshes with more than a couple of vertices, it is more efficient to add all vertices to the mesh at the same time. This can be done by using a std::vector containing TypedMesh::Vertex instead, as described by the following example:

std::vector<MyMesh::Vertex> vertices;
vertices.emplace_back(vec3(0.0f), vec4(1,0,0,1));
vertices.emplace_back(vec3(1.0f), vec4(0,1,0,1));
MyMesh mesh;
mesh.addVertices(vertices);

When creating meshes it is very common to also have Index buffers, in addition to the vertex buffers. To add a index buffer to the mesh you can use the function addIndexBuffer as demonstrated by the following example.

MyMesh mesh;
// Add vertices as above
auto ib = mesh.addIndexBuffer(DrawType::Lines, ConnectivityType::None);
ib->add({0,1}); // Create a line between vertex 0 and 1
ib->add({1,2}); // Create another line between vertex 1 and 2
std::shared_ptr< IndexBufferRAM > addIndexBuffer(DrawType dt, ConnectivityType ct)

Examples

Creating a bounding box with Adjacency information

The following code snippet uses a SimpleMesh2 to create bounding box for a given basisandoffset matrix. It is the code used in meshutil::boundingBoxAdjacency

std::shared_ptr<PosTexColorMesh> boundingBoxAdjacency(const mat4& basisandoffset,
const vec4& color) {
auto mesh = std::make_shared<PosTexColorMesh>();
mesh->setModelMatrix(basisandoffset);
mesh->addVertices({{vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.0), color},
{vec3(1.0, 0.0, 0.0), vec3(1.0, 0.0, 0.0), color},
{vec3(1.0, 1.0, 0.0), vec3(1.0, 1.0, 0.0), color},
{vec3(0.0, 1.0, 0.0), vec3(0.0, 1.0, 0.0), color},
{vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, 1.0), color},
{vec3(1.0, 0.0, 1.0), vec3(1.0, 0.0, 1.0), color},
{vec3(1.0, 1.0, 1.0), vec3(1.0, 1.0, 1.0), color},
{vec3(0.0, 1.0, 1.0), vec3(0.0, 1.0, 1.0), color}});
auto inds1 = mesh->addIndexBuffer(DrawType::Lines, ConnectivityType::StripAdjacency);
inds1->add({3, 0, 1, 2, 3, 0, 1});
auto inds2 = mesh->addIndexBuffer(DrawType::Lines, ConnectivityType::StripAdjacency);
inds2->add({7, 4, 5, 6, 7, 4, 5});
auto inds3 = mesh->addIndexBuffer(DrawType::Lines, ConnectivityType::StripAdjacency);
inds3->add({3, 0, 4, 7, 3, 0, 4});
auto inds4 = mesh->addIndexBuffer(DrawType::Lines, ConnectivityType::StripAdjacency);
inds4->add({2, 1, 5, 6, 2, 1, 2});
return mesh;
}

Creating camera frustum

The following code snippet is another example where we create a camera frustum mesh for a given camera. It is the code used in meshutil::cameraFrustum

std::shared_ptr<ColoredMesh> cameraFrustum(const Camera& camera, vec4 color,
std::shared_ptr<ColoredMesh> mesh) {
const static std::vector<vec3> vertices{vec3(-1, -1, -1), vec3(-1, 1, -1), vec3(1, -1, -1),
vec3(1, 1, -1), vec3(-1, -1, 1), vec3(-1, 1, 1),
vec3(1, -1, 1), vec3(1, 1, 1)};
auto& vertVector = mesh->getTypedDataContainer<buffertraits::PositionsBuffer>();
auto& colorVector = mesh->getTypedDataContainer<buffertraits::ColorsBuffer>();
auto off = static_cast<unsigned int>(vertVector.size());
vertVector.insert(vertVector.end(), vertices.begin(), vertices.end());
colorVector.insert(colorVector.end(), 8, color);
mesh->setModelMatrix(glm::inverse(camera.getProjectionMatrix() * camera.getViewMatrix()));
auto ib = std::make_shared<IndexBufferRAM>();
auto indices = std::make_shared<IndexBuffer>(ib);
ib->add({off + 0, off + 1, off + 1, off + 3, off + 3, off + 2, off + 2, off + 0}); // front
ib->add({off + 4, off + 5, off + 5, off + 7, off + 7, off + 6, off + 6, off + 4}); // back
ib->add({off + 0, off + 4, off + 1, off + 5, off + 2, off + 6, off + 3, off + 7}); // sides
mesh->addIndices(Mesh::MeshInfo(DrawType::Lines, ConnectivityType::None), indices);
return mesh;
}

Member Function Documentation

◆ addVertex()

template<typename... BufferTraits>
template<typename... Args>
uint32_t inviwo::TypedMesh< BufferTraits >::addVertex ( Args &&... args)

Adds a vertex.

Adds a vertex to the mesh. The arguments to the function are automatically determined by the buffers of the mesh. For example:

MyMesh mesh;
mesh.addVertex(vec3(0.0f), vec4(1,0,0,1) );
mesh.addVertex(vec3(1.0f), vec4(0,1,0,1) );
Parameters
argsthe arguments, needs to match the buffers of the mesh
Returns
uint32_t the position of the new vertex is the buffers.

◆ addVertices()

template<typename... BufferTraits>
void inviwo::TypedMesh< BufferTraits >::addVertices ( const std::vector< Vertex > & vertices)

Adds a vector of vertices to the mesh.

This method is often faster than adding the vertices one at a time with TypedMesh::addVertex()

◆ append()

template<typename... BufferTraits>
void inviwo::TypedMesh< BufferTraits >::append ( const TypedMesh< BufferTraits > * mesh)
inline

Append another TypedMesh to the current TypedMesh.

See also
Mesh::append
Parameters
meshThe mesh to append

◆ clone()

template<typename... BufferTraits>
virtual TypedMesh * inviwo::TypedMesh< BufferTraits >::clone ( ) const
inlineoverridevirtual

Reimplemented from inviwo::Mesh.

◆ getTypedBuffer() [1/2]

template<typename... BufferTraits>
template<typename BT >
auto inviwo::TypedMesh< BufferTraits >::getTypedBuffer ( )
inline

Returns a specific buffer. The following example shows how to get the color buffer:

MyMesh mesh;
auto colorBuffer = mesh.getTypedBuffer<buffertraits::ColorsBuffer>();
auto getTypedBuffer()
Returns a specific buffer. The following example shows how to get the color buffer:
Definition typedmesh.h:460

◆ getTypedBuffer() [2/2]

template<typename... BufferTraits>
template<typename BT >
auto inviwo::TypedMesh< BufferTraits >::getTypedBuffer ( ) const
inline

Returns a specific buffer

See also
getTypedBuffer()

◆ getTypedDataContainer() [1/2]

template<typename... BufferTraits>
template<typename BT >
auto & inviwo::TypedMesh< BufferTraits >::getTypedDataContainer ( )
inline

Returns the Data Container of a specific buffer.

See also
getTypedBuffer()

◆ getTypedDataContainer() [2/2]

template<typename... BufferTraits>
template<typename BT >
auto & inviwo::TypedMesh< BufferTraits >::getTypedDataContainer ( ) const
inline

Returns the Data Container of a specific buffer.

See also
getTypedBuffer()

◆ getTypedEditableRAMRepresentation()

template<typename... BufferTraits>
template<typename BT >
auto inviwo::TypedMesh< BufferTraits >::getTypedEditableRAMRepresentation ( )
inline

Returns the Editable RAM Representation of a specific buffer.

See also
getTypedBuffer()

◆ getTypedRAMRepresentation()

template<typename... BufferTraits>
template<typename BT >
auto inviwo::TypedMesh< BufferTraits >::getTypedRAMRepresentation ( ) const
inline

Returns the RAM Representation of a specific buffer.

See also
getTypedBuffer()

◆ setVertex() [1/2]

template<typename... BufferTraits>
template<typename... Args>
void inviwo::TypedMesh< BufferTraits >::setVertex ( size_t index,
Args &&... args )

Sets a specific vertex.

The arguments to the function are automatically determined by the buffers of the mesh.

See also
addVertex
Parameters
indexvertex index to update
argsthe arguments, needs to match the buffers of the mesh

◆ setVertex() [2/2]

template<typename... BufferTraits>
template<typename BT >
void inviwo::TypedMesh< BufferTraits >::setVertex ( size_t index,
const typename BT::type & v )
inline

Updates the a specific value in specific buffer.

The following example will set the color of vertex with index 5 to read:

MyMesh mesh;
// ... add some vertices
mesh.setVertex<buffertraits::ColorsBuffer>(5 , vec4(1,0,0,1) );
Parameters
indexvertex index to update
vthe new value

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