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.stream.Stream; 020 021import org.apache.commons.geometry.euclidean.threed.BoundarySource3D; 022import org.apache.commons.geometry.euclidean.threed.PlaneConvexSubset; 023import org.apache.commons.geometry.euclidean.threed.mesh.TriangleMesh; 024import org.apache.commons.geometry.io.core.BoundaryReadHandler; 025import org.apache.commons.geometry.io.core.input.GeometryInput; 026import org.apache.commons.numbers.core.Precision; 027 028/** Basic interface for reading 3D geometric boundary representations 029 * (<a href="https://en.wikipedia.org/wiki/Boundary_representation">B-reps</a>) from a specific data storage 030 * format. This interface is primarily intended for use with {@link BoundaryIOManager3D}. 031 * 032 * <p><strong>Implementation note:</strong> implementations of this interface <em>must</em> 033 * be thread-safe.</p> 034 * 035 * @see <a href="https://en.wikipedia.org/wiki/Boundary_representations">Boundary representations</a> 036 * @see BoundaryWriteHandler3D 037 * @see BoundaryIOManager3D 038 */ 039public interface BoundaryReadHandler3D extends BoundaryReadHandler<PlaneConvexSubset, BoundarySource3D> { 040 041 /** Return a {@link FacetDefinitionReader} for reading raw 042 * {@link org.apache.commons.geometry.io.euclidean.threed.FacetDefinition facets} from the given 043 * input stream. 044 * @param in input stream to read from 045 * @return facet definition reader instance 046 * @throws IllegalStateException if a data format error occurs 047 * @throws java.io.UncheckedIOException if an I/O error occurs 048 */ 049 FacetDefinitionReader facetDefinitionReader(GeometryInput in); 050 051 /** Return a {@link Stream} that can be used to access all facet information from the given input stream. 052 * The input stream is expected to contain data in the format supported by this handler. 053 * 054 * <p>The underlying input stream is closed when the returned stream is closed. Callers should therefore 055 * use the returned stream in a try-with-resources statement to ensure that all resources are properly released. 056 * </p> 057 * <pre> 058 * try (Stream<FacetDefinition> stream = handler.facets(in)) { 059 * // access stream content 060 * } 061 * </pre> 062 * 063 * <p>The following exceptions may be thrown during stream iteration:</p> 064 * <ul> 065 * <li>{@link IllegalArgumentException} if mathematically invalid data is encountered</li> 066 * <li>{@link IllegalStateException} if a parsing or syntax error occurs</li> 067 * <li>{@link java.io.UncheckedIOException UncheckedIOException} if an I/O error occurs</li> 068 * </ul> 069 * @param in input stream to read from; this is <em>not</em> closed when the returned stream is closed 070 * @return stream providing access to the facet information from the given input stream 071 * @throws java.io.UncheckedIOException if an I/O error occurs during stream creation 072 */ 073 Stream<FacetDefinition> facets(GeometryInput in); 074 075 /** Read a triangle mesh from the given input. Implementations may throw runtime 076 * exceptions if mathematically invalid boundaries are encountered. 077 * @param in input stream to read from 078 * @param precision precision context used for floating point comparisons 079 * @return triangle mesh containing the data from the given input stream 080 * @throws IllegalStateException if a parsing or syntax error occurs 081 * @throws java.io.UncheckedIOException if an I/O error occurs 082 */ 083 TriangleMesh readTriangleMesh(GeometryInput in, Precision.DoubleEquivalence precision); 084}