VTK  9.0.3
Camera.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Types.h"
4 
5 #include "Object.h"
6 
7 #include <VisRTX.h>
8 #include <cassert>
9 #include <string>
10 
11 namespace RTW
12 {
13  class Camera : public Object
14  {
15  friend class Renderer;
16 
17  public:
19  {
20  VisRTX::Context* rtx = VisRTX_GetContext();
21 
22  if (type == "perspective")
23  this->camera = rtx->CreatePerspectiveCamera();
24  else if (type == "orthographic")
25  this->camera = rtx->CreateOrthographicCamera();
26  else
27  assert(false);
28  }
29 
31  {
32  this->camera->Release();
33  }
34 
35  void Commit() override
36  {
37  VisRTX::Vec3f pos;
38  if (this->Get3f({ "pos" }, &pos))
39  this->camera->SetPosition(pos);
40 
41  VisRTX::Vec3f dir;
42  if (this->Get3f({ "dir" }, &dir))
43  this->camera->SetDirection(dir);
44 
45  VisRTX::Vec3f up;
46  if (this->Get3f({ "up" }, &up))
47  this->camera->SetUp(up);
48 
49  VisRTX::Vec2f imageBegin, imageEnd;
50  if (this->Get2f({ "imageStart" }, &imageBegin) && this->Get2f({ "imageEnd" }, &imageEnd))
51  this->camera->SetImageRegion(imageBegin, imageEnd);
52 
53  if (this->camera->GetType() == VisRTX::CameraType::PERSPECTIVE)
54  {
55  VisRTX::PerspectiveCamera* pc = dynamic_cast<VisRTX::PerspectiveCamera*>(this->camera);
56 
57  float fovy;
58  if (this->Get1f({ "fovy" }, &fovy))
59  pc->SetFovY(fovy);
60 
61  float aspect;
62  if (this->Get1f({ "aspect" }, &aspect))
63  pc->SetAspect(aspect);
64 
65  float focalDistance;
66  if (this->Get1f({ "focusDistance" }, &focalDistance))
67  pc->SetFocalDistance(focalDistance);
68 
69  float apertureRadius;
70  if (this->Get1f({ "apertureRadius" }, &apertureRadius))
71  pc->SetApertureRadius(apertureRadius);
72  }
73 
74  else if (this->camera->GetType() == VisRTX::CameraType::ORTHOGRAPHIC)
75  {
76  VisRTX::OrthographicCamera* oc = dynamic_cast<VisRTX::OrthographicCamera*>(this->camera);
77 
78  float height;
79  if (this->Get1f({ "height" }, &height))
80  oc->SetHeight(height);
81 
82  float aspect;
83  if (this->Get1f({ "aspect" }, &aspect))
84  oc->SetAspect(aspect);
85  }
86 
87  else
88  {
89  assert(false);
90  }
91  }
92 
93  private:
94  VisRTX::Camera* camera = nullptr;
95  };
96 }
void Commit() override
Definition: Camera.h:35
~Camera()
Definition: Camera.h:30
Camera(const std::string &type)
Definition: Camera.h:18
VisRTX::Vec3f Get3f(const std::vector< std::string > &ids, const VisRTX::Vec3f &defaultValue=VisRTX::Vec3f(), bool *found=nullptr) const
Definition: Object.h:192
VisRTX::Vec2f Get2f(const std::vector< std::string > &ids, const VisRTX::Vec2f &defaultValue=VisRTX::Vec2f(), bool *found=nullptr) const
Definition: Object.h:158
float Get1f(const std::vector< std::string > &ids, float defaultValue=0.0f, bool *found=nullptr) const
Definition: Object.h:124
Definition: Backend.h:6
@ dir
Definition: vtkX3D.h:330
@ type
Definition: vtkX3D.h:522
@ height
Definition: vtkX3D.h:260
@ string
Definition: vtkX3D.h:496