Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::CategoricalColumn Class Reference

Specialized data column representing categorical values, i.e. strings. Categorical values are internally mapped to a number representation. More...

#include <column.h>

+ Inheritance diagram for inviwo::CategoricalColumn:

Public Types

using type = std::uint32_t
 
using ConstIterator
 

Public Member Functions

 CategoricalColumn (std::string_view header, const std::vector< std::string > &values={}, Unit unit=Unit{}, std::optional< dvec2 > range=std::nullopt)
 
 CategoricalColumn (std::string_view header, std::vector< type > data, std::vector< std::string > lookup, Unit unit=Unit{}, std::optional< dvec2 > range=std::nullopt)
 
 CategoricalColumn (const CategoricalColumn &rhs)
 
 CategoricalColumn (const CategoricalColumn &rhs, const std::vector< std::uint32_t > &rowSelection)
 
 CategoricalColumn (CategoricalColumn &&rhs)=default
 
CategoricalColumnoperator= (const CategoricalColumn &rhs)
 
CategoricalColumnoperator= (CategoricalColumn &&rhs)
 
virtual CategoricalColumnclone () const override
 
virtual CategoricalColumnclone (const std::vector< std::uint32_t > &rowSelection) const override
 
virtual ColumnType getColumnType () const override
 
virtual const std::string & getHeader () const override
 
void setHeader (std::string_view header) override
 
virtual Unit getUnit () const override
 
virtual void setUnit (Unit unit) override
 
virtual void setCustomRange (std::optional< dvec2 > range) override
 
virtual std::optional< dvec2 > getCustomRange () const override
 
virtual dvec2 getDataRange () const override
 
virtual dvec2 getRange () const override
 
virtual size_t getSize () const override
 
void set (size_t idx, std::string_view str)
 
void set (size_t idx, std::uint32_t id)
 
virtual void add (std::string_view value) override
 
AddMany addMany ()
 
virtual void append (const Column &col) override
 and builds a union of all categorical values
 
void append (const std::vector< std::string > &data)
 Append the categorical values given in data.
 
const std::vector< std::string > & getCategories () const
 
std::vector< std::string > getValues () const
 Returns column contents as list of categorical values.
 
util::iter_range< ConstIteratorvalues () const
 
std::uint32_t addCategory (std::string_view cat)
 Add a category cat. It will not be added if the category already exists.
 
- Public Member Functions inherited from inviwo::Column
- 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)
 
const std::string & get (size_t idx) const
 
virtual std::string getAsString (size_t idx) const override
 
std::uint32_t getId (size_t idx) const
 
virtual double getAsDouble (size_t idx) const override
 
ConstIterator begin () const
 
ConstIterator end () const
 
virtual std::shared_ptr< BufferBasegetBuffer () override
 
virtual std::shared_ptr< const BufferBasegetBuffer () const override
 
std::shared_ptr< Buffer< std::uint32_t > > getTypedBuffer ()
 
std::shared_ptr< const Buffer< std::uint32_t > > getTypedBuffer () const
 

Additional Inherited Members

- Protected Member Functions inherited from inviwo::Column
- Protected Attributes inherited from inviwo::MetaDataOwner
MetaDataMap metaData_
 

Detailed Description

Specialized data column representing categorical values, i.e. strings. Categorical values are internally mapped to a number representation.

For example: The data column "blue", "blue", "red", "yellow" might internally be represented by 0, 0, 1, 2. The original string values can be accessed using CategoricalColumn::get(index, true)

See also
CategoricalColumn::get()

Member Typedef Documentation

◆ ConstIterator

Initial value:
util::TransformIterator<decltype(detail::categoricalTransform(
std::declval<const std::vector<std::string>&>())),
std::vector<std::uint32_t>::const_iterator>

Member Function Documentation

◆ add()

virtual void inviwo::CategoricalColumn::add ( std::string_view value)
overridevirtual

Implements inviwo::Column.

◆ addCategory()

std::uint32_t inviwo::CategoricalColumn::addCategory ( std::string_view cat)

Add a category cat. It will not be added if the category already exists.

Returns
index of the category

◆ append() [1/2]

virtual void inviwo::CategoricalColumn::append ( const Column & col)
overridevirtual

and builds a union of all categorical values

Parameters
col
Exceptions
Exceptionif data format does not match

Implements inviwo::Column.

◆ append() [2/2]

void inviwo::CategoricalColumn::append ( const std::vector< std::string > & data)

Append the categorical values given in data.

Parameters
datacategorical values

◆ begin()

ConstIterator inviwo::CategoricalColumn::begin ( ) const

Returns a const iterator over all rows of the column holding the corresponding categorical values as const std::string&.

Returns
iterator over categorical values stored in the column
See also
values

◆ clone() [1/2]

virtual CategoricalColumn * inviwo::CategoricalColumn::clone ( ) const
overridevirtual

Implements inviwo::Column.

◆ clone() [2/2]

virtual CategoricalColumn * inviwo::CategoricalColumn::clone ( const std::vector< std::uint32_t > & rowSelection) const
overridevirtual

Implements inviwo::Column.

◆ end()

ConstIterator inviwo::CategoricalColumn::end ( ) const

