Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-26 10:22:52

0001 // Created on: 2011-09-20
0002 // Created by: Sergey ZERCHANINOV
0003 // Copyright (c) 2011-2013 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef OpenGl_GraduatedTrihedron_HeaderFile
0017 #define OpenGl_GraduatedTrihedron_HeaderFile
0018 
0019 #include <Graphic3d_GraduatedTrihedron.hxx>
0020 #include <NCollection_Array1.hxx>
0021 #include <OpenGl_Aspects.hxx>
0022 #include <OpenGl_Element.hxx>
0023 #include <OpenGl_PrimitiveArray.hxx>
0024 #include <OpenGl_Text.hxx>
0025 
0026 //! This class allows to render Graduated Trihedron, i.e. trihedron with grid.
0027 //! it is based on Graphic3d_GraduatedTrihedron parameters and support its customization
0028 //! on construction level only.
0029 //! @sa Graphic3d_GraduatedTrihedron
0030 class OpenGl_GraduatedTrihedron : public OpenGl_Element
0031 {
0032 public:
0033   DEFINE_STANDARD_ALLOC
0034 
0035 public:
0036   //! Default constructor.
0037   Standard_EXPORT OpenGl_GraduatedTrihedron();
0038 
0039   //! Destructor.
0040   Standard_EXPORT ~OpenGl_GraduatedTrihedron() override;
0041 
0042   //! Draw the element.
0043   Standard_EXPORT void Render(const occ::handle<OpenGl_Workspace>& theWorkspace) const override;
0044 
0045   //! Release OpenGL resources.
0046   Standard_EXPORT void Release(OpenGl_Context* theCtx) override;
0047 
0048   //! Setup configuration.
0049   Standard_EXPORT void SetValues(const Graphic3d_GraduatedTrihedron& theData);
0050 
0051   //! Sets up-to-date values of scene bounding box.
0052   //! Can be used in callback mechanism to get up-to-date values.
0053   //! @sa Graphic3d_GraduatedTrihedron::CubicAxesCallback
0054   Standard_EXPORT void SetMinMax(const NCollection_Vec3<float>& theMin,
0055                                  const NCollection_Vec3<float>& theMax);
0056 
0057   //! Dumps the content of me into the stream
0058   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override;
0059 
0060 private:
0061   //! Axis of trihedron. It incapsulates geometry and style.
0062   class Axis
0063   {
0064   public:
0065     NCollection_Vec3<float>       Direction;
0066     Quantity_Color                NameColor;
0067     OpenGl_Aspects                LineAspect;
0068     mutable OpenGl_Text           Label;
0069     mutable OpenGl_PrimitiveArray Tickmark;
0070     mutable OpenGl_PrimitiveArray Line;
0071     mutable OpenGl_PrimitiveArray Arrow;
0072 
0073   public:
0074     Axis(const Graphic3d_GraduatedTrihedron::AxisAspect& theAspect =
0075            Graphic3d_GraduatedTrihedron::AxisAspect(),
0076          const NCollection_Vec3<float>& theDirection = NCollection_Vec3<float>(1.0f, 0.0f, 0.0f));
0077 
0078     ~Axis();
0079 
0080     Axis& operator=(const Axis& theOther);
0081 
0082     void InitArrow(const occ::handle<OpenGl_Context>& theContext,
0083                    const float                        theLength,
0084                    const NCollection_Vec3<float>&     theNormal) const;
0085 
0086     void InitTickmark(const occ::handle<OpenGl_Context>& theContext,
0087                       const NCollection_Vec3<float>&     theDir) const;
0088 
0089     void InitLine(const occ::handle<OpenGl_Context>& theContext,
0090                   const NCollection_Vec3<float>&     theDir) const;
0091 
0092     void Release(OpenGl_Context* theCtx);
0093   };
0094 
0095 private:
0096   //! Struct for triple of orthonormal vectors
0097   //! and origin point, and axes for tickmarks.
0098   //! It may be not a right or left coordinate system.
0099   struct GridAxes
0100   {
0101   public:
0102     GridAxes()
0103         : Origin(0, 0, 0)
0104     {
0105       Axes[0] = NCollection_Vec3<float>(1.0f, 0.0f, 0.0f);
0106       Axes[1] = NCollection_Vec3<float>(0.0f, 1.0f, 0.0f);
0107       Axes[2] = NCollection_Vec3<float>(0.0f, 0.0f, 1.0f);
0108 
0109       Ticks[0] = NCollection_Vec3<float>(0.0f, 0.0f, 0.0f);
0110       Ticks[1] = NCollection_Vec3<float>(0.0f, 0.0f, 0.0f);
0111       Ticks[2] = NCollection_Vec3<float>(0.0f, 0.0f, 0.0f);
0112     }
0113 
0114   public: //! @name Main grid directions
0115     NCollection_Vec3<float> Origin;
0116     NCollection_Vec3<float> Axes[3];
0117 
0118   public: //! @name Directions for tickmarks
0119     NCollection_Vec3<float> Ticks[3];
0120   };
0121 
0122 private:
0123   //! Initialize or update GL resources for rendering trihedron.
0124   //! @param[in] theContext  the GL context.
0125   void initGlResources(const occ::handle<OpenGl_Context>& theContext) const;
0126 
0127   //! Gets normal of the view out of user.
0128   //! @param[in] theContext  OpenGL Context
0129   //! @param[out] theNormal  normal of the view out of user
0130   //! @return distance corresponding to 1 pixel
0131   float getNormal(const occ::handle<OpenGl_Context>& theContext,
0132                   NCollection_Vec3<float>&           theNormal) const;
0133 
0134   //! Gets distance to point (theX, theY, theZ) of bounding box along the normal
0135   //! @param[in] theNormal  normal of the view out of user
0136   //! @param[in] theCenter  geometry center of bounding box
0137   //! @param[in] theX  x of target point
0138   //! @param[in] theY  y of target point
0139   //! @param[in] theZ  z of terget point
0140   float getDistanceToCorner(const NCollection_Vec3<float>& theNormal,
0141                             const NCollection_Vec3<float>& theCenter,
0142                             const float                    theX,
0143                             const float                    theY,
0144                             const float                    theZ) const;
0145 
0146   //! Gets axes of grid
0147   //! @param[in] theCorners  the corners of grid
0148   //! @param[out] theGridAxes  grid axes, the base of graduated trihedron grid.
0149   char16_t getGridAxes(const float theCorners[8], GridAxes& theGridAxes) const;
0150 
0151   //! Render line from the transformed primitive array myLine
0152   //! @param[in] theWorkspace  the OpenGl Workspace
0153   //! @param[in] theMat  theMat that contains base transformation and is used for applying
0154   //!        translation and rotation
0155   //! @param thaTx the X for vector of translation
0156   //! @param thaTy the Y for vector of translation
0157   //! @param thaTz the Z for vector of translation
0158   void renderLine(const OpenGl_PrimitiveArray&         theLine,
0159                   const occ::handle<OpenGl_Workspace>& theWorkspace,
0160                   const NCollection_Mat4<float>&       theMat,
0161                   const float                          theXt,
0162                   const float                          theYt,
0163                   const float                          theZt) const;
0164 
0165   //! Render grid lines perpendecular the axis of input index
0166   //! @param[in] theWorkspace  the OpenGl Workspace
0167   //! @param[in] theIndex  index of axis
0168   //! @param[in] theGridAxes  grid axes
0169   //! @param[in] theMat  theMat that contains base transformation and is used for applying
0170   //!        translation and rotation
0171   void renderGridPlane(const occ::handle<OpenGl_Workspace>& theWorkspace,
0172                        const int&                           theIndex,
0173                        const GridAxes&                      theGridAxes,
0174                        NCollection_Mat4<float>&             theMat) const;
0175 
0176   //! Render the axis of input index
0177   //! @param[in] theWorkspace  the OpenGl Workspace
0178   //! @param[in] theIndex  index of axis
0179   //! @param[in] theMat  theMat that contains base transformation and is used for applying
0180   //!        translation and rotation
0181   void renderAxis(const occ::handle<OpenGl_Workspace>& theWorkspace,
0182                   const int&                           theIndex,
0183                   const NCollection_Mat4<float>&       theMat) const;
0184 
0185   //! Render grid labels, tickmark lines and labels
0186   //! @param[in] theWorkspace  the OpenGl Workspace
0187   //! @param[in] theMat  theMat that contains base transformation and is used for applying
0188   //!        translation and rotation
0189   //! @param[in] theIndex  index of axis
0190   //! @param[in] theGridAxes  grid axes
0191   //! @param[in] theDpix  distance corresponding to 1 pixel
0192   void renderTickmarkLabels(const occ::handle<OpenGl_Workspace>& theWorkspace,
0193                             const NCollection_Mat4<float>&       theMat,
0194                             const int                            theIndex,
0195                             const GridAxes&                      theGridAxes,
0196                             const float                          theDpix) const;
0197 
0198 protected: //! @name Scene bounding box values
0199   NCollection_Vec3<float> myMin;
0200   NCollection_Vec3<float> myMax;
0201 
0202 protected:
0203   mutable Axis                         myAxes[3]; //!< Axes for trihedron
0204   mutable Graphic3d_GraduatedTrihedron myData;
0205   mutable OpenGl_Aspects               myGridLineAspect; //!< Color grid properties
0206 
0207 protected: //! @name Labels properties
0208   mutable OpenGl_Text    myLabelValues;
0209   mutable OpenGl_Aspects myAspectLabels;
0210   mutable OpenGl_Aspects myAspectValues;
0211 
0212 private:
0213   mutable bool myIsInitialized;
0214 
0215   enum AxisFlags
0216   {
0217     XOO_XYO = 1 << 1,
0218     XOO_XOZ = 1 << 2,
0219     OYO_OYZ = 1 << 3,
0220     OYO_XYO = 1 << 4,
0221     OOZ_XOZ = 1 << 5,
0222     OOZ_OYZ = 1 << 6,
0223     OYZ_XYZ = 1 << 7,
0224     XOZ_XYZ = 1 << 8,
0225     XYO_XYZ = 1 << 9
0226   };
0227 };
0228 
0229 #endif //_OpenGl_GraduatedTrihedron_Header