Skip to content

Commit 42e90a8

Browse files
authored
Patch for Geom_BSplineSurface::Weights (#84)
1 parent 544e72a commit 42e90a8

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
[![Documentation Status](https://readthedocs.org/projects/pyocct/badge/?version=latest)](http://pyocct.readthedocs.io/en/latest/?badge=latest)
44
[![Join the chat at https://gitter.im/pyOCCT/Lobby](https://badges.gitter.im/pyOCCT/Lobby.svg)](https://gitter.im/pyOCCT/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5-
65
![Workflow](https://github.com/trelau/pyOCCT/workflows/Workflow/badge.svg)
7-
[![Anaconda-Server Badge](https://anaconda.org/trelau/pyocct/badges/installer/conda.svg)](https://conda.anaconda.org/trelau/pyocct)
6+
7+
[![Anaconda-Server Badge](https://anaconda.org/trelau/pyocct/badges/version.svg)](https://anaconda.org/trelau/pyocct)
8+
[![Anaconda-Server Badge](https://anaconda.org/trelau/pyocct/badges/latest_release_date.svg)](https://anaconda.org/trelau/pyocct)
9+
[![Anaconda-Server Badge](https://anaconda.org/trelau/pyocct/badges/installer/conda.svg)](https://anaconda.org/trelau/pyocct)
810
[![Anaconda-Server Badge](https://anaconda.org/trelau/pyocct/badges/platforms.svg)](https://anaconda.org/trelau/pyocct)
911
[![Anaconda-Server Badge](https://anaconda.org/trelau/pyocct/badges/downloads.svg)](https://anaconda.org/trelau/pyocct)
1012

binder/config.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,12 @@
906906
+skip OpenGl_TextureFormatSelector<GLuint>
907907
+skip OpenGl_TextureFormatSelector<GLushort>
908908

909+
# Return value policies -------------------------------------------------------
910+
+return_policy OpenGl_GraphicDriver::ChangeOptions-->reference
911+
+return_policy OpenGl_GraphicDriver::Options-->reference
912+
913+
+return_policy V3d_View::ChangeRenderingParams-->reference
914+
909915
# Manual text -----------------------------------------------------------------
910916
+before_type BOPTools_BoxSet<NumType, Dimension, DataType>-->bind_BVH_BoxSet<NumType, Dimension, DataType>(mod, "BOPTools_BoxSet_Base", py::module_local());
911917
+before_type BOPTools_BoxSelector<Dimension>-->bind_BVH_Traverse<Standard_Real, Dimension, BVH_BoxSet<Standard_Real, Dimension, Standard_Integer>, Standard_Boolean>(mod, "BOPTools_BoxSelector_Base", py::module_local());
@@ -974,7 +980,7 @@
974980
# Add exception translator
975981
+after_type Standard_Failure-->py::register_exception_translator([](std::exception_ptr p) {try {if (p) std::rethrow_exception(p);} catch (const Standard_Failure &e) { PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());}});
976982

977-
# Patches -----------------------------------------------------------------
983+
# Patches ---------------------------------------------------------------------
978984

979985
# Patch parameter for AIS_ManipulatorObjectSequence::Append
980986
+patch AIS: (AIS_ManipulatorObjectSequence::*)(const int &)-->(AIS_ManipulatorObjectSequence::*)(const typename AIS_ManipulatorObjectSequence::value_type &)
@@ -985,6 +991,7 @@
985991
+patch bind_BVH_BaseBox: BVH_BaseBox<T, N>-->BVH_BaseBox<T, N, TheDerivedBox>
986992
+patch bind_BVH_Traverse: (const int &)-->(const opencascade::handle<BVH_Tree <NumType, Dimension>>&)
987993

994+
+patch Geom: (const TColStd_Array2OfReal * (Geom_BSplineSurface::*)() const) &Geom_BSplineSurface::Weights-->[](Geom_BSplineSurface& self) -> py::object {return self.Weights() ? py::cast(*self.Weights()) : py::none(); }
988995

989996
+patch IVtkTools: (IVtkOCC_Shape::Handle (-->(opencascade::handle<IVtkOCC_Shape> (
990997

@@ -1005,11 +1012,5 @@
10051012
+patch Font: (TopoDS_Shape (Font_BRepTextBuilder::*)(Font_BRepFont &, const NCollection_String &, const gp_Ax3 &, const Graphic3d_HorizontalTextAlignment, const Graphic3d_VerticalTextAlignment)) &Font_BRepTextBuilder::Perform-->[](Font_BRepTextBuilder &self, Font_BRepFont_ & a0, const NCollection_String & a1, const gp_Ax3 & a2, const Graphic3d_HorizontalTextAlignment a3, const Graphic3d_VerticalTextAlignment a4) -> TopoDS_Shape { return self.Perform(a0, a1, a2, a3, a4); }
10061013
+patch Font: Font_BRepFont &-->Font_BRepFont_ &
10071014

1008-
# Return value policies
1009-
+return_policy OpenGl_GraphicDriver::ChangeOptions-->reference
1010-
+return_policy OpenGl_GraphicDriver::Options-->reference
1011-
1012-
+return_policy V3d_View::ChangeRenderingParams-->reference
1013-
1014-
# Inject trapoline
1015+
# Inject trampoline
10151016
+patch AIS: py::class_<AIS_InteractiveObject, opencascade-->py::class_<AIS_InteractiveObject, AIS_PyInteractiveObject, opencascade

test/test_Geom.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import math
2121
import unittest
2222

23-
from OCCT.Geom import Geom_SphericalSurface
23+
from OCCT.Geom import Geom_SphericalSurface, Geom_RectangularTrimmedSurface
24+
from OCCT.GeomConvert import GeomConvert
25+
from OCCT.TColStd import TColStd_Array2OfReal
2426
from OCCT.gp import gp_Pnt, gp_Ax3, gp_Dir, gp_Sphere
2527

2628

@@ -76,5 +78,41 @@ def test_V2(self):
7678
self.assertAlmostEqual(self._surf.V2(), 0.5 * math.pi)
7779

7880

81+
class Test_Geom_BSplineSurface(unittest.TestCase):
82+
"""
83+
Test for Geom_BSplineSurface class.
84+
"""
85+
86+
def test_Weights(self):
87+
"""
88+
Test Geom_BSplineSurface::Weights()
89+
"""
90+
91+
s1 = Geom_SphericalSurface(gp_Ax3(), 1.)
92+
s2 = Geom_RectangularTrimmedSurface(s1, 0., 1., 0., 1.)
93+
s3 = GeomConvert.SurfaceToBSplineSurface_(s2)
94+
95+
weights = TColStd_Array2OfReal(1, s3.NbUPoles(), 1, s3.NbVPoles())
96+
s3.Weights(weights)
97+
98+
self.assertEqual(weights.Size(), 9)
99+
self.assertAlmostEqual(weights.Value(1, 1), 1.0)
100+
self.assertAlmostEqual(weights.Value(3, 3), 1.0)
101+
102+
def test_Weights_const(self):
103+
"""
104+
Test Geom_BSplineSurface::Weights() const
105+
"""
106+
s1 = Geom_SphericalSurface(gp_Ax3(), 1.)
107+
s2 = Geom_RectangularTrimmedSurface(s1, 0., 1., 0., 1.)
108+
s3 = GeomConvert.SurfaceToBSplineSurface_(s2)
109+
110+
weights = s3.Weights()
111+
112+
self.assertEqual(weights.Size(), 9)
113+
self.assertAlmostEqual(weights.Value(1, 1), 1.0)
114+
self.assertAlmostEqual(weights.Value(3, 3), 1.0)
115+
116+
79117
if __name__ == '__main__':
80118
unittest.main()

0 commit comments

Comments
 (0)