Doc updates

This commit is contained in:
Peter Klimai 2019-10-09 18:26:14 +03:00
parent 6ff8002485
commit f49ad3ee2c
12 changed files with 50 additions and 5 deletions

View File

@ -1,6 +1,6 @@
# DataForge Plugins for Visualisation # DataForge Plugins for Visualisation
This repository contains [DataForge](http://www.inr.ru/~nozik/dataforge/) This repository contains [DataForge](http://npm.mipt.ru/dataforge/)
(also [here](https://github.com/mipt-npm/dataforge-core)) components useful for visualization in (also [here](https://github.com/mipt-npm/dataforge-core)) components useful for visualization in
various scientific applications. Currently, the main application is 3D visualization for accelerator various scientific applications. Currently, the main application is 3D visualization for accelerator
experiments. experiments.

View File

@ -8,7 +8,7 @@ import kotlinx.serialization.Transient
/** /**
* Abstract implementation of group of [VisualObject] * Abstract implementation of mutable group of [VisualObject]
*/ */
abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup { abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup {
@ -60,6 +60,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup
} }
} }
// TODO Consider renaming to `StructureChangeListener` (singular)
private data class StructureChangeListeners(val owner: Any?, val callback: (Name, VisualObject?) -> Unit) private data class StructureChangeListeners(val owner: Any?, val callback: (Name, VisualObject?) -> Unit)
@Transient @Transient

View File

@ -12,6 +12,9 @@ internal data class PropertyListener(
val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit
) )
/**
* Abstract implementation of [VisualObject]
*/
abstract class AbstractVisualObject : VisualObject { abstract class AbstractVisualObject : VisualObject {
@Transient @Transient
@ -19,6 +22,9 @@ abstract class AbstractVisualObject : VisualObject {
abstract override var properties: Config? abstract override var properties: Config?
/**
* Style(s) of the object
*/
override var style: List<String> override var style: List<String>
get() = properties?.let { it[STYLE_KEY].stringList } ?: emptyList() get() = properties?.let { it[STYLE_KEY].stringList } ?: emptyList()
set(value) { set(value) {

View File

@ -3,7 +3,8 @@ package hep.dataforge.vis.common
import kotlin.math.max import kotlin.math.max
/** /**
* Taken from https://github.com/markaren/three.kt/blob/master/threejs-wrapper/src/main/kotlin/info/laht/threekt/math/ColorConstants.kt * Definitions of common colors. Taken from
* https://github.com/markaren/three.kt/blob/master/threejs-wrapper/src/main/kotlin/info/laht/threekt/math/ColorConstants.kt
*/ */
object Colors { object Colors {
const val aliceblue = 0xF0F8FF const val aliceblue = 0xF0F8FF
@ -177,11 +178,17 @@ object Colors {
const val yellow = 0xFFFF00 const val yellow = 0xFFFF00
const val yellowgreen = 0x9ACD32 const val yellowgreen = 0x9ACD32
/**
* Convert Int color to string of format #rrggbb
*/
fun rgbToString(rgb: Int): String { fun rgbToString(rgb: Int): String {
val string = rgb.toString(16).padStart(6, '0') val string = rgb.toString(16).padStart(6, '0')
return "#" + string.substring(max(0, string.length - 6)) return "#" + string.substring(max(0, string.length - 6))
} }
/**
* Convert three bytes representing color to string of format #rrggbb
*/
fun rgbToString(red: UByte, green: UByte, blue: UByte): String { fun rgbToString(red: UByte, green: UByte, blue: UByte): String {
fun colorToString(color: UByte): String{ fun colorToString(color: UByte): String{
return color.toString(16).padStart(2,'0') return color.toString(16).padStart(2,'0')

View File

@ -4,6 +4,9 @@ import hep.dataforge.meta.Meta
import hep.dataforge.names.* import hep.dataforge.names.*
import hep.dataforge.provider.Provider import hep.dataforge.provider.Provider
/**
* Represents a group of [VisualObject] instances
*/
interface VisualGroup : Provider, Iterable<VisualObject>, VisualObject { interface VisualGroup : Provider, Iterable<VisualObject>, VisualObject {
/** /**
* A map of top level named children * A map of top level named children
@ -52,6 +55,9 @@ interface VisualGroup : Provider, Iterable<VisualObject>, VisualObject {
} }
} }
/**
* Mutable version of [VisualGroup]
*/
interface MutableVisualGroup : VisualGroup { interface MutableVisualGroup : VisualGroup {
/** /**

View File

@ -67,9 +67,19 @@ interface VisualObject : MetaRepr, Configurable {
} }
} }
/**
* Get [VisualObject] property using key as a String
*/
fun VisualObject.getProperty(key: String, inherit: Boolean = true): MetaItem<*>? = getProperty(key.toName(), inherit) fun VisualObject.getProperty(key: String, inherit: Boolean = true): MetaItem<*>? = getProperty(key.toName(), inherit)
/**
* Set [VisualObject] property using key as a String
*/
fun VisualObject.setProperty(key: String, value: Any?) = setProperty(key.toName(), value) fun VisualObject.setProperty(key: String, value: Any?) = setProperty(key.toName(), value)
/**
* Apply style to [VisualObject] by adding it to the [style] list
*/
fun VisualObject.applyStyle(name: String) { fun VisualObject.applyStyle(name: String) {
style = style + name style = style + name
} }

View File

@ -3,12 +3,18 @@ package hep.dataforge.vis.common
import hep.dataforge.descriptors.ValueDescriptor import hep.dataforge.descriptors.ValueDescriptor
import hep.dataforge.meta.* import hep.dataforge.meta.*
/**
* Extension property to access the "widget" key of [ValueDescriptor]
*/
var ValueDescriptor.widget: Meta var ValueDescriptor.widget: Meta
get() = this.config["widget"].node?: EmptyMeta get() = this.config["widget"].node?: EmptyMeta
set(value) { set(value) {
this.config["widget"] = value this.config["widget"] = value
} }
/**
* Extension property to access the "widget.type" key of [ValueDescriptor]
*/
var ValueDescriptor.widgetType: String? var ValueDescriptor.widgetType: String?
get() = this["widget.type"].string get() = this["widget.type"].string
set(value) { set(value) {

View File

@ -62,7 +62,7 @@ class Extruded(
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) { override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
val shape: Shape2D = shape val shape: Shape2D = shape
if (shape.size < 3) error("Extruded shape requires more than points per layer") if (shape.size < 3) error("Extruded shape requires more than 2 points per layer")
/** /**
* Expand the shape for specific layers * Expand the shape for specific layers

View File

@ -27,6 +27,9 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers import kotlinx.serialization.UseSerializers
import kotlin.collections.set import kotlin.collections.set
/**
* Represents 3-dimensional Visual Group
*/
@Serializable @Serializable
class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { class VisualGroup3D : AbstractVisualGroup(), VisualObject3D {
/** /**

View File

@ -14,6 +14,9 @@ import hep.dataforge.vis.spatial.VisualObject3D.Companion.SELECTED_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
import kotlinx.serialization.UseSerializers import kotlinx.serialization.UseSerializers
/**
* Interface for 3-dimensional [VisualObject]
*/
interface VisualObject3D : VisualObject { interface VisualObject3D : VisualObject {
var position: Point3D? var position: Point3D?
var rotation: Point3D? var rotation: Point3D?

View File

@ -6,7 +6,7 @@ import info.laht.threekt.core.BufferGeometry
import info.laht.threekt.objects.Mesh import info.laht.threekt.objects.Mesh
/** /**
* This should be inner, becaulse it uses object builder * This should be inner, because it uses object builder
*/ */
class ThreeCompositeFactory(val three: ThreePlugin) : MeshThreeFactory<Composite>(Composite::class) { class ThreeCompositeFactory(val three: ThreePlugin) : MeshThreeFactory<Composite>(Composite::class) {

View File

@ -16,6 +16,9 @@ import info.laht.threekt.math.Matrix4
import info.laht.threekt.math.Vector3 import info.laht.threekt.math.Vector3
import info.laht.threekt.objects.Mesh import info.laht.threekt.objects.Mesh
/**
* Constructive Solid Geometry
*/
open external class CSG { open external class CSG {
open var polygons: Array<Polygon> open var polygons: Array<Polygon>
open fun clone(): CSG open fun clone(): CSG