Skip to content

Commit 33f5383

Browse files
committed
Add an option to plot bounding box diagonal on the figures
1 parent 988cb51 commit 33f5383

File tree

3 files changed

+133
-30
lines changed

3 files changed

+133
-30
lines changed

geomdl/Abstract.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ def render(self, **kwargs):
385385
Keyword Arguments:
386386
* ``cpcolor``: sets the color of the control points polygon
387387
* ``evalcolor``: sets the color of the curve
388+
* ``bboxcolor``: sets the color of the bounding box
388389
* ``filename``: saves the plot with the input name
389390
* ``plot``: a flag to control displaying the plot window. Default is True.
390391
@@ -399,6 +400,7 @@ def render(self, **kwargs):
399400

400401
cpcolor = kwargs.get('cpcolor', 'blue')
401402
evalcolor = kwargs.get('evalcolor', 'black')
403+
bboxcolor = kwargs.get('bboxcolor', 'darkorange')
402404
filename = kwargs.get('filename', None)
403405
plot_visible = kwargs.get('plot', True)
404406

@@ -413,6 +415,7 @@ def render(self, **kwargs):
413415
self._vis_component.clear()
414416
self._vis_component.add(ptsarr=self.ctrlpts, name="Control Points", color=cpcolor, plot_type='ctrlpts')
415417
self._vis_component.add(ptsarr=self.evalpts, name=self.name, color=evalcolor, plot_type='evalpts')
418+
self._vis_component.add(ptsarr=self.bbox, name="Bounding Box", color=bboxcolor, plot_type='bbox')
416419
self._vis_component.render(fig_save_as=filename, display_plot=plot_visible)
417420

418421
def reset(self, **kwargs):
@@ -1180,6 +1183,7 @@ def render(self, **kwargs):
11801183

11811184
cpcolor = kwargs.get('cpcolor', 'blue')
11821185
evalcolor = kwargs.get('evalcolor', 'green')
1186+
bboxcolor = kwargs.get('bboxcolor', 'darkorange')
11831187
trimcolor = kwargs.get('trimcolor', 'black')
11841188
filename = kwargs.get('filename', None)
11851189
plot_visible = kwargs.get('plot', True)
@@ -1236,6 +1240,9 @@ def render(self, **kwargs):
12361240
self._vis_component.add(ptsarr=self.evaluate_list(trim.evalpts),
12371241
name="Trim Curve " + str(idx + 1), color=trimcolor, plot_type='trimcurve')
12381242

1243+
# Bounding box
1244+
self._vis_component.add(ptsarr=self.bbox, name="Bounding Box", color=bboxcolor, plot_type='bbox')
1245+
12391246
# Plot the surface
12401247
self._vis_component.render(fig_save_as=filename, display_plot=plot_visible, colormap=surf_cmap)
12411248

geomdl/visualization/VisMPL.py

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class VisConfig(Abstract.VisConfigAbstract):
2626
2727
* ``ctrlpts`` (bool): Control points polygon/grid visibility. *Default: True*
2828
* ``evalpts`` (bool): Curve/surface points visibility. *Default: True*
29+
* ``bbox`` (bool): Bounding box visibility. *Default: False*
2930
* ``legend`` (bool): Figure legend visibility. *Default: True*
3031
* ``axes`` (bool): Axes and figure grid visibility. *Default: True*
3132
* ``trims`` (bool): Trim curves visibility. *Default: True*
@@ -63,6 +64,7 @@ def __init__(self, **kwargs):
6364
self.dtype = np.float
6465
self.display_ctrlpts = kwargs.get('ctrlpts', True)
6566
self.display_evalpts = kwargs.get('evalpts', True)
67+
self.display_bbox = kwargs.get('bbox', False)
6668
self.display_legend = kwargs.get('legend', True)
6769
self.display_axes = kwargs.get('axes', True)
6870
self.display_trims = kwargs.get('trims', True)
@@ -134,6 +136,12 @@ def render(self, **kwargs):
134136
legend_proxy.append(curveplt)
135137
legend_names.append(plot['name'])
136138

