Beatmup
Beatmup::NNets::Storage::View Class Reference

Maps a 3D tensor onto a storage. More...

#include <storage.h>

Classes

struct  Channel
 

Public Member Functions

 View ()
 
 View (View &&)
 
 View (const View &)
 
Viewoperator= (View &&)
 
 View (Storage &storage)
 
 View (View &&view, const int firstChannel, const int numChannels)
 Creates a slice of another view. More...
 
 View (Storage &storage, const int shuffleStep)
 Creates a view by shuffling storage channels. More...
 
StoragegetStorage ()
 
const StoragegetStorage () const
 
InternalBitmapgetImage (Context &ctx, GraphicPipeline &gpu, int channel) const
 
int getNumberOfTextures () const
 Returns total number of textures in the storage view. More...
 
int getChannelTextureNumber (int channel) const
 Returns number of the texture containing a given channel. More...
 
IntPoint getChannelOrigin (int channel) const
 Returns origin in pixels of a given channel within the texture containing it. More...
 
int getTextureWidth () const
 Returns width in pixels of all the textures. More...
 
int getTextureHeight () const
 Returns height in pixels of all the textures. More...
 
IntPoint getTextureSize () const
 
 operator bool () const
 Conversion operator to a boolean expression (true if the view is not empty). More...
 
Size getSize () const
 
IntPoint getSpatialSize () const
 Returns the spatial size (width and height) of the storage in pixels. More...
 
int getWidth () const
 
int getHeight () const
 
int getDepth () const
 

Private Attributes

std::vector< Channelchannels
 channels of the view More...
 
std::vector< int > textures
 indices of textures in the storage More...
 
Storagestorage
 

Friends

class Binder
 
class Scanner
 
class TextureHandler
 

Detailed Description

Maps a 3D tensor onto a storage.

Set of storage slices along the depth dimension.

Definition at line 308 of file storage.h.

Constructor & Destructor Documentation

◆ View() [1/6]

Beatmup::NNets::Storage::View::View ( )
inline

Definition at line 323 of file storage.h.

323 : storage(nullptr) {}

◆ View() [2/6]

Storage::View::View ( View &&  another)

Definition at line 409 of file storage.cpp.

409  {
410  channels.swap(another.channels);
411  textures.swap(another.textures);
412  storage = another.storage;
413  another.storage = nullptr;
414 }
std::vector< Channel > channels
channels of the view
Definition: storage.h:318
std::vector< int > textures
indices of textures in the storage
Definition: storage.h:319

◆ View() [3/6]

Storage::View::View ( const View another)

Definition at line 402 of file storage.cpp.

402  {
403  channels = another.channels;
404  textures = another.textures;
405  storage = another.storage;
406 }

◆ View() [4/6]

Storage::View::View ( Storage storage)

Definition at line 426 of file storage.cpp.

426  :
427  channels(storage.getSize()[2] / 4),
429  storage(&storage)
430 {
431  const int num = storage.getSize()[2] / 4;
432  for (int i = 0; i < num; ++i) {
433  channels[i].textureIdx = storage.getChannelTextureNumber(4 * i);
434  channels[i].channelIdx = 4 * i;
435  }
436  for (int i = 0; i < storage.getNumberOfTextures(); ++i)
437  textures[i] = i;
438 }
int getNumberOfTextures() const
Returns total number of textures in the storage.
Definition: storage.cpp:365
Size getSize() const
Returns storage size in pixels.
Definition: storage.h:273
int getChannelTextureNumber(int channel) const
Returns number of texture containing a given channel.
Definition: storage.cpp:370

◆ View() [5/6]

Storage::View::View ( View &&  view,
const int  firstChannel,
const int  numChannels 
)

Creates a slice of another view.

Parameters
[in]viewThe input storage view
[in]firstChannelFirst view channel index in the storage
[in]numChannelsNumber of channels in the view

Definition at line 441 of file storage.cpp.

