mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
32
src/StlAPI/StlAPI.cdl
Executable file
32
src/StlAPI/StlAPI.cdl
Executable file
@@ -0,0 +1,32 @@
|
||||
-- File: StlAPI.cdl
|
||||
-- Created: Tue May 13 15:12:43 1997
|
||||
-- Author: Fabien REUTER
|
||||
-- <frr@sgi69>
|
||||
---Copyright: Matra Datavision 1997
|
||||
|
||||
package StlAPI
|
||||
|
||||
---Purpose : Offers the API for STL data manipulation.
|
||||
--
|
||||
|
||||
uses
|
||||
|
||||
TopoDS,
|
||||
StlMesh
|
||||
|
||||
is
|
||||
class Writer;
|
||||
class Reader;
|
||||
|
||||
Write(aShape : in Shape from TopoDS;
|
||||
aFile : in CString from Standard;
|
||||
aAsciiMode : in Boolean from Standard = Standard_True);
|
||||
---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)
|
||||
|
||||
Read(aShape : in out Shape from TopoDS;
|
||||
aFile : CString from Standard);
|
||||
---Purpose : Create a shape from a STL format.
|
||||
|
||||
end StlAPI;
|
19
src/StlAPI/StlAPI.cxx
Executable file
19
src/StlAPI/StlAPI.cxx
Executable file
@@ -0,0 +1,19 @@
|
||||
#include <StlAPI.ixx>
|
||||
#include <StlAPI_Writer.hxx>
|
||||
#include <StlAPI_Reader.hxx>
|
||||
|
||||
void StlAPI::Write(const TopoDS_Shape& aShape,
|
||||
const Standard_CString aFile,
|
||||
const Standard_Boolean aAsciiMode)
|
||||
{
|
||||
StlAPI_Writer writer;
|
||||
writer.ASCIIMode() = aAsciiMode;
|
||||
writer.Write (aShape, aFile);
|
||||
}
|
||||
|
||||
|
||||
void StlAPI::Read(TopoDS_Shape& aShape,const Standard_CString aFile)
|
||||
{
|
||||
StlAPI_Reader reader;
|
||||
reader.Read (aShape, aFile);
|
||||
}
|
20
src/StlAPI/StlAPI_Reader.cdl
Executable file
20
src/StlAPI/StlAPI_Reader.cdl
Executable file
@@ -0,0 +1,20 @@
|
||||
-- File: StlAPI_Reader.cdl
|
||||
-- Created: Fri Jun 23 14:36:58 2000
|
||||
-- Author: Sergey MOZOKHIN
|
||||
-- <smh@russox.nnov.matra-dtv.fr>
|
||||
---Copyright: Matra Datavision 2000
|
||||
|
||||
|
||||
class Reader from StlAPI
|
||||
|
||||
---Purpose: Reading from stereolithography format.
|
||||
|
||||
uses
|
||||
Shape from TopoDS,
|
||||
Mesh from StlMesh
|
||||
is
|
||||
Create;
|
||||
|
||||
Read(me : in out; aShape : in out Shape from TopoDS; aFileName : CString from Standard);
|
||||
|
||||
end Reader;
|
81
src/StlAPI/StlAPI_Reader.cxx
Executable file
81
src/StlAPI/StlAPI_Reader.cxx
Executable file
@@ -0,0 +1,81 @@
|
||||
#include <StlAPI_Reader.ixx>
|
||||
#include <RWStl.hxx>
|
||||
#include <StlMesh_Mesh.hxx>
|
||||
#include <OSD_Path.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
#include <BRepBuilderAPI_MakePolygon.hxx>
|
||||
#include <BRepBuilderAPI_MakeFace.hxx>
|
||||
#include <BRepBuilderAPI_Sewing.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#include <TopoDS_Wire.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <TopoDS_Shell.hxx>
|
||||
#include <StlMesh_MeshExplorer.hxx>
|
||||
|
||||
|
||||
|
||||
StlAPI_Reader::StlAPI_Reader() {}
|
||||
|
||||
void StlAPI_Reader::Read(TopoDS_Shape& aShape, const Standard_CString aFileName)
|
||||
{
|
||||
OSD_Path aFile(aFileName);
|
||||
|
||||
Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile(aFile);
|
||||
Standard_Integer NumberDomains = aSTLMesh->NbDomains();
|
||||
Standard_Integer iND;
|
||||
gp_XYZ p1, p2, p3;
|
||||
TopoDS_Vertex Vertex1, Vertex2, Vertex3;
|
||||
TopoDS_Face AktFace;
|
||||
TopoDS_Wire AktWire;
|
||||
BRepBuilderAPI_Sewing aSewingTool;
|
||||
Standard_Real x1, y1, z1;
|
||||
Standard_Real x2, y2, z2;
|
||||
Standard_Real x3, y3, z3;
|
||||
|
||||
aSewingTool.Init(1.0e-06,Standard_True);
|
||||
|
||||
TopoDS_Compound aComp;
|
||||
BRep_Builder BuildTool;
|
||||
BuildTool.MakeCompound( aComp );
|
||||
|
||||
StlMesh_MeshExplorer aMExp (aSTLMesh);
|
||||
|
||||
for (iND=1;iND<=NumberDomains;iND++)
|
||||
{
|
||||
for (aMExp.InitTriangle (iND); aMExp.MoreTriangle (); aMExp.NextTriangle ())
|
||||
{
|
||||
aMExp.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3);
|
||||
p1.SetCoord(x1,y1,z1);
|
||||
p2.SetCoord(x2,y2,z2);
|
||||
p3.SetCoord(x3,y3,z3);
|
||||
|
||||
if ((!(p1.IsEqual(p2,0.0))) && (!(p1.IsEqual(p3,0.0))))
|
||||
{
|
||||
Vertex1 = BRepBuilderAPI_MakeVertex(p1);
|
||||
Vertex2 = BRepBuilderAPI_MakeVertex(p2);
|
||||
Vertex3 = BRepBuilderAPI_MakeVertex(p3);
|
||||
|
||||
AktWire = BRepBuilderAPI_MakePolygon( Vertex1, Vertex2, Vertex3, Standard_True);
|
||||
|
||||
if( !AktWire.IsNull())
|
||||
{
|
||||
AktFace = BRepBuilderAPI_MakeFace( AktWire);
|
||||
if(!AktFace.IsNull())
|
||||
BuildTool.Add( aComp, AktFace );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
aSTLMesh->Clear();
|
||||
|
||||
aSewingTool.Load( aComp );
|
||||
aSewingTool.Perform();
|
||||
aShape = aSewingTool.SewedShape();
|
||||
if ( aShape.IsNull() )
|
||||
aShape = aComp;
|
||||
}
|
||||
|
63
src/StlAPI/StlAPI_Writer.cdl
Executable file
63
src/StlAPI/StlAPI_Writer.cdl
Executable file
@@ -0,0 +1,63 @@
|
||||
-- File: StlAPI_Writer.cdl
|
||||
-- Created: Fri Jun 23 14:36:58 2000
|
||||
-- Author: Sergey MOZOKHIN
|
||||
-- <smh@russox.nnov.matra-dtv.fr>
|
||||
---Copyright: Matra Datavision 2000
|
||||
|
||||
|
||||
class Writer from StlAPI
|
||||
|
||||
---Purpose: This class creates and writes
|
||||
-- STL files from Open CASCADE shapes. An STL file can be
|
||||
-- written to an existing STL file or to a new one..
|
||||
|
||||
uses
|
||||
Shape from TopoDS,
|
||||
Mesh from StlMesh
|
||||
is
|
||||
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;
|
||||
|
||||
ASCIIMode(me: in out) returns Boolean;
|
||||
---C++: return &
|
||||
---Purpose: Returns the address to the
|
||||
-- flag defining the 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 generated
|
||||
-- file is an ASCII file. If the mode returns False, the
|
||||
-- generated file is a binary file.
|
||||
|
||||
Write(me : in out; aShape : Shape from TopoDS; aFileName : CString from Standard);
|
||||
---Purpose: Converts a given shape to STL format and writes it to file with a given filename.
|
||||
|
||||
fields
|
||||
theRelativeMode : Boolean from Standard;
|
||||
theASCIIMode : Boolean from Standard;
|
||||
theDeflection : Real from Standard;
|
||||
theCoefficient : Real from Standard;
|
||||
theStlMesh : Mesh from StlMesh;
|
||||
end Writer;
|
59
src/StlAPI/StlAPI_Writer.cxx
Executable file
59
src/StlAPI/StlAPI_Writer.cxx
Executable file
@@ -0,0 +1,59 @@
|
||||
#include <StlAPI_Writer.ixx>
|
||||
#include <StlTransfer.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <Bnd_Box.hxx>
|
||||
#include <RWStl.hxx>
|
||||
#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()
|
||||
{
|
||||
return theASCIIMode;
|
||||
}
|
||||
|
||||
void StlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFileName)
|
||||
{
|
||||
OSD_Path aFile(aFileName);
|
||||
if (theRelativeMode) {
|
||||
Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
|
||||
Bnd_Box Total;
|
||||
BRepBndLib::Add(aShape, Total);
|
||||
Total.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
|
||||
theDeflection = MAX3(aXmax-aXmin , aYmax-aYmin , aZmax-aZmin)*theCoefficient;
|
||||
}
|
||||
StlTransfer::BuildIncrementalMesh(aShape, theDeflection, theStlMesh);
|
||||
// Write the built mesh
|
||||
if (theASCIIMode) {
|
||||
RWStl::WriteAscii(theStlMesh, aFile);
|
||||
}
|
||||
else {
|
||||
RWStl::WriteBinary(theStlMesh, aFile);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user