From dee2cf848ca1709e053cc71ab9fef1aef3c0aeba Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 14 Sep 2021 16:30:18 +0300 Subject: [PATCH] Minor adjustment to root conversion --- .../kotlin/ru/mipt/npm/root/DObject.kt | 6 +-- .../kotlin/ru/mipt/npm/root/dRootToSolid.kt | 54 ++++++++----------- .../visionforge-gdml-jupyter/build.gradle.kts | 8 +-- settings.gradle.kts | 2 +- 4 files changed, 27 insertions(+), 43 deletions(-) diff --git a/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/DObject.kt b/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/DObject.kt index 9f4d1971..5af50c3f 100644 --- a/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/DObject.kt +++ b/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/DObject.kt @@ -25,7 +25,7 @@ public class DObjectCache(private val cache: List, public val refStack: Li } } -public open class DObject(public val meta: Meta, private val refCache: DObjectCache) { +public open class DObject(public val meta: Meta, public val refCache: DObjectCache) { public val typename: String by meta.string(key = "_typename".asName()) { error("Type is not defined") @@ -85,10 +85,6 @@ public class DGeoVolume(meta: Meta, refCache: DObjectCache) : DNamed(meta, refCa public val fFillColor: Int? by meta.int() override val name: Name by lazy { Name.parse(fName.ifEmpty { "volume[${meta.hashCode().toUInt()}]" }) } - - public val numberOfChildren: Int by lazy { - fNodes.sumOf { (it.fVolume?.numberOfChildren ?: 0) + 1 } - } } public class DGeoNode(meta: Meta, refCache: DObjectCache) : DNamed(meta, refCache) { diff --git a/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/dRootToSolid.kt b/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/dRootToSolid.kt index a11f1996..7c345dd4 100644 --- a/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/dRootToSolid.kt +++ b/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/dRootToSolid.kt @@ -17,16 +17,11 @@ private operator fun Number.times(f: Float) = toFloat() * f private fun degToRad(d: Double) = d * PI / 180.0 -private class RootToSolidContext(val prototypeHolder: PrototypeHolder, val maxLayer: Int = 3) { - val layers: MutableList = mutableListOf(0) - - val layerLimits = listOf(10_000, 25_000, 50_000, 100_000, 200_000, 400_000, 600_000) - - val bottomLayer: Int get() = layers.size - 1 - fun addLayer() { - layers.add(0) - } -} +private data class RootToSolidContext( + val prototypeHolder: PrototypeHolder, + val currentLayer: Int = 0, + val maxLayer: Int = 5 +) // converting to XYZ to Tait–Bryan angles according to https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix private fun Solid.rotate(rot: DoubleArray) { @@ -267,9 +262,6 @@ private fun SolidGroup.addShape( private fun SolidGroup.addRootNode(obj: DGeoNode, context: RootToSolidContext) { val volume = obj.fVolume ?: return addRootVolume(volume, context, obj.fName) { - if (context.bottomLayer > 0) { - this.layer = context.bottomLayer - } when (obj.typename) { "TGeoNodeMatrix" -> { val fMatrix by obj.dObject(::DGeoMatrix) @@ -285,22 +277,28 @@ private fun SolidGroup.addRootNode(obj: DGeoNode, context: RootToSolidContext) { private fun buildVolume(volume: DGeoVolume, context: RootToSolidContext): Solid? { val group = SolidGroup { - val nodesNum = volume.fNodes.size - if (nodesNum == 0) { + //set current layer + layer = context.currentLayer + val nodes = volume.fNodes + + if (nodes.isEmpty() || context.currentLayer >= context.maxLayer) { //TODO add smart filter volume.fShape?.let { shape -> addShape(shape, context) } - } - val expectedLayerSize = context.layers.last() + nodesNum - //If expected number exceeds layer limit, move everything else to the bottom layer. - if (expectedLayerSize >= context.layerLimits[context.bottomLayer]) { - context.addLayer() - println("Adding new layer. Sizes after add: ${context.layers}") - } - context.layers[context.bottomLayer] += nodesNum - volume.fNodes.forEach { node -> - addRootNode(node, context) + } else { + val newLayer = if (nodes.size <= 2) { + context.currentLayer + } else if (nodes.size > 10) { + context.currentLayer + 2 + } else { + context.currentLayer + 1 + } + val newContext = context.copy(currentLayer = newLayer) + nodes.forEach { node -> + //add children to the next layer + addRootNode(node, newContext) + } } } return if (group.isEmpty()) { @@ -321,12 +319,6 @@ private fun SolidGroup.addRootVolume( cache: Boolean = true, block: Solid.() -> Unit = {} ) { - //skip if maximum layer number is reached - if (context.bottomLayer > context.maxLayer) { - println("Maximum layer depth reached. Skipping ${volume.fName}") - return - } - val combinedName = if (volume.fName.isEmpty()) { name } else if (name == null) { diff --git a/jupyter/visionforge-gdml-jupyter/build.gradle.kts b/jupyter/visionforge-gdml-jupyter/build.gradle.kts index 6c1d7c43..c2c77516 100644 --- a/jupyter/visionforge-gdml-jupyter/build.gradle.kts +++ b/jupyter/visionforge-gdml-jupyter/build.gradle.kts @@ -51,13 +51,9 @@ kotlin { } kscience { - useJupyter() + jupyterLibrary("space.kscience.visionforge.gdml.jupyter.GdmlForJupyter") } readme { maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL -} - -tasks.named("processJupyterApiResources") { - libraryProducers = listOf("space.kscience.visionforge.gdml.jupyter.GdmlForJupyter") -} +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index ad1b4aef..a6f4db0d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,7 +3,7 @@ pluginManagement { val toolsVersion = "0.10.3" repositories { - mavenLocal() + //mavenLocal() maven("https://repo.kotlin.link") mavenCentral() gradlePluginPortal()