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 * https://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 18 /* 19 * This is not the original file distributed by the Apache Software Foundation 20 * It has been modified by the Hipparchus project 21 */ 22 package org.hipparchus.geometry.partitioning; 23 24 import org.hipparchus.geometry.Point; 25 import org.hipparchus.geometry.Space; 26 27 /** This interface is used to visit {@link BSPTree BSP tree} nodes. 28 29 * <p>Navigation through {@link BSPTree BSP trees} can be done using 30 * two different point of views:</p> 31 * <ul> 32 * <li> 33 * the first one is in a node-oriented way using the {@link 34 * BSPTree#getPlus}, {@link BSPTree#getMinus} and {@link 35 * BSPTree#getParent} methods. Terminal nodes without associated 36 * {@link SubHyperplane sub-hyperplanes} can be visited this way, 37 * there is no constraint in the visit order, and it is possible 38 * to visit either all nodes or only a subset of the nodes 39 * </li> 40 * <li> 41 * the second one is in a sub-hyperplane-oriented way using 42 * classes implementing this interface which obeys the visitor 43 * design pattern. The visit order is provided by the visitor as 44 * each node is first encountered. Each node is visited exactly 45 * once. 46 * </li> 47 * </ul> 48 49 * @param <S> Type of the space. 50 * @param <P> Type of the points in space. 51 * @param <H> Type of the hyperplane. 52 * @param <I> Type of the sub-hyperplane. 53 54 * @see BSPTree 55 * @see SubHyperplane 56 57 */ 58 public interface BSPTreeVisitor<S extends Space, P extends Point<S, P>, H extends Hyperplane<S, P, H, I>, I extends SubHyperplane<S, P, H, I>> { 59 60 /** Enumerate for visit order with respect to plus sub-tree, minus sub-tree and cut sub-hyperplane. */ 61 enum Order { 62 /** Indicator for visit order plus sub-tree, then minus sub-tree, 63 * and last cut sub-hyperplane. 64 */ 65 PLUS_MINUS_SUB, 66 67 /** Indicator for visit order plus sub-tree, then cut sub-hyperplane, 68 * and last minus sub-tree. 69 */ 70 PLUS_SUB_MINUS, 71 72 /** Indicator for visit order minus sub-tree, then plus sub-tree, 73 * and last cut sub-hyperplane. 74 */ 75 MINUS_PLUS_SUB, 76 77 /** Indicator for visit order minus sub-tree, then cut sub-hyperplane, 78 * and last plus sub-tree. 79 */ 80 MINUS_SUB_PLUS, 81 82 /** Indicator for visit order cut sub-hyperplane, then plus sub-tree, 83 * and last minus sub-tree. 84 */ 85 SUB_PLUS_MINUS, 86 87 /** Indicator for visit order cut sub-hyperplane, then minus sub-tree, 88 * and last plus sub-tree. 89 */ 90 SUB_MINUS_PLUS 91 } 92 93 /** Determine the visit order for this node. 94 * <p>Before attempting to visit an internal node, this method is 95 * called to determine the desired ordering of the visit. It is 96 * guaranteed that this method will be called before {@link 97 * #visitInternalNode visitInternalNode} for a given node, it will be 98 * called exactly once for each internal node.</p> 99 * @param node BSP node guaranteed to have a non-null cut sub-hyperplane 100 * @return desired visit order, must be one of 101 * {@link Order#PLUS_MINUS_SUB}, {@link Order#PLUS_SUB_MINUS}, 102 * {@link Order#MINUS_PLUS_SUB}, {@link Order#MINUS_SUB_PLUS}, 103 * {@link Order#SUB_PLUS_MINUS}, {@link Order#SUB_MINUS_PLUS} 104 */ 105 Order visitOrder(BSPTree<S, P, H, I> node); 106 107 /** Visit a BSP tree node having a non-null sub-hyperplane. 108 * <p>It is guaranteed that this method will be called after {@link 109 * #visitOrder visitOrder} has been called for a given node, 110 * it wil be called exactly once for each internal node.</p> 111 * @param node BSP node guaranteed to have a non-null cut sub-hyperplane 112 * @see #visitLeafNode 113 */ 114 void visitInternalNode(BSPTree<S, P, H, I> node); 115 116 /** Visit a leaf BSP tree node node having a null sub-hyperplane. 117 * @param node leaf BSP node having a null sub-hyperplane 118 * @see #visitInternalNode 119 */ 120 void visitLeafNode(BSPTree<S, P, H, I> node); 121 122 }