1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0031174: Visualization - support user-provided stipple line patterns [occt720 backport]

This commit is contained in:
kgv 2019-11-18 13:42:06 +03:00
parent 760a94d050
commit 9cee51b43b
10 changed files with 162 additions and 66 deletions

View File

@ -24,7 +24,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_AspectLine3d, Standard_Transient)
Graphic3d_AspectLine3d::Graphic3d_AspectLine3d() Graphic3d_AspectLine3d::Graphic3d_AspectLine3d()
: myColor (Quantity_NOC_YELLOW), : myColor (Quantity_NOC_YELLOW),
myType (Aspect_TOL_SOLID), myType (Aspect_TOL_SOLID),
myWidth (1.0f) myWidth (1.0f),
myLinePattern (0xFFFF)
{ {
// //
} }
@ -38,7 +39,8 @@ Graphic3d_AspectLine3d::Graphic3d_AspectLine3d (const Quantity_Color& theColor
const Standard_Real theWidth) const Standard_Real theWidth)
: myColor (theColor), : myColor (theColor),
myType (theType), myType (theType),
myWidth ((float )theWidth) myWidth ((float )theWidth),
myLinePattern (DefaultLinePatternForType (theType))
{ {
if (myWidth <= 0.0f) if (myWidth <= 0.0f)
{ {

View File

@ -61,7 +61,51 @@ public:
Aspect_TypeOfLine Type() const { return myType; } Aspect_TypeOfLine Type() const { return myType; }
//! Modifies the type of line. //! Modifies the type of line.
void SetType (const Aspect_TypeOfLine theType) { myType = theType; } void SetType (const Aspect_TypeOfLine theType)
{
myType = theType;
myLinePattern = DefaultLinePatternForType (theType);
}
//! Return custom stipple line pattern; 0xFFFF by default.
uint16_t LinePattern() const { return myLinePattern; }
//! Modifies the stipple line pattern, and changes line type to Aspect_TOL_USERDEFINED for non-standard pattern.
void SetLinePattern (uint16_t thePattern)
{
myType = DefaultLineTypeForPattern (thePattern);
myLinePattern = thePattern;
}
//! Return stipple line pattern for line type.
static uint16_t DefaultLinePatternForType (Aspect_TypeOfLine theType)
{
switch (theType)
{
case Aspect_TOL_DASH: return 0xFFC0;
case Aspect_TOL_DOT: return 0xCCCC;
case Aspect_TOL_DOTDASH: return 0xFF18;
case Aspect_TOL_EMPTY: return 0x0000;
case Aspect_TOL_SOLID: return 0xFFFF;
case Aspect_TOL_USERDEFINED: return 0xFF24;
}
return 0xFFFF;
}
//! Return line type for stipple line pattern.
static Aspect_TypeOfLine DefaultLineTypeForPattern (uint16_t thePattern)
{
switch (thePattern)
{
case 0x0000: return Aspect_TOL_EMPTY;
case 0xFFC0: return Aspect_TOL_DASH;
case 0xCCCC: return Aspect_TOL_DOT;
case 0xFF18: return Aspect_TOL_DOTDASH;
case 0xFFFF: return Aspect_TOL_SOLID;
case 0xFF24: return Aspect_TOL_USERDEFINED;
}
return Aspect_TOL_USERDEFINED;
}
//! Return line width. //! Return line width.
Standard_ShortReal Width() const { return myWidth; } Standard_ShortReal Width() const { return myWidth; }
@ -97,6 +141,7 @@ public:
return myProgram == theOther.myProgram return myProgram == theOther.myProgram
&& myType == theOther.myType && myType == theOther.myType
&& myLinePattern == theOther.myLinePattern
&& myColor == theOther.myColor && myColor == theOther.myColor
&& myWidth == theOther.myWidth; && myWidth == theOther.myWidth;
} }
@ -120,6 +165,7 @@ protected:
Quantity_ColorRGBA myColor; Quantity_ColorRGBA myColor;
Aspect_TypeOfLine myType; Aspect_TypeOfLine myType;
Standard_ShortReal myWidth; Standard_ShortReal myWidth;
uint16_t myLinePattern;
}; };

View File