139+
# Plot bounding box
140+
if plot['type'] == 'bbox' and self._config.display_bbox:
141+
bboxplt, = plt.plot(pts[:, 0], pts[:, 1], color=plot['color'], linestyle='--')
142+
legend_proxy.append(bboxplt)
143+
legend_names.append(plot['name'])
144+
137145
# Add legend
138146
if self._config.display_legend:
139147
plt.legend(legend_proxy, legend_names)
@@ -189,15 +197,22 @@ def render(self, **kwargs):
189197
# Plot control points
190198
if plot['type'] == 'ctrlpts' and self._config.display_ctrlpts:
191199
ax.plot(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], linestyle='-.', marker='o')
192-
plot1_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
193-
legend_proxy.append(plot1_proxy)
200+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
201+
legend_proxy.append(plot_proxy)
194202
legend_names.append(plot['name'])
195203

196204
# Plot evaluated points
197205
if plot['type'] == 'evalpts' and self._config.display_evalpts:
198206
ax.plot(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], linestyle='-')
199-
plot2_proxy = mpl.lines.Line2D([0], [0], linestyle='-', color=plot['color'])
200-
legend_proxy.append(plot2_proxy)
207+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='-', color=plot['color'])
208+
legend_proxy.append(plot_proxy)
209+
legend_names.append(plot['name'])
210+
211+
# Plot bounding box
212+
if plot['type'] == 'bbox' and self._config.display_bbox:
213+
ax.plot(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], linestyle='--')
214+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='--', color=plot['color'])
215+
legend_proxy.append(plot_proxy)
201216
legend_names.append(plot['name'])
202217

203218
# Add legend to 3D plot, @ref: https://stackoverflow.com/a/20505720
@@ -255,8 +270,8 @@ def render(self, **kwargs):
255270
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
256271
cp_z = pts[:, 2] + self._ctrlpts_offset
257272
ax.plot(pts[:, 0], pts[:, 1], cp_z, color=plot['color'], linestyle='-.', marker='o')
258-
plot1_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
259-
legend_proxy.append(plot1_proxy)
273+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
274+
legend_proxy.append(plot_proxy)
260275
legend_names.append(plot['name'])
261276

262277
# Plot evaluated points
@@ -265,8 +280,16 @@ def render(self, **kwargs):
265280
for tri in tris:
266281
pts = np.array(tri.vertices_raw, dtype=self._config.dtype)
267282
ax.plot(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'])
268-
plot2_proxy = mpl.lines.Line2D([0], [0], linestyle='-', color=plot['color'])
269-
legend_proxy.append(plot2_proxy)
283+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='-', color=plot['color'])
284+
legend_proxy.append(plot_proxy)
285+
legend_names.append(plot['name'])
286+
287+
# Plot bounding box
288+
if plot['type'] == 'bbox' and self._config.display_bbox:
289+
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
290+
ax.plot(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], linestyle='--')
291+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='--', color=plot['color'])
292+
legend_proxy.append(plot_proxy)
270293
legend_names.append(plot['name'])
271294

272295
# Plot trim curves
@@ -275,8 +298,8 @@ def render(self, **kwargs):
275298
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
276299
ax.scatter(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], marker='o',
277300
s=self._config.trim_size, depthshade=False)
278-
plot3_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
279-
legend_proxy.append(plot3_proxy)
301+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
302+
legend_proxy.append(plot_proxy)
280303
legend_names.append(plot['name'])
281304

282305
# Add legend to 3D plot, @ref: https://stackoverflow.com/a/20505720
@@ -334,16 +357,24 @@ def render(self, **kwargs):
334357
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
335358
cp_z = pts[:, 2] + self._ctrlpts_offset
336359
ax.scatter(pts[:, 0], pts[:, 1], cp_z, color=plot['color'], s=25, depthshade=True)
337-
plot1_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
338-
legend_proxy.append(plot1_proxy)
360+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
361+
legend_proxy.append(plot_proxy)
339362
legend_names.append(plot['name'])
340363

