Polyhedra shape

This commit is contained in:
Alexander Nozik 2019-07-10 20:14:37 +03:00
parent 3f47167c9d
commit 8fecd7647b
5 changed files with 47 additions and 129 deletions

View File

@ -1,31 +0,0 @@
//package hep.dataforge.vis.spatial.gdml
//
//import hep.dataforge.context.AbstractPlugin
//import hep.dataforge.context.Context
//import hep.dataforge.context.PluginFactory
//import hep.dataforge.context.PluginTag
//import hep.dataforge.meta.Meta
//import hep.dataforge.names.Name
//import hep.dataforge.names.toName
//import hep.dataforge.vis.spatial.three.ThreeFactory
//import hep.dataforge.vis.spatial.three.ThreePlugin
//import kotlin.reflect.KClass
//
//class GDMLPlugin : AbstractPlugin() {
// override val tag: PluginTag get() = GDMLPlugin.tag
//
// override fun dependsOn() = listOf(ThreePlugin)
//
// override fun provideTop(target: String): Map<Name, Any> {
// return when(target){
// ThreeFactory.TYPE-> mapOf("gdml".toName() to ThreeGDMLFactory)
// else -> emptyMap()
// }
// }
//
// companion object : PluginFactory<GDMLPlugin> {
// override val tag = PluginTag("vis.gdml", "hep.dataforge")
// override val type: KClass<GDMLPlugin> = GDMLPlugin::class
// override fun invoke(meta: Meta) = GDMLPlugin()
// }
//}

View File

@ -0,0 +1,16 @@
package hep.dataforge.vis.spatial.gdml
import hep.dataforge.meta.Meta
import hep.dataforge.vis.common.DisplayLeaf
import hep.dataforge.vis.common.VisualObject
import hep.dataforge.vis.spatial.GeometryBuilder
import hep.dataforge.vis.spatial.Shape
class Polyhedra(parent: VisualObject?, meta: Meta) : DisplayLeaf(parent, meta), Shape {
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}

View File

@ -1,92 +0,0 @@
//package hep.dataforge.vis.spatial.gdml
//
//import hep.dataforge.meta.Meta
//import hep.dataforge.meta.buildMeta
//import hep.dataforge.meta.toDynamic
//import hep.dataforge.meta.values
//import hep.dataforge.vis.common.DisplayLeaf
//import hep.dataforge.vis.common.VisualObject
//import hep.dataforge.vis.common.int
//import hep.dataforge.vis.spatial.three.MeshThreeFactory
////import hep.dataforge.vis.spatial.jsroot.createCubeBuffer
////import hep.dataforge.vis.spatial.jsroot.createGeometry
////import hep.dataforge.vis.spatial.jsroot.createTubeBuffer
////import hep.dataforge.vis.spatial.jsroot.createXtruBuffer
//import info.laht.threekt.core.BufferGeometry
//
//
//class GDMLShape(parent: VisualObject?, meta: Meta, val shape: GDMLSolid) :
// DisplayLeaf(parent, meta) {
//
// var facesLimit by int(0)
//
// companion object {
// const val TYPE = "geometry.3d.gdml"
// }
//}
//
//
//object ThreeGDMLFactory : MeshThreeFactory<GDMLShape>(GDMLShape::class) {
// //TODO fix ineffective conversion
// private fun Meta?.toJsRoot() = this?.let {
// buildMeta {
// values().forEach { (name, value) ->
// name.toString().replaceFirst("p", "f") to value
// }
// }
// }
//
// override fun buildGeometry(obj: GDMLShape): BufferGeometry {
// return when (obj.shape) {
// is GDMLBox -> createCubeBuffer(
// obj.shape.config.toJsRoot()?.toDynamic(),
// obj.facesLimit
// )
// is GDMLTube -> createTubeBuffer(
// obj.shape.config.toJsRoot()?.toDynamic(),
// obj.facesLimit
// )
// is GDMLXtru -> {
// val meta = buildMeta {
// val vertices = obj.shape.vertices
// val zs = obj.shape.sections.sortedBy { it.zOrder!! }
// "fNz" to zs.size
// "fNvert" to vertices.size
// "fX" to vertices.map { it.x }
// "fY" to vertices.map { it.y }
// "fX0" to zs.map { it.xOffsset }
// "fY0" to zs.map { it.yOffset }
// "fZ" to zs.map { it.zPosition!! }
// "fScale" to zs.map { it.scalingFactor }
// }
// createXtruBuffer(meta.toDynamic(), obj.facesLimit)
// }
// is GDMLUnion -> {
// val meta = buildMeta {
// "fNode.fLeft" to obj.shape.first()?.config.toJsRoot()
// "fNode.fRight" to obj.shape.second()?.config.toJsRoot()
// "fNode._typename" to "TGeoUnion"
// }
// createGeometry(meta.toDynamic(), obj.facesLimit)
// }
// is GDMLSubtraction -> {
// val meta = buildMeta {
// "fNode.fLeft" to obj.shape.first()?.config.toJsRoot()
// "fNode.fRight" to obj.shape.second()?.config.toJsRoot()
// "fNode._typename" to "TGeoSubtraction"
// }
// createGeometry(meta.toDynamic(), obj.facesLimit)
// }
// is GDMLIntersection -> {
// val meta = buildMeta {
// "fNode.fLeft" to obj.shape.first()?.config.toJsRoot()
// "fNode.fRight" to obj.shape.second()?.config.toJsRoot()
// "fNode._typename" to "TGeoIntersection"
// }
// createGeometry(meta.toDynamic(), obj.facesLimit)
// }
//
//
// }
// }
//}

