Commit b2dccfd1 authored by argupta's avatar argupta
Browse files

changes structure to one vis core per node

parent 6a1c60c4
......@@ -81,15 +81,14 @@ class Head : SceneryBase("InVis Head") {
for (rank in 1 until commSize) {
val colorName = "ColorBuffer$rank"
val depthName = "DepthBuffer$rank"
image[rank - 1]?.position(0)
val color = image[rank - 1]?.duplicate()
image[rank-1]?.position(0)
val color = image[rank-1]?.duplicate()
color?.limit(windowSize * windowSize * 3)
image[rank - 1]?.position(windowSize * windowSize * 3)
val depth = image[rank - 1]?.slice()
image[rank - 1]?.position(0)
image[rank-1]?.position(windowSize * windowSize * 3)
val depth = image[rank-1]?.slice()
image[rank-1]?.position(0)
fsb.material.textures[colorName] = "fromBuffer:$colorName"
fsb.material.transferTextures[colorName] = GenericTexture("whatever", GLVector(windowSize.toFloat(), windowSize.toFloat(), 1.0f), 3, contents = color)
fsb.material.textures[depthName] = "fromBuffer:$depthName"
fsb.material.transferTextures[depthName] = GenericTexture("whatever", GLVector(windowSize.toFloat(), windowSize.toFloat(), 1.0f), 1, type = GLTypeEnum.Float, contents = depth)
fsb.material.needsTextureReload = true
......@@ -137,7 +136,9 @@ class Head : SceneryBase("InVis Head") {
override fun main() {
System.setProperty("scenery.master", "true")
settings.set("VideoEncoder.StreamVideo", true)
settings.set("H264Encoder.StreamingAddress", "udp://192.168.0.200:3337")
System.setProperty("scenery.MasterNode", "tcp://127.0.0.1:6666")
println("Head: Calling super.main!")
super.main()
}
......
package graphics.scenery.insitu
import cleargl.GLTypeEnum
import cleargl.GLVector
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.jogamp.opengl.math.Quaternion
import graphics.scenery.*
import graphics.scenery.backends.Renderer
import graphics.scenery.net.NodePublisher
import graphics.scenery.net.NodeSubscriber
import graphics.scenery.numerics.Random
import mpi.MPI
import mpi.MPIException
import mpi.Request
import org.junit.Test
import org.lwjgl.system.MemoryUtil
import org.msgpack.jackson.dataformat.MessagePackFactory
import org.slf4j.LoggerFactory
import org.zeromq.ZContext
import org.zeromq.ZMQ
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.nio.DoubleBuffer
import java.util.*
import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.fixedRateTimer
import kotlin.concurrent.thread
import kotlin.concurrent.timer
import kotlin.math.sqrt
class InVisRenderer : SceneryBase("InVisRenderer"){
val windowSize = 700
// ByteBuffer[] bufferList = new ByteBuffer[7]
val computePartners = 2
lateinit var data: DoubleBuffer
lateinit var props: DoubleBuffer
lateinit var spheres: ArrayList<Sphere>
var data: Array<DoubleBuffer?>? = arrayOfNulls(2)
var props: Array<DoubleBuffer?>? = arrayOfNulls(2)
// var spheres: Array<<ArrayList<Sphere>?>? = arrayOfNulls(2)
lateinit var spheres: Array<ArrayList<Sphere>?>
// stats
var count = 0L
......@@ -55,26 +45,21 @@ class InVisRenderer : SceneryBase("InVisRenderer"){
settings.set("Input.SlowMovementSpeed", 0.5f)
settings.set("Input.FastMovementSpeed", 1.0f)
// spheres = ArrayList(computePartners)
// data = ArrayList(computePartners)
// props = ArrayList(computePartners)
// data = Array(computePartners) { null }
// props = Array(computePartners) {ByteBuffer.allocateDirect(0).asDoubleBuffer()}
spheres = arrayOfNulls(2)
spheres[0] = ArrayList(0)
spheres[1] = ArrayList(0)
renderer = hub.add(SceneryElement.Renderer,
Renderer.createRenderer(hub, applicationName, scene, windowSize, windowSize))
val r = renderer as Renderer
r.activateParallelRendering()
spheres = ArrayList()
data.rewind()
while (data.remaining() > 3) {
val s = Sphere(Random.randomFromRange(0.04f, 0.02f), 10)
val x = data.get().toFloat()
val y = data.get().toFloat()
val z = data.get().toFloat()
// println("x is $x y is $y z is $z")
s.position = GLVector(x, y, z)
color = s.material.diffuse
scene.addChild(s)
spheres.add(s)
}
val box = Box(GLVector(10.0f, 10.0f, 10.0f), insideNormals = true)
box.material.diffuse = GLVector(0.9f, 0.9f, 0.9f)
box.material.cullingMode = Material.CullingMode.Front
......@@ -109,10 +94,11 @@ class InVisRenderer : SceneryBase("InVisRenderer"){
fixedRateTimer(initialDelay = 5, period = 5) {
lock.lock()
if (cont)
if (cont) {
update()
else
} else {
cancel()
}
lock.unlock()
}
......@@ -122,53 +108,82 @@ class InVisRenderer : SceneryBase("InVisRenderer"){
// check buffer if memory location changed
// this.getResult()
data.rewind()
props.rewind()
for (s in spheres) {
val x = data.get().toFloat()
val y = data.get().toFloat()
val z = data.get().toFloat()
//println("x is $x y is $y z is $z")
s.position = GLVector(x, y, z) // isn't this also a copy? can we just set s.position.mElements to a buffer?
val vx = props.get().toFloat()
val vy = props.get().toFloat()
val vz = props.get().toFloat()
val fx = props.get()
val fy = props.get()
val fz = props.get()
val speed = GLVector(vx, vy, vz).magnitude()
val direction = GLVector(vx, vy, vz).normalized
// update statistics
count++
sum += speed
if (min > speed)
min = speed
if (max < speed)
max = speed
val avg = sum / count
val std = (max - min) / sqrt(12f) // simplistic assumption of uniform distribution
// instead of just scaling speed linearly, apply sigmoid to get sharper blue and red
val a = 5f // to scale sigmoid function applied to disp, the larger the value the sharper the contrast
// val disp = (speed - avg) / (max - min) * 2*a // rescaling speed, between -a and a (just for this particular simulation; otherwise need to know average and stddev)
val disp = (speed - avg) / std * a // speed / avg * a
val mindisp = (min - avg) / std * a
val scale = disp / sqrt(1+disp*disp) - mindisp / sqrt(1+mindisp*mindisp) // * sqrt(1+a*a) / a // some sigmoidal scale factor, between -1 and 1, average 0
// s.material.diffuse = color.times(scale) // color.times(.8.toFloat()).plus(direction.times(.2.toFloat()))
// s.material.diffuse = direction
// s.material.diffuse = color.times(.5f).plus(direction.times(.5f)).times(scale)
// s.material.diffuse = GLVector(127 * (1 + scale), 0f, 127 * (1 - scale)) // blue for low speed, red for high
s.material.diffuse = GLVector(255 * scale, 0f, 255 * (1 - scale)) // blue for low speed, red for high
for(c in 0 until computePartners) {
data?.get(c)?.rewind()
props?.get(c)?.rewind()
var counter = 0
if (data?.get(c) == null || props?.get(c) == null) {
println("Buffers are null. Returning!")
return
}
while ( (data?.get(c)?.remaining()!! >= 3) && (props?.get(c)?.remaining()!! >= 6) ) {
// println("Fetching data from the bytebuffers $c")
// println("Data has ${data?.get(c)?.remaining()} remaining")
val x = data!![c]?.get()?.toFloat()
val y = data!![c]?.get()?.toFloat()
val z = data!![c]?.get()?.toFloat()
//println("x is $x y is $y z is $z")
val vx = props!![c]?.get()?.toFloat()
val vy = props!![c]?.get()?.toFloat()
val vz = props!![c]?.get()?.toFloat()
val fx = props!![c]?.get()
val fy = props!![c]?.get()
val fz = props!![c]?.get()
println("$vx $vy $vz $fx $fy $fz")
val speed = GLVector(vx!!, vy!!, vz!!).magnitude()
val direction = GLVector(vx, vy, vz).normalized
// update statistics
count++
sum += speed
if (min > speed)
min = speed
if (max < speed)
max = speed
val avg = sum / count
val std = (max - min) / sqrt(12f) // simplistic assumption of uniform distribution
// instead of just scaling speed linearly, apply sigmoid to get sharper blue and red
val a = 5f // to scale sigmoid function applied to disp, the larger the value the sharper the contrast
// val disp = (speed - avg) / (max - min) * 2*a // rescaling speed, between -a and a (just for this particular simulation; otherwise need to know average and stddev)
val disp = (speed - avg) / std * a // speed / avg * a
val mindisp = (min - avg) / std * a
val scale = disp / sqrt(1 + disp * disp) - mindisp / sqrt(1 + mindisp * mindisp) // * sqrt(1+a*a) / a // some sigmoidal scale factor, between -1 and 1, average 0
if (counter < spheres[c]!!.size) {
// if sphere exists, update its position and color
spheres[c]!![counter].position = GLVector(x!!, y!!, z!!) // isn't this also a copy? can we just set s.position.mElements to a buffer?
spheres[c]!![counter].material.diffuse = GLVector(255 * scale, 0f, 255 * (1 - scale)) // blue for low speed, red for high
} else {
// if sphere does not exist, create it and add it to the list
val s = Sphere(0.03f, 10)
s.position = GLVector(x!!, y!!, z!!) // isn't this also a copy? can we just set s.position.mElements to a buffer?
s.material.diffuse = GLVector(255 * scale, 0f, 255 * (1 - scale)) // blue for low speed, red for high
scene.addChild(s)
spheres[c]!!.add(s)
}
counter += 1
}
while (counter < spheres[c]!!.size) {
// if there are still some spheres remaining in the list, but no data remaining in memory, remove the remaining spheres
val s = spheres[c]!!.removeAt(counter)
scene.removeChild(s)
}
}
}
@Suppress("unused")
private fun updatePos(bb: ByteBuffer) {
private fun updatePos(bb: ByteBuffer, compRank: Int) {
// communicate rank through semaphores instead of checking all the time
// Two semaphores each for consumer and producer, one for each rank
// Producer posts on the rank it is currently using, consumer sees it and changes array
......@@ -176,13 +191,16 @@ class InVisRenderer : SceneryBase("InVisRenderer"){
// Perhaps only two or even one semaphore may suffice, toggling rank at each update
bb.order(ByteOrder.nativeOrder())
println("Capacity of original bytebuffer is ${bb.capacity()}")
lock.lock()
data = bb.asDoubleBuffer() // possibly set to data1, then at next update
println("Trying to update data buffer $compRank. I have the lock!")
data?.set(compRank, bb.asDoubleBuffer()) // possibly set to data1, then at next update
println("Capacity of double bytebuffer is ${data?.get(compRank)?.capacity()}")
lock.unlock()
}
@Suppress("unused")
private fun updateProps(bb: ByteBuffer) {
private fun updateProps(bb: ByteBuffer, compRank: Int) {
// communicate rank through semaphores instead of checking all the time
// Two semaphores each for consumer and producer, one for each rank
// Producer posts on the rank it is currently using, consumer sees it and changes array
......@@ -191,7 +209,8 @@ class InVisRenderer : SceneryBase("InVisRenderer"){
bb.order(ByteOrder.nativeOrder())
lock.lock()
props = bb.asDoubleBuffer() // possibly set to data1, then at next update
println("Trying to update props buffer $compRank. I have the lock!")
props?.set(compRank, bb.asDoubleBuffer()) // possibly set to data1, then at next update
lock.unlock()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment