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
int getAllChannelsOfType(std::vector< std::pair< std::string, Channel< T > >> &channels)
Returns all channels of type T.
Definition: BaseBuffer.hpp:356
UCharProxy getUCharHandle(unsigned int idx, const std::string &name)
Get a Handle object (ElementProxy) of an uchar channel.
Definition: BaseBuffer.hpp:487
BaseBuffer manipulate(V visitor)
Definition: BaseBuffer.hpp:668
void addAtomic(T data, const std::string &name)
Adds an atomic value. Exists only for compatibility reasons. Dont use atomics, they are implemented a...
Datastructures for holding loaded data.
void getChannel(const std::string &name, FloatChannelOptional &channelOptional)
Gets a float channel and returns it as optional.
Definition: BaseBuffer.hpp:426
ElementProxy< T > getHandle(unsigned int idx, const std::string &name)
Get a Handle object (ElementProxy) of a specific typed channel.
bool hasUCharChannel(const std::string &name) const
Checks if an uchar channel is available.
Definition: BaseBuffer.hpp:118
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
FloatProxy getFloatHandle(unsigned int idx, const std::string &name)
Get a Handle object (ElementProxy) of a float channel.
Definition: BaseBuffer.hpp:475
IndexProxy getIndexHandle(unsigned int idx, const std::string &name)
Get a Handle object (ElementProxy) of an index channel.
Definition: BaseBuffer.hpp:499
bool hasIndexChannel(const std::string &name) const
Checks if an index channel is available.
Definition: BaseBuffer.hpp:136
void addEmptyChannel(const std::string &name, size_t n, size_t width)
Adds an empty channel to the map.
boost::optional< T > getAtomic(const std::string &name)
Gets an atomic value.
void addEmptyFloatChannel(const std::string &name, size_t n, size_t width)
Adds an empty float channel to the map.
Definition: BaseBuffer.hpp:242
ucharOptional getUCharAtomic(const std::string &name)
Gets an atomic uchar value.
Definition: BaseBuffer.hpp:649
size_t indexChannelWidth(const std::string &name) const
Gets an index channels width.
Definition: BaseBuffer.hpp:97
std::unordered_map< std::string, VariantChannel< T... > > base
bool removeIndexChannel(const std::string &name)
Removes an index channel. If the type is not required use: erase.
Definition: BaseBuffer.hpp:293
size_t channelWidth(const std::string &name) const
Gets a channels width.
void addIntAtomic(int data, const std::string &name)
Adds an atomic int value. Exists only for compatibility reasons. Dont use atomics, they are implemented as Channels. -> memory overhead. Kept because of api stability.
Definition: BaseBuffer.hpp:608
boost::optional< int > intOptional
Definition: BaseBuffer.hpp:40
floatOptional getFloatAtomic(const std::string &name)
Gets an atomic float value.
Definition: BaseBuffer.hpp:636
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
UCharChannel::Optional UCharChannelOptional
Definition: Channel.hpp:96
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
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
void addFloatChannel(FloatChannelPtr data, const std::string &name)
Adds a float channel pointer to the map.
Definition: BaseBuffer.hpp:159
bool hasChannel(const std::string &name) const
Checks if a channel is available.
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. ...
void addChannel(typename Channel< T >::Ptr data, const std::string &name)
Adds a channel pointer to the map.
boost::optional< unsigned char > ucharOptional
Definition: BaseBuffer.hpp:42
void getChannel(const std::string &name, IndexChannelOptional &channelOptional)
Gets an index channel and returns it as optional.
Definition: BaseBuffer.hpp:437
floatArr getFloatArray(const std::string &name, size_t &n, size_t &w)
Gets a float channel as array.
Definition: BaseBuffer.hpp:528
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
void addEmptyUCharChannel(const std::string &name, size_t n, size_t width)
Adds an empty uchar channel to the map.
Definition: BaseBuffer.hpp:253
ucharArr getUCharArray(const std::string &name, size_t &n, size_t &w)
Gets an uchar channel as array.
Definition: BaseBuffer.hpp:541
void addIndexChannel(IndexChannelPtr data, const std::string &name)
Adds an index channel pointer to the map. cointer to add. cannel.
Definition: BaseBuffer.hpp:179
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
void addUCharChannel(UCharChannelPtr data, const std::string &name)
Adds an uchar channel pointer to the map.
Definition: BaseBuffer.hpp:169
void addUCharAtomic(unsigned char data, const std::string &name)
Adds an atomic uchar value. Exists only for compatibility reasons. Dont use atomics, they are implemented as Channels. -> memory overhead. Kept because of api stability.
Definition: BaseBuffer.hpp:595
void addEmptyIndexChannel(const std::string &name, size_t n, size_t width)
Adds an empty index channel to the map.
Definition: BaseBuffer.hpp:264
VariantChannelMap< char, unsigned char, short, unsigned short, int, unsigned int, float, double > MultiChannelMap
IndexChannel::Ptr IndexChannelPtr
Definition: Channel.hpp:101
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
boost::optional< Channel< T > > Optional
Definition: Channel.hpp:45
size_t floatChannelWidth(const std::string &name) const
Gets a float channels width.
Definition: BaseBuffer.hpp:87
intOptional getIntAtomic(const std::string &name)
Gets an atomic int value.
Definition: BaseBuffer.hpp:662
UCharChannel::Ptr UCharChannelPtr
Definition: Channel.hpp:97
boost::optional< float > floatOptional
Definition: BaseBuffer.hpp:41
bool removeFloatChannel(const std::string &name)
Removes a float channel. If the type is not required use: erase.
Definition: BaseBuffer.hpp:306
boost::shared_array< T > getArray(const std::string &name, size_t &n, size_t &w)
Gets a channel as array.
IndexChannel::Optional IndexChannelOptional
Definition: Channel.hpp:100
bool hasFloatChannel(const std::string &name) const
Checks if a float channel is available.
Definition: BaseBuffer.hpp:127
BaseBuffer clone() const
Definition: BaseBuffer.hpp:678
void getChannel(const std::string &name, UCharChannelOptional &channelOptional)
Gets an uchar channel and returns it as optional.
Definition: BaseBuffer.hpp:448
Channel< unsigned int >::Optional getIndexChannel(const std::string &name)
Gets an index channel and returns it as optional.
Definition: BaseBuffer.hpp:415
FloatChannel::Ptr FloatChannelPtr
Definition: Channel.hpp:89
void addFloatAtomic(float data, const std::string &name)
Adds an atomic float value. Exists only for compatibility reasons. Dont use atomics, they are implemented as Channels. -> memory overhead.
Definition: BaseBuffer.hpp:582
int getAllChannelsOfType(std::map< std::string, Channel< T > > &channels)
Returns all channels of type T.
Definition: BaseBuffer.hpp:338
Channel< float >::Optional getFloatChannel(const std::string &name)
Gets a float channel and returns it as optional.
Definition: BaseBuffer.hpp:393
size_t ucharChannelWidth(const std::string &name) const
Gets an uchar channels width.
Definition: BaseBuffer.hpp:77
std::shared_ptr< Channel< T > > Ptr
Definition: Channel.hpp:46
ChannelManager class Store and access AttributeChannels. It expands the MultiChannelMap with downwoar...
Definition: BaseBuffer.hpp:54
bool removeChannel(const std::string &name)
Removes a channel with a specific type. If the type is not required use: erase.
Channel< unsigned char >::Optional getUCharChannel(const std::string &name)
Gets an uchar channel and returns it as optional.
Definition: BaseBuffer.hpp:404
bool removeUCharChannel(const std::string &name)
Removes an uchar channel. If the type is not required use: erase.
Definition: BaseBuffer.hpp:319
indexArray getIndexArray(const std::string &name, size_t &n, size_t &w)
Gets an index channel as array.
Definition: BaseBuffer.hpp:554
Channel< T >::Optional getChannel(const std::string &name)
Gets a channel and returns it as optional.


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 Mon Feb 28 2022 22:46:06