Class Sphere.SphereTreeApproximationBuilder
java.lang.Object
org.apache.commons.geometry.euclidean.threed.shape.Sphere.SphereTreeApproximationBuilder
- Enclosing class:
Sphere
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
FieldsModifier and TypeFieldDescriptionprivate static final int
Threshold used to determine when to stop inserting structural cuts and begin adding facets.private final Sphere
The sphere that an approximation is being created for.private final int
The number of triangular subdivisions to use. -
Constructor Summary
ConstructorsConstructorDescriptionSphereTreeApproximationBuilder
(Sphere sphere, int subdivisions) Construct a new builder for creating a BSP tree approximation of the given sphere. -
Method Summary
Modifier and TypeMethodDescription(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 Details
-
PARTITION_THRESHOLD
private static final int PARTITION_THRESHOLDThreshold used to determine when to stop inserting structural cuts and begin adding facets.- See Also:
-
sphere
The sphere that an approximation is being created for. -
subdivisions
private final int subdivisionsThe number of triangular subdivisions to use.
-
-
Constructor Details
-
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 Details
-
build
RegionBSPTree3D build()Build the sphere approximation BSP tree.- Returns:
- the sphere approximation BSP tree
- Throws:
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
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
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:
IllegalStateException
- if no portion of the cutter plane intersects the node
-