23
#include "PreCompiled.h"
25
# include <Geom_BSplineSurface.hxx>
26
# include <GeomAbs_Shape.hxx>
27
# include <GeomAPI_PointsToBSplineSurface.hxx>
28
# include <Precision.hxx>
29
# include <TColgp_Array1OfPnt.hxx>
30
# include <TColgp_Array2OfPnt.hxx>
31
# include <TColStd_Array1OfReal.hxx>
32
# include <TColStd_Array2OfReal.hxx>
33
# include <TColStd_Array1OfInteger.hxx>
35
# include <GeomFill_NSections.hxx>
37
#include <Base/GeometryPyCXX.h>
38
#include <Base/PyWrapParseTupleAndKeywords.h>
39
#include <Base/VectorPy.h>
41
#include "BSplineSurfacePy.h"
42
#include "BSplineSurfacePy.cpp"
43
#include "BSplineCurvePy.h"
50
std::string BSplineSurfacePy::representation() const
52
return "<BSplineSurface object>";
55
PyObject *BSplineSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
58
return new BSplineSurfacePy(new GeomBSplineSurface);
62
int BSplineSurfacePy::PyInit(PyObject* , PyObject* )
67
PyObject* BSplineSurfacePy::bounds(PyObject *args)
69
if (!PyArg_ParseTuple(args, ""))
72
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
73
(getGeometryPtr()->handle());
75
Standard_Real u1,u2,v1,v2;
76
surf->Bounds(u1,u2,v1,v2);
77
bound.setItem(0,Py::Float(u1));
78
bound.setItem(1,Py::Float(u2));
79
bound.setItem(2,Py::Float(v1));
80
bound.setItem(3,Py::Float(v2));
81
return Py::new_reference_to(bound);
84
PyObject* BSplineSurfacePy::isURational(PyObject *args)
86
if (!PyArg_ParseTuple(args, ""))
89
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
90
(getGeometryPtr()->handle());
91
Standard_Boolean val = surf->IsURational();
92
return PyBool_FromLong(val ? 1 : 0);
95
PyObject* BSplineSurfacePy::isVRational(PyObject *args)
97
if (!PyArg_ParseTuple(args, ""))
100
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
101
(getGeometryPtr()->handle());
102
Standard_Boolean val = surf->IsVRational();
103
return PyBool_FromLong(val ? 1 : 0);
106
PyObject* BSplineSurfacePy::isUPeriodic(PyObject *args)
108
if (!PyArg_ParseTuple(args, ""))
111
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
112
(getGeometryPtr()->handle());
113
Standard_Boolean val = surf->IsUPeriodic();
114
return PyBool_FromLong(val ? 1 : 0);
117
PyObject* BSplineSurfacePy::isVPeriodic(PyObject *args)
119
if (!PyArg_ParseTuple(args, ""))
122
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
123
(getGeometryPtr()->handle());
124
Standard_Boolean val = surf->IsVPeriodic();
125
return PyBool_FromLong(val ? 1 : 0);
128
PyObject* BSplineSurfacePy::isUClosed(PyObject *args)
130
if (!PyArg_ParseTuple(args, ""))
133
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
134
(getGeometryPtr()->handle());
135
Standard_Boolean val = surf->IsUClosed();
136
return PyBool_FromLong(val ? 1 : 0);
139
PyObject* BSplineSurfacePy::isVClosed(PyObject *args)
141
if (!PyArg_ParseTuple(args, ""))
144
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
145
(getGeometryPtr()->handle());
146
Standard_Boolean val = surf->IsVPeriodic();
147
return PyBool_FromLong(val ? 1 : 0);
150
PyObject* BSplineSurfacePy::increaseDegree(PyObject *args)
152
int udegree, vdegree;
153
if (!PyArg_ParseTuple(args, "ii",&udegree,&vdegree))
156
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
157
(getGeometryPtr()->handle());
158
surf->IncreaseDegree(udegree,vdegree);
162
PyObject* BSplineSurfacePy::increaseUMultiplicity(PyObject *args)
166
if (!PyArg_ParseTuple(args, "ii|i", &start, &end, &mult))
169
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
170
(getGeometryPtr()->handle());
173
surf->IncreaseUMultiplicity(start, mult);
176
surf->IncreaseUMultiplicity(start, end, mult);
182
PyObject* BSplineSurfacePy::increaseVMultiplicity(PyObject *args)
186
if (!PyArg_ParseTuple(args, "ii|i", &start, &end, &mult))
189
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
190
(getGeometryPtr()->handle());
193
surf->IncreaseVMultiplicity(start, mult);
196
surf->IncreaseVMultiplicity(start, end, mult);
202
PyObject* BSplineSurfacePy::incrementUMultiplicity(PyObject *args)
204
int start, end, mult;
205
if (!PyArg_ParseTuple(args, "iii", &start, &end, &mult))
209
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
210
(getGeometryPtr()->handle());
211
surf->IncrementUMultiplicity(start, end, mult);
213
catch (Standard_Failure& e) {
214
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
221
PyObject* BSplineSurfacePy::incrementVMultiplicity(PyObject *args)
223
int start, end, mult;
224
if (!PyArg_ParseTuple(args, "iii", &start, &end, &mult))
228
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
229
(getGeometryPtr()->handle());
230
surf->IncrementVMultiplicity(start, end, mult);
232
catch (Standard_Failure& e) {
233
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
240
PyObject* BSplineSurfacePy::insertUKnot(PyObject *args)
244
PyObject* add = Py_True;
245
if (!PyArg_ParseTuple(args, "did|O!", &U, &M, &tol, &PyBool_Type, &add))
249
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
250
(getGeometryPtr()->handle());
251
surf->InsertUKnot(U, M, tol, Base::asBoolean(add));
253
catch (Standard_Failure& e) {
254
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
261
PyObject* BSplineSurfacePy::insertUKnots(PyObject *args)
264
PyObject* add = Py_True;
267
if (!PyArg_ParseTuple(args, "OO|dO!", &obj1,
269
&tol, &PyBool_Type, &add))
273
Py::Sequence knots(obj1);
274
TColStd_Array1OfReal k(1,knots.size());
276
for (Py::Sequence::iterator it = knots.begin(); it != knots.end(); ++it) {
278
k(index++) = (double)val;
280
Py::Sequence mults(obj2);
281
TColStd_Array1OfInteger m(1,mults.size());
283
for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) {
285
m(index++) = (int)val;
288
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
289
(getGeometryPtr()->handle());
290
surf->InsertUKnots(k, m, tol, Base::asBoolean(add));
293
catch (Standard_Failure& e) {
294
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
301
PyObject* BSplineSurfacePy::insertVKnot(PyObject *args)
305
PyObject* add = Py_True;
306
if (!PyArg_ParseTuple(args, "did|O!", &V, &M, &tol, &PyBool_Type, &add))
310
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
311
(getGeometryPtr()->handle());
312
surf->InsertVKnot(V, M, tol, Base::asBoolean(add));
314
catch (Standard_Failure& e) {
315
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
322
PyObject* BSplineSurfacePy::insertVKnots(PyObject *args)
325
PyObject* add = Py_True;
328
if (!PyArg_ParseTuple(args, "OO|dO!", &obj1,
330
&tol, &PyBool_Type, &add))
334
Py::Sequence knots(obj1);
335
TColStd_Array1OfReal k(1,knots.size());
337
for (Py::Sequence::iterator it = knots.begin(); it != knots.end(); ++it) {
339
k(index++) = (double)val;
341
Py::Sequence mults(obj2);
342
TColStd_Array1OfInteger m(1,mults.size());
344
for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) {
346
m(index++) = (int)val;
349
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
350
(getGeometryPtr()->handle());
351
surf->InsertVKnots(k, m, tol, Base::asBoolean(add));
354
catch (Standard_Failure& e) {
355
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
362
PyObject* BSplineSurfacePy::removeUKnot(PyObject *args)
366
if (!PyArg_ParseTuple(args, "iid", &Index, &M, &tol))
370
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
371
(getGeometryPtr()->handle());
372
Standard_Boolean ok = surf->RemoveUKnot(Index,M,tol);
373
return PyBool_FromLong(ok ? 1 : 0);
375
catch (Standard_Failure& e) {
376
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
381
PyObject* BSplineSurfacePy::removeVKnot(PyObject *args)
385
if (!PyArg_ParseTuple(args, "iid", &Index, &M, &tol))
389
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
390
(getGeometryPtr()->handle());
391
Standard_Boolean ok = surf->RemoveVKnot(Index,M,tol);
392
return PyBool_FromLong(ok ? 1 : 0);
394
catch (Standard_Failure& e) {
395
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
400
PyObject* BSplineSurfacePy::segment(PyObject *args)
403
if (!PyArg_ParseTuple(args, "dddd", &u1,&u2,&v1,&v2))
406
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
407
(getGeometryPtr()->handle());
408
surf->Segment(u1,u2,v1,v2);
411
catch (Standard_Failure& e) {
413
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
418
PyObject* BSplineSurfacePy::setUKnot(PyObject *args)
422
if (!PyArg_ParseTuple(args, "id|i", &Index, &K, &M))
425
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
426
(getGeometryPtr()->handle());
428
surf->SetUKnot(Index, K);
431
surf->SetUKnot(Index, K, M);
437
PyObject* BSplineSurfacePy::setVKnot(PyObject *args)
441
if (!PyArg_ParseTuple(args, "id|i", &Index, &K, &M))
444
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
445
(getGeometryPtr()->handle());
447
surf->SetVKnot(Index, K);
450
surf->SetVKnot(Index, K, M);
456
PyObject* BSplineSurfacePy::getUKnot(PyObject *args)
459
if (!PyArg_ParseTuple(args, "i", &Index))
462
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
463
(getGeometryPtr()->handle());
464
double M = surf->UKnot(Index);
466
return Py_BuildValue("d",M);
469
PyObject* BSplineSurfacePy::getVKnot(PyObject *args)
472
if (!PyArg_ParseTuple(args, "i", &Index))
475
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
476
(getGeometryPtr()->handle());
477
double M = surf->VKnot(Index);
479
return Py_BuildValue("d",M);
482
PyObject* BSplineSurfacePy::setUKnots(PyObject *args)
485
if (!PyArg_ParseTuple(args, "O", &obj))
488
Py::Sequence list(obj);
489
TColStd_Array1OfReal k(1,list.size());
491
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
493
k(index++) = (double)val;
496
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
497
(getGeometryPtr()->handle());
501
catch (Standard_Failure& e) {
502
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
507
PyObject* BSplineSurfacePy::setVKnots(PyObject *args)
510
if (!PyArg_ParseTuple(args, "O", &obj))
513
Py::Sequence list(obj);
514
TColStd_Array1OfReal k(1,list.size());
516
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
518
k(index++) = (double)val;
521
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
522
(getGeometryPtr()->handle());
526
catch (Standard_Failure& e) {
527
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
532
PyObject* BSplineSurfacePy::getUKnots(PyObject *args)
534
if (!PyArg_ParseTuple(args, ""))
537
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
538
(getGeometryPtr()->handle());
539
TColStd_Array1OfReal w(1,surf->NbUKnots());
542
for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) {
543
knots.append(Py::Float(w(i)));
545
return Py::new_reference_to(knots);
547
catch (Standard_Failure& e) {
548
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
553
PyObject* BSplineSurfacePy::getVKnots(PyObject *args)
555
if (!PyArg_ParseTuple(args, ""))
558
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
559
(getGeometryPtr()->handle());
560
TColStd_Array1OfReal w(1,surf->NbVKnots());
563
for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) {
564
knots.append(Py::Float(w(i)));
566
return Py::new_reference_to(knots);
568
catch (Standard_Failure& e) {
569
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
574
PyObject* BSplineSurfacePy::setPole(PyObject *args)
579
if (!PyArg_ParseTuple(args, "iiO!|d", &uindex,&vindex,&(Base::VectorPy::Type),&p,&weight))
581
Base::Vector3d vec = static_cast<Base::VectorPy*>(p)->value();
582
gp_Pnt pnt(vec.x, vec.y, vec.z);
584
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
585
(getGeometryPtr()->handle());
587
surf->SetPole(uindex,vindex,pnt);
589
surf->SetPole(uindex,vindex,pnt,weight);
592
catch (Standard_Failure& e) {
593
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
598
PyObject* BSplineSurfacePy::setPoleCol(PyObject *args)
602
PyObject* obj2=nullptr;
603
if (!PyArg_ParseTuple(args, "iO|O",&vindex,&obj,&obj2))
606
Py::Sequence list(obj);
607
TColgp_Array1OfPnt poles(1, list.size());
609
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
611
Base::Vector3d v = p.toVector();
612
poles(index++) = gp_Pnt(v.x,v.y,v.z);
615
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
616
(getGeometryPtr()->handle());
618
surf->SetPoleCol(vindex, poles);
621
Py::Sequence list(obj2);
622
TColStd_Array1OfReal weights(1, list.size());
624
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
625
weights(index++) = (double)Py::Float(*it);
627
surf->SetPoleCol(vindex, poles, weights);
632
catch (Standard_Failure& e) {
633
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
638
PyObject* BSplineSurfacePy::setPoleRow(PyObject *args)
642
PyObject* obj2=nullptr;
643
if (!PyArg_ParseTuple(args, "iO|O",&uindex,&obj,&obj2))
646
Py::Sequence list(obj);
647
TColgp_Array1OfPnt poles(1, list.size());
649
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
651
Base::Vector3d v = p.toVector();
652
poles(index++) = gp_Pnt(v.x,v.y,v.z);
655
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
656
(getGeometryPtr()->handle());
658
surf->SetPoleRow(uindex, poles);
661
Py::Sequence list(obj2);
662
TColStd_Array1OfReal weights(1, list.size());
664
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
665
weights(index++) = (double)Py::Float(*it);
667
surf->SetPoleRow(uindex, poles, weights);
672
catch (Standard_Failure& e) {
673
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
678
PyObject* BSplineSurfacePy::getPole(PyObject *args)
681
if (!PyArg_ParseTuple(args, "ii", &uindex,&vindex))
684
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
685
(getGeometryPtr()->handle());
686
Standard_OutOfRange_Raise_if
687
(uindex < 1 || uindex > surf->NbUPoles() ||
688
vindex < 1 || vindex > surf->NbVPoles(), "Pole index out of range");
689
gp_Pnt pnt = surf->Pole(uindex,vindex);
690
Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d(
691
pnt.X(), pnt.Y(), pnt.Z()));
694
catch (Standard_Failure& e) {
695
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
700
PyObject* BSplineSurfacePy::getPoles(PyObject *args)
702
if (!PyArg_ParseTuple(args, ""))
705
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
706
(getGeometryPtr()->handle());
707
TColgp_Array2OfPnt p(1,surf->NbUPoles(),1,surf->NbVPoles());
710
for (Standard_Integer i=p.LowerRow(); i<=p.UpperRow(); i++) {
712
for (Standard_Integer j=p.LowerCol(); j<=p.UpperCol(); j++) {
713
const gp_Pnt& pole = p(i,j);
714
row.append(Py::asObject(new Base::VectorPy(
715
Base::Vector3d(pole.X(),pole.Y(),pole.Z()))));
719
return Py::new_reference_to(poles);
721
catch (Standard_Failure& e) {
722
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
727
PyObject* BSplineSurfacePy::setWeight(PyObject *args)
731
if (!PyArg_ParseTuple(args, "iid",&uindex,&vindex,&weight))
734
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
735
(getGeometryPtr()->handle());
736
surf->SetWeight(uindex,vindex,weight);
739
catch (Standard_Failure& e) {
740
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
745
PyObject* BSplineSurfacePy::setWeightCol(PyObject *args)
749
if (!PyArg_ParseTuple(args, "iO",&vindex,&obj))
752
Py::Sequence list(obj);
753
TColStd_Array1OfReal weights(1, list.size());
755
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
756
weights(index++) = (double)Py::Float(*it);
759
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
760
(getGeometryPtr()->handle());
761
surf->SetWeightCol(vindex, weights);
764
catch (Standard_Failure& e) {
765
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
770
PyObject* BSplineSurfacePy::setWeightRow(PyObject *args)
774
if (!PyArg_ParseTuple(args, "iO",&uindex,&obj))
777
Py::Sequence list(obj);
778
TColStd_Array1OfReal weights(1, list.size());
780
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
781
weights(index++) = (double)Py::Float(*it);
784
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
785
(getGeometryPtr()->handle());
786
surf->SetWeightRow(uindex, weights);
789
catch (Standard_Failure& e) {
790
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
795
PyObject* BSplineSurfacePy::getWeight(PyObject *args)
798
if (!PyArg_ParseTuple(args, "ii",&uindex,&vindex))
801
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
802
(getGeometryPtr()->handle());
803
Standard_OutOfRange_Raise_if
804
(uindex < 1 || uindex > surf->NbUPoles() ||
805
vindex < 1 || vindex > surf->NbVPoles(), "Weight index out of range");
806
double w = surf->Weight(uindex,vindex);
807
return Py_BuildValue("d", w);
809
catch (Standard_Failure& e) {
810
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
815
PyObject* BSplineSurfacePy::getWeights(PyObject *args)
817
if (!PyArg_ParseTuple(args, ""))
820
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
821
(getGeometryPtr()->handle());
822
TColStd_Array2OfReal w(1,surf->NbUPoles(),1,surf->NbVPoles());
825
for (Standard_Integer i=w.LowerRow(); i<=w.UpperRow(); i++) {
827
for (Standard_Integer j=w.LowerCol(); j<=w.UpperCol(); j++) {
828
row.append(Py::Float(w(i,j)));
832
return Py::new_reference_to(weights);
834
catch (Standard_Failure& e) {
835
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
840
PyObject* BSplineSurfacePy::getPolesAndWeights(PyObject *args)
842
if (!PyArg_ParseTuple(args, ""))
845
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
846
(getGeometryPtr()->handle());
847
TColgp_Array2OfPnt p(1,surf->NbUPoles(),1,surf->NbVPoles());
849
TColStd_Array2OfReal w(1,surf->NbUPoles(),1,surf->NbVPoles());
853
for (Standard_Integer i=p.LowerRow(); i<=p.UpperRow(); i++) {
855
for (Standard_Integer j=p.LowerCol(); j<=p.UpperCol(); j++) {
856
const gp_Pnt& pole = p(i,j);
857
double weight = w(i,j);
859
t.setItem(0, Py::Float(pole.X()));
860
t.setItem(1, Py::Float(pole.Y()));
861
t.setItem(2, Py::Float(pole.Z()));
862
t.setItem(3, Py::Float(weight));
867
return Py::new_reference_to(poles);
869
catch (Standard_Failure& e) {
870
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
875
PyObject* BSplineSurfacePy::getResolution(PyObject *args)
878
if (!PyArg_ParseTuple(args, "d", &tol))
881
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
882
(getGeometryPtr()->handle());
884
surf->Resolution(tol,utol,vtol);
885
return Py_BuildValue("(dd)",utol,vtol);
887
catch (Standard_Failure& e) {
888
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
893
PyObject* BSplineSurfacePy::movePoint(PyObject *args)
896
int uindex1, uindex2;
897
int vindex1, vindex2;
899
if (!PyArg_ParseTuple(args, "ddO!iiii", &U, &V, &(Base::VectorPy::Type),&pnt,
900
&uindex1, &uindex2,&vindex1, &vindex2))
903
Base::Vector3d p = static_cast<Base::VectorPy*>(pnt)->value();
904
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
905
(getGeometryPtr()->handle());
906
int ufirst, ulast, vfirst, vlast;
907
surf->MovePoint(U, V, gp_Pnt(p.x,p.y,p.z), uindex1, uindex2, vindex1, vindex2,
908
ufirst, ulast, vfirst, vlast);
909
return Py_BuildValue("(iiii)",ufirst, ulast, vfirst, vlast);
911
catch (Standard_Failure& e) {
912
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
917
PyObject* BSplineSurfacePy::setUNotPeriodic(PyObject *args)
919
if (!PyArg_ParseTuple(args, ""))
922
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
923
(getGeometryPtr()->handle());
924
surf->SetUNotPeriodic();
927
catch (Standard_Failure& e) {
928
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
933
PyObject* BSplineSurfacePy::setVNotPeriodic(PyObject *args)
935
if (!PyArg_ParseTuple(args, ""))
938
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
939
(getGeometryPtr()->handle());
940
surf->SetVNotPeriodic();
943
catch (Standard_Failure& e) {
944
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
949
PyObject* BSplineSurfacePy::setUPeriodic(PyObject *args)
951
if (!PyArg_ParseTuple(args, ""))
954
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
955
(getGeometryPtr()->handle());
956
surf->SetUPeriodic();
959
catch (Standard_Failure& e) {
960
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
965
PyObject* BSplineSurfacePy::setVPeriodic(PyObject *args)
967
if (!PyArg_ParseTuple(args, ""))
970
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
971
(getGeometryPtr()->handle());
972
surf->SetVPeriodic();
975
catch (Standard_Failure& e) {
976
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
981
PyObject* BSplineSurfacePy::setUOrigin(PyObject *args)
984
if (!PyArg_ParseTuple(args, "i", &index))
987
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
988
(getGeometryPtr()->handle());
989
surf->SetUOrigin(index);
992
catch (Standard_Failure& e) {
993
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
998
PyObject* BSplineSurfacePy::setVOrigin(PyObject *args)
1001
if (!PyArg_ParseTuple(args, "i", &index))
1004
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1005
(getGeometryPtr()->handle());
1006
surf->SetVOrigin(index);
1009
catch (Standard_Failure& e) {
1010
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
1015
PyObject* BSplineSurfacePy::getUMultiplicity(PyObject *args)
1018
if (!PyArg_ParseTuple(args, "i", &index))
1021
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1022
(getGeometryPtr()->handle());
1023
int mult = surf->UMultiplicity(index);
1024
return Py_BuildValue("i", mult);
1026
catch (Standard_Failure& e) {
1027
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
1032
PyObject* BSplineSurfacePy::getVMultiplicity(PyObject *args)
1035
if (!PyArg_ParseTuple(args, "i", &index))
1038
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1039
(getGeometryPtr()->handle());
1040
int mult = surf->VMultiplicity(index);
1041
return Py_BuildValue("i", mult);
1043
catch (Standard_Failure& e) {
1044
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
1049
PyObject* BSplineSurfacePy::getUMultiplicities(PyObject *args)
1051
if (!PyArg_ParseTuple(args, ""))
1054
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1055
(getGeometryPtr()->handle());
1056
TColStd_Array1OfInteger m(1,surf->NbUKnots());
1057
surf->UMultiplicities(m);
1059
for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) {
1060
mults.append(Py::Long(m(i)));
1062
return Py::new_reference_to(mults);
1064
catch (Standard_Failure& e) {
1065
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
1070
PyObject* BSplineSurfacePy::getVMultiplicities(PyObject *args)
1072
if (!PyArg_ParseTuple(args, ""))
1075
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1076
(getGeometryPtr()->handle());
1077
TColStd_Array1OfInteger m(1,surf->NbVKnots());
1078
surf->VMultiplicities(m);
1080
for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) {
1081
mults.append(Py::Long(m(i)));
1083
return Py::new_reference_to(mults);
1085
catch (Standard_Failure& e) {
1086
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
1091
PyObject* BSplineSurfacePy::exchangeUV(PyObject *args)
1093
if (!PyArg_ParseTuple(args, ""))
1096
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1097
(getGeometryPtr()->handle());
1102
PyObject* BSplineSurfacePy::reparametrize(PyObject * args)
1105
double tol = 0.000001;
1106
if (!PyArg_ParseTuple(args, "ii|d", &u, &v, &tol))
1110
u = std::max<int>(u, 2);
1111
v = std::max<int>(v, 2);
1114
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1115
(getGeometryPtr()->handle());
1117
double maxU = surf->UKnot(surf->NbUKnots());
1118
double maxV = surf->VKnot(surf->NbVKnots());
1120
GeomBSplineSurface* geom = new GeomBSplineSurface();
1121
Handle(Geom_BSplineSurface) spline = Handle(Geom_BSplineSurface)::DownCast
1123
for (int i=1; i<u-1; i++) {
1124
double U = i * 1.0 / (u-1.0);
1125
spline->InsertUKnot(U,i,tol,Standard_True);
1128
for (int i=1; i<v-1; i++) {
1129
double V = i * 1.0 / (v-1.0);
1130
spline->InsertVKnot(V,i,tol,Standard_True);
1133
for (int j=0; j<u; j++) {
1134
double U = j * maxU / (u-1.0);
1135
double newU = j * 1.0 / (u-1.0);
1136
for (int k=0; k<v; k++) {
1137
double V = k * maxV / (v-1.0);
1138
double newV = k * 1.0 / (v-1.0);
1140
gp_Pnt point = surf->Value(U,V);
1141
int ufirst, ulast, vfirst, vlast;
1142
spline->MovePoint(newU, newV, point, j+1, j+1, k+1, k+1, ufirst, ulast, vfirst, vlast);
1146
return new BSplineSurfacePy(geom);
1148
catch (Standard_Failure& e) {
1149
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
1154
PyObject* BSplineSurfacePy::approximate(PyObject *args, PyObject *kwds)
1157
Standard_Integer degMin=3;
1158
Standard_Integer degMax=8;
1159
Standard_Integer continuity=2;
1160
Standard_Real tol3d = Precision::Approximation();
1161
const char* parType = "None";
1162
Standard_Real weight1 = 1.0;
1163
Standard_Real weight2 = 1.0;
1164
Standard_Real weight3 = 1.0;
1170
static const std::array<const char *, 14> kwds_interp{"Points", "DegMin", "DegMax", "Continuity", "Tolerance", "X0",
1171
"dX", "Y0", "dY", "ParamType", "LengthWeight",
1172
"CurvatureWeight", "TorsionWeight", nullptr};
1174
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O|iiidddddsddd", kwds_interp, &obj, °Min, °Max,
1175
&continuity, &tol3d, &X0, &dX, &Y0, &dY, &parType, &weight1, &weight2,
1180
Py::Sequence list(obj);
1181
Standard_Integer lu = list.size();
1182
Py::Sequence col(list.getItem(0));
1183
Standard_Integer lv = col.size();
1184
TColgp_Array2OfPnt interpolationPoints(1, lu, 1, lv);
1185
TColStd_Array2OfReal zPoints(1, lu, 1, lv);
1188
Standard_Integer index1 = 0;
1189
Standard_Integer index2 = 0;
1190
for (Py::Sequence::iterator it1 = list.begin(); it1 != list.end(); ++it1) {
1193
Py::Sequence row(*it1);
1194
for (Py::Sequence::iterator it2 = row.begin(); it2 != row.end(); ++it2) {
1196
if ((dX == 0) || (dY == 0)){
1198
Base::Vector3d pnt = v.toVector();
1199
gp_Pnt newPoint(pnt.x,pnt.y,pnt.z);
1200
interpolationPoints.SetValue(index1, index2, newPoint);
1203
Standard_Real val = PyFloat_AsDouble((*it2).ptr());
1204
zPoints.SetValue(index1, index2, val);
1209
if (continuity<0 || continuity>2) {
1210
Standard_Failure::Raise("continuity must be between 0 and 2");
1213
if (interpolationPoints.RowLength() < 2 || interpolationPoints.ColLength() < 2) {
1214
Standard_Failure::Raise("not enough points given");
1217
GeomAbs_Shape c = GeomAbs_C2;
1230
Approx_ParametrizationType pt;
1231
std::string pstr = parType;
1232
Standard_Boolean useParam = Standard_True;
1233
if (pstr == "Uniform" )
1234
pt = Approx_IsoParametric;
1235
else if (pstr == "Centripetal" )
1236
pt = Approx_Centripetal;
1237
else if (pstr == "ChordLength" )
1238
pt = Approx_ChordLength;
1240
useParam = Standard_False;
1242
GeomAPI_PointsToBSplineSurface surInterpolation;
1243
if (!(dX == 0) && !(dY == 0)) {
1245
surInterpolation.Init(zPoints, X0, dX, Y0, dY, degMin, degMax, c, tol3d);
1247
else if (useParam) {
1249
surInterpolation.Init(interpolationPoints, pt, degMin, degMax, c, tol3d);
1251
else if (!(weight1 == 0) || !(weight2 == 0) || !(weight3 == 0)) {
1253
surInterpolation.Init(interpolationPoints, weight1, weight2, weight3, degMax, c, tol3d);
1257
surInterpolation.Init(interpolationPoints, degMin, degMax, c, tol3d);
1259
Handle(Geom_BSplineSurface) sur(surInterpolation.Surface());
1260
this->getGeomBSplineSurfacePtr()->setHandle(sur);
1263
catch (Standard_Failure& e) {
1264
std::string err = e.GetMessageString();
1265
if (err.empty()) err = e.DynamicType()->Name();
1266
PyErr_SetString(PartExceptionOCCError, err.c_str());
1271
PyObject* BSplineSurfacePy::interpolate(PyObject *args)
1279
int len = PyTuple_GET_SIZE(args);
1281
if (!PyArg_ParseTuple(args, "O|dddd", &obj, &X0, &dX, &Y0, &dY))
1284
Py::Sequence list(obj);
1285
Standard_Integer lu = list.size();
1286
Py::Sequence col(list.getItem(0));
1287
Standard_Integer lv = col.size();
1288
TColgp_Array2OfPnt interpolationPoints(1, lu, 1, lv);
1289
TColStd_Array2OfReal zPoints(1, lu, 1, lv);
1291
Standard_Integer index1 = 0;
1292
Standard_Integer index2 = 0;
1293
for (Py::Sequence::iterator it1 = list.begin(); it1 != list.end(); ++it1) {
1296
Py::Sequence row(*it1);
1297
for (Py::Sequence::iterator it2 = row.begin(); it2 != row.end(); ++it2) {
1301
Base::Vector3d pnt = v.toVector();
1302
gp_Pnt newPoint(pnt.x,pnt.y,pnt.z);
1303
interpolationPoints.SetValue(index1, index2, newPoint);
1306
Standard_Real val = PyFloat_AsDouble((*it2).ptr());
1307
zPoints.SetValue(index1, index2, val);
1312
if (interpolationPoints.RowLength() < 2 || interpolationPoints.ColLength() < 2) {
1313
Standard_Failure::Raise("not enough points given");
1316
GeomAPI_PointsToBSplineSurface surInterpolation;
1318
surInterpolation.Interpolate (interpolationPoints);
1321
surInterpolation.Interpolate(zPoints, X0, dX, Y0, dY);
1323
Handle(Geom_BSplineSurface) sur(surInterpolation.Surface());
1324
this->getGeomBSplineSurfacePtr()->setHandle(sur);
1327
catch (Standard_Failure& e) {
1328
std::string err = e.GetMessageString();
1329
if (err.empty()) err = e.DynamicType()->Name();
1330
PyErr_SetString(PartExceptionOCCError, err.c_str());
1335
PyObject* BSplineSurfacePy::buildFromPolesMultsKnots(PyObject *args, PyObject *keywds)
1337
static const std::array<const char *, 11> kwlist{"poles", "umults", "vmults", "uknots", "vknots", "uperiodic",
1338
"vperiodic", "udegree", "vdegree", "weights", nullptr};
1339
PyObject* uperiodic = Py_False;
1340
PyObject* vperiodic = Py_False;
1341
PyObject* poles = Py_None;
1342
PyObject* umults = Py_None;
1343
PyObject* vmults = Py_None;
1344
PyObject* uknots = Py_None;
1345
PyObject* vknots = Py_None;
1346
PyObject* weights = Py_None;
1349
int number_of_uknots = 0;
1350
int number_of_vknots = 0;
1351
int sum_of_umults = 0;
1352
int sum_of_vmults = 0;
1354
if (!Base::Wrapped_ParseTupleAndKeywords(args, keywds, "OOO|OOO!O!iiO", kwlist,
1355
&poles, &umults, &vmults,
1357
&PyBool_Type, &uperiodic, &PyBool_Type, &vperiodic,
1358
&udegree, &vdegree, &weights)) {
1362
Py::Sequence list(poles);
1363
Standard_Integer lu = list.size();
1364
Py::Sequence col(list.getItem(0));
1365
Standard_Integer lv = col.size();
1366
TColgp_Array2OfPnt occpoles(1, lu, 1, lv);
1367
TColStd_Array2OfReal occweights(1, lu, 1, lv);
1368
Standard_Boolean genweights = (weights==Py_None) ? Standard_True : Standard_False;
1369
Standard_Integer index1 = 0;
1370
Standard_Integer index2 = 0;
1371
for (Py::Sequence::iterator it1 = list.begin(); it1 != list.end(); ++it1) {
1374
Py::Sequence row(*it1);
1375
for (Py::Sequence::iterator it2 = row.begin(); it2 != row.end(); ++it2) {
1378
Base::Vector3d pnt = v.toVector();
1379
gp_Pnt newPoint(pnt.x,pnt.y,pnt.z);
1380
occpoles.SetValue(index1, index2, newPoint);
1381
if (genweights) occweights.SetValue(index1, index2, 1.0);
1384
if (occpoles.RowLength() < 2 || occpoles.ColLength() < 2) {
1385
Standard_Failure::Raise("not enough points given");
1388
Py::Sequence list(weights);
1389
Standard_Integer lwu = list.size();
1390
Py::Sequence col(list.getItem(0));
1391
Standard_Integer lwv = col.size();
1392
if (lwu != lu || lwv != lv) { Standard_Failure::Raise("weights and poles mismatch");}
1393
Standard_Integer index1 = 0;
1394
Standard_Integer index2 = 0;
1395
for (Py::Sequence::iterator it1 = list.begin(); it1 != list.end(); ++it1) {
1398
Py::Sequence row(*it1);
1399
for (Py::Sequence::iterator it2 = row.begin(); it2 != row.end(); ++it2) {
1402
occweights.SetValue(index1, index2, f);
1406
number_of_uknots = PyObject_Length(umults);
1407
number_of_vknots = PyObject_Length(vmults);
1408
if (((uknots != Py_None) && PyObject_Length(uknots) != number_of_uknots) ||
1409
((vknots != Py_None) && PyObject_Length(vknots) != number_of_vknots)){
1410
Standard_Failure::Raise("number of knots and mults mismatch");
1414
TColStd_Array1OfInteger occumults(1,number_of_uknots);
1415
TColStd_Array1OfInteger occvmults(1,number_of_vknots);
1416
TColStd_Array1OfReal occuknots(1,number_of_uknots);
1417
TColStd_Array1OfReal occvknots(1,number_of_vknots);
1418
Py::Sequence umultssq(umults);
1419
Standard_Integer index = 1;
1420
for (Py::Sequence::iterator it = umultssq.begin(); it != umultssq.end() && index <= occumults.Length(); ++it) {
1422
if (index < occumults.Length() || !Base::asBoolean(uperiodic)) {
1423
sum_of_umults += static_cast<int>(mult);
1425
occumults(index++) = static_cast<int>(mult);
1427
Py::Sequence vmultssq(vmults);
1429
for (Py::Sequence::iterator it = vmultssq.begin(); it != vmultssq.end() && index <= occvmults.Length(); ++it) {
1431
if (index < occvmults.Length() || !Base::asBoolean(vperiodic)) {
1432
sum_of_vmults += static_cast<int>(mult);
1434
occvmults(index++) = static_cast<int>(mult);
1437
if (uknots != Py_None) {
1438
Py::Sequence uknotssq(uknots);
1440
for (Py::Sequence::iterator it = uknotssq.begin(); it != uknotssq.end() && index <= occuknots.Length(); ++it) {
1441
Py::Float knot(*it);
1442
occuknots(index++) = knot;
1446
for (int i=1; i<=occuknots.Length(); i++){
1447
occuknots.SetValue(i,(double)(i-1)/(occuknots.Length()-1));
1450
if (vknots != Py_None) {
1451
Py::Sequence vknotssq(vknots);
1453
for (Py::Sequence::iterator it = vknotssq.begin(); it != vknotssq.end() && index <= occvknots.Length(); ++it) {
1454
Py::Float knot(*it);
1455
occvknots(index++) = knot;
1459
for (int i=1; i<=occvknots.Length(); i++){
1460
occvknots.SetValue(i,(double)(i-1)/(occvknots.Length()-1));
1463
if ((Base::asBoolean(uperiodic) && sum_of_umults != lu) ||
1464
(!Base::asBoolean(uperiodic) && sum_of_umults - udegree -1 != lu) ||
1465
(Base::asBoolean(vperiodic) && sum_of_vmults != lv) ||
1466
(!Base::asBoolean(vperiodic) && sum_of_vmults - vdegree -1 != lv)) {
1467
Standard_Failure::Raise("number of poles and sum of mults mismatch");
1470
for (Standard_Integer i=2; i < occumults.Length(); i++) {
1471
if (occumults(i) > udegree) {
1472
Standard_Failure::Raise("multiplicity of inner knot higher than degree");
1475
for (Standard_Integer i=2; i < occvmults.Length(); i++) {
1476
if (occvmults(i) > vdegree) {
1477
Standard_Failure::Raise("multiplicity of inner knot higher than degree");
1481
Handle(Geom_BSplineSurface) spline = new Geom_BSplineSurface(occpoles,occweights,
1482
occuknots,occvknots,occumults,occvmults,udegree,vdegree,
1483
Base::asBoolean(uperiodic),
1484
Base::asBoolean(vperiodic));
1485
if (!spline.IsNull()) {
1486
this->getGeomBSplineSurfacePtr()->setHandle(spline);
1490
Standard_Failure::Raise("failed to create spline");
1495
catch (const Standard_Failure& e) {
1496
Standard_CString msg = e.GetMessageString();
1497
PyErr_SetString(PartExceptionOCCError, msg ? msg : "");
1525
PyObject* BSplineSurfacePy::buildFromNSections(PyObject *args)
1528
PyObject* refSurf = Py_False;
1529
if (!PyArg_ParseTuple(args, "O|O!", &list, &PyBool_Type, &refSurf))
1533
TColGeom_SequenceOfCurve curveSeq;
1534
Py::Sequence curves(list);
1535
for (Py::Sequence::iterator it = curves.begin(); it != curves.end(); ++it) {
1536
Py::Object obj(*it);
1537
if (PyObject_TypeCheck(obj.ptr(), &GeometryCurvePy::Type)) {
1538
GeomCurve* geom = static_cast<GeometryCurvePy*>(obj.ptr())->getGeomCurvePtr();
1539
curveSeq.Append(Handle(Geom_Curve)::DownCast(geom->handle()));
1543
GeomFill_NSections fillOp(curveSeq);
1544
if (Base::asBoolean(refSurf)) {
1545
Handle(Geom_BSplineSurface) ref = Handle(Geom_BSplineSurface)::DownCast
1546
(getGeometryPtr()->handle());
1547
fillOp.SetSurface(ref);
1550
fillOp.ComputeSurface();
1552
Handle(Geom_BSplineSurface) aSurf = fillOp.BSplineSurface();
1553
this->getGeomBSplineSurfacePtr()->setHandle(aSurf);
1556
catch (const Standard_Failure& e) {
1557
Standard_CString msg = e.GetMessageString();
1558
PyErr_SetString(PartExceptionOCCError, msg ? msg : "");
1563
Py::Long BSplineSurfacePy::getUDegree() const
1565
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1566
(getGeometryPtr()->handle());
1567
int deg = surf->UDegree();
1568
return Py::Long(deg);
1571
Py::Long BSplineSurfacePy::getVDegree() const
1573
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1574
(getGeometryPtr()->handle());
1575
int deg = surf->VDegree();
1576
return Py::Long(deg);
1579
Py::Long BSplineSurfacePy::getMaxDegree() const
1581
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1582
(getGeometryPtr()->handle());
1583
return Py::Long(surf->MaxDegree());
1586
Py::Long BSplineSurfacePy::getNbUPoles() const
1588
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1589
(getGeometryPtr()->handle());
1590
return Py::Long(surf->NbUPoles());
1593
Py::Long BSplineSurfacePy::getNbVPoles() const
1595
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1596
(getGeometryPtr()->handle());
1597
return Py::Long(surf->NbVPoles());
1600
Py::Long BSplineSurfacePy::getNbUKnots() const
1602
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1603
(getGeometryPtr()->handle());
1604
return Py::Long(surf->NbUKnots());
1607
Py::Long BSplineSurfacePy::getNbVKnots() const
1609
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1610
(getGeometryPtr()->handle());
1611
return Py::Long(surf->NbVKnots());
1614
Py::Object BSplineSurfacePy::getFirstUKnotIndex() const
1616
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1617
(getGeometryPtr()->handle());
1618
int index = surf->FirstUKnotIndex();
1619
return Py::Long(index);
1622
Py::Object BSplineSurfacePy::getLastUKnotIndex() const
1624
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1625
(getGeometryPtr()->handle());
1626
int index = surf->LastUKnotIndex();
1627
return Py::Long(index);
1630
Py::Object BSplineSurfacePy::getFirstVKnotIndex() const
1632
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1633
(getGeometryPtr()->handle());
1634
int index = surf->FirstVKnotIndex();
1635
return Py::Long(index);
1638
Py::Object BSplineSurfacePy::getLastVKnotIndex() const
1640
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1641
(getGeometryPtr()->handle());
1642
int index = surf->LastVKnotIndex();
1643
return Py::Long(index);
1646
Py::List BSplineSurfacePy::getUKnotSequence() const
1648
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1649
(getGeometryPtr()->handle());
1650
Standard_Integer m = 0;
1651
if (surf->IsUPeriodic()) {
1653
m = surf->NbUPoles() + 2*surf->UDegree() - surf->UMultiplicity(1) + 2;
1656
for (int i=1; i<= surf->NbUKnots(); i++)
1657
m += surf->UMultiplicity(i);
1659
TColStd_Array1OfReal k(1,m);
1660
surf->UKnotSequence(k);
1662
for (Standard_Integer i=k.Lower(); i<=k.Upper(); i++) {
1663
list.append(Py::Float(k(i)));
1668
Py::List BSplineSurfacePy::getVKnotSequence() const
1670
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast
1671
(getGeometryPtr()->handle());
1672
Standard_Integer m = 0;
1673
if (surf->IsVPeriodic()) {
1675
m = surf->NbVPoles() + 2*surf->VDegree() - surf->VMultiplicity(1) + 2;
1678
for (int i=1; i<= surf->NbVKnots(); i++)
1679
m += surf->VMultiplicity(i);
1681
TColStd_Array1OfReal k(1,m);
1682
surf->VKnotSequence(k);
1684
for (Standard_Integer i=k.Lower(); i<=k.Upper(); i++) {
1685
list.append(Py::Float(k(i)));
1690
PyObject* BSplineSurfacePy::scaleKnotsToBounds(PyObject *args)
1697
if (!PyArg_ParseTuple(args, "|dddd", &u0, &u1, &v0, &v1))
1700
if (u0 >= u1 || v0 >= v1) {
1701
Standard_Failure::Raise("Bad parameter range");
1704
GeomBSplineSurface* surf = getGeomBSplineSurfacePtr();
1705
surf->scaleKnotsToBounds(u0, u1, v0, v1);
1708
catch (Standard_Failure& e) {
1709
std::string err = e.GetMessageString();
1710
if (err.empty()) err = e.DynamicType()->Name();
1711
PyErr_SetString(PartExceptionOCCError, err.c_str());
1716
PyObject *BSplineSurfacePy::getCustomAttributes(const char* attr) const
1719
if (strcmp(attr, "setBounds") == 0) {
1720
return PyObject_GetAttrString(const_cast<BSplineSurfacePy*>(this), "scaleKnotsToBounds");
1725
int BSplineSurfacePy::setCustomAttributes(const char* , PyObject* )