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.txt; 018 019import org.apache.commons.geometry.io.core.GeometryFormat; 020import org.apache.commons.geometry.io.core.output.GeometryOutput; 021import org.apache.commons.geometry.io.euclidean.threed.GeometryFormat3D; 022 023/** {@link org.apache.commons.geometry.io.euclidean.threed.BoundaryWriteHandler3D BoundaryWriteHandler3D} 024 * implementation for the non-standard {@link GeometryFormat3D#TXT TXT} format. Output is 025 * written using the UTF-8 charset by default. 026 * @see org.apache.commons.geometry.io.euclidean.threed.BoundaryWriteHandler3D 027 * @see TextFacetDefinitionWriter 028 */ 029public class TextBoundaryWriteHandler3D extends AbstractTextBoundaryWriteHandler3D { 030 031 /** String used to separate vertex components, ie, x, y, z values. */ 032 private String vertexComponentSeparator = TextFacetDefinitionWriter.DEFAULT_VERTEX_COMPONENT_SEPARATOR; 033 034 /** String used to separate vertices. */ 035 private String vertexSeparator = TextFacetDefinitionWriter.DEFAULT_VERTEX_SEPARATOR; 036 037 /** Number of vertices required per facet; will be -1 if disabled. */ 038 private int facetVertexCount = TextFacetDefinitionWriter.DEFAULT_FACET_VERTEX_COUNT; 039 040 /** Get the string used to separate vertex components (ie, individual x, y, z values). 041 * @return string used to separate vertex components 042 * @see TextFacetDefinitionWriter#getVertexComponentSeparator() 043 */ 044 public String getVertexComponentSeparator() { 045 return vertexComponentSeparator; 046 } 047 048 /** Set the string used to separate vertex components (ie, individual x, y, z values). 049 * @param sep string used to separate vertex components 050 * @see TextFacetDefinitionWriter#setVertexComponentSeparator(String) 051 */ 052 public void setVertexComponentSeparator(final String sep) { 053 this.vertexComponentSeparator = sep; 054 } 055 056 /** Get the string used to separate facet vertices. 057 * @return string used to separate facet vertices 058 * @see TextFacetDefinitionWriter#getVertexSeparator() 059 */ 060 public String getVertexSeparator() { 061 return vertexSeparator; 062 } 063 064 /** Set the string used to separate facet vertices. 065 * @param sep string used to separate facet vertices 066 * @see TextFacetDefinitionWriter#setVertexSeparator(String) 067 */ 068 public void setVertexSeparator(final String sep) { 069 this.vertexSeparator = sep; 070 } 071 072 /** Get the number of vertices required per facet or {@code -1} if no specific 073 * number is required. 074 * @return the number of vertices required per facet or {@code -1} if any geometricallly 075 * valid number is allowed (ie, any number greater than or equal to 3) 076 * @see TextFacetDefinitionWriter#getFacetVertexCount() 077 */ 078 public int getFacetVertexCount() { 079 return facetVertexCount; 080 } 081 082 /** Set the number of vertices required per facet. This can be used to enforce a consistent 083 * format in the output. Set to {@code -1} to allow any geometrically valid number of vertices 084 * (ie, any number greater than or equal to 3). 085 * @param vertexCount number of vertices required per facet or {@code -1} to allow any number 086 * @see TextFacetDefinitionWriter#setFacetVertexCount(int) 087 */ 088 public void setFacetVertexCount(final int vertexCount) { 089 this.facetVertexCount = vertexCount; 090 } 091 092 /** {@inheritDoc} */ 093 @Override 094 public GeometryFormat getFormat() { 095 return GeometryFormat3D.TXT; 096 } 097 098 /** {@inheritDoc} */ 099 @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}