BSPTreeVisitor.java

  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.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */
  21. package org.hipparchus.geometry.partitioning;

  22. import org.hipparchus.geometry.Point;
  23. import org.hipparchus.geometry.Space;

  24. /** This interface is used to visit {@link BSPTree BSP tree} nodes.

  25.  * <p>Navigation through {@link BSPTree BSP trees} can be done using
  26.  * two different point of views:</p>
  27.  * <ul>
  28.  *   <li>
  29.  *     the first one is in a node-oriented way using the {@link
  30.  *     BSPTree#getPlus}, {@link BSPTree#getMinus} and {@link
  31.  *     BSPTree#getParent} methods. Terminal nodes without associated
  32.  *     {@link SubHyperplane sub-hyperplanes} can be visited this way,
  33.  *     there is no constraint in the visit order, and it is possible
  34.  *     to visit either all nodes or only a subset of the nodes
  35.  *   </li>
  36.  *   <li>
  37.  *     the second one is in a sub-hyperplane-oriented way using
  38.  *     classes implementing this interface which obeys the visitor
  39.  *     design pattern. The visit order is provided by the visitor as
  40.  *     each node is first encountered. Each node is visited exactly
  41.  *     once.
  42.  *   </li>
  43.  * </ul>

  44.  * @param <S> Type of the space.
  45.  * @param <P> Type of the points in space.
  46.  * @param <H> Type of the hyperplane.
  47.  * @param <I> Type of the sub-hyperplane.

  48.  * @see BSPTree
  49.  * @see SubHyperplane

  50.  */
  51. 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>> {

  52.     /** Enumerate for visit order with respect to plus sub-tree, minus sub-tree and cut sub-hyperplane. */
  53.     enum Order {
  54.         /** Indicator for visit order plus sub-tree, then minus sub-tree,
  55.          * and last cut sub-hyperplane.
  56.          */
  57.         PLUS_MINUS_SUB,

  58.         /** Indicator for visit order plus sub-tree, then cut sub-hyperplane,
  59.          * and last minus sub-tree.
  60.          */
  61.         PLUS_SUB_MINUS,

  62.         /** Indicator for visit order minus sub-tree, then plus sub-tree,
  63.          * and last cut sub-hyperplane.
  64.          */
  65.         MINUS_PLUS_SUB,

  66.         /** Indicator for visit order minus sub-tree, then cut sub-hyperplane,
  67.          * and last plus sub-tree.
  68.          */
  69.         MINUS_SUB_PLUS,

  70.         /** Indicator for visit order cut sub-hyperplane, then plus sub-tree,
  71.          * and last minus sub-tree.
  72.          */
  73.         SUB_PLUS_MINUS,

  74.         /** Indicator for visit order cut sub-hyperplane, then minus sub-tree,
  75.          * and last plus sub-tree.
  76.          */
  77.         SUB_MINUS_PLUS
  78.     }

  79.     /** Determine the visit order for this node.
  80.      * <p>Before attempting to visit an internal node, this method is
  81.      * called to determine the desired ordering of the visit. It is
  82.      * guaranteed that this method will be called before {@link
  83.      * #visitInternalNode visitInternalNode} for a given node, it will be
  84.      * called exactly once for each internal node.</p>
  85.      * @param node BSP node guaranteed to have a non-null cut sub-hyperplane
  86.      * @return desired visit order, must be one of
  87.      * {@link Order#PLUS_MINUS_SUB}, {@link Order#PLUS_SUB_MINUS},
  88.      * {@link Order#MINUS_PLUS_SUB}, {@link Order#MINUS_SUB_PLUS},
  89.      * {@link Order#SUB_PLUS_MINUS}, {@link Order#SUB_MINUS_PLUS}
  90.      */
  91.     Order visitOrder(BSPTree<S, P, H, I> node);

  92.     /** Visit a BSP tree node having a non-null sub-hyperplane.
  93.      * <p>It is guaranteed that this method will be called after {@link
  94.      * #visitOrder visitOrder} has been called for a given node,
  95.      * it wil be called exactly once for each internal node.</p>
  96.      * @param node BSP node guaranteed to have a non-null cut sub-hyperplane
  97.      * @see #visitLeafNode
  98.      */
  99.     void visitInternalNode(BSPTree<S, P, H, I> node);

  100.     /** Visit a leaf BSP tree node node having a null sub-hyperplane.
  101.      * @param node leaf BSP node having a null sub-hyperplane
  102.      * @see #visitInternalNode
  103.      */
  104.     void visitLeafNode(BSPTree<S, P, H, I> node);

  105. }