Text archives Help
- From: cgribble@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1085 - in trunk: Engine/Control Model/Materials scenes
- Date: Wed, 24 May 2006 13:58:11 -0600 (MDT)
Author: cgribble
Date: Wed May 24 13:58:11 2006
New Revision: 1085
Modified:
trunk/Engine/Control/DynPLTWorker.cc
trunk/Engine/Control/DynPLTWorker.h
trunk/Model/Materials/DynPLTMaterial.cc
trunk/scenes/dynplt.cc
Log:
Engine/Control/DynPLTWorker.h
Engine/Control/DynPLTWorker.cc
Added control logic for texture dilation
Model/Materials/DynPLTMaterial.cc
Added texture dilation code; no longer convinced this is necessary, so it's
turned off by default
scenes/dynplt.cc
Added flags for controling texture dilation (off by default)
Modified: trunk/Engine/Control/DynPLTWorker.cc
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.cc (original)
+++ trunk/Engine/Control/DynPLTWorker.cc Wed May 24 13:58:11 2006
@@ -19,9 +19,10 @@
DynPLTContext::DynPLTContext(SCIRun::Mailbox<const Sphere*>* queue,
Scene* scene, unsigned int ngroups,
- unsigned int nsamples, unsigned int max_depth) :
+ unsigned int nsamples, unsigned int max_depth,
+ bool dilate) :
queue(queue), scene(scene), ngroups(ngroups), nsamples(nsamples),
- max_depth(max_depth)
+ max_depth(max_depth), dilate(dilate)
{
// Ensure that the number of samples is a perfect square
nsamples_root=static_cast<int>(SCIRun::Ceil(SCIRun::Sqrt(static_cast<Real>(nsamples))));
@@ -117,6 +118,7 @@
// Intialize the textures
bzero(dynplt->texture, xres*yres*sizeof(float));
bzero(dynplt->inside, xres*yres*sizeof(float));
+ bool dilateTexture=false;
// Generate particle's texture
Vector center=particle->getCenter();
@@ -292,6 +294,7 @@
// Either way, ignore the hit and mark the texel for
// dilation
dynplt->inside[u][v] += 1;
+ dilateTexture=true;
}
}
@@ -331,7 +334,7 @@
}
}
- if (context->dilate)
+ if (context->dilate && dilateTexture)
dynplt->dilate(context);
// XXX: maybe use a transaction to mark the texture as valid and prevent
Modified: trunk/Engine/Control/DynPLTWorker.h
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.h (original)
+++ trunk/Engine/Control/DynPLTWorker.h Wed May 24 13:58:11 2006
@@ -22,7 +22,7 @@
public:
DynPLTContext(SCIRun::Mailbox<const Sphere*>* queue, Scene* scene,
unsigned int ngroups, unsigned int nsamples,
- unsigned int max_depth);
+ unsigned int max_depth, bool dilate);
~DynPLTContext(void) { }
// DynPLT work queue
Modified: trunk/Model/Materials/DynPLTMaterial.cc
==============================================================================
--- trunk/Model/Materials/DynPLTMaterial.cc (original)
+++ trunk/Model/Materials/DynPLTMaterial.cc Wed May 24 13:58:11 2006
@@ -1,5 +1,6 @@
#include <Core/Exceptions/InternalError.h>
+#include <Engine/Control/DynPLTWorker.h>
#include <Model/Materials/DynPLTMaterial.h>
#include <Model/Primitives/Sphere.h>
#include <Model/Textures/Constant.h>
@@ -15,14 +16,14 @@
DynPLTMaterial::DynPLTMaterial(SCIRun::Mailbox<const Sphere*>* queue,
const Color& color) :
- queue(queue)
+ queue(queue), valid(false), requested(false)
{
colortex=new Constant<Color>(color);
}
DynPLTMaterial::DynPLTMaterial(SCIRun::Mailbox<const Sphere*>* queue,
const Texture<Color>* colorfn) :
- queue(queue), colortex(colorfn)
+ queue(queue), valid(false), requested(false), colortex(colorfn)
{
// Do nothing
}
@@ -43,7 +44,7 @@
rays.computeTextureCoordinates2(context);
for (unsigned int i=rays.begin(); i < rays.end(); ++i) {
- // Wrap in x (assumes x is a power of two)
+ // Wrap in x (assumes xres is a power of two)
Real x=rays.getTexCoords2(i, 0)*XRES;
int lx=static_cast<int>(x) & (XRES - 1);
int hx=(lx + 1) & (XRES - 1);
@@ -73,7 +74,6 @@
}
int hy=ly + 1;
- // end XXX
// Interpolate
Real a=(texture[lx][ly] * (1 - wx) +
@@ -163,5 +163,81 @@
void DynPLTMaterial::dilate(const DynPLTContext* context)
{
- // Do nothing
+ // Compute the min and max of inside texture
+ unsigned int width=XRES;
+ unsigned int height=YRES;
+ Real min=inside[0][0];
+ Real max=inside[0][0];
+ for (unsigned int y=1; y<height; ++y) {
+ for (unsigned int x=1; x<width; ++x) {
+ Real tmp=inside[x][y];
+ if (tmp < min)
+ min=tmp;
+ if (tmp > max)
+ max=tmp;
+ }
+ }
+
+ // Normalize the inside texture
+ Real inv_maxmin=1/(max-min);
+ for (unsigned int y=0; y<height; ++y)
+ for (unsigned int x=0; x<width; ++x)
+ inside[x][y]=(inside[x][y] - min)*inv_maxmin;
+
+ // Initialize the dilated texture
+ Real dilated[XRES][YRES];
+ for (unsigned int y=0; y<height; ++y)
+ for (unsigned int x=0; x<width; ++x)
+ dilated[x][y]=texture[x][y];
+
+ // Dilate any necessary pixels
+ unsigned int support=context->support;
+ unsigned int use_weighted_avg=context->use_weighted_avg;
+ Real threshold=context->threshold;
+
+ for (unsigned int y=0; y < height; ++y) {
+ for (unsigned int x=0; x < width; ++x) {
+ // Determine if the pixel should be dilated
+ Real value=inside[x][y];
+ if (value<=0)
+ continue;
+
+ // Loop over each neighbor
+ Real avg=0;
+ Real contribution_total=0;
+ for (unsigned int j=y-support; j <= y+support; j++) {
+ for (unsigned int i=x-support; i <= x+support; i++) {
+ // Check boundary conditions
+ unsigned int newi=i;
+ if (newi >= width)
+ newi=newi - width;
+ else if (newi < 0)
+ newi += width;
+
+ unsigned int newj=j;
+ if (newj >= height)
+ newj=height - 1;
+ else if (newj < 0)
+ newj=0;
+
+ // Determine neighbor's contribution
+ Real contributer=inside[newi][newj];
+ if (contributer < threshold) {
+ contributer *= use_weighted_avg;
+ avg += texture[newi][newj]*(1 - contributer);
+ contribution_total += (1 - contributer);
+ }
+ }
+ }
+
+ // Dilate the pixel
+ if (contribution_total > 0)
+ dilated[x][y]=avg/contribution_total;
+ }
+ }
+
+ // Update texture with dilated results
+ for (unsigned int y=0; y<height; ++y)
+ for (unsigned int x=0; x<width; ++x)
+ texture[x][y]=dilated[x][y];
}
Modified: trunk/scenes/dynplt.cc
==============================================================================
--- trunk/scenes/dynplt.cc (original)
+++ trunk/scenes/dynplt.cc Wed May 24 13:58:11 2006
@@ -31,6 +31,7 @@
{
Group* world=0;
string fname="";
+ bool dilate=false;
int max_depth=3;
int ngroups=100;
int nsamples=32;
@@ -49,13 +50,15 @@
if (!getStringArg(i, args, s))
throw IllegalArgument("scene dynplt -bv", i, args);
world=context.manta_interface->makeGroup(s);
+ } else if (arg=="-dilate") {
+ dilate=true;
+ } else if (arg=="-i") {
+ if (!getStringArg(i, args, fname))
+ throw IllegalArgument("scene dynplt -i", i, args);
} else if (arg=="-nbounces") {
if (!getIntArg(i, args, max_depth))
throw IllegalArgument("scene dynplt -nbounces", i, args);
++max_depth;
- } else if (arg=="-i") {
- if (!getStringArg(i, args, fname))
- throw IllegalArgument("scene dynplt -i", i, args);
} else if (arg=="-ngroups") {
if (!getIntArg(i, args, ngroups))
throw IllegalArgument("scene dynplt -ngroups", i, args);
@@ -77,12 +80,13 @@
} else {
cerr<<"Valid options for scene dynplt:\n";
cerr<<" -bv <string> bounding volume {bvh|grid|group}\n";
- cerr<<" -nbounces <int> number of indirect nbounces\n";
+ cerr<<" -dilate dilate textures during generation\n";
cerr<<" -i <string> particle data filename\n";
+ cerr<<" -nbounces <int> number of indirect nbounces\n";
cerr<<" -ngroups <int> number of sample groups\n";
cerr<<" -nsamples <int> number of samples/texel\n";
cerr<<" -nthreads <int> number of dynplt workers\n";
- cerr<<" -qsize <int> queue qsize\n";
+ cerr<<" -qsize <int> queue qsize\n";
cerr<<" -radius <float> particle radius\n";
cerr<<" -ridx <int> radius index\n";
throw IllegalArgument("scene dynplt", i, args);
@@ -101,7 +105,7 @@
// Create DynPLTContext
DynPLTContext* dpltctx=new DynPLTContext(queue, scene, ngroups, nsamples,
- max_depth);
+ max_depth, dilate);
// Create DynPLTWorker threads
for (unsigned int i=0; i<nthreads; ++i) {
@@ -154,6 +158,9 @@
scene->addBookmark("view 2", Vector(-0.83, 0.85, 4.71),
Vector(0.02, 0.01, 0.29), Vector(-0.59, -0.59, 0.59),
0.59);
+ scene->addBookmark("view 3", Vector(1.01349, 0.0783629, 0.297803),
+ Vector(0.02, 0.02, 0.2),
+ Vector(-0.0890283, -0.13761, 0.986477), 0.204219);
return scene;
}
- [MANTA] r1085 - in trunk: Engine/Control Model/Materials scenes, cgribble, 05/24/2006
Archive powered by MHonArc 2.6.16.