]> gerrit.simantics Code Review - simantics/3d.git/blob - vtk/src/vtk/CellType.java
84f983991f3a058550de0e47eb3c97d97ca60b2f
[simantics/3d.git] / vtk / src / vtk / CellType.java
1 package vtk;
2
3 /**
4  * Provide a mapping to VTK CellType enum
5  *
6  * @author sebastien jourdain - sebastien.jourdain@kitware.com
7  */
8 public enum CellType {
9
10     VERTEX(1, 1), //
11     POLY_VERTEX(2, -1), //
12     LINE(3, 2), //
13     POLY_LINE(4, -1), //
14     TRIANGLE(5, 3), //
15     TRIANGLE_STRIP(6, -1), //
16     POLYGON(7, -1), //
17     PIXEL(8, 4), //
18     QUAD(9, 4), //
19     TETRA(10, 4), //
20     VOXEL(11, 8), //
21     HEXAHEDRON(12, 8), //
22     WEDGE(13, 6), //
23     PYRAMID(14, 5), //
24     PENTAGONAL_PRISM(15, 10), //
25     HEXAGONAL_PRISM(16, 12), //
26     QUADRATRIC_EDGE(21, 3), //
27     QUADRATRIC_TRIANGLE(22, 6), //
28     QUADRATRIC_QUAD(23, 8), //
29     QUADRATRIC_TETRA(24, 10), //
30     QUADRATRIC_HEXAHEDRON(25, 20), //
31     QUADRATRIC_WEDGE(26, 15), //
32     QUADRATRIC_PYRAMID(27, 13);
33
34     private CellType(int id, int nbPoints) {
35         this.id = id;
36         this.nbPoints = nbPoints;
37     }
38
39     /**
40      * @return the id that VTK is using to identify it cell type.
41      */
42     public int GetId() {
43         return id;
44     }
45
46     /**
47      * @return the number of points that cell type own or -1 for cell that have
48      *         a dynamic number of points.
49      */
50     public int GetNumberOfPoints() {
51         return nbPoints;
52     }
53
54     /**
55      * @return true if the number of points can not be given by the cell type
56      */
57     public boolean IsDynamicNumberOfPoints() {
58         return nbPoints == -1;
59     }
60
61     /**
62      * @param vtkCellId
63      * @return an instance of CellType based on the vtk cell id.
64      */
65     public static CellType GetCellType(int vtkCellId) {
66         if (MAPPING == null) {
67             // build it lazyly
68             int max = 0;
69             for (CellType cellType : values()) {
70                 max = Math.max(max, cellType.GetId());
71             }
72             MAPPING = new CellType[max + 1];
73             for (CellType cellType : values()) {
74                 MAPPING[cellType.GetId()] = cellType;
75             }
76         }
77         return MAPPING[vtkCellId];
78     }
79
80     private int id;
81     private int nbPoints;
82     private static CellType[] MAPPING;
83 }