Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:34

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 
0027 //! This class allows to render Graduated Trihedron, i.e. trihedron with grid.
0028 //! it is based on Graphic3d_GraduatedTrihedron parameters and support its customization
0029 //! on construction level only.
0030 //! @sa Graphic3d_GraduatedTrihedron
0031 class OpenGl_GraduatedTrihedron : public OpenGl_Element
0032 {
0033 public:
0034 
0035   DEFINE_STANDARD_ALLOC
0036 
0037 public:
0038 
0039   //! Default constructor.
0040   Standard_EXPORT OpenGl_GraduatedTrihedron();
0041 
0042   //! Destructor.
0043   Standard_EXPORT virtual ~OpenGl_GraduatedTrihedron();
0044 
0045   //! Draw the element.
0046   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE;
0047 
0048   //! Release OpenGL resources.
0049   Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
0050 
0051   //! Setup configuration.
0052   Standard_EXPORT void SetValues (const Graphic3d_GraduatedTrihedron& theData);
0053 
0054   //! Sets up-to-date values of scene bounding box.
0055   //! Can be used in callback mechanism to get up-to-date values.
0056   //! @sa Graphic3d_GraduatedTrihedron::CubicAxesCallback
0057   Standard_EXPORT void SetMinMax (const OpenGl_Vec3& theMin,
0058                                   const OpenGl_Vec3& theMax);
0059 
0060   //! Dumps the content of me into the stream
0061   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0062 
0063 private:
0064 
0065   //! Axis of trihedron. It incapsulates geometry and style.
0066   class Axis
0067   {
0068   public:
0069 
0070     OpenGl_Vec3         Direction;
0071     Quantity_Color      NameColor;
0072     OpenGl_Aspects      LineAspect;
0073     mutable OpenGl_Text Label;
0074     mutable OpenGl_PrimitiveArray Tickmark;
0075     mutable OpenGl_PrimitiveArray Line;
0076     mutable OpenGl_PrimitiveArray Arrow;
0077 
0078   public:
0079 
0080     Axis (const Graphic3d_GraduatedTrihedron::AxisAspect& theAspect =
0081                 Graphic3d_GraduatedTrihedron::AxisAspect(),
0082           const OpenGl_Vec3& theDirection = OpenGl_Vec3 (1.0f, 0.0f, 0.0f));
0083 
0084     ~Axis();
0085 
0086     Axis& operator= (const Axis& theOther);
0087 
0088     void InitArrow (const Handle(OpenGl_Context)& theContext,
0089                     const Standard_ShortReal theLength,
0090                     const OpenGl_Vec3& theNormal) const;
0091 
0092     void InitTickmark (const Handle(OpenGl_Context)& theContext,
0093                        const OpenGl_Vec3& theDir) const;
0094 
0095     void InitLine (const Handle(OpenGl_Context)& theContext,
0096                    const OpenGl_Vec3& theDir) const;
0097 
0098     void Release (OpenGl_Context* theCtx);
0099 
0100   };
0101 
0102 private:
0103 
0104   //! Struct for triple of orthonormal vectors
0105   //! and origin point, and axes for tickmarks.
0106   //! It may be not a right or left coordinate system.
0107   struct GridAxes
0108   {
0109   public:
0110     GridAxes()
0111     : Origin (0, 0, 0)
0112     {
0113       Axes[0] = OpenGl_Vec3 (1.0f, 0.0f, 0.0f);
0114       Axes[1] = OpenGl_Vec3 (0.0f, 1.0f, 0.0f);
0115       Axes[2] = OpenGl_Vec3 (0.0f, 0.0f, 1.0f);
0116 
0117       Ticks[0] = OpenGl_Vec3 (0.0f, 0.0f, 0.0f);
0118       Ticks[1] = OpenGl_Vec3 (0.0f, 0.0f, 0.0f);
0119       Ticks[2] = OpenGl_Vec3 (0.0f, 0.0f, 0.0f);
0120     }
0121 
0122   public: //! @name Main grid directions
0123     OpenGl_Vec3 Origin;
0124     OpenGl_Vec3 Axes[3];
0125 
0126   public: //! @name Directions for tickmarks
0127     OpenGl_Vec3 Ticks[3];
0128   };
0129 
0130 private:
0131 
0132   //! Initialize or update GL resources for rendering trihedron.
0133   //! @param theContext [in] the GL context.
0134   void initGlResources (const Handle(OpenGl_Context)& theContext) const;
0135 
0136   //! Gets normal of the view out of user.
0137   //! @param theContext [in] OpenGL Context
0138   //! @param theNormal [out] normal of the view out of user
0139   //! @return distance corresponding to 1 pixel
0140   Standard_ShortReal getNormal (const Handle(OpenGl_Context)& theContext,
0141                                 OpenGl_Vec3& theNormal) const;
0142 
0143   //! Gets distance to point (theX, theY, theZ) of bounding box along the normal
0144   //! @param theNormal [in] normal of the view out of user
0145   //! @param theCenter [in] geometry center of bounding box
0146   //! @param theX [in] x of target point
0147   //! @param theY [in] y of target point
0148   //! @param theZ [in] z of terget point
0149   Standard_ShortReal getDistanceToCorner (const OpenGl_Vec3& theNormal,
0150                                           const OpenGl_Vec3& theCenter,
0151                                           const Standard_ShortReal theX,
0152                                           const Standard_ShortReal theY,
0153                                           const Standard_ShortReal theZ) const;
0154 
0155   //! Gets axes of grid
0156   //! @param theCorners [in] the corners of grid
0157   //! @param theGridAxes [out] grid axes, the base of graduated trihedron grid.
0158   Standard_ExtCharacter getGridAxes (const Standard_ShortReal theCorners[8],
0159                                      GridAxes& theGridAxes) const;
0160 
0161   //! Render line from the transformed primitive array myLine
0162   //! @param theWorkspace [in] the OpenGl Workspace
0163   //! @param theMat [in] theMat that contains base transformation and is used for applying
0164   //!        translation and rotation
0165   //! @param thaTx the X for vector of translation
0166   //! @param thaTy the Y for vector of translation
0167   //! @param thaTz the Z for vector of translation
0168   void renderLine (const OpenGl_PrimitiveArray&    theLine,
0169                    const Handle(OpenGl_Workspace)& theWorkspace,
0170                    const OpenGl_Mat4&              theMat,
0171                    const Standard_ShortReal        theXt,
0172                    const Standard_ShortReal        theYt,
0173                    const Standard_ShortReal        theZt) const;
0174 
0175   //! Render grid lines perpendecular the axis of input index
0176   //! @param theWorkspace [in] the OpenGl Workspace
0177   //! @param theIndex [in] index of axis
0178   //! @param theGridAxes [in] grid axes
0179   //! @param theMat [in] theMat that contains base transformation and is used for applying
0180   //!        translation and rotation
0181   void renderGridPlane (const Handle(OpenGl_Workspace)& theWorkspace,
0182                         const Standard_Integer& theIndex,
0183                         const GridAxes& theGridAxes,
0184                         OpenGl_Mat4& theMat) const;
0185 
0186 
0187   //! Render the axis of input index
0188   //! @param theWorkspace [in] the OpenGl Workspace
0189   //! @param theIndex [in] index of axis
0190   //! @param theMat [in] theMat that contains base transformation and is used for applying
0191   //!        translation and rotation
0192   void renderAxis (const Handle(OpenGl_Workspace)& theWorkspace,
0193                    const Standard_Integer& theIndex,
0194                    const OpenGl_Mat4& theMat) const;
0195 
0196   //! Render grid labels, tickmark lines and labels
0197   //! @param theWorkspace [in] the OpenGl Workspace
0198   //! @param theMat [in] theMat that contains base transformation and is used for applying
0199   //!        translation and rotation
0200   //! @param theIndex [in] index of axis
0201   //! @param theGridAxes [in] grid axes
0202   //! @param theDpix [in] distance corresponding to 1 pixel
0203   void renderTickmarkLabels (const Handle(OpenGl_Workspace)& theWorkspace,
0204                              const OpenGl_Mat4& theMat,
0205                              const Standard_Integer theIndex,
0206                              const GridAxes& theGridAxes,
0207                              const Standard_ShortReal theDpix) const;
0208 
0209 protected: //! @name Scene bounding box values
0210 
0211   OpenGl_Vec3 myMin;
0212   OpenGl_Vec3 myMax;
0213 
0214 protected:
0215 
0216   mutable Axis myAxes[3]; //!< Axes for trihedron
0217   mutable Graphic3d_GraduatedTrihedron myData;
0218   mutable OpenGl_Aspects   myGridLineAspect; //!< Color grid properties
0219 
0220 protected: //! @name Labels properties
0221 
0222   mutable OpenGl_Text    myLabelValues;
0223   mutable OpenGl_Aspects myAspectLabels;
0224   mutable OpenGl_Aspects myAspectValues;
0225 
0226 private:
0227 
0228   mutable Standard_Boolean myIsInitialized;
0229 
0230   enum AxisFlags
0231   {
0232     XOO_XYO = 1 << 1,
0233     XOO_XOZ = 1 << 2,
0234     OYO_OYZ = 1 << 3,
0235     OYO_XYO = 1 << 4,
0236     OOZ_XOZ = 1 << 5,
0237     OOZ_OYZ = 1 << 6,
0238     OYZ_XYZ = 1 << 7,
0239     XOZ_XYZ = 1 << 8,
0240     XYO_XYZ = 1 << 9
0241   };
0242 };
0243 
0244 #endif //_OpenGl_GraduatedTrihedron_Header