forked from kscience/visionforge
[WIP] layer marking
This commit is contained in:
parent
0d53b6f77d
commit
f2e7e16d62
@ -21,6 +21,7 @@
|
|||||||
- Tube is replaced by more general ConeSurface
|
- Tube is replaced by more general ConeSurface
|
||||||
- position, rotation and size moved to properties
|
- position, rotation and size moved to properties
|
||||||
- prototypes moved to children
|
- prototypes moved to children
|
||||||
|
- Immutable Solid instances
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
@ -32,7 +32,10 @@ val GDMLApp = functionalComponent<GDMLAppProps>("GDMLApp") { props ->
|
|||||||
val parsedVision = when {
|
val parsedVision = when {
|
||||||
name.endsWith(".gdml") || name.endsWith(".xml") -> {
|
name.endsWith(".gdml") || name.endsWith(".xml") -> {
|
||||||
val gdml = Gdml.decodeFromString(data)
|
val gdml = Gdml.decodeFromString(data)
|
||||||
gdml.toVision()
|
gdml.toVision().apply {
|
||||||
|
// console.info("Marking layers for file $name")
|
||||||
|
// markLayers()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
name.endsWith(".json") -> visionManager.decodeFromString(data)
|
name.endsWith(".json") -> visionManager.decodeFromString(data)
|
||||||
else -> {
|
else -> {
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package space.kscience.visionforge.gdml
|
|
||||||
|
|
||||||
import space.kscience.dataforge.names.Name
|
|
||||||
import space.kscience.dataforge.names.plus
|
|
||||||
import space.kscience.visionforge.VisionGroup
|
|
||||||
|
|
||||||
private fun VisionGroup.countChildren(namePrefix: Name, cache: MutableMap<Name, Int> = hashMapOf()): Int {
|
|
||||||
var counter = 0
|
|
||||||
children.forEach { (token, child) ->
|
|
||||||
if (child is VisionGroup) {
|
|
||||||
counter += child.countChildren(namePrefix + token, cache)
|
|
||||||
} else {
|
|
||||||
counter++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cache[namePrefix] = counter
|
|
||||||
return counter
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public fun VisionGroup.processLayers() {
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,62 @@
|
|||||||
|
package space.kscience.visionforge.gdml
|
||||||
|
|
||||||
|
import space.kscience.dataforge.names.Name
|
||||||
|
import space.kscience.dataforge.names.NameToken
|
||||||
|
import space.kscience.dataforge.names.length
|
||||||
|
import space.kscience.dataforge.names.plus
|
||||||
|
import space.kscience.visionforge.VisionGroup
|
||||||
|
import space.kscience.visionforge.solid.Solid
|
||||||
|
import space.kscience.visionforge.solid.SolidGroup
|
||||||
|
import space.kscience.visionforge.solid.layer
|
||||||
|
|
||||||
|
private class VisionCounterTree(
|
||||||
|
val name: Name,
|
||||||
|
val vision: Solid,
|
||||||
|
) {
|
||||||
|
val children: Map<NameToken, VisionCounterTree> =
|
||||||
|
(vision as? VisionGroup)?.children?.mapValues {
|
||||||
|
VisionCounterTree(name + it.key, it.value as Solid)
|
||||||
|
} ?: emptyMap()
|
||||||
|
|
||||||
|
//
|
||||||
|
// val directChildrenCount: Int by lazy {
|
||||||
|
// children.size
|
||||||
|
// }
|
||||||
|
|
||||||
|
val childrenCount: Int =
|
||||||
|
children.values.sumOf { it.childrenCount + 1 }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun VisionCounterTree.topToBottom(): Sequence<VisionCounterTree> = sequence {
|
||||||
|
yield(this@topToBottom)
|
||||||
|
children.values.forEach {
|
||||||
|
yieldAll(it.topToBottom())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun SolidGroup.markLayers(thresholds: List<Int> = listOf(1000, 20000, 100000)) {
|
||||||
|
val counterTree = VisionCounterTree(Name.EMPTY, this)
|
||||||
|
val totalCount = counterTree.childrenCount
|
||||||
|
if (totalCount > thresholds.firstOrNull() ?: 0) {
|
||||||
|
val allNodes = counterTree.topToBottom().toMutableList()
|
||||||
|
//println("tree construction finished")
|
||||||
|
allNodes.sortWith(compareBy<VisionCounterTree>({ it.name.length }, { it.childrenCount }).reversed())
|
||||||
|
|
||||||
|
//mark layers
|
||||||
|
var removed = 0
|
||||||
|
var thresholdIndex = thresholds.indexOfLast { it < totalCount }
|
||||||
|
|
||||||
|
for (node in allNodes) {
|
||||||
|
node.vision.layer = thresholdIndex + 1
|
||||||
|
removed++
|
||||||
|
if (totalCount - removed < thresholds[thresholdIndex]) {
|
||||||
|
thresholdIndex--
|
||||||
|
}
|
||||||
|
if (thresholdIndex < 0) break
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -100,7 +100,7 @@ public class SolidReferenceGroup(
|
|||||||
private class ReferenceChild(
|
private class ReferenceChild(
|
||||||
val owner: SolidReferenceGroup,
|
val owner: SolidReferenceGroup,
|
||||||
private val childName: Name
|
private val childName: Name
|
||||||
) : SolidReference, VisionGroup {
|
) : SolidReference, VisionGroup, Solid {
|
||||||
|
|
||||||
override val prototype: Solid by lazy {
|
override val prototype: Solid by lazy {
|
||||||
if (childName.isEmpty()) owner.prototype else {
|
if (childName.isEmpty()) owner.prototype else {
|
||||||
|
@ -17,7 +17,7 @@ public class Sphere(
|
|||||||
public val phiStart: Float = 0f,
|
public val phiStart: Float = 0f,
|
||||||
public val phi: Float = PI2,
|
public val phi: Float = PI2,
|
||||||
public val thetaStart: Float = 0f,
|
public val thetaStart: Float = 0f,
|
||||||
public val theta: Float = PI.toFloat(),
|
public val theta: Float = PI .toFloat(),
|
||||||
) : SolidBase(), GeometrySolid, VisionPropertyContainer<Sphere> {
|
) : SolidBase(), GeometrySolid, VisionPropertyContainer<Sphere> {
|
||||||
|
|
||||||
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
||||||
|
@ -5,5 +5,5 @@ plugins {
|
|||||||
dependencies {
|
dependencies {
|
||||||
api(project(":visionforge-solid"))
|
api(project(":visionforge-solid"))
|
||||||
implementation(npm("three", "0.130.1"))
|
implementation(npm("three", "0.130.1"))
|
||||||
implementation(npm("three-csg-ts", "3.1.4"))
|
implementation(npm("three-csg-ts", "3.1.5"))
|
||||||
}
|
}
|
||||||
|
@ -54,9 +54,6 @@ public class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
|
|||||||
setAttribute("position", Float32BufferAttribute(positions.toTypedArray(), 3))
|
setAttribute("position", Float32BufferAttribute(positions.toTypedArray(), 3))
|
||||||
setAttribute("normal", Float32BufferAttribute(normals.toTypedArray(), 3))
|
setAttribute("normal", Float32BufferAttribute(normals.toTypedArray(), 3))
|
||||||
//setAttribute("color", Float32BufferAttribute(colors.toFloatArray(), 3))
|
//setAttribute("color", Float32BufferAttribute(colors.toFloatArray(), 3))
|
||||||
//a temporary fix for CSG problem
|
|
||||||
val uvsArray = Array<Float>((counter+1)*2){0f}
|
|
||||||
setAttribute("uv", Float32BufferAttribute(uvsArray, 2))
|
|
||||||
|
|
||||||
computeBoundingSphere()
|
computeBoundingSphere()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user