Cleanup and fix ROOT bug

This commit is contained in:
Alexander Nozik 2023-05-16 21:12:24 +03:00
parent 4ec611eda3
commit c921d5541b
28 changed files with 93 additions and 130 deletions

1
.gitignore vendored
View File

@ -9,4 +9,3 @@ data/
!gradle-wrapper.jar
/kotlin-js-store/yarn.lock
.

View File

@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
import space.kscience.gradle.isInDevelopment
import space.kscience.gradle.useApache2Licence
import space.kscience.gradle.useSPCTeam
@ -30,6 +31,12 @@ subprojects {
freeCompilerArgs = freeCompilerArgs + "-Xcontext-receivers"
}
}
tasks.withType<KotlinJsCompile>{
kotlinOptions{
useEsClasses = true
}
}
}
ksciencePublish {

View File

@ -1,10 +1,8 @@
package ru.mipt.npm.root
import space.kscience.dataforge.meta.double
import space.kscience.dataforge.meta.doubleArray
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.int
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.parseAsName
import space.kscience.dataforge.names.plus
import space.kscience.visionforge.MutableVisionContainer
import space.kscience.visionforge.isEmpty
@ -25,6 +23,8 @@ private data class RootToSolidContext(
val prototypeHolder: PrototypeHolder,
val currentLayer: Int = 0,
val maxLayer: Int = 5,
val ignoreRootColors: Boolean = false,
val colorCache: MutableMap<Meta, String> = mutableMapOf(),
)
// converting to XYZ to TaitBryan angles according to https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
@ -300,7 +300,7 @@ private fun buildVolume(volume: DGeoVolume, context: RootToSolidContext): Solid?
layer = context.currentLayer
val nodes = volume.fNodes
if (nodes.isEmpty() || context.currentLayer >= context.maxLayer) {
if (volume.typename != "TGeoVolumeAssembly" && (nodes.isEmpty() || context.currentLayer >= context.maxLayer)) {
//TODO add smart filter
volume.fShape?.let { shape ->
addShape(shape, context)
@ -326,6 +326,16 @@ private fun buildVolume(volume: DGeoVolume, context: RootToSolidContext): Solid?
group.items.values.first().apply { parent = null }
} else {
group
}.apply {
volume.fMedium?.let { medium ->
color.set(context.colorCache.getOrPut(medium.meta) { RootColors[11 + context.colorCache.size] })
}
if (!context.ignoreRootColors) {
volume.fFillColor?.let {
properties[MATERIAL_COLOR_KEY] = RootColors[it]
}
}
}
}
@ -338,6 +348,7 @@ private fun SolidGroup.addRootVolume(
cache: Boolean = true,
block: Solid.() -> Unit = {},
) {
val combinedName = if (volume.fName.isEmpty()) {
name
} else if (name == null) {
@ -347,12 +358,7 @@ private fun SolidGroup.addRootVolume(
}
if (!cache) {
val group = buildVolume(volume, context)?.apply {
volume.fFillColor?.let {
properties[MATERIAL_COLOR_KEY] = RootColors[it]
}
block()
}
val group = buildVolume(volume, context)?.apply(block)
setChild(combinedName?.let { Name.parse(it) }, group)
} else {
val templateName = volumesName + volume.name
@ -364,17 +370,17 @@ private fun SolidGroup.addRootVolume(
}
}
ref(templateName, name).apply {
volume.fFillColor?.let {
properties[MATERIAL_COLOR_KEY] = RootColors[it]
}
block()
}
ref(templateName, name).apply(block)
}
}
public fun MutableVisionContainer<Solid>.rootGeo(dGeoManager: DGeoManager): SolidGroup = solidGroup {
val context = RootToSolidContext(this)
public fun MutableVisionContainer<Solid>.rootGeo(
dGeoManager: DGeoManager,
name: String? = null,
maxLayer: Int = 5,
ignoreRootColors: Boolean = false,
): SolidGroup = solidGroup(name = name?.parseAsName()) {
val context = RootToSolidContext(this, maxLayer = maxLayer, ignoreRootColors = ignoreRootColors)
dGeoManager.fNodes.forEach { node ->
addRootNode(node, context)
}

View File

@ -1,7 +1,7 @@
package ru.mipt.npm.root
public object RootColors {
private val colorMap = Array<String>(924) { "white" }
private val colorMap = MutableList(924) { "white" }
//colorMap[110] = "white"

View File

@ -23,7 +23,7 @@ import ru.mipt.npm.muon.monitor.sim.Cos2TrackGenerator
import ru.mipt.npm.muon.monitor.sim.simulateOne
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.context.Global
import space.kscience.dataforge.context.fetch
import space.kscience.dataforge.context.request
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.visionforge.solid.Solids
import java.awt.Desktop
@ -36,7 +36,7 @@ private val generator = Cos2TrackGenerator(JDKRandomGenerator(223))
fun Application.module(context: Context = Global) {
val currentDir = File(".").absoluteFile
environment.log.info("Current directory: $currentDir")
val solidManager = context.fetch(Solids)
val solidManager = context.request(Solids)
install(ContentNegotiation) {
json()

View File

@ -7,9 +7,14 @@ import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.isLeaf
import space.kscience.dataforge.meta.string
import space.kscience.visionforge.Colors
import space.kscience.visionforge.html.ResourceLocation
import space.kscience.visionforge.solid.Solids
import java.nio.file.Paths
import space.kscience.visionforge.solid.ambientLight
import space.kscience.visionforge.solid.set
import space.kscience.visionforge.solid.solid
import java.util.zip.ZipInputStream
import kotlin.io.path.Path
import kotlin.io.path.writeText
@ -34,73 +39,17 @@ fun main() {
println(it)
}
val solid = Solids.rootGeo(geo)
Paths.get("BM@N.vf.json").writeText(Solids.encodeToString(solid))
//println(Solids.encodeToString(solid))
makeVisionFile {
makeVisionFile(path = Path("data/output.html"), resourceLocation = ResourceLocation.EMBED) {
vision("canvas") {
requirePlugin(Solids)
solid
solid {
ambientLight {
color.set(Colors.white)
}
rootGeo(geo,"BM@N", maxLayer = 3, ignoreRootColors = true).also {
Path("data/BM@N.vf.json").writeText(Solids.encodeToString(it))
}
}
}
}
}
/* SolidGroup {
set(
"Coil",
solid.getPrototype("Coil".asName())!!.apply {
parent = null
}
)
*//* group("Shade") {
y = 200
color("red")
coneSurface(
bottomOuterRadius = 135,
bottomInnerRadius = 25,
height = 50,
topOuterRadius = 135,
topInnerRadius = 25,
angle = 1.5707964
) {
position = Point3D(79.6, 0, -122.1)
rotation = Point3D(-1.5707964, 0, 0)
}
coneSurface(
bottomOuterRadius = 135,
bottomInnerRadius = 25,
height = 50,
topOuterRadius = 135,
topInnerRadius = 25,
angle = 1.5707964
) {
position = Point3D(-79.6, 0, -122.1)
rotation = Point3D(1.5707964, 0, -3.1415927)
}
coneSurface(
bottomOuterRadius = 135,
bottomInnerRadius = 25,
height = 50,
topOuterRadius = 135,
topInnerRadius = 25,
angle = 1.5707964
) {
position = Point3D(79.6, 0, 122.1)
rotation = Point3D(1.5707964, 0, 0)
}
coneSurface(
bottomOuterRadius = 135,
bottomInnerRadius = 25,
height = 50,
topOuterRadius = 135,
topInnerRadius = 25,
angle = 1.5707964
) {
position = Point3D(-79.6, 0, 122.1)
rotation = Point3D(-1.5707964, 0, -3.1415927)
}
}*//*
}*/
}

View File

@ -7,10 +7,11 @@ val dataforgeVersion: String by rootProject.extra
kscience{
jvm()
js()
native()
dependencies {
api("space.kscience:dataforge-context:$dataforgeVersion")
api(spclibs.kotlinx.html)
api("org.jetbrains.kotlin-wrappers:kotlin-css")
// api("org.jetbrains.kotlin-wrappers:kotlin-css")
}
testDependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${space.kscience.gradle.KScienceVersions.coroutinesVersion}")

View File

@ -0,0 +1,5 @@
package space.kscience.visionforge
@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
public expect annotation class JvmSynchronized()

View File

@ -13,7 +13,6 @@ import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.isEmpty
import space.kscience.dataforge.names.plus
import kotlin.jvm.Synchronized
import kotlin.time.Duration
/**
@ -59,11 +58,11 @@ public class VisionChangeBuilder : MutableVisionContainer<Vision> {
public fun isEmpty(): Boolean = propertyChange.isEmpty() && propertyChange.isEmpty() && children.isEmpty()
@Synchronized
@JvmSynchronized
private fun getOrPutChild(visionName: Name): VisionChangeBuilder =
children.getOrPut(visionName) { VisionChangeBuilder() }
@Synchronized
@JvmSynchronized
internal fun reset() {
vision = null
propertyChange = MutableMeta()

View File

@ -6,7 +6,6 @@ import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import space.kscience.dataforge.names.*
import space.kscience.visionforge.VisionChildren.Companion.STATIC_TOKEN_BODY
import kotlin.jvm.Synchronized
@DslMarker
public annotation class VisionBuilder
@ -132,7 +131,7 @@ internal abstract class VisionChildrenImpl(
abstract var items: MutableMap<NameToken, Vision>?
@Synchronized
@JvmSynchronized
private fun buildItems(): MutableMap<NameToken, Vision> {
if (items == null) {
items = LinkedHashMap()

View File

@ -11,7 +11,6 @@ import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.get
import space.kscience.dataforge.names.*
import kotlin.jvm.Synchronized
public interface VisionProperties {
@ -155,7 +154,7 @@ public abstract class AbstractVisionProperties(
override val own: Meta? get() = properties
@Synchronized
@JvmSynchronized
protected fun getOrCreateProperties(): MutableMeta {
if (properties == null) {
//TODO check performance issues

View File

@ -0,0 +1,3 @@
package space.kscience.visionforge
public actual typealias JvmSynchronized = Synchronized

View File

@ -67,9 +67,7 @@ public fun VisionPage.makeFile(
path: Path?,
fileHeaders: ((Path) -> Map<String, HtmlFragment>)? = null,
): Path {
val actualFile = path?.let {
Path.of(System.getProperty("user.home")).resolve(path)
} ?: Files.createTempFile("tempPlot", ".html")
val actualFile = path ?: Files.createTempFile("tempPlot", ".html")
val actualDefaultHeaders = fileHeaders?.invoke(actualFile)
val actualHeaders = if (actualDefaultHeaders == null) pageHeaders else actualDefaultHeaders + pageHeaders

View File

@ -12,6 +12,6 @@ kscience {
api("space.kscience:gdml:0.4.0")
}
dependencies(jvmTest) {
implementation("ch.qos.logback:logback-classic:1.2.11")
implementation(spclibs.logback.classic)
}
}

View File

@ -2,7 +2,7 @@ plugins {
id("space.kscience.gradle.mpp")
}
val markdownVersion = "0.2.4"
val markdownVersion = "0.4.1"
kscience {
jvm()

View File

@ -5,6 +5,7 @@ plugins {
kscience {
jvm()
js()
native()
useSerialization {
json()
}

View File

@ -6,7 +6,10 @@ import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.NameToken
import space.kscience.dataforge.names.parseAsName
import space.kscience.visionforge.*
import space.kscience.visionforge.AbstractVisionGroup
import space.kscience.visionforge.MutableVisionContainer
import space.kscience.visionforge.MutableVisionGroup
import space.kscience.visionforge.VisionBuilder
/**
@ -53,7 +56,7 @@ public class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder, Mutable
/**
* Get a prototype redirecting the request to the parent if prototype is not found.
* If prototype is a ref, then it is unfolded automatically.
* If a prototype is a ref, then it is unfolded automatically.
*/
override fun getPrototype(name: Name): Solid? =
prototypes?.get(name)?.prototype ?: (parent as? PrototypeHolder)?.getPrototype(name)

View File

@ -10,7 +10,6 @@ import kotlinx.serialization.serializer
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.context.PluginFactory
import space.kscience.dataforge.context.PluginTag
import space.kscience.dataforge.context.request
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.dataforge.names.Name
@ -27,15 +26,9 @@ public class Solids(meta: Meta) : VisionPlugin(meta), MutableVisionContainer<Sol
child?.setAsRoot(visionManager)
}
public companion object : PluginFactory<Solids>, MutableVisionContainer<Solid> {
public companion object : PluginFactory<Solids> {
override val tag: PluginTag = PluginTag(name = "vision.solid", group = PluginTag.DATAFORGE_GROUP)
public val default: Solids by lazy {
Context("@Solids") {
plugin(Solids)
}.request(Solids)
}
override fun build(context: Context, meta: Meta): Solids = Solids(meta)
private fun PolymorphicModuleBuilder<Solid>.solids() {
@ -79,9 +72,9 @@ public class Solids(meta: Meta) : VisionPlugin(meta), MutableVisionContainer<Sol
public fun decodeFromString(str: String): Solid =
jsonForSolids.decodeFromString(PolymorphicSerializer(Solid::class), str)
override fun setChild(name: Name?, child: Solid?) {
default.setChild(name, child)
}
// override fun setChild(name: Name?, child: Solid?) {
// default.setChild(name, child)
// }
}
}

View File

@ -8,7 +8,7 @@ class CompositeTest {
@Test
fun testCompositeBuilder(){
lateinit var composite: Composite
Solids.solidGroup {
testSolids.solidGroup {
composite = composite(CompositeType.INTERSECT) {
y = 300
box(100, 100, 100) {

View File

@ -11,7 +11,7 @@ class ConvexTest {
@Suppress("UNUSED_VARIABLE")
@Test
fun testConvexBuilder() {
val group = Solids.solidGroup {
val group = testSolids.solidGroup {
convex {
point(50, 50, -50)
point(50, -50, -50)

View File

@ -9,7 +9,7 @@ import kotlin.test.assertEquals
class GroupTest {
@Test
fun testGroupWithComposite() {
val group = Solids.solidGroup{
val group = testSolids.solidGroup{
union("union") {
box(100, 100, 100) {
z = 100

View File

@ -41,7 +41,7 @@ class SerializationTest {
x = 100
z = -100
}
val group = Solids.solidGroup {
val group = testSolids.solidGroup {
newRef("cube", cube)
refGroup("pg", Name.parse("pg.content")) {
sphere(50) {
@ -57,7 +57,7 @@ class SerializationTest {
@Test
fun lightSerialization(){
val group = Solids.solidGroup {
val group = testSolids.solidGroup {
ambientLight {
color.set(Colors.white)
intensity = 100.0

View File

@ -7,8 +7,10 @@ import space.kscience.visionforge.getChild
import kotlin.test.Test
import kotlin.test.assertEquals
internal val testSolids = Global.request(Solids)
class SolidPluginTest {
val vision = Solids.solidGroup {
val vision = testSolids.solidGroup {
box(100, 100, 100, name = "aBox")
sphere(100, name = "aSphere") {

View File

@ -62,7 +62,7 @@ class SolidPropertyTest {
@Test
fun testStyleProperty() {
var box: Box? = null
val group = Solids.solidGroup {
val group = testSolids.solidGroup {
styleSheet {
update("testStyle") {
"test" put 22
@ -98,7 +98,7 @@ class SolidPropertyTest {
@Test
fun testReferenceStyleProperty() {
var box: SolidReference? = null
val group = Solids.solidGroup {
val group = testSolids.solidGroup {
styleSheet {
update("testStyle") {
SolidMaterial.MATERIAL_COLOR_KEY put "#555555"

View File

@ -11,7 +11,7 @@ import kotlin.test.assertEquals
@DFExperimental
class SolidReferenceTest {
val groupWithReference = Solids.solidGroup {
val groupWithReference = testSolids.solidGroup {
val theStyle by style {
SolidMaterial.MATERIAL_COLOR_KEY put "red"
}

View File

@ -17,7 +17,7 @@ internal class VisionUpdateTest {
@Test
fun testVisionUpdate() {
val targetVision = Solids.solidGroup {
val targetVision = testSolids.solidGroup {
box(200, 200, 200, name = "origin")
}
val dif = visionManager.VisionChange {

View File

@ -7,7 +7,7 @@ import three.geometries.SphereGeometry
public object ThreeSphereFactory : ThreeMeshFactory<Sphere>(Sphere::class) {
override fun buildGeometry(obj: Sphere): BufferGeometry {
return obj.detail?.let {detail ->
return obj.detail?.let { detail ->
SphereGeometry(
radius = obj.radius,
phiStart = obj.phiStart,
@ -17,7 +17,7 @@ public object ThreeSphereFactory : ThreeMeshFactory<Sphere>(Sphere::class) {
widthSegments = detail,
heightSegments = detail
)
}?: SphereGeometry(
} ?: SphereGeometry(
radius = obj.radius,
phiStart = obj.phiStart,
phiLength = obj.phi,

View File

@ -3,8 +3,7 @@
"OVERRIDING_FINAL_MEMBER",
"RETURN_TYPE_MISMATCH_ON_OVERRIDE",
"CONFLICTING_OVERLOADS",
"EXTERNAL_DELEGATION",
"NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING"
"EXTERNAL_DELEGATION"
)
@file:JsModule("three-csg-ts")