Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:48

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