joonsrenderer 1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +53 -0
  3. data/.mvn/extensions.xml +8 -0
  4. data/CHANGELOG.md +2 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE +674 -0
  7. data/README.md +2 -0
  8. data/Rakefile +43 -0
  9. data/docs/.gitignore +6 -0
  10. data/docs/_config.yml +20 -0
  11. data/docs/_includes/footer.html +38 -0
  12. data/docs/_includes/head.html +15 -0
  13. data/docs/_includes/header.html +27 -0
  14. data/docs/_includes/icon-github.html +1 -0
  15. data/docs/_includes/icon-github.svg +1 -0
  16. data/docs/_includes/icon-twitter.html +1 -0
  17. data/docs/_includes/icon-twitter.svg +1 -0
  18. data/docs/_layouts/default.html +20 -0
  19. data/docs/_layouts/page.html +14 -0
  20. data/docs/_layouts/post.html +15 -0
  21. data/docs/_posts/2017-01-08-animated_ray_tracing.md +72 -0
  22. data/docs/_posts/2017-01-08-welcome.md +78 -0
  23. data/docs/_sass/_base.scss +206 -0
  24. data/docs/_sass/_layout.scss +242 -0
  25. data/docs/_sass/_syntax-highlighting.scss +71 -0
  26. data/docs/about.md +12 -0
  27. data/docs/assets/Animation.ogv +0 -0
  28. data/docs/assets/Animation.png +0 -0
  29. data/docs/assets/basic.png +0 -0
  30. data/docs/assets/basic_traced.png +0 -0
  31. data/docs/css/main.scss +38 -0
  32. data/docs/favicon.ico +0 -0
  33. data/docs/feed.xml +30 -0
  34. data/docs/index.html +38 -0
  35. data/joonsrenderer.gemspec +23 -0
  36. data/lib/joonsrenderer.rb +12 -0
  37. data/lib/joonsrenderer/version.rb +3 -0
  38. data/pom.rb +75 -0
  39. data/pom.xml +163 -0
  40. data/src/main/java/SunflowGUI.java +1354 -0
  41. data/src/main/java/joons/JRFiller.java +79 -0
  42. data/src/main/java/joons/JRImagePanel.java +141 -0
  43. data/src/main/java/joons/JRRecorder.java +183 -0
  44. data/src/main/java/joons/JRStatics.java +199 -0
  45. data/src/main/java/joons/JoonsRenderer.java +837 -0
  46. data/src/main/java/org/sunflow/AsciiFileSunflowAPI.java +98 -0
  47. data/src/main/java/org/sunflow/Benchmark.java +313 -0
  48. data/src/main/java/org/sunflow/BinaryFileSunflowAPI.java +228 -0
  49. data/src/main/java/org/sunflow/FileSunflowAPI.java +354 -0
  50. data/src/main/java/org/sunflow/PluginRegistry.java +322 -0
  51. data/src/main/java/org/sunflow/RealtimeBenchmark.java +125 -0
  52. data/src/main/java/org/sunflow/RenderObjectMap.java +344 -0
  53. data/src/main/java/org/sunflow/SunflowAPI.java +762 -0
  54. data/src/main/java/org/sunflow/SunflowAPIInterface.java +277 -0
  55. data/src/main/java/org/sunflow/core/AccelerationStructure.java +20 -0
  56. data/src/main/java/org/sunflow/core/AccelerationStructureFactory.java +36 -0
  57. data/src/main/java/org/sunflow/core/BucketOrder.java +21 -0
  58. data/src/main/java/org/sunflow/core/Camera.java +125 -0
  59. data/src/main/java/org/sunflow/core/CameraLens.java +29 -0
  60. data/src/main/java/org/sunflow/core/CausticPhotonMapInterface.java +15 -0
  61. data/src/main/java/org/sunflow/core/Display.java +78 -0
  62. data/src/main/java/org/sunflow/core/Filter.java +27 -0
  63. data/src/main/java/org/sunflow/core/GIEngine.java +42 -0
  64. data/src/main/java/org/sunflow/core/Geometry.java +157 -0
  65. data/src/main/java/org/sunflow/core/GlobalPhotonMapInterface.java +21 -0
  66. data/src/main/java/org/sunflow/core/ImageSampler.java +26 -0
  67. data/src/main/java/org/sunflow/core/Instance.java +224 -0
  68. data/src/main/java/org/sunflow/core/InstanceList.java +83 -0
  69. data/src/main/java/org/sunflow/core/IntersectionState.java +120 -0
  70. data/src/main/java/org/sunflow/core/LightSample.java +104 -0
  71. data/src/main/java/org/sunflow/core/LightServer.java +382 -0
  72. data/src/main/java/org/sunflow/core/LightSource.java +67 -0
  73. data/src/main/java/org/sunflow/core/Modifier.java +16 -0
  74. data/src/main/java/org/sunflow/core/Options.java +20 -0
  75. data/src/main/java/org/sunflow/core/ParameterList.java +758 -0
  76. data/src/main/java/org/sunflow/core/PhotonStore.java +62 -0
  77. data/src/main/java/org/sunflow/core/PrimitiveList.java +70 -0
  78. data/src/main/java/org/sunflow/core/Ray.java +219 -0
  79. data/src/main/java/org/sunflow/core/RenderObject.java +25 -0
  80. data/src/main/java/org/sunflow/core/Scene.java +377 -0
  81. data/src/main/java/org/sunflow/core/SceneParser.java +58 -0
  82. data/src/main/java/org/sunflow/core/Shader.java +30 -0
  83. data/src/main/java/org/sunflow/core/ShadingCache.java +84 -0
  84. data/src/main/java/org/sunflow/core/ShadingState.java +939 -0
  85. data/src/main/java/org/sunflow/core/Statistics.java +85 -0
  86. data/src/main/java/org/sunflow/core/Tesselatable.java +36 -0
  87. data/src/main/java/org/sunflow/core/Texture.java +128 -0
  88. data/src/main/java/org/sunflow/core/TextureCache.java +48 -0
  89. data/src/main/java/org/sunflow/core/accel/BoundingIntervalHierarchy.java +652 -0
  90. data/src/main/java/org/sunflow/core/accel/KDTree.java +833 -0
  91. data/src/main/java/org/sunflow/core/accel/NullAccelerator.java +30 -0
  92. data/src/main/java/org/sunflow/core/accel/UniformGrid.java +329 -0
  93. data/src/main/java/org/sunflow/core/bucket/BucketOrderFactory.java +26 -0
  94. data/src/main/java/org/sunflow/core/bucket/ColumnBucketOrder.java +21 -0
  95. data/src/main/java/org/sunflow/core/bucket/DiagonalBucketOrder.java +28 -0
  96. data/src/main/java/org/sunflow/core/bucket/HilbertBucketOrder.java +65 -0
  97. data/src/main/java/org/sunflow/core/bucket/InvertedBucketOrder.java +28 -0
  98. data/src/main/java/org/sunflow/core/bucket/RandomBucketOrder.java +49 -0
  99. data/src/main/java/org/sunflow/core/bucket/RowBucketOrder.java +21 -0
  100. data/src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java +43 -0
  101. data/src/main/java/org/sunflow/core/camera/FisheyeLens.java +25 -0
  102. data/src/main/java/org/sunflow/core/camera/PinholeLens.java +43 -0
  103. data/src/main/java/org/sunflow/core/camera/SphericalLens.java +22 -0
  104. data/src/main/java/org/sunflow/core/camera/ThinLens.java +107 -0
  105. data/src/main/java/org/sunflow/core/display/FastDisplay.java +119 -0
  106. data/src/main/java/org/sunflow/core/display/FileDisplay.java +83 -0
  107. data/src/main/java/org/sunflow/core/display/FrameDisplay.java +97 -0
  108. data/src/main/java/org/sunflow/core/display/ImgPipeDisplay.java +109 -0
  109. data/src/main/java/org/sunflow/core/filter/BlackmanHarrisFilter.java +28 -0
  110. data/src/main/java/org/sunflow/core/filter/BoxFilter.java +16 -0
  111. data/src/main/java/org/sunflow/core/filter/CatmullRomFilter.java +29 -0
  112. data/src/main/java/org/sunflow/core/filter/CubicBSpline.java +32 -0
  113. data/src/main/java/org/sunflow/core/filter/GaussianFilter.java +24 -0
  114. data/src/main/java/org/sunflow/core/filter/LanczosFilter.java +30 -0
  115. data/src/main/java/org/sunflow/core/filter/MitchellFilter.java +28 -0
  116. data/src/main/java/org/sunflow/core/filter/SincFilter.java +25 -0
  117. data/src/main/java/org/sunflow/core/filter/TriangleFilter.java +16 -0
  118. data/src/main/java/org/sunflow/core/gi/AmbientOcclusionGIEngine.java +57 -0
  119. data/src/main/java/org/sunflow/core/gi/FakeGIEngine.java +48 -0
  120. data/src/main/java/org/sunflow/core/gi/InstantGI.java +194 -0
  121. data/src/main/java/org/sunflow/core/gi/IrradianceCacheGIEngine.java +268 -0
  122. data/src/main/java/org/sunflow/core/gi/PathTracingGIEngine.java +65 -0
  123. data/src/main/java/org/sunflow/core/light/DirectionalSpotlight.java +103 -0
  124. data/src/main/java/org/sunflow/core/light/ImageBasedLight.java +303 -0
  125. data/src/main/java/org/sunflow/core/light/PointLight.java +72 -0
  126. data/src/main/java/org/sunflow/core/light/SphereLight.java +166 -0
  127. data/src/main/java/org/sunflow/core/light/SunSkyLight.java +362 -0
  128. data/src/main/java/org/sunflow/core/light/TriangleMeshLight.java +296 -0
  129. data/src/main/java/org/sunflow/core/modifiers/BumpMappingModifier.java +37 -0
  130. data/src/main/java/org/sunflow/core/modifiers/NormalMapModifier.java +34 -0
  131. data/src/main/java/org/sunflow/core/modifiers/PerlinModifier.java +80 -0
  132. data/src/main/java/org/sunflow/core/parser/Keyword.java +39 -0
  133. data/src/main/java/org/sunflow/core/parser/RA2Parser.java +107 -0
  134. data/src/main/java/org/sunflow/core/parser/RA3Parser.java +68 -0
  135. data/src/main/java/org/sunflow/core/parser/SCAbstractParser.java +299 -0
  136. data/src/main/java/org/sunflow/core/parser/SCAsciiParser.java +251 -0
  137. data/src/main/java/org/sunflow/core/parser/SCBinaryParser.java +156 -0
  138. data/src/main/java/org/sunflow/core/parser/SCParser.java +1403 -0
  139. data/src/main/java/org/sunflow/core/parser/ShaveRibParser.java +174 -0
  140. data/src/main/java/org/sunflow/core/parser/TriParser.java +79 -0
  141. data/src/main/java/org/sunflow/core/photonmap/CausticPhotonMap.java +429 -0
  142. data/src/main/java/org/sunflow/core/photonmap/GlobalPhotonMap.java +530 -0
  143. data/src/main/java/org/sunflow/core/photonmap/GridPhotonMap.java +308 -0
  144. data/src/main/java/org/sunflow/core/primitive/Background.java +55 -0
  145. data/src/main/java/org/sunflow/core/primitive/BanchoffSurface.java +100 -0
  146. data/src/main/java/org/sunflow/core/primitive/Box.java +210 -0
  147. data/src/main/java/org/sunflow/core/primitive/CornellBox.java +476 -0
  148. data/src/main/java/org/sunflow/core/primitive/CubeGrid.java +318 -0
  149. data/src/main/java/org/sunflow/core/primitive/Cylinder.java +104 -0
  150. data/src/main/java/org/sunflow/core/primitive/Hair.java +275 -0
  151. data/src/main/java/org/sunflow/core/primitive/JuliaFractal.java +266 -0
  152. data/src/main/java/org/sunflow/core/primitive/ParticleSurface.java +114 -0
  153. data/src/main/java/org/sunflow/core/primitive/Plane.java +163 -0
  154. data/src/main/java/org/sunflow/core/primitive/QuadMesh.java +413 -0
  155. data/src/main/java/org/sunflow/core/primitive/Sphere.java +101 -0
  156. data/src/main/java/org/sunflow/core/primitive/SphereFlake.java +234 -0
  157. data/src/main/java/org/sunflow/core/primitive/Torus.java +145 -0
  158. data/src/main/java/org/sunflow/core/primitive/TriangleMesh.java +849 -0
  159. data/src/main/java/org/sunflow/core/renderer/BucketRenderer.java +491 -0
  160. data/src/main/java/org/sunflow/core/renderer/MultipassRenderer.java +237 -0
  161. data/src/main/java/org/sunflow/core/renderer/ProgressiveRenderer.java +171 -0
  162. data/src/main/java/org/sunflow/core/renderer/SimpleRenderer.java +106 -0
  163. data/src/main/java/org/sunflow/core/shader/AmbientOcclusionShader.java +53 -0
  164. data/src/main/java/org/sunflow/core/shader/AnisotropicWardShader.java +216 -0
  165. data/src/main/java/org/sunflow/core/shader/ConstantShader.java +31 -0
  166. data/src/main/java/org/sunflow/core/shader/DiffuseShader.java +65 -0
  167. data/src/main/java/org/sunflow/core/shader/GlassShader.java +147 -0
  168. data/src/main/java/org/sunflow/core/shader/IDShader.java +27 -0
  169. data/src/main/java/org/sunflow/core/shader/MirrorShader.java +68 -0
  170. data/src/main/java/org/sunflow/core/shader/NormalShader.java +32 -0
  171. data/src/main/java/org/sunflow/core/shader/PhongShader.java +89 -0
  172. data/src/main/java/org/sunflow/core/shader/PrimIDShader.java +30 -0
  173. data/src/main/java/org/sunflow/core/shader/QuickGrayShader.java +63 -0
  174. data/src/main/java/org/sunflow/core/shader/ShinyDiffuseShader.java +98 -0
  175. data/src/main/java/org/sunflow/core/shader/SimpleShader.java +24 -0
  176. data/src/main/java/org/sunflow/core/shader/TexturedAmbientOcclusionShader.java +31 -0
  177. data/src/main/java/org/sunflow/core/shader/TexturedDiffuseShader.java +31 -0
  178. data/src/main/java/org/sunflow/core/shader/TexturedPhongShader.java +31 -0
  179. data/src/main/java/org/sunflow/core/shader/TexturedShinyDiffuseShader.java +31 -0
  180. data/src/main/java/org/sunflow/core/shader/TexturedWardShader.java +31 -0
  181. data/src/main/java/org/sunflow/core/shader/UVShader.java +27 -0
  182. data/src/main/java/org/sunflow/core/shader/UberShader.java +149 -0
  183. data/src/main/java/org/sunflow/core/shader/ViewCausticsShader.java +33 -0
  184. data/src/main/java/org/sunflow/core/shader/ViewGlobalPhotonsShader.java +25 -0
  185. data/src/main/java/org/sunflow/core/shader/ViewIrradianceShader.java +25 -0
  186. data/src/main/java/org/sunflow/core/shader/WireframeShader.java +83 -0
  187. data/src/main/java/org/sunflow/core/tesselatable/BezierMesh.java +254 -0
  188. data/src/main/java/org/sunflow/core/tesselatable/FileMesh.java +251 -0
  189. data/src/main/java/org/sunflow/core/tesselatable/Gumbo.java +1147 -0
  190. data/src/main/java/org/sunflow/core/tesselatable/Teapot.java +237 -0
  191. data/src/main/java/org/sunflow/image/Bitmap.java +15 -0
  192. data/src/main/java/org/sunflow/image/BitmapReader.java +39 -0
  193. data/src/main/java/org/sunflow/image/BitmapWriter.java +79 -0
  194. data/src/main/java/org/sunflow/image/BlackbodySpectrum.java +16 -0
  195. data/src/main/java/org/sunflow/image/ChromaticitySpectrum.java +55 -0
  196. data/src/main/java/org/sunflow/image/Color.java +374 -0
  197. data/src/main/java/org/sunflow/image/ColorEncoder.java +94 -0
  198. data/src/main/java/org/sunflow/image/ColorFactory.java +122 -0
  199. data/src/main/java/org/sunflow/image/ConstantSpectralCurve.java +21 -0
  200. data/src/main/java/org/sunflow/image/IrregularSpectralCurve.java +57 -0
  201. data/src/main/java/org/sunflow/image/RGBSpace.java +207 -0
  202. data/src/main/java/org/sunflow/image/RegularSpectralCurve.java +30 -0
  203. data/src/main/java/org/sunflow/image/SpectralCurve.java +118 -0
  204. data/src/main/java/org/sunflow/image/XYZColor.java +50 -0
  205. data/src/main/java/org/sunflow/image/formats/BitmapBlack.java +27 -0
  206. data/src/main/java/org/sunflow/image/formats/BitmapG8.java +36 -0
  207. data/src/main/java/org/sunflow/image/formats/BitmapGA8.java +30 -0
  208. data/src/main/java/org/sunflow/image/formats/BitmapRGB8.java +40 -0
  209. data/src/main/java/org/sunflow/image/formats/BitmapRGBA8.java +40 -0
  210. data/src/main/java/org/sunflow/image/formats/BitmapRGBE.java +60 -0
  211. data/src/main/java/org/sunflow/image/formats/BitmapXYZ.java +38 -0
  212. data/src/main/java/org/sunflow/image/formats/GenericBitmap.java +73 -0
  213. data/src/main/java/org/sunflow/image/readers/BMPBitmapReader.java +39 -0
  214. data/src/main/java/org/sunflow/image/readers/HDRBitmapReader.java +155 -0
  215. data/src/main/java/org/sunflow/image/readers/IGIBitmapReader.java +104 -0
  216. data/src/main/java/org/sunflow/image/readers/JPGBitmapReader.java +39 -0
  217. data/src/main/java/org/sunflow/image/readers/PNGBitmapReader.java +40 -0
  218. data/src/main/java/org/sunflow/image/readers/TGABitmapReader.java +141 -0
  219. data/src/main/java/org/sunflow/image/writers/EXRBitmapWriter.java +395 -0
  220. data/src/main/java/org/sunflow/image/writers/HDRBitmapWriter.java +54 -0
  221. data/src/main/java/org/sunflow/image/writers/IGIBitmapWriter.java +75 -0
  222. data/src/main/java/org/sunflow/image/writers/PNGBitmapWriter.java +39 -0
  223. data/src/main/java/org/sunflow/image/writers/TGABitmapWriter.java +63 -0
  224. data/src/main/java/org/sunflow/math/BoundingBox.java +340 -0
  225. data/src/main/java/org/sunflow/math/MathUtils.java +159 -0
  226. data/src/main/java/org/sunflow/math/Matrix4.java +573 -0
  227. data/src/main/java/org/sunflow/math/MovingMatrix4.java +119 -0
  228. data/src/main/java/org/sunflow/math/OrthoNormalBasis.java +110 -0
  229. data/src/main/java/org/sunflow/math/PerlinScalar.java +331 -0
  230. data/src/main/java/org/sunflow/math/PerlinVector.java +132 -0
  231. data/src/main/java/org/sunflow/math/Point2.java +36 -0
  232. data/src/main/java/org/sunflow/math/Point3.java +133 -0
  233. data/src/main/java/org/sunflow/math/QMC.java +209 -0
  234. data/src/main/java/org/sunflow/math/Solvers.java +142 -0
  235. data/src/main/java/org/sunflow/math/Vector3.java +197 -0
  236. data/src/main/java/org/sunflow/system/BenchmarkFramework.java +73 -0
  237. data/src/main/java/org/sunflow/system/BenchmarkTest.java +17 -0
  238. data/src/main/java/org/sunflow/system/ByteUtil.java +119 -0
  239. data/src/main/java/org/sunflow/system/FileUtils.java +27 -0
  240. data/src/main/java/org/sunflow/system/ImagePanel.java +282 -0
  241. data/src/main/java/org/sunflow/system/Memory.java +18 -0
  242. data/src/main/java/org/sunflow/system/Parser.java +162 -0
  243. data/src/main/java/org/sunflow/system/Plugins.java +142 -0
  244. data/src/main/java/org/sunflow/system/RenderGlobalsPanel.java +209 -0
  245. data/src/main/java/org/sunflow/system/SearchPath.java +67 -0
  246. data/src/main/java/org/sunflow/system/Timer.java +53 -0
  247. data/src/main/java/org/sunflow/system/UI.java +112 -0
  248. data/src/main/java/org/sunflow/system/UserInterface.java +46 -0
  249. data/src/main/java/org/sunflow/system/ui/ConsoleInterface.java +48 -0
  250. data/src/main/java/org/sunflow/system/ui/SilentInterface.java +28 -0
  251. data/src/main/java/org/sunflow/util/FastHashMap.java +220 -0
  252. data/src/main/java/org/sunflow/util/FloatArray.java +77 -0
  253. data/src/main/java/org/sunflow/util/IntArray.java +77 -0
  254. data/src/test/java/a_maintest.java +129 -0
  255. metadata +300 -0
