// Copyright 2016 The Draco Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #include "compression/attributes/sequential_attribute_encoders_controller.h" #include "compression/attributes/sequential_normal_attribute_encoder.h" #include "compression/attributes/sequential_quantization_attribute_encoder.h" #include "compression/point_cloud/point_cloud_encoder.h" namespace draco { SequentialAttributeEncodersController::SequentialAttributeEncodersController( std::unique_ptr sequencer) : sequencer_(std::move(sequencer)) {} SequentialAttributeEncodersController::SequentialAttributeEncodersController( std::unique_ptr sequencer, int att_id) : AttributesEncoder(att_id), sequencer_(std::move(sequencer)) {} bool SequentialAttributeEncodersController::Initialize( PointCloudEncoder *encoder, const PointCloud *pc) { if (!AttributesEncoder::Initialize(encoder, pc)) return false; if (!CreateSequentialEncoders()) return false; // Initialize all value encoders. for (int i = 0; i < num_attributes(); ++i) { const int32_t att_id = GetAttributeId(i); if (!sequential_encoders_[i]->Initialize(encoder, att_id)) return false; } return true; } bool SequentialAttributeEncodersController::EncodeAttributesEncoderData( EncoderBuffer *out_buffer) { if (!AttributesEncoder::EncodeAttributesEncoderData(out_buffer)) return false; // Encode a unique id of every sequential encoder. for (uint32_t i = 0; i < sequential_encoders_.size(); ++i) { out_buffer->Encode(sequential_encoders_[i]->GetUniqueId()); } return true; } bool SequentialAttributeEncodersController::EncodeAttributes( EncoderBuffer *buffer) { if (!sequencer_ || !sequencer_->GenerateSequence(&point_ids_)) return false; for (uint32_t i = 0; i < sequential_encoders_.size(); ++i) { if (!sequential_encoders_[i]->Encode(point_ids_, buffer)) return false; } return true; } bool SequentialAttributeEncodersController::CreateSequentialEncoders() { sequential_encoders_.resize(num_attributes()); for (int i = 0; i < num_attributes(); ++i) { sequential_encoders_[i] = CreateSequentialEncoder(i); if (sequential_encoders_[i] == nullptr) return false; } return true; } std::unique_ptr SequentialAttributeEncodersController::CreateSequentialEncoder(int i) { const int32_t att_id = GetAttributeId(i); const PointAttribute *const att = encoder()->point_cloud()->attribute(att_id); switch (att->data_type()) { case DT_UINT8: case DT_INT8: case DT_UINT16: case DT_INT16: case DT_UINT32: case DT_INT32: return std::unique_ptr( new SequentialIntegerAttributeEncoder()); case DT_FLOAT32: if (encoder()->options()->GetAttributeInt(att_id, "quantization_bits", -1) > 0) { if (att->attribute_type() == GeometryAttribute::NORMAL) { // We currently only support normals with float coordinates // and must be quantized. return std::unique_ptr( new SequentialNormalAttributeEncoder()); } else { return std::unique_ptr( new SequentialQuantizationAttributeEncoder()); } } break; default: break; } // Return the default attribute encoder. return std::unique_ptr( new SequentialAttributeEncoder()); } } // namespace draco