Commit 50efb716 authored by js9's avatar js9

Adding depth cueing support (like shadows to SR mode only).

Fixing up rendering attributes window a bit.



git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@1928 18c085ea-50e0-402c-830e-de6fd14e8384
parent 7f90159a
This diff is collapsed.
......@@ -52,7 +52,7 @@
// Notes: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Mon Sep 18 10:37:03 PDT 2006
// Creation: Wed Aug 29 13:02:03 PST 2007
//
// Modifications:
//
......@@ -99,6 +99,8 @@ public:
// Property selection methods
virtual void SelectAll();
void SelectSpecularColor();
void SelectStartCuePoint();
void SelectEndCuePoint();
// Property setting methods
void SetAntialiasing(bool antialiasing_);
......@@ -115,6 +117,9 @@ public:
void SetSpecularColor(const ColorAttribute &specularColor_);
void SetDoShadowing(bool doShadowing_);
void SetShadowStrength(double shadowStrength_);
void SetDoDepthCueing(bool doDepthCueing_);
void SetStartCuePoint(const double *startCuePoint_);
void SetEndCuePoint(const double *endCuePoint_);
void SetCompressionActivationMode(TriStateMode compressionActivationMode_);
void SetColorTexturingFlag(bool colorTexturingFlag_);
......@@ -134,6 +139,11 @@ public:
ColorAttribute &GetSpecularColor();
bool GetDoShadowing() const;
double GetShadowStrength() const;
bool GetDoDepthCueing() const;
const double *GetStartCuePoint() const;
double *GetStartCuePoint();
const double *GetEndCuePoint() const;
double *GetEndCuePoint();
TriStateMode GetCompressionActivationMode() const;
bool GetColorTexturingFlag() const;
......@@ -181,8 +191,14 @@ private:
ColorAttribute specularColor;
bool doShadowing;
double shadowStrength;
bool doDepthCueing;
double startCuePoint[3];
double endCuePoint[3];
int compressionActivationMode;
bool colorTexturingFlag;
// Static class format string for type map.
static const char *TypeMapFormatString;
};
#endif
......@@ -61,6 +61,19 @@
<Field name="shadowStrength" label="Shadow Strength" type="double">
0.500000
</Field>
<Field name="doDepthCueing" label="Do Depth Cueing" type="bool">
false
</Field>
<Field name="startCuePoint" type="doubleArray" length="3">
-10.
0.
0.
</Field>
<Field name="endCuePoint" type="doubleArray" length="3">
10.
0.
0.
</Field>
<Field name="compressionActivationMode" label="compressionActivationMode" type="enum" subtype="TriStateMode">
Never
</Field>
......@@ -69,9 +82,9 @@
</Field>
<Function name="GetEffectiveScalableThreshold" user="true" member="true">
</Function>
<Constant name="DEFAULT_SCALABLE_AUTO_THRESHOLD" member="false">
<Constant name="DEFAULT_SCALABLE_AUTO_THRESHOLD" member="true">
</Constant>
<Constant name="DEFAULT_SCALABLE_ACTIVATION_MODE" member="false">
<Constant name="DEFAULT_SCALABLE_ACTIVATION_MODE" member="true">
</Constant>
<Include file="header" quoted="false">
float.h
......
......@@ -110,7 +110,7 @@ static double CalculateShadow_Hard(int l_width, int l_height,
}
// ****************************************************************************
// Function: CalculateShadow_Hard
// Function: CalculateShadow_Antialiased
//
// Purpose:
// Calculates shadows, with antialiased edges.
......@@ -563,6 +563,141 @@ avtSoftwareShader::AddShadows(avtImage_p light_image, avtImage_p current_image,
// ****************************************************************************
// Method: avtSoftwareShader::AddDepthCueing
//
// Purpose:
// Apply depth cueing to the scene. Note that this can be
// applied independent of the view angle, so "fog" is not
// quite the right implementation.
//
// Arguments:
// current_image the image to apply depth cueing to
// current_view the view used to create that image
// start the point at which depth cueing begins
// end the point at which depth cueing ends
// cuecolor typically the background color
//
// Programmer: Jeremy Meredith
// Creation: August 29, 2007
//
// ****************************************************************************
void
avtSoftwareShader::AddDepthCueing(avtImage_p current_image,
avtView3D &current_view,
const double start[3],
const double end[3],
unsigned char cuecolor[3])
{
double direction[3] = {end[0]-start[0], end[1]-start[1], end[2]-start[2]};
double mag = (direction[0]*direction[0] +
direction[1]*direction[1] +
direction[2]*direction[2]);
//
// Set up the buffers we will be reading from and writing to.
//
unsigned char *rgb = current_image->GetImage().GetRGBBuffer();
float *cur_image_zbuff = current_image->GetImage().GetZBuffer();
int rs, cs;
current_image->GetImage().GetSize(&rs, &cs);
//
// Calculate aspect ratios
//
double aspect = double(cs)/double(rs);
//
// Set up VTK camera objects corresponding to the current view. This will
// give us the matrix to use to transform our points.
//
avtViewInfo ccvi;
current_view.SetViewInfoFromView(ccvi);
vtkCamera *cur_cam = vtkCamera::New();
ccvi.SetCameraFromView(cur_cam);
double cur_clip_range[2];
cur_cam->GetClippingRange(cur_clip_range);
vtkMatrix4x4 *cur_trans =
cur_cam->GetCompositePerspectiveTransformMatrix(aspect,
cur_clip_range[0], cur_clip_range[1]);
vtkMatrix4x4 *cur_inverse = vtkMatrix4x4::New();
vtkMatrix4x4::Invert(cur_trans, cur_inverse);
//
// Now iterate over every pixel in the scene and see if the light can
// see the same spots as the camera.
//
int j;
for (j = 0 ; j < rs ; j++)
{
for (int i = 0 ; i < cs ; i++)
{
int idx = j*cs + i;
//
// If there is nothing in the real image, then there is nothing
// to cross-reference against -- return now before doing any work.
//
if (cur_image_zbuff[idx] > 0.9999)
continue;
//
// Convert from "display"/screen space to view space.
//
double view[4];
view[0] = (i - cs/2.)/(cs/2.);
view[1] = (j - rs/2.)/(rs/2.);
// I expected the z to be from 0 to 1, but the VTK matrices
// require you to perform this manipulation with the clipping
// range.
view[2] = cur_image_zbuff[idx]*
(cur_clip_range[1]-cur_clip_range[0])
+ cur_clip_range[0] ;
view[3] = 1.;
// And then to world space.
double world[4];
cur_inverse->MultiplyPoint(view, world);
if (world[3] != 0.)
{
world[0] /= world[3];
world[1] /= world[3];
world[2] /= world[3];
}
world[3] = 1.;
// Get the distance factor (in terms of the direction vec length)
double scale = (direction[0]*(world[0]-start[0]) +
direction[1]*(world[1]-start[1]) +
direction[2]*(world[2]-start[2])) / mag;
// must be between 0 and 1
if (scale > 1)
scale = 1;
if (scale < 0)
scale = 0;
// fade it to the cue color
unsigned char r = rgb[3*idx+0];
unsigned char g = rgb[3*idx+1];
unsigned char b = rgb[3*idx+2];
r = (unsigned char)((1.-scale) * double(r) + (scale) * double(cuecolor[0]));
g = (unsigned char)((1.-scale) * double(g) + (scale) * double(cuecolor[1]));
b = (unsigned char)((1.-scale) * double(b) + (scale) * double(cuecolor[2]));
// and set it back
rgb[3*idx+0] = r;
rgb[3*idx+1] = g;
rgb[3*idx+2] = b;
}
}
cur_cam->Delete();
cur_inverse->Delete();
}
// ****************************************************************************
// Method: avtSoftwareShader::FindLightView
//
......
......@@ -54,7 +54,7 @@ struct avtView3D;
// Class: avtSoftwareShader
//
// Purpose:
// Does shadows in software.
// Does shadows in software. Also handles depth cueing.
//
// Programmer: Hank Childs
// Creation: October 24, 2004
......@@ -64,6 +64,9 @@ struct avtView3D;
// Added FindLightView. Removed the "aspect" argument from AddShadows
// because we can just calculate it based on the image passed in.
//
// Jeremy Meredith, Wed Aug 29 13:11:37 EDT 2007
// Added depth cueing.
//
// ****************************************************************************
class PLOTTER_API avtSoftwareShader
......@@ -73,6 +76,11 @@ class PLOTTER_API avtSoftwareShader
double *);
static void AddShadows(avtImage_p, avtImage_p, avtView3D &, avtView3D &,
double);
static void AddDepthCueing(avtImage_p current_image,
avtView3D &current_view,
const double startPoint[3],
const double endPoint[3],
unsigned char cuecolor[3]);
static avtView3D FindLightView(avtImage_p,avtView3D &,double*,double);
};
......
......@@ -1939,6 +1939,9 @@ NetworkManager::HasNonMeshPlots(const intVector plotIds)
// Set the actor's name to that of the plot so legend attributes can be
// set via the annotation object list.
//
// Jeremy Meredith, Wed Aug 29 15:24:13 EDT 2007
// Added depth cueing.
//
// ****************************************************************************
avtDataObjectWriter_p
......@@ -2236,6 +2239,8 @@ NetworkManager::Render(intVector plotIds, bool getZBuffer, int annotMode,
// Determine if we need to go for two passes
//
bool doShadows = windowAttributes.GetRenderAtts().GetDoShadowing();
bool doDepthCueing =
windowAttributes.GetRenderAtts().GetDoDepthCueing();
bool two_pass_mode = false;
if (viswin->GetWindowMode() == WINMODE_3D)
{
......@@ -2245,10 +2250,14 @@ NetworkManager::Render(intVector plotIds, bool getZBuffer, int annotMode,
#endif
}
else
{
doShadows = false;
doDepthCueing = false;
}
int nstages = 3; // Rendering + Two for Compositing
nstages += (doShadows ? 2 : 0);
nstages += (doDepthCueing ? 1 : 0);
nstages += (two_pass_mode ? 1 : 0);
for (int ss = 0 ; ss < imageBasedPlots.size() ; ss++)
{
......@@ -2291,6 +2300,7 @@ NetworkManager::Render(intVector plotIds, bool getZBuffer, int annotMode,
imageCompositer->SetShouldOutputZBuffer(getZBuffer ||
two_pass_mode ||
doShadows ||
doDepthCueing ||
haveImagePlots);
}
else
......@@ -2322,6 +2332,7 @@ NetworkManager::Render(intVector plotIds, bool getZBuffer, int annotMode,
imageCompositer->AddImageInput(theImage, 0, 0);
imageCompositer->SetAllProcessorsNeedResult(two_pass_mode ||
doShadows ||
doDepthCueing ||
haveImagePlots);
//
......@@ -2477,6 +2488,41 @@ NetworkManager::Render(intVector plotIds, bool getZBuffer, int annotMode,
CallProgressCallback("NetworkManager", "Creating shadows",1,1);
}
//
// Do depth cueing if appropriate.
//
if (doDepthCueing)
{
CallProgressCallback("NetworkManager", "Applying depth cueing",0,1);
avtView3D cur_view = viswin->GetView3D();
//
// Get the image attributes
//
avtImage_p compositedImage;
CopyTo(compositedImage, compositedImageAsDataObject);
int width, height;
viswin->GetSize(width, height);
#ifdef PARALLEL
if (PAR_Rank() == 0)
#endif
{
const double *start =
windowAttributes.GetRenderAtts().GetStartCuePoint();
const double *end =
windowAttributes.GetRenderAtts().GetEndCuePoint();
unsigned char color[] =
{annotationAttributes.GetBackgroundColor().Red(),
annotationAttributes.GetBackgroundColor().Green(),
annotationAttributes.GetBackgroundColor().Blue()};
avtSoftwareShader::AddDepthCueing(compositedImage,cur_view,
start, end, color);
}
CallProgressCallback("NetworkManager", "Applying depth cueing",1,1);
}
//
// If the engine is doing more than just 3D annotations,
// post-process the composited image.
......
This diff is collapsed.
......@@ -50,6 +50,7 @@ class QSpinBox;
class RenderingAttributes;
class WindowInformation;
class QvisOpacitySlider;
class QLineEdit;
// ****************************************************************************
// Class: QvisRenderingWindow
......@@ -97,6 +98,10 @@ class QvisOpacitySlider;
// Brad Whitlock, Mon Sep 18 10:44:21 PDT 2006
// Added color texturing check box.
//
// Jeremy Meredith, Wed Aug 29 15:23:19 EDT 2007
// Added depth cueing support. Improved some other thing in the
// window (like sensitivities and layout).
//
// ****************************************************************************
class GUI_API QvisRenderingWindow : public QvisPostableWindowSimpleObserver
......@@ -120,6 +125,8 @@ protected:
void UpdateInformation(bool doAll);
void Apply(bool ignore = false);
void InterpretScalableAutoThreshold(int,int*,QString*,int*) const;
void GetCurrentValues();
void UpdateWindowSensitivity();
private slots:
void antialiasingToggled(bool);
void objectRepresentationChanged(int);
......@@ -135,6 +142,9 @@ private slots:
void specularPowerChanged(int, const void*);
void shadowToggled(bool);
void shadowStrengthChanged(int, const void*);
void depthCueingToggled(bool);
void depthCueingStartChanged();
void depthCueingEndChanged();
void colorTexturingToggled(bool);
private:
RenderingAttributes *renderAtts;
......@@ -167,6 +177,11 @@ private:
QCheckBox *shadowToggle;
QLabel *shadowStrengthLabel;
QvisOpacitySlider *shadowStrengthSlider;
QCheckBox *depthCueingToggle;
QLabel *depthCueingStartLabel;
QLineEdit *depthCueingStartEdit;
QLabel *depthCueingEndLabel;
QLineEdit *depthCueingEndEdit;
QCheckBox *colorTexturingToggle;
// Labels to display renderer information.
......
......@@ -47,7 +47,7 @@ package llnl.visit;
// Notes: Autogenerated by xml2java.
//
// Programmer: xml2java
// Creation: Wed Mar 14 17:55:10 PST 2007
// Creation: Wed Aug 29 13:00:09 PST 2007
//
// Modifications:
//
......@@ -77,7 +77,7 @@ public class RenderingAttributes extends AttributeSubject
public RenderingAttributes()
{
super(16);
super(19);
antialiasing = false;
geometryRepresentation = GEOMETRYREPRESENTATION_SURFACES;
......@@ -93,13 +93,24 @@ public class RenderingAttributes extends AttributeSubject
specularColor = new ColorAttribute(255, 255, 255);
doShadowing = false;
shadowStrength = 0.5;
doDepthCueing = false;
startCuePoint = new double[3];
startCuePoint[0] = -10;
startCuePoint[1] = 0;
startCuePoint[2] = 0;
endCuePoint = new double[3];
endCuePoint[0] = 10;
endCuePoint[1] = 0;
endCuePoint[2] = 0;
compressionActivationMode = TRISTATEMODE_NEVER;
colorTexturingFlag = true;
}
public RenderingAttributes(RenderingAttributes obj)
{
super(16);
super(19);
int i;
antialiasing = obj.antialiasing;
geometryRepresentation = obj.geometryRepresentation;
......@@ -115,6 +126,17 @@ public class RenderingAttributes extends AttributeSubject
specularColor = new ColorAttribute(obj.specularColor);
doShadowing = obj.doShadowing;
shadowStrength = obj.shadowStrength;
doDepthCueing = obj.doDepthCueing;
startCuePoint = new double[3];
startCuePoint[0] = obj.startCuePoint[0];
startCuePoint[1] = obj.startCuePoint[1];
startCuePoint[2] = obj.startCuePoint[2];
endCuePoint = new double[3];
endCuePoint[0] = obj.endCuePoint[0];
endCuePoint[1] = obj.endCuePoint[1];
endCuePoint[2] = obj.endCuePoint[2];
compressionActivationMode = obj.compressionActivationMode;
colorTexturingFlag = obj.colorTexturingFlag;
......@@ -123,6 +145,18 @@ public class RenderingAttributes extends AttributeSubject
public boolean equals(RenderingAttributes obj)
{
int i;
// Compare the startCuePoint arrays.
boolean startCuePoint_equal = true;
for(i = 0; i < 3 && startCuePoint_equal; ++i)
startCuePoint_equal = (startCuePoint[i] == obj.startCuePoint[i]);
// Compare the endCuePoint arrays.
boolean endCuePoint_equal = true;
for(i = 0; i < 3 && endCuePoint_equal; ++i)
endCuePoint_equal = (endCuePoint[i] == obj.endCuePoint[i]);
// Create the return value
return ((antialiasing == obj.antialiasing) &&
(geometryRepresentation == obj.geometryRepresentation) &&
......@@ -138,6 +172,9 @@ public class RenderingAttributes extends AttributeSubject
(specularColor == obj.specularColor) &&
(doShadowing == obj.doShadowing) &&
(shadowStrength == obj.shadowStrength) &&
(doDepthCueing == obj.doDepthCueing) &&
startCuePoint_equal &&
endCuePoint_equal &&
(compressionActivationMode == obj.compressionActivationMode) &&
(colorTexturingFlag == obj.colorTexturingFlag));
}
......@@ -227,16 +264,54 @@ public class RenderingAttributes extends AttributeSubject
Select(13);
}
public void SetDoDepthCueing(boolean doDepthCueing_)
{
doDepthCueing = doDepthCueing_;
Select(14);
}
public void SetStartCuePoint(double[] startCuePoint_)
{
startCuePoint[0] = startCuePoint_[0];
startCuePoint[1] = startCuePoint_[1];
startCuePoint[2] = startCuePoint_[2];
Select(15);
}
public void SetStartCuePoint(double e0, double e1, double e2)
{
startCuePoint[0] = e0;
startCuePoint[1] = e1;
startCuePoint[2] = e2;
Select(15);
}
public void SetEndCuePoint(double[] endCuePoint_)
{
endCuePoint[0] = endCuePoint_[0];
endCuePoint[1] = endCuePoint_[1];
endCuePoint[2] = endCuePoint_[2];
Select(16);
}
public void SetEndCuePoint(double e0, double e1, double e2)
{
endCuePoint[0] = e0;
endCuePoint[1] = e1;
endCuePoint[2] = e2;
Select(16);
}
public void SetCompressionActivationMode(int compressionActivationMode_)
{
compressionActivationMode = compressionActivationMode_;
Select(14);
Select(17);
}
public void SetColorTexturingFlag(boolean colorTexturingFlag_)
{
colorTexturingFlag = colorTexturingFlag_;
Select(15);
Select(18);
}
// Property getting methods
......@@ -254,6 +329,9 @@ public class RenderingAttributes extends AttributeSubject
public ColorAttribute GetSpecularColor() { return specularColor; }
public boolean GetDoShadowing() { return doShadowing; }
public double GetShadowStrength() { return shadowStrength; }
public boolean GetDoDepthCueing() { return doDepthCueing; }
public double[] GetStartCuePoint() { return startCuePoint; }
public double[] GetEndCuePoint() { return endCuePoint; }
public int GetCompressionActivationMode() { return compressionActivationMode; }
public boolean GetColorTexturingFlag() { return colorTexturingFlag; }
......@@ -289,8 +367,14 @@ public class RenderingAttributes extends AttributeSubject
if(WriteSelect(13, buf))
buf.WriteDouble(shadowStrength);
if(WriteSelect(14, buf))
buf.WriteInt(compressionActivationMode);
buf.WriteBool(doDepthCueing);
if(WriteSelect(15, buf))
buf.WriteDoubleArray(startCuePoint);
if(WriteSelect(16, buf))
buf.WriteDoubleArray(endCuePoint);
if(WriteSelect(17, buf))
buf.WriteInt(compressionActivationMode);
if(WriteSelect(18, buf))
buf.WriteBool(colorTexturingFlag);
}
......@@ -345,9 +429,18 @@ public class RenderingAttributes extends AttributeSubject
SetShadowStrength(buf.ReadDouble());
break;
case 14:
SetCompressionActivationMode(buf.ReadInt());
SetDoDepthCueing(buf.ReadBool());
break;
case 15:
SetStartCuePoint(buf.ReadDoubleArray());
break;
case 16:
SetEndCuePoint(buf.ReadDoubleArray());
break;
case 17:
SetCompressionActivationMode(buf.ReadInt());
break;
case 18:
SetColorTexturingFlag(buf.ReadBool());
break;
}
......@@ -370,6 +463,9 @@ public class RenderingAttributes extends AttributeSubject
private ColorAttribute specularColor;
private boolean doShadowing;
private double shadowStrength;
private boolean doDepthCueing;
private double[] startCuePoint;
private double[] endCuePoint;
private int compressionActivationMode;
private boolean colorTexturingFlag;
}
......
......@@ -248,6 +248,9 @@ static void RotateAroundY(const avtView3D&, double, avtView3D&);
// Jeremy Meredith, Tue Jul 17 16:37:04 EDT 2007
// Added fullscreen support to the QtVisWindow.
//
// Jeremy Meredith, Wed Aug 29 15:21:38 EDT 2007
// Added initialization of depth cueing properties.
//
// ****************************************************************************
ViewerWindow::ViewerWindow(int windowIndex) : ViewerBase(0, "ViewerWindow"),
......@@ -371,6 +374,10 @@ ViewerWindow::ViewerWindow(int windowIndex) : ViewerBase(0, "ViewerWindow"),
doShading = false;
shadingStrength = 0.5;
doDepthCueing = false;
startCuePoint[0] = -10; startCuePoint[0] = 0; startCuePoint[0] = 0;
endCuePoint[0] = 10; endCuePoint[0] = 0; endCuePoint[0] = 0;
}
// ****************************************************************************
......@@ -2239,6 +2246,9 @@ ViewerWindow::InvertBackgroundColor()
// Brad Whitlock, Mon Sep 18 10:56:09 PDT 2006
// Added color texturing.
//
// Jeremy Meredith, Wed Aug 29 15:21:38 EDT 2007
// Added copying of depth cueing properties.
//
// ****************************************************************************
void
......@@ -2259,6 +2269,9 @@ ViewerWindow::CopyGeneralAttributes(const ViewerWindow *source)
source->GetSpecularPower(),
source->GetSpecularColor());
SetShadingProperties(source->GetDoShading(), source->GetShadingStrength());
SetDepthCueingProperties(source->GetDoDepthCueing(),
source->GetStartCuePoint(),
source->GetEndCuePoint());
SetColorTexturingFlag(source->GetColorTexturingFlag());
//
......@@ -5816,6 +5829,9 @@ ViewerWindow::SetLargeIcons(bool val)
// Brad Whitlock, Mon Sep 18 10:57:15 PDT 2006
// Added color texturing flag.
//
// Jeremy Meredith, Wed Aug 29 15:21:38 EDT 2007
// Added depth cueing properties.
//
// ****************************************************************************
WindowAttributes
......@@ -5902,6 +5918,10 @@ ViewerWindow::GetWindowAttributes() const
renderAtts.SetDoShadowing(GetDoShading());
renderAtts.SetShadowStrength(GetShadingStrength());
renderAtts.SetDoDepthCueing(GetDoDepthCueing());
renderAtts.SetStartCuePoint(GetStartCuePoint());
renderAtts.SetEndCuePoint(GetEndCuePoint());
renderAtts.SetColorTexturingFlag(GetColorTexturingFlag());
renderAtts.SetCompressionActivationMode(
......@@ -6781,6 +6801,93 @@ ViewerWindow::SetShadingProperties(bool flag, double str)
shadingStrength = str;
}
// ****************************************************************************
// Method: ViewerWindow::GetDoDepthCueing
//
// Purpose:
// Returns the window's depth cueing flag.
//
// Arguments:
// none
//
// Programmer: Hank Childs
// Creation: August 29, 2007
//
// ****************************************************************************
bool
ViewerWindow::GetDoDepthCueing() const
{
return doDepthCueing;
}
// ****************************************************************************
// Method: ViewerWindow::GetStartCuePoint
//
// Purpose:
// returns the 3D world space point at which depth cueing starts
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith
// Creation: August 29, 2007
//
// ****************************************************************************
const double*
ViewerWindow::GetStartCuePoint() const
{
return startCuePoint;
}
// ****************************************************************************
// Method: ViewerWindow::GetEndCuePoint
//
// Purpose:
// returns the 3D world space point at which depth cueing ends
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith