Commit a5da216c authored by allens's avatar allens

fixed a centroid bug and removed unused gui vars

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@16577 18c085ea-50e0-402c-830e-de6fd14e8384
parent 281909b5
......@@ -49,6 +49,7 @@ ${VISIT_INCLUDE_DIR}/avt/Expressions/ImageProcessing
${VISIT_INCLUDE_DIR}/avt/Expressions/Management
${VISIT_INCLUDE_DIR}/avt/Expressions/Math
${VISIT_INCLUDE_DIR}/avt/Expressions/MeshQuality
${VISIT_INCLUDE_DIR}/avt/Expressions/TimeIterators
${VISIT_INCLUDE_DIR}/avt/FileWriter
${VISIT_INCLUDE_DIR}/avt/Filters
${VISIT_INCLUDE_DIR}/avt/IVP
......
......@@ -80,6 +80,37 @@ PyToroidalPoloidalProjection_ToString(const ToroidalPoloidalProjection *atts, co
str += tmpStr;
SNPRINTF(tmpStr, 1000, "%sr = %g\n", prefix, atts->GetR());
str += tmpStr;
const char *centroidSource_names = "Manual, Auto";
switch (atts->GetCentroidSource())
{
case ToroidalPoloidalProjection::Manual:
SNPRINTF(tmpStr, 1000, "%scentroidSource = %sManual # %s\n", prefix, prefix, centroidSource_names);
str += tmpStr;
break;
case ToroidalPoloidalProjection::Auto:
SNPRINTF(tmpStr, 1000, "%scentroidSource = %sAuto # %s\n", prefix, prefix, centroidSource_names);
str += tmpStr;
break;
default:
break;
}
{ const double *centroid = atts->GetCentroid();
SNPRINTF(tmpStr, 1000, "%scentroid = (", prefix);
str += tmpStr;
for(int i = 0; i < 3; ++i)
{
SNPRINTF(tmpStr, 1000, "%g", centroid[i]);
str += tmpStr;
if(i < 2)
{
SNPRINTF(tmpStr, 1000, ", ");
str += tmpStr;
}
}
SNPRINTF(tmpStr, 1000, ")\n");
str += tmpStr;
}
return str;
}
......@@ -140,6 +171,93 @@ ToroidalPoloidalProjection_GetR(PyObject *self, PyObject *args)
return retval;
}
/*static*/ PyObject *
ToroidalPoloidalProjection_SetCentroidSource(PyObject *self, PyObject *args)
{
ToroidalPoloidalProjectionObject *obj = (ToroidalPoloidalProjectionObject *)self;
int ival;
if(!PyArg_ParseTuple(args, "i", &ival))
return NULL;
// Set the centroidSource in the object.
if(ival >= 0 && ival < 2)
obj->data->SetCentroidSource(ToroidalPoloidalProjection::CentroidSource(ival));
else
{
fprintf(stderr, "An invalid centroidSource value was given. "
"Valid values are in the range of [0,1]. "
"You can also use the following names: "
"Manual, Auto.");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
/*static*/ PyObject *
ToroidalPoloidalProjection_GetCentroidSource(PyObject *self, PyObject *args)
{
ToroidalPoloidalProjectionObject *obj = (ToroidalPoloidalProjectionObject *)self;
PyObject *retval = PyInt_FromLong(long(obj->data->GetCentroidSource()));
return retval;
}
/*static*/ PyObject *
ToroidalPoloidalProjection_SetCentroid(PyObject *self, PyObject *args)
{
ToroidalPoloidalProjectionObject *obj = (ToroidalPoloidalProjectionObject *)self;
double *dvals = obj->data->GetCentroid();
if(!PyArg_ParseTuple(args, "ddd", &dvals[0], &dvals[1], &dvals[2]))
{
PyObject *tuple;
if(!PyArg_ParseTuple(args, "O", &tuple))
return NULL;
if(PyTuple_Check(tuple))
{
if(PyTuple_Size(tuple) != 3)
return NULL;
PyErr_Clear();
for(int i = 0; i < PyTuple_Size(tuple); ++i)
{
PyObject *item = PyTuple_GET_ITEM(tuple, i);
if(PyFloat_Check(item))
dvals[i] = PyFloat_AS_DOUBLE(item);
else if(PyInt_Check(item))
dvals[i] = double(PyInt_AS_LONG(item));
else if(PyLong_Check(item))
dvals[i] = PyLong_AsDouble(item);
else
dvals[i] = 0.;
}
}
else
return NULL;
}
// Mark the centroid in the object as modified.
obj->data->SelectCentroid();
Py_INCREF(Py_None);
return Py_None;
}
/*static*/ PyObject *
ToroidalPoloidalProjection_GetCentroid(PyObject *self, PyObject *args)
{
ToroidalPoloidalProjectionObject *obj = (ToroidalPoloidalProjectionObject *)self;
// Allocate a tuple the with enough entries to hold the centroid.
PyObject *retval = PyTuple_New(3);
const double *centroid = obj->data->GetCentroid();
for(int i = 0; i < 3; ++i)
PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(centroid[i]));
return retval;
}
PyMethodDef PyToroidalPoloidalProjection_methods[TOROIDALPOLOIDALPROJECTION_NMETH] = {
......@@ -148,6 +266,10 @@ PyMethodDef PyToroidalPoloidalProjection_methods[TOROIDALPOLOIDALPROJECTION_NMET
{"GetR0", ToroidalPoloidalProjection_GetR0, METH_VARARGS},
{"SetR", ToroidalPoloidalProjection_SetR, METH_VARARGS},
{"GetR", ToroidalPoloidalProjection_GetR, METH_VARARGS},
{"SetCentroidSource", ToroidalPoloidalProjection_SetCentroidSource, METH_VARARGS},
{"GetCentroidSource", ToroidalPoloidalProjection_GetCentroidSource, METH_VARARGS},
{"SetCentroid", ToroidalPoloidalProjection_SetCentroid, METH_VARARGS},
{"GetCentroid", ToroidalPoloidalProjection_GetCentroid, METH_VARARGS},
{NULL, NULL}
};
......@@ -180,6 +302,15 @@ PyToroidalPoloidalProjection_getattr(PyObject *self, char *name)
return ToroidalPoloidalProjection_GetR0(self, NULL);
if(strcmp(name, "r") == 0)
return ToroidalPoloidalProjection_GetR(self, NULL);
if(strcmp(name, "centroidSource") == 0)
return ToroidalPoloidalProjection_GetCentroidSource(self, NULL);
if(strcmp(name, "Manual") == 0)
return PyInt_FromLong(long(ToroidalPoloidalProjection::Manual));
if(strcmp(name, "Auto") == 0)
return PyInt_FromLong(long(ToroidalPoloidalProjection::Auto));
if(strcmp(name, "centroid") == 0)
return ToroidalPoloidalProjection_GetCentroid(self, NULL);
return Py_FindMethod(PyToroidalPoloidalProjection_methods, self, name);
}
......@@ -198,6 +329,10 @@ PyToroidalPoloidalProjection_setattr(PyObject *self, char *name, PyObject *args)
obj = ToroidalPoloidalProjection_SetR0(self, tuple);
else if(strcmp(name, "r") == 0)
obj = ToroidalPoloidalProjection_SetR(self, tuple);
else if(strcmp(name, "centroidSource") == 0)
obj = ToroidalPoloidalProjection_SetCentroidSource(self, tuple);
else if(strcmp(name, "centroid") == 0)
obj = ToroidalPoloidalProjection_SetCentroid(self, tuple);
if(obj != NULL)
Py_DECREF(obj);
......
......@@ -44,7 +44,7 @@
//
// Functions exposed to the VisIt module.
//
#define TOROIDALPOLOIDALPROJECTION_NMETH 6
#define TOROIDALPOLOIDALPROJECTION_NMETH 10
void PyToroidalPoloidalProjection_StartUp(ToroidalPoloidalProjection *subj, void *data);
void PyToroidalPoloidalProjection_CloseDown();
PyMethodDef * PyToroidalPoloidalProjection_GetMethodTable(int *nMethods);
......
......@@ -127,19 +127,43 @@ QvisToroidalPoloidalProjectionWindow::CreateWindowContents()
QGridLayout *mainLayout = new QGridLayout(0);
topLayout->addLayout(mainLayout);
R0Label = new QLabel(tr("R0: toroidal radius"), central);
mainLayout->addWidget(R0Label,0,0);
R0 = new QLineEdit(central);
connect(R0, SIGNAL(returnPressed()),
this, SLOT(R0ProcessText()));
mainLayout->addWidget(R0, 0,1);
rLabel = new QLabel(tr("r: poloidal radius"), central);
mainLayout->addWidget(rLabel,1,0);
r = new QLineEdit(central);
connect(r, SIGNAL(returnPressed()),
this, SLOT(rProcessText()));
mainLayout->addWidget(r, 1,1);
// R0Label = new QLabel(tr("R0: toroidal radius"), central);
// mainLayout->addWidget(R0Label,0,0);
// R0 = new QLineEdit(central);
// connect(R0, SIGNAL(returnPressed()),
// this, SLOT(R0ProcessText()));
// mainLayout->addWidget(R0, 0,1);
// rLabel = new QLabel(tr("r: poloidal radius"), central);
// mainLayout->addWidget(rLabel,1,0);
// r = new QLineEdit(central);
// connect(r, SIGNAL(returnPressed()),
// this, SLOT(rProcessText()));
// mainLayout->addWidget(r, 1,1);
centroidSourceLabel = new QLabel(tr("Centroid Source"), central);
mainLayout->addWidget(centroidSourceLabel,2,0);
centroidSource = new QWidget(central);
centroidSourceButtonGroup= new QButtonGroup(centroidSource);
QHBoxLayout *centroidSourceLayout = new QHBoxLayout(centroidSource);
centroidSourceLayout->setMargin(0);
centroidSourceLayout->setSpacing(10);
QRadioButton *centroidSourceCentroidSourceManual = new QRadioButton(tr("Manual"), centroidSource);
centroidSourceButtonGroup->addButton(centroidSourceCentroidSourceManual,0);
centroidSourceLayout->addWidget(centroidSourceCentroidSourceManual);
QRadioButton *centroidSourceCentroidSourceAuto = new QRadioButton(tr("Auto"), centroidSource);
centroidSourceButtonGroup->addButton(centroidSourceCentroidSourceAuto,1);
centroidSourceLayout->addWidget(centroidSourceCentroidSourceAuto);
connect(centroidSourceButtonGroup, SIGNAL(buttonClicked(int)),
this, SLOT(centroidSourceChanged(int)));
mainLayout->addWidget(centroidSource, 2,1);
centroidLabel = new QLabel(tr("Centroid (R,phi,Z)"), central);
mainLayout->addWidget(centroidLabel,3,0);
centroid = new QLineEdit(central);
connect(centroid, SIGNAL(returnPressed()),
this, SLOT(centroidProcessText()));
mainLayout->addWidget(centroid, 3,1);
}
......@@ -175,11 +199,32 @@ QvisToroidalPoloidalProjectionWindow::UpdateWindow(bool doAll)
switch(i)
{
case ToroidalPoloidalProjection::ID_R0:
R0->setText(DoubleToQString(atts->GetR0()));
// case ToroidalPoloidalProjection::ID_R0:
// R0->setText(DoubleToQString(atts->GetR0()));
// break;
// case ToroidalPoloidalProjection::ID_r:
// r->setText(DoubleToQString(atts->GetR()));
// break;
case ToroidalPoloidalProjection::ID_centroidSource:
if (atts->GetCentroidSource() == ToroidalPoloidalProjection::Manual)
{
centroid->setEnabled(true);
if(centroidLabel)
centroidLabel->setEnabled(true);
}
else
{
centroid->setEnabled(false);
if(centroidLabel)
centroidLabel->setEnabled(false);
}
centroidSourceButtonGroup->blockSignals(true);
if(centroidSourceButtonGroup->button((int)atts->GetCentroidSource()) != 0)
centroidSourceButtonGroup->button((int)atts->GetCentroidSource())->setChecked(true);
centroidSourceButtonGroup->blockSignals(false);
break;
case ToroidalPoloidalProjection::ID_r:
r->setText(DoubleToQString(atts->GetR()));
case ToroidalPoloidalProjection::ID_centroid:
centroid->setText(DoublesToQString(atts->GetCentroid(), 3));
break;
}
}
......@@ -207,30 +252,44 @@ QvisToroidalPoloidalProjectionWindow::GetCurrentValues(int which_widget)
bool doAll = (which_widget == -1);
// Do R0
if(which_widget == ToroidalPoloidalProjection::ID_R0 || doAll)
// if(which_widget == ToroidalPoloidalProjection::ID_R0 || doAll)
// {
// double val;
// if(LineEditGetDouble(R0, val))
// atts->SetR0(val);
// else
// {
// ResettingError(tr("R0: toroidal radius"),
// DoubleToQString(atts->GetR0()));
// atts->SetR0(atts->GetR0());
// }
// }
// // Do r
// if(which_widget == ToroidalPoloidalProjection::ID_r || doAll)
// {
// double val;
// if(LineEditGetDouble(r, val))
// atts->SetR(val);
// else
// {
// ResettingError(tr("r: poloidal radius"),
// DoubleToQString(atts->GetR()));
// atts->SetR(atts->GetR());
// }
// }
// Do centroid
if(which_widget == ToroidalPoloidalProjection::ID_centroid || doAll)
{
double val;
if(LineEditGetDouble(R0, val))
atts->SetR0(val);
double val[3];
if(LineEditGetDoubles(centroid, val, 3))
atts->SetCentroid(val);
else
{
ResettingError(tr("R0: toroidal radius"),
DoubleToQString(atts->GetR0()));
atts->SetR0(atts->GetR0());
}
}
// Do r
if(which_widget == ToroidalPoloidalProjection::ID_r || doAll)
{
double val;
if(LineEditGetDouble(r, val))
atts->SetR(val);
else
{
ResettingError(tr("r: poloidal radius"),
DoubleToQString(atts->GetR()));
atts->SetR(atts->GetR());
ResettingError(tr("Centroid (R,phi,Z)"),
DoublesToQString(atts->GetCentroid(),3));
atts->SetCentroid(atts->GetCentroid());
}
}
......@@ -242,18 +301,37 @@ QvisToroidalPoloidalProjectionWindow::GetCurrentValues(int which_widget)
//
// void
// QvisToroidalPoloidalProjectionWindow::R0ProcessText()
// {
// GetCurrentValues(ToroidalPoloidalProjection::ID_R0);
// Apply();
// }
// void
// QvisToroidalPoloidalProjectionWindow::rProcessText()
// {
// GetCurrentValues(ToroidalPoloidalProjection::ID_r);
// Apply();
// }
void
QvisToroidalPoloidalProjectionWindow::R0ProcessText()
QvisToroidalPoloidalProjectionWindow::centroidSourceChanged(int val)
{
GetCurrentValues(ToroidalPoloidalProjection::ID_R0);
Apply();
if(val != atts->GetCentroidSource())
{
atts->SetCentroidSource(ToroidalPoloidalProjection::CentroidSource(val));
Apply();
}
}
void
QvisToroidalPoloidalProjectionWindow::rProcessText()
QvisToroidalPoloidalProjectionWindow::centroidProcessText()
{
GetCurrentValues(ToroidalPoloidalProjection::ID_r);
GetCurrentValues(ToroidalPoloidalProjection::ID_centroid);
Apply();
}
......
......@@ -86,17 +86,21 @@ class QvisToroidalPoloidalProjectionWindow : public QvisOperatorWindow
void UpdateWindow(bool doAll);
virtual void GetCurrentValues(int which_widget);
private slots:
void R0ProcessText();
void rProcessText();
// void R0ProcessText();
// void rProcessText();
void centroidSourceChanged(int val);
void centroidProcessText();
private:
QLineEdit *R0;
QLineEdit *r;
QLabel *R0Label;
QLabel *rLabel;
// QLineEdit *R0;
// QLineEdit *r;
QWidget *centroidSource;
QButtonGroup *centroidSourceButtonGroup;
QLineEdit *centroid;
// QLabel *R0Label;
// QLabel *rLabel;
QLabel *centroidSourceLabel;
QLabel *centroidLabel;
ToroidalPoloidalProjection *atts;
};
#endif
......@@ -39,6 +39,43 @@
#include <ToroidalPoloidalProjection.h>
#include <DataNode.h>
//
// Enum conversion methods for ToroidalPoloidalProjection::CentroidSource
//
static const char *CentroidSource_strings[] = {
"Manual", "Auto"};
std::string
ToroidalPoloidalProjection::CentroidSource_ToString(ToroidalPoloidalProjection::CentroidSource t)
{
int index = int(t);
if(index < 0 || index >= 2) index = 0;
return CentroidSource_strings[index];
}
std::string
ToroidalPoloidalProjection::CentroidSource_ToString(int t)
{
int index = (t < 0 || t >= 2) ? 0 : t;
return CentroidSource_strings[index];
}
bool
ToroidalPoloidalProjection::CentroidSource_FromString(const std::string &s, ToroidalPoloidalProjection::CentroidSource &val)
{
val = ToroidalPoloidalProjection::Manual;
for(int i = 0; i < 2; ++i)
{
if(s == CentroidSource_strings[i])
{
val = (CentroidSource)i;
return true;
}
}
return false;
}
// ****************************************************************************
// Method: ToroidalPoloidalProjection::ToroidalPoloidalProjection
//
......@@ -58,6 +95,10 @@ void ToroidalPoloidalProjection::Init()
{
R0 = 1.5;
r = 0.2;
centroidSource = Manual;
centroid[0] = 0;
centroid[1] = 0;
centroid[2] = 0;
ToroidalPoloidalProjection::SelectAll();
}
......@@ -81,6 +122,11 @@ void ToroidalPoloidalProjection::Copy(const ToroidalPoloidalProjection &obj)
{
R0 = obj.R0;
r = obj.r;
centroidSource = obj.centroidSource;
centroid[0] = obj.centroid[0];
centroid[1] = obj.centroid[1];
centroid[2] = obj.centroid[2];
ToroidalPoloidalProjection::SelectAll();
}
......@@ -237,9 +283,16 @@ ToroidalPoloidalProjection::operator = (const ToroidalPoloidalProjection &obj)
bool
ToroidalPoloidalProjection::operator == (const ToroidalPoloidalProjection &obj) const
{
// Compare the centroid arrays.
bool centroid_equal = true;
for(int i = 0; i < 3 && centroid_equal; ++i)
centroid_equal = (centroid[i] == obj.centroid[i]);
// Create the return value
return ((R0 == obj.R0) &&
(r == obj.r));
(r == obj.r) &&
(centroidSource == obj.centroidSource) &&
centroid_equal);
}
// ****************************************************************************
......@@ -383,8 +436,10 @@ ToroidalPoloidalProjection::NewInstance(bool copy) const
void
ToroidalPoloidalProjection::SelectAll()
{
Select(ID_R0, (void *)&R0);
Select(ID_r, (void *)&r);
Select(ID_R0, (void *)&R0);
Select(ID_r, (void *)&r);
Select(ID_centroidSource, (void *)&centroidSource);
Select(ID_centroid, (void *)centroid, 3);
}
///////////////////////////////////////////////////////////////////////////////
......@@ -429,6 +484,18 @@ ToroidalPoloidalProjection::CreateNode(DataNode *parentNode, bool completeSave,
node->AddNode(new DataNode("r", r));
}
if(completeSave || !FieldsEqual(ID_centroidSource, &defaultObject))
{
addToParent = true;
node->AddNode(new DataNode("centroidSource", CentroidSource_ToString(centroidSource)));
}
if(completeSave || !FieldsEqual(ID_centroid, &defaultObject))
{
addToParent = true;
node->AddNode(new DataNode("centroid", centroid, 3));
}
// Add the node to the parent node.
if(addToParent || forceAdd)
......@@ -469,6 +536,24 @@ ToroidalPoloidalProjection::SetFromNode(DataNode *parentNode)
SetR0(node->AsDouble());
if((node = searchNode->GetNode("r")) != 0)
SetR(node->AsDouble());
if((node = searchNode->GetNode("centroidSource")) != 0)
{
// Allow enums to be int or string in the config file
if(node->GetNodeType() == INT_NODE)
{
int ival = node->AsInt();
if(ival >= 0 && ival < 2)
SetCentroidSource(CentroidSource(ival));
}
else if(node->GetNodeType() == STRING_NODE)
{
CentroidSource value;
if(CentroidSource_FromString(node->AsString(), value))
SetCentroidSource(value);
}
}
if((node = searchNode->GetNode("centroid")) != 0)
SetCentroid(node->AsDoubleArray());
}
///////////////////////////////////////////////////////////////////////////////
......@@ -489,6 +574,22 @@ ToroidalPoloidalProjection::SetR(double r_)
Select(ID_r, (void *)&r);
}
void
ToroidalPoloidalProjection::SetCentroidSource(ToroidalPoloidalProjection::CentroidSource centroidSource_)
{
centroidSource = centroidSource_;
Select(ID_centroidSource, (void *)&centroidSource);
}
void
ToroidalPoloidalProjection::SetCentroid(const double *centroid_)
{
centroid[0] = centroid_[0];
centroid[1] = centroid_[1];
centroid[2] = centroid_[2];
Select(ID_centroid, (void *)centroid, 3);
}
///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////
......@@ -505,6 +606,34 @@ ToroidalPoloidalProjection::GetR() const
return r;
}
ToroidalPoloidalProjection::CentroidSource
ToroidalPoloidalProjection::GetCentroidSource() const
{
return CentroidSource(centroidSource);
}
const double *
ToroidalPoloidalProjection::GetCentroid() const
{
return centroid;
}
double *
ToroidalPoloidalProjection::GetCentroid()
{
return centroid;
}
///////////////////////////////////////////////////////////////////////////////
// Select property methods
///////////////////////////////////////////////////////////////////////////////
void
ToroidalPoloidalProjection::SelectCentroid()
{
Select(ID_centroid, (void *)centroid, 3);
}
///////////////////////////////////////////////////////////////////////////////
// Keyframing methods
///////////////////////////////////////////////////////////////////////////////
......@@ -529,8 +658,10 @@ ToroidalPoloidalProjection::GetFieldName(int index) const
{
switch (index)
{
case ID_R0: return "R0";
case ID_r: return "r";
case ID_R0: return "R0";
case ID_r: return "r";
case ID_centroidSource: return "centroidSource";
case ID_centroid: return "centroid";
default: return "invalid index";
}
}
......@@ -555,8 +686,10 @@ ToroidalPoloidalProjection::GetFieldType(int index) const
{
switch (index)
{
case ID_R0: return FieldType_double;
case ID_r: return FieldType_double;
case ID_R0: return FieldType_double;
case ID_r: return FieldType_double;
case ID_centroidSource: return FieldType_enum;
case ID_centroid: return FieldType_doubleArray;
default: return FieldType_unknown;
}
}
......@@ -581,8 +714,10 @@ ToroidalPoloidalProjection::GetFieldTypeName(int index) const
{
switch (index)
{
case ID_R0: return "double";
case ID_r: return "double";
case ID_R0: return "double";
case ID_r: return "double";
case ID_centroidSource: return "enum";
case ID_centroid: return "doubleArray";
default: return "invalid index";
}
}
......@@ -619,6 +754,21 @@ ToroidalPoloidalProjection::FieldsEqual(int index_, const AttributeGroup *rhs) c
retval = (r == obj.r);
}
break;
case ID_centroidSource:
{ // new scope
retval = (centroidSource == obj.centroidSource);
}
break;
case ID_centroid:
{ // new scope
// Compare the centroid arrays.
bool centroid_equal = true;
for(int i = 0; i < 3 && centroid_equal; ++i)
centroid_equal = (centroid[i] == obj.centroid[i]);
retval = centroid_equal;
}
break;
default: retval = false;
}
......