GeometryFormat3D.java

  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. import java.util.Collections;
  19. import java.util.List;

  20. import org.apache.commons.geometry.io.core.GeometryFormat;

  21. /** Enum containing 3D geometry formats supported internally by Apache Commons Geometry.
  22.  */
  23. public enum GeometryFormat3D implements GeometryFormat {

  24.     /** Value representing the OBJ file format.
  25.      * @see <a href="https://en.wikipedia.org/wiki/Wavefront_.obj_file">Wavefront .obj file</a>
  26.      */
  27.     OBJ("obj"),

  28.     /** Value representing the STL file format in both the text (i.e. "ASCII") and binary forms.
  29.      * @see <a href="https://en.wikipedia.org/wiki/STL_(file_format)">STL</a>
  30.      */
  31.     STL("stl"),

  32.     /** Value representing a simple, <em>non-standard</em> text geometry format that defines facets one per line
  33.      * by listing the coordinates of the facet vertices in order, separated by non-numeric characters (e.g. whitespace,
  34.      * commas, semicolons, etc). Each line follows the pattern
  35.      * <p>
  36.      * <code>
  37.      *      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> ...
  38.      * </code>
  39.      * </p>
  40.      * <p>where the <em>p1</em> elements contain the coordinates of the first facet vertex,
  41.      * <em>p2</em> those of the second, and so on. Facets may have 3 or more vertices and do not need to all have
  42.      * the same number of vertices.
  43.      *
  44.      * <p>This format is non-standard and no guarantees are made regarding its compatibility with other systems.
  45.      * It is intended primarily to provide a convenient, human-readable format for data input and analysis.</p>
  46.      * @see org.apache.commons.geometry.io.euclidean.threed.txt.TextFacetDefinitionReader
  47.      * @see org.apache.commons.geometry.io.euclidean.threed.txt.TextFacetDefinitionWriter
  48.      */
  49.     TXT("txt"),

  50.     /** Value representing a simple, <em>non-standard</em> CSV geometry format that defines triangular facets
  51.      * one per line by listing the facet vertex coordinates in order, separated by commas. This format is a subset
  52.      * of the {@link #TXT} format with commas as separators and facets written as triangles (to ensure that
  53.      * all rows have the same number of columns).
  54.      *
  55.      * <p>This format is non-standard and no guarantees are made regarding its compatibility with other systems.
  56.      * It is intended primarily to provide a convenient, human-readable format for data input and analysis.</p>
  57.      * @see org.apache.commons.geometry.io.euclidean.threed.txt.TextFacetDefinitionWriter#csvFormat(java.io.Writer)
  58.      */
  59.     CSV("csv");

  60.     /** List of file extensions associated with the format. The first file extension
  61.      * listed is taken as the default.
  62.      */
  63.     private final List<String> fileExtensions;

  64.     /** Construct a new instance with the given file extension.
  65.      * @param fileExt file extension
  66.      */
  67.     GeometryFormat3D(final String fileExt) {
  68.         this.fileExtensions = Collections.singletonList(fileExt);
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     public String getFormatName() {
  73.         return name();
  74.     }

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     public String getDefaultFileExtension() {
  78.         return fileExtensions.get(0);
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public List<String> getFileExtensions() {
  83.         return fileExtensions;
  84.     }
  85. }