Integration of OCCT 6.5.0 from SVN
[occt.git] / src / StlAPI / StlAPI_Writer.cxx
CommitLineData
7fd59977 1#include <StlAPI_Writer.ixx>
2#include <StlTransfer.hxx>
3#include <TopoDS_Shape.hxx>
4#include <Bnd_Box.hxx>
5#include <RWStl.hxx>
6#include <BRepBndLib.hxx>
7#include <OSD_Path.hxx>
8
9#define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
10#define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
11
12StlAPI_Writer::StlAPI_Writer()
13{
14 theStlMesh = new StlMesh_Mesh;
15 theASCIIMode = Standard_True;
16 theDeflection = 0.01;
17 theRelativeMode = Standard_True;
18 theCoefficient = 0.001;
19}
20
21void StlAPI_Writer::SetDeflection(const Standard_Real aDeflection)
22{
23 theDeflection = aDeflection;
24}
25void StlAPI_Writer::SetCoefficient(const Standard_Real aCoefficient)
26{
27 theCoefficient = aCoefficient;
28}
29
30Standard_Boolean& StlAPI_Writer::RelativeMode()
31{
32 return theRelativeMode;
33}
34
35Standard_Boolean& StlAPI_Writer::ASCIIMode()
36{
37 return theASCIIMode;
38}
39
40void StlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFileName)
41{
42 OSD_Path aFile(aFileName);
43 if (theRelativeMode) {
44 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
45 Bnd_Box Total;
46 BRepBndLib::Add(aShape, Total);
47 Total.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
48 theDeflection = MAX3(aXmax-aXmin , aYmax-aYmin , aZmax-aZmin)*theCoefficient;
49 }
50 StlTransfer::BuildIncrementalMesh(aShape, theDeflection, theStlMesh);
51 // Write the built mesh
52 if (theASCIIMode) {
53 RWStl::WriteAscii(theStlMesh, aFile);
54 }
55 else {
56 RWStl::WriteBinary(theStlMesh, aFile);
57 }
58}
59