mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
0025279: OCCT fails to read VRML file created by OCCT
1) Version of VRML format is added to VrmlAPI_Writer::Write() and VrmlAPI::Write() to allow use the both versions of the VRML by one writer. 2) Unification of the command to write VRML of both versions. Now "writevrml" command can write VRLM files of v1.0 and v2.0, with wireframe/shaded/both representations. Parameter "Deflection" was removed (next commit will remove meshing, so parameter will be useless). 3) Meshing is removed from writers of both (v1.0 and v2.0) versions. Shaded representation is skipped in case when a mesh does not exist. Wireframe representation checks the existence of a mesh before. If the mesh exists, a deflected edges are taken from the mesh, otherwise - are generated with the default deflection. 4) Drawing of redundant edges is removed in wireframe representation of VRML version 1.0 (a grid on non-plane surfaces does not match a real edges of TopoDS_Shape and does not match representation in version 2.0). Test case for issue CR25279
This commit is contained in:
@@ -41,8 +41,8 @@ is
|
||||
class Writer;
|
||||
---Purpose: With help of this class user can change parameters of writing.
|
||||
|
||||
Write(aShape: Shape from TopoDS; aFileName: CString from Standard);
|
||||
---Purpose: Converts the shape aShape to VRML format and writes it
|
||||
Write(aShape: Shape from TopoDS; aFileName: CString from Standard; aVersion: Integer = 2);
|
||||
---Purpose: Converts the shape aShape to VRML format of the passed version and writes it
|
||||
-- to the file identified by aFileName using default parameters.
|
||||
|
||||
end VrmlAPI;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
#include <VrmlAPI_Writer.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
|
||||
void VrmlAPI::Write(const TopoDS_Shape& aShape, const Standard_CString aFileName) {
|
||||
void VrmlAPI::Write(const TopoDS_Shape& aShape, const Standard_CString aFileName, const Standard_Integer aVersion) {
|
||||
VrmlAPI_Writer writer;
|
||||
writer.Write(aShape, aFileName);
|
||||
writer.Write(aShape, aFileName, aVersion);
|
||||
}
|
||||
|
@@ -81,9 +81,19 @@ is
|
||||
GetFreeBoundsMaterial(me) returns Material from Vrml;
|
||||
GetUnfreeBoundsMaterial(me) returns Material from Vrml;
|
||||
|
||||
Write(me; aShape : Shape from TopoDS; aFile : CString from Standard);
|
||||
Write(me; aShape : Shape from TopoDS; aFile : CString from Standard; aVersion: Integer = 2);
|
||||
---Purpose: Converts the shape aShape to
|
||||
-- VRML format and writes it to the file identified by aFile.
|
||||
-- VRML format of the passed version and writes it to the file identified by aFile.
|
||||
|
||||
write_v1(me; aShape: Shape from TopoDS; aFileName: CString from Standard)
|
||||
is protected;
|
||||
---Purpose: Converts the shape aShape to VRML format of version 1.0 and writes it
|
||||
-- to the file identified by aFileName using default parameters.
|
||||
|
||||
write_v2(me; aShape: Shape from TopoDS; aFileName: CString from Standard)
|
||||
is protected;
|
||||
---Purpose: Converts the shape aShape to VRML format of version 2.0 and writes it
|
||||
-- to the file identified by aFileName using default parameters.
|
||||
|
||||
fields
|
||||
myRepresentation : RepresentationOfShape from VrmlAPI;
|
||||
|
@@ -30,7 +30,15 @@
|
||||
#include <Vrml_Instancing.hxx>
|
||||
#include <Vrml_Separator.hxx>
|
||||
#include <VrmlConverter_WFDeflectionShape.hxx>
|
||||
#include <VrmlData_Scene.hxx>
|
||||
#include <VrmlData_ShapeConvert.hxx>
|
||||
#include <OSD_OpenFile.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopAbs_ShapeEnum.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <Poly_Triangulation.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
|
||||
VrmlAPI_Writer::VrmlAPI_Writer()
|
||||
{
|
||||
@@ -212,7 +220,15 @@ Handle(Vrml_Material) VrmlAPI_Writer::GetUnfreeBoundsMaterial() const
|
||||
return myUnfreeBoundsMaterial;
|
||||
}
|
||||
|
||||
void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFile) const
|
||||
void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFile, const Standard_Integer aVersion) const
|
||||
{
|
||||
if (aVersion == 1)
|
||||
write_v1(aShape, aFile);
|
||||
else if (aVersion == 2)
|
||||
write_v2(aShape, aFile);
|
||||
}
|
||||
|
||||
void VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Standard_CString aFile) const
|
||||
{
|
||||
OSD_Path thePath(aFile);
|
||||
TCollection_AsciiString theFile;thePath.SystemName(theFile);
|
||||
@@ -263,6 +279,26 @@ void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFi
|
||||
TopTools_Array1OfShape Shapes(1,1);
|
||||
Shapes.SetValue(1,aShape);
|
||||
|
||||
// Check shape tesselation
|
||||
TopExp_Explorer anExp (aShape, TopAbs_FACE);
|
||||
TopLoc_Location aLoc;
|
||||
Standard_Boolean hasTriangles = Standard_False;
|
||||
for (; anExp.More(); anExp.Next())
|
||||
{
|
||||
const TopoDS_Face& aFace = TopoDS::Face (anExp.Current());
|
||||
if (!aFace.IsNull())
|
||||
{
|
||||
Handle(Poly_Triangulation) aTri =
|
||||
BRep_Tool::Triangulation (aFace, aLoc);
|
||||
|
||||
if (!aTri.IsNull())
|
||||
{
|
||||
hasTriangles = Standard_True;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=========================================
|
||||
//---- Definition of data for Projector
|
||||
//=========================================
|
||||
@@ -296,7 +332,7 @@ void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFi
|
||||
projector1->Add(outfile);
|
||||
Vrml_Separator S2;
|
||||
S2.Print(outfile);
|
||||
if (myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation)
|
||||
if ( (myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation) && hasTriangles)
|
||||
{
|
||||
Vrml_Group Group1;
|
||||
Group1.Print(outfile);
|
||||
@@ -318,3 +354,23 @@ void VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFi
|
||||
S1.Print(outfile);
|
||||
}
|
||||
|
||||
void VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,const Standard_CString aFile) const
|
||||
{
|
||||
Standard_Boolean anExtFace = Standard_False;
|
||||
if(myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation)
|
||||
anExtFace = Standard_True;
|
||||
|
||||
Standard_Boolean anExtEdge = Standard_False;
|
||||
if(myRepresentation == VrmlAPI_WireFrameRepresentation|| myRepresentation == VrmlAPI_BothRepresentation)
|
||||
anExtEdge = Standard_True;
|
||||
|
||||
VrmlData_Scene aScene;
|
||||
VrmlData_ShapeConvert aConv(aScene);
|
||||
aConv.AddShape(aShape);
|
||||
aConv.Convert(anExtFace, anExtEdge);
|
||||
|
||||
filebuf aFoc;
|
||||
ostream outStream (&aFoc);
|
||||
if (aFoc.open (aFile, ios::out))
|
||||
outStream << aScene;
|
||||
}
|
||||
|
Reference in New Issue
Block a user