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
19 import org.apache.commons.geometry.io.core.GeometryFormat;
20 import org.apache.commons.geometry.io.core.output.GeometryOutput;
21 import org.apache.commons.geometry.io.euclidean.threed.GeometryFormat3D;
22
23 /** {@link org.apache.commons.geometry.io.euclidean.threed.BoundaryWriteHandler3D BoundaryWriteHandler3D}
24 * implementation for the non-standard {@link GeometryFormat3D#TXT TXT} format. Output is
25 * written using the UTF-8 charset by default.
26 * @see org.apache.commons.geometry.io.euclidean.threed.BoundaryWriteHandler3D
27 * @see TextFacetDefinitionWriter
28 */
29 public class TextBoundaryWriteHandler3D extends AbstractTextBoundaryWriteHandler3D {
30
31 /** String used to separate vertex components, ie, x, y, z values. */
32 private String vertexComponentSeparator = TextFacetDefinitionWriter.DEFAULT_VERTEX_COMPONENT_SEPARATOR;
33
34 /** String used to separate vertices. */
35 private String vertexSeparator = TextFacetDefinitionWriter.DEFAULT_VERTEX_SEPARATOR;
36
37 /** Number of vertices required per facet; will be -1 if disabled. */
38 private int facetVertexCount = TextFacetDefinitionWriter.DEFAULT_FACET_VERTEX_COUNT;
39
40 /** Get the string used to separate vertex components (ie, individual x, y, z values).
41 * @return string used to separate vertex components
42 * @see TextFacetDefinitionWriter#getVertexComponentSeparator()
43 */
44 public String getVertexComponentSeparator() {
45 return vertexComponentSeparator;
46 }
47
48 /** Set the string used to separate vertex components (ie, individual x, y, z values).
49 * @param sep string used to separate vertex components
50 * @see TextFacetDefinitionWriter#setVertexComponentSeparator(String)
51 */
52 public void setVertexComponentSeparator(final String sep) {
53 this.vertexComponentSeparator = sep;
54 }
55
56 /** Get the string used to separate facet vertices.
57 * @return string used to separate facet vertices
58 * @see TextFacetDefinitionWriter#getVertexSeparator()
59 */
60 public String getVertexSeparator() {
61 return vertexSeparator;
62 }
63
64 /** Set the string used to separate facet vertices.
65 * @param sep string used to separate facet vertices
66 * @see TextFacetDefinitionWriter#setVertexSeparator(String)
67 */
68 public void setVertexSeparator(final String sep) {
69 this.vertexSeparator = sep;
70 }
71
72 /** Get the number of vertices required per facet or {@code -1} if no specific
73 * number is required.
74 * @return the number of vertices required per facet or {@code -1} if any geometricallly
75 * valid number is allowed (ie, any number greater than or equal to 3)
76 * @see TextFacetDefinitionWriter#getFacetVertexCount()
77 */
78 public int getFacetVertexCount() {
79 return facetVertexCount;
80 }
81
82 /** Set the number of vertices required per facet. This can be used to enforce a consistent
83 * format in the output. Set to {@code -1} to allow any geometrically valid number of vertices
84 * (ie, any number greater than or equal to 3).
85 * @param vertexCount number of vertices required per facet or {@code -1} to allow any number
86 * @see TextFacetDefinitionWriter#setFacetVertexCount(int)
87 */
88 public void setFacetVertexCount(final int vertexCount) {
89 this.facetVertexCount = vertexCount;
90 }
91
92 /** {@inheritDoc} */
93 @Override
94 public GeometryFormat getFormat() {
95 return GeometryFormat3D.TXT;
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 protected TextFacetDefinitionWriter getFacetDefinitionWriter(final GeometryOutput out) {
101 final TextFacetDefinitionWriter facetWriter = super.getFacetDefinitionWriter(out);
102
103 facetWriter.setVertexComponentSeparator(vertexComponentSeparator);
104 facetWriter.setVertexSeparator(vertexSeparator);
105 facetWriter.setFacetVertexCount(facetVertexCount);
106
107 return facetWriter;
108 }
109 }