@ -3264,46 +3264,25 @@ void OpenGl_Context::SetColor4fv (const OpenGl_Vec4& theColor)
void OpenGl_Context::SetTypeOfLine (const Aspect_TypeOfLine theType, void OpenGl_Context::SetTypeOfLine (const Aspect_TypeOfLine theType,
const Standard_ShortReal theFactor) const Standard_ShortReal theFactor)
{ {
Standard_Integer aPattern = 0xFFFF; SetLineStipple (theFactor, Graphic3d_AspectLine3d::DefaultLinePatternForType (theType));
switch (theType) }
{
case Aspect_TOL_DASH:
{
aPattern = 0xFFC0;
break;
}
case Aspect_TOL_DOT:
{
aPattern = 0xCCCC;
break;
}
case Aspect_TOL_DOTDASH:
{
aPattern = 0xFF18;
break;
}
case Aspect_TOL_EMPTY:
case Aspect_TOL_SOLID:
{
aPattern = 0xFFFF;
break;
}
case Aspect_TOL_USERDEFINED:
{
aPattern = 0xFF24;
break;
}
}
// =======================================================================
// function : SetLineStipple
// purpose :
// =======================================================================
void OpenGl_Context::SetLineStipple (const Standard_ShortReal theFactor,
const uint16_t thePattern)
{
if (!myActiveProgram.IsNull()) if (!myActiveProgram.IsNull())
{ {
myActiveProgram->SetUniform (this, "uPattern", aPattern); myActiveProgram->SetUniform (this, "uPattern", (Standard_Integer )thePattern);
myActiveProgram->SetUniform (this, "uFactor", theFactor); myActiveProgram->SetUniform (this, "uFactor", theFactor);
return; return;
} }
#if !defined(GL_ES_VERSION_2_0) #if !defined(GL_ES_VERSION_2_0)
if (aPattern != 0xFFFF) if (thePattern != 0xFFFF)
{ {
#ifdef HAVE_GL2PS #ifdef HAVE_GL2PS
if (IsFeedback()) if (IsFeedback())
@ -3317,7 +3296,7 @@ void OpenGl_Context::SetTypeOfLine (const Aspect_TypeOfLine theType,
core11fwd->glEnable (GL_LINE_STIPPLE); core11fwd->glEnable (GL_LINE_STIPPLE);
core11->glLineStipple (static_cast<GLint> (theFactor), core11->glLineStipple (static_cast<GLint> (theFactor),
static_cast<GLushort> (aPattern)); static_cast<GLushort> (thePattern));
} }
} }
else else

View File

@ -680,6 +680,13 @@ public: //! @name methods to alter or retrieve current state
Standard_EXPORT void SetTypeOfLine (const Aspect_TypeOfLine theType, Standard_EXPORT void SetTypeOfLine (const Aspect_TypeOfLine theType,
const Standard_ShortReal theFactor = 1.0f); const Standard_ShortReal theFactor = 1.0f);
//! Setup stipple line pattern with 1.0f factor; wrapper for glLineStipple().
void SetLineStipple (const uint16_t thePattern) { SetLineStipple (1.0f, thePattern); }
//! Setup type of line; wrapper for glLineStipple().
Standard_EXPORT void SetLineStipple (const Standard_ShortReal theFactor,
const uint16_t thePattern);
//! Setup width of line. //! Setup width of line.
Standard_EXPORT void SetLineWidth (const Standard_ShortReal theWidth); Standard_EXPORT void SetLineWidth (const Standard_ShortReal theWidth);

View File

@ -474,7 +474,7 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo
myVboAttribs->BindPositionAttribute (aGlContext); myVboAttribs->BindPositionAttribute (aGlContext);
aGlContext->SetColor4fv (theEdgeColour); aGlContext->SetColor4fv (theEdgeColour);
aGlContext->SetTypeOfLine (anAspect->Aspect()->Type()); aGlContext->SetLineStipple(anAspect->Aspect()->LinePattern());
aGlContext->SetLineWidth (anAspect->Aspect()->Width()); aGlContext->SetLineWidth (anAspect->Aspect()->Width());
if (!myVboIndices.IsNull()) if (!myVboIndices.IsNull())
@ -833,7 +833,7 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
if (myDrawMode == GL_LINES if (myDrawMode == GL_LINES
|| myDrawMode == GL_LINE_STRIP) || myDrawMode == GL_LINE_STRIP)
{ {
aCtx->SetTypeOfLine (anAspectLine->Aspect()->Type()); aCtx->SetLineStipple(anAspectLine->Aspect()->LinePattern());
aCtx->SetLineWidth (anAspectLine->Aspect()->Width()); aCtx->SetLineWidth (anAspectLine->Aspect()->Width());
} }

View File

@ -224,7 +224,7 @@ void OpenGl_Workspace::ResetAppliedAspect()
ApplyAspectMarker(); ApplyAspectMarker();
ApplyAspectText(); ApplyAspectText();
myGlContext->SetTypeOfLine (myDefaultAspectLine.Aspect()->Type()); myGlContext->SetLineStipple(myDefaultAspectLine.Aspect()->LinePattern());
myGlContext->SetLineWidth (myDefaultAspectLine.Aspect()->Width()); myGlContext->SetLineWidth (myDefaultAspectLine.Aspect()->Width());
} }

