0024672: Visualization - AIS_TexturedShape does not activate back face culling aspect
[occt.git] / src / AIS / AIS_TexturedShape.hxx
1 // Created on: 2001-07-02
2 // Created by: Mathias BOSSHARD
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _AIS_TexturedShape_HeaderFile
17 #define _AIS_TexturedShape_HeaderFile
18
19 #include <AIS_Shape.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <Graphic3d_NameOfTexture2D.hxx>
22 #include <Image_PixMap.hxx>
23 #include <Standard_DefineHandle.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <Handle_Graphic3d_AspectFillArea3d.hxx>
26 #include <Handle_Graphic3d_Texture2Dmanual.hxx>
27 #include <Handle_Prs3d_Presentation.hxx>
28 #include <Handle_PrsMgr_PresentationManager3d.hxx>
29
30 class Graphic3d_AspectFillArea3d;
31 class Graphic3d_Texture2Dmanual;
32 class TopoDS_Shape;
33 class TCollection_AsciiString;
34 class PrsMgr_PresentationManager3d;
35 class Prs3d_Presentation;
36
37 //! This class allows to map textures on shapes.
38 //! Presentations modes AIS_WireFrame (0) and AIS_Shaded (1) behave in the same manner as in AIS_Shape,
39 //! whilst new modes 2 (bounding box) and 3 (texture mapping) extends it functionality.
40 //!
41 //! The texture itself is parametrized in (0,1)x(0,1).
42 //! Each face of a shape located in UV space is provided with these parameters:
43 //! - Umin - starting position in U
44 //! - Umax - ending   position in U
45 //! - Vmin - starting position in V
46 //! - Vmax - ending   position in V
47 //! Each face is triangulated and a texel is assigned to each node.
48 //! Facets are then filled using a linear interpolation of texture between each 'three texels'.
49 //! User can act on:
50 //! - the number of occurrences of the texture on the face
51 //! - the position of the origin of the texture
52 //! - the scale factor of the texture
53 class AIS_TexturedShape : public AIS_Shape
54 {
55
56 public: //! @name main methods
57
58   //! Initializes the textured shape.
59   Standard_EXPORT AIS_TexturedShape (const TopoDS_Shape& theShape);
60
61   //! Sets the texture source. <theTextureFileName> can specify path to texture image or one of the standard predefined textures.
62   //! The accepted file types are those used in Image_AlienPixMap with extensions such as rgb, png, jpg and more.
63   //! To specify the standard predefined texture, the <theTextureFileName> should contain integer - the Graphic3d_NameOfTexture2D enumeration index.
64   //! Setting texture source using this method resets the source pixmap (if was set previously).
65   Standard_EXPORT virtual void SetTextureFileName (const TCollection_AsciiString& theTextureFileName);
66
67   //! Sets the texture source. <theTexturePixMap> specifies image data.
68   //! Please note that the data should be in Bottom-Up order, the flag of Image_PixMap::IsTopDown() will be ignored by graphic driver.
69   //! Setting texture source using this method resets the source by filename (if was set previously).
70   Standard_EXPORT virtual void SetTexturePixMap (const Image_PixMap_Handle& theTexturePixMap);
71
72   //! @return flag to control texture mapping (for presentation mode 3)
73   Standard_Boolean TextureMapState() const { return myToMapTexture; }
74
75   //! Enables texture mapping
76   Standard_EXPORT void SetTextureMapOn();
77
78   //! Disables texture mapping
79   Standard_EXPORT void SetTextureMapOff();
80
81   //! @return path to the texture file
82   Standard_CString TextureFile() const { return myTextureFile.ToCString(); }
83
84   //! @return the source pixmap for texture map
85   const Handle(Image_PixMap)& TexturePixMap() const { return myTexturePixMap; }
86
87 public: //! @name methods to alter texture mapping properties
88
89   //! Use this method to display the textured shape without recomputing the whole presentation.
90   //! Use this method when ONLY the texture content has been changed.
91   //! If other parameters (ie: scale factors, texture origin, texture repeat...) have changed, the whole presentation has to be recomputed:
92   //! @code
93   //! if (myShape->DisplayMode() == 3)
94   //! {
95   //!   myAISContext->RecomputePrsOnly (myShape);
96   //! }
97   //! else
98   //! {
99   //!   myAISContext->SetDisplayMode (myShape, 3, Standard_False);
100   //!   myAISContext->Display        (myShape, Standard_True);
101   //! }
102   //! @endcode
103   Standard_EXPORT void UpdateAttributes();
104
105   //! Enables texture modulation
106   Standard_EXPORT void EnableTextureModulate();
107
108   //! Disables texture modulation
109   Standard_EXPORT void DisableTextureModulate();
110
111   //! @return texture repeat flag
112   Standard_Boolean TextureRepeat() const { return myToRepeat; }
113
114   //! @return texture repeat U value
115   Standard_Real URepeat() const { return myUVRepeat.X(); }
116
117   //! @return texture repeat V value
118   Standard_Real VRepeat() const { return myUVRepeat.Y(); }
119
120   //! Sets the number of occurrences of the texture on each face. The texture itself is parameterized in (0,1) by (0,1).
121   //! Each face of the shape to be textured is parameterized in UV space (Umin,Umax) by (Vmin,Vmax).
122   //! If RepeatYN is set to false, texture coordinates are clamped in the range (0,1)x(0,1) of the face.
123   Standard_EXPORT void SetTextureRepeat (const Standard_Boolean theToRepeat,
124                                          const Standard_Real    theURepeat = 1.0,
125                                          const Standard_Real    theVRepeat = 1.0);
126
127   //! @return true if texture UV origin has been modified
128   Standard_Boolean TextureOrigin() const { return myIsCustomOrigin; }
129
130   //! @return texture origin U position (0.0 by default)
131   Standard_Real TextureUOrigin() const { return myUVOrigin.X(); }
132
133   //! @return texture origin V position (0.0 by default)
134   Standard_Real TextureVOrigin() const { return myUVOrigin.Y(); }
135
136   //! Use this method to change the origin of the texture. The texel (0,0) will be mapped to the surface (UOrigin,VOrigin)
137   Standard_EXPORT void SetTextureOrigin (const Standard_Boolean theToSetTextureOrigin,
138                                          const Standard_Real    theUOrigin = 0.0,
139                                          const Standard_Real    theVOrigin = 0.0);
140
141   //! @return true if scale factor should be applied to texture mapping
142   Standard_Boolean TextureScale() const { return myToScale; }
143
144   //! @return scale factor for U coordinate (1.0 by default)
145   Standard_Real TextureScaleU() const { return myUVScale.X(); }
146
147   //! @return scale factor for V coordinate (1.0 by default)
148   Standard_Real TextureScaleV() const { return myUVScale.Y(); }
149
150   //! Use this method to scale the texture (percent of the face).
151   //! You can specify a scale factor for both U and V.
152   //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat,
153   //!          the texture will appear twice on the face in each direction.
154   Standard_EXPORT void SetTextureScale (const Standard_Boolean theToSetTextureScale,
155                                         const Standard_Real    theScaleU = 1.0,
156                                         const Standard_Real    theScaleV = 1.0);
157
158   //! @return true if displaying of triangles is requested
159   Standard_Boolean ShowTriangles() const { return myToShowTriangles; }
160
161   //! Use this method to show the triangulation of the shape (for debugging etc.).
162   Standard_EXPORT void ShowTriangles (const Standard_Boolean theToShowTriangles = Standard_False);
163
164   //! @return true if texture color modulation is turned on
165   Standard_Boolean TextureModulate() const { return myModulate; }
166
167 protected: //! @name overridden methods
168
169   //! Compute presentation with texture mapping support.
170   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
171                                         const Handle(Prs3d_Presentation)&           thePrs,
172                                         const Standard_Integer                      theMode);
173
174   Standard_EXPORT void updateAttributes (const Handle(Prs3d_Presentation)& thePrs);
175
176 protected: //! @name presentation fields
177
178   Handle(Graphic3d_Texture2Dmanual)  myTexture;
179   Handle(Graphic3d_AspectFillArea3d) myAspect;
180
181 protected: //! @name texture source fields
182
183   Handle(Image_PixMap)               myTexturePixMap;
184   TCollection_AsciiString            myTextureFile;
185   Graphic3d_NameOfTexture2D          myPredefTexture;
186
187 protected: //! @name texture mapping properties
188
189   Standard_Boolean                   myToMapTexture;
190   Standard_Boolean                   myModulate;
191   gp_Pnt2d                           myUVOrigin;
192   Standard_Boolean                   myIsCustomOrigin;
193   gp_Pnt2d                           myUVRepeat;
194   Standard_Boolean                   myToRepeat;
195   gp_Pnt2d                           myUVScale;
196   Standard_Boolean                   myToScale;
197   Standard_Boolean                   myToShowTriangles;
198
199 public:
200
201   DEFINE_STANDARD_RTTI (AIS_TexturedShape)
202
203 };
204
205 DEFINE_STANDARD_HANDLE (AIS_TexturedShape, AIS_Shape)
206
207 #endif // _AIS_TexturedShape_HeaderFile