MeshLib C++ Docs
Loading...
Searching...
No Matches
MRViewport.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRViewportGL.h"
4#include "MRFitData.h"
6#include <MRMesh/MRVector3.h>
7#include <MRMesh/MRPlane3.h>
10#include <MRMesh/MRQuaternion.h>
11#include <MRMesh/MRMatrix4.h>
12#include <MRMesh/MRColor.h>
13#include <MRMesh/MRBox.h>
14#include "MRImGui.h"
15#include <memory>
16#include <functional>
17#include <unordered_map>
18#include <optional>
19#include <span>
20
21namespace MR
22{
25
26
27inline ImVec2 position( const ViewportRectangle& rect )
28{
29 return { rect.min.x, rect.min.y };
30}
31
32inline ImVec2 size( const ViewportRectangle& rect )
33{
34 return { width( rect ), height( rect ) };
35}
36
40template<typename T>
41inline Vector4<T> toVec4( const ViewportRectangle& rect )
42{
43 return Vector4<T>{T( rect.min.x ), T( rect.min.y ), T( MR::width( rect ) ), T( MR::height( rect ) )};
44}
45
49{
50public:
51 using ViewportRectangle = MR::ViewportRectangle;
52
55 MRVIEWER_API static Viewport& get( ViewportId viewportId = {} );
56
57 MRVIEWER_API Viewport();
58 MRVIEWER_API ~Viewport();
59
60private:
61 Viewport( const Viewport & ) = default;
62 Viewport & operator = ( const Viewport & ) = default;
63public:
64 [[nodiscard]] Viewport clone() const { return Viewport( *this ); }
65 Viewport( Viewport && ) noexcept = default;
66 Viewport & operator = ( Viewport && ) noexcept = default;
67
69 MRVIEWER_API void init();
70
77 MRVIEWER_API void setAxesPos( const int pixelXoffset = -100, const int pixelYoffset = -100 );
78 MRVIEWER_API void setAxesSize( const int axisPixSize = 80 );
79
81 MRVIEWER_API const Vector2f& getAxesPosition() const;
82 MRVIEWER_API float getAxesSize() const;
83
85 [[deprecated("Use (draw/getBaseRenderParams/getModelRenderParams)OrthoFixedPos functions instead of using this value")]]
86 const Matrix4f& getAxesProjectionMatrix() const { return axesProjMat_; }
87
89 MRVIEWER_API void shut();
90
92
94 MRVIEWER_API void clearFramebuffers();
95
97 MRVIEWER_API void recursiveDraw( const Object& obj,
98 DepthFunction depthFunc = DepthFunction::Default, const AffineXf3f& rootXf = {}, RenderModelPassMask renderType = RenderModelPassMask::All,
99 const TransparencyMode& transparentMode = {}, int* numDraws = nullptr ) const;
100
103 MRVIEWER_API bool draw( const VisualObject& obj,
104 DepthFunction depthFunc = DepthFunction::Default, RenderModelPassMask pass = RenderModelPassMask::All, const TransparencyMode& transparentMode = {} ) const;
105
108 MRVIEWER_API bool draw( const VisualObject& obj, const AffineXf3f& xf,
109 DepthFunction depthFunc = DepthFunction::Default, RenderModelPassMask pass = RenderModelPassMask::All, const TransparencyMode& transparentMode = {} ) const;
110
113 MRVIEWER_API bool draw( const VisualObject& obj, const AffineXf3f& xf, const Matrix4f & projM,
114 DepthFunction depthFunc = DepthFunction::Default, RenderModelPassMask pass = RenderModelPassMask::All, const TransparencyMode& transparentMode = {} ) const;
115
118 MRVIEWER_API bool drawOrthoFixedPos( const VisualObject& obj, const AffineXf3f& xf,
119 DepthFunction depthFunc = DepthFunction::Default, RenderModelPassMask pass = RenderModelPassMask::All, const TransparencyMode& transparentMode = {} ) const;
120
123 {
124 float width{1.0f};
125 bool depthTest{ true };
126 };
127
129 MRVIEWER_API void drawLines( const std::vector<LineSegm3f>& lines, const std::vector<SegmEndColors>& colors, const LinePointImmediateRenderParams & params );
130 void drawLines( const std::vector<LineSegm3f>& lines, const std::vector<SegmEndColors>& colors, float width = 1, bool depthTest = true )
131 { drawLines( lines, colors, { getBaseRenderParams(), width, depthTest } ); }
132
134 MRVIEWER_API void drawPoints( const std::vector<Vector3f>& points, const std::vector<Vector4f>& colors, const LinePointImmediateRenderParams & params );
135 void drawPoints( const std::vector<Vector3f>& points, const std::vector<Vector4f>& colors, float width = 1, bool depthTest = true )
136 { drawPoints( points, colors, { getBaseRenderParams(), width, depthTest } ); }
137
139 {
140 Vector4f a, b, c;
141 };
142
144 MRVIEWER_API void drawTris( const std::vector<Triangle3f>& tris, const std::vector<TriCornerColors>& colors, const ModelRenderParams& params, bool depthTest = true );
145 MRVIEWER_API void drawTris( const std::vector<Triangle3f>& tris, const std::vector<TriCornerColors>& colors, const Matrix4f& modelM = {}, bool depthTest = true );
146
148 [[nodiscard]] BaseRenderParams getBaseRenderParams() const { return getBaseRenderParams( projM_ ); }
149
151 [[nodiscard]] BaseRenderParams getBaseRenderParams( const Matrix4f & projM ) const
152 { return { viewM_, projM, id, toVec4<int>( viewportRect_ ) }; }
153
156 { return { axesViewMat_, axesProjMat_, id, toVec4<int>( viewportRect_ ) }; }
157
160 const Matrix4f & modelM,
161 Matrix4f * normM,
164 const TransparencyMode& transparentMode = {}
165 ) const
166 { return getModelRenderParams( modelM, getBaseRenderParams(projM_), normM, depthFunc, pass, transparentMode ); }
167
170 const Matrix4f & modelM,
171 Matrix4f * normM,
174 const TransparencyMode& transparentMode = {}
175 ) const
176 { return getModelRenderParams( modelM, getBaseRenderParamsOrthoFixedPos(), normM, depthFunc, pass, transparentMode ); }
177
179 [[nodiscard]] MRVIEWER_API ModelRenderParams getModelRenderParams( const Matrix4f & modelM, const BaseRenderParams& baseParams,
180 Matrix4f * normM,
183 const TransparencyMode& transparentMode = {}
184 ) const;
185
187 using PickRenderObjectPredicate = std::function<bool ( const VisualObject*, ViewportMask )>;
190 {
192 std::optional<Vector2f> point;
193
196
199 int pickRadius = -1;
203 bool exactPickFirst = true;
204
207
212 {
213 return {};
214 }
215 };
218 MRVIEWER_API ObjAndPick pickRenderObject( const PickRenderObjectParams& params = PickRenderObjectParams::defaults() ) const;
220 MRVIEWER_API ObjAndPick pickRenderObject( std::span<VisualObject* const> objects, const PickRenderObjectParams& params = PickRenderObjectParams::defaults() ) const;
222 MRVIEWER_API ConstObjAndPick pickRenderObjectConst( std::span<const VisualObject* const> objects, const PickRenderObjectParams& params = PickRenderObjectParams::defaults() ) const;
223
231 MRVIEWER_API ObjAndPick pick_render_object() const;
232 [[deprecated("Use `pickRenderObject()`")]]
233 MRVIEWER_API ObjAndPick pick_render_object( uint16_t pickRadius ) const;
239 [[deprecated("Use `pickRenderObject( objects } )`")]]
240 MRVIEWER_API ObjAndPick pick_render_object( const std::vector<VisualObject*>& objects ) const;
245 [[deprecated("Use `pickRenderObject( ... )`")]]
246 MRVIEWER_API ObjAndPick pick_render_object( const std::vector<VisualObject*>& objects, uint16_t pickRadius, bool exactPickFirst = true ) const;
248 [[deprecated("Use `pickRenderObject( { .exactPickFirst = ... } )`")]]
249 MRVIEWER_API ObjAndPick pick_render_object( bool exactPickFirst ) const;
255 [[deprecated("Use `pickRenderObject( { .point = ... } )`")]]
256 MRVIEWER_API ObjAndPick pick_render_object( const Vector2f& viewportPoint ) const;
261 [[deprecated("Use `multiPickObjects( objects, { .point = ... } )`")]]
262 MRVIEWER_API ObjAndPick pick_render_object( const std::vector<VisualObject*>& objects, const Vector2f& viewportPoint ) const;
263
267 MRVIEWER_API std::vector<ObjAndPick> multiPickObjects( std::span<VisualObject* const> objects, const std::vector<Vector2f>& viewportPoints, const BaseRenderParams* overrideRenderParams = nullptr ) const;
268
273 MRVIEWER_API std::vector<std::shared_ptr<VisualObject>> findObjectsInRect( const Box2i& rect,
274 int maxRenderResolutionSide = 512 ) const;
275
280 MRVIEWER_API std::unordered_map<std::shared_ptr<ObjectMesh>, FaceBitSet> findVisibleFaces( const BitSet& includePixBs,
281 int maxRenderResolutionSide = 512 ) const;
282
284 [[nodiscard]] MRVIEWER_API FaceBitSet findCameraLookingFaces( const Mesh& mesh, const AffineXf3f& meshToWorld ) const;
285
286
292 [[deprecated("Use `pickRenderObject()`.")]]
293 MRVIEWER_API ConstObjAndPick const_pick_render_object() const;
298 [[deprecated("Use `pickRenderObject( objects )`.")]]
299 MRVIEWER_API ConstObjAndPick const_pick_render_object( const std::vector<const VisualObject*>& objects ) const;
302 MRVIEWER_API std::vector<ConstObjAndPick> constMultiPickObjects( const std::vector<const VisualObject*>& objects, const std::vector<Vector2f>& viewportPoints ) const;
303
307 MRVIEWER_API void transformView( const AffineXf3f & xf );
308
309 bool getRedrawFlag() const { return needRedraw_; }
310 void resetRedrawFlag() { needRedraw_ = false; }
311
314
316 {
317 Color backgroundColor = Color( Vector3f{0.3f, 0.3f, 0.5f} );
318 Vector3f lightPosition{0.0f, 0.3f, 0.0f};
319
322 float cameraZoom{1.0f};
323 float cameraViewAngle{45.0f};
324 float cameraDnear{1.0f};
325 float cameraDfar{100.0f};
326
327 bool depthTest{true};
328 bool orthographic{true};
329
331 {
332 Auto,
333 Fixed
334 } globalBasisScaleMode{ GlobalBasisScaleMode::Auto };
335
337 float objectScale{1.0f};
338
340
341 std::string label;
342
343 Plane3f clippingPlane{Vector3f::plusX(), 0.0f};
344
346 {
347 Static,
349 Dynamic
351
354 std::optional<Vector3f> staticRotationPivot;
355
358 bool compensateRotation{ true };
359
361 bool selectable{true};
362
363 bool operator==( const Viewport::Parameters& other ) const = default;
364 };
365
367 MRVIEWER_API void setRotation( bool state );
368
370 MRVIEWER_API const ViewportRectangle& getViewportRect() const;
371
373 MRVIEWER_API float getPixelSize() const;
374
377 MRVIEWER_API float getPixelSizeAtPoint( const Vector3f& worldPoint ) const;
378
381 MRVIEWER_API void setViewportRect( const ViewportRectangle& rect );
382
383private:
385 Matrix4f viewM_;
386 Matrix4f projM_;
387
388public:
390 [[nodiscard]] MRVIEWER_API AffineXf3f getUnscaledViewXf() const;
391
393 [[nodiscard]] AffineXf3f getViewXf() const { return AffineXf3f( viewM_ ); }
394
396 [[nodiscard]] Vector3f getUpDirection() const { return Vector3f( viewM_.y.x, viewM_.y.y, viewM_.y.z ).normalized(); }
397
399 [[nodiscard]] Vector3f getRightDirection() const { return Vector3f( viewM_.x.x, viewM_.x.y, viewM_.x.z ).normalized(); }
400
402 [[nodiscard]] Vector3f getBackwardDirection() const { return Vector3f( viewM_.z.x, viewM_.z.y, viewM_.z.z ).normalized(); }
403
407 MRVIEWER_API Line3f unprojectPixelRay( const Vector2f& viewportPoint ) const;
408
410 MRVIEWER_API Vector3f worldToCameraSpace( const Vector3f& p ) const;
411 MRVIEWER_API std::vector<Vector3f> worldToCameraSpace( const std::vector<Vector3f>& p ) const;
412
416 MRVIEWER_API Vector3f projectToClipSpace( const Vector3f& worldPoint ) const;
417 MRVIEWER_API std::vector<Vector3f> projectToClipSpace( const std::vector<Vector3f>& worldPoints ) const;
418 MRVIEWER_API Vector3f unprojectFromClipSpace( const Vector3f& clipPoint ) const;
419 MRVIEWER_API std::vector<Vector3f> unprojectFromClipSpace( const std::vector<Vector3f>& clipPoints ) const;
420
424 MRVIEWER_API Vector3f projectToViewportSpace( const Vector3f& worldPoint ) const;
425 MRVIEWER_API std::vector<Vector3f> projectToViewportSpace( const std::vector<Vector3f>& worldPoints ) const;
429 MRVIEWER_API Vector3f unprojectFromViewportSpace( const Vector3f& viewportPoint ) const;
430 MRVIEWER_API std::vector<Vector3f> unprojectFromViewportSpace( const std::vector<Vector3f>& viewportPoints ) const;
431
437 MRVIEWER_API Vector3f clipSpaceToViewportSpace( const Vector3f& p ) const;
438 MRVIEWER_API std::vector<Vector3f> clipSpaceToViewportSpace( const std::vector<Vector3f>& p ) const;
439 MRVIEWER_API Vector3f viewportSpaceToClipSpace( const Vector3f& p ) const;
440 MRVIEWER_API std::vector<Vector3f> viewportSpaceToClipSpace( const std::vector<Vector3f>& p ) const;
441
443 void setupView();
449 void preDraw();
455 void postDraw() const;
456
460 MRVIEWER_API void fitData( float fill = 1.0f, bool snapView = true );
461
465 MRVIEWER_API void fitBox( const Box3f& newSceneBox, float fill = 1.0f, bool snapView = true );
466
471
473 MRVIEWER_API void preciseFitBoxToScreenBorder( const FitBoxParams& params );
475 MRVIEWER_API void preciseFitDataToScreenBorder( const FitDataParams& params = {} );
476
478 MRVIEWER_API float getRatio() const;
479
481 MRVIEWER_API bool allModelsInsideViewportRectangle() const;
482
483 MRVIEWER_API const Box3f& getSceneBox() const;
484
485 const Parameters& getParameters() const { return params_; }
486
488 MRVIEWER_API Vector3f getCameraPoint() const;
490 MRVIEWER_API void setCameraPoint( const Vector3f& cameraWorldPos );
491
492 MRVIEWER_API void setCameraTrackballAngle( const Quaternionf& rot );
493
494 MRVIEWER_API void setCameraTranslation( const Vector3f& translation );
495
496 MRVIEWER_API void setCameraViewAngle( float newViewAngle );
497
498 MRVIEWER_API void setCameraZoom( float zoom );
499
500 MRVIEWER_API void setOrthographic( bool orthographic );
501
502 MRVIEWER_API void setBackgroundColor( const Color& color );
503
504 MRVIEWER_API void setClippingPlane( const Plane3f& plane );
505
506 MRVIEWER_API void setLabel( std::string s );
507
508 void setSelectable( bool on ) { params_.selectable = on; }
509
510 MRVIEWER_API void showAxes( bool on );
511 MRVIEWER_API void showClippingPlane( bool on );
512 MRVIEWER_API void showRotationCenter( bool on );
513 MRVIEWER_API void showGlobalBasis( bool on );
515
516 MRVIEWER_API void setParameters( const Viewport::Parameters& params );
517
521 MRVIEWER_API void cameraLookAlong( const Vector3f& dir, const Vector3f& up );
522
525 MRVIEWER_API void cameraRotateAround( const Line3f& axis, float angle );
526
528 Vector3f getRotationPivot() const { return rotationPivot_; }
529
534 MRVIEWER_API void resetStaticRotationPivot( const std::optional<Vector3f>& pivot = std::nullopt );
535private:
538 void setRotationPivot_( const Vector3f& point ) { rotationPivot_ = point; }
540 void setupViewMatrix_();
542 AffineXf3f getViewXf_() const;
543
545 void setupProjMatrix_();
547 void setupAxesViewProjMatrix_();
548
552 Matrix4f getFullViewportMatrix() const { return projM_ * viewM_; }
553 Matrix4f getFullViewportInversedMatrix() const;
554
555 ViewportRectangle viewportRect_;
556
557 ViewportGL viewportGL_;
558
559 bool previewLinesDepthTest_ = false;
560 bool previewPointsDepthTest_ = false;
561
562 void draw_border() const;
563 void draw_rotation_center() const;
564 void draw_clipping_plane() const;
565 void drawGlobalBasis() const;
566
568 void initBaseAxes();
570 void drawAxesAndViewController() const;
571
574 Matrix4f axesViewMat_;
575 Matrix4f axesProjMat_;
576 Vector2f basisAxesPos_;
577 float basisAxesSize_;
578
580 int pixelXoffset_{ -100 };
581 int pixelYoffset_{ -128 };
582 int axisPixSize_{ 70 };
583
584 void updateSceneBox_();
585 void rotateView_();
586
587 enum class Space
588 {
589 World,
590 CameraOrthographic,
591 CameraPerspective
592 };
593
598 Box3f calcBox_( const std::vector<std::shared_ptr<VisualObject>>& objs, Space space, bool selectedPrimitives = false ) const;
599
607 std::pair<float, bool> getZoomFOVtoScreen_( std::function<Box3f()> getBoxFn, Vector3f* cameraShift = nullptr ) const;
612 void preciseFitToScreenBorder_( std::function<Box3f( bool zoomFOV, bool globalBasis )> getBoxFn, const BaseFitParams& params );
613
614 bool rotation_{ false };
615 Vector3f rotationPivot_;
616 Vector3f static_point_;
617 Vector2f static_viewport_point;
618 float distToSceneCenter_;
619
620 bool needRedraw_{false};
621
623 Box3f sceneBox_;
624
625 Parameters params_;
626};
627
628}
Definition MRBitSet.h:24
named object in the data model
Definition MRObject.h:62
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:42
Definition MRViewport.h:49
Visual Object.
Definition MRVisualObject.h:116
auto width(const Box< V > &box)
returns size along x axis
Definition MRBox.h:354
auto height(const Box< V > &box)
returns size along y axis
Definition MRBox.h:361
MRVIEWER_API Vector3f projectToClipSpace(const Vector3f &worldPoint) const
MRVIEWER_API bool draw(const VisualObject &obj, const AffineXf3f &xf, const Matrix4f &projM, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
RotationCenterMode
Definition MRViewport.h:346
int pickRadius
Definition MRViewport.h:199
PickRenderObjectPredicate predicate
Predicate to additionally filter objects that should be treated as pickable.
Definition MRViewport.h:195
MRVIEWER_API void showRotationCenter(bool on)
Vector4f c
Definition MRViewport.h:140
MRVIEWER_API ConstObjAndPick const_pick_render_object() const
MRVIEWER_API Vector3f projectToViewportSpace(const Vector3f &worldPoint) const
MRVIEWER_API void setCameraViewAngle(float newViewAngle)
MRVIEWER_API void setCameraZoom(float zoom)
bool exactPickFirst
Definition MRViewport.h:203
MRVIEWER_API ObjAndPick pick_render_object(const std::vector< VisualObject * > &objects, uint16_t pickRadius, bool exactPickFirst=true) const
MRVIEWER_API void shut()
Shutdown.
static PickRenderObjectParams defaults()
Definition MRViewport.h:211
MR::BaseFitParams BaseFitParams
Definition MRViewport.h:468
MRVIEWER_API float getAxesSize() const
MRVIEWER_API ObjAndPick pick_render_object(const std::vector< VisualObject * > &objects, const Vector2f &viewportPoint) const
Vector3f getRightDirection() const
assume that viewM is orthogonal and inverse=transpose
Definition MRViewport.h:399
float cameraViewAngle
Definition MRViewport.h:323
MRVIEWER_API ~Viewport()
Vector3f cameraTranslation
Definition MRViewport.h:321
MRVIEWER_API std::vector< Vector3f > unprojectFromViewportSpace(const std::vector< Vector3f > &viewportPoints) const
MRVIEWER_API bool drawOrthoFixedPos(const VisualObject &obj, const AffineXf3f &xf, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
Color backgroundColor
Definition MRViewport.h:317
MRVIEWER_API void cameraLookAlong(const Vector3f &dir, const Vector3f &up)
MRVIEWER_API Vector3f unprojectFromClipSpace(const Vector3f &clipPoint) const
FitMode
Fit mode ( types of objects for which the fit is applied )
Definition MRFitData.h:14
MRVIEWER_API ObjAndPick pick_render_object(uint16_t pickRadius) const
MRVIEWER_API ConstObjAndPick pickRenderObjectConst(std::span< const VisualObject *const > objects, const PickRenderObjectParams &params=PickRenderObjectParams::defaults()) const
This overload uses const objects from the list (possibly filtered by a predicate)....
MRVIEWER_API void showGlobalBasis(bool on)
std::function< bool(const VisualObject *, ViewportMask)> PickRenderObjectPredicate
Predicate to additionally filter objects that should be treated as pickable.
Definition MRViewport.h:187
MRVIEWER_API void cameraRotateAround(const Line3f &axis, float angle)
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
bool orthographic
Definition MRViewport.h:328
Vector3f getRotationPivot() const
returns current rotation pivot in world space, which should appear static on a screen during rotation...
Definition MRViewport.h:528
MRVIEWER_API void setCameraTranslation(const Vector3f &translation)
MRVIEWER_API ObjAndPick pickRenderObject(const PickRenderObjectParams &params=PickRenderObjectParams::defaults()) const
bool getRedrawFlag() const
Definition MRViewport.h:309
BaseRenderParams getBaseRenderParams(const Matrix4f &projM) const
Prepares base rendering parameters for this viewport with custom projection matrix.
Definition MRViewport.h:151
MRVIEWER_API float getRatio() const
returns viewport width/height ratio
void setSelectable(bool on)
Definition MRViewport.h:508
MRVIEWER_API float getPixelSize() const
Finds length between near pixels on zNear plane. Only good in the orthographic projection.
MRVIEWER_API ConstObjAndPick const_pick_render_object(const std::vector< const VisualObject * > &objects) const
MRVIEWER_API Vector3f unprojectFromViewportSpace(const Vector3f &viewportPoint) const
MRVIEWER_API const Vector2f & getAxesPosition() const
returns position of basis axes in viewport space
void drawLines(const std::vector< LineSegm3f > &lines, const std::vector< SegmEndColors > &colors, float width=1, bool depthTest=true)
Definition MRViewport.h:130
MRVIEWER_API void init()
Initialization.
MRVIEWER_API float getPixelSizeAtPoint(const Vector3f &worldPoint) const
void resetRedrawFlag()
Definition MRViewport.h:310
Vector4f b
Definition MRViewport.h:140
MRVIEWER_API void preciseFitDataToScreenBorder(const FitDataParams &params={})
fit view and proj matrices to match the screen size with given objects
float cameraDfar
Definition MRViewport.h:325
MRVIEWER_API Vector3f viewportSpaceToClipSpace(const Vector3f &p) const
MR::ViewportRectangle ViewportRectangle
Definition MRViewport.h:51
MRVIEWER_API ModelRenderParams getModelRenderParams(const Matrix4f &modelM, const BaseRenderParams &baseParams, Matrix4f *normM, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
Prepares rendering parameters to draw a model with given transformation in this viewport with custom ...
MRVIEWER_API void setRotation(bool state)
Starts or stop rotation.
Vector4f a
Definition MRViewport.h:140
MRVIEWER_API void setParameters(const Viewport::Parameters &params)
MRVIEWER_API std::vector< Vector3f > clipSpaceToViewportSpace(const std::vector< Vector3f > &p) const
MRVIEWER_API void setOrthographic(bool orthographic)
Color borderColor
Definition MRViewport.h:339
MRVIEWER_API bool draw(const VisualObject &obj, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
ModelRenderParams getModelRenderParamsOrthoFixedPos(const Matrix4f &modelM, Matrix4f *normM, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
Prepares rendering parameters to draw a model with orthographic proj matrix and rotation component of...
Definition MRViewport.h:169
ModelRenderParams getModelRenderParams(const Matrix4f &modelM, Matrix4f *normM, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
Prepares rendering parameters to draw a model with given transformation in this viewport.
Definition MRViewport.h:159
AffineXf3f getViewXf() const
converts directly from the view matrix
Definition MRViewport.h:393
void preDraw()
bool depthTest
Definition MRViewport.h:125
MRVIEWER_API void showClippingPlane(bool on)
MRVIEWER_API const ViewportRectangle & getViewportRect() const
Note, Y is up for this box.
MRVIEWER_API void fitBox(const Box3f &newSceneBox, float fill=1.0f, bool snapView=true)
MRVIEWER_API void showAxes(bool on)
bool depthTest
Definition MRViewport.h:327
BaseRenderParams getBaseRenderParamsOrthoFixedPos() const
Prepares base rendering parameters for this viewport with orthographic proj matrix and rotation compo...
Definition MRViewport.h:155
RenderModelPassMask
Various passes of the 3D rendering.
Definition MRRenderModelParameters.h:40
MRVIEWER_API std::vector< Vector3f > worldToCameraSpace(const std::vector< Vector3f > &p) const
MRVIEWER_API Vector3f getCameraPoint() const
returns camera world location for the current view
MRVIEWER_API void drawTris(const std::vector< Triangle3f > &tris, const std::vector< TriCornerColors > &colors, const Matrix4f &modelM={}, bool depthTest=true)
MRVIEWER_API void drawTris(const std::vector< Triangle3f > &tris, const std::vector< TriCornerColors > &colors, const ModelRenderParams &params, bool depthTest=true)
Draw triangles immediately (flat shaded)
MRVIEWER_API void resetStaticRotationPivot(const std::optional< Vector3f > &pivot=std::nullopt)
Plane3f clippingPlane
Definition MRViewport.h:343
MRVIEWER_API void setCameraTrackballAngle(const Quaternionf &rot)
std::string label
Definition MRViewport.h:341
MRVIEWER_API ObjAndPick pick_render_object(const std::vector< VisualObject * > &objects) const
NOTE! If your list is hardcoded, use .objects = std::array{ a, b, c }.
MRVIEWER_API bool draw(const VisualObject &obj, const AffineXf3f &xf, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
Vector3f getBackwardDirection() const
assume that viewM is orthogonal and inverse=transpose
Definition MRViewport.h:402
MRVIEWER_API Line3f unprojectPixelRay(const Vector2f &viewportPoint) const
assume that viewM is orthogonal and inverse=transpose
MRVIEWER_API std::vector< Vector3f > unprojectFromClipSpace(const std::vector< Vector3f > &clipPoints) const
Viewport clone() const
Definition MRViewport.h:64
float cameraZoom
Definition MRViewport.h:322
MRVIEWER_API void setLabel(std::string s)
Quaternionf cameraTrackballAngle
x y z - position, w - factor
Definition MRViewport.h:320
Vector3f lightPosition
Definition MRViewport.h:318
Vector4< T > toVec4(const ViewportRectangle &rect)
Definition MRViewport.h:41
MRVIEWER_API std::unordered_map< std::shared_ptr< ObjectMesh >, FaceBitSet > findVisibleFaces(const BitSet &includePixBs, int maxRenderResolutionSide=512) const
const Parameters & getParameters() const
Definition MRViewport.h:485
MRVIEWER_API std::vector< Vector3f > viewportSpaceToClipSpace(const std::vector< Vector3f > &p) const
MRVIEWER_API FaceBitSet findCameraLookingFaces(const Mesh &mesh, const AffineXf3f &meshToWorld) const
finds all triangles of a mesh that having normals oriented toward the camera in this viewport
MRVIEWER_API std::vector< Vector3f > projectToViewportSpace(const std::vector< Vector3f > &worldPoints) const
MRVIEWER_API void fitData(float fill=1.0f, bool snapView=true)
MRVIEWER_API void setAxesSize(const int axisPixSize=80)
MRVIEWER_API void recursiveDraw(const Object &obj, DepthFunction depthFunc=DepthFunction::Default, const AffineXf3f &rootXf={}, RenderModelPassMask renderType=RenderModelPassMask::All, const TransparencyMode &transparentMode={}, int *numDraws=nullptr) const
Immediate draw of given object tree.
MRVIEWER_API void drawPoints(const std::vector< Vector3f > &points, const std::vector< Vector4f > &colors, const LinePointImmediateRenderParams &params)
Draw points immediately.
enum MR::Viewport::Parameters::GlobalBasisScaleMode Auto
MRVIEWER_API const Box3f & getSceneBox() const
DepthFunction
Definition MRIRenderObject.h:21
static MRVIEWER_API Viewport & get(ViewportId viewportId={})
void setupView()
updates view and projection matrices due to camera parameters (called each frame)
MRVIEWER_API ObjAndPick pickRenderObject(std::span< VisualObject *const > objects, const PickRenderObjectParams &params=PickRenderObjectParams::defaults()) const
This overload uses objects from the list (possibly filtered by a predicate).
bool selectable
this flag allows viewport to be selected by user
Definition MRViewport.h:361
MRVIEWER_API void setViewportRect(const ViewportRectangle &rect)
Viewport(Viewport &&) noexcept=default
GlobalBasisScaleMode
Definition MRViewport.h:331
MRVIEWER_API std::vector< ObjAndPick > multiPickObjects(std::span< VisualObject *const > objects, const std::vector< Vector2f > &viewportPoints, const BaseRenderParams *overrideRenderParams=nullptr) const
enum MR::Viewport::Parameters::RotationCenterMode Dynamic
MRVIEWER_API void transformView(const AffineXf3f &xf)
std::optional< Vector3f > staticRotationPivot
Definition MRViewport.h:354
bool operator==(const Viewport::Parameters &other) const =default
MRVIEWER_API Vector3f worldToCameraSpace(const Vector3f &p) const
convert point(s) to camera space by applying view matrix
MRVIEWER_API ObjAndPick pick_render_object(bool exactPickFirst) const
This function allows to pick point in scene by GL with default pick radius, but with specified exactP...
MRVIEWER_API std::vector< ConstObjAndPick > constMultiPickObjects(const std::vector< const VisualObject * > &objects, const std::vector< Vector2f > &viewportPoints) const
MRVIEWER_API AffineXf3f getUnscaledViewXf() const
returns orthonormal matrix with translation
const Matrix4f & getAxesProjectionMatrix() const
returns projection matrix that is used for basis axes and view controller rendering
Definition MRViewport.h:86
MRVIEWER_API void setClippingPlane(const Plane3f &plane)
MRVIEWER_API void preciseFitBoxToScreenBorder(const FitBoxParams &params)
fit view and proj matrices to match the screen size with given box
MRVIEWER_API bool allModelsInsideViewportRectangle() const
returns true if all models are fully projected inside the viewport rectangle
float cameraDnear
Definition MRViewport.h:324
void postDraw() const
BaseRenderParams getBaseRenderParams() const
Prepares base rendering parameters for this viewport.
Definition MRViewport.h:148
MRVIEWER_API void drawLines(const std::vector< LineSegm3f > &lines, const std::vector< SegmEndColors > &colors, const LinePointImmediateRenderParams &params)
Draw lines immediately.
bool compensateRotation
Definition MRViewport.h:358
void drawPoints(const std::vector< Vector3f > &points, const std::vector< Vector4f > &colors, float width=1, bool depthTest=true)
Definition MRViewport.h:135
MRVIEWER_API Viewport()
MRVIEWER_API void setBackgroundColor(const Color &color)
const BaseRenderParams * baseRenderParams
if not nullptr it can override render params for picker
Definition MRViewport.h:206
MRVIEWER_API std::vector< std::shared_ptr< VisualObject > > findObjectsInRect(const Box2i &rect, int maxRenderResolutionSide=512) const
MRVIEWER_API void setAxesPos(const int pixelXoffset=-100, const int pixelYoffset=-100)
float width
Definition MRViewport.h:124
MRVIEWER_API void clearFramebuffers()
----------------— Drawing functions
MRVIEWER_API ObjAndPick pick_render_object(const Vector2f &viewportPoint) const
MRVIEWER_API void setCameraPoint(const Vector3f &cameraWorldPos)
sets camera world location for the current view
MRVIEWER_API Vector3f clipSpaceToViewportSpace(const Vector3f &p) const
ViewportId id
Unique identifier.
Definition MRViewport.h:313
std::optional< Vector2f > point
If specified, this is the target screen point. Otherwise use the mouse pos in viewport coordinates.
Definition MRViewport.h:192
float objectScale
Caches the two-norm between the min/max point of the bounding box.
Definition MRViewport.h:337
MRVIEWER_API std::vector< Vector3f > projectToClipSpace(const std::vector< Vector3f > &worldPoints) const
MRVIEWER_API void rotationCenterMode(Parameters::RotationCenterMode mode)
Vector3f getUpDirection() const
returns unit vector in world space corresponding to up-direction in camera space
Definition MRViewport.h:396
MRVIEWER_API ObjAndPick pick_render_object() const
@ DynamicStatic
scene is always rotated around its center or another manually set point
@ Dynamic
scene is rotated around picked point on object, or around center, if miss pick
@ other
Angle, normally float. Measure in radians.
@ angle
Direction, normally Vector3f.
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRFitData.h:23
Common rendering parameters for meshes and UI.
Definition MRIRenderObject.h:36
Definition MRColor.h:12
Definition MRFitData.h:45
Definition MRFitData.h:32
Definition MRMesh.h:23
Mesh rendering parameters for primary rendering (as opposed to the picker).
Definition MRIRenderObject.h:54
struct to determine transparent rendering mode
Definition MRRenderModelParameters.h:13
Definition MRVector4.h:26
Rendering parameters for immediate drawing of lines and points.
Definition MRViewport.h:123
Definition MRViewport.h:316
Point picking parameters.
Definition MRViewport.h:190
Definition MRViewport.h:139