来自点的 Opencascade 表面

Opencascade surface from points

我只想用 opencascade 编写两个简单的函数,以便从 C# winform 应用程序调用:一个用于从点创建曲面,一个用于获取曲面的点。 我不是用 C++ 编写的,但是遵循 opencascade 示例并通过文档和代码和平我得出了这个:

OCCProxy.h

#pragma once

#ifdef OCCTPROXY_EXPORTS
#define OCCTPROXY_API __declspec(dllexport)
#else
#define OCCTPROXY_API __declspec(dllimport)
#endif

extern "C" OCCTPROXY_API void PtsToSrf(double points[][3], int ptsNumber);

extern "C" OCCTPROXY_API void GetSrfPoint(double u, double v, double& x, double& y, double& z);

OCCProxy.cpp

#include "GeomAbs_Shape.hxx"
#include "Geom_BSplineSurface.hxx"
#include "GeomAPI_PointsToBSplineSurface.hxx"
#include "gp_Pnt.hxx"
#include "NCollection_Mat4.hxx"
#include "OCCTProxy.h"
#include "pch.h"
#include "Standard_Handle.hxx"
#include "TColgp_Array2OfPnt.hxx"

//Approximated surface
Handle(Geom_BSplineSurface) srf; //line 12

//Create approximated surface from a list of point
void PtsToSrf(double points[][3], int ptsNumber)
{
    //convert double array points array     
    TColgp_Array2OfPnt pts(0, ptsNumber, 0, 0);
    for (int i = 0; i < ptsNumber; i++) 
        for (int j = 0; i < 3; i++)
        {
            gp_Pnt pt = gp_Pnt(
                points[i][0], points[i][1], points[i][2]);
            pts.SetValue(i, 0, pt);
        }   

    //approximate a BSpline surface passing through an array of points
    GeomAPI_PointsToBSplineSurface srf_approximator(   //line 28
        pts, 3, 8, GeomAbs_C2, 0.001);   //line 29
    srf = srf_approximator.Surface();   //line 30   
}

//Get approximated surface point
void GetSrfPoint(double u, double v,
    double& x, double& y, double& z)
{
    gp_Pnt p;
    srf->D0(u, v, p);   //line 38
    
    x = p.X();
    y = p.Y();
    z = p.Z();
}

我在“OCCProxy.cpp”中收到以下列表错误:

C2065 'Geom_BSplineSurface': 未声明的标识符 [第 12 行]

C2923 'opencascade::handle':'Geom_BSplineSurface' 不是参数 'T' 的有效模板类型参数 [第 12 行]

C2133 'srf':未知大小 [第 12 行]

C2512 'opencascade::handle': 没有合适的默认构造函数可用 [第 12 行]

C2065 'GeomAPI_PointsToBSplineSurface': 未声明的标识符 [第 28 行]

C2146 语法错误:缺少';'在标识符 'srf_approximator' 之前 [第 28 行]

C2065 'GeomAbs_C2': 未声明的标识符 [第 29 行]

C3861 'srf_approximator': 未找到标识符 [第 28 行]

C2065 'srf_approximator': 未声明的标识符 [第 30 行]

C2678 二进制“->”:未找到采用 'opencascade::handle' 类型左操作数的运算符(或没有可接受的转换) [第 38 行]

C2039 'D0': 不是 'opencascade::handle' [第 38 行]

的成员

也许他们是很愚蠢的问题,但我无法解决。

感谢您的帮助

乔凡尼

编辑 - Geom_BSplineSurface

的定义
class Geom_BSplineSurface;
DEFINE_STANDARD_HANDLE(Geom_BSplineSurface, Geom_BoundedSurface)

class Geom_BSplineSurface : public Geom_BoundedSurface
{

public:

  Standard_EXPORT Geom_BSplineSurface(const TColgp_Array2OfPnt& Poles, const TColStd_Array1OfReal& UKnots, const TColStd_Array1OfReal& VKnots, const TColStd_Array1OfInteger& UMults, const TColStd_Array1OfInteger& VMults, const Standard_Integer UDegree, const Standard_Integer VDegree, const Standard_Boolean UPeriodic = Standard_False, const Standard_Boolean VPeriodic = Standard_False);

  Standard_EXPORT Geom_BSplineSurface(const TColgp_Array2OfPnt& Poles, const TColStd_Array2OfReal& Weights, const TColStd_Array1OfReal& UKnots, const TColStd_Array1OfReal& VKnots, const TColStd_Array1OfInteger& UMults, const TColStd_Array1OfInteger& VMults, const Standard_Integer UDegree, const Standard_Integer VDegree, const Standard_Boolean UPeriodic = Standard_False, const Standard_Boolean VPeriodic = Standard_False);

  ... methods

 Standard_EXPORT Handle(Geom_Geometry) Copy() const Standard_OVERRIDE;

  ... other methods And fields
}

最后,我可以在我的计算机上复制并解决问题。

问题在行#include "pch.h"。这是预编译头文件。 必须先包含它。原因看这里:

所以只需将 #include "pch.h" 移动到第一行就可以了。

#include "pch.h"
#include <GeomAbs_Shape.hxx>
#include <Geom_BSplineSurface.hxx>
#include <GeomAPI_PointsToBSplineSurface.hxx>
#include "gp_Pnt.hxx"
#include "NCollection_Mat4.hxx"
#include "OCCProxy.h"
#include "Standard_Handle.hxx"
#include "TColgp_Array2OfPnt.hxx"




//Approximated surface
Handle(Geom_BSplineSurface) srf; //line 12

//Create approximated surface from a list of point
extern "C" OCCTPROXY_API void PtsToSrf(double points[][3], int ptsNumber)
{
    //convert double array points array     
    TColgp_Array2OfPnt pts(0, ptsNumber, 0, 0);
    for (int i = 0; i < ptsNumber; i++)
        for (int j = 0; i < 3; i++)
        {
            gp_Pnt pt = gp_Pnt(
                points[i][0], points[i][1], points[i][2]);
            pts.SetValue(i, 0, pt);
        }

    //approximate a BSpline surface passing through an array of points
    GeomAPI_PointsToBSplineSurface srf_approximator(   //line 28
        pts, 3, 8, GeomAbs_C2, 0.001);   //line 29
    srf = srf_approximator.Surface();   //line 30   
}
//
////Get approximated surface point
extern "C" OCCTPROXY_API void GetSrfPoint(double u, double v,
    double& x, double& y, double& z)
{
    gp_Pnt p;
    srf->D0(u, v, p);   //line 38

    x = p.X();
    y = p.Y();
    z = p.Z();
}