Commit 4aa948c1 authored by hrchilds's avatar hrchilds

Update from October 24, 2004

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@346 18c085ea-50e0-402c-830e-de6fd14e8384
parent e2c35547
......@@ -128,13 +128,13 @@ RenderingAttributes::TriStateMode_FromString(const std::string &s, RenderingAttr
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
// ****************************************************************************
RenderingAttributes::RenderingAttributes() : AttributeSubject("biibibiibffa"),
RenderingAttributes::RenderingAttributes() : AttributeSubject("biibibiibffabd"),
specularColor(255, 255, 255)
{
antialiasing = false;
......@@ -148,6 +148,8 @@ RenderingAttributes::RenderingAttributes() : AttributeSubject("biibibiibffa"),
specularFlag = false;
specularCoeff = 0.6;
specularPower = 10;
doShadowing = false;
shadowStrength = 0.5;
}
// ****************************************************************************
......@@ -159,13 +161,13 @@ RenderingAttributes::RenderingAttributes() : AttributeSubject("biibibiibffa"),
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
// ****************************************************************************
RenderingAttributes::RenderingAttributes(const RenderingAttributes &obj) : AttributeSubject("biibibiibffa")
RenderingAttributes::RenderingAttributes(const RenderingAttributes &obj) : AttributeSubject("biibibiibffabd")
{
antialiasing = obj.antialiasing;
geometryRepresentation = obj.geometryRepresentation;
......@@ -179,6 +181,8 @@ RenderingAttributes::RenderingAttributes(const RenderingAttributes &obj) : Attri
specularCoeff = obj.specularCoeff;
specularPower = obj.specularPower;
specularColor = obj.specularColor;
doShadowing = obj.doShadowing;
shadowStrength = obj.shadowStrength;
SelectAll();
}
......@@ -192,7 +196,7 @@ RenderingAttributes::RenderingAttributes(const RenderingAttributes &obj) : Attri
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -212,7 +216,7 @@ RenderingAttributes::~RenderingAttributes()
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -233,6 +237,8 @@ RenderingAttributes::operator = (const RenderingAttributes &obj)
specularCoeff = obj.specularCoeff;
specularPower = obj.specularPower;
specularColor = obj.specularColor;
doShadowing = obj.doShadowing;
shadowStrength = obj.shadowStrength;
SelectAll();
}
......@@ -246,7 +252,7 @@ RenderingAttributes::operator = (const RenderingAttributes &obj)
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -267,7 +273,9 @@ RenderingAttributes::operator == (const RenderingAttributes &obj) const
(specularFlag == obj.specularFlag) &&
(specularCoeff == obj.specularCoeff) &&
(specularPower == obj.specularPower) &&
(specularColor == obj.specularColor));
(specularColor == obj.specularColor) &&
(doShadowing == obj.doShadowing) &&
(shadowStrength == obj.shadowStrength));
}
// ****************************************************************************
......@@ -279,7 +287,7 @@ RenderingAttributes::operator == (const RenderingAttributes &obj) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -300,7 +308,7 @@ RenderingAttributes::operator != (const RenderingAttributes &obj) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -321,7 +329,7 @@ RenderingAttributes::TypeName() const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -349,7 +357,7 @@ RenderingAttributes::CopyAttributes(const AttributeGroup *atts)
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -375,7 +383,7 @@ RenderingAttributes::CreateCompatible(const std::string &tname) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -402,7 +410,7 @@ RenderingAttributes::NewInstance(bool copy) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -423,6 +431,8 @@ RenderingAttributes::SelectAll()
Select(9, (void *)&specularCoeff);
Select(10, (void *)&specularPower);
Select(11, (void *)&specularColor);
Select(12, (void *)&doShadowing);
Select(13, (void *)&shadowStrength);
}
///////////////////////////////////////////////////////////////////////////////
......@@ -438,7 +448,7 @@ RenderingAttributes::SelectAll()
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -529,6 +539,18 @@ RenderingAttributes::CreateNode(DataNode *parentNode, bool completeSave, bool fo
}
else
delete specularColorNode;
if(completeSave || !FieldsEqual(12, &defaultObject))
{
addToParent = true;
node->AddNode(new DataNode("doShadowing", doShadowing));
}
if(completeSave || !FieldsEqual(13, &defaultObject))
{
addToParent = true;
node->AddNode(new DataNode("shadowStrength", shadowStrength));
}
// Add the node to the parent node.
if(addToParent || forceAdd)
......@@ -548,7 +570,7 @@ RenderingAttributes::CreateNode(DataNode *parentNode, bool completeSave, bool fo
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -646,6 +668,10 @@ RenderingAttributes::SetFromNode(DataNode *parentNode)
SetSpecularPower(node->AsFloat());
if((node = searchNode->GetNode("specularColor")) != 0)
specularColor.SetFromNode(node);
if((node = searchNode->GetNode("doShadowing")) != 0)
SetDoShadowing(node->AsBool());
if((node = searchNode->GetNode("shadowStrength")) != 0)
SetShadowStrength(node->AsDouble());
}
///////////////////////////////////////////////////////////////////////////////
......@@ -736,6 +762,20 @@ RenderingAttributes::SetSpecularColor(const ColorAttribute &specularColor_)
Select(11, (void *)&specularColor);
}
void
RenderingAttributes::SetDoShadowing(bool doShadowing_)
{
doShadowing = doShadowing_;
Select(12, (void *)&doShadowing);
}
void
RenderingAttributes::SetShadowStrength(double shadowStrength_)
{
shadowStrength = shadowStrength_;
Select(13, (void *)&shadowStrength);
}
///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////
......@@ -818,6 +858,18 @@ RenderingAttributes::GetSpecularColor()
return specularColor;
}
bool
RenderingAttributes::GetDoShadowing() const
{
return doShadowing;
}
double
RenderingAttributes::GetShadowStrength() const
{
return shadowStrength;
}
///////////////////////////////////////////////////////////////////////////////
// Select property methods
///////////////////////////////////////////////////////////////////////////////
......@@ -841,7 +893,7 @@ RenderingAttributes::SelectSpecularColor()
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -864,6 +916,8 @@ RenderingAttributes::GetFieldName(int index) const
case 9: return "specularCoeff";
case 10: return "specularPower";
case 11: return "specularColor";
case 12: return "Do Shadowing";
case 13: return "Shadow Strength";
default: return "invalid index";
}
}
......@@ -877,7 +931,7 @@ RenderingAttributes::GetFieldName(int index) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -900,6 +954,8 @@ RenderingAttributes::GetFieldType(int index) const
case 9: return FieldType_float;
case 10: return FieldType_float;
case 11: return FieldType_color;
case 12: return FieldType_bool;
case 13: return FieldType_double;
default: return FieldType_unknown;
}
}
......@@ -913,7 +969,7 @@ RenderingAttributes::GetFieldType(int index) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -936,6 +992,8 @@ RenderingAttributes::GetFieldTypeName(int index) const
case 9: return "float";
case 10: return "float";
case 11: return "color";
case 12: return "bool";
case 13: return "double";
default: return "invalid index";
}
}
......@@ -949,7 +1007,7 @@ RenderingAttributes::GetFieldTypeName(int index) const
// Note: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -1022,6 +1080,16 @@ RenderingAttributes::FieldsEqual(int index_, const AttributeGroup *rhs) const
retval = (specularColor == obj.specularColor);
}
break;
case 12:
{ // new scope
retval = (doShadowing == obj.doShadowing);
}
break;
case 13:
{ // new scope
retval = (shadowStrength == obj.shadowStrength);
}
break;
default: retval = false;
}
......
......@@ -15,7 +15,7 @@
// Notes: Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation: Wed May 12 07:29:22 PDT 2004
// Creation: Sun Oct 24 07:27:47 PDT 2004
//
// Modifications:
//
......@@ -75,6 +75,8 @@ public:
void SetSpecularCoeff(float specularCoeff_);
void SetSpecularPower(float specularPower_);
void SetSpecularColor(const ColorAttribute &specularColor_);
void SetDoShadowing(bool doShadowing_);
void SetShadowStrength(double shadowStrength_);
// Property getting methods
bool GetAntialiasing() const;
......@@ -90,6 +92,8 @@ public:
float GetSpecularPower() const;
const ColorAttribute &GetSpecularColor() const;
ColorAttribute &GetSpecularColor();
bool GetDoShadowing() const;
double GetShadowStrength() const;
// Persistence methods
virtual bool CreateNode(DataNode *node, bool completeSave, bool forceAdd);
......@@ -133,6 +137,8 @@ private:
float specularCoeff;
float specularPower;
ColorAttribute specularColor;
bool doShadowing;
double shadowStrength;
};
#endif
......@@ -54,6 +54,12 @@
255
255
</Field>
<Field name="doShadowing" label="Do Shadowing" type="bool">
false
</Field>
<Field name="shadowStrength" label="Shadow Strength" type="double">
0.500000
</Field>
<Function name="GetEffectiveScalableThreshold" user="true" member="true">
</Function>
<Constant name="DEFAULT_SCALABLE_AUTO_THRESHOLD" member="false">
......
......@@ -1409,6 +1409,10 @@ avtDatabase::GetExtentsFromAuxiliaryData(avtDataSpecification_p spec,
avtIntervalTree *tree = (avtIntervalTree *) *(list.list[0]);
float fextents[6];
tree->GetExtents(fextents);
int nvals = 2;
if (strcmp(type, AUXILIARY_DATA_SPATIAL_EXTENTS) == 0)
nvals = 6;
for (int i = 0; i < 6; i++)
extents[i] = fextents[i];
......
......@@ -147,6 +147,9 @@
# Brad Whitlock, Thu Apr 22 17:14:16 PST 2004
# Added more libraries so we can prelink on MacOS X.
#
# Hank Childs, Sun Oct 24 08:17:46 PDT 2004
# Added avtSoftwareShader.
#
##############################################################################
##
......@@ -169,7 +172,7 @@ SRC=avtLegend.C avtVariableLegend.C avtGeometryDrawable.C avtActor.C \
avtLineoutActor.C avtTransparencyActor.C avtLabelActor.C \
avtDecorationsDrawable.C avtDecorationsMapper.C avtLabeledCurveMapper.C \
avtExternallyRenderedImagesActor.C avtTensorGlyphMapper.C avtDrawable.C \
avtPointGlyphMapper.C
avtPointGlyphMapper.C avtSoftwareShader.C
......
// ************************************************************************* //
// avtSoftwareShader.C //
// ************************************************************************* //
#include <avtSoftwareShader.h>
#include <vtkCamera.h>
#include <vtkLight.h>
#include <vtkMatrix4x4.h>
#include <LightAttributes.h>
#include <avtViewInfo.h>
#include <avtView3D.h>
// ****************************************************************************
// Method: avtSoftwareShader::GetLightDirection
//
// Purpose:
// Gets the direction of the light.
//
// Programmer: Hank Childs
// Creation: October 24, 2004
//
// ****************************************************************************
bool
avtSoftwareShader::GetLightDirection(const LightAttributes &la,
const avtView3D &cur_view, double *light_dir)
{
bool canShade = true;
if (la.GetType() == LightAttributes::Object)
{
light_dir[0] = -la.GetDirection()[0];
light_dir[1] = -la.GetDirection()[1];
light_dir[2] = -la.GetDirection()[2];
}
else if (la.GetType() == LightAttributes::Camera)
{
vtkCamera *cam = vtkCamera::New();
avtViewInfo ccvi;
cur_view.SetViewInfoFromView(ccvi);
ccvi.SetCameraFromView(cam);
vtkMatrix4x4 *lt = cam->GetCameraLightTransformMatrix();
vtkLight *light = vtkLight::New();
light->SetTransformMatrix(lt);
float ld[3];
ld[0] = la.GetDirection()[0];
ld[1] = la.GetDirection()[1];
ld[2] = la.GetDirection()[2];
light->SetPosition(ld);
light->GetTransformedPosition(ld);
light_dir[0] = -ld[0];
light_dir[1] = -ld[1];
light_dir[2] = -ld[2];
light->Delete();
cam->Delete();
}
else
canShade = false;
if (canShade)
{
double mag = light_dir[0]*light_dir[0] + light_dir[1]*light_dir[1] +
light_dir[2]*light_dir[2];
mag = sqrt(mag);
if (mag != 0.)
{
light_dir[0] /= mag;
light_dir[1] /= mag;
light_dir[2] /= mag;
}
}
return canShade;
}
// ****************************************************************************
// Method: avtSoftwareShader::AddShadows
//
// Purpose:
// Adds shadows to the images.
//
// Programmer: Hank Childs
// Creation: October 24, 2004
//
// ****************************************************************************
void
avtSoftwareShader::AddShadows(avtImage_p light_image, avtImage_p current_image,
avtView3D &light_dir, avtView3D &current_view,
double aspect, double strength)
{
//
// 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();
float *light_image_zbuff = light_image->GetImage().GetZBuffer();
int rs, cs;
current_image->GetImage().GetSize(&rs, &cs);
//
// 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 do the same thing for "light view".
//
avtViewInfo lvi;
light_dir.SetViewInfoFromView(lvi);
vtkCamera *light_cam = vtkCamera::New();
lvi.SetCameraFromView(light_cam);
double light_clip_range[2];
light_cam->GetClippingRange(light_clip_range);
vtkMatrix4x4 *light_trans =
light_cam->GetCompositePerspectiveTransformMatrix(aspect,
light_clip_range[0], light_clip_range[1]);
vtkMatrix4x4 *light_inverse = vtkMatrix4x4::New();
vtkMatrix4x4::Invert(light_trans, light_inverse);
//
// Now iterate over every pixel in the scene and see if the light can
// see the same spots as the camera.
//
bool *should_shade = new bool[rs*cs];
for (int 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.99)
continue;
//
// Convert from "display"/screen space to view space.
//
float 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.;
float 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.;
//
// Okay, we now know the world space coordinates of this pixel.
// For ease of reference, let's call this PPOS.
// If we put PPOS into the light transformation matrix, then it
// will give us a point in view space for the light transform.
//
float view_light[4];
light_trans->MultiplyPoint(world, view_light);
if (view_light[3] != 0.)
{
view_light[0] /= view_light[3];
view_light[1] /= view_light[3];
view_light[2] /= view_light[3];
}
//
// Now PPOS is in the light's view space. Let's convert to screen
// space so we can compare to the light's z-buffer value.
// (Note that we are comparing z-buffer values rather than
// converting these back into world space.)
//
int display[2];
float z_display;
display[0] = (int)(view_light[0] * cs/2. + cs/2.);
display[1] = (int)(view_light[1] * rs/2. + rs/2.);
z_display = (view_light[2] - light_clip_range[0]) /
(light_clip_range[1] - light_clip_range[0]);
bool found_something_close = false;
//
// Compare the pixels in display space (using z-buff comparisons).
//
for (int m = display[0] - 1 ; m <= display[0] + 1 ; m++)
{
if (m < 0 || m >= cs)
continue;
for (int n = display[1] - 1 ; n <= display[1] + 1 ; n++)
{
if (n < 0 || n >= rs)
continue;
int light_idx = n*cs + m;
if (z_display < light_image_zbuff[light_idx]+0.001)
found_something_close = true;
}
}
/*
* HERE IS AN ATTEMPT TO COMPARE THE PIXELS IN WORLD SPACE.
* THIS IS HERE IN CASE WE DECIDE NOT TO DO THE COMPARISONS IN DISPLAY
* SPACE (WHICH IS WHAT IS BEING DONE ABOVE.
*