fix regression with extra attributes

This commit is contained in:
m-schuetz
2020-08-23 14:11:31 +02:00
parent 0eb7008b47
commit 99e4838d3b
2 changed files with 191 additions and 56 deletions

View File

@@ -488,7 +488,9 @@ namespace chunker_countsort_laszip {
continue;
}
if (mapping.find(attribute.name) != mapping.end()) {
bool standardMappingExists = mapping.find(attribute.name) != mapping.end();
bool isIncludedInOutput = outputAttributes.get(attribute.name) != nullptr;
if (standardMappingExists && isIncludedInOutput) {
handlers.push_back(mapping[attribute.name]);
}
}
@@ -527,76 +529,77 @@ namespace chunker_countsort_laszip {
}
for (int i = firstExtraIndex; i < inputAttributes.list.size(); i++) {
Attribute& attribute = inputAttributes.list[i];
Attribute& inputAttribute = inputAttributes.list[i];
Attribute* attribute = outputAttributes.get(inputAttribute.name);
int targetOffset = outputAttributes.getOffset(inputAttribute.name);
int attributeSize = attribute.size;
int targetOffset = outputAttributes.getOffset(attribute.name);
int attributeSize = inputAttribute.size;
auto handleAttribute = [data, point, header, attributeSize, attributeOffset, sourceOffset, &attribute](int64_t offset) {
memcpy(data + offset + attributeOffset, point->extra_bytes + sourceOffset, attributeSize);
if (attribute != nullptr) {
auto handleAttribute = [data, point, header, attributeSize, attributeOffset, sourceOffset, attribute](int64_t offset) {
memcpy(data + offset + attributeOffset, point->extra_bytes + sourceOffset, attributeSize);
std::function<double(uint8_t*)> f;
std::function<double(uint8_t*)> f;
// TODO: shouldn't use DOUBLE as a unifying type
// it won't work with uint64_t and int64_t
if (attribute.type == AttributeType::INT8) {
f = asDouble<int8_t>;
} else if (attribute.type == AttributeType::INT16) {
f = asDouble<int16_t>;
} else if (attribute.type == AttributeType::INT32) {
f = asDouble<int32_t>;
} else if (attribute.type == AttributeType::INT64) {
f = asDouble<int64_t>;
} else if (attribute.type == AttributeType::UINT8) {
f = asDouble<uint8_t>;
} else if (attribute.type == AttributeType::UINT16) {
f = asDouble<uint16_t>;
} else if (attribute.type == AttributeType::UINT32) {
f = asDouble<uint32_t>;
} else if (attribute.type == AttributeType::UINT64) {
f = asDouble<uint64_t>;
} else if (attribute.type == AttributeType::FLOAT) {
f = asDouble<float>;
} else if (attribute.type == AttributeType::DOUBLE) {
f = asDouble<double>;
}
// TODO: shouldn't use DOUBLE as a unifying type
// it won't work with uint64_t and int64_t
if (attribute->type == AttributeType::INT8) {
f = asDouble<int8_t>;
} else if (attribute->type == AttributeType::INT16) {
f = asDouble<int16_t>;
} else if (attribute->type == AttributeType::INT32) {
f = asDouble<int32_t>;
} else if (attribute->type == AttributeType::INT64) {
f = asDouble<int64_t>;
} else if (attribute->type == AttributeType::UINT8) {
f = asDouble<uint8_t>;
} else if (attribute->type == AttributeType::UINT16) {
f = asDouble<uint16_t>;
} else if (attribute->type == AttributeType::UINT32) {
f = asDouble<uint32_t>;
} else if (attribute->type == AttributeType::UINT64) {
f = asDouble<uint64_t>;
} else if (attribute->type == AttributeType::FLOAT) {
f = asDouble<float>;
} else if (attribute->type == AttributeType::DOUBLE) {
f = asDouble<double>;
}
if (attribute.numElements == 1) {
double x = f(point->extra_bytes + sourceOffset);
if (attribute->numElements == 1) {
double x = f(point->extra_bytes + sourceOffset);
attribute.min.x = std::min(attribute.min.x, x);
attribute.max.x = std::max(attribute.max.x, x);
} else if (attribute.numElements == 2) {
double x = f(point->extra_bytes + sourceOffset + 0 * attribute.elementSize);
double y = f(point->extra_bytes + sourceOffset + 1 * attribute.elementSize);
attribute->min.x = std::min(attribute->min.x, x);
attribute->max.x = std::max(attribute->max.x, x);
} else if (attribute->numElements == 2) {
double x = f(point->extra_bytes + sourceOffset + 0 * attribute->elementSize);
double y = f(point->extra_bytes + sourceOffset + 1 * attribute->elementSize);
attribute.min.x = std::min(attribute.min.x, x);
attribute.min.y = std::min(attribute.min.y, y);
attribute.max.x = std::max(attribute.max.x, x);
attribute.max.y = std::max(attribute.max.y, y);
attribute->min.x = std::min(attribute->min.x, x);
attribute->min.y = std::min(attribute->min.y, y);
attribute->max.x = std::max(attribute->max.x, x);
attribute->max.y = std::max(attribute->max.y, y);
} else if (attribute.numElements == 3) {
double x = f(point->extra_bytes + sourceOffset + 0 * attribute.elementSize);
double y = f(point->extra_bytes + sourceOffset + 1 * attribute.elementSize);
double z = f(point->extra_bytes + sourceOffset + 2 * attribute.elementSize);
} else if (attribute->numElements == 3) {
double x = f(point->extra_bytes + sourceOffset + 0 * attribute->elementSize);
double y = f(point->extra_bytes + sourceOffset + 1 * attribute->elementSize);
double z = f(point->extra_bytes + sourceOffset + 2 * attribute->elementSize);
attribute.min.x = std::min(attribute.min.x, x);
attribute.min.y = std::min(attribute.min.y, y);
attribute.min.z = std::min(attribute.min.z, z);
attribute.max.x = std::max(attribute.max.x, x);
attribute.max.y = std::max(attribute.max.y, y);
attribute.max.z = std::max(attribute.max.z, z);
}
attribute->min.x = std::min(attribute->min.x, x);
attribute->min.y = std::min(attribute->min.y, y);
attribute->min.z = std::min(attribute->min.z, z);
attribute->max.x = std::max(attribute->max.x, x);
attribute->max.y = std::max(attribute->max.y, y);
attribute->max.z = std::max(attribute->max.z, z);
}
};
};
if(targetOffset >= 0){
handlers.push_back(handleAttribute);
}
sourceOffset += attribute.size;
attributeOffset += attribute.size;
sourceOffset += attribute->size;
attributeOffset += attribute->size;
}
}

