HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfEnvmap.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 #ifndef INCLUDED_IMF_ENVMAP_H
7 #define INCLUDED_IMF_ENVMAP_H
8 
9 //-----------------------------------------------------------------------------
10 //
11 // Environment maps
12 //
13 // Environment maps define a mapping from 3D directions to 2D
14 // pixel space locations. Environment maps are typically used
15 // in 3D rendering, for effects such as quickly approximating
16 // how shiny surfaces reflect their environment.
17 //
18 // Environment maps can be stored in scanline-based or in tiled
19 // OpenEXR files. The fact that an image is an environment map
20 // is indicated by the presence of an EnvmapAttribute whose name
21 // is "envmap". (Convenience functions to access this attribute
22 // are defined in header file ImfStandardAttributes.h.)
23 // The attribute's value defines the mapping from 3D directions
24 // to 2D pixel space locations.
25 //
26 // This header file defines the set of possible EnvmapAttribute
27 // values.
28 //
29 // For each possible EnvmapAttribute value, this header file also
30 // defines a set of convenience functions to convert between 3D
31 // directions and 2D pixel locations.
32 //
33 // Most of the convenience functions defined below require a
34 // dataWindow parameter. For scanline-based images, and for
35 // tiled images with level mode ONE_LEVEL, the dataWindow
36 // parameter should be set to the image's data window, as
37 // defined in the image header. For tiled images with level
38 // mode MIPMAP_LEVELS or RIPMAP_LEVELS, the data window of the
39 // image level that is being accessed should be used instead.
40 // (See the dataWindowForLevel() methods in ImfTiledInputFile.h
41 // and ImfTiledOutputFile.h.)
42 //
43 //-----------------------------------------------------------------------------
44 
45 #include "ImfExport.h"
46 #include "ImfNamespace.h"
47 
48 #include <ImathBox.h>
49 
51 
52 //--------------------------------
53 // Supported environment map types
54 //--------------------------------
55 
57 {
58  ENVMAP_LATLONG = 0, // Latitude-longitude environment map
59  ENVMAP_CUBE = 1, // Cube map
60 
61  NUM_ENVMAPTYPES // Number of different environment map types
62 };
63 
64 //-------------------------------------------------------------------------
65 // Latitude-Longitude Map:
66 //
67 // The environment is projected onto the image using polar coordinates
68 // (latitude and longitude). A pixel's x coordinate corresponds to
69 // its longitude, and the y coordinate corresponds to its latitude.
70 // Pixel (dataWindow.min.x, dataWindow.min.y) has latitude +pi/2 and
71 // longitude +pi; pixel (dataWindow.max.x, dataWindow.max.y) has
72 // latitude -pi/2 and longitude -pi.
73 //
74 // In 3D space, latitudes -pi/2 and +pi/2 correspond to the negative and
75 // positive y direction. Latitude 0, longitude 0 points into positive
76 // z direction; and latitude 0, longitude pi/2 points into positive x
77 // direction.
78 //
79 // The size of the data window should be 2*N by N pixels (width by height),
80 // where N can be any integer greater than 0.
81 //-------------------------------------------------------------------------
82 
83 namespace LatLongMap
84 {
85 //----------------------------------------------------
86 // Convert a 3D direction to a 2D vector whose x and y
87 // components represent the corresponding latitude
88 // and longitude.
89 //----------------------------------------------------
90 
93 
94 //--------------------------------------------------------
95 // Convert the position of a pixel to a 2D vector whose
96 // x and y components represent the corresponding latitude
97 // and longitude.
98 //--------------------------------------------------------
99 
102  const IMATH_NAMESPACE::Box2i& dataWindow,
104 
105 //-------------------------------------------------------------
106 // Convert a 2D vector, whose x and y components represent
107 // longitude and latitude, into a corresponding pixel position.
108 //-------------------------------------------------------------
109 
112  const IMATH_NAMESPACE::Box2i& dataWindow,
113  const IMATH_NAMESPACE::V2f& latLong);
114 
115 //-----------------------------------------------------
116 // Convert a 3D direction vector into a corresponding
117 // pixel position. pixelPosition(dw,dir) is equivalent
118 // to pixelPosition(dw,latLong(dw,dir)).
119 //-----------------------------------------------------
120 
123  const IMATH_NAMESPACE::Box2i& dataWindow,
124  const IMATH_NAMESPACE::V3f& direction);
125 
126 //--------------------------------------------------------
127 // Convert the position of a pixel in a latitude-longitude
128 // map into a corresponding 3D direction.
129 //--------------------------------------------------------
130 
133  const IMATH_NAMESPACE::Box2i& dataWindow,
134  const IMATH_NAMESPACE::V2f& pixelPosition);
135 } // namespace LatLongMap
136 
137 //--------------------------------------------------------------
138 // Cube Map:
139 //
140 // The environment is projected onto the six faces of an
141 // axis-aligned cube. The cube's faces are then arranged
142 // in a 2D image as shown below.
143 //
144 // 2-----------3
145 // / /|
146 // / / | Y
147 // / / | |
148 // 6-----------7 | |
149 // | | | |
150 // | | | |
151 // | 0 | 1 *------- X
152 // | | / /
153 // | | / /
154 // | |/ /
155 // 4-----------5 Z
156 //
157 // dataWindow.min
158 // /
159 // /
160 // +-----------+
161 // |3 Y 7|
162 // | | |
163 // | | |
164 // | ---+---Z | +X face
165 // | | |
166 // | | |
167 // |1 5|
168 // +-----------+
169 // |6 Y 2|
170 // | | |
171 // | | |
172 // | Z---+--- | -X face
173 // | | |
174 // | | |
175 // |4 0|
176 // +-----------+
177 // |6 Z 7|
178 // | | |
179 // | | |
180 // | ---+---X | +Y face
181 // | | |
182 // | | |
183 // |2 3|
184 // +-----------+
185 // |0 1|
186 // | | |
187 // | | |
188 // | ---+---X | -Y face
189 // | | |
190 // | | |
191 // |4 Z 5|
192 // +-----------+
193 // |7 Y 6|
194 // | | |
195 // | | |
196 // | X---+--- | +Z face
197 // | | |
198 // | | |
199 // |5 4|
200 // +-----------+
201 // |2 Y 3|
202 // | | |
203 // | | |
204 // | ---+---X | -Z face
205 // | | |
206 // | | |
207 // |0 1|
208 // +-----------+
209 // /
210 // /
211 // dataWindow.max
212 //
213 // The size of the data window should be N by 6*N pixels
214 // (width by height), where N can be any integer greater
215 // than 0.
216 //
217 //--------------------------------------------------------------
218 
219 //------------------------------------
220 // Names for the six faces of the cube
221 //------------------------------------
222 
224 {
225  CUBEFACE_POS_X, // +X face
226  CUBEFACE_NEG_X, // -X face
227  CUBEFACE_POS_Y, // +Y face
228  CUBEFACE_NEG_Y, // -Y face
229  CUBEFACE_POS_Z, // +Z face
230  CUBEFACE_NEG_Z // -Z face
231 };
232 
233 namespace CubeMap
234 {
235 //---------------------------------------------
236 // Width and height of a cube's face, in pixels
237 //---------------------------------------------
238 
240 int sizeOfFace (const IMATH_NAMESPACE::Box2i& dataWindow);
241 
242 //------------------------------------------
243 // Compute the region in the environment map
244 // that is covered by the specified face.
245 //------------------------------------------
246 
249 dataWindowForFace (CubeMapFace face, const IMATH_NAMESPACE::Box2i& dataWindow);
250 
251 //----------------------------------------------------
252 // Convert the coordinates of a pixel within a face
253 // [in the range from (0,0) to (s-1,s-1), where
254 // s == sizeOfFace(dataWindow)] to pixel coordinates
255 // in the environment map.
256 //----------------------------------------------------
257 
260  CubeMapFace face,
261  const IMATH_NAMESPACE::Box2i& dataWindow,
262  IMATH_NAMESPACE::V2f positionInFace);
263 
264 //--------------------------------------------------------------
265 // Convert a 3D direction into a cube face, and a pixel position
266 // within that face.
267 //
268 // If you have a 3D direction, dir, the following code fragment
269 // finds the position, pos, of the corresponding pixel in an
270 // environment map with data window dw:
271 //
272 // CubeMapFace f;
273 // V2f pif, pos;
274 //
275 // faceAndPixelPosition (dir, dw, f, pif);
276 // pos = pixelPosition (f, dw, pif);
277 //
278 //--------------------------------------------------------------
279 
283  const IMATH_NAMESPACE::Box2i& dataWindow,
284  CubeMapFace& face,
285  IMATH_NAMESPACE::V2f& positionInFace);
286 
287 // --------------------------------------------------------
288 // Given a cube face and a pixel position within that face,
289 // compute the corresponding 3D direction.
290 // --------------------------------------------------------
291 
294  CubeMapFace face,
295  const IMATH_NAMESPACE::Box2i& dataWindow,
296  const IMATH_NAMESPACE::V2f& positionInFace);
297 } // namespace CubeMap
298 
300 
301 #endif
#define IMF_EXPORT_ENUM
Definition: ImfExport.h:56
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
enum IMF_EXPORT_ENUM CubeMapFace
Definition: ImfEnvmap.h:223
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
ENVMAP_CUBE
Definition: ImfEnvmap.h:59
ENVMAP_LATLONG
Definition: ImfEnvmap.h:58
CUBEFACE_POS_Y
Definition: ImfEnvmap.h:225
IMF_EXPORT IMATH_NAMESPACE::V2f pixelPosition(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &latLong)
IMF_EXPORT void faceAndPixelPosition(const IMATH_NAMESPACE::V3f &direction, const IMATH_NAMESPACE::Box2i &dataWindow, CubeMapFace &face, IMATH_NAMESPACE::V2f &positionInFace)
CUBEFACE_NEG_Y
Definition: ImfEnvmap.h:225
Envmapint
Definition: ImfEnvmap.h:56
Box< V2i > Box2i
2D box of base type int.
Definition: ImathBox.h:143
IMF_EXPORT IMATH_NAMESPACE::V2f latLong(const IMATH_NAMESPACE::V3f &direction)
IMF_EXPORT IMATH_NAMESPACE::V2f pixelPosition(CubeMapFace face, const IMATH_NAMESPACE::Box2i &dataWindow, IMATH_NAMESPACE::V2f positionInFace)
#define IMF_EXPORT
Definition: ImfExport.h:54
CUBEFACE_NEG_X
Definition: ImfEnvmap.h:225
IMF_EXPORT int sizeOfFace(const IMATH_NAMESPACE::Box2i &dataWindow)
IMF_EXPORT IMATH_NAMESPACE::V3f direction(CubeMapFace face, const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &positionInFace)
Vec2< float > V2f
Vec2 of float.
Definition: ImathVec.h:834
Vec3< float > V3f
Vec3 of float.
Definition: ImathVec.h:849
CUBEFACE_POS_Z
Definition: ImfEnvmap.h:225
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
IMF_EXPORT IMATH_NAMESPACE::Box2i dataWindowForFace(CubeMapFace face, const IMATH_NAMESPACE::Box2i &dataWindow)
CUBEFACE_POS_X
Definition: ImfEnvmap.h:225