0022777: Visualization - Unsafe way to get attribute values from MeshVS_Drawer
[occt.git] / src / MeshVS / MeshVS_NodalColorPrsBuilder.hxx
1 // Created on: 2003-11-12
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2003-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 _MeshVS_NodalColorPrsBuilder_HeaderFile
17 #define _MeshVS_NodalColorPrsBuilder_HeaderFile
18
19 #include <MeshVS_DataMapOfIntegerColor.hxx>
20 #include <Aspect_SequenceOfColor.hxx>
21 #include <TColStd_DataMapOfIntegerReal.hxx>
22 #include <Quantity_Color.hxx>
23 #include <MeshVS_PrsBuilder.hxx>
24 #include <MeshVS_DisplayModeFlags.hxx>
25 #include <MeshVS_BuilderPriority.hxx>
26 #include <TColStd_PackedMapOfInteger.hxx>
27 #include <MeshVS_HArray1OfSequenceOfInteger.hxx>
28 #include <TColStd_Array1OfInteger.hxx>
29 #include <TColStd_Array1OfReal.hxx>
30
31 class MeshVS_Mesh;
32 class MeshVS_DataSource;
33 class Quantity_Color;
34 class Graphic3d_Texture2D;
35 class Graphic3d_ArrayOfPrimitives;
36
37 DEFINE_STANDARD_HANDLE(MeshVS_NodalColorPrsBuilder, MeshVS_PrsBuilder)
38
39 //! This class provides methods to create presentation of nodes with assigned color.
40 //! There are two ways of presentation building
41 //! 1. Without using texture.
42 //! In this case colors of nodes are specified with DataMapOfIntegerColor and presentation
43 //! is built with gradient fill between these nodes (default behaviour)
44 //! 2. Using texture.
45 //! In this case presentation is built with spectrum filling between nodes. For example, if
46 //! one node has blue color and second one has violet color, parameters of this class may be
47 //! set to fill presentation between nodes with solar spectrum.
48 //! Methods:
49 //! UseTexture - activates/deactivates this way
50 //! SetColorMap - sets colors used for generation of texture
51 //! SetColorindices - specifies correspondence between node IDs and indices of colors from color map
52 class MeshVS_NodalColorPrsBuilder : public MeshVS_PrsBuilder
53 {
54
55 public:
56
57   
58   Standard_EXPORT MeshVS_NodalColorPrsBuilder(const Handle(MeshVS_Mesh)& Parent, const MeshVS_DisplayModeFlags& Flags = MeshVS_DMF_NodalColorDataPrs, const Handle(MeshVS_DataSource)& DS = 0, const Standard_Integer Id = -1, const MeshVS_BuilderPriority& Priority = MeshVS_BP_NodalColor);
59   
60   //! Builds presentation of nodes with assigned color.
61   Standard_EXPORT virtual void Build (const Handle(Prs3d_Presentation)& Prs, const TColStd_PackedMapOfInteger& IDs, TColStd_PackedMapOfInteger& IDsToExclude, const Standard_Boolean IsElement, const Standard_Integer DisplayMode) const Standard_OVERRIDE;
62   
63   //! Returns map of colors assigned to nodes.
64   Standard_EXPORT const MeshVS_DataMapOfIntegerColor& GetColors() const;
65   
66   //! Sets map of colors assigned to nodes.
67   Standard_EXPORT void SetColors (const MeshVS_DataMapOfIntegerColor& Map);
68   
69   //! Returns true, if map isn't empty
70   Standard_EXPORT Standard_Boolean HasColors() const;
71   
72   //! Returns color assigned to single node
73   Standard_EXPORT Standard_Boolean GetColor (const Standard_Integer ID, Quantity_Color& theColor) const;
74   
75   //! Sets color assigned to single node
76   Standard_EXPORT void SetColor (const Standard_Integer ID, const Quantity_Color& theColor);
77   
78   //! Specify whether texture must be used to build presentation
79   Standard_EXPORT void UseTexture (const Standard_Boolean theToUse);
80   
81   //! Verify whether texture is used to build presentation
82   Standard_EXPORT Standard_Boolean IsUseTexture() const;
83   
84   //! Set colors to be used for texrture presentation
85   //! theColors - colors for valid coordinates (laying in range [0, 1])
86   Standard_EXPORT void SetColorMap (const Aspect_SequenceOfColor& theColors);
87   
88   //! Return colors used for texrture presentation
89   Standard_EXPORT const Aspect_SequenceOfColor& GetColorMap() const;
90   
91   //! Set color representing invalid texture coordinate
92   //! (laying outside range [0, 1])
93   Standard_EXPORT void SetInvalidColor (const Quantity_Color& theInvalidColor);
94   
95   //! Return color representing invalid texture coordinate
96   //! (laying outside range [0, 1])
97   Standard_EXPORT Quantity_Color GetInvalidColor() const;
98   
99   //! Specify correspondence between node IDs and texture coordinates (range [0, 1])
100   Standard_EXPORT void SetTextureCoords (const TColStd_DataMapOfIntegerReal& theMap);
101   
102   //! Get correspondence between node IDs and texture coordinates (range [0, 1])
103   Standard_EXPORT const TColStd_DataMapOfIntegerReal& GetTextureCoords() const;
104   
105   //! Specify correspondence between node ID and texture coordinate (range [0, 1])
106   Standard_EXPORT void SetTextureCoord (const Standard_Integer theID, const Standard_Real theCoord);
107   
108   //! Return correspondence between node IDs and texture coordinate (range [0, 1])
109   Standard_EXPORT Standard_Real GetTextureCoord (const Standard_Integer theID);
110   
111   //! Add to array polygons or polylines representing volume
112   Standard_EXPORT void AddVolumePrs (const Handle(MeshVS_HArray1OfSequenceOfInteger)& theTopo, const TColStd_Array1OfInteger& theNodes, const TColStd_Array1OfReal& theCoords, const Handle(Graphic3d_ArrayOfPrimitives)& theArray, const Standard_Boolean theIsShaded, const Standard_Integer theNbColors, const Standard_Integer theNbTexColors, const Standard_Real theColorRatio) const;
113
114
115
116
117   DEFINE_STANDARD_RTTIEXT(MeshVS_NodalColorPrsBuilder,MeshVS_PrsBuilder)
118
119 protected:
120
121
122
123
124 private:
125
126   
127   //! Create texture in accordance with myTextureColorMap
128   Standard_EXPORT Handle(Graphic3d_Texture2D) CreateTexture() const;
129
130   MeshVS_DataMapOfIntegerColor myNodeColorMap;
131   Standard_Boolean myUseTexture;
132   Aspect_SequenceOfColor myTextureColorMap;
133   TColStd_DataMapOfIntegerReal myTextureCoords;
134   Quantity_Color myInvalidColor;
135
136
137 };
138
139
140
141
142
143
144
145 #endif // _MeshVS_NodalColorPrsBuilder_HeaderFile