draco icon indicating copy to clipboard operation
draco copied to clipboard

I Can not make Encoding Point Cloud to Buffer to work

Open jorajipo opened this issue 2 years ago • 0 comments

I was checking code of the coded test so I made a very simple test project triyng to encode a point cloud, but when I print the number of encoded points I allways get zero, i don´t know what am I doing wreong or if there is another way to test if the encoding is going well.

here is my code:

#include #include

#include "draco/compression/encode.h" #include "draco/point_cloud/point_cloud.h" #include "draco/io/point_cloud_io.h" //to encode to buffer #include "draco/point_cloud/point_cloud_builder.h"

int main(int argc, char** argv) {

//Create Point Cloud
draco::PointCloudBuilder pc_builder;

constexpr int kNumPoints = 1000;
pc_builder.Start(kNumPoints);

// Add position attribute.
const int32_t pos_att_id = pc_builder.AddAttribute(
    draco::GeometryAttribute::POSITION, 3, draco::DT_FLOAT32);


// Initialize the attribute values.
for (draco::PointIndex i(0); i < kNumPoints; ++i) {
  const float pos_coord = static_cast<float>(i.value());
  pc_builder.SetAttributeValueForPoint(
      pos_att_id, i,
      draco::Vector3f(pos_coord, -pos_coord, pos_coord).data());
}

std::unique_ptr<draco::PointCloud> geometry = pc_builder.Finalize(true);

// Ensure the logged number of encoded points and faces matches the number // we get from the decoder. int32_t encoding_method = draco::POINT_CLOUD_KD_TREE_ENCODING;

draco::Encoder encoder;

encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, 10);

encoder.SetEncodingMethod(encoding_method);

encoder.SetTrackEncodedProperties(true);
encoder.SetSpeedOptions(4,4);

draco::EncoderBuffer buffer;
draco::Status status = encoder.EncodePointCloudToBuffer(*geometry, &buffer);

std::cout << "Number of points in the cloud: " << geometry->num_points();
std::cout <<" - Encoded points: "<< encoder.num_encoded_points();
std::cout << " buffer.data " << buffer.data() << "buffer.size" << buffer.size();


return 0;

}

jorajipo avatar May 15 '23 18:05 jorajipo