google / google/draco

EncodePointCloudToBuffer compression point and normal error

Open
#598 3 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
C++
Stars
7.5k
Forks
1.1k
Avg merge
47m
Merged PRs (30d)
1

Description

I got an error when using EncodePointCloudToBuffer to compress points and normals. The location of the error is in the prediction_scheme_wrap_encoding_transform.h file
inline void ComputeCorrection (const DataTypeT * original_vals,
                                 const DataTypeT * predicted_vals,
                                 CorrTypeT * out_corr_vals)
  function. The original_vals and out_corr_vals parameters are NULL.
When only compressing the point is successful, the error is reported when compressing with the normal.I'm sure my data is error-free, but I can't find the reason. Do you have any good suggestions? And I didn't find an official example.
Here is the complete code:

int main() {
std::cout << "Hello, World!" << std::endl;

std::vector> normals;
std::vector> positions;
float x, nx;
x = 0;
//create 30 points and normals
for (int i = 0; i < 30; i++) {
x = x + 0.01 * i;
x = x + 0.01 * i;
x = x + 0.01 * i;
positions.push_back({x, x, x});
normals.push_back({0, 1, 0});
}

std::unique_ptr dracoPointCloud(new draco::PointCloud());
//POSITION
int j;
int vertexCount = 30;//num
int componentCount = 3;
int byte_stride = sizeof(float) * componentCount;
draco::GeometryAttribute::Type att_type = draco::GeometryAttribute::POSITION;
draco::PointAttribute att;
att.Init(att_type, NULL, componentCount, draco::DT_FLOAT32, false,
byte_stride, 0);
int att_id = dracoPointCloud->AddAttribute(att, true, vertexCount);
draco::PointAttribute *att_ptr = dracoPointCloud->attribute(att_id);
draco::PointIndex pointIndex(0);

for (j = 0; j < 30; j++) {
std::array vIndex = positions[j];
std::vector vertex_data(componentCount);
memcpy(&vertex_data[0], &(vIndex[0]), sizeof(float) * componentCount);
att_ptr->SetAttributeValue(att_ptr->mapped_index(pointIndex), &vertex_data[0]);
pointIndex++;
}

//NORMAL
vertexCount = 30;//num
componentCount = 3;
byte_stride = sizeof(float) * componentCount;
draco::GeometryAttribute::Type att_normal_type = draco::GeometryAttribute::NORMAL;
draco::PointAttribute attNormal;
attNormal.Init(att_normal_type, NULL, componentCount, draco::DT_FLOAT32, false,
byte_stride, 0);
int att_normal_id = dracoPointCloud->AddAttribute(attNormal, true, vertexCount);
draco::PointAttribute *att_normal_ptr = dracoPointCloud->attribute(att_normal_id);

draco::PointIndex pointNormal(0);
for (j = 0; j < 30; j++) {
std::array vIndex = normals[j];
std::vector vertex_data(componentCount);
memcpy(&vertex_data[0], &(vIndex[0]), sizeof(float) * componentCount);
att_normal_ptr->SetAttributeValue(att_normal_ptr->mapped_index(pointNormal), &vertex_data[0]);
pointNormal++;
}

const int dracoCompressionSpeed = 7;
const int dracoPositionBits = 14;
const int dracoNormalBits = 8;
const int dracoColorBits = 8;
const int dracoGenericBits = 12;

draco::EncoderBuffer dracoBuffer;

draco::Encoder encoder;
encoder.SetSpeedOptions(dracoCompressionSpeed, dracoCompressionSpeed);
encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, dracoPositionBits);
encoder.SetAttributeQuantization(draco::GeometryAttribute::NORMAL, dracoNormalBits);
encoder.SetAttributeQuantization(draco::GeometryAttribute::COLOR, dracoColorBits);
encoder.SetAttributeQuantization(draco::GeometryAttribute::GENERIC, dracoGenericBits);
//encoder.SetEncodingMethod(draco::PointCloudEncodingMethod::POINT_CLOUD_KD_TREE_ENCODING);

//draco::EncoderBuffer dracoBuffer1;
const draco::Status status = encoder.EncodePointCloudToBuffer(*dracoPointCloud, &dracoBuffer);

//dracoBuffer
if (!status.ok()) {
std::cout << "Error: Encode mesh.\n";

}
std::cout << "success\n";
system("pause");

return 0;}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.