mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0028205: Visualization - add functionality for dumping results of detection algorithms into image
StdSelect_ViewerSelector3d::ToPixMap() - added new method for dumping detection results into an image.
This commit is contained in:
@@ -19,9 +19,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Image_PixMap,Standard_Transient)
|
||||
|
||||
// =======================================================================
|
||||
@@ -339,6 +336,136 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
|
||||
return Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetPixelColor
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Image_PixMap::SetPixelColor (const Standard_Integer theX,
|
||||
const Standard_Integer theY,
|
||||
const NCollection_Vec4<float>& theColor)
|
||||
{
|
||||
if (IsEmpty()
|
||||
|| theX < 0 || Standard_Size(theX) >= SizeX()
|
||||
|| theY < 0 || Standard_Size(theY) >= SizeY())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (myImgFormat)
|
||||
{
|
||||
case ImgGrayF:
|
||||
{
|
||||
ChangeValue<Standard_ShortReal> (theY, theX) = theColor.r();
|
||||
return;
|
||||
}
|
||||
case ImgAlphaF:
|
||||
{
|
||||
ChangeValue<Standard_ShortReal> (theY, theX) = theColor.a();
|
||||
return;
|
||||
}
|
||||
case ImgRGBAF:
|
||||
{
|
||||
Image_ColorRGBAF& aPixel = ChangeValue<Image_ColorRGBAF> (theY, theX);
|
||||
aPixel.r() = theColor.r();
|
||||
aPixel.g() = theColor.g();
|
||||
aPixel.b() = theColor.b();
|
||||
aPixel.a() = theColor.a();
|
||||
return;
|
||||
}
|
||||
case ImgBGRAF:
|
||||
{
|
||||
Image_ColorBGRAF& aPixel = ChangeValue<Image_ColorBGRAF> (theY, theX);
|
||||
aPixel.r() = theColor.r();
|
||||
aPixel.g() = theColor.g();
|
||||
aPixel.b() = theColor.b();
|
||||
aPixel.a() = theColor.a();
|
||||
return;
|
||||
}
|
||||
case ImgRGBF:
|
||||
{
|
||||
Image_ColorRGBF& aPixel = ChangeValue<Image_ColorRGBF> (theY, theX);
|
||||
aPixel.r() = theColor.r();
|
||||
aPixel.g() = theColor.g();
|
||||
aPixel.b() = theColor.b();
|
||||
return;
|
||||
}
|
||||
case ImgBGRF:
|
||||
{
|
||||
Image_ColorBGRF& aPixel = ChangeValue<Image_ColorBGRF> (theY, theX);
|
||||
aPixel.r() = theColor.r();
|
||||
aPixel.g() = theColor.g();
|
||||
aPixel.b() = theColor.b();
|
||||
return;
|
||||
}
|
||||
case ImgRGBA:
|
||||
{
|
||||
Image_ColorRGBA& aPixel = ChangeValue<Image_ColorRGBA> (theY, theX);
|
||||
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
|
||||
aPixel.g() = Standard_Byte(theColor.g() * 255.0f);
|
||||
aPixel.b() = Standard_Byte(theColor.b() * 255.0f);
|
||||
aPixel.a() = Standard_Byte(theColor.a() * 255.0f);
|
||||
return;
|
||||
}
|
||||
case ImgBGRA:
|
||||
{
|
||||
Image_ColorBGRA& aPixel = ChangeValue<Image_ColorBGRA> (theY, theX);
|
||||
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
|
||||
aPixel.g() = Standard_Byte(theColor.g() * 255.0f);
|
||||
aPixel.b() = Standard_Byte(theColor.b() * 255.0f);
|
||||
aPixel.a() = Standard_Byte(theColor.a() * 255.0f);
|
||||
return;
|
||||
}
|
||||
case ImgRGB32:
|
||||
{
|
||||
Image_ColorRGB32& aPixel = ChangeValue<Image_ColorRGB32> (theY, theX);
|
||||
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
|
||||
aPixel.g() = Standard_Byte(theColor.g() * 255.0f);
|
||||
aPixel.b() = Standard_Byte(theColor.b() * 255.0f);
|
||||
aPixel.a_() = 255;
|
||||
return;
|
||||
}
|
||||
case ImgBGR32:
|
||||
{
|
||||
Image_ColorBGR32& aPixel = ChangeValue<Image_ColorBGR32> (theY, theX);
|
||||
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
|
||||
aPixel.g() = Standard_Byte(theColor.g() * 255.0f);
|
||||
aPixel.b() = Standard_Byte(theColor.b() * 255.0f);
|
||||
aPixel.a_() = 255;
|
||||
return;
|
||||
}
|
||||
case ImgRGB:
|
||||
{
|
||||
Image_ColorRGB& aPixel = ChangeValue<Image_ColorRGB> (theY, theX);
|
||||
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
|
||||
aPixel.g() = Standard_Byte(theColor.g() * 255.0f);
|
||||
aPixel.b() = Standard_Byte(theColor.b() * 255.0f);
|
||||
return;
|
||||
}
|
||||
case ImgBGR:
|
||||
{
|
||||
Image_ColorBGR& aPixel = ChangeValue<Image_ColorBGR> (theY, theX);
|
||||
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
|
||||
aPixel.g() = Standard_Byte(theColor.g() * 255.0f);
|
||||
aPixel.b() = Standard_Byte(theColor.b() * 255.0f);
|
||||
return;
|
||||
}
|
||||
case ImgGray:
|
||||
{
|
||||
ChangeValue<Standard_Byte> (theY, theX) = Standard_Byte(theColor.r() * 255.0f);
|
||||
return;
|
||||
}
|
||||
case ImgAlpha:
|
||||
{
|
||||
ChangeValue<Standard_Byte> (theY, theX) = Standard_Byte(theColor.a() * 255.0f);
|
||||
return;
|
||||
}
|
||||
case ImgUNKNOWN:
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SwapRgbaBgra
|
||||
// purpose :
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
#include <Image_PixMapData.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <Quantity_Color.hxx>
|
||||
#include <Quantity_ColorRGBA.hxx>
|
||||
|
||||
//! Class represents packed image plane.
|
||||
class Image_PixMap : public Standard_Transient
|
||||
@@ -119,8 +119,9 @@ public: // high-level API
|
||||
Standard_EXPORT virtual ~Image_PixMap();
|
||||
|
||||
//! Returns the pixel color. This function is relatively slow.
|
||||
//! @param theX - column index from left
|
||||
//! @param theY - row index from top
|
||||
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
|
||||
//! @param theX column index from left
|
||||
//! @param theY row index from top
|
||||
//! @return the pixel color
|
||||
inline Quantity_Color PixelColor (const Standard_Integer theX,
|
||||
const Standard_Integer theY) const
|
||||
@@ -131,10 +132,37 @@ public: // high-level API
|
||||
|
||||
//! Returns the pixel color. This function is relatively slow.
|
||||
//! theAlpha argument is set to color intensity (0 - transparent, 1 - opaque)
|
||||
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
|
||||
Standard_EXPORT Quantity_Color PixelColor (const Standard_Integer theX,
|
||||
const Standard_Integer theY,
|
||||
Quantity_Parameter& theAlpha) const;
|
||||
|
||||
//! Sets the pixel color. This function is relatively slow.
|
||||
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
|
||||
void SetPixelColor (const Standard_Integer theX,
|
||||
const Standard_Integer theY,
|
||||
const Quantity_ColorRGBA& theColor)
|
||||
{
|
||||
const NCollection_Vec4<float> aColor = theColor;
|
||||
SetPixelColor (theX, theY, aColor);
|
||||
}
|
||||
|
||||
//! Sets the pixel color. This function is relatively slow.
|
||||
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
|
||||
void SetPixelColor(const Standard_Integer theX,
|
||||
const Standard_Integer theY,
|
||||
const Quantity_Color& theColor)
|
||||
{
|
||||
const NCollection_Vec3<float> aColor = theColor;
|
||||
SetPixelColor (theX, theY, NCollection_Vec4<float> (aColor, 1.0f));
|
||||
}
|
||||
|
||||
//! Sets the pixel color. This function is relatively slow.
|
||||
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
|
||||
Standard_EXPORT void SetPixelColor (const Standard_Integer theX,
|
||||
const Standard_Integer theY,
|
||||
const NCollection_Vec4<float>& theColor);
|
||||
|
||||
//! Initialize image plane as wrapper over alien data.
|
||||
//! Data will not be copied! Notice that caller should ensure
|
||||
//! that data pointer will not be released during this wrapper lifetime.
|
||||
|
Reference in New Issue
Block a user