Fix a couple of point cloud related problems

* crash that occurs when loading an empty dataset
* trying to access outside of range when sampling color or size values
This commit is contained in:
Emma Broman
2024-02-20 08:39:54 +01:00
parent 1b5335fa89
commit 8fddd55851
4 changed files with 12 additions and 2 deletions

View File

@@ -71,6 +71,8 @@ struct Dataset {
/// the dataset
float maxPositionComponent = 0.f;
bool isEmpty() const;
int index(std::string_view variableName) const;
bool normalizeVariable(std::string_view variableName);
glm::vec2 findValueRange(int variableIndex) const;

View File

@@ -1072,12 +1072,12 @@ std::vector<float> RenderablePointCloud::createDataSlice() {
}
// Colors
if (_hasColorMapFile) {
if (_hasColorMapFile && colorParamIndex > -1) {
result.push_back(e.data[colorParamIndex]);
}
// Size data
if (_hasDatavarSize) {
if (_hasDatavarSize && sizeParamIndex > -1) {
// @TODO: Consider more detailed control over the scaling. Currently the value
// is multiplied with the value as is. Should have similar mapping properties
// as the color mapping

View File

@@ -623,6 +623,10 @@ ColorMap loadFileWithCache(std::filesystem::path path)
} // namespace color
bool Dataset::isEmpty() const {
return variables.empty() || entries.empty();
}
int Dataset::index(std::string_view variableName) const {
for (const Dataset::Variable& v : variables) {
if (v.name == variableName) {

View File

@@ -428,6 +428,10 @@ glm::vec4 ColorMappingComponent::colorFromColorMap(float valueToColorFrom) const
}
void ColorMappingComponent::initializeParameterData(const dataloader::Dataset& dataset) {
if (dataset.isEmpty()) {
return;
}
// Initialize empty ranges based on values in the dataset
for (const properties::OptionProperty::Option& option : dataColumn.options()) {
int optionIndex = option.value;