forked from kscience/visionforge
Use KMath-geometry for solids
This commit is contained in:
parent
38302eac4c
commit
442fcb6c5b
@ -6,6 +6,7 @@ import space.kscience.dataforge.names.asName
|
|||||||
import space.kscience.dataforge.names.plus
|
import space.kscience.dataforge.names.plus
|
||||||
|
|
||||||
import space.kscience.gdml.*
|
import space.kscience.gdml.*
|
||||||
|
import space.kscience.kmath.geometry.RotationOrder
|
||||||
import space.kscience.visionforge.*
|
import space.kscience.visionforge.*
|
||||||
import space.kscience.visionforge.html.VisionOutput
|
import space.kscience.visionforge.html.VisionOutput
|
||||||
import space.kscience.visionforge.solid.*
|
import space.kscience.visionforge.solid.*
|
||||||
|
@ -8,6 +8,10 @@ import space.kscience.dataforge.meta.descriptors.value
|
|||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
import space.kscience.dataforge.names.asName
|
import space.kscience.dataforge.names.asName
|
||||||
import space.kscience.dataforge.names.plus
|
import space.kscience.dataforge.names.plus
|
||||||
|
import space.kscience.kmath.complex.Quaternion
|
||||||
|
import space.kscience.kmath.geometry.RotationOrder
|
||||||
|
import space.kscience.kmath.geometry.fromEuler
|
||||||
|
import space.kscience.kmath.geometry.radians
|
||||||
import space.kscience.visionforge.*
|
import space.kscience.visionforge.*
|
||||||
import space.kscience.visionforge.Vision.Companion.VISIBLE_KEY
|
import space.kscience.visionforge.Vision.Companion.VISIBLE_KEY
|
||||||
import space.kscience.visionforge.solid.Solid.Companion.DETAIL_KEY
|
import space.kscience.visionforge.solid.Solid.Companion.DETAIL_KEY
|
||||||
@ -122,15 +126,6 @@ public var Solid.layer: Int
|
|||||||
|
|
||||||
// Common properties
|
// Common properties
|
||||||
|
|
||||||
public enum class RotationOrder {
|
|
||||||
XYZ,
|
|
||||||
YZX,
|
|
||||||
ZXY,
|
|
||||||
XZY,
|
|
||||||
YXZ,
|
|
||||||
ZYX
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotation order
|
* Rotation order
|
||||||
*/
|
*/
|
||||||
@ -211,25 +206,42 @@ public var Solid.rotationX: Number by float(X_ROTATION_KEY, 0f)
|
|||||||
public var Solid.rotationY: Number by float(Y_ROTATION_KEY, 0f)
|
public var Solid.rotationY: Number by float(Y_ROTATION_KEY, 0f)
|
||||||
public var Solid.rotationZ: Number by float(Z_ROTATION_KEY, 0f)
|
public var Solid.rotationZ: Number by float(Z_ROTATION_KEY, 0f)
|
||||||
|
|
||||||
public var Solid.quaternion: Pair<Float, Float32Vector3D>?
|
/**
|
||||||
|
* Raw quaternion value defined in properties
|
||||||
|
*/
|
||||||
|
public var Solid.quaternionValue: Quaternion?
|
||||||
get() = properties.getValue(Solid.QUATERNION_KEY)?.list?.let {
|
get() = properties.getValue(Solid.QUATERNION_KEY)?.list?.let {
|
||||||
require(it.size == 4) { "Quaternion must be a number array of 4 elements" }
|
require(it.size == 4) { "Quaternion must be a number array of 4 elements" }
|
||||||
it[0].float to Float32Vector3D(it[1].float, it[2].float, it[3].float)
|
Quaternion(it[0].float, it[1].float, it[2].float, it[3].float)
|
||||||
}
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
properties.setValue(
|
properties.setValue(
|
||||||
Solid.QUATERNION_KEY,
|
Solid.QUATERNION_KEY,
|
||||||
value?.let {
|
value?.let {
|
||||||
ListValue(
|
ListValue(
|
||||||
value.first,
|
value.w,
|
||||||
value.second.x,
|
value.x,
|
||||||
value.second.y,
|
value.y,
|
||||||
value.second.z
|
value.z
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quaternion value including information from euler angles
|
||||||
|
*/
|
||||||
|
public var Solid.quaternion: Quaternion
|
||||||
|
get() = quaternionValue ?: Quaternion.fromEuler(
|
||||||
|
rotationX.radians,
|
||||||
|
rotationY.radians,
|
||||||
|
rotationZ.radians,
|
||||||
|
rotationOrder
|
||||||
|
)
|
||||||
|
set(value) {
|
||||||
|
quaternionValue = value
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//public var Solid.quaternion: Quaternion?
|
//public var Solid.quaternion: Quaternion?
|
||||||
// get() = meta[Solid::quaternion.name]?.value?.doubleArray?.let { Quaternion(it) }
|
// get() = meta[Solid::quaternion.name]?.value?.doubleArray?.let { Quaternion(it) }
|
||||||
|
@ -3,6 +3,7 @@ package space.kscience.visionforge.solid.transform
|
|||||||
import space.kscience.dataforge.misc.DFExperimental
|
import space.kscience.dataforge.misc.DFExperimental
|
||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
import space.kscience.dataforge.names.asName
|
import space.kscience.dataforge.names.asName
|
||||||
|
import space.kscience.kmath.complex.QuaternionField
|
||||||
import space.kscience.visionforge.root
|
import space.kscience.visionforge.root
|
||||||
import space.kscience.visionforge.solid.*
|
import space.kscience.visionforge.solid.*
|
||||||
|
|
||||||
@ -14,10 +15,7 @@ internal fun Solid.updateFrom(other: Solid): Solid {
|
|||||||
x += other.x
|
x += other.x
|
||||||
y += other.y
|
y += other.y
|
||||||
z += other.y
|
z += other.y
|
||||||
if(quaternion != null || other.quaternion != null) TODO("Quaternion support not implemented")
|
quaternion = with(QuaternionField) { other.quaternion * quaternion }
|
||||||
rotationX += other.rotationX
|
|
||||||
rotationY += other.rotationY
|
|
||||||
rotationZ += other.rotationZ
|
|
||||||
scaleX *= other.scaleX
|
scaleX *= other.scaleX
|
||||||
scaleY *= other.scaleY
|
scaleY *= other.scaleY
|
||||||
scaleZ *= other.scaleZ
|
scaleZ *= other.scaleZ
|
||||||
|
@ -49,15 +49,15 @@ public fun Object3D.updatePosition(vision: Vision) {
|
|||||||
// } else {
|
// } else {
|
||||||
// setRotationFromEuler( Euler(obj.rotationX, obj.rotationY, obj.rotationZ, obj.rotationOrder.name))
|
// setRotationFromEuler( Euler(obj.rotationX, obj.rotationY, obj.rotationZ, obj.rotationOrder.name))
|
||||||
// }
|
// }
|
||||||
val quaternion = vision.quaternion
|
val quaternion = vision.quaternionValue
|
||||||
|
|
||||||
if (quaternion != null) {
|
if (quaternion != null) {
|
||||||
setRotationFromQuaternion(
|
setRotationFromQuaternion(
|
||||||
Quaternion(
|
Quaternion(
|
||||||
quaternion.second.x,
|
quaternion.x,
|
||||||
quaternion.second.y,
|
quaternion.y,
|
||||||
quaternion.second.z,
|
quaternion.z,
|
||||||
quaternion.first
|
quaternion.w
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user