I just want to write two simple functions with opencascade to be called from a C# winform application: one for create a surface from points, one for get the points of the surface. I don't write in C++, but following opencascade samples and by documentation and peace of code I arrive to this:
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();
}
I get the following list error in "OCCProxy.cpp":
C2065 'Geom_BSplineSurface': undeclared identifier [line 12]
C2923 'opencascade::handle': 'Geom_BSplineSurface' is not a valid template type argument for parameter 'T' [line 12]
C2133 'srf': unknown size [line 12]
C2512 'opencascade::handle': no appropriate default constructor available [line 12]
C2065 'GeomAPI_PointsToBSplineSurface': undeclared identifier [line 28]
C2146 syntax error: missing ';' before identifier 'srf_approximator' [line 28]
C2065 'GeomAbs_C2': undeclared identifier [line 29]
C3861 'srf_approximator': identifier not found [line 28]
C2065 'srf_approximator': undeclared identifier [line 30]
C2678 binary '->': no operator found which takes a left-hand operand of type 'opencascade::handle' (or there is no acceptable conversion) [line 38]
C2039 'D0': is not a member of 'opencascade::handle' [line 38]
Maybe they are very stupid problem but I can't solve it.
Thanks for any help
Giovanni
Edit - Definition of 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
}
FINALLY, I could replicate and resolve the problem on my computer.
The problem is in line #include "pch.h"
. This is precompiled header. It has to be included first. See here for the reason why: What is "pch.h" and why is it needed to be included as the first header file?
So just move #include "pch.h"
as first line and you will be fine.
#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();
}