441  :
442  storage(view.storage)
443 {
444 #ifdef BEATMUP_DEBUG
445  Storage::checkChannelNumber(firstChannel);
446  Storage::checkChannelNumber(firstChannel + numChannels);
447  OutOfRange::check(firstChannel + numChannels, 0, view.getDepth(), "Number of channels out of range: %d");
448 #endif
449  Bitset usedTextures(storage->getNumberOfTextures(), false);
450  for (int i = firstChannel; i < firstChannel + numChannels; i += 4)
451  usedTextures.set(view.textures[view.getChannelTextureNumber(i)]);
452 
453  textures.reserve(usedTextures.count());
454  std::map<int, int> textureMap;
455  for (int i = 0; i < storage->getNumberOfTextures(); ++i)
456  if (usedTextures[i]) {
457  textureMap[i] = textures.size();
458  textures.emplace_back(i);
459  }
460 
461  channels.reserve(numChannels / 4);
462  for (int i = firstChannel; i < firstChannel + numChannels; i += 4) {
463  const auto entry = view.channels[i / 4];
464  channels.push_back(Channel{ entry.channelIdx, textureMap[entry.textureIdx] });
465  }
466 }
A set of boolean flags.
Definition: bitset.h:30
static void checkChannelNumber(int channel)
Checks whether a channel number points to the first channel in a texture.
Definition: storage.h:290
static void check(const datatype value, const datatype min, const datatype max, const char *message)
Definition: exception.h:86

◆ View() [6/6]

Storage::View::View ( Storage storage,
const int  shuffleStep 
)

Creates a view by shuffling storage channels.

For shuffling step n, the view will contain the storage channel quads in the following order: 0, 1, 2, 3, 4n, 4n+1, 4n+2, 4n+3, 8n, 8n+1, 8n+2, 8n+3, ..., 4, 5, 6, 7, 4n+4, 4n+5, 4n+6, 4n+7, 8n+4, ...

Parameters
[in]storageThe storage
[in]shuffleStepShuffling step (n)

Definition at line 469 of file storage.cpp.

469  :
470  channels(storage.getSize()[2] / 4),
472  storage(&storage)
473 {
474  const int num = storage.getSize()[2] / 4;
475 #ifdef BEATMUP_DEBUG
476  OutOfRange::checkMin(shuffleStep, 1, "Shuffling step must be positive, but %d got");
477 #endif
478  RuntimeError::check(num % shuffleStep == 0, "Shuffling step *4 must be a divider of the storage depth");
479 
480  for (int i = 0; i < storage.getNumberOfTextures(); ++i)
481  textures[i] = i;
482 
483  for (int i = 0; i < num; ++i) {
484  const int shuffled = 4 * ((shuffleStep * i) % num + (shuffleStep * i) / num);
485  channels[i].textureIdx = storage.getChannelTextureNumber(shuffled);
486  channels[i].channelIdx = shuffled;
487  }
488 }
static void checkMin(const datatype value, const datatype min, const char *message)
Definition: exception.h:92
static void check(const bool condition, const std::string &message)
Definition: exception.h:64

Member Function Documentation

◆ operator=()

Storage::View & Storage::View::operator= ( View &&  another)

Definition at line 417 of file storage.cpp.

417  {
418  channels.swap(another.channels);
419  textures.swap(another.textures);
420  storage = another.storage;
421  another.storage = nullptr;
422  return *this;
423 }

◆ getStorage() [1/2]

Storage& Beatmup::NNets::Storage::View::getStorage ( )
inline

Definition at line 347 of file storage.h.

347 { return *storage; }

◆ getStorage() [2/2]

const Storage& Beatmup::NNets::Storage::View::getStorage ( ) const
inline

Definition at line 348 of file storage.h.

348 { return *storage; }

◆ getImage()

InternalBitmap * Storage::View::getImage ( Context ctx,
GraphicPipeline gpu,
int  channel 
) const

Definition at line 491 of file storage.cpp.

491  {
492 #ifdef BEATMUP_DEBUG
493  OutOfRange::check(channel, 0, getDepth() - 1, "Channel index out of range: %d");
494 #endif
495  const int storageChannel = channels[channel / 4].channelIdx + (channel % 4);
496  return storage->getImage(ctx, gpu, storageChannel);
497 }
InternalBitmap * getImage(Context &ctx, GraphicPipeline &gpu, int channel) const
Converts a feature channel into a bitmap for debugging purposes.
Definition: storage.cpp:312
Beatmup::Context * ctx

