001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.geometry.io.euclidean.threed;
018
019import java.util.Collections;
020import java.util.List;
021
022import org.apache.commons.geometry.io.core.GeometryFormat;
023
024/** Enum containing 3D geometry formats supported internally by Apache Commons Geometry.
025 */
026public enum GeometryFormat3D implements GeometryFormat {
027
028    /** Value representing the OBJ file format.
029     * @see <a href="https://en.wikipedia.org/wiki/Wavefront_.obj_file">Wavefront .obj file</a>
030     */
031    OBJ("obj"),
032
033    /** Value representing the STL file format in both the text (i.e. "ASCII") and binary forms.
034     * @see <a href="https://en.wikipedia.org/wiki/STL_(file_format)">STL</a>
035     */
036    STL("stl"),
037
038    /** Value representing a simple, <em>non-standard</em> text geometry format that defines facets one per line
039     * by listing the coordinates of the facet vertices in order, separated by non-numeric characters (e.g. whitespace,
040     * commas, semicolons, etc). Each line follows the pattern
041     * <p>
042     * <code>
043     *      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> ...
044     * </code>
045     * </p>
046     * <p>where the <em>p1</em> elements contain the coordinates of the first facet vertex,
047     * <em>p2</em> those of the second, and so on. Facets may have 3 or more vertices and do not need to all have
048     * the same number of vertices.
049     *
050     * <p>This format is non-standard and no guarantees are made regarding its compatibility with other systems.
051     * It is intended primarily to provide a convenient, human-readable format for data input and analysis.</p>
052     * @see org.apache.commons.geometry.io.euclidean.threed.txt.TextFacetDefinitionReader
053     * @see org.apache.commons.geometry.io.euclidean.threed.txt.TextFacetDefinitionWriter
054     */
055    TXT("txt"),
056
057    /** Value representing a simple, <em>non-standard</em> CSV geometry format that defines triangular facets
058     * one per line by listing the facet vertex coordinates in order, separated by commas. This format is a subset
059     * of the {@link #TXT} format with commas as separators and facets written as triangles (to ensure that
060     * all rows have the same number of columns).
061     *
062     * <p>This format is non-standard and no guarantees are made regarding its compatibility with other systems.
063     * It is intended primarily to provide a convenient, human-readable format for data input and analysis.</p>
064     * @see org.apache.commons.geometry.io.euclidean.threed.txt.TextFacetDefinitionWriter#csvFormat(java.io.Writer)
065     */
066    CSV("csv");
067
068    /** List of file extensions associated with the format. The first file extension
069     * listed is taken as the default.
070     */
071    private final List<String> fileExtensions;
072
073    /** Construct a new instance with the given file extension.
074     * @param fileExt file extension
075     */
076    GeometryFormat3D(final String fileExt) {
077        this.fileExtensions = Collections.singletonList(fileExt);
078    }
079
080    /** {@inheritDoc} */
081    @Override
082    public String getFormatName() {
083        return name();
084    }
085
086    /** {@inheritDoc} */
087    @Override
088    public String getDefaultFileExtension() {
089        return fileExtensions.get(0);
090    }
091
092    /** {@inheritDoc} */
093    @Override
094    public List<String> getFileExtensions() {
095        return fileExtensions;
096    }
097}