Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-30 09:03:45

0001 // Created on: 2013-06-25
0002 // Created by: Dmitry BOBYLEV
0003 // Copyright (c) 2013-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 Graphic3d_MarkerImage_HeaderFile
0017 #define Graphic3d_MarkerImage_HeaderFile
0018 
0019 #include <Aspect_TypeOfMarker.hxx>
0020 #include <NCollection_Vec4.hxx>
0021 #include <Standard_TypeDef.hxx>
0022 #include <NCollection_Array1.hxx>
0023 #include <NCollection_HArray1.hxx>
0024 #include <TCollection_AsciiString.hxx>
0025 
0026 class Image_PixMap;
0027 
0028 //! This class is used to store bitmaps and images for markers rendering.
0029 //! It can convert bitmap texture stored in NCollection_HArray1<uint8_t> to Image_PixMap and vice
0030 //! versa.
0031 class Graphic3d_MarkerImage : public Standard_Transient
0032 {
0033   DEFINE_STANDARD_RTTIEXT(Graphic3d_MarkerImage, Standard_Transient)
0034 public:
0035   //! Returns a marker image for the marker of the specified type, scale and color.
0036   Standard_EXPORT static occ::handle<Graphic3d_MarkerImage> StandardMarker(
0037     const Aspect_TypeOfMarker      theMarkerType,
0038     const float                    theScale,
0039     const NCollection_Vec4<float>& theColor);
0040 
0041 public:
0042   //! Constructor from existing pixmap.
0043   //! @param[in] theImage  source image
0044   //! @param[in] theImageAlpha  colorless image
0045   Standard_EXPORT Graphic3d_MarkerImage(
0046     const occ::handle<Image_PixMap>& theImage,
0047     const occ::handle<Image_PixMap>& theImageAlpha = occ::handle<Image_PixMap>());
0048 
0049   //! Creates marker image from array of bytes
0050   //! (method for compatibility with old markers definition).
0051   //! @param[in] theBitMap  source bitmap stored as array of bytes
0052   //! @param[in] theWidth   number of bits in a row
0053   //! @param[in] theHeight  number of bits in a column
0054   Standard_EXPORT Graphic3d_MarkerImage(const occ::handle<NCollection_HArray1<uint8_t>>& theBitMap,
0055                                         const int                                        theWidth,
0056                                         const int                                        theHeight);
0057 
0058   //! Return marker image.
0059   //! If an instance of the class has been initialized with a bitmap, it will be converted to image.
0060   Standard_EXPORT const occ::handle<Image_PixMap>& GetImage();
0061 
0062   //! Return image alpha as grayscale image.
0063   //! Note that if an instance of the class has been initialized with a bitmap
0064   //! or with grayscale image this method will return exactly the same image as GetImage()
0065   Standard_EXPORT const occ::handle<Image_PixMap>& GetImageAlpha();
0066 
0067   //! Return an unique ID.
0068   //! This ID will be used to manage resource in graphic driver.
0069   Standard_EXPORT const TCollection_AsciiString& GetImageId() const;
0070 
0071   //! Return an unique ID.
0072   //! This ID will be used to manage resource in graphic driver.
0073   Standard_EXPORT const TCollection_AsciiString& GetImageAlphaId() const;
0074 
0075   //! Return texture size
0076   Standard_EXPORT void GetTextureSize(int& theWidth, int& theHeight) const;
0077 
0078   //! Return TRUE if marker image has colors (e.g. RGBA and not grayscale).
0079   Standard_EXPORT bool IsColoredImage() const;
0080 
0081   //! Return marker image as array of bytes.
0082   //! If an instance of the class has been initialized with image, it will be converted to bitmap
0083   //! based on the parameter theAlphaValue.
0084   //! @param theAlphaValue pixels in the image that have alpha value greater than
0085   //!                      or equal to this parameter will be stored in bitmap as "1",
0086   //!                      others will be stored as "0"
0087   //! @param[in] theIsTopDown  flag indicating expected rows order in returned bitmap, which is
0088   //! bottom-up by default
0089   Standard_EXPORT occ::handle<NCollection_HArray1<uint8_t>> GetBitMapArray(
0090     const double theAlphaValue = 0.5,
0091     const bool   theIsTopDown  = false) const;
0092 
0093 protected:
0094   //! Constructor from existing pixmap with predefined ids.
0095   Standard_EXPORT Graphic3d_MarkerImage(
0096     const TCollection_AsciiString&   theId,
0097     const TCollection_AsciiString&   theAlphaId,
0098     const occ::handle<Image_PixMap>& theImage,
0099     const occ::handle<Image_PixMap>& theImageAlpha = occ::handle<Image_PixMap>());
0100 
0101 private:
0102   TCollection_AsciiString myImageId;      //!< resource identifier
0103   TCollection_AsciiString myImageAlphaId; //!< resource identifier
0104                                           // clang-format off
0105   occ::handle<NCollection_HArray1<uint8_t>> myBitMap;       //!< bytes array with bitmap definition (for compatibility with old code)
0106   occ::handle<Image_PixMap>          myImage;        //!< full-color  marker definition
0107   occ::handle<Image_PixMap>          myImageAlpha;   //!< alpha-color marker definition (for dynamic hi-lighting)
0108   int              myMargin;       //!< extra margin from boundaries for bitmap -> point sprite conversion, 1 px by default
0109                // clang-format on
0110   int myWidth;  //!< marker width
0111   int myHeight; //!< marker height
0112 };
0113 
0114 #endif // _Graphic3d_MarkerImage_H__