Visual Computing Library  devel
Loading...
Searching...
No Matches
vcl::comp::Materials Class Reference

A component that manages materials and textures for a mesh. More...

#include <vclib/mesh/components/materials.h>

Inheritance diagram for vcl::comp::Materials:

Public Types

using ConstMaterialIterator = std::vector< Material >::const_iterator
 Const iterator for the vector of materials.
 
using ConstTextureImageIterator = std::map< std::string, Image >::const_iterator
 Const iterator for the map of texture images.
 
using MaterialIterator = std::vector< Material >::iterator
 Iterator for the vector of materials.
 
using MaterialType = Material
 Exposes the Material type used by this component.
 
using TextureImageIterator = std::map< std::string, Image >::iterator
 Iterator for the map of texture images.
 

Public Member Functions

void clearMaterials ()
 Clears the vector of materials.
 
Materialmaterial (uint i)
 Returns a mutable reference to the material at the specified index.
 
const Materialmaterial (uint i) const
 Returns the material at the specified index.
 
MaterialIterator materialBegin ()
 Returns an iterator to the beginning of the vector of materials.
 
ConstMaterialIterator materialBegin () const
 Returns a const iterator to the beginning of the vector of materials.
 
MaterialIterator materialEnd ()
 Returns an iterator to the end of the vector of materials.
 
ConstMaterialIterator materialEnd () const
 Returns a const iterator to the end of the vector of materials.
 
View< MaterialIteratormaterials ()
 Returns a lightweight view object that stores the begin and end iterators of the vector of materials. The view object exposes the iterators trough the begin() and end() member functions, and therefore the returned object can be used in range-based for loops:
 
View< ConstMaterialIteratormaterials () const
 Returns a lightweight const view object that stores the begin and end iterators of the vector of materials. The view object exposes the iterators trough the begin() and end() member functions, and therefore the returned object can be used in range-based for loops:
 
 Materials ()=default
 Default constructor for the Materials component.
 
uint materialsNumber () const
 Returns the number of materials of the mesh.
 
std::string & meshBasePath ()
 Returns a reference to the mesh base path.
 
const std::string & meshBasePath () const
 Returns the mesh base path.
 
void pushMaterial (const Material &mat)
 Adds a material to the vector of materials.
 
void pushTextureImage (const std::string &texturePath, const Image &img)
 Adds a texture image to the map of texture images.
 
void pushTextureImage (const std::string &texturePath, Image &&img)
 Adds a texture image to the map of texture images (move version).
 
const ImagetextureImage (const std::string &texturePath) const
 Returns the texture image associated to the given texture path.
 
TextureImageIterator textureImageBegin ()
 Returns an iterator to the beginning of the map of texture images.
 
ConstTextureImageIterator textureImageBegin () const
 Returns a const iterator to the beginning of the map of texture images.
 
TextureImageIterator textureImageEnd ()
 Returns an iterator to the end of the map of texture images.
 
ConstTextureImageIterator textureImageEnd () const
 Returns a const iterator to the end of the map of texture images.
 
View< TextureImageIteratortextureImages ()
 Returns a lightweight view object that stores the begin and end iterators of the map of texture images. The view object exposes the iterators trough the begin() and end() member functions, and therefore the returned object can be used in range-based for loops:
 
View< ConstTextureImageIteratortextureImages () const
 Returns a lightweight const view object that stores the begin and end iterators of the map of texture images. The view object exposes the iterators trough the begin() and end() member functions, and therefore the returned object can be used in range-based for loops:
 
uint textureImagesNumber () const
 Returns the number of texture images stored in the component.
 

Protected Member Functions

void deserialize (std::istream &is)
 
template<typename Element >
void importFrom (const Element &e, bool=true)
 
void serialize (std::ostream &os) const
 

Private Types

using Base = Component< Materials, CompId::MATERIALS, detail::MData, void, false, false >
 

Private Member Functions

std::vector< Material > & mats ()
 
const std::vector< Material > & mats () const
 
std::map< std::string, Image > & txtImgs ()
 
const std::map< std::string, Image > & txtImgs () const
 

Static Private Attributes

static const Image EMPTY_IMAGE
 

Detailed Description

A component that manages materials and textures for a mesh.

The Materials component stores a collection of materials and their associated texture images. It also keeps track of the base path of the mesh, which is used to resolve relative paths for texture files.

This component provides functionalities to:

  • Add and retrieve materials.
  • Add and retrieve texture images, mapping them by their file paths.
  • Iterate over the stored materials and texture images.
  • Clear all stored material and texture data.

Member Function Documentation

◆ clearMaterials()

void vcl::comp::Materials::clearMaterials ( )
inline

Clears the vector of materials.

This function clears the vector of materials and the map of texture images, resetting the component to an empty state.

◆ material() [1/2]

Material & vcl::comp::Materials::material ( uint  i)
inline

Returns a mutable reference to the material at the specified index.

Parameters
[in]iThe index of the material.
Returns
A reference to the Material object.

◆ material() [2/2]

const Material & vcl::comp::Materials::material ( uint  i) const
inline

Returns the material at the specified index.

Parameters
[in]iThe index of the material.
Returns
A const reference to the Material object

◆ materialBegin() [1/2]

MaterialIterator vcl::comp::Materials::materialBegin ( )
inline

Returns an iterator to the beginning of the vector of materials.

Returns
an iterator to the beginning of the vector of materials.

◆ materialBegin() [2/2]

ConstMaterialIterator vcl::comp::Materials::materialBegin ( ) const
inline

Returns a const iterator to the beginning of the vector of materials.

