fix ANARIMapperVolume usage edge cases (empty actor is valid)

This commit is contained in:
Jefferson Amstutz 2024-04-04 13:27:44 -05:00
parent ea30203836
commit 232d9dde9c

@ -157,6 +157,8 @@ void ANARIMapperVolume::ConstructArrays(bool regenerate)
this->Current = true; this->Current = true;
this->Valid = false; this->Valid = false;
auto d = this->GetDevice();
const auto& actor = this->GetActor(); const auto& actor = this->GetActor();
const auto& coords = actor.GetCoordinateSystem(); const auto& coords = actor.GetCoordinateSystem();
const auto& cells = actor.GetCellSet(); const auto& cells = actor.GetCellSet();
@ -168,24 +170,21 @@ void ANARIMapperVolume::ConstructArrays(bool regenerate)
const bool isScalar = fieldArray.GetNumberOfComponentsFlat() == 1; const bool isScalar = fieldArray.GetNumberOfComponentsFlat() == 1;
this->Handles->ReleaseArrays(); this->Handles->ReleaseArrays();
anari_cpp::release(d, this->Handles->SpatialField);
if (!this->Handles->SpatialField) this->Handles->SpatialField = nullptr;
{
this->Handles->SpatialField = anari_cpp::newObject<anari_cpp::SpatialField>(
this->GetDevice(), (isStructured && isScalar) ? "structuredRegular" : "unstructured");
}
// Structured regular volume data // Structured regular volume data
if (isStructured && isScalar) if (isStructured && isScalar)
{ {
this->Handles->SpatialField =
anari_cpp::newObject<anari_cpp::SpatialField>(this->GetDevice(), "structuredRegular");
auto structuredCells = cells.AsCellSet<vtkm::cont::CellSetStructured<3>>(); auto structuredCells = cells.AsCellSet<vtkm::cont::CellSetStructured<3>>();
auto pdims = auto pdims =
isPointBased ? structuredCells.GetPointDimensions() : structuredCells.GetCellDimensions(); isPointBased ? structuredCells.GetPointDimensions() : structuredCells.GetCellDimensions();
StructuredVolumeArrays arrays; StructuredVolumeArrays arrays;
auto d = this->GetDevice();
vtkm::cont::ArrayCopyShallowIfPossible(fieldArray, arrays.Data); vtkm::cont::ArrayCopyShallowIfPossible(fieldArray, arrays.Data);
auto* ptr = (float*)arrays.Data.GetBuffers()[0].ReadPointerHost(*arrays.Token); auto* ptr = (float*)arrays.Data.GetBuffers()[0].ReadPointerHost(*arrays.Token);
@ -206,15 +205,11 @@ void ANARIMapperVolume::ConstructArrays(bool regenerate)
this->StructuredArrays = arrays; this->StructuredArrays = arrays;
this->Valid = true; this->Valid = true;
} }
// Unstructured volume data // Unstructured volume data
else else if (isPointBased)
{ {
this->Handles->SpatialField =
if (!isPointBased) anari_cpp::newObject<anari_cpp::SpatialField>(this->GetDevice(), "unstructured");
{
throw vtkm::cont::ErrorBadValue("Anari Unstructured volume data must be point-based.");
}
UntructuredVolumeArrays arrays; UntructuredVolumeArrays arrays;
@ -265,9 +260,6 @@ void ANARIMapperVolume::ConstructArrays(bool regenerate)
// Vetrex Data // Vetrex Data
vtkm::cont::ArrayCopyShallowIfPossible(fieldArray, arrays.VertexData); vtkm::cont::ArrayCopyShallowIfPossible(fieldArray, arrays.VertexData);
// Send data to ANARI
auto d = this->GetDevice();
// "indexPrefixed" // "indexPrefixed"
this->Handles->UnstructuredParameters.IndexPrefixed = false; this->Handles->UnstructuredParameters.IndexPrefixed = false;
@ -399,6 +391,13 @@ void ANARIMapperVolume::UpdateSpatialField()
} }
anari_cpp::commitParameters(d, this->Handles->SpatialField); anari_cpp::commitParameters(d, this->Handles->SpatialField);
if (this->Handles->Volume)
{
anari_cpp::setParameter(d, this->Handles->Volume, "field", this->GetANARISpatialField());
anari_cpp::setParameter(d, this->Handles->Volume, "value", this->GetANARISpatialField());
anari_cpp::commitParameters(d, this->Handles->Volume);
}
} }
ANARIMapperVolume::ANARIHandles::~ANARIHandles() ANARIMapperVolume::ANARIHandles::~ANARIHandles()