mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Split the DataSetBuilders into h/cxx files.
This commit is contained in:
parent
9cfc9112cd
commit
158f57c9a1
@ -114,6 +114,9 @@ set(sources
|
||||
BoundsGlobalCompute.cxx
|
||||
CellSet.cxx
|
||||
CellSetStructured.cxx
|
||||
DataSetBuilderExplicit.cxx
|
||||
DataSetBuilderRectilinear.cxx
|
||||
DataSetBuilderUniform.cxx
|
||||
DynamicArrayHandle.cxx
|
||||
EnvironmentTracker.cxx
|
||||
Field.cxx
|
||||
|
110
vtkm/cont/DataSetBuilderExplicit.cxx
Normal file
110
vtkm/cont/DataSetBuilderExplicit.cxx
Normal file
@ -0,0 +1,110 @@
|
||||
//============================================================================
|
||||
// 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/DataSetBuilderExplicit.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
VTKM_CONT
|
||||
DataSetBuilderExplicitIterative::DataSetBuilderExplicitIterative()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
VTKM_CONT
|
||||
void DataSetBuilderExplicitIterative::Begin(const std::string& coordName,
|
||||
const std::string& cellName)
|
||||
{
|
||||
this->coordNm = coordName;
|
||||
this->cellNm = cellName;
|
||||
this->points.resize(0);
|
||||
this->shapes.resize(0);
|
||||
this->numIdx.resize(0);
|
||||
this->connectivity.resize(0);
|
||||
}
|
||||
|
||||
//Define points.
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DataSetBuilderExplicitIterative::Create()
|
||||
{
|
||||
DataSetBuilderExplicit dsb;
|
||||
return dsb.Create(points, shapes, numIdx, connectivity, coordNm, cellNm);
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
vtkm::Id DataSetBuilderExplicitIterative::AddPoint(const vtkm::Vec<vtkm::Float32, 3>& pt)
|
||||
{
|
||||
points.push_back(pt);
|
||||
vtkm::Id id = static_cast<vtkm::Id>(points.size());
|
||||
return id;
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
vtkm::Id DataSetBuilderExplicitIterative::AddPoint(const vtkm::Float32& x,
|
||||
const vtkm::Float32& y,
|
||||
const vtkm::Float32& z)
|
||||
{
|
||||
points.push_back(vtkm::make_Vec(x, y, z));
|
||||
vtkm::Id id = static_cast<vtkm::Id>(points.size());
|
||||
return id;
|
||||
}
|
||||
|
||||
//Define cells.
|
||||
VTKM_CONT
|
||||
void DataSetBuilderExplicitIterative::AddCell(vtkm::UInt8 shape)
|
||||
{
|
||||
this->shapes.push_back(shape);
|
||||
this->numIdx.push_back(0);
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
void DataSetBuilderExplicitIterative::AddCell(const vtkm::UInt8& shape,
|
||||
const std::vector<vtkm::Id>& conn)
|
||||
{
|
||||
this->shapes.push_back(shape);
|
||||
this->numIdx.push_back(static_cast<vtkm::IdComponent>(conn.size()));
|
||||
connectivity.insert(connectivity.end(), conn.begin(), conn.end());
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
void DataSetBuilderExplicitIterative::AddCell(const vtkm::UInt8& shape,
|
||||
const vtkm::Id* conn,
|
||||
const vtkm::IdComponent& n)
|
||||
{
|
||||
this->shapes.push_back(shape);
|
||||
this->numIdx.push_back(n);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
connectivity.push_back(conn[i]);
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
void DataSetBuilderExplicitIterative::AddCellPoint(vtkm::Id pointIndex)
|
||||
{
|
||||
VTKM_ASSERT(this->numIdx.size() > 0);
|
||||
this->connectivity.push_back(pointIndex);
|
||||
this->numIdx.back() += 1;
|
||||
}
|
||||
}
|
||||
} // end namespace vtkm::cont
|
@ -33,7 +33,7 @@ namespace cont
|
||||
//Coordinates builder??
|
||||
//Need a singlecellset handler.
|
||||
|
||||
class DataSetBuilderExplicit
|
||||
class VTKM_CONT_EXPORT DataSetBuilderExplicit
|
||||
{
|
||||
template <typename T>
|
||||
VTKM_CONT static void CopyInto(const std::vector<T>& input, vtkm::cont::ArrayHandle<T>& output)
|
||||
@ -317,38 +317,20 @@ class DataSetBuilderExplicitIterative
|
||||
{
|
||||
public:
|
||||
VTKM_CONT
|
||||
DataSetBuilderExplicitIterative() {}
|
||||
DataSetBuilderExplicitIterative();
|
||||
|
||||
VTKM_CONT
|
||||
void Begin(const std::string& coordName = "coords", const std::string& cellName = "cells")
|
||||
{
|
||||
this->coordNm = coordName;
|
||||
this->cellNm = cellName;
|
||||
this->points.resize(0);
|
||||
this->shapes.resize(0);
|
||||
this->numIdx.resize(0);
|
||||
this->connectivity.resize(0);
|
||||
}
|
||||
void Begin(const std::string& coordName = "coords", const std::string& cellName = "cells");
|
||||
|
||||
//Define points.
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet Create();
|
||||
|
||||
VTKM_CONT
|
||||
vtkm::Id AddPoint(const vtkm::Vec<vtkm::Float32, 3>& pt)
|
||||
{
|
||||
points.push_back(pt);
|
||||
vtkm::Id id = static_cast<vtkm::Id>(points.size());
|
||||
return id;
|
||||
}
|
||||
vtkm::Id AddPoint(const vtkm::Vec<vtkm::Float32, 3>& pt);
|
||||
|
||||
VTKM_CONT
|
||||
vtkm::Id AddPoint(const vtkm::Float32& x, const vtkm::Float32& y, const vtkm::Float32& z = 0)
|
||||
{
|
||||
points.push_back(vtkm::make_Vec(x, y, z));
|
||||
vtkm::Id id = static_cast<vtkm::Id>(points.size());
|
||||
return id;
|
||||
}
|
||||
vtkm::Id AddPoint(const vtkm::Float32& x, const vtkm::Float32& y, const vtkm::Float32& z = 0);
|
||||
|
||||
template <typename T>
|
||||
VTKM_CONT vtkm::Id AddPoint(const T& x, const T& y, const T& z = 0)
|
||||
@ -365,38 +347,16 @@ public:
|
||||
|
||||
//Define cells.
|
||||
VTKM_CONT
|
||||
void AddCell(vtkm::UInt8 shape)
|
||||
{
|
||||
this->shapes.push_back(shape);
|
||||
this->numIdx.push_back(0);
|
||||
}
|
||||
void AddCell(vtkm::UInt8 shape);
|
||||
|
||||
VTKM_CONT
|
||||
void AddCell(const vtkm::UInt8& shape, const std::vector<vtkm::Id>& conn)
|
||||
{
|
||||
this->shapes.push_back(shape);
|
||||
this->numIdx.push_back(static_cast<vtkm::IdComponent>(conn.size()));
|
||||
connectivity.insert(connectivity.end(), conn.begin(), conn.end());
|
||||
}
|
||||
void AddCell(const vtkm::UInt8& shape, const std::vector<vtkm::Id>& conn);
|
||||
|
||||
VTKM_CONT
|
||||
void AddCell(const vtkm::UInt8& shape, const vtkm::Id* conn, const vtkm::IdComponent& n)
|
||||
{
|
||||
this->shapes.push_back(shape);
|
||||
this->numIdx.push_back(n);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
connectivity.push_back(conn[i]);
|
||||
}
|
||||
}
|
||||
void AddCell(const vtkm::UInt8& shape, const vtkm::Id* conn, const vtkm::IdComponent& n);
|
||||
|
||||
VTKM_CONT
|
||||
void AddCellPoint(vtkm::Id pointIndex)
|
||||
{
|
||||
VTKM_ASSERT(this->numIdx.size() > 0);
|
||||
this->connectivity.push_back(pointIndex);
|
||||
this->numIdx.back() += 1;
|
||||
}
|
||||
void AddCellPoint(vtkm::Id pointIndex);
|
||||
|
||||
private:
|
||||
std::string coordNm, cellNm;
|
||||
@ -406,12 +366,6 @@ private:
|
||||
std::vector<vtkm::IdComponent> numIdx;
|
||||
std::vector<vtkm::Id> connectivity;
|
||||
};
|
||||
|
||||
inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicitIterative::Create()
|
||||
{
|
||||
DataSetBuilderExplicit dsb;
|
||||
return dsb.Create(points, shapes, numIdx, connectivity, coordNm, cellNm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
33
vtkm/cont/DataSetBuilderRectilinear.cxx
Normal file
33
vtkm/cont/DataSetBuilderRectilinear.cxx
Normal file
@ -0,0 +1,33 @@
|
||||
//============================================================================
|
||||
// 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/DataSetBuilderRectilinear.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
VTKM_CONT
|
||||
DataSetBuilderRectilinear::DataSetBuilderRectilinear()
|
||||
{
|
||||
}
|
||||
}
|
||||
} // end namespace vtkm::cont
|
@ -31,7 +31,7 @@ namespace vtkm
|
||||
namespace cont
|
||||
{
|
||||
|
||||
class DataSetBuilderRectilinear
|
||||
class VTKM_CONT_EXPORT DataSetBuilderRectilinear
|
||||
{
|
||||
template <typename T, typename U>
|
||||
VTKM_CONT static void CopyInto(const std::vector<T>& input, vtkm::cont::ArrayHandle<U>& output)
|
||||
@ -55,7 +55,7 @@ class DataSetBuilderRectilinear
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
DataSetBuilderRectilinear() {}
|
||||
DataSetBuilderRectilinear();
|
||||
|
||||
//1D grids.
|
||||
template <typename T>
|
||||
|
115
vtkm/cont/DataSetBuilderUniform.cxx
Normal file
115
vtkm/cont/DataSetBuilderUniform.cxx
Normal file
@ -0,0 +1,115 @@
|
||||
//============================================================================
|
||||
// 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/DataSetBuilderUniform.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
VTKM_CONT
|
||||
DataSetBuilderUniform::DataSetBuilderUniform()
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DataSetBuilderUniform::Create(const vtkm::Id& dimension,
|
||||
std::string coordNm,
|
||||
std::string cellNm)
|
||||
{
|
||||
return CreateDataSet(vtkm::Id3(dimension, 1, 1), VecType(0), VecType(1), coordNm, cellNm);
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DataSetBuilderUniform::Create(const vtkm::Id2& dimensions,
|
||||
std::string coordNm,
|
||||
std::string cellNm)
|
||||
{
|
||||
return CreateDataSet(
|
||||
vtkm::Id3(dimensions[0], dimensions[1], 1), VecType(0), VecType(1), coordNm, cellNm);
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DataSetBuilderUniform::Create(const vtkm::Id3& dimensions,
|
||||
std::string coordNm,
|
||||
std::string cellNm)
|
||||
{
|
||||
return CreateDataSet(vtkm::Id3(dimensions[0], dimensions[1], dimensions[2]),
|
||||
VecType(0),
|
||||
VecType(1),
|
||||
coordNm,
|
||||
cellNm);
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DataSetBuilderUniform::CreateDataSet(
|
||||
const vtkm::Id3& dimensions,
|
||||
const vtkm::Vec<vtkm::FloatDefault, 3>& origin,
|
||||
const vtkm::Vec<vtkm::FloatDefault, 3>& spacing,
|
||||
std::string coordNm,
|
||||
std::string cellNm)
|
||||
{
|
||||
vtkm::Id dims[3] = { 1, 1, 1 };
|
||||
int ndims = 0;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (dimensions[i] > 1)
|
||||
{
|
||||
if (spacing[i] <= 0.0f)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("spacing must be > 0.0");
|
||||
}
|
||||
dims[ndims++] = dimensions[i];
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::cont::DataSet dataSet;
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates coords(dimensions, origin, spacing);
|
||||
vtkm::cont::CoordinateSystem cs(coordNm, coords);
|
||||
dataSet.AddCoordinateSystem(cs);
|
||||
|
||||
if (ndims == 1)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<1> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(dims[0]);
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else if (ndims == 2)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<2> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(vtkm::Id2(dims[0], dims[1]));
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else if (ndims == 3)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<3> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(vtkm::Id3(dims[0], dims[1], dims[2]));
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Invalid cell set dimension");
|
||||
}
|
||||
|
||||
return dataSet;
|
||||
}
|
||||
}
|
||||
} // end namespace vtkm::cont
|
@ -28,13 +28,13 @@ namespace vtkm
|
||||
namespace cont
|
||||
{
|
||||
|
||||
class DataSetBuilderUniform
|
||||
class VTKM_CONT_EXPORT DataSetBuilderUniform
|
||||
{
|
||||
using VecType = vtkm::Vec<vtkm::FloatDefault, 3>;
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
DataSetBuilderUniform() {}
|
||||
DataSetBuilderUniform();
|
||||
|
||||
//1D uniform grid
|
||||
template <typename T>
|
||||
@ -55,10 +55,7 @@ public:
|
||||
VTKM_CONT
|
||||
static vtkm::cont::DataSet Create(const vtkm::Id& dimension,
|
||||
std::string coordNm = "coords",
|
||||
std::string cellNm = "cells")
|
||||
{
|
||||
return CreateDataSet(vtkm::Id3(dimension, 1, 1), VecType(0), VecType(1), coordNm, cellNm);
|
||||
}
|
||||
std::string cellNm = "cells");
|
||||
|
||||
//2D uniform grids.
|
||||
template <typename T>
|
||||
@ -82,11 +79,7 @@ public:
|
||||
VTKM_CONT
|
||||
static vtkm::cont::DataSet Create(const vtkm::Id2& dimensions,
|
||||
std::string coordNm = "coords",
|
||||
std::string cellNm = "cells")
|
||||
{
|
||||
return CreateDataSet(
|
||||
vtkm::Id3(dimensions[0], dimensions[1], 1), VecType(0), VecType(1), coordNm, cellNm);
|
||||
}
|
||||
std::string cellNm = "cells");
|
||||
|
||||
//3D uniform grids.
|
||||
template <typename T>
|
||||
@ -111,14 +104,7 @@ public:
|
||||
VTKM_CONT
|
||||
static vtkm::cont::DataSet Create(const vtkm::Id3& dimensions,
|
||||
std::string coordNm = "coords",
|
||||
std::string cellNm = "cells")
|
||||
{
|
||||
return CreateDataSet(vtkm::Id3(dimensions[0], dimensions[1], dimensions[2]),
|
||||
VecType(0),
|
||||
VecType(1),
|
||||
coordNm,
|
||||
cellNm);
|
||||
}
|
||||
std::string cellNm = "cells");
|
||||
|
||||
private:
|
||||
VTKM_CONT
|
||||
@ -126,52 +112,7 @@ private:
|
||||
const vtkm::Vec<vtkm::FloatDefault, 3>& origin,
|
||||
const vtkm::Vec<vtkm::FloatDefault, 3>& spacing,
|
||||
std::string coordNm,
|
||||
std::string cellNm)
|
||||
{
|
||||
vtkm::Id dims[3] = { 1, 1, 1 };
|
||||
int ndims = 0;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (dimensions[i] > 1)
|
||||
{
|
||||
if (spacing[i] <= 0.0f)
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("spacing must be > 0.0");
|
||||
}
|
||||
dims[ndims++] = dimensions[i];
|
||||
}
|
||||
}
|
||||
|
||||
vtkm::cont::DataSet dataSet;
|
||||
vtkm::cont::ArrayHandleUniformPointCoordinates coords(dimensions, origin, spacing);
|
||||
vtkm::cont::CoordinateSystem cs(coordNm, coords);
|
||||
dataSet.AddCoordinateSystem(cs);
|
||||
|
||||
if (ndims == 1)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<1> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(dims[0]);
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else if (ndims == 2)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<2> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(vtkm::Id2(dims[0], dims[1]));
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else if (ndims == 3)
|
||||
{
|
||||
vtkm::cont::CellSetStructured<3> cellSet(cellNm);
|
||||
cellSet.SetPointDimensions(vtkm::Id3(dims[0], dims[1], dims[2]));
|
||||
dataSet.AddCellSet(cellSet);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Invalid cell set dimension");
|
||||
}
|
||||
|
||||
return dataSet;
|
||||
}
|
||||
std::string cellNm);
|
||||
};
|
||||
|
||||
} // namespace cont
|
||||
|
Loading…
Reference in New Issue
Block a user