132
testing/testing.mjs Normal file
View File

@@ -0,0 +1,132 @@
import {spawn} from "child_process";
let cmd = "../build/Release/PotreeConverter.exe";
let testcases = [
{
input: ["D:/dev/pointclouds/testdata/crash.las"],
output: "D:/temp/test/crash.las",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/aerial_lidar2019_2524_1197_laz14_dip.laz"],
output: "D:/temp/test/aerial_lidar2019_2524_1197_laz14_dip.laz",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/trott_crashing"],
output: "D:/temp/test/trott_crashing",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/d85034_COO_VERRIERES_CORCELLES_MLS_2019_000170_dip.laz"],
output: "D:/temp/test/d85034_COO_VERRIERES_CORCELLES_MLS_2019_000170_dip.laz",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/heidentor.las"],
output: "D:/temp/test/heidentor.las",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/heidentor.laz"],
output: "D:/temp/test/heidentor.laz",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/heidentor.laz"],
output: "D:/temp/test/heidentor.laz_only_rgb",
arguments: ["--attributes", "rgb"],
},{
input: ["D:/dev/pointclouds/testdata/ca13"],
output: "D:/temp/test/ca13",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/ca13"],
output: "D:/temp/test/ca13_rgb_intensity_classification",
arguments: ["--attributes", "rgb", "intensity", "classification"],
},{
input: ["D:/dev/pointclouds/testdata/lion.laz"],
output: "D:/temp/test/lion.laz",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/eclepens.laz"],
output: "D:/temp/test/eclepens.laz",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/retz.laz"],
output: "D:/temp/test/retz.laz",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/vol_total.laz"],
output: "D:/temp/test/vol_total.laz",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/affandi"],
output: "D:/temp/test/affandi",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/ahn3"],
output: "D:/temp/test/ahn3",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/Grab15.laz"],
output: "D:/temp/test/Grab15.laz",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/tahoe.laz"],
output: "D:/temp/test/tahoe.laz",
arguments: [],
},{
input: ["D:/dev/pointclouds/testdata/railway_000039.laz"],
output: "D:/temp/test/railway_000039.laz",
arguments: [],
}
];
async function runTestcase(testcase){
console.log(`======================================`);
console.log(`starting testcase`);
console.log(testcase);
return new Promise(resolve => {
let args = [
testcase.input,
"-o", testcase.output,
...testcase.arguments,
];
let process = spawn(cmd, args);
process.stdout.on('data', (data) => {
//console.log(`stdout: ${data}`);
});
process.stderr.on('data', (data) => {
//console.error(`stderr: ${data}`);
});
process.on('close', (code) => {
console.log(`child process exited with code ${code}`);
if(code !== 0){
console.error("ERROR!");
}
resolve();
});
});
}
async function run(){
let testcase = testcases[0];
for(let testcase of testcases){
await runTestcase(testcase);
}
}
run();