View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.geometry.euclidean.threed.mesh;
18  
19  import java.util.List;
20  
21  import org.apache.commons.geometry.core.Transform;
22  import org.apache.commons.geometry.euclidean.threed.BoundarySource3D;
23  import org.apache.commons.geometry.euclidean.threed.ConvexPolygon3D;
24  import org.apache.commons.geometry.euclidean.threed.Vector3D;
25  
26  /** Interface representing a 3D mesh data structure.
27   * @param <F> Mesh face implementation type
28   * @see <a href="https://en.wikipedia.org/wiki/Polygon_mesh">Polygon Mesh</a>
29   */
30  public interface Mesh<F extends Mesh.Face> extends BoundarySource3D {
31  
32      /** Get an iterable containing the vertices in the mesh.
33       * @return an iterable containing the vertices in the mesh
34       */
35      Iterable<Vector3D> vertices();
36  
37      /** Get a list containing all vertices in the mesh.
38       * @return a list containing all vertices in the mesh
39       */
40      List<Vector3D> getVertices();
41  
42      /** Get the number of vertices in the mesh.
43       * @return the number of vertices in the mesh
44       */
45      int getVertexCount();
46  
47      /** Get an iterable containing all faces in the mesh.
48       * @return an iterable containing all faces in the mesh
49       */
50      Iterable<F> faces();
51  
52      /** Get a list containing all faces in the mesh.
53       * @return a list containing all faces in the mesh
54       */
55      List<F> getFaces();
56  
57      /** Get the number of faces in the mesh.
58       * @return the number of faces in the mesh
59       */
60      int getFaceCount();
61  
62      /** Get a face from the mesh by its index.
63       * @param index the index of the mesh to retrieve
64       * @return the face at the given index
65       * @throws IndexOutOfBoundsException if the index is out of bounds
66       */
67      F getFace(int index);
68  
69      /** Return a new, transformed mesh by applying the given transform to
70       * all vertices. Faces and vertex ordering are not affected.
71       * @param transform transform to apply
72       * @return a new, transformed mesh
73       */
74      Mesh<F> transform(Transform<Vector3D> transform);
75  
76      /** Interface representing a single face in a mesh.
77       */
78      interface Face {
79  
80          /** Get the 0-based index of the face in the mesh.
81           * @return the 0-based index of the face in the mesh
82           */
83          int getIndex();
84  
85          /** Get an array containing the 0-based indices of the vertices defining
86           * this face. The indices are references to the vertex positions in
87           * the mesh vertex list.
88           * @return an array containing the indices of the vertices defining
89           *      this face
90           * @see Mesh#getVertices()
91           */
92          int[] getVertexIndices();
93  
94          /** Get the vertices for the face.
95           * @return the vertices for the face
96           */
97          List<Vector3D> getVertices();
98  
99          /** Return true if the vertices for this face define a convex polygon
100          * with non-zero size.
101          * @return true if the vertices for this face define a convex polygon
102          *      with non-zero size
103          */
104         boolean definesPolygon();
105 
106         /** Get the 3D polygon defined by this face.
107          * @return the 3D polygon defined by this face
108          * @throws IllegalArgumentException if the vertices for the face do not
109          *      define a polygon
110          * @see #definesPolygon()
111          */
112         ConvexPolygon3D getPolygon();
113     }
114 }