Returns
a const iterator to the beginning of the vector of materials.

◆ materialEnd() [1/2]

MaterialIterator vcl::comp::Materials::materialEnd ( )
inline

Returns an iterator to the end of the vector of materials.

Returns
an iterator to the end of the vector of materials.

◆ materialEnd() [2/2]

ConstMaterialIterator vcl::comp::Materials::materialEnd ( ) const
inline

Returns a const iterator to the end of the vector of materials.

Returns
a const iterator to the end of the vector of materials.

◆ materials() [1/2]

View< MaterialIterator > vcl::comp::Materials::materials ( )
inline

Returns a lightweight view object that stores the begin and end iterators of the vector of materials. The view object exposes the iterators trough the begin() and end() member functions, and therefore the returned object can be used in range-based for loops:

for (auto& mat : m.materials()) {
// Do something with mat
}
A class representing a box in N-dimensional space.
Definition box.h:46
View< MaterialIterator > materials()
Returns a lightweight view object that stores the begin and end iterators of the vector of materials....
Definition materials.h:283
Returns
a lightweight view object that can be used in range-based for loops to iterate over the vector of materials.

◆ materials() [2/2]

View< ConstMaterialIterator > vcl::comp::Materials::materials ( ) const
inline

Returns a lightweight const view object that stores the begin and end iterators of the vector of materials. The view object exposes the iterators trough the begin() and end() member functions, and therefore the returned object can be used in range-based for loops:

for (const auto& mat : m.materials()) {
// Do something with mat
}
Returns
a lightweight view object that can be used in range-based for loops to iterate over the vector of materials.

◆ materialsNumber()

uint vcl::comp::Materials::materialsNumber ( ) const
inline

Returns the number of materials of the mesh.

Returns
The total number of materials.

◆ meshBasePath() [1/2]

std::string & vcl::comp::Materials::meshBasePath ( )
inline

Returns a reference to the mesh base path.

Returns
A reference to the mesh base path string.

◆ meshBasePath() [2/2]

const std::string & vcl::comp::Materials::meshBasePath ( ) const
inline

Returns the mesh base path.

This path is typically used to resolve relative paths of texture files.

Returns
A const reference to the mesh base path string.

◆ pushMaterial()

void vcl::comp::Materials::pushMaterial ( const Material mat)
inline

Adds a material to the vector of materials.

Parameters
[in]matThe material to add.

◆ pushTextureImage() [1/2]

void vcl::comp::Materials::pushTextureImage ( const std::string &  texturePath,
const Image img 
)
inline

Adds a texture image to the map of texture images.

If an image with the same texture path already exists, it is overwritten.

Parameters
[in]texturePathThe path of the texture.
[in]imgThe image to add.

◆ pushTextureImage() [2/2]

void vcl::comp::Materials::pushTextureImage ( const std::string &  texturePath,
Image &&  img 
)
inline

Adds a texture image to the map of texture images (move version).

If an image with the same texture path already exists, it is overwritten.

Parameters
[in]texturePathThe path of the texture.
[in]imgThe image to add.

◆ textureImage()

const Image & vcl::comp::Materials::textureImage ( const std::string &  texturePath) const
inline

Returns the texture image associated to the given texture path.

If no image is found for the given texture path, an empty image is returned.

Parameters
[in]texturePathThe path of the texture.
Returns
the texture image associated to the given texture path, or an empty image if no image is found.

◆ textureImageBegin() [1/2]

TextureImageIterator vcl::comp::Materials::textureImageBegin ( )
inline

Returns an iterator to the beginning of the map of texture images.

Returns
an iterator to the beginning of the map of texture images.

◆ textureImageBegin() [2/2]

ConstTextureImageIterator vcl::comp::Materials::textureImageBegin ( ) const
inline

Returns a const iterator to the beginning of the map of texture images.

Returns
a const iterator to the beginning of the map of texture images.

◆ textureImageEnd() [1/2]

TextureImageIterator vcl::comp::Materials::textureImageEnd ( )
inline

Returns an iterator to the end of the map of texture images.

Returns
an iterator to the end of the map of texture images.

◆ textureImageEnd() [2/2]

ConstTextureImageIterator vcl::comp::Materials::textureImageEnd ( ) const
inline

Returns a const iterator to the end of the map of texture images.

Returns
a const iterator to the end of the map of texture images.

◆ textureImages() [1/2]

View< TextureImageIterator > vcl::comp::Materials::textureImages ( )
inline

Returns a lightweight view object that stores the begin and end iterators of the map of texture images. The view object exposes the iterators trough the begin() and end() member functions, and therefore the returned object can be used in range-based for loops:

for (auto& [path, img] : m.textureImages()) {
// Do something with path and img
}
View< TextureImageIterator > textureImages()
Returns a lightweight view object that stores the begin and end iterators of the map of texture image...
Definition materials.h:323
Returns
a lightweight view object that can be used in range-based for loops to iterate over the map of texture images.

◆ textureImages() [2/2]

View< ConstTextureImageIterator > vcl::comp::Materials::textureImages ( ) const
inline

Returns a lightweight const view object that stores the begin and end iterators of the map of texture images. The view object exposes the iterators trough the begin() and end() member functions, and therefore the returned object can be used in range-based for loops:

for (const auto& [path, img] : m.textureImages()) {
// Do something with path and img
}
Returns
a lightweight view object that can be used in range-based for loops to iterate over the map of texture images.

◆ textureImagesNumber()

uint vcl::comp::Materials::textureImagesNumber ( ) const
inline

Returns the number of texture images stored in the component.

Returns
The total number of texture images.

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