MCPcopy
hub / github.com/CadQuery/cadquery / ctrlPts

Function ctrlPts

cadquery/vis.py:201–295  ·  view source on GitHub ↗

Convert Edge, Face, Surface or Curve to a vtkActor representing control points.

(
    s: Union[Face, Edge, Surface, Curve],
    size: float = DEFAULT_CTRL_PT_SIZE,
    color: str = DEFAULT_CTRL_PT_COLOR,
)

Source from the content-addressed store, hash-verified

199
200
201def ctrlPts(
202 s: Union[Face, Edge, Surface, Curve],
203 size: float = DEFAULT_CTRL_PT_SIZE,
204 color: str = DEFAULT_CTRL_PT_COLOR,
205) -> vtkActor:
206 """
207 Convert Edge, Face, Surface or Curve to a vtkActor representing control points.
208 """
209
210 # handle Surface, Curve first
211 if isinstance(s, Surface):
212 return ctrlPts(s.face(), size, color)
213 elif isinstance(s, Curve):
214 return ctrlPts(s.edge(), size, color)
215
216 rv = vtkActor()
217
218 mapper = vtkPolyDataMapper()
219 points = vtkPoints()
220 cells = vtkCellArray()
221 data = vtkPolyData()
222
223 data.SetPoints(points)
224 data.SetVerts(cells)
225 data.SetLines(cells)
226
227 if isinstance(s, Face):
228
229 if isinstance(s._geomAdaptor(), Geom_BSplineSurface):
230 surf = cast(Geom_BSplineSurface, s._geomAdaptor())
231 else:
232 raise ValueError(
233 f"Only NURBS surfaces are supported, encountered {s._geomAdaptor()}"
234 )
235
236 Nu = surf.NbUPoles()
237 Nv = surf.NbVPoles()
238
239 u_periodic = surf.IsUPeriodic()
240 v_periodic = surf.IsVPeriodic()
241
242 # add points
243 for i in range(Nu):
244 for j in range(Nv):
245 pt = surf.Pole(i + 1, j + 1)
246 points.InsertNextPoint(pt.X(), pt.Y(), pt.Z())
247
248 # u edges
249 for j in range(Nv):
250 for i in range(Nu - 1):
251 cells.InsertNextCell(2, (Nv * i + j, Nv * (i + 1) + j))
252
253 if u_periodic:
254 cells.InsertNextCell(2, (Nv * (i + 1) + j, 0 + j))
255
256 # v edges
257 for i in range(Nu):
258 for j in range(Nv - 1):

Callers 4

showablesFunction · 0.90
test_show_nurbsFunction · 0.90
test_ctrlPtsFunction · 0.90
test_styleFunction · 0.90

Calls 4

faceMethod · 0.45
edgeMethod · 0.45
_geomAdaptorMethod · 0.45
geomTypeMethod · 0.45

Tested by 4

showablesFunction · 0.72
test_show_nurbsFunction · 0.72
test_ctrlPtsFunction · 0.72
test_styleFunction · 0.72