Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r505 - in branches/AFR/Engine: Control ImageTraversers
- Date: Fri, 26 Aug 2005 13:25:33 -0600 (MDT)
Author: abe
Date: Fri Aug 26 13:25:32 2005
New Revision: 505
Modified:
branches/AFR/Engine/Control/AFRPipeline.cc
branches/AFR/Engine/ImageTraversers/AFImageTraverser.cc
branches/AFR/Engine/ImageTraversers/AFImageTraverser.h
Log:
removed setup frame, can call master etc directly from pipeline, need to edit
image.h
Modified: branches/AFR/Engine/Control/AFRPipeline.cc
==============================================================================
--- branches/AFR/Engine/Control/AFRPipeline.cc (original)
+++ branches/AFR/Engine/Control/AFRPipeline.cc Fri Aug 26 13:25:32 2005
@@ -1,5 +1,6 @@
+
/*
For more information, please see:
http://software.sci.utah.edu
@@ -247,7 +248,7 @@
name << "AFRPipeline Worker " << i;
// Construct the thread.
- Thread* t = new Thread(new Worker(this, i, false), name.str().c_str(),
0, Thread::NotActivated);
+ Thread* t = new Thread(new Manta::Worker(this, i, false),
name.str().c_str(), 0, Thread::NotActivated);
t->setStackSize(RENDER_THREAD_STACKSIZE);
t->activate(false);
workers[i] = t;
Modified: branches/AFR/Engine/ImageTraversers/AFImageTraverser.cc
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFImageTraverser.cc (original)
+++ branches/AFR/Engine/ImageTraversers/AFImageTraverser.cc Fri Aug 26
13:25:32 2005
@@ -125,12 +125,11 @@
// note that max fragment size is hard coded to 32 in fragment.h
// so not to exceed that limit.
- fragment_size = 16; // ****** HARD CODED *******
chunk_size = num_clients*256; // this is done so that
- // program scales well when #processors increase
+ // program scales well when #processors
increase
int qSize = (int)(samplingrate*0.1);
frametype = new FrameType[num_clients+1];
- numFragments = chunk_size/(num_clients*fragment_size);
+ numFragments = (int)ceil((float)chunk_size/(float)(num_clients));
temporalQ = new CQ<Sample>[num_clients];
sampleQ[EVEN_FRAME] = new Sample[chunk_size];
sampleQ[ODD_FRAME] = new Sample[chunk_size];
@@ -159,24 +158,6 @@
allocateFragments(EVEN_FRAME);
}
-void AFImageTraverser::setupFrame(const RenderContext& context)
-{
- if(context.proc==0) // master gthread
- {
- // get the current time
- //using namespace SCIRun;
- //cout << "setting up frame in master " << endl;
- chunkTimeStamp =
(float)samples_done/(float)samplingrate;//Time::currentSeconds();
- }
- //else
- //{
- //cout << "setting up frame in client" << endl;
- // get the assignment from the load balancer.
- context.loadBalancer->setupFrame(context);
- //}
- //cout << "done setup frame" << endl;
-}
-
// Called from setupDisplayChannel.
// Called from masterThread.
void AFImageTraverser::allocateFragments(const FrameType f) {
@@ -207,9 +188,6 @@
RayPacketData raydata;
RayPacket rays(raydata, size, depth, flags);
double cx, cy;
- Fragment f; // for output to image
- f.setSize(size);
- f.setFlags(Fragment::ConstantEye);
int isx, isy;
isx = (int)sx;
isy = (int)sy;
@@ -219,23 +197,22 @@
s->c[0], s->c[1], s->c[2]);
float t = (float)chunkTimeStamp;
+ Color color[5];
for(int i=0;i<size;i++) {
// normalized
- Fragment::Element& fe = f.get(i);
- fe.which_eye = 0;
double px, py;
switch(i)
{
- case 0: cx = sx; cy = sy; fe.x = isx; fe.y = isy;
+ case 0: cx = sx; cy = sy;
break; // center
- case 1: cx = sx-1; cy = sy; fe.x = isx-1; fe.y = isy;
+ case 1: cx = sx-1; cy = sy;
break; // left
- case 2: cx = sx+1; cy = sy; fe.x = isx+1; fe.y = isy;
+ case 2: cx = sx+1; cy = sy;
break; // right
- case 3: cx = sx; cy = sy-1; fe.x = isx; fe.y = isy-1;
+ case 3: cx = sx; cy = sy-1;
break; // bottom
- case 4: cx = sx; cy = sy+1; fe.x = isx; fe.y = isy+1;
+ case 4: cx = sx; cy = sy+1;
break; // top
};
//cout << "raytracing: " << cx << ", " << cy << endl;
@@ -251,7 +228,7 @@
py = (double)(-1.0 + 2.0*cy/(double)xres);
}
//printf("%f, %f\n", (float)px, (float)py);
- rays.setPixel(i, 0, px, py, &fe.color);
+ rays.setPixel(i, 0, px, py, &color[i]);
}
// Trace the rays. The results will automatically go into the fragment
context.renderer->traceEyeRays(context, rays);
@@ -259,30 +236,34 @@
// okay now copy from fragment to temporalQ
for(int i=0;i<size;i++) {
RayPacket::Element& re = rays.get(i);
- Fragment::Element& fe = f.get(i);
- RGBColor tempcol = fe.color.convertRGB();
+ RGBColor tempcol = color[i].convertRGB();
Point p = re.hitPosition;
switch(i)
{
case 0:
ss.set(CENTER_SAMPLE, sx, sy, t, p.x(), p.y(), p.z(),
tempcol.r(), tempcol.g(), tempcol.b());
+ image->set(sx, sy, color[i]);
break;
case 1:
ss.set(LEFT_SAMPLE, sx-1, sy, t, p.x(), p.y(), p.z(),
tempcol.r(), tempcol.g(), tempcol.b());
+ image->set(sx-1, sy, color[i]);
break;
case 2:
ss.set(RIGHT_SAMPLE, sx+1, sy, t, p.x(), p.y(), p.z(),
tempcol.r(), tempcol.g(), tempcol.b());
+ image->set(sx+1, sy, color[i]);
break;
case 3:
ss.set(BOTTOM_SAMPLE, sx, sy-1, t, p.x(), p.y(), p.z(),
tempcol.r(), tempcol.g(), tempcol.b());
+ image->set(sx, sy-1, color[i]);
break;
case 4:
ss.set(TOP_SAMPLE, sx, sy+1, t, p.x(), p.y(), p.z(),
tempcol.r(), tempcol.g(), tempcol.b());
+ image->set(sx, sy+1, color[i]);
break;
};
}
@@ -290,38 +271,29 @@
ss.computeGradients(t);
//cout << "inserting in Q, commented" << endl;
samplesetQ[frametype[myID]][myID-1].qInsert(&ss);
- //cout << "setting image for the xhair fragment" << endl;
- image->set(f);
//cout << "DONE" << endl;
}
///////////////////////////////////////////////////////////////////////////////
-// Render all of samples in a fragment.
-// This is similar to a pixel sampler.
+// Render all of samples in a fragment of the chunk.
///////////////////////////////////////////////////////////////////////////////
void AFImageTraverser::renderFragment(const RenderContext& context,
- int assignment, Image* image,
+ int chunkstart, int chunkend, Image*
image,
int xres, int yres)
{
//cout << "inside renderFragment " << endl;
// renders the fragment by jittering it and stores result in temporalQ
int flags = RayPacket::HaveImageCoordinates | RayPacket::ConstantEye;
- Fragment fragment;
- int fsize = (fragment_size<(chunk_size-assignment*fragment_size))?
- fragment_size : (chunk_size-assignment*fragment_size);
- fragment.setSize(fsize);
- fragment.setFlags(Fragment::ConstantEye);
- int myID = context.proc;
-
-
/////////////////////////////////////////////////////////////////////////////
- // Create ray packets.
+ int myID = context.proc;
+ int fsize = chunkend - chunkstart;
+ Color color[RayPacket::MaxSize];
+
/////////////////////////////////////////////////////////////////////////////
+ // Create ray packets.
for(int f=0;f<fsize;f+=RayPacket::MaxSize) {
-
- int size = RayPacket::MaxSize;
- if(size<fragment_size) size = fsize;
+ int size = RayPacket::MaxSize;
if(size >= fsize-f)
size = fsize-f;
@@ -330,17 +302,13 @@
RayPacketData raydata;
RayPacket rays(raydata, size, depth, flags);
- // Copy samples from the sampleQ into the fragment.
+ // Copy samples from the sampleQ into the fragment.
for(int i=0;i<size;i++) {
- Fragment::Element& fe = fragment.get(f+i);
float cx, cy;
- int sind = fragment_size*assignment + f+i;
+ int sind = chunkstart + f + i;
cx = sampleQ[frametype[myID]][sind].viewCoord[0];
cy = sampleQ[frametype[myID]][sind].viewCoord[1];
- fe.x = (int)cx;
- fe.y = (int)cy;
- fe.which_eye = 0;
// normalized
double px, py;
@@ -358,37 +326,35 @@
}
// Specify the position and color pointer for the packet element.
- rays.setPixel(i, 0, px, py, &fe.color);
+ rays.setPixel(i, 0, px, py, &color[i]);
}
///////////////////////////////////////////////////////////////////////////
// Trace the rays. The results will automatically go into the fragment
context.renderer->traceEyeRays(context, rays);
- // Compute world space hit positions.
+ // Compute world space hit positions.
rays.computeHitPositions();
-
///////////////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////////////
// okay now copy from fragment to temporalQ
for(int i=0;i<size;i++) {
- int sind = fragment_size*assignment + f+i;
- Fragment::Element& fe = fragment.get(f+i);
-
+ int sind = chunkstart + f + i;
RayPacket::Element& re = rays.get(i);
- RGBColor tempcol = fe.color.convertRGB();
+ RGBColor tempcol = color[i].convertRGB();
sampleQ[frametype[myID]][sind].c[0] = tempcol.r();
sampleQ[frametype[myID]][sind].c[1] = tempcol.g();
sampleQ[frametype[myID]][sind].c[2] = tempcol.b();
sampleQ[frametype[myID]][sind].worldCoord[0] = re.hitPosition.x();
sampleQ[frametype[myID]][sind].worldCoord[1] = re.hitPosition.y();
sampleQ[frametype[myID]][sind].worldCoord[2] = re.hitPosition.z();
+
/////////////////////////////////////////////////////////////////////////////
+ // Skip reconstruction and set the image pixel.
+ image->set(sampleQ[frametype[myID]][sind].viewCoord[0],
sampleQ[frametype[myID]][sind].viewCoord[1], color[i]);
}
}
-
/////////////////////////////////////////////////////////////////////////////
- // Skip reconstruction and set the image pixel.
- image->set(fragment);
}
///////////////////////////////////////////////////////////////////////////////
@@ -396,37 +362,7 @@
///////////////////////////////////////////////////////////////////////////////
void AFImageTraverser::renderImage( const RenderContext& context, Image*
image ) {
- // Basically do the following, if it is a master thread call master
function, else
- // call the client function
-
- if(context.proc == 0) // master thread
- {
- masterThread(context, image);
- image->setValid(true);
- //cout << "masterthread done" << endl;
- }
- else
- {
- //cout << "here we call client" << endl;
- int s,e;
- // this is what every thread does: gets the next assignment and render
it.
- while(context.loadBalancer->getNextAssignment(context, s, e)) {
- //cout << "loadbalancer returned " << s << ", " << e << endl;
- for(int assignment = s; assignment < e; assignment++) {
- clientThread(context, image, assignment);
- }
- }
-
- // update the frame type
-
- // Do all of the threads call this??
-
- if(frametype[context.proc]==EVEN_FRAME)
- frametype[context.proc] = ODD_FRAME;
- else
- frametype[context.proc] = EVEN_FRAME;
- //cout << "clientThread done" << endl;
- }
+// we do nothing here, AFRPipeline direcly calls master/client blocks
}
@@ -444,6 +380,7 @@
FrameType prevFrameType = (frametype[0]==EVEN_FRAME)? ODD_FRAME :
EVEN_FRAME;
+ chunkTimeStamp =
(float)samples_done/(float)samplingrate;//Time::currentSeconds();
// return during intialization here
if(!initpass)
{
@@ -493,6 +430,11 @@
allocateFragments(EVEN_FRAME);
frametype[0] = EVEN_FRAME;
}
+ image->setValid(true);
+ if(frametype[context.proc]==EVEN_FRAME)
+ frametype[context.proc] = ODD_FRAME;
+ else
+ frametype[context.proc] = EVEN_FRAME;
//cout << "allocation done, now incrementing sample count" << endl;
//cout << "masterThread done" << endl;
}
@@ -500,7 +442,7 @@
///////////////////////////////////////////////////////////////////////////////
// This method implements the master thread functionality.
///////////////////////////////////////////////////////////////////////////////
-void AFImageTraverser::clientThread(const RenderContext& context, Image*
image, int assignment) {
+void AFImageTraverser::clientThread(const RenderContext& context, Image*
image) {
//cout << "inside clientThread for frametype " << frametype[context.proc]
<< endl;
bool stereo;
@@ -509,15 +451,16 @@
int myID = context.proc;
Sample s;
//cout << "calling renderFragment for allotted fragment, myID = " << myID
<< endl;
- renderFragment(context, assignment, image, xres, yres);
+ int chunkstart = (context.proc-1)*numFragments;
+ int chunkend = (chunk_size<context.proc*numFragments)? chunk_size :
context.proc*numFragments;
+ renderFragment(context, chunkstart, chunkend, image, xres, yres);
//cout << "done RenderFragment" << endl;
// let us not write temporal samples to image
//cout << "now placing fragment in temporalQ" << endl;
- for(int i=0; i<fragment_size; i++) {
- //cout << "placing id: " << frametype[myID] << ", " <<
fragment_size*assignment+i << endl;
-
temporalQ[myID-1].qInsert(&sampleQ[frametype[myID]][fragment_size*assignment+i]);
+ for(int i=chunkstart; i<chunkend; i++) {
+ temporalQ[myID-1].qInsert(&sampleQ[frametype[myID]][i]);
}
//cout << "placement in temporalQ done" << endl;
@@ -530,7 +473,7 @@
int i;
Sample *sp;
//cout << "now making xhairs" << endl;
- for(i=0; i<fragment_size; i++) {
+ for(i=0; i<(chunkend-chunkstart); i++) {
sp = temporalQ[myID-1].seekLast();
if(sp!=NULL) {
@@ -570,6 +513,10 @@
}
}
}
+ if(frametype[context.proc]==EVEN_FRAME)
+ frametype[context.proc] = ODD_FRAME;
+ else
+ frametype[context.proc] = EVEN_FRAME;
//cout << "making xhairs done" << endl;
}
Modified: branches/AFR/Engine/ImageTraversers/AFImageTraverser.h
==============================================================================
--- branches/AFR/Engine/ImageTraversers/AFImageTraverser.h (original)
+++ branches/AFR/Engine/ImageTraversers/AFImageTraverser.h Fri Aug 26
13:25:32 2005
@@ -33,14 +33,14 @@
void allocateFragments(const FrameType f);
// Render fragments.
- void renderFragment(const RenderContext& context, int
assignment, Image* image, int xres, int yres);
+ void renderFragment(const RenderContext& context, int
chunkstart, int chunkend, Image* image, int xres, int yres);
void renderCrossHair(const RenderContext& context,
int myID, Image *image, int xres, int yres, Sample *s);
// Master thread task.
void masterThread(const RenderContext& context,
Image* image);
// Sampler/Renderer task.
- void clientThread(const RenderContext& context,
Image* image, int assignment);
+ void clientThread(const RenderContext& context,
Image* image);
// Update kdtree-cut.
void adjustTiles(Timestamp currenttime);
@@ -54,7 +54,7 @@
// Image kd-tree.
KDTree kdtree;
- // Not sure ???
+ // number of fragments a chunk is divided into. It is
divided equally amongst all clients
int numFragments;
//
@@ -73,7 +73,7 @@
// ??????????????
int num_clients;
- int chunk_size, fragment_size;
+ int chunk_size;
int samplingrate;
unsigned int samples_done;
- [MANTA] r505 - in branches/AFR/Engine: Control ImageTraversers, abe, 08/26/2005
Archive powered by MHonArc 2.6.16.