Merge topic 'compile_in_dataset'

3eb8294b Build vtkm::cont::DataSet into the vtkm_cont library.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Matt Larsen <mlarsen@cs.uoregon.edu>
Merge-request: !1032
This commit is contained in:
Robert Maynard 2017-12-22 13:24:31 +00:00 committed by Kitware Robot
commit de7162ab8f
3 changed files with 187 additions and 127 deletions

@ -98,6 +98,7 @@ set(sources
CellSetExplicit.cxx
CellSetStructured.cxx
CoordinateSystem.cxx
DataSet.cxx
DynamicArrayHandle.cxx
EnvironmentTracker.cxx
Field.cxx

164
vtkm/cont/DataSet.cxx Normal file

@ -0,0 +1,164 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// 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.
//
// Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/DataSet.h>
namespace vtkm
{
namespace cont
{
DataSet::DataSet()
{
}
void DataSet::Clear()
{
this->CoordSystems.clear();
this->Fields.clear();
this->CellSets.clear();
}
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)];
}
vtkm::Id DataSet::GetFieldIndex(const std::string& name,
vtkm::cont::Field::AssociationEnum assoc) const
{
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)];
}
vtkm::Id DataSet::GetCoordinateSystemIndex(const std::string& name) const
{
bool found;
vtkm::Id index = this->FindCoordinateSystemIndex(name, found);
if (found)
{
return index;
}
else
{
throw vtkm::cont::ErrorBadValue("No coordinate system with requested name");
}
}
vtkm::Id DataSet::GetCellSetIndex(const std::string& name) const
{
bool found;
vtkm::Id index = this->FindCellSetIndex(name, found);
if (found)
{
return index;
}
else
{
throw vtkm::cont::ErrorBadValue("No cell set with requested name");
}
}
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);
}
out << " CellSets[" << this->GetNumberOfCellSets() << "]\n";
for (vtkm::Id index = 0; index < this->GetNumberOfCellSets(); index++)
{
this->GetCellSet(index).PrintSummary(out);
}
out << " Fields[" << this->GetNumberOfFields() << "]\n";
for (vtkm::Id index = 0; index < this->GetNumberOfFields(); index++)
{
this->GetField(index).PrintSummary(out);
}
}
vtkm::Id DataSet::FindFieldIndex(const std::string& name,
vtkm::cont::Field::AssociationEnum association,
bool& found) const
{
for (std::size_t index = 0; index < this->Fields.size(); ++index)
{
if ((association == vtkm::cont::Field::ASSOC_ANY ||
association == this->Fields[index].GetAssociation()) &&
this->Fields[index].GetName() == name)
{
found = true;
return static_cast<vtkm::Id>(index);
}
}
found = false;
return -1;
}
vtkm::Id DataSet::FindCoordinateSystemIndex(const std::string& name, bool& found) const
{
for (std::size_t index = 0; index < this->CoordSystems.size(); ++index)
{
if (this->CoordSystems[index].GetName() == name)
{
found = true;
return static_cast<vtkm::Id>(index);
}
}
found = false;
return -1;
}
vtkm::Id DataSet::FindCellSetIndex(const std::string& name, bool& found) const
{
for (std::size_t index = 0; index < static_cast<size_t>(this->GetNumberOfCellSets()); ++index)
{
if (this->CellSets[index].GetName() == name)
{
found = true;
return static_cast<vtkm::Id>(index);
}
}
found = false;
return -1;
}
} // namespace cont
} // namespace vtkm