View File

@ -188,39 +188,74 @@ void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes)
//function : ParseLineType //function : ParseLineType
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg, Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg,
Aspect_TypeOfLine& theType) Aspect_TypeOfLine& theType,
uint16_t& thePattern)
{ {
TCollection_AsciiString aTypeStr (theArg); TCollection_AsciiString aTypeStr (theArg);
aTypeStr.LowerCase(); aTypeStr.LowerCase();
if (aTypeStr == "empty") if (aTypeStr == "empty"
|| aTypeStr == "-1")
{ {
theType = Aspect_TOL_EMPTY; theType = Aspect_TOL_EMPTY;
thePattern = Graphic3d_AspectLine3d::DefaultLinePatternForType (theType);
} }
else if (aTypeStr == "solid") else if (aTypeStr == "solid"
|| aTypeStr == "0")
{ {
theType = Aspect_TOL_SOLID; theType = Aspect_TOL_SOLID;
thePattern = Graphic3d_AspectLine3d::DefaultLinePatternForType (theType);
} }
else if (aTypeStr == "dot") else if (aTypeStr == "dot"
|| aTypeStr == "2")
{ {
theType = Aspect_TOL_DOT; theType = Aspect_TOL_DOT;
thePattern = Graphic3d_AspectLine3d::DefaultLinePatternForType (theType);
} }
else if (aTypeStr == "dash") else if (aTypeStr == "dash"
|| aTypeStr == "1")
{ {
theType = Aspect_TOL_DASH; theType = Aspect_TOL_DASH;
thePattern = Graphic3d_AspectLine3d::DefaultLinePatternForType (theType);
} }
else if (aTypeStr == "dotdash") else if (aTypeStr == "dotdash"
|| aTypeStr == "3")
{ {
theType = Aspect_TOL_DOTDASH; theType = Aspect_TOL_DOTDASH;
thePattern = Graphic3d_AspectLine3d::DefaultLinePatternForType (theType);
} }
else else
{ {
const int aTypeInt = Draw::Atoi (theArg); if (aTypeStr.StartsWith ("0x"))
if (aTypeInt < -1 || aTypeInt >= Aspect_TOL_USERDEFINED) {
aTypeStr = aTypeStr.SubString (3, aTypeStr.Length());
}
if (aTypeStr.Length() != 4
|| !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (1)))
|| !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (2)))
|| !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (3)))
|| !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (4))))
{ {
return Standard_False; return Standard_False;
} }
theType = (Aspect_TypeOfLine )aTypeInt;
std::stringstream aStream;
aStream << std::setbase (16) << aTypeStr.ToCString();
if (aStream.fail())
{
return Standard_False;
}
Standard_Integer aNumber = -1;
aStream >> aNumber;
if (aStream.fail())
{
return Standard_False;
}
thePattern = (uint16_t )aNumber;
theType = Graphic3d_AspectLine3d::DefaultLineTypeForPattern (thePattern);
} }
return Standard_True; return Standard_True;
} }
@ -1628,7 +1663,7 @@ struct ViewerTest_AspectsChangeSet
Standard_Real LineWidth; Standard_Real LineWidth;
Standard_Integer ToSetTypeOfLine; Standard_Integer ToSetTypeOfLine;
Aspect_TypeOfLine TypeOfLine; uint16_t StippleLinePattern;
Standard_Integer ToSetTypeOfMarker; Standard_Integer ToSetTypeOfMarker;
Aspect_TypeOfMarker TypeOfMarker; Aspect_TypeOfMarker TypeOfMarker;
@ -1674,7 +1709,7 @@ struct ViewerTest_AspectsChangeSet
ToSetLineWidth (0), ToSetLineWidth (0),
LineWidth (1.0), LineWidth (1.0),
ToSetTypeOfLine (0), ToSetTypeOfLine (0),
TypeOfLine (Aspect_TOL_SOLID), StippleLinePattern(0xFFFF),
ToSetTypeOfMarker (0), ToSetTypeOfMarker (0),
TypeOfMarker (Aspect_TOM_PLUS), TypeOfMarker (Aspect_TOM_PLUS),
ToSetMarkerSize (0), ToSetMarkerSize (0),
@ -2080,7 +2115,9 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
std::cout << "Error: wrong syntax at " << anArg << "\n"; std::cout << "Error: wrong syntax at " << anArg << "\n";
return 1; return 1;
} }
if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aChangeSet->TypeOfLine))
Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY;
if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType, aChangeSet->StippleLinePattern))
{ {
std::cout << "Error: wrong syntax at " << anArg << "\n"; std::cout << "Error: wrong syntax at " << anArg << "\n";
return 1; return 1;
@ -2302,7 +2339,7 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
aChangeSet->ToSetLineWidth = -1; aChangeSet->ToSetLineWidth = -1;
aChangeSet->LineWidth = 1.0; aChangeSet->LineWidth = 1.0;
aChangeSet->ToSetTypeOfLine = -1; aChangeSet->ToSetTypeOfLine = -1;
aChangeSet->TypeOfLine = Aspect_TOL_SOLID; aChangeSet->StippleLinePattern = 0xFFFF;
aChangeSet->ToSetTypeOfMarker = -1; aChangeSet->ToSetTypeOfMarker = -1;
aChangeSet->TypeOfMarker = Aspect_TOM_PLUS; aChangeSet->TypeOfMarker = Aspect_TOM_PLUS;
aChangeSet->ToSetMarkerSize = -1; aChangeSet->ToSetMarkerSize = -1;
@ -2455,11 +2492,11 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
} }
if (aChangeSet->ToSetTypeOfLine != 0) if (aChangeSet->ToSetTypeOfLine != 0)
{ {
aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->LineAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->WireAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->FreeBoundaryAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->UnFreeBoundaryAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->SeenLineAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
} }
if (aChangeSet->ToSetTypeOfMarker != 0) if (aChangeSet->ToSetTypeOfMarker != 0)
{ {
@ -2633,11 +2670,11 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
} }
if (aChangeSet->ToSetTypeOfLine != 0) if (aChangeSet->ToSetTypeOfLine != 0)
{ {
aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->LineAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->WireAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->FreeBoundaryAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->UnFreeBoundaryAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine); aDrawer->SeenLineAspect()->Aspect()->SetLinePattern (aChangeSet->StippleLinePattern);
toRedisplay = Standard_True; toRedisplay = Standard_True;
} }
if (aChangeSet->ToSetTypeOfMarker != 0) if (aChangeSet->ToSetTypeOfMarker != 0)
@ -6217,7 +6254,7 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
"\n\t\t: [-setMaterial MatName] [-unsetMaterial]" "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
"\n\t\t: [-setTransparency Transp] [-unsetTransparency]" "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
"\n\t\t: [-setWidth LineWidth] [-unsetWidth]" "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
"\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]" "\n\t\t: [-setLineType {solid|dash|dot|dotDash|0xHexPattern}] [-unsetLineType]"
"\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]" "\n\t\t: [-setMarkerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]"
"\n\t\t: [-unsetMarkerType]" "\n\t\t: [-unsetMarkerType]"
"\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]" "\n\t\t: [-setMarkerSize Scale] [-unsetMarkerSize]"

