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

0023743: AIS_Triangulation crashes if Poly_Triangulation has no normals

A crash on absent normals is avoided.
AIS_Triangulation::Compute() is corrected so that it is much faster,
Adding test case for this fix
This commit is contained in:
vro 2013-02-15 16:52:07 +04:00
parent 5f05c0a3d8
commit 16e65a0347
2 changed files with 55 additions and 14 deletions

View File

@ -56,14 +56,9 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre
case 0:
const TColgp_Array1OfPnt& nodes = myTriangulation->Nodes(); //Nodes
const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles(); //Triangle
const TShort_Array1OfShortReal& normals = myTriangulation->Normals(); //Normal
Standard_Boolean hasVNormals = Standard_False;
Standard_Boolean hasVColors = Standard_False;
if( normals.Length() > 0 )
hasVNormals = Standard_True;
if( myFlagColor == 1 )
hasVColors = Standard_True;
Standard_Boolean hasVNormals = myTriangulation->HasNormals();
Standard_Boolean hasVColors = (myFlagColor == 1);
Handle(Graphic3d_ArrayOfTriangles) anArray =
new Graphic3d_ArrayOfTriangles ( myNbNodes, //maxVertexs
@ -80,13 +75,46 @@ void AIS_Triangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre
Standard_Integer j;
Standard_Real ambient = aspect->FrontMaterial().Ambient();
for ( i = nodes.Lower(); i<= nodes.Upper(); i++ ){
if( myFlagColor == 1 )
anArray->AddVertex( nodes(i), AttenuateColor(myColor->Value(i),ambient));
if( myFlagColor == 0 )
anArray->AddVertex( nodes(i) );
j = (i - nodes.Lower()) * 3;
anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3));
if (hasVNormals)
{
const TShort_Array1OfShortReal& normals = myTriangulation->Normals();
if (hasVColors)
{
const TColStd_Array1OfInteger& colors = myColor->Array1();
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ )
{
j = (i - nodes.Lower()) * 3;
anArray->AddVertex(nodes(i), AttenuateColor(colors(i), ambient));
anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3));
}
}
else // !hasVColors
{
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ )
{
j = (i - nodes.Lower()) * 3;
anArray->AddVertex(nodes(i));
anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3));
}
}
}
else // !hasVNormals
{
if (hasVColors)
{
const TColStd_Array1OfInteger& colors = myColor->Array1();
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ )
{
anArray->AddVertex(nodes(i), AttenuateColor(colors(i), ambient));
}
}
else // !hasVColors
{
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ )
{
anArray->AddVertex(nodes(i));
}
}
}
Standard_Integer indexTriangle[3] = {0,0,0};

13
tests/bugs/vis/bug23743 Executable file
View File

@ -0,0 +1,13 @@
puts "================"
puts "CR23743"
puts "================"
puts ""
#######################################################################
# AIS_Triangulation crashes if Poly_Triangulation has no normals
#######################################################################
vinit
vdrawsphere result 100
vfit
set only_screen 1