@ -20,6 +20,8 @@
#ifndef vtk_m_cont_DataSet_h
#define vtk_m_cont_DataSet_h
#include <vtkm/cont/vtkm_cont_export.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
@ -33,29 +35,17 @@ namespace vtkm
namespace cont
{
class DataSet
class VTKM_CONT_EXPORT DataSet
{
public:
VTKM_CONT
DataSet() {}
VTKM_CONT DataSet();
VTKM_CONT void Clear();
VTKM_CONT void AddField(const Field& field) { this->Fields.push_back(field); }
VTKM_CONT
void Clear()
{
this->CoordSystems.clear();
this->Fields.clear();
this->CellSets.clear();
}
VTKM_CONT
void AddField(Field field) { this->Fields.push_back(field); }
VTKM_CONT
const vtkm::cont::Field& GetField(vtkm::Id index) const
{
VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfFields()));
return this->Fields[static_cast<std::size_t>(index)];
}
const vtkm::cont::Field& GetField(vtkm::Id index) const;
VTKM_CONT
bool HasField(const std::string& name,
@ -69,19 +59,7 @@ public:
VTKM_CONT
vtkm::Id GetFieldIndex(
const std::string& name,
vtkm::cont::Field::AssociationEnum assoc = vtkm::cont::Field::ASSOC_ANY) const
{
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);
}
}
vtkm::cont::Field::AssociationEnum assoc = vtkm::cont::Field::ASSOC_ANY) const;
VTKM_CONT
const vtkm::cont::Field& GetField(
@ -104,14 +82,13 @@ public:
}
VTKM_CONT
void AddCoordinateSystem(vtkm::cont::CoordinateSystem cs) { this->CoordSystems.push_back(cs); }
void AddCoordinateSystem(const vtkm::cont::CoordinateSystem& cs)
{
this->CoordSystems.push_back(cs);
}
VTKM_CONT
const vtkm::cont::CoordinateSystem& GetCoordinateSystem(vtkm::Id index = 0) const
{
VTKM_ASSERT((index >= 0) && (index < this->GetNumberOfCoordinateSystems()));
return this->CoordSystems[static_cast<std::size_t>(index)];
}
const vtkm::cont::CoordinateSystem& GetCoordinateSystem(vtkm::Id index = 0) const;
VTKM_CONT
bool HasCoordinateSystem(const std::string& name) const
@ -122,19 +99,7 @@ public:
}
VTKM_CONT
vtkm::Id GetCoordinateSystemIndex(const std::string& name) const
{
bool found;
vtkm::Id index = this->FindCoordinateSystemIndex(name, found);
if (found)
{
return index;
}
else
{
throw vtkm::cont::ErrorBadValue("No coordinate system with requested name");
}
}
vtkm::Id GetCoordinateSystemIndex(const std::string& name) const;
VTKM_CONT
const vtkm::cont::CoordinateSystem& GetCoordinateSystem(const std::string& name) const
@ -143,7 +108,7 @@ public:
}
VTKM_CONT
void AddCellSet(vtkm::cont::DynamicCellSet cellSet) { this->CellSets.push_back(cellSet); }
void AddCellSet(const vtkm::cont::DynamicCellSet& cellSet) { this->CellSets.push_back(cellSet); }
template <typename CellSetType>
VTKM_CONT void AddCellSet(const CellSetType& cellSet)
@ -168,19 +133,7 @@ public:
}
VTKM_CONT
vtkm::Id GetCellSetIndex(const std::string& name) const
{
bool found;
vtkm::Id index = this->FindCellSetIndex(name, found);
if (found)
{
return index;
}
else
{
throw vtkm::cont::ErrorBadValue("No cell set with requested name");
}
}
vtkm::Id GetCellSetIndex(const std::string& name) const;
VTKM_CONT
vtkm::cont::DynamicCellSet GetCellSet(const std::string& name) const
@ -207,27 +160,7 @@ public:
}
VTKM_CONT
void 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);
}
out << " CellSets[" << this->GetNumberOfCellSets() << "]\n";
for (vtkm::Id index = 0; index < this->GetNumberOfCellSets(); index++)
{
this->GetCellSet(index).PrintSummary(out);
}
out << " Fields[" << this->GetNumberOfFields() << "]\n";
for (vtkm::Id index = 0; index < this->GetNumberOfFields(); index++)
{
this->GetField(index).PrintSummary(out);
}
}
void PrintSummary(std::ostream& out) const;
private:
std::vector<vtkm::cont::CoordinateSystem> CoordSystems;
@ -237,51 +170,13 @@ private:
VTKM_CONT
vtkm::Id FindFieldIndex(const std::string& name,
vtkm::cont::Field::AssociationEnum association,
bool& found) const
{
for (std::size_t index = 0; index < this->Fields.size(); ++index)
{
if ((association == vtkm::cont::Field::ASSOC_ANY ||
association == this->Fields[index].GetAssociation()) &&
this->Fields[index].GetName() == name)
{
found = true;
return static_cast<vtkm::Id>(index);
}
}
found = false;
return -1;
}
bool& found) const;
VTKM_CONT
vtkm::Id FindCoordinateSystemIndex(const std::string& name, bool& found) const
{
for (std::size_t index = 0; index < this->CoordSystems.size(); ++index)
{
if (this->CoordSystems[index].GetName() == name)
{
found = true;
return static_cast<vtkm::Id>(index);
}
}
found = false;
return -1;
}
vtkm::Id FindCoordinateSystemIndex(const std::string& name, bool& found) const;
VTKM_CONT
vtkm::Id FindCellSetIndex(const std::string& name, bool& found) const
{
for (std::size_t index = 0; index < static_cast<size_t>(this->GetNumberOfCellSets()); ++index)
{
if (this->CellSets[index].GetName() == name)
{
found = true;
return static_cast<vtkm::Id>(index);
}
}
found = false;
return -1;
}
vtkm::Id FindCellSetIndex(const std::string& name, bool& found) const;
};
} // namespace cont