Commit 677fa5a5 authored by allens's avatar allens

fixed centroid subtraction and added option to project or not

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@16579 18c085ea-50e0-402c-830e-de6fd14e8384
parent b6e49298
......@@ -111,6 +111,11 @@ PyToroidalPoloidalProjection_ToString(const ToroidalPoloidalProjection *atts, co
SNPRINTF(tmpStr, 1000, ")\n");
str += tmpStr;
}
if(atts->GetProject2D())
SNPRINTF(tmpStr, 1000, "%sproject2D = 1\n", prefix);
else
SNPRINTF(tmpStr, 1000, "%sproject2D = 0\n", prefix);
str += tmpStr;
return str;
}
......@@ -258,6 +263,30 @@ ToroidalPoloidalProjection_GetCentroid(PyObject *self, PyObject *args)
return retval;
}
/*static*/ PyObject *
ToroidalPoloidalProjection_SetProject2D(PyObject *self, PyObject *args)
{
ToroidalPoloidalProjectionObject *obj = (ToroidalPoloidalProjectionObject *)self;
int ival;
if(!PyArg_ParseTuple(args, "i", &ival))
return NULL;
// Set the project2D in the object.
obj->data->SetProject2D(ival != 0);
Py_INCREF(Py_None);
return Py_None;
}
/*static*/ PyObject *
ToroidalPoloidalProjection_GetProject2D(PyObject *self, PyObject *args)
{
ToroidalPoloidalProjectionObject *obj = (ToroidalPoloidalProjectionObject *)self;
PyObject *retval = PyInt_FromLong(obj->data->GetProject2D()?1L:0L);
return retval;
}
PyMethodDef PyToroidalPoloidalProjection_methods[TOROIDALPOLOIDALPROJECTION_NMETH] = {
......@@ -270,6 +299,8 @@ PyMethodDef PyToroidalPoloidalProjection_methods[TOROIDALPOLOIDALPROJECTION_NMET
{"GetCentroidSource", ToroidalPoloidalProjection_GetCentroidSource, METH_VARARGS},
{"SetCentroid", ToroidalPoloidalProjection_SetCentroid, METH_VARARGS},
{"GetCentroid", ToroidalPoloidalProjection_GetCentroid, METH_VARARGS},
{"SetProject2D", ToroidalPoloidalProjection_SetProject2D, METH_VARARGS},
{"GetProject2D", ToroidalPoloidalProjection_GetProject2D, METH_VARARGS},
{NULL, NULL}
};
......@@ -311,6 +342,8 @@ PyToroidalPoloidalProjection_getattr(PyObject *self, char *name)
if(strcmp(name, "centroid") == 0)
return ToroidalPoloidalProjection_GetCentroid(self, NULL);
if(strcmp(name, "project2D") == 0)
return ToroidalPoloidalProjection_GetProject2D(self, NULL);
return Py_FindMethod(PyToroidalPoloidalProjection_methods, self, name);
}
......@@ -333,6 +366,8 @@ PyToroidalPoloidalProjection_setattr(PyObject *self, char *name, PyObject *args)
obj = ToroidalPoloidalProjection_SetCentroidSource(self, tuple);
else if(strcmp(name, "centroid") == 0)
obj = ToroidalPoloidalProjection_SetCentroid(self, tuple);
else if(strcmp(name, "project2D") == 0)
obj = ToroidalPoloidalProjection_SetProject2D(self, tuple);
if(obj != NULL)
Py_DECREF(obj);
......
......@@ -44,7 +44,7 @@
//
// Functions exposed to the VisIt module.
//
#define TOROIDALPOLOIDALPROJECTION_NMETH 10
#define TOROIDALPOLOIDALPROJECTION_NMETH 12
void PyToroidalPoloidalProjection_StartUp(ToroidalPoloidalProjection *subj, void *data);
void PyToroidalPoloidalProjection_CloseDown();
PyMethodDef * PyToroidalPoloidalProjection_GetMethodTable(int *nMethods);
......
......@@ -165,6 +165,11 @@ QvisToroidalPoloidalProjectionWindow::CreateWindowContents()
this, SLOT(centroidProcessText()));
mainLayout->addWidget(centroid, 3,1);
project2D = new QCheckBox(tr("Project to XY plane"), central);
connect(project2D, SIGNAL(toggled(bool)),
this, SLOT(project2DChanged(bool)));
mainLayout->addWidget(project2D, 4,0);
}
......@@ -226,6 +231,11 @@ QvisToroidalPoloidalProjectionWindow::UpdateWindow(bool doAll)
case ToroidalPoloidalProjection::ID_centroid:
centroid->setText(DoublesToQString(atts->GetCentroid(), 3));
break;
case ToroidalPoloidalProjection::ID_project2D:
project2D->blockSignals(true);
project2D->setChecked(atts->GetProject2D());
project2D->blockSignals(false);
break;
}
}
}
......@@ -265,7 +275,7 @@ QvisToroidalPoloidalProjectionWindow::GetCurrentValues(int which_widget)
// }
// }
// // Do r
// Do r
// if(which_widget == ToroidalPoloidalProjection::ID_r || doAll)
// {
// double val;
......@@ -336,3 +346,12 @@ QvisToroidalPoloidalProjectionWindow::centroidProcessText()
}
void
QvisToroidalPoloidalProjectionWindow::project2DChanged(bool val)
{
atts->SetProject2D(val);
SetUpdate(false);
Apply();
}
......@@ -90,12 +90,14 @@ class QvisToroidalPoloidalProjectionWindow : public QvisOperatorWindow
// void rProcessText();
void centroidSourceChanged(int val);
void centroidProcessText();
void project2DChanged(bool val);
private:
// QLineEdit *R0;
// QLineEdit *r;
QWidget *centroidSource;
QButtonGroup *centroidSourceButtonGroup;
QLineEdit *centroid;
QCheckBox *project2D;
// QLabel *R0Label;
// QLabel *rLabel;
QLabel *centroidSourceLabel;
......@@ -103,4 +105,7 @@ class QvisToroidalPoloidalProjectionWindow : public QvisOperatorWindow
ToroidalPoloidalProjection *atts;
};
#endif
......@@ -99,6 +99,7 @@ void ToroidalPoloidalProjection::Init()
centroid[0] = 0;
centroid[1] = 0;
centroid[2] = 0;
project2D = true;
ToroidalPoloidalProjection::SelectAll();
}
......@@ -127,6 +128,7 @@ void ToroidalPoloidalProjection::Copy(const ToroidalPoloidalProjection &obj)
centroid[1] = obj.centroid[1];
centroid[2] = obj.centroid[2];
project2D = obj.project2D;
ToroidalPoloidalProjection::SelectAll();
}
......@@ -292,7 +294,8 @@ ToroidalPoloidalProjection::operator == (const ToroidalPoloidalProjection &obj)
return ((R0 == obj.R0) &&
(r == obj.r) &&
(centroidSource == obj.centroidSource) &&
centroid_equal);
centroid_equal &&
(project2D == obj.project2D));
}
// ****************************************************************************
......@@ -440,6 +443,7 @@ ToroidalPoloidalProjection::SelectAll()
Select(ID_r, (void *)&r);
Select(ID_centroidSource, (void *)&centroidSource);
Select(ID_centroid, (void *)centroid, 3);
Select(ID_project2D, (void *)&project2D);
}
///////////////////////////////////////////////////////////////////////////////
......@@ -496,6 +500,12 @@ ToroidalPoloidalProjection::CreateNode(DataNode *parentNode, bool completeSave,
node->AddNode(new DataNode("centroid", centroid, 3));
}
if(completeSave || !FieldsEqual(ID_project2D, &defaultObject))
{
addToParent = true;
node->AddNode(new DataNode("project2D", project2D));
}
// Add the node to the parent node.
if(addToParent || forceAdd)
......@@ -554,6 +564,8 @@ ToroidalPoloidalProjection::SetFromNode(DataNode *parentNode)
}
if((node = searchNode->GetNode("centroid")) != 0)
SetCentroid(node->AsDoubleArray());
if((node = searchNode->GetNode("project2D")) != 0)
SetProject2D(node->AsBool());
}
///////////////////////////////////////////////////////////////////////////////
......@@ -590,6 +602,13 @@ ToroidalPoloidalProjection::SetCentroid(const double *centroid_)
Select(ID_centroid, (void *)centroid, 3);
}
void
ToroidalPoloidalProjection::SetProject2D(bool project2D_)
{
project2D = project2D_;
Select(ID_project2D, (void *)&project2D);
}
///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////
......@@ -624,6 +643,12 @@ ToroidalPoloidalProjection::GetCentroid()
return centroid;
}
bool
ToroidalPoloidalProjection::GetProject2D() const
{
return project2D;
}
///////////////////////////////////////////////////////////////////////////////
// Select property methods
///////////////////////////////////////////////////////////////////////////////
......@@ -662,6 +687,7 @@ ToroidalPoloidalProjection::GetFieldName(int index) const
case ID_r: return "r";
case ID_centroidSource: return "centroidSource";
case ID_centroid: return "centroid";
case ID_project2D: return "project2D";
default: return "invalid index";
}
}
......@@ -690,6 +716,7 @@ ToroidalPoloidalProjection::GetFieldType(int index) const
case ID_r: return FieldType_double;
case ID_centroidSource: return FieldType_enum;
case ID_centroid: return FieldType_doubleArray;
case ID_project2D: return FieldType_bool;
default: return FieldType_unknown;
}
}
......@@ -718,6 +745,7 @@ ToroidalPoloidalProjection::GetFieldTypeName(int index) const
case ID_r: return "double";
case ID_centroidSource: return "enum";
case ID_centroid: return "doubleArray";
case ID_project2D: return "bool";
default: return "invalid index";
}
}
......@@ -769,6 +797,11 @@ ToroidalPoloidalProjection::FieldsEqual(int index_, const AttributeGroup *rhs) c
retval = centroid_equal;
}
break;
case ID_project2D:
{ // new scope
retval = (project2D == obj.project2D);
}
break;
default: retval = false;
}
......
......@@ -98,6 +98,7 @@ public:
void SetR(double r_);
void SetCentroidSource(CentroidSource centroidSource_);
void SetCentroid(const double *centroid_);
void SetProject2D(bool project2D_);
// Property getting methods
double GetR0() const;
......@@ -105,6 +106,7 @@ public:
CentroidSource GetCentroidSource() const;
const double *GetCentroid() const;
double *GetCentroid();
bool GetProject2D() const;
// Persistence methods
virtual bool CreateNode(DataNode *node, bool completeSave, bool forceAdd);
......@@ -130,6 +132,7 @@ public:
ID_r,
ID_centroidSource,
ID_centroid,
ID_project2D,
ID__LAST
};
......@@ -138,11 +141,12 @@ private:
double r;
int centroidSource;
double centroid[3];
bool project2D;
// Static class format string for type map.
static const char *TypeMapFormatString;
static const private_tmfs_t TmfsStruct;
};
#define TOROIDALPOLOIDALPROJECTION_TMFS "ddiD"
#define TOROIDALPOLOIDALPROJECTION_TMFS "ddiDb"
#endif
......@@ -59,7 +59,7 @@ import llnl.visit.Plugin;
public class ToroidalPoloidalProjection extends AttributeSubject implements Plugin
{
private static int ToroidalPoloidalProjection_numAdditionalAtts = 4;
private static int ToroidalPoloidalProjection_numAdditionalAtts = 5;
// Enum values
public final static int CENTROIDSOURCE_MANUAL = 0;
......@@ -77,6 +77,7 @@ public class ToroidalPoloidalProjection extends AttributeSubject implements Plug
centroid[0] = 0;
centroid[1] = 0;
centroid[2] = 0;
project2D = true;
}
public ToroidalPoloidalProjection(int nMoreFields)
......@@ -90,6 +91,7 @@ public class ToroidalPoloidalProjection extends AttributeSubject implements Plug
centroid[0] = 0;
centroid[1] = 0;
centroid[2] = 0;
project2D = true;
}
public ToroidalPoloidalProjection(ToroidalPoloidalProjection obj)
......@@ -106,6 +108,7 @@ public class ToroidalPoloidalProjection extends AttributeSubject implements Plug
centroid[1] = obj.centroid[1];
centroid[2] = obj.centroid[2];
project2D = obj.project2D;
SelectAll();
}
......@@ -133,7 +136,8 @@ public class ToroidalPoloidalProjection extends AttributeSubject implements Plug
return ((R0 == obj.R0) &&
(r == obj.r) &&
(centroidSource == obj.centroidSource) &&
centroid_equal);
centroid_equal &&
(project2D == obj.project2D));
}
public String GetName() { return "ToroidalPoloidalProjection"; }
......@@ -174,11 +178,18 @@ public class ToroidalPoloidalProjection extends AttributeSubject implements Plug
Select(3);
}
public void SetProject2D(boolean project2D_)
{
project2D = project2D_;
Select(4);
}
// Property getting methods
public double GetR0() { return R0; }
public double GetR() { return r; }
public int GetCentroidSource() { return centroidSource; }
public double[] GetCentroid() { return centroid; }
public boolean GetProject2D() { return project2D; }
// Write and read methods.
public void WriteAtts(CommunicationBuffer buf)
......@@ -191,6 +202,8 @@ public class ToroidalPoloidalProjection extends AttributeSubject implements Plug
buf.WriteInt(centroidSource);
if(WriteSelect(3, buf))
buf.WriteDoubleArray(centroid);
if(WriteSelect(4, buf))
buf.WriteBool(project2D);
}
public void ReadAtts(int index, CommunicationBuffer buf)
......@@ -209,6 +222,9 @@ public class ToroidalPoloidalProjection extends AttributeSubject implements Plug
case 3:
SetCentroid(buf.ReadDoubleArray());
break;
case 4:
SetProject2D(buf.ReadBool());
break;
}
}
......@@ -224,6 +240,7 @@ public class ToroidalPoloidalProjection extends AttributeSubject implements Plug
str = str + "CENTROIDSOURCE_AUTO";
str = str + "\n";
str = str + doubleArrayToString("centroid", centroid, indent) + "\n";
str = str + boolToString("project2D", project2D, indent) + "\n";
return str;
}
......@@ -233,5 +250,6 @@ public class ToroidalPoloidalProjection extends AttributeSubject implements Plug
private double r;
private int centroidSource;
private double[] centroid;
private boolean project2D;
}
......@@ -19,5 +19,8 @@
0.000000
0.000000
</Field>
<Field name="project2D" label="Project to XY plane" type="bool">
true
</Field>
</Attribute>
</Plugin>
......@@ -58,7 +58,8 @@
//
// ****************************************************************************
avtToroidalPoloidalProjectionFilter::avtToroidalPoloidalProjectionFilter()
avtToroidalPoloidalProjectionFilter::avtToroidalPoloidalProjectionFilter() :
rMax(0)
{
}
......@@ -257,7 +258,9 @@ avtToroidalPoloidalProjectionFilter::ExecuteData(vtkDataSet *in_ds,
R0 = centroid.x;
double poloidal_angle_theta = 0.0,toroidal_angle_phi = 0.0;
rMax = 0;
double poloidal_angle_theta = 0.0, toroidal_angle_phi = 0.0;
//test mapping of theta
// double test_r = 1;
......@@ -291,16 +294,15 @@ avtToroidalPoloidalProjectionFilter::ExecuteData(vtkDataSet *in_ds,
//on xy plane
double u = R0 - sqrt(x*x + y*y);
//r = sqrt(u*u + (z-centroid.z)*(z-centroid.z));
//compute hyp(r) = sqrt(length of adjacent(u)**2 + length of opposite(z)**2)
r = sqrt(u*u + (z-centroid.z)*(z-centroid.z));
//atan2 supports range of -PI to PI ..
//theta = inverse tangent of opposite over adjacent
//u is negated here because Linda Sugiyama requested the
//mapping goes counter clockwise and outside of the torus
//should be 0, inside is PI/-PI top is PI/2 and bottom is
//-PI/2 and this mapping has that effect
poloidal_angle_theta = atan2(z,-u);
poloidal_angle_theta = atan2((z-centroid.z),-u);
//phi is computed from and atan2 supports range of -PI to PI ..
//x = (R0 +rcos(theta))sin(phi), y = (R0+rcos(theta)cos(phi))
......@@ -314,7 +316,18 @@ avtToroidalPoloidalProjectionFilter::ExecuteData(vtkDataSet *in_ds,
//map to 2D x = toroidal, y = poloidal, z is projected to 0
out_pt[0] = toroidal_angle_phi; //x axis goes in the direction of torus
out_pt[1] = poloidal_angle_theta;//y axis goes in the direction of the poloid
out_pt[2] = 0.; //out_pt[2] = r;
if( atts.GetProject2D() == true )
out_pt[2] = 0.;
else //if( atts.GetProject2D() == false )
{
r = sqrt(u*u + (z-centroid.z)*(z-centroid.z));
out_pt[2] = r;
if( rMax < r )
rMax = r;
}
outPts->SetPoint(i, out_pt);
}
......@@ -339,10 +352,9 @@ avtToroidalPoloidalProjectionFilter::ExecuteData(vtkDataSet *in_ds,
for (int z = 0 ; z < ncells ; z++)
{
ds->GetCell(z)->GetBounds(b);
//check bounds in x and y direction
//if either x or y direction have large bounds
//then we presume that they are wrapping around and therefore
//can be used as ghost cells
//check bounds in x and y direction, if either x or y
//direction have large bounds then presume that they are
//wrapping around and therefore can be used as ghost cells
if (b[0] < -1 && b[1] > 1)
gz->SetValue(z, 1);
else if (b[2] < -1 && b[3] > 1)
......@@ -350,6 +362,10 @@ avtToroidalPoloidalProjectionFilter::ExecuteData(vtkDataSet *in_ds,
else
gz->SetValue(z,0); //setting any other values to 0
}
// Update to get teh correct rMax value.
if( atts.GetProject2D() == false )
UpdateDataObjectInfo();
ManageMemory(ds);
ds->Delete();
......@@ -366,8 +382,11 @@ avtToroidalPoloidalProjectionFilter::UpdateDataObjectInfo(void)
outAtts.SetContainsGhostZones(AVT_CREATED_GHOSTS);
if (inAtts.GetSpatialDimension() == 3)
outAtts.SetSpatialDimension(2);
if( atts.GetProject2D() == true )
outAtts.SetSpatialDimension(2);
else //if( atts.GetProject2D() == false )
outAtts.SetSpatialDimension(3);
GetOutput()->GetInfo().GetValidity().InvalidateSpatialMetaData();
......@@ -375,9 +394,12 @@ avtToroidalPoloidalProjectionFilter::UpdateDataObjectInfo(void)
outAtts.GetDesiredSpatialExtents()->Clear();
outAtts.GetActualSpatialExtents()->Clear();
double bounds[6] = { -M_PI, M_PI, -M_PI, M_PI, 0, 0 };
double bounds[6] = { -M_PI, M_PI, -M_PI, M_PI, 0, rMax };
outAtts.GetThisProcsOriginalSpatialExtents()->Set(bounds);
outAtts.SetXLabel("Toroidal");
outAtts.SetYLabel("Poloidal");
if( atts.GetProject2D() == false )
outAtts.SetZLabel("R");
}
......@@ -93,6 +93,7 @@ class avtToroidalPoloidalProjectionFilter : public avtPluginDataTreeIterator
protected:
virtual avtVector GetCentroid(vtkPoints* inPts);
double rMax;
ToroidalPoloidalProjection atts;
virtual vtkDataSet *ExecuteData(vtkDataSet *, int, std::string);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment