Class Sphere.SphereTreeApproximationBuilder
- java.lang.Object
-
- org.apache.commons.geometry.euclidean.threed.shape.Sphere.SphereTreeApproximationBuilder
-
- Enclosing class:
- Sphere
private static final class Sphere.SphereTreeApproximationBuilder extends java.lang.Object
Internal class used to construct hyperplane-bounded approximations of spheres as BSP trees. The class begins with an octahedron inscribed in the sphere and then subdivides each triangular face a specified number of times.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
PARTITION_THRESHOLD
Threshold used to determine when to stop inserting structural cuts and begin adding facets.private Sphere
sphere
The sphere that an approximation is being created for.private int
subdivisions
The number of triangular subdivisions to use.
-
Constructor Summary
Constructors Constructor Description SphereTreeApproximationBuilder(Sphere sphere, int subdivisions)
Construct a new builder for creating a BSP tree approximation of the given sphere.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) RegionBSPTree3D
build()
Build the sphere approximation BSP tree.private void
checkedCut(RegionBSPTree3D.RegionNode3D node, Plane cutter, RegionCutRule cutRule)
Insert the cut into the given node, throwing an exception if no portion of the cutter intersects the node.private Plane
createPlane(Vector3D p1, Vector3D p2, Vector3D p3)
Create a plane from the given points, using the precision context of the sphere.private RegionBSPTree3D.RegionNode3D
insertSubdividedTriangles(RegionBSPTree3D.RegionNode3D node, Vector3D p1, Vector3D p2, Vector3D p3, int level)
Recursively insert subdivided triangles into the given node.private void
partitionAndInsert(RegionBSPTree3D.RegionNode3D node, Vector3D p1, Vector3D p2, Vector3D p3, int level)
Recursively insert structural BSP tree cuts into the given node and then insert subdivided triangles when a target subdivision level is reached.
-
-
-
Field Detail
-
PARTITION_THRESHOLD
private static final int PARTITION_THRESHOLD
Threshold used to determine when to stop inserting structural cuts and begin adding facets.- See Also:
- Constant Field Values
-
sphere
private final Sphere sphere
The sphere that an approximation is being created for.
-
subdivisions
private final int subdivisions
The number of triangular subdivisions to use.
-
-
Constructor Detail
-
SphereTreeApproximationBuilder
SphereTreeApproximationBuilder(Sphere sphere, int subdivisions)
Construct a new builder for creating a BSP tree approximation of the given sphere.- Parameters:
sphere
- the sphere to create an approximation ofsubdivisions
- the number of triangle subdivisions to use in tree creation
-
-
Method Detail
-
build
RegionBSPTree3D build()
Build the sphere approximation BSP tree.- Returns:
- the sphere approximation BSP tree
- Throws:
java.lang.IllegalStateException
- if tree creation fails for the configured subdivision count
-
partitionAndInsert
private void partitionAndInsert(RegionBSPTree3D.RegionNode3D node, Vector3D p1, Vector3D p2, Vector3D p3, int level)
Recursively insert structural BSP tree cuts into the given node and then insert subdivided triangles when a target subdivision level is reached. The structural BSP tree cuts are used to help reduce the overall depth of the BSP tree.- Parameters:
node
- the node to insert intop1
- first triangle pointp2
- second triangle pointp3
- third triangle pointlevel
- current subdivision level
-
insertSubdividedTriangles
private RegionBSPTree3D.RegionNode3D insertSubdividedTriangles(RegionBSPTree3D.RegionNode3D node, Vector3D p1, Vector3D p2, Vector3D p3, int level)
Recursively insert subdivided triangles into the given node. Each triangle is inserted into the minus side of the previous triangle.- Parameters:
node
- the node to insert intop1
- first triangle pointp2
- second triangle pointp3
- third triangle pointlevel
- the current subdivision level- Returns:
- the node representing the inside of the region after insertion of all triangles
-
createPlane
private Plane createPlane(Vector3D p1, Vector3D p2, Vector3D p3)
Create a plane from the given points, using the precision context of the sphere.- Parameters:
p1
- first pointp2
- second pointp3
- third point- Returns:
- a plane defined by the given points
-
checkedCut
private void checkedCut(RegionBSPTree3D.RegionNode3D node, Plane cutter, RegionCutRule cutRule)
Insert the cut into the given node, throwing an exception if no portion of the cutter intersects the node.- Parameters:
node
- node to cutcutter
- plane to use to cut the nodecutRule
- cut rule to apply- Throws:
java.lang.IllegalStateException
- if no portion of the cutter plane intersects the node
-
-