File indexing completed on 2026-09-28 09:21:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _OpenGl_ShaderGrid_HeaderFile
0015 #define _OpenGl_ShaderGrid_HeaderFile
0016
0017 #include <Aspect_GridParams.hxx>
0018 #include <Bnd_Box.hxx>
0019 #include <Graphic3d_Camera.hxx>
0020 #include <Graphic3d_Vertex.hxx>
0021 #include <NCollection_Mat4.hxx>
0022 #include <NCollection_Vec2.hxx>
0023 #include <OpenGl_Context.hxx>
0024 #include <OpenGl_ShaderProgram.hxx>
0025 #include <gp_Ax3.hxx>
0026
0027
0028 class OpenGl_ShaderGrid
0029 {
0030 public:
0031
0032 bool IsShown() const { return myIsShown; }
0033
0034
0035 bool IsBackground() const { return myParams.IsBackground(); }
0036
0037
0038 const Aspect_GridParams& Params() const { return myParams; }
0039
0040
0041 bool Display(const Aspect_GridParams& theParams,
0042 const gp_Ax3& thePlane,
0043 const occ::handle<Graphic3d_Camera>& theCamera,
0044 const occ::handle<OpenGl_Context>& theContext);
0045
0046
0047 void Erase();
0048
0049
0050 void AddZFitBounds(Bnd_Box& theGraphicBox, const occ::handle<Graphic3d_Camera>& theCamera) const;
0051
0052
0053 bool Echo(const occ::handle<Graphic3d_Camera>& theCamera,
0054 const int theWidth,
0055 const int theHeight,
0056 const int theX,
0057 const int theY,
0058 Graphic3d_Vertex& thePoint,
0059 Graphic3d_Vertex& theDisplayPoint) const;
0060
0061
0062 bool SnapPoint(const occ::handle<Graphic3d_Camera>& theCamera,
0063 const Graphic3d_Vertex& thePoint,
0064 Graphic3d_Vertex& theGridPoint) const;
0065
0066
0067 void SetUniforms(const occ::handle<OpenGl_Context>& theContext,
0068 const occ::handle<OpenGl_ShaderProgram>& theProgram,
0069 const occ::handle<Graphic3d_Camera>& theCamera,
0070 const NCollection_Mat4<float>& theWorldView) const;
0071
0072
0073 NCollection_Mat4<float> DrawWorldView(const NCollection_Mat4<float>& theCurrentWorldView) const;
0074
0075 private:
0076
0077 void frame(gp_Pnt& theOrigin, gp_XYZ& theX, gp_XYZ& theY, gp_XYZ& theN) const;
0078
0079
0080 void effectiveScale(const occ::handle<Graphic3d_Camera>& theCamera,
0081 double& theScaleX,
0082 double& theScaleY) const;
0083
0084
0085 bool isPointInBounds(const double theLocalX, const double theLocalY) const;
0086
0087
0088 static void addLocalPoint(Bnd_Box& theBox,
0089 const gp_Pnt& theOrigin,
0090 const gp_XYZ& theX,
0091 const gp_XYZ& theY,
0092 const double theLocalX,
0093 const double theLocalY);
0094
0095
0096 void addFiniteBounds(Bnd_Box& theBox) const;
0097
0098
0099 void addViewFootprintBounds(Bnd_Box& theBox,
0100 const occ::handle<Graphic3d_Camera>& theCamera) const;
0101
0102
0103 bool planeLocalHit(const occ::handle<Graphic3d_Camera>& theCamera,
0104 const double theNdcX,
0105 const double theNdcY,
0106 double& theLocalX,
0107 double& theLocalY,
0108 gp_XYZ* theHit = nullptr,
0109 const bool theToRejectBehind = true) const;
0110
0111
0112 bool referenceLocal(const occ::handle<Graphic3d_Camera>& theCamera,
0113 double& theLocalX,
0114 double& theLocalY) const;
0115
0116
0117 static double snappedLocalShift(const double theLocal, const double theScale);
0118
0119
0120 bool hasSameAnchorFrame(const Aspect_GridParams& theParams, const gp_Ax3& thePlane) const;
0121
0122
0123 bool acceptEchoCandidate(const occ::handle<Graphic3d_Camera>& theCamera,
0124 const int theWidth,
0125 const int theHeight,
0126 const int theX,
0127 const int theY,
0128 const gp_Pnt& theGridOrigin,
0129 const gp_XYZ& theGridX,
0130 const gp_XYZ& theGridY,
0131 const double theLocalX,
0132 const double theLocalY,
0133 gp_XYZ& theBestSnapped,
0134 double& theBestDist2,
0135 bool& theHasBestPoint) const;
0136
0137
0138 static NCollection_Vec3<float> viewPoint(const NCollection_Mat4<float>& theWorldView,
0139 const gp_Pnt& thePoint);
0140
0141
0142 static NCollection_Vec3<float> viewDirection(const NCollection_Mat4<float>& theWorldView,
0143 const gp_XYZ& theDirection);
0144
0145
0146 static bool echoDisplayPoint(const occ::handle<Graphic3d_Camera>& theCamera,
0147 const gp_XYZ& theSnapped,
0148 gp_Pnt& theDisplayPoint);
0149
0150
0151 static bool angleInArc(const double theStart, const double theEnd, const double theAngle);
0152
0153 private:
0154 Aspect_GridParams myParams;
0155 gp_Ax3 myPlane;
0156 NCollection_Mat4<float> myRefViewMatrix;
0157 bool myIsShown = false;
0158 };
0159
0160 #endif