Returns a const iterator over all rows of the column holding the corresponding categorical values as const std::string&.

Returns
iterator over categorical values stored in the column
See also
values

◆ get()

const std::string & inviwo::CategoricalColumn::get ( size_t idx) const

Return the categorical value in row idx.

◆ getAsDouble()

virtual double inviwo::CategoricalColumn::getAsDouble ( size_t idx) const
overridevirtual

Return the numerical id of the category in row idx.

Implements inviwo::Column.

◆ getAsString()

virtual std::string inviwo::CategoricalColumn::getAsString ( size_t idx) const
overridevirtual

Return the categorical value in row idx.

Implements inviwo::Column.

◆ getBuffer() [1/2]

virtual std::shared_ptr< const BufferBase > inviwo::CategoricalColumn::getBuffer ( ) const
overridevirtual

Return the buffer holding the internal representations (std::uint32_t) of the categorical values for the entire column.

Implements inviwo::Column.

◆ getBuffer() [2/2]

virtual std::shared_ptr< BufferBase > inviwo::CategoricalColumn::getBuffer ( )
overridevirtual

Return the buffer holding the internal representations (std::uint32_t) of the categorical values for the entire column.

Implements inviwo::Column.

◆ getCategories()

const std::vector< std::string > & inviwo::CategoricalColumn::getCategories ( ) const
inline

Returns the unique set of categorical values.

◆ getColumnType()

virtual ColumnType inviwo::CategoricalColumn::getColumnType ( ) const
overridevirtual

Implements inviwo::Column.

◆ getCustomRange()

virtual std::optional< dvec2 > inviwo::CategoricalColumn::getCustomRange ( ) const
overridevirtual

Returns the custom column range. If no range has been set previously, the return value will be std::nullopt.

Implements inviwo::Column.

◆ getDataRange()

virtual dvec2 inviwo::CategoricalColumn::getDataRange ( ) const
overridevirtual

Returns the range (i.e. the min/max) of the data, ignoring any custom range

Implements inviwo::Column.

◆ getHeader()

virtual const std::string & inviwo::CategoricalColumn::getHeader ( ) const
overridevirtual

Implements inviwo::Column.

◆ getId()

std::uint32_t inviwo::CategoricalColumn::getId ( size_t idx) const

Return the numerical id of the category in row idx.

◆ getRange()

virtual dvec2 inviwo::CategoricalColumn::getRange ( ) const
overridevirtual

Returns the custom range if set or else the range (i.e. the min/max) of the data

Implements inviwo::Column.

◆ getSize()

virtual size_t inviwo::CategoricalColumn::getSize ( ) const
overridevirtual

Implements inviwo::Column.

◆ getTypedBuffer() [1/2]

std::shared_ptr< Buffer< std::uint32_t > > inviwo::CategoricalColumn::getTypedBuffer ( )

Return the buffer holding the internal representations (std::uint32_t) of the categorical values for the entire column.

◆ getTypedBuffer() [2/2]

std::shared_ptr< const Buffer< std::uint32_t > > inviwo::CategoricalColumn::getTypedBuffer ( ) const

Return the buffer holding the internal representations (std::uint32_t) of the categorical values for the entire column.

◆ getUnit()

virtual Unit inviwo::CategoricalColumn::getUnit ( ) const
overridevirtual

Implements inviwo::Column.

◆ getValues()

std::vector< std::string > inviwo::CategoricalColumn::getValues ( ) const

Returns column contents as list of categorical values.

Returns
all categorical values stored in the column
See also
values

◆ set() [1/2]

void inviwo::CategoricalColumn::set ( size_t idx,
std::string_view str )

Set the value of row idx to str.

◆ set() [2/2]

void inviwo::CategoricalColumn::set ( size_t idx,
std::uint32_t id )

Set the value of row idx by using the numerical id of a category.

Exceptions
RangeExceptionif id does not correspond to a registered category
See also
addCategory

◆ setCustomRange()

virtual void inviwo::CategoricalColumn::setCustomRange ( std::optional< dvec2 > )
overridevirtual

Set a custom range for the column which can be used for normalization, plotting, color mapping, etc.

Implements inviwo::Column.

◆ setHeader()

void inviwo::CategoricalColumn::setHeader ( std::string_view header)
overridevirtual

Implements inviwo::Column.

◆ setUnit()

virtual void inviwo::CategoricalColumn::setUnit ( Unit unit)
overridevirtual

Implements inviwo::Column.

◆ values()

util::iter_range< ConstIterator > inviwo::CategoricalColumn::values ( ) const

Returns a const iterator range over all rows of the column holding the corresponding categorical values as const std::string&.

Example:

CategoricalColumn col("example", {"first", "second"});
for (auto v : col.values()) {
std::cout << "value: " << v;
}
for (auto&& [row, v] : util::enumerate<std::uint32_t>(col.values())) {
std::cout << fmt::format("Row: {}, value: {}", row, v);
}
Specialized data column representing categorical values, i.e. strings. Categorical values are interna...
Definition column.h:275
auto enumerate(T &&cont, Ts &&... conts)
Definition zip.h:571
Returns
iterator range over all categorical values stored in the column
See also
getValues

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