[Part] BSplineSurface: add setBounds method

This commit is contained in:
tomate44
2022-07-26 11:05:56 +02:00
committed by wwmayer
parent b330552337
commit 7328f2f302
4 changed files with 72 additions and 0 deletions

View File

@@ -729,5 +729,15 @@
</UserDocu>
</Documentation>
</Methode>
<Methode Name="setBounds">
<Documentation>
<UserDocu>
Changes the U and V parametric bounds of the surface.
The geometry is not modified.
bspline_surf.setBounds(u0, u1, v0, v1)
Default arguments are 0.0, 1.0, 0.0, 1.0
</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@@ -1680,6 +1680,32 @@ Py::List BSplineSurfacePy::getVKnotSequence(void) const
return list;
}
PyObject* BSplineSurfacePy::setBounds(PyObject *args)
{
double u0=0.0;
double u1=1.0;
double v0=0.0;
double v1=1.0;
if (!PyArg_ParseTuple(args, "|dddd", &u0, &u1, &v0, &v1))
return nullptr;
try {
if (u0 >= u1 || v0 >= v1) {
Standard_Failure::Raise("Bad parameter range");
return nullptr;;
}
GeomBSplineSurface* surf = getGeomBSplineSurfacePtr();
surf->setBounds(u0, u1, v0, v1);
Py_Return;
}
catch (Standard_Failure& e) {
std::string err = e.GetMessageString();
if (err.empty()) err = e.DynamicType()->Name();
PyErr_SetString(PartExceptionOCCError, err.c_str());
return nullptr;
}
}
PyObject *BSplineSurfacePy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;

View File

@@ -4458,6 +4458,41 @@ Geometry *GeomBSplineSurface::copy(void) const
return newSurf;
}
void GeomBSplineSurface::setBounds(double u0, double u1, double v0, double v1)
{
try {
Handle(Geom_BSplineSurface) surf = Handle(Geom_BSplineSurface)::DownCast(mySurface->Copy());
Standard_RangeError_Raise_if (u1 <= u0 || v1 <= v0, " ");
Standard_Real bu0,bu1,bv0,bv1;
surf->Bounds(bu0,bu1,bv0,bv1);
if ((abs(u0-bu0) > Precision::Confusion()) || (abs(u1-bu1) > Precision::Confusion())) {
TColStd_Array1OfReal uk(1,surf->NbUKnots());
TColStd_Array1OfReal nuk(1,surf->NbUKnots());
surf->UKnots(uk);
Standard_Real ur = uk(uk.Upper()) - uk(uk.Lower());
for (Standard_Integer i=uk.Lower(); i<=uk.Upper(); i++) {
nuk(i) = u0 + ((u1 - u0) * (uk(i) - uk(uk.Lower())) / ur);
}
surf->SetUKnots(nuk);
}
if ((abs(v0-bv0) > Precision::Confusion()) || (abs(v1-bv1) > Precision::Confusion())) {
TColStd_Array1OfReal vk(1,surf->NbVKnots());
TColStd_Array1OfReal nvk(1,surf->NbVKnots());
surf->VKnots(vk);
Standard_Real vr = vk(vk.Upper()) - vk(vk.Lower());
for (Standard_Integer j=vk.Lower(); j<=vk.Upper(); j++) {
nvk(j) = v0 + ((v1 - v0) * (vk(j) - vk(vk.Lower())) / vr);
}
surf->SetVKnots(nvk);
}
mySurface = surf;
return;
}
catch (Standard_Failure& e) {
THROWM(Base::CADKernelError,e.GetMessageString())
}
}
// Persistence implementer
unsigned int GeomBSplineSurface::getMemSize (void) const
{

View File

@@ -844,6 +844,7 @@ public:
virtual ~GeomBSplineSurface();
virtual Geometry *copy(void) const;
void setBounds(double u0, double u1, double v0, double v1);
// Persistence implementer ---------------------
virtual unsigned int getMemSize(void) const;
virtual void Save(Base::Writer &/*writer*/) const;