2017-12-19 20:14:30 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-12-19 20:14:30 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
void DataSet::Clear()
|
|
|
|
{
|
|
|
|
this->CoordSystems.clear();
|
|
|
|
this->Fields.clear();
|
2019-08-13 17:08:54 +00:00
|
|
|
this->CellSet = this->CellSet.NewInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::Id DataSet::GetNumberOfCells() const
|
|
|
|
{
|
|
|
|
return this->CellSet.GetNumberOfCells();
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::Id DataSet::GetNumberOfPoints() const
|
|
|
|
{
|
|
|
|
if (this->CoordSystems.empty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return this->CoordSystems[0].GetNumberOfPoints();
|
2017-12-19 20:14:30 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 16:26:18 +00:00
|
|
|
void DataSet::CopyStructure(const vtkm::cont::DataSet& source)
|
|
|
|
{
|
|
|
|
this->CoordSystems = source.CoordSystems;
|
2019-08-13 17:08:54 +00:00
|
|
|
this->CellSet = source.CellSet;
|
2018-04-20 16:26:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 20:14:30 +00:00
|
|
|
const vtkm::cont::Field& DataSet::GetField(vtkm::Id index) const
|
|
|
|
{
|
|
|
|
VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfFields()));
|
|
|
|
return this->Fields[static_cast<std::size_t>(index)];
|
|
|
|
}
|
|
|
|
|
2019-08-26 19:58:11 +00:00
|
|
|
vtkm::cont::Field& DataSet::GetField(vtkm::Id index)
|
|
|
|
{
|
|
|
|
VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfFields()));
|
|
|
|
return this->Fields[static_cast<std::size_t>(index)];
|
|
|
|
}
|
|
|
|
|
2018-05-18 20:10:15 +00:00
|
|
|
vtkm::Id DataSet::GetFieldIndex(const std::string& name, vtkm::cont::Field::Association assoc) const
|
2017-12-19 20:14:30 +00:00
|
|
|
{
|
|
|
|
bool found;
|
|
|
|
vtkm::Id index = this->FindFieldIndex(name, assoc, found);
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw vtkm::cont::ErrorBadValue("No field with requested name: " + name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const vtkm::cont::CoordinateSystem& DataSet::GetCoordinateSystem(vtkm::Id index) const
|
|
|
|
{
|
|
|
|
VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfCoordinateSystems()));
|
|
|
|
return this->CoordSystems[static_cast<std::size_t>(index)];
|
|
|
|
}
|
|
|
|
|
2019-08-22 20:46:52 +00:00
|
|
|
vtkm::cont::CoordinateSystem& DataSet::GetCoordinateSystem(vtkm::Id index)
|
|
|
|
{
|
|
|
|
VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfCoordinateSystems()));
|
|
|
|
return this->CoordSystems[static_cast<std::size_t>(index)];
|
|
|
|
}
|
|
|
|
|
2017-12-19 20:14:30 +00:00
|
|
|
vtkm::Id DataSet::GetCoordinateSystemIndex(const std::string& name) const
|
|
|
|
{
|
2019-08-19 13:04:53 +00:00
|
|
|
vtkm::Id index = -1;
|
|
|
|
for (auto i = this->CoordSystems.begin(); i != this->CoordSystems.end(); ++i)
|
2017-12-19 20:14:30 +00:00
|
|
|
{
|
2019-08-19 13:04:53 +00:00
|
|
|
if (i->GetName() == name)
|
|
|
|
{
|
|
|
|
index = static_cast<vtkm::Id>(std::distance(this->CoordSystems.begin(), i));
|
|
|
|
break;
|
|
|
|
}
|
2017-12-19 20:14:30 +00:00
|
|
|
}
|
2019-08-19 13:04:53 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
const vtkm::cont::CoordinateSystem& DataSet::GetCoordinateSystem(const std::string& name) const
|
|
|
|
{
|
|
|
|
vtkm::Id index = this->GetCoordinateSystemIndex(name);
|
|
|
|
if (index < 0)
|
2017-12-19 20:14:30 +00:00
|
|
|
{
|
2019-08-19 13:04:53 +00:00
|
|
|
std::string error_message("No coordinate system with the name " + name +
|
|
|
|
" valid names are: \n");
|
|
|
|
for (const auto& cs : this->CoordSystems)
|
|
|
|
{
|
|
|
|
error_message += cs.GetName() + "\n";
|
|
|
|
}
|
|
|
|
throw vtkm::cont::ErrorBadValue(error_message);
|
2017-12-19 20:14:30 +00:00
|
|
|
}
|
2019-08-19 13:04:53 +00:00
|
|
|
return this->GetCoordinateSystem(index);
|
|
|
|
}
|
|
|
|
|
2019-08-22 20:46:52 +00:00
|
|
|
vtkm::cont::CoordinateSystem& DataSet::GetCoordinateSystem(const std::string& name)
|
|
|
|
{
|
|
|
|
vtkm::Id index = this->GetCoordinateSystemIndex(name);
|
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
std::string error_message("No coordinate system with the name " + name +
|
|
|
|
" valid names are: \n");
|
|
|
|
for (const auto& cs : this->CoordSystems)
|
|
|
|
{
|
|
|
|
error_message += cs.GetName() + "\n";
|
|
|
|
}
|
|
|
|
throw vtkm::cont::ErrorBadValue(error_message);
|
|
|
|
}
|
|
|
|
return this->GetCoordinateSystem(index);
|
|
|
|
}
|
|
|
|
|
2017-12-19 20:14:30 +00:00
|
|
|
void DataSet::PrintSummary(std::ostream& out) const
|
|
|
|
{
|
|
|
|
out << "DataSet:\n";
|
|
|
|
out << " CoordSystems[" << this->CoordSystems.size() << "]\n";
|
|
|
|
for (std::size_t index = 0; index < this->CoordSystems.size(); index++)
|
|
|
|
{
|
|
|
|
this->CoordSystems[index].PrintSummary(out);
|
|
|
|
}
|
|
|
|
|
2019-08-13 17:08:54 +00:00
|
|
|
out << " CellSet \n";
|
|
|
|
this->GetCellSet().PrintSummary(out);
|
2017-12-19 20:14:30 +00:00
|
|
|
|
|
|
|
out << " Fields[" << this->GetNumberOfFields() << "]\n";
|
|
|
|
for (vtkm::Id index = 0; index < this->GetNumberOfFields(); index++)
|
|
|
|
{
|
|
|
|
this->GetField(index).PrintSummary(out);
|
|
|
|
}
|
2019-08-22 18:35:08 +00:00
|
|
|
|
|
|
|
out.flush();
|
2017-12-19 20:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::Id DataSet::FindFieldIndex(const std::string& name,
|
2018-05-18 20:10:15 +00:00
|
|
|
vtkm::cont::Field::Association association,
|
2017-12-19 20:14:30 +00:00
|
|
|
bool& found) const
|
|
|
|
{
|
|
|
|
for (std::size_t index = 0; index < this->Fields.size(); ++index)
|
|
|
|
{
|
2018-05-18 20:10:15 +00:00
|
|
|
if ((association == vtkm::cont::Field::Association::ANY ||
|
2017-12-19 20:14:30 +00:00
|
|
|
association == this->Fields[index].GetAssociation()) &&
|
|
|
|
this->Fields[index].GetName() == name)
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
return static_cast<vtkm::Id>(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
found = false;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cont
|
|
|
|
} // namespace vtkm
|