toxiclibs 0.2-java → 0.5.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +16 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE +675 -0
- data/README.md +12 -5
- data/Rakefile +25 -82
- data/examples/attract_repel/attract_repel.rb +30 -0
- data/examples/attract_repel/attractor.rb +23 -0
- data/examples/attract_repel/particle.rb +27 -0
- data/examples/data/ti_yong.png +0 -0
- data/examples/force_directed/cluster.rb +76 -0
- data/examples/force_directed/force_directed_graph.rb +92 -0
- data/examples/force_directed/node.rb +26 -0
- data/examples/gray_scott_image.rb +75 -0
- data/examples/gray_scott_tone_map.rb +77 -0
- data/examples/implicit.rb +139 -0
- data/examples/inflate_mesh.rb +89 -0
- data/examples/model_align.rb +44 -0
- data/examples/povmesh/ftest.rb +46 -0
- data/examples/povmesh/tentacle.rb +73 -0
- data/examples/simple_cluster/cluster.rb +47 -0
- data/examples/simple_cluster/node.rb +27 -0
- data/examples/simple_cluster/simple_cluster.rb +60 -0
- data/examples/soft_body/blanket.rb +45 -0
- data/examples/soft_body/connection.rb +16 -0
- data/examples/soft_body/particle.rb +22 -0
- data/examples/soft_body/soft_body_square_adapted.rb +55 -0
- data/lib/toxiclibs.jar +0 -0
- data/lib/toxiclibs.rb +91 -32
- data/lib/toxiclibs/version.rb +1 -1
- data/pom.xml +122 -0
- data/src/com/toxi/net/ClientListener.java +41 -0
- data/src/com/toxi/net/ServerListener.java +70 -0
- data/src/com/toxi/net/ServerListenerAdapter.java +47 -0
- data/src/com/toxi/net/ServerState.java +18 -0
- data/src/com/toxi/net/UDPConnection.java +66 -0
- data/src/com/toxi/net/UDPSyncClient.java +81 -0
- data/src/com/toxi/net/UDPSyncServer.java +450 -0
- data/src/com/toxi/nio/UDPClient.java +121 -0
- data/src/com/toxi/nio/UDPClientState.java +32 -0
- data/src/com/toxi/nio/UDPServer.java +129 -0
- data/src/toxi/color/AccessCriteria.java +114 -0
- data/src/toxi/color/AlphaAccessor.java +67 -0
- data/src/toxi/color/CMYKAccessor.java +122 -0
- data/src/toxi/color/CMYKDistanceProxy.java +40 -0
- data/src/toxi/color/ColorGradient.java +260 -0
- data/src/toxi/color/ColorList.java +699 -0
- data/src/toxi/color/ColorRange.java +671 -0
- data/src/toxi/color/ColorTheme.java +163 -0
- data/src/toxi/color/DistanceProxy.java +44 -0
- data/src/toxi/color/HSVAccessor.java +113 -0
- data/src/toxi/color/HSVDistanceProxy.java +40 -0
- data/src/toxi/color/HistEntry.java +85 -0
- data/src/toxi/color/Histogram.java +185 -0
- data/src/toxi/color/Hue.java +249 -0
- data/src/toxi/color/LuminanceAccessor.java +78 -0
- data/src/toxi/color/NamedColor.java +935 -0
- data/src/toxi/color/ProximityComparator.java +70 -0
- data/src/toxi/color/RGBAccessor.java +113 -0
- data/src/toxi/color/RGBDistanceProxy.java +41 -0
- data/src/toxi/color/ReadonlyTColor.java +296 -0
- data/src/toxi/color/TColor.java +1677 -0
- data/src/toxi/color/TColorAdapter.java +68 -0
- data/src/toxi/color/ToneMap.java +218 -0
- data/src/toxi/color/theory/AnalogousStrategy.java +140 -0
- data/src/toxi/color/theory/ColorTheoryRegistry.java +139 -0
- data/src/toxi/color/theory/ColorTheoryStrategy.java +56 -0
- data/src/toxi/color/theory/ComplementaryStrategy.java +111 -0
- data/src/toxi/color/theory/CompoundTheoryStrategy.java +143 -0
- data/src/toxi/color/theory/LeftSplitComplementaryStrategy.java +82 -0
- data/src/toxi/color/theory/MonochromeTheoryStrategy.java +103 -0
- data/src/toxi/color/theory/RightSplitComplementaryStrategy.java +82 -0
- data/src/toxi/color/theory/SingleComplementStrategy.java +76 -0
- data/src/toxi/color/theory/SplitComplementaryStrategy.java +77 -0
- data/src/toxi/color/theory/TetradTheoryStrategy.java +114 -0
- data/src/toxi/color/theory/TriadTheoryStrategy.java +77 -0
- data/src/toxi/data/csv/CSVAdapter.java +74 -0
- data/src/toxi/data/csv/CSVFieldMapper.java +212 -0
- data/src/toxi/data/csv/CSVListener.java +61 -0
- data/src/toxi/data/csv/CSVParser.java +202 -0
- data/src/toxi/data/feeds/AtomAuthor.java +49 -0
- data/src/toxi/data/feeds/AtomContent.java +50 -0
- data/src/toxi/data/feeds/AtomEntry.java +111 -0
- data/src/toxi/data/feeds/AtomFeed.java +129 -0
- data/src/toxi/data/feeds/AtomLink.java +62 -0
- data/src/toxi/data/feeds/RSSChannel.java +88 -0
- data/src/toxi/data/feeds/RSSEnclosure.java +60 -0
- data/src/toxi/data/feeds/RSSFeed.java +99 -0
- data/src/toxi/data/feeds/RSSItem.java +104 -0
- data/src/toxi/data/feeds/util/EntityStripper.java +2480 -0
- data/src/toxi/data/feeds/util/Iso8601DateAdapter.java +101 -0
- data/src/toxi/data/feeds/util/Rfc822DateAdapter.java +93 -0
- data/src/toxi/geom/AABB.java +658 -0
- data/src/toxi/geom/Axis3D.java +116 -0
- data/src/toxi/geom/AxisAlignedCylinder.java +163 -0
- data/src/toxi/geom/BernsteinPolynomial.java +94 -0
- data/src/toxi/geom/BezierCurve2D.java +159 -0
- data/src/toxi/geom/BezierCurve3D.java +148 -0
- data/src/toxi/geom/BooleanShapeBuilder.java +185 -0
- data/src/toxi/geom/BoxIntersector.java +52 -0
- data/src/toxi/geom/Circle.java +230 -0
- data/src/toxi/geom/CircleIntersector.java +85 -0
- data/src/toxi/geom/Cone.java +150 -0
- data/src/toxi/geom/ConvexPolygonClipper.java +136 -0
- data/src/toxi/geom/CoordinateExtractor.java +16 -0
- data/src/toxi/geom/Ellipse.java +250 -0
- data/src/toxi/geom/GMatrix.java +2599 -0
- data/src/toxi/geom/GVector.java +833 -0
- data/src/toxi/geom/GlobalGridTesselator.java +54 -0
- data/src/toxi/geom/GridTesselator.java +108 -0
- data/src/toxi/geom/Intersector2D.java +49 -0
- data/src/toxi/geom/Intersector3D.java +51 -0
- data/src/toxi/geom/IsectData2D.java +103 -0
- data/src/toxi/geom/IsectData3D.java +103 -0
- data/src/toxi/geom/Line2D.java +534 -0
- data/src/toxi/geom/Line3D.java +471 -0
- data/src/toxi/geom/LineStrip2D.java +430 -0
- data/src/toxi/geom/LineStrip3D.java +230 -0
- data/src/toxi/geom/LocalGridTesselator.java +57 -0
- data/src/toxi/geom/Matrix3d.java +3048 -0
- data/src/toxi/geom/Matrix4f.java +3446 -0
- data/src/toxi/geom/Matrix4x4.java +1076 -0
- data/src/toxi/geom/MatrixSizeException.java +58 -0
- data/src/toxi/geom/OctreeVisitor.java +44 -0
- data/src/toxi/geom/Origin3D.java +148 -0
- data/src/toxi/geom/Plane.java +293 -0
- data/src/toxi/geom/PlaneIntersector.java +57 -0
- data/src/toxi/geom/PointCloud3D.java +253 -0
- data/src/toxi/geom/PointOctree.java +502 -0
- data/src/toxi/geom/PointQuadtree.java +375 -0
- data/src/toxi/geom/Polygon2D.java +1038 -0
- data/src/toxi/geom/PolygonClipper2D.java +45 -0
- data/src/toxi/geom/PolygonTesselator.java +20 -0
- data/src/toxi/geom/QuadtreeVisitor.java +44 -0
- data/src/toxi/geom/Quaternion.java +641 -0
- data/src/toxi/geom/Ray2D.java +146 -0
- data/src/toxi/geom/Ray3D.java +150 -0
- data/src/toxi/geom/Ray3DIntersector.java +75 -0
- data/src/toxi/geom/ReadonlyVec2D.java +575 -0
- data/src/toxi/geom/ReadonlyVec3D.java +628 -0
- data/src/toxi/geom/ReadonlyVec4D.java +431 -0
- data/src/toxi/geom/Rect.java +720 -0
- data/src/toxi/geom/Reflector3D.java +58 -0
- data/src/toxi/geom/Shape2D.java +94 -0
- data/src/toxi/geom/Shape3D.java +42 -0
- data/src/toxi/geom/SingularMatrixException.java +57 -0
- data/src/toxi/geom/SpatialBins.java +182 -0
- data/src/toxi/geom/SpatialIndex.java +61 -0
- data/src/toxi/geom/Sphere.java +224 -0
- data/src/toxi/geom/SphereIntersectorReflector.java +196 -0
- data/src/toxi/geom/Spline2D.java +349 -0
- data/src/toxi/geom/Spline3D.java +351 -0
- data/src/toxi/geom/SutherlandHodgemanClipper.java +151 -0
- data/src/toxi/geom/Triangle2D.java +422 -0
- data/src/toxi/geom/Triangle3D.java +456 -0
- data/src/toxi/geom/TriangleIntersector.java +105 -0
- data/src/toxi/geom/Vec2D.java +1328 -0
- data/src/toxi/geom/Vec3D.java +1832 -0
- data/src/toxi/geom/Vec4D.java +985 -0
- data/src/toxi/geom/VecMathUtil.java +100 -0
- data/src/toxi/geom/XAxisCylinder.java +64 -0
- data/src/toxi/geom/YAxisCylinder.java +65 -0
- data/src/toxi/geom/ZAxisCylinder.java +64 -0
- data/src/toxi/geom/mesh/BezierPatch.java +200 -0
- data/src/toxi/geom/mesh/BoxSelector.java +62 -0
- data/src/toxi/geom/mesh/DefaultSTLColorModel.java +67 -0
- data/src/toxi/geom/mesh/DefaultSelector.java +50 -0
- data/src/toxi/geom/mesh/Face.java +176 -0
- data/src/toxi/geom/mesh/LaplacianSmooth.java +80 -0
- data/src/toxi/geom/mesh/MaterialiseSTLColorModel.java +150 -0
- data/src/toxi/geom/mesh/Mesh3D.java +224 -0
- data/src/toxi/geom/mesh/MeshIntersector.java +91 -0
- data/src/toxi/geom/mesh/OBJWriter.java +194 -0
- data/src/toxi/geom/mesh/PLYWriter.java +167 -0
- data/src/toxi/geom/mesh/PlaneSelector.java +90 -0
- data/src/toxi/geom/mesh/STLColorModel.java +54 -0
- data/src/toxi/geom/mesh/STLReader.java +185 -0
- data/src/toxi/geom/mesh/STLWriter.java +323 -0
- data/src/toxi/geom/mesh/SphereFunction.java +156 -0
- data/src/toxi/geom/mesh/SphericalHarmonics.java +110 -0
- data/src/toxi/geom/mesh/SuperEllipsoid.java +110 -0
- data/src/toxi/geom/mesh/SurfaceFunction.java +75 -0
- data/src/toxi/geom/mesh/SurfaceMeshBuilder.java +149 -0
- data/src/toxi/geom/mesh/Terrain.java +451 -0
- data/src/toxi/geom/mesh/TriangleMesh.java +1201 -0
- data/src/toxi/geom/mesh/Vertex.java +78 -0
- data/src/toxi/geom/mesh/VertexSelector.java +193 -0
- data/src/toxi/geom/mesh/WEFace.java +100 -0
- data/src/toxi/geom/mesh/WEMeshFilterStrategy.java +51 -0
- data/src/toxi/geom/mesh/WETriangleMesh.java +761 -0
- data/src/toxi/geom/mesh/WEVertex.java +134 -0
- data/src/toxi/geom/mesh/WingedEdge.java +115 -0
- data/src/toxi/geom/mesh/subdiv/CentroidSubdiv.java +37 -0
- data/src/toxi/geom/mesh/subdiv/DisplacementSubdivision.java +85 -0
- data/src/toxi/geom/mesh/subdiv/DualDisplacementSubdivision.java +94 -0
- data/src/toxi/geom/mesh/subdiv/DualSubdivision.java +49 -0
- data/src/toxi/geom/mesh/subdiv/EdgeLengthComparator.java +50 -0
- data/src/toxi/geom/mesh/subdiv/FaceCountComparator.java +51 -0
- data/src/toxi/geom/mesh/subdiv/MidpointDisplacementSubdivision.java +80 -0
- data/src/toxi/geom/mesh/subdiv/MidpointSubdiv.java +42 -0
- data/src/toxi/geom/mesh/subdiv/MidpointSubdivision.java +48 -0
- data/src/toxi/geom/mesh/subdiv/NewSubdivStrategy.java +23 -0
- data/src/toxi/geom/mesh/subdiv/NormalDisplacementSubdivision.java +74 -0
- data/src/toxi/geom/mesh/subdiv/SubdivisionStrategy.java +83 -0
- data/src/toxi/geom/mesh/subdiv/TriSubdivision.java +51 -0
- data/src/toxi/geom/mesh2d/DelaunayTriangle.java +222 -0
- data/src/toxi/geom/mesh2d/DelaunayTriangulation.java +327 -0
- data/src/toxi/geom/mesh2d/DelaunayVertex.java +560 -0
- data/src/toxi/geom/mesh2d/Voronoi.java +149 -0
- data/src/toxi/geom/nurbs/BasicNurbsCurve.java +210 -0
- data/src/toxi/geom/nurbs/BasicNurbsSurface.java +233 -0
- data/src/toxi/geom/nurbs/ControlNet.java +148 -0
- data/src/toxi/geom/nurbs/CurveCreator.java +112 -0
- data/src/toxi/geom/nurbs/CurveUtils.java +259 -0
- data/src/toxi/geom/nurbs/InterpolationException.java +65 -0
- data/src/toxi/geom/nurbs/KnotVector.java +333 -0
- data/src/toxi/geom/nurbs/NurbsCreator.java +815 -0
- data/src/toxi/geom/nurbs/NurbsCurve.java +120 -0
- data/src/toxi/geom/nurbs/NurbsMeshCreator.java +145 -0
- data/src/toxi/geom/nurbs/NurbsSurface.java +147 -0
- data/src/toxi/image/util/Filter8bit.java +331 -0
- data/src/toxi/image/util/TiledFrameExporter.java +162 -0
- data/src/toxi/math/BezierInterpolation.java +102 -0
- data/src/toxi/math/CircularInterpolation.java +88 -0
- data/src/toxi/math/CosineInterpolation.java +51 -0
- data/src/toxi/math/DecimatedInterpolation.java +77 -0
- data/src/toxi/math/ExponentialInterpolation.java +68 -0
- data/src/toxi/math/InterpolateStrategy.java +60 -0
- data/src/toxi/math/Interpolation2D.java +93 -0
- data/src/toxi/math/LinearInterpolation.java +46 -0
- data/src/toxi/math/MathUtils.java +990 -0
- data/src/toxi/math/NonLinearScaleMap.java +101 -0
- data/src/toxi/math/ScaleMap.java +183 -0
- data/src/toxi/math/SigmoidInterpolation.java +78 -0
- data/src/toxi/math/SinCosLUT.java +141 -0
- data/src/toxi/math/ThresholdInterpolation.java +58 -0
- data/src/toxi/math/ZoomLensInterpolation.java +126 -0
- data/src/toxi/math/conversion/UnitTranslator.java +161 -0
- data/src/toxi/math/noise/PerlinNoise.java +281 -0
- data/src/toxi/math/noise/SimplexNoise.java +542 -0
- data/src/toxi/math/waves/AMFMSineWave.java +143 -0
- data/src/toxi/math/waves/AbstractWave.java +248 -0
- data/src/toxi/math/waves/ConstantWave.java +48 -0
- data/src/toxi/math/waves/FMHarmonicSquareWave.java +155 -0
- data/src/toxi/math/waves/FMSawtoothWave.java +144 -0
- data/src/toxi/math/waves/FMSineWave.java +142 -0
- data/src/toxi/math/waves/FMSquareWave.java +143 -0
- data/src/toxi/math/waves/FMTriangleWave.java +126 -0
- data/src/toxi/math/waves/SineWave.java +81 -0
- data/src/toxi/math/waves/Wave2D.java +68 -0
- data/src/toxi/math/waves/WaveState.java +69 -0
- data/src/toxi/music/scale/AbstractScale.java +117 -0
- data/src/toxi/music/scale/GenericScale.java +66 -0
- data/src/toxi/music/scale/MajorScale.java +41 -0
- data/src/toxi/newmesh/AttributedEdge.java +106 -0
- data/src/toxi/newmesh/AttributedFace.java +63 -0
- data/src/toxi/newmesh/IndexedTriangleMesh.java +809 -0
- data/src/toxi/newmesh/MeshAttributeCompiler.java +45 -0
- data/src/toxi/newmesh/MeshFaceNormalCompiler.java +52 -0
- data/src/toxi/newmesh/MeshUVCompiler.java +52 -0
- data/src/toxi/newmesh/MeshVertexColorCompiler.java +49 -0
- data/src/toxi/newmesh/MeshVertexCompiler.java +54 -0
- data/src/toxi/newmesh/MeshVertexNormalCompiler.java +55 -0
- data/src/toxi/newmesh/SpatialIndex.java +78 -0
- data/src/toxi/physics2d/ParticlePath2D.java +100 -0
- data/src/toxi/physics2d/ParticleString2D.java +184 -0
- data/src/toxi/physics2d/PullBackSpring2D.java +51 -0
- data/src/toxi/physics2d/VerletConstrainedSpring2D.java +89 -0
- data/src/toxi/physics2d/VerletMinDistanceSpring2D.java +57 -0
- data/src/toxi/physics2d/VerletParticle2D.java +457 -0
- data/src/toxi/physics2d/VerletPhysics2D.java +448 -0
- data/src/toxi/physics2d/VerletSpring2D.java +181 -0
- data/src/toxi/physics2d/behaviors/AttractionBehavior2D.java +212 -0
- data/src/toxi/physics2d/behaviors/ConstantForceBehavior2D.java +112 -0
- data/src/toxi/physics2d/behaviors/GravityBehavior2D.java +61 -0
- data/src/toxi/physics2d/behaviors/ParticleBehavior2D.java +66 -0
- data/src/toxi/physics2d/constraints/AngularConstraint.java +83 -0
- data/src/toxi/physics2d/constraints/AxisConstraint.java +71 -0
- data/src/toxi/physics2d/constraints/CircularConstraint.java +69 -0
- data/src/toxi/physics2d/constraints/MaxConstraint.java +66 -0
- data/src/toxi/physics2d/constraints/MinConstraint.java +66 -0
- data/src/toxi/physics2d/constraints/ParticleConstraint2D.java +47 -0
- data/src/toxi/physics2d/constraints/PolygonConstraint.java +93 -0
- data/src/toxi/physics2d/constraints/RectConstraint.java +114 -0
- data/src/toxi/physics3d/ParticlePath3D.java +100 -0
- data/src/toxi/physics3d/ParticleString3D.java +184 -0
- data/src/toxi/physics3d/PullBackSpring3D.java +50 -0
- data/src/toxi/physics3d/VerletConstrainedSpring3D.java +88 -0
- data/src/toxi/physics3d/VerletMinDistanceSpring3D.java +56 -0
- data/src/toxi/physics3d/VerletParticle3D.java +385 -0
- data/src/toxi/physics3d/VerletPhysics3D.java +417 -0
- data/src/toxi/physics3d/VerletSpring3D.java +180 -0
- data/src/toxi/physics3d/behaviors/AttractionBehavior3D.java +182 -0
- data/src/toxi/physics3d/behaviors/ConstantForceBehavior3D.java +92 -0
- data/src/toxi/physics3d/behaviors/GravityBehavior3D.java +61 -0
- data/src/toxi/physics3d/behaviors/ParticleBehavior3D.java +52 -0
- data/src/toxi/physics3d/constraints/AxisConstraint.java +68 -0
- data/src/toxi/physics3d/constraints/BoxConstraint.java +121 -0
- data/src/toxi/physics3d/constraints/CylinderConstraint.java +87 -0
- data/src/toxi/physics3d/constraints/MaxConstraint.java +65 -0
- data/src/toxi/physics3d/constraints/MinConstraint.java +65 -0
- data/src/toxi/physics3d/constraints/ParticleConstraint3D.java +49 -0
- data/src/toxi/physics3d/constraints/PlaneConstraint.java +78 -0
- data/src/toxi/physics3d/constraints/SoftBoxConstraint.java +87 -0
- data/src/toxi/physics3d/constraints/SphereConstraint.java +108 -0
- data/src/toxi/processing/ArrowModifier.java +116 -0
- data/src/toxi/processing/DashedLineModifier.java +48 -0
- data/src/toxi/processing/DeltaOrientationMapper.java +57 -0
- data/src/toxi/processing/Line2DRenderModifier.java +18 -0
- data/src/toxi/processing/MeshToVBO.java +94 -0
- data/src/toxi/processing/NormalMapper.java +18 -0
- data/src/toxi/processing/POVInterface.java +121 -0
- data/src/toxi/processing/POVMesh.java +219 -0
- data/src/toxi/processing/POVWriter.java +460 -0
- data/src/toxi/processing/RCOpaque.java +77 -0
- data/src/toxi/processing/RCTransp.java +78 -0
- data/src/toxi/processing/TextureBuilder.java +232 -0
- data/src/toxi/processing/Textures.java +110 -0
- data/src/toxi/processing/ToxiclibsSupport.java +1239 -0
- data/src/toxi/processing/Tracing.java +25 -0
- data/src/toxi/processing/XYZNormalMapper.java +30 -0
- data/src/toxi/sim/automata/CAMatrix.java +297 -0
- data/src/toxi/sim/automata/CARule.java +76 -0
- data/src/toxi/sim/automata/CARule2D.java +354 -0
- data/src/toxi/sim/automata/CAWolfram1D.java +309 -0
- data/src/toxi/sim/automata/EvolvableMatrix.java +61 -0
- data/src/toxi/sim/automata/MatrixEvolver.java +42 -0
- data/src/toxi/sim/dla/BottomUpOrder.java +76 -0
- data/src/toxi/sim/dla/DLA.java +497 -0
- data/src/toxi/sim/dla/DLAConfiguration.java +364 -0
- data/src/toxi/sim/dla/DLAEventAdapter.java +64 -0
- data/src/toxi/sim/dla/DLAEventListener.java +57 -0
- data/src/toxi/sim/dla/DLAGuideLines.java +219 -0
- data/src/toxi/sim/dla/DLAParticle.java +102 -0
- data/src/toxi/sim/dla/DLASegment.java +88 -0
- data/src/toxi/sim/dla/PipelineOrder.java +50 -0
- data/src/toxi/sim/dla/RadialDistanceOrder.java +92 -0
- data/src/toxi/sim/erosion/ErosionFunction.java +122 -0
- data/src/toxi/sim/erosion/TalusAngleErosion.java +145 -0
- data/src/toxi/sim/erosion/ThermalErosion.java +75 -0
- data/src/toxi/sim/fluids/FluidSolver2D.java +762 -0
- data/src/toxi/sim/fluids/FluidSolver3D.java +326 -0
- data/src/toxi/sim/grayscott/GrayScott.java +469 -0
- data/src/toxi/util/DateUtils.java +141 -0
- data/src/toxi/util/FileSequenceDescriptor.java +181 -0
- data/src/toxi/util/FileUtils.java +467 -0
- data/src/toxi/util/datatypes/ArraySet.java +128 -0
- data/src/toxi/util/datatypes/ArrayUtil.java +404 -0
- data/src/toxi/util/datatypes/BiasedDoubleRange.java +141 -0
- data/src/toxi/util/datatypes/BiasedFloatRange.java +141 -0
- data/src/toxi/util/datatypes/BiasedIntegerRange.java +141 -0
- data/src/toxi/util/datatypes/DoubleRange.java +251 -0
- data/src/toxi/util/datatypes/FloatRange.java +251 -0
- data/src/toxi/util/datatypes/GenericSet.java +215 -0
- data/src/toxi/util/datatypes/IntegerRange.java +247 -0
- data/src/toxi/util/datatypes/IntegerSet.java +149 -0
- data/src/toxi/util/datatypes/ItemIndex.java +72 -0
- data/src/toxi/util/datatypes/SingletonRegistry.java +91 -0
- data/src/toxi/util/datatypes/TypedProperties.java +291 -0
- data/src/toxi/util/datatypes/UndirectedGraph.java +134 -0
- data/src/toxi/util/datatypes/UniqueItemIndex.java +223 -0
- data/src/toxi/util/datatypes/WeightedRandomEntry.java +76 -0
- data/src/toxi/util/datatypes/WeightedRandomSet.java +125 -0
- data/src/toxi/util/events/EventDispatcher.java +86 -0
- data/src/toxi/volume/AdditiveBrush.java +19 -0
- data/src/toxi/volume/ArrayIsoSurface.java +297 -0
- data/src/toxi/volume/BoxBrush.java +100 -0
- data/src/toxi/volume/BrushMode.java +16 -0
- data/src/toxi/volume/HashIsoSurface.java +354 -0
- data/src/toxi/volume/IsoSurface.java +59 -0
- data/src/toxi/volume/MarchingCubesIndex.java +312 -0
- data/src/toxi/volume/MeshLatticeBuilder.java +358 -0
- data/src/toxi/volume/MeshVoxelizer.java +216 -0
- data/src/toxi/volume/MultiplyBrush.java +20 -0
- data/src/toxi/volume/PeakBrush.java +21 -0
- data/src/toxi/volume/ReplaceBrush.java +19 -0
- data/src/toxi/volume/RoundBrush.java +113 -0
- data/src/toxi/volume/VolumetricBrush.java +160 -0
- data/src/toxi/volume/VolumetricHashMap.java +179 -0
- data/src/toxi/volume/VolumetricSpace.java +195 -0
- data/src/toxi/volume/VolumetricSpaceArray.java +214 -0
- data/toxiclibs.gemspec +34 -0
- metadata +424 -27
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* __ .__ .__ ._____.
|
|
3
|
+
* _/ |_ _______ __|__| ____ | | |__\_ |__ ______
|
|
4
|
+
* \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
|
|
5
|
+
* | | ( <_> > <| \ \___| |_| || \_\ \\___ \
|
|
6
|
+
* |__| \____/__/\_ \__|\___ >____/__||___ /____ >
|
|
7
|
+
* \/ \/ \/ \/
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2006-2011 Karsten Schmidt
|
|
10
|
+
*
|
|
11
|
+
* This library is free software; you can redistribute it and/or
|
|
12
|
+
* modify it under the terms of the GNU Lesser General Public
|
|
13
|
+
* License as published by the Free Software Foundation; either
|
|
14
|
+
* version 2.1 of the License, or (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* http://creativecommons.org/licenses/LGPL/2.1/
|
|
17
|
+
*
|
|
18
|
+
* This library is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
21
|
+
* Lesser General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
24
|
+
* License along with this library; if not, write to the Free Software
|
|
25
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
package toxi.geom.mesh.subdiv;
|
|
29
|
+
|
|
30
|
+
import java.util.ArrayList;
|
|
31
|
+
import java.util.List;
|
|
32
|
+
|
|
33
|
+
import toxi.geom.Vec3D;
|
|
34
|
+
import toxi.geom.mesh.WingedEdge;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* This subdivision strategy splits an edge in four equal parts using three
|
|
38
|
+
* split points at 25%, 50% and 75% of the edge.
|
|
39
|
+
*/
|
|
40
|
+
public class TriSubdivision extends SubdivisionStrategy {
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public List<Vec3D> computeSplitPoints(WingedEdge edge) {
|
|
44
|
+
List<Vec3D> mid = new ArrayList<>(3);
|
|
45
|
+
mid.add(edge.a.interpolateTo(edge.b, 0.25f));
|
|
46
|
+
mid.add(edge.a.interpolateTo(edge.b, 0.5f));
|
|
47
|
+
mid.add(edge.a.interpolateTo(edge.b, 0.75f));
|
|
48
|
+
return mid;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
package toxi.geom.mesh2d;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2007 by L. Paul Chew.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, without written agreement and without
|
|
7
|
+
* license or royalty fees, to use, copy, modify, and distribute this
|
|
8
|
+
* software and its documentation for any purpose, subject to the following
|
|
9
|
+
* conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included
|
|
12
|
+
* in all copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
* DEALINGS IN THE SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import java.util.Arrays;
|
|
24
|
+
import java.util.Collection;
|
|
25
|
+
import java.util.Iterator;
|
|
26
|
+
import java.util.NoSuchElementException;
|
|
27
|
+
|
|
28
|
+
import toxi.util.datatypes.ArraySet;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A DelaunayTriangle is an immutable Set of exactly three Pnts.
|
|
32
|
+
*
|
|
33
|
+
* All Set operations are available. Individual vertices can be accessed via
|
|
34
|
+
* iterator() and also via triangle.get(index).
|
|
35
|
+
*
|
|
36
|
+
* Note that, even if two triangles have the same vertex set, they are
|
|
37
|
+
* *different* triangles. Methods equals() and hashCode() are consistent with
|
|
38
|
+
* this rule.
|
|
39
|
+
*
|
|
40
|
+
* @author Paul Chew
|
|
41
|
+
*
|
|
42
|
+
* Created December 2007. Replaced general simplices with geometric
|
|
43
|
+
* triangle.
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
public class DelaunayTriangle extends ArraySet<DelaunayVertex> {
|
|
47
|
+
|
|
48
|
+
private int idNumber; // The id number
|
|
49
|
+
private DelaunayVertex circumcenter = null; // The triangle's circumcenter
|
|
50
|
+
|
|
51
|
+
private static int idGenerator = 0; // Used to create id numbers
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
public static boolean moreInfo = false; // True if more info in toString
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param collection
|
|
60
|
+
* a Collection holding the Simplex vertices
|
|
61
|
+
* @throws IllegalArgumentException
|
|
62
|
+
* if there are not three distinct vertices
|
|
63
|
+
*/
|
|
64
|
+
public DelaunayTriangle(Collection<? extends DelaunayVertex> collection) {
|
|
65
|
+
super(collection);
|
|
66
|
+
idNumber = idGenerator++;
|
|
67
|
+
if (this.size() != 3) {
|
|
68
|
+
throw new IllegalArgumentException(
|
|
69
|
+
"DelaunayTriangle must have 3 vertices");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param vertices
|
|
75
|
+
* the vertices of the DelaunayTriangle.
|
|
76
|
+
* @throws IllegalArgumentException
|
|
77
|
+
* if there are not three distinct vertices
|
|
78
|
+
*/
|
|
79
|
+
public DelaunayTriangle(DelaunayVertex... vertices) {
|
|
80
|
+
this(Arrays.asList(vertices));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param vertex
|
|
86
|
+
* @return
|
|
87
|
+
*/
|
|
88
|
+
@Override
|
|
89
|
+
public boolean add(DelaunayVertex vertex) {
|
|
90
|
+
throw new UnsupportedOperationException();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* @param o
|
|
96
|
+
* @return
|
|
97
|
+
*/
|
|
98
|
+
@Override
|
|
99
|
+
public boolean equals(Object o) {
|
|
100
|
+
if (o instanceof DelaunayTriangle){
|
|
101
|
+
return (this == o);
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* @return
|
|
109
|
+
*/
|
|
110
|
+
@Override
|
|
111
|
+
public int hashCode() {
|
|
112
|
+
int hash = 7;
|
|
113
|
+
hash = 53 * hash + this.idNumber;
|
|
114
|
+
return hash;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Report the facet opposite vertex.
|
|
119
|
+
*
|
|
120
|
+
* @param vertex
|
|
121
|
+
* a vertex of this DelaunayTriangle
|
|
122
|
+
* @return the facet opposite vertex
|
|
123
|
+
* @throws IllegalArgumentException
|
|
124
|
+
* if the vertex is not in triangle
|
|
125
|
+
*/
|
|
126
|
+
public ArraySet<DelaunayVertex> facetOpposite(DelaunayVertex vertex) {
|
|
127
|
+
ArraySet<DelaunayVertex> facet = new ArraySet<>(this);
|
|
128
|
+
if (!facet.remove(vertex)) {
|
|
129
|
+
throw new IllegalArgumentException("Vertex not in triangle");
|
|
130
|
+
}
|
|
131
|
+
return facet;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @return the triangle's circumcenter
|
|
136
|
+
*/
|
|
137
|
+
public DelaunayVertex getCircumcenter() {
|
|
138
|
+
if (circumcenter == null) {
|
|
139
|
+
circumcenter = DelaunayVertex.circumcenter(this
|
|
140
|
+
.toArray(new DelaunayVertex[0]));
|
|
141
|
+
}
|
|
142
|
+
return circumcenter;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get arbitrary vertex of this triangle, but not any of the bad vertices.
|
|
147
|
+
*
|
|
148
|
+
* @param badVertices
|
|
149
|
+
* one or more bad vertices
|
|
150
|
+
* @return a vertex of this triangle, but not one of the bad vertices
|
|
151
|
+
* @throws NoSuchElementException
|
|
152
|
+
* if no vertex found
|
|
153
|
+
*/
|
|
154
|
+
public DelaunayVertex getVertexButNot(DelaunayVertex... badVertices) {
|
|
155
|
+
Collection<DelaunayVertex> bad = Arrays.asList(badVertices);
|
|
156
|
+
for (DelaunayVertex v : this) {
|
|
157
|
+
if (!bad.contains(v)) {
|
|
158
|
+
return v;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
throw new NoSuchElementException("No vertex found");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* True iff triangles are neighbors. Two triangles are neighbors if they
|
|
166
|
+
* share a facet.
|
|
167
|
+
*
|
|
168
|
+
* @param triangle
|
|
169
|
+
* the other DelaunayTriangle
|
|
170
|
+
* @return true iff this DelaunayTriangle is a neighbor of triangle
|
|
171
|
+
*/
|
|
172
|
+
public boolean isNeighbor(DelaunayTriangle triangle) {
|
|
173
|
+
int count = 0;
|
|
174
|
+
count = this.stream().filter((vertex) -> (!triangle.contains(vertex))).map((_item) -> 1).reduce(count, Integer::sum);
|
|
175
|
+
return count == 1;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* The following two methods ensure that all triangles are different. */
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
*
|
|
182
|
+
* @return
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
@Override
|
|
187
|
+
public Iterator<DelaunayVertex> iterator() {
|
|
188
|
+
return new Iterator<DelaunayVertex>() {
|
|
189
|
+
|
|
190
|
+
private final Iterator<DelaunayVertex> it = DelaunayTriangle.super
|
|
191
|
+
.iterator();
|
|
192
|
+
|
|
193
|
+
@Override
|
|
194
|
+
public boolean hasNext() {
|
|
195
|
+
return it.hasNext();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
@Override
|
|
199
|
+
public DelaunayVertex next() {
|
|
200
|
+
return it.next();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@Override
|
|
204
|
+
public void remove() {
|
|
205
|
+
throw new UnsupportedOperationException();
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
*
|
|
212
|
+
* @return
|
|
213
|
+
*/
|
|
214
|
+
@Override
|
|
215
|
+
public String toString() {
|
|
216
|
+
if (!moreInfo) {
|
|
217
|
+
return "DelaunayTriangle" + idNumber;
|
|
218
|
+
}
|
|
219
|
+
return "DelaunayTriangle" + idNumber + super.toString();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
package toxi.geom.mesh2d;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2005, 2007 by L. Paul Chew.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, without written agreement and without
|
|
7
|
+
* license or royalty fees, to use, copy, modify, and distribute this
|
|
8
|
+
* software and its documentation for any purpose, subject to the following
|
|
9
|
+
* conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included
|
|
12
|
+
* in all copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
* DEALINGS IN THE SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import java.util.AbstractSet;
|
|
23
|
+
import java.util.ArrayList;
|
|
24
|
+
import java.util.HashSet;
|
|
25
|
+
import java.util.Iterator;
|
|
26
|
+
import java.util.LinkedList;
|
|
27
|
+
import java.util.List;
|
|
28
|
+
import java.util.Queue;
|
|
29
|
+
import java.util.Set;
|
|
30
|
+
|
|
31
|
+
import toxi.util.datatypes.UndirectedGraph;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A 2D Delaunay DelaunayTriangulation (DT) with incremental site insertion.
|
|
35
|
+
*
|
|
36
|
+
* This is not the fastest way to build a DT, but it's a reasonable way to build
|
|
37
|
+
* a DT incrementally and it makes a nice interactive display. There are several
|
|
38
|
+
* O(n log n) methods, but they require that the sites are all known initially.
|
|
39
|
+
*
|
|
40
|
+
* A DelaunayTriangulation is a Set of Triangles. A DelaunayTriangulation is
|
|
41
|
+
* unmodifiable as a Set; the only way to change it is to add sites (via
|
|
42
|
+
* delaunayPlace).
|
|
43
|
+
*
|
|
44
|
+
* @author Paul Chew
|
|
45
|
+
*
|
|
46
|
+
* Created July 2005. Derived from an earlier, messier version.
|
|
47
|
+
*
|
|
48
|
+
* Modified November 2007. Rewrote to use AbstractSet as parent class and to use
|
|
49
|
+
* the UndirectedGraph class internally. Tried to make the DT algorithm clearer
|
|
50
|
+
* by explicitly creating a cavity. Added code needed to find a Voronoi cell.
|
|
51
|
+
*
|
|
52
|
+
* @author Karsten Schmidt
|
|
53
|
+
*
|
|
54
|
+
* Ported to use toxiclibs classes (June 2010).
|
|
55
|
+
*/
|
|
56
|
+
public class DelaunayTriangulation extends AbstractSet<DelaunayTriangle> {
|
|
57
|
+
|
|
58
|
+
private DelaunayTriangle mostRecent = null;
|
|
59
|
+
|
|
60
|
+
private final UndirectedGraph<DelaunayTriangle> triGraph;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* All sites must fall within the initial triangle.
|
|
64
|
+
*
|
|
65
|
+
* @param triangle the initial triangle
|
|
66
|
+
*/
|
|
67
|
+
public DelaunayTriangulation(DelaunayTriangle triangle) {
|
|
68
|
+
triGraph = new UndirectedGraph<>();
|
|
69
|
+
triGraph.add(triangle);
|
|
70
|
+
mostRecent = triangle;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* True iff triangle is a member of this triangulation. This method isn't
|
|
75
|
+
* required by AbstractSet, but it improves efficiency.
|
|
76
|
+
*
|
|
77
|
+
* @param triangle the object to check for membership
|
|
78
|
+
* @return
|
|
79
|
+
*/
|
|
80
|
+
@Override
|
|
81
|
+
public boolean contains(Object triangle) {
|
|
82
|
+
return triGraph.getNodes().contains(triangle);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Place a new site into the DT. Nothing happens if the site matches an
|
|
87
|
+
* existing DT vertex.
|
|
88
|
+
*
|
|
89
|
+
* @param site the new DelaunayVertex
|
|
90
|
+
* @throws IllegalArgumentException if site does not lie in any triangle
|
|
91
|
+
*/
|
|
92
|
+
public void delaunayPlace(DelaunayVertex site) {
|
|
93
|
+
// Uses straightforward scheme rather than best asymptotic time
|
|
94
|
+
// Locate containing triangle
|
|
95
|
+
DelaunayTriangle triangle = locate(site);
|
|
96
|
+
// Give up if no containing triangle or if site is already in DT
|
|
97
|
+
if (triangle == null) {
|
|
98
|
+
throw new IllegalArgumentException("No containing triangle");
|
|
99
|
+
}
|
|
100
|
+
if (triangle.contains(site)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Determine the cavity and update the triangulation
|
|
104
|
+
Set<DelaunayTriangle> cavity = getCavity(site, triangle);
|
|
105
|
+
mostRecent = update(site, cavity);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Determine the cavity caused by site.
|
|
110
|
+
*
|
|
111
|
+
* @param site the site causing the cavity
|
|
112
|
+
* @param triangle the triangle containing site
|
|
113
|
+
* @return set of all triangles that have site in their circumcircle
|
|
114
|
+
*/
|
|
115
|
+
private Set<DelaunayTriangle> getCavity(DelaunayVertex site,
|
|
116
|
+
DelaunayTriangle triangle) {
|
|
117
|
+
Set<DelaunayTriangle> encroached = new HashSet<>();
|
|
118
|
+
Queue<DelaunayTriangle> toBeChecked = new LinkedList<>();
|
|
119
|
+
Set<DelaunayTriangle> marked = new HashSet<>();
|
|
120
|
+
toBeChecked.add(triangle);
|
|
121
|
+
marked.add(triangle);
|
|
122
|
+
while (!toBeChecked.isEmpty()) {
|
|
123
|
+
triangle = toBeChecked.remove();
|
|
124
|
+
if (site.vsCircumcircle(triangle.toArray(new DelaunayVertex[0])) == 1) {
|
|
125
|
+
// Site outside triangle => triangle not in cavity
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
encroached.add(triangle);
|
|
129
|
+
// Check the neighbors
|
|
130
|
+
for (DelaunayTriangle neighbor : triGraph
|
|
131
|
+
.getConnectedNodesFor(triangle)) {
|
|
132
|
+
if (marked.contains(neighbor)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
marked.add(neighbor);
|
|
136
|
+
toBeChecked.add(neighbor);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return encroached;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
* @return
|
|
145
|
+
*/
|
|
146
|
+
@Override
|
|
147
|
+
public Iterator<DelaunayTriangle> iterator() {
|
|
148
|
+
return triGraph.getNodes().iterator();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Locate the triangle with point inside it or on its boundary.
|
|
153
|
+
*
|
|
154
|
+
* @param point the point to locate
|
|
155
|
+
* @return the triangle that holds point; null if no such triangle
|
|
156
|
+
*/
|
|
157
|
+
public DelaunayTriangle locate(DelaunayVertex point) {
|
|
158
|
+
DelaunayTriangle triangle = mostRecent;
|
|
159
|
+
if (!this.contains(triangle)) {
|
|
160
|
+
triangle = null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Try a directed walk (this works fine in 2D, but can fail in 3D)
|
|
164
|
+
Set<DelaunayTriangle> visited = new HashSet<>();
|
|
165
|
+
while (triangle != null) {
|
|
166
|
+
if (visited.contains(triangle)) { // This should never happen
|
|
167
|
+
System.out.println("Warning: Caught in a locate loop");
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
visited.add(triangle);
|
|
171
|
+
// Corner opposite point
|
|
172
|
+
DelaunayVertex corner = point.isOutside(triangle
|
|
173
|
+
.toArray(new DelaunayVertex[0]));
|
|
174
|
+
if (corner == null) {
|
|
175
|
+
return triangle;
|
|
176
|
+
}
|
|
177
|
+
triangle = this.neighborOpposite(corner, triangle);
|
|
178
|
+
}
|
|
179
|
+
// No luck; try brute force
|
|
180
|
+
System.out.println("Warning: Checking all triangles for " + point);
|
|
181
|
+
for (DelaunayTriangle tri : this) {
|
|
182
|
+
if (point.isOutside(tri.toArray(new DelaunayVertex[0])) == null) {
|
|
183
|
+
return tri;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// No such triangle
|
|
187
|
+
System.out.println("Warning: No triangle holds " + point);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Report neighbor opposite the given vertex of triangle.
|
|
193
|
+
*
|
|
194
|
+
* @param site a vertex of triangle
|
|
195
|
+
* @param triangle we want the neighbor of this triangle
|
|
196
|
+
* @return the neighbor opposite site in triangle; null if none
|
|
197
|
+
* @throws IllegalArgumentException if site is not in this triangle
|
|
198
|
+
*/
|
|
199
|
+
public DelaunayTriangle neighborOpposite(DelaunayVertex site,
|
|
200
|
+
DelaunayTriangle triangle) {
|
|
201
|
+
if (!triangle.contains(site)) {
|
|
202
|
+
throw new IllegalArgumentException("Bad vertex; not in triangle");
|
|
203
|
+
}
|
|
204
|
+
for (DelaunayTriangle neighbor : triGraph
|
|
205
|
+
.getConnectedNodesFor(triangle)) {
|
|
206
|
+
if (!neighbor.contains(site)) {
|
|
207
|
+
return neighbor;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Return the set of triangles adjacent to triangle.
|
|
215
|
+
*
|
|
216
|
+
* @param triangle the triangle to check
|
|
217
|
+
* @return the neighbors of triangle
|
|
218
|
+
*/
|
|
219
|
+
public Set<DelaunayTriangle> neighbors(DelaunayTriangle triangle) {
|
|
220
|
+
return triGraph.getConnectedNodesFor(triangle);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
*
|
|
225
|
+
* @return
|
|
226
|
+
*/
|
|
227
|
+
@Override
|
|
228
|
+
public int size() {
|
|
229
|
+
return triGraph.getNodes().size();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Report triangles surrounding site in order (cw or ccw).
|
|
234
|
+
*
|
|
235
|
+
* @param site we want the surrounding triangles for this site
|
|
236
|
+
* @param triangle a "starting" triangle that has site as a vertex
|
|
237
|
+
* @return all triangles surrounding site in order (cw or ccw)
|
|
238
|
+
* @throws IllegalArgumentException if site is not in triangle
|
|
239
|
+
*/
|
|
240
|
+
public List<DelaunayTriangle> surroundingTriangles(DelaunayVertex site,
|
|
241
|
+
DelaunayTriangle triangle) {
|
|
242
|
+
if (!triangle.contains(site)) {
|
|
243
|
+
throw new IllegalArgumentException("Site not in triangle");
|
|
244
|
+
}
|
|
245
|
+
List<DelaunayTriangle> list = new ArrayList<>();
|
|
246
|
+
DelaunayTriangle start = triangle;
|
|
247
|
+
DelaunayVertex guide = triangle.getVertexButNot(site); // Affects cw or
|
|
248
|
+
// ccw
|
|
249
|
+
while (true) {
|
|
250
|
+
list.add(triangle);
|
|
251
|
+
DelaunayTriangle previous = triangle;
|
|
252
|
+
triangle = this.neighborOpposite(guide, triangle); // Next triangle
|
|
253
|
+
guide = previous.getVertexButNot(site, guide); // Update guide
|
|
254
|
+
if (triangle == start) {
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return list;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
*
|
|
263
|
+
* @return
|
|
264
|
+
*/
|
|
265
|
+
@Override
|
|
266
|
+
public String toString() {
|
|
267
|
+
return "DelaunayTriangulation with " + size() + " triangles";
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Update the triangulation by removing the cavity triangles and then
|
|
272
|
+
* filling the cavity with new triangles.
|
|
273
|
+
*
|
|
274
|
+
* @param site the site that created the cavity
|
|
275
|
+
* @param cavity the triangles with site in their circumcircle
|
|
276
|
+
* @return one of the new triangles
|
|
277
|
+
*/
|
|
278
|
+
private DelaunayTriangle update(DelaunayVertex site,
|
|
279
|
+
Set<DelaunayTriangle> cavity) {
|
|
280
|
+
Set<Set<DelaunayVertex>> boundary = new HashSet<>();
|
|
281
|
+
Set<DelaunayTriangle> theTriangles = new HashSet<>();
|
|
282
|
+
|
|
283
|
+
// Find boundary facets and adjacent triangles
|
|
284
|
+
cavity.stream().map((DelaunayTriangle triangle) -> {
|
|
285
|
+
theTriangles.addAll(neighbors(triangle));
|
|
286
|
+
return triangle;
|
|
287
|
+
}).forEach((DelaunayTriangle triangle) -> {
|
|
288
|
+
triangle.stream().map((vertex) -> triangle.facetOpposite(vertex)).forEach((facet) -> {
|
|
289
|
+
if (boundary.contains(facet)) {
|
|
290
|
+
boundary.remove(facet);
|
|
291
|
+
} else {
|
|
292
|
+
boundary.add(facet);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
theTriangles.removeAll(cavity); // Adj triangles only
|
|
297
|
+
// Remove the cavity triangles from the triangulation
|
|
298
|
+
cavity.stream().forEach((DelaunayTriangle triangle) -> {
|
|
299
|
+
triGraph.remove(triangle);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// Build each new triangle and add it to the triangulation
|
|
303
|
+
Set<DelaunayTriangle> newTriangles = new HashSet<>();
|
|
304
|
+
boundary.stream().map((vertices) -> {
|
|
305
|
+
vertices.add(site);
|
|
306
|
+
return vertices;
|
|
307
|
+
}).map((vertices) -> new DelaunayTriangle(vertices)).map((tri) -> {
|
|
308
|
+
triGraph.add(tri);
|
|
309
|
+
return tri;
|
|
310
|
+
}).forEach((tri) -> {
|
|
311
|
+
newTriangles.add(tri);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// Update the graph links for each new triangle
|
|
315
|
+
theTriangles.addAll(newTriangles); // Adj triangle + new triangles
|
|
316
|
+
for (DelaunayTriangle triangle : newTriangles) {
|
|
317
|
+
for (DelaunayTriangle other : theTriangles) {
|
|
318
|
+
if (triangle.isNeighbor(other)) {
|
|
319
|
+
triGraph.connect(triangle, other);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Return one of the new triangles
|
|
325
|
+
return newTriangles.iterator().next();
|
|
326
|
+
}
|
|
327
|
+
}
|