HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMG_FileTTMap.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: IMG_FileTTMap.h ( IMG Library, C++)
7  *
8  * COMMENTS: Tiled Texture Maps
9  */
10 
11 #ifndef __IMG_FileTTMap__
12 #define __IMG_FileTTMap__
13 
14 #include "IMG_API.h"
15 #include "IMG_File.h"
16 #include "IMG_TextureFilter.h"
17 #include <UT/UT_Array.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_UniquePtr.h>
20 #include <SYS/SYS_Inline.h>
21 
22 class UT_Filter;
23 class UT_FilterWindow;
24 class UT_Options;
25 class IMG_TTMipSampler;
26 class IMG_Raster;
27 
28 /// An IMG_TTChannel is used to retrieve pixel data from the image.
29 /// Each image owns an array of IMG_TTChannel objects that could
30 /// represent environment map rasters or mipmap levels.
32 {
33 public:
34  IMG_TTChannel();
35  virtual ~IMG_TTChannel();
36 
38 
39  virtual void getRes(int &xres, int &yres,
40  int &tile_xres, int &tile_yres) const = 0;
41 
42  virtual int64 getMemoryUsage(bool inclusive) const = 0;
43 
44  virtual void filterPixels(float *rgba, int nchan,
45  int first_x, int first_y,
47  const float *xweights,
48  const float *yweights,
49  int usize, int vsize) = 0;
50 
51  virtual void getPixel(float *rgba, int nchan, int iu, int iv,
52  const IMG_TextureFilter &filter) = 0;
53 
54  /// This method returns the raw pixel data.
55  virtual void getPixel(void *pixel, int iu, int iv) = 0;
56  /// Return raw scanline data
57  virtual void getScanline(void *scanline,
58  int y, int xres, size_t bpp);
59 
60  /// Return raw tile data
61  virtual void getTile(const UT_DimRect &region,
62  void *data,
63  int bytes_per_pixel,
64  int bytes_per_scanline);
65 
66  /// This method is called when the channel is destroyed
67  virtual void closeChannel() {};
68 };
69 
70 /// A IMG_TTMap represents a tiled texture format that can be
71 /// sampled for texture mapping or for environment mapping. This class
72 /// supports methods for sampling and filtering the texture data.
73 /// This class is pure virtual and so derived classes must override the
74 /// image file and format operations.
75 class IMG_API IMG_FileTTMap : public IMG_File
76 {
77 public:
78  IMG_FileTTMap();
79  ~IMG_FileTTMap() override;
80 
82 
83  const char *className() const override { return "IMG_FileTTMap"; }
84 
85  /// Return true if texture evaluation of this format is enabled
86  virtual bool textureEnabled() const;
87 
88  int getOGLRaster(void *data, int xres, int yres,
90  int raster_number=0);
91 
92  /// Lookup information about the raster specified by the IMG_TextureFilter
93  /// This returns the resolution for each MIP map as well as the data format
94  /// and the number of image channels.
95  bool getMipInfo(int aov_channel,
97  IMG_DataType &data_type,
98  int &nchannels) const;
99 
100  /// Read pixels for a given MIP level
101  bool getMipData(int aov_channel, int mip_level,
102  const UT_DimRect &region,
103  void *data) const;
104 
105  // Perform unfiltered evaluation at a specified uv. This operation
106  // will not even perform filtering on pixels, so the caller is
107  // responsible for all filtering and antialiasing.
108  void unfilteredSample(
109  float *result, int tuple_size, float u, float v,
110  const IMG_TextureFilter &info,
111  int channel, int raster);
112 
113  // Sample with filtering at the specified uv.
114  void sample(float *result, int tuple_size, float u, float v,
115  const IMG_TextureFilter &info,
116  int channel, int raster)
117  {
118  float ua[4] = {u,u,u,u};
119  float va[4] = {v,v,v,v};
120 
121  sample(result, tuple_size,
122  ua, va, 1, info, channel, raster);
123  }
124 
125 
126  // Sample the map within a quadrilateral in texture space. When
127  // specifying four corners of the map, the order of the coordinates is
128  // very important:
129  //
130  // BAD GOOD GOOD
131  // 2--3 3--2 2--3
132  // \/ | | | |
133  // /\ | | | |
134  // 0--1 0--1 1--0
135  void sample(float *result, float &visible, int tuple_size,
136  const float u[4], const float v[4],
137  float quality,
138  const IMG_TextureFilter &info,
139  int channel, int raster);
140  void sample(float *result, int tuple_size,
141  const float u[4], const float v[4],
142  float quality,
143  const IMG_TextureFilter &info,
144  int channel, int raster)
145  {
146  float visible;
147  sample(result, visible,
148  tuple_size, u, v, quality,
149  info, channel, raster);
150  }
151 
152  // Only call the envLookup functions if this RAT is really a cubic
153  // environment map.
154  void envLookup(float *result, int tuple_size,
155  const UT_Vector3 &r, float angle,
156  const IMG_TextureFilter &info, int channel);
157 
158  void envLookup(float *result, int tuple_size,
159  const UT_Vector3 &r00, const UT_Vector3 &r01,
160  const UT_Vector3 &r11, const UT_Vector3 &r10,
161  const IMG_TextureFilter &info,
162  int channel);
163 
164  fpreal getUPixelSize() const { return myDx; }
165  fpreal getVPixelSize() const { return myDy; }
166 
167  int64 getMemoryUsage(bool inclusive) const override;
168  virtual int getRasterCount() const { return 0; }
169  int getChannelTupleSize(int ch) const;
170  virtual int getNumChannels() const { return getStat().getNumPlanes(); }
171  const UT_StringHolder &ocioColorSpace(int channel) const;
172 
173  const UT_StringHolder &swrapMode() const { return mySWrapMode; }
174  const UT_StringHolder &twrapMode() const { return myTWrapMode; }
175 
176  // Return the channel index to use for lookups that haven't specified a
177  // particular channel.
178  virtual int getDefaultChannelIndex() const
179  { return 0; }
180  int findChannelIndex(const char *name) const;
181 
182  // TODO: Remove this method and replace with calls to IMG_Stat::getImageType
183  // Add IMG_TYPE_ENVMAP to the IMG_ImageType enum.
184  virtual int isReflMap() const { return 0; }
185 
187  { return myTTChannels(i).get(); }
188 
189 protected:
190  void initialize(int mipcount,
192 
193  int closeFile() override;
194 
196  exint numTTChannels() const { return myTTChannels.size(); }
198  IMG_TTChannel *getTTChannel(exint i) { return myTTChannels(i).get(); }
199 
200 protected:
201  // Mipmap level to start reading from the file.
203 
204 private:
205  void initScaleAndSize();
206 
207  //
208  // Data used in lookup of pixel values. These members MUST be
209  // initialized by derived classes before this class is used for
210  // sampling, by calling the initialize() method above.
211  //
212  void clearMips();
213 
214  // We have MIPs for each channel and raster
215  int getMipOffset(int aov, int image, int mip=0) const
216  {
217  // Each image AOV has myMipCount mip levels, so
218  // there are myMipCount IMG_TTChannel's for every
219  // AOV.
220  // Textures can contain multiple images (6-pack
221  // environment maps for example).
222  // These are flattened to a linear array:
223  // image0.aov0.mip0 [4x4]
224  // image0.aov0.mip1 [2x2]
225  // image0.aov0.mip2 [1x1]
226  // image1.aov0.mip0 [4x4]
227  // image1.aov0.mip1
228  // image1.aov0.mip2
229  // image2.aov0.mip0
230  // image2.aov0.mip1
231  // image2.aov0.mip2
232  // image0.aov1.mip0
233  // image0.aov1.mip1
234  // ...
235  return (aov*getRasterCount()+image)*myMipCount + mip;
236  }
237 
238  float myDx, myDy; // Inverse pixel sizes
239 
240  UT_Array<int> myColorSize;
241  UT_StringArray myOCIOColorSpace;
242  UT_StringHolder mySWrapMode;
243  UT_StringHolder myTWrapMode;
244 
245  // Mipmap samplers are stored as an array of pointers, with each
246  // entry representing one mipmap level. If this class is an
247  // environment map, multiple sets of mipmaps may be stored sequentially
248  // in this array.
249  UT_Array<UT_UniquePtr<IMG_TTMipSampler>> myMips; // Mip Maps
251  int myMipCount;
252  int myDSMComponentCount;
253  int myDepthComplexityPlane;
254  bool myFixMipFilterWidth;
255 };
256 
257 #endif
SYS_FORCE_INLINE IMG_TTChannel * getTTChannel(exint i)
const UT_StringHolder & swrapMode() const
virtual int isReflMap() const
SIM_API const UT_StringHolder angle
virtual int getNumChannels() const
const GLdouble * v
Definition: glcorearb.h:837
int64 exint
Definition: SYS_Types.h:125
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
GLint y
Definition: glcorearb.h:103
**But if you need a result
Definition: thread.h:613
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
#define IMG_API
Definition: IMG_API.h:10
virtual int getRasterCount() const
IMG_DataType
Definition: IMG_FileTypes.h:17
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
fpreal getVPixelSize() const
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
HUSD_API const char * raster()
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
Modes for filtering.
A map of string to various well defined value types.
Definition: UT_Options.h:84
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual void closeChannel()
This method is called when the channel is destroyed.
Definition: IMG_FileTTMap.h:67
void sample(float *result, int tuple_size, const float u[4], const float v[4], float quality, const IMG_TextureFilter &info, int channel, int raster)
IMG_ColorModel
Definition: IMG_FileTypes.h:52
const IMG_TTChannel * getChannel(exint i) const
fpreal getUPixelSize() const
void sample(float *result, int tuple_size, float u, float v, const IMG_TextureFilter &info, int channel, int raster)
GLboolean r
Definition: glcorearb.h:1222
virtual int getDefaultChannelIndex() const
SYS_FORCE_INLINE exint numTTChannels() const
Definition: format.h:895
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
const UT_StringHolder & twrapMode() const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297