Loading files
3d097a032This file is pinned to the selected release. Download the original to open it in your design tool.
// Created on: 2013-06-25
// Created by: Dmitry BOBYLEV
// Copyright (c) 2013-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef Graphic3d_MarkerImage_HeaderFile
#define Graphic3d_MarkerImage_HeaderFile
#include <Aspect_TypeOfMarker.hxx>
#include <NCollection_Vec4.hxx>
#include <Standard_TypeDef.hxx>
#include <NCollection_Array1.hxx>
#include <NCollection_HArray1.hxx>
#include <TCollection_AsciiString.hxx>
class Image_PixMap;
//! This class is used to store bitmaps and images for markers rendering.
//! It can convert bitmap texture stored in NCollection_HArray1<uint8_t> to Image_PixMap and vice
//! versa.
class Graphic3d_MarkerImage : public Standard_Transient
{
DEFINE_STANDARD_RTTIEXT(Graphic3d_MarkerImage, Standard_Transient)
public:
//! Returns a marker image for the marker of the specified type, scale and color.
Standard_EXPORT static occ::handle<Graphic3d_MarkerImage> StandardMarker(
const Aspect_TypeOfMarker theMarkerType,
const float theScale,
const NCollection_Vec4<float>& theColor);
public:
//! Constructor from existing pixmap.
//! @param[in] theImage source image
//! @param[in] theImageAlpha colorless image
Standard_EXPORT Graphic3d_MarkerImage(
const occ::handle<Image_PixMap>& theImage,
const occ::handle<Image_PixMap>& theImageAlpha = occ::handle<Image_PixMap>());
//! Creates marker image from array of bytes
//! (method for compatibility with old markers definition).
//! @param[in] theBitMap source bitmap stored as array of bytes
//! @param[in] theWidth number of bits in a row
//! @param[in] theHeight number of bits in a column
Standard_EXPORT Graphic3d_MarkerImage(const occ::handle<NCollection_HArray1<uint8_t>>& theBitMap,
const int theWidth,
const int theHeight);
//! Return marker image.
//! If an instance of the class has been initialized with a bitmap, it will be converted to image.
Standard_EXPORT const occ::handle<Image_PixMap>& GetImage();
//! Return image alpha as grayscale image.
//! Note that if an instance of the class has been initialized with a bitmap
//! or with grayscale image this method will return exactly the same image as GetImage()
Standard_EXPORT const occ::handle<Image_PixMap>& GetImageAlpha();
//! Return an unique ID.
//! This ID will be used to manage resource in graphic driver.
Standard_EXPORT const TCollection_AsciiString& GetImageId() const;
//! Return an unique ID.
//! This ID will be used to manage resource in graphic driver.
Standard_EXPORT const TCollection_AsciiString& GetImageAlphaId() const;
//! Return texture size
Standard_EXPORT void GetTextureSize(int& theWidth, int& theHeight) const;
//! Return TRUE if marker image has colors (e.g. RGBA and not grayscale).
Standard_EXPORT bool IsColoredImage() const;
//! Return marker image as array of bytes.
//! If an instance of the class has been initialized with image, it will be converted to bitmap
//! based on the parameter theAlphaValue.
//! @param theAlphaValue pixels in the image that have alpha value greater than
//! or equal to this parameter will be stored in bitmap as "1",
//! others will be stored as "0"
//! @param[in] theIsTopDown flag indicating expected rows order in returned bitmap, which is
//! bottom-up by default
Standard_EXPORT occ::handle<NCollection_HArray1<uint8_t>> GetBitMapArray(
const double theAlphaValue = 0.5,
const bool theIsTopDown = false) const;
protected:
//! Constructor from existing pixmap with predefined ids.
Standard_EXPORT Graphic3d_MarkerImage(
const TCollection_AsciiString& theId,
const TCollection_AsciiString& theAlphaId,
const occ::handle<Image_PixMap>& theImage,
const occ::handle<Image_PixMap>& theImageAlpha = occ::handle<Image_PixMap>());
private:
TCollection_AsciiString myImageId; //!< resource identifier
TCollection_AsciiString myImageAlphaId; //!< resource identifier
// clang-format off
occ::handle<NCollection_HArray1<uint8_t>> myBitMap; //!< bytes array with bitmap definition (for compatibility with old code)
occ::handle<Image_PixMap> myImage; //!< full-color marker definition
occ::handle<Image_PixMap> myImageAlpha; //!< alpha-color marker definition (for dynamic hi-lighting)
int myMargin; //!< extra margin from boundaries for bitmap -> point sprite conversion, 1 px by default
// clang-format on
int myWidth; //!< marker width
int myHeight; //!< marker height
};
#endif // _Graphic3d_MarkerImage_H__