341364
# Plot evaluated points
342365
if plot['type'] == 'evalpts' and self._config.display_evalpts:
343366
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
344367
ax.plot(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'])
345-
plot2_proxy = mpl.lines.Line2D([0], [0], linestyle='-', color=plot['color'])
346-
legend_proxy.append(plot2_proxy)
368+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='-', color=plot['color'])
369+
legend_proxy.append(plot_proxy)
370+
legend_names.append(plot['name'])
371+
372+
# Plot bounding box
373+
if plot['type'] == 'bbox' and self._config.display_bbox:
374+
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
375+
ax.plot(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], linestyle='--')
376+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='--', color=plot['color'])
377+
legend_proxy.append(plot_proxy)
347378
legend_names.append(plot['name'])
348379

349380
# Plot trim curves
@@ -352,8 +383,8 @@ def render(self, **kwargs):
352383
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
353384
ax.scatter(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], marker='o',
354385
s=self._config.trim_size, depthshade=False)
355-
plot3_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
356-
legend_proxy.append(plot3_proxy)
386+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
387+
legend_proxy.append(plot_proxy)
357388
legend_names.append(plot['name'])
358389

359390
# Add legend to 3D plot, @ref: https://stackoverflow.com/a/20505720
@@ -426,8 +457,8 @@ def render(self, **kwargs):
426457
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
427458
cp_z = pts[:, 2] + self._ctrlpts_offset
428459
ax.plot(pts[:, 0], pts[:, 1], cp_z, color=plot['color'], linestyle='-.', marker='o')
429-
plot1_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
430-
legend_proxy.append(plot1_proxy)
460+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
461+
legend_proxy.append(plot_proxy)
431462
legend_names.append(plot['name'])
432463

433464
# Plot evaluated points
@@ -456,8 +487,16 @@ def render(self, **kwargs):
456487

457488
# Use custom Triangulation object and the choice of color/colormap to plot the surface
458489
ax.plot_trisurf(triangulation, pts[:, 2], **trisurf_params)
459-
plot2_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='^')
460-
legend_proxy.append(plot2_proxy)
490+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='^')
491+
legend_proxy.append(plot_proxy)
492+
legend_names.append(plot['name'])
493+
494+
# Plot bounding box
495+
if plot['type'] == 'bbox' and self._config.display_bbox:
496+
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
497+
ax.plot(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], linestyle='--')
498+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='--', color=plot['color'])
499+
legend_proxy.append(plot_proxy)
461500
legend_names.append(plot['name'])
462501

463502
# Plot trim curves
@@ -466,8 +505,8 @@ def render(self, **kwargs):
466505
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
467506
ax.scatter(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], marker='o',
468507
s=self._config.trim_size, depthshade=False)
469-
plot3_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
470-
legend_proxy.append(plot3_proxy)
508+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
509+
legend_proxy.append(plot_proxy)
471510
legend_names.append(plot['name'])
472511

473512
# Add legend to 3D plot, @ref: https://stackoverflow.com/a/20505720
@@ -525,16 +564,24 @@ def render(self, **kwargs):
525564
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
526565
cp_z = pts[:, 2] + self._ctrlpts_offset
527566
ax.plot(pts[:, 0], pts[:, 1], cp_z, color=plot['color'], linestyle='-.', marker='o')
528-
plot1_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
529-
legend_proxy.append(plot1_proxy)
567+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='-.', color=plot['color'], marker='o')
568+
legend_proxy.append(plot_proxy)
530569
legend_names.append(plot['name'])
531570

532571
# Plot evaluated points
533572
if plot['type'] == 'evalpts' and self._config.display_evalpts:
534573
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
535574
ax.scatter(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], s=50, depthshade=True)
536-
plot2_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
537-
legend_proxy.append(plot2_proxy)
575+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
576+
legend_proxy.append(plot_proxy)
577+
legend_names.append(plot['name'])
578+
579+
# Plot bounding box
580+
if plot['type'] == 'bbox' and self._config.display_bbox:
581+
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
582+
ax.plot(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], linestyle='--')
583+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='--', color=plot['color'])
584+
legend_proxy.append(plot_proxy)
538585
legend_names.append(plot['name'])
539586

540587
# Plot trim curves
@@ -543,8 +590,8 @@ def render(self, **kwargs):
543590
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
544591
ax.scatter(pts[:, 0], pts[:, 1], pts[:, 2], color=plot['color'], marker='o',
545592
s=self._config.trim_size, depthshade=False)
546-
plot3_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
547-
legend_proxy.append(plot3_proxy)
593+
plot_proxy = mpl.lines.Line2D([0], [0], linestyle='none', color=plot['color'], marker='o')
594+
legend_proxy.append(plot_proxy)
548595
legend_names.append(plot['name'])
549596

