Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/draco/compression/attributes/sequential_attribute_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ class SequentialAttributeDecoder {
virtual bool DecodePortableAttribute(const std::vector<PointIndex> &point_ids,
DecoderBuffer *in_buffer);

virtual void PrepareDecodingPortableAttribute(const size_t data_size, DecoderBuffer *in_buffer) {
mBuffer.Init(in_buffer->data_head(), data_size, in_buffer->bitstream_version());
in_buffer->Advance(data_size);
}

// Performs lossless decoding of the portable attribute data.
virtual bool DecodePortableAttribute(const std::vector<PointIndex> &point_ids) {
return DecodePortableAttribute(point_ids, &mBuffer);
}

// Decodes any data needed to revert portable transform of the decoded
// attribute.
virtual bool DecodeDataNeededByPortableTransform(
Expand Down Expand Up @@ -71,6 +81,8 @@ class SequentialAttributeDecoder {

PointAttribute *portable_attribute() { return portable_attribute_.get(); }

DecoderBuffer mBuffer;

private:
PointCloudDecoder *decoder_;
PointAttribute *attribute_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@
#include "draco/compression/attributes/sequential_quantization_attribute_decoder.h"
#include "draco/compression/config/compression_shared.h"

#include "draco/psy/psy_draco.h"

namespace draco {

class DecodePortableAttributeJob : public IDracoJob
{
public:
DecodePortableAttributeJob() : mpDecoder(nullptr), mpPointIds(nullptr) {}
DecodePortableAttributeJob(SequentialAttributeDecoder* pDecoder, std::vector<PointIndex>* pPointIds)
: mpDecoder(pDecoder), mpPointIds(pPointIds) {
}

bool DoJob() override {
if (mpDecoder && mpPointIds) {
return mpDecoder->DecodePortableAttribute(*mpPointIds);
}
return false;
}

SequentialAttributeDecoder* mpDecoder;
std::vector<PointIndex>* mpPointIds;
};

SequentialAttributeDecodersController::SequentialAttributeDecodersController(
std::unique_ptr<PointsSequencer> sequencer)
: sequencer_(std::move(sequencer)) {}
Expand Down Expand Up @@ -61,12 +82,35 @@ bool SequentialAttributeDecodersController::DecodeAttributes(

bool SequentialAttributeDecodersController::DecodePortableAttributes(
DecoderBuffer *in_buffer) {
PSY_DRACO_PROFILE_SECTION("DecodePortableAttributes()");
const int32_t num_attributes = GetNumAttributes();
for (int i = 0; i < num_attributes; ++i) {
if (!sequential_decoders_[i]->DecodePortableAttribute(point_ids_,
in_buffer))
std::vector<size_t> encoded_blob_sizes(num_attributes, 0);
if (!in_buffer->Decode(encoded_blob_sizes.data(), num_attributes * sizeof(size_t))) {
return false;
}

for (int i = 0; i < num_attributes; ++i) {
sequential_decoders_[i]->PrepareDecodingPortableAttribute(encoded_blob_sizes[i], in_buffer);
}

if (num_attributes > 1 && psy::GetJobsParallelController()) {
auto p_controller = psy::GetJobsParallelController();
std::vector<std::shared_ptr<IDracoJob>> jobs(num_attributes);
std::vector<IDracoJob*> p_jobs(num_attributes, nullptr);
for (uint32_t i = 0; i < num_attributes; ++i) {
jobs[i].reset(new DecodePortableAttributeJob(sequential_decoders_[i].get(), &point_ids_));
p_jobs[i] = jobs[i].get();
}
if (!p_controller->RunJobsParallely(p_jobs.data(), num_attributes)) {
return false;
}
} else {
for (int i = 0; i < num_attributes; ++i) {
if (!sequential_decoders_[i]->DecodePortableAttribute(point_ids_))
return false;
}
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class SequentialAttributeEncoder {
virtual bool EncodePortableAttribute(const std::vector<PointIndex> &point_ids,
EncoderBuffer *out_buffer);

// Performs lossless encoding of the transformed attribute data.
virtual bool EncodePortableAttribute(const std::vector<PointIndex> &point_ids) {
mBuffer.Resize(0);
return EncodePortableAttribute(point_ids, &mBuffer);
}

// Encodes any data related to the portable attribute transform.
virtual bool EncodeDataNeededByPortableTransform(EncoderBuffer *out_buffer);

Expand All @@ -79,6 +85,8 @@ class SequentialAttributeEncoder {
int attribute_id() const { return attribute_id_; }
PointCloudEncoder *encoder() const { return encoder_; }

EncoderBuffer mBuffer;

protected:
// Should be used to initialize newly created prediction scheme.
// Returns false when the initialization failed (in which case the scheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,30 @@
#include "draco/compression/attributes/sequential_quantization_attribute_encoder.h"
#include "draco/compression/point_cloud/point_cloud_encoder.h"


#include "draco/psy/psy_draco.h"

namespace draco {

class EncodePortableAttributeJob : public IDracoJob
{
public:
EncodePortableAttributeJob() : mpEncoder(nullptr), mpPointIds(nullptr) {}
EncodePortableAttributeJob(SequentialAttributeEncoder* pEncoder, std::vector<PointIndex>* pPointIds)
: mpEncoder(pEncoder), mpPointIds(pPointIds) {
}

bool DoJob() override {
if (mpEncoder && mpPointIds) {
return (mpEncoder->EncodePortableAttribute(*mpPointIds));
}
return (false);
}

SequentialAttributeEncoder* mpEncoder;
std::vector<PointIndex>* mpPointIds;
};

SequentialAttributeEncodersController::SequentialAttributeEncodersController(
std::unique_ptr<PointsSequencer> sequencer)
: sequencer_(std::move(sequencer)) {}
Expand Down Expand Up @@ -72,11 +94,39 @@ bool SequentialAttributeEncodersController::

bool SequentialAttributeEncodersController::EncodePortableAttributes(
EncoderBuffer *out_buffer) {
for (uint32_t i = 0; i < sequential_encoders_.size(); ++i) {
if (!sequential_encoders_[i]->EncodePortableAttribute(point_ids_,
out_buffer))
return false;
PSY_DRACO_PROFILE_SECTION("EncodePortableAttributes()");

const auto encoders_count = sequential_encoders_.size();

if (encoders_count > 1 && psy::GetJobsParallelController()) {
auto p_controller = psy::GetJobsParallelController();
std::vector<std::shared_ptr<IDracoJob>> jobs(encoders_count);
std::vector<IDracoJob*> p_jobs(encoders_count, nullptr);
for (uint32_t i = 0; i < encoders_count; ++i) {
jobs[i].reset(new EncodePortableAttributeJob(sequential_encoders_[i].get(), &point_ids_));
p_jobs[i] = jobs[i].get();
}
if (!p_controller->RunJobsParallely(p_jobs.data(), encoders_count)) {
return false;
}
} else {
for (uint32_t i = 0; i < encoders_count; ++i) {
if (!sequential_encoders_[i]->EncodePortableAttribute(point_ids_)) {
return false;
}
}
}

for (uint32_t i = 0; i < encoders_count; ++i) {
if (!out_buffer->Encode(sequential_encoders_[i]->mBuffer.size())) {
return false;
}
}

for (uint32_t i = 0; i < encoders_count; ++i) {
out_buffer->Encode(sequential_encoders_[i]->mBuffer.data(), sequential_encoders_[i]->mBuffer.size());
}

return true;
}

Expand Down
21 changes: 20 additions & 1 deletion src/draco/psy/psy_draco.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,28 @@ class PSY_DRACO_API IProfilerManager
virtual ~IProfilerManager() {}
};

class PSY_DRACO_API IDracoJob
{
public:
virtual bool DoJob() = 0;
virtual ~IDracoJob() {}
};
class PSY_DRACO_API IDracoJobsController
{
public:
virtual bool RunJobsParallely(IDracoJob** pJobs, const size_t jobsCount) const = 0;
virtual ~IDracoJobsController() {}
};

namespace psy
{

PSY_DRACO_API IProfilerManager* GetProfilerManager();
PSY_DRACO_API void SetProfilerManager(IProfilerManager*);

PSY_DRACO_API IDracoJobsController* GetJobsParallelController();
PSY_DRACO_API void SetJobsParallelController(IDracoJobsController*);

namespace draco
{

Expand All @@ -57,7 +73,10 @@ enum PSY_DRACO_API MeshType : uint8_t
* - 1.0: support incremental mesh compression
* - 1.1: 2018/01/05 (*)
* + support vertex color compression
* - Support I frame index encoding as part of the header
* - ?.?:
* + support I frame index encoding as part of the header
* - 1.2: 2018/02/07
* + support encode/decode attributes parallely
*/
#define PSY_DRACO_API_MAJOR_VERSION 1
#define PSY_DRACO_API_MINOR_VERSION 1
Expand Down
14 changes: 14 additions & 0 deletions src/draco/psy/psy_draco_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ void SetProfilerManager(IProfilerManager* pProp)
}
gmpProfilerManager = pProp;
} // SetProfilerManager

static IDracoJobsController* gmpJobsParallelController = nullptr;
IDracoJobsController* GetJobsParallelController()
{
return gmpJobsParallelController;
} // GetJobsParallelController
void SetJobsParallelController(IDracoJobsController* pProp)
{
if (gmpJobsParallelController)
{
delete gmpJobsParallelController;
}
gmpJobsParallelController = pProp;
} // SetJobsParallelController
} // namespace psy

namespace psy
Expand Down