MeshLib C++ Docs
Loading...
Searching...
No Matches
MRViewport.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRViewerFwd.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>
15#include <MRMesh/MRUniquePtr.h>
16#include <MRMesh/MRVector4.h>
17#include "MRImGui.h"
18#include <memory>
19#include <functional>
20#include <unordered_map>
21#include <optional>
22#include <span>
23#include <vector>
24
25namespace MR
26{
29
30
33{
34 Vector4f a, b;
35};
36
37inline bool operator==( const SegmEndColors& a, const SegmEndColors& b )
38{
39 return a.a == b.a && a.b == b.b;
40}
41
44{
45 std::vector<Vector3f> points;
46 std::vector<Vector4f> colors;
47};
48
50{
51 return a.points == b.points && a.colors == b.colors;
52}
53
54inline ImVec2 position( const ViewportRectangle& rect )
55{
56 return { rect.min.x, rect.min.y };
57}
58
59inline ImVec2 size( const ViewportRectangle& rect )
60{
61 return { width( rect ), height( rect ) };
62}
63
67template<typename T>
68inline Vector4<T> toVec4( const ViewportRectangle& rect )
69{
70 return Vector4<T>{T( rect.min.x ), T( rect.min.y ), T( MR::width( rect ) ), T( MR::height( rect ) )};
71}
72
76{
77public:
79
82 MRVIEWER_API static Viewport& get( ViewportId viewportId = {} );
83
84 MRVIEWER_API Viewport();
85 MRVIEWER_API ~Viewport();
86
87private:
88 MRVIEWER_API Viewport( const Viewport & );
89 MRVIEWER_API Viewport & operator = ( const Viewport & );
90public:
91 [[nodiscard]] Viewport clone() const { return Viewport( *this ); }
92 MRVIEWER_API Viewport( Viewport && ) noexcept;
93 MRVIEWER_API Viewport & operator = ( Viewport && ) noexcept;
94
96 MRVIEWER_API void init();
97
104 MRVIEWER_API void setAxesPos( const int pixelXoffset = -100, const int pixelYoffset = -100 );
105 MRVIEWER_API void setAxesSize( const int axisPixSize = 80 );
106
108 MRVIEWER_API const Vector2f& getAxesPosition() const;
109 MRVIEWER_API float getAxesSize() const;
110
112 [[deprecated("Use (draw/getBaseRenderParams/getModelRenderParams)OrthoFixedPos functions instead of using this value")]]
113 const Matrix4f& getAxesProjectionMatrix() const { return axesProjMat_; }
114
116 MRVIEWER_API void shut();
117
119
121 MRVIEWER_API void clearFramebuffers();
122
124 MRVIEWER_API void recursiveDraw( const Object& obj,
125 DepthFunction depthFunc = DepthFunction::Default, const AffineXf3f& rootXf = {}, RenderModelPassMask renderType = RenderModelPassMask::All,
126 const TransparencyMode& transparentMode = {}, int* numDraws = nullptr ) const;
127
130 MRVIEWER_API bool draw( const VisualObject& obj,
131 DepthFunction depthFunc = DepthFunction::Default, RenderModelPassMask pass = RenderModelPassMask::All, const TransparencyMode& transparentMode = {} ) const;
132
135 MRVIEWER_API bool draw( const VisualObject& obj, const AffineXf3f& xf,
136 DepthFunction depthFunc = DepthFunction::Default, RenderModelPassMask pass = RenderModelPassMask::All, const TransparencyMode& transparentMode = {} ) const;
137
140 MRVIEWER_API bool draw( const VisualObject& obj, const AffineXf3f& xf, const Matrix4f & projM,
141 DepthFunction depthFunc = DepthFunction::Default, RenderModelPassMask pass = RenderModelPassMask::All, const TransparencyMode& transparentMode = {} ) const;
142
145 MRVIEWER_API bool drawOrthoFixedPos( const VisualObject& obj, const AffineXf3f& xf,
146 DepthFunction depthFunc = DepthFunction::Default, RenderModelPassMask pass = RenderModelPassMask::All, const TransparencyMode& transparentMode = {} ) const;
147
150 {
151 float width{1.0f};
152 bool depthTest{ true };
153 };
154
156 MRVIEWER_API void drawLines( const std::vector<LineSegm3f>& lines, const std::vector<SegmEndColors>& colors, const LinePointImmediateRenderParams & params );
157 void drawLines( const std::vector<LineSegm3f>& lines, const std::vector<SegmEndColors>& colors, float width = 1, bool depthTest = true )
158 { drawLines( lines, colors, { getBaseRenderParams(), width, depthTest } ); }
159
161 MRVIEWER_API void drawPoints( std::span<const Vector3f> points, std::span<const Vector4f> colors, const LinePointImmediateRenderParams & params );
162 void drawPoints( std::span<const Vector3f> points, std::span<const Vector4f> colors, float width = 1, bool depthTest = true )
163 { drawPoints( points, colors, { getBaseRenderParams(), width, depthTest } ); }
164
166 {
167 Vector4f a, b, c;
168 };
169
171 MRVIEWER_API void drawTris( const std::vector<Triangle3f>& tris, const std::vector<TriCornerColors>& colors, const ModelRenderParams& params, bool depthTest = true );
172 MRVIEWER_API void drawTris( const std::vector<Triangle3f>& tris, const std::vector<TriCornerColors>& colors, const Matrix4f& modelM = {}, bool depthTest = true );
173
175 [[nodiscard]] BaseRenderParams getBaseRenderParams() const { return getBaseRenderParams( projM_ ); }
176
178 [[nodiscard]] BaseRenderParams getBaseRenderParams( const Matrix4f & projM ) const
179 { return { viewM_, projM, id, toVec4<int>( viewportRect_ ) }; }
180
183 { return { axesViewMat_, axesProjMat_, id, toVec4<int>( viewportRect_ ) }; }
184
187 const Matrix4f & modelM,
188 Matrix4f * normM,
191 const TransparencyMode& transparentMode = {}
192 ) const
193 { return getModelRenderParams( modelM, getBaseRenderParams(projM_), normM, depthFunc, pass, transparentMode ); }
194
197 const Matrix4f & modelM,
198 Matrix4f * normM,
201 const TransparencyMode& transparentMode = {}
202 ) const
203 { return getModelRenderParams( modelM, getBaseRenderParamsOrthoFixedPos(), normM, depthFunc, pass, transparentMode ); }
204
206 [[nodiscard]] MRVIEWER_API ModelRenderParams getModelRenderParams( const Matrix4f & modelM, const BaseRenderParams& baseParams,
207 Matrix4f * normM,
210 const TransparencyMode& transparentMode = {}
211 ) const;
212
214 using PickRenderObjectPredicate = std::function<bool ( const VisualObject*, ViewportMask )>;
217 {
219 std::optional<Vector2f> point;
220
223
226 int pickRadius = -1;
230 bool exactPickFirst = true;
231
234
239 {
240 return {};
241 }
242 };
243
247 MRVIEWER_API ObjAndPick pickRenderObject( std::span<VisualObject* const> objects, const PickRenderObjectParams& params = PickRenderObjectParams::defaults() ) const;
249 MRVIEWER_API ConstObjAndPick pickRenderObjectConst( std::span<const VisualObject* const> objects, const PickRenderObjectParams& params = PickRenderObjectParams::defaults() ) const;
250
258 MRVIEWER_API ObjAndPick pick_render_object() const;
259 [[deprecated("Use `pickRenderObject()`")]]
260 MRVIEWER_API ObjAndPick pick_render_object( uint16_t pickRadius ) const;
266 [[deprecated("Use `pickRenderObject( objects } )`")]]
267 MRVIEWER_API ObjAndPick pick_render_object( const std::vector<VisualObject*>& objects ) const;
272 [[deprecated("Use `pickRenderObject( ... )`")]]
273 MRVIEWER_API ObjAndPick pick_render_object( const std::vector<VisualObject*>& objects, uint16_t pickRadius, bool exactPickFirst = true ) const;
275 [[deprecated("Use `pickRenderObject( { .exactPickFirst = ... } )`")]]
276 MRVIEWER_API ObjAndPick pick_render_object( bool exactPickFirst ) const;
282 [[deprecated("Use `pickRenderObject( { .point = ... } )`")]]
283 MRVIEWER_API ObjAndPick pick_render_object( const Vector2f& viewportPoint ) const;
288 [[deprecated("Use `multiPickObjects( objects, { .point = ... } )`")]]
289 MRVIEWER_API ObjAndPick pick_render_object( const std::vector<VisualObject*>& objects, const Vector2f& viewportPoint ) const;
290
294 MRVIEWER_API std::vector<ObjAndPick> multiPickObjects( std::span<VisualObject* const> objects, const std::vector<Vector2f>& viewportPoints, const BaseRenderParams* overrideRenderParams = nullptr ) const;
295
300 MRVIEWER_API std::vector<std::shared_ptr<VisualObject>> findObjectsInRect( const Box2i& rect,
301 int maxRenderResolutionSide = 512 ) const;
302
307 MRVIEWER_API std::unordered_map<std::shared_ptr<ObjectMesh>, FaceBitSet> findVisibleFaces( const BitSet& includePixBs,
308 int maxRenderResolutionSide = 512 ) const;
309
311 [[nodiscard]] MRVIEWER_API FaceBitSet findCameraLookingFaces( const Mesh& mesh, const AffineXf3f& meshToWorld ) const;
312
313
319 [[deprecated("Use `pickRenderObject()`.")]]
325 [[deprecated("Use `pickRenderObject( objects )`.")]]
326 MRVIEWER_API ConstObjAndPick const_pick_render_object( const std::vector<const VisualObject*>& objects ) const;
329 MRVIEWER_API std::vector<ConstObjAndPick> constMultiPickObjects( const std::vector<const VisualObject*>& objects, const std::vector<Vector2f>& viewportPoints ) const;
330
334 MRVIEWER_API void transformView( const AffineXf3f & xf );
335
337 bool getRedrawFlag() const { return needRedraw_ || cameraAnimation_; }
338 void resetRedrawFlag() { needRedraw_ = false; }
339
342
344 {
345 Color backgroundColor = Color( Vector3f{0.3f, 0.3f, 0.5f} );
346 Vector3f lightPosition{0.0f, 0.3f, 0.0f};
347
350 float cameraZoom{1.0f};
351 float cameraViewAngle{45.0f};
352 float cameraDnear{1.0f};
353 float cameraDfar{100.0f};
354
355 bool depthTest{true};
356 bool orthographic{true};
357
359 {
362 } globalBasisScaleMode{ GlobalBasisScaleMode::Auto };
363
365 float objectScale{1.0f};
366
368
369 std::string label;
370
371 Plane3f clippingPlane{Vector3f::plusX(), 0.0f};
372
379
382 std::optional<Vector3f> staticRotationPivot;
383
386 bool compensateRotation{ true };
387
389 bool selectable{true};
390
391 bool operator==( const Viewport::Parameters& other ) const = default;
392 };
393
410
413 MRVIEWER_API void setRotation( bool state );
414
416 MRVIEWER_API const ViewportRectangle& getViewportRect() const;
417
419 MRVIEWER_API float getPixelSize() const;
420
423 MRVIEWER_API float getPixelSizeAtPoint( const Vector3f& worldPoint ) const;
424
427 MRVIEWER_API void setViewportRect( const ViewportRectangle& rect );
428
429private:
431 Matrix4f viewM_;
432 Matrix4f projM_;
433
434public:
436 [[nodiscard]] MRVIEWER_API AffineXf3f getUnscaledViewXf() const;
437
439 [[nodiscard]] AffineXf3f getViewXf() const { return AffineXf3f( viewM_ ); }
440
442 [[nodiscard]] Vector3f getUpDirection() const { return Vector3f( viewM_.y.x, viewM_.y.y, viewM_.y.z ).normalized(); }
443
445 [[nodiscard]] Vector3f getRightDirection() const { return Vector3f( viewM_.x.x, viewM_.x.y, viewM_.x.z ).normalized(); }
446
448 [[nodiscard]] Vector3f getBackwardDirection() const { return Vector3f( viewM_.z.x, viewM_.z.y, viewM_.z.z ).normalized(); }
449
453 MRVIEWER_API Line3f unprojectPixelRay( const Vector2f& viewportPoint ) const;
454
456 MRVIEWER_API Vector3f worldToCameraSpace( const Vector3f& p ) const;
457 MRVIEWER_API std::vector<Vector3f> worldToCameraSpace( const std::vector<Vector3f>& p ) const;
458
462 MRVIEWER_API Vector3f projectToClipSpace( const Vector3f& worldPoint ) const;
463 MRVIEWER_API std::vector<Vector3f> projectToClipSpace( const std::vector<Vector3f>& worldPoints ) const;
464 MRVIEWER_API Vector3f unprojectFromClipSpace( const Vector3f& clipPoint ) const;
465 MRVIEWER_API std::vector<Vector3f> unprojectFromClipSpace( const std::vector<Vector3f>& clipPoints ) const;
466
470 MRVIEWER_API Vector3f projectToViewportSpace( const Vector3f& worldPoint ) const;
471 MRVIEWER_API std::vector<Vector3f> projectToViewportSpace( const std::vector<Vector3f>& worldPoints ) const;
475 MRVIEWER_API Vector3f unprojectFromViewportSpace( const Vector3f& viewportPoint ) const;
476 MRVIEWER_API std::vector<Vector3f> unprojectFromViewportSpace( const std::vector<Vector3f>& viewportPoints ) const;
477
483 MRVIEWER_API Vector3f clipSpaceToViewportSpace( const Vector3f& p ) const;
484 MRVIEWER_API std::vector<Vector3f> clipSpaceToViewportSpace( const std::vector<Vector3f>& p ) const;
485 MRVIEWER_API Vector3f viewportSpaceToClipSpace( const Vector3f& p ) const;
486 MRVIEWER_API std::vector<Vector3f> viewportSpaceToClipSpace( const std::vector<Vector3f>& p ) const;
487
489 MRVIEWER_API void setupView();
495 void preDraw();
501 void postDraw() const;
502
506 MRVIEWER_API void fitData( float fill = 1.0f, bool snapView = true );
507
511 MRVIEWER_API void fitBox( const Box3f& newSceneBox, float fill = 1.0f, bool snapView = true );
512
519 [[nodiscard]] MRVIEWER_API Parameters calcFitDataParameters( const Parameters& camera, float fill = 1.0f, bool snapView = true ) const;
520
522 [[nodiscard]] MRVIEWER_API Parameters calcFitBoxParameters( const Parameters& camera, const Box3f& box, float fill = 1.0f, bool snapView = true ) const;
523
528
530 MRVIEWER_API void preciseFitBoxToScreenBorder( const FitBoxParams& params );
532 MRVIEWER_API void preciseFitDataToScreenBorder( const FitDataParams& params = {} );
533
536 [[nodiscard]] MRVIEWER_API Parameters calcPreciseFitBoxParameters( const Parameters& camera, const FitBoxParams& params, Box3f* sceneBox = nullptr ) const;
537
540 [[nodiscard]] MRVIEWER_API Parameters calcPreciseFitDataParameters( const Parameters& camera, const FitDataParams& params = {}, Box3f* sceneBox = nullptr ) const;
541
543 MRVIEWER_API float getRatio() const;
544
546 MRVIEWER_API bool allModelsInsideViewportRectangle() const;
547
548 MRVIEWER_API const Box3f& getSceneBox() const;
549
550 const Parameters& getParameters() const { return params_; }
551
553 MRVIEWER_API Vector3f getCameraPoint() const;
555 MRVIEWER_API void setCameraPoint( const Vector3f& cameraWorldPos );
556
557 MRVIEWER_API void setCameraTrackballAngle( const Quaternionf& rot );
558
559 MRVIEWER_API void setCameraTranslation( const Vector3f& translation );
560
561 MRVIEWER_API void setCameraViewAngle( float newViewAngle );
562
563 MRVIEWER_API void setCameraZoom( float zoom );
564
565 MRVIEWER_API void setOrthographic( bool orthographic );
566
567 MRVIEWER_API void setBackgroundColor( const Color& color );
568
570 MRVIEWER_API void setBackgroundTexture( std::optional<BackgroundTexture> texture );
571 [[nodiscard]] const std::optional<BackgroundTexture>& getBackgroundTexture() const { return backgroundTexture_; }
572
573 MRVIEWER_API void setClippingPlane( const Plane3f& plane );
574
575 MRVIEWER_API void setLabel( std::string s );
576
577 void setSelectable( bool on ) { params_.selectable = on; }
578
579 MRVIEWER_API void showAxes( bool on );
580 MRVIEWER_API void showClippingPlane( bool on );
581 MRVIEWER_API void showRotationCenter( bool on );
582 MRVIEWER_API void showGlobalBasis( bool on );
584
585 MRVIEWER_API void setParameters( const Viewport::Parameters& params );
586
597 MRVIEWER_API void animateCamera( const Parameters& target, float seconds, const Box3f& sceneBox = {} );
598
601 [[nodiscard]] const Parameters* getCameraAnimationTarget() const { return cameraAnimation_ ? &cameraAnimation_->target : nullptr; }
602
606 MRVIEWER_API void cameraLookAlong( const Vector3f& dir, const Vector3f& up );
607
610 MRVIEWER_API void cameraRotateAround( const Line3f& axis, float angle );
611
613 Vector3f getRotationPivot() const { return rotationPivot_; }
614
619 MRVIEWER_API void resetStaticRotationPivot( const std::optional<Vector3f>& pivot = std::nullopt );
620private:
624 void setRotationPivot_( const Vector3f& point ) { needRedraw_ |= rotationPivot_ != point; rotationPivot_ = point; }
626 void setupViewMatrix_();
628 AffineXf3f getViewXf_() const;
629
631 void setupProjMatrix_();
633 void setupAxesViewProjMatrix_();
634
638 Matrix4f getFullViewportMatrix() const { return projM_ * viewM_; }
639 Matrix4f getFullViewportInversedMatrix() const;
640
641 ViewportRectangle viewportRect_;
642
643 UniquePtr<ViewportGL> viewportGL_;
644
645 bool previewLinesDepthTest_ = false;
646 bool previewPointsDepthTest_ = false;
647
648 void draw_border() const;
649 void draw_rotation_center() const;
650 void draw_clipping_plane() const;
651 void drawGlobalBasis() const;
652
654 void initBaseAxes();
656 void drawAxesAndViewController() const;
657
660 Matrix4f axesViewMat_;
661 Matrix4f axesProjMat_;
662 Vector2f basisAxesPos_;
663 float basisAxesSize_;
664
666 int pixelXoffset_{ -100 };
667 int pixelYoffset_{ -128 };
668 int axisPixSize_{ 70 };
669
671 [[nodiscard]] Box3f calcSceneBox_() const;
672 void updateSceneBox_() { sceneBox_ = calcSceneBox_(); }
673 void rotateView_();
674
675 enum class Space
676 {
677 World,
678 CameraOrthographic,
679 CameraPerspective
680 };
681
686 Box3f calcBox_( const std::vector<std::shared_ptr<VisualObject>>& objs, Space space, const AffineXf3f& viewXf, bool selectedPrimitives = false ) const;
687
693 std::pair<float, bool> getZoomFOVtoScreen_( const Parameters& params, const std::function<Box3f()>& getBoxFn ) const;
697 Parameters preciseFitToScreenBorder_( Parameters params, const std::function<Box3f( Space space, const AffineXf3f& viewXf, bool globalBasis )>& getBoxFn,
698 const BaseFitParams& fitParams, Box3f* sceneBox ) const;
700 void applyPreciseFit_( const Parameters& params, const Box3f& sceneBox );
701
702 int rotationDepth_{ 0 };
703 Vector3f rotationPivot_;
704 Vector3f static_point_;
705 Vector2f static_viewport_point;
706 float distToSceneCenter_;
707
708 bool needRedraw_{false};
709
711 Box3f sceneBox_;
712
713 Parameters params_;
714
716 void updateCameraAnimation_();
717
718 struct CameraAnimation
719 {
722 double startTime = 0;
723 double stepTime = 0;
724 float seconds = 0;
725 float startSpeed = 0;
726 };
727 std::optional<CameraAnimation> cameraAnimation_;
728
729 std::optional<BackgroundTexture> backgroundTexture_;
730 bool backgroundTextureChanged_{ false };
731};
732
733}
Definition MRBitSet.h:71
named object in the data model
Definition MRObject.h:61
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:42
Visual Object.
Definition MRVisualObject.h:116
auto width(const Box< V > &box)
returns size along x axis
Definition MRBox.h:386
auto height(const Box< V > &box)
returns size along y axis
Definition MRBox.h:393
ObjAndPick pick_render_object(const Vector2f &viewportPoint) const
RotationCenterMode
Definition MRViewport.h:374
AffineXf3f getUnscaledViewXf() const
returns orthonormal matrix with translation
int pickRadius
Definition MRViewport.h:226
MR::FitMode FitMode
Definition MRViewport.h:524
std::vector< Vector3f > unprojectFromClipSpace(const std::vector< Vector3f > &clipPoints) const
PickRenderObjectPredicate predicate
Predicate to additionally filter objects that should be treated as pickable.
Definition MRViewport.h:222
bool operator==(const Allocator< T > &, const Allocator< U > &) noexcept
Definition MRAllocator.h:95
Vector4f c
Definition MRViewport.h:167
Vector4f a
Definition MRViewport.h:34
bool exactPickFirst
Definition MRViewport.h:230
Vector3f unprojectFromViewportSpace(const Vector3f &viewportPoint) const
void preciseFitDataToScreenBorder(const FitDataParams &params={})
fit view and proj matrices to match the screen size with given objects
bool drawOrthoFixedPos(const VisualObject &obj, const AffineXf3f &xf, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
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
void setCameraTranslation(const Vector3f &translation)
static PickRenderObjectParams defaults()
Definition MRViewport.h:238
void clearFramebuffers()
----------------— Drawing functions
float getPixelSizeAtPoint(const Vector3f &worldPoint) const
MR::BaseFitParams BaseFitParams
Definition MRViewport.h:525
float getPixelSize() const
Finds length between near pixels on zNear plane. Only good in the orthographic projection.
void shut()
Shutdown.
Vector3f projectToClipSpace(const Vector3f &worldPoint) const
std::vector< Vector3f > projectToViewportSpace(const std::vector< Vector3f > &worldPoints) const
Vector3f getRightDirection() const
assume that viewM is orthogonal and inverse=transpose
Definition MRViewport.h:445
float cameraViewAngle
Definition MRViewport.h:351
const Vector2f & getAxesPosition() const
returns position of basis axes in viewport space
Vector3f cameraTranslation
Definition MRViewport.h:349
void fitBox(const Box3f &newSceneBox, float fill=1.0f, bool snapView=true)
Color backgroundColor
Definition MRViewport.h:345
double startTime
animated fields as the last step set them, to detect camera changes by somebody else
Definition MRViewport.h:722
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)....
void setBackgroundTexture(std::optional< BackgroundTexture > texture)
sets the texture drawn over the background color, std::nullopt removes it
FitMode
Fit mode ( types of objects for which the fit is applied )
Definition MRFitData.h:14
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...
void setAxesPos(const int pixelXoffset=-100, const int pixelYoffset=-100)
std::function< bool(const VisualObject *, ViewportMask)> PickRenderObjectPredicate
Predicate to additionally filter objects that should be treated as pickable.
Definition MRViewport.h:214
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:59
Parameters current
Definition MRViewport.h:721
MeshTexture texture
image (its first row is the bottom one) with its filter and wrap types; WrapType::Clamp draws nothing...
Definition MRViewport.h:397
std::vector< Vector3f > worldToCameraSpace(const std::vector< Vector3f > &p) const
void rotationCenterMode(Parameters::RotationCenterMode mode)
bool orthographic
Definition MRViewport.h:356
Vector4f b
Definition MRViewport.h:34
void setLabel(std::string s)
Vector3f getRotationPivot() const
returns current rotation pivot in world space, which should appear static on a screen during rotation...
Definition MRViewport.h:613
bool getRedrawFlag() const
returns true if the viewport has to be redrawn; it stays true while the camera is animated
Definition MRViewport.h:337
BaseRenderParams getBaseRenderParams(const Matrix4f &projM) const
Prepares base rendering parameters for this viewport with custom projection matrix.
Definition MRViewport.h:178
std::vector< ConstObjAndPick > constMultiPickObjects(const std::vector< const VisualObject * > &objects, const std::vector< Vector2f > &viewportPoints) const
void setSelectable(bool on)
Definition MRViewport.h:577
void showRotationCenter(bool on)
void showClippingPlane(bool on)
std::unordered_map< std::shared_ptr< ObjectMesh >, FaceBitSet > findVisibleFaces(const BitSet &includePixBs, int maxRenderResolutionSide=512) const
void drawTris(const std::vector< Triangle3f > &tris, const std::vector< TriCornerColors > &colors, const ModelRenderParams &params, bool depthTest=true)
Draw triangles immediately (flat shaded)
void setOrthographic(bool orthographic)
void drawLines(const std::vector< LineSegm3f > &lines, const std::vector< SegmEndColors > &colors, float width=1, bool depthTest=true)
Definition MRViewport.h:157
void resetRedrawFlag()
Definition MRViewport.h:338
Vector2f startPos
position of the image's upper-left corner in viewport space, in framebuffer pixels: (0,...
Definition MRViewport.h:398
Parameters calcPreciseFitBoxParameters(const Parameters &camera, const FitBoxParams &params, Box3f *sceneBox=nullptr) const
Vector4f b
Definition MRViewport.h:167
float cameraDfar
Definition MRViewport.h:353
StretchMode
how the image size follows the viewport size; all modes except None ignore startPos and scaling
Definition MRViewport.h:403
MR::ViewportRectangle ViewportRectangle
Definition MRViewport.h:78
MR::FitDataParams FitDataParams
Definition MRViewport.h:526
Vector4f a
Definition MRViewport.h:167
std::vector< Vector3f > clipSpaceToViewportSpace(const std::vector< Vector3f > &p) const
Color borderColor
Definition MRViewport.h:367
ObjAndPick pickRenderObject(const PickRenderObjectParams &params=PickRenderObjectParams::defaults()) const
const Parameters * getCameraAnimationTarget() const
Definition MRViewport.h:601
void animateCamera(const Parameters &target, float seconds, const Box3f &sceneBox={})
Line3f unprojectPixelRay(const Vector2f &viewportPoint) const
assume that viewM is orthogonal and inverse=transpose
Parameters calcFitDataParameters(const Parameters &camera, float fill=1.0f, bool snapView=true) const
float startSpeed
Definition MRViewport.h:725
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:196
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:186
void setCameraTrackballAngle(const Quaternionf &rot)
AffineXf3f getViewXf() const
converts directly from the view matrix
Definition MRViewport.h:439
void preDraw()
float seconds
when the last step set the camera
Definition MRViewport.h:724
bool depthTest
Definition MRViewport.h:152
Plane3f
Definition MRMeshFwd.h:391
void drawTris(const std::vector< Triangle3f > &tris, const std::vector< TriCornerColors > &colors, const Matrix4f &modelM={}, bool depthTest=true)
bool depthTest
Definition MRViewport.h:355
BaseRenderParams getBaseRenderParamsOrthoFixedPos() const
Prepares base rendering parameters for this viewport with orthographic proj matrix and rotation compo...
Definition MRViewport.h:182
std::pair< std::shared_ptr< MR::VisualObject >, MR::PointOnObject > ObjAndPick
Definition MRViewerFwd.h:86
RenderModelPassMask
Various passes of the 3D rendering.
Definition MRRenderModelParameters.h:40
void drawPoints(std::span< const Vector3f > points, std::span< const Vector4f > colors, float width=1, bool depthTest=true)
Definition MRViewport.h:162
Vector3f unprojectFromClipSpace(const Vector3f &clipPoint) const
Vector3f worldToCameraSpace(const Vector3f &p) const
convert point(s) to camera space by applying view matrix
std::vector< Vector3f > viewportSpaceToClipSpace(const std::vector< Vector3f > &p) const
bool draw(const VisualObject &obj, const AffineXf3f &xf, const Matrix4f &projM, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
Plane3f clippingPlane
Definition MRViewport.h:371
const std::optional< BackgroundTexture > & getBackgroundTexture() const
Definition MRViewport.h:571
Viewport(Viewport &&) noexcept
std::string label
Definition MRViewport.h:369
void resetStaticRotationPivot(const std::optional< Vector3f > &pivot=std::nullopt)
void setAxesSize(const int axisPixSize=80)
bool allModelsInsideViewportRectangle() const
returns true if all models are fully projected inside the viewport rectangle
std::pair< std::shared_ptr< const MR::VisualObject >, MR::PointOnObject > ConstObjAndPick
Definition MRViewerFwd.h:87
Vector3f getBackwardDirection() const
assume that viewM is orthogonal and inverse=transpose
Definition MRViewport.h:448
Viewport clone() const
Definition MRViewport.h:91
void cameraLookAlong(const Vector3f &dir, const Vector3f &up)
bool draw(const VisualObject &obj, const AffineXf3f &xf, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
float cameraZoom
Definition MRViewport.h:350
Vector3f getCameraPoint() const
returns camera world location for the current view
ConstObjAndPick const_pick_render_object() const
Quaternionf cameraTrackballAngle
x y z - position, w - factor
Definition MRViewport.h:348
double stepTime
seconds of a steady clock
Definition MRViewport.h:723
Vector3f lightPosition
Definition MRViewport.h:346
Vector4< T > toVec4(const ViewportRectangle &rect)
Definition MRViewport.h:68
Vector3f projectToViewportSpace(const Vector3f &worldPoint) const
bool draw(const VisualObject &obj, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, const TransparencyMode &transparentMode={}) const
const Parameters & getParameters() const
Definition MRViewport.h:550
void drawLines(const std::vector< LineSegm3f > &lines, const std::vector< SegmEndColors > &colors, const LinePointImmediateRenderParams &params)
Draw lines immediately.
void setParameters(const Viewport::Parameters &params)
ObjAndPick pick_render_object() const
enum MR::Viewport::Parameters::GlobalBasisScaleMode Auto
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.
const Box3f & getSceneBox() const
Vector2f scaling
size of one image pixel in framebuffer pixels
Definition MRViewport.h:399
DepthFunction
Definition MRIRenderObject.h:21
ObjAndPick pick_render_object(uint16_t pickRadius) const
static Viewport & get(ViewportId viewportId={})
void setupView()
updates view and projection matrices due to camera parameters (called each frame)
float getAxesSize() const
void preciseFitBoxToScreenBorder(const FitBoxParams &params)
fit view and proj matrices to match the screen size with given box
ObjAndPick pick_render_object(const std::vector< VisualObject * > &objects, const Vector2f &viewportPoint) const
void showAxes(bool on)
Quaternionf
Definition MRMeshFwd.h:459
bool selectable
this flag allows viewport to be selected by user
Definition MRViewport.h:389
GlobalBasisScaleMode
Definition MRViewport.h:359
Vector3f viewportSpaceToClipSpace(const Vector3f &p) const
enum MR::Viewport::Parameters::RotationCenterMode Dynamic
std::vector< Vector3f > projectToClipSpace(const std::vector< Vector3f > &worldPoints) const
std::optional< Vector3f > staticRotationPivot
Definition MRViewport.h:382
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).
std::vector< ObjAndPick > multiPickObjects(std::span< VisualObject *const > objects, const std::vector< Vector2f > &viewportPoints, const BaseRenderParams *overrideRenderParams=nullptr) const
bool operator==(const Viewport::Parameters &other) const =default
Parameters start
Definition MRViewport.h:720
void setCameraZoom(float zoom)
void setRotation(bool state)
Parameters calcFitBoxParameters(const Parameters &camera, const Box3f &box, float fill=1.0f, bool snapView=true) const
returns the parameters that fitBox would set if this viewport had given camera parameters,...
const Matrix4f & getAxesProjectionMatrix() const
returns projection matrix that is used for basis axes and view controller rendering
Definition MRViewport.h:113
MR::FitBoxParams FitBoxParams
Definition MRViewport.h:527
std::vector< Vector3f > points
Definition MRViewport.h:45
Vector3f clipSpaceToViewportSpace(const Vector3f &p) const
float cameraDnear
Definition MRViewport.h:352
void postDraw() const
void setBackgroundColor(const Color &color)
BaseRenderParams getBaseRenderParams() const
Prepares base rendering parameters for this viewport.
Definition MRViewport.h:175
std::vector< std::shared_ptr< VisualObject > > findObjectsInRect(const Box2i &rect, int maxRenderResolutionSide=512) const
bool compensateRotation
Definition MRViewport.h:386
ObjAndPick pick_render_object(const std::vector< VisualObject * > &objects) const
NOTE! If your list is hardcoded, use .objects = std::array{ a, b, c }.
const ViewportRectangle & getViewportRect() const
Note, Y is up for this box.
void cameraRotateAround(const Line3f &axis, float angle)
void setCameraPoint(const Vector3f &cameraWorldPos)
sets camera world location for the current view
void setCameraViewAngle(float newViewAngle)
void fitData(float fill=1.0f, bool snapView=true)
void setClippingPlane(const Plane3f &plane)
void transformView(const AffineXf3f &xf)
void showGlobalBasis(bool on)
const BaseRenderParams * baseRenderParams
if not nullptr it can override render params for picker
Definition MRViewport.h:233
Box2f ViewportRectangle
Viewport size.
Definition MRViewerFwd.h:17
ObjAndPick pick_render_object(const std::vector< VisualObject * > &objects, uint16_t pickRadius, bool exactPickFirst=true) const
std::vector< Vector3f > unprojectFromViewportSpace(const std::vector< Vector3f > &viewportPoints) const
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 ...
ConstObjAndPick const_pick_render_object(const std::vector< const VisualObject * > &objects) const
float width
Definition MRViewport.h:151
void init()
Initialization.
std::vector< Vector4f > colors
Definition MRViewport.h:46
void drawPoints(std::span< const Vector3f > points, std::span< const Vector4f > colors, const LinePointImmediateRenderParams &params)
Draw points immediately.
enum MR::Viewport::BackgroundTexture::StretchMode stretchMode
Parameters calcPreciseFitDataParameters(const Parameters &camera, const FitDataParams &params={}, Box3f *sceneBox=nullptr) const
float getRatio() const
returns viewport width/height ratio
ViewportId id
Unique identifier.
Definition MRViewport.h:341
std::optional< Vector2f > point
If specified, this is the target screen point. Otherwise use the mouse pos in viewport coordinates.
Definition MRViewport.h:219
Parameters target
Definition MRViewport.h:720
float objectScale
Caches the two-norm between the min/max point of the bounding box.
Definition MRViewport.h:365
void setViewportRect(const ViewportRectangle &rect)
Vector3f getUpDirection() const
returns unit vector in world space corresponding to up-direction in camera space
Definition MRViewport.h:442
@ DynamicStatic
scene is always rotated around its center or another manually set point
Definition MRViewport.h:376
@ Static
Definition MRViewport.h:375
@ Dynamic
scene is rotated around picked point on object, or around center, if miss pick
Definition MRViewport.h:377
@ position
Definition MRFeatureObject.h:23
@ other
Angle, normally float. Measure in radians.
Definition MRFeatureObject.h:27
@ angle
Direction, normally Vector3f.
Definition MRFeatureObject.h:26
@ Fit
the whole image is visible in the viewport center, the aspect ratio is kept
Definition MRViewport.h:406
@ None
placed by startPos and scaling
Definition MRViewport.h:404
@ Fill
covers the viewport, centered and cropped, the aspect ratio is kept
Definition MRViewport.h:407
@ Stretch
covers the viewport exactly, the aspect ratio is not kept
Definition MRViewport.h:405
@ All
Definition MRRenderModelParameters.h:46
@ Default
Definition MRIRenderObject.h:30
@ Fixed
uses current scene size
Definition MRViewport.h:361
@ seconds
Definition MRUnitInfo.h:59
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
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 MRMeshTexture.h:13
Definition MRMesh.h:24
Mesh rendering parameters for primary rendering (as opposed to the picker).
Definition MRIRenderObject.h:54
colors of segment ends
Definition MRViewport.h:33
struct to determine transparent rendering mode
Definition MRRenderModelParameters.h:13
Definition MRVector4.h:26
stores points and corresponding colors (sizes of vectors should be the same)
Definition MRViewport.h:44
texture drawn over the background color and below the scene
Definition MRViewport.h:396
Rendering parameters for immediate drawing of lines and points.
Definition MRViewport.h:150
Definition MRViewport.h:344
Point picking parameters.
Definition MRViewport.h:217
Definition MRViewport.h:166