Multiple fixes

This commit is contained in:
Alexander Nozik 2023-05-29 21:38:30 +03:00
parent c48e5aac25
commit 33778801b6
28 changed files with 207 additions and 79 deletions

View File

@ -118,7 +118,7 @@ private object RootDecoder {
subclass(TGeoCompositeShape.serializer().unref(refCache))
subclass(TGeoShapeAssembly.serializer().unref(refCache))
default {
defaultDeserializer {
if (it == null) {
TGeoShape.serializer().unref(refCache)
} else {
@ -136,7 +136,7 @@ private object RootDecoder {
val unrefed = TGeoMatrix.serializer().unref(refCache)
default {
defaultDeserializer {
if (it == null) {
unrefed
} else {
@ -149,7 +149,7 @@ private object RootDecoder {
subclass(TGeoVolumeAssembly.serializer().unref(refCache))
val unrefed = TGeoVolume.serializer().unref(refCache)
default {
defaultDeserializer {
if (it == null) {
unrefed
} else {
@ -163,7 +163,7 @@ private object RootDecoder {
subclass(TGeoNodeOffset.serializer().unref(refCache))
val unrefed = TGeoNode.serializer().unref(refCache)
default {
defaultDeserializer {
if (it == null) {
unrefed
} else {

View File

@ -7,6 +7,7 @@ kscience {
js {
useCommonJs()
browser {
binaries.executable()
commonWebpackConfig {
cssSupport {
enabled.set(false)
@ -27,7 +28,6 @@ kscience {
implementation(projects.visionforgeThreejs)
implementation(npm("react-file-drop", "3.0.6"))
}
application()
}
//kotlin {

View File

@ -4,13 +4,13 @@ plugins {
kscience{
useCoroutines()
application()
}
kotlin{
js(IR){
useCommonJs()
browser {
binaries.executable()
commonWebpackConfig {
cssSupport{
enabled.set(false)

View File

@ -38,7 +38,6 @@ kscience {
implementation(project(":visionforge-threejs"))
//implementation(devNpm("webpack-bundle-analyzer", "4.4.0"))
}
application()
}
application {

View File

@ -2,6 +2,7 @@ plugins {
kotlin("multiplatform")
kotlin("jupyter.api")
id("com.github.johnrengelman.shadow") version "7.1.2"
// application
}
repositories {
@ -29,6 +30,7 @@ kotlin {
}
jvm {
// withJava()
compilations.all {
kotlinOptions {
jvmTarget = "11"
@ -88,4 +90,8 @@ val processJupyterApiResources by tasks.getting(org.jetbrains.kotlinx.jupyter.ap
libraryProducers = listOf("space.kscience.visionforge.examples.VisionForgePlayGroundForJupyter")
}
tasks.findByName("shadowJar")?.dependsOn(processJupyterApiResources)
tasks.findByName("shadowJar")?.dependsOn(processJupyterApiResources)
//application{
// mainClass.set("space.kscience.visionforge.examples.ShapesKt")
//}

View File

@ -2,37 +2,73 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"tags": [],
"pycharm": {
"is_executing": true
},
"ExecuteTime": {
"end_time": "2023-05-29T15:22:37.933397300Z",
"start_time": "2023-05-29T15:22:37.913872100Z"
}
},
"outputs": [],
"source": [
"@file:DependsOn(\"../build/libs/playground-0.3.0-dev-4-all.jar\")"
]
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2023-05-29T15:22:50.486483300Z",
"start_time": "2023-05-29T15:22:50.457485500Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Line_2.jupyter.kts (1:1 - 3) Unresolved reference: vf"
]
}
],
"source": [
"vf.startServer()"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"ExecuteTime": {
"end_time": "2023-05-29T15:22:51.410680600Z",
"start_time": "2023-05-29T15:22:51.250779400Z"
}
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Line_3.jupyter.kts (1:16 - 26) Unresolved reference: coroutines\n",
"Line_3.jupyter.kts (4:1 - 7) Unresolved reference: Plotly\n",
"Line_3.jupyter.kts (5:5 - 12) Unresolved reference: scatter\n",
"Line_3.jupyter.kts (6:9 - 10) Unresolved reference: x\n",
"Line_3.jupyter.kts (7:9 - 10) Unresolved reference: y\n",
"Line_3.jupyter.kts (8:12 - 14) Unresolved reference: vf\n",
"Line_3.jupyter.kts (9:13 - 15) Unresolved reference: vf\n",
"Line_3.jupyter.kts (10:23 - 31) Unresolved reference: isActive\n",
"Line_3.jupyter.kts (11:21 - 26) Unresolved reference: delay\n",
"Line_3.jupyter.kts (12:21 - 22) Unresolved reference: y"
]
}
],
"source": [
"import kotlinx.coroutines.*\n",
"import kotlin.random.Random\n",
@ -84,6 +120,9 @@
"nbconvert_exporter": "",
"pygments_lexer": "kotlin",
"version": "1.8.0-dev-3517"
},
"ktnbPluginMetadata": {
"isAddProjectLibrariesToClasspath": false
}
},
"nbformat": 4,

View File

@ -0,0 +1,39 @@
package space.kscience.visionforge.examples
import kotlin.math.PI
import space.kscience.visionforge.Colors
import space.kscience.visionforge.solid.*
fun main() = makeVisionFile{
vision("canvas") {
solid {
ambientLight()
box(100.0, 100.0, 100.0) {
z = -110.0
color.set("teal")
}
sphere(50.0) {
x = 110
detail = 16
color.set("red")
}
tube(50, height = 10, innerRadius = 25, angle = PI) {
y = 110
detail = 16
rotationX = PI / 4
color.set("blue")
}
sphereLayer(50, 40, theta = PI / 2) {
rotationX = -PI * 3 / 4
z = 110
color.set(Colors.pink)
}
tube(30,20, 20){
detail = 31
y = - 220
}
}
}
}

View File

@ -8,7 +8,6 @@ kscience {
// useSerialization {
// json()
// }
application()
dependencies{
implementation(projects.visionforgeThreejs.visionforgeThreejsServer)
implementation("ch.qos.logback:logback-classic:1.4.5")

View File

@ -3,8 +3,7 @@ package ru.mipt.npm.sat
import io.ktor.server.cio.CIO
import io.ktor.server.engine.embeddedServer
import io.ktor.server.http.content.resources
import io.ktor.server.http.content.static
import io.ktor.server.http.content.staticResources
import io.ktor.server.routing.routing
import kotlinx.coroutines.*
import kotlinx.html.div
@ -41,9 +40,7 @@ fun main() {
val server = embeddedServer(CIO, connector.port, connector.host) {
routing {
static {
resources()
}
staticResources("", null, null)
}
visionPage(

View File

@ -1,11 +1,11 @@
plugins {
id("space.kscience.gradle.mpp")
`maven-publish`
application
}
kscience {
useCoroutines()
application()
jvm {
withJava()
}
@ -22,4 +22,8 @@ kscience {
application {
mainClass.set("space.kscience.visionforge.solid.demo.FXDemoAppKt")
}
kotlin{
explicitApi = null
}

View File

@ -5,8 +5,8 @@ import space.kscience.dataforge.names.Name
import space.kscience.visionforge.Vision
import space.kscience.visionforge.solid.Solids
public interface VisionLayout<in V: Vision> {
interface VisionLayout<in V: Vision> {
val solids: Solids
public fun render(name: Name, vision: V, meta: Meta = Meta.EMPTY)
fun render(name: Name, vision: V, meta: Meta = Meta.EMPTY)
}

View File

@ -6,5 +6,5 @@ kotlin.incremental.js.ir=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx4G
toolsVersion=0.14.8-kotlin-1.8.20
toolsVersion=0.14.9-kotlin-1.8.20
org.jetbrains.compose.experimental.jscanvas.enabled=true

View File

@ -0,0 +1,11 @@
package space.kscience.visionforge.compose
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
@Composable
public fun ThreeJs(){
Surface {
}
}

View File

@ -4,26 +4,24 @@ plugins {
val dataforgeVersion: String by rootProject.extra
kscience{
kscience {
jvm()
js()
native()
useCoroutines()
dependencies {
api("space.kscience:dataforge-context:$dataforgeVersion")
api(spclibs.kotlinx.html)
// api("org.jetbrains.kotlin-wrappers:kotlin-css")
}
testDependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${space.kscience.gradle.KScienceVersions.coroutinesVersion}")
}
dependencies(jsMain){
jsMain {
api("org.jetbrains.kotlin-wrappers:kotlin-extensions")
}
useSerialization{
useSerialization {
json()
}
}
readme{
readme {
maturity = space.kscience.gradle.Maturity.DEVELOPMENT
}

View File

@ -70,7 +70,7 @@ public class VisionManager(meta: Meta) : AbstractPlugin(meta), MutableVisionCont
private val defaultSerialModule: SerializersModule = SerializersModule {
polymorphic(Vision::class) {
default { SimpleVisionGroup.serializer() }
defaultDeserializer { SimpleVisionGroup.serializer() }
subclass(NullVision.serializer())
subclass(SimpleVisionGroup.serializer())
subclass(VisionOfNumberField.serializer())

View File

@ -94,7 +94,7 @@ internal class VisionPropertyTest {
}
@Test
fun testChildrenPropertyFlow() = runTest(dispatchTimeoutMs = 200) {
fun testChildrenPropertyFlow() = runTest(timeout = 200.milliseconds) {
val group = Global.request(VisionManager).group {
properties {

View File

@ -10,8 +10,9 @@ kscience {
binaries.library()
}
dependencies {
api(project(":visionforge-core"))
api(projects.visionforgeCore)
api("org.jetbrains:markdown:$markdownVersion")
api("org.jetbrains:annotations:24.0.0")
}
useSerialization()
}

View File

@ -1,5 +1,8 @@
package space.kscience.visionforge.markup
import space.kscience.dataforge.context.PluginFactory
import space.kscience.visionforge.VisionPlugin
public expect class MarkupPlugin: VisionPlugin
public expect class MarkupPlugin: VisionPlugin{
public companion object : PluginFactory<MarkupPlugin>
}

View File

@ -10,6 +10,8 @@ import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.visionforge.AbstractVision
import space.kscience.visionforge.Vision
import space.kscience.visionforge.VisionBuilder
import space.kscience.visionforge.html.VisionOutput
import space.kscience.visionforge.root
@Serializable
@ -38,4 +40,16 @@ internal val markupSerializersModule = SerializersModule {
polymorphic(Vision::class) {
subclass(VisionOfMarkup.serializer())
}
}
/**
* Embed a dynamic markdown block in a vision
*/
@VisionBuilder
public inline fun VisionOutput.markdown(
format: String = VisionOfMarkup.COMMONMARK_FORMAT,
block: VisionOfMarkup.() -> Unit,
): VisionOfMarkup {
requirePlugin(MarkupPlugin)
return VisionOfMarkup(format).apply(block)
}

View File

@ -44,7 +44,7 @@ public actual class MarkupPlugin : VisionPlugin(), ElementVisionRenderer {
element.append(div)
}
public companion object : PluginFactory<MarkupPlugin> {
public actual companion object : PluginFactory<MarkupPlugin> {
override val tag: PluginTag = PluginTag("vision.markup", PluginTag.DATAFORGE_GROUP)
override fun build(context: Context, meta: Meta): MarkupPlugin = MarkupPlugin()

View File

@ -1,6 +1,7 @@
package space.kscience.visionforge.markup
import kotlinx.serialization.modules.SerializersModule
import org.intellij.lang.annotations.Language
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.context.PluginFactory
import space.kscience.dataforge.context.PluginTag
@ -12,10 +13,14 @@ public actual class MarkupPlugin : VisionPlugin() {
override val tag: PluginTag get() = Companion.tag
public companion object : PluginFactory<MarkupPlugin> {
public actual companion object : PluginFactory<MarkupPlugin> {
override val tag: PluginTag = PluginTag("vision.plotly", PluginTag.DATAFORGE_GROUP)
override fun build(context: Context, meta: Meta): MarkupPlugin = MarkupPlugin()
}
}
public fun VisionOfMarkup.content(@Language("markdown") text: String) {
content = text
}

View File

@ -16,6 +16,7 @@ import space.kscience.plotly.Plot
import space.kscience.plotly.Plotly
import space.kscience.visionforge.MutableVisionProperties
import space.kscience.visionforge.Vision
import space.kscience.visionforge.VisionBuilder
import space.kscience.visionforge.html.VisionOutput
@Serializable
@ -82,7 +83,10 @@ public class VisionOfPlotly private constructor(
public fun Plot.asVision(): VisionOfPlotly = VisionOfPlotly(this)
@DFExperimental
/**
* Embed a dynamic plotly plot in a vision
*/
@VisionBuilder
public inline fun VisionOutput.plotly(
block: Plot.() -> Unit,
): VisionOfPlotly {

View File

@ -9,12 +9,10 @@ kscience {
useSerialization {
json()
}
useCoroutines()
dependencies {
api(projects.visionforgeCore)
}
testDependencies {
implementation(spclibs.kotlinx.coroutines.test)
}
dependencies(jvmTest) {
implementation(spclibs.logback.classic)
}

View File

@ -18,42 +18,54 @@ public class ConeSegment(
public val bottomRadius: Float,
public val height: Float,
public val topRadius: Float,
public val startAngle: Float = 0f,
public val angle: Float = PI2
public val phiStart: Float = 0f,
public val phi: Float = PI2,
) : SolidBase<ConeSegment>(), GeometrySolid {
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
val segments = detail ?: 32
require(segments >= 4) { "The number of segments in cone segment is too small" }
val angleStep = angle / (segments - 1)
init {
require(bottomRadius > 0) { "Bottom radius must be positive" }
require(topRadius > 0) { "Top radius must be positive" }
}
fun shape(r: Float, z: Float): List<Point3D> {
return (0 until segments).map { i ->
Point3D(r * cos(startAngle + angleStep * i), r * sin(startAngle + angleStep * i), z)
}
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
val segments: Int = detail ?: 32
require(segments >= 4) { "The number of segments in cone segment is too small" }
val angleStep = phi / (segments - 1)
/**
* Top and bottom shape
*/
fun shape(r: Float, z: Float): List<Point3D> = (0 until segments).map { i ->
Point3D(r * cos(phiStart + angleStep * i), r * sin(phiStart + angleStep * i), z)
}
geometryBuilder.apply {
with(geometryBuilder) {
// top and bottom faces
val bottomOuterPoints: List<Point3D> = shape(topRadius, -height / 2)
val upperOuterPoints: List<Point3D> = shape(bottomRadius, height / 2)
//creating shape in x-y plane with z = 0
val bottomOuterPoints = shape(topRadius, -height / 2)
val upperOuterPoints = shape(bottomRadius, height / 2)
//outer face
(1 until segments).forEach {
for (it in 1 until segments) {
face4(bottomOuterPoints[it - 1], bottomOuterPoints[it], upperOuterPoints[it], upperOuterPoints[it - 1])
}
if (angle == PI2) {
//if the cone is closed
if (phi == PI2) {
face4(bottomOuterPoints.last(), bottomOuterPoints[0], upperOuterPoints[0], upperOuterPoints.last())
}
val zeroBottom = Point3D(0f, 0f, 0f)
val zeroTop = Point3D(0f, 0f, height)
(1 until segments).forEach {
//top and bottom cups
val zeroBottom = Point3D(0f, 0f, -height / 2)
val zeroTop = Point3D(0f, 0f, height / 2)
for (it in 1 until segments) {
face(bottomOuterPoints[it - 1], zeroBottom, bottomOuterPoints[it])
face(upperOuterPoints[it - 1], upperOuterPoints[it], zeroTop)
}
if (angle == PI2) {
// closed surface
if (phi == PI2) {
face(bottomOuterPoints.last(), zeroBottom, bottomOuterPoints[0])
face(upperOuterPoints.last(), upperOuterPoints[0], zeroTop)
} else {
@ -71,7 +83,7 @@ public inline fun MutableVisionContainer<Solid>.cylinder(
r: Number,
height: Number,
name: String? = null,
block: ConeSegment.() -> Unit = {}
block: ConeSegment.() -> Unit = {},
): ConeSegment = ConeSegment(
r.toFloat(),
height.toFloat(),
@ -86,11 +98,11 @@ public inline fun MutableVisionContainer<Solid>.cone(
startAngle: Number = 0f,
angle: Number = PI2,
name: String? = null,
block: ConeSegment.() -> Unit = {}
block: ConeSegment.() -> Unit = {},
): ConeSegment = ConeSegment(
bottomRadius.toFloat(),
height.toFloat(),
topRadius = upperRadius.toFloat(),
startAngle = startAngle.toFloat(),
angle = angle.toFloat()
phiStart = startAngle.toFloat(),
phi = angle.toFloat()
).apply(block).also { setChild(name, it) }

View File

@ -38,10 +38,8 @@ public class ConeSurface(
require(segments >= 4) { "The number of segments in tube is too small" }
val angleStep = angle / (segments - 1)
fun shape(r: Float, z: Float): List<Point3D> {
return (0 until segments).map { i ->
Point3D(r * cos(startAngle + angleStep * i), r * sin(startAngle + angleStep * i), z)
}
fun shape(r: Float, z: Float): List<Point3D> = (0 until segments).map { i ->
Point3D(r * cos(startAngle + angleStep * i), r * sin(startAngle + angleStep * i), z)
}
geometryBuilder.apply {
@ -50,7 +48,7 @@ public class ConeSurface(
val bottomOuterPoints = shape(bottomRadius, -height / 2)
val topOuterPoints = shape(topRadius, height / 2)
//outer face
(1 until segments).forEach {
for (it in 1 until segments) {
face4(bottomOuterPoints[it - 1], bottomOuterPoints[it], topOuterPoints[it], topOuterPoints[it - 1])
}

View File

@ -44,6 +44,7 @@ public class Solids(meta: Meta) : VisionPlugin(meta), MutableVisionContainer<Sol
subclass(PolyLine.serializer())
subclass(SolidLabel.serializer())
subclass(Sphere.serializer())
subclass(SphereLayer.serializer())
subclass(AmbientLightSource.serializer())
subclass(PointLightSource.serializer())
@ -56,7 +57,7 @@ public class Solids(meta: Meta) : VisionPlugin(meta), MutableVisionContainer<Sol
}
polymorphic(Solid::class) {
default { SolidBase.serializer(serializer<Solid>()) }
defaultDeserializer { SolidBase.serializer(serializer<Solid>()) }
solids()
}
}

View File

@ -18,16 +18,16 @@ public object ThreeConeFactory : ThreeMeshFactory<ConeSegment>(ConeSegment::clas
radialSegments = segments,
heightSegments = segments,
openEnded = false,
thetaStart = obj.startAngle,
thetaLength = obj.angle
thetaStart = obj.phiStart,
thetaLength = obj.phi
)
} ?: CylinderGeometry(
radiusTop = obj.topRadius,
radiusBottom = obj.bottomRadius,
height = obj.height,
openEnded = false,
thetaStart = obj.startAngle,
thetaLength = obj.angle
thetaStart = obj.phiStart,
thetaLength = obj.phi
)
return cylinder.rotateX(PI/2)
}

View File

@ -111,7 +111,7 @@ public class ThreePlugin : AbstractPlugin(), ElementVisionRenderer {
is Composite -> compositeFactory.build(this, vision, observe)
else -> {
//find specialized factory for this type if it is present
//find a specialized factory for this type if it is present
val factory: ThreeFactory<Solid>? = findObjectFactory(vision::class)
when {
factory != null -> factory.build(this, vision, observe)