@@ -0,0 +1,30 @@
1
+ package org.sunflow.core.accel;
2
+
3
+ import org.sunflow.core.AccelerationStructure;
4
+ import org.sunflow.core.IntersectionState;
5
+ import org.sunflow.core.PrimitiveList;
6
+ import org.sunflow.core.Ray;
7
+
8
+ public class NullAccelerator implements AccelerationStructure {
9
+
10
+ private PrimitiveList primitives;
11
+ private int n;
12
+
13
+ public NullAccelerator() {
14
+ primitives = null;
15
+ n = 0;
16
+ }
17
+
18
+ @Override
19
+ public void build(PrimitiveList primitives) {
20
+ this.primitives = primitives;
21
+ n = primitives.getNumPrimitives();
22
+ }
23
+
24
+ @Override
25
+ public void intersect(Ray r, IntersectionState state) {
26
+ for (int i = 0; i < n; i++) {
27
+ primitives.intersectPrimitive(r, i, state);
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,329 @@
1
+ package org.sunflow.core.accel;
2
+
3
+ import org.sunflow.core.AccelerationStructure;
4
+ import org.sunflow.core.IntersectionState;
5
+ import org.sunflow.core.PrimitiveList;
6
+ import org.sunflow.core.Ray;
7
+ import org.sunflow.math.BoundingBox;
8
+ import org.sunflow.math.MathUtils;
9
+ import org.sunflow.math.Vector3;
10
+ import org.sunflow.system.Timer;
11
+ import org.sunflow.system.UI;
12
+ import org.sunflow.system.UI.Module;
13
+ import org.sunflow.util.IntArray;
14
+
15
+ public final class UniformGrid implements AccelerationStructure {
16
+
17
+ private int nx, ny, nz;
18
+ private PrimitiveList primitives;
19
+ private BoundingBox bounds;
20
+ private int[][] cells;
21
+ private float voxelwx, voxelwy, voxelwz;
22
+ private float invVoxelwx, invVoxelwy, invVoxelwz;
23
+
24
+ public UniformGrid() {
25
+ nx = ny = nz = 0;
26
+ bounds = null;
27
+ cells = null;
28
+ voxelwx = voxelwy = voxelwz = 0;
29
+ invVoxelwx = invVoxelwy = invVoxelwz = 0;
30
+ }
31
+
32
+ @Override
33
+ public void build(PrimitiveList primitives) {
34
+ Timer t = new Timer();
35
+ t.start();
36
+ this.primitives = primitives;
37
+ int n = primitives.getNumPrimitives();
38
+ // compute bounds
39
+ bounds = primitives.getWorldBounds(null);
40
+ // create grid from number of objects
41
+ bounds.enlargeUlps();
42
+ Vector3 w = bounds.getExtents();
43
+ double s = Math.pow((w.x * w.y * w.z) / n, 1 / 3.0);
44
+ nx = MathUtils.clamp((int) ((w.x / s) + 0.5), 1, 128);
45
+ ny = MathUtils.clamp((int) ((w.y / s) + 0.5), 1, 128);
46
+ nz = MathUtils.clamp((int) ((w.z / s) + 0.5), 1, 128);
47
+ voxelwx = w.x / nx;
48
+ voxelwy = w.y / ny;
49
+ voxelwz = w.z / nz;
50
+ invVoxelwx = 1 / voxelwx;
51
+ invVoxelwy = 1 / voxelwy;
52
+ invVoxelwz = 1 / voxelwz;
53
+ UI.printDetailed(Module.ACCEL, "Creating grid: %dx%dx%d ...", nx, ny, nz);
54
+ IntArray[] buildCells = new IntArray[nx * ny * nz];
55
+ // add all objects into the grid cells they overlap
56
+ int[] imin = new int[3];
57
+ int[] imax = new int[3];
58
+ int numCellsPerObject = 0;
59
+ for (int i = 0; i < n; i++) {
60
+ getGridIndex(primitives.getPrimitiveBound(i, 0), primitives.getPrimitiveBound(i, 2), primitives.getPrimitiveBound(i, 4), imin);
61
+ getGridIndex(primitives.getPrimitiveBound(i, 1), primitives.getPrimitiveBound(i, 3), primitives.getPrimitiveBound(i, 5), imax);
62
+ for (int ix = imin[0]; ix <= imax[0]; ix++) {
63
+ for (int iy = imin[1]; iy <= imax[1]; iy++) {
64
+ for (int iz = imin[2]; iz <= imax[2]; iz++) {
65
+ int idx = ix + (nx * iy) + (nx * ny * iz);
66
+ if (buildCells[idx] == null) {
67
+ buildCells[idx] = new IntArray();
68
+ }
69
+ buildCells[idx].add(i);
70
+ numCellsPerObject++;
71
+ }
72
+ }
73
+ }
74
+ }
75
+ UI.printDetailed(Module.ACCEL, "Building cells ...");
76
+ int numEmpty = 0;
77
+ int numInFull = 0;
78
+ cells = new int[nx * ny * nz][];
79
+ int i = 0;
80
+ for (IntArray cell : buildCells) {
81
+ if (cell != null) {
82
+ if (cell.getSize() == 0) {
83
+ numEmpty++;
84
+ cell = null;
85
+ } else {
86
+ cells[i] = cell.trim();
87
+ numInFull += cell.getSize();
88
+ }
89
+ } else {
90
+ numEmpty++;
91
+ }
92
+ i++;
93
+ }
94
+ t.end();
95
+ UI.printDetailed(Module.ACCEL, "Uniform grid statistics:");
96
+ UI.printDetailed(Module.ACCEL, " * Grid cells: %d", cells.length);
97
+ UI.printDetailed(Module.ACCEL, " * Used cells: %d", cells.length - numEmpty);
98
+ UI.printDetailed(Module.ACCEL, " * Empty cells: %d", numEmpty);
99
+ UI.printDetailed(Module.ACCEL, " * Occupancy: %.2f%%", 100.0 * (cells.length - numEmpty) / cells.length);
100
+ UI.printDetailed(Module.ACCEL, " * Objects/Cell: %.2f", (double) numInFull / (double) cells.length);
101
+ UI.printDetailed(Module.ACCEL, " * Objects/Used Cell: %.2f", (double) numInFull / (double) (cells.length - numEmpty));
102
+ UI.printDetailed(Module.ACCEL, " * Cells/Object: %.2f", (double) numCellsPerObject / (double) n);
103
+ UI.printDetailed(Module.ACCEL, " * Build time: %s", t.toString());
104
+ }
105
+
106
+ @Override
107
+ public void intersect(Ray r, IntersectionState state) {
108
+ float intervalMin = r.getMin();
109
+ float intervalMax = r.getMax();
110
+ float orgX = r.ox;
111
+ float dirX = r.dx, invDirX = 1 / dirX;
112
+ float t1, t2;
113
+ t1 = (bounds.getMinimum().x - orgX) * invDirX;
114
+ t2 = (bounds.getMaximum().x - orgX) * invDirX;
115
+ if (invDirX > 0) {
116
+ if (t1 > intervalMin) {
117
+ intervalMin = t1;
118
+ }
119
+ if (t2 < intervalMax) {
120
+ intervalMax = t2;
121
+ }
122
+ } else {
123
+ if (t2 > intervalMin) {
124
+ intervalMin = t2;
125
+ }
126
+ if (t1 < intervalMax) {
127
+ intervalMax = t1;
128
+ }
129
+ }
130
+ if (intervalMin > intervalMax) {
131
+ return;
132
+ }
133
+ float orgY = r.oy;
134
+ float dirY = r.dy, invDirY = 1 / dirY;
135
+ t1 = (bounds.getMinimum().y - orgY) * invDirY;
136
+ t2 = (bounds.getMaximum().y - orgY) * invDirY;
137
+ if (invDirY > 0) {
138
+ if (t1 > intervalMin) {
139
+ intervalMin = t1;
140
+ }
141
+ if (t2 < intervalMax) {
142
+ intervalMax = t2;
143
+ }
144
+ } else {
145
+ if (t2 > intervalMin) {
146
+ intervalMin = t2;
147
+ }
148
+ if (t1 < intervalMax) {
149
+ intervalMax = t1;
150
+ }
151
+ }
152
+ if (intervalMin > intervalMax) {
153
+ return;
154
+ }
155
+ float orgZ = r.oz;
156
+ float dirZ = r.dz, invDirZ = 1 / dirZ;
157
+ t1 = (bounds.getMinimum().z - orgZ) * invDirZ;
158
+ t2 = (bounds.getMaximum().z - orgZ) * invDirZ;
159
+ if (invDirZ > 0) {
160
+ if (t1 > intervalMin) {
161
+ intervalMin = t1;
162
+ }
163
+ if (t2 < intervalMax) {
164
+ intervalMax = t2;
165
+ }
166
+ } else {
167
+ if (t2 > intervalMin) {
168
+ intervalMin = t2;
169
+ }
170
+ if (t1 < intervalMax) {
171
+ intervalMax = t1;
172
+ }
173
+ }
174
+ if (intervalMin > intervalMax) {
175
+ return;
176
+ }
177
+ // box is hit at [intervalMin, intervalMax]
178
+ orgX += intervalMin * dirX;
179
+ orgY += intervalMin * dirY;
180
+ orgZ += intervalMin * dirZ;
181
+ // locate starting point inside the grid
182
+ // and set up 3D-DDA vars
183
+ int indxX, indxY, indxZ;
184
+ int stepX, stepY, stepZ;
185
+ int stopX, stopY, stopZ;
186
+ float deltaX, deltaY, deltaZ;
187
+ float tnextX, tnextY, tnextZ;
188
+ // stepping factors along X
189
+ indxX = (int) ((orgX - bounds.getMinimum().x) * invVoxelwx);
190
+ if (indxX < 0) {
191
+ indxX = 0;
192
+ } else if (indxX >= nx) {
193
+ indxX = nx - 1;
194
+ }
195
+ if (Math.abs(dirX) < 1e-6f) {
196
+ stepX = 0;
197
+ stopX = indxX;
198
+ deltaX = 0;
199
+ tnextX = Float.POSITIVE_INFINITY;
200
+ } else if (dirX > 0) {
201
+ stepX = 1;
202
+ stopX = nx;
203
+ deltaX = voxelwx * invDirX;
204
+ tnextX = intervalMin + ((indxX + 1) * voxelwx + bounds.getMinimum().x - orgX) * invDirX;
205
+ } else {
206
+ stepX = -1;
207
+ stopX = -1;
208
+ deltaX = -voxelwx * invDirX;
209
+ tnextX = intervalMin + (indxX * voxelwx + bounds.getMinimum().x - orgX) * invDirX;
210
+ }
211
+ // stepping factors along Y
212
+ indxY = (int) ((orgY - bounds.getMinimum().y) * invVoxelwy);
213
+ if (indxY < 0) {
214
+ indxY = 0;
215
+ } else if (indxY >= ny) {
216
+ indxY = ny - 1;
217
+ }
218
+ if (Math.abs(dirY) < 1e-6f) {
219
+ stepY = 0;
220
+ stopY = indxY;
221
+ deltaY = 0;
222
+ tnextY = Float.POSITIVE_INFINITY;
223
+ } else if (dirY > 0) {
224
+ stepY = 1;
225
+ stopY = ny;
226
+ deltaY = voxelwy * invDirY;
227
+ tnextY = intervalMin + ((indxY + 1) * voxelwy + bounds.getMinimum().y - orgY) * invDirY;
228
+ } else {
229
+ stepY = -1;
230
+ stopY = -1;
231
+ deltaY = -voxelwy * invDirY;
232
+ tnextY = intervalMin + (indxY * voxelwy + bounds.getMinimum().y - orgY) * invDirY;
233
+ }
234
+ // stepping factors along Z
235
+ indxZ = (int) ((orgZ - bounds.getMinimum().z) * invVoxelwz);
236
+ if (indxZ < 0) {
237
+ indxZ = 0;
238
+ } else if (indxZ >= nz) {
239
+ indxZ = nz - 1;
240
+ }
241
+ if (Math.abs(dirZ) < 1e-6f) {
242
+ stepZ = 0;
243
+ stopZ = indxZ;
244
+ deltaZ = 0;
245
+ tnextZ = Float.POSITIVE_INFINITY;
246
+ } else if (dirZ > 0) {
247
+ stepZ = 1;
248
+ stopZ = nz;
249
+ deltaZ = voxelwz * invDirZ;
250
+ tnextZ = intervalMin + ((indxZ + 1) * voxelwz + bounds.getMinimum().z - orgZ) * invDirZ;
251
+ } else {
252
+ stepZ = -1;
253
+ stopZ = -1;
254
+ deltaZ = -voxelwz * invDirZ;
255
+ tnextZ = intervalMin + (indxZ * voxelwz + bounds.getMinimum().z - orgZ) * invDirZ;
256
+ }
257
+ int cellstepX = stepX;
258
+ int cellstepY = stepY * nx;
259
+ int cellstepZ = stepZ * ny * nx;
260
+ int cell = indxX + indxY * nx + indxZ * ny * nx;
261
+ // trace through the grid
262
+ for (;;) {
263
+ if (tnextX < tnextY && tnextX < tnextZ) {
264
+ if (cells[cell] != null) {
265
+ for (int i : cells[cell]) {
266
+ primitives.intersectPrimitive(r, i, state);
267
+ }
268
+ if (state.hit() && (r.getMax() < tnextX && r.getMax() < intervalMax)) {
269
+ return;
270
+ }
271
+ }
272
+ intervalMin = tnextX;
273
+ if (intervalMin > intervalMax) {
274
+ return;
275
+ }
276
+ indxX += stepX;
277
+ if (indxX == stopX) {
278
+ return;
279
+ }
280
+ tnextX += deltaX;
281
+ cell += cellstepX;
282
+ } else if (tnextY < tnextZ) {
283
+ if (cells[cell] != null) {
284
+ for (int i : cells[cell]) {
285
+ primitives.intersectPrimitive(r, i, state);
286
+ }
287
+ if (state.hit() && (r.getMax() < tnextY && r.getMax() < intervalMax)) {
288
+ return;
289
+ }
290
+ }
291
+ intervalMin = tnextY;
292
+ if (intervalMin > intervalMax) {
293
+ return;
294
+ }
295
+ indxY += stepY;
296
+ if (indxY == stopY) {
297
+ return;
298
+ }
299
+ tnextY += deltaY;
300
+ cell += cellstepY;
301
+ } else {
302
+ if (cells[cell] != null) {
303
+ for (int i : cells[cell]) {
304
+ primitives.intersectPrimitive(r, i, state);
305
+ }
306
+ if (state.hit() && (r.getMax() < tnextZ && r.getMax() < intervalMax)) {
307
+ return;
308
+ }
309
+ }
310
+ intervalMin = tnextZ;
311
+ if (intervalMin > intervalMax) {
312
+ return;
313
+ }
314
+ indxZ += stepZ;
315
+ if (indxZ == stopZ) {
316
+ return;
317
+ }
318
+ tnextZ += deltaZ;
319
+ cell += cellstepZ;
320
+ }
321
+ }
322
+ }
323
+
324
+ private void getGridIndex(float x, float y, float z, int[] i) {
325
+ i[0] = MathUtils.clamp((int) ((x - bounds.getMinimum().x) * invVoxelwx), 0, nx - 1);
326
+ i[1] = MathUtils.clamp((int) ((y - bounds.getMinimum().y) * invVoxelwy), 0, ny - 1);
327
+ i[2] = MathUtils.clamp((int) ((z - bounds.getMinimum().z) * invVoxelwz), 0, nz - 1);
328
+ }
329
+ }
@@ -0,0 +1,26 @@
1
+ package org.sunflow.core.bucket;
2
+
3
+ import org.sunflow.PluginRegistry;
4
+ import org.sunflow.core.BucketOrder;
5
+ import org.sunflow.system.UI;
6
+ import org.sunflow.system.UI.Module;
7
+
8
+ public class BucketOrderFactory {
9
+
10
+ public static BucketOrder create(String order) {
11
+ boolean flip = false;
12
+ if (order.startsWith("inverse") || order.startsWith("invert") || order.startsWith("reverse")) {
13
+ String[] tokens = order.split("\\s+");
14
+ if (tokens.length == 2) {
15
+ order = tokens[1];
16
+ flip = true;
17
+ }
18
+ }
19
+ BucketOrder o = PluginRegistry.BUCKET_ORDER_PLUGINS.createObject(order);
20
+ if (o == null) {
21
+ UI.printWarning(Module.BCKT, "Unrecognized bucket ordering: \"%s\" - using hilbert", order);
22
+ return create("hilbert");
23
+ }
24
+ return flip ? new InvertedBucketOrder(o) : o;
25
+ }
26
+ }
@@ -0,0 +1,21 @@
1
+ package org.sunflow.core.bucket;
2
+
3
+ import org.sunflow.core.BucketOrder;
4
+
5
+ public class ColumnBucketOrder implements BucketOrder {
6
+
7
+ @Override
8
+ public int[] getBucketSequence(int nbw, int nbh) {
9
+ int[] coords = new int[2 * nbw * nbh];
10
+ for (int i = 0; i < nbw * nbh; i++) {
11
+ int bx = i / nbh;
12
+ int by = i % nbh;
13
+ if ((bx & 1) == 1) {
14
+ by = nbh - 1 - by;
15
+ }
16
+ coords[2 * i + 0] = bx;
17
+ coords[2 * i + 1] = by;
18
+ }
19
+ return coords;
20
+ }
21
+ }
@@ -0,0 +1,28 @@
1
+ package org.sunflow.core.bucket;
2
+
3
+ import org.sunflow.core.BucketOrder;
4
+
5
+ public class DiagonalBucketOrder implements BucketOrder {
6
+
7
+ @Override
8
+ public int[] getBucketSequence(int nbw, int nbh) {
9
+ int[] coords = new int[2 * nbw * nbh];
10
+ int x = 0, y = 0, nx = 1, ny = 0;
11
+ for (int i = 0; i < nbw * nbh; i++) {
12
+ coords[2 * i + 0] = x;
13
+ coords[2 * i + 1] = y;
14
+ do {
15
+ if (y == ny) {
16
+ y = 0;
17
+ x = nx;
18
+ ny++;
19
+ nx++;
20
+ } else {
21
+ x--;
22
+ y++;
23
+ }
24
+ } while ((y >= nbh || x >= nbw) && i != (nbw * nbh - 1));
25
+ }
26
+ return coords;
27
+ }
28
+ }
@@ -0,0 +1,65 @@
1
+ package org.sunflow.core.bucket;
2
+
3
+ import org.sunflow.core.BucketOrder;
4
+
5
+ public class HilbertBucketOrder implements BucketOrder {
6
+
7
+ @Override
8
+ public int[] getBucketSequence(int nbw, int nbh) {
9
+ int hi = 0; // hilbert curve index
10
+ int hn = 0; // hilbert curve order
11
+ while (((1 << hn) < nbw || (1 << hn) < nbh) && hn < 16) {
12
+ hn++; // fit to number of buckets
13
+ }
14
+ int hN = 1 << (2 * hn); // number of hilbert buckets - 2**2n
15
+ int n = nbw * nbh; // total number of buckets
16
+ int[] coords = new int[2 * n]; // storage for bucket coordinates
17
+ for (int i = 0; i < n; i++) {
18
+ int hx, hy;
19
+ do {
20
+ // s is the hilbert index, shifted to start in the middle
21
+ int s = hi; // (hi + (hN >> 1)) & (hN - 1);
22
+ // int n = hn;
23
+ // adapted from Hacker's Delight
24
+ int comp, swap, cs, t, sr;
25
+ s = s | (0x55555555 << (2 * hn)); // Pad s on left with 01
26
+ sr = (s >>> 1) & 0x55555555; // (no change) groups.
27
+ cs = ((s & 0x55555555) + sr) ^ 0x55555555;// Compute
28
+ // complement
29
+ // & swap info in
30
+ // two-bit groups.
31
+ // Parallel prefix xor op to propagate both complement
32
+ // and swap info together from left to right (there is
33
+ // no step "cs ^= cs >> 1", so in effect it computes
34
+ // two independent parallel prefix operations on two
35
+ // interleaved sets of sixteen bits).
36
+ cs = cs ^ (cs >>> 2);
37
+ cs = cs ^ (cs >>> 4);
38
+ cs = cs ^ (cs >>> 8);
39
+ cs = cs ^ (cs >>> 16);
40
+ swap = cs & 0x55555555; // Separate the swap and
41
+ comp = (cs >>> 1) & 0x55555555; // complement bits.
42
+ t = (s & swap) ^ comp; // Calculate x and y in
43
+ s = s ^ sr ^ t ^ (t << 1); // the odd & even bit
44
+ // positions, resp.
45
+ s = s & ((1 << 2 * hn) - 1); // Clear out any junk
46
+ // on the left (unpad).
47
+ // Now "unshuffle" to separate the x and y bits.
48
+ t = (s ^ (s >>> 1)) & 0x22222222;
49
+ s = s ^ t ^ (t << 1);
50
+ t = (s ^ (s >>> 2)) & 0x0C0C0C0C;
51
+ s = s ^ t ^ (t << 2);
52
+ t = (s ^ (s >>> 4)) & 0x00F000F0;
53
+ s = s ^ t ^ (t << 4);
54
+ t = (s ^ (s >>> 8)) & 0x0000FF00;
55
+ s = s ^ t ^ (t << 8);
56
+ hx = s >>> 16; // Assign the two halves
57
+ hy = s & 0xFFFF; // of t to x and y.
58
+ hi++;
59
+ } while ((hx >= nbw || hy >= nbh || hx < 0 || hy < 0) && hi < hN);
60
+ coords[2 * i + 0] = hx;
61
+ coords[2 * i + 1] = hy;
62
+ }
63
+ return coords;
64
+ }
65
+ }