Skip to content

Commit b0883f5

Browse files
author
Onur R. Bingol
committed
Add visualization component options to Curve classes
1 parent fb1ab69 commit b0883f5

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

geomdl/BSpline.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(self):
5656
self._curve_points = []
5757
self._dimension = 3 # 3D coordinates
5858
self._rational = False
59+
self._vis_component = None
5960

6061
@property
6162
def order(self):
@@ -177,6 +178,53 @@ def curvepts(self):
177178
"""
178179
return self._curve_points
179180

181+
@property
182+
def vis(self):
183+
""" Visualization component.
184+
185+
.. note:: The visualization component is completely optional to use.
186+
187+
:getter: Gets the visualization component
188+
:setter: Sets the visualization component
189+
:type: float
190+
"""
191+
return self._vis_component
192+
193+
@vis.setter
194+
def vis(self, value):
195+
if not isinstance(value, VisBase.VisAbstract):
196+
warnings.warn("Visualization component is NOT an instance of VisABC")
197+
return
198+
self._vis_component = value
199+
200+
# Runs visualization component to render the surface
201+
def render(self, cpcolor="blue", curvecolor="black"):
202+
""" Renders the curve using the loaded visualization component
203+
204+
The visualization component must be set using :py:attr:`~vis` property before calling this method.
205+
206+
:param cpcolor: Color of the control points polygon
207+
:type cpcolor: str
208+
:param curvecolor: Color of the curve
209+
:type curvecolor: str
210+
:return: None
211+
"""
212+
if not self._vis_component:
213+
warnings.warn("No visualization component has set")
214+
return
215+
216+
# Check all parameters are set
217+
self._check_variables()
218+
219+
# Check if the surface has been evaluated
220+
if not self._curve_points:
221+
self.evaluate()
222+
223+
# Run the visualization component
224+
self._vis_component.add(self.ctrlpts, "Control Points", cpcolor)
225+
self._vis_component.add(self.curvepts, "Curve", curvecolor)
226+
self._vis_component.render()
227+
180228
# Cleans up the control points
181229
def _reset_ctrlpts(self):
182230
if self._control_points:

0 commit comments

Comments
 (0)