joonsrenderer 1.1-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 +7 -0
- data/.gitignore +53 -0
- data/.mvn/extensions.xml +8 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +6 -0
- data/LICENSE +674 -0
- data/README.md +2 -0
- data/Rakefile +43 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +20 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +15 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2017-01-08-animated_ray_tracing.md +72 -0
- data/docs/_posts/2017-01-08-welcome.md +78 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +12 -0
- data/docs/assets/Animation.ogv +0 -0
- data/docs/assets/Animation.png +0 -0
- data/docs/assets/basic.png +0 -0
- data/docs/assets/basic_traced.png +0 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/joonsrenderer.gemspec +23 -0
- data/lib/joonsrenderer.rb +12 -0
- data/lib/joonsrenderer/version.rb +3 -0
- data/pom.rb +75 -0
- data/pom.xml +163 -0
- data/src/main/java/SunflowGUI.java +1354 -0
- data/src/main/java/joons/JRFiller.java +79 -0
- data/src/main/java/joons/JRImagePanel.java +141 -0
- data/src/main/java/joons/JRRecorder.java +183 -0
- data/src/main/java/joons/JRStatics.java +199 -0
- data/src/main/java/joons/JoonsRenderer.java +837 -0
- data/src/main/java/org/sunflow/AsciiFileSunflowAPI.java +98 -0
- data/src/main/java/org/sunflow/Benchmark.java +313 -0
- data/src/main/java/org/sunflow/BinaryFileSunflowAPI.java +228 -0
- data/src/main/java/org/sunflow/FileSunflowAPI.java +354 -0
- data/src/main/java/org/sunflow/PluginRegistry.java +322 -0
- data/src/main/java/org/sunflow/RealtimeBenchmark.java +125 -0
- data/src/main/java/org/sunflow/RenderObjectMap.java +344 -0
- data/src/main/java/org/sunflow/SunflowAPI.java +762 -0
- data/src/main/java/org/sunflow/SunflowAPIInterface.java +277 -0
- data/src/main/java/org/sunflow/core/AccelerationStructure.java +20 -0
- data/src/main/java/org/sunflow/core/AccelerationStructureFactory.java +36 -0
- data/src/main/java/org/sunflow/core/BucketOrder.java +21 -0
- data/src/main/java/org/sunflow/core/Camera.java +125 -0
- data/src/main/java/org/sunflow/core/CameraLens.java +29 -0
- data/src/main/java/org/sunflow/core/CausticPhotonMapInterface.java +15 -0
- data/src/main/java/org/sunflow/core/Display.java +78 -0
- data/src/main/java/org/sunflow/core/Filter.java +27 -0
- data/src/main/java/org/sunflow/core/GIEngine.java +42 -0
- data/src/main/java/org/sunflow/core/Geometry.java +157 -0
- data/src/main/java/org/sunflow/core/GlobalPhotonMapInterface.java +21 -0
- data/src/main/java/org/sunflow/core/ImageSampler.java +26 -0
- data/src/main/java/org/sunflow/core/Instance.java +224 -0
- data/src/main/java/org/sunflow/core/InstanceList.java +83 -0
- data/src/main/java/org/sunflow/core/IntersectionState.java +120 -0
- data/src/main/java/org/sunflow/core/LightSample.java +104 -0
- data/src/main/java/org/sunflow/core/LightServer.java +382 -0
- data/src/main/java/org/sunflow/core/LightSource.java +67 -0
- data/src/main/java/org/sunflow/core/Modifier.java +16 -0
- data/src/main/java/org/sunflow/core/Options.java +20 -0
- data/src/main/java/org/sunflow/core/ParameterList.java +758 -0
- data/src/main/java/org/sunflow/core/PhotonStore.java +62 -0
- data/src/main/java/org/sunflow/core/PrimitiveList.java +70 -0
- data/src/main/java/org/sunflow/core/Ray.java +219 -0
- data/src/main/java/org/sunflow/core/RenderObject.java +25 -0
- data/src/main/java/org/sunflow/core/Scene.java +377 -0
- data/src/main/java/org/sunflow/core/SceneParser.java +58 -0
- data/src/main/java/org/sunflow/core/Shader.java +30 -0
- data/src/main/java/org/sunflow/core/ShadingCache.java +84 -0
- data/src/main/java/org/sunflow/core/ShadingState.java +939 -0
- data/src/main/java/org/sunflow/core/Statistics.java +85 -0
- data/src/main/java/org/sunflow/core/Tesselatable.java +36 -0
- data/src/main/java/org/sunflow/core/Texture.java +128 -0
- data/src/main/java/org/sunflow/core/TextureCache.java +48 -0
- data/src/main/java/org/sunflow/core/accel/BoundingIntervalHierarchy.java +652 -0
- data/src/main/java/org/sunflow/core/accel/KDTree.java +833 -0
- data/src/main/java/org/sunflow/core/accel/NullAccelerator.java +30 -0
- data/src/main/java/org/sunflow/core/accel/UniformGrid.java +329 -0
- data/src/main/java/org/sunflow/core/bucket/BucketOrderFactory.java +26 -0
- data/src/main/java/org/sunflow/core/bucket/ColumnBucketOrder.java +21 -0
- data/src/main/java/org/sunflow/core/bucket/DiagonalBucketOrder.java +28 -0
- data/src/main/java/org/sunflow/core/bucket/HilbertBucketOrder.java +65 -0
- data/src/main/java/org/sunflow/core/bucket/InvertedBucketOrder.java +28 -0
- data/src/main/java/org/sunflow/core/bucket/RandomBucketOrder.java +49 -0
- data/src/main/java/org/sunflow/core/bucket/RowBucketOrder.java +21 -0
- data/src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java +43 -0
- data/src/main/java/org/sunflow/core/camera/FisheyeLens.java +25 -0
- data/src/main/java/org/sunflow/core/camera/PinholeLens.java +43 -0
- data/src/main/java/org/sunflow/core/camera/SphericalLens.java +22 -0
- data/src/main/java/org/sunflow/core/camera/ThinLens.java +107 -0
- data/src/main/java/org/sunflow/core/display/FastDisplay.java +119 -0
- data/src/main/java/org/sunflow/core/display/FileDisplay.java +83 -0
- data/src/main/java/org/sunflow/core/display/FrameDisplay.java +97 -0
- data/src/main/java/org/sunflow/core/display/ImgPipeDisplay.java +109 -0
- data/src/main/java/org/sunflow/core/filter/BlackmanHarrisFilter.java +28 -0
- data/src/main/java/org/sunflow/core/filter/BoxFilter.java +16 -0
- data/src/main/java/org/sunflow/core/filter/CatmullRomFilter.java +29 -0
- data/src/main/java/org/sunflow/core/filter/CubicBSpline.java +32 -0
- data/src/main/java/org/sunflow/core/filter/GaussianFilter.java +24 -0
- data/src/main/java/org/sunflow/core/filter/LanczosFilter.java +30 -0
- data/src/main/java/org/sunflow/core/filter/MitchellFilter.java +28 -0
- data/src/main/java/org/sunflow/core/filter/SincFilter.java +25 -0
- data/src/main/java/org/sunflow/core/filter/TriangleFilter.java +16 -0
- data/src/main/java/org/sunflow/core/gi/AmbientOcclusionGIEngine.java +57 -0
- data/src/main/java/org/sunflow/core/gi/FakeGIEngine.java +48 -0
- data/src/main/java/org/sunflow/core/gi/InstantGI.java +194 -0
- data/src/main/java/org/sunflow/core/gi/IrradianceCacheGIEngine.java +268 -0
- data/src/main/java/org/sunflow/core/gi/PathTracingGIEngine.java +65 -0
- data/src/main/java/org/sunflow/core/light/DirectionalSpotlight.java +103 -0
- data/src/main/java/org/sunflow/core/light/ImageBasedLight.java +303 -0
- data/src/main/java/org/sunflow/core/light/PointLight.java +72 -0
- data/src/main/java/org/sunflow/core/light/SphereLight.java +166 -0
- data/src/main/java/org/sunflow/core/light/SunSkyLight.java +362 -0
- data/src/main/java/org/sunflow/core/light/TriangleMeshLight.java +296 -0
- data/src/main/java/org/sunflow/core/modifiers/BumpMappingModifier.java +37 -0
- data/src/main/java/org/sunflow/core/modifiers/NormalMapModifier.java +34 -0
- data/src/main/java/org/sunflow/core/modifiers/PerlinModifier.java +80 -0
- data/src/main/java/org/sunflow/core/parser/Keyword.java +39 -0
- data/src/main/java/org/sunflow/core/parser/RA2Parser.java +107 -0
- data/src/main/java/org/sunflow/core/parser/RA3Parser.java +68 -0
- data/src/main/java/org/sunflow/core/parser/SCAbstractParser.java +299 -0
- data/src/main/java/org/sunflow/core/parser/SCAsciiParser.java +251 -0
- data/src/main/java/org/sunflow/core/parser/SCBinaryParser.java +156 -0
- data/src/main/java/org/sunflow/core/parser/SCParser.java +1403 -0
- data/src/main/java/org/sunflow/core/parser/ShaveRibParser.java +174 -0
- data/src/main/java/org/sunflow/core/parser/TriParser.java +79 -0
- data/src/main/java/org/sunflow/core/photonmap/CausticPhotonMap.java +429 -0
- data/src/main/java/org/sunflow/core/photonmap/GlobalPhotonMap.java +530 -0
- data/src/main/java/org/sunflow/core/photonmap/GridPhotonMap.java +308 -0
- data/src/main/java/org/sunflow/core/primitive/Background.java +55 -0
- data/src/main/java/org/sunflow/core/primitive/BanchoffSurface.java +100 -0
- data/src/main/java/org/sunflow/core/primitive/Box.java +210 -0
- data/src/main/java/org/sunflow/core/primitive/CornellBox.java +476 -0
- data/src/main/java/org/sunflow/core/primitive/CubeGrid.java +318 -0
- data/src/main/java/org/sunflow/core/primitive/Cylinder.java +104 -0
- data/src/main/java/org/sunflow/core/primitive/Hair.java +275 -0
- data/src/main/java/org/sunflow/core/primitive/JuliaFractal.java +266 -0
- data/src/main/java/org/sunflow/core/primitive/ParticleSurface.java +114 -0
- data/src/main/java/org/sunflow/core/primitive/Plane.java +163 -0
- data/src/main/java/org/sunflow/core/primitive/QuadMesh.java +413 -0
- data/src/main/java/org/sunflow/core/primitive/Sphere.java +101 -0
- data/src/main/java/org/sunflow/core/primitive/SphereFlake.java +234 -0
- data/src/main/java/org/sunflow/core/primitive/Torus.java +145 -0
- data/src/main/java/org/sunflow/core/primitive/TriangleMesh.java +849 -0
- data/src/main/java/org/sunflow/core/renderer/BucketRenderer.java +491 -0
- data/src/main/java/org/sunflow/core/renderer/MultipassRenderer.java +237 -0
- data/src/main/java/org/sunflow/core/renderer/ProgressiveRenderer.java +171 -0
- data/src/main/java/org/sunflow/core/renderer/SimpleRenderer.java +106 -0
- data/src/main/java/org/sunflow/core/shader/AmbientOcclusionShader.java +53 -0
- data/src/main/java/org/sunflow/core/shader/AnisotropicWardShader.java +216 -0
- data/src/main/java/org/sunflow/core/shader/ConstantShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/DiffuseShader.java +65 -0
- data/src/main/java/org/sunflow/core/shader/GlassShader.java +147 -0
- data/src/main/java/org/sunflow/core/shader/IDShader.java +27 -0
- data/src/main/java/org/sunflow/core/shader/MirrorShader.java +68 -0
- data/src/main/java/org/sunflow/core/shader/NormalShader.java +32 -0
- data/src/main/java/org/sunflow/core/shader/PhongShader.java +89 -0
- data/src/main/java/org/sunflow/core/shader/PrimIDShader.java +30 -0
- data/src/main/java/org/sunflow/core/shader/QuickGrayShader.java +63 -0
- data/src/main/java/org/sunflow/core/shader/ShinyDiffuseShader.java +98 -0
- data/src/main/java/org/sunflow/core/shader/SimpleShader.java +24 -0
- data/src/main/java/org/sunflow/core/shader/TexturedAmbientOcclusionShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedDiffuseShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedPhongShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedShinyDiffuseShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedWardShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/UVShader.java +27 -0
- data/src/main/java/org/sunflow/core/shader/UberShader.java +149 -0
- data/src/main/java/org/sunflow/core/shader/ViewCausticsShader.java +33 -0
- data/src/main/java/org/sunflow/core/shader/ViewGlobalPhotonsShader.java +25 -0
- data/src/main/java/org/sunflow/core/shader/ViewIrradianceShader.java +25 -0
- data/src/main/java/org/sunflow/core/shader/WireframeShader.java +83 -0
- data/src/main/java/org/sunflow/core/tesselatable/BezierMesh.java +254 -0
- data/src/main/java/org/sunflow/core/tesselatable/FileMesh.java +251 -0
- data/src/main/java/org/sunflow/core/tesselatable/Gumbo.java +1147 -0
- data/src/main/java/org/sunflow/core/tesselatable/Teapot.java +237 -0
- data/src/main/java/org/sunflow/image/Bitmap.java +15 -0
- data/src/main/java/org/sunflow/image/BitmapReader.java +39 -0
- data/src/main/java/org/sunflow/image/BitmapWriter.java +79 -0
- data/src/main/java/org/sunflow/image/BlackbodySpectrum.java +16 -0
- data/src/main/java/org/sunflow/image/ChromaticitySpectrum.java +55 -0
- data/src/main/java/org/sunflow/image/Color.java +374 -0
- data/src/main/java/org/sunflow/image/ColorEncoder.java +94 -0
- data/src/main/java/org/sunflow/image/ColorFactory.java +122 -0
- data/src/main/java/org/sunflow/image/ConstantSpectralCurve.java +21 -0
- data/src/main/java/org/sunflow/image/IrregularSpectralCurve.java +57 -0
- data/src/main/java/org/sunflow/image/RGBSpace.java +207 -0
- data/src/main/java/org/sunflow/image/RegularSpectralCurve.java +30 -0
- data/src/main/java/org/sunflow/image/SpectralCurve.java +118 -0
- data/src/main/java/org/sunflow/image/XYZColor.java +50 -0
- data/src/main/java/org/sunflow/image/formats/BitmapBlack.java +27 -0
- data/src/main/java/org/sunflow/image/formats/BitmapG8.java +36 -0
- data/src/main/java/org/sunflow/image/formats/BitmapGA8.java +30 -0
- data/src/main/java/org/sunflow/image/formats/BitmapRGB8.java +40 -0
- data/src/main/java/org/sunflow/image/formats/BitmapRGBA8.java +40 -0
- data/src/main/java/org/sunflow/image/formats/BitmapRGBE.java +60 -0
- data/src/main/java/org/sunflow/image/formats/BitmapXYZ.java +38 -0
- data/src/main/java/org/sunflow/image/formats/GenericBitmap.java +73 -0
- data/src/main/java/org/sunflow/image/readers/BMPBitmapReader.java +39 -0
- data/src/main/java/org/sunflow/image/readers/HDRBitmapReader.java +155 -0
- data/src/main/java/org/sunflow/image/readers/IGIBitmapReader.java +104 -0
- data/src/main/java/org/sunflow/image/readers/JPGBitmapReader.java +39 -0
- data/src/main/java/org/sunflow/image/readers/PNGBitmapReader.java +40 -0
- data/src/main/java/org/sunflow/image/readers/TGABitmapReader.java +141 -0
- data/src/main/java/org/sunflow/image/writers/EXRBitmapWriter.java +395 -0
- data/src/main/java/org/sunflow/image/writers/HDRBitmapWriter.java +54 -0
- data/src/main/java/org/sunflow/image/writers/IGIBitmapWriter.java +75 -0
- data/src/main/java/org/sunflow/image/writers/PNGBitmapWriter.java +39 -0
- data/src/main/java/org/sunflow/image/writers/TGABitmapWriter.java +63 -0
- data/src/main/java/org/sunflow/math/BoundingBox.java +340 -0
- data/src/main/java/org/sunflow/math/MathUtils.java +159 -0
- data/src/main/java/org/sunflow/math/Matrix4.java +573 -0
- data/src/main/java/org/sunflow/math/MovingMatrix4.java +119 -0
- data/src/main/java/org/sunflow/math/OrthoNormalBasis.java +110 -0
- data/src/main/java/org/sunflow/math/PerlinScalar.java +331 -0
- data/src/main/java/org/sunflow/math/PerlinVector.java +132 -0
- data/src/main/java/org/sunflow/math/Point2.java +36 -0
- data/src/main/java/org/sunflow/math/Point3.java +133 -0
- data/src/main/java/org/sunflow/math/QMC.java +209 -0
- data/src/main/java/org/sunflow/math/Solvers.java +142 -0
- data/src/main/java/org/sunflow/math/Vector3.java +197 -0
- data/src/main/java/org/sunflow/system/BenchmarkFramework.java +73 -0
- data/src/main/java/org/sunflow/system/BenchmarkTest.java +17 -0
- data/src/main/java/org/sunflow/system/ByteUtil.java +119 -0
- data/src/main/java/org/sunflow/system/FileUtils.java +27 -0
- data/src/main/java/org/sunflow/system/ImagePanel.java +282 -0
- data/src/main/java/org/sunflow/system/Memory.java +18 -0
- data/src/main/java/org/sunflow/system/Parser.java +162 -0
- data/src/main/java/org/sunflow/system/Plugins.java +142 -0
- data/src/main/java/org/sunflow/system/RenderGlobalsPanel.java +209 -0
- data/src/main/java/org/sunflow/system/SearchPath.java +67 -0
- data/src/main/java/org/sunflow/system/Timer.java +53 -0
- data/src/main/java/org/sunflow/system/UI.java +112 -0
- data/src/main/java/org/sunflow/system/UserInterface.java +46 -0
- data/src/main/java/org/sunflow/system/ui/ConsoleInterface.java +48 -0
- data/src/main/java/org/sunflow/system/ui/SilentInterface.java +28 -0
- data/src/main/java/org/sunflow/util/FastHashMap.java +220 -0
- data/src/main/java/org/sunflow/util/FloatArray.java +77 -0
- data/src/main/java/org/sunflow/util/IntArray.java +77 -0
- data/src/test/java/a_maintest.java +129 -0
- metadata +300 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
package org.sunflow.system;
|
|
2
|
+
|
|
3
|
+
import java.util.Locale;
|
|
4
|
+
|
|
5
|
+
import org.sunflow.system.ui.ConsoleInterface;
|
|
6
|
+
import org.sunflow.system.ui.SilentInterface;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Static singleton interface to a UserInterface object. This is set to a text
|
|
10
|
+
* console by default.
|
|
11
|
+
*/
|
|
12
|
+
public final class UI {
|
|
13
|
+
|
|
14
|
+
private static UserInterface ui = new ConsoleInterface();
|
|
15
|
+
private static boolean canceled = false;
|
|
16
|
+
private static int verbosity = 3;
|
|
17
|
+
|
|
18
|
+
public enum Module {
|
|
19
|
+
|
|
20
|
+
API, GEOM, HAIR, ACCEL, BCKT, IPR, LIGHT, GUI, SCENE, BENCH, TEX, IMG, DISP, QMC, SYS, USER, CAM,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public enum PrintLevel {
|
|
24
|
+
|
|
25
|
+
ERROR, WARN, INFO, DETAIL
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private UI() {
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Sets the active user interface implementation. Passing
|
|
33
|
+
* <code>null</code> silences printing completely.
|
|
34
|
+
*
|
|
35
|
+
* @param ui object to recieve all user interface calls
|
|
36
|
+
*/
|
|
37
|
+
public final static void set(UserInterface ui) {
|
|
38
|
+
if (ui == null) {
|
|
39
|
+
ui = new SilentInterface();
|
|
40
|
+
}
|
|
41
|
+
UI.ui = ui;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public final static void verbosity(int verbosity) {
|
|
45
|
+
UI.verbosity = verbosity;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public final static String formatOutput(Module m, PrintLevel level, String s) {
|
|
49
|
+
return String.format("%-5s %-6s: %s", m.name(), level.name().toLowerCase(Locale.ENGLISH), s);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public final static synchronized void printDetailed(Module m, String s, Object... args) {
|
|
53
|
+
if (verbosity > 3) {
|
|
54
|
+
ui.print(m, PrintLevel.DETAIL, String.format(s, args));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public final static synchronized void printInfo(Module m, String s, Object... args) {
|
|
59
|
+
if (verbosity > 2) {
|
|
60
|
+
ui.print(m, PrintLevel.INFO, String.format(s, args));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public final static synchronized void printWarning(Module m, String s, Object... args) {
|
|
65
|
+
if (verbosity > 1) {
|
|
66
|
+
ui.print(m, PrintLevel.WARN, String.format(s, args));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public final static synchronized void printError(Module m, String s, Object... args) {
|
|
71
|
+
if (verbosity > 0) {
|
|
72
|
+
ui.print(m, PrintLevel.ERROR, String.format(s, args));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public final static synchronized void taskStart(String s, int min, int max) {
|
|
77
|
+
ui.taskStart(s, min, max);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public final static synchronized void taskUpdate(int current) {
|
|
81
|
+
ui.taskUpdate(current);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public final static synchronized void taskStop() {
|
|
85
|
+
ui.taskStop();
|
|
86
|
+
// reset canceled status
|
|
87
|
+
// this assume the parent application will deal with it immediately
|
|
88
|
+
canceled = false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Cancel the currently active task. This forces the application to abort as
|
|
93
|
+
* soon as possible.
|
|
94
|
+
*/
|
|
95
|
+
public final static synchronized void taskCancel() {
|
|
96
|
+
printInfo(Module.GUI, "Abort requested by the user ...");
|
|
97
|
+
canceled = true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Check to see if the current task should be aborted.
|
|
102
|
+
*
|
|
103
|
+
* @return <code>true</code> if the current task should be stopped,
|
|
104
|
+
* <code>false</code> otherwise
|
|
105
|
+
*/
|
|
106
|
+
public final static synchronized boolean taskCanceled() {
|
|
107
|
+
if (canceled) {
|
|
108
|
+
printInfo(Module.GUI, "Abort request noticed by the current task");
|
|
109
|
+
}
|
|
110
|
+
return canceled;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package org.sunflow.system;
|
|
2
|
+
|
|
3
|
+
import org.sunflow.system.UI.Module;
|
|
4
|
+
import org.sunflow.system.UI.PrintLevel;
|
|
5
|
+
|
|
6
|
+
public interface UserInterface {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Displays some information to the user from the specified module with the
|
|
10
|
+
* specified print level. A user interface is free to show or ignore any
|
|
11
|
+
* message. Level filtering is done in the core and shouldn't be
|
|
12
|
+
* re-implemented by the user interface. All messages will be short enough
|
|
13
|
+
* to fit on one line.
|
|
14
|
+
*
|
|
15
|
+
* @param m module the message came from
|
|
16
|
+
* @param level seriousness of the message
|
|
17
|
+
* @param s string to display
|
|
18
|
+
*/
|
|
19
|
+
void print(Module m, PrintLevel level, String s);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Prepare a progress bar representing a lengthy task. The actual progress
|
|
23
|
+
* is first shown by the call to update and closed when update is closed
|
|
24
|
+
* with the max value. It is currently not possible to nest calls to
|
|
25
|
+
* setTask, so only one task needs to be tracked at a time.
|
|
26
|
+
*
|
|
27
|
+
* @param s desriptive string
|
|
28
|
+
* @param min minimum value of the task
|
|
29
|
+
* @param max maximum value of the task
|
|
30
|
+
*/
|
|
31
|
+
void taskStart(String s, int min, int max);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Updates the current progress bar to a value between the current min and
|
|
35
|
+
* max. When min or max are passed the progressed bar is shown or hidden
|
|
36
|
+
* respectively.
|
|
37
|
+
*
|
|
38
|
+
* @param current current value of the task in progress.
|
|
39
|
+
*/
|
|
40
|
+
void taskUpdate(int current);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Closes the current progress bar to indicate the task is over
|
|
44
|
+
*/
|
|
45
|
+
void taskStop();
|
|
46
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
package org.sunflow.system.ui;
|
|
2
|
+
|
|
3
|
+
import org.sunflow.system.UI;
|
|
4
|
+
import org.sunflow.system.UserInterface;
|
|
5
|
+
import org.sunflow.system.UI.Module;
|
|
6
|
+
import org.sunflow.system.UI.PrintLevel;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Basic console implementation of a user interface.
|
|
10
|
+
*/
|
|
11
|
+
public class ConsoleInterface implements UserInterface {
|
|
12
|
+
|
|
13
|
+
private int min;
|
|
14
|
+
private int max;
|
|
15
|
+
private float invP;
|
|
16
|
+
private String task;
|
|
17
|
+
private int lastP;
|
|
18
|
+
|
|
19
|
+
public ConsoleInterface() {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public void print(Module m, PrintLevel level, String s) {
|
|
24
|
+
System.err.println(UI.formatOutput(m, level, s));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Override
|
|
28
|
+
public void taskStart(String s, int min, int max) {
|
|
29
|
+
task = s;
|
|
30
|
+
this.min = min;
|
|
31
|
+
this.max = max;
|
|
32
|
+
lastP = -1;
|
|
33
|
+
invP = 100.0f / (max - min);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Override
|
|
37
|
+
public void taskUpdate(int current) {
|
|
38
|
+
int p = (min == max) ? 0 : (int) ((current - min) * invP);
|
|
39
|
+
if (p != lastP) {
|
|
40
|
+
System.err.print(task + " [" + (lastP = p) + "%]\r");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public void taskStop() {
|
|
46
|
+
System.err.print(" \r");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package org.sunflow.system.ui;
|
|
2
|
+
|
|
3
|
+
import org.sunflow.system.UserInterface;
|
|
4
|
+
import org.sunflow.system.UI.Module;
|
|
5
|
+
import org.sunflow.system.UI.PrintLevel;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Null implementation of a user interface. This is usefull to silence the
|
|
9
|
+
* output.
|
|
10
|
+
*/
|
|
11
|
+
public class SilentInterface implements UserInterface {
|
|
12
|
+
|
|
13
|
+
@Override
|
|
14
|
+
public void print(Module m, PrintLevel level, String s) {
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Override
|
|
18
|
+
public void taskStart(String s, int min, int max) {
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Override
|
|
22
|
+
public void taskUpdate(int current) {
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Override
|
|
26
|
+
public void taskStop() {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
package org.sunflow.util;
|
|
2
|
+
|
|
3
|
+
import java.util.Iterator;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fast hash map implementation which uses array storage along with quadratic
|
|
7
|
+
* probing to resolve collisions. The capacity is doubled when the load goes
|
|
8
|
+
* beyond 50% and is halved when the load drops below 20%.
|
|
9
|
+
*
|
|
10
|
+
* @param <K>
|
|
11
|
+
* @param <V>
|
|
12
|
+
*/
|
|
13
|
+
public class FastHashMap<K, V> implements Iterable<FastHashMap.Entry<K, V>> {
|
|
14
|
+
|
|
15
|
+
private static final int MIN_SIZE = 4;
|
|
16
|
+
|
|
17
|
+
public static class Entry<K, V> {
|
|
18
|
+
|
|
19
|
+
private final K k;
|
|
20
|
+
private V v;
|
|
21
|
+
|
|
22
|
+
private Entry(K k, V v) {
|
|
23
|
+
this.k = k;
|
|
24
|
+
this.v = v;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private boolean isRemoved() {
|
|
28
|
+
return v == null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private void remove() {
|
|
32
|
+
v = null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public K getKey() {
|
|
36
|
+
return k;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public V getValue() {
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
private Entry<K, V>[] entries;
|
|
44
|
+
private int size;
|
|
45
|
+
|
|
46
|
+
public FastHashMap() {
|
|
47
|
+
clear();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public final void clear() {
|
|
51
|
+
size = 0;
|
|
52
|
+
entries = alloc(MIN_SIZE);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public V put(K k, V v) {
|
|
56
|
+
int hash = k.hashCode(), t = 0;
|
|
57
|
+
int pos = entries.length; // mark invalid position
|
|
58
|
+
for (;;) {
|
|
59
|
+
hash &= entries.length - 1;
|
|
60
|
+
if (entries[hash] == null) {
|
|
61
|
+
break; // done probing
|
|
62
|
+
} else if (entries[hash].isRemoved() && pos == entries.length) {
|
|
63
|
+
pos = hash; // store, but keep searching
|
|
64
|
+
} else if (entries[hash].k.equals(k)) {
|
|
65
|
+
// update entry
|
|
66
|
+
V old = entries[hash].v;
|
|
67
|
+
entries[hash].v = v;
|
|
68
|
+
return old;
|
|
69
|
+
}
|
|
70
|
+
t++;
|
|
71
|
+
hash += t;
|
|
72
|
+
}
|
|
73
|
+
// did we find a spot for insertion among the deleted values ?
|
|
74
|
+
if (pos < entries.length) {
|
|
75
|
+
hash = pos;
|
|
76
|
+
}
|
|
77
|
+
entries[hash] = new Entry<>(k, v);
|
|
78
|
+
size++;
|
|
79
|
+
if (size * 2 > entries.length) {
|
|
80
|
+
resize(entries.length * 2);
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public V get(K k) {
|
|
86
|
+
int hash = k.hashCode(), t = 0;
|
|
87
|
+
for (;;) {
|
|
88
|
+
hash &= entries.length - 1;
|
|
89
|
+
if (entries[hash] == null) {
|
|
90
|
+
return null;
|
|
91
|
+
} else if (!entries[hash].isRemoved() && entries[hash].k.equals(k)) {
|
|
92
|
+
return entries[hash].v;
|
|
93
|
+
}
|
|
94
|
+
t++;
|
|
95
|
+
hash += t;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public boolean containsKey(K k) {
|
|
100
|
+
int hash = k.hashCode(), t = 0;
|
|
101
|
+
for (;;) {
|
|
102
|
+
hash &= entries.length - 1;
|
|
103
|
+
if (entries[hash] == null) {
|
|
104
|
+
return false;
|
|
105
|
+
} else if (!entries[hash].isRemoved() && entries[hash].k.equals(k)) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
t++;
|
|
109
|
+
hash += t;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public void remove(K k) {
|
|
114
|
+
int hash = k.hashCode(), t = 0;
|
|
115
|
+
for (;;) {
|
|
116
|
+
hash &= entries.length - 1;
|
|
117
|
+
if (entries[hash] == null) {
|
|
118
|
+
return; // not found, return
|
|
119
|
+
} else if (!entries[hash].isRemoved() && entries[hash].k.equals(k)) {
|
|
120
|
+
entries[hash].remove(); // flag as removed
|
|
121
|
+
size--;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
t++;
|
|
125
|
+
hash += t;
|
|
126
|
+
}
|
|
127
|
+
// do we need to shrink?
|
|
128
|
+
if (entries.length > MIN_SIZE && size * 10 < 2 * entries.length) {
|
|
129
|
+
resize(entries.length / 2);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Resize internal storage to the specified capacity. The capacity must be a
|
|
135
|
+
* power of two.
|
|
136
|
+
*
|
|
137
|
+
* @param capacity new capacity for the internal array
|
|
138
|
+
*/
|
|
139
|
+
private void resize(int capacity) {
|
|
140
|
+
assert (capacity & (capacity - 1)) == 0;
|
|
141
|
+
assert capacity >= MIN_SIZE;
|
|
142
|
+
Entry<K, V>[] newentries = alloc(capacity);
|
|
143
|
+
for (Entry<K, V> e : entries) {
|
|
144
|
+
if (e == null || e.isRemoved()) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
int hash = e.k.hashCode(), t = 0;
|
|
148
|
+
for (;;) {
|
|
149
|
+
hash &= newentries.length - 1;
|
|
150
|
+
if (newentries[hash] == null) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
assert !newentries[hash].k.equals(e.k);
|
|
154
|
+
t++;
|
|
155
|
+
hash += t;
|
|
156
|
+
}
|
|
157
|
+
newentries[hash] = new Entry<>(e.k, e.v);
|
|
158
|
+
}
|
|
159
|
+
// copy new entries over old ones
|
|
160
|
+
entries = newentries;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Wrap the entry array allocation because it requires silencing some
|
|
165
|
+
* generics warnings.
|
|
166
|
+
*
|
|
167
|
+
* @param size number of elements to allocate
|
|
168
|
+
* @return
|
|
169
|
+
*/
|
|
170
|
+
@SuppressWarnings("unchecked")
|
|
171
|
+
private Entry<K, V>[] alloc(int size) {
|
|
172
|
+
return new Entry[size];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private class EntryIterator implements Iterator<Entry<K, V>> {
|
|
176
|
+
|
|
177
|
+
private int index;
|
|
178
|
+
|
|
179
|
+
private EntryIterator() {
|
|
180
|
+
index = 0;
|
|
181
|
+
if (!readable()) {
|
|
182
|
+
inc();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private boolean readable() {
|
|
187
|
+
return !(entries[index] == null || entries[index].isRemoved());
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private void inc() {
|
|
191
|
+
do {
|
|
192
|
+
index++;
|
|
193
|
+
} while (hasNext() && !readable());
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
@Override
|
|
197
|
+
public boolean hasNext() {
|
|
198
|
+
return index < entries.length;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@Override
|
|
202
|
+
public Entry<K, V> next() {
|
|
203
|
+
try {
|
|
204
|
+
return entries[index];
|
|
205
|
+
} finally {
|
|
206
|
+
inc();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@Override
|
|
211
|
+
public void remove() {
|
|
212
|
+
throw new UnsupportedOperationException();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@Override
|
|
217
|
+
public Iterator<Entry<K, V>> iterator() {
|
|
218
|
+
return new EntryIterator();
|
|
219
|
+
}
|
|
220
|
+
}
|