2015-09-24 12:39:27 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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 Sandia Corporation.
|
|
|
|
// Copyright 2015 UT-Battelle, LLC.
|
|
|
|
// Copyright 2015 Los Alamos National Security.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_cont_CellSetSingleType_h
|
|
|
|
#define vtk_m_cont_CellSetSingleType_h
|
|
|
|
|
|
|
|
#include <vtkm/CellShape.h>
|
|
|
|
#include <vtkm/CellTraits.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleConstant.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
|
|
|
#include <vtkm/cont/CellSet.h>
|
|
|
|
#include <vtkm/cont/CellSetExplicit.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace cont {
|
|
|
|
|
|
|
|
|
|
|
|
//Only works with fixed sized cell sets
|
|
|
|
|
|
|
|
template< typename ConnectivityStorageTag = VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG >
|
|
|
|
class CellSetSingleType :
|
|
|
|
public vtkm::cont::CellSetExplicit<
|
|
|
|
typename vtkm::cont::ArrayHandleConstant<vtkm::UInt8>::StorageTag, //ShapeStorageTag
|
|
|
|
typename vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>::StorageTag, //NumIndicesStorageTag
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
typename vtkm::cont::ArrayHandleCounting<vtkm::Id>::StorageTag //IndexOffsetStorageTag
|
|
|
|
>
|
|
|
|
{
|
2015-10-21 22:27:09 +00:00
|
|
|
typedef vtkm::cont::CellSetSingleType<ConnectivityStorageTag> Thisclass;
|
2015-09-24 12:39:27 +00:00
|
|
|
typedef vtkm::cont::CellSetExplicit<
|
|
|
|
typename vtkm::cont::ArrayHandleConstant<vtkm::UInt8>::StorageTag,
|
|
|
|
typename vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>::StorageTag,
|
|
|
|
ConnectivityStorageTag,
|
|
|
|
typename vtkm::cont::ArrayHandleCounting<vtkm::Id>::StorageTag > Superclass;
|
|
|
|
|
|
|
|
public:
|
2016-10-20 12:27:52 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-09-24 12:39:27 +00:00
|
|
|
CellSetSingleType(const std::string &name = std::string())
|
2016-12-20 23:14:50 +00:00
|
|
|
: Superclass(name),
|
|
|
|
ExpectedNumberOfCellsAdded(-1),
|
|
|
|
CellShapeAsId(CellShapeTagEmpty::Id),
|
|
|
|
NumberOfPointsPerCell(0)
|
2015-09-24 12:39:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-10-21 22:27:09 +00:00
|
|
|
CellSetSingleType(const Thisclass &src)
|
2016-12-20 23:14:50 +00:00
|
|
|
: Superclass(src),
|
|
|
|
ExpectedNumberOfCellsAdded(-1),
|
|
|
|
CellShapeAsId(src.CellShapeAsId),
|
|
|
|
NumberOfPointsPerCell(src.NumberOfPointsPerCell)
|
2015-10-21 22:27:09 +00:00
|
|
|
{ }
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-10-21 22:27:09 +00:00
|
|
|
Thisclass &operator=(const Thisclass &src)
|
|
|
|
{
|
|
|
|
this->Superclass::operator=(src);
|
2016-12-20 23:14:50 +00:00
|
|
|
this->CellShapeAsId = src.CellShapeAsId;
|
|
|
|
this->NumberOfPointsPerCell = src.NumberOfPointsPerCell;
|
2015-10-21 22:27:09 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~CellSetSingleType() { }
|
|
|
|
|
2015-09-28 14:26:57 +00:00
|
|
|
/// First method to add cells -- one at a time.
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2016-12-20 23:14:50 +00:00
|
|
|
void PrepareToAddCells(vtkm::Id numCells,
|
|
|
|
vtkm::Id connectivityMaxLen)
|
2015-09-28 14:26:57 +00:00
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
this->CellShapeAsId = vtkm::CELL_SHAPE_EMPTY;
|
2015-09-28 14:26:57 +00:00
|
|
|
|
|
|
|
this->PointToCell.Connectivity.Allocate(connectivityMaxLen);
|
|
|
|
|
2016-12-20 23:14:50 +00:00
|
|
|
this->NumberOfCellsAdded = 0;
|
|
|
|
this->ConnectivityAdded = 0;
|
|
|
|
this->ExpectedNumberOfCellsAdded = numCells;
|
2015-09-28 14:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Second method to add cells -- one at a time.
|
2016-12-20 23:14:50 +00:00
|
|
|
template <typename IdVecType>
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2016-12-20 23:14:50 +00:00
|
|
|
void AddCell(vtkm::UInt8 shapeId,
|
2015-09-28 14:26:57 +00:00
|
|
|
vtkm::IdComponent numVertices,
|
2016-12-20 23:14:50 +00:00
|
|
|
const IdVecType &ids)
|
2015-09-28 14:26:57 +00:00
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
using Traits = vtkm::VecTraits<IdVecType>;
|
|
|
|
VTKM_STATIC_ASSERT_MSG(
|
|
|
|
(std::is_same<typename Traits::ComponentType,vtkm::Id>::value),
|
|
|
|
"CellSetSingleType::AddCell requires vtkm::Id for indices.");
|
|
|
|
|
|
|
|
if (Traits::GetNumberOfComponents(ids) < numVertices)
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue(
|
2016-12-20 23:14:50 +00:00
|
|
|
"Not enough indices given to CellSetSingleType::AddCell.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->ConnectivityAdded+numVertices >
|
|
|
|
this->PointToCell.Connectivity.GetNumberOfValues())
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue(
|
2016-12-20 23:14:50 +00:00
|
|
|
"Connectivity increased passed estimated maximum connectivity.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->CellShapeAsId == vtkm::CELL_SHAPE_EMPTY)
|
|
|
|
{
|
|
|
|
if (shapeId == vtkm::CELL_SHAPE_EMPTY)
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue(
|
2016-12-20 23:14:50 +00:00
|
|
|
"Cannot create cells of type empty.");
|
|
|
|
}
|
|
|
|
this->CellShapeAsId = shapeId;
|
|
|
|
this->CheckNumberOfPointsPerCell(numVertices);
|
|
|
|
this->NumberOfPointsPerCell = numVertices;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (shapeId != this->GetCellShape(0))
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue(
|
2016-12-20 23:14:50 +00:00
|
|
|
"Cannot have differing shapes in CellSetSingleType.");
|
|
|
|
}
|
|
|
|
if (numVertices != this->NumberOfPointsPerCell)
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue(
|
2016-12-20 23:14:50 +00:00
|
|
|
"Inconsistent number of points in cells for CellSetSingleType.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (vtkm::IdComponent iVert=0; iVert < numVertices; ++iVert)
|
2015-09-28 14:26:57 +00:00
|
|
|
{
|
|
|
|
this->PointToCell.Connectivity.GetPortalControl().Set(
|
2016-12-20 23:14:50 +00:00
|
|
|
this->ConnectivityAdded+iVert, Traits::GetComponent(ids,iVert));
|
2015-09-28 14:26:57 +00:00
|
|
|
}
|
2016-12-20 23:14:50 +00:00
|
|
|
this->NumberOfCellsAdded++;
|
|
|
|
this->ConnectivityAdded += numVertices;
|
2015-09-28 14:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Third and final method to add cells -- one at a time.
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2016-12-20 23:14:50 +00:00
|
|
|
void CompleteAddingCells(vtkm::Id numPoints)
|
2015-09-28 14:26:57 +00:00
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
this->NumberOfPoints = numPoints;
|
|
|
|
this->PointToCell.Connectivity.Shrink(this->ConnectivityAdded);
|
|
|
|
|
|
|
|
vtkm::Id numCells = this->NumberOfCellsAdded;
|
|
|
|
|
|
|
|
this->PointToCell.Shapes =
|
|
|
|
vtkm::cont::make_ArrayHandleConstant(this->GetCellShape(0), numCells);
|
|
|
|
this->PointToCell.NumIndices =
|
|
|
|
vtkm::cont::make_ArrayHandleConstant(this->NumberOfPointsPerCell,
|
|
|
|
numCells);
|
|
|
|
this->PointToCell.IndexOffsets =
|
|
|
|
vtkm::cont::make_ArrayHandleCounting(
|
|
|
|
vtkm::Id(0),
|
|
|
|
static_cast<vtkm::Id>(this->NumberOfPointsPerCell),
|
|
|
|
numCells);
|
|
|
|
|
2015-09-28 14:26:57 +00:00
|
|
|
this->PointToCell.ElementsValid = true;
|
|
|
|
this->PointToCell.IndexOffsetsValid = true;
|
2016-12-20 23:14:50 +00:00
|
|
|
|
|
|
|
if (this->ExpectedNumberOfCellsAdded != this->GetNumberOfCells())
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue(
|
2016-12-20 23:14:50 +00:00
|
|
|
"Did not add the expected number of cells.");
|
|
|
|
}
|
|
|
|
|
|
|
|
this->NumberOfCellsAdded = -1;
|
|
|
|
this->ConnectivityAdded = -1;
|
|
|
|
this->ExpectedNumberOfCellsAdded = -1;
|
2015-09-28 14:26:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 12:39:27 +00:00
|
|
|
//This is the way you can fill the memory from another system without copying
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2016-12-20 23:14:50 +00:00
|
|
|
void Fill(vtkm::Id numPoints,
|
|
|
|
vtkm::UInt8 shapeId,
|
|
|
|
vtkm::IdComponent numberOfPointsPerCell,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Id,ConnectivityStorageTag>
|
|
|
|
&connectivity)
|
2015-09-24 12:39:27 +00:00
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
this->NumberOfPoints = numPoints;
|
|
|
|
this->CellShapeAsId = shapeId;
|
|
|
|
this->CheckNumberOfPointsPerCell(numberOfPointsPerCell);
|
|
|
|
const vtkm::Id numCells =
|
|
|
|
connectivity.GetNumberOfValues() / numberOfPointsPerCell;
|
|
|
|
VTKM_ASSERT((connectivity.GetNumberOfValues() % numberOfPointsPerCell) == 0);
|
2015-09-24 12:39:27 +00:00
|
|
|
this->PointToCell.Shapes =
|
2016-12-20 23:14:50 +00:00
|
|
|
vtkm::cont::make_ArrayHandleConstant(shapeId, numCells);
|
2015-09-24 12:39:27 +00:00
|
|
|
this->PointToCell.NumIndices =
|
|
|
|
vtkm::cont::make_ArrayHandleConstant(numberOfPointsPerCell,
|
2016-12-20 23:14:50 +00:00
|
|
|
numCells);
|
2015-09-24 12:39:27 +00:00
|
|
|
this->PointToCell.IndexOffsets =
|
|
|
|
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0),
|
|
|
|
static_cast<vtkm::Id>(numberOfPointsPerCell),
|
2016-12-20 23:14:50 +00:00
|
|
|
numCells );
|
2015-09-24 12:39:27 +00:00
|
|
|
this->PointToCell.Connectivity = connectivity;
|
|
|
|
|
|
|
|
this->PointToCell.ElementsValid = true;
|
|
|
|
this->PointToCell.IndexOffsetsValid = true;
|
|
|
|
}
|
|
|
|
|
2016-11-28 21:07:40 +00:00
|
|
|
VTKM_CONT
|
2016-12-20 23:14:50 +00:00
|
|
|
vtkm::Id GetCellShapeAsId() const
|
|
|
|
{
|
|
|
|
return this->CellShapeAsId;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
vtkm::UInt8 GetCellShape(vtkm::Id vtkmNotUsed(cellIndex)) const
|
2016-11-28 21:07:40 +00:00
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
return static_cast<vtkm::UInt8>(this->CellShapeAsId);
|
2016-11-28 21:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void PrintSummary(std::ostream &out) const
|
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
out << " ExplicitSingleCellSet: " << this->Name << " Type "<<this->CellShapeAsId<<std::endl;
|
2016-11-28 21:07:40 +00:00
|
|
|
out << " PointToCell: " << std::endl;
|
|
|
|
this->PointToCell.PrintSummary(out);
|
|
|
|
out << " CellToPoint: " << std::endl;
|
|
|
|
this->CellToPoint.PrintSummary(out);
|
|
|
|
}
|
|
|
|
|
2015-09-24 12:39:27 +00:00
|
|
|
private:
|
|
|
|
template< typename CellShapeTag>
|
2016-12-20 23:14:50 +00:00
|
|
|
void CheckNumberOfPointsPerCell(CellShapeTag,
|
|
|
|
vtkm::CellTraitsTagSizeFixed,
|
|
|
|
vtkm::IdComponent numVertices) const
|
2015-09-24 12:39:27 +00:00
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
if (numVertices != vtkm::CellTraits<CellShapeTag>::NUM_POINTS)
|
|
|
|
{
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue(
|
2016-12-20 23:14:50 +00:00
|
|
|
"Passed invalid number of points for cell shape.");
|
|
|
|
}
|
2015-09-24 12:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template< typename CellShapeTag>
|
2016-12-20 23:14:50 +00:00
|
|
|
void CheckNumberOfPointsPerCell(CellShapeTag,
|
|
|
|
vtkm::CellTraitsTagSizeVariable,
|
|
|
|
vtkm::IdComponent vtkmNotUsed(numVertices)) const
|
|
|
|
{
|
|
|
|
// Technically, a shape with a variable number of points probably has a
|
|
|
|
// minimum number of points, but we are not being sophisticated enough to
|
|
|
|
// check that. Instead, just pass the check by returning without error.
|
2015-09-24 12:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-20 23:14:50 +00:00
|
|
|
void CheckNumberOfPointsPerCell(vtkm::IdComponent numVertices) const
|
2015-09-24 12:39:27 +00:00
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
switch (this->CellShapeAsId)
|
2015-09-24 12:39:27 +00:00
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
vtkmGenericCellShapeMacro(
|
|
|
|
this->CheckNumberOfPointsPerCell(CellShapeTag(),
|
|
|
|
vtkm::CellTraits<CellShapeTag>::IsSizeFixed(),
|
|
|
|
numVertices) );
|
2015-09-24 12:39:27 +00:00
|
|
|
default:
|
2017-01-09 21:15:32 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue(
|
2015-09-24 12:39:27 +00:00
|
|
|
"CellSetSingleType unable to determine the cell type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-20 23:14:50 +00:00
|
|
|
vtkm::Id ExpectedNumberOfCellsAdded;
|
|
|
|
vtkm::Id CellShapeAsId;
|
|
|
|
vtkm::IdComponent NumberOfPointsPerCell;
|
2015-09-24 12:39:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
|
|
|
#endif //vtk_m_cont_CellSetSingleType_h
|