17#include <unordered_map>
27inline ImVec2
position(
const ViewportRectangle& rect )
29 return { rect.min.x, rect.min.y };
32inline ImVec2
size(
const ViewportRectangle& rect )
77 MRVIEWER_API
void setAxesPos( const
int pixelXoffset = -100, const
int pixelYoffset = -100 );
99 const TransparencyMode& transparentMode = {},
int* numDraws = nullptr )
const;
113 MRVIEWER_API
bool draw(
const VisualObject& obj,
const AffineXf3f& xf,
const Matrix4f & projM,
130 void drawLines(
const std::vector<LineSegm3f>& lines,
const std::vector<SegmEndColors>& colors,
float width = 1,
bool depthTest =
true )
135 void drawPoints(
const std::vector<Vector3f>& points,
const std::vector<Vector4f>& colors,
float width = 1,
bool depthTest =
true )
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 );
152 {
return { viewM_, projM,
id,
toVec4<int>( viewportRect_ ) }; }
156 {
return { axesViewMat_, axesProjMat_,
id,
toVec4<int>( viewportRect_ ) }; }
160 const Matrix4f & modelM,
170 const Matrix4f & modelM,
232 [[deprecated(
"Use `pickRenderObject()`")]]
239 [[deprecated(
"Use `pickRenderObject( objects } )`")]]
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 = ... } )`")]]
255 [[deprecated(
"Use `pickRenderObject( { .point = ... } )`")]]
261 [[deprecated(
"Use `multiPickObjects( objects, { .point = ... } )`")]]
262 MRVIEWER_API ObjAndPick
pick_render_object(
const std::vector<VisualObject*>& objects,
const Vector2f& viewportPoint )
const;
267 MRVIEWER_API std::vector<ObjAndPick>
multiPickObjects( std::span<VisualObject* const> objects,
const std::vector<Vector2f>& viewportPoints,
const BaseRenderParams* overrideRenderParams =
nullptr )
const;
274 int maxRenderResolutionSide = 512 )
const;
281 int maxRenderResolutionSide = 512 )
const;
292 [[deprecated(
"Use `pickRenderObject()`.")]]
298 [[deprecated(
"Use `pickRenderObject( objects )`.")]]
302 MRVIEWER_API std::vector<ConstObjAndPick>
constMultiPickObjects(
const std::vector<const VisualObject*>& objects,
const std::vector<Vector2f>& viewportPoints )
const;
393 [[nodiscard]] AffineXf3f
getViewXf()
const {
return AffineXf3f( viewM_ ); }
396 [[nodiscard]] Vector3f
getUpDirection()
const {
return Vector3f( viewM_.y.x, viewM_.y.y, viewM_.y.z ).normalized(); }
399 [[nodiscard]] Vector3f
getRightDirection()
const {
return Vector3f( viewM_.x.x, viewM_.x.y, viewM_.x.z ).normalized(); }
402 [[nodiscard]] Vector3f
getBackwardDirection()
const {
return Vector3f( viewM_.z.x, viewM_.z.y, viewM_.z.z ).normalized(); }
417 MRVIEWER_API std::vector<Vector3f>
projectToClipSpace(
const std::vector<Vector3f>& worldPoints )
const;
460 MRVIEWER_API
void fitData(
float fill = 1.0f,
bool snapView =
true );
465 MRVIEWER_API
void fitBox(
const Box3f& newSceneBox,
float fill = 1.0f,
bool snapView =
true );
538 void setRotationPivot_(
const Vector3f& point ) { rotationPivot_ = point; }
540 void setupViewMatrix_();
542 AffineXf3f getViewXf_()
const;
545 void setupProjMatrix_();
547 void setupAxesViewProjMatrix_();
552 Matrix4f getFullViewportMatrix()
const {
return projM_ * viewM_; }
553 Matrix4f getFullViewportInversedMatrix()
const;
557 ViewportGL viewportGL_;
559 bool previewLinesDepthTest_ =
false;
560 bool previewPointsDepthTest_ =
false;
562 void draw_border()
const;
563 void draw_rotation_center()
const;
564 void draw_clipping_plane()
const;
565 void drawGlobalBasis()
const;
570 void drawAxesAndViewController()
const;
574 Matrix4f axesViewMat_;
575 Matrix4f axesProjMat_;
576 Vector2f basisAxesPos_;
577 float basisAxesSize_;
580 int pixelXoffset_{ -100 };
581 int pixelYoffset_{ -128 };
582 int axisPixSize_{ 70 };
584 void updateSceneBox_();
598 Box3f calcBox_(
const std::vector<std::shared_ptr<VisualObject>>& objs, Space space,
bool selectedPrimitives =
false )
const;
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 );
614 bool rotation_{
false };
615 Vector3f rotationPivot_;
616 Vector3f static_point_;
617 Vector2f static_viewport_point;
618 float distToSceneCenter_;
620 bool needRedraw_{
false};
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
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 ¶ms=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 ¶ms=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 ¶ms={})
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 ¶ms)
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
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 ¶ms, 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 ¶ms)
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 ¶ms=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 ¶ms)
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
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 ¶ms)
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 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.
@ Fixed
uses current scene size
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRFitData.h:23
Common rendering parameters for meshes and UI.
Definition MRIRenderObject.h:36
Definition MRFitData.h:45
Definition MRFitData.h:32
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
Definition MRViewport.h:316
Point picking parameters.
Definition MRViewport.h:190
Definition MRViewport.h:139