View File

@ -7,6 +7,8 @@ import hep.dataforge.vis.common.VisualObject
import hep.dataforge.vis.common.color
import hep.dataforge.vis.spatial.*
import scientifik.gdml.*
import kotlin.math.cos
import kotlin.math.sin
private fun VisualObject.applyPosition(pos: GDMLPosition): VisualObject = apply {
@ -28,7 +30,14 @@ private fun VisualGroup.addSolid(root: GDML, solid: GDMLSolid, block: VisualObje
is GDMLBox -> box(solid.x, solid.y, solid.z)
is GDMLTube -> TODO()
is GDMLXtru -> extrude {
TODO()
shape {
solid.vertices.forEach {
point(it.x, it.y)
}
}
solid.sections.sortedBy { it.zOrder }.forEach { section ->
layer(section.zPosition ?: 0f, section.xOffset, section.yOffset, section.scalingFactor)
}
}
is GDMLScaledSolid -> {
//Add solid with modified scale
@ -46,7 +55,21 @@ private fun VisualGroup.addSolid(root: GDML, solid: GDMLSolid, block: VisualObje
thetaStart = solid.starttheta.toDouble()
}
is GDMLOrb -> sphere(solid.r)
is GDMLPolyhedra -> TODO()
is GDMLPolyhedra -> extrude {
//getting the radius of first
require(solid.planes.size > 1) { "The polyhedron geometry requires at least two planes" }
val baseRadius = solid.planes.first().rmax.toDouble()
shape {
(0..solid.numsides).forEach {
val phi = solid.deltaphi.toDouble() / solid.numsides * it + solid.startphi.toDouble()
baseRadius * cos(phi) to baseRadius * sin(phi)
}
}
solid.planes.forEach { plane ->
//scaling all radii relative to first layer radius
layer(plane.z, scale = plane.rmax.toDouble() / baseRadius)
}
}
is GDMLBoolSolid -> {
val first = solid.first.resolve(root) ?: error("")
val second = solid.second.resolve(root) ?: error("")
@ -85,8 +108,8 @@ private fun VisualGroup.addVolume(
}
gdmlVolume.physVolumes.forEach {
val volume = it.volumeref.resolve(root)?: error("Volume with ref ${it.volumeref.ref} could not be resolved")
addVolume(root,volume,resolveColor).apply {
val volume = it.volumeref.resolve(root) ?: error("Volume with ref ${it.volumeref.ref} could not be resolved")
addVolume(root, volume, resolveColor).apply {
it.resolvePosition(root)?.let { pos -> applyPosition(pos) }
it.resolveRotation(root)?.let { rot -> applyRotation(rot) }
}
@ -99,5 +122,5 @@ private fun VisualGroup.addVolume(
fun GDML.toVisual(): VisualGroup {
//TODO add materials cache
fun GDMLMaterialBase.color(): Meta = EmptyMeta
return VisualGroup().also { it.addVolume(this, world){color()} }
return VisualGroup().also { it.addVolume(this, world) { color() } }
}

View File

@ -1,8 +1,8 @@
package hep.dataforge.vis.spatial
import hep.dataforge.meta.*
import hep.dataforge.vis.common.VisualGroup
import hep.dataforge.vis.common.DisplayLeaf
import hep.dataforge.vis.common.VisualGroup
import hep.dataforge.vis.common.VisualObject
import kotlin.math.PI
import kotlin.math.cos
@ -18,6 +18,8 @@ class Shape2DBuilder {
list.add(Point2D(x, y))
}
infix fun Number.to(y:Number) = point(this, y)
fun build(): Shape2D = list
}