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