0027919: Visualization - support multiple transformation persistence groups within...
[occt.git] / src / Graphic3d / Graphic3d_MarkerImage.hxx
1 // Created on: 2013-06-25
2 // Created by: Dmitry BOBYLEV
3 // Copyright (c) 2013-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 _Graphic3d_MarkerImage_H__
17 #define _Graphic3d_MarkerImage_H__
18
19 #include <Aspect_TypeOfMarker.hxx>
20 #include <Graphic3d_Vec4.hxx>
21 #include <TColStd_HArray1OfByte.hxx>
22 #include <TCollection_AsciiString.hxx>
23
24 class Image_PixMap;
25
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
29 {
30   DEFINE_STANDARD_RTTIEXT(Graphic3d_MarkerImage, Standard_Transient)
31 public:
32
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);
37
38 public:
39
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)());
45
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);
54
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();
58
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();
63
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;
67
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;
71
72   //! Return texture size
73   Standard_EXPORT void GetTextureSize (Standard_Integer& theWidth,
74                                        Standard_Integer& theHeight) const;
75
76   //! Return TRUE if marker image has colors (e.g. RGBA and not grayscale).
77   Standard_EXPORT bool IsColoredImage() const;
78
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;
87
88 protected:
89
90   //! Constructor from existing pixmap with predefined ids.
91   Standard_EXPORT Graphic3d_MarkerImage (const TCollection_AsciiString& theId,
92                                          const TCollection_AsciiString& theAlphaId,
93                                          const Handle(Image_PixMap)& theImage,
94                                          const Handle(Image_PixMap)& theImageAlpha = Handle(Image_PixMap)());
95
96 private:
97
98   TCollection_AsciiString       myImageId;      //!< resource identifier
99   TCollection_AsciiString       myImageAlphaId; //!< resource identifier
100   Handle(TColStd_HArray1OfByte) myBitMap;       //!< bytes array with bitmap definition (for compatibility with old code)
101   Handle(Image_PixMap)          myImage;        //!< full-color  marker definition
102   Handle(Image_PixMap)          myImageAlpha;   //!< alpha-color marker definition (for dynamic hi-lighting)
103   Standard_Integer              myMargin;       //!< extra margin from boundaries for bitmap -> point sprite conversion, 1 px by default
104   Standard_Integer              myWidth;        //!< marker width
105   Standard_Integer              myHeight;       //!< marker height
106
107 };
108
109 DEFINE_STANDARD_HANDLE (Graphic3d_MarkerImage, Standard_Transient)
110
111 #endif // _Graphic3d_MarkerImage_H__