f376ac72 |
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> |
ec357c5c |
23 | #include <Standard_Type.hxx> |
f376ac72 |
24 | #include <TCollection_AsciiString.hxx> |
cb389a77 |
25 | #include <Graphic3d_AspectFillArea3d.hxx> |
26 | #include <Graphic3d_Texture2Dmanual.hxx> |
27 | #include <Prs3d_Presentation.hxx> |
28 | #include <PrsMgr_PresentationManager3d.hxx> |
f376ac72 |
29 | |
30 | class Graphic3d_AspectFillArea3d; |
31 | class Graphic3d_Texture2Dmanual; |
f376ac72 |
32 | |
33 | //! This class allows to map textures on shapes. |
34 | //! Presentations modes AIS_WireFrame (0) and AIS_Shaded (1) behave in the same manner as in AIS_Shape, |
35 | //! whilst new modes 2 (bounding box) and 3 (texture mapping) extends it functionality. |
36 | //! |
37 | //! The texture itself is parametrized in (0,1)x(0,1). |
38 | //! Each face of a shape located in UV space is provided with these parameters: |
39 | //! - Umin - starting position in U |
40 | //! - Umax - ending position in U |
41 | //! - Vmin - starting position in V |
42 | //! - Vmax - ending position in V |
43 | //! Each face is triangulated and a texel is assigned to each node. |
44 | //! Facets are then filled using a linear interpolation of texture between each 'three texels'. |
45 | //! User can act on: |
46 | //! - the number of occurrences of the texture on the face |
47 | //! - the position of the origin of the texture |
48 | //! - the scale factor of the texture |
49 | class AIS_TexturedShape : public AIS_Shape |
50 | { |
51 | |
52 | public: //! @name main methods |
53 | |
54 | //! Initializes the textured shape. |
55 | Standard_EXPORT AIS_TexturedShape (const TopoDS_Shape& theShape); |
56 | |
57 | //! Sets the texture source. <theTextureFileName> can specify path to texture image or one of the standard predefined textures. |
58 | //! The accepted file types are those used in Image_AlienPixMap with extensions such as rgb, png, jpg and more. |
59 | //! To specify the standard predefined texture, the <theTextureFileName> should contain integer - the Graphic3d_NameOfTexture2D enumeration index. |
60 | //! Setting texture source using this method resets the source pixmap (if was set previously). |
61 | Standard_EXPORT virtual void SetTextureFileName (const TCollection_AsciiString& theTextureFileName); |
62 | |
63 | //! Sets the texture source. <theTexturePixMap> specifies image data. |
64 | //! Please note that the data should be in Bottom-Up order, the flag of Image_PixMap::IsTopDown() will be ignored by graphic driver. |
65 | //! Setting texture source using this method resets the source by filename (if was set previously). |
a13f2dc4 |
66 | Standard_EXPORT virtual void SetTexturePixMap (const Handle(Image_PixMap)& theTexturePixMap); |
f376ac72 |
67 | |
68 | //! @return flag to control texture mapping (for presentation mode 3) |
69 | Standard_Boolean TextureMapState() const { return myToMapTexture; } |
70 | |
71 | //! Enables texture mapping |
72 | Standard_EXPORT void SetTextureMapOn(); |
73 | |
74 | //! Disables texture mapping |
75 | Standard_EXPORT void SetTextureMapOff(); |
76 | |
77 | //! @return path to the texture file |
78 | Standard_CString TextureFile() const { return myTextureFile.ToCString(); } |
79 | |
80 | //! @return the source pixmap for texture map |
81 | const Handle(Image_PixMap)& TexturePixMap() const { return myTexturePixMap; } |
82 | |
83 | public: //! @name methods to alter texture mapping properties |
84 | |
85 | //! Use this method to display the textured shape without recomputing the whole presentation. |
86 | //! Use this method when ONLY the texture content has been changed. |
87 | //! If other parameters (ie: scale factors, texture origin, texture repeat...) have changed, the whole presentation has to be recomputed: |
88 | //! @code |
89 | //! if (myShape->DisplayMode() == 3) |
90 | //! { |
91 | //! myAISContext->RecomputePrsOnly (myShape); |
92 | //! } |
93 | //! else |
94 | //! { |
95 | //! myAISContext->SetDisplayMode (myShape, 3, Standard_False); |
96 | //! myAISContext->Display (myShape, Standard_True); |
97 | //! } |
98 | //! @endcode |
99 | Standard_EXPORT void UpdateAttributes(); |
100 | |
735dc1d2 |
101 | //! Sets the color. |
79104795 |
102 | Standard_EXPORT virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE; |
7389f96d |
103 | |
735dc1d2 |
104 | //! Removes settings for the color. |
79104795 |
105 | Standard_EXPORT virtual void UnsetColor() Standard_OVERRIDE; |
735dc1d2 |
106 | |
107 | //! Sets the material aspect. |
79104795 |
108 | Standard_EXPORT virtual void SetMaterial (const Graphic3d_MaterialAspect& theAspect) Standard_OVERRIDE; |
735dc1d2 |
109 | |
110 | //! Removes settings for material aspect. |
79104795 |
111 | Standard_EXPORT virtual void UnsetMaterial() Standard_OVERRIDE; |
735dc1d2 |
112 | |
f376ac72 |
113 | //! Enables texture modulation |
114 | Standard_EXPORT void EnableTextureModulate(); |
115 | |
116 | //! Disables texture modulation |
117 | Standard_EXPORT void DisableTextureModulate(); |
118 | |
119 | //! @return texture repeat flag |
120 | Standard_Boolean TextureRepeat() const { return myToRepeat; } |
121 | |
122 | //! @return texture repeat U value |
123 | Standard_Real URepeat() const { return myUVRepeat.X(); } |
124 | |
125 | //! @return texture repeat V value |
126 | Standard_Real VRepeat() const { return myUVRepeat.Y(); } |
127 | |
128 | //! Sets the number of occurrences of the texture on each face. The texture itself is parameterized in (0,1) by (0,1). |
129 | //! Each face of the shape to be textured is parameterized in UV space (Umin,Umax) by (Vmin,Vmax). |
130 | //! If RepeatYN is set to false, texture coordinates are clamped in the range (0,1)x(0,1) of the face. |
131 | Standard_EXPORT void SetTextureRepeat (const Standard_Boolean theToRepeat, |
132 | const Standard_Real theURepeat = 1.0, |
133 | const Standard_Real theVRepeat = 1.0); |
134 | |
135 | //! @return true if texture UV origin has been modified |
136 | Standard_Boolean TextureOrigin() const { return myIsCustomOrigin; } |
137 | |
138 | //! @return texture origin U position (0.0 by default) |
139 | Standard_Real TextureUOrigin() const { return myUVOrigin.X(); } |
140 | |
141 | //! @return texture origin V position (0.0 by default) |
142 | Standard_Real TextureVOrigin() const { return myUVOrigin.Y(); } |
143 | |
144 | //! Use this method to change the origin of the texture. The texel (0,0) will be mapped to the surface (UOrigin,VOrigin) |
145 | Standard_EXPORT void SetTextureOrigin (const Standard_Boolean theToSetTextureOrigin, |
146 | const Standard_Real theUOrigin = 0.0, |
147 | const Standard_Real theVOrigin = 0.0); |
148 | |
149 | //! @return true if scale factor should be applied to texture mapping |
150 | Standard_Boolean TextureScale() const { return myToScale; } |
151 | |
152 | //! @return scale factor for U coordinate (1.0 by default) |
153 | Standard_Real TextureScaleU() const { return myUVScale.X(); } |
154 | |
155 | //! @return scale factor for V coordinate (1.0 by default) |
156 | Standard_Real TextureScaleV() const { return myUVScale.Y(); } |
157 | |
158 | //! Use this method to scale the texture (percent of the face). |
159 | //! You can specify a scale factor for both U and V. |
160 | //! Example: if you set ScaleU and ScaleV to 0.5 and you enable texture repeat, |
161 | //! the texture will appear twice on the face in each direction. |
162 | Standard_EXPORT void SetTextureScale (const Standard_Boolean theToSetTextureScale, |
163 | const Standard_Real theScaleU = 1.0, |
164 | const Standard_Real theScaleV = 1.0); |
165 | |
166 | //! @return true if displaying of triangles is requested |
167 | Standard_Boolean ShowTriangles() const { return myToShowTriangles; } |
168 | |
169 | //! Use this method to show the triangulation of the shape (for debugging etc.). |
7ccd27ca |
170 | Standard_EXPORT void ShowTriangles (const Standard_Boolean theToShowTriangles); |
f376ac72 |
171 | |
172 | //! @return true if texture color modulation is turned on |
173 | Standard_Boolean TextureModulate() const { return myModulate; } |
174 | |
175 | protected: //! @name overridden methods |
176 | |
177 | //! Compute presentation with texture mapping support. |
178 | Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
179 | const Handle(Prs3d_Presentation)& thePrs, |
79104795 |
180 | const Standard_Integer theMode) Standard_OVERRIDE; |
f376ac72 |
181 | |
8e3ebc7a |
182 | Standard_EXPORT void updateAttributes (const Handle(Prs3d_Presentation)& thePrs); |
183 | |
f376ac72 |
184 | protected: //! @name presentation fields |
185 | |
186 | Handle(Graphic3d_Texture2Dmanual) myTexture; |
187 | Handle(Graphic3d_AspectFillArea3d) myAspect; |
188 | |
189 | protected: //! @name texture source fields |
190 | |
191 | Handle(Image_PixMap) myTexturePixMap; |
192 | TCollection_AsciiString myTextureFile; |
193 | Graphic3d_NameOfTexture2D myPredefTexture; |
194 | |
195 | protected: //! @name texture mapping properties |
196 | |
197 | Standard_Boolean myToMapTexture; |
198 | Standard_Boolean myModulate; |
f376ac72 |
199 | Standard_Boolean myIsCustomOrigin; |
f376ac72 |
200 | Standard_Boolean myToRepeat; |
f376ac72 |
201 | Standard_Boolean myToScale; |
202 | Standard_Boolean myToShowTriangles; |
203 | |
204 | public: |
205 | |
92efcf78 |
206 | DEFINE_STANDARD_RTTIEXT(AIS_TexturedShape,AIS_Shape) |
f376ac72 |
207 | |
208 | }; |
209 | |
210 | DEFINE_STANDARD_HANDLE (AIS_TexturedShape, AIS_Shape) |
211 | |
212 | #endif // _AIS_TexturedShape_HeaderFile |