Use Quantity_ColorRGBA as surface color to store a transparency in XCAFPrs_Style.
//! Modifies the color of the interior of the face
void SetInteriorColor (const Quantity_Color& theColor) { myInteriorColor.SetRGB (theColor); }
+ //! Modifies the color of the interior of the face
+ void SetInteriorColor (const Quantity_ColorRGBA& theColor) { myInteriorColor = theColor; }
+
//! Return back interior color.
const Quantity_Color& BackInteriorColor() const { return myBackInteriorColor.GetRGB(); }
//! Modifies the color of the interior of the back face
void SetBackInteriorColor (const Quantity_Color& theColor) { myBackInteriorColor.SetRGB (theColor); }
+ //! Modifies the color of the interior of the back face
+ void SetBackInteriorColor (const Quantity_ColorRGBA& theColor) { myBackInteriorColor = theColor; }
+
//! Returns the surface material of external faces
const Graphic3d_MaterialAspect& FrontMaterial() const { return myFrontMaterial; }
//! Modifies the ambient and diffuse color of the surface.
Standard_EXPORT void SetColor (const Quantity_Color& theColor);
- //! Returns the transparency coefficient of the surface.
+ //! Returns the transparency coefficient of the surface (1.0 - Alpha); 0.0 means opaque.
Standard_ShortReal Transparency() const { return myTransparencyCoef; }
+ //! Returns the alpha coefficient of the surface (1.0 - Transparency); 1.0 means opaque.
+ Standard_ShortReal Alpha() const { return 1.0f - myTransparencyCoef; }
+
//! Modifies the transparency coefficient of the surface, where 0 is opaque and 1 is fully transparent.
//! Transparency is applicable to materials that have at least one of reflection modes (ambient, diffuse, specular or emissive) enabled.
//! See also SetReflectionModeOn() and SetReflectionModeOff() methods.
//! Warning: Raises MaterialDefinitionError if given value is a negative value or greater than 1.0.
Standard_EXPORT void SetTransparency (const Standard_ShortReal theValue);
+ //! Modifies the alpha coefficient of the surface, where 1.0 is opaque and 0.0 is fully transparent.
+ void SetAlpha (Standard_ShortReal theValue) { SetTransparency (1.0f - theValue); }
+
//! Returns the ambient color of the surface.
const Quantity_Color& AmbientColor() const { return myColors[Graphic3d_TOR_AMBIENT]; }
myMatBack .SetColor (theHighlight->ColorRGBA());
}
- Standard_ShortReal aTranspFront = 0.f;
- Standard_ShortReal aTranspBack = 0.f;
- if (CheckIsTransparent (theAspect, theHighlight, aTranspFront, aTranspBack))
+ Standard_ShortReal anAlphaFront = 1.0f;
+ Standard_ShortReal anAlphaBack = 1.0f;
+ if (CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack))
{
- myMatFront.Diffuse.a() = 1.0f - aTranspFront;
- myMatBack .Diffuse.a() = 1.0f - aTranspBack;
+ myMatFront.Diffuse.a() = anAlphaFront;
+ myMatBack .Diffuse.a() = anAlphaBack;
}
// do not update material properties in case of zero reflection mode,
// =======================================================================
Standard_Boolean OpenGl_Context::CheckIsTransparent (const OpenGl_AspectFace* theAspect,
const Handle(Graphic3d_PresentationAttributes)& theHighlight,
- Standard_ShortReal& theTranspFront,
- Standard_ShortReal& theTranspBack)
+ Standard_ShortReal& theAlphaFront,
+ Standard_ShortReal& theAlphaBack)
{
const Handle(Graphic3d_AspectFillArea3d)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull())
? theHighlight->BasicFillAreaAspect()
: aMatFrontSrc;
// handling transparency
- theTranspFront = aMatFrontSrc.Transparency();
- theTranspBack = aMatBackSrc .Transparency();
if (!theHighlight.IsNull()
&& theHighlight->BasicFillAreaAspect().IsNull())
{
- theTranspFront = theHighlight->Transparency();
- theTranspBack = theHighlight->Transparency();
+ theAlphaFront = theHighlight->ColorRGBA().Alpha();
+ theAlphaBack = theHighlight->ColorRGBA().Alpha();
+ }
+ else
+ {
+ theAlphaFront = aMatFrontSrc.Alpha();
+ theAlphaBack = aMatBackSrc .Alpha();
}
- return theTranspFront != 0.f
- || theTranspBack != 0.f;
+ const bool isTransparent = theAlphaFront < 1.0f
+ || theAlphaBack < 1.0f;
+ return isTransparent;
}
// =======================================================================
//! Checks if transparency is required for the given aspect and highlight style.
Standard_EXPORT static Standard_Boolean CheckIsTransparent (const OpenGl_AspectFace* theAspect,
const Handle(Graphic3d_PresentationAttributes)& theHighlight,
- Standard_ShortReal& theTranspFront,
- Standard_ShortReal& theTranspBack);
+ Standard_ShortReal& theAlphaFront,
+ Standard_ShortReal& theAlphaBack);
+
+ //! Checks if transparency is required for the given aspect and highlight style.
+ static Standard_Boolean CheckIsTransparent (const OpenGl_AspectFace* theAspect,
+ const Handle(Graphic3d_PresentationAttributes)& theHighlight)
+ {
+ Standard_ShortReal anAlphaFront = 1.0f, anAlphaBack = 1.0f;
+ return CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack);
+ }
//! Setup current color.
Standard_EXPORT void SetColor4fv (const OpenGl_Vec4& theColor);
return Standard_True;
}
- Standard_ShortReal aFront = 0.f;
- Standard_ShortReal aBack = 0.f;
-
if (OpenGl_Context::CheckIsTransparent (theWorkspace->AspectFace(),
- theWorkspace->HighlightStyle(),
- aFront, aBack))
+ theWorkspace->HighlightStyle()))
{
++mySkippedCounter;
return Standard_False;
return dynamic_cast<const OpenGl_AspectFace*> (theGlElement) != NULL;
}
- Standard_ShortReal aFront = 0.f;
- Standard_ShortReal aBack = 0.f;
-
return OpenGl_Context::CheckIsTransparent (theWorkspace->AspectFace(),
- theWorkspace->HighlightStyle(),
- aFront, aBack);
+ theWorkspace->HighlightStyle());
}
const Graphic3d_MaterialAspect& aSrcMat = theAspect->Aspect()->FrontMaterial();
const OpenGl_Vec3& aMatCol = theAspect->Aspect()->InteriorColor();
+ const bool isPhysic = aSrcMat.MaterialType (Graphic3d_MATERIAL_PHYSIC);
const float aShine = 128.0f * float(aSrcMat.Shininess());
- const bool isPhysic = aSrcMat.MaterialType (Graphic3d_MATERIAL_PHYSIC) == Standard_True;
// ambient component
if (aSrcMat.ReflectionMode (Graphic3d_TOR_AMBIENT))
}
const float anIndex = (float )aSrcMat.RefractionIndex();
- theMaterial.Transparency = BVH_Vec4f (1.0f - (float )aSrcMat.Transparency(),
- (float )aSrcMat.Transparency(),
+ theMaterial.Transparency = BVH_Vec4f (aSrcMat.Alpha(), aSrcMat.Transparency(),
anIndex == 0 ? 1.0f : anIndex,
anIndex == 0 ? 1.0f : 1.0f / anIndex);
const Quantity_Color& theInteriorColor)
{
const bool isPhysic = theMat.MaterialType (Graphic3d_MATERIAL_PHYSIC);
+ ChangeShine() = 128.0f * theMat.Shininess();
+ ChangeTransparency() = theMat.Alpha();
// ambient component
if (theMat.ReflectionMode (Graphic3d_TOR_AMBIENT))
{
Emission = THE_BLACK_COLOR;
}
-
- ChangeShine() = 128.0f * theMat.Shininess();
- ChangeTransparency() = 1.0f - theMat.Transparency();
}
// =======================================================================
Quantity_Color.hxx
Quantity_ColorHasher.hxx
Quantity_ColorRGBA.hxx
+Quantity_ColorRGBAHasher.hxx
Quantity_ColorDefinitionError.hxx
Quantity_Concentration.hxx
Quantity_Conductivity.hxx
--- /dev/null
+// Copyright (c) 2017 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 _Quantity_ColorRGBAHasher_HeaderFile
+#define _Quantity_ColorRGBAHasher_HeaderFile
+
+#include <Quantity_ColorRGBA.hxx>
+#include <Quantity_ColorHasher.hxx>
+
+//! Hasher of Quantity_ColorRGBA.
+struct Quantity_ColorRGBAHasher
+{
+
+ //! Returns hash code for the given color.
+ static Standard_Integer HashCode (const Quantity_ColorRGBA& theColor,
+ const Standard_Integer theUpper)
+ {
+ const NCollection_Vec4<float>& aColor = theColor;
+ uint32_t aColor32 = (uint32_t(aColor.a() * 255.0f) << 24)
+ + (uint32_t(aColor.b() * 255.0f) << 16)
+ + (uint32_t(aColor.g() * 255.0f) << 8)
+ + uint32_t(aColor.r() * 255.0f);
+ return ((aColor32 & 0x7fffffff) % theUpper) + 1;
+ }
+
+ //! Returns true if two colors are equal.
+ static Standard_Boolean IsEqual (const Quantity_ColorRGBA& theColor1,
+ const Quantity_ColorRGBA& theColor2)
+ {
+ return theColor1 == theColor2;
+ }
+
+};
+
+#endif // _Quantity_ColorRGBAHasher_HeaderFile
}
else
{
- Quantity_Color aColor;
+ Quantity_ColorRGBA aColor;
if (aColorTool->GetColor (aLabel, XCAFDoc_ColorGen, aColor))
{
- aStyle.SetColorCurv (aColor);
+ aStyle.SetColorCurv (aColor.GetRGB());
aStyle.SetColorSurf (aColor);
}
if (aColorTool->GetColor (aLabel, XCAFDoc_ColorSurf, aColor))
}
if (aColorTool->GetColor (aLabel, XCAFDoc_ColorCurv, aColor))
{
- aStyle.SetColorCurv (aColor);
+ aStyle.SetColorCurv (aColor.GetRGB());
}
}
}
}
- Quantity_Color aColor;
+ Quantity_ColorRGBA aColor;
XCAFPrs_Style aShuoStyle;
if (!aColorTool->IsVisible (aShuolab))
{
{
if (aColorTool->GetColor (aShuolab, XCAFDoc_ColorGen, aColor))
{
- aShuoStyle.SetColorCurv (aColor);
+ aShuoStyle.SetColorCurv (aColor.GetRGB());
aShuoStyle.SetColorSurf (aColor);
}
if (aColorTool->GetColor (aShuolab, XCAFDoc_ColorSurf, aColor))
}
if (aColorTool->GetColor (aShuolab, XCAFDoc_ColorCurv, aColor))
{
- aShuoStyle.SetColorCurv (aColor);
+ aShuoStyle.SetColorCurv (aColor.GetRGB());
}
}
if (!aShuoStyle.IsSetColorCurv()
XCAFPrs_Style aDefStyle;
DefaultStyle (aDefStyle);
Quantity_Color aColorCurv = aDefStyle.GetColorCurv();
- Quantity_Color aColorSurf = aDefStyle.GetColorSurf();
+ Quantity_ColorRGBA aColorSurf = aDefStyle.GetColorSurfRGBA();
SetColors (myDrawer, aColorCurv, aColorSurf);
const XCAFPrs_Style& aStyle = aStyleGroupIter.Key();
aDrawer->SetHidden (!aStyle.IsVisible());
- aColorCurv = aStyle.IsSetColorCurv() ? aStyle.GetColorCurv() : aDefStyle.GetColorCurv();
- aColorSurf = aStyle.IsSetColorSurf() ? aStyle.GetColorSurf() : aDefStyle.GetColorSurf();
+ aColorCurv = aStyle.IsSetColorCurv() ? aStyle.GetColorCurv() : aDefStyle.GetColorCurv();
+ aColorSurf = aStyle.IsSetColorSurf() ? aStyle.GetColorSurfRGBA() : aDefStyle.GetColorSurfRGBA();
SetColors (aDrawer, aColorCurv, aColorSurf);
}
//=======================================================================
void XCAFPrs_AISObject::SetColors (const Handle(Prs3d_Drawer)& theDrawer,
const Quantity_Color& theColorCurv,
- const Quantity_Color& theColorSurf)
+ const Quantity_ColorRGBA& theColorSurf)
{
if (!theDrawer->HasOwnShadingAspect())
{
theDrawer->WireAspect()->SetColor (theColorCurv);
Graphic3d_MaterialAspect aMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
- aMaterial.SetColor (theColorSurf);
+ aMaterial.SetColor (theColorSurf.GetRGB());
+ aMaterial.SetAlpha (theColorSurf.Alpha());
theDrawer->ShadingAspect()->Aspect()->SetInteriorColor (theColorSurf);
theDrawer->ShadingAspect()->Aspect()->SetFrontMaterial (aMaterial);
- theDrawer->UIsoAspect()->SetColor (theColorSurf);
- theDrawer->VIsoAspect()->SetColor (theColorSurf);
+ theDrawer->UIsoAspect()->SetColor (theColorSurf.GetRGB());
+ theDrawer->VIsoAspect()->SetColor (theColorSurf.GetRGB());
}
//=======================================================================
const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
// take current color
- const Quantity_Color aColorCurv = aDrawer->WireAspect()->Aspect()->Color();
- const Quantity_Color aSurfColor = aDrawer->ShadingAspect()->Aspect()->InteriorColor();
+ const Quantity_Color aColorCurv = aDrawer->WireAspect()->Aspect()->Color();
+ const Quantity_ColorRGBA aSurfColor = aDrawer->ShadingAspect()->Aspect()->InteriorColorRGBA();
// SetColors() will take the material from myDrawer
SetColors (aDrawer, aColorCurv, aSurfColor);
//! Set colors to drawer
Standard_EXPORT void SetColors (const Handle(Prs3d_Drawer)& theDrawer,
const Quantity_Color& theColorCurv,
- const Quantity_Color& theColorSurf);
+ const Quantity_ColorRGBA& theColorSurf);
+
+ //! Set colors to drawer
+ void SetColors (const Handle(Prs3d_Drawer)& theDrawer,
+ const Quantity_Color& theColorCurv,
+ const Quantity_Color& theColorSurf) { SetColors (theDrawer, theColorCurv, Quantity_ColorRGBA (theColorSurf)); }
//! Fills out a default style object which is used when styles are
//! not explicitly defined in the document.
//function : SetColorSurf
//purpose :
//=======================================================================
-void XCAFPrs_Style::SetColorSurf (const Quantity_Color& theColor)
+void XCAFPrs_Style::SetColorSurf (const Quantity_ColorRGBA& theColor)
{
myColorSurf = theColor;
myHasColorSurf = Standard_True;
void XCAFPrs_Style::UnSetColorSurf()
{
myHasColorSurf = Standard_False;
- myColorSurf.SetValues (Quantity_NOC_YELLOW);
+ myColorSurf.ChangeRGB().SetValues (Quantity_NOC_YELLOW);
+ myColorSurf.SetAlpha (1.0f);
}
//=======================================================================
#include <Standard.hxx>
#include <Standard_DefineAlloc.hxx>
#include <Standard_Handle.hxx>
-#include <Quantity_ColorHasher.hxx>
+#include <Quantity_ColorRGBAHasher.hxx>
//! Represents a set of styling settings applicable to a (sub)shape
class XCAFPrs_Style
Standard_Boolean IsSetColorSurf() const { return myHasColorSurf; }
//! Return surface color.
- const Quantity_Color& GetColorSurf() const { return myColorSurf; }
+ const Quantity_Color& GetColorSurf() const { return myColorSurf.GetRGB(); }
//! Set surface color.
- Standard_EXPORT void SetColorSurf (const Quantity_Color& col);
-
+ void SetColorSurf (const Quantity_Color& theColor) { SetColorSurf (Quantity_ColorRGBA (theColor)); }
+
+ //! Return surface color.
+ const Quantity_ColorRGBA& GetColorSurfRGBA() const { return myColorSurf; }
+
+ //! Set surface color.
+ Standard_EXPORT void SetColorSurf (const Quantity_ColorRGBA& theColor);
+
//! Manage surface color setting
Standard_EXPORT void UnSetColorSurf();
int aHashCode = 0;
if (theStyle.myHasColorSurf)
{
- aHashCode = aHashCode ^ Quantity_ColorHasher::HashCode (theStyle.myColorSurf, theUpper);
+ aHashCode = aHashCode ^ Quantity_ColorRGBAHasher::HashCode (theStyle.myColorSurf, theUpper);
}
if (theStyle.myHasColorCurv)
{
protected:
- Quantity_Color myColorSurf;
- Quantity_Color myColorCurv;
- Standard_Boolean myHasColorSurf;
- Standard_Boolean myHasColorCurv;
- Standard_Boolean myIsVisible;
+ Quantity_ColorRGBA myColorSurf;
+ Quantity_Color myColorCurv;
+ Standard_Boolean myHasColorSurf;
+ Standard_Boolean myHasColorCurv;
+ Standard_Boolean myIsVisible;
};
XSetColor D_First b_10 0 1 1 c
XAddColor D_First 0.5 0.5 1 0.1
+XShow D_First
+vfit
+vsetdispmode 1
+vdump $::imagedir/${::casename}_first.png
+if { [vreadpixel 300 200 rgb name] != "GRAY14" } { puts "Error: wrong color in 3D Viewer" }
+
# Write file
SaveAs D_First ${imagedir}/bug28521.xbf
Close D_First
puts "Error: wrong color."
}
+XShow D_Second
+vfit
+vsetdispmode 1
+vdump $::imagedir/${::casename}.png
+if { [vreadpixel 300 200 rgb name] != "GRAY14" } { puts "Error: wrong color in 3D Viewer" }
+
Close D_Second