1 // Created on: 2013-06-25
2 // Created by: Dmitry BOBYLEV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Graphic3d_MarkerImage_H__
17 #define _Graphic3d_MarkerImage_H__
19 #include <Aspect_TypeOfMarker.hxx>
20 #include <Graphic3d_Vec4.hxx>
21 #include <TColStd_HArray1OfByte.hxx>
22 #include <TCollection_AsciiString.hxx>
26 //! This class is used to store bitmaps and images for markers rendering.
27 //! It can convert bitmap texture stored in TColStd_HArray1OfByte to Image_PixMap and vice versa.
28 class Graphic3d_MarkerImage : public Standard_Transient
30 DEFINE_STANDARD_RTTIEXT(Graphic3d_MarkerImage, Standard_Transient)
33 //! Returns a marker image for the marker of the specified type, scale and color.
34 Standard_EXPORT static Handle(Graphic3d_MarkerImage) StandardMarker (const Aspect_TypeOfMarker theMarkerType,
35 const Standard_ShortReal theScale,
36 const Graphic3d_Vec4& theColor);
40 //! Constructor from existing pixmap.
41 //! @param theImage [in] source image
42 //! @param theImageAlpha [in] colorless image
43 Standard_EXPORT Graphic3d_MarkerImage (const Handle(Image_PixMap)& theImage,
44 const Handle(Image_PixMap)& theImageAlpha = Handle(Image_PixMap)());
46 //! Creates marker image from array of bytes
47 //! (method for compatibility with old markers definition).
48 //! @param theBitMap [in] source bitmap stored as array of bytes
49 //! @param theWidth [in] number of bits in a row
50 //! @param theHeight [in] number of bits in a column
51 Standard_EXPORT Graphic3d_MarkerImage (const Handle(TColStd_HArray1OfByte)& theBitMap,
52 const Standard_Integer theWidth,
53 const Standard_Integer theHeight);
55 //! Return marker image.
56 //! If an instance of the class has been initialized with a bitmap, it will be converted to image.
57 Standard_EXPORT const Handle(Image_PixMap)& GetImage();
59 //! Return image alpha as grayscale image.
60 //! Note that if an instance of the class has been initialized with a bitmap
61 //! or with grayscale image this method will return exactly the same image as GetImage()
62 Standard_EXPORT const Handle(Image_PixMap)& GetImageAlpha();
64 //! Return an unique ID.
65 //! This ID will be used to manage resource in graphic driver.
66 Standard_EXPORT const TCollection_AsciiString& GetImageId() const;
68 //! Return an unique ID.
69 //! This ID will be used to manage resource in graphic driver.
70 Standard_EXPORT const TCollection_AsciiString& GetImageAlphaId() const;
72 //! Return texture size
73 Standard_EXPORT void GetTextureSize (Standard_Integer& theWidth,
74 Standard_Integer& theHeight) const;
76 //! Return TRUE if marker image has colors (e.g. RGBA and not grayscale).
77 Standard_EXPORT bool IsColoredImage() const;
79 //! Return marker image as array of bytes.
80 //! If an instance of the class has been initialized with image, it will be converted to bitmap based on the parameter theAlphaValue.
81 //! @param theAlphaValue pixels in the image that have alpha value greater than
82 //! or equal to this parameter will be stored in bitmap as "1",
83 //! others will be stored as "0"
84 //! @param theIsTopDown [in] flag indicating expected rows order in returned bitmap, which is bottom-up by default
85 Standard_EXPORT Handle(TColStd_HArray1OfByte) GetBitMapArray (const Standard_Real theAlphaValue = 0.5,
86 const Standard_Boolean theIsTopDown = false) const;
90 TCollection_AsciiString myImageId; //!< resource identifier
91 TCollection_AsciiString myImageAlphaId; //!< resource identifier
92 Handle(TColStd_HArray1OfByte) myBitMap; //!< bytes array with bitmap definition (for compatibility with old code)
93 Handle(Image_PixMap) myImage; //!< full-color marker definition
94 Handle(Image_PixMap) myImageAlpha; //!< alpha-color marker definition (for dynamic hi-lighting)
95 Standard_Integer myMargin; //!< extra margin from boundaries for bitmap -> point sprite conversion, 1 px by default
96 Standard_Integer myWidth; //!< marker width
97 Standard_Integer myHeight; //!< marker height
101 DEFINE_STANDARD_HANDLE (Graphic3d_MarkerImage, Standard_Transient)
103 #endif // _Graphic3d_MarkerImage_H__