Differential D9642 Diff 31357 extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_encoder.cc
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_encoder.cc
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_encoder.cc.
| // Copyright 2016 The Draco Authors. | // Copyright 2016 The Draco Authors. | ||||
| // | // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | // You may obtain a copy of the License at | ||||
| // | // | ||||
| // http://www.apache.org/licenses/LICENSE-2.0 | // http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | // | ||||
| // Unless required by applicable law or agreed to in writing, software | // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | // limitations under the License. | ||||
| // | // | ||||
| #include "draco/compression/attributes/kd_tree_attributes_encoder.h" | #include "draco/compression/attributes/kd_tree_attributes_encoder.h" | ||||
| #include "draco/compression/attributes/kd_tree_attributes_shared.h" | #include "draco/compression/attributes/kd_tree_attributes_shared.h" | ||||
| #include "draco/compression/attributes/point_d_vector.h" | #include "draco/compression/attributes/point_d_vector.h" | ||||
| #include "draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h" | #include "draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h" | ||||
| #include "draco/compression/point_cloud/algorithms/float_points_tree_encoder.h" | #include "draco/compression/point_cloud/algorithms/float_points_tree_encoder.h" | ||||
| #include "draco/compression/point_cloud/point_cloud_encoder.h" | #include "draco/compression/point_cloud/point_cloud_encoder.h" | ||||
| #include "draco/core/varint_encoding.h" | #include "draco/core/varint_encoding.h" | ||||
| namespace draco { | namespace draco { | ||||
| Show All 21 Lines | for (uint32_t i = 0; i < num_attributes(); ++i) { | ||||
| const int att_id = GetAttributeId(i); | const int att_id = GetAttributeId(i); | ||||
| const PointAttribute *const att = | const PointAttribute *const att = | ||||
| encoder()->point_cloud()->attribute(att_id); | encoder()->point_cloud()->attribute(att_id); | ||||
| if (att->data_type() == DT_FLOAT32) { | if (att->data_type() == DT_FLOAT32) { | ||||
| // Quantization path. | // Quantization path. | ||||
| AttributeQuantizationTransform attribute_quantization_transform; | AttributeQuantizationTransform attribute_quantization_transform; | ||||
| const int quantization_bits = encoder()->options()->GetAttributeInt( | const int quantization_bits = encoder()->options()->GetAttributeInt( | ||||
| att_id, "quantization_bits", -1); | att_id, "quantization_bits", -1); | ||||
| if (quantization_bits < 1) | if (quantization_bits < 1) { | ||||
| return false; | return false; | ||||
| } | |||||
| if (encoder()->options()->IsAttributeOptionSet(att_id, | if (encoder()->options()->IsAttributeOptionSet(att_id, | ||||
| "quantization_origin") && | "quantization_origin") && | ||||
| encoder()->options()->IsAttributeOptionSet(att_id, | encoder()->options()->IsAttributeOptionSet(att_id, | ||||
| "quantization_range")) { | "quantization_range")) { | ||||
| // Quantization settings are explicitly specified in the provided | // Quantization settings are explicitly specified in the provided | ||||
| // options. | // options. | ||||
| std::vector<float> quantization_origin(att->num_components()); | std::vector<float> quantization_origin(att->num_components()); | ||||
| encoder()->options()->GetAttributeVector(att_id, "quantization_origin", | encoder()->options()->GetAttributeVector(att_id, "quantization_origin", | ||||
| Show All 23 Lines | if (att->data_type() == DT_FLOAT32) { | ||||
| // unsigned integers that can be processed by the core kd tree algorithm. | // unsigned integers that can be processed by the core kd tree algorithm. | ||||
| std::vector<int32_t> min_value(att->num_components(), | std::vector<int32_t> min_value(att->num_components(), | ||||
| std::numeric_limits<int32_t>::max()); | std::numeric_limits<int32_t>::max()); | ||||
| std::vector<int32_t> act_value(att->num_components()); | std::vector<int32_t> act_value(att->num_components()); | ||||
| for (AttributeValueIndex avi(0); avi < static_cast<uint32_t>(att->size()); | for (AttributeValueIndex avi(0); avi < static_cast<uint32_t>(att->size()); | ||||
| ++avi) { | ++avi) { | ||||
| att->ConvertValue<int32_t>(avi, &act_value[0]); | att->ConvertValue<int32_t>(avi, &act_value[0]); | ||||
| for (int c = 0; c < att->num_components(); ++c) { | for (int c = 0; c < att->num_components(); ++c) { | ||||
| if (min_value[c] > act_value[c]) | if (min_value[c] > act_value[c]) { | ||||
| min_value[c] = act_value[c]; | min_value[c] = act_value[c]; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| for (int c = 0; c < att->num_components(); ++c) { | for (int c = 0; c < att->num_components(); ++c) { | ||||
| min_signed_values_.push_back(min_value[c]); | min_signed_values_.push_back(min_value[c]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (att->data_type() == DT_UINT32 || att->data_type() == DT_UINT16 || | ||||
| quantized_portable_attributes_[num_processed_quantized_attributes] | quantized_portable_attributes_[num_processed_quantized_attributes] | ||||
| .get(); | .get(); | ||||
| num_processed_quantized_attributes++; | num_processed_quantized_attributes++; | ||||
| } else { | } else { | ||||
| // Unsupported data type. | // Unsupported data type. | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (source_att == nullptr) | if (source_att == nullptr) { | ||||
| return false; | return false; | ||||
| } | |||||
| // Copy source_att to the vector. | // Copy source_att to the vector. | ||||
| if (source_att->data_type() == DT_UINT32) { | if (source_att->data_type() == DT_UINT32) { | ||||
| // If the data type is the same as the one used by the point vector, we | // If the data type is the same as the one used by the point vector, we | ||||
| // can directly copy individual elements. | // can directly copy individual elements. | ||||
| for (PointIndex pi(0); pi < num_points; ++pi) { | for (PointIndex pi(0); pi < num_points; ++pi) { | ||||
| const AttributeValueIndex avi = source_att->mapped_index(pi); | const AttributeValueIndex avi = source_att->mapped_index(pi); | ||||
| const uint8_t *const att_value_address = source_att->GetAddress(avi); | const uint8_t *const att_value_address = source_att->GetAddress(avi); | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | if (data[i] > 0) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| switch (compression_level) { | switch (compression_level) { | ||||
| case 6: { | case 6: { | ||||
| DynamicIntegerPointsKdTreeEncoder<6> points_encoder(num_components_); | DynamicIntegerPointsKdTreeEncoder<6> points_encoder(num_components_); | ||||
| if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | ||||
| num_bits, out_buffer)) | num_bits, out_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 5: { | case 5: { | ||||
| DynamicIntegerPointsKdTreeEncoder<5> points_encoder(num_components_); | DynamicIntegerPointsKdTreeEncoder<5> points_encoder(num_components_); | ||||
| if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | ||||
| num_bits, out_buffer)) | num_bits, out_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 4: { | case 4: { | ||||
| DynamicIntegerPointsKdTreeEncoder<4> points_encoder(num_components_); | DynamicIntegerPointsKdTreeEncoder<4> points_encoder(num_components_); | ||||
| if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | ||||
| num_bits, out_buffer)) | num_bits, out_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 3: { | case 3: { | ||||
| DynamicIntegerPointsKdTreeEncoder<3> points_encoder(num_components_); | DynamicIntegerPointsKdTreeEncoder<3> points_encoder(num_components_); | ||||
| if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | ||||
| num_bits, out_buffer)) | num_bits, out_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 2: { | case 2: { | ||||
| DynamicIntegerPointsKdTreeEncoder<2> points_encoder(num_components_); | DynamicIntegerPointsKdTreeEncoder<2> points_encoder(num_components_); | ||||
| if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | ||||
| num_bits, out_buffer)) | num_bits, out_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 1: { | case 1: { | ||||
| DynamicIntegerPointsKdTreeEncoder<1> points_encoder(num_components_); | DynamicIntegerPointsKdTreeEncoder<1> points_encoder(num_components_); | ||||
| if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | ||||
| num_bits, out_buffer)) | num_bits, out_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| case 0: { | case 0: { | ||||
| DynamicIntegerPointsKdTreeEncoder<0> points_encoder(num_components_); | DynamicIntegerPointsKdTreeEncoder<0> points_encoder(num_components_); | ||||
| if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), | ||||
| num_bits, out_buffer)) | num_bits, out_buffer)) { | ||||
| return false; | return false; | ||||
| } | |||||
| break; | break; | ||||
| } | } | ||||
| // Compression level and/or encoding speed seem wrong. | // Compression level and/or encoding speed seem wrong. | ||||
| default: | default: | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| } // namespace draco | } // namespace draco | ||||