繁体   English   中英

点的 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': 没有合适的默认构造函数可用[line 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' [line 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" 这是预编译的头文件。 必须首先被包括在内 原因请参见此处: 什么是“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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM