Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lowercase types (i, u, f) when reading PCD files #6930

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- Split pybind declarations/definitions to avoid C++ types in Python docs (PR #6869)
- Fix minimal oriented bounding box of MeshBase derived classes and add new unit tests (PR #6898)
- Fix projection of point cloud to Depth/RGBD image if no position attribute is provided (PR #6880)
- Support lowercase types when reading PCD files (PR #6930)

## 0.13

Expand Down
21 changes: 12 additions & 9 deletions cpp/open3d/io/file_format/FilePCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ bool ReadPCDHeader(FILE *file, PCDHeader &header) {
double UnpackBinaryPCDElement(const char *data_ptr,
const char type,
const int size) {
if (type == 'I') {
const char type_uppercase = std::toupper(type, std::locale());
if (type_uppercase == 'I') {
if (size == 1) {
std::int8_t data;
memcpy(&data, data_ptr, sizeof(data));
Expand All @@ -236,7 +237,7 @@ double UnpackBinaryPCDElement(const char *data_ptr,
} else {
return 0.0;
}
} else if (type == 'U') {
} else if (type_uppercase == 'U') {
if (size == 1) {
std::uint8_t data;
memcpy(&data, data_ptr, sizeof(data));
Expand All @@ -252,7 +253,7 @@ double UnpackBinaryPCDElement(const char *data_ptr,
} else {
return 0.0;
}
} else if (type == 'F') {
} else if (type_uppercase == 'F') {
if (size == 4) {
float data;
memcpy(&data, data_ptr, sizeof(data));
Expand Down Expand Up @@ -281,11 +282,12 @@ double UnpackASCIIPCDElement(const char *data_ptr,
const char type,
const int size) {
char *end;
if (type == 'I') {
const char type_uppercase = std::toupper(type, std::locale());
if (type_uppercase == 'I') {
return (double)std::strtol(data_ptr, &end, 0);
} else if (type == 'U') {
} else if (type_uppercase == 'U') {
return (double)std::strtoul(data_ptr, &end, 0);
} else if (type == 'F') {
} else if (type_uppercase == 'F') {
return std::strtod(data_ptr, &end);
}
return 0.0;
Expand All @@ -297,13 +299,14 @@ Eigen::Vector3d UnpackASCIIPCDColor(const char *data_ptr,
if (size == 4) {
std::uint8_t data[4] = {0, 0, 0, 0};
char *end;
if (type == 'I') {
const char type_uppercase = std::toupper(type, std::locale());
if (type_uppercase == 'I') {
std::int32_t value = std::strtol(data_ptr, &end, 0);
memcpy(data, &value, 4);
} else if (type == 'U') {
} else if (type_uppercase == 'U') {
std::uint32_t value = std::strtoul(data_ptr, &end, 0);
memcpy(data, &value, 4);
} else if (type == 'F') {
} else if (type_uppercase == 'F') {
float value = std::strtof(data_ptr, &end);
memcpy(data, &value, 4);
}
Expand Down
25 changes: 15 additions & 10 deletions cpp/open3d/t/io/file_format/FilePCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,34 @@ struct WriteAttributePtr {
};

static core::Dtype GetDtypeFromPCDHeaderField(char type, int size) {
if (type == 'I') {
char type_uppercase = std::toupper(type, std::locale());
if (type_uppercase == 'I') {
if (size == 1) return core::Dtype::Int8;
if (size == 2) return core::Dtype::Int16;
if (size == 4) return core::Dtype::Int32;
if (size == 8)
return core::Dtype::Int64;
else
utility::LogError("Unsupported data type.");
} else if (type == 'U') {
utility::LogError("Unsupported size {} for data type {}.", size,
type);
} else if (type_uppercase == 'U') {
if (size == 1) return core::Dtype::UInt8;
if (size == 2) return core::Dtype::UInt16;
if (size == 4) return core::Dtype::UInt32;
if (size == 8)
return core::Dtype::UInt64;
else
utility::LogError("Unsupported data type.");
} else if (type == 'F') {
utility::LogError("Unsupported size {} for data type {}.", size,
type);
} else if (type_uppercase == 'F') {
if (size == 4) return core::Dtype::Float32;
if (size == 8)
return core::Dtype::Float64;
else
utility::LogError("Unsupported data type.");
utility::LogError("Unsupported size {} for data type {}.", size,
type);
} else {
utility::LogError("Unsupported data type.");
utility::LogError("Unsupported data type {}.", type);
}
}

Expand Down Expand Up @@ -305,13 +309,14 @@ static void ReadASCIIPCDColorsFromField(ReadAttributePtr &attr,
if (field.size == 4) {
std::uint8_t data[4] = {0};
char *end;
if (field.type == 'I') {
char type_uppercase = std::toupper(field.type, std::locale());
if (type_uppercase == 'I') {
std::int32_t value = std::strtol(data_ptr, &end, 0);
std::memcpy(data, &value, sizeof(std::int32_t));
} else if (field.type == 'U') {
} else if (type_uppercase == 'U') {
std::uint32_t value = std::strtoul(data_ptr, &end, 0);
std::memcpy(data, &value, sizeof(std::uint32_t));
} else if (field.type == 'F') {
} else if (type_uppercase == 'F') {
float value = std::strtof(data_ptr, &end);
std::memcpy(data, &value, sizeof(float));
}
Expand Down
Loading