1 // Copyright 2009-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include "common/MotionTransform.h"
7 #include "common/Util.h"
8 
9 namespace ospray {
10 
11 //! base camera class abstraction
12 /*! the base class itself does not do anything useful; look into
Camera()13     perspectivecamera etc for that */
14 struct OSPRAY_SDK_INTERFACE Camera : public ManagedObject
15 {
16   Camera();
17   ~Camera() override;
18 
19   std::string toString() const override;
20   void commit() override;
21 
22   // Project the bounding box to the screen
23   // The projected box will be returned in normalized [0, 1] coordinates in
24   // the framebuffer, the z coordinate will store the min and max depth, in
25   // box.lower, box.upper respectively
26   // Assume no motion blur nor depth of field (true for SciVis)
27   virtual box3f projectBox(const box3f &b) const;
28 
29   static Camera *createInstance(const char *identifier);
30   template <typename T>
31   static void registerType(const char *type);
32 
33   // Data members //
34 
35   // if motionBlur in local camera space; otherwise in world-space:
36   vec3f pos; // position of the camera
37   vec3f dir; // main direction of the camera
38   vec3f up; // up direction of the camera
39 
40   float nearClip{1e-6f}; // near clipping distance
41   // definition of the image region, may even be outside of [0..1]^2
42   // to simulate sensor shift
43   vec2f imageStart; // lower left corner
44   vec2f imageEnd; // upper right corner
45   range1f shutter{0.5f, 0.5f}; // start and end time of camera shutter time
46   float rollingShutterDuration{0.0f};
47   OSPShutterType shutterType{OSP_SHUTTER_GLOBAL};
48 
49   void setDevice(RTCDevice embreeDevice);
50 
51  private:
52   template <typename BASE_CLASS, typename CHILD_CLASS>
53   friend void registerTypeHelper(const char *type);
54   static void registerType(const char *type, FactoryFcn<Camera> f);
55   RTCDevice embreeDevice{nullptr};
56   RTCGeometry embreeGeometry{nullptr};
57   MotionTransform motionTransform;
58 };
59 
60 OSPTYPEFOR_SPECIALIZATION(Camera *, OSP_CAMERA);
61 
62 // Inlined defintions /////////////////////////////////////////////////////////
63 
64 template <typename T>
65 inline void Camera::registerType(const char *type)
66 {
67   registerTypeHelper<Camera, T>(type);
68 }
69 
70 } // namespace ospray
71