@@ -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(sinspheres){
valx=data.get().toFloat()
valy=data.get().toFloat()
valz=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?
valvx=props.get().toFloat()
valvy=props.get().toFloat()
valvz=props.get().toFloat()
valfx=props.get()
valfy=props.get()
valfz=props.get()
valspeed=GLVector(vx,vy,vz).magnitude()
valdirection=GLVector(vx,vy,vz).normalized
// update statistics
count++
sum+=speed
if(min>speed)
min=speed
if(max<speed)
max=speed
valavg=sum/count
valstd=(max-min)/sqrt(12f)// simplistic assumption of uniform distribution
// instead of just scaling speed linearly, apply sigmoid to get sharper blue and red
vala=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)
valdisp=(speed-avg)/std*a// speed / avg * a
valmindisp=(min-avg)/std*a
valscale=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
// println("Fetching data from the bytebuffers $c")
// println("Data has ${data?.get(c)?.remaining()} remaining")
valx=data!![c]?.get()?.toFloat()
valy=data!![c]?.get()?.toFloat()
valz=data!![c]?.get()?.toFloat()
//println("x is $x y is $y z is $z")
valvx=props!![c]?.get()?.toFloat()
valvy=props!![c]?.get()?.toFloat()
valvz=props!![c]?.get()?.toFloat()
valfx=props!![c]?.get()
valfy=props!![c]?.get()
valfz=props!![c]?.get()
println("$vx $vy $vz $fx $fy $fz")
valspeed=GLVector(vx!!,vy!!,vz!!).magnitude()
valdirection=GLVector(vx,vy,vz).normalized
// update statistics
count++
sum+=speed
if(min>speed)
min=speed
if(max<speed)
max=speed
valavg=sum/count
valstd=(max-min)/sqrt(12f)// simplistic assumption of uniform distribution
// instead of just scaling speed linearly, apply sigmoid to get sharper blue and red
vala=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)
valdisp=(speed-avg)/std*a// speed / avg * a
valmindisp=(min-avg)/std*a
valscale=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
vals=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
vals=spheres[c]!!.removeAt(counter)
scene.removeChild(s)
}
}
}
@Suppress("unused")
privatefunupdatePos(bb:ByteBuffer){
privatefunupdatePos(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()}")