draco icon indicating copy to clipboard operation
draco copied to clipboard

EncodePointCloudToBuffer compression point and normal error

Open mylove10086 opened this issue 5 years ago • 3 comments

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<std::array<float, 3>> normals;
std::vector<std::array<float, 3>> 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<draco::PointCloud> 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<float, 3> vIndex = positions[j];
    std::vector<float> 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<float, 3> vIndex = normals[j];
    std::vector<float> 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;}

mylove10086 avatar Apr 13 '20 10:04 mylove10086

in latest version of draco: att.Init(att_type, componentCount, draco::DT_FLOAT32, false,byte_stride); it accept 5 params not 7

evehal avatar Apr 27 '20 09:04 evehal

We're trying to achieve similar goals with pointcloud compression, except we're working with nodejs. I think it would be nice to have official examples on implementing pointcloud compressions.

CaseyPYZ avatar May 09 '20 08:05 CaseyPYZ

We're trying to achieve similar goals with pointcloud compression, except we're working with nodejs. I think it would be nice to have official examples on implementing pointcloud compressions.

This is an example of compression points sorted out by evehal after replying to me https://blog.csdn.net/u014572215/article/details/105821918 Including point location, normal, color, noise

mylove10086 avatar May 11 '20 01:05 mylove10086