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.io.euclidean.threed;
    18
    19  import java.util.Collections;
    20  import java.util.List;
    21
    22  import org.apache.commons.geometry.io.core.GeometryFormat;
    23
    24  /** Enum containing 3D geometry formats supported internally by Apache Commons Geometry.
    25   */
    26  public enum GeometryFormat3D implements GeometryFormat {
    27
    28      /** Value representing the OBJ file format.
    29       * @see <a href="https://en.wikipedia.org/wiki/Wavefront_.obj_file">Wavefront .obj file</a>
    30       */
    31      OBJ("obj"),
    32
    33      /** Value representing the STL file format in both the text (i.e. "ASCII") and binary forms.
    34       * @see <a href="https://en.wikipedia.org/wiki/STL_(file_format)">STL</a>
    35       */
    36      STL("stl"),
    37
    38      /** Value representing a simple, <em>non-standard</em> text geometry format that defines facets one per line
    39       * by listing the coordinates of the facet vertices in order, separated by non-numeric characters (e.g. whitespace,
    40       * commas, semicolons, etc). Each line follows the pattern
    41       * <p>
    42       * <code>
    43       *      p1<sub>x</sub> p1<sub>y</sub> p1<sub>z</sub> p2<sub>x</sub> p2<sub>y</sub> p2<sub>z</sub> p3<sub>x</sub> p3<sub>y</sub> p3<sub>z</sub> ...
    44       * </code>
    45       * </p>
    46       * <p>where the <em>p1</em> elements contain the coordinates of the first facet vertex,
    47       * <em>p2</em> those of the second, and so on. Facets may have 3 or more vertices and do not need to all have
    48       * the same number of vertices.
    49       *
    50       * <p>This format is non-standard and no guarantees are made regarding its compatibility with other systems.
    51       * It is intended primarily to provide a convenient, human-readable format for data input and analysis.</p>
    52       * @see org.apache.commons.geometry.io.euclidean.threed.txt.TextFacetDefinitionReader
    53       * @see org.apache.commons.geometry.io.euclidean.threed.txt.TextFacetDefinitionWriter
    54       */
    55      TXT("txt"),
    56
    57      /** Value representing a simple, <em>non-standard</em> CSV geometry format that defines triangular facets
    58       * one per line by listing the facet vertex coordinates in order, separated by commas. This format is a subset
    59       * of the {@link #TXT} format with commas as separators and facets written as triangles (to ensure that
    60       * all rows have the same number of columns).
    61       *
    62       * <p>This format is non-standard and no guarantees are made regarding its compatibility with other systems.
    63       * It is intended primarily to provide a convenient, human-readable format for data input and analysis.</p>
    64       * @see org.apache.commons.geometry.io.euclidean.threed.txt.TextFacetDefinitionWriter#csvFormat(java.io.Writer)
    65       */
    66      CSV("csv");
    67
    68      /** List of file extensions associated with the format. The first file extension
    69       * listed is taken as the default.
    70       */
    71      private final List<String> fileExtensions;
    72
    73      /** Construct a new instance with the given file extension.
    74       * @param fileExt file extension
    75       */
    76      GeometryFormat3D(final String fileExt) {
    77          this.fileExtensions = Collections.singletonList(fileExt);
    78      }
    79
    80      /** {@inheritDoc} */
    81      @Override
    82      public String getFormatName() {
    83          return name();
    84      }
    85
    86      /** {@inheritDoc} */
    87      @Override
    88      public String getDefaultFileExtension() {
    89          return fileExtensions.get(0);
    90      }
    91
    92      /** {@inheritDoc} */
    93      @Override
    94      public List<String> getFileExtensions() {
    95          return fileExtensions;
    96      }
    97  }