# eryar

PipeCAD - Plant Piping Design Software.
RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
posts - 595, comments - 590, trackbacks - 0, articles - 0

eryar@163.com

B样条曲面

## 3 Conclusion

``````
#include <TColgp_Array2OfPnt.hxx>
#include <Geom_Plane.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_ConicalSurface.hxx>
#include <Geom_SphericalSurface.hxx>
#include <Geom_ToroidalSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <GeomAPI_PointsToBSplineSurface.hxx>
#include <IntPatch_Polyhedron.hxx>
#include <IntPatch_InterferencePolyhedron.hxx>
#pragma comment(lib, "TKernel.lib")
#pragma comment(lib, "TKMath.lib")
#pragma comment(lib, "TKG2d.lib")
#pragma comment(lib, "TKG3d.lib")
#pragma comment(lib, "TKGeomBase.lib")
#pragma comment(lib, "TKGeomAlgo.lib")
void makeSurface(Handle(Geom_BSplineSurface)& theSurface)
{
TColgp_Array2OfPnt aPoints(1, 5, 1, 5);
aPoints.SetValue(1, 1, gp_Pnt(-4, -4, 5));
aPoints.SetValue(1, 2, gp_Pnt(-4, -2, 5));
aPoints.SetValue(1, 3, gp_Pnt(-4, 0, 4));
aPoints.SetValue(1, 4, gp_Pnt(-4, 2, 5));
aPoints.SetValue(1, 5, gp_Pnt(-4, 4, 5));
aPoints.SetValue(2, 1, gp_Pnt(-2, -4, 4));
aPoints.SetValue(2, 2, gp_Pnt(-2, -2, 4));
aPoints.SetValue(2, 3, gp_Pnt(-2, 0, 4));
aPoints.SetValue(2, 4, gp_Pnt(-2, 2, 4));
aPoints.SetValue(2, 5, gp_Pnt(-2, 5, 4));
aPoints.SetValue(3, 1, gp_Pnt(0, -4, 3.5));
aPoints.SetValue(3, 2, gp_Pnt(0, -2, 3.5));
aPoints.SetValue(3, 3, gp_Pnt(0, 0, 3.5));
aPoints.SetValue(3, 4, gp_Pnt(0, 2, 3.5));
aPoints.SetValue(3, 5, gp_Pnt(0, 5, 3.5));
aPoints.SetValue(4, 1, gp_Pnt(2, -4, 4));
aPoints.SetValue(4, 2, gp_Pnt(2, -2, 4));
aPoints.SetValue(4, 3, gp_Pnt(2, 0, 3.5));
aPoints.SetValue(4, 4, gp_Pnt(2, 2, 5));
aPoints.SetValue(4, 5, gp_Pnt(2, 5, 4));
aPoints.SetValue(5, 1, gp_Pnt(4, -4, 5));
aPoints.SetValue(5, 2, gp_Pnt(4, -2, 5));
aPoints.SetValue(5, 3, gp_Pnt(4, 0, 5));
aPoints.SetValue(5, 4, gp_Pnt(4, 2, 6));
aPoints.SetValue(5, 5, gp_Pnt(4, 5, 5));
theSurface = GeomAPI_PointsToBSplineSurface(aPoints).Surface();
}
void writeStl(const IntPatch_Polyhedron& thePolyhedron, const std::string& theFileName)
{
// Dump surface polyhedron to STL file.
std::ofstream aStlFile(theFileName);
aStlFile << "solid polyhedron" << std::endl;
// Dump triangles.
for (Standard_Integer t = 1; t <= thePolyhedron.NbTriangles(); ++t)
{
Standard_Integer aPi1 = 0;
Standard_Integer aPi2 = 0;
Standard_Integer aPi3 = 0;
thePolyhedron.Triangle(t, aPi1, aPi2, aPi3);
const gp_Pnt& aP1 = thePolyhedron.Point(aPi1);
const gp_Pnt& aP2 = thePolyhedron.Point(aPi2);
const gp_Pnt& aP3 = thePolyhedron.Point(aPi3);
aStlFile << "facet" << std::endl;
aStlFile << "outer loop" << std::endl;
aStlFile << "vertex " << aP1.X() << " " << aP1.Y() << " " << aP1.Z() << std::endl;
aStlFile << "vertex " << aP2.X() << " " << aP2.Y() << " " << aP2.Z() << std::endl;
aStlFile << "vertex " << aP3.X() << " " << aP3.Y() << " " << aP3.Z() << std::endl;
aStlFile << "endloop" << std::endl;
aStlFile << "endfacet" << std::endl;
}
aStlFile << "endsolid polyhedron" << std::endl;
aStlFile.close();
}
void testPolyhedron()
{
// Plane surface polyhedron.
Handle(Geom_Plane) aPlane = new Geom_Plane(gp::XOY());
writeStl(aPlanePolyhedron, "d:/plane.stl");
// Spherical surface polyhedron.
Handle(Geom_SphericalSurface) aSphericalSurface = new Geom_SphericalSurface(gp::XOY(), 3.0);
writeStl(aSphericalPolyhedron, "d:/spherical.stl");
// Cylindrical surface polyhedron.
Handle(Geom_CylindricalSurface) aCylindricalSurface = new Geom_CylindricalSurface(gp::XOY(), 5.0);
writeStl(aCylindricalPolyhedron, "d:/cylindrical.stl");
// Toroidal Surface polyhedron.
Handle(Geom_ToroidalSurface) aToroidalSurface = new Geom_ToroidalSurface(gp::XOY(), 10.0, 3.0);
writeStl(aToroidalPolyhedron, "d:/toroidal.stl");
// BSpline surface polyhedron.
Handle(Geom_BSplineSurface) aBSplineSurface;
makeSurface(aBSplineSurface);