问题描述
我只想用 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);
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,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& 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 Standard_Boolean VPeriodic = Standard_False);
... methods
Standard_EXPORT Handle(Geom_Geometry) copy() const Standard_OVERRIDE;
... other methods And fields
}
解决方法
最后,我可以在我的计算机上复制并解决问题。
问题出在第 #include "pch.h"
行。这是预编译的头文件。 必须首先包含它。请参阅此处了解原因:What is "pch.h" and why is it needed to be included as the first header file?
所以只需将 #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);
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,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();
}