Ocean
View.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_RENDERING_VIEW_H
9 #define META_OCEAN_RENDERING_VIEW_H
10 
13 #include "ocean/rendering/Node.h"
14 #include "ocean/rendering/Object.h"
17 
18 #include "ocean/math/Line3.h"
19 #include "ocean/math/Quaternion.h"
20 #include "ocean/math/RGBAColor.h"
22 #include "ocean/math/Vector3.h"
23 
24 namespace Ocean
25 {
26 
27 namespace Rendering
28 {
29 
30 // Forward declaration.
31 class View;
32 
33 /**
34  * Definition of a smart object reference holding a view node.
35  * A view can holds several background objects, however only the first one is used for rendering.
36  * @see SmartObjectRef, View.
37  * @ingroup rendering
38  */
40 
41 /**
42  * This class is the base class for all rendering views.
43  * @ingroup rendering
44  */
45 class OCEAN_RENDERING_EXPORT View : virtual public Object
46 {
47  public:
48 
49  /**
50  * Definition of a vector holding background objects.
51  */
52  typedef std::vector<BackgroundRef> Backgrounds;
53 
54  public:
55 
56  /**
57  * Returns the aspect ratio of this view.
58  * @return Ratio between width and height
59  * @exception NotSupportedException Is thrown if this function is not supported
60  * @see setAspectRatio().
61  */
62  virtual Scalar aspectRatio() const;
63 
64  /**
65  * Returns the distance to the near clipping plane.
66  * @return Distance to near clipping plane
67  * @exception NotSupportedException Is thrown if this function is not supported
68  * @see setNearDistance(), farDistance().
69  */
70  virtual Scalar nearDistance() const;
71 
72  /**
73  * Returns the distance to the far clipping plane.
74  * @return Distance to far clipping plane
75  * @exception NotSupportedException Is thrown if this function is not supported
76  * @see setFarDistance(), nearDistance().
77  */
78  virtual Scalar farDistance() const;
79 
80  /**
81  * Returns the transformation between view and world (the extrinsic camera data, the inverse of the known View Matrix).
82  * @return The view's transformation, which is world_T_view
83  * @exception NotSupportedException Is thrown if this function is not supported
84  * @see setTransformation().
85  */
87 
88  /**
89  * Returns the projection matrix of this view.
90  * @return The view's projection matrix, which is clip_T_view
91  * @exception NotSupportedException Is thrown if this function is not supported
92  */
94 
95  /**
96  * Returns the background color of the view.
97  * @return Background color
98  * @exception NotSupportedException Is thrown if this function is not supported
99  * @see background(), backgrounds().
100  */
101  virtual RGBAColor backgroundColor() const;
102 
103  /**
104  * Returns the currently used background of the view.
105  * @return Background object
106  * @see backgrounds(), backgroundColor().
107  */
108  virtual BackgroundRef background() const;
109 
110  /**
111  * Returns all defined background objects.
112  * A view can hold more than one background object, however only the first background object is used for rendering
113  * @return Defined background objects
114  * @see background(), backgroundColor().
115  */
116  virtual Backgrounds backgrounds() const;
117 
118  /**
119  * Returns whether the head light is enabled.
120  * @return True, if so
121  * @see setUseHeadlight().
122  * @exception NotSupportedException Is thrown if this function is not supported
123  */
124  virtual bool useHeadlight() const;
125 
126  /**
127  * Returns the phantom mode of this view.
128  * @return Phantom mode
129  * @exception NotSupportedException Is thrown if this function is not supported
130  * @see setPhantomMode().
131  */
133 
134  /**
135  * Returns a viewing ray into the scene.
136  * The start position is located at the center of projection.
137  * @param x Horizontal position on the projection plane defining the intersection between plane and ray, in pixel
138  * @param y Vertical position on the projection plane defining the intersection between plane and ray, in pixel
139  * @param width Horizontal width of the projection plane in pixel
140  * @param height Vertical height of the projection plane in pixel
141  * @return Resulting viewing ray
142  */
143  virtual Line3 viewingRay(const Scalar x, const Scalar y, const unsigned int width, const unsigned int height) const;
144 
145  /**
146  * Sets the aspect ratio of this view.
147  * @param aspectRatio The ratio between width and height, with range (0, infinity)
148  * @return True, if succeeded
149  * @exception NotSupportedException Is thrown if this function is not supported
150  * @see aspectRatio().
151  */
152  virtual bool setAspectRatio(const Scalar aspectRatio);
153 
154  /**
155  * Sets the distance to the near clipping plane.
156  * @param distance The distance to the near clipping plane to set, with range (0, farDistance())
157  * @return True, if succeeded
158  * @exception NotSupportedException Is thrown if this function is not supported
159  * @see nearDistance(), setFarDistance(), setNearFarDistance().
160  */
161  virtual bool setNearDistance(const Scalar distance);
162 
163  /**
164  * Sets the distance to the far clipping plane.
165  * @param distance The distance to the far clipping plane to set, with range (nearDistance(), infinity)
166  * @return True, if succeeded
167  * @exception NotSupportedException Is thrown if this function is not supported
168  * @see farDistance(), setNearDistance(), setNearFarDistance().
169  */
170  virtual bool setFarDistance(const Scalar distance);
171 
172  /**
173  * Sets the distance to the near and far clipping plane.
174  * @param nearDistance The distance to the near clipping plane, with range (0, farDistance)
175  * @param farDistance The distance to the far clipping plane to set, with range (nearDistance, infinity)
176  * @return True, if succeeded
177  * @exception NotSupportedException Is thrown if this function is not supported
178  * @see farDistance(), setNearDistance().
179  */
180  virtual bool setNearFarDistance(const Scalar nearDistance, const Scalar farDistance);
181 
182  /**
183  * Sets the position and orientation of the view in world coordinates (the extrinsic camera data, the inverse of the known View Matrix).
184  * @param world_T_view The transformation converting the view to world, must be valid
185  * @exception NotSupportedException Is thrown if this function is not supported
186  * @see transformation().
187  */
188  virtual void setTransformation(const HomogenousMatrix4& world_T_view);
189 
190  /**
191  * Sets the background color of the view.
192  * @param color Background color to set
193  * @return True, if the color is valid and could be set
194  * @exception NotSupportedException Is thrown if this function is not supported
195  * @see backgroundColor(), addBackground(), removeBackground().
196  */
197  virtual bool setBackgroundColor(const RGBAColor& color);
198 
199  /**
200  * Adds a new background object to the background stack of the view.
201  * A view can hold more than one background object, however the first background object is used for rendering only.
202  * @param background Background to add
203  * @exception NotSupportedException Is thrown if this function is not supported
204  * @see background(), removeBackground(), setBackgroundColor().
205  */
206  virtual void addBackground(const BackgroundRef& background);
207 
208  /**
209  * Removes a background object from the background stack of this view.
210  * If the background to remove is the currently first object in the background stack, the next background object in the queue will be used for rendering.
211  * @param background Background to remove
212  * @exception NotSupportedException Is thrown if this function is not supported
213  */
214  virtual void removeBackground(const BackgroundRef& background);
215 
216  /**
217  * Sets whether the headlight should be activated.
218  * @param state True, to activate the headlight
219  * @exception NotSupportedException Is thrown if this function is not supported
220  * @see useHeadlight().
221  */
222  virtual void setUseHeadlight(const bool state);
223 
224  /**
225  * Sets the phantom mode of this view.
226  * @param mode Phantom mode to be set
227  * @return True, if succeeded
228  * @exception NotSupportedException Is thrown if this function is not supported
229  * @see phantomMode().
230  */
232 
233  /**
234  * Fits the camera to a given node.
235  * If no node is specified the entire scene world is fitted.
236  * @param node Node to fit the camera to
237  * @exception NotSupportedException Is thrown if this function is not supported
238  */
239  virtual void fitCamera(const NodeRef& node = NodeRef());
240 
241  /**
242  * Returns the type of this object.
243  * @see Object::type().
244  */
245  ObjectType type() const override;
246 
247  protected:
248 
249  /**
250  * Creates a new view object.
251  */
252  View();
253 
254  /**
255  * Destructs a view object.
256  */
257  ~View() override;
258 
259  protected:
260 
261  /// The view's background objects.
263 };
264 
265 }
266 
267 }
268 
269 #endif // META_OCEAN_RENDERING_VIEW_H
This class implements an infinite line in 3D space.
Definition: Line3.h:70
This class implements a color defined by red, green, blue and alpha parameters.
Definition: RGBAColor.h:41
This class is the base class for all rendering objects.
Definition: Object.h:54
ObjectType
Definition of different object type.
Definition: Object.h:63
PhantomMode
Definition of different phantom modes.
Definition: PhantomAttribute.h:43
This class is the base class for all rendering views.
Definition: View.h:46
virtual bool setPhantomMode(const PhantomAttribute::PhantomMode mode)
Sets the phantom mode of this view.
virtual Line3 viewingRay(const Scalar x, const Scalar y, const unsigned int width, const unsigned int height) const
Returns a viewing ray into the scene.
virtual HomogenousMatrix4 transformation() const
Returns the transformation between view and world (the extrinsic camera data, the inverse of the know...
Backgrounds backgrounds_
The view's background objects.
Definition: View.h:262
View()
Creates a new view object.
virtual void fitCamera(const NodeRef &node=NodeRef())
Fits the camera to a given node.
virtual bool setNearFarDistance(const Scalar nearDistance, const Scalar farDistance)
Sets the distance to the near and far clipping plane.
~View() override
Destructs a view object.
virtual void addBackground(const BackgroundRef &background)
Adds a new background object to the background stack of the view.
virtual Scalar farDistance() const
Returns the distance to the far clipping plane.
virtual PhantomAttribute::PhantomMode phantomMode() const
Returns the phantom mode of this view.
virtual bool setBackgroundColor(const RGBAColor &color)
Sets the background color of the view.
virtual void setTransformation(const HomogenousMatrix4 &world_T_view)
Sets the position and orientation of the view in world coordinates (the extrinsic camera data,...
virtual bool useHeadlight() const
Returns whether the head light is enabled.
virtual RGBAColor backgroundColor() const
Returns the background color of the view.
virtual Backgrounds backgrounds() const
Returns all defined background objects.
virtual bool setAspectRatio(const Scalar aspectRatio)
Sets the aspect ratio of this view.
virtual BackgroundRef background() const
Returns the currently used background of the view.
virtual SquareMatrix4 projectionMatrix() const
Returns the projection matrix of this view.
virtual void removeBackground(const BackgroundRef &background)
Removes a background object from the background stack of this view.
virtual Scalar nearDistance() const
Returns the distance to the near clipping plane.
virtual void setUseHeadlight(const bool state)
Sets whether the headlight should be activated.
virtual bool setFarDistance(const Scalar distance)
Sets the distance to the far clipping plane.
virtual Scalar aspectRatio() const
Returns the aspect ratio of this view.
std::vector< BackgroundRef > Backgrounds
Definition of a vector holding background objects.
Definition: View.h:52
ObjectType type() const override
Returns the type of this object.
virtual bool setNearDistance(const Scalar distance)
Sets the distance to the near clipping plane.
float Scalar
Definition of a scalar type.
Definition: Math.h:128
SmartObjectRef< View > ViewRef
Definition of a smart object reference holding a view node.
Definition: View.h:31
SmartObjectRef< Node > NodeRef
Definition of a smart object reference holding a node.
Definition: rendering/Node.h:27
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15