forked from kscience/visionforge
Performance optimization
This commit is contained in:
parent
75540a078f
commit
25fc143363
@ -3,7 +3,7 @@ plugins {
|
|||||||
// id("org.jetbrains.kotlinx.kover") version "0.5.0"
|
// 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")
|
val fxVersion by extra("11")
|
||||||
|
|
||||||
allprojects{
|
allprojects{
|
||||||
@ -15,6 +15,7 @@ subprojects {
|
|||||||
if (name.startsWith("visionforge")) apply<MavenPublishPlugin>()
|
if (name.startsWith("visionforge")) apply<MavenPublishPlugin>()
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
maven("https://repo.kotlin.link")
|
maven("https://repo.kotlin.link")
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://maven.jzy3d.org/releases")
|
maven("https://maven.jzy3d.org/releases")
|
||||||
|
@ -82,7 +82,6 @@ class Model(val manager: VisionManager) {
|
|||||||
}
|
}
|
||||||
event.track?.let {
|
event.track?.let {
|
||||||
tracks.polyline(*it.toTypedArray(), name = "track[${event.id}]") {
|
tracks.polyline(*it.toTypedArray(), name = "track[${event.id}]") {
|
||||||
thickness = 4
|
|
||||||
color.set("red")
|
color.set("red")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,12 @@ import space.kscience.visionforge.solid.plus
|
|||||||
class SC1(
|
class SC1(
|
||||||
val name: String,
|
val name: String,
|
||||||
val center: Point3D,
|
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(
|
class SC16(
|
||||||
val name: String,
|
val name: String,
|
||||||
val center: Point3D
|
val center: Point3D,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,73 +28,86 @@ class SC16(
|
|||||||
val y: Double
|
val y: Double
|
||||||
when (index) {
|
when (index) {
|
||||||
7 -> {
|
7 -> {
|
||||||
x = 1.5 * Monitor.PIXEL_XY_SPACING;
|
x = 1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = 1.5 * Monitor.PIXEL_XY_SPACING;
|
y = 1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
4 -> {
|
4 -> {
|
||||||
x = 0.5 * Monitor.PIXEL_XY_SPACING;
|
x = 0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = 1.5 * Monitor.PIXEL_XY_SPACING;
|
y = 1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
6 -> {
|
6 -> {
|
||||||
x = 1.5 * Monitor.PIXEL_XY_SPACING;
|
x = 1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = 0.5 * Monitor.PIXEL_XY_SPACING;
|
y = 0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
5 -> {
|
5 -> {
|
||||||
x = 0.5 * Monitor.PIXEL_XY_SPACING;
|
x = 0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = 0.5 * Monitor.PIXEL_XY_SPACING;
|
y = 0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
3 -> {
|
3 -> {
|
||||||
x = -1.5 * Monitor.PIXEL_XY_SPACING;
|
x = -1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = 1.5 * Monitor.PIXEL_XY_SPACING;
|
y = 1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
0 -> {
|
0 -> {
|
||||||
x = -0.5 * Monitor.PIXEL_XY_SPACING;
|
x = -0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = 1.5 * Monitor.PIXEL_XY_SPACING;
|
y = 1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
2 -> {
|
2 -> {
|
||||||
x = -1.5 * Monitor.PIXEL_XY_SPACING;
|
x = -1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = 0.5 * Monitor.PIXEL_XY_SPACING;
|
y = 0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
1 -> {
|
1 -> {
|
||||||
x = -0.5 * Monitor.PIXEL_XY_SPACING;
|
x = -0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = 0.5 * Monitor.PIXEL_XY_SPACING;
|
y = 0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
11 -> {
|
11 -> {
|
||||||
x = -1.5 * Monitor.PIXEL_XY_SPACING;
|
x = -1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = -1.5 * Monitor.PIXEL_XY_SPACING;
|
y = -1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
8 -> {
|
8 -> {
|
||||||
x = -0.5 * Monitor.PIXEL_XY_SPACING;
|
x = -0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = -1.5 * Monitor.PIXEL_XY_SPACING;
|
y = -1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
10 -> {
|
10 -> {
|
||||||
x = -1.5 * Monitor.PIXEL_XY_SPACING;
|
x = -1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = -0.5 * Monitor.PIXEL_XY_SPACING;
|
y = -0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
9 -> {
|
9 -> {
|
||||||
x = -0.5 * Monitor.PIXEL_XY_SPACING;
|
x = -0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = -0.5 * Monitor.PIXEL_XY_SPACING;
|
y = -0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
15 -> {
|
15 -> {
|
||||||
x = 1.5 * Monitor.PIXEL_XY_SPACING;
|
x = 1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = -1.5 * Monitor.PIXEL_XY_SPACING;
|
y = -1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
12 -> {
|
12 -> {
|
||||||
x = 0.5 * Monitor.PIXEL_XY_SPACING;
|
x = 0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = -1.5 * Monitor.PIXEL_XY_SPACING;
|
y = -1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
14 -> {
|
14 -> {
|
||||||
x = 1.5 * Monitor.PIXEL_XY_SPACING;
|
x = 1.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = -0.5 * Monitor.PIXEL_XY_SPACING;
|
y = -0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
}
|
}
|
||||||
|
|
||||||
13 -> {
|
13 -> {
|
||||||
x = 0.5 * Monitor.PIXEL_XY_SPACING;
|
x = 0.5 * Monitor.PIXEL_XY_SPACING
|
||||||
y = -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 offset = Point3D(-y, x, 0)//rotateDetector(Point3D(x, y, 0.0));
|
||||||
val pixelName = "${name}_${index}"
|
val pixelName = "${name}_${index}"
|
||||||
@ -137,7 +150,7 @@ object Monitor {
|
|||||||
.mapNotNull { line ->
|
.mapNotNull { line ->
|
||||||
if (line.startsWith(" ")) {
|
if (line.startsWith(" ")) {
|
||||||
val split = line.trim().split("\\s+".toRegex())
|
val split = line.trim().split("\\s+".toRegex())
|
||||||
val detectorName = split[1];
|
val detectorName = split[1]
|
||||||
val x = split[4].toDouble() - 500
|
val x = split[4].toDouble() - 500
|
||||||
val y = split[5].toDouble() - 500
|
val y = split[5].toDouble() - 500
|
||||||
val z = 180 - split[6].toDouble()
|
val z = 180 - split[6].toDouble()
|
||||||
|
@ -165,6 +165,8 @@ public abstract class AbstractVisionProperties(
|
|||||||
return properties!!
|
return properties!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val descriptorCache = HashMap<Name, MetaDescriptor?>()
|
||||||
|
|
||||||
override fun getValue(
|
override fun getValue(
|
||||||
name: Name,
|
name: Name,
|
||||||
inherit: Boolean?,
|
inherit: Boolean?,
|
||||||
@ -172,7 +174,7 @@ public abstract class AbstractVisionProperties(
|
|||||||
): Value? {
|
): Value? {
|
||||||
own?.get(name)?.value?.let { return it }
|
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
|
val stylesFlag = includeStyles ?: descriptor?.usesStyles ?: true
|
||||||
|
|
||||||
if (stylesFlag) {
|
if (stylesFlag) {
|
||||||
|
@ -24,15 +24,19 @@ public object ThreeCanvasLabelFactory : ThreeFactory<SolidLabel> {
|
|||||||
|
|
||||||
override fun build(three: ThreePlugin, vision: SolidLabel, observe: Boolean): Object3D {
|
override fun build(three: ThreePlugin, vision: SolidLabel, observe: Boolean): Object3D {
|
||||||
val canvas = document.createElement("canvas") as HTMLCanvasElement
|
val canvas = document.createElement("canvas") as HTMLCanvasElement
|
||||||
val context = canvas.getContext("2d") as CanvasRenderingContext2D
|
canvas.getContext("2d").apply {
|
||||||
context.font = "Bold ${vision.fontSize}pt ${vision.fontFamily}"
|
this as CanvasRenderingContext2D
|
||||||
context.fillStyle = vision.properties.getValue(SolidMaterial.MATERIAL_COLOR_KEY, false, true)?.value ?: "black"
|
font = "Bold ${vision.fontSize}pt ${vision.fontFamily}"
|
||||||
context.textBaseline = CanvasTextBaseline.MIDDLE
|
fillStyle = vision.properties.getValue(
|
||||||
val metrics = context.measureText(vision.text)
|
SolidMaterial.MATERIAL_COLOR_KEY,
|
||||||
|
inherit = false,
|
||||||
|
includeStyles = true
|
||||||
|
)?.value ?: "black"
|
||||||
|
textBaseline = CanvasTextBaseline.MIDDLE
|
||||||
|
val metrics = measureText(vision.text)
|
||||||
//canvas.width = metrics.width.toInt()
|
//canvas.width = metrics.width.toInt()
|
||||||
|
fillText(vision.text, (canvas.width - metrics.width) / 2, 0.5 * canvas.height)
|
||||||
|
}
|
||||||
context.fillText(vision.text, (canvas.width - metrics.width) / 2, 0.5 * canvas.height)
|
|
||||||
|
|
||||||
|
|
||||||
// canvas contents will be used for a texture
|
// canvas contents will be used for a texture
|
||||||
|
@ -93,22 +93,17 @@ public object ThreeMaterials {
|
|||||||
* Compute color
|
* Compute color
|
||||||
*/
|
*/
|
||||||
public fun Meta.threeColor(): Color? {
|
public fun Meta.threeColor(): Color? {
|
||||||
if (isEmpty()) return null
|
value?.let { value ->
|
||||||
val value = value
|
return when {
|
||||||
return if (isLeaf) {
|
|
||||||
when {
|
|
||||||
value == null -> null
|
|
||||||
value === Null -> null
|
value === Null -> null
|
||||||
value.type == ValueType.NUMBER -> Color(value.int)
|
value.type == ValueType.NUMBER -> Color(value.int)
|
||||||
else -> Color(value.string)
|
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? {
|
public fun ColorAccessor.threeColor(): Color? {
|
||||||
|
@ -16,11 +16,13 @@ public object ThreeReferenceFactory : ThreeFactory<SolidReference> {
|
|||||||
|
|
||||||
override val type: KClass<SolidReference> = SolidReference::class
|
override val type: KClass<SolidReference> = SolidReference::class
|
||||||
|
|
||||||
private fun Object3D.replicate(): Object3D {
|
private fun Object3D.replicate(): Object3D = when {
|
||||||
return when {
|
|
||||||
isMesh(this) -> Mesh(geometry, material).also {
|
isMesh(this) -> Mesh(geometry, material).also {
|
||||||
|
//clone geometry
|
||||||
|
it.material.cached = true
|
||||||
it.applyMatrix4(matrix)
|
it.applyMatrix4(matrix)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> clone(false)
|
else -> clone(false)
|
||||||
}.also { obj: Object3D ->
|
}.also { obj: Object3D ->
|
||||||
obj.name = this.name
|
obj.name = this.name
|
||||||
@ -28,7 +30,6 @@ public object ThreeReferenceFactory : ThreeFactory<SolidReference> {
|
|||||||
obj.add(child.replicate())
|
obj.add(child.replicate())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun build(three: ThreePlugin, vision: SolidReference, observe: Boolean): Object3D {
|
override fun build(three: ThreePlugin, vision: SolidReference, observe: Boolean): Object3D {
|
||||||
val template = vision.prototype
|
val template = vision.prototype
|
||||||
|
Loading…
Reference in New Issue
Block a user