// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
+#include <AIS_DisplayMode.hxx>
#include <AIS_Triangulation.hxx>
#include <AIS_InteractiveObject.hxx>
#include <Standard_Type.hxx>
myFlagColor = 0;
}
+//=======================================================================
+//function : SetTransparency
+//purpose :
+//=======================================================================
+void AIS_Triangulation::SetTransparency (const Standard_Real theValue)
+{
+ if (!myDrawer->HasOwnShadingAspect())
+ {
+ myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
+ if (myDrawer->HasLink())
+ {
+ *myDrawer->ShadingAspect()->Aspect() = *myDrawer->Link()->ShadingAspect()->Aspect();
+ }
+ }
+
+ // override transparency
+ myDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
+ myTransparency = theValue;
+
+ updatePresentation();
+}
+
+//=======================================================================
+//function : UnsetTransparency
+//purpose :
+//=======================================================================
+void AIS_Triangulation::UnsetTransparency()
+{
+ myTransparency = 0.0;
+ if (!myDrawer->HasOwnShadingAspect())
+ {
+ return;
+ }
+ else if (HasColor() || HasMaterial())
+ {
+ myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
+ }
+
+ updatePresentation();
+}
+
+//=======================================================================
+//function : updatePresentation
+//purpose :
+//=======================================================================
+void AIS_Triangulation::updatePresentation()
+{
+ if (HasVertexColors())
+ {
+ SetToUpdate (AIS_WireFrame);
+ }
+ else
+ {
+ // modify shading presentation without re-computation
+ const PrsMgr_Presentations& aPrsList = Presentations();
+ Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
+ for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
+ {
+ const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
+ if (aPrsModed.Mode() != AIS_WireFrame)
+ {
+ continue;
+ }
+
+ const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
+
+ if (IsTransparent())
+ {
+ aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
+ }
+
+ for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
+ {
+ const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
+ if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
+ {
+ aGroup->SetGroupPrimitivesAspect (anAreaAsp);
+ }
+ }
+
+ if (!IsTransparent())
+ {
+ aPrs->ResetDisplayPriority();
+ }
+ }
+
+ myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
+ myToRecomputeModes.Clear();
+ }
+}
+
//=======================================================================
//function : Compute
//purpose :
const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles(); //Triangle
Standard_Boolean hasVNormals = myTriangulation->HasNormals();
- Standard_Boolean hasVColors = (myFlagColor == 1);
+ Standard_Boolean hasVColors = HasVertexColors();
Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (myNbNodes, myNbTriangles * 3,
hasVNormals, hasVColors, Standard_False);
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ )
{
j = (i - nodes.Lower()) * 3;
- anArray->AddVertex(nodes(i), AttenuateColor(colors(i), ambient));
+ anArray->AddVertex(nodes(i), attenuateColor(colors(i), ambient));
anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3));
}
}
const TColStd_Array1OfInteger& colors = myColor->Array1();
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ )
{
- anArray->AddVertex(nodes(i), AttenuateColor(colors(i), ambient));
+ anArray->AddVertex(nodes(i), attenuateColor(colors(i), ambient));
}
}
else // !hasVColors
// after glColorMaterial(GL_AMBIENT_AND_DIFFUSE). Without it, colors look unnatural and flat.
//=======================================================================
-Standard_Integer AIS_Triangulation::AttenuateColor( const Standard_Integer aColor,
- const Standard_Real aComposition)
+Graphic3d_Vec4ub AIS_Triangulation::attenuateColor (const Standard_Integer theColor,
+ const Standard_Real theComposition)
{
- Standard_Integer red,
- green,
- blue,
- alpha;
-
- alpha = aColor&0xff000000;
- alpha >>= 24;
-
- blue = aColor&0x00ff0000;
- blue >>= 16;
-
- green = aColor&0x0000ff00;
- green >>= 8;
-
- red = aColor&0x000000ff;
- red >>= 0;
- red = (Standard_Integer)(aComposition * red);
- green = (Standard_Integer)(aComposition * green);
- blue = (Standard_Integer)(aComposition * blue);
+ const Graphic3d_Vec4ub& aColor = *reinterpret_cast<const Graphic3d_Vec4ub*> (&theColor);
+ // If IsTranparent() is false alpha value will be ignored anyway.
+ Standard_Byte anAlpha = IsTransparent() ? static_cast<Standard_Byte> (255.0 - myDrawer->ShadingAspect()->Aspect()->FrontMaterial().Transparency() * 255.0)
+ : 255;
- Standard_Integer color;
- color = red;
- color += green << 8;
- color += blue << 16;
- color += alpha << 24;
- return color;
+ return Graphic3d_Vec4ub ((Standard_Byte)(theComposition * aColor.r()),
+ (Standard_Byte)(theComposition * aColor.g()),
+ (Standard_Byte)(theComposition * aColor.b()),
+ anAlpha);
}
//! Get the color for each node.
//! Each 32-bit color is Alpha << 24 + Blue << 16 + Green << 8 + Red
Standard_EXPORT Handle(TColStd_HArray1OfInteger) GetColors() const;
+
+ //! Returns true if triangulation has vertex colors.
+ Standard_Boolean HasVertexColors() const
+ {
+ return (myFlagColor == 1);
+ }
Standard_EXPORT void SetTriangulation (const Handle(Poly_Triangulation)& aTriangulation);
//! Returns Poly_Triangulation .
Standard_EXPORT Handle(Poly_Triangulation) GetTriangulation() const;
+ //! Sets the value aValue for transparency in the reconstructed compound shape.
+ Standard_EXPORT virtual void SetTransparency (const Standard_Real aValue = 0.6) Standard_OVERRIDE;
-
+ //! Removes the setting for transparency in the reconstructed compound shape.
+ Standard_EXPORT virtual void UnsetTransparency() Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(AIS_Triangulation,AIS_InteractiveObject)
protected:
+ Standard_EXPORT void updatePresentation();
//! All color components are multiplied by aComponent, the result is then packed again as 32-bit integer.
//! Color attenuation is applied to the vertex colors in order to have correct visual result
//! after glColorMaterial(GL_AMBIENT_AND_DIFFUSE). Without it, colors look unnatural and flat.
- Standard_EXPORT Standard_Integer AttenuateColor (const Standard_Integer aColor, const Standard_Real aComponent);
+ Standard_EXPORT Graphic3d_Vec4ub attenuateColor (const Standard_Integer theColor, const Standard_Real theComponent);
Handle(Poly_Triangulation) myTriangulation;
Handle(TColStd_HArray1OfInteger) myColor;
//! On all architecture proccers type (x86 or SPARC) you can
//! use this byte order.
Standard_EXPORT Standard_Integer AddVertex (const gp_Pnt& aVertice, const Standard_Integer aColor);
+
+ //! Adds a vertice and vertex color in the vertex array.
+ //! returns the actual vertex number.
+ //! Warning: <theColor> is ignored when the <hasVColors>
+ //! constructor parameter is FALSE
+ Standard_Integer AddVertex (const gp_Pnt& theVertex,
+ const Graphic3d_Vec4ub& theColor);
//! Adds a vertice and vertex normal in the vertex array.
//! returns the actual vertex number.
//! Change the vertex color of rank <anIndex> in the array.
void SetVertexColor (const Standard_Integer anIndex, const Standard_Real R, const Standard_Real G, const Standard_Real B);
+
+ //! Change the vertex color of rank <theIndex> in the array.
+ void SetVertexColor (const Standard_Integer theIndex,
+ const Graphic3d_Vec4ub& theColor);
//! Change the vertex color of rank <anIndex> in the array.
//! aColor = Alpha << 24 + Blue << 16 + Green << 8 + Red
return AddVertex (theVertex.x(), theVertex.y(), theVertex.z());
}
+inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex,
+ const Graphic3d_Vec4ub& theColor)
+{
+ const Standard_Integer anIndex = AddVertex (theVertex);
+ SetVertexColor (anIndex, theColor);
+ return anIndex;
+}
+
inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX,
const Standard_Real theY,
const Standard_Real theZ)
myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
}
+inline void Graphic3d_ArrayOfPrimitives::SetVertexColor (const Standard_Integer theIndex,
+ const Graphic3d_Vec4ub& theColor)
+{
+ SetVertexColor (theIndex, *reinterpret_cast<const Standard_Integer*> (&theColor));
+}
+
inline void Graphic3d_ArrayOfPrimitives::SetVertexNormal (const Standard_Integer theIndex,
const Standard_Real theNX,
const Standard_Real theNY,
// stupid initialization of Green color in RGBA space as integer
// probably wrong for big-endian CPUs
- Standard_Integer aRed = 0;
- Standard_Integer aGreen = 255;
- Standard_Integer aBlue = 0;
- Standard_Integer anAlpha = 0; // not used
- Standard_Integer aColorInt = aRed;
- aColorInt += aGreen << 8;
- aColorInt += aBlue << 16;
- aColorInt += anAlpha << 24;
+ const Graphic3d_Vec4ub aColor (0, 255, 0, 0);
// setup colors array per vertex
Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints);
for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId)
{
- aColorArray->SetValue (aNodeId, aColorInt);
+ aColorArray->SetValue (aNodeId, *reinterpret_cast<const Standard_Integer*> (&aColor));
}
aShape->SetColors (aColorArray);