From f3f9012c5ae8407672d4d5a76e6785b0baebf1e1 Mon Sep 17 00:00:00 2001 From: Peter Klimai Date: Thu, 2 Jan 2020 16:24:52 +0300 Subject: [PATCH 1/3] Translate HTML instructions in GDML example, and include example file --- README.md | 4 +- demo/gdml/src/jsMain/resources/cubes.gdml | 254 ++++++++++++++++++++++ demo/gdml/src/jsMain/web/index.html | 6 +- 3 files changed, 260 insertions(+), 4 deletions(-) create mode 100644 demo/gdml/src/jsMain/resources/cubes.gdml diff --git a/README.md b/README.md index ff2820f1..aab72d1b 100644 --- a/README.md +++ b/README.md @@ -70,4 +70,6 @@ To run full-stack app (both server and browser front-end), run ##### gdml -Visualization example for geometry defined as GDML file. +Visualization example for geometry defined as GDML file. Once you open Web application, +drag-and-drop GDML file to the window to see visualization. For example file, use +`demo\gdml\src\jsMain\resources\cubes.gdml`. diff --git a/demo/gdml/src/jsMain/resources/cubes.gdml b/demo/gdml/src/jsMain/resources/cubes.gdml new file mode 100644 index 00000000..4d66c389 --- /dev/null +++ b/demo/gdml/src/jsMain/resources/cubes.gdml @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/gdml/src/jsMain/web/index.html b/demo/gdml/src/jsMain/web/index.html index 3b2a99b2..bad59418 100644 --- a/demo/gdml/src/jsMain/web/index.html +++ b/demo/gdml/src/jsMain/web/index.html @@ -12,10 +12,10 @@
- Загрузить данные + title="To load data in text format, drag-and-drop file here"> + Load data
- (перетащить файл сюда) + (drag file here)

GDML demo

-- 2.34.1 From 8206a636b5466db9b0f7066d5bfd75e50e65bdb9 Mon Sep 17 00:00:00 2001 From: Peter Klimai Date: Fri, 31 Jan 2020 13:42:58 +0300 Subject: [PATCH 2/3] Implement Sphere.toGeometry #11 --- README.md | 4 +- .../hep/dataforge/vis/spatial/Sphere.kt | 37 ++++++++++++++----- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index aab72d1b..afdbe49e 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ This repository contains [DataForge](http://npm.mipt.ru/dataforge/) (also [here](https://github.com/mipt-npm/dataforge-core)) components useful for visualization in -various scientific applications. Currently, the main application is 3D visualization for particle -physics experiments. +various scientific applications. The main application for now is 3D visualization for particle +physics experiments. Other applications including 2D plots are planned for future. The project is developed as a Kotlin multiplatform application, currently targeting browser JavaScript and JVM. diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt index 26a9e820..a016747c 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt @@ -8,6 +8,8 @@ import hep.dataforge.vis.common.AbstractVisualObject import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import kotlin.math.PI +import kotlin.math.cos +import kotlin.math.sin @Serializable class Sphere( @@ -26,16 +28,31 @@ class Sphere( override var scale: Point3D? = null override fun toGeometry(geometryBuilder: GeometryBuilder) { - TODO("not implemented") -// val segments = this.detail ?: 8 -// require(segments >= 4) { "The detail for sphere must be >= 4" } -// val phiStep = phi / segments -// val thetaStep = theta / segments -// for (i in 1 until segments - 1) { -// for (j in 0 until segments - 1) { -// val point1 = Point3D() -// } -// } + fun point3DfromSphCoord(r: Float, theta: Float, phi: Float): Point3D { + val z = r * cos(theta) + val x = r * sin(theta) * cos(phi) + val y = r * sin(theta) * sin(phi) + return Point3D(x, y, z) + } + val segments = this.detail ?: 8 + require(segments >= 4) { "The detail for sphere must be >= 4" } + val phiStep = phi / segments + val thetaStep = theta / segments + for (i in 0 until segments) { // theta iteration + val theta1 = thetaStart + i * thetaStep + val theta2 = theta1 + thetaStep + for (j in 0 until segments) { // phi iteration + val phi1 = phiStart + j * phiStep + val phi2 = phi1 + phiStep + val point1 = point3DfromSphCoord(radius, theta1, phi1) + val point2 = point3DfromSphCoord(radius, theta1, phi2) + val point3 = point3DfromSphCoord(radius, theta2, phi2) + val point4 = point3DfromSphCoord(radius, theta2, phi1) + geometryBuilder.apply { + face4(point1, point2, point3, point4) + } + } + } } } -- 2.34.1 From 0c69c1cdbca193cb6a1cb76f04653f9baf7f5899 Mon Sep 17 00:00:00 2001 From: Peter Klimai Date: Wed, 5 Feb 2020 12:34:08 +0300 Subject: [PATCH 3/3] Update Sphere to match three.js axis --- .../kotlin/hep/dataforge/vis/spatial/Sphere.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt index a016747c..58e2c8b6 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt @@ -29,9 +29,10 @@ class Sphere( override fun toGeometry(geometryBuilder: GeometryBuilder) { fun point3DfromSphCoord(r: Float, theta: Float, phi: Float): Point3D { - val z = r * cos(theta) - val x = r * sin(theta) * cos(phi) - val y = r * sin(theta) * sin(phi) + // This transformation matches three.js sphere implementation + val y = r * cos(theta) + val z = r * sin(theta) * sin(phi) + val x = - r * sin(theta) * cos(phi) return Point3D(x, y, z) } val segments = this.detail ?: 8 @@ -49,7 +50,8 @@ class Sphere( val point3 = point3DfromSphCoord(radius, theta2, phi2) val point4 = point3DfromSphCoord(radius, theta2, phi1) geometryBuilder.apply { - face4(point1, point2, point3, point4) + // 1-2-3-4 gives the same face but with opposite orientation + face4(point1, point4, point3, point2) } } } -- 2.34.1