Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-03 10:55:49

0001 // Created on: 2003-11-12
0002 // Created by: Alexander SOLOVYOV
0003 // Copyright (c) 2003-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 _MeshVS_NodalColorPrsBuilder_HeaderFile
0017 #define _MeshVS_NodalColorPrsBuilder_HeaderFile
0018 
0019 #include <Standard_Integer.hxx>
0020 #include <Quantity_Color.hxx>
0021 #include <NCollection_DataMap.hxx>
0022 #include <NCollection_Sequence.hxx>
0023 #include <MeshVS_PrsBuilder.hxx>
0024 #include <MeshVS_DisplayModeFlags.hxx>
0025 #include <MeshVS_BuilderPriority.hxx>
0026 #include <TColStd_PackedMapOfInteger.hxx>
0027 #include <NCollection_Array1.hxx>
0028 #include <NCollection_HArray1.hxx>
0029 
0030 class MeshVS_Mesh;
0031 class MeshVS_DataSource;
0032 class Graphic3d_Texture2D;
0033 class Graphic3d_ArrayOfPrimitives;
0034 
0035 //! This class provides methods to create presentation of nodes with assigned color.
0036 //! There are two ways of presentation building
0037 //! 1. Without using texture.
0038 //! In this case colors of nodes are specified with DataMapOfIntegerColor and presentation
0039 //! is built with gradient fill between these nodes (default behaviour)
0040 //! 2. Using texture.
0041 //! In this case presentation is built with spectrum filling between nodes. For example, if
0042 //! one node has blue color and second one has violet color, parameters of this class may be
0043 //! set to fill presentation between nodes with solar spectrum.
0044 //! Methods:
0045 //! UseTexture - activates/deactivates this way
0046 //! SetColorMap - sets colors used for generation of texture
0047 //! SetColorindices - specifies correspondence between node IDs and indices of colors from color map
0048 class MeshVS_NodalColorPrsBuilder : public MeshVS_PrsBuilder
0049 {
0050 
0051 public:
0052   Standard_EXPORT MeshVS_NodalColorPrsBuilder(
0053     const occ::handle<MeshVS_Mesh>&       Parent,
0054     const MeshVS_DisplayModeFlags&        Flags    = MeshVS_DMF_NodalColorDataPrs,
0055     const occ::handle<MeshVS_DataSource>& DS       = nullptr,
0056     const int                             Id       = -1,
0057     const MeshVS_BuilderPriority&         Priority = MeshVS_BP_NodalColor);
0058 
0059   //! Builds presentation of nodes with assigned color.
0060   Standard_EXPORT void Build(const occ::handle<Prs3d_Presentation>& Prs,
0061                              const TColStd_PackedMapOfInteger&      IDs,
0062                              TColStd_PackedMapOfInteger&            IDsToExclude,
0063                              const bool                             IsElement,
0064                              const int                              DisplayMode) const override;
0065 
0066   //! Returns map of colors assigned to nodes.
0067   Standard_EXPORT const NCollection_DataMap<int, Quantity_Color>& GetColors() const;
0068 
0069   //! Sets map of colors assigned to nodes.
0070   Standard_EXPORT void SetColors(const NCollection_DataMap<int, Quantity_Color>& Map);
0071 
0072   //! Returns true, if map isn't empty
0073   Standard_EXPORT bool HasColors() const;
0074 
0075   //! Returns color assigned to single node
0076   Standard_EXPORT bool GetColor(const int ID, Quantity_Color& theColor) const;
0077 
0078   //! Sets color assigned to single node
0079   Standard_EXPORT void SetColor(const int ID, const Quantity_Color& theColor);
0080 
0081   //! Specify whether texture must be used to build presentation
0082   Standard_EXPORT void UseTexture(const bool theToUse);
0083 
0084   //! Verify whether texture is used to build presentation
0085   Standard_EXPORT bool IsUseTexture() const;
0086 
0087   //! Set colors to be used for texrture presentation
0088   //! theColors - colors for valid coordinates (laying in range [0, 1])
0089   Standard_EXPORT void SetColorMap(const NCollection_Sequence<Quantity_Color>& theColors);
0090 
0091   //! Return colors used for texrture presentation
0092   Standard_EXPORT const NCollection_Sequence<Quantity_Color>& GetColorMap() const;
0093 
0094   //! Set color representing invalid texture coordinate
0095   //! (laying outside range [0, 1])
0096   Standard_EXPORT void SetInvalidColor(const Quantity_Color& theInvalidColor);
0097 
0098   //! Return color representing invalid texture coordinate
0099   //! (laying outside range [0, 1])
0100   Standard_EXPORT Quantity_Color GetInvalidColor() const;
0101 
0102   //! Specify correspondence between node IDs and texture coordinates (range [0, 1])
0103   Standard_EXPORT void SetTextureCoords(const NCollection_DataMap<int, double>& theMap);
0104 
0105   //! Get correspondence between node IDs and texture coordinates (range [0, 1])
0106   Standard_EXPORT const NCollection_DataMap<int, double>& GetTextureCoords() const;
0107 
0108   //! Specify correspondence between node ID and texture coordinate (range [0, 1])
0109   Standard_EXPORT void SetTextureCoord(const int theID, const double theCoord);
0110 
0111   //! Return correspondence between node IDs and texture coordinate (range [0, 1])
0112   Standard_EXPORT double GetTextureCoord(const int theID);
0113 
0114   //! Add to array polygons or polylines representing volume
0115   Standard_EXPORT void AddVolumePrs(
0116     const occ::handle<NCollection_HArray1<NCollection_Sequence<int>>>& theTopo,
0117     const NCollection_Array1<int>&                                     theNodes,
0118     const NCollection_Array1<double>&                                  theCoords,
0119     const occ::handle<Graphic3d_ArrayOfPrimitives>&                    theArray,
0120     const bool                                                         theIsShaded,
0121     const int                                                          theNbColors,
0122     const int                                                          theNbTexColors,
0123     const double                                                       theColorRatio) const;
0124 
0125   DEFINE_STANDARD_RTTIEXT(MeshVS_NodalColorPrsBuilder, MeshVS_PrsBuilder)
0126 
0127 private:
0128   //! Create texture in accordance with myTextureColorMap
0129   Standard_EXPORT occ::handle<Graphic3d_Texture2D> CreateTexture() const;
0130 
0131   NCollection_DataMap<int, Quantity_Color> myNodeColorMap;
0132   bool                                     myUseTexture;
0133   NCollection_Sequence<Quantity_Color>     myTextureColorMap;
0134   NCollection_DataMap<int, double>         myTextureCoords;
0135   Quantity_Color                           myInvalidColor;
0136 };
0137 
0138 #endif // _MeshVS_NodalColorPrsBuilder_HeaderFile