mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
0025357: STL writer does not check the given shape for existing triangulation and remeshes shape using BRepMesh in force mode.
StlTransfer.cxx, function StlTransfer::BuildIncrementalMesh(...) fills the StlMesh_Mesh. Before this fix the StlTransfer always force meshing of the passed shape. Now meshing is completely removed from the StlTransfer. StlWriter can return error status now, for example, if a mesh of the passed shape is empty. In this case file will be not created. Added test case bugs/xde/bug25357 Avoid the warning on gcc compiler. Test scripts were modified according to the fix. 1) bug23192, bug22670, bug23193: removed "isParallel" flag from the command arguments. Manually meshing of the shape (as far as meshing was removed from STL writer). 2) bug22898: before the fix writestl always remeshes the shape with a deflection, related to the boundery box of the shape. For "hammer" shape there is a 38.9076 deflection for mesh. Differences between before writing and after reading are dedicated to fact that stl writes triangulation as an elements of the spahe (like faces, edges etc.)
This commit is contained in:
@@ -25,12 +25,21 @@ uses
|
||||
StlMesh
|
||||
|
||||
is
|
||||
enumeration ErrorStatus is
|
||||
---Purpose: Set of statuses to indicate a type of the error
|
||||
-- occurred during data retrieving and writing operations.
|
||||
StatusOK,
|
||||
MeshIsEmpty,
|
||||
CannotOpenFile
|
||||
|
||||
end ErrorStatus;
|
||||
|
||||
class Writer;
|
||||
class Reader;
|
||||
|
||||
Write(aShape : in Shape from TopoDS;
|
||||
aFile : in CString from Standard;
|
||||
aAsciiMode : in Boolean from Standard = Standard_True);
|
||||
aAsciiMode : in Boolean from Standard = Standard_True) returns ErrorStatus from StlAPI;
|
||||
---Purpose : Convert and write shape to STL format.
|
||||
-- file is written in binary if aAsciiMode is False
|
||||
-- otherwise it is written in Ascii (by default)
|
||||
|
@@ -15,13 +15,13 @@
|
||||
#include <StlAPI_Writer.hxx>
|
||||
#include <StlAPI_Reader.hxx>
|
||||
|
||||
void StlAPI::Write(const TopoDS_Shape& aShape,
|
||||
StlAPI_ErrorStatus StlAPI::Write(const TopoDS_Shape& aShape,
|
||||
const Standard_CString aFile,
|
||||
const Standard_Boolean aAsciiMode)
|
||||
{
|
||||
StlAPI_Writer writer;
|
||||
writer.ASCIIMode() = aAsciiMode;
|
||||
writer.Write (aShape, aFile);
|
||||
return writer.Write (aShape, aFile);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -21,34 +21,12 @@ class Writer from StlAPI
|
||||
|
||||
uses
|
||||
Shape from TopoDS,
|
||||
Mesh from StlMesh
|
||||
Mesh from StlMesh,
|
||||
ErrorStatus from StlAPI
|
||||
is
|
||||
Create;
|
||||
Create;
|
||||
---Purpose: Creates a writer object with
|
||||
-- default parameters: ASCIIMode, RelativeMode, SetCoefficent,
|
||||
-- SetDeflection. These parameters may be modified.
|
||||
|
||||
SetDeflection(me: in out; aDeflection : in Real from Standard);
|
||||
---Purpose: Sets the deflection of the meshing algorithm.
|
||||
-- Deflection is used, only if relative mode is false
|
||||
|
||||
SetCoefficient(me: in out; aCoefficient : in Real from Standard);
|
||||
---Purpose: Sets the coeffiecient for computation of deflection through
|
||||
-- relative size of shape. Default value = 0.001
|
||||
|
||||
RelativeMode(me: in out) returns Boolean;
|
||||
---C++: return &
|
||||
---Purpose: Returns the address to the
|
||||
-- flag defining the relative mode for writing the file.
|
||||
-- This address may be used to either read or change the flag.
|
||||
-- If the mode returns True (default value), the
|
||||
-- deflection is calculated from the relative size of the
|
||||
-- shape. If the mode returns False, the user defined deflection is used.
|
||||
-- Example
|
||||
-- Read:
|
||||
-- Standard_Boolean val = Writer.RelativeMode( );
|
||||
-- Modify:
|
||||
-- Writer.RelativeMode( ) = Standard_True;
|
||||
-- default parameters: ASCIIMode.
|
||||
|
||||
ASCIIMode(me: in out) returns Boolean;
|
||||
---C++: return &
|
||||
@@ -61,14 +39,11 @@ is
|
||||
|
||||
Write(me : in out;
|
||||
aShape : Shape from TopoDS;
|
||||
aFileName : CString from Standard;
|
||||
InParallel : Boolean from Standard = Standard_False);
|
||||
aFileName : CString from Standard) returns ErrorStatus from StlAPI;
|
||||
---Purpose: Converts a given shape to STL format and writes it to file with a given filename.
|
||||
--- \return the error state.
|
||||
|
||||
fields
|
||||
theRelativeMode : Boolean from Standard;
|
||||
theASCIIMode : Boolean from Standard;
|
||||
theDeflection : Real from Standard;
|
||||
theCoefficient : Real from Standard;
|
||||
theStlMesh : Mesh from StlMesh;
|
||||
end Writer;
|
||||
|
@@ -19,30 +19,10 @@
|
||||
#include <BRepBndLib.hxx>
|
||||
#include <OSD_Path.hxx>
|
||||
|
||||
#define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
|
||||
#define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
|
||||
|
||||
StlAPI_Writer::StlAPI_Writer()
|
||||
{
|
||||
theStlMesh = new StlMesh_Mesh;
|
||||
theASCIIMode = Standard_True;
|
||||
theDeflection = 0.01;
|
||||
theRelativeMode = Standard_True;
|
||||
theCoefficient = 0.001;
|
||||
}
|
||||
|
||||
void StlAPI_Writer::SetDeflection(const Standard_Real aDeflection)
|
||||
{
|
||||
theDeflection = aDeflection;
|
||||
}
|
||||
void StlAPI_Writer::SetCoefficient(const Standard_Real aCoefficient)
|
||||
{
|
||||
theCoefficient = aCoefficient;
|
||||
}
|
||||
|
||||
Standard_Boolean& StlAPI_Writer::RelativeMode()
|
||||
{
|
||||
return theRelativeMode;
|
||||
}
|
||||
|
||||
Standard_Boolean& StlAPI_Writer::ASCIIMode()
|
||||
@@ -50,23 +30,26 @@ Standard_Boolean& StlAPI_Writer::ASCIIMode()
|
||||
return theASCIIMode;
|
||||
}
|
||||
|
||||
void StlAPI_Writer::Write(const TopoDS_Shape& theShape, const Standard_CString theFileName, const Standard_Boolean theInParallel)
|
||||
StlAPI_ErrorStatus StlAPI_Writer::Write(const TopoDS_Shape& theShape, const Standard_CString theFileName)
|
||||
{
|
||||
OSD_Path aFile(theFileName);
|
||||
if (theRelativeMode) {
|
||||
Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
|
||||
Bnd_Box Total;
|
||||
BRepBndLib::Add(theShape, Total);
|
||||
Total.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
|
||||
theDeflection = MAX3(aXmax-aXmin , aYmax-aYmin , aZmax-aZmin)*theCoefficient;
|
||||
}
|
||||
StlTransfer::BuildIncrementalMesh(theShape, theDeflection, theInParallel, theStlMesh);
|
||||
StlTransfer::RetrieveMesh(theShape, theStlMesh);
|
||||
|
||||
if (theStlMesh.IsNull() || theStlMesh->IsEmpty())
|
||||
return StlAPI_MeshIsEmpty;
|
||||
|
||||
// Write the built mesh
|
||||
Standard_Boolean wasFileOpened = Standard_False;
|
||||
if (theASCIIMode) {
|
||||
RWStl::WriteAscii(theStlMesh, aFile);
|
||||
wasFileOpened = RWStl::WriteAscii(theStlMesh, aFile);
|
||||
}
|
||||
else {
|
||||
RWStl::WriteBinary(theStlMesh, aFile);
|
||||
wasFileOpened = RWStl::WriteBinary(theStlMesh, aFile);
|
||||
}
|
||||
|
||||
if (!wasFileOpened)
|
||||
return StlAPI_CannotOpenFile;
|
||||
|
||||
return StlAPI_StatusOK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user