@@ -2034,16 +2034,9 @@ template <> int32_t componentTypeFromCpp<uint32_t>() {
2034
2034
return Accessor::ComponentType::UNSIGNED_INT;
2035
2035
}
2036
2036
2037
- template <class ... Ts> struct overloaded : Ts... {
2038
- using Ts::operator ()...;
2039
- };
2040
- template <class ... Ts> overloaded (Ts...) -> overloaded<Ts...>;
2041
-
2042
- // encapsulation of the binary batch id data in an I3dm. If byteSize is 0, then
2043
- // the semantic is invalid for some reason.
2037
+ // encapsulation of the binary batch id data in an I3dm
2044
2038
struct BatchIdSemantic {
2045
2039
std::variant<
2046
- std::monostate,
2047
2040
std::span<const uint8_t >,
2048
2041
std::span<const uint16_t >,
2049
2042
std::span<const uint32_t >>
@@ -2073,65 +2066,62 @@ struct BatchIdSemantic {
2073
2066
const auto byteOffsetIt = batchIdIt->value .FindMember (" byteOffset" );
2074
2067
if (byteOffsetIt == batchIdIt->value .MemberEnd () ||
2075
2068
!byteOffsetIt->value .IsUint ()) {
2076
- return ;
2069
+ // Warning
2077
2070
}
2078
2071
uint32_t byteOffset = byteOffsetIt->value .GetUint ();
2079
2072
const auto componentTypeIt = batchIdIt->value .FindMember (" componentType" );
2080
- if (componentTypeIt != batchIdIt-> value .MemberEnd () &&
2073
+ if (componentTypeIt != featureTableJson .MemberEnd () &&
2081
2074
componentTypeIt->value .IsString ()) {
2082
2075
const std::string& componentTypeString =
2083
2076
componentTypeIt->value .GetString ();
2084
- if (MetadataProperty::stringToMetadataComponentType.count (
2085
- componentTypeString) == 0 ) {
2086
- return ;
2077
+ if (MetadataProperty::stringToMetadataComponentType.find (
2078
+ componentTypeString) ==
2079
+ MetadataProperty::stringToMetadataComponentType.end ()) {
2080
+ // Warning
2087
2081
}
2088
2082
MetadataProperty::ComponentType componentType =
2089
2083
MetadataProperty::stringToMetadataComponentType.at (
2090
2084
componentTypeString);
2091
2085
rawData = featureTableJsonData.data ();
2092
- numElements = numInstances;
2093
2086
if (componentType == MetadataProperty::ComponentType::UNSIGNED_BYTE) {
2094
2087
batchSpan = makeSpan<uint8_t >(rawData, byteOffset, numInstances);
2088
+ numElements = numInstances;
2095
2089
byteSize = numElements * sizeof (uint8_t );
2096
2090
} else if (
2097
2091
componentType == MetadataProperty::ComponentType::UNSIGNED_SHORT) {
2098
- batchSpan = makeSpan<uint16_t >(rawData, byteOffset, numInstances);
2092
+ batchSpan = makeSpan<uint8_t >(rawData, byteOffset, numInstances);
2093
+ numElements = numInstances;
2099
2094
byteSize = numElements * sizeof (uint16_t );
2100
2095
} else if (
2101
2096
componentType == MetadataProperty::ComponentType::UNSIGNED_INT) {
2102
2097
batchSpan = makeSpan<uint32_t >(rawData, byteOffset, numInstances);
2098
+ numElements = numInstances;
2103
2099
byteSize = numElements * sizeof (uint32_t );
2104
2100
}
2105
2101
}
2106
2102
}
2107
2103
2108
2104
size_t idSize () const {
2109
2105
return std::visit (
2110
- overloaded (
2111
- [](const std::monostate&) -> size_t { return 0 ; },
2112
- [](auto && batchIds) -> size_t { return sizeof (batchIds[0 ]); }),
2106
+ [](auto && batchIds) { return sizeof (batchIds[0 ]); },
2113
2107
batchSpan);
2114
2108
}
2115
2109
2116
2110
uint32_t maxBatchId () const {
2117
2111
return std::visit (
2118
- overloaded (
2119
- [](const std::monostate&) -> uint32_t { return 0 ; },
2120
- [](auto && batchIds) -> uint32_t {
2121
- auto itr = std::max_element (batchIds.begin (), batchIds.end ());
2122
- return *itr;
2123
- }),
2112
+ [](auto && batchIds) {
2113
+ auto itr = std::max_element (batchIds.begin (), batchIds.end ());
2114
+ return static_cast <uint32_t >(*itr);
2115
+ },
2124
2116
batchSpan);
2125
2117
}
2126
2118
2127
2119
int32_t componentType () const {
2128
2120
return std::visit (
2129
- overloaded (
2130
- [](const std::monostate&) { return -1 ; },
2131
- [](auto && batchIds) {
2132
- using span_type = std::remove_reference_t <decltype (batchIds)>;
2133
- return componentTypeFromCpp<typename span_type::value_type>();
2134
- }),
2121
+ [](auto && batchIds) {
2122
+ using span_type = std::remove_reference_t <decltype (batchIds)>;
2123
+ return componentTypeFromCpp<typename span_type::value_type>();
2124
+ },
2135
2125
batchSpan);
2136
2126
}
2137
2127
};
@@ -2185,7 +2175,7 @@ ErrorList BatchTableToGltfStructuralMetadata::convertFromI3dm(
2185
2175
// IDs, the number of instances.
2186
2176
int64_t featureCount = 0 ;
2187
2177
std::optional<BatchIdSemantic> optBatchIds;
2188
- bool hasBatchIds = featureTableJson.HasMember (" BATCH_ID" );
2178
+ const auto batchIdIt = featureTableJson.FindMember (" BATCH_ID" );
2189
2179
std::optional<uint32_t > optInstancesLength =
2190
2180
GltfConverterUtility::getValue<uint32_t >(
2191
2181
featureTableJson,
@@ -2194,20 +2184,15 @@ ErrorList BatchTableToGltfStructuralMetadata::convertFromI3dm(
2194
2184
result.emplaceError (" Required INSTANCES_LENGTH semantic is missing" );
2195
2185
return result;
2196
2186
}
2197
- featureCount = *optInstancesLength;
2198
- if (hasBatchIds) {
2187
+ if (batchIdIt == featureTableJson.MemberEnd ()) {
2188
+ featureCount = *optInstancesLength;
2189
+ } else {
2199
2190
optBatchIds = BatchIdSemantic (
2200
2191
featureTableJson,
2201
2192
*optInstancesLength,
2202
2193
featureTableJsonData);
2203
- if (optBatchIds->byteSize == 0 ) {
2204
- result.emplaceError (" Invalid Batch ID Semantic" );
2205
- optBatchIds.reset ();
2206
- } else {
2207
- featureCount = optBatchIds->maxBatchId () + 1 ;
2208
- }
2209
- } else {
2210
- featureCount = *optInstancesLength;
2194
+ uint32_t maxBatchId = optBatchIds->maxBatchId ();
2195
+ featureCount = maxBatchId + 1 ;
2211
2196
}
2212
2197
2213
2198
convertBatchTableToGltfStructuralMetadataExtension (
0 commit comments