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 
18 class UT_Filter;
19 class UT_FilterWindow;
20 class UT_Options;
21 class IMG_TTMipSampler;
22 class IMG_Raster;
23 class TBF_Channel;
24 
25 
26 /// An IMG_TTChannel is used to retrieve pixel data from the image.
27 /// Each image owns an array of IMG_TTChannel objects that could
28 /// represent environment map rasters or mipmap levels.
30 {
31 public:
32  IMG_TTChannel();
33  virtual ~IMG_TTChannel();
34 
35  virtual int64 getMemoryUsage(bool inclusive) const = 0;
36 
37  virtual void filterPixels(float *rgba, int nchan,
38  int first_x, int first_y,
40  const float *xweights,
41  const float *yweights,
42  int usize, int vsize) = 0;
43 
44  virtual void getPixel(float *rgba, int nchan, int iu, int iv,
45  const IMG_TextureFilter &filter) = 0;
46 
47  /// This method returns the raw pixel data.
48  virtual void getPixel(void *pixel, int iu, int iv) = 0;
49  /// Return raw scanline data
50  virtual void getScanline(void *scanline,
51  int y, int xres, size_t bpp);
52 
53  /// This method is called when the channel is destroyed
54  virtual void closeChannel() {};
55 };
56 
57 /// A IMG_TTMap represents a tiled texture format that can be
58 /// sampled for texture mapping or for environment mapping. This class
59 /// supports methods for sampling and filtering the texture data.
60 /// This class is pure virtual and so derived classes must override the
61 /// image file and format operations.
63 {
64 public:
65  IMG_FileTTMap();
66  virtual ~IMG_FileTTMap();
67 
68  virtual const char *className() const { return "IMG_FileTTMap"; }
69 
70  /// Return true if texture evaluation of this format is enabled
71  virtual bool textureEnabled() const;
72 
73  int getOGLRaster(void *data, int xres, int yres,
75  int raster_number=0);
76 
77  // Perform unfiltered evaluation at a specified uv. This operation
78  // will not even perform filtering on pixels, so the caller is
79  // responsible for all filtering and antialiasing.
80  void unfilteredSample(
81  float *result, int tuple_size, float u, float v,
82  const IMG_TextureFilter &info,
83  int channel, int raster);
84 
85  // Sample with filtering at the specified uv.
86  void sample(float *result, int tuple_size, float u, float v,
87  const IMG_TextureFilter &info,
88  int channel, int raster)
89  {
90  float ua[4] = {u,u,u,u};
91  float va[4] = {v,v,v,v};
92 
93  sample(result, tuple_size,
94  ua, va, 1, info, channel, raster);
95  }
96 
97 
98  // Sample the map within a quadrilateral in texture space. When
99  // specifying four corners of the map, the order of the coordinates is
100  // very important:
101  //
102  // BAD GOOD GOOD
103  // 2--3 3--2 2--3
104  // \/ | | | |
105  // /\ | | | |
106  // 0--1 0--1 1--0
107  void sample(float *result, float &visible, int tuple_size,
108  const float u[4], const float v[4],
109  float quality,
110  const IMG_TextureFilter &info,
111  int channel, int raster);
112  void sample(float *result, int tuple_size,
113  const float u[4], const float v[4],
114  float quality,
115  const IMG_TextureFilter &info,
116  int channel, int raster)
117  {
118  float visible;
119  sample(result, visible,
120  tuple_size, u, v, quality,
121  info, channel, raster);
122  }
123 
124  // Only call the envLookup functions if this RAT is really a cubic
125  // environment map.
126  void envLookup(float *result, int tuple_size,
127  const UT_Vector3 &r, float angle,
128  const IMG_TextureFilter &info, int channel);
129 
130  void envLookup(float *result, int tuple_size,
131  const UT_Vector3 &r00, const UT_Vector3 &r01,
132  const UT_Vector3 &r11, const UT_Vector3 &r10,
133  const IMG_TextureFilter &info,
134  int channel);
135 
136  fpreal getUPixelSize() const { return myDx; }
137  fpreal getVPixelSize() const { return myDy; }
138 
139  virtual int64 getMemoryUsage(bool inclusive) const;
140  virtual int getRasterCount() const { return 0; }
141  int getChannelTupleSize(int ch) const;
142  virtual int getNumChannels() const { return getStat().getNumPlanes(); }
143 
144  // Return the channel index to use for lookups that haven't specified a
145  // particular channel.
146  virtual int getDefaultChannelIndex() const
147  { return 0; }
148  int findChannelIndex(const char *name) const;
149 
150  // TODO: Remove this method and replace with calls to IMG_Stat::getImageType
151  // Add IMG_TYPE_ENVMAP to the IMG_ImageType enum.
152  virtual int isReflMap() const { return 0; }
153 
154 protected:
155  void initialize(int mipcount,
156  const UT_ValArray<IMG_TTChannel *> &channels);
157 
158  virtual int closeFile();
159 
160 protected:
161  // Mipmap level to start reading from the file.
163 
164 private:
165  void initScaleAndSize();
166 
167  //
168  // Data used in lookup of pixel values. These members MUST be
169  // initialized by derived classes before this class is used for
170  // sampling, by calling the initialize() method above.
171  //
172  void clearMips();
173 
174  // We have MIPs for each channel and raster
175  int getMipOffset(int channel, int raster)
176  {
177  channel *= getRasterCount();
178  channel += raster;
179  return myMipCount * channel;
180  }
181 
182  float myDx, myDy; // Inverse pixel sizes
183 
184  UT_IntArray myColorSize;
185 
186  // Mipmap samplers are stored as an array of pointers, with each
187  // entry representing one mipmap level. If this class is an
188  // environment map, multiple sets of mipmaps may be stored sequentially
189  // in this array.
190  UT_ValArray<IMG_TTMipSampler *> myMips; // Mip Maps
191  int myMipCount;
192  int myDSMComponentCount;
193  int myDepthComplexityPlane;
194  bool myFixMipFilterWidth;
195 };
196 
197 #endif
int getNumPlanes() const
Returns the number of image planes in the image a plane contains the actual structure of the image da...
virtual int64 getMemoryUsage(bool inclusive) const
virtual int isReflMap() const
virtual int getNumChannels() const
const GLdouble * v
Definition: glcorearb.h:836
virtual int closeFile()=0
GLint y
Definition: glcorearb.h:102
3D Vector class.
long long int64
Definition: SYS_Types.h:107
#define IMG_API
Definition: IMG_API.h:10
virtual int getRasterCount() const
IMG_DataType
Definition: IMG_FileTypes.h:17
fpreal getVPixelSize() const
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:472
Generic interface for reading and writing image files. This class handles the reading and writing of ...
Definition: IMG_File.h:54
GLboolean * data
Definition: glcorearb.h:130
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:318
GLuint const GLchar * name
Definition: glcorearb.h:785
Modes for filtering.
double fpreal
Definition: SYS_Types.h:270
A map of string to various well defined value types.
Definition: UT_Options.h:42
virtual const char * className() const
Definition: IMG_FileTTMap.h:68
virtual void closeChannel()
This method is called when the channel is destroyed.
Definition: IMG_FileTTMap.h:54
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)
const IMG_Stat & getStat() const
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)
Definition: IMG_FileTTMap.h:86
GLboolean r
Definition: glcorearb.h:1221
virtual int getDefaultChannelIndex() const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296