MeshLib
 
Loading...
Searching...
No Matches
MRViewportGL.h
Go to the documentation of this file.
1#pragma once
2#include "MRViewerFwd.h"
3#include "MRMesh/MRVector4.h"
4#include "MRMesh/MRVector2.h"
5#include "MRMesh/MRBox.h"
6#include "MRMesh/MRPlane3.h"
8#include "MRMesh/MRColor.h"
11
12#include <span>
13
14namespace MR
15{
16// colors of segment ends
18{
19 Vector4f a, b;
20};
21
22inline bool operator==( const SegmEndColors& a, const SegmEndColors& b )
23{
24 return a.a == b.a && a.b == b.b;
25}
26
27// stores points and corresponding colors (sizes of vectors should be the same)
29{
30 std::vector<Vector3f> points;
31 std::vector<Vector4f> colors;
32};
33
35{
36 return a.points == b.points && a.colors == b.colors;
37}
38
39// store lines and corresponding colors (sizes of vectors should be the same)
41{
42 std::vector<LineSegm3f> lines;
43 std::vector<SegmEndColors> colors;
44};
45
47{
48 return a.lines == b.lines && a.colors == b.colors;
49}
50
51// This class holds data needed to render viewport primitives and accumulative picker via OpenGL
53{
54public:
55 typedef unsigned int GLuint;
56 typedef float GLfloat;
57
58 ViewportGL() = default;
59 // Copy operators do nothing, not to share GL data
61 ViewportGL& operator = ( const ViewportGL& ) { return *this; }
62
63 MRVIEWER_API ViewportGL( ViewportGL&& other ) noexcept;
66
67 // Initialize all GL buffers and arrays
68 void init();
69 // Free all GL data
70 void free();
71
72 // Binds and draws viewport border
73 void drawBorder( const Box2f& rect, const Color& color ) const;
74
75 // Fills viewport with given color (clear frame buffer)
76 void fillViewport( const Box2f& rect, const Color& color ) const;
77
78 // Check that members have been initialized
79 bool checkInit() const;
80
81 // Parameters of objects picking
83 {
84 std::span<VisualObject* const> renderVector; // objects to pick
85 BaseRenderParams baseRenderParams; // parameters for rendering pick object
86 Plane3f clippingPlane; // viewport clip plane (it is not applied while object does not have clipping flag set)
87 };
89 {
90 unsigned geomId{ unsigned( -1 ) }; // id of picked object in PickParameters::renderVector (-1 means invalid)
91 unsigned primId{ unsigned( -1 ) }; // id of picked primitive (-1 means invalid)
92 // Note: for point clouds, primId is a point index after discretization
93 };
94 // Result of object picking
96 {
97 float zBuffer{1.0f}; // camera z coordinate of picked point (1.0f means far plane)
98 };
99 using PickResults = std::vector<PickResult>;
100 // Find picked object, face id and z coordinate, of objects given in parameters (works for vector of picks)
101 PickResults pickObjects( const PickParameters& params, const std::vector<Vector2i>& picks ) const;
102 // Find unique objects in given rect (return vector of ids of objects from params)
103 // if maxRenderResolutionSide less then current rect size, downscale rendering for better performance
104 std::vector<unsigned> findUniqueObjectsInRect( const PickParameters& params, const Box2i& rect,
105 int maxRenderResolutionSide ) const;
106
107 using BasePickResults = std::vector<BasePickResult>;
113 // Pick all pixels in rect
114 // if maxRenderResolutionSide less then current rect size, downscale rendering for better performance
116 int maxRenderResolutionSide ) const;
117
118private:
119 struct PickColor
120 {
121 unsigned color[4];
122 };
123
124 struct PickTextureFrameBuffer
125 {
126 void resize( const Vector2i& size );
127 void del();
128 void bind( bool read );
129 private:
130 unsigned int framebuffer_{ 0 };
131 unsigned int colorTexture_{ 0 };
132 unsigned int renderbuffer_{ 0 };
133 Vector2i size_;
134 };
135 mutable PickTextureFrameBuffer pickFBO_;
136
137 std::vector<PickColor> pickObjectsInRect_( const PickParameters& params, const Box2i& rect ) const;
138
139 bool inited_ = false;
140
141 GLuint add_line_colors_vbo = 0;
142 GLuint add_line_vbo = 0;
143 GLuint add_line_vao = 0;
144
145 GLuint add_point_colors_vbo = 0;
146 GLuint add_point_vbo = 0;
147 GLuint add_point_vao = 0;
148
149 GLuint border_line_vbo = 0;
150 GLuint border_line_vao = 0;
151};
152
153}
Definition MRViewportGL.h:53
MRVIEWER_API ViewportGL(ViewportGL &&other) noexcept
std::vector< BasePickResult > BasePickResults
Definition MRViewportGL.h:107
unsigned int GLuint
Definition MRViewportGL.h:55
void fillViewport(const Box2f &rect, const Color &color) const
ViewportGL(const ViewportGL &)
Definition MRViewportGL.h:60
float GLfloat
Definition MRViewportGL.h:56
bool checkInit() const
std::vector< PickResult > PickResults
Definition MRViewportGL.h:99
ViewportGL()=default
PickResults pickObjects(const PickParameters &params, const std::vector< Vector2i > &picks) const
ViewportGL & operator=(const ViewportGL &)
Definition MRViewportGL.h:61
void drawBorder(const Box2f &rect, const Color &color) const
std::vector< unsigned > findUniqueObjectsInRect(const PickParameters &params, const Box2i &rect, int maxRenderResolutionSide) const
ScaledPickRes pickObjectsInRect(const PickParameters &params, const Box2i &rect, int maxRenderResolutionSide) const
MRMESH_API bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
Definition MRCameraOrientationPlugin.h:7
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
Box2i
Definition MRMesh/MRMeshFwd.h:298
Common rendering parameters for meshes and UI.
Definition MRIRenderObject.h:32
Definition MRColor.h:9
Definition MRViewportGL.h:18
Vector4f a
Definition MRViewportGL.h:19
Vector4f b
Definition MRViewportGL.h:19
Definition MRViewportGL.h:89
unsigned primId
Definition MRViewportGL.h:91
unsigned geomId
Definition MRViewportGL.h:90
Definition MRViewportGL.h:83
BaseRenderParams baseRenderParams
Definition MRViewportGL.h:85
std::span< VisualObject *const > renderVector
Definition MRViewportGL.h:84
Plane3f clippingPlane
Definition MRViewportGL.h:86
Definition MRViewportGL.h:96
float zBuffer
Definition MRViewportGL.h:97
Definition MRViewportGL.h:109
BasePickResults pickRes
Definition MRViewportGL.h:110
Box2i updatedBox
Definition MRViewportGL.h:111
Definition MRViewportGL.h:41
std::vector< LineSegm3f > lines
Definition MRViewportGL.h:42
std::vector< SegmEndColors > colors
Definition MRViewportGL.h:43
Definition MRViewportGL.h:29
std::vector< Vector3f > points
Definition MRViewportGL.h:30
std::vector< Vector4f > colors
Definition MRViewportGL.h:31