Cafu Engine
SHLMapMan.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_SCENEGRAPH_SHLMAP_MANAGER_HPP_INCLUDED
8 #define CAFU_SCENEGRAPH_SHLMAP_MANAGER_HPP_INCLUDED
9 
10 #include "Templates/Array.hpp"
11 
12 #include <fstream>
13 
14 namespace MatSys
15 {
16  class TextureMapI;
17 }
18 
19 
20 namespace cf
21 {
22  namespace SceneGraph
23  {
24  /// This class manages SHL maps, e.g. by "allocating" rectangular areas in larger coefficient maps.
25  class SHLMapManT
26  {
27  public:
28 
29  static const unsigned long SIZE_S;
30  static const unsigned long SIZE_T;
31 
32  static char NrOfBands; ///< Number n of bands for which we have computed and stored coefficients (n^2 many).
33  static unsigned int NrOfRepres; ///< Number of representatives of SH vectors. If >0, the SHL coeffs are compressed, uncompressed otherwise.
34 
35  struct SHLMapT
36  {
37  /// Constructor.
38  SHLMapT();
39 
40  /// This should actually be ArrayT< ArrayT<float> > Coeffs; that is, for each SHLMap element,
41  /// store an array of coefficients. However, this adds the overhead of the internal 'ArrayT'
42  /// management data to the storage for each element, and thus we prefer the "flat" approach.
44 
45  /// For compressed SHL coeffs, this array contains the index for each map element into the bigger lookup-table.
46  /// That is, if NrOfRepres>0, then Indices.Size()==SIZE_S*SIZE_T, and 0 otherwise.
48  };
49 
50 
51  /// The constructor.
52  SHLMapManT();
53 
54  /// The destructor.
55  ~SHLMapManT();
56 
57  /// Reads the lookup-table the indices are referring to (nothing is written when NrOfRepres==0 (uncompressed data)).
58  void ReadSHLCoeffsTable(std::istream& InFile);
59 
60  /// Write the lookup-table the indices are referring to (nothing is written when NrOfRepres==0 (uncompressed data)).
61  /// This writes a total of NrOfRepres*NR_OF_SH_COEFFS coefficients.
62  void WriteSHLCoeffsTable(std::ostream& OutFile) const;
63 
64  /// Finds a position for a rectangular SHLMap within SHLMaps[SHLMaps.Size()-1].Coeff.
65  /// If no such position exists, a new, empty SHLMapT is created and appended to the SHLMaps.
66  /// Returns true on success, false on failure (i.e. if SizeS>MAX_SIZE_S || SizeT>MAX_SIZE_T).
67  bool Allocate(unsigned long SizeS, unsigned long SizeT, unsigned long& BitmapNr, unsigned long& PosS, unsigned long& PosT);
68 
69  /// Initializes the MatSys textures.
70  void InitTextures();
71 
72 
73  ArrayT<SHLMapT*> SHLMaps;
74  ArrayT<float> SHLCoeffsTable; ///< The lookup-table of representatives (NrOfRepres * (NrOfBands^2) many) the SHLMaps::Indices refer to.
75 
76  /// For uncompressed SHL coeffs, for each SHLMap we store an array of texture objects,
77  /// where each texture contains four SHL coeffs (in its RGBA components).
78  /// Thus, for 16 SHL coeffs (uncompressed), we keep 16/4 == 4 textures per SHLMap.
79  /// For compressed SHL coeffs, each SHLMap only requires a single texture object
80  /// (that is, the size of the inner arrays is always 1), because in this case, we only
81  /// store SHL vector *indices* (16 bit precision) that only require the R and G components
82  /// (8 bits each) of a single texture.
84 
85  // For compressed SHL data, this is the table of representatives.
86  // Unused when uncompressed SHL data is used.
87  MatSys::TextureMapI* SHLRepresentativesTexture;
88  unsigned long SHLRepresentativesTexWidth;
89 
90 
91  private:
92 
93  SHLMapManT(const SHLMapManT&); ///< Use of the Copy Constructor is not allowed.
94  void operator = (const SHLMapManT&); ///< Use of the Assignment Operator is not allowed.
95 
96  bool AllocateHelper(unsigned long SizeS, unsigned long SizeT, unsigned long& PosS, unsigned long& PosT);
97 
98  ArrayT<unsigned long> BitmapAllocated;
99  };
100  }
101 }
102 
103 #endif
ArrayT< ArrayT< MatSys::TextureMapI * > > SHLMapTextures
For uncompressed SHL coeffs, for each SHLMap we store an array of texture objects, where each texture contains four SHL coeffs (in its RGBA components).
Definition: SHLMapMan.hpp:83
This class manages SHL maps, e.g. by "allocating" rectangular areas in larger coefficient maps...
Definition: SHLMapMan.hpp:25
SHLMapManT()
The constructor.
Definition: SHLMapMan.cpp:40
void ReadSHLCoeffsTable(std::istream &InFile)
Reads the lookup-table the indices are referring to (nothing is written when NrOfRepres==0 (uncompres...
Definition: SHLMapMan.cpp:70
void WriteSHLCoeffsTable(std::ostream &OutFile) const
Write the lookup-table the indices are referring to (nothing is written when NrOfRepres==0 (uncompres...
Definition: SHLMapMan.cpp:83
~SHLMapManT()
The destructor.
Definition: SHLMapMan.cpp:49
ArrayT< float > Coeffs
This should actually be ArrayT< ArrayT<float> > Coeffs; that is, for each SHLMap element, store an array of coefficients.
Definition: SHLMapMan.hpp:43
static char NrOfBands
Number n of bands for which we have computed and stored coefficients (n^2 many).
Definition: SHLMapMan.hpp:32
Definition: SHLMapMan.hpp:35
ArrayT< float > SHLCoeffsTable
The lookup-table of representatives (NrOfRepres * (NrOfBands^2) many) the SHLMaps::Indices refer to...
Definition: SHLMapMan.hpp:74
This is an interface to a texture-map.
Definition: TextureMap.hpp:23
static unsigned int NrOfRepres
Number of representatives of SH vectors. If >0, the SHL coeffs are compressed, uncompressed otherwise...
Definition: SHLMapMan.hpp:33
bool Allocate(unsigned long SizeS, unsigned long SizeT, unsigned long &BitmapNr, unsigned long &PosS, unsigned long &PosT)
Finds a position for a rectangular SHLMap within SHLMaps[SHLMaps.Size()-1].Coeff. ...
Definition: SHLMapMan.cpp:90
SHLMapT()
Constructor.
Definition: SHLMapMan.cpp:21
void InitTextures()
Initializes the MatSys textures.
Definition: SHLMapMan.cpp:109
ArrayT< unsigned short > Indices
For compressed SHL coeffs, this array contains the index for each map element into the bigger lookup-...
Definition: SHLMapMan.hpp:47