17#include <unordered_map>
29 return { rect.min.x, rect.min.y };
77 MRVIEWER_API
void setAxesPos( const
int pixelXoffset = -100, const
int pixelYoffset = -100 );
100 MRVIEWER_API
bool draw( const
VisualObject& obj, const AffineXf3f& xf, const Matrix4f & projM,
107 bool depthTest{
true };
112 void drawLines(
const std::vector<LineSegm3f>& lines,
const std::vector<SegmEndColors>& colors,
float width = 1,
bool depthTest =
true )
117 void drawPoints(
const std::vector<Vector3f>& points,
const std::vector<Vector4f>& colors,
float width = 1,
bool depthTest =
true )
126 MRVIEWER_API
void drawTris(
const std::vector<Triangle3f>& tris,
const std::vector<TriCornerColors>& colors,
const ModelRenderParams& params,
bool depthTest =
true );
127 MRVIEWER_API
void drawTris(
const std::vector<Triangle3f>& tris,
const std::vector<TriCornerColors>& colors,
const Matrix4f& modelM = {},
bool depthTest = true );
134 {
return { viewM_, projM,
id,
toVec4<int>( viewportRect_ ) }; }
138 const Matrix4f & modelM,
142 bool allowAlphaSort =
false
151 bool allowAlphaSort =
false
197 [[deprecated(
"Use `pickRenderObject()`")]]
204 [[deprecated(
"Use `pickRenderObject( objects } )`")]]
210 [[deprecated(
"Use `pickRenderObject( ... )`")]]
213 [[deprecated(
"Use `pickRenderObject( { .exactPickFirst = ... } )`")]]
220 [[deprecated(
"Use `pickRenderObject( { .point = ... } )`")]]
226 [[deprecated(
"Use `multiPickObjects( objects, { .point = ... } )`")]]
232 MRVIEWER_API std::vector<ObjAndPick>
multiPickObjects( std::span<VisualObject* const> objects,
const std::vector<Vector2f>& viewportPoints )
const;
239 int maxRenderResolutionSide = 512 )
const;
246 int maxRenderResolutionSide = 512 )
const;
253 [[deprecated(
"Use `pickRenderObject()`.")]]
259 [[deprecated(
"Use `pickRenderObject( objects )`.")]]
263 MRVIEWER_API std::vector<ConstObjAndPick>
constMultiPickObjects(
const std::vector<const VisualObject*>& objects,
const std::vector<Vector2f>& viewportPoints )
const;
345 [[nodiscard]] AffineXf3f
getViewXf()
const {
return AffineXf3f( viewM_ ); }
348 [[nodiscard]] Vector3f
getUpDirection()
const {
return Vector3f( viewM_.y.x, viewM_.y.y, viewM_.y.z ).normalized(); }
351 [[nodiscard]] Vector3f
getRightDirection()
const {
return Vector3f( viewM_.x.x, viewM_.x.y, viewM_.x.z ).normalized(); }
354 [[nodiscard]] Vector3f
getBackwardDirection()
const {
return Vector3f( viewM_.z.x, viewM_.z.y, viewM_.z.z ).normalized(); }
369 MRVIEWER_API std::vector<Vector3f>
projectToClipSpace(
const std::vector<Vector3f>& worldPoints )
const;
412 MRVIEWER_API
void fitData(
float fill = 1.0f,
bool snapView =
true );
417 MRVIEWER_API
void fitBox(
const Box3f& newSceneBox,
float fill = 1.0f,
bool snapView =
true );
484 void setupViewMatrix_();
486 AffineXf3f getViewXf_()
const;
489 void setupProjMatrix_();
491 void setupStaticProjMatrix_();
496 Matrix4f getFullViewportMatrix()
const {
return projM_ * viewM_; }
497 Matrix4f getFullViewportInversedMatrix()
const;
503 bool previewLinesDepthTest_ =
false;
504 bool previewPointsDepthTest_ =
false;
506 void draw_border()
const;
507 void draw_rotation_center()
const;
508 void draw_clipping_plane()
const;
509 void draw_global_basis()
const;
514 void drawAxes()
const;
517 Matrix4f staticProj_;
518 Vector3f relPoseBase;
519 Vector3f relPoseSide;
522 int pixelXoffset_{ -100 };
523 int pixelYoffset_{ -100 };
524 int axisPixSize_{ 70 };
527 void setRotationPivot_(
const Vector3f& point );
528 void updateSceneBox_();
542 Box3f calcBox_(
const std::vector<std::shared_ptr<VisualObject>>& objs, Space space,
bool selectedPrimitives =
false )
const;
551 std::pair<float, bool> getZoomFOVtoScreen_( std::function<Box3f()> getBoxFn, Vector3f* cameraShift =
nullptr )
const;
556 void preciseFitToScreenBorder_( std::function<Box3f(
bool zoomFOV,
bool globalBasis )> getBoxFn,
const BaseFitParams& params );
558 bool rotation_{
false };
559 Vector3f rotationPivot_;
560 Vector3f static_point_;
561 Vector2f static_viewport_point;
562 float distToSceneCenter_;
564 bool needRedraw_{
false};
std::pair< std::shared_ptr< const MR::VisualObject >, MR::PointOnObject > ConstObjAndPick
Definition MRViewport.h:22
std::pair< std::shared_ptr< MR::VisualObject >, MR::PointOnObject > ObjAndPick
Definition MRViewport.h:21
container of bits
Definition MRMesh/MRBitSet.h:27
Definition MRViewportGL.h:53
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:38
Definition MRViewport.h:49
MRVIEWER_API Vector3f projectToClipSpace(const Vector3f &worldPoint) const
MRVIEWER_API void showRotationCenter(bool on)
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)
MRVIEWER_API ObjAndPick pick_render_object(const std::vector< VisualObject * > &objects, uint16_t pickRadius, bool exactPickFirst=true) const
MR::BaseFitParams BaseFitParams
Definition MRViewport.h:420
MRVIEWER_API ObjAndPick pick_render_object(const std::vector< VisualObject * > &objects, const Vector2f &viewportPoint) const
Vector3f getRightDirection() const
returns unit vector in world space corresponding to right-direction in camera space
Definition MRViewport.h:351
ModelRenderParams getModelRenderParams(const Matrix4f &modelM, Matrix4f *normM, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, bool allowAlphaSort=false) const
Prepares rendering parameters to draw a model with given transformation in this viewport.
Definition MRViewport.h:137
MRVIEWER_API std::vector< Vector3f > unprojectFromViewportSpace(const std::vector< Vector3f > &viewportPoints) const
MRVIEWER_API void cameraLookAlong(const Vector3f &dir, const Vector3f &up)
MRVIEWER_API Vector3f unprojectFromClipSpace(const Vector3f &clipPoint) const
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
MRVIEWER_API void showGlobalBasis(bool on)
std::function< bool(const VisualObject *, ViewportMask)> PickRenderObjectPredicate
Definition MRViewport.h:155
MRVIEWER_API void cameraRotateAround(const Line3f &axis, float angle)
MRVIEWER_API ModelRenderParams getModelRenderParams(const Matrix4f &modelM, const Matrix4f &projM, Matrix4f *normM, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, bool allowAlphaSort=false) const
Prepares rendering parameters to draw a model with given transformation in this viewport with custom ...
MRVIEWER_API void setCameraTranslation(const Vector3f &translation)
MRVIEWER_API ObjAndPick pickRenderObject(const PickRenderObjectParams ¶ms=PickRenderObjectParams::defaults()) const
bool getRedrawFlag() const
Definition MRViewport.h:270
BaseRenderParams getBaseRenderParams(const Matrix4f &projM) const
Prepares base rendering parameters for this viewport with custom projection matrix.
Definition MRViewport.h:133
MRVIEWER_API float getRatio() const
void setSelectable(bool on)
Definition MRViewport.h:460
MRVIEWER_API float getPixelSize() const
MRVIEWER_API ConstObjAndPick const_pick_render_object(const std::vector< const VisualObject * > &objects) const
MRVIEWER_API Vector3f unprojectFromViewportSpace(const Vector3f &viewportPoint) const
void drawLines(const std::vector< LineSegm3f > &lines, const std::vector< SegmEndColors > &colors, float width=1, bool depthTest=true)
Definition MRViewport.h:112
MRVIEWER_API float getPixelSizeAtPoint(const Vector3f &worldPoint) const
void resetRedrawFlag()
Definition MRViewport.h:271
MRVIEWER_API void preciseFitDataToScreenBorder(const FitDataParams ¶ms={})
MRVIEWER_API Vector3f viewportSpaceToClipSpace(const Vector3f &p) const
MR::ViewportRectangle ViewportRectangle
Definition MRViewport.h:51
MRVIEWER_API void setRotation(bool state)
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)
AffineXf3f getViewXf() const
converts directly from the view matrix
Definition MRViewport.h:345
MRVIEWER_API void showClippingPlane(bool on)
MRVIEWER_API const ViewportRectangle & getViewportRect() const
MRVIEWER_API void fitBox(const Box3f &newSceneBox, float fill=1.0f, bool snapView=true)
MRVIEWER_API void showAxes(bool on)
MRVIEWER_API std::vector< Vector3f > worldToCameraSpace(const std::vector< Vector3f > &p) const
MRVIEWER_API Vector3f getCameraPoint() const
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 setCameraTrackballAngle(const Quaternionf &rot)
MRVIEWER_API ObjAndPick pick_render_object(const std::vector< VisualObject * > &objects) const
Vector3f getBackwardDirection() const
returns unit vector in world space corresponding to direction toward camera in camera space
Definition MRViewport.h:354
MRVIEWER_API Line3f unprojectPixelRay(const Vector2f &viewportPoint) const
MRVIEWER_API std::vector< Vector3f > unprojectFromClipSpace(const std::vector< Vector3f > &clipPoints) const
Viewport clone() const
Definition MRViewport.h:64
MRVIEWER_API void setLabel(std::string s)
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:437
MRVIEWER_API std::vector< Vector3f > viewportSpaceToClipSpace(const std::vector< Vector3f > &p) const
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 drawPoints(const std::vector< Vector3f > &points, const std::vector< Vector4f > &colors, const LinePointImmediateRenderParams ¶ms)
Draw points immediately.
MRVIEWER_API const Box3f & getSceneBox() const
static MRVIEWER_API Viewport & get(ViewportId viewportId={})
MRVIEWER_API std::vector< ObjAndPick > multiPickObjects(std::span< VisualObject *const > objects, const std::vector< Vector2f > &viewportPoints) const
MRVIEWER_API ObjAndPick pickRenderObject(std::span< VisualObject *const > objects, const PickRenderObjectParams ¶ms=PickRenderObjectParams::defaults()) const
MRVIEWER_API void setViewportRect(const ViewportRectangle &rect)
Viewport(Viewport &&) noexcept=default
MRVIEWER_API void transformView(const AffineXf3f &xf)
MRVIEWER_API Vector3f worldToCameraSpace(const Vector3f &p) const
MRVIEWER_API ObjAndPick pick_render_object(bool exactPickFirst) const
MRVIEWER_API std::vector< ConstObjAndPick > constMultiPickObjects(const std::vector< const VisualObject * > &objects, const std::vector< Vector2f > &viewportPoints) const
MRVIEWER_API bool draw(const VisualObject &obj, DepthFunction depthFunc=DepthFunction::Default, RenderModelPassMask pass=RenderModelPassMask::All, bool allowAlphaSort=false) const
MRVIEWER_API AffineXf3f getUnscaledViewXf() const
returns orthonormal matrix with translation
MRVIEWER_API void setClippingPlane(const Plane3f &plane)
MRVIEWER_API void preciseFitBoxToScreenBorder(const FitBoxParams ¶ms)
MRVIEWER_API bool allModelsInsideViewportRectangle() const
BaseRenderParams getBaseRenderParams() const
Prepares base rendering parameters for this viewport.
Definition MRViewport.h:130
MRVIEWER_API void drawLines(const std::vector< LineSegm3f > &lines, const std::vector< SegmEndColors > &colors, const LinePointImmediateRenderParams ¶ms)
Draw lines immediately.
void drawPoints(const std::vector< Vector3f > &points, const std::vector< Vector4f > &colors, float width=1, bool depthTest=true)
Definition MRViewport.h:117
MRVIEWER_API void setBackgroundColor(const Color &color)
MRVIEWER_API Vector3f getRotationPivot() const
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)
MRVIEWER_API void clearFramebuffers()
MRVIEWER_API ObjAndPick pick_render_object(const Vector2f &viewportPoint) const
MRVIEWER_API void setCameraPoint(const Vector3f &cameraWorldPos)
MRVIEWER_API Vector3f clipSpaceToViewportSpace(const Vector3f &p) const
ViewportId id
Definition MRViewport.h:274
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:348
MRVIEWER_API ObjAndPick pick_render_object() const
Visual Object.
Definition MRVisualObject.h:131
auto width(const Box< V > &box)
returns size along x axis
Definition MRMesh/MRBox.h:247
auto height(const Box< V > &box)
returns size along y axis
Definition MRMesh/MRBox.h:254
Definition MRCameraOrientationPlugin.h:8
FitMode
Definition MRFitData.h:11
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
RenderModelPassMask
Various passes of the 3D rendering.
Definition MRRenderModelParameters.h:10
Vector4< T > toVec4(const ViewportRectangle &rect)
Definition MRViewport.h:41
DepthFunction
Definition MRIRenderObject.h:18
Box2f ViewportRectangle
Viewport size.
Definition MRViewerFwd.h:12
Definition MRFitData.h:19
Common rendering parameters for meshes and UI.
Definition MRIRenderObject.h:33
Definition MRFitData.h:41
Definition MRFitData.h:28
Mesh rendering parameters for primary rendering (as opposed to the picker).
Definition MRIRenderObject.h:51
Definition MRPointOnObject.h:16
Definition MRVector4.h:13
Definition MRViewport.h:277
RotationCenterMode
Definition MRViewport.h:307
float cameraViewAngle
Definition MRViewport.h:284
Vector3f cameraTranslation
Definition MRViewport.h:282
Color backgroundColor
Definition MRViewport.h:278
bool orthographic
Definition MRViewport.h:289
float cameraDfar
Definition MRViewport.h:286
Color borderColor
Definition MRViewport.h:300
bool depthTest
Definition MRViewport.h:288
Plane3f clippingPlane
Definition MRViewport.h:304
std::string label
Definition MRViewport.h:302
float cameraZoom
Definition MRViewport.h:283
Quaternionf cameraTrackballAngle
Definition MRViewport.h:281
Vector3f lightPosition
Definition MRViewport.h:279
enum MR::Viewport::Parameters::GlobalBasisScaleMode Auto
bool selectable
Definition MRViewport.h:314
GlobalBasisScaleMode
Definition MRViewport.h:292
enum MR::Viewport::Parameters::RotationCenterMode Dynamic
bool operator==(const Viewport::Parameters &other) const =default
float cameraDnear
Definition MRViewport.h:285
float objectScale
Definition MRViewport.h:298
Definition MRViewport.h:158
int pickRadius
Definition MRViewport.h:167
PickRenderObjectPredicate predicate
Definition MRViewport.h:163
bool exactPickFirst
Definition MRViewport.h:171
static PickRenderObjectParams defaults()
Definition MRViewport.h:176
std::optional< Vector2f > point
Definition MRViewport.h:160
Definition MRViewport.h:121
Vector4f c
Definition MRViewport.h:122
Vector4f b
Definition MRViewport.h:122
Vector4f a
Definition MRViewport.h:122