Commit ada94d86 authored by bonnell's avatar bonnell
Browse files

Add GetPickOutputObject() cli method which returns pick results as a python dictionary.

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@16560 18c085ea-50e0-402c-830e-de6fd14e8384
parent 928c13bd
......@@ -4357,3 +4357,164 @@ PickAttributes::SetRayPoint2(const doubleVector &_v)
rayPoint2[2] = _v[2];
}
// ****************************************************************************
// Method: PickAttributes::CreateXMLString
//
// Purpose:
// Creates an xml output string containing all the information gathered
// from a pick.
//
// Programmer: Kathleen Biagas
// Creation: September 22, 2011
//
// Modifications:
//
// ****************************************************************************
void
PickAttributes::CreateXMLString(std::string &os, bool withLetter)
{
if (!os.empty())
os.clear();
if (error)
return;
if (!fulfilled)
return;
MapNode m;
if (pickType == Zone || pickType == DomainZone)
{
m["zone_id"] = elementNumber;
}
else if (pickType == Node || pickType == DomainNode)
{
m["node_id"] = elementNumber;
}
doubleVector p;
if (pickType == CurveNode)
{
p.push_back(nodePoint[0]);
p.push_back(nodePoint[1]);
m["point"] = p;
}
else if (pickType == CurveZone)
{
p.push_back(nodePoint[0]);
p.push_back(nodePoint[1]);
m["point1"] = p;
p[0] = cellPoint[0];
p[1] = cellPoint[0];
m["point2"] = p;
}
else if (cellPoint[0] != FLT_MAX)
{
p.push_back(cellPoint[0]);
p.push_back(cellPoint[1]);
if (dimension == 3)
{
p.push_back(cellPoint[2]);
}
//if (!needTransformMessage)
{
m["point"] = p;
}
#if 0
else
{
m["transformed_point"] = p;
}
#endif
}
char buff[512];
std::string fileName;
size_t pos = databaseName.find_last_of('/');
if (pos >= databaseName.size())
fileName = databaseName;
else
fileName = databaseName.substr(pos+1) ;
m["filename"] = fileName;
if (withLetter)
{
m["pick_letter"] = pickLetter;
}
if (domain != -1)
{
m["domain_id"] = domain;
}
if (showTimeStep && timeStep != -1)
{
m["timestep"] = timeStep;
}
if (displayIncidentElements)
{
bool showId = false;
bool showGlobal = globalIncidentElements.size() == incidentElements.size();
std::string elName;
std::string ghostName;
if (pickType == Zone || pickType == DomainZone)
{
if (!showGlobal)
elName = "incident_nodes";
else
elName = "global_incident_nodes";
ghostName = "ghost_incident_nodes";
showId = showNodeId;
}
else if (pickType == Node || pickType == DomainNode)
{
if (!showGlobal)
elName = "incident_zones";
else
elName = "global_incident_zones";
ghostName = "ghost_incident_zones";
showId = showZoneId;
}
if (showId)
{
m[elName] = incidentElements;
#if 0
intVector els, ghostEls;
for (size_t i = 0; i < incidentElements.size(); ++i)
{
if (ghosts.size() > 0 && ghosts[i])
ghostEls.push_back(incidentElements[i]);
else if (showGlobal)
els.push_back(globalIncidentElements[i]);
else
els.push_back(incidentElements[i]);
}
m[elName] = els;
if (!ghostEls.empty())
m[ghostName] = ghostEls;
#endif
}
}
for (size_t i = 0; i < varInfo.size(); ++i)
{
std::string pt = PickType_ToString(pickType);
PickVarInfo* info = (PickVarInfo*)varInfo[i];
info->CreateOutputMapNode(pt, m);
}
if (invalidVars.size() > 0)
{
for (size_t i = 0; i < invalidVars.size(); ++i)
{
m[invalidVars[i]] = std::string("invalid");
}
}
os = m.ToXML();
}
......@@ -1067,3 +1067,166 @@ PickAttributes::SetRayPoint2(const doubleVector &_v)
rayPoint2[2] = _v[2];
}
Function: CreateXMLString
Declaration: void CreateXMLString(std::string &os, bool withLetter = true);
Definition:
// ****************************************************************************
// Method: PickAttributes::CreateXMLString
//
// Purpose:
// Creates an xml output string containing all the information gathered
// from a pick.
//
// Programmer: Kathleen Biagas
// Creation: September 22, 2011
//
// Modifications:
//
// ****************************************************************************
void
PickAttributes::CreateXMLString(std::string &os, bool withLetter)
{
if (!os.empty())
os.clear();
if (error)
return;
if (!fulfilled)
return;
MapNode m;
if (pickType == Zone || pickType == DomainZone)
{
m["zone_id"] = elementNumber;
}
else if (pickType == Node || pickType == DomainNode)
{
m["node_id"] = elementNumber;
}
doubleVector p;
if (pickType == CurveNode)
{
p.push_back(nodePoint[0]);
p.push_back(nodePoint[1]);
m["point"] = p;
}
else if (pickType == CurveZone)
{
p.push_back(nodePoint[0]);
p.push_back(nodePoint[1]);
m["point1"] = p;
p[0] = cellPoint[0];
p[1] = cellPoint[0];
m["point2"] = p;
}
else if (cellPoint[0] != FLT_MAX)
{
p.push_back(cellPoint[0]);
p.push_back(cellPoint[1]);
if (dimension == 3)
{
p.push_back(cellPoint[2]);
}
//if (!needTransformMessage)
{
m["point"] = p;
}
#if 0
else
{
m["transformed_point"] = p;
}
#endif
}
char buff[512];
std::string fileName;
size_t pos = databaseName.find_last_of('/');
if (pos >= databaseName.size())
fileName = databaseName;
else
fileName = databaseName.substr(pos+1) ;
m["filename"] = fileName;
if (withLetter)
{
m["pick_letter"] = pickLetter;
}
if (domain != -1)
{
m["domain_id"] = domain;
}
if (showTimeStep && timeStep != -1)
{
m["timestep"] = timeStep;
}
if (displayIncidentElements)
{
bool showId = false;
bool showGlobal = globalIncidentElements.size() == incidentElements.size();
std::string elName;
std::string ghostName;
if (pickType == Zone || pickType == DomainZone)
{
if (!showGlobal)
elName = "incident_nodes";
else
elName = "global_incident_nodes";
ghostName = "ghost_incident_nodes";
showId = showNodeId;
}
else if (pickType == Node || pickType == DomainNode)
{
if (!showGlobal)
elName = "incident_zones";
else
elName = "global_incident_zones";
ghostName = "ghost_incident_zones";
showId = showZoneId;
}
if (showId)
{
m[elName] = incidentElements;
#if 0
intVector els, ghostEls;
for (size_t i = 0; i < incidentElements.size(); ++i)
{
if (ghosts.size() > 0 && ghosts[i])
ghostEls.push_back(incidentElements[i]);
else if (showGlobal)
els.push_back(globalIncidentElements[i]);
else
els.push_back(incidentElements[i]);
}
m[elName] = els;
if (!ghostEls.empty())
m[ghostName] = ghostEls;
#endif
}
}
for (size_t i = 0; i < varInfo.size(); ++i)
{
std::string pt = PickType_ToString(pickType);
PickVarInfo* info = (PickVarInfo*)varInfo[i];
info->CreateOutputMapNode(pt, m);
}
if (invalidVars.size() > 0)
{
for (size_t i = 0; i < invalidVars.size(); ++i)
{
m[invalidVars[i]] = std::string("invalid");
}
}
os = m.ToXML();
}
......@@ -353,6 +353,7 @@ public:
void CreateConciseOutputString(std::string &os, bool withLetter = true);
void SetRayPoint1(const doubleVector &);
void SetRayPoint2(const doubleVector &);
void CreateXMLString(std::string &os, bool withLetter = true);
// IDs that can be used to identify fields in case statements
enum {
......
......@@ -225,6 +225,8 @@
</Function>
<Function name="SetRayPoint2" user="true" member="true">
</Function>
<Function name="CreateXMLString" user="true" member="true">
</Function>
<Include file="source" quoted="false">
stdio.h
</Include>
......
......@@ -1669,3 +1669,228 @@ PickVarInfo::PrintArray(std::string &os,
}
}
// ****************************************************************************
// Method: PickVarInfo::CreateOutputMapNode
//
// Purpose:
// Creates a MapNode object containing all the information gathered
// from a pick.
//
// Programmer: Kathleen Biagas
// Creation: October 24, 2011
//
// Modifications:
//
// ****************************************************************************
void
PickVarInfo::CreateOutputMapNode(const std::string &type, MapNode &m)
{
bool centeringsMatch = false;
switch (centering)
{
case Nodal: if (type == "Node" || type == "DomainNode")
centeringsMatch = true;
break;
case Zonal: if (type == "Zone" || type == "DomainZone")
centeringsMatch = true;
break;
case None: break;
}
if (!(names.empty() && mixNames.empty()))
{
if (variableType == "material")
{
int mixOffset = 0;
if (numMatsPerZone.size() == 1 && numMatsPerZone[0] == 1)
{
std::string subname;
if (names.size() > 0)
subname = names[0] + " ";
subname += mixNames[mixOffset];
if (mixValues[mixOffset] < 1.)
{
MapNode n;
n[subname] = mixValues[mixOffset];
m[variableName] = n;
}
else
{
m[variableName] = subname;
}
}
else
{
MapNode n;
MapNode o;
for (size_t i = 0; i < numMatsPerZone.size(); ++i)
{
int nMats = numMatsPerZone[i];
std::string base;
if (names.size() > 0)
base = names[i].substr(1, names[i].size()-2);
for (int j = 0; j < nMats; ++j)
{
if (mixValues[j+mixOffset] < 1.)
{
// n[base + mixNames[j+mixOffset]] = mixValues[j+mixOffset];
if (!base.empty())
o[mixNames[j+mixOffset]] = mixValues[j+mixOffset];
else
n[mixNames[j+mixOffset]] = mixValues[j+mixOffset];
}
else
{
if (!base.empty())
n[base] = mixNames[j+mixOffset];
#if 0
else
n[mixNames[j+mixOffset]] = std::string("type2b");
#endif
}
}
if (!base.empty() && o.GetNumEntries() > 0)
n[base] = o;
mixOffset += nMats;
}
m[variableName] = n;
}
}
else if (variableType == "species")
{
int matOffset = 0;
int mixOffset = 0;
MapNode n;
MapNode o;
MapNode p;
for (size_t i = 0; i < numMatsPerZone.size(); ++i)
{
std::string base;
if (names.size() > 1)
{
base = names[i].substr(1, names[i].size() -2);
}
int nMats = numMatsPerZone[i];
for (int j = 0; j < numMatsPerZone[i]; ++j)
{
int nSpecs = numSpecsPerMat[j+matOffset];
for (int k = 0; k < nSpecs; k++)
{
p[mixNames[k+mixOffset]] = mixValues[k+mixOffset];
}
o[matNames[j+matOffset]] = p;
mixOffset += nSpecs;
}
if (!base.empty() && o.GetNumEntries() > 0)
n[base] = o;
matOffset += nMats;
}
if (n.GetNumEntries() > 0)
m[variableName] = n;
else
m[variableName] = o;
}
else
{
MapNode n;
int mixOffset = 0;
for (size_t i = 0; i < names.size(); ++i)
{
std::string stripName = names[i].substr(1, names[i].size() -2);
if (variableType == "scalar")
{
if (centeringsMatch)
{
if (!treatAsASCII)
m[variableName] = values[i];
else
m[variableName] = (char) values[i];
}
else
{
if (!treatAsASCII)
n[stripName] = values[i];
else
n[stripName] = (char) values[i];
}
}
else if (variableType == "vector")
{
doubleVector v;
size_t stride = values.size() / names.size();
for (size_t j = 0; j < stride -1; j++)
v.push_back(values[i*stride+j]);
if (centeringsMatch)
m[variableName] = v;
else
n[stripName] = v;
}
else if (variableType == "tensor")
{
size_t ncomps = (values.size()-names.size())/names.size();
size_t offset = i*(ncomps+1);
doubleVector v;
for (size_t j = 0; j < ncomps; j++)
{
v.push_back(values[offset+ncomps*j]);
v.push_back(values[offset+ncomps*j+1]);
}
v.push_back(values[offset+ncomps*ncomps]);
if (centeringsMatch)
m[variableName] = v;
else
n[stripName] = v;
}
else if (variableType == "symm_tensor")
{
if (centeringsMatch)
m[variableName] = std::string("some symm_tensor info here");
else
n[stripName] = std::string("some symm_tensor info here");
}
else if (variableType == "array")
{
size_t ncomps = (values.size()-names.size())/names.size();
size_t offset = i*(ncomps+1);
doubleVector v;
for (size_t j = 0; j < ncomps; j++)
v.push_back(values[offset+j]);
if (centeringsMatch)
m[variableName] = v;
else
n[stripName] = v;
}
else if (variableType == "label")
{
size_t labelSize = values.size() / names.size();
std::string l;
for (size_t j = labelSize*i; j < labelSize *(i+1); ++j)
l += (char)values[j];
if (centeringsMatch)
m[variableName] = l;
else
n[stripName] = l;
}
}
if (!centeringsMatch && n.GetNumEntries() != 0)
m[variableName] = n;
#if 0
if (mixVar)
{
int nMats = numMatsPerZone[i];
std::string matname;
for (int j = 0; j < nMats; ++j)
{
matname = "material " + mixNames[j+mixOffset];
m[matname] = mixValues[j+mixOffset];
}
mixOffset += nMats;
}
#endif
}
}
}
......@@ -674,3 +674,231 @@ PickVarInfo::PrintArray(std::string &os,
}
}
Function: CreateOutputMapNode
Declaration: void CreateOutputMapNode(const std::string &, MapNode &);
Definition:
// ****************************************************************************
// Method: PickVarInfo::CreateOutputMapNode
//
// Purpose:
// Creates a MapNode object containing all the information gathered
// from a pick.
//
// Programmer: Kathleen Biagas
// Creation: October 24, 2011
//
// Modifications:
//
// ****************************************************************************
void
PickVarInfo::CreateOutputMapNode(const std::string &type, MapNode &m)
{
bool centeringsMatch = false;
switch (centering)
{
case Nodal: if (type == "Node" || type == "DomainNode")
centeringsMatch = true;
break;
case Zonal: if (type == "Zone" || type == "DomainZone")
centeringsMatch = true;
break;