Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-22 09:23:12

0001 // Created on: 2001-07-02
0002 // Created by: Mathias BOSSHARD
0003 // Copyright (c) 2001-2014 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 _AIS_TexturedShape_HeaderFile
0017 #define _AIS_TexturedShape_HeaderFile
0018 
0019 #include <AIS_Shape.hxx>
0020 #include <gp_Pnt2d.hxx>
0021 #include <Graphic3d_NameOfTexture2D.hxx>
0022 #include <Image_PixMap.hxx>
0023 #include <Standard_Type.hxx>
0024 #include <TCollection_AsciiString.hxx>
0025 #include <Graphic3d_AspectFillArea3d.hxx>
0026 #include <Prs3d_Presentation.hxx>
0027 #include <PrsMgr_PresentationManager.hxx>
0028 
0029 class Graphic3d_AspectFillArea3d;
0030 class Graphic3d_Texture2D;
0031 
0032 //! This class allows to map textures on shapes.
0033 //! Presentations modes AIS_WireFrame (0) and AIS_Shaded (1) behave in the same manner as in
0034 //! AIS_Shape, whilst new modes 2 (bounding box) and 3 (texture mapping) extends it functionality.
0035 //!
0036 //! The texture itself is parametrized in (0,1)x(0,1).
0037 //! Each face of a shape located in UV space is provided with these parameters:
0038 //! - Umin - starting position in U
0039 //! - Umax - ending   position in U
0040 //! - Vmin - starting position in V
0041 //! - Vmax - ending   position in V
0042 //! Each face is triangulated and a texel is assigned to each node.
0043 //! Facets are then filled using a linear interpolation of texture between each 'three texels'.
0044 //! User can act on:
0045 //! - the number of occurrences of the texture on the face
0046 //! - the position of the origin of the texture
0047 //! - the scale factor of the texture
0048 class AIS_TexturedShape : public AIS_Shape
0049 {
0050 
0051 public: //! @name main methods
0052   //! Initializes the textured shape.
0053   Standard_EXPORT AIS_TexturedShape(const TopoDS_Shape& theShape);
0054 
0055   //! Sets the texture source. <theTextureFileName> can specify path to texture image or one of the
0056   //! standard predefined textures. The accepted file types are those used in Image_AlienPixMap with
0057   //! extensions such as rgb, png, jpg and more. To specify the standard predefined texture, the
0058   //! <theTextureFileName> should contain integer - the Graphic3d_NameOfTexture2D enumeration index.
0059   //! Setting texture source using this method resets the source pixmap (if was set previously).
0060   Standard_EXPORT virtual void SetTextureFileName(
0061     const TCollection_AsciiString& theTextureFileName);
0062 
0063   //! Sets the texture source. <theTexturePixMap> specifies image data.
0064   //! Please note that the data should be in Bottom-Up order, the flag of Image_PixMap::IsTopDown()
0065   //! will be ignored by graphic driver. Setting texture source using this method resets the source
0066   //! by filename (if was set previously).
0067   Standard_EXPORT virtual void SetTexturePixMap(const Handle(Image_PixMap)& theTexturePixMap);
0068 
0069   //! @return flag to control texture mapping (for presentation mode 3)
0070   Standard_Boolean TextureMapState() const { return myToMapTexture; }
0071 
0072   //! Enables texture mapping
0073   Standard_EXPORT void SetTextureMapOn();
0074 
0075   //! Disables texture mapping
0076   Standard_EXPORT void SetTextureMapOff();
0077 
0078   //! @return path to the texture file
0079   Standard_CString TextureFile() const { return myTextureFile.ToCString(); }
0080 
0081   //! @return the source pixmap for texture map
0082   const Handle(Image_PixMap)& TexturePixMap() const { return myTexturePixMap; }
0083 
0084 public: //! @name methods to alter texture mapping properties
0085   //! Use this method to display the textured shape without recomputing the whole presentation.
0086   //! Use this method when ONLY the texture content has been changed.
0087   //! If other parameters (ie: scale factors, texture origin, texture repeat...) have changed, the
0088   //! whole presentation has to be recomputed:
0089   //! @code
0090   //! if (myShape->DisplayMode() == 3)
0091   //! {
0092   //!   myAISContext->RecomputePrsOnly (myShape);
0093   //! }
0094   //! else
0095   //! {
0096   //!   myAISContext->SetDisplayMode (myShape, 3, Standard_False);
0097   //!   myAISContext->Display        (myShape, Standard_True);
0098   //! }
0099   //! @endcode
0100   Standard_EXPORT void UpdateAttributes();
0101 
0102   //! Sets the color.
0103   Standard_EXPORT virtual void SetColor(const Quantity_Color& theColor) Standard_OVERRIDE;
0104 
0105   //! Removes settings for the color.
0106   Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE;
0107 
0108   //! Sets the material aspect.
0109   Standard_EXPORT virtual void SetMaterial(const Graphic3d_MaterialAspect& theAspect)
0110     Standard_OVERRIDE;
0111 
0112   //! Removes settings for material aspect.
0113   Standard_EXPORT virtual void UnsetMaterial() Standard_OVERRIDE;
0114 
0115   //! Enables texture modulation
0116   Standard_EXPORT void EnableTextureModulate();
0117 
0118   //! Disables texture modulation
0119   Standard_EXPORT void DisableTextureModulate();
0120 
0121   //! @return texture repeat flag
0122   Standard_Boolean TextureRepeat() const { return myToRepeat; }
0123 
0124   //! @return texture repeat U value
0125   Standard_Real URepeat() const { return myUVRepeat.X(); }
0126 
0127   //! @return texture repeat V value
0128   Standard_Real VRepeat() const { return myUVRepeat.Y(); }
0129 
0130   //! Sets the number of occurrences of the texture on each face. The texture itself is
0131   //! parameterized in (0,1) by (0,1). Each face of the shape to be textured is parameterized in UV
0132   //! space (Umin,Umax) by (Vmin,Vmax). If RepeatYN is set to false, texture coordinates are clamped
0133   //! in the range (0,1)x(0,1) of the face.
0134   Standard_EXPORT void SetTextureRepeat(const Standard_Boolean theToRepeat,
0135                                         const Standard_Real    theURepeat = 1.0,
0136                                         const Standard_Real    theVRepeat = 1.0);
0137 
0138   //! @return true if texture UV origin has been modified
0139   Standard_Boolean TextureOrigin() const { return myIsCustomOrigin; }
0140 
0141   //! @return texture origin U position (0.0 by default)
0142   Standard_Real TextureUOrigin() const { return myUVOrigin.X(); }
0143 
0144   //! @return texture origin V position (0.0 by default)
0145   Standard_Real TextureVOrigin() const { return myUVOrigin.Y(); }
0146 
0147   //! Use this method to change the origin of the texture. The texel (0,0) will be mapped to the
0148   //! surface (UOrigin,VOrigin)
0149   Standard_EXPORT void SetTextureOrigin(const Standard_Boolean theToSetTextureOrigin,
0150                                         const Standard_Real    theUOrigin = 0.0,
0151                                         const Standard_Real    theVOrigin = 0.0);
0152 
0153   //! @return true if scale factor should be applied to texture mapping
0154   Standard_Boolean TextureScale() const { return myToScale; }
0155 
0156   //! @return scale factor for U coordinate (1.0 by default)
0157   Standard_Real TextureScaleU() const { return myUVScale.X(); }
0158 
0159   //! @return scale factor for V coordinate (1.0 by default)
0160   Standard_Real TextureScaleV() const { return myUVScale.Y(); }
0161 
0162   //! Use this method to scale the texture (percent of the face).
0163   //! You can specify a scale factor for both U and V.
0164   //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat,
0165   //!          the texture will appear twice on the face in each direction.
0166   Standard_EXPORT void SetTextureScale(const Standard_Boolean theToSetTextureScale,
0167                                        const Standard_Real    theScaleU = 1.0,
0168                                        const Standard_Real    theScaleV = 1.0);
0169 
0170   //! @return true if displaying of triangles is requested
0171   Standard_Boolean ShowTriangles() const { return myToShowTriangles; }
0172 
0173   //! Use this method to show the triangulation of the shape (for debugging etc.).
0174   Standard_EXPORT void ShowTriangles(const Standard_Boolean theToShowTriangles);
0175 
0176   //! @return true if texture color modulation is turned on
0177   Standard_Boolean TextureModulate() const { return myModulate; }
0178 
0179   //! Return true if specified display mode is supported (extends AIS_Shape with Display Mode 3).
0180   virtual Standard_Boolean AcceptDisplayMode(const Standard_Integer theMode) const Standard_OVERRIDE
0181   {
0182     return theMode >= 0 && theMode <= 3;
0183   }
0184 
0185 protected: //! @name overridden methods
0186   //! Compute presentation with texture mapping support.
0187   Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager)& thePrsMgr,
0188                                        const Handle(Prs3d_Presentation)&         thePrs,
0189                                        const Standard_Integer theMode) Standard_OVERRIDE;
0190 
0191   Standard_EXPORT void updateAttributes(const Handle(Prs3d_Presentation)& thePrs);
0192 
0193 protected: //! @name presentation fields
0194   Handle(Graphic3d_Texture2D)        myTexture;
0195   Handle(Graphic3d_AspectFillArea3d) myAspect;
0196 
0197 protected: //! @name texture source fields
0198   Handle(Image_PixMap)      myTexturePixMap;
0199   TCollection_AsciiString   myTextureFile;
0200   Graphic3d_NameOfTexture2D myPredefTexture;
0201 
0202 protected: //! @name texture mapping properties
0203   Standard_Boolean myToMapTexture;
0204   Standard_Boolean myModulate;
0205   Standard_Boolean myIsCustomOrigin;
0206   Standard_Boolean myToRepeat;
0207   Standard_Boolean myToScale;
0208   Standard_Boolean myToShowTriangles;
0209 
0210 public:
0211   DEFINE_STANDARD_RTTIEXT(AIS_TexturedShape, AIS_Shape)
0212 };
0213 
0214 DEFINE_STANDARD_HANDLE(AIS_TexturedShape, AIS_Shape)
0215 
0216 #endif // _AIS_TexturedShape_HeaderFile