Minor adjustment to root conversion

This commit is contained in:
Alexander Nozik 2021-09-14 16:30:18 +03:00
parent 0ec9033702
commit dee2cf848c
4 changed files with 27 additions and 43 deletions

View File

@ -25,7 +25,7 @@ public class DObjectCache(private val cache: List<Meta>, 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()) { public val typename: String by meta.string(key = "_typename".asName()) {
error("Type is not defined") 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() public val fFillColor: Int? by meta.int()
override val name: Name by lazy { Name.parse(fName.ifEmpty { "volume[${meta.hashCode().toUInt()}]" }) } 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) { public class DGeoNode(meta: Meta, refCache: DObjectCache) : DNamed(meta, refCache) {

View File

@ -17,16 +17,11 @@ private operator fun Number.times(f: Float) = toFloat() * f
private fun degToRad(d: Double) = d * PI / 180.0 private fun degToRad(d: Double) = d * PI / 180.0
private class RootToSolidContext(val prototypeHolder: PrototypeHolder, val maxLayer: Int = 3) { private data class RootToSolidContext(
val layers: MutableList<Int> = mutableListOf(0) val prototypeHolder: PrototypeHolder,
val currentLayer: Int = 0,
val layerLimits = listOf(10_000, 25_000, 50_000, 100_000, 200_000, 400_000, 600_000) val maxLayer: Int = 5
)
val bottomLayer: Int get() = layers.size - 1
fun addLayer() {
layers.add(0)
}
}
// converting to XYZ to TaitBryan angles according to https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // converting to XYZ to TaitBryan angles according to https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
private fun Solid.rotate(rot: DoubleArray) { private fun Solid.rotate(rot: DoubleArray) {
@ -267,9 +262,6 @@ private fun SolidGroup.addShape(
private fun SolidGroup.addRootNode(obj: DGeoNode, context: RootToSolidContext) { private fun SolidGroup.addRootNode(obj: DGeoNode, context: RootToSolidContext) {
val volume = obj.fVolume ?: return val volume = obj.fVolume ?: return
addRootVolume(volume, context, obj.fName) { addRootVolume(volume, context, obj.fName) {
if (context.bottomLayer > 0) {
this.layer = context.bottomLayer
}
when (obj.typename) { when (obj.typename) {
"TGeoNodeMatrix" -> { "TGeoNodeMatrix" -> {
val fMatrix by obj.dObject(::DGeoMatrix) 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? { private fun buildVolume(volume: DGeoVolume, context: RootToSolidContext): Solid? {
val group = SolidGroup { val group = SolidGroup {
val nodesNum = volume.fNodes.size //set current layer
if (nodesNum == 0) { layer = context.currentLayer
val nodes = volume.fNodes
if (nodes.isEmpty() || context.currentLayer >= context.maxLayer) {
//TODO add smart filter //TODO add smart filter
volume.fShape?.let { shape -> volume.fShape?.let { shape ->
addShape(shape, context) addShape(shape, context)
} }
} else {
val newLayer = if (nodes.size <= 2) {
context.currentLayer
} else if (nodes.size > 10) {
context.currentLayer + 2
} else {
context.currentLayer + 1
} }
val expectedLayerSize = context.layers.last() + nodesNum val newContext = context.copy(currentLayer = newLayer)
//If expected number exceeds layer limit, move everything else to the bottom layer. nodes.forEach { node ->
if (expectedLayerSize >= context.layerLimits[context.bottomLayer]) { //add children to the next layer
context.addLayer() addRootNode(node, newContext)
println("Adding new layer. Sizes after add: ${context.layers}")
} }
context.layers[context.bottomLayer] += nodesNum
volume.fNodes.forEach { node ->
addRootNode(node, context)
} }
} }
return if (group.isEmpty()) { return if (group.isEmpty()) {
@ -321,12 +319,6 @@ private fun SolidGroup.addRootVolume(
cache: Boolean = true, cache: Boolean = true,
block: Solid.() -> Unit = {} 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()) { val combinedName = if (volume.fName.isEmpty()) {
name name
} else if (name == null) { } else if (name == null) {

View File

@ -51,13 +51,9 @@ kotlin {
} }
kscience { kscience {
useJupyter() jupyterLibrary("space.kscience.visionforge.gdml.jupyter.GdmlForJupyter")
} }
readme { readme {
maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL
} }
tasks.named<org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask>("processJupyterApiResources") {
libraryProducers = listOf("space.kscience.visionforge.gdml.jupyter.GdmlForJupyter")
}

View File

@ -3,7 +3,7 @@ pluginManagement {
val toolsVersion = "0.10.3" val toolsVersion = "0.10.3"
repositories { repositories {
mavenLocal() //mavenLocal()
maven("https://repo.kotlin.link") maven("https://repo.kotlin.link")
mavenCentral() mavenCentral()
gradlePluginPortal() gradlePluginPortal()