1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2011,
4 //  Sony Pictures Imageworks, Inc. and
5 //  Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 // *       Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // *       Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 // *       Neither the name of Sony Pictures Imageworks, nor
19 // Industrial Light & Magic nor the names of their contributors may be used
20 // to endorse or promote products derived from this software without specific
21 // prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //-*****************************************************************************
36 
37 #ifndef Alembic_AbcGeom_CameraSample_h
38 #define Alembic_AbcGeom_CameraSample_h
39 
40 #include <Alembic/Util/Export.h>
41 #include <Alembic/AbcGeom/Foundation.h>
42 #include <Alembic/AbcGeom/FilmBackXformOp.h>
43 
44 namespace Alembic {
45 namespace AbcGeom {
46 namespace ALEMBIC_VERSION_NS {
47 
48 //-*****************************************************************************
49 class ALEMBIC_EXPORT CameraSample
50 {
51 public:
52 
53     //! Creates a default sample with a bunch of defaults set
CameraSample()54     CameraSample() { reset(); }
55 
56     //! Create a default sample and set the defaults so that they
57     //! calculate the provided screen window.
58     CameraSample( double iTop, double iBottom, double iLeft, double iRight );
59 
60     void getScreenWindow( double & oTop, double & oBottom, double & oLeft,
61         double & oRight );
62 
63     //! get the camera focal length in millimeters.
getFocalLength()64     double getFocalLength() const { return m_focalLength; }
65 
66     //! set the camera focal length in millimeters.
setFocalLength(double iVal)67     void  setFocalLength( double iVal ) { m_focalLength = iVal; }
68 
69     //! get the horizontal camera film back in centimeters
getHorizontalAperture()70     double getHorizontalAperture() const { return m_horizontalAperture; }
71 
72     //! set the horizontal camera film back in centimeters
setHorizontalAperture(double iVal)73     void setHorizontalAperture( double iVal ) { m_horizontalAperture = iVal; }
74 
75     //! get the horizontal film back offset in centimeters
getHorizontalFilmOffset()76     double getHorizontalFilmOffset() const { return m_horizontalFilmOffset; }
77 
78     //! set the horizontal film back offset in centimeters
setHorizontalFilmOffset(double iVal)79     void setHorizontalFilmOffset( double iVal )
80     { m_horizontalFilmOffset = iVal; }
81 
82     //! get the vertical camera film back in centimeters
getVerticalAperture()83     double getVerticalAperture() const { return m_verticalAperture; }
84 
85     //! set the vertical camera film back in centimeters
setVerticalAperture(double iVal)86     void setVerticalAperture( double iVal ) { m_verticalAperture = iVal; }
87 
88     //! get the vertical film back offset in centimeters
getVerticalFilmOffset()89     double getVerticalFilmOffset() const { return m_verticalFilmOffset; }
90 
91     //! set the vertical film back offset in centimeters
setVerticalFilmOffset(double iVal)92     void setVerticalFilmOffset( double iVal ) { m_verticalFilmOffset = iVal; }
93 
94     //! get the amount the camera's lens compresses the image horizontally
95     //! (width / height aspect ratio)
getLensSqueezeRatio()96     double getLensSqueezeRatio() const { return m_lensSqueezeRatio; }
97 
98     //! set the amount the camera's lens compresses the image horizontally
99     //! (width / height aspect ratio)
setLensSqueezeRatio(double iVal)100     void setLensSqueezeRatio( double iVal )
101     { m_lensSqueezeRatio = iVal; }
102 
103     //! get over scan fractional percentage for the left part of the
104     //! screen window
getOverScanLeft()105     double getOverScanLeft() { return m_overscanLeft; }
106 
107     //! set over scan fractional percentage for the left part of the
108     //! screen window
setOverScanLeft(double iVal)109     void setOverScanLeft( double iVal ) { m_overscanLeft = iVal; }
110 
111     //! get over scan fractional percentage for the right part of the
112     //! screen window
getOverScanRight()113     double getOverScanRight() const { return m_overscanRight; }
114 
115     //! set over scan fractional percentage for the right part of the
116     //! screen window
setOverScanRight(double iVal)117     void setOverScanRight( double iVal ) { m_overscanRight = iVal; }
118 
119     //! get over scan fractional percentage for the top part of the
120     //! screen window
getOverScanTop()121     double getOverScanTop() const { return m_overscanTop; }
122 
123     //! get over scan fractional percentage for the top part of the
124     //! screen window
setOverScanTop(double iVal)125     void setOverScanTop( double iVal ) { m_overscanTop = iVal; }
126 
127     //! get over scan fractional percentage for the bottom part of the
128     //! screen window
getOverScanBottom()129     double getOverScanBottom() const { return m_overscanBottom; }
130 
131     //! set over scan fractional percentage for the bottom part of the
132     //! screen window
setOverScanBottom(double iVal)133     void setOverScanBottom( double iVal ) { m_overscanBottom = iVal; }
134 
135     //! get the f-stop (focal length divided by "effective" lens diameter)
getFStop()136     double getFStop() const { return m_fStop; }
137 
138     //! set the f-stop (focal length divided by "effective" lens diameter)
setFStop(double iVal)139     void setFStop( double iVal ) { m_fStop = iVal; }
140 
141     //! get the distance from the camera to the object being focused on
142     //! in centimeters
getFocusDistance()143     double getFocusDistance() const { return m_focusDistance; }
144 
145     //! set the distance from the camera to the object being focused on
146     //! in centimeters
setFocusDistance(double iVal)147     void setFocusDistance( double iVal ) { m_focusDistance = iVal; }
148 
149     //! get the frame relative shutter open time in seconds.
getShutterOpen()150     double getShutterOpen() const { return m_shutterOpen; }
151 
152     //! set the frame relative shutter open time in seconds.
setShutterOpen(double iVal)153     void setShutterOpen( double iVal ) { m_shutterOpen = iVal; }
154 
155     //! get the frame relative shutter close time in seconds.
getShutterClose()156     double getShutterClose() const { return m_shutterClose; }
157 
158     //! set the frame relative shutter open time in seconds.
setShutterClose(double iVal)159     void setShutterClose( double iVal ) { m_shutterClose = iVal; }
160 
161     //! get the distance from the camera to the near clipping plane in
162     //! centimeters
getNearClippingPlane()163     double getNearClippingPlane() const { return m_nearClippingPlane; }
164 
165     //! set the distance from the camera to the near clipping plane in
166     //! centimeters
setNearClippingPlane(double iVal)167     void setNearClippingPlane( double iVal ) { m_nearClippingPlane = iVal; }
168 
169     //! get the distance from the camera to the far clipping plane in
170     //! centimeters
getFarClippingPlane()171     double getFarClippingPlane() const { return m_farClippingPlane; }
172 
173     //! set the distance from the camera to the near clipping plane in
174     //! centimeters
setFarClippingPlane(double iVal)175     void setFarClippingPlane( double iVal ) { m_farClippingPlane = iVal; }
176 
getChildBounds()177     Abc::Box3d getChildBounds() const { return m_childBounds; }
setChildBounds(const Abc::Box3d & iBounds)178     void setChildBounds( const Abc::Box3d & iBounds )
179     { m_childBounds = iBounds; }
180 
181 
182     // helper function for getting one of the 16 core, non film back xform op
183     // related values
184     double getCoreValue( std::size_t iIndex ) const;
185 
186     // calculated the field of view in degrees
187     double getFieldOfView() const;;
188 
189     // add an op and return the index of the op in its op-stack
190     std::size_t addOp( FilmBackXformOp iOp );
191 
192     FilmBackXformOp getOp( std::size_t iIndex ) const;
193     FilmBackXformOp &operator[]( const std::size_t &iIndex );
194     const FilmBackXformOp &operator[]( const std::size_t &iIndex ) const;
195 
196     //! Returns the concatenated 3x3 film back matrix
197     Abc::M33d getFilmBackMatrix () const;
198 
199     std::size_t getNumOps() const;
200     std::size_t getNumOpChannels() const;
201 
reset()202     void reset()
203     {
204         // in mm
205         m_focalLength = 35.0;
206 
207         // in cm
208         m_horizontalAperture = 3.6;
209         m_horizontalFilmOffset = 0.0;
210         m_verticalAperture = 2.4;
211         m_verticalFilmOffset = 0.0;
212 
213         // width/height lens aspect ratio
214         m_lensSqueezeRatio = 1.0;
215 
216         m_overscanLeft = 0.0;
217         m_overscanRight = 0.0;
218         m_overscanTop = 0.0;
219         m_overscanBottom = 0.0;
220 
221         // optical property of the lens, focal length divided by
222         // "effective" lens diameter
223         m_fStop = 5.6;
224 
225         m_focusDistance = 5.0;
226         m_shutterOpen = 0.0;
227         m_shutterClose = 0.020833333333333332;
228 
229         m_nearClippingPlane = 0.1;
230         m_farClippingPlane = 100000.0;
231 
232         m_childBounds.makeEmpty();
233         m_ops.clear();
234     }
235 
236 private:
237     double m_focalLength;
238     double m_horizontalAperture;
239     double m_horizontalFilmOffset;
240     double m_verticalAperture;
241     double m_verticalFilmOffset;
242     double m_lensSqueezeRatio;
243 
244     double m_overscanLeft;
245     double m_overscanRight;
246     double m_overscanTop;
247     double m_overscanBottom;
248 
249     double m_fStop;
250     double m_focusDistance;
251     double m_shutterOpen;
252     double m_shutterClose;
253 
254     double m_nearClippingPlane;
255     double m_farClippingPlane;
256 
257     Abc::Box3d m_childBounds;
258 
259     std::vector<FilmBackXformOp> m_ops;
260 };
261 
262 } // End namespace ALEMBIC_VERSION_NS
263 
264 using namespace ALEMBIC_VERSION_NS;
265 
266 } // End namespace AbcGeom
267 } // End namespace Alembic
268 
269 #endif
270