BaseBuffer.hpp
Go to the documentation of this file.
1 
28 #pragma once
29 
30 #ifndef LVR2_TYPES_BASEBUFFER
31 #define LVR2_TYPES_BASEBUFFER
32 
33 #include <algorithm>
34 #include <vector>
35 #include "MultiChannelMap.hpp"
36 #include "lvr2/io/DataStruct.hpp"
37 
38 namespace lvr2 {
39 
40 using intOptional = boost::optional<int>;
41 using floatOptional = boost::optional<float>;
42 using ucharOptional = boost::optional<unsigned char>;
43 
47 
54 class BaseBuffer : public MultiChannelMap {
56 public:
57  using base::base;
58 
62 
69  template<typename T>
70  size_t channelWidth(const std::string& name) const;
71 
77  inline size_t ucharChannelWidth(const std::string& name) const
78  {
79  return channelWidth<unsigned char>(name);
80  }
81 
87  inline size_t floatChannelWidth(const std::string& name) const
88  {
89  return channelWidth<float>(name);
90  }
91 
97  inline size_t indexChannelWidth(const std::string& name) const
98  {
99  return channelWidth<unsigned int>(name);
100  }
101 
105 
111  template<typename T>
112  bool hasChannel(const std::string& name) const;
113 
118  inline bool hasUCharChannel(const std::string& name) const
119  {
120  return hasChannel<unsigned char>(name);
121  }
122 
127  inline bool hasFloatChannel(const std::string& name) const
128  {
129  return hasChannel<float>(name);
130  }
131 
136  inline bool hasIndexChannel(const std::string& name) const
137  {
138  return hasChannel<unsigned int>(name);
139  }
140 
144 
151  template<typename T>
152  void addChannel(typename Channel<T>::Ptr data, const std::string& name);
153 
159  inline void addFloatChannel(FloatChannelPtr data, const std::string& name)
160  {
161  addChannel<float>(data, name);
162  }
163 
169  inline void addUCharChannel(UCharChannelPtr data, const std::string& name)
170  {
171  addChannel<unsigned char>(data, name);
172  }
173 
179  inline void addIndexChannel(IndexChannelPtr data, const std::string& name)
180  {
181  addChannel<unsigned int>(data, name);
182  }
183 
190  template<typename T>
191  void addChannel(boost::shared_array<T> array, std::string name, size_t n, size_t width);
192 
198  inline void addIndexChannel( indexArray array, std::string name, size_t n, size_t width)
199  {
200  addChannel<unsigned int>(array, name, n, width);
201  }
202 
208  inline void addFloatChannel( floatArr array, std::string name, size_t n, size_t width)
209  {
210  addChannel<float>(array, name, n, width);
211  }
212 
220  inline void addUCharChannel(ucharArr array, std::string name, size_t n, size_t width)
221  {
222  addChannel<unsigned char>(array, name, n, width);
223  }
224 
233  template<typename T>
234  void addEmptyChannel( const std::string& name, size_t n, size_t width);
235 
242  inline void addEmptyFloatChannel( const std::string& name, size_t n, size_t width)
243  {
244  addEmptyChannel<float>(name, n, width);
245  }
246 
253  inline void addEmptyUCharChannel( const std::string& name, size_t n, size_t width)
254  {
255  addEmptyChannel<unsigned char>(name, n, width);
256  }
257 
264  inline void addEmptyIndexChannel( const std::string& name, size_t n, size_t width)
265  {
266  addEmptyChannel<unsigned int>(name, n, width);
267  }
268 
272 
282  template<typename T>
283  bool removeChannel(const std::string& name);
284 
293  bool removeIndexChannel(const std::string& name)
294  {
295  return removeChannel<unsigned int>(name);
296  }
297 
306  bool removeFloatChannel(const std::string& name)
307  {
308  return removeChannel<float>(name);
309  }
310 
319  bool removeUCharChannel(const std::string& name)
320  {
321  return removeChannel<unsigned char>(name);
322  }
323 
327  //
328 
337  template <typename T>
338  int getAllChannelsOfType(std::map<std::string, Channel<T> >& channels)
339  {
340  for(auto it = this->typedBegin<T>(); it != this->end(); ++it)
341  {
342  channels.insert(*it);
343  }
345  }
346 
355  template <typename T>
356  int getAllChannelsOfType(std::vector<std::pair<std::string, Channel<T> >>& channels)
357  {
358  for(auto it = this->typedBegin<T>(); it != this->end(); ++it)
359  {
360  channels.push_back({it->first, it->second});
361  }
363  }
364 
365 
373  template<typename T>
374  typename Channel<T>::Optional getChannel(const std::string& name);
375 
383  template<typename T>
384  const typename Channel<T>::Optional getChannel(const std::string& name) const;
385 
386 
393  inline Channel<float>::Optional getFloatChannel(const std::string& name)
394  {
395  return getChannel<float>(name);
396  }
397 
404  inline Channel<unsigned char>::Optional getUCharChannel(const std::string& name)
405  {
406  return getChannel<unsigned char>(name);
407  }
408 
415  inline Channel<unsigned int>::Optional getIndexChannel(const std::string& name)
416  {
417  return getChannel<unsigned int>(name);
418  }
419 
426  inline void getChannel(const std::string& name, FloatChannelOptional& channelOptional )
427  {
428  channelOptional = getFloatChannel(name);
429  }
430 
437  inline void getChannel(const std::string& name, IndexChannelOptional& channelOptional)
438  {
439  channelOptional = getIndexChannel(name);
440  }
441 
448  inline void getChannel(const std::string& name, UCharChannelOptional& channelOptional)
449  {
450  channelOptional = getUCharChannel(name);
451  }
452 
456 
465  template<typename T>
466  ElementProxy<T> getHandle(unsigned int idx, const std::string& name);
467 
475  inline FloatProxy getFloatHandle(unsigned int idx, const std::string& name)
476  {
477  return getHandle<float>(idx, name);
478  }
479 
487  inline UCharProxy getUCharHandle(unsigned int idx, const std::string& name)
488  {
489  return getHandle<unsigned char>(idx, name);
490  }
491 
499  inline IndexProxy getIndexHandle(unsigned int idx, const std::string& name)
500  {
501  return getHandle<unsigned int>(idx, name);
502  }
503 
507 
517  template<typename T>
518  boost::shared_array<T> getArray(const std::string& name, size_t& n, size_t& w);
519 
528  inline floatArr getFloatArray(const std::string& name, size_t& n, size_t& w)
529  {
530  return getArray<float>(name, n, w);
531  }
532 
541  inline ucharArr getUCharArray(const std::string& name, size_t& n, size_t& w)
542  {
543  return getArray<unsigned char>(name, n, w);
544  }
545 
554  inline indexArray getIndexArray(const std::string& name, size_t& n, size_t& w)
555  {
556  return getArray<unsigned int>(name, n, w);
557  }
558 
562 
572  template<typename T>
573  void addAtomic(T data, const std::string& name);
574 
582  inline void addFloatAtomic(float data, const std::string& name)
583  {
584  addAtomic(data, name);
585  }
586 
595  inline void addUCharAtomic(unsigned char data, const std::string& name)
596  {
597  addAtomic(data, name);
598  }
599 
608  inline void addIntAtomic(int data, const std::string& name)
609  {
610  addAtomic(data, name);
611  }
615 
625  template<typename T>
626  boost::optional<T> getAtomic(const std::string& name);
627 
636  inline floatOptional getFloatAtomic(const std::string& name)
637  {
638  return getAtomic<float>(name);
639  }
640 
649  inline ucharOptional getUCharAtomic(const std::string& name)
650  {
651  return getAtomic<unsigned char>(name);
652  }
653 
662  inline intOptional getIntAtomic(const std::string& name)
663  {
664  return getAtomic<int>(name);
665  }
666 
667  template<typename V>
669  {
670  BaseBuffer cm;
671  for(auto vchannel: *this)
672  {
673  cm.insert({vchannel.first, boost::apply_visitor(visitor, vchannel.second)});
674  }
675  return cm;
676  }
677 
678  BaseBuffer clone() const {
679  BaseBuffer ret;
680 
681  for(auto elem : *this)
682  {
683  ret.insert({elem.first, elem.second.clone()});
684  }
685 
686  return ret;
687  }
688 };
689 
690 } // namespace lvr2
691 
692 #include "BaseBuffer.tcc"
693 
694 #endif // LVR2_TYPES_BASEBUFFER
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::BaseBuffer::addIntAtomic
void addIntAtomic(int data, const std::string &name)
Adds an atomic int value. Exists only for compatibility reasons. Dont use atomics,...
Definition: BaseBuffer.hpp:608
lvr2::BaseBuffer::getAtomic
boost::optional< T > getAtomic(const std::string &name)
Gets an atomic value.
lvr2::IndexChannelOptional
IndexChannel::Optional IndexChannelOptional
Definition: Channel.hpp:100
lvr2::FloatChannelPtr
FloatChannel::Ptr FloatChannelPtr
Definition: Channel.hpp:89
lvr2::UCharChannelOptional
UCharChannel::Optional UCharChannelOptional
Definition: Channel.hpp:96
lvr2::BaseBuffer::hasUCharChannel
bool hasUCharChannel(const std::string &name) const
Checks if an uchar channel is available.
Definition: BaseBuffer.hpp:118
lvr2::ElementProxy
Definition: ElementProxy.hpp:43
lvr2::BaseBuffer::floatChannelWidth
size_t floatChannelWidth(const std::string &name) const
Gets a float channels width.
Definition: BaseBuffer.hpp:87
lvr2::BaseBuffer::getIndexHandle
IndexProxy getIndexHandle(unsigned int idx, const std::string &name)
Get a Handle object (ElementProxy) of an index channel.
Definition: BaseBuffer.hpp:499
lvr2::BaseBuffer::getChannel
void getChannel(const std::string &name, FloatChannelOptional &channelOptional)
Gets a float channel and returns it as optional.
Definition: BaseBuffer.hpp:426
lvr2::Channel::Optional
boost::optional< Channel< T > > Optional
Definition: Channel.hpp:45
lvr2::UCharChannelPtr
UCharChannel::Ptr UCharChannelPtr
Definition: Channel.hpp:97
lvr2::indexArray
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
lvr2::BaseBuffer::getUCharHandle
UCharProxy getUCharHandle(unsigned int idx, const std::string &name)
Get a Handle object (ElementProxy) of an uchar channel.
Definition: BaseBuffer.hpp:487
lvr2::BaseBuffer::getArray
boost::shared_array< T > getArray(const std::string &name, size_t &n, size_t &w)
Gets a channel as array.
lvr2::BaseBuffer::getChannel
void getChannel(const std::string &name, IndexChannelOptional &channelOptional)
Gets an index channel and returns it as optional.
Definition: BaseBuffer.hpp:437
lvr2::BaseBuffer::channelWidth
size_t channelWidth(const std::string &name) const
Gets a channels width.
lvr2::BaseBuffer::addEmptyIndexChannel
void addEmptyIndexChannel(const std::string &name, size_t n, size_t width)
Adds an empty index channel to the map.
Definition: BaseBuffer.hpp:264
lvr2::BaseBuffer::getAllChannelsOfType
int getAllChannelsOfType(std::vector< std::pair< std::string, Channel< T > >> &channels)
Returns all channels of type T.
Definition: BaseBuffer.hpp:356
lvr2::ucharOptional
boost::optional< unsigned char > ucharOptional
Definition: BaseBuffer.hpp:42
lvr2::BaseBuffer::hasIndexChannel
bool hasIndexChannel(const std::string &name) const
Checks if an index channel is available.
Definition: BaseBuffer.hpp:136
lvr2::BaseBuffer::addFloatChannel
void addFloatChannel(floatArr array, std::string name, size_t n, size_t width)
Constructs a float channel from an boost::shared_array and saves it to the map.
Definition: BaseBuffer.hpp:208
lvr2::BaseBuffer::clone
BaseBuffer clone() const
Definition: BaseBuffer.hpp:678
lvr2::BaseBuffer::addAtomic
void addAtomic(T data, const std::string &name)
Adds an atomic value. Exists only for compatibility reasons. Dont use atomics, they are implemented a...
lvr2::BaseBuffer::getChannel
Channel< T >::Optional getChannel(const std::string &name)
Gets a channel and returns it as optional.
lvr2::BaseBuffer::manipulate
BaseBuffer manipulate(V visitor)
Definition: BaseBuffer.hpp:668
lvr2::FloatChannelOptional
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
lvr2::BaseBuffer::getFloatAtomic
floatOptional getFloatAtomic(const std::string &name)
Gets an atomic float value.
Definition: BaseBuffer.hpp:636
lvr2::BaseBuffer::indexChannelWidth
size_t indexChannelWidth(const std::string &name) const
Gets an index channels width.
Definition: BaseBuffer.hpp:97
lvr2::floatOptional
boost::optional< float > floatOptional
Definition: BaseBuffer.hpp:41
lvr2::IndexChannelPtr
IndexChannel::Ptr IndexChannelPtr
Definition: Channel.hpp:101
lvr2::BaseBuffer::ucharChannelWidth
size_t ucharChannelWidth(const std::string &name) const
Gets an uchar channels width.
Definition: BaseBuffer.hpp:77
lvr2::map
OutMapT< typename InMapT::HandleType, std::result_of_t< MapF(typename InMapT::ValueType)> > map(const InMapT &mapIn, MapF func)
Calls func for each value of the given map and save the result in the output map.
lvr2::BaseBuffer::getAllChannelsOfType
int getAllChannelsOfType(std::map< std::string, Channel< T > > &channels)
Returns all channels of type T.
Definition: BaseBuffer.hpp:338
lvr2::BaseBuffer::getIndexArray
indexArray getIndexArray(const std::string &name, size_t &n, size_t &w)
Gets an index channel as array.
Definition: BaseBuffer.hpp:554
lvr2::BaseBuffer::addIndexChannel
void addIndexChannel(indexArray array, std::string name, size_t n, size_t width)
Constructs an index channel from an boost::shared_array and saves it to the map.
Definition: BaseBuffer.hpp:198
lvr2::BaseBuffer::removeFloatChannel
bool removeFloatChannel(const std::string &name)
Removes a float channel. @detail If the type is not required use: erase.
Definition: BaseBuffer.hpp:306
lvr2::BaseBuffer::getIndexChannel
Channel< unsigned int >::Optional getIndexChannel(const std::string &name)
Gets an index channel and returns it as optional.
Definition: BaseBuffer.hpp:415
lvr2::BaseBuffer::addUCharChannel
void addUCharChannel(ucharArr array, std::string name, size_t n, size_t width)
Constructs an uchar channel from an boost::shared_array and saves it to the map.
Definition: BaseBuffer.hpp:220
lvr2::BaseBuffer::getIntAtomic
intOptional getIntAtomic(const std::string &name)
Gets an atomic int value.
Definition: BaseBuffer.hpp:662
lvr2::BaseBuffer::getChannel
void getChannel(const std::string &name, UCharChannelOptional &channelOptional)
Gets an uchar channel and returns it as optional.
Definition: BaseBuffer.hpp:448
lvr2::Channel::Ptr
std::shared_ptr< Channel< T > > Ptr
Definition: Channel.hpp:46
lvr2::BaseBuffer
ChannelManager class Store and access AttributeChannels. It expands the MultiChannelMap with downwoar...
Definition: BaseBuffer.hpp:54
lvr2::MultiChannelMap
VariantChannelMap< char, unsigned char, short, unsigned short, int, unsigned int, float, double > MultiChannelMap
Definition: MultiChannelMap.hpp:59
DataStruct.hpp
Datastructures for holding loaded data.
lvr2::VariantChannelMap
Definition: VariantChannelMap.hpp:43
lvr2::BaseBuffer::addUCharChannel
void addUCharChannel(UCharChannelPtr data, const std::string &name)
Adds an uchar channel pointer to the map.
Definition: BaseBuffer.hpp:169
lvr2::BaseBuffer::addChannel
void addChannel(typename Channel< T >::Ptr data, const std::string &name)
Adds a channel pointer to the map.
lvr2::BaseBuffer::hasFloatChannel
bool hasFloatChannel(const std::string &name) const
Checks if a float channel is available.
Definition: BaseBuffer.hpp:127
lvr2::BaseBuffer::removeIndexChannel
bool removeIndexChannel(const std::string &name)
Removes an index channel. @detail If the type is not required use: erase.
Definition: BaseBuffer.hpp:293
lvr2::BaseBuffer::getFloatChannel
Channel< float >::Optional getFloatChannel(const std::string &name)
Gets a float channel and returns it as optional.
Definition: BaseBuffer.hpp:393
lvr2::Channel
Definition: Channel.hpp:42
lvr2::BaseBuffer::getUCharArray
ucharArr getUCharArray(const std::string &name, size_t &n, size_t &w)
Gets an uchar channel as array.
Definition: BaseBuffer.hpp:541
MultiChannelMap.hpp
lvr2::BaseBuffer::addUCharAtomic
void addUCharAtomic(unsigned char data, const std::string &name)
Adds an atomic uchar value. Exists only for compatibility reasons. Dont use atomics,...
Definition: BaseBuffer.hpp:595
lvr2::BaseBuffer::addFloatAtomic
void addFloatAtomic(float data, const std::string &name)
Adds an atomic float value. Exists only for compatibility reasons. Dont use atomics,...
Definition: BaseBuffer.hpp:582
lvr2::BaseBuffer::removeUCharChannel
bool removeUCharChannel(const std::string &name)
Removes an uchar channel. @detail If the type is not required use: erase.
Definition: BaseBuffer.hpp:319
lvr2::BaseBuffer::getFloatHandle
FloatProxy getFloatHandle(unsigned int idx, const std::string &name)
Get a Handle object (ElementProxy) of a float channel.
Definition: BaseBuffer.hpp:475
lvr2::BaseBuffer::addEmptyUCharChannel
void addEmptyUCharChannel(const std::string &name, size_t n, size_t width)
Adds an empty uchar channel to the map.
Definition: BaseBuffer.hpp:253
lvr2::ucharArr
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
lvr2::BaseBuffer::addEmptyFloatChannel
void addEmptyFloatChannel(const std::string &name, size_t n, size_t width)
Adds an empty float channel to the map.
Definition: BaseBuffer.hpp:242
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::BaseBuffer::addIndexChannel
void addIndexChannel(IndexChannelPtr data, const std::string &name)
Adds an index channel pointer to the map. cointer to add. cannel.
Definition: BaseBuffer.hpp:179
lvr2::BaseBuffer::getUCharAtomic
ucharOptional getUCharAtomic(const std::string &name)
Gets an atomic uchar value.
Definition: BaseBuffer.hpp:649
lvr2::BaseBuffer::hasChannel
bool hasChannel(const std::string &name) const
Checks if a channel is available.
lvr2::BaseBuffer::addFloatChannel
void addFloatChannel(FloatChannelPtr data, const std::string &name)
Adds a float channel pointer to the map.
Definition: BaseBuffer.hpp:159
lvr2::BaseBuffer::getUCharChannel
Channel< unsigned char >::Optional getUCharChannel(const std::string &name)
Gets an uchar channel and returns it as optional.
Definition: BaseBuffer.hpp:404
lvr2::BaseBuffer::removeChannel
bool removeChannel(const std::string &name)
Removes a channel with a specific type. @detail If the type is not required use: erase.
lvr2::BaseBuffer::getHandle
ElementProxy< T > getHandle(unsigned int idx, const std::string &name)
Get a Handle object (ElementProxy) of a specific typed channel.
lvr2::BaseBuffer::addEmptyChannel
void addEmptyChannel(const std::string &name, size_t n, size_t width)
Adds an empty channel to the map.
lvr2::VariantChannelMap::base
std::unordered_map< std::string, VariantChannel< T... > > base
Definition: VariantChannelMap.hpp:52
lvr2::intOptional
boost::optional< int > intOptional
Definition: BaseBuffer.hpp:40
lvr2::VariantChannelMap::index_of_type
Access type index by type.
Definition: VariantChannelMap.hpp:61
lvr2::BaseBuffer::getFloatArray
floatArr getFloatArray(const std::string &name, size_t &n, size_t &w)
Gets a float channel as array.
Definition: BaseBuffer.hpp:528


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:22