◆ getNumberOfTextures()

int Beatmup::NNets::Storage::View::getNumberOfTextures ( ) const
inline

Returns total number of textures in the storage view.

Definition at line 355 of file storage.h.

355 { return (int)textures.size(); }

◆ getChannelTextureNumber()

int Storage::View::getChannelTextureNumber ( int  channel) const

Returns number of the texture containing a given channel.

Definition at line 500 of file storage.cpp.

500  {
501 #ifdef BEATMUP_DEBUG
503  OutOfRange::check(channel, 0, getDepth() - 1, "Channel index out of range: %d");
504 #endif
505  return channels[channel / 4].textureIdx;
506 }

◆ getChannelOrigin()

IntPoint Storage::View::getChannelOrigin ( int  channel) const

Returns origin in pixels of a given channel within the texture containing it.

Definition at line 509 of file storage.cpp.

509  {
510 #ifdef BEATMUP_DEBUG
512  OutOfRange::check(channel, 0, getDepth() - 1, "Channel index out of range: %d");
513 #endif
514  const Channel& ch = channels[channel / 4];
515  return storage->getChannelOrigin(ch.channelIdx);
516 }
IntPoint getChannelOrigin(int channel) const
Returns origin in pixels of a given channel within the texture containing it.
Definition: storage.cpp:379

◆ getTextureWidth()

int Beatmup::NNets::Storage::View::getTextureWidth ( ) const
inline

Returns width in pixels of all the textures.

Definition at line 370 of file storage.h.

370 { return storage->getTextureWidth(); }
int getTextureWidth() const
Returns width in pixels of all the textures.
Definition: storage.cpp:390

◆ getTextureHeight()

int Beatmup::NNets::Storage::View::getTextureHeight ( ) const
inline

Returns height in pixels of all the textures.

Definition at line 375 of file storage.h.

375 { return storage->getTextureHeight(); }
int getTextureHeight() const
Returns height in pixels of all the textures.
Definition: storage.cpp:395

◆ getTextureSize()

IntPoint Beatmup::NNets::Storage::View::getTextureSize ( ) const
inline

Definition at line 377 of file storage.h.

CustomPoint< int > IntPoint
Definition: geometry.h:629

◆ operator bool()

Beatmup::NNets::Storage::View::operator bool ( ) const
inline

Conversion operator to a boolean expression (true if the view is not empty).

Definition at line 382 of file storage.h.

382 { return storage != nullptr; }

◆ getSize()

Size Beatmup::NNets::Storage::View::getSize ( ) const
inline

Definition at line 384 of file storage.h.

384 { return storage->getSize(); }

◆ getSpatialSize()

IntPoint Beatmup::NNets::Storage::View::getSpatialSize ( ) const
inline

Returns the spatial size (width and height) of the storage in pixels.

Definition at line 389 of file storage.h.

389  {
390  const Size size = storage->getSize();
391  return IntPoint(size[0], size[1]);
392  };

◆ getWidth()

int Beatmup::NNets::Storage::View::getWidth ( ) const
inline

Definition at line 394 of file storage.h.

394 { return storage->size[0]; }

◆ getHeight()

int Beatmup::NNets::Storage::View::getHeight ( ) const
inline

Definition at line 395 of file storage.h.

395 { return storage->size[1]; }

◆ getDepth()

int Beatmup::NNets::Storage::View::getDepth ( ) const
inline

Definition at line 396 of file storage.h.

396 { return 4 * (int)channels.size(); }

Friends And Related Function Documentation

◆ Binder

friend class Binder
friend

Definition at line 309 of file storage.h.

◆ Scanner

friend class Scanner
friend

Definition at line 310 of file storage.h.

◆ TextureHandler

friend class TextureHandler
friend

Definition at line 311 of file storage.h.

Member Data Documentation

◆ channels

std::vector<Channel> Beatmup::NNets::Storage::View::channels
private

channels of the view

Definition at line 318 of file storage.h.

◆ textures

std::vector<int> Beatmup::NNets::Storage::View::textures
private

indices of textures in the storage

Definition at line 319 of file storage.h.

◆ storage

Storage* Beatmup::NNets::Storage::View::storage
private

Definition at line 320 of file storage.h.


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