-
Notifications
You must be signed in to change notification settings - Fork 444
/
geometric_sources.py
2799 lines (2265 loc) · 73.6 KB
/
geometric_sources.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Provides an easy way of generating several geometric sources.
Also includes some pure-python helpers.
"""
from __future__ import annotations
from typing import Dict, Sequence, Tuple, Union
import numpy as np
from vtkmodules.vtkRenderingFreeType import vtkVectorText
import pyvista
from pyvista.core import _vtk_core as _vtk
from pyvista.core._typing_core import BoundsLike, MatrixLike, NumpyArray, VectorLike
from pyvista.core.utilities.misc import _check_range, _reciprocal, no_new_attr
from .arrays import _coerce_pointslike_arg
from .helpers import wrap
SINGLE_PRECISION = _vtk.vtkAlgorithm.SINGLE_PRECISION
DOUBLE_PRECISION = _vtk.vtkAlgorithm.DOUBLE_PRECISION
def translate(surf, center=(0.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0)):
"""Translate and orient a mesh to a new center and direction.
By default, the input mesh is considered centered at the origin
and facing in the x direction.
Parameters
----------
surf : pyvista.core.pointset.PolyData
Mesh to be translated and oriented.
center : tuple, optional, default: (0.0, 0.0, 0.0)
Center point to which the mesh should be translated.
direction : tuple, optional, default: (1.0, 0.0, 0.0)
Direction vector along which the mesh should be oriented.
"""
normx = np.array(direction) / np.linalg.norm(direction)
normy_temp = [0.0, 1.0, 0.0]
# Adjust normy if collinear with normx since cross-product will
# be zero otherwise
if np.allclose(normx, [0, 1, 0]):
normy_temp = [-1.0, 0.0, 0.0]
elif np.allclose(normx, [0, -1, 0]):
normy_temp = [1.0, 0.0, 0.0]
normz = np.cross(normx, normy_temp)
normz /= np.linalg.norm(normz)
normy = np.cross(normz, normx)
trans = np.zeros((4, 4))
trans[:3, 0] = normx
trans[:3, 1] = normy
trans[:3, 2] = normz
trans[3, 3] = 1
surf.transform(trans)
if not np.allclose(center, [0.0, 0.0, 0.0]):
surf.points += np.array(center, dtype=surf.points.dtype)
if _vtk.vtk_version_info < (9, 3):
@no_new_attr
class CapsuleSource(_vtk.vtkCapsuleSource):
"""Capsule source algorithm class.
.. versionadded:: 0.44.0
Parameters
----------
center : sequence[float], default: (0.0, 0.0, 0.0)
Center in ``[x, y, z]``.
direction : sequence[float], default: (1.0, 0.0, 0.0)
Direction of the capsule in ``[x, y, z]``.
radius : float, default: 0.5
Radius of the capsule.
cylinder_length : float, default: 1.0
Cylinder length of the capsule.
theta_resolution : int, default: 30
Set the number of points in the azimuthal direction (ranging
from ``start_theta`` to ``end_theta``).
phi_resolution : int, default: 30
Set the number of points in the polar direction (ranging from
``start_phi`` to ``end_phi``).
Examples
--------
Create a default CapsuleSource.
>>> import pyvista as pv
>>> source = pv.CapsuleSource()
>>> source.output.plot(show_edges=True, line_width=5)
"""
_new_attr_exceptions = ['_direction']
def __init__(
self,
center=(0.0, 0.0, 0.0),
direction=(1.0, 0.0, 0.0),
radius=0.5,
cylinder_length=1.0,
theta_resolution=30,
phi_resolution=30,
):
"""Initialize the capsule source class."""
super().__init__()
self.center = center
self._direction = direction
self.radius = radius
self.cylinder_length = cylinder_length
self.theta_resolution = theta_resolution
self.phi_resolution = phi_resolution
@property
def center(self) -> Sequence[float]:
"""Get the center in ``[x, y, z]``. Axis of the capsule passes through this point.
Returns
-------
sequence[float]
Center in ``[x, y, z]``. Axis of the capsule passes through this
point.
"""
return self.GetCenter()
@center.setter
def center(self, center: Sequence[float]):
"""Set the center in ``[x, y, z]``. Axis of the capsule passes through this point.
Parameters
----------
center : sequence[float]
Center in ``[x, y, z]``. Axis of the capsule passes through this
point.
"""
self.SetCenter(center)
@property
def direction(self) -> Sequence[float]:
"""Get the direction vector in ``[x, y, z]``. Orientation vector of the capsule.
Returns
-------
sequence[float]
Direction vector in ``[x, y, z]``. Orientation vector of the
capsule.
"""
return self._direction
@direction.setter
def direction(self, direction: Sequence[float]):
"""Set the direction in ``[x, y, z]``. Axis of the capsule passes through this point.
Parameters
----------
direction : sequence[float]
Direction vector in ``[x, y, z]``. Orientation vector of the
capsule.
"""
self._direction = direction
@property
def cylinder_length(self) -> float:
"""Get the cylinder length along the capsule in its specified direction.
Returns
-------
float
Cylinder length along the capsule in its specified direction.
"""
return self.GetCylinderLength()
@cylinder_length.setter
def cylinder_length(self, length: float):
"""Set the cylinder length of the capsule.
Parameters
----------
length : float
Cylinder length of the capsule.
"""
self.SetCylinderLength(length)
@property
def radius(self) -> float:
"""Get base radius of the capsule.
Returns
-------
float
Base radius of the capsule.
"""
return self.GetRadius()
@radius.setter
def radius(self, radius: float):
"""Set base radius of the capsule.
Parameters
----------
radius : float
Base radius of the capsule.
"""
self.SetRadius(radius)
@property
def theta_resolution(self) -> int:
"""Get the number of points in the azimuthal direction.
Returns
-------
int
The number of points in the azimuthal direction.
"""
return self.GetThetaResolution()
@theta_resolution.setter
def theta_resolution(self, theta_resolution: int):
"""Set the number of points in the azimuthal direction.
Parameters
----------
theta_resolution : int
The number of points in the azimuthal direction.
"""
self.SetThetaResolution(theta_resolution)
@property
def phi_resolution(self) -> int:
"""Get the number of points in the polar direction.
Returns
-------
int
The number of points in the polar direction.
"""
return self.GetPhiResolution()
@phi_resolution.setter
def phi_resolution(self, phi_resolution: int):
"""Set the number of points in the polar direction.
Parameters
----------
phi_resolution : int
The number of points in the polar direction.
"""
self.SetPhiResolution(phi_resolution)
@property
def output(self):
"""Get the output data object for a port on this algorithm.
Returns
-------
pyvista.PolyData
Capsule surface.
"""
self.Update()
return wrap(self.GetOutput())
@no_new_attr
class ConeSource(_vtk.vtkConeSource):
"""Cone source algorithm class.
Parameters
----------
center : sequence[float], default: (0.0, 0.0, 0.0)
Center in ``[x, y, z]``. Axis of the cone passes through this
point.
direction : sequence[float], default: (1.0, 0.0, 0.0)
Direction vector in ``[x, y, z]``. Orientation vector of the
cone.
height : float, default: 1.0
Height along the cone in its specified direction.
radius : float, optional
Base radius of the cone.
capping : bool, default: True
Enable or disable the capping the base of the cone with a
polygon.
angle : float, optional
The angle in degrees between the axis of the cone and a
generatrix.
resolution : int, default: 6
Number of facets used to represent the cone.
Examples
--------
Create a default ConeSource.
>>> import pyvista as pv
>>> source = pv.ConeSource()
>>> source.output.plot(show_edges=True, line_width=5)
"""
def __init__(
self,
center=(0.0, 0.0, 0.0),
direction=(1.0, 0.0, 0.0),
height=1.0,
radius=None,
capping=True,
angle=None,
resolution=6,
):
"""Initialize the cone source class."""
super().__init__()
self.center = center
self.direction = direction
self.height = height
self.capping = capping
if angle is not None and radius is not None:
raise ValueError(
"Both radius and angle cannot be specified. They are mutually exclusive."
)
elif angle is not None and radius is None:
self.angle = angle
elif angle is None and radius is not None:
self.radius = radius
elif angle is None and radius is None:
self.radius = 0.5
self.resolution = resolution
@property
def center(self) -> Sequence[float]:
"""Get the center in ``[x, y, z]``. Axis of the cone passes through this point.
Returns
-------
sequence[float]
Center in ``[x, y, z]``. Axis of the cone passes through this
point.
"""
return self.GetCenter()
@center.setter
def center(self, center: Sequence[float]):
"""Set the center in ``[x, y, z]``. Axis of the cone passes through this point.
Parameters
----------
center : sequence[float]
Center in ``[x, y, z]``. Axis of the cone passes through this
point.
"""
self.SetCenter(center)
@property
def direction(self) -> Sequence[float]:
"""Get the direction vector in ``[x, y, z]``. Orientation vector of the cone.
Returns
-------
sequence[float]
Direction vector in ``[x, y, z]``. Orientation vector of the
cone.
"""
return self.GetDirection()
@direction.setter
def direction(self, direction: Sequence[float]):
"""Set the direction in ``[x, y, z]``. Axis of the cone passes through this point.
Parameters
----------
direction : sequence[float]
Direction vector in ``[x, y, z]``. Orientation vector of the
cone.
"""
self.SetDirection(direction)
@property
def height(self) -> float:
"""Get the height along the cone in its specified direction.
Returns
-------
float
Height along the cone in its specified direction.
"""
return self.GetHeight()
@height.setter
def height(self, height: float):
"""Set the height of the cone.
Parameters
----------
height : float
Height of the cone.
"""
self.SetHeight(height)
@property
def radius(self) -> float:
"""Get base radius of the cone.
Returns
-------
float
Base radius of the cone.
"""
return self.GetRadius()
@radius.setter
def radius(self, radius: float):
"""Set base radius of the cone.
Parameters
----------
radius : float
Base radius of the cone.
"""
self.SetRadius(radius)
@property
def capping(self) -> bool:
"""Enable or disable the capping the base of the cone with a polygon.
Returns
-------
bool
Enable or disable the capping the base of the cone with a
polygon.
"""
return bool(self.GetCapping())
@capping.setter
def capping(self, capping: bool):
"""Set base capping of the cone.
Parameters
----------
capping : bool, optional
Enable or disable the capping the base of the cone with a
polygon.
"""
self.SetCapping(capping)
@property
def angle(self) -> float:
"""Get the angle in degrees between the axis of the cone and a generatrix.
Returns
-------
float
The angle in degrees between the axis of the cone and a
generatrix.
"""
return self.GetAngle()
@angle.setter
def angle(self, angle: float):
"""Set the angle in degrees between the axis of the cone and a generatrix.
Parameters
----------
angle : float, optional
The angle in degrees between the axis of the cone and a
generatrix.
"""
self.SetAngle(angle)
@property
def resolution(self) -> int:
"""Get number of points on the circular face of the cone.
Returns
-------
int
Number of points on the circular face of the cone.
"""
return self.GetResolution()
@resolution.setter
def resolution(self, resolution: int):
"""Set number of points on the circular face of the cone.
Parameters
----------
resolution : int
Number of points on the circular face of the cone.
"""
self.SetResolution(resolution)
@property
def output(self):
"""Get the output data object for a port on this algorithm.
Returns
-------
pyvista.PolyData
Cone surface.
"""
self.Update()
return wrap(self.GetOutput())
@no_new_attr
class CylinderSource(_vtk.vtkCylinderSource):
"""Cylinder source algorithm class.
.. warning::
:func:`pyvista.Cylinder` function rotates the :class:`pyvista.CylinderSource` 's
:class:`pyvista.PolyData` in its own way.
It rotates the :attr:`pyvista.CylinderSource.output` 90 degrees in z-axis, translates and
orients the mesh to a new ``center`` and ``direction``.
Parameters
----------
center : sequence[float], default: (0.0, 0.0, 0.0)
Location of the centroid in ``[x, y, z]``.
direction : sequence[float], default: (1.0, 0.0, 0.0)
Direction cylinder points to in ``[x, y, z]``.
radius : float, default: 0.5
Radius of the cylinder.
height : float, default: 1.0
Height of the cylinder.
capping : bool, default: True
Cap cylinder ends with polygons.
resolution : int, default: 100
Number of points on the circular face of the cylinder.
Examples
--------
Create a default CylinderSource.
>>> import pyvista as pv
>>> source = pv.CylinderSource()
>>> source.output.plot(show_edges=True, line_width=5)
Display a 3D plot of a default :class:`CylinderSource`.
>>> import pyvista as pv
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(pv.CylinderSource(), show_edges=True, line_width=5)
>>> pl.show()
Visualize the output of :class:`CylinderSource` in a 3D plot.
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(
... pv.CylinderSource().output, show_edges=True, line_width=5
... )
>>> pl.show()
The above examples are similar in terms of their behavior.
"""
_new_attr_exceptions = ['_center', '_direction']
def __init__(
self,
center=(0.0, 0.0, 0.0),
direction=(1.0, 0.0, 0.0),
radius=0.5,
height=1.0,
capping=True,
resolution=100,
):
"""Initialize the cylinder source class."""
super().__init__()
self._center = center
self._direction = direction
self.radius = radius
self.height = height
self.resolution = resolution
self.capping = capping
@property
def center(self) -> Sequence[float]:
"""Get location of the centroid in ``[x, y, z]``.
Returns
-------
sequence[float]
Center in ``[x, y, z]``. Axis of the cylinder passes through this
point.
"""
return self._center
@center.setter
def center(self, center: Sequence[float]):
"""Set location of the centroid in ``[x, y, z]``.
Parameters
----------
center : sequence[float]
Center in ``[x, y, z]``. Axis of the cylinder passes through this
point.
"""
self._center = center
@property
def direction(self) -> Sequence[float]:
"""Get the direction vector in ``[x, y, z]``. Orientation vector of the cylinder.
Returns
-------
sequence[float]
Direction vector in ``[x, y, z]``. Orientation vector of the
cylinder.
"""
return self._direction
@direction.setter
def direction(self, direction: Sequence[float]):
"""Set the direction in ``[x, y, z]``. Axis of the cylinder passes through this point.
Parameters
----------
direction : sequence[float]
Direction vector in ``[x, y, z]``. Orientation vector of the
cylinder.
"""
self._direction = direction
@property
def radius(self) -> float:
"""Get radius of the cylinder.
Returns
-------
float
Radius of the cylinder.
"""
return self.GetRadius()
@radius.setter
def radius(self, radius: float):
"""Set radius of the cylinder.
Parameters
----------
radius : float
Radius of the cylinder.
"""
self.SetRadius(radius)
@property
def height(self) -> float:
"""Get the height of the cylinder.
Returns
-------
float
Height of the cylinder.
"""
return self.GetHeight()
@height.setter
def height(self, height: float):
"""Set the height of the cylinder.
Parameters
----------
height : float
Height of the cylinder.
"""
self.SetHeight(height)
@property
def resolution(self) -> int:
"""Get number of points on the circular face of the cylinder.
Returns
-------
int
Number of points on the circular face of the cone.
"""
return self.GetResolution()
@resolution.setter
def resolution(self, resolution: int):
"""Set number of points on the circular face of the cone.
Parameters
----------
resolution : int
Number of points on the circular face of the cone.
"""
self.SetResolution(resolution)
@property
def capping(self) -> bool:
"""Get cap cylinder ends with polygons.
Returns
-------
bool
Cap cylinder ends with polygons.
"""
return bool(self.GetCapping())
@capping.setter
def capping(self, capping: bool):
"""Set cap cylinder ends with polygons.
Parameters
----------
capping : bool, optional
Cap cylinder ends with polygons.
"""
self.SetCapping(capping)
@property
def capsule_cap(self) -> bool:
"""Get whether the capping should make the cylinder a capsule.
.. versionadded:: 0.44.0
Returns
-------
bool
Capsule cap.
"""
return bool(self.GetCapsuleCap())
@capsule_cap.setter
def capsule_cap(self, capsule_cap: bool):
"""Set whether the capping should make the cylinder a capsule.
Parameters
----------
capsule_cap : bool
Capsule cap.
"""
self.SetCapsuleCap(capsule_cap)
@property
def output(self):
"""Get the output data object for a port on this algorithm.
Returns
-------
pyvista.PolyData
Cylinder surface.
"""
self.Update()
return wrap(self.GetOutput())
@no_new_attr
class MultipleLinesSource(_vtk.vtkLineSource):
"""Multiple lines source algorithm class.
Parameters
----------
points : array_like[float], default: [[-0.5, 0.0, 0.0], [0.5, 0.0, 0.0]]
List of points defining a broken line.
"""
_new_attr_exceptions = ['points']
def __init__(self, points=None):
"""Initialize the multiple lines source class."""
if points is None:
points = [[-0.5, 0.0, 0.0], [0.5, 0.0, 0.0]]
super().__init__()
self.points = points
@property
def points(self) -> NumpyArray[float]:
"""Return the points defining a broken line.
Returns
-------
np.ndarray
Points defining a broken line.
"""
return _vtk.vtk_to_numpy(self.GetPoints().GetData())
@points.setter
def points(self, points: Union[MatrixLike[float], VectorLike[float]]):
"""Set the list of points defining a broken line.
Parameters
----------
points : VectorLike[float] | MatrixLike[float]
List of points defining a broken line.
"""
points, _ = _coerce_pointslike_arg(points)
if not (len(points) >= 2):
raise ValueError('>=2 points need to define multiple lines.')
self.SetPoints(pyvista.vtk_points(points))
@property
def output(self):
"""Get the output data object for a port on this algorithm.
Returns
-------
pyvista.PolyData
Line mesh.
"""
self.Update()
return wrap(self.GetOutput())
class Text3DSource(vtkVectorText):
"""3D text from a string.
Generate 3D text from a string with a specified width, height or depth.
.. versionadded:: 0.43
Parameters
----------
string : str, default: ""
Text string of the source.
depth : float, optional
Depth of the text. If ``None``, the depth is set to half
the :attr:`height` by default. Set to ``0.0`` for planar
text.
width : float, optional
Width of the text. If ``None``, the width is scaled
proportional to :attr:`height`.
height : float, optional
Height of the text. If ``None``, the height is scaled
proportional to :attr:`width`.
center : Sequence[float], default: (0.0, 0.0, 0.0)
Center of the text, defined as the middle of the axis-aligned
bounding box of the text.
normal : Sequence[float], default: (0.0, 0.0, 1.0)
Normal direction of the text. The direction is parallel to the
:attr:`depth` of the text and points away from the front surface
of the text.
process_empty_string : bool, default: True
If ``True``, when :attr:`string` is empty the :attr:`output` is a
single point located at :attr:`center` instead of an empty mesh.
See :attr:`process_empty_string` for details.
"""
_new_attr_exceptions = [
'_center',
'_height',
'_width',
'_depth',
'_normal',
'_process_empty_string',
'_output',
'_extrude_filter',
'_tri_filter',
'_modified',
]
def __init__(
self,
string=None,
depth=None,
width=None,
height=None,
center=(0, 0, 0),
normal=(0, 0, 1),
process_empty_string=True,
):
"""Initialize source."""
super().__init__()
# Create output filters to make text 3D
extrude = _vtk.vtkLinearExtrusionFilter()
extrude.SetInputConnection(self.GetOutputPort())
extrude.SetExtrusionTypeToNormalExtrusion()
extrude.SetVector(0, 0, 1)
self._extrude_filter = extrude
tri_filter = _vtk.vtkTriangleFilter()
tri_filter.SetInputConnection(extrude.GetOutputPort())
self._tri_filter = tri_filter
self._output = pyvista.PolyData()
# Set params
self.string = "" if string is None else string
self._process_empty_string = process_empty_string
self._center = center
self._normal = normal
self._height = height
self._width = width
self._depth = depth
self._modified = True
def __setattr__(self, name, value): # numpydoc ignore=GL08
"""Override to set modified flag and disable setting new attributes."""
if hasattr(self, name) and name != '_modified':
# Set modified flag
old_value = getattr(self, name)
if not np.array_equal(old_value, value):
object.__setattr__(self, name, value)
object.__setattr__(self, '_modified', True)
else:
# Do not allow setting attributes.
# This is similar to using @no_new_attr decorator but without
# the __setattr__ override since this class defines its own override
# for setting the modified flag
if name in Text3DSource._new_attr_exceptions:
object.__setattr__(self, name, value)
else:
raise AttributeError(
f'Attribute "{name}" does not exist and cannot be added to type '
f'{self.__class__.__name__}'
)
def __del__(self):
"""Delete filters."""
self._tri_filter = None
self._extrude_filter = None
@property
def string(self) -> str: # numpydoc ignore=RT01
"""Return or set the text string."""
return self.GetText()
@string.setter
def string(self, string: str): # numpydoc ignore=GL08
self.SetText("" if string is None else string)
@property
def process_empty_string(self) -> bool: # numpydoc ignore=RT01
"""Return or set flag to control behavior when empty strings are set.
When :attr:`string` is empty or only contains whitespace, the :attr:`output`
mesh will be empty. This can cause the bounds of the output to be undefined.
If ``True``, the output is modified to instead have a single point located
at :attr:`center`.
"""
return self._process_empty_string
@process_empty_string.setter
def process_empty_string(self, value: bool): # numpydoc ignore=GL08
self._process_empty_string = value
@property
def center(self) -> Tuple[float, float, float]: # numpydoc ignore=RT01
"""Return or set the center of the text.
The center is defined as the middle of the axis-aligned bounding box
of the text.
"""
return self._center
@center.setter
def center(self, center: Sequence[float]): # numpydoc ignore=GL08
self._center = float(center[0]), float(center[1]), float(center[2])
@property
def normal(self) -> Tuple[float, float, float]: # numpydoc ignore=RT01
"""Return or set the normal direction of the text.
The normal direction is parallel to the :attr:`depth` of the text, and
points away from the front surface of the text.
"""
return self._normal
@normal.setter
def normal(self, normal: Sequence[float]): # numpydoc ignore=GL08
self._normal = float(normal[0]), float(normal[1]), float(normal[2])
@property
def width(self) -> float: # numpydoc ignore=RT01
"""Return or set the width of the text."""
return self._width
@width.setter
def width(self, width: float): # numpydoc ignore=GL08
_check_range(width, rng=(0, float('inf')), parm_name='width') if width is not None else None
self._width = width