我有一个关于如何在pythonOCC中使用样条线的两部分问题。
首先,我知道我可以使用
创建样条曲线array = []
array.append(gp_Pnt2d (0,0))
array.append(gp_Pnt2d (1,2))
array.append(gp_Pnt2d (2,3))
array.append(gp_Pnt2d (4,3))
array.append(gp_Pnt2d (5,5))
pt2d_list = point2d_list_to_TColgp_Array1OfPnt2d(array)
SPL1 = Geom2dAPI_PointsToBSpline(pt2d_list).Curve()
display.DisplayShape(make_edge2d(SPL1) , update=True)
我希望bspline可以通过
计算BSPL1 = Geom2dAPI_PointsToBSpline(pt2d_list)
但我怎么得到:
如何删除或添加bspline结?
其次,在pythonOCC中加载CAD绘图.stp文件时,如下所示:
from OCC import TopoDS, StlAPI
shape = TopoDS.TopoDS_Shape()
stl_reader = StlAPI.StlAPI_Reader()
stl_reader.Read(shape,str(filename))
display.DisplayShape(shape)
如何从knot,bspline和coefficient等形状中获取数据。
答案 0 :(得分:1)
我已经使用python-boost
来实现这一点。
看看这个功能:http://letslearncomputing.blogspot.com/2013/04/c-program-for-cubic-spline-interpolation.html
你可以在这里得到你想要的5个值。
您只需将代码修改为C++
(不是C
)
BOOST_PYTHON_MODULE(Spline)
{
import_array();
boost::python::numeric::array::set_module_and_type("numpy", "ndarray");
class_<Spline, Spline*>("Spline", init<>())
.def("spline", &Spline::spline)
;
}
所以在Python中你可以使用:
from Spline.Spline import *
operation = Spline()
value, error_ = operation.spline(np.array(your_x_array), np.array(your_y_array), 0.01)
Cpp类:
#define NUMBER_OF_SAMPLES 14
class Spline
{
public:
boost::python::list spline(numeric::array& x_val, numeric::array& y_val, double look_up_val);
};
然后在boost::python::list Spline::spline(numeric::array& x_val, numeric::array& y_val, double p)
函数中得到:
PyArrayObject* x_pyArr = (PyArrayObject*)PyArray_FROM_O(x_val.ptr());
PyArrayObject* y_pyArr = (PyArrayObject*)PyArray_FROM_O(y_val.ptr());
int size = *(x_pyArr->dimensions), i , j;
double* data_x = (double*)x_pyArr->data;
double* data_y = (double*)y_pyArr->data;
double h[NUMBER_OF_SAMPLES], a, b, c, d, s[NUMBER_OF_SAMPLES] = { 0 }, F[NUMBER_OF_SAMPLES], f[NUMBER_OF_SAMPLES], x[NUMBER_OF_SAMPLES], m[NUMBER_OF_SAMPLES][NUMBER_OF_SAMPLES] = { 0 }, temp;
for (int i = 0; i < size; i++)
{
x[i] = *(data_x + i);
f[i] = *(data_y + i);
}
根据链接中的代码等等。我在Spline::spline
函数中返回一个python列表:
boost::python::list return_val;
// ....
return_val.append(sum);
return_val.append(result);
return return_val;
答案 1 :(得分:0)
我会看一下scipy documentation并在那里搜索您尝试应用的功能。