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 class TBF_Channel;
28 
29 
30 /// An IMG_TTChannel is used to retrieve pixel data from the image.
31 /// Each image owns an array of IMG_TTChannel objects that could
32 /// represent environment map rasters or mipmap levels.
34 {
35 public:
36  IMG_TTChannel();
37  virtual ~IMG_TTChannel();
38 
40 
41  virtual void getRes(int &xres, int &yres,
42  int &tile_xres, int &tile_yres) const = 0;
43 
44  virtual int64 getMemoryUsage(bool inclusive) const = 0;
45 
46  virtual void filterPixels(float *rgba, int nchan,
47  int first_x, int first_y,
49  const float *xweights,
50  const float *yweights,
51  int usize, int vsize) = 0;
52 
53  virtual void getPixel(float *rgba, int nchan, int iu, int iv,
54  const IMG_TextureFilter &filter) = 0;
55 
56  /// This method returns the raw pixel data.
57  virtual void getPixel(void *pixel, int iu, int iv) = 0;
58  /// Return raw scanline data
59  virtual void getScanline(void *scanline,
60  int y, int xres, size_t bpp);
61 
62  /// Return raw tile data
63  virtual void getTile(const UT_DimRect &region,
64  void *data,
65  int bytes_per_pixel,
66  int bytes_per_scanline);
67 
68  /// This method is called when the channel is destroyed
69  virtual void closeChannel() {};
70 };
71 
72 /// A IMG_TTMap represents a tiled texture format that can be
73 /// sampled for texture mapping or for environment mapping. This class
74 /// supports methods for sampling and filtering the texture data.
75 /// This class is pure virtual and so derived classes must override the
76 /// image file and format operations.
77 class IMG_API IMG_FileTTMap : public IMG_File
78 {
79 public:
80  IMG_FileTTMap();
81  ~IMG_FileTTMap() override;
82 
84 
85  const char *className() const override { return "IMG_FileTTMap"; }
86 
87  /// Return true if texture evaluation of this format is enabled
88  virtual bool textureEnabled() const;
89 
90  int getOGLRaster(void *data, int xres, int yres,
92  int raster_number=0);
93 
94  /// Lookup information about the raster specified by the IMG_TextureFilter
95  /// This returns the resolution for each MIP map as well as the data format
96  /// and the number of image channels.
97  bool getMipInfo(int aov_channel,
99  IMG_DataType &data_type,
100  int &nchannels) const;
101 
102  /// Read pixels for a given MIP level
103  bool getMipData(int aov_channel, int mip_level,
104  const UT_DimRect &region,
105  void *data) const;
106 
107  // Perform unfiltered evaluation at a specified uv. This operation
108  // will not even perform filtering on pixels, so the caller is
109  // responsible for all filtering and antialiasing.
110  void unfilteredSample(
111  float *result, int tuple_size, float u, float v,
112  const IMG_TextureFilter &info,
113  int channel, int raster);
114 
115  // Sample with filtering at the specified uv.
116  void sample(float *result, int tuple_size, float u, float v,
117  const IMG_TextureFilter &info,
118  int channel, int raster)
119  {
120  float ua[4] = {u,u,u,u};
121  float va[4] = {v,v,v,v};
122 
123  sample(result, tuple_size,
124  ua, va, 1, info, channel, raster);
125  }
126 
127 
128  // Sample the map within a quadrilateral in texture space. When
129  // specifying four corners of the map, the order of the coordinates is
130  // very important:
131  //
132  // BAD GOOD GOOD
133  // 2--3 3--2 2--3
134  // \/ | | | |
135  // /\ | | | |
136  // 0--1 0--1 1--0
137  void sample(float *result, float &visible, int tuple_size,
138  const float u[4], const float v[4],
139  float quality,
140  const IMG_TextureFilter &info,
141  int channel, int raster);
142  void sample(float *result, int tuple_size,
143  const float u[4], const float v[4],
144  float quality,
145  const IMG_TextureFilter &info,
146  int channel, int raster)
147  {
148  float visible;
149  sample(result, visible,
150  tuple_size, u, v, quality,
151  info, channel, raster);
152  }
153 
154  // Only call the envLookup functions if this RAT is really a cubic
155  // environment map.
156  void envLookup(float *result, int tuple_size,
157  const UT_Vector3 &r, float angle,
158  const IMG_TextureFilter &info, int channel);
159 
160  void envLookup(float *result, int tuple_size,
161  const UT_Vector3 &r00, const UT_Vector3 &r01,
162  const UT_Vector3 &r11, const UT_Vector3 &r10,
163  const IMG_TextureFilter &info,
164  int channel);
165 
166  fpreal getUPixelSize() const { return myDx; }
167  fpreal getVPixelSize() const { return myDy; }
168 
169  int64 getMemoryUsage(bool inclusive) const override;
170  virtual int getRasterCount() const { return 0; }
171  int getChannelTupleSize(int ch) const;
172  virtual int getNumChannels() const { return getStat().getNumPlanes(); }
173  const UT_StringHolder &ocioColorSpace(int channel) const;
174 
175  const UT_StringHolder &swrapMode() const { return mySWrapMode; }
176  const UT_StringHolder &twrapMode() const { return myTWrapMode; }
177 
178  // Return the channel index to use for lookups that haven't specified a
179  // particular channel.
180  virtual int getDefaultChannelIndex() const
181  { return 0; }
182  int findChannelIndex(const char *name) const;
183 
184  // TODO: Remove this method and replace with calls to IMG_Stat::getImageType
185  // Add IMG_TYPE_ENVMAP to the IMG_ImageType enum.
186  virtual int isReflMap() const { return 0; }
187 
188 protected:
189  void initialize(int mipcount,
191 
192  int closeFile() override;
193 
195  exint numTTChannels() const { return myTTChannels.size(); }
197  IMG_TTChannel *getTTChannel(exint i) { return myTTChannels(i).get(); }
198 
199 protected:
200  // Mipmap level to start reading from the file.
202 
203 private:
204  void initScaleAndSize();
205 
206  //
207  // Data used in lookup of pixel values. These members MUST be
208  // initialized by derived classes before this class is used for
209  // sampling, by calling the initialize() method above.
210  //
211  void clearMips();
212 
213  // We have MIPs for each channel and raster
214  int getMipOffset(int aov, int image, int mip=0) const
215  {
216  // Each image AOV has myMipCount mip levels, so
217  // there are myMipCount IMG_TTChannel's for every
218  // AOV.
219  // Textures can contain multiple images (6-pack
220  // environment maps for example).
221  // These are flattened to a linear array:
222  // image0.aov0.mip0 [4x4]
223  // image0.aov0.mip1 [2x2]
224  // image0.aov0.mip2 [1x1]
225  // image1.aov0.mip0 [4x4]
226  // image1.aov0.mip1
227  // image1.aov0.mip2
228  // image2.aov0.mip0
229  // image2.aov0.mip1
230  // image2.aov0.mip2
231  // image0.aov1.mip0
232  // image0.aov1.mip1
233  // ...
234  return (aov*getRasterCount()+image)*myMipCount + mip;
235  }
236 
237  float myDx, myDy; // Inverse pixel sizes
238 
239  UT_Array<int> myColorSize;
240  UT_StringArray myOCIOColorSpace;
241  UT_StringHolder mySWrapMode;
242  UT_StringHolder myTWrapMode;
243 
244  // Mipmap samplers are stored as an array of pointers, with each
245  // entry representing one mipmap level. If this class is an
246  // environment map, multiple sets of mipmaps may be stored sequentially
247  // in this array.
248  UT_Array<UT_UniquePtr<IMG_TTMipSampler>> myMips; // Mip Maps
250  int myMipCount;
251  int myDSMComponentCount;
252  int myDepthComplexityPlane;
253  bool myFixMipFilterWidth;
254 };
255 
256 #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:69
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:53
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
#define const
Definition: zconf.h:214
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