Inviwo  0.9.10.1
Inviwo documentation
inviwo::Data< Self, Repr > Class Template Referenceabstract

The base class for all data objects. More...

#include <data.h>

+ Inheritance diagram for inviwo::Data< Self, Repr >:

Public Types

using self = Self
 
using repr = Repr
 

Public Member Functions

virtual Data< Self, Repr > * clone () const =0
 
template<typename T >
const T * getRepresentation () const
 
template<typename T >
T * getEditableRepresentation ()
 
template<typename T >
bool hasRepresentation () const
 
bool hasRepresentations () const
 
void addRepresentation (std::shared_ptr< Repr > representation)
 
void removeRepresentation (const Repr *representation)
 
void removeOtherRepresentations (const Repr *representation)
 
void clearRepresentations ()
 
void invalidateAllOther (const Repr *repr)
 

Protected Member Functions

 Data (const Data< Self, Repr > &rhs)
 
Data< Self, Repr > & operator= (const Data< Self, Repr > &rhs)
 
template<typename T >
const T * getValidRepresentation () const
 
void copyRepresentationsTo (Data< Self, Repr > *targetData) const
 
std::shared_ptr< Repr > addRepresentationInternal (std::shared_ptr< Repr > representation) const
 

Protected Attributes

std::mutex mutex_
 
std::unordered_map< std::type_index, std::shared_ptr< Repr > > representations_
 
std::shared_ptr< Repr > lastValidRepresentation_
 

Detailed Description

template<typename Self, typename Repr>
class inviwo::Data< Self, Repr >

The base class for all data objects.

Data is a handle class and, by it self does not have any data, it only stores metadata, and a list of representations. The representations is were the actually data is stored. A Volume can have a set of different representations, for example a VolumeRAM representation and a VolumeGL representation. At any time at least one of the representations should be in a valid state. When ever we want to access the data of a volume we will ask the volume for a representation of some kind, and the handle is then responsible to try and provide that to us. If the requested representation is valid the handle can just return the that representation. If not, it will have to find a valid representation and try to either create the representation we wanted from the valid representation, if there was no representation of the kind we asked for around. Or if there is a invalid representation around, update that representation with the valid representation.

Call getRepresentation to retrieve the data:

// Create a Buffer with a BufferRAM representation
auto buffer = util::makeBuffer<vec2>(
{ {0.0f, 1.0f}, {-1.0f, -1.0f}, {1.0f, -1.0f} });
// Retrieve a read-only representation of the data
auto bufferRAM = buffer.getRepresentation<BufferRAM>();
// The data will be transferred to the GPU if not already there.
auto bufferGL = buffer.getRepresentation<BufferGL>();

Requirements:

  1. Copy constructor for deep copy
  2. Assignment operator for deep copy
  3. Clone pattern

1 and 2 are needed to be a vaild member type of std::vector. 3 is needed for the factory pattern, 3 should be implemented using 1.

Note
Do not use the same representation in different Data objects. This can cause inconsistencies since the Data objects cannot know if another one has edited the representation.
See also
Representation and RepresentationConverter

Member Function Documentation

◆ addRepresentation()

template<typename Self , typename Repr>
void inviwo::Data< Self, Repr >::addRepresentation ( std::shared_ptr< Repr >  representation)

Add the representation and set it as last valid. The owner of the representation will be set to this object.

Note
A representation can only be added to one Data object.
Parameters
representationThe representation to add

◆ clearRepresentations()

template<typename Self , typename Repr >
void inviwo::Data< Self, Repr >::clearRepresentations ( )

Delete all representations.

◆ getEditableRepresentation()

template<typename Self , typename Repr >
template<typename T >
T * inviwo::Data< Self, Repr >::getEditableRepresentation ( )

Get an editable representation. This will invalidate all other representations. They will now have to be updated from this one before use.

See also
getRepresentation and invalidateAllOther

◆ getRepresentation()

template<typename Self , typename Repr >
template<typename T >
const T * inviwo::Data< Self, Repr >::getRepresentation ( ) const

Get a representation of type T. If there already is a valid representation of type T, just return it, if it's invalid use the last valid representation to update it so it will be valid. It there is no representation of type T, create it from the last valid representation. If there are no representations create a default representation and from that create a representation of type T.

◆ hasRepresentation()

template<typename Self , typename Repr >
template<typename T >
bool inviwo::Data< Self, Repr >::hasRepresentation ( ) const

Check if a specific representation type exists. Example:

hasRepresentation<BufferRAM>();
Returns
true if existing, false otherwise.

◆ hasRepresentations()

template<typename Self , typename Repr >
bool inviwo::Data< Self, Repr >::hasRepresentations ( ) const

Check if the Data object has any representation.

Returns
true if any representation exist, false otherwise.

◆ invalidateAllOther()

template<typename Self , typename Repr>
void inviwo::Data< Self, Repr >::invalidateAllOther ( const Repr *  repr)

This call will make all other representations invalid. You need to call this function if you are modifying a representation directly without calling getEditableRepresentation. getEditableRepresentation will automatically invalidate all other representations.

See also
getEditableRepresentation

◆ removeOtherRepresentations()

template<typename Self , typename Repr>
void inviwo::Data< Self, Repr >::removeOtherRepresentations ( const Repr *  representation)

Remove all other representations. This will delete all representations except the one passed in.

Parameters
representationThe representation to keep

◆ removeRepresentation()

template<typename Self , typename Repr>
void inviwo::Data< Self, Repr >::removeRepresentation ( const Repr *  representation)

Remove representation from data object. This will delete the representation, thus rendering the representation pointer invalid.

Parameters
representationThe representation to remove

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