Debian Codegraph @

pyvista/core/celltype.py

raw
1 """Define types of cells."""
2
3 from __future__ import annotations
4
5 from enum import EnumMeta
6 from enum import IntEnum
7 import textwrap
8 from types import MappingProxyType
9 from typing import ClassVar
10 from typing import Literal
11 from typing import NamedTuple
12 from typing import cast
13 from typing import get_args
14
15 from pyvista import _vtk
16 from pyvista.core._vtk_utilities import vtk_version_info
17
18 _Dimension = Literal[0, 1, 2, 3]
19 PLACEHOLDER = 'IMAGE-HASH-PLACEHOLDER'
20
21 # Canonical dimensions for abstract / placeholder cell types.
22 # ``vtkCellTypeUtilities.GetDimension(value)`` returns ``0`` for these on
23 # vtk<9.4 AND emits ``vtkGenericCell ERR| Unsupported cell type: N Setting to
24 # vtkEmptyCell`` warnings via the ``vtkEmptyCell`` fallback. Using a hardcoded
25 # table avoids the warnings and gives the correct dimension on every VTK
26 # build. See https://github.com/pyvista/pyvista/issues/8634
27 _ABSTRACT_DIMENSIONS: dict[int, _Dimension] = {
28 _vtk.VTK_PARAMETRIC_CURVE: 1,
29 _vtk.VTK_PARAMETRIC_SURFACE: 2,
30 _vtk.VTK_PARAMETRIC_TRI_SURFACE: 2,
31 _vtk.VTK_PARAMETRIC_QUAD_SURFACE: 2,
32 _vtk.VTK_PARAMETRIC_TETRA_REGION: 3,
33 _vtk.VTK_PARAMETRIC_HEX_REGION: 3,
34 _vtk.VTK_HIGHER_ORDER_EDGE: 1,
35 _vtk.VTK_HIGHER_ORDER_TRIANGLE: 2,
36 _vtk.VTK_HIGHER_ORDER_QUAD: 2,
37 _vtk.VTK_HIGHER_ORDER_POLYGON: 2,
38 _vtk.VTK_HIGHER_ORDER_TETRAHEDRON: 3,
39 _vtk.VTK_HIGHER_ORDER_WEDGE: 3,
40 _vtk.VTK_HIGHER_ORDER_PYRAMID: 3,
41 _vtk.VTK_HIGHER_ORDER_HEXAHEDRON: 3,
42 _vtk.VTK_LAGRANGE_PYRAMID: 3,
43 _vtk.VTK_BEZIER_PYRAMID: 3,
44 }
45
46 _GRID_TEMPLATE_NO_IMAGE = """
47 .. grid:: 1
48 :margin: 1
49
50 .. grid-item::
51
52 {}
53
54 {}
55 """
56
57 _GRID_TEMPLATE_WITH_IMAGE = """
58 .. grid:: 1 2 2 2
59 :reverse:
60 :margin: 1
61
62 .. grid-item::
63 :columns: 12 4 4 4
64
65 .. card::
66 :class-body: sd-px-0 sd-py-0 sd-rounded-3
67 :link: pyvista.examples.cells.{}
68 :link-type: any
69
70 .. image:: /../_build/plot_directive/api/examples/_autosummary/pyvista-examples-cells-{}-{}_00_00.png
71
72 .. grid-item::
73 :columns: 12 8 8 8
74
75 {}
76
77 {}
78 """ # noqa: E501
79
80
81 def _indent_paragraph(string: str, level: int) -> str:
82 indentation = ''.join([' '] * level)
83 return textwrap.indent(textwrap.dedent(string).strip(), indentation)
84
85
86 # See link for color names: https://sphinx-design.readthedocs.io/en/latest/badges_buttons.html
87 _BADGE_COLORS = dict(
88 linear='primary', composite='success', dimension='secondary', geometry='muted'
89 )
90
91
92 def _generate_badge(*, kind: str, text: str, attr: str) -> str:
93 color = _BADGE_COLORS[kind]
94 ref = f'pyvista.CellType.{attr}'
95 return f':bdg-link-{color}:`{text} <{ref}>`'
96
97
98 def _generate_linear_badge(is_linear: bool) -> str: # noqa: FBT001
99 text = 'Linear' if is_linear else 'Non-linear'
100 return _generate_badge(kind='linear', text=text, attr='is_linear')
101
102
103 def _generate_composite_badge(is_composite: bool) -> str: # noqa: FBT001
104 text = 'Composite' if is_composite else 'Primary'
105 return _generate_badge(kind='composite', text=text, attr='is_composite')
106
107
108 def _generate_dimension_badge(dimension: int) -> str:
109 return _generate_badge(kind='dimension', text=f'{dimension}D', attr='dimension')
110
111
112 def _generate_points_badge(n_points: int) -> str:
113 return _generate_badge(kind='geometry', text=f'Points: {n_points}', attr='n_points')
114
115
116 def _generate_edges_badge(n_edges: int) -> str:
117 return _generate_badge(kind='geometry', text=f'Edges: {n_edges}', attr='n_edges')
118
119
120 def _generate_faces_badge(n_faces: int) -> str:
121 return _generate_badge(kind='geometry', text=f'Faces: {n_faces}', attr='n_faces')
122
123
124 class _CellTypeTuple(NamedTuple):
125 value: int
126 doc: str = ''
127 example: str | None = None
128 variable_points: bool = False
129 variable_edges: bool = False
130 variable_faces: bool = False
131
132
133 _CELL_TYPE_INFO = dict(
134 ####################################################################################
135 # Linear cells
136 EMPTY_CELL=_CellTypeTuple(
137 value=_vtk.VTK_EMPTY_CELL,
138 example='Empty',
139 doc="""Used as a place-holder during processing.""",
140 ),
141 VERTEX=_CellTypeTuple(
142 value=_vtk.VTK_VERTEX,
143 example='Vertex',
144 doc="""
145 Represents a point in 3D space.
146
147 The vertex is a primary zero-dimensional cell. It is defined by a single point.
148 """,
149 ),
150 POLY_VERTEX=_CellTypeTuple(
151 value=_vtk.VTK_POLY_VERTEX,
152 example='PolyVertex',
153 variable_points=True,
154 doc="""
155 Represents a set of points in 3D space.
156
157 The polyvertex is a composite zero-dimensional cell. It is defined by an
158 arbitrarily ordered list of points.
159 """,
160 ),
161 LINE=_CellTypeTuple(
162 value=_vtk.VTK_LINE,
163 example='Line',
164 doc="""
165 Represents a 1D line.
166
167 The line is a primary one-dimensional cell. It is defined by two points.
168 The direction along the line is from the first point to the second point.
169 """,
170 ),
171 POLY_LINE=_CellTypeTuple(
172 value=_vtk.VTK_POLY_LINE,
173 example='PolyLine',
174 variable_points=True,
175 doc="""
176 Represents a set of 1D lines.
177
178 The polyline is a composite one-dimensional cell consisting of one or more
179 connected lines.
180 """,
181 ),
182 TRIANGLE=_CellTypeTuple(
183 value=_vtk.VTK_TRIANGLE,
184 example='Triangle',
185 doc="""
186 Represents a 2D triangle.
187
188 The triangle is a primary two-dimensional cell. The triangle is defined by a
189 counter-clockwise ordered list of three points.
190 """,
191 ),
192 TRIANGLE_STRIP=_CellTypeTuple(
193 value=_vtk.VTK_TRIANGLE_STRIP,
194 example='TriangleStrip',
195 variable_points=True,
196 variable_edges=True,
197 doc="""
198 Represents a 2D triangle strip.
199
200 The triangle strip is a composite two-dimensional cell consisting of one or more
201 triangles. It is a compact representation of triangles connected edge-to-edge.
202 """,
203 ),
204 POLYGON=_CellTypeTuple(
205 value=_vtk.VTK_POLYGON,
206 example='Polygon',
207 variable_points=True,
208 variable_edges=True,
209 doc="""
210 Represents a 2D n-sided polygon.
211
212 The polygon is a primary two-dimensional cell. It is defined by an ordered list
213 of three or more points lying in a plane.
214 """,
215 ),
216 PIXEL=_CellTypeTuple(
217 value=_vtk.VTK_PIXEL,
218 example='Pixel',
219 doc="""
220 Represents a 2D orthogonal quadrilateral.
221
222 The pixel is a primary two-dimensional cell defined by an ordered list of four
223 points.
224
225 .. warning::
226 This definition of a pixel differs from the conventional definition which
227 describes a single constant-valued element in an image. The meaning of this
228 term can vary depending on context. See :ref:`image_representations_example`
229 for examples.
230 """,
231 ),
232 QUAD=_CellTypeTuple(
233 value=_vtk.VTK_QUAD,
234 example='Quadrilateral',
235 doc="""
236 Represents a 2D quadrilateral.
237
238 The quadrilateral is a primary two-dimensional cell. It is defined by an ordered
239 list of four points lying in a plane.
240 """,
241 ),
242 TETRA=_CellTypeTuple(
243 value=_vtk.VTK_TETRA,
244 example='Tetrahedron',
245 doc="""
246 Represents a 3D tetrahedron.
247
248 The tetrahedron is a primary three-dimensional cell. The tetrahedron is defined
249 by a list of four non-planar points. It has six edges and four triangular faces.
250 """,
251 ),
252 VOXEL=_CellTypeTuple(
253 value=_vtk.VTK_VOXEL,
254 example='Voxel',
255 doc="""
256 Represents a 3D orthogonal parallelepiped.
257
258 The voxel is a primary three-dimensional cell defined by an ordered list of
259 eight points.
260
261 .. warning::
262 This definition of a voxel differs from the conventional definition which
263 describes a single constant-valued volume element. The meaning of this
264 term can vary depending on context. See :ref:`image_representations_example`
265 for examples.
266 """,
267 ),
268 HEXAHEDRON=_CellTypeTuple(
269 value=_vtk.VTK_HEXAHEDRON,
270 example='Hexahedron',
271 doc="""
272 Represents a 3D rectangular hexahedron.
273
274 The hexahedron is a primary three-dimensional cell consisting of six
275 quadrilateral faces, twelve edges, and eight vertices.
276 """,
277 ),
278 WEDGE=_CellTypeTuple(
279 value=_vtk.VTK_WEDGE,
280 example='Wedge',
281 doc="""
282 Represents a linear 3D wedge.
283
284 The wedge is a primary three-dimensional cell consisting of two triangular
285 and three quadrilateral faces.
286 """,
287 ),
288 PYRAMID=_CellTypeTuple(
289 value=_vtk.VTK_PYRAMID,
290 example='Pyramid',
291 doc="""
292 Represents a 3D pyramid.
293
294 The pyramid is a primary three-dimensional cell consisting of a rectangular base
295 with four triangular faces. It is defined by an ordered list of five points.
296 """,
297 ),
298 PENTAGONAL_PRISM=_CellTypeTuple(
299 value=_vtk.VTK_PENTAGONAL_PRISM,
300 example='PentagonalPrism',
301 doc="""
302 Represents a convex 3D prism with a pentagonal base and five quadrilateral faces.
303
304 The pentagonal prism is a primary three-dimensional cell defined by an ordered
305 list of ten points.
306 """,
307 ),
308 HEXAGONAL_PRISM=_CellTypeTuple(
309 value=_vtk.VTK_HEXAGONAL_PRISM,
310 example='HexagonalPrism',
311 doc="""
312 Represents a 3D prism with hexagonal base and six quadrilateral faces.
313
314 The hexagonal prism is a primary three-dimensional cell defined by an ordered
315 list of twelve points.
316 """,
317 ),
318 ####################################################################################
319 # Quadratic, isoparametric cells
320 QUADRATIC_EDGE=_CellTypeTuple(
321 value=_vtk.VTK_QUADRATIC_EDGE,
322 example='QuadraticEdge',
323 doc="""
324 Represents a 1D, 3-node, iso-parametric parabolic line.
325
326 The cell includes a mid-edge node.
327 """,
328 ),
329 QUADRATIC_TRIANGLE=_CellTypeTuple(
330 value=_vtk.VTK_QUADRATIC_TRIANGLE,
331 example='QuadraticTriangle',
332 doc="""
333 Represents a 2D, 6-node, iso-parametric parabolic triangle.
334
335 The cell includes a mid-edge node for each of the three edges of the cell.
336 """,
337 ),
338 QUADRATIC_QUAD=_CellTypeTuple(
339 value=_vtk.VTK_QUADRATIC_QUAD,
340 example='QuadraticQuadrilateral',
341 doc="""
342 Represents a 2D, 8-node iso-parametric parabolic quadrilateral element.
343
344 The cell includes a mid-edge node for each of the four edges of the cell.
345 """,
346 ),
347 QUADRATIC_POLYGON=_CellTypeTuple(
348 value=_vtk.VTK_QUADRATIC_POLYGON,
349 example='QuadraticPolygon',
350 variable_points=True,
351 variable_edges=True,
352 doc="""
353 Represents a 2D n-sided (2*n nodes) parabolic polygon.
354
355 The polygon cannot have any internal holes, and cannot self-intersect.
356 The cell includes a mid-edge node for each of the n edges of the cell.
357 """,
358 ),
359 QUADRATIC_TETRA=_CellTypeTuple(
360 value=_vtk.VTK_QUADRATIC_TETRA,
361 example='QuadraticTetrahedron',
362 doc="""
363 Represents a 3D, 10-node, iso-parametric parabolic tetrahedron.
364
365 The cell includes a mid-edge node on each of the side edges of the tetrahedron.
366 """,
367 ),
368 QUADRATIC_HEXAHEDRON=_CellTypeTuple(
369 value=_vtk.VTK_QUADRATIC_HEXAHEDRON,
370 example='QuadraticHexahedron',
371 doc="""
372 Represents a 3D, 20-node iso-parametric parabolic hexahedron.
373
374 The cell includes a mid-edge node.
375 """,
376 ),
377 QUADRATIC_WEDGE=_CellTypeTuple(
378 value=_vtk.VTK_QUADRATIC_WEDGE,
379 example='QuadraticWedge',
380 doc="""
381 Represents a 3D, 15-node iso-parametric parabolic wedge.
382
383 The cell includes a mid-edge node.
384 """,
385 ),
386 QUADRATIC_PYRAMID=_CellTypeTuple(
387 value=_vtk.VTK_QUADRATIC_PYRAMID,
388 example='QuadraticPyramid',
389 doc="""
390 Represents a 3D, 13-node iso-parametric parabolic pyramid.
391
392 The cell includes a mid-edge node.
393 """,
394 ),
395 BIQUADRATIC_QUAD=_CellTypeTuple(
396 value=_vtk.VTK_BIQUADRATIC_QUAD,
397 example='BiQuadraticQuadrilateral',
398 doc="""
399 Represents a 2D, 9-node iso-parametric parabolic quadrilateral element with a center-point.
400
401 The cell includes a mid-edge node for each of the four edges of the cell and
402 a center node at the surface.
403 """,
404 ),
405 TRIQUADRATIC_HEXAHEDRON=_CellTypeTuple(
406 value=_vtk.VTK_TRIQUADRATIC_HEXAHEDRON,
407 example='TriQuadraticHexahedron',
408 doc="""
409 Represents a 3D, 27-node iso-parametric triquadratic hexahedron.
410
411 The cell includes 8 edge nodes, 12 mid-edge nodes, 6 mid-face nodes and one
412 mid-volume node.
413 """,
414 ),
415 TRIQUADRATIC_PYRAMID=_CellTypeTuple(
416 value=_vtk.VTK_TRIQUADRATIC_PYRAMID,
417 example='TriQuadraticPyramid',
418 doc="""
419 Represents a second order 3D iso-parametric 19-node pyramid.
420
421 The cell includes 5 corner nodes, 8 mid-edge nodes, 5 mid-face nodes,
422 and 1 volumetric centroid node.
423 """,
424 ),
425 QUADRATIC_LINEAR_QUAD=_CellTypeTuple(
426 value=_vtk.VTK_QUADRATIC_LINEAR_QUAD,
427 example='QuadraticLinearQuadrilateral',
428 doc="""
429 Represents a 2D, 6-node iso-parametric quadratic-linear quadrilateral element.
430
431 The cell includes a mid-edge node for two of the four edges.
432 """,
433 ),
434 QUADRATIC_LINEAR_WEDGE=_CellTypeTuple(
435 value=_vtk.VTK_QUADRATIC_LINEAR_WEDGE,
436 example='QuadraticLinearWedge',
437 doc="""
438 Represents a 3D, 12-node iso-parametric linear quadratic wedge.
439
440 The cell includes mid-edge node in the triangle edges.
441 """,
442 ),
443 BIQUADRATIC_QUADRATIC_WEDGE=_CellTypeTuple(
444 value=_vtk.VTK_BIQUADRATIC_QUADRATIC_WEDGE,
445 example='BiQuadraticQuadraticWedge',
446 doc="""
447 Represents a 3D, 18-node iso-parametric bi-quadratic wedge.
448
449 The cell includes a mid-edge node.
450 """,
451 ),
452 BIQUADRATIC_QUADRATIC_HEXAHEDRON=_CellTypeTuple(
453 value=_vtk.VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON,
454 example='BiQuadraticQuadraticHexahedron',
455 doc="""
456 Represents a 3D, 24-node iso-parametric biquadratic hexahedron.
457
458 The cell includes mid-edge and center-face nodes.
459 """,
460 ),
461 BIQUADRATIC_TRIANGLE=_CellTypeTuple(
462 value=_vtk.VTK_BIQUADRATIC_TRIANGLE,
463 example='BiQuadraticTriangle',
464 doc="""
465 Represents a 2D, 7-node, iso-parametric parabolic triangle.
466
467 The cell includes three mid-edge nodes besides the three triangle vertices
468 and a center node.
469 """,
470 ),
471 ####################################################################################
472 # Cubic, iso-parametric cell
473 CUBIC_LINE=_CellTypeTuple(
474 value=_vtk.VTK_CUBIC_LINE,
475 example='CubicLine',
476 doc="""
477 Represents a 1D iso-parametric cubic line.
478
479 The cell includes two mid-edge nodes.
480 """,
481 ),
482 ####################################################################################
483 # Special class of cells formed by convex group of points
484 CONVEX_POINT_SET=_CellTypeTuple(
485 value=_vtk.VTK_CONVEX_POINT_SET,
486 example='ConvexPointSet',
487 doc="""
488 Represents a 3D cell defined by a convex set of points.
489 """,
490 variable_points=True,
491 variable_edges=True,
492 variable_faces=True,
493 ),
494 ####################################################################################
495 # Polyhedron cell (consisting of polygonal faces)
496 POLYHEDRON=_CellTypeTuple(
497 value=_vtk.VTK_POLYHEDRON,
498 example='Polyhedron',
499 doc="""
500 Represents a 3D cell defined by a set of polygonal faces.
501
502 """,
503 variable_points=True,
504 variable_edges=True,
505 variable_faces=True,
506 ),
507 ####################################################################################
508 # Higher order cells in parametric form
509 PARAMETRIC_CURVE=_CellTypeTuple(value=_vtk.VTK_PARAMETRIC_CURVE),
510 PARAMETRIC_SURFACE=_CellTypeTuple(value=_vtk.VTK_PARAMETRIC_SURFACE),
511 PARAMETRIC_TRI_SURFACE=_CellTypeTuple(value=_vtk.VTK_PARAMETRIC_TRI_SURFACE),
512 PARAMETRIC_QUAD_SURFACE=_CellTypeTuple(value=_vtk.VTK_PARAMETRIC_QUAD_SURFACE),
513 PARAMETRIC_TETRA_REGION=_CellTypeTuple(value=_vtk.VTK_PARAMETRIC_TETRA_REGION),
514 PARAMETRIC_HEX_REGION=_CellTypeTuple(value=_vtk.VTK_PARAMETRIC_HEX_REGION),
515 ####################################################################################
516 # Higher order cells
517 HIGHER_ORDER_EDGE=_CellTypeTuple(value=_vtk.VTK_HIGHER_ORDER_EDGE),
518 HIGHER_ORDER_TRIANGLE=_CellTypeTuple(value=_vtk.VTK_HIGHER_ORDER_TRIANGLE),
519 HIGHER_ORDER_QUAD=_CellTypeTuple(value=_vtk.VTK_HIGHER_ORDER_QUAD),
520 HIGHER_ORDER_POLYGON=_CellTypeTuple(value=_vtk.VTK_HIGHER_ORDER_POLYGON),
521 HIGHER_ORDER_TETRAHEDRON=_CellTypeTuple(value=_vtk.VTK_HIGHER_ORDER_TETRAHEDRON),
522 HIGHER_ORDER_WEDGE=_CellTypeTuple(value=_vtk.VTK_HIGHER_ORDER_WEDGE),
523 HIGHER_ORDER_PYRAMID=_CellTypeTuple(value=_vtk.VTK_HIGHER_ORDER_PYRAMID),
524 HIGHER_ORDER_HEXAHEDRON=_CellTypeTuple(value=_vtk.VTK_HIGHER_ORDER_HEXAHEDRON),
525 ####################################################################################
526 # Arbitrary order Lagrange elements (formulated separated from generic higher order cells)
527 LAGRANGE_CURVE=_CellTypeTuple(
528 value=_vtk.VTK_LAGRANGE_CURVE,
529 example='LagrangeCurve',
530 variable_points=True,
531 doc="""
532 Lagrange representation of a curve with arbitrary order.
533 """,
534 ),
535 LAGRANGE_TRIANGLE=_CellTypeTuple(
536 value=_vtk.VTK_LAGRANGE_TRIANGLE,
537 example='LagrangeTriangle',
538 variable_points=True,
539 doc="""
540 Lagrange representation of a triangle with arbitrary order.
541 """,
542 ),
543 LAGRANGE_QUADRILATERAL=_CellTypeTuple(
544 value=_vtk.VTK_LAGRANGE_QUADRILATERAL,
545 example='LagrangeQuadrilateral',
546 variable_points=True,
547 doc="""
548 Lagrange representation of a quadrilateral with arbitrary order.
549 """,
550 ),
551 LAGRANGE_TETRAHEDRON=_CellTypeTuple(
552 value=_vtk.VTK_LAGRANGE_TETRAHEDRON,
553 example='LagrangeTetrahedron',
554 variable_points=True,
555 doc="""
556 Lagrange representation of a tetrahedron with arbitrary order.
557 """,
558 ),
559 LAGRANGE_HEXAHEDRON=_CellTypeTuple(
560 value=_vtk.VTK_LAGRANGE_HEXAHEDRON,
561 example='LagrangeHexahedron',
562 variable_points=True,
563 doc="""
564 Lagrange representation of a hexahedron with arbitrary order.
565 """,
566 ),
567 LAGRANGE_WEDGE=_CellTypeTuple(
568 value=_vtk.VTK_LAGRANGE_WEDGE,
569 example='LagrangeWedge',
570 variable_points=True,
571 doc="""
572 Lagrange representation of a wedge with arbitrary order.
573 """,
574 ),
575 LAGRANGE_PYRAMID=_CellTypeTuple(
576 value=_vtk.VTK_LAGRANGE_PYRAMID,
577 doc="""
578 Lagrange representation of a pyramid with arbitrary order.
579 """,
580 ),
581 ####################################################################################
582 # Arbitrary order Bezier elements (formulated separated from generic higher order cells)
583 BEZIER_CURVE=_CellTypeTuple(
584 value=_vtk.VTK_BEZIER_CURVE,
585 example='BezierCurve',
586 variable_points=True,
587 doc="""
588 Bezier representation of a curve with arbitrary order.
589 """,
590 ),
591 BEZIER_TRIANGLE=_CellTypeTuple(
592 value=_vtk.VTK_BEZIER_TRIANGLE,
593 example='BezierTriangle',
594 variable_points=True,
595 doc="""
596 Bezier representation of a triangle with arbitrary order.
597 """,
598 ),
599 BEZIER_QUADRILATERAL=_CellTypeTuple(
600 value=_vtk.VTK_BEZIER_QUADRILATERAL,
601 example='BezierQuadrilateral',
602 variable_points=True,
603 doc="""
604 Bezier representation of a quadrilateral with arbitrary order.
605 """,
606 ),
607 BEZIER_TETRAHEDRON=_CellTypeTuple(
608 value=_vtk.VTK_BEZIER_TETRAHEDRON,
609 example='BezierTetrahedron',
610 variable_points=True,
611 doc="""
612 Bezier representation of a tetrahedron with arbitrary order.
613 """,
614 ),
615 BEZIER_HEXAHEDRON=_CellTypeTuple(
616 value=_vtk.VTK_BEZIER_HEXAHEDRON,
617 example='BezierHexahedron',
618 variable_points=True,
619 doc="""
620 Bezier representation of a hexahedron with arbitrary order.
621 """,
622 ),
623 BEZIER_WEDGE=_CellTypeTuple(
624 value=_vtk.VTK_BEZIER_WEDGE,
625 example='BezierWedge',
626 variable_points=True,
627 doc="""
628 Bezier representation of a wedge with arbitrary order.
629 """,
630 ),
631 BEZIER_PYRAMID=_CellTypeTuple(
632 value=_vtk.VTK_BEZIER_PYRAMID,
633 doc="""
634 Bezier representation of a pyramid with arbitrary order.
635 """,
636 ),
637 )
638
639
640 class _CellTypeMeta(EnumMeta):
641 """Metaclass to enable class property definitions for CellType."""
642
643 _dimension_map: ClassVar[dict[_Dimension, frozenset[CellType]]] = {}
644 _dimension_map_proxy: ClassVar[MappingProxyType[_Dimension, frozenset[CellType]]] = (
645 MappingProxyType(_dimension_map)
646 )
647
648 @property
649 def dimension_map(cls) -> MappingProxyType[_Dimension, frozenset[CellType]]:
650 """Return a mapping with sets for all cell types grouped by topological dimension.
651
652 The groupings are derived from each member's :attr:`dimension`.
653
654 .. versionadded:: 0.48
655
656 Returns
657 -------
658 dict
659 Dictionary with cell dimensions ``0``, ``1``, ``2,``, ``3`` as keys, and frozen sets as
660 values with the respective :class:`CellType` members.
661
662 See Also
663 --------
664 dimension
665 pyvista.DataSet.max_cell_dimensionality
666 pyvista.DataSet.min_cell_dimensionality
667 pyvista.DataSet.distinct_cell_types
668
669 Examples
670 --------
671 Common 2D cell types such as :attr:`TRIANGLE` and :attr:`TRIANGLE_STRIP`
672 are in the 2D grouping.
673
674 >>> import pyvista as pv
675 >>> two_d = pv.CellType.dimension_map[2]
676 >>> pv.CellType.TRIANGLE in two_d
677 True
678 >>> pv.CellType.TRIANGLE_STRIP in two_d
679 True
680
681 Check whether a mesh contains only 2D cells by combining this with
682 :attr:`~pyvista.DataSet.distinct_cell_types`.
683
684 >>> mesh = pv.Sphere()
685 >>> mesh.distinct_cell_types <= pv.CellType.dimension_map[2]
686 True
687
688 Show all 0D cell types.
689
690 >>> sorted(pv.CellType.dimension_map[0]) # doctest: +NORMALIZE_WHITESPACE
691 [<CellType.EMPTY_CELL: 0>,
692 <CellType.VERTEX: 1>,
693 <CellType.POLY_VERTEX: 2>]
694
695 Show all 1D cell types.
696
697 >>> sorted(pv.CellType.dimension_map[1]) # doctest: +NORMALIZE_WHITESPACE
698 [<CellType.LINE: 3>,
699 <CellType.POLY_LINE: 4>,
700 <CellType.QUADRATIC_EDGE: 21>,
701 <CellType.CUBIC_LINE: 35>,
702 <CellType.PARAMETRIC_CURVE: 51>,
703 <CellType.HIGHER_ORDER_EDGE: 60>,
704 <CellType.LAGRANGE_CURVE: 68>,
705 <CellType.BEZIER_CURVE: 75>]
706
707 Show all 2D cell types.
708
709 >>> sorted(pv.CellType.dimension_map[2]) # doctest: +NORMALIZE_WHITESPACE
710 [<CellType.TRIANGLE: 5>,
711 <CellType.TRIANGLE_STRIP: 6>,
712 <CellType.POLYGON: 7>,
713 <CellType.PIXEL: 8>,
714 <CellType.QUAD: 9>,
715 <CellType.QUADRATIC_TRIANGLE: 22>,
716 <CellType.QUADRATIC_QUAD: 23>,
717 <CellType.BIQUADRATIC_QUAD: 28>,
718 <CellType.QUADRATIC_LINEAR_QUAD: 30>,
719 <CellType.BIQUADRATIC_TRIANGLE: 34>,
720 <CellType.QUADRATIC_POLYGON: 36>,
721 <CellType.PARAMETRIC_SURFACE: 52>,
722 <CellType.PARAMETRIC_TRI_SURFACE: 53>,
723 <CellType.PARAMETRIC_QUAD_SURFACE: 54>,
724 <CellType.HIGHER_ORDER_TRIANGLE: 61>,
725 <CellType.HIGHER_ORDER_QUAD: 62>,
726 <CellType.HIGHER_ORDER_POLYGON: 63>,
727 <CellType.LAGRANGE_TRIANGLE: 69>,
728 <CellType.LAGRANGE_QUADRILATERAL: 70>,
729 <CellType.BEZIER_TRIANGLE: 76>,
730 <CellType.BEZIER_QUADRILATERAL: 77>]
731
732 Show all 3D cell types.
733
734 >>> sorted(pv.CellType.dimension_map[3]) # doctest: +NORMALIZE_WHITESPACE
735 [<CellType.TETRA: 10>,
736 <CellType.VOXEL: 11>,
737 <CellType.HEXAHEDRON: 12>,
738 <CellType.WEDGE: 13>,
739 <CellType.PYRAMID: 14>,
740 <CellType.PENTAGONAL_PRISM: 15>,
741 <CellType.HEXAGONAL_PRISM: 16>,
742 <CellType.QUADRATIC_TETRA: 24>,
743 <CellType.QUADRATIC_HEXAHEDRON: 25>,
744 <CellType.QUADRATIC_WEDGE: 26>,
745 <CellType.QUADRATIC_PYRAMID: 27>,
746 <CellType.TRIQUADRATIC_HEXAHEDRON: 29>,
747 <CellType.QUADRATIC_LINEAR_WEDGE: 31>,
748 <CellType.BIQUADRATIC_QUADRATIC_WEDGE: 32>,
749 <CellType.BIQUADRATIC_QUADRATIC_HEXAHEDRON: 33>,
750 <CellType.TRIQUADRATIC_PYRAMID: 37>,
751 <CellType.CONVEX_POINT_SET: 41>,
752 <CellType.POLYHEDRON: 42>,
753 <CellType.PARAMETRIC_TETRA_REGION: 55>,
754 <CellType.PARAMETRIC_HEX_REGION: 56>,
755 <CellType.HIGHER_ORDER_TETRAHEDRON: 64>,
756 <CellType.HIGHER_ORDER_WEDGE: 65>,
757 <CellType.HIGHER_ORDER_PYRAMID: 66>,
758 <CellType.HIGHER_ORDER_HEXAHEDRON: 67>,
759 <CellType.LAGRANGE_TETRAHEDRON: 71>,
760 <CellType.LAGRANGE_HEXAHEDRON: 72>,
761 <CellType.LAGRANGE_WEDGE: 73>,
762 <CellType.LAGRANGE_PYRAMID: 74>,
763 <CellType.BEZIER_TETRAHEDRON: 78>,
764 <CellType.BEZIER_HEXAHEDRON: 79>,
765 <CellType.BEZIER_WEDGE: 80>,
766 <CellType.BEZIER_PYRAMID: 81>]
767
768 """
769 if not (mapping := cls._dimension_map):
770 # Populate dict on first access
771 for dimension in get_args(_Dimension):
772 mapping[dimension] = frozenset(
773 celltype for celltype in CellType if celltype.dimension == dimension
774 )
775 return cls._dimension_map_proxy
776
777
778 class CellType(IntEnum, metaclass=_CellTypeMeta):
779 """Define types of cells.
780
781 Cells are defined by specifying a type in combination with an ordered list of points.
782 The ordered list, often referred to as the connectivity list, combined with the
783 type specification, implicitly defines the topology of the cell. The x-y-z point
784 coordinates define the cell geometry.
785
786 Although point coordinates are defined in three dimensions, the cell topology can
787 be 0, 1, 2, or 3-dimensional. Use :attr:`dimension` to check the topological dimension.
788
789 Cells can be primary (e.g. triangle) or composite (e.g. triangle strip). Composite
790 cells consist of one or more primary cells, while primary cells cannot be
791 decomposed. Use :attr:`is_composite` to check if a cell type is primary or composite.
792
793 Cells can also be characterized as linear or non-linear. Linear cells use
794 linear or constant interpolation, while non-linear cells may use quadratic,
795 cubic, or some other interpolation. Use :attr:`is_linear` to check if a cell type is linear.
796
797 Higher order interpolation is possible using Lagrange or Bézier cells. For Lagrange cells,
798 all the points lie on the interpolation curve, whereas for the Bézier cells, only the points at
799 the extremities are interpolatory.
800
801 This enumeration defines all cell types used in VTK and supported by PyVista. The
802 type(s) of cell(s) to use is typically chosen based on application need, such as
803 graphics rendering or numerical simulation.
804
805 .. seealso::
806
807 :class:`pyvista.Cell`
808 Wrapper for instances of :vtk:`vtkCell`.
809
810 :mod:`pyvista.examples.cells`
811 Examples creating a mesh comprising a single cell.
812
813 :ref:`linear_cells_example`
814 Detailed example using linear cells.
815
816 :ref:`create_polyhedron_example`
817 Example creating a mesh with :attr:`~pyvista.CellType.POLYHEDRON` cells.
818
819 :ref:`create_polydata_strips_example`
820 Example creating a mesh with :attr:`~pyvista.CellType.TRIANGLE_STRIP` cells.
821
822 References
823 ----------
824 `VTK Book: Cell Types <https://book.vtk.org/en/latest/VTKBook/05Chapter5.html#cell-types>`_
825 VTK reference about cell types.
826
827 `Modeling Lagrange Finite Elements in VTK <https://www.kitware.com//modeling-arbitrary-order-lagrange-finite-elements-in-the-visualization-toolkit/>`_
828 VTK blog post about Lagrange cells.
829
830 `Implementation of rational Bézier cells into VTK <https://www.kitware.com/implementation-of-rational-bezier-cells-into-vtk/>`_
831 VTK blog post about Bezier cells.
832
833 `vtkCellType.h <https://vtk.org/doc/nightly/html/vtkCellType_8h_source.html>`_
834 List of all cell types defined in VTK.
835
836 Examples
837 --------
838 Create a single cube. Notice how the cell type is defined using the
839 ``CellType``.
840
841 >>> import numpy as np
842 >>> from pyvista import CellType
843 >>> import pyvista as pv
844 >>> cells = np.array([8, 0, 1, 2, 3, 4, 5, 6, 7])
845 >>> cell_type = np.array([CellType.HEXAHEDRON], np.int8)
846 >>> points = np.array(
847 ... [
848 ... [0, 0, 0],
849 ... [1, 0, 0],
850 ... [1, 1, 0],
851 ... [0, 1, 0],
852 ... [0, 0, 1],
853 ... [1, 0, 1],
854 ... [1, 1, 1],
855 ... [0, 1, 1],
856 ... ],
857 ... dtype=np.float32,
858 ... )
859 >>> grid = pv.UnstructuredGrid(cells, cell_type, points)
860 >>> grid
861 UnstructuredGrid (...)
862 N Cells: 1
863 N Points: 8
864 X Bounds: 0.000e+00, 1.000e+00
865 Y Bounds: 0.000e+00, 1.000e+00
866 Z Bounds: 0.000e+00, 1.000e+00
867 N Arrays: 0
868
869 """
870
871 # Attributes populated in __new__
872 _vtk_class: type[_vtk.vtkCell] | None
873 _dimension: _Dimension
874 _is_linear: bool
875 _is_composite: bool
876 _n_points: int
877 _n_edges: int
878 _n_faces: int
879 _example: str | None
880
881 def __new__( # noqa: PYI034
882 cls: type[CellType],
883 value: int,
884 _doc: str = '',
885 _example: str | None = None,
886 _variable_points: bool = False, # noqa: FBT001, FBT002
887 _variable_edges: bool = False, # noqa: FBT001, FBT002
888 _variable_faces: bool = False, # noqa: FBT001, FBT002
889 ) -> CellType:
890 """Create new enum.
891
892 Optionally specify documentation info.
893
894 .. note::
895
896 When specifying multi-line ``doc`` strings, the lines *must* be all aligned.
897 I.e. do not put the first line immediately after the triple quotes; instead
898 put the first line of text on a new line.
899
900 Parameters
901 ----------
902 value : int
903 Integer value of the cell type.
904
905 _doc : str, optional
906 Short description of this cell type. Typically a single line but no more
907 than 3-4 lines. Should only include a general description and no technical
908 details or cell connectivity.
909
910 _example : str, optional
911 Name of the example for this cell type in `pyvista.examples.cell.<NAME>`.
912 When specified, the first figure from this example is used as the image for
913 the cell.
914
915 _variable_points: bool, optional
916 Override the value shown for this cell type's `Points` badge. May be
917 useful for composite cells (e.g. POLY_LINE or POLY_VERTEX) where a value
918 of ``0`` may otherwise be shown. By default, the value from ``vtk_class``
919 is used.
920
921 _variable_edges: bool, optional
922 Override the value shown for this cell type's `Edges` badge. May be
923 useful for composite cells (e.g. POLY_LINE or POLY_VERTEX) where a value
924 of ``0`` may otherwise be shown. By default, the value from ``vtk_class``
925 is used.
926
927 _variable_faces: bool, optional
928 Override the value shown for this cell type's `Faces` badge. May be
929 useful for composite cells (e.g. POLY_LINE or POLY_VERTEX) where a value
930 of ``0`` may otherwise be shown. By default, the value from ``vtk_class``
931 is used.
932
933 """
934 self = int.__new__(cls, value)
935 self._value_ = value
936 self._example = _example
937 self.__doc__ = ''
938
939 # Get the vtk class associated with this cell type. For simplicity, skip abstract types
940 # even though some actually do have a corresponding class. Among other things, skipping
941 # abstract types helps avoid the need to work around this VTK bug: https://gitlab.kitware.com/vtk/vtk/-/issues/19988
942 _vtk_class_name = _vtk.vtkCellTypeUtilities.GetClassNameFromTypeId(value)
943 if vtk_version_info < (9, 6, 0):
944 # Fix bug with older VTK where higher order Triangle/Quadrilateral are swapped
945 _vtk_class_name = {
946 'vtkBezierTriangle': 'vtkBezierQuadrilateral',
947 'vtkBezierQuadrilateral': 'vtkBezierTriangle',
948 'vtkLagrangeTriangle': 'vtkLagrangeQuadrilateral',
949 'vtkLagrangeQuadrilateral': 'vtkLagrangeTriangle',
950 }.get(_vtk_class_name, _vtk_class_name)
951 self._vtk_class = (
952 None
953 if _vtk_class_name.startswith(('vtkParametric', 'vtkHigherOrder')) # Abstract
954 or _vtk_class_name in ('vtkLagrangePyramid', 'vtkBezierPyramid') # Missing vtk class
955 or _vtk_class_name == 'UnknownClass' # Abstract/missing classes in vtk 9.7.0
956 else getattr(_vtk, _vtk_class_name)
957 )
958
959 # Set cell type properties using vtkCellTypeUtilities. For abstract
960 # types whose value is in ``_ABSTRACT_DIMENSIONS`` we skip the call
961 # entirely (it returns 0 and emits warnings on vtk<9.4 because there
962 # is no concrete cell class). Unknown abstract types (e.g. anything
963 # vtk 9.7+ adds that we have not catalogued) still go through the
964 # utility.
965 if self._vtk_class is None and value in _ABSTRACT_DIMENSIONS:
966 self._dimension = _ABSTRACT_DIMENSIONS[value]
967 else:
968 self._dimension = cast('_Dimension', _vtk.vtkCellTypeUtilities.GetDimension(value))
969 self._is_linear = bool(_vtk.vtkCellTypeUtilities.IsLinear(value))
970 if value == _vtk.VTK_HEXAGONAL_PRISM:
971 # Need to fix https://gitlab.kitware.com/vtk/vtk/-/issues/19988#note_1786788
972 self._is_linear = True
973
974 # Set properties that require instantiating the class.
975 # Assume primary cell with -1 values for points/edges/faces for abstract classes
976 self._n_points = -1
977 self._n_edges = -1
978 self._n_faces = -1
979 self._is_composite = False
980 if self._vtk_class is not None:
981 cell = self._vtk_class()
982 self._is_composite = not bool(cell.IsPrimaryCell())
983
984 # Use -1 to denote the cell has variable points/edges/faces
985 self._n_points = -1 if _variable_points else cell.GetNumberOfPoints()
986 self._n_edges = -1 if _variable_edges else cell.GetNumberOfEdges()
987 self._n_faces = -1 if _variable_faces else cell.GetNumberOfFaces()
988
989 _doc = textwrap.dedent(_doc).strip()
990
991 # Generate cell type documentation if specified
992 if self._vtk_class or _doc or _example:
993 _badges = ''
994 if self._vtk_class:
995 _linear_badge = _generate_linear_badge(self._is_linear)
996 _composite_badge = _generate_composite_badge(self._is_composite)
997 _dimension_badge = _generate_dimension_badge(self._dimension)
998
999 _points = 'variable' if _variable_points else self._n_points
1000 _points_badge = _generate_points_badge(_points) # type: ignore[arg-type]
1001
1002 _edges = 'variable' if _variable_edges else self._n_edges
1003 _edges_badge = _generate_edges_badge(_edges) # type: ignore[arg-type]
1004
1005 _faces = 'variable' if _variable_faces else self._n_faces
1006 _faces_badge = _generate_faces_badge(_faces) # type: ignore[arg-type]
1007
1008 _badges = _indent_paragraph(
1009 f'{_linear_badge} {_composite_badge} {_dimension_badge}\n'
1010 f'{_points_badge} {_edges_badge} {_faces_badge}',
1011 level=2,
1012 )
1013
1014 # Add additional references to VTK docs
1015 _vtk_class_ref = f':vtk:`{self._vtk_class.__name__}`'
1016 _see_also = f'See also {_vtk_class_ref}.'
1017 _doc += f'\n\n{_see_also}'
1018
1019 _doc = _indent_paragraph(_doc, level=2)
1020
1021 self.__doc__ += (
1022 _GRID_TEMPLATE_NO_IMAGE.format(_badges, _doc)
1023 if (_example is None or _example == 'Empty')
1024 else _GRID_TEMPLATE_WITH_IMAGE.format(
1025 _example, _example, PLACEHOLDER, _badges, _doc
1026 )
1027 )
1028
1029 return self
1030
1031 @property
1032 def vtk_class(self) -> type[_vtk.vtkCell] | None: # numpydoc ignore=RT01
1033 """Return the :vtk:`vtkCell` class associated with this cell type.
1034
1035 Only concrete VTK classes that can instantiated are returned. ``None`` is returned
1036 if the cell type has no corresponding VTK class or if the class is abstract.
1037
1038 .. versionadded:: 0.48
1039
1040 See Also
1041 --------
1042 pyvista.Cell
1043
1044 Examples
1045 --------
1046 Get the VTK class associated with the :attr:`TRIANGLE` cell type.
1047
1048 >>> import pyvista as pv
1049 >>> pv.CellType.TRIANGLE.vtk_class
1050 <class 'vtkmodules.vtkCommonDataModel.vtkTriangle'>
1051
1052 Abstract cell types like ``HIGHER_ORDER_HEXAHEDRON`` return ``None``.
1053
1054 >>> pv.CellType.HIGHER_ORDER_HEXAHEDRON.vtk_class is None
1055 True
1056
1057 """
1058 return self._vtk_class
1059
1060 @property
1061 def dimension(self) -> _Dimension: # numpydoc ignore=RT01
1062 """Return this cell type's dimension.
1063
1064 .. versionadded:: 0.48
1065
1066 See Also
1067 --------
1068 pyvista.Cell.dimension
1069 dimension_map
1070
1071 Examples
1072 --------
1073 :attr:`VERTEX` is 0D.
1074
1075 >>> import pyvista as pv
1076 >>> pv.CellType.VERTEX.dimension
1077 0
1078
1079 :attr:`LINE` is 1D.
1080
1081 >>> pv.CellType.LINE.dimension
1082 1
1083
1084 :attr:`TRIANGLE` is 2D.
1085
1086 >>> pv.CellType.TRIANGLE.dimension
1087 2
1088
1089 :attr:`HEXAHEDRON` is 3D.
1090
1091 >>> pv.CellType.HEXAHEDRON.dimension
1092 3
1093
1094 """
1095 return self._dimension
1096
1097 @property
1098 def is_linear(self) -> bool: # numpydoc ignore=RT01
1099 """Return ``True`` if this cell type is linear.
1100
1101 .. versionadded:: 0.48
1102
1103 See Also
1104 --------
1105 is_composite
1106 pyvista.Cell.is_linear
1107
1108 Examples
1109 --------
1110 :attr:`HEXAHEDRON` is linear.
1111
1112 >>> import pyvista as pv
1113 >>> pv.CellType.HEXAHEDRON.is_linear
1114 True
1115
1116 :attr:`QUADRATIC_HEXAHEDRON` is not linear.
1117
1118 >>> pv.CellType.QUADRATIC_HEXAHEDRON.is_linear
1119 False
1120
1121 """
1122 return self._is_linear
1123
1124 @property
1125 def is_composite(self) -> bool: # numpydoc ignore=RT01
1126 """Return ``True`` if this cell type is composed of multiple smaller cells.
1127
1128 .. versionadded:: 0.48
1129
1130 See Also
1131 --------
1132 is_linear
1133
1134 Examples
1135 --------
1136 :attr:`VERTEX` is a primary cell and is not composite.
1137
1138 >>> import pyvista as pv
1139 >>> pv.CellType.VERTEX.is_composite
1140 False
1141
1142 :attr:`POLY_VERTEX` `is` composite since it's composed of multiple vertex cells.
1143
1144 >>> pv.CellType.POLY_VERTEX.is_composite
1145 True
1146
1147 """
1148 return self._is_composite
1149
1150 @property
1151 def n_points(self) -> int: # numpydoc ignore=RT01
1152 """Return the number of points defined by this cell type.
1153
1154 .. versionadded:: 0.48
1155
1156 See Also
1157 --------
1158 n_edges, n_faces
1159 pyvista.Cell.n_points
1160
1161 Raises
1162 ------
1163 ValueError
1164 If the number of points cannot be determined without a concrete instance.
1165 Composite cells, higher order cells, polygon, and polyhedron will all raise an error.
1166
1167 Examples
1168 --------
1169 :attr:`LINE` has a fixed number of points.
1170
1171 >>> import pyvista as pv
1172 >>> pv.CellType.LINE.n_points
1173 2
1174
1175 :attr:`POLY_LINE` has a variable number of points and raises a ValueError.
1176
1177 >>> try:
1178 ... pv.CellType.POLY_LINE.n_points
1179 ... except ValueError as error:
1180 ... print(error)
1181 Cannot determine number of points for 'POLY_LINE' without a concrete cell instance.
1182
1183 """
1184 if (n_points := self._n_points) == -1:
1185 msg = (
1186 f'Cannot determine number of points for {self.name!r} '
1187 f'without a concrete cell instance.'
1188 )
1189 raise ValueError(msg)
1190 return n_points
1191
1192 @property
1193 def n_edges(self) -> int: # numpydoc ignore=RT01
1194 """Return the number of edges defined by this cell type.
1195
1196 .. versionadded:: 0.48
1197
1198 See Also
1199 --------
1200 n_points, n_faces
1201 pyvista.Cell.n_edges
1202
1203 Raises
1204 ------
1205 ValueError
1206 If the number of edges cannot be determined without a concrete instance.
1207 Polygon, polyhedron, triangle strip, and convex point set will all raise an error.
1208
1209 Examples
1210 --------
1211 :attr:`QUAD` has a fixed number of edges.
1212
1213 >>> import pyvista as pv
1214 >>> pv.CellType.QUAD.n_edges
1215 4
1216
1217 :attr:`POLYGON` has a variable number of edges and raises a ValueError.
1218
1219 >>> try:
1220 ... pv.CellType.POLYGON.n_edges
1221 ... except ValueError as error:
1222 ... print(error)
1223 Cannot determine number of edges for 'POLYGON' without a concrete cell instance.
1224
1225 Zero- and one-dimensional cell types have no edges.
1226
1227 >>> pv.CellType.VERTEX.n_edges
1228 0
1229
1230 >>> pv.CellType.LINE.n_edges
1231 0
1232
1233 """
1234 if (n_edges := self._n_edges) == -1:
1235 msg = (
1236 f'Cannot determine number of edges for {self.name!r} '
1237 f'without a concrete cell instance.'
1238 )
1239 raise ValueError(msg)
1240 return n_edges
1241
1242 @property
1243 def n_faces(self) -> int: # numpydoc ignore=RT01
1244 """Return the number of faces defined by this cell type.
1245
1246 .. versionadded:: 0.48
1247
1248 See Also
1249 --------
1250 n_points, n_edges
1251 pyvista.Cell.n_faces
1252
1253 Raises
1254 ------
1255 ValueError
1256 If the number of faces cannot be determined without a concrete instance.
1257 Polyhedron and convex point set will raise an error.
1258
1259 Examples
1260 --------
1261 :attr:`WEDGE` has a fixed number of faces.
1262
1263 >>> import pyvista as pv
1264 >>> pv.CellType.WEDGE.n_faces
1265 5
1266
1267 :attr:`POLYHEDRON` has a variable number of faces and raises a ValueError.
1268
1269 >>> try:
1270 ... pv.CellType.POLYHEDRON.n_faces
1271 ... except ValueError as error:
1272 ... print(error)
1273 Cannot determine number of faces for 'POLYHEDRON' without a concrete cell instance.
1274
1275 Only three-dimensional cell types have faces.
1276
1277 >>> pv.CellType.LINE.n_faces
1278 0
1279
1280 >>> pv.CellType.QUAD.n_faces
1281 0
1282
1283 """
1284 if (n_faces := self._n_faces) == -1:
1285 msg = (
1286 f'Cannot determine number of faces for {self.name!r} '
1287 f'without a concrete cell instance.'
1288 )
1289 raise ValueError(msg)
1290 return n_faces
1291
1292 EMPTY_CELL = _CELL_TYPE_INFO['EMPTY_CELL']
1293 VERTEX = _CELL_TYPE_INFO['VERTEX']
1294 POLY_VERTEX = _CELL_TYPE_INFO['POLY_VERTEX']
1295 LINE = _CELL_TYPE_INFO['LINE']
1296 POLY_LINE = _CELL_TYPE_INFO['POLY_LINE']
1297 TRIANGLE = _CELL_TYPE_INFO['TRIANGLE']
1298 TRIANGLE_STRIP = _CELL_TYPE_INFO['TRIANGLE_STRIP']
1299 POLYGON = _CELL_TYPE_INFO['POLYGON']
1300 PIXEL = _CELL_TYPE_INFO['PIXEL']
1301 QUAD = _CELL_TYPE_INFO['QUAD']
1302 TETRA = _CELL_TYPE_INFO['TETRA']
1303 VOXEL = _CELL_TYPE_INFO['VOXEL']
1304 HEXAHEDRON = _CELL_TYPE_INFO['HEXAHEDRON']
1305 WEDGE = _CELL_TYPE_INFO['WEDGE']
1306 PYRAMID = _CELL_TYPE_INFO['PYRAMID']
1307 PENTAGONAL_PRISM = _CELL_TYPE_INFO['PENTAGONAL_PRISM']
1308 HEXAGONAL_PRISM = _CELL_TYPE_INFO['HEXAGONAL_PRISM']
1309 QUADRATIC_EDGE = _CELL_TYPE_INFO['QUADRATIC_EDGE']
1310 QUADRATIC_TRIANGLE = _CELL_TYPE_INFO['QUADRATIC_TRIANGLE']
1311 QUADRATIC_QUAD = _CELL_TYPE_INFO['QUADRATIC_QUAD']
1312 QUADRATIC_POLYGON = _CELL_TYPE_INFO['QUADRATIC_POLYGON']
1313 QUADRATIC_TETRA = _CELL_TYPE_INFO['QUADRATIC_TETRA']
1314 QUADRATIC_HEXAHEDRON = _CELL_TYPE_INFO['QUADRATIC_HEXAHEDRON']
1315 QUADRATIC_WEDGE = _CELL_TYPE_INFO['QUADRATIC_WEDGE']
1316 QUADRATIC_PYRAMID = _CELL_TYPE_INFO['QUADRATIC_PYRAMID']
1317 BIQUADRATIC_QUAD = _CELL_TYPE_INFO['BIQUADRATIC_QUAD']
1318 TRIQUADRATIC_HEXAHEDRON = _CELL_TYPE_INFO['TRIQUADRATIC_HEXAHEDRON']
1319 TRIQUADRATIC_PYRAMID = _CELL_TYPE_INFO['TRIQUADRATIC_PYRAMID']
1320 QUADRATIC_LINEAR_QUAD = _CELL_TYPE_INFO['QUADRATIC_LINEAR_QUAD']
1321 QUADRATIC_LINEAR_WEDGE = _CELL_TYPE_INFO['QUADRATIC_LINEAR_WEDGE']
1322 BIQUADRATIC_QUADRATIC_WEDGE = _CELL_TYPE_INFO['BIQUADRATIC_QUADRATIC_WEDGE']
1323 BIQUADRATIC_QUADRATIC_HEXAHEDRON = _CELL_TYPE_INFO['BIQUADRATIC_QUADRATIC_HEXAHEDRON']
1324 BIQUADRATIC_TRIANGLE = _CELL_TYPE_INFO['BIQUADRATIC_TRIANGLE']
1325 CUBIC_LINE = _CELL_TYPE_INFO['CUBIC_LINE']
1326 CONVEX_POINT_SET = _CELL_TYPE_INFO['CONVEX_POINT_SET']
1327 POLYHEDRON = _CELL_TYPE_INFO['POLYHEDRON']
1328 PARAMETRIC_CURVE = _CELL_TYPE_INFO['PARAMETRIC_CURVE']
1329 PARAMETRIC_SURFACE = _CELL_TYPE_INFO['PARAMETRIC_SURFACE']
1330 PARAMETRIC_TRI_SURFACE = _CELL_TYPE_INFO['PARAMETRIC_TRI_SURFACE']
1331 PARAMETRIC_QUAD_SURFACE = _CELL_TYPE_INFO['PARAMETRIC_QUAD_SURFACE']
1332 PARAMETRIC_TETRA_REGION = _CELL_TYPE_INFO['PARAMETRIC_TETRA_REGION']
1333 PARAMETRIC_HEX_REGION = _CELL_TYPE_INFO['PARAMETRIC_HEX_REGION']
1334 HIGHER_ORDER_EDGE = _CELL_TYPE_INFO['HIGHER_ORDER_EDGE']
1335 HIGHER_ORDER_TRIANGLE = _CELL_TYPE_INFO['HIGHER_ORDER_TRIANGLE']
1336 HIGHER_ORDER_QUAD = _CELL_TYPE_INFO['HIGHER_ORDER_QUAD']
1337 HIGHER_ORDER_POLYGON = _CELL_TYPE_INFO['HIGHER_ORDER_POLYGON']
1338 HIGHER_ORDER_TETRAHEDRON = _CELL_TYPE_INFO['HIGHER_ORDER_TETRAHEDRON']
1339 HIGHER_ORDER_WEDGE = _CELL_TYPE_INFO['HIGHER_ORDER_WEDGE']
1340 HIGHER_ORDER_PYRAMID = _CELL_TYPE_INFO['HIGHER_ORDER_PYRAMID']
1341 HIGHER_ORDER_HEXAHEDRON = _CELL_TYPE_INFO['HIGHER_ORDER_HEXAHEDRON']
1342 LAGRANGE_CURVE = _CELL_TYPE_INFO['LAGRANGE_CURVE']
1343 LAGRANGE_TRIANGLE = _CELL_TYPE_INFO['LAGRANGE_TRIANGLE']
1344 LAGRANGE_QUADRILATERAL = _CELL_TYPE_INFO['LAGRANGE_QUADRILATERAL']
1345 LAGRANGE_TETRAHEDRON = _CELL_TYPE_INFO['LAGRANGE_TETRAHEDRON']
1346 LAGRANGE_HEXAHEDRON = _CELL_TYPE_INFO['LAGRANGE_HEXAHEDRON']
1347 LAGRANGE_WEDGE = _CELL_TYPE_INFO['LAGRANGE_WEDGE']
1348 LAGRANGE_PYRAMID = _CELL_TYPE_INFO['LAGRANGE_PYRAMID']
1349 BEZIER_CURVE = _CELL_TYPE_INFO['BEZIER_CURVE']
1350 BEZIER_TRIANGLE = _CELL_TYPE_INFO['BEZIER_TRIANGLE']
1351 BEZIER_QUADRILATERAL = _CELL_TYPE_INFO['BEZIER_QUADRILATERAL']
1352 BEZIER_TETRAHEDRON = _CELL_TYPE_INFO['BEZIER_TETRAHEDRON']
1353 BEZIER_HEXAHEDRON = _CELL_TYPE_INFO['BEZIER_HEXAHEDRON']
1354 BEZIER_WEDGE = _CELL_TYPE_INFO['BEZIER_WEDGE']
1355 BEZIER_PYRAMID = _CELL_TYPE_INFO['BEZIER_PYRAMID']