TextBoundaryWriteHandler3D.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.txt;

  18. import org.apache.commons.geometry.io.core.GeometryFormat;
  19. import org.apache.commons.geometry.io.core.output.GeometryOutput;
  20. import org.apache.commons.geometry.io.euclidean.threed.GeometryFormat3D;

  21. /** {@link org.apache.commons.geometry.io.euclidean.threed.BoundaryWriteHandler3D BoundaryWriteHandler3D}
  22.  * implementation for the non-standard {@link GeometryFormat3D#TXT TXT} format. Output is
  23.  * written using the UTF-8 charset by default.
  24.  * @see org.apache.commons.geometry.io.euclidean.threed.BoundaryWriteHandler3D
  25.  * @see TextFacetDefinitionWriter
  26.  */
  27. public class TextBoundaryWriteHandler3D extends AbstractTextBoundaryWriteHandler3D {

  28.     /** String used to separate vertex components, ie, x, y, z values. */
  29.     private String vertexComponentSeparator = TextFacetDefinitionWriter.DEFAULT_VERTEX_COMPONENT_SEPARATOR;

  30.     /** String used to separate vertices. */
  31.     private String vertexSeparator = TextFacetDefinitionWriter.DEFAULT_VERTEX_SEPARATOR;

  32.     /** Number of vertices required per facet; will be -1 if disabled. */
  33.     private int facetVertexCount = TextFacetDefinitionWriter.DEFAULT_FACET_VERTEX_COUNT;

  34.     /** Get the string used to separate vertex components (ie, individual x, y, z values).
  35.      * @return string used to separate vertex components
  36.      * @see TextFacetDefinitionWriter#getVertexComponentSeparator()
  37.      */
  38.     public String getVertexComponentSeparator() {
  39.         return vertexComponentSeparator;
  40.     }

  41.     /** Set the string used to separate vertex components (ie, individual x, y, z values).
  42.      * @param sep string used to separate vertex components
  43.      * @see TextFacetDefinitionWriter#setVertexComponentSeparator(String)
  44.      */
  45.     public void setVertexComponentSeparator(final String sep) {
  46.         this.vertexComponentSeparator = sep;
  47.     }

  48.     /** Get the string used to separate facet vertices.
  49.      * @return string used to separate facet vertices
  50.      * @see TextFacetDefinitionWriter#getVertexSeparator()
  51.      */
  52.     public String getVertexSeparator() {
  53.         return vertexSeparator;
  54.     }

  55.     /** Set the string used to separate facet vertices.
  56.      * @param sep string used to separate facet vertices
  57.      * @see TextFacetDefinitionWriter#setVertexSeparator(String)
  58.      */
  59.     public void setVertexSeparator(final String sep) {
  60.         this.vertexSeparator = sep;
  61.     }

  62.     /** Get the number of vertices required per facet or {@code -1} if no specific
  63.      * number is required.
  64.      * @return the number of vertices required per facet or {@code -1} if any geometricallly
  65.      *      valid number is allowed (ie, any number greater than or equal to 3)
  66.      * @see TextFacetDefinitionWriter#getFacetVertexCount()
  67.      */
  68.     public int getFacetVertexCount() {
  69.         return facetVertexCount;
  70.     }

  71.     /** Set the number of vertices required per facet. This can be used to enforce a consistent
  72.      * format in the output. Set to {@code -1} to allow any geometrically valid number of vertices
  73.      * (ie, any number greater than or equal to 3).
  74.      * @param vertexCount number of vertices required per facet or {@code -1} to allow any number
  75.      * @see TextFacetDefinitionWriter#setFacetVertexCount(int)
  76.      */
  77.     public void setFacetVertexCount(final int vertexCount) {
  78.         this.facetVertexCount = vertexCount;
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public GeometryFormat getFormat() {
  83.         return GeometryFormat3D.TXT;
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     protected TextFacetDefinitionWriter getFacetDefinitionWriter(final GeometryOutput out) {
  88.         final TextFacetDefinitionWriter facetWriter = super.getFacetDefinitionWriter(out);

  89.         facetWriter.setVertexComponentSeparator(vertexComponentSeparator);
  90.         facetWriter.setVertexSeparator(vertexSeparator);
  91.         facetWriter.setFacetVertexCount(facetVertexCount);

  92.         return facetWriter;
  93.     }
  94. }