From e38bac8d230ba55324a4faf7ee94c2e749638959 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 11 Aug 2021 18:17:47 +0300 Subject: [PATCH] Fix MM model --- .../kotlin/ru/mipt/npm/muon/monitor/Model.kt | 4 +++- .../kotlin/ru/mipt/npm/muon/monitor/Monitor.kt | 3 ++- .../ru/mipt/npm/muon/monitor/MMAppComponent.kt | 6 ++++-- .../kotlin/ru/mipt/npm/muon/monitor/sim/Pixel.kt | 12 ++++++------ .../visionforge/solid/three/ThreeLineFactory.kt | 10 +++++++--- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt index 854e520c..0c5e0af0 100644 --- a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt +++ b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt @@ -28,7 +28,6 @@ class Model(val manager: VisionManager) { private fun SolidGroup.detector(detector: SC16) { group(detector.name) { - position = detector.center detector.pixels.forEach { pixel(it) } @@ -65,6 +64,7 @@ class Model(val manager: VisionManager) { } private fun highlight(pixel: String) { + println("highlight $pixel") map[pixel]?.color?.invoke("blue") } @@ -76,6 +76,7 @@ class Model(val manager: VisionManager) { } fun displayEvent(event: Event) { + println("Received event: $event") events.add(event) event.hits.forEach { highlight(it) @@ -83,6 +84,7 @@ class Model(val manager: VisionManager) { event.track?.let { tracks.polyline(*it.toTypedArray(), name = "track[${event.id}]") { thickness = 4 + color("red") } } } diff --git a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Monitor.kt b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Monitor.kt index 3b64bb5a..3e1db5bc 100644 --- a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Monitor.kt +++ b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Monitor.kt @@ -3,6 +3,7 @@ package ru.mipt.npm.muon.monitor import ru.mipt.npm.muon.monitor.Monitor.PIXEL_XY_SIZE import ru.mipt.npm.muon.monitor.Monitor.PIXEL_Z_SIZE import space.kscience.visionforge.solid.Point3D +import space.kscience.visionforge.solid.plus /** * A single pixel @@ -97,7 +98,7 @@ class SC16( } val offset = Point3D(-y, x, 0)//rotateDetector(Point3D(x, y, 0.0)); val pixelName = "${name}_${index}" - SC1(pixelName, offset) + SC1(pixelName, offset + center) } } } diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt index d981fa44..8450cb4a 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt @@ -56,8 +56,10 @@ val MMApp = functionalComponent("Muon monitor") { props -> } } - val root = props.model.root.apply { - edges() + val root = useMemo(props.model) { + props.model.root.apply { + edges() + } } gridRow { diff --git a/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/sim/Pixel.kt b/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/sim/Pixel.kt index 579bca15..7cd54417 100644 --- a/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/sim/Pixel.kt +++ b/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/sim/Pixel.kt @@ -16,10 +16,10 @@ import kotlin.random.Random */ internal class SC1Aux(val sc: SC1, var efficiency: Double = 1.0) { // val layer: Layer = findLayer(center.z); - private val upLayer = - findLayer(sc.center.z + sc.zSize / 2f)//Layer("${name}_up", center.z + zSize / 2.0); - private val bottomLayer = - findLayer(sc.center.z - sc.zSize / 2f)//Layer("${name}_bottom", center.z - zSize / 2.0); + private val upLayer = findLayer(sc.center.z + sc.zSize / 2f) + //Layer("${name}_up", center.z + zSize / 2.0); + private val bottomLayer = findLayer(sc.center.z - sc.zSize / 2f) + //Layer("${name}_bottom", center.z - zSize / 2.0); private val centralLayer = findLayer(sc.center.z) private val center = Vector3D(sc.center.x.toDouble(), sc.center.y.toDouble(), sc.center.z.toDouble()) @@ -115,8 +115,8 @@ internal class SC1Aux(val sc: SC1, var efficiency: Double = 1.0) { private val auxCache = HashMap() -fun SC1.isHit(track: Line): Boolean{ - return auxCache.getOrPut(this){ +fun SC1.isHit(track: Line): Boolean { + return auxCache.getOrPut(this) { SC1Aux(this) }.isHit(track) } \ No newline at end of file diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeLineFactory.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeLineFactory.kt index 49fca0d9..ee36d74b 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeLineFactory.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeLineFactory.kt @@ -7,9 +7,11 @@ import info.laht.threekt.objects.LineSegments import space.kscience.visionforge.computePropertyNode import space.kscience.visionforge.onPropertyChange import space.kscience.visionforge.solid.PolyLine +import space.kscience.visionforge.solid.SolidMaterial import space.kscience.visionforge.solid.color import space.kscience.visionforge.solid.string import space.kscience.visionforge.solid.three.ThreeMaterials.DEFAULT_LINE_COLOR +import kotlin.math.ceil import kotlin.reflect.KClass public object ThreeLineFactory : ThreeFactory { @@ -17,12 +19,14 @@ public object ThreeLineFactory : ThreeFactory { override fun invoke(three: ThreePlugin, obj: PolyLine): Object3D { val geometry = BufferGeometry().apply { - setFromPoints(Array(obj.points.size) { obj.points[it].toVector() }) + setFromPoints(Array((obj.points.size - 1) * 2) { + obj.points[ceil(it / 2.0).toInt()].toVector() + }) } val material = ThreeMaterials.getLineMaterial( - obj.computePropertyNode(MeshThreeFactory.EDGES_MATERIAL_KEY), - true + obj.computePropertyNode(SolidMaterial.MATERIAL_KEY), + false ) material.linewidth = obj.thickness.toDouble()