View File

@ -191,8 +191,18 @@ public:
//! Parses line type argument. //! Parses line type argument.
//! Handles either enumeration (integer) value or string constant. //! Handles either enumeration (integer) value or string constant.
Standard_EXPORT static Standard_Boolean ParseLineType (Standard_CString theArg, Standard_EXPORT static Standard_Boolean ParseLineType (Standard_CString theArg,
Aspect_TypeOfLine& theType); Aspect_TypeOfLine& theType,
uint16_t& thePattern);
//! Parses line type argument.
//! Handles either enumeration (integer) value or string constant.
static Standard_Boolean ParseLineType (Standard_CString theArg,
Aspect_TypeOfLine& theType)
{
uint16_t aPattern = 0xFFFF;
return ParseLineType (theArg, theType, aPattern);
}
//! Parses marker type argument. //! Parses marker type argument.
//! Handles either enumeration (integer) value or string constant. //! Handles either enumeration (integer) value or string constant.

View File

@ -0,0 +1,15 @@
puts "========"
puts "0031174: Visualization - support user-provided stipple line patterns"
puts "========"
puts ""
pload MODELING VISUALIZATION
box b1 1 2 3
box b2 1 2 3
vclear
vinit View1
vdisplay -dispMode 0 b1 b2
vfit
vaspects b1 -setLineWidth 4 -setLineType FF00 -setColor RED
vaspects b2 -setLineWidth 4 -setLineType 00FF -setColor GREEN
vdump $::imagedir/${::casename}_glsl.png