Commit 67aacfe6 authored by Jeff Baumes's avatar Jeff Baumes
Browse files

ENH: Some cleanup of vtkSelection/vtkTable

 - Added Dump() method to vtkSelection much like that in vtkTable.

 - I reversed the call structure of vtkTable's Set/GetValue methods,
   so that it is now possible to set/get values in columns with no
   name assigned to them.
parent 3ce00db1
......@@ -38,7 +38,7 @@ struct vtkSelectionInternals
};
//----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkSelection, "1.29");
vtkCxxRevisionMacro(vtkSelection, "1.30");
vtkStandardNewMacro(vtkSelection);
//----------------------------------------------------------------------------
......@@ -253,3 +253,84 @@ vtkSelection* vtkSelection::GetData(vtkInformationVector* v, int i)
{
return vtkSelection::GetData(v->GetInformationObject(i));
}
//----------------------------------------------------------------------------
void vtkSelection::Dump()
{
this->Dump(cout);
}
//----------------------------------------------------------------------------
void vtkSelection::Dump(ostream& os)
{
vtkSmartPointer<vtkTable> tmpTable = vtkSmartPointer<vtkTable>::New();
cerr << "==Selection==" << endl;
for (unsigned int i = 0; i < this->GetNumberOfNodes(); ++i)
{
os << "===Node " << i << "===" << endl;
vtkSelectionNode* node = this->GetNode(i);
os << "ContentType: ";
switch (node->GetContentType())
{
case vtkSelectionNode::GLOBALIDS:
os << "GLOBALIDS";
break;
case vtkSelectionNode::PEDIGREEIDS:
os << "PEDIGREEIDS";
break;
case vtkSelectionNode::VALUES:
os << "VALUES";
break;
case vtkSelectionNode::INDICES:
os << "INDICES";
break;
case vtkSelectionNode::FRUSTUM:
os << "FRUSTUM";
break;
case vtkSelectionNode::LOCATIONS:
os << "LOCATIONS";
break;
case vtkSelectionNode::THRESHOLDS:
os << "THRESHOLDS";
break;
case vtkSelectionNode::BLOCKS:
os << "BLOCKS";
break;
default:
os << "UNKNOWN";
break;
}
os << endl;
os << "FieldType: ";
switch (node->GetFieldType())
{
case vtkSelectionNode::CELL:
os << "CELL";
break;
case vtkSelectionNode::POINT:
os << "POINT";
break;
case vtkSelectionNode::FIELD:
os << "FIELD";
break;
case vtkSelectionNode::VERTEX:
os << "VERTEX";
break;
case vtkSelectionNode::EDGE:
os << "EDGE";
break;
case vtkSelectionNode::ROW:
os << "ROW";
break;
default:
os << "UNKNOWN";
break;
}
os << endl;
if (node->GetSelectionData())
{
tmpTable->SetRowData(node->GetSelectionData());
tmpTable->Dump(10);
}
}
}
......@@ -93,6 +93,13 @@ public:
// Return the MTime taking into account changes to the properties
unsigned long GetMTime();
// Description:
// Dumps the contents of the selection, giving basic information only.
virtual void Dump();
//BTX
virtual void Dump(ostream& os);
//ETX
// Description:
// Retrieve a vtkSelection stored inside an invormation object.
static vtkSelection* GetData(vtkInformation* info);
......
......@@ -35,7 +35,7 @@
// Standard functions
//
vtkCxxRevisionMacro(vtkTable, "1.28");
vtkCxxRevisionMacro(vtkTable, "1.29");
vtkStandardNewMacro(vtkTable);
vtkCxxSetObjectMacro(vtkTable, RowData, vtkDataSetAttributes);
......@@ -102,7 +102,8 @@ void vtkTable::Dump( unsigned int colWidth )
for ( int c = 0; c < this->GetNumberOfColumns(); ++ c )
{
cout << "| ";
vtkStdString str = this->GetColumnName( c );
const char* name = this->GetColumnName( c );
vtkStdString str = name ? name : "";
if ( colWidth < str.length() )
{
......@@ -382,17 +383,9 @@ vtkAbstractArray* vtkTable::GetColumn(vtkIdType col)
//----------------------------------------------------------------------------
void vtkTable::SetValue(vtkIdType row, vtkIdType col, vtkVariant value)
{
int column = static_cast<int>(col);
this->SetValueByName(row, this->GetColumnName(column), value);
}
//----------------------------------------------------------------------------
void vtkTable::SetValueByName(vtkIdType row, const char* col, vtkVariant value)
{
vtkAbstractArray* arr = this->GetColumnByName(col);
vtkAbstractArray* arr = this->GetColumn(col);
if (!arr)
{
vtkErrorMacro(<< "Could not find column named " << col);
return;
}
int comps = arr->GetNumberOfComponents();
......@@ -486,10 +479,16 @@ void vtkTable::SetValueByName(vtkIdType row, const char* col, vtkVariant value)
}
//----------------------------------------------------------------------------
vtkVariant vtkTable::GetValue(vtkIdType row, vtkIdType col)
void vtkTable::SetValueByName(vtkIdType row, const char* col, vtkVariant value)
{
int column = static_cast<int>(col);
return this->GetValueByName(row, this->GetColumnName(column));
int colIndex = -1;
this->RowData->GetAbstractArray(col, colIndex);
if (colIndex < 0)
{
vtkErrorMacro(<< "Could not find column named " << col);
return;
}
this->SetValue(row, colIndex, value);
}
//----------------------------------------------------------------------------
......@@ -500,9 +499,9 @@ vtkVariant vtkTableGetVariantValue(iterT* it, vtkIdType row)
}
//----------------------------------------------------------------------------
vtkVariant vtkTable::GetValueByName(vtkIdType row, const char* col)
vtkVariant vtkTable::GetValue(vtkIdType row, vtkIdType col)
{
vtkAbstractArray* arr = this->GetColumnByName(col);
vtkAbstractArray* arr = this->GetColumn(col);
if (!arr)
{
return vtkVariant();
......@@ -592,6 +591,18 @@ vtkVariant vtkTable::GetValueByName(vtkIdType row, const char* col)
return vtkVariant();
}
//----------------------------------------------------------------------------
vtkVariant vtkTable::GetValueByName(vtkIdType row, const char* col)
{
int colIndex = -1;
this->RowData->GetAbstractArray(col, colIndex);
if (colIndex < 0)
{
return vtkVariant();
}
return this->GetValue(row, colIndex);
}
//----------------------------------------------------------------------------
vtkTable* vtkTable::GetData(vtkInformation* info)
{
......
Supports Markdown
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