Performance optimization

This commit is contained in:
Alexander Nozik 2022-08-23 12:06:27 +03:00
parent 75540a078f
commit 25fc143363
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
7 changed files with 85 additions and 70 deletions

View File

@ -3,7 +3,7 @@ plugins {
// id("org.jetbrains.kotlinx.kover") version "0.5.0"
}
val dataforgeVersion by extra("0.6.0-dev-13")
val dataforgeVersion by extra("0.6.0-dev-15")
val fxVersion by extra("11")
allprojects{
@ -15,6 +15,7 @@ subprojects {
if (name.startsWith("visionforge")) apply<MavenPublishPlugin>()
repositories {
mavenLocal()
maven("https://repo.kotlin.link")
mavenCentral()
maven("https://maven.jzy3d.org/releases")

View File

@ -82,7 +82,6 @@ class Model(val manager: VisionManager) {
}
event.track?.let {
tracks.polyline(*it.toTypedArray(), name = "track[${event.id}]") {
thickness = 4
color.set("red")
}
}

View File

@ -11,12 +11,12 @@ import space.kscience.visionforge.solid.plus
class SC1(
val name: String,
val center: Point3D,
val xSize: Float = PIXEL_XY_SIZE, val ySize: Float = PIXEL_XY_SIZE, val zSize: Float = PIXEL_Z_SIZE
val xSize: Float = PIXEL_XY_SIZE, val ySize: Float = PIXEL_XY_SIZE, val zSize: Float = PIXEL_Z_SIZE,
)
class SC16(
val name: String,
val center: Point3D
val center: Point3D,
) {
/**
@ -28,73 +28,86 @@ class SC16(
val y: Double
when (index) {
7 -> {
x = 1.5 * Monitor.PIXEL_XY_SPACING;
y = 1.5 * Monitor.PIXEL_XY_SPACING;
x = 1.5 * Monitor.PIXEL_XY_SPACING
y = 1.5 * Monitor.PIXEL_XY_SPACING
}
4 -> {
x = 0.5 * Monitor.PIXEL_XY_SPACING;
y = 1.5 * Monitor.PIXEL_XY_SPACING;
x = 0.5 * Monitor.PIXEL_XY_SPACING
y = 1.5 * Monitor.PIXEL_XY_SPACING
}
6 -> {
x = 1.5 * Monitor.PIXEL_XY_SPACING;
y = 0.5 * Monitor.PIXEL_XY_SPACING;
x = 1.5 * Monitor.PIXEL_XY_SPACING
y = 0.5 * Monitor.PIXEL_XY_SPACING
}
5 -> {
x = 0.5 * Monitor.PIXEL_XY_SPACING;
y = 0.5 * Monitor.PIXEL_XY_SPACING;
x = 0.5 * Monitor.PIXEL_XY_SPACING
y = 0.5 * Monitor.PIXEL_XY_SPACING
}
3 -> {
x = -1.5 * Monitor.PIXEL_XY_SPACING;
y = 1.5 * Monitor.PIXEL_XY_SPACING;
x = -1.5 * Monitor.PIXEL_XY_SPACING
y = 1.5 * Monitor.PIXEL_XY_SPACING
}
0 -> {
x = -0.5 * Monitor.PIXEL_XY_SPACING;
y = 1.5 * Monitor.PIXEL_XY_SPACING;
x = -0.5 * Monitor.PIXEL_XY_SPACING
y = 1.5 * Monitor.PIXEL_XY_SPACING
}
2 -> {
x = -1.5 * Monitor.PIXEL_XY_SPACING;
y = 0.5 * Monitor.PIXEL_XY_SPACING;
x = -1.5 * Monitor.PIXEL_XY_SPACING
y = 0.5 * Monitor.PIXEL_XY_SPACING
}
1 -> {
x = -0.5 * Monitor.PIXEL_XY_SPACING;
y = 0.5 * Monitor.PIXEL_XY_SPACING;
x = -0.5 * Monitor.PIXEL_XY_SPACING
y = 0.5 * Monitor.PIXEL_XY_SPACING
}
11 -> {
x = -1.5 * Monitor.PIXEL_XY_SPACING;
y = -1.5 * Monitor.PIXEL_XY_SPACING;
x = -1.5 * Monitor.PIXEL_XY_SPACING
y = -1.5 * Monitor.PIXEL_XY_SPACING
}
8 -> {
x = -0.5 * Monitor.PIXEL_XY_SPACING;
y = -1.5 * Monitor.PIXEL_XY_SPACING;
x = -0.5 * Monitor.PIXEL_XY_SPACING
y = -1.5 * Monitor.PIXEL_XY_SPACING
}
10 -> {
x = -1.5 * Monitor.PIXEL_XY_SPACING;
y = -0.5 * Monitor.PIXEL_XY_SPACING;
x = -1.5 * Monitor.PIXEL_XY_SPACING
y = -0.5 * Monitor.PIXEL_XY_SPACING
}
9 -> {
x = -0.5 * Monitor.PIXEL_XY_SPACING;
y = -0.5 * Monitor.PIXEL_XY_SPACING;
x = -0.5 * Monitor.PIXEL_XY_SPACING
y = -0.5 * Monitor.PIXEL_XY_SPACING
}
15 -> {
x = 1.5 * Monitor.PIXEL_XY_SPACING;
y = -1.5 * Monitor.PIXEL_XY_SPACING;
x = 1.5 * Monitor.PIXEL_XY_SPACING
y = -1.5 * Monitor.PIXEL_XY_SPACING
}
12 -> {
x = 0.5 * Monitor.PIXEL_XY_SPACING;
y = -1.5 * Monitor.PIXEL_XY_SPACING;
x = 0.5 * Monitor.PIXEL_XY_SPACING
y = -1.5 * Monitor.PIXEL_XY_SPACING
}
14 -> {
x = 1.5 * Monitor.PIXEL_XY_SPACING;
y = -0.5 * Monitor.PIXEL_XY_SPACING;
x = 1.5 * Monitor.PIXEL_XY_SPACING
y = -0.5 * Monitor.PIXEL_XY_SPACING
}
13 -> {
x = 0.5 * Monitor.PIXEL_XY_SPACING;
y = -0.5 * Monitor.PIXEL_XY_SPACING;
x = 0.5 * Monitor.PIXEL_XY_SPACING
y = -0.5 * Monitor.PIXEL_XY_SPACING
}
else -> throw Error();
else -> throw Error()
}
val offset = Point3D(-y, x, 0)//rotateDetector(Point3D(x, y, 0.0));
val pixelName = "${name}_${index}"
@ -137,7 +150,7 @@ object Monitor {
.mapNotNull { line ->
if (line.startsWith(" ")) {
val split = line.trim().split("\\s+".toRegex())
val detectorName = split[1];
val detectorName = split[1]
val x = split[4].toDouble() - 500
val y = split[5].toDouble() - 500
val z = 180 - split[6].toDouble()

View File

@ -165,6 +165,8 @@ public abstract class AbstractVisionProperties(
return properties!!
}
private val descriptorCache = HashMap<Name, MetaDescriptor?>()
override fun getValue(
name: Name,
inherit: Boolean?,
@ -172,7 +174,7 @@ public abstract class AbstractVisionProperties(
): Value? {
own?.get(name)?.value?.let { return it }
val descriptor = descriptor?.get(name)
val descriptor = descriptor?.let { descriptor -> descriptorCache.getOrPut(name) { descriptor[name] } }
val stylesFlag = includeStyles ?: descriptor?.usesStyles ?: true
if (stylesFlag) {

View File

@ -24,15 +24,19 @@ public object ThreeCanvasLabelFactory : ThreeFactory<SolidLabel> {
override fun build(three: ThreePlugin, vision: SolidLabel, observe: Boolean): Object3D {
val canvas = document.createElement("canvas") as HTMLCanvasElement
val context = canvas.getContext("2d") as CanvasRenderingContext2D
context.font = "Bold ${vision.fontSize}pt ${vision.fontFamily}"
context.fillStyle = vision.properties.getValue(SolidMaterial.MATERIAL_COLOR_KEY, false, true)?.value ?: "black"
context.textBaseline = CanvasTextBaseline.MIDDLE
val metrics = context.measureText(vision.text)
//canvas.width = metrics.width.toInt()
context.fillText(vision.text, (canvas.width - metrics.width) / 2, 0.5 * canvas.height)
canvas.getContext("2d").apply {
this as CanvasRenderingContext2D
font = "Bold ${vision.fontSize}pt ${vision.fontFamily}"
fillStyle = vision.properties.getValue(
SolidMaterial.MATERIAL_COLOR_KEY,
inherit = false,
includeStyles = true
)?.value ?: "black"
textBaseline = CanvasTextBaseline.MIDDLE
val metrics = measureText(vision.text)
//canvas.width = metrics.width.toInt()
fillText(vision.text, (canvas.width - metrics.width) / 2, 0.5 * canvas.height)
}
// canvas contents will be used for a texture

View File

@ -93,22 +93,17 @@ public object ThreeMaterials {
* Compute color
*/
public fun Meta.threeColor(): Color? {
if (isEmpty()) return null
val value = value
return if (isLeaf) {
when {
value == null -> null
value?.let { value ->
return when {
value === Null -> null
value.type == ValueType.NUMBER -> Color(value.int)
else -> Color(value.string)
}
} else {
Color(
getValue(Colors.RED_KEY.asName())?.int ?: 0,
getValue(Colors.GREEN_KEY.asName())?.int ?: 0,
getValue(Colors.BLUE_KEY.asName())?.int ?: 0
)
}
val red = getValue(Colors.RED_KEY.asName())?.int
val green = getValue(Colors.GREEN_KEY.asName())?.int
val blue = getValue(Colors.BLUE_KEY.asName())?.int
return if (red == null && green == null && blue == null) null else Color(red ?: 0, green ?: 0, blue ?: 0)
}
public fun ColorAccessor.threeColor(): Color? {

View File

@ -16,17 +16,18 @@ public object ThreeReferenceFactory : ThreeFactory<SolidReference> {
override val type: KClass<SolidReference> = SolidReference::class
private fun Object3D.replicate(): Object3D {
return when {
isMesh(this) -> Mesh(geometry, material).also {
it.applyMatrix4(matrix)
}
else -> clone(false)
}.also { obj: Object3D ->
obj.name = this.name
children.forEach { child: Object3D ->
obj.add(child.replicate())
}
private fun Object3D.replicate(): Object3D = when {
isMesh(this) -> Mesh(geometry, material).also {
//clone geometry
it.material.cached = true
it.applyMatrix4(matrix)
}
else -> clone(false)
}.also { obj: Object3D ->
obj.name = this.name
children.forEach { child: Object3D ->
obj.add(child.replicate())
}
}