mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-05-01 10:26:12 +03:00
0030389: Data Exchange - StlAPI_Writer does not check if the face has triangulation
When merging triangulation of the faces skip those having no triangulation. Test case for the issue.
This commit is contained in:
parent
7e19e96ae9
commit
44d5a096a3
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
#include <Bnd_Box.hxx>
|
#include <Bnd_Box.hxx>
|
||||||
#include <BRepBndLib.hxx>
|
#include <BRepBndLib.hxx>
|
||||||
|
#include <Message.hxx>
|
||||||
|
#include <Message_Messenger.hxx>
|
||||||
#include <OSD_Path.hxx>
|
#include <OSD_Path.hxx>
|
||||||
#include <OSD_OpenFile.hxx>
|
#include <OSD_OpenFile.hxx>
|
||||||
#include <RWStl.hxx>
|
#include <RWStl.hxx>
|
||||||
@ -56,16 +58,29 @@ Standard_Boolean StlAPI_Writer::Write (const TopoDS_Shape& theShape,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (aNbTriangles == 0)
|
||||||
|
{
|
||||||
|
// No triangulation on the shape
|
||||||
|
return Standard_False;
|
||||||
|
}
|
||||||
|
|
||||||
// create temporary triangulation
|
// create temporary triangulation
|
||||||
Handle(Poly_Triangulation) aMesh = new Poly_Triangulation (aNbNodes, aNbTriangles, Standard_False);
|
Handle(Poly_Triangulation) aMesh = new Poly_Triangulation (aNbNodes, aNbTriangles, Standard_False);
|
||||||
|
// count faces missing triangulation
|
||||||
|
Standard_Integer aNbFacesNoTri = 0;
|
||||||
// fill temporary triangulation
|
// fill temporary triangulation
|
||||||
Standard_Integer aNodeOffset = 0;
|
Standard_Integer aNodeOffset = 0;
|
||||||
Standard_Integer aTriangleOffet = 0;
|
Standard_Integer aTriangleOffet = 0;
|
||||||
for (TopExp_Explorer anExpSF (theShape, TopAbs_FACE); anExpSF.More(); anExpSF.Next())
|
for (TopExp_Explorer anExpSF (theShape, TopAbs_FACE); anExpSF.More(); anExpSF.Next())
|
||||||
{
|
{
|
||||||
|
const TopoDS_Shape& aFace = anExpSF.Current();
|
||||||
TopLoc_Location aLoc;
|
TopLoc_Location aLoc;
|
||||||
Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (TopoDS::Face (anExpSF.Current()), aLoc);
|
Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation (TopoDS::Face (aFace), aLoc);
|
||||||
|
if (aTriangulation.IsNull())
|
||||||
|
{
|
||||||
|
++aNbFacesNoTri;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
|
const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
|
||||||
const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
|
const Poly_Array1OfTriangle& aTriangles = aTriangulation->Triangles();
|
||||||
@ -109,7 +124,20 @@ Standard_Boolean StlAPI_Writer::Write (const TopoDS_Shape& theShape,
|
|||||||
}
|
}
|
||||||
|
|
||||||
OSD_Path aPath (theFileName);
|
OSD_Path aPath (theFileName);
|
||||||
return myASCIIMode
|
Standard_Boolean isDone = (myASCIIMode
|
||||||
? RWStl::WriteAscii (aMesh, aPath)
|
? RWStl::WriteAscii (aMesh, aPath)
|
||||||
: RWStl::WriteBinary (aMesh, aPath);
|
: RWStl::WriteBinary (aMesh, aPath));
|
||||||
|
|
||||||
|
if (isDone && (aNbFacesNoTri > 0))
|
||||||
|
{
|
||||||
|
// Print warning with number of faces missing triangulation
|
||||||
|
TCollection_AsciiString aWarningMsg =
|
||||||
|
TCollection_AsciiString ("Warning: ") +
|
||||||
|
TCollection_AsciiString (aNbFacesNoTri) +
|
||||||
|
TCollection_AsciiString ((aNbFacesNoTri == 1) ? " face has" : " faces have") +
|
||||||
|
TCollection_AsciiString (" been skipped due to null triangulation");
|
||||||
|
Message::DefaultMessenger()->Send (aWarningMsg, Message_Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
return isDone;
|
||||||
}
|
}
|
||||||
|
19
tests/bugs/stlvrml/bug30389
Normal file
19
tests/bugs/stlvrml/bug30389
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "0030389: Data Exchange - StlAPI_Writer does not check if the face has triangulation"
|
||||||
|
puts "========"
|
||||||
|
puts ""
|
||||||
|
|
||||||
|
box b 1 1 1
|
||||||
|
|
||||||
|
# mesh only 5 faces of the box
|
||||||
|
eval compound [lrange [explode b f] 0 4] cf
|
||||||
|
incmesh cf 0.1
|
||||||
|
|
||||||
|
# save box into stl
|
||||||
|
writestl b $imagedir/${casename}.stl
|
||||||
|
|
||||||
|
# read stl
|
||||||
|
readstl result $imagedir/${casename}.stl -brep
|
||||||
|
|
||||||
|
# check that it contains only 10 triangles
|
||||||
|
checknbshapes result -face 10
|
Loading…
x
Reference in New Issue
Block a user