HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_CameraParms.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  * COMMENTS:
7  * A minimalist representation of a camera's parms (except transform).
8  *
9  */
10 
11 #ifndef __UT_Camera_h__
12 #define __UT_Camera_h__
13 
14 #include "UT_API.h"
15 #include "UT_Options.h"
16 #include "UT_VectorTypes.h"
17 #include <stdlib.h>
18 #include <SYS/SYS_Types.h>
19 
20 class UT_JSONParser;
21 class UT_JSONValue;
22 class UT_JSONWriter;
23 
24 // Projections for cameras.
25 // Using the "OBJ" naming for historical reasons.
27 {
31 };
32 
34 {
35 public:
37  { setDefaults(); }
38 
39  void setDefaults();
40 
41  fpreal focal; // Focal length
42  fpreal aperture; // Aperture
43  fpreal pixelaspect; // Aspect ratio
44  fpreal focusdistance; // Focus distance
45  fpreal fstop; // F-Stop;
46  fpreal imagingdistance; // imaging distance
47  fpreal cropx[2]; // Min max for cropping in x
48  fpreal cropy[2]; // Min max for cropping in y
49  fpreal winx[2]; // Sub-windowing in X
50  fpreal winy[2]; // Sub-windowing in Y
51  fpreal clipnear, clipfar; // Near/Far clipping planes
52  fpreal shutteropen; // Shutter open
53  fpreal shutterclose; // Shutter close
54  fpreal orthozoom; // Orthographic zoom
55  fpreal guidescale; // Scale of the Camera Display
56 
57  exint resx, resy; // Resolution for camera
58 
59  OBJ_ProjectionType projection; // Camera Projection
60  UT_OptionsHolder metadata; // Custom Metadata
61 
62 
63  /// @{
64  /// Methods to get and set the parameters with UT_Options.
65  UT_Options getOptions() const;
66  void setFromOptions(const UT_Options *options);
67  /// @}
68 
69  /// @{
70  /// Methods to serialize the parameters to a JSON stream:
71  /// @code
72  /// "aperture":41.42136,
73  /// "pixelaspect":1,
74  /// "clipnear": 0.001
75  /// "clipfar" :1000000,
76  /// "cropmax":[1,1],
77  /// "cropmin":[0,0],
78  /// "focal":50,
79  /// "focusdistance":10,
80  /// "fstop":22.1,
81  /// "orthozoom":1,
82  /// "guidescale": 1,
83  /// "imagingdistance": 1,
84  /// "projection":"perspective",
85  /// "resolutionx" :320,
86  /// "resolutiony" : 243,
87  /// "shutteropen" : 0
88  /// "shutterclose": 0,
89  /// "windowmax":[1,1],
90  /// "windowmin":[0,0]
91  /// "metadata": {}
92  /// @endcode
93  bool save(UT_JSONWriter &w) const;
94  bool save(UT_JSONValue &v) const;
95  bool load(UT_JSONParser &p);
96  /// @}
97 
98  bool operator==(const UT_CameraParms &other) const;
99  bool operator!=(const UT_CameraParms &other) const
100  {
101  return !(*this == other);
102  }
103  /// adds the float parameters together
104  /// which means everything but
105  /// - resolution
106  /// - metadata
107  /// - projection
108  UT_CameraParms &operator+=(const UT_CameraParms &other);
109  /// same as above but multiplies float parameters by multiplier
110  UT_CameraParms &operator*=(const fpreal multiplier);
111 
112  /// @{
113  /// Methods to serialize a 3D camera to a JSON stream:
114  /// @code
115  /// {
116  /// "camera":{
117  /// "aperture":41.42136,
118  /// "aspect":1,
119  /// "clipnear": 0.001,
120  /// "clipfar": 1000000,
121  /// "cropmax":[1,1],
122  /// "cropmin":[0,0],
123  /// "focal":50,
124  /// "focusdistance":10,
125  /// "fstop":22.1,
126  /// "orthozoom":1,
127  /// "guidescale":1,
128  /// "imagingdistance": 1
129  /// "projection":"perspective",
130  /// "resolutionx":320,
131  /// "resolutiony":243,
132  /// "shutteropen":0,
133  /// "shutterclose":0,
134  /// "windowmax":[1,1],
135  /// "windowmin":[0,0]
136  /// "metadata": {}
137  /// },
138  /// "position":[0,0,0],
139  /// "transform":[1,0,0,0,1,0,0,0,1]
140  /// }
141  /// @endcode
142  static bool save3DCamera(UT_JSONWriter &w,
143  const UT_Vector3D &position,
144  const UT_Matrix3D &transform,
145  const UT_CameraParms &parms);
146  static bool load3DCamera(UT_JSONParser &p,
150  /// @}
151 
152  static const char *getProjectionToken(OBJ_ProjectionType projection);
153  static OBJ_ProjectionType getProjectionEnum(const char *token);
154 
155  ///@{
156  /// Convenience functions
158  {
159  return (fpreal)(resx) / (fpreal)(resy);
160  }
161  void getWindowSize(fpreal &x, fpreal &y) const
162  {
163  x = winx[1] - winx[0];
164  y = winy[1] - winy[0];
165  }
166 
167  void getWindowCenter(fpreal &x, fpreal &y) const
168  {
169  x = (winx[0] + winx[1]) * 0.5 - 0.5;
170  y = (winy[0] + winy[1]) * 0.5 - 0.5;
171  }
172  /// sets the window from a window offset and a window size
173  void setWindow(fpreal x, fpreal y, fpreal sizex, fpreal sizey)
174  {
175  sizex *= .5;
176  sizey *= .5;
177  x += .5;
178  y += .5;
179  winx[0] = x - sizex;
180  winx[1] = x + sizex;
181  winy[0] = y - sizey;
182  winy[1] = y + sizey;
183  }
184  /// returns true if the camera is orthographic
185  bool isOrthographic() const
186  {
187  return projection == OBJ_PROJ_ORTHO;
188  }
189 
190  ///@}
191 
192 };
193 
194 UT_API size_t
195 UTformatBuffer(char *buffer, size_t buffer_size, const UT_CameraParms &camp);
196 
197 #endif // __UT_Camera_h__
fpreal imagingdistance
void setWindow(fpreal x, fpreal y, fpreal sizex, fpreal sizey)
sets the window from a window offset and a window size
const GLdouble * v
Definition: glcorearb.h:837
void getWindowCenter(fpreal &x, fpreal &y) const
bool operator!=(const UT_CameraParms &other) const
int64 exint
Definition: SYS_Types.h:125
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define UT_API
Definition: UT_API.h:14
GLint y
Definition: glcorearb.h:103
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:39
GLuint buffer
Definition: glcorearb.h:660
UT_API size_t UTformatBuffer(char *buffer, size_t buffer_size, const UT_CameraParms &camp)
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
fpreal focusdistance
bool isOrthographic() const
returns true if the camera is orthographic
UN_API void setFromOptions(UN_GraphData *graph_data, const UN_Options &graph_opts)
Load and set the graph based on the given options.
OBJ_ProjectionType
void getWindowSize(fpreal &x, fpreal &y) const
GA_API const UT_StringHolder transform
GLint GLenum GLint x
Definition: glcorearb.h:409
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
Definition: ImathMatrix.h:5082
A map of string to various well defined value types.
Definition: UT_Options.h:87
GA_API const UT_StringHolder parms
fpreal64 fpreal
Definition: SYS_Types.h:283
SIM_API const UT_StringHolder position
fpreal getAspectRatio() const
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
OBJ_ProjectionType projection
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
UT_OptionsHolder metadata