vtk-m/vtkm/rendering/raytracing/MeshConnectivityContainers.cxx

174 lines
5.5 KiB
C++
Raw Normal View History

2018-09-11 02:51:45 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
2018-09-11 02:51:45 +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 <sstream>
#include <vtkm/CellShape.h>
#include <vtkm/cont/ErrorBadValue.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/cont/internal/DeviceAdapterListHelpers.h>
#include <vtkm/rendering/raytracing/BoundingVolumeHierarchy.h>
#include <vtkm/rendering/raytracing/Logger.h>
#include <vtkm/rendering/raytracing/MeshConnectivity.h>
2018-09-11 02:51:45 +00:00
#include <vtkm/rendering/raytracing/MeshConnectivityContainers.h>
#include <vtkm/rendering/raytracing/Ray.h>
#include <vtkm/rendering/raytracing/TriangleIntersector.h>
namespace vtkm
{
namespace rendering
{
namespace raytracing
{
MeshConnectivityContainer::MeshConnectivityContainer(){};
MeshConnectivityContainer::~MeshConnectivityContainer(){};
2018-09-11 02:51:45 +00:00
template <typename T>
VTKM_CONT void MeshConnectivityContainer::FindEntryImpl(Ray<T>& rays)
2018-09-11 02:51:45 +00:00
{
bool getCellIndex = true;
Intersector.SetUseWaterTight(true);
2018-10-30 14:46:42 +00:00
Intersector.IntersectRays(rays, getCellIndex);
}
void MeshConnectivityContainer::FindEntry(Ray<vtkm::Float32>& rays)
2018-09-11 02:51:45 +00:00
{
2018-10-30 14:46:42 +00:00
this->FindEntryImpl(rays);
2018-09-11 02:51:45 +00:00
}
void MeshConnectivityContainer::FindEntry(Ray<vtkm::Float64>& rays)
2018-09-11 02:51:45 +00:00
{
2018-10-30 14:46:42 +00:00
this->FindEntryImpl(rays);
2018-09-11 02:51:45 +00:00
}
VTKM_CONT
MeshConnectivityContainerUnstructured::MeshConnectivityContainerUnstructured(
const vtkm::cont::CellSetExplicit<>& cellset,
const vtkm::cont::CoordinateSystem& coords,
const IdHandle& faceConn,
const IdHandle& faceOffsets,
const Id4Handle& triangles)
2018-09-11 02:51:45 +00:00
: FaceConnectivity(faceConn)
, FaceOffsets(faceOffsets)
, Cellset(cellset)
, Coords(coords)
{
2018-10-30 14:46:42 +00:00
this->Triangles = triangles;
2018-09-11 02:51:45 +00:00
//
// Grab the cell arrays
//
CellConn =
Cellset.GetConnectivityArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
2018-09-11 02:51:45 +00:00
CellOffsets =
Cellset.GetOffsetsArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
Shapes = Cellset.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
2018-09-11 02:51:45 +00:00
2018-10-30 14:46:42 +00:00
Intersector.SetData(Coords, Triangles);
2018-09-11 02:51:45 +00:00
}
MeshConnectivityContainerUnstructured::~MeshConnectivityContainerUnstructured(){};
2018-09-11 02:51:45 +00:00
MeshConnectivity MeshConnectivityContainerUnstructured::PrepareForExecution(
vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const
2018-09-11 02:51:45 +00:00
{
return MeshConnectivity(this->FaceConnectivity,
this->FaceOffsets,
this->CellConn,
this->CellOffsets,
this->Shapes,
deviceId,
token);
2018-09-11 02:51:45 +00:00
}
VTKM_CONT
MeshConnectivityContainerSingleType::MeshConnectivityContainerSingleType(
2018-09-11 02:51:45 +00:00
const vtkm::cont::CellSetSingleType<>& cellset,
const vtkm::cont::CoordinateSystem& coords,
const IdHandle& faceConn,
const Id4Handle& triangles)
2018-09-11 02:51:45 +00:00
: FaceConnectivity(faceConn)
, Coords(coords)
, Cellset(cellset)
{
2018-10-30 14:46:42 +00:00
this->Triangles = triangles;
2018-09-11 02:51:45 +00:00
this->Intersector.SetUseWaterTight(true);
this->CellConnectivity =
Cellset.GetConnectivityArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
2018-09-11 02:51:45 +00:00
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> shapes =
Cellset.GetShapesArray(vtkm::TopologyElementTagCell(), vtkm::TopologyElementTagPoint());
2018-09-11 02:51:45 +00:00
this->ShapeId = shapes.ReadPortal().Get(0);
2018-09-11 02:51:45 +00:00
CellTables tables;
this->NumIndices = tables.FaceLookUp(tables.CellTypeLookUp(ShapeId), 2);
2018-09-11 02:51:45 +00:00
if (this->NumIndices == 0)
2018-09-11 02:51:45 +00:00
{
std::stringstream message;
message << "Unstructured Mesh Connecitity Single type Error: unsupported cell type: ";
message << ShapeId;
throw vtkm::cont::ErrorBadValue(message.str());
}
vtkm::Id start = 0;
this->NumFaces = tables.FaceLookUp(tables.CellTypeLookUp(this->ShapeId), 1);
vtkm::Id numCells = this->CellConnectivity.ReadPortal().GetNumberOfValues();
this->CellOffsets =
vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(start, this->NumIndices, numCells);
2018-09-11 02:51:45 +00:00
Logger* logger = Logger::GetInstance();
logger->OpenLogEntry("mesh_conn_construction");
this->Intersector.SetData(Coords, Triangles);
2018-09-11 02:51:45 +00:00
}
MeshConnectivity MeshConnectivityContainerSingleType::PrepareForExecution(
vtkm::cont::DeviceAdapterId deviceId,
vtkm::cont::Token& token) const
2018-09-11 02:51:45 +00:00
{
return MeshConnectivity(this->FaceConnectivity,
this->CellConnectivity,
this->CellOffsets,
this->ShapeId,
this->NumIndices,
this->NumFaces,
deviceId,
token);
2018-09-11 02:51:45 +00:00
}
MeshConnectivityContainerStructured::MeshConnectivityContainerStructured(
const vtkm::cont::CellSetStructured<3>& cellset,
const vtkm::cont::CoordinateSystem& coords,
const Id4Handle& triangles)
2018-09-11 02:51:45 +00:00
: Coords(coords)
, Cellset(cellset)
{
this->Triangles = triangles;
this->Intersector.SetUseWaterTight(true);
2018-09-11 02:51:45 +00:00
this->PointDims = this->Cellset.GetPointDimensions();
this->CellDims = this->Cellset.GetCellDimensions();
2018-09-11 02:51:45 +00:00
2018-10-30 14:46:42 +00:00
this->Intersector.SetData(Coords, Triangles);
2018-09-11 02:51:45 +00:00
}
MeshConnectivity MeshConnectivityContainerStructured::PrepareForExecution(
vtkm::cont::DeviceAdapterId,
vtkm::cont::Token&) const
2018-09-11 02:51:45 +00:00
{
return MeshConnectivity(CellDims, PointDims);
2018-09-11 02:51:45 +00:00
}
}
}
} //namespace vtkm::rendering::raytracing