550597
# Add legend to 3D plot, @ref: https://stackoverflow.com/a/20505720

geomdl/visualization/VisPlotly.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class VisConfig(Abstract.VisConfigAbstract):
2424
2525
* ``ctrlpts`` (bool): Control points polygon/grid visibility. *Default: True*
2626
* ``evalpts`` (bool): Curve/surface points visibility. *Default: True*
27+
* ``bbox`` (bool): Bounding box visibility. *Default: False*
2728
* ``legend`` (bool): Figure legend visibility. *Default: True*
2829
* ``axes`` (bool): Axes and figure grid visibility. *Default: True*
2930
* ``trims`` (bool): Trim curves visibility. *Default: True*
@@ -77,6 +78,7 @@ def __init__(self, **kwargs):
7778
# Get keyword arguments
7879
self.display_ctrlpts = kwargs.get('ctrlpts', True)
7980
self.display_evalpts = kwargs.get('evalpts', True)
81+
self.display_bbox = kwargs.get('bbox', False)
8082
self.display_trims = kwargs.get('trims', True)
8183
self.display_legend = kwargs.get('legend', True)
8284
self.display_axes = kwargs.get('axes', True)
@@ -112,7 +114,7 @@ def render(self, **kwargs):
112114
line=dict(
113115
color=plot['color'],
114116
width=self._config.line_width,
115-
dash='dashdot'
117+
dash='dash'
116118
)
117119
)
118120
plot_data.append(figure)
@@ -131,6 +133,20 @@ def render(self, **kwargs):
131133
)
132134
plot_data.append(figure)
133135

136+
# Plot bounding box
137+
if plot['type'] == 'bbox' and self._config.display_bbox:
138+
figure = graph_objs.Scatter(
139+
x=pts[:, 0],
140+
y=pts[:, 1],
141+
name=plot['name'],
142+
line=dict(
143+
color=plot['color'],
144+
width=self._config.line_width,
145+
dash='dashdot',
146+
)
147+
)
148+
plot_data.append(figure)
149+
134150
plot_layout = dict(
135151
width=self._config.figure_size[0],
136152
height=self._config.figure_size[1],
@@ -203,7 +219,7 @@ def render(self, **kwargs):
203219
line=dict(
204220
color=plot['color'],
205221
width=self._config.line_width,
206-
dash='dashdot'
222+
dash='dash'
207223
),
208224
marker=dict(
209225
color=plot['color'],
@@ -227,6 +243,22 @@ def render(self, **kwargs):
227243
)
228244
plot_data.append(figure)
229245

246+
# Plot bounding box
247+
if plot['type'] == 'bbox' and self._config.display_bbox:
248+
figure = graph_objs.Scatter3d(
249+
x=pts[:, 0],
250+
y=pts[:, 1],
251+
z=pts[:, 2],
252+
name=plot['name'],
253+
mode='lines',
254+
line=dict(
255+
color=plot['color'],
256+
width=self._config.line_width,
257+
dash='dashdot',
258+
),
259+
)
260+
plot_data.append(figure)
261+
230262
plot_layout = dict(
231263
width=self._config.figure_size[0],
232264
height=self._config.figure_size[1],
@@ -347,6 +379,23 @@ def render(self, **kwargs):
347379
)
348380
plot_data.append(figure)
349381

382+
# Plot bounding box
383+
if plot['type'] == 'bbox' and self._config.display_bbox:
384+
pts = np.array(plot['ptsarr'], dtype=self._config.dtype)
385+
figure = graph_objs.Scatter3d(
386+
x=pts[:, 0],
387+
y=pts[:, 1],
388+
z=pts[:, 2],
389+
name=plot['name'],
390+
mode='lines',
391+
line=dict(
392+
color=plot['color'],
393+
width=self._config.line_width,
394+
dash='dashdot',
395+
),
396+
)
397+
plot_data.append(figure)
398+
350399
# Plot trim curves
351400
if self._config.display_trims:
352401
if plot['type'] == 'trimcurve':

0 commit comments

Comments
 (0)