-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUsdSpatialField.cpp
107 lines (88 loc) · 3.33 KB
/
UsdSpatialField.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2020 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#include "UsdSpatialField.h"
#include "UsdAnari.h"
#include "UsdDataArray.h"
#include "UsdDevice.h"
#include "UsdVolume.h"
#include <algorithm>
DEFINE_PARAMETER_MAP(UsdSpatialField,
REGISTER_PARAMETER_MACRO("name", ANARI_STRING, name)
REGISTER_PARAMETER_MACRO("usd::name", ANARI_STRING, usdName)
REGISTER_PARAMETER_MACRO("usd::time", ANARI_FLOAT64, timeStep)
REGISTER_PARAMETER_MACRO("usd::timeVarying", ANARI_INT32, timeVarying)
REGISTER_PARAMETER_MACRO("data", ANARI_ARRAY, data)
REGISTER_PARAMETER_MACRO("spacing", ANARI_FLOAT32_VEC3, gridSpacing)
REGISTER_PARAMETER_MACRO("origin", ANARI_FLOAT32_VEC3, gridOrigin)
) // See .h for usage.
constexpr UsdSpatialField::ComponentPair UsdSpatialField::componentParamNames[]; // Workaround for C++14's lack of inlining constexpr arrays
UsdSpatialField::UsdSpatialField(const char* name, const char* type, UsdDevice* device)
: BridgedBaseObjectType(ANARI_SPATIAL_FIELD, name, device)
{
}
UsdSpatialField::~UsdSpatialField()
{
#ifdef OBJECT_LIFETIME_EQUALS_USD_LIFETIME
if(cachedBridge)
cachedBridge->DeleteSpatialField(usdHandle);
#endif
}
void UsdSpatialField::commit(UsdDevice* device)
{
// Notify observers (such as volume) that the spatial field has changed.
notify(this, device);
// Continue with the normal commit, ie. adding to the commit list or immediate execution of doCommitData
BridgedBaseObjectType::commit(device);
}
void UsdSpatialField::remove(UsdDevice* device)
{
applyRemoveFunc(device, &UsdBridge::DeleteSpatialField);
}
bool UsdSpatialField::deferCommit(UsdDevice* device)
{
// Always defer until flushing of commit list, to give parent volumes the possibility to detect which of its child fields have been committed,
// such that those volumes with committed children are also automatically committed.
return !device->isFlushingCommitList();
}
bool UsdSpatialField::doCommitData(UsdDevice* device)
{
UsdBridge* usdBridge = device->getUsdBridge();
const UsdSpatialFieldData& paramData = getReadParams();
const char* debugName = getName();
UsdLogInfo logInfo(device, this, ANARI_SPATIAL_FIELD, debugName);
bool isNew = false;
if(!usdHandle.value)
isNew = usdBridge->CreateSpatialField(debugName, usdHandle);
// Only perform type checks, actual data gets uploaded during UsdVolume::commit()
const UsdDataArray* fieldDataArray = paramData.data;
if (!fieldDataArray)
{
device->reportStatus(this, ANARI_SPATIAL_FIELD, ANARI_SEVERITY_ERROR, ANARI_STATUS_INVALID_OPERATION,
"UsdSpatialField '%s' commit failed: data missing.", debugName);
return false;
}
const UsdDataLayout& dataLayout = fieldDataArray->getLayout();
if (!AssertNoStride(dataLayout, logInfo, "data"))
return false;
switch (fieldDataArray->getType())
{
case ANARI_INT8:
case ANARI_UINT8:
case ANARI_INT16:
case ANARI_UINT16:
case ANARI_INT32:
case ANARI_UINT32:
case ANARI_INT64:
case ANARI_UINT64:
case ANARI_FLOAT32:
case ANARI_FLOAT64:
break;
default:
device->reportStatus(this, ANARI_SPATIAL_FIELD, ANARI_SEVERITY_ERROR, ANARI_STATUS_INVALID_ARGUMENT,
"UsdSpatialField '%s' commit failed: incompatible data type.", debugName);
return false;
}
// Make sure that parameters are set a first time
paramChanged = paramChanged || isNew;
return false;
}