diff options
author | Jim Eckerlein <UX3D-eckerlein> | 2020-12-07 17:23:55 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-12-07 19:09:34 +0300 |
commit | 3012446f02781e5208e55a8c997041b782955a74 (patch) | |
tree | 18bec2f8a2311fb07542145cb44ac39e113a922a /extern | |
parent | fb82cfb539f4a33b6fa0a3b44f4833d27b9ef8ca (diff) |
glTF: update Draco library to new version
To support decoding and enhanced encoding of Draco compressed glTF files.
Differential Revision: https://developer.blender.org/D9642
Diffstat (limited to 'extern')
-rw-r--r-- | extern/draco/CMakeLists.txt | 16 | ||||
-rw-r--r-- | extern/draco/draco/AUTHORS (renamed from extern/draco/dracoenc/AUTHORS) | 0 | ||||
-rw-r--r-- | extern/draco/draco/CMakeLists.txt (renamed from extern/draco/dracoenc/CMakeLists.txt) | 107 | ||||
-rw-r--r-- | extern/draco/draco/LICENSE (renamed from extern/draco/dracoenc/LICENSE) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/animation/keyframe_animation.cc (renamed from extern/draco/dracoenc/src/draco/animation/keyframe_animation.cc) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/animation/keyframe_animation.h (renamed from extern/draco/dracoenc/src/draco/animation/keyframe_animation.h) | 17 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/animation/keyframe_animation_decoder.cc (renamed from extern/draco/dracoenc/src/draco/animation/keyframe_animation_decoder.cc) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/animation/keyframe_animation_decoder.h (renamed from extern/draco/dracoenc/src/draco/animation/keyframe_animation_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/animation/keyframe_animation_encoder.cc (renamed from extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/animation/keyframe_animation_encoder.h (renamed from extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/attribute_octahedron_transform.cc (renamed from extern/draco/dracoenc/src/draco/attributes/attribute_octahedron_transform.cc) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/attribute_octahedron_transform.h (renamed from extern/draco/dracoenc/src/draco/attributes/attribute_octahedron_transform.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/attribute_quantization_transform.cc (renamed from extern/draco/dracoenc/src/draco/attributes/attribute_quantization_transform.cc) | 19 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/attribute_quantization_transform.h (renamed from extern/draco/dracoenc/src/draco/attributes/attribute_quantization_transform.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/attribute_transform.cc (renamed from extern/draco/dracoenc/src/draco/attributes/attribute_transform.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/attribute_transform.h (renamed from extern/draco/dracoenc/src/draco/attributes/attribute_transform.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/attribute_transform_data.h (renamed from extern/draco/dracoenc/src/draco/attributes/attribute_transform_data.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/attribute_transform_type.h (renamed from extern/draco/dracoenc/src/draco/attributes/attribute_transform_type.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/geometry_attribute.cc (renamed from extern/draco/dracoenc/src/draco/attributes/geometry_attribute.cc) | 27 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/geometry_attribute.h (renamed from extern/draco/dracoenc/src/draco/attributes/geometry_attribute.h) | 37 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/geometry_indices.h (renamed from extern/draco/dracoenc/src/draco/attributes/geometry_indices.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/point_attribute.cc (renamed from extern/draco/dracoenc/src/draco/attributes/point_attribute.cc) | 30 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/attributes/point_attribute.h (renamed from extern/draco/dracoenc/src/draco/attributes/point_attribute.h) | 36 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/attributes_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder.cc) | 34 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/attributes_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder.h) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/attributes_decoder_interface.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder_interface.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/attributes_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/attributes_encoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/attributes_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/attributes_encoder.h) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_decoder.cc) | 98 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_encoder.cc) | 31 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_shared.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_shared.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/linear_sequencer.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/linear_sequencer.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/mesh_attribute_indices_encoding_data.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/mesh_attribute_indices_encoding_data.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/normal_compression_utils.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/normal_compression_utils.h) | 18 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/point_d_vector.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/point_d_vector.h) | 10 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/points_sequencer.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/points_sequencer.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h) | 16 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h) | 12 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h) | 31 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h) | 33 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h) | 13 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h) | 28 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h) | 12 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h) | 12 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.cc) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h) | 17 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h) | 13 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h) | 14 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoder.cc) | 13 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoders_controller.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoders_controller.cc) | 27 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoders_controller.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoders_controller.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoder.cc) | 12 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoders_controller.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoders_controller.cc) | 30 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoders_controller.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoders_controller.h) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_decoder.cc) | 60 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_decoder.h) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoder.cc) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_decoder.cc) | 13 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_decoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_encoder.cc) | 7 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc) | 24 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_decoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_encoder.cc) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.cc) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/direct_bit_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_decoder.cc) | 12 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/direct_bit_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/direct_bit_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_encoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/direct_bit_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/folded_integer_bit_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/folded_integer_bit_decoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/folded_integer_bit_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/folded_integer_bit_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/rans_bit_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_decoder.cc) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/rans_bit_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_decoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/rans_bit_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_encoder.cc) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/rans_bit_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_decoder.cc) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_encoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/config/compression_shared.h (renamed from extern/draco/dracoenc/src/draco/compression/config/compression_shared.h) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/config/decoder_options.h (renamed from extern/draco/dracoenc/src/draco/compression/config/decoder_options.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/config/draco_options.h (renamed from extern/draco/dracoenc/src/draco/compression/config/draco_options.h) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/config/encoder_options.h (renamed from extern/draco/dracoenc/src/draco/compression/config/encoder_options.h) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/config/encoding_features.h (renamed from extern/draco/dracoenc/src/draco/compression/config/encoding_features.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/decode.cc (renamed from extern/draco/dracoenc/src/draco/compression/decode.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/decode.h (renamed from extern/draco/dracoenc/src/draco/compression/decode.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/encode.cc (renamed from extern/draco/dracoenc/src/draco/compression/encode.cc) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/encode.h (renamed from extern/draco/dracoenc/src/draco/compression/encode.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/encode_base.h (renamed from extern/draco/dracoenc/src/draco/compression/encode_base.h) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/ans.h (renamed from extern/draco/dracoenc/src/draco/compression/entropy/ans.h) | 34 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/rans_symbol_coding.h (renamed from extern/draco/dracoenc/src/draco/compression/entropy/rans_symbol_coding.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/rans_symbol_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/entropy/rans_symbol_decoder.h) | 41 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/rans_symbol_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/entropy/rans_symbol_encoder.h) | 30 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/shannon_entropy.cc (renamed from extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy.cc) | 12 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/shannon_entropy.h (renamed from extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/symbol_decoding.cc (renamed from extern/draco/dracoenc/src/draco/compression/entropy/symbol_decoding.cc) | 30 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/symbol_decoding.h (renamed from extern/draco/dracoenc/src/draco/compression/entropy/symbol_decoding.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/symbol_encoding.cc (renamed from extern/draco/dracoenc/src/draco/compression/entropy/symbol_encoding.cc) | 18 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/entropy/symbol_encoding.h (renamed from extern/draco/dracoenc/src/draco/compression/entropy/symbol_encoding.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/expert_encode.cc (renamed from extern/draco/dracoenc/src/draco/compression/expert_encode.cc) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/expert_encode.h (renamed from extern/draco/dracoenc/src/draco/compression/expert_encode.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder.cc) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder.cc) | 7 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.cc (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.cc) | 200 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h) | 14 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder.cc) | 37 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.cc (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.cc) | 72 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_shared.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_shared.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h) | 30 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h) | 12 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h) | 30 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder.cc) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_sequential_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_decoder.cc) | 42 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_sequential_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_sequential_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_encoder.cc) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/mesh_sequential_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/traverser/depth_first_traverser.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/traverser/depth_first_traverser.h) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/traverser/max_prediction_degree_traverser.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/traverser/max_prediction_degree_traverser.h) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/traverser/mesh_traversal_sequencer.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/traverser/mesh_traversal_sequencer.h) | 11 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/mesh/traverser/traverser_base.h (renamed from extern/draco/dracoenc/src/draco/compression/mesh/traverser/traverser_base.h) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h) | 56 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h) | 18 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.cc) | 20 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h) | 24 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.h) | 41 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h) | 21 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/point_cloud_types.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/point_cloud_types.h) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/quantize_points_3.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/quantize_points_3.h) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/algorithms/queuing_policy.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/queuing_policy.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_decoder.cc) | 66 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_decoder.h) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_encoder.cc) | 63 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.cc) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.cc) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_decoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_decoder.cc) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_decoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_encoder.cc (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoder.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_encoder.h (renamed from extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/bit_utils.cc (renamed from extern/draco/dracoenc/src/draco/core/bit_utils.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/bit_utils.h (renamed from extern/draco/dracoenc/src/draco/core/bit_utils.h) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/bounding_box.cc (renamed from extern/draco/dracoenc/src/draco/core/bounding_box.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/bounding_box.h (renamed from extern/draco/dracoenc/src/draco/core/bounding_box.h) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/cycle_timer.cc (renamed from extern/draco/dracoenc/src/draco/core/cycle_timer.cc) | 4 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/cycle_timer.h (renamed from extern/draco/dracoenc/src/draco/core/cycle_timer.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/data_buffer.cc (renamed from extern/draco/dracoenc/src/draco/core/data_buffer.cc) | 13 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/data_buffer.h (renamed from extern/draco/dracoenc/src/draco/core/data_buffer.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/decoder_buffer.cc (renamed from extern/draco/dracoenc/src/draco/core/decoder_buffer.cc) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/decoder_buffer.h (renamed from extern/draco/dracoenc/src/draco/core/decoder_buffer.h) | 22 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/divide.cc (renamed from extern/draco/dracoenc/src/draco/core/divide.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/divide.h (renamed from extern/draco/dracoenc/src/draco/core/divide.h) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/draco_index_type.h (renamed from extern/draco/dracoenc/src/draco/core/draco_index_type.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/draco_index_type_vector.h (renamed from extern/draco/dracoenc/src/draco/core/draco_index_type_vector.h) | 8 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/draco_types.cc (renamed from extern/draco/dracoenc/src/draco/core/draco_types.cc) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/draco_types.h (renamed from extern/draco/dracoenc/src/draco/core/draco_types.h) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/draco_version.h (renamed from extern/draco/dracoenc/src/draco/core/draco_version.h) | 2 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/encoder_buffer.cc (renamed from extern/draco/dracoenc/src/draco/core/encoder_buffer.cc) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/encoder_buffer.h (renamed from extern/draco/dracoenc/src/draco/core/encoder_buffer.h) | 12 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/hash_utils.cc (renamed from extern/draco/dracoenc/src/draco/core/hash_utils.cc) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/hash_utils.h (renamed from extern/draco/dracoenc/src/draco/core/hash_utils.h) | 4 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/macros.h (renamed from extern/draco/dracoenc/src/draco/core/macros.h) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/math_utils.h (renamed from extern/draco/dracoenc/src/draco/core/math_utils.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/options.cc (renamed from extern/draco/dracoenc/src/draco/core/options.cc) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/options.h (renamed from extern/draco/dracoenc/src/draco/core/options.h) | 17 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/quantization_utils.cc (renamed from extern/draco/dracoenc/src/draco/core/quantization_utils.cc) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/quantization_utils.h (renamed from extern/draco/dracoenc/src/draco/core/quantization_utils.h) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/status.h (renamed from extern/draco/dracoenc/src/draco/core/status.h) | 4 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/status_or.h (renamed from extern/draco/dracoenc/src/draco/core/status_or.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/varint_decoding.h (renamed from extern/draco/dracoenc/src/draco/core/varint_decoding.h) | 53 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/varint_encoding.h (renamed from extern/draco/dracoenc/src/draco/core/varint_encoding.h) | 12 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/core/vector_d.h (renamed from extern/draco/dracoenc/src/draco/core/vector_d.h) | 60 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/draco_features.h | 10 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/corner_table.cc (renamed from extern/draco/dracoenc/src/draco/mesh/corner_table.cc) | 63 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/corner_table.h (renamed from extern/draco/dracoenc/src/draco/mesh/corner_table.h) | 59 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/corner_table_iterators.h (renamed from extern/draco/dracoenc/src/draco/mesh/corner_table_iterators.h) | 10 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh.cc (renamed from extern/draco/dracoenc/src/draco/mesh/mesh.cc) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh.h (renamed from extern/draco/dracoenc/src/draco/mesh/mesh.h) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_are_equivalent.cc (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent.cc) | 39 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_are_equivalent.h (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_attribute_corner_table.cc (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_attribute_corner_table.cc) | 21 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_attribute_corner_table.h (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_attribute_corner_table.h) | 27 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_cleanup.cc (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_cleanup.cc) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_cleanup.h (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_cleanup.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_misc_functions.cc (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_misc_functions.cc) | 13 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_misc_functions.h (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_misc_functions.h) | 28 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_stripifier.cc (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_stripifier.cc) | 9 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/mesh_stripifier.h (renamed from extern/draco/dracoenc/src/draco/mesh/mesh_stripifier.h) | 24 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/triangle_soup_mesh_builder.cc (renamed from extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder.cc) | 6 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/triangle_soup_mesh_builder.h (renamed from extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder.h) | 1 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/mesh/valence_cache.h (renamed from extern/draco/dracoenc/src/draco/mesh/valence_cache.h) | 18 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/metadata/geometry_metadata.cc (renamed from extern/draco/dracoenc/src/draco/metadata/geometry_metadata.cc) | 10 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/metadata/geometry_metadata.h (renamed from extern/draco/dracoenc/src/draco/metadata/geometry_metadata.h) | 22 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/metadata/metadata.cc (renamed from extern/draco/dracoenc/src/draco/metadata/metadata.cc) | 4 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/metadata/metadata.h (renamed from extern/draco/dracoenc/src/draco/metadata/metadata.h) | 18 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/metadata/metadata_decoder.cc (renamed from extern/draco/dracoenc/src/draco/metadata/metadata_decoder.cc) | 91 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/metadata/metadata_decoder.h (renamed from extern/draco/dracoenc/src/draco/metadata/metadata_decoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/metadata/metadata_encoder.cc (renamed from extern/draco/dracoenc/src/draco/metadata/metadata_encoder.cc) | 15 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/metadata/metadata_encoder.h (renamed from extern/draco/dracoenc/src/draco/metadata/metadata_encoder.h) | 0 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/point_cloud/point_cloud.cc (renamed from extern/draco/dracoenc/src/draco/point_cloud/point_cloud.cc) | 47 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/point_cloud/point_cloud.h (renamed from extern/draco/dracoenc/src/draco/point_cloud/point_cloud.h) | 21 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/point_cloud/point_cloud_builder.cc (renamed from extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder.cc) | 3 | ||||
-rw-r--r-- | extern/draco/draco/src/draco/point_cloud/point_cloud_builder.h (renamed from extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder.h) | 0 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/DracoConfig.cmake | 3 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/FindDraco.cmake | 58 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/compiler_flags.cmake | 216 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/compiler_tests.cmake | 124 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/draco_features.cmake | 57 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/draco_test_config.h.cmake | 13 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/draco_version.cc.cmake | 21 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/draco_version.h.cmake | 21 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/msvc_runtime.cmake | 14 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/sanitizers.cmake | 19 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/arm-ios-common.cmake | 13 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/arm64-android-ndk-libcpp.cmake | 12 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/arm64-ios.cmake | 14 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/arm64-linux-gcc.cmake | 18 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/armv7-android-ndk-libcpp.cmake | 12 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/armv7-ios.cmake | 14 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/armv7-linux-gcc.cmake | 24 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/armv7s-ios.cmake | 14 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/x86-android-ndk-libcpp.cmake | 12 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/toolchains/x86_64-android-ndk-libcpp.cmake | 12 | ||||
-rw-r--r-- | extern/draco/dracoenc/cmake/util.cmake | 73 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoding_test.cc | 168 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/animation/keyframe_animation_test.cc | 102 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/attributes/point_attribute_test.cc | 129 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/attributes/point_d_vector_test.cc | 359 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_test.cc | 192 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_test.cc | 71 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoding_test.cc | 67 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/bit_coders/rans_coding_test.cc | 9 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/config/decoder_options_test.cc | 67 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/decode_test.cc | 196 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/encode_test.cc | 293 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy_test.cc | 56 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/entropy/symbol_coding_test.cc | 170 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder_helpers.h | 84 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoding_test.cc | 247 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder_helpers.h | 81 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder_test.cc | 93 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoding_test.cc | 456 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoding_test.cc | 90 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/buffer_bit_coding_test.cc | 116 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/draco_test_base.h | 11 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/draco_test_utils.cc | 83 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/draco_test_utils.h | 70 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/draco_tests.cc | 6 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/math_utils_test.cc | 22 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/quantization_utils_test.cc | 91 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/status_test.cc | 38 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/statusor.h | 81 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/core/vector_d_test.cc | 235 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/draco_features.h | 8 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/mesh_io.cc | 69 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/mesh_io.h | 102 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/obj_decoder.cc | 689 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/obj_decoder.h | 130 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/obj_decoder_test.cc | 190 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/obj_encoder.cc | 314 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/obj_encoder.h | 92 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/obj_encoder_test.cc | 106 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/parser_utils.cc | 232 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/parser_utils.h | 64 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_decoder.cc | 295 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_decoder.h | 69 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_decoder_test.cc | 90 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_encoder.cc | 201 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_encoder.h | 54 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_property_reader.h | 96 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_property_writer.h | 94 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_reader.cc | 295 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_reader.h | 152 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/ply_reader_test.cc | 147 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/point_cloud_io.cc | 58 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/point_cloud_io.h | 89 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/io/point_cloud_io_test.cc | 115 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent_test.cc | 99 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/mesh/mesh_cleanup_test.cc | 131 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder_test.cc | 197 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/metadata/metadata_encoder_test.cc | 165 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/metadata/metadata_test.cc | 156 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder_test.cc | 171 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/point_cloud/point_cloud_test.cc | 131 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/tools/draco_decoder.cc | 178 | ||||
-rw-r--r-- | extern/draco/dracoenc/src/draco/tools/draco_encoder.cc | 373 | ||||
-rw-r--r-- | extern/draco/src/common.cpp | 77 | ||||
-rw-r--r-- | extern/draco/src/common.h | 50 | ||||
-rw-r--r-- | extern/draco/src/decoder.cpp | 222 | ||||
-rw-r--r-- | extern/draco/src/decoder.h | 53 | ||||
-rw-r--r-- | extern/draco/src/draco-compressor.cpp | 277 | ||||
-rw-r--r-- | extern/draco/src/draco-compressor.h | 173 | ||||
-rw-r--r-- | extern/draco/src/encoder.cpp | 247 | ||||
-rw-r--r-- | extern/draco/src/encoder.h | 51 |
353 files changed, 2766 insertions, 11208 deletions
diff --git a/extern/draco/CMakeLists.txt b/extern/draco/CMakeLists.txt index 6961fa8a769..d4cfeea4bee 100644 --- a/extern/draco/CMakeLists.txt +++ b/extern/draco/CMakeLists.txt @@ -19,20 +19,24 @@ # ***** END GPL LICENSE BLOCK ***** # Build Draco library. -add_subdirectory(dracoenc) +add_subdirectory(draco) -# Build blender-draco-exporter module. +# Build Draco-Blender bridging module. set(SRC - src/draco-compressor.cpp - src/draco-compressor.h + src/common.cpp + src/common.h + src/decoder.cpp + src/decoder.h + src/encoder.cpp + src/encoder.h ) set(INC - dracoenc/src + draco/src ) set(LIB - dracoenc + draco ) add_library(extern_draco SHARED "${SRC}") diff --git a/extern/draco/dracoenc/AUTHORS b/extern/draco/draco/AUTHORS index 67f63a67129..67f63a67129 100644 --- a/extern/draco/dracoenc/AUTHORS +++ b/extern/draco/draco/AUTHORS diff --git a/extern/draco/dracoenc/CMakeLists.txt b/extern/draco/draco/CMakeLists.txt index 3d33bdb74c2..6f9ffce6b48 100644 --- a/extern/draco/dracoenc/CMakeLists.txt +++ b/extern/draco/draco/CMakeLists.txt @@ -2,103 +2,165 @@ remove_strict_flags() set(SRC src/draco/animation/keyframe_animation.cc + src/draco/animation/keyframe_animation.h + src/draco/animation/keyframe_animation_decoder.cc + src/draco/animation/keyframe_animation_decoder.h src/draco/animation/keyframe_animation_encoder.cc src/draco/animation/keyframe_animation_encoder.h - src/draco/animation/keyframe_animation.h src/draco/attributes/attribute_octahedron_transform.cc src/draco/attributes/attribute_octahedron_transform.h src/draco/attributes/attribute_quantization_transform.cc src/draco/attributes/attribute_quantization_transform.h src/draco/attributes/attribute_transform.cc - src/draco/attributes/attribute_transform_data.h src/draco/attributes/attribute_transform.h + src/draco/attributes/attribute_transform_data.h src/draco/attributes/attribute_transform_type.h src/draco/attributes/geometry_attribute.cc src/draco/attributes/geometry_attribute.h src/draco/attributes/geometry_indices.h src/draco/attributes/point_attribute.cc src/draco/attributes/point_attribute.h + src/draco/compression/attributes/attributes_decoder.cc + src/draco/compression/attributes/attributes_decoder.h + src/draco/compression/attributes/attributes_decoder_interface.h src/draco/compression/attributes/attributes_encoder.cc src/draco/compression/attributes/attributes_encoder.h + src/draco/compression/attributes/kd_tree_attributes_decoder.cc + src/draco/compression/attributes/kd_tree_attributes_decoder.h src/draco/compression/attributes/kd_tree_attributes_encoder.cc src/draco/compression/attributes/kd_tree_attributes_encoder.h + src/draco/compression/attributes/kd_tree_attributes_shared.h src/draco/compression/attributes/linear_sequencer.h + src/draco/compression/attributes/mesh_attribute_indices_encoding_data.h + src/draco/compression/attributes/normal_compression_utils.h + src/draco/compression/attributes/point_d_vector.h src/draco/compression/attributes/points_sequencer.h + src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h + src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h + src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h + src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h + src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_decoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h + src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h + src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h + src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h + src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h + src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h + src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h + src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h + src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.cc src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h - src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h + src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h + src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h + src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h + src/draco/compression/attributes/sequential_attribute_decoder.cc + src/draco/compression/attributes/sequential_attribute_decoder.h + src/draco/compression/attributes/sequential_attribute_decoders_controller.cc + src/draco/compression/attributes/sequential_attribute_decoders_controller.h src/draco/compression/attributes/sequential_attribute_encoder.cc src/draco/compression/attributes/sequential_attribute_encoder.h src/draco/compression/attributes/sequential_attribute_encoders_controller.cc src/draco/compression/attributes/sequential_attribute_encoders_controller.h + src/draco/compression/attributes/sequential_integer_attribute_decoder.cc + src/draco/compression/attributes/sequential_integer_attribute_decoder.h src/draco/compression/attributes/sequential_integer_attribute_encoder.cc src/draco/compression/attributes/sequential_integer_attribute_encoder.h + src/draco/compression/attributes/sequential_normal_attribute_decoder.cc + src/draco/compression/attributes/sequential_normal_attribute_decoder.h src/draco/compression/attributes/sequential_normal_attribute_encoder.cc src/draco/compression/attributes/sequential_normal_attribute_encoder.h + src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc + src/draco/compression/attributes/sequential_quantization_attribute_decoder.h src/draco/compression/attributes/sequential_quantization_attribute_encoder.cc src/draco/compression/attributes/sequential_quantization_attribute_encoder.h src/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h + src/draco/compression/bit_coders/adaptive_rans_bit_decoder.cc + src/draco/compression/bit_coders/adaptive_rans_bit_decoder.h src/draco/compression/bit_coders/adaptive_rans_bit_encoder.cc src/draco/compression/bit_coders/adaptive_rans_bit_encoder.h + src/draco/compression/bit_coders/direct_bit_decoder.cc + src/draco/compression/bit_coders/direct_bit_decoder.h src/draco/compression/bit_coders/direct_bit_encoder.cc src/draco/compression/bit_coders/direct_bit_encoder.h + src/draco/compression/bit_coders/folded_integer_bit_decoder.h src/draco/compression/bit_coders/folded_integer_bit_encoder.h + src/draco/compression/bit_coders/rans_bit_decoder.cc + src/draco/compression/bit_coders/rans_bit_decoder.h src/draco/compression/bit_coders/rans_bit_encoder.cc src/draco/compression/bit_coders/rans_bit_encoder.h + src/draco/compression/bit_coders/symbol_bit_decoder.cc + src/draco/compression/bit_coders/symbol_bit_decoder.h src/draco/compression/bit_coders/symbol_bit_encoder.cc src/draco/compression/bit_coders/symbol_bit_encoder.h src/draco/compression/config/compression_shared.h + src/draco/compression/config/decoder_options.h src/draco/compression/config/draco_options.h src/draco/compression/config/encoder_options.h src/draco/compression/config/encoding_features.h - src/draco/compression/encode_base.h + src/draco/compression/decode.cc + src/draco/compression/decode.h src/draco/compression/encode.cc src/draco/compression/encode.h + src/draco/compression/encode_base.h src/draco/compression/entropy/ans.h src/draco/compression/entropy/rans_symbol_coding.h + src/draco/compression/entropy/rans_symbol_decoder.h src/draco/compression/entropy/rans_symbol_encoder.h src/draco/compression/entropy/shannon_entropy.cc src/draco/compression/entropy/shannon_entropy.h + src/draco/compression/entropy/symbol_decoding.cc + src/draco/compression/entropy/symbol_decoding.h src/draco/compression/entropy/symbol_encoding.cc src/draco/compression/entropy/symbol_encoding.h src/draco/compression/expert_encode.cc src/draco/compression/expert_encode.h + src/draco/compression/mesh/mesh_decoder.cc + src/draco/compression/mesh/mesh_decoder.h + src/draco/compression/mesh/mesh_edgebreaker_decoder.cc + src/draco/compression/mesh/mesh_edgebreaker_decoder.h + src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.cc + src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h + src/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h src/draco/compression/mesh/mesh_edgebreaker_encoder.cc src/draco/compression/mesh/mesh_edgebreaker_encoder.h src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.cc src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h src/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h src/draco/compression/mesh/mesh_edgebreaker_shared.h + src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h src/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h + src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h + src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h src/draco/compression/mesh/mesh_encoder.cc src/draco/compression/mesh/mesh_encoder.h - src/draco/compression/mesh/mesh_encoder_helpers.h + src/draco/compression/mesh/mesh_sequential_decoder.cc + src/draco/compression/mesh/mesh_sequential_decoder.h src/draco/compression/mesh/mesh_sequential_encoder.cc src/draco/compression/mesh/mesh_sequential_encoder.h src/draco/compression/mesh/traverser/depth_first_traverser.h @@ -106,18 +168,32 @@ set(SRC src/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h src/draco/compression/mesh/traverser/mesh_traversal_sequencer.h src/draco/compression/mesh/traverser/traverser_base.h + src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.cc + src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.cc src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h + src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.cc + src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.cc src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h + src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.cc + src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.h + src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.cc + src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h src/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h src/draco/compression/point_cloud/algorithms/point_cloud_types.h src/draco/compression/point_cloud/algorithms/quantize_points_3.h src/draco/compression/point_cloud/algorithms/queuing_policy.h + src/draco/compression/point_cloud/point_cloud_decoder.cc + src/draco/compression/point_cloud/point_cloud_decoder.h src/draco/compression/point_cloud/point_cloud_encoder.cc src/draco/compression/point_cloud/point_cloud_encoder.h + src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.cc + src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.cc src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h + src/draco/compression/point_cloud/point_cloud_sequential_decoder.cc + src/draco/compression/point_cloud/point_cloud_sequential_decoder.h src/draco/compression/point_cloud/point_cloud_sequential_encoder.cc src/draco/compression/point_cloud/point_cloud_sequential_encoder.h src/draco/core/bit_utils.cc @@ -128,12 +204,15 @@ set(SRC src/draco/core/cycle_timer.h src/draco/core/data_buffer.cc src/draco/core/data_buffer.h + src/draco/core/decoder_buffer.cc + src/draco/core/decoder_buffer.h src/draco/core/divide.cc src/draco/core/divide.h src/draco/core/draco_index_type.h src/draco/core/draco_index_type_vector.h src/draco/core/draco_types.cc src/draco/core/draco_types.h + src/draco/core/draco_version.h src/draco/core/encoder_buffer.cc src/draco/core/encoder_buffer.h src/draco/core/hash_utils.cc @@ -145,20 +224,21 @@ set(SRC src/draco/core/quantization_utils.cc src/draco/core/quantization_utils.h src/draco/core/status.h - src/draco/core/statusor.h + src/draco/core/status_or.h + src/draco/core/varint_decoding.h src/draco/core/varint_encoding.h src/draco/core/vector_d.h src/draco/mesh/corner_table.cc src/draco/mesh/corner_table.h src/draco/mesh/corner_table_iterators.h + src/draco/mesh/mesh.cc + src/draco/mesh/mesh.h src/draco/mesh/mesh_are_equivalent.cc src/draco/mesh/mesh_are_equivalent.h src/draco/mesh/mesh_attribute_corner_table.cc src/draco/mesh/mesh_attribute_corner_table.h - src/draco/mesh/mesh.cc src/draco/mesh/mesh_cleanup.cc src/draco/mesh/mesh_cleanup.h - src/draco/mesh/mesh.h src/draco/mesh/mesh_misc_functions.cc src/draco/mesh/mesh_misc_functions.h src/draco/mesh/mesh_stripifier.cc @@ -169,13 +249,15 @@ set(SRC src/draco/metadata/geometry_metadata.cc src/draco/metadata/geometry_metadata.h src/draco/metadata/metadata.cc + src/draco/metadata/metadata.h + src/draco/metadata/metadata_decoder.cc + src/draco/metadata/metadata_decoder.h src/draco/metadata/metadata_encoder.cc src/draco/metadata/metadata_encoder.h - src/draco/metadata/metadata.h - src/draco/point_cloud/point_cloud_builder.cc - src/draco/point_cloud/point_cloud_builder.h src/draco/point_cloud/point_cloud.cc src/draco/point_cloud/point_cloud.h + src/draco/point_cloud/point_cloud_builder.cc + src/draco/point_cloud/point_cloud_builder.h ) set(LIB @@ -185,4 +267,5 @@ set(INC src ) -blender_add_lib(dracoenc "${SRC}" "${INC}" "" "${LIB}") +blender_add_lib(draco "${SRC}" "${INC}" "" "${LIB}") + diff --git a/extern/draco/dracoenc/LICENSE b/extern/draco/draco/LICENSE index 7a4a3ea2424..7a4a3ea2424 100644 --- a/extern/draco/dracoenc/LICENSE +++ b/extern/draco/draco/LICENSE diff --git a/extern/draco/dracoenc/src/draco/animation/keyframe_animation.cc b/extern/draco/draco/src/draco/animation/keyframe_animation.cc index 05ae3b1184e..eaf94a3305d 100644 --- a/extern/draco/dracoenc/src/draco/animation/keyframe_animation.cc +++ b/extern/draco/draco/src/draco/animation/keyframe_animation.cc @@ -29,8 +29,9 @@ bool KeyframeAnimation::SetTimestamps( } else { // Check if the number of frames is consistent with // the existing keyframes. - if (num_frames != num_points()) + if (num_frames != num_points()) { return false; + } } } else { // This is the first attribute. @@ -40,10 +41,8 @@ bool KeyframeAnimation::SetTimestamps( // Add attribute for time stamp data. std::unique_ptr<PointAttribute> timestamp_att = std::unique_ptr<PointAttribute>(new PointAttribute()); - timestamp_att->Init(GeometryAttribute::GENERIC, nullptr, 1, DT_FLOAT32, false, - sizeof(float), 0); - timestamp_att->SetIdentityMapping(); - timestamp_att->Reset(num_frames); + timestamp_att->Init(GeometryAttribute::GENERIC, 1, DT_FLOAT32, false, + num_frames); for (PointIndex i(0); i < num_frames; ++i) { timestamp_att->SetAttributeValue(timestamp_att->mapped_index(i), ×tamp[i.value()]); diff --git a/extern/draco/dracoenc/src/draco/animation/keyframe_animation.h b/extern/draco/draco/src/draco/animation/keyframe_animation.h index 0e8b111aaea..a7afb2b81be 100644 --- a/extern/draco/dracoenc/src/draco/animation/keyframe_animation.h +++ b/extern/draco/draco/src/draco/animation/keyframe_animation.h @@ -71,30 +71,29 @@ int32_t KeyframeAnimation::AddKeyframes(DataType data_type, uint32_t num_components, const std::vector<T> &data) { // TODO(draco-eng): Verify T is consistent with |data_type|. - if (num_components == 0) + if (num_components == 0) { return -1; + } // If timestamps is not added yet, then reserve attribute 0 for timestamps. if (!num_attributes()) { // Add a temporary attribute with 0 points to fill attribute id 0. std::unique_ptr<PointAttribute> temp_att = std::unique_ptr<PointAttribute>(new PointAttribute()); - temp_att->Init(GeometryAttribute::GENERIC, nullptr, num_components, - data_type, false, DataTypeLength(data_type), 0); - temp_att->Reset(0); + temp_att->Init(GeometryAttribute::GENERIC, num_components, data_type, false, + 0); this->AddAttribute(std::move(temp_att)); set_num_frames(data.size() / num_components); } - if (data.size() != num_components * num_frames()) + if (data.size() != num_components * num_frames()) { return -1; + } std::unique_ptr<PointAttribute> keyframe_att = std::unique_ptr<PointAttribute>(new PointAttribute()); - keyframe_att->Init(GeometryAttribute::GENERIC, nullptr, num_components, - data_type, false, DataTypeLength(data_type), 0); - keyframe_att->SetIdentityMapping(); - keyframe_att->Reset(num_frames()); + keyframe_att->Init(GeometryAttribute::GENERIC, num_components, data_type, + false, num_frames()); const size_t stride = num_components; for (PointIndex i(0); i < num_frames(); ++i) { keyframe_att->SetAttributeValue(keyframe_att->mapped_index(i), diff --git a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_decoder.cc b/extern/draco/draco/src/draco/animation/keyframe_animation_decoder.cc index 8c0e71f62fa..20659468d94 100644 --- a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_decoder.cc +++ b/extern/draco/draco/src/draco/animation/keyframe_animation_decoder.cc @@ -21,8 +21,9 @@ Status KeyframeAnimationDecoder::Decode(const DecoderOptions &options, KeyframeAnimation *animation) { const auto status = PointCloudSequentialDecoder::Decode( options, in_buffer, static_cast<PointCloud *>(animation)); - if (!status.ok()) + if (!status.ok()) { return status; + } return OkStatus(); } diff --git a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_decoder.h b/extern/draco/draco/src/draco/animation/keyframe_animation_decoder.h index fdf086b3a38..fdf086b3a38 100644 --- a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_decoder.h +++ b/extern/draco/draco/src/draco/animation/keyframe_animation_decoder.h diff --git a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoder.cc b/extern/draco/draco/src/draco/animation/keyframe_animation_encoder.cc index f7d84f3106a..f7d84f3106a 100644 --- a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoder.cc +++ b/extern/draco/draco/src/draco/animation/keyframe_animation_encoder.cc diff --git a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoder.h b/extern/draco/draco/src/draco/animation/keyframe_animation_encoder.h index 6096c79fa12..6096c79fa12 100644 --- a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoder.h +++ b/extern/draco/draco/src/draco/animation/keyframe_animation_encoder.h diff --git a/extern/draco/dracoenc/src/draco/attributes/attribute_octahedron_transform.cc b/extern/draco/draco/src/draco/attributes/attribute_octahedron_transform.cc index e1180a48dda..283a21251f4 100644 --- a/extern/draco/dracoenc/src/draco/attributes/attribute_octahedron_transform.cc +++ b/extern/draco/draco/src/draco/attributes/attribute_octahedron_transform.cc @@ -25,8 +25,9 @@ bool AttributeOctahedronTransform::InitFromAttribute( const AttributeTransformData *const transform_data = attribute.GetAttributeTransformData(); if (!transform_data || - transform_data->transform_type() != ATTRIBUTE_OCTAHEDRON_TRANSFORM) + transform_data->transform_type() != ATTRIBUTE_OCTAHEDRON_TRANSFORM) { return false; // Wrong transform type. + } quantization_bits_ = transform_data->GetParameterValue<int32_t>(0); return true; } @@ -68,8 +69,9 @@ AttributeOctahedronTransform::GeneratePortableAttribute( float att_val[3]; int32_t dst_index = 0; OctahedronToolBox converter; - if (!converter.SetQuantizationBits(quantization_bits_)) + if (!converter.SetQuantizationBits(quantization_bits_)) { return nullptr; + } for (uint32_t i = 0; i < point_ids.size(); ++i) { const AttributeValueIndex att_val_id = attribute.mapped_index(point_ids[i]); attribute.GetValue(att_val_id, att_val); diff --git a/extern/draco/dracoenc/src/draco/attributes/attribute_octahedron_transform.h b/extern/draco/draco/src/draco/attributes/attribute_octahedron_transform.h index 6e4e74284f0..6e4e74284f0 100644 --- a/extern/draco/dracoenc/src/draco/attributes/attribute_octahedron_transform.h +++ b/extern/draco/draco/src/draco/attributes/attribute_octahedron_transform.h diff --git a/extern/draco/dracoenc/src/draco/attributes/attribute_quantization_transform.cc b/extern/draco/draco/src/draco/attributes/attribute_quantization_transform.cc index 237becefc61..daa634ed03f 100644 --- a/extern/draco/dracoenc/src/draco/attributes/attribute_quantization_transform.cc +++ b/extern/draco/draco/src/draco/attributes/attribute_quantization_transform.cc @@ -25,8 +25,9 @@ bool AttributeQuantizationTransform::InitFromAttribute( const AttributeTransformData *const transform_data = attribute.GetAttributeTransformData(); if (!transform_data || - transform_data->transform_type() != ATTRIBUTE_QUANTIZATION_TRANSFORM) + transform_data->transform_type() != ATTRIBUTE_QUANTIZATION_TRANSFORM) { return false; // Wrong transform type. + } int32_t byte_offset = 0; quantization_bits_ = transform_data->GetParameterValue<int32_t>(byte_offset); byte_offset += 4; @@ -80,22 +81,30 @@ bool AttributeQuantizationTransform::ComputeParameters( ++i) { attribute.GetValue(i, att_val.get()); for (int c = 0; c < num_components; ++c) { - if (min_values_[c] > att_val[c]) + if (min_values_[c] > att_val[c]) { min_values_[c] = att_val[c]; - if (max_values[c] < att_val[c]) + } + if (max_values[c] < att_val[c]) { max_values[c] = att_val[c]; + } } } for (int c = 0; c < num_components; ++c) { + if (std::isnan(min_values_[c]) || std::isinf(min_values_[c]) || + std::isnan(max_values[c]) || std::isinf(max_values[c])) { + return false; + } const float dif = max_values[c] - min_values_[c]; - if (dif > range_) + if (dif > range_) { range_ = dif; + } } // In case all values are the same, initialize the range to unit length. This // will ensure that all values are quantized properly to the same value. - if (range_ == 0.f) + if (range_ == 0.f) { range_ = 1.f; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/attributes/attribute_quantization_transform.h b/extern/draco/draco/src/draco/attributes/attribute_quantization_transform.h index 934856f2db7..934856f2db7 100644 --- a/extern/draco/dracoenc/src/draco/attributes/attribute_quantization_transform.h +++ b/extern/draco/draco/src/draco/attributes/attribute_quantization_transform.h diff --git a/extern/draco/dracoenc/src/draco/attributes/attribute_transform.cc b/extern/draco/draco/src/draco/attributes/attribute_transform.cc index 55af630ac07..55af630ac07 100644 --- a/extern/draco/dracoenc/src/draco/attributes/attribute_transform.cc +++ b/extern/draco/draco/src/draco/attributes/attribute_transform.cc diff --git a/extern/draco/dracoenc/src/draco/attributes/attribute_transform.h b/extern/draco/draco/src/draco/attributes/attribute_transform.h index d746fbf6eea..d746fbf6eea 100644 --- a/extern/draco/dracoenc/src/draco/attributes/attribute_transform.h +++ b/extern/draco/draco/src/draco/attributes/attribute_transform.h diff --git a/extern/draco/dracoenc/src/draco/attributes/attribute_transform_data.h b/extern/draco/draco/src/draco/attributes/attribute_transform_data.h index 96ed073200d..96ed073200d 100644 --- a/extern/draco/dracoenc/src/draco/attributes/attribute_transform_data.h +++ b/extern/draco/draco/src/draco/attributes/attribute_transform_data.h diff --git a/extern/draco/dracoenc/src/draco/attributes/attribute_transform_type.h b/extern/draco/draco/src/draco/attributes/attribute_transform_type.h index 51ce6f333b4..51ce6f333b4 100644 --- a/extern/draco/dracoenc/src/draco/attributes/attribute_transform_type.h +++ b/extern/draco/draco/src/draco/attributes/attribute_transform_type.h diff --git a/extern/draco/dracoenc/src/draco/attributes/geometry_attribute.cc b/extern/draco/draco/src/draco/attributes/geometry_attribute.cc index 914a85d9dc2..f7ed6a86915 100644 --- a/extern/draco/dracoenc/src/draco/attributes/geometry_attribute.cc +++ b/extern/draco/draco/src/draco/attributes/geometry_attribute.cc @@ -14,8 +14,6 @@ // #include "draco/attributes/geometry_attribute.h" -using std::array; - namespace draco { GeometryAttribute::GeometryAttribute() @@ -45,8 +43,9 @@ void GeometryAttribute::Init(GeometryAttribute::Type attribute_type, } bool GeometryAttribute::CopyFrom(const GeometryAttribute &src_att) { - if (buffer_ == nullptr || src_att.buffer_ == nullptr) + if (buffer_ == nullptr || src_att.buffer_ == nullptr) { return false; + } buffer_->Update(src_att.buffer_->data(), src_att.buffer_->data_size()); num_components_ = src_att.num_components_; data_type_ = src_att.data_type_; @@ -55,27 +54,35 @@ bool GeometryAttribute::CopyFrom(const GeometryAttribute &src_att) { byte_offset_ = src_att.byte_offset_; attribute_type_ = src_att.attribute_type_; buffer_descriptor_ = src_att.buffer_descriptor_; + unique_id_ = src_att.unique_id_; return true; } bool GeometryAttribute::operator==(const GeometryAttribute &va) const { - if (attribute_type_ != va.attribute_type_) + if (attribute_type_ != va.attribute_type_) { return false; + } // It's OK to compare just the buffer descriptors here. We don't need to // compare the buffers themselves. - if (buffer_descriptor_.buffer_id != va.buffer_descriptor_.buffer_id) + if (buffer_descriptor_.buffer_id != va.buffer_descriptor_.buffer_id) { return false; + } if (buffer_descriptor_.buffer_update_count != - va.buffer_descriptor_.buffer_update_count) + va.buffer_descriptor_.buffer_update_count) { return false; - if (num_components_ != va.num_components_) + } + if (num_components_ != va.num_components_) { return false; - if (data_type_ != va.data_type_) + } + if (data_type_ != va.data_type_) { return false; - if (byte_stride_ != va.byte_stride_) + } + if (byte_stride_ != va.byte_stride_) { return false; - if (byte_offset_ != va.byte_offset_) + } + if (byte_offset_ != va.byte_offset_) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/attributes/geometry_attribute.h b/extern/draco/draco/src/draco/attributes/geometry_attribute.h index 7be40fe2f65..b94ba8e22dd 100644 --- a/extern/draco/dracoenc/src/draco/attributes/geometry_attribute.h +++ b/extern/draco/draco/src/draco/attributes/geometry_attribute.h @@ -91,8 +91,9 @@ class GeometryAttribute { // Byte address of the attribute index. const int64_t byte_pos = byte_offset_ + byte_stride_ * att_index.value(); // Check we are not reading past end of data. - if (byte_pos + sizeof(*out) > buffer_->data_size()) + if (byte_pos + sizeof(*out) > buffer_->data_size()) { return false; + } buffer_->Read(byte_pos, &((*out)[0]), sizeof(*out)); return true; } @@ -118,6 +119,13 @@ class GeometryAttribute { buffer_->Read(byte_pos, out_data, byte_stride_); } + // Sets a value of an attribute entry. The input value must be allocated to + // cover all components of a single attribute entry. + void SetAttributeValue(AttributeValueIndex entry_index, const void *value) { + const int64_t byte_pos = entry_index.value() * byte_stride(); + buffer_->Write(byte_pos, value, byte_stride()); + } + // DEPRECATED: Use // ConvertValue(AttributeValueIndex att_id, // int out_num_components, @@ -139,8 +147,9 @@ class GeometryAttribute { template <typename OutT> bool ConvertValue(AttributeValueIndex att_id, int8_t out_num_components, OutT *out_val) const { - if (out_val == nullptr) + if (out_val == nullptr) { return false; + } switch (data_type_) { case DT_INT8: return ConvertTypedValue<int8_t, OutT>(att_id, out_num_components, @@ -191,6 +200,26 @@ class GeometryAttribute { return ConvertValue<OutT>(att_index, num_components_, out_value); } + // Utility function. Returns |attribute_type| as std::string. + static std::string TypeToString(Type attribute_type) { + switch (attribute_type) { + case INVALID: + return "INVALID"; + case POSITION: + return "POSITION"; + case NORMAL: + return "NORMAL"; + case COLOR: + return "COLOR"; + case TEX_COORD: + return "TEX_COORD"; + case GENERIC: + return "GENERIC"; + default: + return "UNKNOWN"; + } + } + bool operator==(const GeometryAttribute &va) const; // Returns the type of the attribute indicating the nature of the attribute. @@ -285,8 +314,8 @@ struct GeometryAttributeHasher { size_t hash = HashCombine(va.buffer_descriptor_.buffer_id, va.buffer_descriptor_.buffer_update_count); hash = HashCombine(va.num_components_, hash); - hash = HashCombine((int8_t)va.data_type_, hash); - hash = HashCombine((int8_t)va.attribute_type_, hash); + hash = HashCombine(static_cast<int8_t>(va.data_type_), hash); + hash = HashCombine(static_cast<int8_t>(va.attribute_type_), hash); hash = HashCombine(va.byte_stride_, hash); return HashCombine(va.byte_offset_, hash); } diff --git a/extern/draco/dracoenc/src/draco/attributes/geometry_indices.h b/extern/draco/draco/src/draco/attributes/geometry_indices.h index 80e43e30a13..80e43e30a13 100644 --- a/extern/draco/dracoenc/src/draco/attributes/geometry_indices.h +++ b/extern/draco/draco/src/draco/attributes/geometry_indices.h diff --git a/extern/draco/dracoenc/src/draco/attributes/point_attribute.cc b/extern/draco/draco/src/draco/attributes/point_attribute.cc index 0c4e8e1c738..b28f860c15d 100644 --- a/extern/draco/dracoenc/src/draco/attributes/point_attribute.cc +++ b/extern/draco/draco/src/draco/attributes/point_attribute.cc @@ -32,20 +32,32 @@ PointAttribute::PointAttribute(const GeometryAttribute &att) num_unique_entries_(0), identity_mapping_(false) {} +void PointAttribute::Init(Type attribute_type, int8_t num_components, + DataType data_type, bool normalized, + size_t num_attribute_values) { + attribute_buffer_ = std::unique_ptr<DataBuffer>(new DataBuffer()); + GeometryAttribute::Init(attribute_type, attribute_buffer_.get(), + num_components, data_type, normalized, + DataTypeLength(data_type) * num_components, 0); + Reset(num_attribute_values); + SetIdentityMapping(); +} + void PointAttribute::CopyFrom(const PointAttribute &src_att) { if (buffer() == nullptr) { // If the destination attribute doesn't have a valid buffer, create it. attribute_buffer_ = std::unique_ptr<DataBuffer>(new DataBuffer()); ResetBuffer(attribute_buffer_.get(), 0, 0); } - if (!GeometryAttribute::CopyFrom(src_att)) + if (!GeometryAttribute::CopyFrom(src_att)) { return; + } identity_mapping_ = src_att.identity_mapping_; num_unique_entries_ = src_att.num_unique_entries_; indices_map_ = src_att.indices_map_; if (src_att.attribute_transform_data_) { attribute_transform_data_ = std::unique_ptr<AttributeTransformData>( - new AttributeTransformData(*src_att.attribute_transform_data_.get())); + new AttributeTransformData(*src_att.attribute_transform_data_)); } else { attribute_transform_data_ = nullptr; } @@ -56,14 +68,20 @@ bool PointAttribute::Reset(size_t num_attribute_values) { attribute_buffer_ = std::unique_ptr<DataBuffer>(new DataBuffer()); } const int64_t entry_size = DataTypeLength(data_type()) * num_components(); - if (!attribute_buffer_->Update(nullptr, num_attribute_values * entry_size)) + if (!attribute_buffer_->Update(nullptr, num_attribute_values * entry_size)) { return false; + } // Assign the new buffer to the parent attribute. ResetBuffer(attribute_buffer_.get(), entry_size, 0); num_unique_entries_ = static_cast<uint32_t>(num_attribute_values); return true; } +void PointAttribute::Resize(size_t new_num_unique_entries) { + num_unique_entries_ = static_cast<uint32_t>(new_num_unique_entries); + attribute_buffer_->Resize(new_num_unique_entries * byte_stride()); +} + #ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED AttributeValueIndex::ValueType PointAttribute::DeduplicateValues( const GeometryAttribute &in_att) { @@ -100,8 +118,9 @@ AttributeValueIndex::ValueType PointAttribute::DeduplicateValues( default: return -1; // Unsupported data type. } - if (unique_vals == 0) + if (unique_vals == 0) { return -1; // Unexpected error. + } return unique_vals; } @@ -181,8 +200,9 @@ AttributeValueIndex::ValueType PointAttribute::DeduplicateFormattedValues( ++unique_vals; } } - if (unique_vals == num_unique_entries_) + if (unique_vals == num_unique_entries_) { return unique_vals.value(); // Nothing has changed. + } if (is_mapping_identity()) { // Change identity mapping to the explicit one. // The number of points is equal to the number of old unique values. diff --git a/extern/draco/dracoenc/src/draco/attributes/point_attribute.h b/extern/draco/draco/src/draco/attributes/point_attribute.h index 46e58a40aa1..ee36620313e 100644 --- a/extern/draco/dracoenc/src/draco/attributes/point_attribute.h +++ b/extern/draco/draco/src/draco/attributes/point_attribute.h @@ -17,13 +17,12 @@ #include <memory> -#include "draco/draco_features.h" - #include "draco/attributes/attribute_transform_data.h" #include "draco/attributes/geometry_attribute.h" #include "draco/core/draco_index_type_vector.h" #include "draco/core/hash_utils.h" #include "draco/core/macros.h" +#include "draco/draco_features.h" namespace draco { @@ -41,6 +40,12 @@ class PointAttribute : public GeometryAttribute { PointAttribute(PointAttribute &&attribute) = default; PointAttribute &operator=(PointAttribute &&attribute) = default; + // Initializes a point attribute. By default the attribute will be set to + // identity mapping between point indices and attribute values. To set custom + // mapping use SetExplicitMapping() function. + void Init(Type attribute_type, int8_t num_components, DataType data_type, + bool normalized, size_t num_attribute_values); + // Copies attribute data from the provided |src_att| attribute. void CopyFrom(const PointAttribute &src_att); @@ -49,15 +54,17 @@ class PointAttribute : public GeometryAttribute { size_t size() const { return num_unique_entries_; } AttributeValueIndex mapped_index(PointIndex point_index) const { - if (identity_mapping_) + if (identity_mapping_) { return AttributeValueIndex(point_index.value()); + } return indices_map_[point_index]; } DataBuffer *buffer() const { return attribute_buffer_.get(); } bool is_mapping_identity() const { return identity_mapping_; } size_t indices_map_size() const { - if (is_mapping_identity()) + if (is_mapping_identity()) { return 0; + } return indices_map_.size(); } @@ -65,10 +72,14 @@ class PointAttribute : public GeometryAttribute { return GetAddress(mapped_index(point_index)); } - // Sets the new number of unique attribute entries for the attribute. - void Resize(size_t new_num_unique_entries) { - num_unique_entries_ = static_cast<uint32_t>(new_num_unique_entries); - } + // Sets the new number of unique attribute entries for the attribute. The + // function resizes the attribute storage to hold |num_attribute_values| + // entries. + // All previous entries with AttributeValueIndex < |num_attribute_values| + // are preserved. Caller needs to ensure that the PointAttribute is still + // valid after the resizing operation (that is, each point is mapped to a + // valid attribute value). + void Resize(size_t new_num_unique_entries); // Functions for setting the type of mapping between point indices and // attribute entry ids. @@ -92,13 +103,6 @@ class PointAttribute : public GeometryAttribute { indices_map_[point_index] = entry_index; } - // Sets a value of an attribute entry. The input value must be allocated to - // cover all components of a single attribute entry. - void SetAttributeValue(AttributeValueIndex entry_index, const void *value) { - const int64_t byte_pos = entry_index.value() * byte_stride(); - buffer()->Write(byte_pos, value, byte_stride()); - } - // Same as GeometryAttribute::GetValue(), but using point id as the input. // Mapping to attribute value index is performed automatically. void GetMappedValue(PointIndex point_index, void *out_data) const { @@ -165,7 +169,7 @@ struct PointAttributeHasher { hash = HashCombine(attribute.identity_mapping_, hash); hash = HashCombine(attribute.num_unique_entries_, hash); hash = HashCombine(attribute.indices_map_.size(), hash); - if (attribute.indices_map_.size() > 0) { + if (!attribute.indices_map_.empty()) { const uint64_t indices_hash = FingerprintString( reinterpret_cast<const char *>(attribute.indices_map_.data()), attribute.indices_map_.size()); diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder.cc b/extern/draco/draco/src/draco/compression/attributes/attributes_decoder.cc index eb42edea06a..ce5b8b9c756 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/attributes_decoder.cc @@ -33,31 +33,42 @@ bool AttributesDecoder::DecodeAttributesDecoderData(DecoderBuffer *in_buffer) { #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (point_cloud_decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!in_buffer->Decode(&num_attributes)) + if (!in_buffer->Decode(&num_attributes)) { return false; + } } else #endif { - if (!DecodeVarint(&num_attributes, in_buffer)) + if (!DecodeVarint(&num_attributes, in_buffer)) { return false; + } } - if (num_attributes == 0) + if (num_attributes == 0) { return false; + } point_attribute_ids_.resize(num_attributes); PointCloud *pc = point_cloud_; for (uint32_t i = 0; i < num_attributes; ++i) { // Decode attribute descriptor data. uint8_t att_type, data_type, num_components, normalized; - if (!in_buffer->Decode(&att_type)) + if (!in_buffer->Decode(&att_type)) { return false; - if (!in_buffer->Decode(&data_type)) + } + if (!in_buffer->Decode(&data_type)) { return false; - if (!in_buffer->Decode(&num_components)) + } + if (!in_buffer->Decode(&num_components)) { return false; - if (!in_buffer->Decode(&normalized)) + } + if (!in_buffer->Decode(&normalized)) { return false; - if (data_type <= DT_INVALID || data_type >= DT_TYPES_COUNT) + } + if (att_type >= GeometryAttribute::NAMED_ATTRIBUTES_COUNT) { + return false; + } + if (data_type == DT_INVALID || data_type >= DT_TYPES_COUNT) { return false; + } const DataType draco_dt = static_cast<DataType>(data_type); // Add the attribute to the point cloud @@ -70,8 +81,9 @@ bool AttributesDecoder::DecodeAttributesDecoderData(DecoderBuffer *in_buffer) { if (point_cloud_decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(1, 3)) { uint16_t custom_id; - if (!in_buffer->Decode(&custom_id)) + if (!in_buffer->Decode(&custom_id)) { return false; + } // TODO(draco-eng): Add "custom_id" to attribute metadata. unique_id = static_cast<uint32_t>(custom_id); ga.set_unique_id(unique_id); @@ -87,8 +99,10 @@ bool AttributesDecoder::DecodeAttributesDecoderData(DecoderBuffer *in_buffer) { point_attribute_ids_[i] = att_id; // Update the inverse map. - if (att_id >= static_cast<int32_t>(point_attribute_to_local_id_map_.size())) + if (att_id >= + static_cast<int32_t>(point_attribute_to_local_id_map_.size())) { point_attribute_to_local_id_map_.resize(att_id + 1, -1); + } point_attribute_to_local_id_map_[att_id] = i; } return true; diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder.h b/extern/draco/draco/src/draco/compression/attributes/attributes_decoder.h index 9c6e9fe5e4d..5b2bb2cfeb2 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/attributes_decoder.h @@ -17,11 +17,10 @@ #include <vector> -#include "draco/draco_features.h" - #include "draco/compression/attributes/attributes_decoder_interface.h" #include "draco/compression/point_cloud/point_cloud_decoder.h" #include "draco/core/decoder_buffer.h" +#include "draco/draco_features.h" #include "draco/point_cloud/point_cloud.h" namespace draco { @@ -54,12 +53,15 @@ class AttributesDecoder : public AttributesDecoderInterface { // Decodes attribute data from the source buffer. bool DecodeAttributes(DecoderBuffer *in_buffer) override { - if (!DecodePortableAttributes(in_buffer)) + if (!DecodePortableAttributes(in_buffer)) { return false; - if (!DecodeDataNeededByPortableTransforms(in_buffer)) + } + if (!DecodeDataNeededByPortableTransforms(in_buffer)) { return false; - if (!TransformAttributesToOriginalFormat()) + } + if (!TransformAttributesToOriginalFormat()) { return false; + } return true; } @@ -67,8 +69,9 @@ class AttributesDecoder : public AttributesDecoderInterface { int32_t GetLocalIdForPointAttribute(int32_t point_attribute_id) const { const int id_map_size = static_cast<int>(point_attribute_to_local_id_map_.size()); - if (point_attribute_id >= id_map_size) + if (point_attribute_id >= id_map_size) { return -1; + } return point_attribute_to_local_id_map_[point_attribute_id]; } virtual bool DecodePortableAttributes(DecoderBuffer *in_buffer) = 0; diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder_interface.h b/extern/draco/draco/src/draco/compression/attributes/attributes_decoder_interface.h index 8e5cf52ac3b..8e5cf52ac3b 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_decoder_interface.h +++ b/extern/draco/draco/src/draco/compression/attributes/attributes_decoder_interface.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_encoder.cc b/extern/draco/draco/src/draco/compression/attributes/attributes_encoder.cc index 797c62f30aa..797c62f30aa 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_encoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/attributes_encoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_encoder.h b/extern/draco/draco/src/draco/compression/attributes/attributes_encoder.h index 09d10109803..9de846ae6d4 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/attributes_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/attributes_encoder.h @@ -48,15 +48,18 @@ class AttributesEncoder { // Encode attribute data to the target buffer. virtual bool EncodeAttributes(EncoderBuffer *out_buffer) { - if (!TransformAttributesToPortableFormat()) + if (!TransformAttributesToPortableFormat()) { return false; - if (!EncodePortableAttributes(out_buffer)) + } + if (!EncodePortableAttributes(out_buffer)) { return false; + } // Encode data needed by portable transforms after the attribute is encoded. // This corresponds to the order in which the data is going to be decoded by // the decoder. - if (!EncodeDataNeededByPortableTransforms(out_buffer)) + if (!EncodeDataNeededByPortableTransforms(out_buffer)) { return false; + } return true; } @@ -87,8 +90,9 @@ class AttributesEncoder { void AddAttributeId(int32_t id) { point_attribute_ids_.push_back(id); - if (id >= static_cast<int32_t>(point_attribute_to_local_id_map_.size())) + if (id >= static_cast<int32_t>(point_attribute_to_local_id_map_.size())) { point_attribute_to_local_id_map_.resize(id + 1, -1); + } point_attribute_to_local_id_map_[id] = static_cast<int32_t>(point_attribute_ids_.size()) - 1; } @@ -127,8 +131,9 @@ class AttributesEncoder { int32_t GetLocalIdForPointAttribute(int32_t point_attribute_id) const { const int id_map_size = static_cast<int>(point_attribute_to_local_id_map_.size()); - if (point_attribute_id >= id_map_size) + if (point_attribute_id >= id_map_size) { return -1; + } return point_attribute_to_local_id_map_[point_attribute_id]; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_decoder.cc b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_decoder.cc index 4faa8ab29b5..99469f94590 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_decoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_decoder.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/compression/attributes/kd_tree_attributes_decoder.h" + #include "draco/compression/attributes/kd_tree_attributes_shared.h" #include "draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h" #include "draco/compression/point_cloud/algorithms/float_points_tree_decoder.h" @@ -92,7 +93,7 @@ class PointAttributeVectorOutputIterator { const uint32_t &data_size = std::get<3>(att); const uint32_t &num_components = std::get<4>(att); const uint32_t *data_source = val.data() + offset; - if (data_size != 4) { // handle uint16_t, uint8_t + if (data_size < 4) { // handle uint16_t, uint8_t // selectively copy data bytes uint8_t *data_counter = data_; for (uint32_t index = 0; index < num_components; @@ -103,8 +104,9 @@ class PointAttributeVectorOutputIterator { data_source = reinterpret_cast<uint32_t *>(data_); } const AttributeValueIndex avi = attribute->mapped_index(point_id_); - if (avi >= static_cast<uint32_t>(attribute->size())) + if (avi >= static_cast<uint32_t>(attribute->size())) { return *this; + } attribute->SetAttributeValue(avi, data_source); } return *this; @@ -134,8 +136,9 @@ bool KdTreeAttributesDecoder::DecodePortableAttributes( return true; } uint8_t compression_level = 0; - if (!in_buffer->Decode(&compression_level)) + if (!in_buffer->Decode(&compression_level)) { return false; + } const int32_t num_points = GetDecoder()->point_cloud()->num_points(); // Decode data using the kd tree decoding into integer (portable) attributes. @@ -197,44 +200,51 @@ bool KdTreeAttributesDecoder::DecodePortableAttributes( switch (compression_level) { case 0: { DynamicIntegerPointsKdTreeDecoder<0> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 1: { DynamicIntegerPointsKdTreeDecoder<1> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 2: { DynamicIntegerPointsKdTreeDecoder<2> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 3: { DynamicIntegerPointsKdTreeDecoder<3> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 4: { DynamicIntegerPointsKdTreeDecoder<4> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 5: { DynamicIntegerPointsKdTreeDecoder<5> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 6: { DynamicIntegerPointsKdTreeDecoder<6> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } default: @@ -256,22 +266,26 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms( if (att->data_type() == DT_FLOAT32) { const int num_components = att->num_components(); min_value.resize(num_components); - if (!in_buffer->Decode(&min_value[0], sizeof(float) * num_components)) + if (!in_buffer->Decode(&min_value[0], sizeof(float) * num_components)) { return false; + } float max_value_dif; - if (!in_buffer->Decode(&max_value_dif)) + if (!in_buffer->Decode(&max_value_dif)) { return false; + } uint8_t quantization_bits; - if (!in_buffer->Decode(&quantization_bits) || quantization_bits > 31) + if (!in_buffer->Decode(&quantization_bits) || quantization_bits > 31) { return false; + } AttributeQuantizationTransform transform; transform.SetParameters(quantization_bits, min_value.data(), num_components, max_value_dif); const int num_transforms = static_cast<int>(attribute_quantization_transforms_.size()); if (!transform.TransferToAttribute( - quantized_portable_attributes_[num_transforms].get())) + quantized_portable_attributes_[num_transforms].get())) { return false; + } attribute_quantization_transforms_.push_back(transform); } } @@ -299,6 +313,10 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms( const DataType data_type = att->data_type(); const uint32_t data_size = (std::max)(0, DataTypeLength(data_type)); const uint32_t num_components = att->num_components(); + if (data_size > 4) { + return false; + } + atts[attribute_index] = std::make_tuple( att, total_dimensionality, data_type, data_size, num_components); // everything is treated as 32bit in the encoder. @@ -310,24 +328,30 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms( att->SetIdentityMapping(); // Decode method uint8_t method; - if (!in_buffer->Decode(&method)) + if (!in_buffer->Decode(&method)) { return false; + } if (method == KdTreeAttributesEncodingMethod::kKdTreeQuantizationEncoding) { uint8_t compression_level = 0; - if (!in_buffer->Decode(&compression_level)) + if (!in_buffer->Decode(&compression_level)) { return false; + } uint32_t num_points = 0; - if (!in_buffer->Decode(&num_points)) + if (!in_buffer->Decode(&num_points)) { return false; + } att->Reset(num_points); FloatPointsTreeDecoder decoder; + decoder.set_num_points_from_header(num_points); PointAttributeVectorOutputIterator<float> out_it(atts); - if (!decoder.DecodePointCloud(in_buffer, out_it)) + if (!decoder.DecodePointCloud(in_buffer, out_it)) { return false; + } } else if (method == KdTreeAttributesEncodingMethod::kKdTreeIntegerEncoding) { uint8_t compression_level = 0; - if (!in_buffer->Decode(&compression_level)) + if (!in_buffer->Decode(&compression_level)) { return false; + } if (6 < compression_level) { LOGE("KdTreeAttributesDecoder: compression level %i not supported.\n", compression_level); @@ -335,8 +359,9 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms( } uint32_t num_points; - if (!in_buffer->Decode(&num_points)) + if (!in_buffer->Decode(&num_points)) { return false; + } for (auto attribute_index = 0; static_cast<uint32_t>(attribute_index) < attribute_count; @@ -353,44 +378,51 @@ bool KdTreeAttributesDecoder::DecodeDataNeededByPortableTransforms( switch (compression_level) { case 0: { DynamicIntegerPointsKdTreeDecoder<0> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 1: { DynamicIntegerPointsKdTreeDecoder<1> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 2: { DynamicIntegerPointsKdTreeDecoder<2> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 3: { DynamicIntegerPointsKdTreeDecoder<3> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 4: { DynamicIntegerPointsKdTreeDecoder<4> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 5: { DynamicIntegerPointsKdTreeDecoder<5> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } case 6: { DynamicIntegerPointsKdTreeDecoder<6> decoder(total_dimensionality); - if (!decoder.DecodePoints(in_buffer, out_it)) + if (!decoder.DecodePoints(in_buffer, out_it)) { return false; + } break; } default: @@ -445,16 +477,19 @@ bool KdTreeAttributesDecoder::TransformAttributesToOriginalFormat() { // Values are stored as unsigned in the attribute, make them signed again. if (att->data_type() == DT_INT32) { if (!TransformAttributeBackToSignedType<int32_t>( - att, num_processed_signed_components)) + att, num_processed_signed_components)) { return false; + } } else if (att->data_type() == DT_INT16) { if (!TransformAttributeBackToSignedType<int16_t>( - att, num_processed_signed_components)) + att, num_processed_signed_components)) { return false; + } } else if (att->data_type() == DT_INT8) { if (!TransformAttributeBackToSignedType<int8_t>( - att, num_processed_signed_components)) + att, num_processed_signed_components)) { return false; + } } num_processed_signed_components += att->num_components(); } else if (att->data_type() == DT_FLOAT32) { @@ -491,8 +526,9 @@ bool KdTreeAttributesDecoder::TransformAttributesToOriginalFormat() { int quant_val_id = 0; int out_byte_pos = 0; Dequantizer dequantizer; - if (!dequantizer.Init(transform.range(), max_quantized_value)) + if (!dequantizer.Init(transform.range(), max_quantized_value)) { return false; + } const uint32_t *const portable_attribute_data = reinterpret_cast<const uint32_t *>( src_att->GetAddress(AttributeValueIndex(0))); diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_decoder.h b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_decoder.h index 87338d6b0d4..87338d6b0d4 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_encoder.cc b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_encoder.cc index f2a8af23bfc..0f9c31565e5 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_encoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_encoder.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/compression/attributes/kd_tree_attributes_encoder.h" + #include "draco/compression/attributes/kd_tree_attributes_shared.h" #include "draco/compression/attributes/point_d_vector.h" #include "draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h" @@ -50,8 +51,9 @@ bool KdTreeAttributesEncoder::TransformAttributesToPortableFormat() { AttributeQuantizationTransform attribute_quantization_transform; const int quantization_bits = encoder()->options()->GetAttributeInt( att_id, "quantization_bits", -1); - if (quantization_bits < 1) + if (quantization_bits < 1) { return false; + } if (encoder()->options()->IsAttributeOptionSet(att_id, "quantization_origin") && encoder()->options()->IsAttributeOptionSet(att_id, @@ -91,8 +93,9 @@ bool KdTreeAttributesEncoder::TransformAttributesToPortableFormat() { ++avi) { att->ConvertValue<int32_t>(avi, &act_value[0]); 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]; + } } } for (int c = 0; c < att->num_components(); ++c) { @@ -167,8 +170,9 @@ bool KdTreeAttributesEncoder::EncodePortableAttributes( return false; } - if (source_att == nullptr) + if (source_att == nullptr) { return false; + } // Copy source_att to the vector. if (source_att->data_type() == DT_UINT32) { @@ -233,50 +237,57 @@ bool KdTreeAttributesEncoder::EncodePortableAttributes( case 6: { DynamicIntegerPointsKdTreeEncoder<6> points_encoder(num_components_); if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), - num_bits, out_buffer)) + num_bits, out_buffer)) { return false; + } break; } case 5: { DynamicIntegerPointsKdTreeEncoder<5> points_encoder(num_components_); if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), - num_bits, out_buffer)) + num_bits, out_buffer)) { return false; + } break; } case 4: { DynamicIntegerPointsKdTreeEncoder<4> points_encoder(num_components_); if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), - num_bits, out_buffer)) + num_bits, out_buffer)) { return false; + } break; } case 3: { DynamicIntegerPointsKdTreeEncoder<3> points_encoder(num_components_); if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), - num_bits, out_buffer)) + num_bits, out_buffer)) { return false; + } break; } case 2: { DynamicIntegerPointsKdTreeEncoder<2> points_encoder(num_components_); if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), - num_bits, out_buffer)) + num_bits, out_buffer)) { return false; + } break; } case 1: { DynamicIntegerPointsKdTreeEncoder<1> points_encoder(num_components_); if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), - num_bits, out_buffer)) + num_bits, out_buffer)) { return false; + } break; } case 0: { DynamicIntegerPointsKdTreeEncoder<0> points_encoder(num_components_); if (!points_encoder.EncodePoints(point_vector.begin(), point_vector.end(), - num_bits, out_buffer)) + num_bits, out_buffer)) { return false; + } break; } // Compression level and/or encoding speed seem wrong. diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_encoder.h b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_encoder.h index 8b4c4e2faab..8b4c4e2faab 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_shared.h b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_shared.h index 94841a91d99..94841a91d99 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/kd_tree_attributes_shared.h +++ b/extern/draco/draco/src/draco/compression/attributes/kd_tree_attributes_shared.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/linear_sequencer.h b/extern/draco/draco/src/draco/compression/attributes/linear_sequencer.h index dc4dfffe9d5..7d9b5264199 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/linear_sequencer.h +++ b/extern/draco/draco/src/draco/compression/attributes/linear_sequencer.h @@ -32,8 +32,9 @@ class LinearSequencer : public PointsSequencer { protected: bool GenerateSequenceInternal() override { - if (num_points_ < 0) + if (num_points_ < 0) { return false; + } out_point_ids()->resize(num_points_); for (int i = 0; i < num_points_; ++i) { out_point_ids()->at(i) = PointIndex(i); diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/mesh_attribute_indices_encoding_data.h b/extern/draco/draco/src/draco/compression/attributes/mesh_attribute_indices_encoding_data.h index 9a358e44733..9a358e44733 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/mesh_attribute_indices_encoding_data.h +++ b/extern/draco/draco/src/draco/compression/attributes/mesh_attribute_indices_encoding_data.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/normal_compression_utils.h b/extern/draco/draco/src/draco/compression/attributes/normal_compression_utils.h index 4e6ff1a2134..32e27c711e3 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/normal_compression_utils.h +++ b/extern/draco/draco/src/draco/compression/attributes/normal_compression_utils.h @@ -39,6 +39,7 @@ #define DRACO_COMPRESSION_ATTRIBUTES_NORMAL_COMPRESSION_UTILS_H_ #include <inttypes.h> + #include <algorithm> #include <cmath> @@ -55,8 +56,9 @@ class OctahedronToolBox { center_value_(-1) {} bool SetQuantizationBits(int32_t q) { - if (q < 2 || q > 30) + if (q < 2 || q > 30) { return false; + } quantization_bits_ = q; max_quantized_value_ = (1 << quantization_bits_) - 1; max_value_ = max_quantized_value_ - 1; @@ -157,8 +159,9 @@ class OctahedronToolBox { int_vec[2] = 0; } // Take care of the sign. - if (scaled_vector[2] < 0) + if (scaled_vector[2] < 0) { int_vec[2] *= -1; + } IntegerVectorToQuantizedOctahedralCoords(int_vec, out_s, out_t); } @@ -189,6 +192,8 @@ class OctahedronToolBox { } } + // TODO(b/149328891): Change function to not use templates as |T| is only + // float. template <typename T> void OctaherdalCoordsToUnitVector(T in_s, T in_t, T *out_vector) const { DRACO_DCHECK_GE(in_s, 0); @@ -304,18 +309,21 @@ class OctahedronToolBox { // For correction values. int32_t ModMax(int32_t x) const { - if (x > this->center_value()) + if (x > this->center_value()) { return x - this->max_quantized_value(); - if (x < -this->center_value()) + } + if (x < -this->center_value()) { return x + this->max_quantized_value(); + } return x; } // For correction values. int32_t MakePositive(int32_t x) const { DRACO_DCHECK_LE(x, this->center_value() * 2); - if (x < 0) + if (x < 0) { return x + this->max_quantized_value(); + } return x; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/point_d_vector.h b/extern/draco/draco/src/draco/compression/attributes/point_d_vector.h index ce99c8014d7..3b115d500cd 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/point_d_vector.h +++ b/extern/draco/draco/src/draco/compression/attributes/point_d_vector.h @@ -19,6 +19,7 @@ #include <cstring> #include <memory> #include <vector> + #include "draco/core/macros.h" namespace draco { @@ -42,8 +43,9 @@ class PseudoPointD { // Specifically copies referenced memory void swap(PseudoPointD &other) noexcept { - for (internal_t dim = 0; dim < dimension_; dim += 1) + for (internal_t dim = 0; dim < dimension_; dim += 1) { std::swap(mem_[dim], other.mem_[dim]); + } } PseudoPointD(const PseudoPointD &other) @@ -59,9 +61,11 @@ class PseudoPointD { } bool operator==(const PseudoPointD &other) const { - for (auto dim = 0; dim < dimension_; dim += 1) - if (mem_[dim] != other.mem_[dim]) + for (auto dim = 0; dim < dimension_; dim += 1) { + if (mem_[dim] != other.mem_[dim]) { return false; + } + } return true; } bool operator!=(const PseudoPointD &other) const { diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/points_sequencer.h b/extern/draco/draco/src/draco/compression/attributes/points_sequencer.h index 2f4f7e16d11..2f4f7e16d11 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/points_sequencer.h +++ b/extern/draco/draco/src/draco/compression/attributes/points_sequencer.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h index b64b23d25de..36c124baa83 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h @@ -18,13 +18,12 @@ #include <algorithm> #include <cmath> -#include "draco/draco_features.h" - #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h" #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h" #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h" #include "draco/compression/bit_coders/rans_bit_decoder.h" #include "draco/core/varint_decoding.h" +#include "draco/draco_features.h" namespace draco { @@ -123,8 +122,9 @@ bool MeshPredictionSchemeConstrainedMultiParallelogramDecoder< ++num_parallelograms; // Stop processing when we reach the maximum number of allowed // parallelograms. - if (num_parallelograms == kMaxNumParallelograms) + if (num_parallelograms == kMaxNumParallelograms) { break; + } } // Proceed to the next corner attached to the vertex. First swing left @@ -154,8 +154,9 @@ bool MeshPredictionSchemeConstrainedMultiParallelogramDecoder< for (int i = 0; i < num_parallelograms; ++i) { const int context = num_parallelograms - 1; const int pos = is_crease_edge_pos[context]++; - if (is_crease_edge_[context].size() <= pos) + if (is_crease_edge_[context].size() <= pos) { return false; + } const bool is_crease = is_crease_edge_[context][pos]; if (!is_crease) { ++num_used_parallelograms; @@ -206,12 +207,15 @@ bool MeshPredictionSchemeConstrainedMultiParallelogramDecoder< // Encode selected edges using separate rans bit coder for each context. for (int i = 0; i < kMaxNumParallelograms; ++i) { uint32_t num_flags; - DecodeVarint<uint32_t>(&num_flags, buffer); + if (!DecodeVarint<uint32_t>(&num_flags, buffer)) { + return false; + } if (num_flags > 0) { is_crease_edge_[i].resize(num_flags); RAnsBitDecoder decoder; - if (!decoder.StartDecoding(buffer)) + if (!decoder.StartDecoding(buffer)) { return false; + } for (uint32_t j = 0; j < num_flags; ++j) { is_crease_edge_[i][j] = decoder.DecodeNextBit(); } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h index 455c2ceb5ed..77df8ee24f1 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_encoder.h @@ -108,10 +108,12 @@ class MeshPredictionSchemeConstrainedMultiParallelogramEncoder int residual_error; bool operator<(const Error &e) const { - if (num_bits < e.num_bits) + if (num_bits < e.num_bits) { return true; - if (num_bits > e.num_bits) + } + if (num_bits > e.num_bits) { return false; + } return residual_error < e.residual_error; } }; @@ -231,8 +233,9 @@ bool MeshPredictionSchemeConstrainedMultiParallelogramEncoder< ++num_parallelograms; // Stop processing when we reach the maximum number of allowed // parallelograms. - if (num_parallelograms == kMaxNumParallelograms) + if (num_parallelograms == kMaxNumParallelograms) { break; + } } // Proceed to the next corner attached to the vertex. First swing left @@ -304,8 +307,9 @@ bool MeshPredictionSchemeConstrainedMultiParallelogramEncoder< } uint8_t configuration = 0; for (int j = 0; j < num_parallelograms; ++j) { - if (exluded_parallelograms[j]) + if (exluded_parallelograms[j]) { continue; + } for (int c = 0; c < num_components; ++c) { multi_pred_vals[c] += pred_vals[j][c]; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h index c7a4e351aeb..c7a4e351aeb 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_shared.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h index f712952556a..f712952556a 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_data.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h index 6694a981c10..6694a981c10 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h index ab3c81a3901..ab3c81a3901 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h index cd8299627b7..da1387a3075 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h @@ -15,11 +15,10 @@ #ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_GEOMETRIC_NORMAL_DECODER_H_ #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_GEOMETRIC_NORMAL_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h" #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h" #include "draco/compression/bit_coders/rans_bit_decoder.h" +#include "draco/draco_features.h" namespace draco { @@ -52,12 +51,15 @@ class MeshPredictionSchemeGeometricNormalDecoder } bool IsInitialized() const override { - if (!predictor_.IsInitialized()) + if (!predictor_.IsInitialized()) { return false; - if (!this->mesh_data().IsInitialized()) + } + if (!this->mesh_data().IsInitialized()) { return false; - if (!octahedron_tool_box_.IsInitialized()) + } + if (!octahedron_tool_box_.IsInitialized()) { return false; + } return true; } @@ -70,10 +72,12 @@ class MeshPredictionSchemeGeometricNormalDecoder } bool SetParentAttribute(const PointAttribute *att) override { - if (att->attribute_type() != GeometryAttribute::POSITION) + if (att->attribute_type() != GeometryAttribute::POSITION) { return false; // Invalid attribute type. - if (att->num_components() != 3) + } + if (att->num_components() != 3) { return false; // Currently works only for 3 component positions. + } predictor_.SetPositionAttribute(*att); return true; } @@ -137,23 +141,28 @@ bool MeshPredictionSchemeGeometricNormalDecoder< DataTypeT, TransformT, MeshDataT>::DecodePredictionData(DecoderBuffer *buffer) { // Get data needed for transform - if (!this->transform().DecodeTransformData(buffer)) + if (!this->transform().DecodeTransformData(buffer)) { return false; + } #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { uint8_t prediction_mode; - buffer->Decode(&prediction_mode); + if (!buffer->Decode(&prediction_mode)) { + return false; + } if (!predictor_.SetNormalPredictionMode( - NormalPredictionMode(prediction_mode))) + NormalPredictionMode(prediction_mode))) { return false; + } } #endif // Init normal flips. - if (!flip_normal_bit_decoder_.StartDecoding(buffer)) + if (!flip_normal_bit_decoder_.StartDecoding(buffer)) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h index ffddf0170d6..cf146f83ac9 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_encoder.h @@ -50,10 +50,12 @@ class MeshPredictionSchemeGeometricNormalEncoder } bool IsInitialized() const override { - if (!predictor_.IsInitialized()) + if (!predictor_.IsInitialized()) { return false; - if (!this->mesh_data().IsInitialized()) + } + if (!this->mesh_data().IsInitialized()) { return false; + } return true; } @@ -66,10 +68,12 @@ class MeshPredictionSchemeGeometricNormalEncoder } bool SetParentAttribute(const PointAttribute *att) override { - if (att->attribute_type() != GeometryAttribute::POSITION) + if (att->attribute_type() != GeometryAttribute::POSITION) { return false; // Invalid attribute type. - if (att->num_components() != 3) + } + if (att->num_components() != 3) { return false; // Currently works only for 3 component positions. + } predictor_.SetPositionAttribute(*att); return true; } @@ -162,8 +166,9 @@ template <typename DataTypeT, class TransformT, class MeshDataT> bool MeshPredictionSchemeGeometricNormalEncoder< DataTypeT, TransformT, MeshDataT>::EncodePredictionData(EncoderBuffer *buffer) { - if (!this->transform().EncodeTransformData(buffer)) + if (!this->transform().EncodeTransformData(buffer)) { return false; + } // Encode normal flips. flip_normal_bit_encoder_.EndEncoding(buffer); diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h index bf1a6146111..bf1a6146111 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_area.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h index 9a26551decf..a554dda9676 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_predictor_base.h @@ -45,10 +45,12 @@ class MeshPredictionSchemeGeometricNormalPredictorBase { entry_to_point_id_map_ = map; } bool IsInitialized() const { - if (pos_attribute_ == nullptr) + if (pos_attribute_ == nullptr) { return false; - if (entry_to_point_id_map_ == nullptr) + } + if (entry_to_point_id_map_ == nullptr) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h index a0cc802da03..fc82e0a8f76 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_decoder.h @@ -16,10 +16,9 @@ #ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_MULTI_PARALLELOGRAM_DECODER_H_ #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_MULTI_PARALLELOGRAM_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h" #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h" +#include "draco/draco_features.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h index 301b357d411..301b357d411 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_multi_parallelogram_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_decoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_decoder.h index 4d47ddf306e..4d47ddf306e 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h index f00801932c2..f00801932c2 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h index c63c8d05ba6..485d457ccf6 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_parallelogram_shared.h @@ -47,8 +47,9 @@ inline bool ComputeParallelogramPrediction( const std::vector<int32_t> &vertex_to_data_map, const DataTypeT *in_data, int num_components, DataTypeT *out_prediction) { const CornerIndex oci = table->Opposite(ci); - if (oci == kInvalidCornerIndex) + if (oci == kInvalidCornerIndex) { return false; + } int vert_opp, vert_next, vert_prev; GetParallelogramEntries<CornerTableT>(oci, table, vertex_to_data_map, &vert_opp, &vert_next, &vert_prev); diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h index 2e389b2a2b4..02cf7e60f26 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_decoder.h @@ -18,12 +18,11 @@ #include <math.h> -#include "draco/draco_features.h" - #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_decoder.h" #include "draco/compression/bit_coders/rans_bit_decoder.h" #include "draco/core/varint_decoding.h" #include "draco/core/vector_d.h" +#include "draco/draco_features.h" #include "draco/mesh/corner_table.h" namespace draco { @@ -60,10 +59,12 @@ class MeshPredictionSchemeTexCoordsDecoder } bool IsInitialized() const override { - if (pos_attribute_ == nullptr) + if (pos_attribute_ == nullptr) { return false; - if (!this->mesh_data().IsInitialized()) + } + if (!this->mesh_data().IsInitialized()) { return false; + } return true; } @@ -76,12 +77,15 @@ class MeshPredictionSchemeTexCoordsDecoder } bool SetParentAttribute(const PointAttribute *att) override { - if (att == nullptr) + if (att == nullptr) { return false; - if (att->attribute_type() != GeometryAttribute::POSITION) + } + if (att->attribute_type() != GeometryAttribute::POSITION) { return false; // Invalid attribute type. - if (att->num_components() != 3) + } + if (att->num_components() != 3) { return false; // Currently works only for 3 component positions. + } pos_attribute_ = att; return true; } @@ -144,22 +148,27 @@ bool MeshPredictionSchemeTexCoordsDecoder<DataTypeT, TransformT, MeshDataT>:: // Decode the delta coded orientations. uint32_t num_orientations = 0; if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { - if (!buffer->Decode(&num_orientations)) + if (!buffer->Decode(&num_orientations)) { return false; + } } else { - if (!DecodeVarint(&num_orientations, buffer)) + if (!DecodeVarint(&num_orientations, buffer)) { return false; + } } - if (num_orientations == 0) + if (num_orientations == 0) { return false; + } orientations_.resize(num_orientations); bool last_orientation = true; RAnsBitDecoder decoder; - if (!decoder.StartDecoding(buffer)) + if (!decoder.StartDecoding(buffer)) { return false; + } for (uint32_t i = 0; i < num_orientations; ++i) { - if (!decoder.DecodeNextBit()) + if (!decoder.DecodeNextBit()) { last_orientation = !last_orientation; + } orientations_[i] = last_orientation; } decoder.EndDecoding(); diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h index 0e938b9c388..813b72ae35f 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_encoder.h @@ -16,6 +16,7 @@ #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_ENCODER_H_ #include <math.h> + #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_encoder.h" #include "draco/compression/bit_coders/rans_bit_encoder.h" #include "draco/core/varint_encoding.h" @@ -55,10 +56,12 @@ class MeshPredictionSchemeTexCoordsEncoder } bool IsInitialized() const override { - if (pos_attribute_ == nullptr) + if (pos_attribute_ == nullptr) { return false; - if (!this->mesh_data().IsInitialized()) + } + if (!this->mesh_data().IsInitialized()) { return false; + } return true; } @@ -71,10 +74,12 @@ class MeshPredictionSchemeTexCoordsEncoder } bool SetParentAttribute(const PointAttribute *att) override { - if (att->attribute_type() != GeometryAttribute::POSITION) + if (att->attribute_type() != GeometryAttribute::POSITION) { return false; // Invalid attribute type. - if (att->num_components() != 3) + } + if (att->num_components() != 3) { return false; // Currently works only for 3 component positions. + } pos_attribute_ = att; return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h index 0fee0ceb6e2..83d4966393f 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_decoder.h @@ -48,10 +48,12 @@ class MeshPredictionSchemeTexCoordsPortableDecoder } bool IsInitialized() const override { - if (!predictor_.IsInitialized()) + if (!predictor_.IsInitialized()) { return false; - if (!this->mesh_data().IsInitialized()) + } + if (!this->mesh_data().IsInitialized()) { return false; + } return true; } @@ -64,10 +66,12 @@ class MeshPredictionSchemeTexCoordsPortableDecoder } bool SetParentAttribute(const PointAttribute *att) override { - if (!att || att->attribute_type() != GeometryAttribute::POSITION) + if (!att || att->attribute_type() != GeometryAttribute::POSITION) { return false; // Invalid attribute type. - if (att->num_components() != 3) + } + if (att->num_components() != 3) { return false; // Currently works only for 3 component positions. + } predictor_.SetPositionAttribute(*att); return true; } @@ -84,6 +88,10 @@ bool MeshPredictionSchemeTexCoordsPortableDecoder< DataTypeT *out_data, int /* size */, int num_components, const PointIndex *entry_to_point_id_map) { + if (num_components != MeshPredictionSchemeTexCoordsPortablePredictor< + DataTypeT, MeshDataT>::kNumComponents) { + return false; + } predictor_.SetEntryToPointIdMap(entry_to_point_id_map); this->transform().Init(num_components); @@ -92,8 +100,9 @@ bool MeshPredictionSchemeTexCoordsPortableDecoder< for (int p = 0; p < corner_map_size; ++p) { const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p); if (!predictor_.template ComputePredictedValue<false>(corner_id, out_data, - p)) + p)) { return false; + } const int dst_offset = p * num_components; this->transform().ComputeOriginalValue(predictor_.predicted_value(), @@ -109,16 +118,19 @@ bool MeshPredictionSchemeTexCoordsPortableDecoder< *buffer) { // Decode the delta coded orientations. int32_t num_orientations = 0; - if (!buffer->Decode(&num_orientations) || num_orientations < 0) + if (!buffer->Decode(&num_orientations) || num_orientations < 0) { return false; + } predictor_.ResizeOrientations(num_orientations); bool last_orientation = true; RAnsBitDecoder decoder; - if (!decoder.StartDecoding(buffer)) + if (!decoder.StartDecoding(buffer)) { return false; + } for (int i = 0; i < num_orientations; ++i) { - if (!decoder.DecodeNextBit()) + if (!decoder.DecodeNextBit()) { last_orientation = !last_orientation; + } predictor_.set_orientation(i, last_orientation); } decoder.EndDecoding(); diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h index 04a66325183..741ec66dc2a 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_encoder.h @@ -51,10 +51,12 @@ class MeshPredictionSchemeTexCoordsPortableEncoder } bool IsInitialized() const override { - if (!predictor_.IsInitialized()) + if (!predictor_.IsInitialized()) { return false; - if (!this->mesh_data().IsInitialized()) + } + if (!this->mesh_data().IsInitialized()) { return false; + } return true; } @@ -67,10 +69,12 @@ class MeshPredictionSchemeTexCoordsPortableEncoder } bool SetParentAttribute(const PointAttribute *att) override { - if (att->attribute_type() != GeometryAttribute::POSITION) + if (att->attribute_type() != GeometryAttribute::POSITION) { return false; // Invalid attribute type. - if (att->num_components() != 3) + } + if (att->num_components() != 3) { return false; // Currently works only for 3 component positions. + } predictor_.SetPositionAttribute(*att); return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h index f9357712638..5d8a5060133 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_tex_coords_portable_predictor.h @@ -16,6 +16,7 @@ #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_PREDICTOR_H_ #include <math.h> + #include "draco/attributes/point_attribute.h" #include "draco/core/math_utils.h" #include "draco/core/vector_d.h" @@ -28,6 +29,8 @@ namespace draco { template <typename DataTypeT, class MeshDataT> class MeshPredictionSchemeTexCoordsPortablePredictor { public: + static constexpr int kNumComponents = 2; + explicit MeshPredictionSchemeTexCoordsPortablePredictor(const MeshDataT &md) : pos_attribute_(nullptr), entry_to_point_id_map_(nullptr), @@ -71,7 +74,6 @@ class MeshPredictionSchemeTexCoordsPortablePredictor { private: const PointAttribute *pos_attribute_; const PointIndex *entry_to_point_id_map_; - static constexpr int kNumComponents = 2; DataTypeT predicted_value_[kNumComponents]; // Encoded / decoded array of UV flips. // TODO(ostava): We should remove this and replace this with in-place encoding @@ -203,14 +205,16 @@ bool MeshPredictionSchemeTexCoordsPortablePredictor< } } else { // When decoding the data, we already know which orientation to use. - if (orientations_.empty()) + if (orientations_.empty()) { return false; + } const bool orientation = orientations_.back(); orientations_.pop_back(); - if (orientation) + if (orientation) { predicted_uv = (x_uv + cx_uv) / pn_norm2_squared; - else + } else { predicted_uv = (x_uv - cx_uv) / pn_norm2_squared; + } } predicted_value_[0] = static_cast<int>(predicted_uv[0]); predicted_value_[1] = static_cast<int>(predicted_uv[1]); diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h index 9a14ff8d7d2..064e1b44fe1 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h @@ -46,8 +46,9 @@ class PredictionSchemeDecoder : public PredictionSchemeTypedDecoderInterface< : attribute_(attribute), transform_(transform) {} bool DecodePredictionData(DecoderBuffer *buffer) override { - if (!transform_.DecodeTransformData(buffer)) + if (!transform_.DecodeTransformData(buffer)) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h index db835554385..cf2a6ba6b3b 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h @@ -18,9 +18,8 @@ #ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_FACTORY_H_ #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_FACTORY_H_ -#include "draco/draco_features.h" - #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h" +#include "draco/draco_features.h" #ifdef DRACO_NORMAL_ENCODING_SUPPORTED #include "draco/compression/attributes/prediction_schemes/mesh_prediction_scheme_geometric_normal_decoder.h" #endif @@ -154,8 +153,9 @@ std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>> CreatePredictionSchemeForDecoder(PredictionSchemeMethod method, int att_id, const PointCloudDecoder *decoder, const TransformT &transform) { - if (method == PREDICTION_NONE) + if (method == PREDICTION_NONE) { return nullptr; + } const PointAttribute *const att = decoder->point_cloud()->attribute(att_id); if (decoder->GetGeometryType() == TRIANGULAR_MESH) { // Cast the decoder to mesh decoder. This is not necessarily safe if there @@ -170,8 +170,9 @@ CreatePredictionSchemeForDecoder(PredictionSchemeMethod method, int att_id, MeshDecoder, PredictionSchemeDecoder<DataTypeT, TransformT>, MeshPredictionSchemeDecoderFactory<DataTypeT>>( mesh_decoder, method, att_id, transform, decoder->bitstream_version()); - if (ret) + if (ret) { return ret; + } // Otherwise try to create another prediction scheme. } // Create delta decoder. diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h index 6f19f7fdb99..6f19f7fdb99 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_interface.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h index 47c1532ad98..47c1532ad98 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_decoding_transform.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h index ae72c71208a..ae72c71208a 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h index 324afafa637..324afafa637 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_delta_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h index 548a54d4e02..2a211a9fc20 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder.h @@ -46,8 +46,9 @@ class PredictionSchemeEncoder : public PredictionSchemeTypedEncoderInterface< : attribute_(attribute), transform_(transform) {} bool EncodePredictionData(EncoderBuffer *buffer) override { - if (!transform_.EncodeTransformData(buffer)) + if (!transform_.EncodeTransformData(buffer)) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.cc b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.cc index 6b74e571c6d..428340da013 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.cc +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.cc @@ -62,10 +62,12 @@ PredictionSchemeMethod GetPredictionMethodFromOptions( int att_id, const EncoderOptions &options) { const int pred_type = options.GetAttributeInt(att_id, "prediction_scheme", -1); - if (pred_type == -1) + if (pred_type == -1) { return PREDICTION_UNDEFINED; - if (pred_type < 0 || pred_type >= NUM_PREDICTION_SCHEMES) + } + if (pred_type < 0 || pred_type >= NUM_PREDICTION_SCHEMES) { return PREDICTION_NONE; + } return static_cast<PredictionSchemeMethod>(pred_type); } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h index 4cc40010773..40a7683aa0d 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_factory.h @@ -86,8 +86,9 @@ CreatePredictionSchemeForEncoder(PredictionSchemeMethod method, int att_id, if (method == PREDICTION_UNDEFINED) { method = SelectPredictionMethod(att_id, encoder); } - if (method == PREDICTION_NONE) + if (method == PREDICTION_NONE) { return nullptr; // No prediction is used. + } if (encoder->GetGeometryType() == TRIANGULAR_MESH) { // Cast the encoder to mesh encoder. This is not necessarily safe if there // is some other encoder decides to use TRIANGULAR_MESH as the return type, @@ -100,8 +101,9 @@ CreatePredictionSchemeForEncoder(PredictionSchemeMethod method, int att_id, MeshEncoder, PredictionSchemeEncoder<DataTypeT, TransformT>, MeshPredictionSchemeEncoderFactory<DataTypeT>>( mesh_encoder, method, att_id, transform, kDracoMeshBitstreamVersion); - if (ret) + if (ret) { return ret; + } // Otherwise try to create another prediction scheme. } // Create delta encoder. diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h index ab64bce7114..ab64bce7114 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoder_interface.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h index 0929492aaec..0929492aaec 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_encoding_transform.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h index 9fce686ae41..b36c4c8a273 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_factory.h @@ -61,8 +61,9 @@ std::unique_ptr<PredictionSchemeT> CreateMeshPredictionScheme( &encoding_data->vertex_to_encoded_attribute_value_index_map); MeshPredictionSchemeFactoryT factory; auto ret = factory(method, att, transform, md, bitstream_version); - if (ret) + if (ret) { return ret; + } } else { typedef MeshPredictionSchemeData<CornerTable> MeshData; MeshData md; @@ -71,8 +72,9 @@ std::unique_ptr<PredictionSchemeT> CreateMeshPredictionScheme( &encoding_data->vertex_to_encoded_attribute_value_index_map); MeshPredictionSchemeFactoryT factory; auto ret = factory(method, att, transform, md, bitstream_version); - if (ret) + if (ret) { return ret; + } } } return nullptr; diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h index c9b3706930f..c9b3706930f 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h index 14ecb84654b..5a6c7c2dd45 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h @@ -44,18 +44,23 @@ class PredictionSchemeNormalOctahedronCanonicalizedDecodingTransform bool DecodeTransformData(DecoderBuffer *buffer) { DataTypeT max_quantized_value, center_value; - if (!buffer->Decode(&max_quantized_value)) + if (!buffer->Decode(&max_quantized_value)) { return false; - if (!buffer->Decode(¢er_value)) + } + if (!buffer->Decode(¢er_value)) { return false; + } (void)center_value; - if (!this->set_max_quantized_value(max_quantized_value)) + if (!this->set_max_quantized_value(max_quantized_value)) { return false; + } // Account for reading wrong values, e.g., due to fuzzing. - if (this->quantization_bits() < 2) + if (this->quantization_bits() < 2) { return false; - if (this->quantization_bits() > 30) + } + if (this->quantization_bits() > 30) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h index 0dc96967b10..0dc96967b10 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h index 981077294f8..4a1e3a67b83 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_base.h @@ -90,8 +90,9 @@ class PredictionSchemeNormalOctahedronCanonicalizedTransformBase } bool IsInBottomLeft(const Point2 &p) const { - if (p[0] == 0 && p[1] == 0) + if (p[0] == 0 && p[1] == 0) { return true; + } return (p[0] < 0 && p[1] <= 0); } }; diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h index dbb788a33e0..a1bc4a327ac 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h @@ -18,13 +18,12 @@ #include <cmath> -#include "draco/draco_features.h" - #include "draco/compression/attributes/normal_compression_utils.h" #include "draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h" #include "draco/core/decoder_buffer.h" #include "draco/core/macros.h" #include "draco/core/vector_d.h" +#include "draco/draco_features.h" namespace draco { @@ -45,11 +44,13 @@ class PredictionSchemeNormalOctahedronDecodingTransform void Init(int num_components) {} bool DecodeTransformData(DecoderBuffer *buffer) { DataTypeT max_quantized_value, center_value; - if (!buffer->Decode(&max_quantized_value)) + if (!buffer->Decode(&max_quantized_value)) { return false; + } if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { - if (!buffer->Decode(¢er_value)) + if (!buffer->Decode(¢er_value)) { return false; + } } (void)center_value; return this->set_max_quantized_value(max_quantized_value); diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h index 4abfef66903..4abfef66903 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h index ff71fe86fdf..c9dd7d67bf4 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_base.h @@ -60,8 +60,9 @@ class PredictionSchemeNormalOctahedronTransformBase { protected: inline bool set_max_quantized_value(DataTypeT max_quantized_value) { - if (max_quantized_value % 2 == 0) + if (max_quantized_value % 2 == 0) { return false; + } int q = MostSignificantBit(max_quantized_value) + 1; return octahedron_tool_box_.SetQuantizationBits(q); } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h index bd40df8d2f9..0a14d0d9ba4 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_decoding_transform.h @@ -39,25 +39,30 @@ class PredictionSchemeWrapDecodingTransform predicted_vals = this->ClampPredictedValue(predicted_vals); for (int i = 0; i < this->num_components(); ++i) { out_original_vals[i] = predicted_vals[i] + corr_vals[i]; - if (out_original_vals[i] > this->max_value()) + if (out_original_vals[i] > this->max_value()) { out_original_vals[i] -= this->max_dif(); - else if (out_original_vals[i] < this->min_value()) + } else if (out_original_vals[i] < this->min_value()) { out_original_vals[i] += this->max_dif(); + } } } bool DecodeTransformData(DecoderBuffer *buffer) { DataTypeT min_value, max_value; - if (!buffer->Decode(&min_value)) + if (!buffer->Decode(&min_value)) { return false; - if (!buffer->Decode(&max_value)) + } + if (!buffer->Decode(&max_value)) { return false; - if (min_value > max_value) + } + if (min_value > max_value) { return false; + } this->set_min_value(min_value); this->set_max_value(max_value); - if (!this->InitCorrectionBounds()) + if (!this->InitCorrectionBounds()) { return false; + } return true; } }; diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h index 8cd241f2e0a..1f5e8b13584 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_encoding_transform.h @@ -32,15 +32,17 @@ class PredictionSchemeWrapEncodingTransform void Init(const DataTypeT *orig_data, int size, int num_components) { PredictionSchemeWrapTransformBase<DataTypeT>::Init(num_components); // Go over the original values and compute the bounds. - if (size == 0) + if (size == 0) { return; + } DataTypeT min_value = orig_data[0]; DataTypeT max_value = min_value; for (int i = 1; i < size; ++i) { - if (orig_data[i] < min_value) + if (orig_data[i] < min_value) { min_value = orig_data[i]; - else if (orig_data[i] > max_value) + } else if (orig_data[i] > max_value) { max_value = orig_data[i]; + } } this->set_min_value(min_value); this->set_max_value(max_value); @@ -58,10 +60,11 @@ class PredictionSchemeWrapEncodingTransform out_corr_vals[i] = original_vals[i] - predicted_vals[i]; // Wrap around if needed. DataTypeT &corr_val = out_corr_vals[i]; - if (corr_val < this->min_correction()) + if (corr_val < this->min_correction()) { corr_val += this->max_dif(); - else if (corr_val > this->max_correction()) + } else if (corr_val > this->max_correction()) { corr_val -= this->max_dif(); + } } } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h index cf522269f1f..26f61fbaf6a 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h +++ b/extern/draco/draco/src/draco/compression/attributes/prediction_schemes/prediction_scheme_wrap_transform_base.h @@ -15,6 +15,7 @@ #ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_WRAP_TRANSFORM_BASE_H_ #define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_WRAP_TRANSFORM_BASE_H_ +#include <limits> #include <vector> #include "draco/compression/config/compression_shared.h" @@ -61,12 +62,13 @@ class PredictionSchemeWrapTransformBase { inline const DataTypeT *ClampPredictedValue( const DataTypeT *predicted_val) const { for (int i = 0; i < this->num_components(); ++i) { - if (predicted_val[i] > max_value_) + if (predicted_val[i] > max_value_) { clamped_value_[i] = max_value_; - else if (predicted_val[i] < min_value_) + } else if (predicted_val[i] < min_value_) { clamped_value_[i] = min_value_; - else + } else { clamped_value_[i] = predicted_val[i]; + } } return &clamped_value_[0]; } @@ -81,13 +83,15 @@ class PredictionSchemeWrapTransformBase { bool InitCorrectionBounds() { const int64_t dif = static_cast<int64_t>(max_value_) - static_cast<int64_t>(min_value_); - if (dif < 0 || dif >= std::numeric_limits<DataTypeT>::max()) + if (dif < 0 || dif >= std::numeric_limits<DataTypeT>::max()) { return false; + } max_dif_ = 1 + static_cast<DataTypeT>(dif); max_correction_ = max_dif_ / 2; min_correction_ = -max_correction_; - if ((max_dif_ & 1) == 0) + if ((max_dif_ & 1) == 0) { max_correction_ -= 1; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoder.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoder.cc index 9e33cef3428..b4ba24f2d31 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoder.cc @@ -36,10 +36,13 @@ bool SequentialAttributeDecoder::InitializeStandalone( bool SequentialAttributeDecoder::DecodePortableAttribute( const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { - if (attribute_->num_components() <= 0 || !attribute_->Reset(point_ids.size())) + if (attribute_->num_components() <= 0 || + !attribute_->Reset(point_ids.size())) { return false; - if (!DecodeValues(point_ids, in_buffer)) + } + if (!DecodeValues(point_ids, in_buffer)) { return false; + } return true; } @@ -74,8 +77,9 @@ bool SequentialAttributeDecoder::InitPredictionScheme( for (int i = 0; i < ps->GetNumParentAttributes(); ++i) { const int att_id = decoder_->point_cloud()->GetNamedAttributeId( ps->GetParentAttributeType(i)); - if (att_id == -1) + if (att_id == -1) { return false; // Requested attribute does not exist. + } #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { if (!ps->SetParentAttribute(decoder_->point_cloud()->attribute(att_id))) { @@ -102,8 +106,9 @@ bool SequentialAttributeDecoder::DecodeValues( int out_byte_pos = 0; // Decode raw attribute values in their original format. for (int i = 0; i < num_values; ++i) { - if (!in_buffer->Decode(value_data, entry_size)) + if (!in_buffer->Decode(value_data, entry_size)) { return false; + } attribute_->buffer()->Write(out_byte_pos, value_data, entry_size); out_byte_pos += entry_size; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoder.h b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoder.h index 721a587fc2a..d48119465a9 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoder.h @@ -15,10 +15,9 @@ #ifndef DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_ATTRIBUTE_DECODER_H_ #define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_ATTRIBUTE_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/attributes/prediction_schemes/prediction_scheme_interface.h" #include "draco/compression/point_cloud/point_cloud_decoder.h" +#include "draco/draco_features.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoders_controller.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoders_controller.cc index 2676eb7905c..0e5e26bcaa2 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoders_controller.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoders_controller.cc @@ -27,36 +27,42 @@ SequentialAttributeDecodersController::SequentialAttributeDecodersController( bool SequentialAttributeDecodersController::DecodeAttributesDecoderData( DecoderBuffer *buffer) { - if (!AttributesDecoder::DecodeAttributesDecoderData(buffer)) + if (!AttributesDecoder::DecodeAttributesDecoderData(buffer)) { return false; + } // Decode unique ids of all sequential encoders and create them. const int32_t num_attributes = GetNumAttributes(); sequential_decoders_.resize(num_attributes); for (int i = 0; i < num_attributes; ++i) { uint8_t decoder_type; - if (!buffer->Decode(&decoder_type)) + if (!buffer->Decode(&decoder_type)) { return false; + } // Create the decoder from the id. sequential_decoders_[i] = CreateSequentialDecoder(decoder_type); - if (!sequential_decoders_[i]) + if (!sequential_decoders_[i]) { return false; - if (!sequential_decoders_[i]->Init(GetDecoder(), GetAttributeId(i))) + } + if (!sequential_decoders_[i]->Init(GetDecoder(), GetAttributeId(i))) { return false; + } } return true; } bool SequentialAttributeDecodersController::DecodeAttributes( DecoderBuffer *buffer) { - if (!sequencer_ || !sequencer_->GenerateSequence(&point_ids_)) + if (!sequencer_ || !sequencer_->GenerateSequence(&point_ids_)) { return false; + } // Initialize point to attribute value mapping for all decoded attributes. const int32_t num_attributes = GetNumAttributes(); for (int i = 0; i < num_attributes; ++i) { PointAttribute *const pa = GetDecoder()->point_cloud()->attribute(GetAttributeId(i)); - if (!sequencer_->UpdatePointToAttributeIndexMapping(pa)) + if (!sequencer_->UpdatePointToAttributeIndexMapping(pa)) { return false; + } } return AttributesDecoder::DecodeAttributes(buffer); } @@ -66,8 +72,9 @@ bool SequentialAttributeDecodersController::DecodePortableAttributes( const int32_t num_attributes = GetNumAttributes(); for (int i = 0; i < num_attributes; ++i) { if (!sequential_decoders_[i]->DecodePortableAttribute(point_ids_, - in_buffer)) + in_buffer)) { return false; + } } return true; } @@ -77,8 +84,9 @@ bool SequentialAttributeDecodersController:: const int32_t num_attributes = GetNumAttributes(); for (int i = 0; i < num_attributes; ++i) { if (!sequential_decoders_[i]->DecodeDataNeededByPortableTransform( - point_ids_, in_buffer)) + point_ids_, in_buffer)) { return false; + } } return true; } @@ -106,8 +114,9 @@ bool SequentialAttributeDecodersController:: } } if (!sequential_decoders_[i]->TransformAttributeToOriginalFormat( - point_ids_)) + point_ids_)) { return false; + } } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoders_controller.h b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoders_controller.h index 9fd5e490741..abc1f368523 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_decoders_controller.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_decoders_controller.h @@ -37,8 +37,9 @@ class SequentialAttributeDecodersController : public AttributesDecoder { const PointAttribute *GetPortableAttribute( int32_t point_attribute_id) override { const int32_t loc_id = GetLocalIdForPointAttribute(point_attribute_id); - if (loc_id < 0) + if (loc_id < 0) { return nullptr; + } return sequential_decoders_[loc_id]->GetPortableAttribute(); } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoder.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoder.cc index 95547c005e7..6bde3eeb3ba 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoder.cc @@ -46,8 +46,9 @@ bool SequentialAttributeEncoder::TransformAttributeToPortableFormat( bool SequentialAttributeEncoder::EncodePortableAttribute( const std::vector<PointIndex> &point_ids, EncoderBuffer *out_buffer) { // Lossless encoding of the input values. - if (!EncodeValues(point_ids, out_buffer)) + if (!EncodeValues(point_ids, out_buffer)) { return false; + } return true; } @@ -80,8 +81,9 @@ bool SequentialAttributeEncoder::InitPredictionScheme( for (int i = 0; i < ps->GetNumParentAttributes(); ++i) { const int att_id = encoder_->point_cloud()->GetNamedAttributeId( ps->GetParentAttributeType(i)); - if (att_id == -1) + if (att_id == -1) { return false; // Requested attribute does not exist. + } parent_attributes_.push_back(att_id); encoder_->MarkParentAttribute(att_id); } @@ -93,10 +95,12 @@ bool SequentialAttributeEncoder::SetPredictionSchemeParentAttributes( for (int i = 0; i < ps->GetNumParentAttributes(); ++i) { const int att_id = encoder_->point_cloud()->GetNamedAttributeId( ps->GetParentAttributeType(i)); - if (att_id == -1) + if (att_id == -1) { return false; // Requested attribute does not exist. - if (!ps->SetParentAttribute(encoder_->GetPortableAttribute(att_id))) + } + if (!ps->SetParentAttribute(encoder_->GetPortableAttribute(att_id))) { return false; + } } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoder.h b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoder.h index 540ba947077..00f62db8959 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoder.h @@ -64,8 +64,9 @@ class SequentialAttributeEncoder { int GetParentAttributeId(int i) const { return parent_attributes_[i]; } const PointAttribute *GetPortableAttribute() const { - if (portable_attribute_ != nullptr) + if (portable_attribute_ != nullptr) { return portable_attribute_.get(); + } return attribute(); } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoders_controller.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoders_controller.cc index b40cef842ae..521935c1e99 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoders_controller.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoders_controller.cc @@ -31,23 +31,27 @@ SequentialAttributeEncodersController::SequentialAttributeEncodersController( bool SequentialAttributeEncodersController::Init(PointCloudEncoder *encoder, const PointCloud *pc) { - if (!AttributesEncoder::Init(encoder, pc)) + if (!AttributesEncoder::Init(encoder, pc)) { return false; - if (!CreateSequentialEncoders()) + } + if (!CreateSequentialEncoders()) { return false; + } // Initialize all value encoders. for (uint32_t i = 0; i < num_attributes(); ++i) { const int32_t att_id = GetAttributeId(i); - if (!sequential_encoders_[i]->Init(encoder, att_id)) + if (!sequential_encoders_[i]->Init(encoder, att_id)) { return false; + } } return true; } bool SequentialAttributeEncodersController::EncodeAttributesEncoderData( EncoderBuffer *out_buffer) { - if (!AttributesEncoder::EncodeAttributesEncoderData(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()); @@ -57,8 +61,9 @@ bool SequentialAttributeEncodersController::EncodeAttributesEncoderData( bool SequentialAttributeEncodersController::EncodeAttributes( EncoderBuffer *buffer) { - if (!sequencer_ || !sequencer_->GenerateSequence(&point_ids_)) + if (!sequencer_ || !sequencer_->GenerateSequence(&point_ids_)) { return false; + } return AttributesEncoder::EncodeAttributes(buffer); } @@ -66,8 +71,9 @@ bool SequentialAttributeEncodersController:: TransformAttributesToPortableFormat() { for (uint32_t i = 0; i < sequential_encoders_.size(); ++i) { if (!sequential_encoders_[i]->TransformAttributeToPortableFormat( - point_ids_)) + point_ids_)) { return false; + } } return true; } @@ -76,8 +82,9 @@ 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)) + out_buffer)) { return false; + } } return true; } @@ -86,8 +93,9 @@ bool SequentialAttributeEncodersController:: EncodeDataNeededByPortableTransforms(EncoderBuffer *out_buffer) { for (uint32_t i = 0; i < sequential_encoders_.size(); ++i) { if (!sequential_encoders_[i]->EncodeDataNeededByPortableTransform( - out_buffer)) + out_buffer)) { return false; + } } return true; } @@ -96,11 +104,13 @@ bool SequentialAttributeEncodersController::CreateSequentialEncoders() { sequential_encoders_.resize(num_attributes()); for (uint32_t i = 0; i < num_attributes(); ++i) { sequential_encoders_[i] = CreateSequentialEncoder(i); - if (sequential_encoders_[i] == nullptr) + if (sequential_encoders_[i] == nullptr) { return false; + } if (i < sequential_encoder_marked_as_parent_.size()) { - if (sequential_encoder_marked_as_parent_[i]) + if (sequential_encoder_marked_as_parent_[i]) { sequential_encoders_[i]->MarkParentAttribute(); + } } } return true; diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoders_controller.h b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoders_controller.h index d5574abef8d..13c2704ec0a 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_attribute_encoders_controller.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_attribute_encoders_controller.h @@ -42,23 +42,26 @@ class SequentialAttributeEncodersController : public AttributesEncoder { int NumParentAttributes(int32_t point_attribute_id) const override { const int32_t loc_id = GetLocalIdForPointAttribute(point_attribute_id); - if (loc_id < 0) + if (loc_id < 0) { return 0; + } return sequential_encoders_[loc_id]->NumParentAttributes(); } int GetParentAttributeId(int32_t point_attribute_id, int32_t parent_i) const override { const int32_t loc_id = GetLocalIdForPointAttribute(point_attribute_id); - if (loc_id < 0) + if (loc_id < 0) { return -1; + } return sequential_encoders_[loc_id]->GetParentAttributeId(parent_i); } bool MarkParentAttribute(int32_t point_attribute_id) override { const int32_t loc_id = GetLocalIdForPointAttribute(point_attribute_id); - if (loc_id < 0) + if (loc_id < 0) { return false; + } // Mark the attribute encoder as parent (even when if it is not created // yet). if (sequential_encoder_marked_as_parent_.size() <= loc_id) { @@ -66,8 +69,9 @@ class SequentialAttributeEncodersController : public AttributesEncoder { } sequential_encoder_marked_as_parent_[loc_id] = true; - if (sequential_encoders_.size() <= loc_id) + if (sequential_encoders_.size() <= loc_id) { return true; // Sequential encoders not generated yet. + } sequential_encoders_[loc_id]->MarkParentAttribute(); return true; } @@ -75,8 +79,9 @@ class SequentialAttributeEncodersController : public AttributesEncoder { const PointAttribute *GetPortableAttribute( int32_t point_attribute_id) override { const int32_t loc_id = GetLocalIdForPointAttribute(point_attribute_id); - if (loc_id < 0) + if (loc_id < 0) { return nullptr; + } return sequential_encoders_[loc_id]->GetPortableAttribute(); } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_decoder.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_decoder.cc index 8d9210af912..d01fb26aad4 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_decoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_decoder.cc @@ -24,8 +24,9 @@ SequentialIntegerAttributeDecoder::SequentialIntegerAttributeDecoder() {} bool SequentialIntegerAttributeDecoder::Init(PointCloudDecoder *decoder, int attribute_id) { - if (!SequentialAttributeDecoder::Init(decoder, attribute_id)) + if (!SequentialAttributeDecoder::Init(decoder, attribute_id)) { return false; + } return true; } @@ -33,8 +34,9 @@ bool SequentialIntegerAttributeDecoder::TransformAttributeToOriginalFormat( const std::vector<PointIndex> &point_ids) { #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder() && - decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) + decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { return true; // Don't revert the transform here for older files. + } #endif return StoreValues(static_cast<uint32_t>(point_ids.size())); } @@ -43,30 +45,37 @@ bool SequentialIntegerAttributeDecoder::DecodeValues( const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { // Decode prediction scheme. int8_t prediction_scheme_method; - in_buffer->Decode(&prediction_scheme_method); + if (!in_buffer->Decode(&prediction_scheme_method)) { + return false; + } if (prediction_scheme_method != PREDICTION_NONE) { int8_t prediction_transform_type; - in_buffer->Decode(&prediction_transform_type); + if (!in_buffer->Decode(&prediction_transform_type)) { + return false; + } prediction_scheme_ = CreateIntPredictionScheme( static_cast<PredictionSchemeMethod>(prediction_scheme_method), static_cast<PredictionSchemeTransformType>(prediction_transform_type)); } if (prediction_scheme_) { - if (!InitPredictionScheme(prediction_scheme_.get())) + if (!InitPredictionScheme(prediction_scheme_.get())) { return false; + } } - if (!DecodeIntegerValues(point_ids, in_buffer)) + if (!DecodeIntegerValues(point_ids, in_buffer)) { return false; + } #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED const int32_t num_values = static_cast<uint32_t>(point_ids.size()); if (decoder() && decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { // For older files, revert the transform right after we decode the data. - if (!StoreValues(num_values)) + if (!StoreValues(num_values)) { return false; + } } #endif return true; @@ -76,8 +85,9 @@ std::unique_ptr<PredictionSchemeTypedDecoderInterface<int32_t>> SequentialIntegerAttributeDecoder::CreateIntPredictionScheme( PredictionSchemeMethod method, PredictionSchemeTransformType transform_type) { - if (transform_type != PREDICTION_TRANSFORM_WRAP) + if (transform_type != PREDICTION_TRANSFORM_WRAP) { return nullptr; // For now we support only wrap transform. + } return CreatePredictionSchemeForDecoder< int32_t, PredictionSchemeWrapDecodingTransform<int32_t>>( method, attribute_id(), decoder()); @@ -86,44 +96,55 @@ SequentialIntegerAttributeDecoder::CreateIntPredictionScheme( bool SequentialIntegerAttributeDecoder::DecodeIntegerValues( const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { const int num_components = GetNumValueComponents(); - if (num_components <= 0) + if (num_components <= 0) { return false; + } const size_t num_entries = point_ids.size(); const size_t num_values = num_entries * num_components; PreparePortableAttribute(static_cast<int>(num_entries), num_components); int32_t *const portable_attribute_data = GetPortableAttributeData(); - if (portable_attribute_data == nullptr) + if (portable_attribute_data == nullptr) { return false; + } uint8_t compressed; - if (!in_buffer->Decode(&compressed)) + if (!in_buffer->Decode(&compressed)) { return false; + } if (compressed > 0) { // Decode compressed values. if (!DecodeSymbols(static_cast<uint32_t>(num_values), num_components, in_buffer, - reinterpret_cast<uint32_t *>(portable_attribute_data))) + reinterpret_cast<uint32_t *>(portable_attribute_data))) { return false; + } } else { // Decode the integer data directly. // Get the number of bytes for a given entry. uint8_t num_bytes; - if (!in_buffer->Decode(&num_bytes)) + if (!in_buffer->Decode(&num_bytes)) { return false; + } if (num_bytes == DataTypeLength(DT_INT32)) { if (portable_attribute()->buffer()->data_size() < - sizeof(int32_t) * num_values) + sizeof(int32_t) * num_values) { return false; + } if (!in_buffer->Decode(portable_attribute_data, - sizeof(int32_t) * num_values)) + sizeof(int32_t) * num_values)) { return false; + } } else { - if (portable_attribute()->buffer()->data_size() < num_bytes * num_values) + if (portable_attribute()->buffer()->data_size() < + num_bytes * num_values) { return false; + } if (in_buffer->remaining_size() < - static_cast<int64_t>(num_bytes) * static_cast<int64_t>(num_values)) + static_cast<int64_t>(num_bytes) * static_cast<int64_t>(num_values)) { return false; + } for (size_t i = 0; i < num_values; ++i) { - in_buffer->Decode(portable_attribute_data + i, num_bytes); + if (!in_buffer->Decode(portable_attribute_data + i, num_bytes)) + return false; } } } @@ -138,8 +159,9 @@ bool SequentialIntegerAttributeDecoder::DecodeIntegerValues( // If the data was encoded with a prediction scheme, we must revert it. if (prediction_scheme_) { - if (!prediction_scheme_->DecodePredictionData(in_buffer)) + if (!prediction_scheme_->DecodePredictionData(in_buffer)) { return false; + } if (num_values > 0) { if (!prediction_scheme_->ComputeOriginalValues( diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_decoder.h b/extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_decoder.h index 150ae1f831f..ef48ed817a5 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_decoder.h @@ -15,10 +15,9 @@ #ifndef DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_INTEGER_ATTRIBUTE_DECODER_H_ #define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_INTEGER_ATTRIBUTE_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/attributes/prediction_schemes/prediction_scheme_decoder.h" #include "draco/compression/attributes/sequential_attribute_decoder.h" +#include "draco/draco_features.h" namespace draco { @@ -56,8 +55,9 @@ class SequentialIntegerAttributeDecoder : public SequentialAttributeDecoder { void PreparePortableAttribute(int num_entries, int num_components); int32_t *GetPortableAttributeData() { - if (portable_attribute()->size() == 0) + if (portable_attribute()->size() == 0) { return nullptr; + } return reinterpret_cast<int32_t *>( portable_attribute()->GetAddress(AttributeValueIndex(0))); } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoder.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_encoder.cc index 0cae81d9f95..2889e0521a0 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_encoder.cc @@ -25,8 +25,9 @@ SequentialIntegerAttributeEncoder::SequentialIntegerAttributeEncoder() {} bool SequentialIntegerAttributeEncoder::Init(PointCloudEncoder *encoder, int attribute_id) { - if (!SequentialAttributeEncoder::Init(encoder, attribute_id)) + if (!SequentialAttributeEncoder::Init(encoder, attribute_id)) { return false; + } if (GetUniqueId() == SEQUENTIAL_ATTRIBUTE_ENCODER_INTEGER) { // When encoding integers, this encoder currently works only for integer // attributes up to 32 bits. @@ -58,11 +59,13 @@ bool SequentialIntegerAttributeEncoder::Init(PointCloudEncoder *encoder, bool SequentialIntegerAttributeEncoder::TransformAttributeToPortableFormat( const std::vector<PointIndex> &point_ids) { if (encoder()) { - if (!PrepareValues(point_ids, encoder()->point_cloud()->num_points())) + if (!PrepareValues(point_ids, encoder()->point_cloud()->num_points())) { return false; + } } else { - if (!PrepareValues(point_ids, 0)) + if (!PrepareValues(point_ids, 0)) { return false; + } } // Update point to attribute mapping with the portable attribute if the @@ -100,8 +103,9 @@ bool SequentialIntegerAttributeEncoder::EncodeValues( const std::vector<PointIndex> &point_ids, EncoderBuffer *out_buffer) { // Initialize general quantization data. const PointAttribute *const attrib = attribute(); - if (attrib->size() == 0) + if (attrib->size() == 0) { return true; + } int8_t prediction_scheme_method = PREDICTION_NONE; if (prediction_scheme_) { @@ -202,8 +206,9 @@ bool SequentialIntegerAttributeEncoder::PrepareValues( for (PointIndex pi : point_ids) { const AttributeValueIndex att_id = attrib->mapped_index(pi); if (!attrib->ConvertValue<int32_t>(att_id, - portable_attribute_data + dst_index)) + portable_attribute_data + dst_index)) { return false; + } dst_index += num_components; } return true; diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoder.h b/extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_encoder.h index c1d6222ef40..c1d6222ef40 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_integer_attribute_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_decoder.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_decoder.cc index 2f208d50dbe..017344393dc 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_decoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_decoder.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/compression/attributes/sequential_normal_attribute_decoder.h" + #include "draco/attributes/attribute_octahedron_transform.h" #include "draco/compression/attributes/normal_compression_utils.h" @@ -26,11 +27,13 @@ bool SequentialNormalAttributeDecoder::Init(PointCloudDecoder *decoder, if (!SequentialIntegerAttributeDecoder::Init(decoder, attribute_id)) return false; // Currently, this encoder works only for 3-component normal vectors. - if (attribute()->num_components() != 3) + if (attribute()->num_components() != 3) { return false; + } // Also the data type must be DT_FLOAT32. - if (attribute()->data_type() != DT_FLOAT32) + if (attribute()->data_type() != DT_FLOAT32) { return false; + } return true; } @@ -39,8 +42,9 @@ bool SequentialNormalAttributeDecoder::DecodeIntegerValues( #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { uint8_t quantization_bits; - if (!in_buffer->Decode(&quantization_bits)) + if (!in_buffer->Decode(&quantization_bits)) { return false; + } quantization_bits_ = quantization_bits; } #endif @@ -53,8 +57,9 @@ bool SequentialNormalAttributeDecoder::DecodeDataNeededByPortableTransform( if (decoder()->bitstream_version() >= DRACO_BITSTREAM_VERSION(2, 0)) { // For newer file version, decode attribute transform data here. uint8_t quantization_bits; - if (!in_buffer->Decode(&quantization_bits)) + if (!in_buffer->Decode(&quantization_bits)) { return false; + } quantization_bits_ = quantization_bits; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_decoder.h b/extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_decoder.h index d6439fcd6cf..860eacb4c84 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_decoder.h @@ -15,12 +15,11 @@ #ifndef DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_NORMAL_ATTRIBUTE_DECODER_H_ #define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_NORMAL_ATTRIBUTE_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/attributes/prediction_schemes/prediction_scheme_decoder_factory.h" #include "draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_decoding_transform.h" #include "draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_decoding_transform.h" #include "draco/compression/attributes/sequential_integer_attribute_decoder.h" +#include "draco/draco_features.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_encoder.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_encoder.cc index af207a87111..23fa8bb7b39 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_encoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_encoder.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/compression/attributes/sequential_normal_attribute_encoder.h" + #include "draco/compression/attributes/normal_compression_utils.h" namespace draco { @@ -22,14 +23,16 @@ bool SequentialNormalAttributeEncoder::Init(PointCloudEncoder *encoder, if (!SequentialIntegerAttributeEncoder::Init(encoder, attribute_id)) return false; // Currently this encoder works only for 3-component normal vectors. - if (attribute()->num_components() != 3) + if (attribute()->num_components() != 3) { return false; + } // Initialize AttributeOctahedronTransform. const int quantization_bits = encoder->options()->GetAttributeInt( attribute_id, "quantization_bits", -1); - if (quantization_bits < 1) + if (quantization_bits < 1) { return false; + } attribute_octahedron_transform_.SetParameters(quantization_bits); return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_encoder.h b/extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_encoder.h index 53705c5982b..53705c5982b 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_normal_attribute_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_normal_attribute_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc index dfaf2edbe8e..bf925c4a595 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.cc @@ -24,13 +24,15 @@ SequentialQuantizationAttributeDecoder::SequentialQuantizationAttributeDecoder() bool SequentialQuantizationAttributeDecoder::Init(PointCloudDecoder *decoder, int attribute_id) { - if (!SequentialIntegerAttributeDecoder::Init(decoder, attribute_id)) + if (!SequentialIntegerAttributeDecoder::Init(decoder, attribute_id)) { return false; + } const PointAttribute *const attribute = decoder->point_cloud()->attribute(attribute_id); // Currently we can quantize only floating point arguments. - if (attribute->data_type() != DT_FLOAT32) + if (attribute->data_type() != DT_FLOAT32) { return false; + } return true; } @@ -38,8 +40,9 @@ bool SequentialQuantizationAttributeDecoder::DecodeIntegerValues( const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0) && - !DecodeQuantizedDataInfo()) + !DecodeQuantizedDataInfo()) { return false; + } #endif return SequentialIntegerAttributeDecoder::DecodeIntegerValues(point_ids, in_buffer); @@ -50,8 +53,9 @@ bool SequentialQuantizationAttributeDecoder:: const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) { if (decoder()->bitstream_version() >= DRACO_BITSTREAM_VERSION(2, 0)) { // Decode quantization data here only for files with bitstream version 2.0+ - if (!DecodeQuantizedDataInfo()) + if (!DecodeQuantizedDataInfo()) { return false; + } } // Store the decoded transform data in portable attribute; @@ -69,14 +73,17 @@ bool SequentialQuantizationAttributeDecoder::DecodeQuantizedDataInfo() { const int num_components = attribute()->num_components(); min_value_ = std::unique_ptr<float[]>(new float[num_components]); if (!decoder()->buffer()->Decode(min_value_.get(), - sizeof(float) * num_components)) + sizeof(float) * num_components)) { return false; - if (!decoder()->buffer()->Decode(&max_value_dif_)) + } + if (!decoder()->buffer()->Decode(&max_value_dif_)) { return false; + } uint8_t quantization_bits; if (!decoder()->buffer()->Decode(&quantization_bits) || - quantization_bits > 31) + quantization_bits > 31) { return false; + } quantization_bits_ = quantization_bits; return true; } @@ -92,8 +99,9 @@ bool SequentialQuantizationAttributeDecoder::DequantizeValues( int quant_val_id = 0; int out_byte_pos = 0; Dequantizer dequantizer; - if (!dequantizer.Init(max_value_dif_, max_quantized_value)) + if (!dequantizer.Init(max_value_dif_, max_quantized_value)) { return false; + } const int32_t *const portable_attribute_data = GetPortableAttributeData(); for (uint32_t i = 0; i < num_values; ++i) { for (int c = 0; c < num_components; ++c) { diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_decoder.h b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.h index 27d88be72bd..c0b7637a750 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_decoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_decoder.h @@ -15,9 +15,8 @@ #ifndef DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_QUANTIZATION_ATTRIBUTE_DECODER_H_ #define DRACO_COMPRESSION_ATTRIBUTES_SEQUENTIAL_QUANTIZATION_ATTRIBUTE_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/attributes/sequential_integer_attribute_decoder.h" +#include "draco/draco_features.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_encoder.cc b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_encoder.cc index 9110450061c..cd5b8b141e0 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_encoder.cc +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_encoder.cc @@ -23,19 +23,22 @@ SequentialQuantizationAttributeEncoder:: bool SequentialQuantizationAttributeEncoder::Init(PointCloudEncoder *encoder, int attribute_id) { - if (!SequentialIntegerAttributeEncoder::Init(encoder, attribute_id)) + if (!SequentialIntegerAttributeEncoder::Init(encoder, attribute_id)) { return false; + } // This encoder currently works only for floating point attributes. const PointAttribute *const attribute = encoder->point_cloud()->attribute(attribute_id); - if (attribute->data_type() != DT_FLOAT32) + if (attribute->data_type() != DT_FLOAT32) { return false; + } // Initialize AttributeQuantizationTransform. const int quantization_bits = encoder->options()->GetAttributeInt( attribute_id, "quantization_bits", -1); - if (quantization_bits < 1) + if (quantization_bits < 1) { return false; + } if (encoder->options()->IsAttributeOptionSet(attribute_id, "quantization_origin") && encoder->options()->IsAttributeOptionSet(attribute_id, @@ -52,8 +55,10 @@ bool SequentialQuantizationAttributeEncoder::Init(PointCloudEncoder *encoder, attribute->num_components(), range); } else { // Compute quantization settings from the attribute values. - attribute_quantization_transform_.ComputeParameters(*attribute, - quantization_bits); + if (!attribute_quantization_transform_.ComputeParameters( + *attribute, quantization_bits)) { + return false; + } } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_encoder.h b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_encoder.h index e9762bdd6d0..e9762bdd6d0 100644 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_quantization_attribute_encoder.h +++ b/extern/draco/draco/src/draco/compression/attributes/sequential_quantization_attribute_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h index faacbd5b940..faacbd5b940 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_coding_shared.h diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.cc b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.cc index 87ff7007a3d..056842c4a99 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.cc +++ b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.cc @@ -26,15 +26,18 @@ bool AdaptiveRAnsBitDecoder::StartDecoding(DecoderBuffer *source_buffer) { Clear(); uint32_t size_in_bytes; - if (!source_buffer->Decode(&size_in_bytes)) + if (!source_buffer->Decode(&size_in_bytes)) { return false; - if (size_in_bytes > source_buffer->remaining_size()) + } + if (size_in_bytes > source_buffer->remaining_size()) { return false; + } if (ans_read_init(&ans_decoder_, reinterpret_cast<uint8_t *>( const_cast<char *>(source_buffer->data_head())), - size_in_bytes) != 0) + size_in_bytes) != 0) { return false; + } source_buffer->Advance(size_in_bytes); return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.h b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.h index a1ea011dd6a..a1ea011dd6a 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.cc b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.cc index 5ce9dc388b8..5ce9dc388b8 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.cc +++ b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.h b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.h index 9b1832844ad..9b1832844ad 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/adaptive_rans_bit_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_decoder.cc b/extern/draco/draco/src/draco/compression/bit_coders/direct_bit_decoder.cc index 515ea9b52ee..2abe3382a4c 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_decoder.cc +++ b/extern/draco/draco/src/draco/compression/bit_coders/direct_bit_decoder.cc @@ -23,19 +23,23 @@ DirectBitDecoder::~DirectBitDecoder() { Clear(); } bool DirectBitDecoder::StartDecoding(DecoderBuffer *source_buffer) { Clear(); uint32_t size_in_bytes; - if (!source_buffer->Decode(&size_in_bytes)) + if (!source_buffer->Decode(&size_in_bytes)) { return false; + } // Check that size_in_bytes is > 0 and a multiple of 4 as the encoder always // encodes 32 bit elements. - if (size_in_bytes == 0 || size_in_bytes & 0x3) + if (size_in_bytes == 0 || size_in_bytes & 0x3) { return false; - if (size_in_bytes > source_buffer->remaining_size()) + } + if (size_in_bytes > source_buffer->remaining_size()) { return false; + } const uint32_t num_32bit_elements = size_in_bytes / 4; bits_.resize(num_32bit_elements); - if (!source_buffer->Decode(bits_.data(), size_in_bytes)) + if (!source_buffer->Decode(bits_.data(), size_in_bytes)) { return false; + } pos_ = bits_.begin(); num_used_bits_ = 0; return true; diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_decoder.h b/extern/draco/draco/src/draco/compression/bit_coders/direct_bit_decoder.h index b9fbc2d6fed..b9fbc2d6fed 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_decoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/direct_bit_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_encoder.cc b/extern/draco/draco/src/draco/compression/bit_coders/direct_bit_encoder.cc index d39143cf56a..d39143cf56a 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_encoder.cc +++ b/extern/draco/draco/src/draco/compression/bit_coders/direct_bit_encoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_encoder.h b/extern/draco/draco/src/draco/compression/bit_coders/direct_bit_encoder.h index 705b2ca93c2..705b2ca93c2 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/direct_bit_encoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/direct_bit_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/folded_integer_bit_decoder.h b/extern/draco/draco/src/draco/compression/bit_coders/folded_integer_bit_decoder.h index 9f8bedd1eb0..c14058b6569 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/folded_integer_bit_decoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/folded_integer_bit_decoder.h @@ -32,8 +32,9 @@ class FoldedBit32Decoder { // Sets |source_buffer| as the buffer to decode bits from. bool StartDecoding(DecoderBuffer *source_buffer) { for (int i = 0; i < 32; i++) { - if (!folded_number_decoders_[i].StartDecoding(source_buffer)) + if (!folded_number_decoders_[i].StartDecoding(source_buffer)) { return false; + } } return bit_decoder_.StartDecoding(source_buffer); } diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/folded_integer_bit_encoder.h b/extern/draco/draco/src/draco/compression/bit_coders/folded_integer_bit_encoder.h index 375b38a61fb..375b38a61fb 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/folded_integer_bit_encoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/folded_integer_bit_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_decoder.cc b/extern/draco/draco/src/draco/compression/bit_coders/rans_bit_decoder.cc index 023e0dbc192..a9b8fb9e91e 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_decoder.cc +++ b/extern/draco/draco/src/draco/compression/bit_coders/rans_bit_decoder.cc @@ -27,30 +27,35 @@ RAnsBitDecoder::~RAnsBitDecoder() { Clear(); } bool RAnsBitDecoder::StartDecoding(DecoderBuffer *source_buffer) { Clear(); - if (!source_buffer->Decode(&prob_zero_)) + if (!source_buffer->Decode(&prob_zero_)) { return false; + } uint32_t size_in_bytes; #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (source_buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { - if (!source_buffer->Decode(&size_in_bytes)) + if (!source_buffer->Decode(&size_in_bytes)) { return false; + } } else #endif { - if (!DecodeVarint(&size_in_bytes, source_buffer)) + if (!DecodeVarint(&size_in_bytes, source_buffer)) { return false; + } } - if (size_in_bytes > source_buffer->remaining_size()) + if (size_in_bytes > source_buffer->remaining_size()) { return false; + } if (ans_read_init(&ans_decoder_, reinterpret_cast<uint8_t *>( const_cast<char *>(source_buffer->data_head())), - size_in_bytes) != 0) + size_in_bytes) != 0) { return false; + } source_buffer->Advance(size_in_bytes); return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_decoder.h b/extern/draco/draco/src/draco/compression/bit_coders/rans_bit_decoder.h index 1fbf6a1324a..25d243eac16 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_decoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/rans_bit_decoder.h @@ -18,10 +18,9 @@ #include <vector> -#include "draco/draco_features.h" - #include "draco/compression/entropy/ans.h" #include "draco/core/decoder_buffer.h" +#include "draco/draco_features.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_encoder.cc b/extern/draco/draco/src/draco/compression/bit_coders/rans_bit_encoder.cc index ea2972fe262..8d00ea35292 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_encoder.cc +++ b/extern/draco/draco/src/draco/compression/bit_coders/rans_bit_encoder.cc @@ -72,8 +72,9 @@ void RAnsBitEncoder::EncodeLeastSignificantBits32(int nbits, uint32_t value) { void RAnsBitEncoder::EndEncoding(EncoderBuffer *target_buffer) { uint64_t total = bit_counts_[1] + bit_counts_[0]; - if (total == 0) + if (total == 0) { total++; + } // The probability interval [0,1] is mapped to values of [0, 256]. However, // the coding scheme can not deal with probabilities of 0 or 1, which is why @@ -83,8 +84,9 @@ void RAnsBitEncoder::EndEncoding(EncoderBuffer *target_buffer) { ((bit_counts_[0] / static_cast<double>(total)) * 256.0) + 0.5); uint8_t zero_prob = 255; - if (zero_prob_raw < 255) + if (zero_prob_raw < 255) { zero_prob = static_cast<uint8_t>(zero_prob_raw); + } zero_prob += (zero_prob == 0); diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_encoder.h b/extern/draco/draco/src/draco/compression/bit_coders/rans_bit_encoder.h index 1993dd3d3c2..1993dd3d3c2 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_encoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/rans_bit_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_decoder.cc b/extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_decoder.cc index 6b35ae3f87f..8ed50ef92ec 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_decoder.cc +++ b/extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_decoder.cc @@ -6,12 +6,14 @@ namespace draco { bool SymbolBitDecoder::StartDecoding(DecoderBuffer *source_buffer) { uint32_t size; - if (!source_buffer->Decode(&size)) + if (!source_buffer->Decode(&size)) { return false; + } symbols_.resize(size); - if (!DecodeSymbols(size, 1, source_buffer, symbols_.data())) + if (!DecodeSymbols(size, 1, source_buffer, symbols_.data())) { return false; + } std::reverse(symbols_.begin(), symbols_.end()); return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_decoder.h b/extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_decoder.h index 909d7174fb5..909d7174fb5 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_decoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_encoder.cc b/extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_encoder.cc index 83834236fa5..83834236fa5 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_encoder.cc +++ b/extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_encoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_encoder.h b/extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_encoder.h index 7f1570c1a7c..7f1570c1a7c 100644 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/symbol_bit_encoder.h +++ b/extern/draco/draco/src/draco/compression/bit_coders/symbol_bit_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/config/compression_shared.h b/extern/draco/draco/src/draco/compression/config/compression_shared.h index 5204fbc1f3e..40061d3cd48 100644 --- a/extern/draco/dracoenc/src/draco/compression/config/compression_shared.h +++ b/extern/draco/draco/src/draco/compression/config/compression_shared.h @@ -18,7 +18,6 @@ #include <stdint.h> #include "draco/core/macros.h" - #include "draco/draco_features.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/compression/config/decoder_options.h b/extern/draco/draco/src/draco/compression/config/decoder_options.h index 3b3889993e2..3b3889993e2 100644 --- a/extern/draco/dracoenc/src/draco/compression/config/decoder_options.h +++ b/extern/draco/draco/src/draco/compression/config/decoder_options.h diff --git a/extern/draco/dracoenc/src/draco/compression/config/draco_options.h b/extern/draco/draco/src/draco/compression/config/draco_options.h index c77f5df4014..0d1247b2ad1 100644 --- a/extern/draco/dracoenc/src/draco/compression/config/draco_options.h +++ b/extern/draco/draco/src/draco/compression/config/draco_options.h @@ -159,8 +159,9 @@ int DracoOptions<AttributeKeyT>::GetAttributeInt(const AttributeKeyT &att_key, const std::string &name, int default_val) const { const Options *const att_options = FindAttributeOptions(att_key); - if (att_options && att_options->IsOptionSet(name)) + if (att_options && att_options->IsOptionSet(name)) { return att_options->GetInt(name, default_val); + } return global_options_.GetInt(name, default_val); } @@ -176,8 +177,9 @@ float DracoOptions<AttributeKeyT>::GetAttributeFloat( const AttributeKeyT &att_key, const std::string &name, float default_val) const { const Options *const att_options = FindAttributeOptions(att_key); - if (att_options && att_options->IsOptionSet(name)) + if (att_options && att_options->IsOptionSet(name)) { return att_options->GetFloat(name, default_val); + } return global_options_.GetFloat(name, default_val); } @@ -192,8 +194,9 @@ bool DracoOptions<AttributeKeyT>::GetAttributeBool(const AttributeKeyT &att_key, const std::string &name, bool default_val) const { const Options *const att_options = FindAttributeOptions(att_key); - if (att_options && att_options->IsOptionSet(name)) + if (att_options && att_options->IsOptionSet(name)) { return att_options->GetBool(name, default_val); + } return global_options_.GetBool(name, default_val); } @@ -210,8 +213,9 @@ bool DracoOptions<AttributeKeyT>::GetAttributeVector( const AttributeKey &att_key, const std::string &name, int num_dims, DataTypeT *val) const { const Options *const att_options = FindAttributeOptions(att_key); - if (att_options && att_options->IsOptionSet(name)) + if (att_options && att_options->IsOptionSet(name)) { return att_options->GetVector(name, num_dims, val); + } return global_options_.GetVector(name, num_dims, val); } @@ -227,8 +231,9 @@ template <typename AttributeKeyT> bool DracoOptions<AttributeKeyT>::IsAttributeOptionSet( const AttributeKey &att_key, const std::string &name) const { const Options *const att_options = FindAttributeOptions(att_key); - if (att_options) + if (att_options) { return att_options->IsOptionSet(name); + } return global_options_.IsOptionSet(name); } diff --git a/extern/draco/dracoenc/src/draco/compression/config/encoder_options.h b/extern/draco/draco/src/draco/compression/config/encoder_options.h index aacd58e0187..ed1b020683d 100644 --- a/extern/draco/dracoenc/src/draco/compression/config/encoder_options.h +++ b/extern/draco/draco/src/draco/compression/config/encoder_options.h @@ -15,11 +15,10 @@ #ifndef DRACO_COMPRESSION_CONFIG_ENCODER_OPTIONS_H_ #define DRACO_COMPRESSION_CONFIG_ENCODER_OPTIONS_H_ -#include "draco/draco_features.h" - #include "draco/attributes/geometry_attribute.h" #include "draco/compression/config/draco_options.h" #include "draco/compression/config/encoding_features.h" +#include "draco/draco_features.h" namespace draco { @@ -56,8 +55,9 @@ class EncoderOptionsBase : public DracoOptions<AttributeKeyT> { const int encoding_speed = this->GetGlobalInt("encoding_speed", -1); const int decoding_speed = this->GetGlobalInt("decoding_speed", -1); const int max_speed = std::max(encoding_speed, decoding_speed); - if (max_speed == -1) + if (max_speed == -1) { return 5; // Default value. + } return max_speed; } diff --git a/extern/draco/dracoenc/src/draco/compression/config/encoding_features.h b/extern/draco/draco/src/draco/compression/config/encoding_features.h index d6a8b7128a8..d6a8b7128a8 100644 --- a/extern/draco/dracoenc/src/draco/compression/config/encoding_features.h +++ b/extern/draco/draco/src/draco/compression/config/encoding_features.h diff --git a/extern/draco/dracoenc/src/draco/compression/decode.cc b/extern/draco/draco/src/draco/compression/decode.cc index ab70ef1ec60..ab70ef1ec60 100644 --- a/extern/draco/dracoenc/src/draco/compression/decode.cc +++ b/extern/draco/draco/src/draco/compression/decode.cc diff --git a/extern/draco/dracoenc/src/draco/compression/decode.h b/extern/draco/draco/src/draco/compression/decode.h index 0216d72586a..5f3fad26bb4 100644 --- a/extern/draco/dracoenc/src/draco/compression/decode.h +++ b/extern/draco/draco/src/draco/compression/decode.h @@ -15,12 +15,11 @@ #ifndef DRACO_COMPRESSION_DECODE_H_ #define DRACO_COMPRESSION_DECODE_H_ -#include "draco/draco_features.h" - #include "draco/compression/config/compression_shared.h" #include "draco/compression/config/decoder_options.h" #include "draco/core/decoder_buffer.h" #include "draco/core/status_or.h" +#include "draco/draco_features.h" #include "draco/mesh/mesh.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/compression/encode.cc b/extern/draco/draco/src/draco/compression/encode.cc index 5de05ace81f..f380aec1591 100644 --- a/extern/draco/dracoenc/src/draco/compression/encode.cc +++ b/extern/draco/draco/src/draco/compression/encode.cc @@ -85,8 +85,9 @@ void Encoder::SetEncodingMethod(int encoding_method) { Status Encoder::SetAttributePredictionScheme(GeometryAttribute::Type type, int prediction_scheme_method) { Status status = CheckPredictionScheme(type, prediction_scheme_method); - if (!status.ok()) + if (!status.ok()) { return status; + } options().SetAttributeInt(type, "prediction_scheme", prediction_scheme_method); return status; diff --git a/extern/draco/dracoenc/src/draco/compression/encode.h b/extern/draco/draco/src/draco/compression/encode.h index bce8b34c238..bce8b34c238 100644 --- a/extern/draco/dracoenc/src/draco/compression/encode.h +++ b/extern/draco/draco/src/draco/compression/encode.h diff --git a/extern/draco/dracoenc/src/draco/compression/encode_base.h b/extern/draco/draco/src/draco/compression/encode_base.h index 451d970eb6f..0c63a972bf4 100644 --- a/extern/draco/dracoenc/src/draco/compression/encode_base.h +++ b/extern/draco/draco/src/draco/compression/encode_base.h @@ -68,24 +68,29 @@ class EncoderBase { Status CheckPredictionScheme(GeometryAttribute::Type att_type, int prediction_scheme) const { // Out of bound checks: - if (prediction_scheme < PREDICTION_NONE) + if (prediction_scheme < PREDICTION_NONE) { return Status(Status::DRACO_ERROR, "Invalid prediction scheme requested."); - if (prediction_scheme >= NUM_PREDICTION_SCHEMES) + } + if (prediction_scheme >= NUM_PREDICTION_SCHEMES) { return Status(Status::DRACO_ERROR, "Invalid prediction scheme requested."); + } // Deprecated prediction schemes: - if (prediction_scheme == MESH_PREDICTION_TEX_COORDS_DEPRECATED) + if (prediction_scheme == MESH_PREDICTION_TEX_COORDS_DEPRECATED) { return Status(Status::DRACO_ERROR, "MESH_PREDICTION_TEX_COORDS_DEPRECATED is deprecated."); - if (prediction_scheme == MESH_PREDICTION_MULTI_PARALLELOGRAM) + } + if (prediction_scheme == MESH_PREDICTION_MULTI_PARALLELOGRAM) { return Status(Status::DRACO_ERROR, "MESH_PREDICTION_MULTI_PARALLELOGRAM is deprecated."); + } // Attribute specific checks: if (prediction_scheme == MESH_PREDICTION_TEX_COORDS_PORTABLE) { - if (att_type != GeometryAttribute::TEX_COORD) + if (att_type != GeometryAttribute::TEX_COORD) { return Status(Status::DRACO_ERROR, "Invalid prediction scheme for attribute type."); + } } if (prediction_scheme == MESH_PREDICTION_GEOMETRIC_NORMAL) { if (att_type != GeometryAttribute::NORMAL) { diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/ans.h b/extern/draco/draco/src/draco/compression/entropy/ans.h index 310ae256667..c765256b96e 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/ans.h +++ b/extern/draco/draco/src/draco/compression/entropy/ans.h @@ -255,11 +255,12 @@ static inline void uabs_write(struct AnsCoder *ans, int val, AnsP8 p0) { ans->buf[ans->buf_offset++] = ans->state % DRACO_ANS_IO_BASE; ans->state /= DRACO_ANS_IO_BASE; } - if (!val) + if (!val) { ans->state = DRACO_ANS_DIV(ans->state * DRACO_ANS_P8_PRECISION, p0); - else + } else { ans->state = DRACO_ANS_DIV((ans->state + 1) * DRACO_ANS_P8_PRECISION + p - 1, p) - 1; + } } static inline int uabs_read(struct AnsDecoder *ans, AnsP8 p0) { @@ -276,10 +277,11 @@ static inline int uabs_read(struct AnsDecoder *ans, AnsP8 p0) { xp = sp / DRACO_ANS_P8_PRECISION; // s = xp1 - xp; s = (sp & 0xFF) >= p0; - if (UNPREDICTABLE(s)) + if (UNPREDICTABLE(s)) { ans->state = xp; - else + } else { ans->state = state - xp; + } return s; } @@ -297,29 +299,33 @@ static inline int uabs_read_bit(struct AnsDecoder *ans) { static inline int ans_read_init(struct AnsDecoder *const ans, const uint8_t *const buf, int offset) { unsigned x; - if (offset < 1) + if (offset < 1) { return 1; + } ans->buf = buf; x = buf[offset - 1] >> 6; if (x == 0) { ans->buf_offset = offset - 1; ans->state = buf[offset - 1] & 0x3F; } else if (x == 1) { - if (offset < 2) + if (offset < 2) { return 1; + } ans->buf_offset = offset - 2; ans->state = mem_get_le16(buf + offset - 2) & 0x3FFF; } else if (x == 2) { - if (offset < 3) + if (offset < 3) { return 1; + } ans->buf_offset = offset - 3; ans->state = mem_get_le24(buf + offset - 3) & 0x3FFFFF; } else { return 1; } ans->state += DRACO_ANS_L_BASE; - if (ans->state >= DRACO_ANS_L_BASE * DRACO_ANS_IO_BASE) + if (ans->state >= DRACO_ANS_L_BASE * DRACO_ANS_IO_BASE) { return 1; + } return 0; } @@ -415,21 +421,24 @@ class RAnsDecoder { // error. inline int read_init(const uint8_t *const buf, int offset) { unsigned x; - if (offset < 1) + if (offset < 1) { return 1; + } ans_.buf = buf; x = buf[offset - 1] >> 6; if (x == 0) { ans_.buf_offset = offset - 1; ans_.state = buf[offset - 1] & 0x3F; } else if (x == 1) { - if (offset < 2) + if (offset < 2) { return 1; + } ans_.buf_offset = offset - 2; ans_.state = mem_get_le16(buf + offset - 2) & 0x3FFF; } else if (x == 2) { - if (offset < 3) + if (offset < 3) { return 1; + } ans_.buf_offset = offset - 3; ans_.state = mem_get_le24(buf + offset - 3) & 0x3FFFFF; } else if (x == 3) { @@ -439,8 +448,9 @@ class RAnsDecoder { return 1; } ans_.state += l_rans_base; - if (ans_.state >= l_rans_base * DRACO_ANS_IO_BASE) + if (ans_.state >= l_rans_base * DRACO_ANS_IO_BASE) { return 1; + } return 0; } diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/rans_symbol_coding.h b/extern/draco/draco/src/draco/compression/entropy/rans_symbol_coding.h index 0a68e29fe26..0a68e29fe26 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/rans_symbol_coding.h +++ b/extern/draco/draco/src/draco/compression/entropy/rans_symbol_coding.h diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/rans_symbol_decoder.h b/extern/draco/draco/src/draco/compression/entropy/rans_symbol_decoder.h index 1b5f1c8b715..10cdc6781a0 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/rans_symbol_decoder.h +++ b/extern/draco/draco/src/draco/compression/entropy/rans_symbol_decoder.h @@ -15,12 +15,11 @@ #ifndef DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_DECODER_H_ #define DRACO_COMPRESSION_ENTROPY_RANS_SYMBOL_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/config/compression_shared.h" #include "draco/compression/entropy/rans_symbol_coding.h" #include "draco/core/decoder_buffer.h" #include "draco/core/varint_decoding.h" +#include "draco/draco_features.h" namespace draco { @@ -59,30 +58,35 @@ template <int unique_symbols_bit_length_t> bool RAnsSymbolDecoder<unique_symbols_bit_length_t>::Create( DecoderBuffer *buffer) { // Check that the DecoderBuffer version is set. - if (buffer->bitstream_version() == 0) + if (buffer->bitstream_version() == 0) { return false; - // Decode the number of alphabet symbols. + } + // Decode the number of alphabet symbols. #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!buffer->Decode(&num_symbols_)) + if (!buffer->Decode(&num_symbols_)) { return false; + } } else #endif { - if (!DecodeVarint(&num_symbols_, buffer)) + if (!DecodeVarint(&num_symbols_, buffer)) { return false; + } } probability_table_.resize(num_symbols_); - if (num_symbols_ == 0) + if (num_symbols_ == 0) { return true; + } // Decode the table. for (uint32_t i = 0; i < num_symbols_; ++i) { uint8_t prob_data = 0; // Decode the first byte and extract the number of extra bytes we need to // get, or the offset to the next symbol with non-zero probability. - if (!buffer->Decode(&prob_data)) + if (!buffer->Decode(&prob_data)) { return false; + } // Token is stored in the first two bits of the first byte. Values 0-2 are // used to indicate the number of extra bytes, and value 3 is a special // symbol used to denote run-length coding of zero probability entries. @@ -90,8 +94,9 @@ bool RAnsSymbolDecoder<unique_symbols_bit_length_t>::Create( const int token = prob_data & 3; if (token == 3) { const uint32_t offset = prob_data >> 2; - if (i + offset >= num_symbols_) + if (i + offset >= num_symbols_) { return false; + } // Set zero probability for all symbols in the specified range. for (uint32_t j = 0; j < offset + 1; ++j) { probability_table_[i + j] = 0; @@ -102,8 +107,9 @@ bool RAnsSymbolDecoder<unique_symbols_bit_length_t>::Create( uint32_t prob = prob_data >> 2; for (int b = 0; b < extra_bytes; ++b) { uint8_t eb; - if (!buffer->Decode(&eb)) + if (!buffer->Decode(&eb)) { return false; + } // Shift 8 bits for each extra byte and subtract 2 for the two first // bits. prob |= static_cast<uint32_t>(eb) << (8 * (b + 1) - 2); @@ -111,8 +117,9 @@ bool RAnsSymbolDecoder<unique_symbols_bit_length_t>::Create( probability_table_[i] = prob; } } - if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) + if (!ans_.rans_build_look_up_table(&probability_table_[0], num_symbols_)) { return false; + } return true; } @@ -123,23 +130,27 @@ bool RAnsSymbolDecoder<unique_symbols_bit_length_t>::StartDecoding( // Decode the number of bytes encoded by the encoder. #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (buffer->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!buffer->Decode(&bytes_encoded)) + if (!buffer->Decode(&bytes_encoded)) { return false; + } } else #endif { - if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) + if (!DecodeVarint<uint64_t>(&bytes_encoded, buffer)) { return false; + } } - if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) + if (bytes_encoded > static_cast<uint64_t>(buffer->remaining_size())) { return false; + } const uint8_t *const data_head = reinterpret_cast<const uint8_t *>(buffer->data_head()); // Advance the buffer past the rANS data. buffer->Advance(bytes_encoded); - if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) + if (ans_.read_init(data_head, static_cast<int>(bytes_encoded)) != 0) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/rans_symbol_encoder.h b/extern/draco/draco/src/draco/compression/entropy/rans_symbol_encoder.h index 4b0ed091af0..4e07ec87123 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/rans_symbol_encoder.h +++ b/extern/draco/draco/src/draco/compression/entropy/rans_symbol_encoder.h @@ -91,8 +91,9 @@ bool RAnsSymbolEncoder<unique_symbols_bit_length_t>::Create( int max_valid_symbol = 0; for (int i = 0; i < num_symbols; ++i) { total_freq += frequencies[i]; - if (frequencies[i] > 0) + if (frequencies[i] > 0) { max_valid_symbol = i; + } } num_symbols = max_valid_symbol + 1; num_symbols_ = num_symbols; @@ -111,8 +112,9 @@ bool RAnsSymbolEncoder<unique_symbols_bit_length_t>::Create( // RAns probability in range of [1, rans_precision - 1]. uint32_t rans_prob = static_cast<uint32_t>(prob * rans_precision_d + 0.5f); - if (rans_prob == 0 && freq > 0) + if (rans_prob == 0 && freq > 0) { rans_prob = 1; + } probability_table_[i].prob = rans_prob; total_rans_prob += rans_prob; } @@ -140,25 +142,30 @@ bool RAnsSymbolEncoder<unique_symbols_bit_length_t>::Create( for (int j = num_symbols - 1; j > 0; --j) { int symbol_id = sorted_probabilities[j]; if (probability_table_[symbol_id].prob <= 1) { - if (j == num_symbols - 1) + if (j == num_symbols - 1) { return false; // Most frequent symbol would be empty. + } break; } const int32_t new_prob = static_cast<int32_t>( floor(act_rel_error_d * static_cast<double>(probability_table_[symbol_id].prob))); int32_t fix = probability_table_[symbol_id].prob - new_prob; - if (fix == 0u) + if (fix == 0u) { fix = 1; - if (fix >= static_cast<int32_t>(probability_table_[symbol_id].prob)) + } + if (fix >= static_cast<int32_t>(probability_table_[symbol_id].prob)) { fix = probability_table_[symbol_id].prob - 1; - if (fix > error) + } + if (fix > error) { fix = error; + } probability_table_[symbol_id].prob -= fix; total_rans_prob -= fix; error -= fix; - if (total_rans_prob == rans_precision_) + if (total_rans_prob == rans_precision_) { break; + } } } } @@ -170,8 +177,9 @@ bool RAnsSymbolEncoder<unique_symbols_bit_length_t>::Create( probability_table_[i].cum_prob = total_prob; total_prob += probability_table_[i].prob; } - if (total_prob != rans_precision_) + if (total_prob != rans_precision_) { return false; + } // Estimate the number of bits needed to encode the input. // From Shannon entropy the total number of bits N is: @@ -180,15 +188,17 @@ bool RAnsSymbolEncoder<unique_symbols_bit_length_t>::Create( // symbol's frequency in the input data. double num_bits = 0; for (int i = 0; i < num_symbols; ++i) { - if (probability_table_[i].prob == 0) + if (probability_table_[i].prob == 0) { continue; + } const double norm_prob = static_cast<double>(probability_table_[i].prob) / rans_precision_d; num_bits += static_cast<double>(frequencies[i]) * log2(norm_prob); } num_expected_bits_ = static_cast<uint64_t>(ceil(-num_bits)); - if (!EncodeTable(buffer)) + if (!EncodeTable(buffer)) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy.cc b/extern/draco/draco/src/draco/compression/entropy/shannon_entropy.cc index 5050c11188c..137eafe5fac 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy.cc +++ b/extern/draco/draco/src/draco/compression/entropy/shannon_entropy.cc @@ -27,20 +27,23 @@ int64_t ComputeShannonEntropy(const uint32_t *symbols, int num_symbols, log2(static_cast<double>(symbol_frequencies[i]) / num_symbols_d); } } - if (out_num_unique_symbols) + if (out_num_unique_symbols) { *out_num_unique_symbols = num_unique_symbols; + } // Entropy is always negative. return static_cast<int64_t>(-total_bits); } double ComputeBinaryShannonEntropy(uint32_t num_values, uint32_t num_true_values) { - if (num_values == 0) + if (num_values == 0) { return 0; + } // We can exit early if the data set has 0 entropy. - if (num_true_values == 0 || num_values == num_true_values) + if (num_true_values == 0 || num_values == num_true_values) { return 0; + } const double true_freq = static_cast<double>(num_true_values) / static_cast<double>(num_values); const double false_freq = 1.0 - true_freq; @@ -120,8 +123,9 @@ ShannonEntropyTracker::EntropyData ShannonEntropyTracker::UpdateSymbols( int64_t ShannonEntropyTracker::GetNumberOfDataBits( const EntropyData &entropy_data) { - if (entropy_data.num_values < 2) + if (entropy_data.num_values < 2) { return 0; + } // We need to compute the number of bits required to represent the stream // using the entropy norm. Note that: // diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy.h b/extern/draco/draco/src/draco/compression/entropy/shannon_entropy.h index 85165f4cb8d..85165f4cb8d 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy.h +++ b/extern/draco/draco/src/draco/compression/entropy/shannon_entropy.h diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_decoding.cc b/extern/draco/draco/src/draco/compression/entropy/symbol_decoding.cc index 39a1eb0ff24..93d29971c89 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_decoding.cc +++ b/extern/draco/draco/src/draco/compression/entropy/symbol_decoding.cc @@ -31,12 +31,14 @@ bool DecodeRawSymbols(uint32_t num_values, DecoderBuffer *src_buffer, bool DecodeSymbols(uint32_t num_values, int num_components, DecoderBuffer *src_buffer, uint32_t *out_values) { - if (num_values == 0) + if (num_values == 0) { return true; + } // Decode which scheme to use. uint8_t scheme; - if (!src_buffer->Decode(&scheme)) + if (!src_buffer->Decode(&scheme)) { return false; + } if (scheme == SYMBOL_CODING_TAGGED) { return DecodeTaggedSymbols<RAnsSymbolDecoder>(num_values, num_components, src_buffer, out_values); @@ -52,14 +54,17 @@ bool DecodeTaggedSymbols(uint32_t num_values, int num_components, DecoderBuffer *src_buffer, uint32_t *out_values) { // Decode the encoded data. SymbolDecoderT<5> tag_decoder; - if (!tag_decoder.Create(src_buffer)) + if (!tag_decoder.Create(src_buffer)) { return false; + } - if (!tag_decoder.StartDecoding(src_buffer)) + if (!tag_decoder.StartDecoding(src_buffer)) { return false; + } - if (num_values > 0 && tag_decoder.num_symbols() == 0) + if (num_values > 0 && tag_decoder.num_symbols() == 0) { return false; // Wrong number of symbols. + } // src_buffer now points behind the encoded tag data (to the place where the // values are encoded). @@ -71,8 +76,9 @@ bool DecodeTaggedSymbols(uint32_t num_values, int num_components, // Decode the actual value. for (int j = 0; j < num_components; ++j) { uint32_t val; - if (!src_buffer->DecodeLeastSignificantBits32(bit_length, &val)) + if (!src_buffer->DecodeLeastSignificantBits32(bit_length, &val)) { return false; + } out_values[value_id++] = val; } } @@ -85,14 +91,17 @@ template <class SymbolDecoderT> bool DecodeRawSymbolsInternal(uint32_t num_values, DecoderBuffer *src_buffer, uint32_t *out_values) { SymbolDecoderT decoder; - if (!decoder.Create(src_buffer)) + if (!decoder.Create(src_buffer)) { return false; + } - if (num_values > 0 && decoder.num_symbols() == 0) + if (num_values > 0 && decoder.num_symbols() == 0) { return false; // Wrong number of symbols. + } - if (!decoder.StartDecoding(src_buffer)) + if (!decoder.StartDecoding(src_buffer)) { return false; + } for (uint32_t i = 0; i < num_values; ++i) { // Decode a symbol into the value. const uint32_t value = decoder.DecodeSymbol(); @@ -106,8 +115,9 @@ template <template <int> class SymbolDecoderT> bool DecodeRawSymbols(uint32_t num_values, DecoderBuffer *src_buffer, uint32_t *out_values) { uint8_t max_bit_length; - if (!src_buffer->Decode(&max_bit_length)) + if (!src_buffer->Decode(&max_bit_length)) { return false; + } switch (max_bit_length) { case 1: return DecodeRawSymbolsInternal<SymbolDecoderT<1>>(num_values, src_buffer, diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_decoding.h b/extern/draco/draco/src/draco/compression/entropy/symbol_decoding.h index ea11165c347..ea11165c347 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_decoding.h +++ b/extern/draco/draco/src/draco/compression/entropy/symbol_decoding.h diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_encoding.cc b/extern/draco/draco/src/draco/compression/entropy/symbol_encoding.cc index 9a5868c40a5..710c96284da 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_encoding.cc +++ b/extern/draco/draco/src/draco/compression/entropy/symbol_encoding.cc @@ -36,8 +36,9 @@ void SetSymbolEncodingMethod(Options *options, SymbolCodingMethod method) { bool SetSymbolEncodingCompressionLevel(Options *options, int compression_level) { - if (compression_level < 0 || compression_level > 10) + if (compression_level < 0 || compression_level > 10) { return false; + } options->SetInt("symbol_encoding_compression_level", compression_level); return true; } @@ -56,8 +57,9 @@ static void ComputeBitLengths(const uint32_t *symbols, int num_values, // Get the maximum value for a given entry across all attribute components. uint32_t max_component_value = symbols[i]; for (int j = 1; j < num_components; ++j) { - if (max_component_value < symbols[i + j]) + if (max_component_value < symbols[i + j]) { max_component_value = symbols[i + j]; + } } int value_msb_pos = 0; if (max_component_value > 0) { @@ -113,12 +115,15 @@ bool EncodeRawSymbols(const uint32_t *symbols, int num_values, bool EncodeSymbols(const uint32_t *symbols, int num_values, int num_components, const Options *options, EncoderBuffer *target_buffer) { - if (num_values < 0) + if (num_values < 0) { return false; - if (num_values == 0) + } + if (num_values == 0) { return true; - if (num_components <= 0) + } + if (num_components <= 0) { num_components = 1; + } std::vector<uint32_t> bit_lengths; uint32_t max_value; ComputeBitLengths(symbols, num_values, num_components, &bit_lengths, @@ -275,8 +280,9 @@ bool EncodeRawSymbols(const uint32_t *symbols, int num_values, } int unique_symbols_bit_length = symbol_bits + 1; // Currently, we don't support encoding of more than 2^18 unique symbols. - if (unique_symbols_bit_length > kMaxRawEncodingBitLength) + if (unique_symbols_bit_length > kMaxRawEncodingBitLength) { return false; + } int compression_level = kDefaultSymbolCodingCompressionLevel; if (options != nullptr && options->IsOptionSet("symbol_encoding_compression_level")) { diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_encoding.h b/extern/draco/draco/src/draco/compression/entropy/symbol_encoding.h index 839b28b17a5..839b28b17a5 100644 --- a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_encoding.h +++ b/extern/draco/draco/src/draco/compression/entropy/symbol_encoding.h diff --git a/extern/draco/dracoenc/src/draco/compression/expert_encode.cc b/extern/draco/draco/src/draco/compression/expert_encode.cc index 112e6ae3d3e..4c70a72a765 100644 --- a/extern/draco/dracoenc/src/draco/compression/expert_encode.cc +++ b/extern/draco/draco/src/draco/compression/expert_encode.cc @@ -30,8 +30,9 @@ ExpertEncoder::ExpertEncoder(const Mesh &mesh) : point_cloud_(&mesh), mesh_(&mesh) {} Status ExpertEncoder::EncodeToBuffer(EncoderBuffer *out_buffer) { - if (point_cloud_ == nullptr) + if (point_cloud_ == nullptr) { return Status(Status::DRACO_ERROR, "Invalid input geometry."); + } if (mesh_ == nullptr) { return EncodePointCloudToBuffer(*point_cloud_, out_buffer); } @@ -62,13 +63,16 @@ Status ExpertEncoder::EncodePointCloudToBuffer(const PointCloud &pc, if (kd_tree_possible && att->data_type() != DT_FLOAT32 && att->data_type() != DT_UINT32 && att->data_type() != DT_UINT16 && att->data_type() != DT_UINT8 && att->data_type() != DT_INT32 && - att->data_type() != DT_INT16 && att->data_type() != DT_INT8) + att->data_type() != DT_INT16 && att->data_type() != DT_INT8) { kd_tree_possible = false; + } if (kd_tree_possible && att->data_type() == DT_FLOAT32 && - options().GetAttributeInt(0, "quantization_bits", -1) <= 0) + options().GetAttributeInt(0, "quantization_bits", -1) <= 0) { kd_tree_possible = false; // Quantization not enabled. - if (!kd_tree_possible) + } + if (!kd_tree_possible) { break; + } } if (kd_tree_possible) { @@ -167,8 +171,9 @@ Status ExpertEncoder::SetAttributePredictionScheme( auto att_type = att->attribute_type(); const Status status = CheckPredictionScheme(att_type, prediction_scheme_method); - if (!status.ok()) + if (!status.ok()) { return status; + } options().SetAttributeInt(attribute_id, "prediction_scheme", prediction_scheme_method); return status; diff --git a/extern/draco/dracoenc/src/draco/compression/expert_encode.h b/extern/draco/draco/src/draco/compression/expert_encode.h index a1aa7b8b3a8..a1aa7b8b3a8 100644 --- a/extern/draco/dracoenc/src/draco/compression/expert_encode.h +++ b/extern/draco/draco/src/draco/compression/expert_encode.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder.cc b/extern/draco/draco/src/draco/compression/mesh/mesh_decoder.cc index 01913dcd047..6e48e56fb98 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder.cc +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_decoder.cc @@ -25,10 +25,12 @@ Status MeshDecoder::Decode(const DecoderOptions &options, } bool MeshDecoder::DecodeGeometryData() { - if (mesh_ == nullptr) + if (mesh_ == nullptr) { return false; - if (!DecodeConnectivity()) + } + if (!DecodeConnectivity()) { return false; + } return PointCloudDecoder::DecodeGeometryData(); } diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_decoder.h index 397a679d440..397a679d440 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder.cc b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder.cc index e164f82b12b..427dd59f5df 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder.cc +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/compression/mesh/mesh_edgebreaker_decoder.h" + #include "draco/compression/mesh/mesh_edgebreaker_decoder_impl.h" #include "draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h" #include "draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h" @@ -27,8 +28,9 @@ bool MeshEdgebreakerDecoder::CreateAttributesDecoder(int32_t att_decoder_id) { bool MeshEdgebreakerDecoder::InitializeDecoder() { uint8_t traversal_decoder_type; - if (!buffer()->Decode(&traversal_decoder_type)) + if (!buffer()->Decode(&traversal_decoder_type)) { return false; + } impl_ = nullptr; if (traversal_decoder_type == MESH_EDGEBREAKER_STANDARD_ENCODING) { #ifdef DRACO_STANDARD_EDGEBREAKER_SUPPORTED @@ -51,8 +53,9 @@ bool MeshEdgebreakerDecoder::InitializeDecoder() { if (!impl_) { return false; } - if (!impl_->Init(this)) + if (!impl_->Init(this)) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder.h index c3569405220..5c161794298 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder.h @@ -15,10 +15,9 @@ #ifndef DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_DECODER_H_ #define DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/mesh/mesh_decoder.h" #include "draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h" +#include "draco/draco_features.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.cc b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.cc index 9b91a6f07c4..50d1971c15b 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.cc +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.cc @@ -65,14 +65,16 @@ MeshEdgebreakerDecoderImpl<TraversalDecoder>::GetAttributeCornerTable( int att_id) const { for (uint32_t i = 0; i < attribute_data_.size(); ++i) { const int decoder_id = attribute_data_[i].decoder_id; - if (decoder_id < 0 || decoder_id >= decoder_->num_attributes_decoders()) + if (decoder_id < 0 || decoder_id >= decoder_->num_attributes_decoders()) { continue; + } const AttributesDecoderInterface *const dec = decoder_->attributes_decoder(decoder_id); for (int j = 0; j < dec->GetNumAttributes(); ++j) { if (dec->GetAttributeId(j) == att_id) { - if (attribute_data_[i].is_connectivity_used) + if (attribute_data_[i].is_connectivity_used) { return &attribute_data_[i].connectivity_data; + } return nullptr; } } @@ -86,13 +88,15 @@ MeshEdgebreakerDecoderImpl<TraversalDecoder>::GetAttributeEncodingData( int att_id) const { for (uint32_t i = 0; i < attribute_data_.size(); ++i) { const int decoder_id = attribute_data_[i].decoder_id; - if (decoder_id < 0 || decoder_id >= decoder_->num_attributes_decoders()) + if (decoder_id < 0 || decoder_id >= decoder_->num_attributes_decoders()) { continue; + } const AttributesDecoderInterface *const dec = decoder_->attributes_decoder(decoder_id); for (int j = 0; j < dec->GetNumAttributes(); ++j) { - if (dec->GetAttributeId(j) == att_id) + if (dec->GetAttributeId(j) == att_id) { return &attribute_data_[i].encoding_data; + } } } return &pos_encoding_data_; @@ -124,11 +128,13 @@ template <class TraversalDecoder> bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::CreateAttributesDecoder( int32_t att_decoder_id) { int8_t att_data_id; - if (!decoder_->buffer()->Decode(&att_data_id)) + if (!decoder_->buffer()->Decode(&att_data_id)) { return false; + } uint8_t decoder_type; - if (!decoder_->buffer()->Decode(&decoder_type)) + if (!decoder_->buffer()->Decode(&decoder_type)) { return false; + } if (att_data_id >= 0) { if (att_data_id >= attribute_data_.size()) { @@ -137,22 +143,25 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::CreateAttributesDecoder( // Ensure that the attribute data is not mapped to a different attributes // decoder already. - if (attribute_data_[att_data_id].decoder_id >= 0) + if (attribute_data_[att_data_id].decoder_id >= 0) { return false; + } attribute_data_[att_data_id].decoder_id = att_decoder_id; } else { // Assign the attributes decoder to |pos_encoding_data_|. - if (pos_data_decoder_id_ >= 0) + if (pos_data_decoder_id_ >= 0) { return false; // Some other decoder is already using the data. Error. + } pos_data_decoder_id_ = att_decoder_id; } MeshTraversalMethod traversal_method = MESH_TRAVERSAL_DEPTH_FIRST; if (decoder_->bitstream_version() >= DRACO_BITSTREAM_VERSION(1, 2)) { uint8_t traversal_method_encoded; - if (!decoder_->buffer()->Decode(&traversal_method_encoded)) + if (!decoder_->buffer()->Decode(&traversal_method_encoded)) { return false; + } traversal_method = static_cast<MeshTraversalMethod>(traversal_method_encoded); } @@ -186,10 +195,12 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::CreateAttributesDecoder( return false; // Unsupported method } } else { - if (traversal_method != MESH_TRAVERSAL_DEPTH_FIRST) + if (traversal_method != MESH_TRAVERSAL_DEPTH_FIRST) { return false; // Unsupported method. - if (att_data_id < 0) + } + if (att_data_id < 0) { return false; // Attribute data must be specified. + } // Per-corner attribute decoder. @@ -216,8 +227,9 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::CreateAttributesDecoder( sequencer = std::move(traversal_sequencer); } - if (!sequencer) + if (!sequencer) { return false; + } std::unique_ptr<SequentialAttributeDecodersController> att_controller( new SequentialAttributeDecodersController(std::move(sequencer))); @@ -234,11 +246,13 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { uint32_t num_new_verts; if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!decoder_->buffer()->Decode(&num_new_verts)) + if (!decoder_->buffer()->Decode(&num_new_verts)) { return false; + } } else { - if (!DecodeVarint(&num_new_verts, decoder_->buffer())) + if (!DecodeVarint(&num_new_verts, decoder_->buffer())) { return false; + } } num_new_vertices_ = num_new_verts; } @@ -247,50 +261,58 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { uint32_t num_encoded_vertices; #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!decoder_->buffer()->Decode(&num_encoded_vertices)) + if (!decoder_->buffer()->Decode(&num_encoded_vertices)) { return false; + } } else #endif { - if (!DecodeVarint(&num_encoded_vertices, decoder_->buffer())) + if (!DecodeVarint(&num_encoded_vertices, decoder_->buffer())) { return false; + } } num_encoded_vertices_ = num_encoded_vertices; uint32_t num_faces; #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!decoder_->buffer()->Decode(&num_faces)) + if (!decoder_->buffer()->Decode(&num_faces)) { return false; + } } else #endif { - if (!DecodeVarint(&num_faces, decoder_->buffer())) + if (!DecodeVarint(&num_faces, decoder_->buffer())) { return false; + } } - if (num_faces > std::numeric_limits<CornerIndex::ValueType>::max() / 3) + if (num_faces > std::numeric_limits<CornerIndex::ValueType>::max() / 3) { return false; // Draco cannot handle this many faces. + } if (static_cast<uint32_t>(num_encoded_vertices_) > num_faces * 3) { return false; // There cannot be more vertices than 3 * num_faces. } uint8_t num_attribute_data; - if (!decoder_->buffer()->Decode(&num_attribute_data)) + if (!decoder_->buffer()->Decode(&num_attribute_data)) { return false; + } uint32_t num_encoded_symbols; #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!decoder_->buffer()->Decode(&num_encoded_symbols)) + if (!decoder_->buffer()->Decode(&num_encoded_symbols)) { return false; + } } else #endif { - if (!DecodeVarint(&num_encoded_symbols, decoder_->buffer())) + if (!DecodeVarint(&num_encoded_symbols, decoder_->buffer())) { return false; + } } if (num_faces < num_encoded_symbols) { @@ -311,14 +333,16 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { uint32_t num_encoded_split_symbols; #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!decoder_->buffer()->Decode(&num_encoded_split_symbols)) + if (!decoder_->buffer()->Decode(&num_encoded_split_symbols)) { return false; + } } else #endif { - if (!DecodeVarint(&num_encoded_split_symbols, decoder_->buffer())) + if (!DecodeVarint(&num_encoded_split_symbols, decoder_->buffer())) { return false; + } } if (num_encoded_split_symbols > num_encoded_symbols) { @@ -328,8 +352,9 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { // Decode topology (connectivity). vertex_traversal_length_.clear(); corner_table_ = std::unique_ptr<CornerTable>(new CornerTable()); - if (corner_table_ == nullptr) + if (corner_table_ == nullptr) { return false; + } processed_corner_ids_.clear(); processed_corner_ids_.reserve(num_faces); processed_connectivity_corners_.clear(); @@ -347,9 +372,10 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { // Add one attribute data for each attribute decoder. attribute_data_.resize(num_attribute_data); - if (!corner_table_->Reset(num_faces, - num_encoded_vertices_ + num_encoded_split_symbols)) + if (!corner_table_->Reset( + num_faces, num_encoded_vertices_ + num_encoded_split_symbols)) { return false; + } // Start with all vertices marked as holes (boundaries). // Only vertices decoded with TOPOLOGY_C symbol (and the initial face) will @@ -363,15 +389,18 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { uint32_t encoded_connectivity_size; if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!decoder_->buffer()->Decode(&encoded_connectivity_size)) + if (!decoder_->buffer()->Decode(&encoded_connectivity_size)) { return false; + } } else { - if (!DecodeVarint(&encoded_connectivity_size, decoder_->buffer())) + if (!DecodeVarint(&encoded_connectivity_size, decoder_->buffer())) { return false; + } } if (encoded_connectivity_size == 0 || - encoded_connectivity_size > decoder_->buffer()->remaining_size()) + encoded_connectivity_size > decoder_->buffer()->remaining_size()) { return false; + } DecoderBuffer event_buffer; event_buffer.Init( decoder_->buffer()->data_head() + encoded_connectivity_size, @@ -380,14 +409,16 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { // Decode hole and topology split events. topology_split_decoded_bytes = DecodeHoleAndTopologySplitEvents(&event_buffer); - if (topology_split_decoded_bytes == -1) + if (topology_split_decoded_bytes == -1) { return false; + } } else #endif { - if (DecodeHoleAndTopologySplitEvents(decoder_->buffer()) == -1) + if (DecodeHoleAndTopologySplitEvents(decoder_->buffer()) == -1) { return false; + } } traversal_decoder_.Init(this); @@ -397,12 +428,14 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { traversal_decoder_.SetNumAttributeData(num_attribute_data); DecoderBuffer traversal_end_buffer; - if (!traversal_decoder_.Start(&traversal_end_buffer)) + if (!traversal_decoder_.Start(&traversal_end_buffer)) { return false; + } const int num_connectivity_verts = DecodeConnectivity(num_encoded_symbols); - if (num_connectivity_verts == -1) + if (num_connectivity_verts == -1) { return false; + } // Set the main buffer to the end of the traversal. decoder_->buffer()->Init(traversal_end_buffer.data_head(), @@ -421,16 +454,18 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 1)) { for (CornerIndex ci(0); ci < corner_table_->num_corners(); ci += 3) { - if (!DecodeAttributeConnectivitiesOnFaceLegacy(ci)) + if (!DecodeAttributeConnectivitiesOnFaceLegacy(ci)) { return false; + } } } else #endif { for (CornerIndex ci(0); ci < corner_table_->num_corners(); ci += 3) { - if (!DecodeAttributeConnectivitiesOnFace(ci)) + if (!DecodeAttributeConnectivitiesOnFace(ci)) { return false; + } } } } @@ -456,12 +491,14 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity() { // it). int32_t att_connectivity_verts = attribute_data_[i].connectivity_data.num_vertices(); - if (att_connectivity_verts < corner_table_->num_vertices()) + if (att_connectivity_verts < corner_table_->num_vertices()) { att_connectivity_verts = corner_table_->num_vertices(); + } attribute_data_[i].encoding_data.Init(att_connectivity_verts); } - if (!AssignPointsToCorners(num_connectivity_verts)) + if (!AssignPointsToCorners(num_connectivity_verts)) { return false; + } return true; } @@ -523,8 +560,9 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( // Find the corner "b" from the corner "a" which is the corner on the // top of the active stack. - if (active_corner_stack.empty()) + if (active_corner_stack.empty()) { return -1; + } const CornerIndex corner_a = active_corner_stack.back(); const VertexIndex vertex_x = @@ -565,8 +603,9 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( // . . // . . // * - if (active_corner_stack.empty()) + if (active_corner_stack.empty()) { return -1; + } const CornerIndex corner_a = active_corner_stack.back(); // First corner on the new face is either corner "l" or "r". @@ -587,8 +626,9 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( // Update vertex mapping. const VertexIndex new_vert_index = corner_table_->AddNewVertex(); - if (corner_table_->num_vertices() > max_num_vertices) + if (corner_table_->num_vertices() > max_num_vertices) { return -1; // Unexpected number of decoded vertices. + } corner_table_->MapCornerToVertex(opp_corner, new_vert_index); corner_table_->SetLeftMostCorner(new_vert_index, opp_corner); @@ -614,8 +654,9 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( // \ / S \ / // *.......* // - if (active_corner_stack.empty()) + if (active_corner_stack.empty()) { return -1; + } const CornerIndex corner_b = active_corner_stack.back(); active_corner_stack.pop_back(); @@ -626,8 +667,9 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( // Topology split event. Move the retrieved edge to the stack. active_corner_stack.push_back(it->second); } - if (active_corner_stack.empty()) + if (active_corner_stack.empty()) { return -1; + } const CornerIndex corner_a = active_corner_stack.back(); if (corner_table_->Opposite(corner_a) != kInvalidCornerIndex || @@ -669,8 +711,9 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( // Make sure the old vertex n is now mapped to an invalid corner (make it // isolated). corner_table_->MakeVertexIsolated(vertex_n); - if (remove_invalid_vertices) + if (remove_invalid_vertices) { invalid_vertices.push_back(vertex_n); + } active_corner_stack.back() = corner; } else if (symbol == TOPOLOGY_E) { const CornerIndex corner(3 * face.value()); @@ -682,8 +725,9 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( corner_table_->MapCornerToVertex(corner + 2, corner_table_->AddNewVertex()); - if (corner_table_->num_vertices() > max_num_vertices) + if (corner_table_->num_vertices() > max_num_vertices) { return -1; // Unexpected number of decoded vertices. + } corner_table_->SetLeftMostCorner(first_vert_index, corner); corner_table_->SetLeftMostCorner(first_vert_index + 1, corner + 1); @@ -713,8 +757,9 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( int encoder_split_symbol_id; while (IsTopologySplit(encoder_symbol_id, &split_edge, &encoder_split_symbol_id)) { - if (encoder_split_symbol_id < 0) + if (encoder_split_symbol_id < 0) { return -1; // Wrong split symbol id. + } // Symbol was part of a topology split. Now we need to determine which // edge should be added to the active edges stack. const CornerIndex act_top_corner = active_corner_stack.back(); @@ -742,8 +787,9 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( } } } - if (corner_table_->num_vertices() > max_num_vertices) + if (corner_table_->num_vertices() > max_num_vertices) { return -1; // Unexpected number of decoded vertices. + } // Decode start faces and connect them to the faces from the active stack. while (active_corner_stack.size() > 0) { const CornerIndex corner = active_corner_stack.back(); @@ -817,21 +863,23 @@ int MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeConnectivity( init_corners_.push_back(corner); } } - if (num_faces != corner_table_->num_faces()) + if (num_faces != corner_table_->num_faces()) { return -1; // Unexpected number of decoded faces. + } int num_vertices = corner_table_->num_vertices(); // If any vertex was marked as isolated, we want to remove it from the corner // table to ensure that all vertices in range <0, num_vertices> are valid. - for (const VertexIndex invalid_vert : invalid_vertices) { + for (const VertexIndex& invalid_vert : invalid_vertices) { // Find the last valid vertex and swap it with the isolated vertex. VertexIndex src_vert(num_vertices - 1); while (corner_table_->LeftMostCorner(src_vert) == kInvalidCornerIndex) { // The last vertex is invalid, proceed to the previous one. src_vert = VertexIndex(--num_vertices - 1); } - if (src_vert < invalid_vert) + if (src_vert < invalid_vert) { continue; // No need to swap anything. + } // Remap all corners mapped to |src_vert| to |invalid_vert|. VertexCornersIterator<CornerTable> vcit(corner_table_.get(), src_vert); @@ -861,29 +909,36 @@ MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeHoleAndTopologySplitEvents( uint32_t num_topology_splits; #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!decoder_buffer->Decode(&num_topology_splits)) + if (!decoder_buffer->Decode(&num_topology_splits)) { return -1; + } } else #endif { - if (!DecodeVarint(&num_topology_splits, decoder_buffer)) + if (!DecodeVarint(&num_topology_splits, decoder_buffer)) { return -1; + } } if (num_topology_splits > 0) { - if (num_topology_splits > static_cast<uint32_t>(corner_table_->num_faces())) + if (num_topology_splits > + static_cast<uint32_t>(corner_table_->num_faces())) { return -1; + } #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(1, 2)) { for (uint32_t i = 0; i < num_topology_splits; ++i) { TopologySplitEventData event_data; - if (!decoder_buffer->Decode(&event_data.split_symbol_id)) + if (!decoder_buffer->Decode(&event_data.split_symbol_id)) { return -1; - if (!decoder_buffer->Decode(&event_data.source_symbol_id)) + } + if (!decoder_buffer->Decode(&event_data.source_symbol_id)) { return -1; + } uint8_t edge_data; - if (!decoder_buffer->Decode(&edge_data)) + if (!decoder_buffer->Decode(&edge_data)) { return -1; + } event_data.source_edge = edge_data & 1; topology_split_data_.push_back(event_data); } @@ -900,8 +955,9 @@ MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeHoleAndTopologySplitEvents( DecodeVarint<uint32_t>(&delta, decoder_buffer); event_data.source_symbol_id = delta + last_source_symbol_id; DecodeVarint<uint32_t>(&delta, decoder_buffer); - if (delta > event_data.source_symbol_id) + if (delta > event_data.source_symbol_id) { return -1; + } event_data.split_symbol_id = event_data.source_symbol_id - static_cast<int32_t>(delta); last_source_symbol_id = event_data.source_symbol_id; @@ -925,11 +981,13 @@ MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeHoleAndTopologySplitEvents( uint32_t num_hole_events = 0; #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!decoder_buffer->Decode(&num_hole_events)) + if (!decoder_buffer->Decode(&num_hole_events)) { return -1; + } } else if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 1)) { - if (!DecodeVarint(&num_hole_events, decoder_buffer)) + if (!DecodeVarint(&num_hole_events, decoder_buffer)) { return -1; + } } #endif if (num_hole_events > 0) { @@ -937,8 +995,9 @@ MeshEdgebreakerDecoderImpl<TraversalDecoder>::DecodeHoleAndTopologySplitEvents( if (decoder_->bitstream_version() < DRACO_BITSTREAM_VERSION(1, 2)) { for (uint32_t i = 0; i < num_hole_events; ++i) { HoleEventData event_data; - if (!decoder_buffer->Decode(&event_data)) + if (!decoder_buffer->Decode(&event_data)) { return -1; + } hole_event_data_.push_back(event_data); } @@ -981,8 +1040,9 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>:: for (uint32_t i = 0; i < attribute_data_.size(); ++i) { const bool is_seam = traversal_decoder_.DecodeAttributeSeam(i); - if (is_seam) + if (is_seam) { attribute_data_[i].attribute_seam_corners.push_back(corners[c].value()); + } } } return true; @@ -1009,13 +1069,15 @@ bool MeshEdgebreakerDecoderImpl< } const FaceIndex opp_face_id = corner_table_->Face(opp_corner); // Don't decode edges when the opposite face has been already processed. - if (opp_face_id < src_face_id) + if (opp_face_id < src_face_id) { continue; + } for (uint32_t i = 0; i < attribute_data_.size(); ++i) { const bool is_seam = traversal_decoder_.DecodeAttributeSeam(i); - if (is_seam) + if (is_seam) { attribute_data_[i].attribute_seam_corners.push_back(corners[c].value()); + } } } return true; @@ -1055,8 +1117,9 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::AssignPointsToCorners( std::vector<int32_t> corner_to_point_map(corner_table_->num_corners()); for (int v = 0; v < corner_table_->num_vertices(); ++v) { CornerIndex c = corner_table_->LeftMostCorner(VertexIndex(v)); - if (c == kInvalidCornerIndex) + if (c == kInvalidCornerIndex) { continue; // Isolated vertex. + } CornerIndex deduplication_first_corner = c; if (is_vert_hole_[v]) { // If the vertex is on a boundary, start deduplication from the left most @@ -1066,8 +1129,9 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::AssignPointsToCorners( // If we are not on the boundary we need to find the first seam (of any // attribute). for (uint32_t i = 0; i < attribute_data_.size(); ++i) { - if (!attribute_data_[i].connectivity_data.IsCornerOnSeam(c)) + if (!attribute_data_[i].connectivity_data.IsCornerOnSeam(c)) { continue; // No seam for this attribute, ignore it. + } // Else there needs to be at least one seam edge. // At this point, we use identity mapping between corners and point ids. @@ -1076,8 +1140,9 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::AssignPointsToCorners( CornerIndex act_c = corner_table_->SwingRight(c); bool seam_found = false; while (act_c != c) { - if (act_c == kInvalidCornerIndex) + if (act_c == kInvalidCornerIndex) { return false; + } if (attribute_data_[i].connectivity_data.Vertex(act_c) != vert_id) { // Attribute seam found. Stop. deduplication_first_corner = act_c; @@ -1086,8 +1151,9 @@ bool MeshEdgebreakerDecoderImpl<TraversalDecoder>::AssignPointsToCorners( } act_c = corner_table_->SwingRight(act_c); } - if (seam_found) + if (seam_found) { break; // No reason to process other attributes if we found a seam. + } } } diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h index 5299a189d48..78053f91dbe 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl.h @@ -17,14 +17,13 @@ #include <unordered_map> #include <unordered_set> -#include "draco/compression/mesh/traverser/mesh_traversal_sequencer.h" - -#include "draco/draco_features.h" #include "draco/compression/attributes/mesh_attribute_indices_encoding_data.h" #include "draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h" #include "draco/compression/mesh/mesh_edgebreaker_shared.h" +#include "draco/compression/mesh/traverser/mesh_traversal_sequencer.h" #include "draco/core/decoder_buffer.h" +#include "draco/draco_features.h" #include "draco/mesh/corner_table.h" #include "draco/mesh/mesh_attribute_corner_table.h" @@ -85,8 +84,9 @@ class MeshEdgebreakerDecoderImpl : public MeshEdgebreakerDecoderImplInterface { // symbol. bool IsTopologySplit(int encoder_symbol_id, EdgeFaceName *out_face_edge, int *out_encoder_split_symbol_id) { - if (topology_split_data_.size() == 0) + if (topology_split_data_.size() == 0) { return false; + } if (topology_split_data_.back().source_symbol_id > static_cast<uint32_t>(encoder_symbol_id)) { // Something is wrong; if the desired source symbol is greater than the @@ -97,8 +97,9 @@ class MeshEdgebreakerDecoderImpl : public MeshEdgebreakerDecoderImplInterface { *out_encoder_split_symbol_id = -1; return true; } - if (topology_split_data_.back().source_symbol_id != encoder_symbol_id) + if (topology_split_data_.back().source_symbol_id != encoder_symbol_id) { return false; + } *out_face_edge = static_cast<EdgeFaceName>(topology_split_data_.back().source_edge); *out_encoder_split_symbol_id = topology_split_data_.back().split_symbol_id; @@ -123,8 +124,9 @@ class MeshEdgebreakerDecoderImpl : public MeshEdgebreakerDecoderImplInterface { bool AssignPointsToCorners(int num_connectivity_verts); bool IsFaceVisited(CornerIndex corner_id) const { - if (corner_id < 0) + if (corner_id < 0) { return true; // Invalid corner signalizes that the face does not exist. + } return visited_faces_[corner_table_->Face(corner_id).value()]; } diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h index 31fabf252d8..31fabf252d8 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder.cc b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder.cc index 54fd55a483c..5aff5d8cc10 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder.cc +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder.cc @@ -59,23 +59,27 @@ bool MeshEdgebreakerEncoder::InitializeEncoder() { new MeshEdgebreakerEncoderImpl< MeshEdgebreakerTraversalValenceEncoder>()); } - if (!impl_) + if (!impl_) { return false; - if (!impl_->Init(this)) + } + if (!impl_->Init(this)) { return false; + } return true; } bool MeshEdgebreakerEncoder::GenerateAttributesEncoder(int32_t att_id) { - if (!impl_->GenerateAttributesEncoder(att_id)) + if (!impl_->GenerateAttributesEncoder(att_id)) { return false; + } return true; } bool MeshEdgebreakerEncoder::EncodeAttributesEncoderIdentifier( int32_t att_encoder_id) { - if (!impl_->EncodeAttributesEncoderIdentifier(att_encoder_id)) + if (!impl_->EncodeAttributesEncoderIdentifier(att_encoder_id)) { return false; + } return true; } @@ -84,11 +88,13 @@ Status MeshEdgebreakerEncoder::EncodeConnectivity() { } void MeshEdgebreakerEncoder::ComputeNumberOfEncodedPoints() { - if (!impl_) + if (!impl_) { return; + } const CornerTable *const corner_table = impl_->GetCornerTable(); - if (!corner_table) + if (!corner_table) { return; + } size_t num_points = corner_table->num_vertices() - corner_table->NumIsolatedVertices(); @@ -96,22 +102,26 @@ void MeshEdgebreakerEncoder::ComputeNumberOfEncodedPoints() { // Gather all corner tables for all non-position attributes. std::vector<const MeshAttributeCornerTable *> attribute_corner_tables; for (int i = 0; i < mesh()->num_attributes(); ++i) { - if (mesh()->attribute(i)->attribute_type() == GeometryAttribute::POSITION) + if (mesh()->attribute(i)->attribute_type() == + GeometryAttribute::POSITION) { continue; + } const MeshAttributeCornerTable *const att_corner_table = GetAttributeCornerTable(i); // Attribute corner table may not be used in some configurations. For // these cases we can assume the attribute connectivity to be the same as // the connectivity of the position data. - if (att_corner_table) + if (att_corner_table) { attribute_corner_tables.push_back(att_corner_table); + } } // Add a new point based on the configuration of interior attribute seams // (replicating what the decoder would do). for (VertexIndex vi(0); vi < corner_table->num_vertices(); ++vi) { - if (corner_table->IsVertexIsolated(vi)) + if (corner_table->IsVertexIsolated(vi)) { continue; + } // Go around all corners of the vertex and keep track of the observed // attribute seams. const CornerIndex first_corner_index = corner_table->LeftMostCorner(vi); @@ -144,8 +154,9 @@ void MeshEdgebreakerEncoder::ComputeNumberOfEncodedPoints() { ++num_attribute_seams; } - if (corner_index == first_corner_index) + if (corner_index == first_corner_index) { break; + } // Proceed to the next corner last_corner_index = corner_index; @@ -170,11 +181,13 @@ void MeshEdgebreakerEncoder::ComputeNumberOfEncodedPoints() { } void MeshEdgebreakerEncoder::ComputeNumberOfEncodedFaces() { - if (!impl_) + if (!impl_) { return; + } const CornerTable *const corner_table = impl_->GetCornerTable(); - if (!corner_table) + if (!corner_table) { return; + } set_num_encoded_faces(corner_table->num_faces() - corner_table->NumDegeneratedFaces()); } diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder.h index 70d4d5061a7..70d4d5061a7 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.cc b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.cc index f69ec993f9e..0791dc6705a 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.cc +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.cc @@ -67,8 +67,9 @@ MeshEdgebreakerEncoderImpl<TraversalEncoder>::GetAttributeCornerTable( int att_id) const { for (uint32_t i = 0; i < attribute_data_.size(); ++i) { if (attribute_data_[i].attribute_index == att_id) { - if (attribute_data_[i].is_connectivity_used) + if (attribute_data_[i].is_connectivity_used) { return &attribute_data_[i].connectivity_data; + } return nullptr; } } @@ -80,8 +81,9 @@ const MeshAttributeIndicesEncodingData * MeshEdgebreakerEncoderImpl<TraversalEncoder>::GetAttributeEncodingData( int att_id) const { for (uint32_t i = 0; i < attribute_data_.size(); ++i) { - if (attribute_data_[i].attribute_index == att_id) + if (attribute_data_[i].attribute_index == att_id) { return &attribute_data_[i].encoding_data; + } } return &pos_encoding_data_; } @@ -212,8 +214,9 @@ bool MeshEdgebreakerEncoderImpl<TraversalEncoder>::GenerateAttributesEncoder( sequencer = std::move(traversal_sequencer); } - if (!sequencer) + if (!sequencer) { return false; + } if (att_data_id == -1) { pos_traversal_method_ = traversal_method; @@ -316,11 +319,13 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() { processed_connectivity_corners_.reserve(corner_table_->num_faces()); pos_encoding_data_.num_values = 0; - if (!FindHoles()) + if (!FindHoles()) { return Status(Status::DRACO_ERROR, "Failed to process mesh holes."); + } - if (!InitAttributeData()) + if (!InitAttributeData()) { return Status(Status::DRACO_ERROR, "Failed to initialize attribute data."); + } const uint8_t num_attribute_data = static_cast<uint8_t>(attribute_data_.size()); @@ -336,10 +341,12 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() { for (int c_id = 0; c_id < num_corners; ++c_id) { CornerIndex corner_index(c_id); const FaceIndex face_id = corner_table_->Face(corner_index); - if (visited_faces_[face_id.value()]) + if (visited_faces_[face_id.value()]) { continue; // Face has been already processed. - if (corner_table_->IsDegenerated(face_id)) + } + if (corner_table_->IsDegenerated(face_id)) { continue; // Ignore degenerated faces. + } CornerIndex start_corner; const bool interior_config = @@ -375,8 +382,10 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() { const FaceIndex opp_face_id = corner_table_->Face(opp_id); if (opp_face_id != kInvalidFaceIndex && !visited_faces_[opp_face_id.value()]) { - if (!EncodeConnectivityFromCorner(opp_id)) - return Status(Status::DRACO_ERROR, "Failed to encode mesh component."); + if (!EncodeConnectivityFromCorner(opp_id)) { + return Status(Status::DRACO_ERROR, + "Failed to encode mesh component."); + } } } else { // Boundary configuration. We start on a boundary rather than on a face. @@ -384,8 +393,9 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() { EncodeHole(corner_table_->Next(start_corner), true); // Start processing the face opposite to the boundary edge (the face // containing the start_corner). - if (!EncodeConnectivityFromCorner(start_corner)) + if (!EncodeConnectivityFromCorner(start_corner)) { return Status(Status::DRACO_ERROR, "Failed to encode mesh component."); + } } } // Reverse the order of connectivity corners to match the order in which @@ -416,8 +426,9 @@ Status MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivity() { EncodeVarint(num_split_symbols_, encoder_->buffer()); // Append the traversal buffer. - if (!EncodeSplitData()) + if (!EncodeSplitData()) { return Status(Status::DRACO_ERROR, "Failed to encode split data."); + } encoder_->buffer()->Encode(traversal_encoder_.buffer().data(), traversal_encoder_.buffer().size()); @@ -542,17 +553,19 @@ bool MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivityFromCorner( if (IsRightFaceVisited(corner_id)) { // Right face has been already visited. // Check whether there is a topology split event. - if (right_face_id != kInvalidFaceIndex) + if (right_face_id != kInvalidFaceIndex) { CheckAndStoreTopologySplitEvent(last_encoded_symbol_id_, face_id.value(), RIGHT_FACE_EDGE, right_face_id.value()); + } if (IsLeftFaceVisited(corner_id)) { // Both neighboring faces are visited. End reached. // Check whether there is a topology split event on the left face. - if (left_face_id != kInvalidFaceIndex) + if (left_face_id != kInvalidFaceIndex) { CheckAndStoreTopologySplitEvent(last_encoded_symbol_id_, face_id.value(), LEFT_FACE_EDGE, left_face_id.value()); + } traversal_encoder_.EncodeSymbol(TOPOLOGY_E); corner_traversal_stack_.pop_back(); break; // Break from the while (num_visited_faces < num_faces) loop. @@ -565,10 +578,11 @@ bool MeshEdgebreakerEncoderImpl<TraversalEncoder>::EncodeConnectivityFromCorner( // Right face was not visited. if (IsLeftFaceVisited(corner_id)) { // Check whether there is a topology split event on the left face. - if (left_face_id != kInvalidFaceIndex) + if (left_face_id != kInvalidFaceIndex) { CheckAndStoreTopologySplitEvent(last_encoded_symbol_id_, face_id.value(), LEFT_FACE_EDGE, left_face_id.value()); + } traversal_encoder_.EncodeSymbol(TOPOLOGY_L); // Left face visited, go to the right one. corner_id = right_corner_id; @@ -669,8 +683,9 @@ bool MeshEdgebreakerEncoderImpl<TraversalEncoder>::IsRightFaceVisited( CornerIndex corner_id) const { const CornerIndex next_corner_id = corner_table_->Next(corner_id); const CornerIndex opp_corner_id = corner_table_->Opposite(next_corner_id); - if (opp_corner_id != kInvalidCornerIndex) + if (opp_corner_id != kInvalidCornerIndex) { return visited_faces_[corner_table_->Face(opp_corner_id).value()]; + } // Else we are on a boundary. return true; } @@ -680,8 +695,9 @@ bool MeshEdgebreakerEncoderImpl<TraversalEncoder>::IsLeftFaceVisited( CornerIndex corner_id) const { const CornerIndex prev_corner_id = corner_table_->Previous(corner_id); const CornerIndex opp_corner_id = corner_table_->Opposite(prev_corner_id); - if (opp_corner_id != kInvalidCornerIndex) + if (opp_corner_id != kInvalidCornerIndex) { return visited_faces_[corner_table_->Face(opp_corner_id).value()]; + } // Else we are on a boundary. return true; } @@ -692,8 +708,9 @@ bool MeshEdgebreakerEncoderImpl<TraversalEncoder>::FindHoles() { const int num_corners = corner_table_->num_corners(); // Go over all corners and detect non-visited open boundaries for (CornerIndex i(0); i < num_corners; ++i) { - if (corner_table_->IsDegenerated(corner_table_->Face(i))) + if (corner_table_->IsDegenerated(corner_table_->Face(i))) { continue; // Don't process corners assigned to degenerated faces. + } if (corner_table_->Opposite(i) == kInvalidCornerIndex) { // No opposite corner means no opposite face, so the opposite edge // of the corner is an open boundary. @@ -733,8 +750,9 @@ template <class TraversalEncoder> int MeshEdgebreakerEncoderImpl<TraversalEncoder>::GetSplitSymbolIdOnFace( int face_id) const { auto it = face_to_split_symbol_map_.find(face_id); - if (it == face_to_split_symbol_map_.end()) + if (it == face_to_split_symbol_map_.end()) { return -1; + } return it->second; } @@ -745,8 +763,9 @@ void MeshEdgebreakerEncoderImpl< EdgeFaceName src_edge, int neighbor_face_id) { const int symbol_id = GetSplitSymbolIdOnFace(neighbor_face_id); - if (symbol_id == -1) + if (symbol_id == -1) { return; // Not a split symbol, no topology split event could happen. + } TopologySplitEventData event_data; event_data.split_symbol_id = symbol_id; @@ -757,20 +776,23 @@ void MeshEdgebreakerEncoderImpl< template <class TraversalEncoder> bool MeshEdgebreakerEncoderImpl<TraversalEncoder>::InitAttributeData() { - if (use_single_connectivity_) + if (use_single_connectivity_) { return true; // All attributes use the same connectivity. + } const int num_attributes = mesh_->num_attributes(); // Ignore the position attribute. It's decoded separately. attribute_data_.resize(num_attributes - 1); - if (num_attributes == 1) + if (num_attributes == 1) { return true; + } int data_index = 0; for (int i = 0; i < num_attributes; ++i) { const int32_t att_index = i; if (mesh_->attribute(att_index)->attribute_type() == - GeometryAttribute::POSITION) + GeometryAttribute::POSITION) { continue; + } const PointAttribute *const att = mesh_->attribute(att_index); attribute_data_[data_index].attribute_index = att_index; attribute_data_[data_index] @@ -802,12 +824,14 @@ bool MeshEdgebreakerEncoderImpl< visited_faces_[src_face_id.value()] = true; for (int c = 0; c < 3; ++c) { const CornerIndex opp_corner = corner_table_->Opposite(corners[c]); - if (opp_corner == kInvalidCornerIndex) + if (opp_corner == kInvalidCornerIndex) { continue; // Don't encode attribute seams on boundary edges. + } const FaceIndex opp_face_id = corner_table_->Face(opp_corner); // Don't encode edges when the opposite face has been already processed. - if (visited_faces_[opp_face_id.value()]) + if (visited_faces_[opp_face_id.value()]) { continue; + } for (uint32_t i = 0; i < attribute_data_.size(); ++i) { if (attribute_data_[i].connectivity_data.IsCornerOppositeToSeamEdge( diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h index fb33771637e..fb33771637e 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h index 627d5126296..627d5126296 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_encoder_impl_interface.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_shared.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_shared.h index cb3c29dd669..cb3c29dd669 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_shared.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_shared.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h index 128d7f5d988..ce91adc8747 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h @@ -15,12 +15,11 @@ #ifndef DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_DECODER_H_ #define DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/bit_coders/rans_bit_decoder.h" #include "draco/compression/mesh/mesh_edgebreaker_decoder.h" #include "draco/compression/mesh/mesh_edgebreaker_decoder_impl_interface.h" #include "draco/compression/mesh/mesh_edgebreaker_shared.h" +#include "draco/draco_features.h" namespace draco { @@ -60,14 +59,17 @@ class MeshEdgebreakerTraversalDecoder { bool Start(DecoderBuffer *out_buffer) { // Decode symbols from the main buffer decoder and face configurations from // the start_face_buffer decoder. - if (!DecodeTraversalSymbols()) + if (!DecodeTraversalSymbols()) { return false; + } - if (!DecodeStartFaces()) + if (!DecodeStartFaces()) { return false; + } - if (!DecodeAttributeSeams()) + if (!DecodeAttributeSeams()) { return false; + } *out_buffer = buffer_; return true; } @@ -118,8 +120,9 @@ class MeshEdgebreakerTraversalDecoder { // Called when the traversal is finished. void Done() { - if (symbol_buffer_.bit_decoder_active()) + if (symbol_buffer_.bit_decoder_active()) { symbol_buffer_.EndBitDecoding(); + } #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (buffer_.bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { start_face_buffer_.EndBitDecoding(); @@ -137,11 +140,13 @@ class MeshEdgebreakerTraversalDecoder { bool DecodeTraversalSymbols() { uint64_t traversal_size; symbol_buffer_ = buffer_; - if (!symbol_buffer_.StartBitDecoding(true, &traversal_size)) + if (!symbol_buffer_.StartBitDecoding(true, &traversal_size)) { return false; + } buffer_ = symbol_buffer_; - if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) + if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) { return false; + } buffer_.Advance(traversal_size); return true; } @@ -152,11 +157,13 @@ class MeshEdgebreakerTraversalDecoder { if (buffer_.bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { start_face_buffer_ = buffer_; uint64_t traversal_size; - if (!start_face_buffer_.StartBitDecoding(true, &traversal_size)) + if (!start_face_buffer_.StartBitDecoding(true, &traversal_size)) { return false; + } buffer_ = start_face_buffer_; - if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) + if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) { return false; + } buffer_.Advance(traversal_size); return true; } @@ -170,8 +177,9 @@ class MeshEdgebreakerTraversalDecoder { attribute_connectivity_decoders_ = std::unique_ptr<BinaryDecoder[]>( new BinaryDecoder[num_attribute_data_]); for (int i = 0; i < num_attribute_data_; ++i) { - if (!attribute_connectivity_decoders_[i].StartDecoding(&buffer_)) + if (!attribute_connectivity_decoders_[i].StartDecoding(&buffer_)) { return false; + } } } return true; diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h index 08cb66e4cdc..08cb66e4cdc 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h index d3289e28c76..3f9004585c6 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_decoder.h @@ -16,9 +16,8 @@ #ifndef DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_PREDICTIVE_DECODER_H_ #define DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_PREDICTIVE_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h" +#include "draco/draco_features.h" namespace draco { @@ -41,17 +40,20 @@ class MeshEdgebreakerTraversalPredictiveDecoder void SetNumEncodedVertices(int num_vertices) { num_vertices_ = num_vertices; } bool Start(DecoderBuffer *out_buffer) { - if (!MeshEdgebreakerTraversalDecoder::Start(out_buffer)) + if (!MeshEdgebreakerTraversalDecoder::Start(out_buffer)) { return false; + } int32_t num_split_symbols; if (!out_buffer->Decode(&num_split_symbols) || num_split_symbols < 0) return false; - if (num_split_symbols >= num_vertices_) + if (num_split_symbols >= num_vertices_) { return false; + } // Set the valences of all initial vertices to 0. vertex_valences_.resize(num_vertices_, 0); - if (!prediction_decoder_.StartDecoding(out_buffer)) + if (!prediction_decoder_.StartDecoding(out_buffer)) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h index 118687cc769..eb937fe8080 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_predictive_encoder.h @@ -36,8 +36,9 @@ class MeshEdgebreakerTraversalPredictiveEncoder num_symbols_(0) {} bool Init(MeshEdgebreakerEncoderImplInterface *encoder) { - if (!MeshEdgebreakerTraversalEncoder::Init(encoder)) + if (!MeshEdgebreakerTraversalEncoder::Init(encoder)) { return false; + } corner_table_ = encoder->GetCornerTable(); // Initialize valences of all vertices. vertex_valences_.resize(corner_table_->num_vertices()); diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h index 4da9d0e3a8b..621883a5f1f 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_decoder.h @@ -15,11 +15,10 @@ #ifndef DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_VALENCE_DECODER_H_ #define DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_VALENCE_DECODER_H_ -#include "draco/draco_features.h" - #include "draco/compression/entropy/symbol_decoding.h" #include "draco/compression/mesh/mesh_edgebreaker_traversal_decoder.h" #include "draco/core/varint_decoding.h" +#include "draco/draco_features.h" namespace draco { @@ -46,32 +45,39 @@ class MeshEdgebreakerTraversalValenceDecoder bool Start(DecoderBuffer *out_buffer) { #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (BitstreamVersion() < DRACO_BITSTREAM_VERSION(2, 2)) { - if (!MeshEdgebreakerTraversalDecoder::DecodeTraversalSymbols()) + if (!MeshEdgebreakerTraversalDecoder::DecodeTraversalSymbols()) { return false; + } } #endif - if (!MeshEdgebreakerTraversalDecoder::DecodeStartFaces()) + if (!MeshEdgebreakerTraversalDecoder::DecodeStartFaces()) { return false; - if (!MeshEdgebreakerTraversalDecoder::DecodeAttributeSeams()) + } + if (!MeshEdgebreakerTraversalDecoder::DecodeAttributeSeams()) { return false; + } *out_buffer = *buffer(); #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (BitstreamVersion() < DRACO_BITSTREAM_VERSION(2, 2)) { uint32_t num_split_symbols; if (BitstreamVersion() < DRACO_BITSTREAM_VERSION(2, 0)) { - if (!out_buffer->Decode(&num_split_symbols)) + if (!out_buffer->Decode(&num_split_symbols)) { return false; + } } else { - if (!DecodeVarint(&num_split_symbols, out_buffer)) + if (!DecodeVarint(&num_split_symbols, out_buffer)) { return false; + } } - if (num_split_symbols >= static_cast<uint32_t>(num_vertices_)) + if (num_split_symbols >= static_cast<uint32_t>(num_vertices_)) { return false; + } int8_t mode; - if (!out_buffer->Decode(&mode)) + if (!out_buffer->Decode(&mode)) { return false; + } if (mode == EDGEBREAKER_VALENCE_MODE_2_7) { min_valence_ = 2; max_valence_ = 7; @@ -87,8 +93,9 @@ class MeshEdgebreakerTraversalValenceDecoder max_valence_ = 7; } - if (num_vertices_ < 0) + if (num_vertices_ < 0) { return false; + } // Set the valences of all initial vertices to 0. vertex_valences_.resize(num_vertices_, 0); @@ -114,8 +121,9 @@ class MeshEdgebreakerTraversalValenceDecoder // First check if we have a valid context. if (active_context_ != -1) { const int context_counter = --context_counters_[active_context_]; - if (context_counter < 0) + if (context_counter < 0) { return TOPOLOGY_INVALID; + } const int symbol_id = context_symbols_[active_context_][context_counter]; last_symbol_ = edge_breaker_symbol_to_topology_id[symbol_id]; } else { diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h index ef3a86bf983..c492c84bb45 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_edgebreaker_traversal_valence_encoder.h @@ -43,8 +43,9 @@ class MeshEdgebreakerTraversalValenceEncoder max_valence_(7) {} bool Init(MeshEdgebreakerEncoderImplInterface *encoder) { - if (!MeshEdgebreakerTraversalEncoder::Init(encoder)) + if (!MeshEdgebreakerTraversalEncoder::Init(encoder)) { return false; + } min_valence_ = 2; max_valence_ = 7; corner_table_ = encoder->GetCornerTable(); @@ -117,8 +118,9 @@ class MeshEdgebreakerTraversalValenceEncoder int num_left_faces = 0; CornerIndex act_c = corner_table_->Opposite(prev); while (act_c != kInvalidCornerIndex) { - if (encoder_impl()->IsFaceEncoded(corner_table_->Face(act_c))) + if (encoder_impl()->IsFaceEncoded(corner_table_->Face(act_c))) { break; // Stop when we reach the first visited face. + } ++num_left_faces; act_c = corner_table_->Opposite(corner_table_->Next(act_c)); } @@ -132,8 +134,9 @@ class MeshEdgebreakerTraversalValenceEncoder act_c = corner_table_->Opposite(next); while (act_c != kInvalidCornerIndex) { - if (encoder_impl()->IsFaceEncoded(corner_table_->Face(act_c))) + if (encoder_impl()->IsFaceEncoded(corner_table_->Face(act_c))) { break; // Stop when we reach the first visited face. + } ++num_right_faces; // Map corners on the right side to the newly created vertex. corner_to_vertex_map_[corner_table_->Next(act_c)] = new_vert_id; diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder.cc b/extern/draco/draco/src/draco/compression/mesh/mesh_encoder.cc index 2da5de1fc82..483ea02a7bc 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder.cc +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_encoder.cc @@ -25,8 +25,9 @@ void MeshEncoder::SetMesh(const Mesh &m) { Status MeshEncoder::EncodeGeometryData() { DRACO_RETURN_IF_ERROR(EncodeConnectivity()); - if (options()->GetGlobalBool("store_number_of_encoded_faces", false)) + if (options()->GetGlobalBool("store_number_of_encoded_faces", false)) { ComputeNumberOfEncodedFaces(); + } return OkStatus(); } diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_encoder.h index 30ec4fa3492..30ec4fa3492 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_decoder.cc b/extern/draco/draco/src/draco/compression/mesh/mesh_sequential_decoder.cc index de71700e160..53f5e8651b8 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_decoder.cc +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_sequential_decoder.cc @@ -28,34 +28,42 @@ bool MeshSequentialDecoder::DecodeConnectivity() { uint32_t num_points; #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) { - if (!buffer()->Decode(&num_faces)) + if (!buffer()->Decode(&num_faces)) { return false; - if (!buffer()->Decode(&num_points)) + } + if (!buffer()->Decode(&num_points)) { return false; + } } else #endif { - if (!DecodeVarint(&num_faces, buffer())) + if (!DecodeVarint(&num_faces, buffer())) { return false; - if (!DecodeVarint(&num_points, buffer())) + } + if (!DecodeVarint(&num_points, buffer())) { return false; + } } // Check that num_faces and num_points are valid values. const uint64_t faces_64 = static_cast<uint64_t>(num_faces); const uint64_t points_64 = static_cast<uint64_t>(num_points); // Compressed sequential encoding can only handle (2^32 - 1) / 3 indices. - if (faces_64 > 0xffffffff / 3) + if (faces_64 > 0xffffffff / 3) { return false; - if (points_64 > faces_64 * 3) + } + if (points_64 > faces_64 * 3) { return false; + } uint8_t connectivity_method; - if (!buffer()->Decode(&connectivity_method)) + if (!buffer()->Decode(&connectivity_method)) { return false; + } if (connectivity_method == 0) { - if (!DecodeAndDecompressIndices(num_faces)) + if (!DecodeAndDecompressIndices(num_faces)) { return false; + } } else { if (num_points < 256) { // Decode indices as uint8_t. @@ -63,8 +71,9 @@ bool MeshSequentialDecoder::DecodeConnectivity() { Mesh::Face face; for (int j = 0; j < 3; ++j) { uint8_t val; - if (!buffer()->Decode(&val)) + if (!buffer()->Decode(&val)) { return false; + } face[j] = val; } mesh()->AddFace(face); @@ -75,8 +84,9 @@ bool MeshSequentialDecoder::DecodeConnectivity() { Mesh::Face face; for (int j = 0; j < 3; ++j) { uint16_t val; - if (!buffer()->Decode(&val)) + if (!buffer()->Decode(&val)) { return false; + } face[j] = val; } mesh()->AddFace(face); @@ -88,8 +98,9 @@ bool MeshSequentialDecoder::DecodeConnectivity() { Mesh::Face face; for (int j = 0; j < 3; ++j) { uint32_t val; - if (!DecodeVarint(&val, buffer())) + if (!DecodeVarint(&val, buffer())) { return false; + } face[j] = val; } mesh()->AddFace(face); @@ -100,8 +111,9 @@ bool MeshSequentialDecoder::DecodeConnectivity() { Mesh::Face face; for (int j = 0; j < 3; ++j) { uint32_t val; - if (!buffer()->Decode(&val)) + if (!buffer()->Decode(&val)) { return false; + } face[j] = val; } mesh()->AddFace(face); @@ -125,8 +137,9 @@ bool MeshSequentialDecoder::CreateAttributesDecoder(int32_t att_decoder_id) { bool MeshSequentialDecoder::DecodeAndDecompressIndices(uint32_t num_faces) { // Get decoded indices differences that were encoded with an entropy code. std::vector<uint32_t> indices_buffer(num_faces * 3); - if (!DecodeSymbols(num_faces * 3, 1, buffer(), indices_buffer.data())) + if (!DecodeSymbols(num_faces * 3, 1, buffer(), indices_buffer.data())) { return false; + } // Reconstruct the indices from the differences. // See MeshSequentialEncoder::CompressAndEncodeIndices() for more details. int32_t last_index_value = 0; @@ -136,8 +149,9 @@ bool MeshSequentialDecoder::DecodeAndDecompressIndices(uint32_t num_faces) { for (int j = 0; j < 3; ++j) { const uint32_t encoded_val = indices_buffer[vertex_index++]; int32_t index_diff = (encoded_val >> 1); - if (encoded_val & 1) + if (encoded_val & 1) { index_diff = -index_diff; + } const int32_t index_value = index_diff + last_index_value; face[j] = index_value; last_index_value = index_value; diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_decoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_sequential_decoder.h index 3a86c75d5e9..3a86c75d5e9 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_decoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_sequential_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_encoder.cc b/extern/draco/draco/src/draco/compression/mesh/mesh_sequential_encoder.cc index b53ff0c25a6..02ac7779ea3 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_encoder.cc +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_sequential_encoder.cc @@ -37,8 +37,9 @@ Status MeshSequentialEncoder::EncodeConnectivity() { if (options()->GetGlobalBool("compress_connectivity", false)) { // 0 = Encode compressed indices. buffer()->Encode(static_cast<uint8_t>(0)); - if (!CompressAndEncodeIndices()) + if (!CompressAndEncodeIndices()) { return Status(Status::DRACO_ERROR, "Failed to compress connectivity."); + } } else { // 1 = Encode indices directly. buffer()->Encode(static_cast<uint8_t>(1)); diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_encoder.h b/extern/draco/draco/src/draco/compression/mesh/mesh_sequential_encoder.h index 672609642b0..672609642b0 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_sequential_encoder.h +++ b/extern/draco/draco/src/draco/compression/mesh/mesh_sequential_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/depth_first_traverser.h b/extern/draco/draco/src/draco/compression/mesh/traverser/depth_first_traverser.h index 84420cb3888..0b387ec3a70 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/depth_first_traverser.h +++ b/extern/draco/draco/src/draco/compression/mesh/traverser/depth_first_traverser.h @@ -57,8 +57,9 @@ class DepthFirstTraverser void OnTraversalEnd() {} bool TraverseFromCorner(CornerIndex corner_id) { - if (this->IsFaceVisited(corner_id)) + if (this->IsFaceVisited(corner_id)) { return true; // Already traversed. + } corner_traversal_stack_.clear(); corner_traversal_stack_.push_back(corner_id); @@ -68,8 +69,9 @@ class DepthFirstTraverser this->corner_table()->Vertex(this->corner_table()->Next(corner_id)); const VertexIndex prev_vert = this->corner_table()->Vertex(this->corner_table()->Previous(corner_id)); - if (next_vert == kInvalidVertexIndex || prev_vert == kInvalidVertexIndex) + if (next_vert == kInvalidVertexIndex || prev_vert == kInvalidVertexIndex) { return false; + } if (!this->IsVertexVisited(next_vert)) { this->MarkVertexVisited(next_vert); this->traversal_observer().OnNewVertexVisited( @@ -96,8 +98,9 @@ class DepthFirstTraverser this->MarkFaceVisited(face_id); this->traversal_observer().OnNewFaceVisited(face_id); const VertexIndex vert_id = this->corner_table()->Vertex(corner_id); - if (vert_id == kInvalidVertexIndex) + if (vert_id == kInvalidVertexIndex) { return false; + } if (!this->IsVertexVisited(vert_id)) { const bool on_boundary = this->corner_table()->IsOnBoundary(vert_id); this->MarkVertexVisited(vert_id); diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/max_prediction_degree_traverser.h b/extern/draco/draco/src/draco/compression/mesh/traverser/max_prediction_degree_traverser.h index b60d2c159f2..514193eae73 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/max_prediction_degree_traverser.h +++ b/extern/draco/draco/src/draco/compression/mesh/traverser/max_prediction_degree_traverser.h @@ -63,8 +63,9 @@ class MaxPredictionDegreeTraverser void OnTraversalEnd() {} bool TraverseFromCorner(CornerIndex corner_id) { - if (prediction_degree_.size() == 0) + if (prediction_degree_.size() == 0) { return true; + } // Traversal starts from the |corner_id|. It's going to follow either the // right or the left neighboring faces to |corner_id| based on their @@ -184,8 +185,9 @@ class MaxPredictionDegreeTraverser inline void AddCornerToTraversalStack(CornerIndex ci, int priority) { traversal_stacks_[priority].push_back(ci); // Make sure that the best available priority is up to date. - if (priority < best_priority_) + if (priority < best_priority_) { best_priority_ = priority; + } } // Returns the priority of traversing edge leading to |corner_id|. @@ -199,8 +201,9 @@ class MaxPredictionDegreeTraverser priority = (degree > 1 ? 1 : 2); } // Clamp the priority to the maximum number of buckets. - if (priority >= kMaxPriority) + if (priority >= kMaxPriority) { priority = kMaxPriority - 1; + } return priority; } diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h b/extern/draco/draco/src/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h index e66dd14b238..e66dd14b238 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h +++ b/extern/draco/draco/src/draco/compression/mesh/traverser/mesh_attribute_indices_encoding_observer.h diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/mesh_traversal_sequencer.h b/extern/draco/draco/src/draco/compression/mesh/traverser/mesh_traversal_sequencer.h index fbcda53b792..ebe1d5f7a9e 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/mesh_traversal_sequencer.h +++ b/extern/draco/draco/src/draco/compression/mesh/traverser/mesh_traversal_sequencer.h @@ -56,12 +56,13 @@ class MeshTraversalSequencer : public PointsSequencer { const PointIndex point_id = face[p]; const VertexIndex vert_id = corner_table->Vertex(CornerIndex(3 * f.value() + p)); - if (vert_id == kInvalidVertexIndex) + if (vert_id == kInvalidVertexIndex) { return false; + } const AttributeValueIndex att_entry_id( encoding_data_ ->vertex_to_encoded_attribute_value_index_map[vert_id.value()]); - if (att_entry_id.value() >= num_points) { + if (point_id >= num_points || att_entry_id.value() >= num_points) { // There cannot be more attribute values than the number of points. return false; } @@ -80,14 +81,16 @@ class MeshTraversalSequencer : public PointsSequencer { traverser_.OnTraversalStart(); if (corner_order_) { for (uint32_t i = 0; i < corner_order_->size(); ++i) { - if (!ProcessCorner(corner_order_->at(i))) + if (!ProcessCorner(corner_order_->at(i))) { return false; + } } } else { const int32_t num_faces = traverser_.corner_table()->num_faces(); for (int i = 0; i < num_faces; ++i) { - if (!ProcessCorner(CornerIndex(3 * i))) + if (!ProcessCorner(CornerIndex(3 * i))) { return false; + } } } traverser_.OnTraversalEnd(); diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/traverser_base.h b/extern/draco/draco/src/draco/compression/mesh/traverser/traverser_base.h index 643c5db565b..f2f8da79d09 100644 --- a/extern/draco/dracoenc/src/draco/compression/mesh/traverser/traverser_base.h +++ b/extern/draco/draco/src/draco/compression/mesh/traverser/traverser_base.h @@ -43,15 +43,17 @@ class TraverserBase { const CornerTable &GetCornerTable() const { return *corner_table_; } inline bool IsFaceVisited(FaceIndex face_id) const { - if (face_id == kInvalidFaceIndex) + if (face_id == kInvalidFaceIndex) { return true; // Invalid faces are always considered as visited. + } return is_face_visited_[face_id.value()]; } // Returns true if the face containing the given corner was visited. inline bool IsFaceVisited(CornerIndex corner_id) const { - if (corner_id == kInvalidCornerIndex) + if (corner_id == kInvalidCornerIndex) { return true; // Invalid faces are always considered as visited. + } return is_face_visited_[corner_id.value() / 3]; } diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.cc index de46f05af67..de46f05af67 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h index 61a153560ae..87bc2b7ef3e 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_decoder.h @@ -155,25 +155,36 @@ template <int compression_level_t> template <class OutputIteratorT> bool DynamicIntegerPointsKdTreeDecoder<compression_level_t>::DecodePoints( DecoderBuffer *buffer, OutputIteratorT &oit) { - buffer->Decode(&bit_length_); - if (bit_length_ > 32) + if (!buffer->Decode(&bit_length_)) { return false; - buffer->Decode(&num_points_); - if (num_points_ == 0) + } + if (bit_length_ > 32) { + return false; + } + if (!buffer->Decode(&num_points_)) { + return false; + } + if (num_points_ == 0) { return true; + } num_decoded_points_ = 0; - if (!numbers_decoder_.StartDecoding(buffer)) + if (!numbers_decoder_.StartDecoding(buffer)) { return false; - if (!remaining_bits_decoder_.StartDecoding(buffer)) + } + if (!remaining_bits_decoder_.StartDecoding(buffer)) { return false; - if (!axis_decoder_.StartDecoding(buffer)) + } + if (!axis_decoder_.StartDecoding(buffer)) { return false; - if (!half_decoder_.StartDecoding(buffer)) + } + if (!half_decoder_.StartDecoding(buffer)) { return false; + } - if (!DecodeInternal(num_points_, oit)) + if (!DecodeInternal(num_points_, oit)) { return false; + } numbers_decoder_.EndDecoding(); remaining_bits_decoder_.EndDecoding(); @@ -187,8 +198,9 @@ template <int compression_level_t> uint32_t DynamicIntegerPointsKdTreeDecoder<compression_level_t>::GetAxis( uint32_t num_remaining_points, const VectorUint32 &levels, uint32_t last_axis) { - if (!Policy::select_axis) + if (!Policy::select_axis) { return DRACO_INCREMENT_MOD(last_axis, dimension_); + } uint32_t best_axis = 0; if (num_remaining_points < 64) { @@ -226,12 +238,14 @@ bool DynamicIntegerPointsKdTreeDecoder<compression_level_t>::DecodeInternal( const VectorUint32 &old_base = base_stack_[stack_pos]; const VectorUint32 &levels = levels_stack_[stack_pos]; - if (num_remaining_points > num_points) + if (num_remaining_points > num_points) { return false; + } const uint32_t axis = GetAxis(num_remaining_points, levels, last_axis); - if (axis >= dimension_) + if (axis >= dimension_) { return false; + } const uint32_t level = levels[axis]; @@ -258,9 +272,10 @@ bool DynamicIntegerPointsKdTreeDecoder<compression_level_t>::DecodeInternal( for (uint32_t j = 0; j < dimension_; j++) { p_[axes_[j]] = 0; const uint32_t num_remaining_bits = bit_length_ - levels[axes_[j]]; - if (num_remaining_bits) + if (num_remaining_bits) { remaining_bits_decoder_.DecodeLeastSignificantBits32( num_remaining_bits, &p_[axes_[j]]); + } p_[axes_[j]] = old_base[axes_[j]] | p_[axes_[j]]; } *oit = p_; @@ -270,8 +285,9 @@ bool DynamicIntegerPointsKdTreeDecoder<compression_level_t>::DecodeInternal( continue; } - if (num_decoded_points_ > num_points_) + if (num_decoded_points_ > num_points_) { return false; + } const int num_remaining_bits = bit_length_ - level; const uint32_t modifier = 1 << (num_remaining_bits - 1); @@ -286,16 +302,20 @@ bool DynamicIntegerPointsKdTreeDecoder<compression_level_t>::DecodeInternal( uint32_t first_half = num_remaining_points / 2 - number; uint32_t second_half = num_remaining_points - first_half; - if (first_half != second_half) - if (!half_decoder_.DecodeNextBit()) + if (first_half != second_half) { + if (!half_decoder_.DecodeNextBit()) { std::swap(first_half, second_half); + } + } levels_stack_[stack_pos][axis] += 1; levels_stack_[stack_pos + 1] = levels_stack_[stack_pos]; // copy - if (first_half) + if (first_half) { status_stack.push(DecodingStatus(first_half, axis, stack_pos)); - if (second_half) + } + if (second_half) { status_stack.push(DecodingStatus(second_half, axis, stack_pos + 1)); + } } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.cc index e7abf52c4a2..e7abf52c4a2 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h index 47ac653c85f..14fa32d7083 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/dynamic_integer_points_kd_tree_encoder.h @@ -191,8 +191,9 @@ bool DynamicIntegerPointsKdTreeEncoder<compression_level_t>::EncodePoints( buffer->Encode(bit_length_); buffer->Encode(num_points_); - if (num_points_ == 0) + if (num_points_ == 0) { return true; + } numbers_encoder_.StartEncoding(); remaining_bits_encoder_.StartEncoding(); @@ -215,8 +216,9 @@ DynamicIntegerPointsKdTreeEncoder<compression_level_t>::GetAndEncodeAxis( RandomAccessIteratorT begin, RandomAccessIteratorT end, const VectorUint32 &old_base, const VectorUint32 &levels, uint32_t last_axis) { - if (!Policy::select_axis) + if (!Policy::select_axis) { return DRACO_INCREMENT_MOD(last_axis, dimension_); + } // For many points this function selects the axis that should be used // for the split by keeping as many points as possible bundled. @@ -296,8 +298,9 @@ void DynamicIntegerPointsKdTreeEncoder<compression_level_t>::EncodeInternal( const uint32_t num_remaining_points = static_cast<uint32_t>(end - begin); // If this happens all axis are subdivided to the end. - if ((bit_length_ - level) == 0) + if ((bit_length_ - level) == 0) { continue; + } // Fast encoding of remaining bits if number of points is 1 or 2. // Doing this also for 2 gives a slight additional speed up. @@ -338,8 +341,9 @@ void DynamicIntegerPointsKdTreeEncoder<compression_level_t>::EncodeInternal( const uint32_t second_half = static_cast<uint32_t>(end - split); const bool left = first_half < second_half; - if (first_half != second_half) + if (first_half != second_half) { half_encoder_.EncodeBit(left); + } if (left) { EncodeNumber(required_bits, num_remaining_points / 2 - first_half); @@ -349,10 +353,12 @@ void DynamicIntegerPointsKdTreeEncoder<compression_level_t>::EncodeInternal( levels_stack_[stack_pos][axis] += 1; levels_stack_[stack_pos + 1] = levels_stack_[stack_pos]; // copy - if (split != begin) + if (split != begin) { status_stack.push(Status(begin, split, axis, stack_pos)); - if (split != end) + } + if (split != end) { status_stack.push(Status(split, end, axis, stack_pos + 1)); + } } } extern template class DynamicIntegerPointsKdTreeEncoder<0>; diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.cc index 98526c4e63d..9e8d895f176 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.cc @@ -62,23 +62,20 @@ class ConversionOutputIterator { }; FloatPointsTreeDecoder::FloatPointsTreeDecoder() - : num_points_(0), compression_level_(0) { + : num_points_(0), compression_level_(0), num_points_from_header_(0) { qinfo_.quantization_bits = 0; qinfo_.range = 0; } bool FloatPointsTreeDecoder::DecodePointCloudKdTreeInternal( DecoderBuffer *buffer, std::vector<Point3ui> *qpoints) { - if (!buffer->Decode(&qinfo_.quantization_bits)) - return false; - if (qinfo_.quantization_bits > 31) - return false; - if (!buffer->Decode(&qinfo_.range)) - return false; - if (!buffer->Decode(&num_points_)) - return false; - if (!buffer->Decode(&compression_level_)) + if (!buffer->Decode(&qinfo_.quantization_bits)) return false; + if (qinfo_.quantization_bits > 31) return false; + if (!buffer->Decode(&qinfo_.range)) return false; + if (!buffer->Decode(&num_points_)) return false; + if (num_points_from_header_ > 0 && num_points_ != num_points_from_header_) return false; + if (!buffer->Decode(&compression_level_)) return false; // Only allow compression level in [0..6]. if (6 < compression_level_) { @@ -135,8 +132,9 @@ bool FloatPointsTreeDecoder::DecodePointCloudKdTreeInternal( } } - if (qpoints->size() != num_points_) + if (qpoints->size() != num_points_) { return false; + } return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h index d3425696a5a..4f09ed2c31d 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_decoder.h @@ -43,8 +43,9 @@ class FloatPointsTreeDecoder { template <class OutputIteratorT> bool DecodePointCloud(const char *data, size_t data_size, OutputIteratorT out) { - if (data == 0 || data_size <= 0) + if (data == 0 || data_size <= 0) { return false; + } DecoderBuffer buffer; buffer.Init(data, data_size); @@ -65,6 +66,10 @@ class FloatPointsTreeDecoder { } } + void set_num_points_from_header(uint32_t num_points) { + num_points_from_header_ = num_points; + } + private: bool DecodePointCloudKdTreeInternal(DecoderBuffer *buffer, std::vector<Point3ui> *qpoints); @@ -74,6 +79,11 @@ class FloatPointsTreeDecoder { PointCloudCompressionMethod method_; uint32_t num_points_; uint32_t compression_level_; + + // Member variable to check if the number of points from the file header + // matches the number of points in the compression header. If + // |num_points_from_header_| is 0, do not perform the check. Defaults to 0. + uint32_t num_points_from_header_; }; #ifndef DRACO_OLD_GCC @@ -93,26 +103,30 @@ bool FloatPointsTreeDecoder::DecodePointCloud(DecoderBuffer *buffer, std::vector<Point3ui> qpoints; uint32_t decoded_version; - if (!buffer->Decode(&decoded_version)) + if (!buffer->Decode(&decoded_version)) { return false; + } if (decoded_version == 3) { int8_t method_number; - if (!buffer->Decode(&method_number)) + if (!buffer->Decode(&method_number)) { return false; + } method_ = static_cast<PointCloudCompressionMethod>(method_number); if (method_ == KDTREE) { - if (!DecodePointCloudKdTreeInternal(buffer, &qpoints)) + if (!DecodePointCloudKdTreeInternal(buffer, &qpoints)) { return false; + } } else { // Unsupported method. fprintf(stderr, "Method not supported. \n"); return false; } } else if (decoded_version == 2) { // Version 2 only uses KDTREE method. - if (!DecodePointCloudKdTreeInternal(buffer, &qpoints)) + if (!DecodePointCloudKdTreeInternal(buffer, &qpoints)) { return false; + } } else { // Unsupported version. fprintf(stderr, "Version not supported. \n"); return false; diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.cc index 317430f2b8e..317430f2b8e 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h index 1fd807427f5..26ba94f1f59 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/float_points_tree_encoder.h @@ -105,11 +105,13 @@ bool FloatPointsTreeEncoder::EncodePointCloud(InputIteratorT points_begin, buffer()->Encode(qinfo_.range); buffer()->Encode(num_points_); - if (method_ == KDTREE) + if (method_ == KDTREE) { buffer()->Encode(compression_level_); + } - if (num_points_ == 0) + if (num_points_ == 0) { return true; + } if (method_ == KDTREE) { return EncodePointCloudKdTreeInternal(&qpoints); diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.cc index d0428a28e6a..d0428a28e6a 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.h index 06ee718e0f5..94e523cadaf 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_decoder.h @@ -153,19 +153,28 @@ template <class PointDiT, int compression_level_t> template <class OutputIteratorT> bool IntegerPointsKdTreeDecoder<PointDiT, compression_level_t>::DecodePoints( DecoderBuffer *buffer, OutputIteratorT oit) { - buffer->Decode(&bit_length_); - buffer->Decode(&num_points_); - if (num_points_ == 0) + if (!buffer->Decode(&bit_length_)) { + return false; + } + if (!buffer->Decode(&num_points_)) { + return false; + } + if (num_points_ == 0) { return true; + } - if (!numbers_decoder_.StartDecoding(buffer)) + if (!numbers_decoder_.StartDecoding(buffer)) { return false; - if (!remaining_bits_decoder_.StartDecoding(buffer)) + } + if (!remaining_bits_decoder_.StartDecoding(buffer)) { return false; - if (!axis_decoder_.StartDecoding(buffer)) + } + if (!axis_decoder_.StartDecoding(buffer)) { return false; - if (!half_decoder_.StartDecoding(buffer)) + } + if (!half_decoder_.StartDecoding(buffer)) { return false; + } DecodeInternal(num_points_, PointTraits<PointDiT>::Origin(), PointTraits<PointDiT>::ZeroArray(), 0, oit); @@ -182,8 +191,9 @@ template <class PointDiT, int compression_level_t> uint32_t IntegerPointsKdTreeDecoder<PointDiT, compression_level_t>::GetAxis( uint32_t num_remaining_points, const PointDiT & /* base */, std::array<uint32_t, D> levels, uint32_t last_axis) { - if (!Policy::select_axis) + if (!Policy::select_axis) { return DRACO_INCREMENT_MOD(last_axis, D); + } uint32_t best_axis = 0; if (num_remaining_points < 64) { @@ -247,9 +257,10 @@ void IntegerPointsKdTreeDecoder<PointDiT, compression_level_t>::DecodeInternal( // Get remaining bits, mind the carry if not starting at x. PointDiT p = PointTraits<PointDiT>::Origin(); for (int j = 0; j < static_cast<int>(D); j++) { - if (num_remaining_bits[j]) + if (num_remaining_bits[j]) { remaining_bits_decoder_.DecodeLeastSignificantBits32( num_remaining_bits[j], &p[axes[j]]); + } p[axes[j]] = old_base[axes[j]] | p[axes[j]]; } *oit++ = p; @@ -270,15 +281,19 @@ void IntegerPointsKdTreeDecoder<PointDiT, compression_level_t>::DecodeInternal( uint32_t first_half = num_remaining_points / 2 - number; uint32_t second_half = num_remaining_points - first_half; - if (first_half != second_half) - if (!half_decoder_.DecodeNextBit()) + if (first_half != second_half) { + if (!half_decoder_.DecodeNextBit()) { std::swap(first_half, second_half); + } + } levels[axis] += 1; - if (first_half) + if (first_half) { status_q.push(DecodingStatus(first_half, old_base, levels, axis)); - if (second_half) + } + if (second_half) { status_q.push(DecodingStatus(second_half, new_base, levels, axis)); + } } } diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.cc index ee10595003b..ee10595003b 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h index 9a3e8d76f8c..b8811092ed7 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/integer_points_kd_tree_encoder.h @@ -204,8 +204,9 @@ bool IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::EncodePoints( buffer->Encode(bit_length_); buffer->Encode(num_points_); - if (num_points_ == 0) + if (num_points_ == 0) { return true; + } numbers_encoder_.StartEncoding(); remaining_bits_encoder_.StartEncoding(); @@ -228,8 +229,9 @@ uint32_t IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::GetAxis( RandomAccessIteratorT begin, RandomAccessIteratorT end, const PointDiT &old_base, std::array<uint32_t, D> levels, uint32_t last_axis) { - if (!Policy::select_axis) + if (!Policy::select_axis) { return DRACO_INCREMENT_MOD(last_axis, D); + } // For many points this function selects the axis that should be used // for the split by keeping as many points as possible bundled. @@ -256,8 +258,9 @@ uint32_t IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::GetAxis( PointDiT split(old_base); for (int i = 0; i < D; i++) { - if (num_remaining_bits[i]) + if (num_remaining_bits[i]) { split[i] += 1 << (num_remaining_bits[i] - 1); + } } std::array<uint32_t, D> deviations = PointTraits<PointDiT>::ZeroArray(); @@ -316,8 +319,9 @@ void IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::EncodeInternal( const uint32_t num_remaining_points = end - begin; // If this happens all axis are subdivided to the end. - if ((bit_length_ - level) == 0) + if ((bit_length_ - level) == 0) { continue; + } // Fast encoding of remaining bits if number of points is 1. // Doing this also for 2 gives a slight additional speed up. @@ -361,8 +365,9 @@ void IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::EncodeInternal( const uint32_t second_half = end - split; const bool left = first_half < second_half; - if (first_half != second_half) + if (first_half != second_half) { half_encoder_.EncodeBit(left); + } if (left) { EncodeNumber(required_bits, num_remaining_points / 2 - first_half); @@ -371,12 +376,14 @@ void IntegerPointsKdTreeEncoder<PointDiT, compression_level_t>::EncodeInternal( } levels[axis] += 1; - if (split != begin) + if (split != begin) { status_q.push(EncodingStatus<RandomAccessIteratorT>( begin, split, old_base, levels, axis)); - if (split != end) + } + if (split != end) { status_q.push(EncodingStatus<RandomAccessIteratorT>(split, end, new_base, levels, axis)); + } } } diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h index 9541c966856..9541c966856 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/point_cloud_compression_method.h diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/point_cloud_types.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/point_cloud_types.h index 3ed1d13e054..893efbefa32 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/point_cloud_types.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/point_cloud_types.h @@ -16,6 +16,7 @@ #define DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_POINT_CLOUD_TYPES_H_ #include <inttypes.h> + #include <vector> #include "draco/core/vector_d.h" diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/quantize_points_3.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/quantize_points_3.h index 771173032f6..01943ad9e6c 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/quantize_points_3.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/quantize_points_3.h @@ -16,6 +16,7 @@ #define DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_QUANTIZE_POINTS_3_H_ #include <inttypes.h> + #include "draco/compression/point_cloud/algorithms/point_cloud_types.h" #include "draco/core/quantization_utils.h" diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/queuing_policy.h b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/queuing_policy.h index 2db0ea213b8..2db0ea213b8 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/algorithms/queuing_policy.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/algorithms/queuing_policy.h diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_decoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_decoder.cc index cf5d997e67a..5196edf960c 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_decoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_decoder.cc @@ -28,20 +28,27 @@ PointCloudDecoder::PointCloudDecoder() Status PointCloudDecoder::DecodeHeader(DecoderBuffer *buffer, DracoHeader *out_header) { constexpr char kIoErrorMsg[] = "Failed to parse Draco header."; - if (!buffer->Decode(out_header->draco_string, 5)) + if (!buffer->Decode(out_header->draco_string, 5)) { return Status(Status::IO_ERROR, kIoErrorMsg); - if (memcmp(out_header->draco_string, "DRACO", 5) != 0) + } + if (memcmp(out_header->draco_string, "DRACO", 5) != 0) { return Status(Status::DRACO_ERROR, "Not a Draco file."); - if (!buffer->Decode(&(out_header->version_major))) + } + if (!buffer->Decode(&(out_header->version_major))) { return Status(Status::IO_ERROR, kIoErrorMsg); - if (!buffer->Decode(&(out_header->version_minor))) + } + if (!buffer->Decode(&(out_header->version_minor))) { return Status(Status::IO_ERROR, kIoErrorMsg); - if (!buffer->Decode(&(out_header->encoder_type))) + } + if (!buffer->Decode(&(out_header->encoder_type))) { return Status(Status::IO_ERROR, kIoErrorMsg); - if (!buffer->Decode(&(out_header->encoder_method))) + } + if (!buffer->Decode(&(out_header->encoder_method))) { return Status(Status::IO_ERROR, kIoErrorMsg); - if (!buffer->Decode(&(out_header->flags))) + } + if (!buffer->Decode(&(out_header->flags))) { return Status(Status::IO_ERROR, kIoErrorMsg); + } return OkStatus(); } @@ -49,8 +56,9 @@ Status PointCloudDecoder::DecodeMetadata() { std::unique_ptr<GeometryMetadata> metadata = std::unique_ptr<GeometryMetadata>(new GeometryMetadata()); MetadataDecoder metadata_decoder; - if (!metadata_decoder.DecodeGeometryMetadata(buffer_, metadata.get())) + if (!metadata_decoder.DecodeGeometryMetadata(buffer_, metadata.get())) { return Status(Status::DRACO_ERROR, "Failed to decode metadata."); + } point_cloud_->AddMetadata(std::move(metadata)); return OkStatus(); } @@ -65,9 +73,10 @@ Status PointCloudDecoder::Decode(const DecoderOptions &options, DRACO_RETURN_IF_ERROR(DecodeHeader(buffer_, &header)) // Sanity check that we are really using the right decoder (mostly for cases // where the Decode method was called manually outside of our main API. - if (header.encoder_type != GetGeometryType()) + if (header.encoder_type != GetGeometryType()) { return Status(Status::DRACO_ERROR, "Using incompatible decoder for the input geometry."); + } // TODO(ostava): We should check the method as well, but currently decoders // don't expose the decoding method id. version_major_ = header.version_major; @@ -80,11 +89,13 @@ Status PointCloudDecoder::Decode(const DecoderOptions &options, header.encoder_type == POINT_CLOUD ? kDracoPointCloudBitstreamVersionMinor : kDracoMeshBitstreamVersionMinor; // Check for version compatibility. - if (version_major_ < 1 || version_major_ > max_supported_major_version) + if (version_major_ < 1 || version_major_ > max_supported_major_version) { return Status(Status::UNKNOWN_VERSION, "Unknown major version."); + } if (version_major_ == max_supported_major_version && - version_minor_ > max_supported_minor_version) + version_minor_ > max_supported_minor_version) { return Status(Status::UNKNOWN_VERSION, "Unknown minor version."); + } buffer_->set_bitstream_version( DRACO_BITSTREAM_VERSION(version_major_, version_minor_)); @@ -92,37 +103,44 @@ Status PointCloudDecoder::Decode(const DecoderOptions &options, (header.flags & METADATA_FLAG_MASK)) { DRACO_RETURN_IF_ERROR(DecodeMetadata()) } - if (!InitializeDecoder()) + if (!InitializeDecoder()) { return Status(Status::DRACO_ERROR, "Failed to initialize the decoder."); - if (!DecodeGeometryData()) + } + if (!DecodeGeometryData()) { return Status(Status::DRACO_ERROR, "Failed to decode geometry data."); - if (!DecodePointAttributes()) + } + if (!DecodePointAttributes()) { return Status(Status::DRACO_ERROR, "Failed to decode point attributes."); + } return OkStatus(); } bool PointCloudDecoder::DecodePointAttributes() { uint8_t num_attributes_decoders; - if (!buffer_->Decode(&num_attributes_decoders)) + if (!buffer_->Decode(&num_attributes_decoders)) { return false; + } // Create all attribute decoders. This is implementation specific and the // derived classes can use any data encoded in the // PointCloudEncoder::EncodeAttributesEncoderIdentifier() call. for (int i = 0; i < num_attributes_decoders; ++i) { - if (!CreateAttributesDecoder(i)) + if (!CreateAttributesDecoder(i)) { return false; + } } // Initialize all attributes decoders. No data is decoded here. for (auto &att_dec : attributes_decoders_) { - if (!att_dec->Init(this, point_cloud_)) + if (!att_dec->Init(this, point_cloud_)) { return false; + } } // Decode any data needed by the attribute decoders. for (int i = 0; i < num_attributes_decoders; ++i) { - if (!attributes_decoders_[i]->DecodeAttributesDecoderData(buffer_)) + if (!attributes_decoders_[i]->DecodeAttributesDecoderData(buffer_)) { return false; + } } // Create map between attribute and decoder ids. @@ -138,26 +156,30 @@ bool PointCloudDecoder::DecodePointAttributes() { } // Decode the actual attributes using the created attribute decoders. - if (!DecodeAllAttributes()) + if (!DecodeAllAttributes()) { return false; + } - if (!OnAttributesDecoded()) + if (!OnAttributesDecoded()) { return false; + } return true; } bool PointCloudDecoder::DecodeAllAttributes() { for (auto &att_dec : attributes_decoders_) { - if (!att_dec->DecodeAttributes(buffer_)) + if (!att_dec->DecodeAttributes(buffer_)) { return false; + } } return true; } const PointAttribute *PointCloudDecoder::GetPortableAttribute( int32_t parent_att_id) { - if (parent_att_id < 0 || parent_att_id >= point_cloud_->num_attributes()) + if (parent_att_id < 0 || parent_att_id >= point_cloud_->num_attributes()) { return nullptr; + } const int32_t parent_att_decoder_id = attribute_to_decoder_map_[parent_att_id]; return attributes_decoders_[parent_att_decoder_id]->GetPortableAttribute( diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_decoder.h b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_decoder.h index abcb5e068f7..4af7f5cd32c 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_decoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_decoder.h @@ -42,10 +42,12 @@ class PointCloudDecoder { bool SetAttributesDecoder( int att_decoder_id, std::unique_ptr<AttributesDecoderInterface> decoder) { - if (att_decoder_id < 0) + if (att_decoder_id < 0) { return false; - if (att_decoder_id >= static_cast<int>(attributes_decoders_.size())) + } + if (att_decoder_id >= static_cast<int>(attributes_decoders_.size())) { attributes_decoders_.resize(att_decoder_id + 1); + } attributes_decoders_[att_decoder_id] = std::move(decoder); return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_encoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_encoder.cc index 986706582f0..b4b0ee94093 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_encoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_encoder.cc @@ -35,19 +35,24 @@ Status PointCloudEncoder::Encode(const EncoderOptions &options, attribute_to_encoder_map_.clear(); attributes_encoder_ids_order_.clear(); - if (!point_cloud_) + if (!point_cloud_) { return Status(Status::DRACO_ERROR, "Invalid input geometry."); + } DRACO_RETURN_IF_ERROR(EncodeHeader()) DRACO_RETURN_IF_ERROR(EncodeMetadata()) - if (!InitializeEncoder()) + if (!InitializeEncoder()) { return Status(Status::DRACO_ERROR, "Failed to initialize encoder."); - if (!EncodeEncoderData()) + } + if (!EncodeEncoderData()) { return Status(Status::DRACO_ERROR, "Failed to encode internal data."); + } DRACO_RETURN_IF_ERROR(EncodeGeometryData()); - if (!EncodePointAttributes()) + if (!EncodePointAttributes()) { return Status(Status::DRACO_ERROR, "Failed to encode point attributes."); - if (options.GetGlobalBool("store_number_of_encoded_points", false)) + } + if (options.GetGlobalBool("store_number_of_encoded_points", false)) { ComputeNumberOfEncodedPoints(); + } return OkStatus(); } @@ -92,8 +97,9 @@ Status PointCloudEncoder::EncodeMetadata() { } bool PointCloudEncoder::EncodePointAttributes() { - if (!GenerateAttributesEncoders()) + if (!GenerateAttributesEncoders()) { return false; + } // Encode the number of attribute encoders. buffer_->Encode(static_cast<uint8_t>(attributes_encoders_.size())); @@ -101,39 +107,45 @@ bool PointCloudEncoder::EncodePointAttributes() { // Initialize all the encoders (this is used for example to init attribute // dependencies, no data is encoded in this step). for (auto &att_enc : attributes_encoders_) { - if (!att_enc->Init(this, point_cloud_)) + if (!att_enc->Init(this, point_cloud_)) { return false; + } } // Rearrange attributes to respect dependencies between individual attributes. - if (!RearrangeAttributesEncoders()) + if (!RearrangeAttributesEncoders()) { return false; + } // Encode any data that is necessary to create the corresponding attribute // decoder. for (int att_encoder_id : attributes_encoder_ids_order_) { - if (!EncodeAttributesEncoderIdentifier(att_encoder_id)) + if (!EncodeAttributesEncoderIdentifier(att_encoder_id)) { return false; + } } // Also encode any attribute encoder data (such as the info about encoded // attributes). for (int att_encoder_id : attributes_encoder_ids_order_) { if (!attributes_encoders_[att_encoder_id]->EncodeAttributesEncoderData( - buffer_)) + buffer_)) { return false; + } } // Lastly encode all the attributes using the provided attribute encoders. - if (!EncodeAllAttributes()) + if (!EncodeAllAttributes()) { return false; + } return true; } bool PointCloudEncoder::GenerateAttributesEncoders() { for (int i = 0; i < point_cloud_->num_attributes(); ++i) { - if (!GenerateAttributesEncoder(i)) + if (!GenerateAttributesEncoder(i)) { return false; + } } attribute_to_encoder_map_.resize(point_cloud_->num_attributes()); for (uint32_t i = 0; i < attributes_encoders_.size(); ++i) { @@ -146,27 +158,31 @@ bool PointCloudEncoder::GenerateAttributesEncoders() { bool PointCloudEncoder::EncodeAllAttributes() { for (int att_encoder_id : attributes_encoder_ids_order_) { - if (!attributes_encoders_[att_encoder_id]->EncodeAttributes(buffer_)) + if (!attributes_encoders_[att_encoder_id]->EncodeAttributes(buffer_)) { return false; + } } return true; } bool PointCloudEncoder::MarkParentAttribute(int32_t parent_att_id) { - if (parent_att_id < 0 || parent_att_id >= point_cloud_->num_attributes()) + if (parent_att_id < 0 || parent_att_id >= point_cloud_->num_attributes()) { return false; + } const int32_t parent_att_encoder_id = attribute_to_encoder_map_[parent_att_id]; if (!attributes_encoders_[parent_att_encoder_id]->MarkParentAttribute( - parent_att_id)) + parent_att_id)) { return false; + } return true; } const PointAttribute *PointCloudEncoder::GetPortableAttribute( int32_t parent_att_id) { - if (parent_att_id < 0 || parent_att_id >= point_cloud_->num_attributes()) + if (parent_att_id < 0 || parent_att_id >= point_cloud_->num_attributes()) { return nullptr; + } const int32_t parent_att_encoder_id = attribute_to_encoder_map_[parent_att_id]; return attributes_encoders_[parent_att_encoder_id]->GetPortableAttribute( @@ -193,8 +209,9 @@ bool PointCloudEncoder::RearrangeAttributesEncoders() { // Flagged when any of the encoder get processed. bool encoder_processed = false; for (uint32_t i = 0; i < attributes_encoders_.size(); ++i) { - if (is_encoder_processed[i]) + if (is_encoder_processed[i]) { continue; // Encoder already processed. + } // Check if all parent encoders are already processed. bool can_be_processed = true; for (uint32_t p = 0; p < attributes_encoders_[i]->num_attributes(); ++p) { @@ -211,8 +228,9 @@ bool PointCloudEncoder::RearrangeAttributesEncoders() { } } } - if (!can_be_processed) + if (!can_be_processed) { continue; // Try to process the encoder in the next iteration. + } // Encoder can be processed. Update the encoding order. attributes_encoder_ids_order_[num_processed_encoders++] = i; is_encoder_processed[i] = true; @@ -238,8 +256,9 @@ bool PointCloudEncoder::RearrangeAttributesEncoders() { const int ae = attributes_encoder_ids_order_[ae_order]; const int32_t num_encoder_attributes = attributes_encoders_[ae]->num_attributes(); - if (num_encoder_attributes < 2) + if (num_encoder_attributes < 2) { continue; // No need to resolve dependencies for a single attribute. + } num_processed_attributes = 0; attribute_encoding_order.resize(num_encoder_attributes); while (num_processed_attributes < num_encoder_attributes) { @@ -247,8 +266,9 @@ bool PointCloudEncoder::RearrangeAttributesEncoders() { bool attribute_processed = false; for (int i = 0; i < num_encoder_attributes; ++i) { const int32_t att_id = attributes_encoders_[ae]->GetAttributeId(i); - if (is_attribute_processed[i]) + if (is_attribute_processed[i]) { continue; // Attribute already processed. + } // Check if all parent attributes are already processed. bool can_be_processed = true; for (int p = 0; @@ -260,8 +280,9 @@ bool PointCloudEncoder::RearrangeAttributesEncoders() { break; } } - if (!can_be_processed) + if (!can_be_processed) { continue; // Try to process the attribute in the next iteration. + } // Attribute can be processed. Update the encoding order. attribute_encoding_order[num_processed_attributes++] = i; is_attribute_processed[i] = true; diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_encoder.h b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_encoder.h index 8883f17a789..8883f17a789 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_encoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.cc index c35fd79df60..2deebbc4853 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.cc @@ -20,10 +20,12 @@ namespace draco { bool PointCloudKdTreeDecoder::DecodeGeometryData() { int32_t num_points; - if (!buffer()->Decode(&num_points)) + if (!buffer()->Decode(&num_points)) { return false; - if (num_points < 0) + } + if (num_points < 0) { return false; + } point_cloud()->set_num_points(num_points); return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h index 6e192f2a5a0..6e192f2a5a0 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.cc index 6d0446baad1..92b6c84cd63 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/compression/point_cloud/point_cloud_kd_tree_encoder.h" + #include "draco/compression/attributes/kd_tree_attributes_encoder.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h index 6acbb949d40..6acbb949d40 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_kd_tree_encoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_decoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_decoder.cc index 614cf37b266..b9382d31070 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_decoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_decoder.cc @@ -21,8 +21,9 @@ namespace draco { bool PointCloudSequentialDecoder::DecodeGeometryData() { int32_t num_points; - if (!buffer()->Decode(&num_points)) + if (!buffer()->Decode(&num_points)) { return false; + } point_cloud()->set_num_points(num_points); return true; } diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_decoder.h b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_decoder.h index 9968dc27517..9968dc27517 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_decoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_decoder.h diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoder.cc b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_encoder.cc index fa7b6fd905c..fa7b6fd905c 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoder.cc +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_encoder.cc diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoder.h b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_encoder.h index 40d8edcdbb0..40d8edcdbb0 100644 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoder.h +++ b/extern/draco/draco/src/draco/compression/point_cloud/point_cloud_sequential_encoder.h diff --git a/extern/draco/dracoenc/src/draco/core/bit_utils.cc b/extern/draco/draco/src/draco/core/bit_utils.cc index 37119a7171b..37119a7171b 100644 --- a/extern/draco/dracoenc/src/draco/core/bit_utils.cc +++ b/extern/draco/draco/src/draco/core/bit_utils.cc diff --git a/extern/draco/dracoenc/src/draco/core/bit_utils.h b/extern/draco/draco/src/draco/core/bit_utils.h index f63cd0750c9..a102095c719 100644 --- a/extern/draco/dracoenc/src/draco/core/bit_utils.h +++ b/extern/draco/draco/src/draco/core/bit_utils.h @@ -20,6 +20,7 @@ #include <inttypes.h> #include <stdint.h> + #include <type_traits> #if defined(_MSC_VER) diff --git a/extern/draco/dracoenc/src/draco/core/bounding_box.cc b/extern/draco/draco/src/draco/core/bounding_box.cc index d95b1e90759..d95b1e90759 100644 --- a/extern/draco/dracoenc/src/draco/core/bounding_box.cc +++ b/extern/draco/draco/src/draco/core/bounding_box.cc diff --git a/extern/draco/dracoenc/src/draco/core/bounding_box.h b/extern/draco/draco/src/draco/core/bounding_box.h index 0259267c99c..1c20fad8bf2 100644 --- a/extern/draco/dracoenc/src/draco/core/bounding_box.h +++ b/extern/draco/draco/src/draco/core/bounding_box.h @@ -36,10 +36,12 @@ class BoundingBox { // argument to an iterator. inline void update_bounding_box(const Vector3f &new_point) { for (int i = 0; i < 3; i++) { - if (new_point[i] < min_point_[i]) + if (new_point[i] < min_point_[i]) { min_point_[i] = new_point[i]; - if (new_point[i] > max_point_[i]) + } + if (new_point[i] > max_point_[i]) { max_point_[i] = new_point[i]; + } } } diff --git a/extern/draco/dracoenc/src/draco/core/cycle_timer.cc b/extern/draco/draco/src/draco/core/cycle_timer.cc index 1eea9f59702..94b4b28b2f9 100644 --- a/extern/draco/dracoenc/src/draco/core/cycle_timer.cc +++ b/extern/draco/draco/src/draco/core/cycle_timer.cc @@ -19,7 +19,7 @@ void DracoTimer::Start() { #ifdef _WIN32 QueryPerformanceCounter(&tv_start); #else - gettimeofday(&tv_start, NULL); + gettimeofday(&tv_start, nullptr); #endif } @@ -27,7 +27,7 @@ void DracoTimer::Stop() { #ifdef _WIN32 QueryPerformanceCounter(&tv_end); #else - gettimeofday(&tv_end, NULL); + gettimeofday(&tv_end, nullptr); #endif } diff --git a/extern/draco/dracoenc/src/draco/core/cycle_timer.h b/extern/draco/draco/src/draco/core/cycle_timer.h index 172f1c2e9b5..172f1c2e9b5 100644 --- a/extern/draco/dracoenc/src/draco/core/cycle_timer.h +++ b/extern/draco/draco/src/draco/core/cycle_timer.h diff --git a/extern/draco/dracoenc/src/draco/core/data_buffer.cc b/extern/draco/draco/src/draco/core/data_buffer.cc index 867760a6fcc..f0b43d67dbd 100644 --- a/extern/draco/dracoenc/src/draco/core/data_buffer.cc +++ b/extern/draco/draco/src/draco/core/data_buffer.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/core/data_buffer.h" + #include <algorithm> namespace draco { @@ -26,15 +27,18 @@ bool DataBuffer::Update(const void *data, int64_t size) { bool DataBuffer::Update(const void *data, int64_t size, int64_t offset) { if (data == nullptr) { - if (size + offset < 0) + if (size + offset < 0) { return false; + } // If no data is provided, just resize the buffer. data_.resize(size + offset); } else { - if (size < 0) + if (size < 0) { return false; - if (size + offset > static_cast<int64_t>(data_.size())) + } + if (size + offset > static_cast<int64_t>(data_.size())) { data_.resize(size + offset); + } const uint8_t *const byte_data = static_cast<const uint8_t *>(data); std::copy(byte_data, byte_data + size, data_.data() + offset); } @@ -48,8 +52,9 @@ void DataBuffer::Resize(int64_t size) { } void DataBuffer::WriteDataToStream(std::ostream &stream) { - if (data_.size() == 0) + if (data_.size() == 0) { return; + } stream.write(reinterpret_cast<char *>(data_.data()), data_.size()); } diff --git a/extern/draco/dracoenc/src/draco/core/data_buffer.h b/extern/draco/draco/src/draco/core/data_buffer.h index 8ee690540bc..8ee690540bc 100644 --- a/extern/draco/dracoenc/src/draco/core/data_buffer.h +++ b/extern/draco/draco/src/draco/core/data_buffer.h diff --git a/extern/draco/dracoenc/src/draco/core/decoder_buffer.cc b/extern/draco/draco/src/draco/core/decoder_buffer.cc index 5ce1f064ac2..4e8ed618d92 100644 --- a/extern/draco/dracoenc/src/draco/core/decoder_buffer.cc +++ b/extern/draco/draco/src/draco/core/decoder_buffer.cc @@ -41,13 +41,15 @@ bool DecoderBuffer::StartBitDecoding(bool decode_size, uint64_t *out_size) { if (decode_size) { #ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED if (bitstream_version_ < DRACO_BITSTREAM_VERSION(2, 2)) { - if (!Decode(out_size)) + if (!Decode(out_size)) { return false; + } } else #endif { - if (!DecodeVarint(out_size, this)) + if (!DecodeVarint(out_size, this)) { return false; + } } } bit_mode_ = true; diff --git a/extern/draco/dracoenc/src/draco/core/decoder_buffer.h b/extern/draco/draco/src/draco/core/decoder_buffer.h index 5e3d1ac738d..0559abbe415 100644 --- a/extern/draco/dracoenc/src/draco/core/decoder_buffer.h +++ b/extern/draco/draco/src/draco/core/decoder_buffer.h @@ -16,12 +16,12 @@ #define DRACO_CORE_DECODER_BUFFER_H_ #include <stdint.h> + #include <cstring> #include <memory> -#include "draco/draco_features.h" - #include "draco/core/macros.h" +#include "draco/draco_features.h" namespace draco { @@ -55,8 +55,9 @@ class DecoderBuffer { // Decodes up to 32 bits into out_val. Can be called only in between // StartBitDecoding and EndBitDecoding. Otherwise returns false. bool DecodeLeastSignificantBits32(int nbits, uint32_t *out_value) { - if (!bit_decoder_active()) + if (!bit_decoder_active()) { return false; + } bit_decoder_.GetBits(nbits, out_value); return true; } @@ -66,15 +67,17 @@ class DecoderBuffer { // Returns false on error. template <typename T> bool Decode(T *out_val) { - if (!Peek(out_val)) + if (!Peek(out_val)) { return false; + } pos_ += sizeof(T); return true; } bool Decode(void *out_data, size_t size_to_decode) { - if (data_size_ < static_cast<int64_t>(pos_ + size_to_decode)) + if (data_size_ < static_cast<int64_t>(pos_ + size_to_decode)) { return false; // Buffer overflow. + } memcpy(out_data, (data_ + pos_), size_to_decode); pos_ += size_to_decode; return true; @@ -84,15 +87,17 @@ class DecoderBuffer { template <typename T> bool Peek(T *out_val) { const size_t size_to_decode = sizeof(T); - if (data_size_ < static_cast<int64_t>(pos_ + size_to_decode)) + if (data_size_ < static_cast<int64_t>(pos_ + size_to_decode)) { return false; // Buffer overflow. + } memcpy(out_val, (data_ + pos_), size_to_decode); return true; } bool Peek(void *out_data, size_t size_to_peek) { - if (data_size_ < static_cast<int64_t>(pos_ + size_to_peek)) + if (data_size_ < static_cast<int64_t>(pos_ + size_to_peek)) { return false; // Buffer overflow. + } memcpy(out_data, (data_ + pos_), size_to_peek); return true; } @@ -157,8 +162,9 @@ class DecoderBuffer { DRACO_DCHECK_GE(nbits, 0); DRACO_DCHECK_LE(nbits, 32); uint32_t value = 0; - for (int32_t bit = 0; bit < nbits; ++bit) + for (int32_t bit = 0; bit < nbits; ++bit) { value |= GetBit() << bit; + } *x = value; return true; } diff --git a/extern/draco/dracoenc/src/draco/core/divide.cc b/extern/draco/draco/src/draco/core/divide.cc index 6d2e57120c8..6d2e57120c8 100644 --- a/extern/draco/dracoenc/src/draco/core/divide.cc +++ b/extern/draco/draco/src/draco/core/divide.cc diff --git a/extern/draco/dracoenc/src/draco/core/divide.h b/extern/draco/draco/src/draco/core/divide.h index 2217c861e0b..7e3838a008c 100644 --- a/extern/draco/dracoenc/src/draco/core/divide.h +++ b/extern/draco/draco/src/draco/core/divide.h @@ -19,6 +19,7 @@ // This file is based off libvpx's divide.h. #include <stdint.h> + #include <climits> namespace draco { diff --git a/extern/draco/dracoenc/src/draco/core/draco_index_type.h b/extern/draco/draco/src/draco/core/draco_index_type.h index d9dd3f64fa8..d9dd3f64fa8 100644 --- a/extern/draco/dracoenc/src/draco/core/draco_index_type.h +++ b/extern/draco/draco/src/draco/core/draco_index_type.h diff --git a/extern/draco/dracoenc/src/draco/core/draco_index_type_vector.h b/extern/draco/draco/src/draco/core/draco_index_type_vector.h index e2062ef3f35..d47ab3b04eb 100644 --- a/extern/draco/dracoenc/src/draco/core/draco_index_type_vector.h +++ b/extern/draco/draco/src/draco/core/draco_index_type_vector.h @@ -28,7 +28,7 @@ namespace draco { // draco_index_type.h . // TODO(ostava): Make the interface more complete. It's currently missing // features such as iterators. -// TODO(draco-eng): Make unit tests for this class. +// TODO(vytyaz): Add more unit tests for this class. template <class IndexTypeT, class ValueTypeT> class IndexTypeVector { public: @@ -50,10 +50,16 @@ class IndexTypeVector { } size_t size() const { return vector_.size(); } + bool empty() const { return vector_.empty(); } void push_back(const ValueTypeT &val) { vector_.push_back(val); } void push_back(ValueTypeT &&val) { vector_.push_back(std::move(val)); } + template <typename... Args> + void emplace_back(Args &&... args) { + vector_.emplace_back(std::forward<Args>(args)...); + } + inline reference operator[](const IndexTypeT &index) { return vector_[index.value()]; } diff --git a/extern/draco/dracoenc/src/draco/core/draco_types.cc b/extern/draco/draco/src/draco/core/draco_types.cc index 9bde05fda80..9bde05fda80 100644 --- a/extern/draco/dracoenc/src/draco/core/draco_types.cc +++ b/extern/draco/draco/src/draco/core/draco_types.cc diff --git a/extern/draco/dracoenc/src/draco/core/draco_types.h b/extern/draco/draco/src/draco/core/draco_types.h index f5a21e4f1d0..d14437a0214 100644 --- a/extern/draco/dracoenc/src/draco/core/draco_types.h +++ b/extern/draco/draco/src/draco/core/draco_types.h @@ -16,6 +16,7 @@ #define DRACO_CORE_DRACO_TYPES_H_ #include <stdint.h> + #include <string> #include "draco/draco_features.h" diff --git a/extern/draco/dracoenc/src/draco/core/draco_version.h b/extern/draco/draco/src/draco/core/draco_version.h index 9d3a67e4f8e..ffd7948c64d 100644 --- a/extern/draco/dracoenc/src/draco/core/draco_version.h +++ b/extern/draco/draco/src/draco/core/draco_version.h @@ -18,7 +18,7 @@ namespace draco { // Draco version is comprised of <major>.<minor>.<revision>. -static const char kDracoVersion[] = "1.3.5"; +static const char kDracoVersion[] = "1.3.6"; const char *Version() { return kDracoVersion; } diff --git a/extern/draco/dracoenc/src/draco/core/encoder_buffer.cc b/extern/draco/draco/src/draco/core/encoder_buffer.cc index a5e936fd89b..df98677a85b 100644 --- a/extern/draco/dracoenc/src/draco/core/encoder_buffer.cc +++ b/extern/draco/draco/src/draco/core/encoder_buffer.cc @@ -31,10 +31,12 @@ void EncoderBuffer::Clear() { void EncoderBuffer::Resize(int64_t nbytes) { buffer_.resize(nbytes); } bool EncoderBuffer::StartBitEncoding(int64_t required_bits, bool encode_size) { - if (bit_encoder_active()) + if (bit_encoder_active()) { return false; // Bit encoding mode already active. - if (required_bits <= 0) + } + if (required_bits <= 0) { return false; // Invalid size. + } encode_bit_sequence_size_ = encode_size; const int64_t required_bytes = (required_bits + 7) / 8; bit_encoder_reserved_bytes_ = required_bytes; @@ -54,8 +56,9 @@ bool EncoderBuffer::StartBitEncoding(int64_t required_bits, bool encode_size) { } void EncoderBuffer::EndBitEncoding() { - if (!bit_encoder_active()) + if (!bit_encoder_active()) { return; + } // Get the number of encoded bits and bytes (rounded up). const uint64_t encoded_bits = bit_encoder_->Bits(); const uint64_t encoded_bytes = (encoded_bits + 7) / 8; diff --git a/extern/draco/dracoenc/src/draco/core/encoder_buffer.h b/extern/draco/draco/src/draco/core/encoder_buffer.h index ff3e89ba270..b153a629792 100644 --- a/extern/draco/dracoenc/src/draco/core/encoder_buffer.h +++ b/extern/draco/draco/src/draco/core/encoder_buffer.h @@ -47,8 +47,9 @@ class EncoderBuffer { // Encode up to 32 bits into the buffer. Can be called only in between // StartBitEncoding and EndBitEncoding. Otherwise returns false. bool EncodeLeastSignificantBits32(int nbits, uint32_t value) { - if (!bit_encoder_active()) + if (!bit_encoder_active()) { return false; + } bit_encoder_->PutBits(value, nbits); return true; } @@ -57,15 +58,17 @@ class EncoderBuffer { // Returns false when the value couldn't be encoded. template <typename T> bool Encode(const T &data) { - if (bit_encoder_active()) + if (bit_encoder_active()) { return false; + } const uint8_t *src_data = reinterpret_cast<const uint8_t *>(&data); buffer_.insert(buffer_.end(), src_data, src_data + sizeof(T)); return true; } bool Encode(const void *data, size_t data_size) { - if (bit_encoder_active()) + if (bit_encoder_active()) { return false; + } const uint8_t *src_data = reinterpret_cast<const uint8_t *>(data); buffer_.insert(buffer_.end(), src_data, src_data + data_size); return true; @@ -87,8 +90,9 @@ class EncoderBuffer { void PutBits(uint32_t data, int32_t nbits) { DRACO_DCHECK_GE(nbits, 0); DRACO_DCHECK_LE(nbits, 32); - for (int32_t bit = 0; bit < nbits; ++bit) + for (int32_t bit = 0; bit < nbits; ++bit) { PutBit((data >> bit) & 1); + } } // Return number of bits encoded so far. diff --git a/extern/draco/dracoenc/src/draco/core/hash_utils.cc b/extern/draco/draco/src/draco/core/hash_utils.cc index 9a78c2cfafd..fbbd653f369 100644 --- a/extern/draco/dracoenc/src/draco/core/hash_utils.cc +++ b/extern/draco/draco/src/draco/core/hash_utils.cc @@ -50,8 +50,9 @@ uint64_t FingerprintString(const char *s, size_t len) { hash = HashCombine(new_hash, hash); } - if (hash < std::numeric_limits<uint64_t>::max() - 1) + if (hash < std::numeric_limits<uint64_t>::max() - 1) { hash += 2; + } return hash; } } // namespace draco diff --git a/extern/draco/dracoenc/src/draco/core/hash_utils.h b/extern/draco/draco/src/draco/core/hash_utils.h index 0e8da60aa54..aa61523e7fe 100644 --- a/extern/draco/dracoenc/src/draco/core/hash_utils.h +++ b/extern/draco/draco/src/draco/core/hash_utils.h @@ -16,9 +16,9 @@ #define DRACO_CORE_HASH_UTILS_H_ #include <stdint.h> -#include <functional> -// TODO(fgalligan): Move this to core. +#include <cstddef> +#include <functional> namespace draco { diff --git a/extern/draco/dracoenc/src/draco/core/macros.h b/extern/draco/draco/src/draco/core/macros.h index 09819e63969..89b706e53a5 100644 --- a/extern/draco/dracoenc/src/draco/core/macros.h +++ b/extern/draco/draco/src/draco/core/macros.h @@ -16,7 +16,6 @@ #define DRACO_CORE_MACROS_H_ #include "assert.h" - #include "draco/draco_features.h" #ifdef ANDROID_LOGGING diff --git a/extern/draco/dracoenc/src/draco/core/math_utils.h b/extern/draco/draco/src/draco/core/math_utils.h index 50cf5d57199..7f382fa34d4 100644 --- a/extern/draco/dracoenc/src/draco/core/math_utils.h +++ b/extern/draco/draco/src/draco/core/math_utils.h @@ -27,8 +27,9 @@ // replacement for std::sqrt() for general cases. IntSqrt is in fact about 3X // slower compared to most implementation of std::sqrt(). inline uint64_t IntSqrt(uint64_t number) { - if (number == 0) + if (number == 0) { return 0; + } // First estimate good initial value of the square root as log2(number). uint64_t act_number = number; uint64_t square_root = 1; diff --git a/extern/draco/dracoenc/src/draco/core/options.cc b/extern/draco/draco/src/draco/core/options.cc index a9ce14b9837..9b81db48987 100644 --- a/extern/draco/dracoenc/src/draco/core/options.cc +++ b/extern/draco/draco/src/draco/core/options.cc @@ -23,8 +23,9 @@ namespace draco { Options::Options() {} void Options::MergeAndReplace(const Options &other_options) { - for (const auto &item : other_options.options_) + for (const auto &item : other_options.options_) { options_[item.first] = item.second; + } } void Options::SetInt(const std::string &name, int val) { @@ -47,8 +48,9 @@ int Options::GetInt(const std::string &name) const { return GetInt(name, -1); } int Options::GetInt(const std::string &name, int default_val) const { const auto it = options_.find(name); - if (it == options_.end()) + if (it == options_.end()) { return default_val; + } return std::atoi(it->second.c_str()); } @@ -58,8 +60,9 @@ float Options::GetFloat(const std::string &name) const { float Options::GetFloat(const std::string &name, float default_val) const { const auto it = options_.find(name); - if (it == options_.end()) + if (it == options_.end()) { return default_val; + } return static_cast<float>(std::atof(it->second.c_str())); } @@ -69,8 +72,9 @@ bool Options::GetBool(const std::string &name) const { bool Options::GetBool(const std::string &name, bool default_val) const { const int ret = GetInt(name, -1); - if (ret == -1) + if (ret == -1) { return default_val; + } return static_cast<bool>(ret); } @@ -81,8 +85,9 @@ std::string Options::GetString(const std::string &name) const { std::string Options::GetString(const std::string &name, const std::string &default_val) const { const auto it = options_.find(name); - if (it == options_.end()) + if (it == options_.end()) { return default_val; + } return it->second; } diff --git a/extern/draco/dracoenc/src/draco/core/options.h b/extern/draco/draco/src/draco/core/options.h index 4995299633c..1bc4dc0fb7b 100644 --- a/extern/draco/dracoenc/src/draco/core/options.h +++ b/extern/draco/draco/src/draco/core/options.h @@ -81,8 +81,9 @@ void Options::SetVector(const std::string &name, const DataTypeT *vec, int num_dims) { std::string out; for (int i = 0; i < num_dims; ++i) { - if (i > 0) + if (i > 0) { out += " "; + } // GNU STL on android doesn't include a proper std::to_string, but the libc++ // version does @@ -107,11 +108,13 @@ template <typename DataTypeT> bool Options::GetVector(const std::string &name, int num_dims, DataTypeT *out_val) const { const auto it = options_.find(name); - if (it == options_.end()) + if (it == options_.end()) { return false; + } const std::string value = it->second; - if (value.length() == 0) + if (value.length() == 0) { return true; // Option set but no data is present + } const char *act_str = value.c_str(); char *next_str; for (int i = 0; i < num_dims; ++i) { @@ -119,10 +122,11 @@ bool Options::GetVector(const std::string &name, int num_dims, #ifdef ANDROID const int val = strtol(act_str, &next_str, 10); #else - const int val = std::strtol(act_str, &next_str, 10); + const int val = static_cast<int>(std::strtol(act_str, &next_str, 10)); #endif - if (act_str == next_str) + if (act_str == next_str) { return true; // End reached. + } act_str = next_str; out_val[i] = static_cast<DataTypeT>(val); } else { @@ -131,8 +135,9 @@ bool Options::GetVector(const std::string &name, int num_dims, #else const float val = std::strtof(act_str, &next_str); #endif - if (act_str == next_str) + if (act_str == next_str) { return true; // End reached. + } act_str = next_str; out_val[i] = static_cast<DataTypeT>(val); } diff --git a/extern/draco/dracoenc/src/draco/core/quantization_utils.cc b/extern/draco/draco/src/draco/core/quantization_utils.cc index 26417b01998..58dcf5c8c20 100644 --- a/extern/draco/dracoenc/src/draco/core/quantization_utils.cc +++ b/extern/draco/draco/src/draco/core/quantization_utils.cc @@ -27,8 +27,9 @@ void Quantizer::Init(float delta) { inverse_delta_ = 1.f / delta; } Dequantizer::Dequantizer() : delta_(1.f) {} bool Dequantizer::Init(float range, int32_t max_quantized_value) { - if (max_quantized_value <= 0) + if (max_quantized_value <= 0) { return false; + } delta_ = range / static_cast<float>(max_quantized_value); return true; } diff --git a/extern/draco/dracoenc/src/draco/core/quantization_utils.h b/extern/draco/draco/src/draco/core/quantization_utils.h index 54910467407..0f60f1e1b17 100644 --- a/extern/draco/dracoenc/src/draco/core/quantization_utils.h +++ b/extern/draco/draco/src/draco/core/quantization_utils.h @@ -22,6 +22,7 @@ #define DRACO_CORE_QUANTIZATION_UTILS_H_ #include <stdint.h> + #include <cmath> #include "draco/core/macros.h" diff --git a/extern/draco/dracoenc/src/draco/core/status.h b/extern/draco/draco/src/draco/core/status.h index 9ac3def7cd1..449ad8566de 100644 --- a/extern/draco/dracoenc/src/draco/core/status.h +++ b/extern/draco/draco/src/draco/core/status.h @@ -31,6 +31,7 @@ class Status { UNSUPPORTED_VERSION = -4, // Input not compatible with the current version. UNKNOWN_VERSION = -5, // Input was created with an unknown version of // the library. + UNSUPPORTED_FEATURE = -6, // Input contains feature that is not supported. }; Status() : code_(OK) {} @@ -66,8 +67,9 @@ inline Status OkStatus() { return Status(Status::OK); } #define DRACO_RETURN_IF_ERROR(expression) \ { \ const draco::Status _local_status = (expression); \ - if (!_local_status.ok()) \ + if (!_local_status.ok()) { \ return _local_status; \ + } \ } } // namespace draco diff --git a/extern/draco/dracoenc/src/draco/core/status_or.h b/extern/draco/draco/src/draco/core/status_or.h index 156b9bc02a7..156b9bc02a7 100644 --- a/extern/draco/dracoenc/src/draco/core/status_or.h +++ b/extern/draco/draco/src/draco/core/status_or.h diff --git a/extern/draco/dracoenc/src/draco/core/varint_decoding.h b/extern/draco/draco/src/draco/core/varint_decoding.h index 6cd41b29220..4e86df732e0 100644 --- a/extern/draco/dracoenc/src/draco/core/varint_decoding.h +++ b/extern/draco/draco/src/draco/core/varint_decoding.h @@ -22,33 +22,54 @@ namespace draco { +namespace { + +// Decodes a specified unsigned integer as varint. |depth| is the current +// recursion call depth. The first call to the function must be 1. +template <typename IntTypeT> +bool DecodeVarintUnsigned(int depth, IntTypeT *out_val, DecoderBuffer *buffer) { + constexpr IntTypeT max_depth = sizeof(IntTypeT) + 1 + (sizeof(IntTypeT) >> 3); + if (depth > max_depth) { + return false; + } + // Coding of unsigned values. + // 0-6 bit - data + // 7 bit - next byte? + uint8_t in; + if (!buffer->Decode(&in)) { + return false; + } + if (in & (1 << 7)) { + // Next byte is available, decode it first. + if (!DecodeVarintUnsigned<IntTypeT>(depth + 1, out_val, buffer)) { + return false; + } + // Append decoded info from this byte. + *out_val <<= 7; + *out_val |= in & ((1 << 7) - 1); + } else { + // Last byte reached + *out_val = in; + } + return true; +} + +} // namespace + // Decodes a specified integer as varint. Note that the IntTypeT must be the // same as the one used in the corresponding EncodeVarint() call. template <typename IntTypeT> bool DecodeVarint(IntTypeT *out_val, DecoderBuffer *buffer) { if (std::is_unsigned<IntTypeT>::value) { - // Coding of unsigned values. - // 0-6 bit - data - // 7 bit - next byte? - uint8_t in; - if (!buffer->Decode(&in)) + if (!DecodeVarintUnsigned<IntTypeT>(1, out_val, buffer)) { return false; - if (in & (1 << 7)) { - // Next byte is available, decode it first. - if (!DecodeVarint<IntTypeT>(out_val, buffer)) - return false; - // Append decoded info from this byte. - *out_val <<= 7; - *out_val |= in & ((1 << 7) - 1); - } else { - // Last byte reached - *out_val = in; } } else { // IntTypeT is a signed value. Decode the symbol and convert to signed. typename std::make_unsigned<IntTypeT>::type symbol; - if (!DecodeVarint(&symbol, buffer)) + if (!DecodeVarintUnsigned(1, &symbol, buffer)) { return false; + } *out_val = ConvertSymbolToSignedInt(symbol); } return true; diff --git a/extern/draco/dracoenc/src/draco/core/varint_encoding.h b/extern/draco/draco/src/draco/core/varint_encoding.h index b9b6dcab78d..9a8a5393698 100644 --- a/extern/draco/dracoenc/src/draco/core/varint_encoding.h +++ b/extern/draco/draco/src/draco/core/varint_encoding.h @@ -34,20 +34,24 @@ bool EncodeVarint(IntTypeT val, EncoderBuffer *out_buffer) { out |= val & ((1 << 7) - 1); if (val >= (1 << 7)) { out |= (1 << 7); - if (!out_buffer->Encode(out)) + if (!out_buffer->Encode(out)) { return false; - if (!EncodeVarint<IntTypeT>(val >> 7, out_buffer)) + } + if (!EncodeVarint<IntTypeT>(val >> 7, out_buffer)) { return false; + } return true; } - if (!out_buffer->Encode(out)) + if (!out_buffer->Encode(out)) { return false; + } } else { // IntTypeT is a signed value. Convert to unsigned symbol and encode. const typename std::make_unsigned<IntTypeT>::type symbol = ConvertSignedIntToSymbol(val); - if (!EncodeVarint(symbol, out_buffer)) + if (!EncodeVarint(symbol, out_buffer)) { return false; + } } return true; } diff --git a/extern/draco/dracoenc/src/draco/core/vector_d.h b/extern/draco/draco/src/draco/core/vector_d.h index 189517f3928..bed97304feb 100644 --- a/extern/draco/dracoenc/src/draco/core/vector_d.h +++ b/extern/draco/draco/src/draco/core/vector_d.h @@ -16,6 +16,7 @@ #define DRACO_CORE_VECTOR_D_H_ #include <inttypes.h> + #include <algorithm> #include <array> #include <cmath> @@ -36,8 +37,9 @@ class VectorD { typedef ScalarT CoefficientType; VectorD() { - for (int i = 0; i < dimension; ++i) + for (int i = 0; i < dimension; ++i) { (*this)[i] = Scalar(0); + } } // The following constructor does not compile in opt mode, which for now led @@ -83,8 +85,9 @@ class VectorD { } VectorD(const Self &o) { - for (int i = 0; i < dimension; ++i) + for (int i = 0; i < dimension; ++i) { (*this)[i] = o[i]; + } } // Constructs the vector from another vector with a different data type or a @@ -97,10 +100,11 @@ class VectorD { template <class OtherScalarT, int other_dimension_t> explicit VectorD(const VectorD<OtherScalarT, other_dimension_t> &src_vector) { for (int i = 0; i < dimension; ++i) { - if (i < other_dimension_t) + if (i < other_dimension_t) { v_[i] = Scalar(src_vector[i]); - else + } else { v_[i] = Scalar(0); + } } } @@ -137,6 +141,35 @@ class VectorD { return ret; } + Self operator*(const Self &o) const { + Self ret; + for (int i = 0; i < dimension; ++i) { + ret[i] = (*this)[i] * o[i]; + } + return ret; + } + + Self &operator+=(const Self &o) { + for (int i = 0; i < dimension; ++i) { + (*this)[i] += o[i]; + } + return *this; + } + + Self &operator-=(const Self &o) { + for (int i = 0; i < dimension; ++i) { + (*this)[i] -= o[i]; + } + return *this; + } + + Self &operator*=(const Self &o) { + for (int i = 0; i < dimension; ++i) { + (*this)[i] *= o[i]; + } + return *this; + } + Self operator*(const Scalar &o) const { Self ret; for (int i = 0; i < dimension; ++i) { @@ -171,8 +204,9 @@ class VectorD { bool operator==(const Self &o) const { for (int i = 0; i < dimension; ++i) { - if ((*this)[i] != o[i]) + if ((*this)[i] != o[i]) { return false; + } } return true; } @@ -181,14 +215,17 @@ class VectorD { bool operator<(const Self &x) const { for (int i = 0; i < dimension - 1; ++i) { - if (v_[i] < x.v_[i]) + if (v_[i] < x.v_[i]) { return true; - if (v_[i] > x.v_[i]) + } + if (v_[i] > x.v_[i]) { return false; + } } // Only one check needed for the last dimension. - if (v_[dimension - 1] < x.v_[dimension - 1]) + if (v_[dimension - 1] < x.v_[dimension - 1]) { return true; + } return false; } @@ -222,6 +259,12 @@ class VectorD { } } + Self GetNormalized() const { + Self ret(*this); + ret.Normalize(); + return ret; + } + const Scalar &MaxCoeff() const { return *std::max_element(v_.begin(), v_.end()); } @@ -231,6 +274,7 @@ class VectorD { } Scalar *data() { return &(v_[0]); } + const Scalar *data() const { return &(v_[0]); } private: std::array<Scalar, dimension> v_; diff --git a/extern/draco/draco/src/draco/draco_features.h b/extern/draco/draco/src/draco/draco_features.h new file mode 100644 index 00000000000..27e3d7f136a --- /dev/null +++ b/extern/draco/draco/src/draco/draco_features.h @@ -0,0 +1,10 @@ +#ifndef DRACO_FEATURES_H_ +#define DRACO_FEATURES_H_ + +#define DRACO_MESH_COMPRESSION_SUPPORTED +#define DRACO_NORMAL_ENCODING_SUPPORTED +#define DRACO_STANDARD_EDGEBREAKER_SUPPORTED +#define DRACO_ATTRIBUTE_INDICES_DEDUPLICATION_SUPPORTED +#define DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED + +#endif // DRACO_FEATURES_H_ diff --git a/extern/draco/dracoenc/src/draco/mesh/corner_table.cc b/extern/draco/draco/src/draco/mesh/corner_table.cc index dcfd7967c0b..6066e58bd8b 100644 --- a/extern/draco/dracoenc/src/draco/mesh/corner_table.cc +++ b/extern/draco/draco/src/draco/mesh/corner_table.cc @@ -30,8 +30,9 @@ CornerTable::CornerTable() std::unique_ptr<CornerTable> CornerTable::Create( const IndexTypeVector<FaceIndex, FaceType> &faces) { std::unique_ptr<CornerTable> ct(new CornerTable()); - if (!ct->Init(faces)) + if (!ct->Init(faces)) { return nullptr; + } return ct; } @@ -45,12 +46,15 @@ bool CornerTable::Init(const IndexTypeVector<FaceIndex, FaceType> &faces) { } } int num_vertices = -1; - if (!ComputeOppositeCorners(&num_vertices)) + if (!ComputeOppositeCorners(&num_vertices)) { return false; - if (!BreakNonManifoldEdges()) + } + if (!BreakNonManifoldEdges()) { return false; - if (!ComputeVertexCorners(num_vertices)) + } + if (!ComputeVertexCorners(num_vertices)) { return false; + } return true; } @@ -59,11 +63,13 @@ bool CornerTable::Reset(int num_faces) { } bool CornerTable::Reset(int num_faces, int num_vertices) { - if (num_faces < 0 || num_vertices < 0) + if (num_faces < 0 || num_vertices < 0) { return false; + } if (static_cast<unsigned int>(num_faces) > - std::numeric_limits<CornerIndex::ValueType>::max() / 3) + std::numeric_limits<CornerIndex::ValueType>::max() / 3) { return false; + } corner_to_vertex_map_.assign(num_faces * 3, kInvalidVertexIndex); opposite_corners_.assign(num_faces * 3, kInvalidCornerIndex); vertex_corners_.reserve(num_vertices); @@ -74,8 +80,9 @@ bool CornerTable::Reset(int num_faces, int num_vertices) { bool CornerTable::ComputeOppositeCorners(int *num_vertices) { DRACO_DCHECK(GetValenceCache().IsCacheEmpty()); - if (num_vertices == nullptr) + if (num_vertices == nullptr) { return false; + } opposite_corners_.resize(num_corners(), kInvalidCornerIndex); // Out implementation for finding opposite corners is based on keeping track @@ -92,8 +99,9 @@ bool CornerTable::ComputeOppositeCorners(int *num_vertices) { num_corners_on_vertices.reserve(num_corners()); for (CornerIndex c(0); c < num_corners(); ++c) { const VertexIndex v1 = Vertex(c); - if (v1.value() >= static_cast<int>(num_corners_on_vertices.size())) + if (v1.value() >= static_cast<int>(num_corners_on_vertices.size())) { num_corners_on_vertices.resize(v1.value() + 1, 0); + } // For each corner there is always exactly one outgoing half-edge attached // to its vertex. num_corners_on_vertices[v1.value()]++; @@ -150,11 +158,13 @@ bool CornerTable::ComputeOppositeCorners(int *num_vertices) { offset = vertex_offset[sink_v.value()]; for (int i = 0; i < num_corners_on_vert; ++i, ++offset) { const VertexIndex other_v = vertex_edges[offset].sink_vert; - if (other_v == kInvalidVertexIndex) + if (other_v == kInvalidVertexIndex) { break; // No matching half-edge found on the sink vertex. + } if (other_v == source_v) { - if (tip_v == Vertex(vertex_edges[offset].edge_corner)) + if (tip_v == Vertex(vertex_edges[offset].edge_corner)) { continue; // Don't connect mirrored faces. + } // A matching half-edge was found on the sink vertex. Mark the // half-edge's opposite corner. opposite_c = vertex_edges[offset].edge_corner; @@ -165,8 +175,9 @@ bool CornerTable::ComputeOppositeCorners(int *num_vertices) { // slot. for (int j = i + 1; j < num_corners_on_vert; ++j, ++offset) { vertex_edges[offset] = vertex_edges[offset + 1]; - if (vertex_edges[offset].sink_vert == kInvalidVertexIndex) + if (vertex_edges[offset].sink_vert == kInvalidVertexIndex) { break; // Unused half-edge reached. + } } // Mark the last entry as unused. vertex_edges[offset].sink_vert = kInvalidVertexIndex; @@ -217,8 +228,9 @@ bool CornerTable::BreakNonManifoldEdges() { do { mesh_connectivity_updated = false; for (CornerIndex c(0); c < num_corners(); ++c) { - if (visited_corners[c.value()]) + if (visited_corners[c.value()]) { continue; + } sink_vertices.clear(); // First swing all the way to find the left-most corner connected to the @@ -267,10 +279,12 @@ bool CornerTable::BreakNonManifoldEdges() { // that the final surface would be manifold. const CornerIndex opp_other_edge_corner = Opposite(other_edge_corner); - if (opp_edge_corner != kInvalidCornerIndex) + if (opp_edge_corner != kInvalidCornerIndex) { SetOppositeCorner(opp_edge_corner, kInvalidCornerIndex); - if (opp_other_edge_corner != kInvalidCornerIndex) + } + if (opp_other_edge_corner != kInvalidCornerIndex) { SetOppositeCorner(opp_other_edge_corner, kInvalidCornerIndex); + } SetOppositeCorner(edge_corner, kInvalidCornerIndex); SetOppositeCorner(other_edge_corner, kInvalidCornerIndex); @@ -312,13 +326,15 @@ bool CornerTable::ComputeVertexCorners(int num_vertices) { for (FaceIndex f(0); f < num_faces(); ++f) { const CornerIndex first_face_corner = FirstCorner(f); // Check whether the face is degenerated. If so ignore it. - if (IsDegenerated(f)) + if (IsDegenerated(f)) { continue; + } for (int k = 0; k < 3; ++k) { const CornerIndex c = first_face_corner + k; - if (visited_corners[c.value()]) + if (visited_corners[c.value()]) { continue; + } VertexIndex v = corner_to_vertex_map_[c]; // Note that one vertex maps to many corners, but we just keep track // of the vertex which has a boundary on the left if the vertex lies on @@ -350,8 +366,9 @@ bool CornerTable::ComputeVertexCorners(int num_vertices) { corner_to_vertex_map_[act_c] = v; } act_c = SwingLeft(act_c); - if (act_c == c) + if (act_c == c) { break; // Full circle reached. + } } if (act_c == kInvalidCornerIndex) { // If we have reached an open boundary we need to swing right from the @@ -372,27 +389,31 @@ bool CornerTable::ComputeVertexCorners(int num_vertices) { // Count the number of isolated (unprocessed) vertices. num_isolated_vertices_ = 0; for (bool visited : visited_vertices) { - if (!visited) + if (!visited) { ++num_isolated_vertices_; + } } return true; } bool CornerTable::IsDegenerated(FaceIndex face) const { - if (face == kInvalidFaceIndex) + if (face == kInvalidFaceIndex) { return true; + } const CornerIndex first_face_corner = FirstCorner(face); const VertexIndex v0 = Vertex(first_face_corner); const VertexIndex v1 = Vertex(Next(first_face_corner)); const VertexIndex v2 = Vertex(Previous(first_face_corner)); - if (v0 == v1 || v0 == v2 || v1 == v2) + if (v0 == v1 || v0 == v2 || v1 == v2) { return true; + } return false; } int CornerTable::Valence(VertexIndex v) const { - if (v == kInvalidVertexIndex) + if (v == kInvalidVertexIndex) { return -1; + } return ConfidentValence(v); } diff --git a/extern/draco/dracoenc/src/draco/mesh/corner_table.h b/extern/draco/draco/src/draco/mesh/corner_table.h index 704a7b1b5c4..3aa720fdeb9 100644 --- a/extern/draco/dracoenc/src/draco/mesh/corner_table.h +++ b/extern/draco/draco/src/draco/mesh/corner_table.h @@ -80,23 +80,27 @@ class CornerTable { } inline CornerIndex Opposite(CornerIndex corner) const { - if (corner == kInvalidCornerIndex) + if (corner == kInvalidCornerIndex) { return corner; + } return opposite_corners_[corner]; } inline CornerIndex Next(CornerIndex corner) const { - if (corner == kInvalidCornerIndex) + if (corner == kInvalidCornerIndex) { return corner; + } return LocalIndex(++corner) ? corner : corner - 3; } inline CornerIndex Previous(CornerIndex corner) const { - if (corner == kInvalidCornerIndex) + if (corner == kInvalidCornerIndex) { return corner; + } return LocalIndex(corner) ? corner - 1 : corner + 2; } inline VertexIndex Vertex(CornerIndex corner) const { - if (corner == kInvalidCornerIndex) + if (corner == kInvalidCornerIndex) { return kInvalidVertexIndex; + } return ConfidentVertex(corner); } inline VertexIndex ConfidentVertex(CornerIndex corner) const { @@ -105,13 +109,15 @@ class CornerTable { return corner_to_vertex_map_[corner]; } inline FaceIndex Face(CornerIndex corner) const { - if (corner == kInvalidCornerIndex) + if (corner == kInvalidCornerIndex) { return kInvalidFaceIndex; + } return FaceIndex(corner.value() / 3); } inline CornerIndex FirstCorner(FaceIndex face) const { - if (face == kInvalidFaceIndex) + if (face == kInvalidFaceIndex) { return kInvalidCornerIndex; + } return CornerIndex(face.value() * 3); } inline std::array<CornerIndex, 3> AllCorners(FaceIndex face) const { @@ -146,8 +152,9 @@ class CornerTable { // Returns the parent vertex index of a given corner table vertex. VertexIndex VertexParent(VertexIndex vertex) const { - if (vertex.value() < static_cast<uint32_t>(num_original_vertices_)) + if (vertex.value() < static_cast<uint32_t>(num_original_vertices_)) { return vertex; + } return non_manifold_vertex_parents_[vertex - num_original_vertices_]; } @@ -163,8 +170,9 @@ class CornerTable { int ConfidentValence(VertexIndex v) const; // Returns the valence of the vertex at the given corner. inline int Valence(CornerIndex c) const { - if (c == kInvalidCornerIndex) + if (c == kInvalidCornerIndex) { return -1; + } return ConfidentValence(c); } inline int ConfidentValence(CornerIndex c) const { @@ -175,8 +183,9 @@ class CornerTable { // Returns true if the specified vertex is on a boundary. inline bool IsOnBoundary(VertexIndex vert) const { const CornerIndex corner = LeftMostCorner(vert); - if (SwingLeft(corner) == kInvalidCornerIndex) + if (SwingLeft(corner) == kInvalidCornerIndex) { return true; + } return false; } @@ -205,13 +214,15 @@ class CornerTable { // \ / \ / // *-------* inline CornerIndex GetLeftCorner(CornerIndex corner_id) const { - if (corner_id == kInvalidCornerIndex) + if (corner_id == kInvalidCornerIndex) { return kInvalidCornerIndex; + } return Opposite(Previous(corner_id)); } inline CornerIndex GetRightCorner(CornerIndex corner_id) const { - if (corner_id == kInvalidCornerIndex) + if (corner_id == kInvalidCornerIndex) { return kInvalidCornerIndex; + } return Opposite(Next(corner_id)); } @@ -241,10 +252,12 @@ class CornerTable { // Sets opposite corners for both input corners. inline void SetOppositeCorners(CornerIndex corner_0, CornerIndex corner_1) { DRACO_DCHECK(GetValenceCache().IsCacheEmpty()); - if (corner_0 != kInvalidCornerIndex) + if (corner_0 != kInvalidCornerIndex) { SetOppositeCorner(corner_0, corner_1); - if (corner_1 != kInvalidCornerIndex) + } + if (corner_1 != kInvalidCornerIndex) { SetOppositeCorner(corner_1, corner_0); + } } // Updates mapping between a corner and a vertex. @@ -260,11 +273,26 @@ class CornerTable { return VertexIndex(static_cast<uint32_t>(vertex_corners_.size() - 1)); } + // Adds a new face connected to three vertices. Note that connectivity is not + // automatically updated and all opposite corners need to be set explicitly. + FaceIndex AddNewFace(const std::array<VertexIndex, 3> &vertices) { + // Add a new invalid face. + const FaceIndex new_face_index(num_faces()); + for (int i = 0; i < 3; ++i) { + corner_to_vertex_map_.push_back(vertices[i]); + SetLeftMostCorner(vertices[i], + CornerIndex(corner_to_vertex_map_.size() - 1)); + } + opposite_corners_.resize(corner_to_vertex_map_.size(), kInvalidCornerIndex); + return new_face_index; + } + // Sets a new left most corner for a given vertex. void SetLeftMostCorner(VertexIndex vert, CornerIndex corner) { DRACO_DCHECK(GetValenceCache().IsCacheEmpty()); - if (vert != kInvalidVertexIndex) + if (vert != kInvalidVertexIndex) { vertex_corners_[vert] = corner; + } } // Updates the vertex to corner map on a specified vertex. This should be @@ -273,8 +301,9 @@ class CornerTable { void UpdateVertexToCornerMap(VertexIndex vert) { DRACO_DCHECK(GetValenceCache().IsCacheEmpty()); const CornerIndex first_c = vertex_corners_[vert]; - if (first_c == kInvalidCornerIndex) + if (first_c == kInvalidCornerIndex) { return; // Isolated vertex. + } CornerIndex act_c = SwingLeft(first_c); CornerIndex c = first_c; while (act_c != kInvalidCornerIndex && act_c != first_c) { diff --git a/extern/draco/dracoenc/src/draco/mesh/corner_table_iterators.h b/extern/draco/draco/src/draco/mesh/corner_table_iterators.h index 65869dbe109..7122aa1be0f 100644 --- a/extern/draco/dracoenc/src/draco/mesh/corner_table_iterators.h +++ b/extern/draco/draco/src/draco/mesh/corner_table_iterators.h @@ -45,6 +45,13 @@ class VertexRingIterator return corner_table_->Vertex(ring_corner); } + // Returns one of the corners opposite to the edge connecting the currently + // iterated ring vertex with the central vertex. + CornerIndex EdgeCorner() const { + return left_traversal_ ? corner_table_->Next(corner_) + : corner_table_->Previous(corner_); + } + // Returns true when all ring vertices have been visited. bool End() const { return corner_ == kInvalidCornerIndex; } @@ -120,8 +127,9 @@ class FaceAdjacencyIterator corner_(start_corner_) { // We need to start with a corner that has a valid opposite face (if // there is any such corner). - if (corner_table_->Opposite(corner_) == kInvalidCornerIndex) + if (corner_table_->Opposite(corner_) == kInvalidCornerIndex) { FindNextFaceNeighbor(); + } } // Gets the last visited adjacent face. diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh.cc b/extern/draco/draco/src/draco/mesh/mesh.cc index a78a6ec96a8..3be4b1494ec 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh.cc +++ b/extern/draco/draco/src/draco/mesh/mesh.cc @@ -15,12 +15,9 @@ #include "draco/mesh/mesh.h" #include <array> -#include <unordered_map> namespace draco { -using std::unordered_map; - // Shortcut for typed conditionals. template <bool B, class T, class F> using conditional_t = typename std::conditional<B, T, F>::type; diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh.h b/extern/draco/draco/src/draco/mesh/mesh.h index b8ca5353a81..f4506da81c9 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh.h +++ b/extern/draco/draco/src/draco/mesh/mesh.h @@ -93,8 +93,9 @@ class Mesh : public PointCloud { // Returns the point id of for a corner |ci|. inline PointIndex CornerToPointId(int ci) const { - if (ci == kInvalidCornerIndex.value()) + if (ci < 0 || static_cast<uint32_t>(ci) == kInvalidCornerIndex.value()) { return kInvalidPointIndex; + } return this->face(FaceIndex(ci / 3))[ci % 3]; } diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent.cc b/extern/draco/draco/src/draco/mesh/mesh_are_equivalent.cc index deb68940a54..b832379afe4 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent.cc +++ b/extern/draco/draco/src/draco/mesh/mesh_are_equivalent.cc @@ -101,10 +101,12 @@ void MeshAreEquivalent::Init(const Mesh &mesh0, const Mesh &mesh1) { } bool MeshAreEquivalent::operator()(const Mesh &mesh0, const Mesh &mesh1) { - if (mesh0.num_faces() != mesh1.num_faces()) + if (mesh0.num_faces() != mesh1.num_faces()) { return false; - if (mesh0.num_attributes() != mesh1.num_attributes()) + } + if (mesh0.num_attributes() != mesh1.num_attributes()) { return false; + } // The following function inits mesh info, i.e., computes the order of // faces with respect to the lex order. This way one can then compare the @@ -121,20 +123,27 @@ bool MeshAreEquivalent::operator()(const Mesh &mesh0, const Mesh &mesh1) { mesh0.GetNamedAttribute(AttributeType(att_id)); const PointAttribute *const att1 = mesh1.GetNamedAttribute(AttributeType(att_id)); - if (att0 == nullptr && att1 == nullptr) + if (att0 == nullptr && att1 == nullptr) { continue; - if (att0 == nullptr) + } + if (att0 == nullptr) { return false; - if (att1 == nullptr) + } + if (att1 == nullptr) { return false; - if (att0->data_type() != att1->data_type()) + } + if (att0->data_type() != att1->data_type()) { return false; - if (att0->num_components() != att1->num_components()) + } + if (att0->num_components() != att1->num_components()) { return false; - if (att0->normalized() != att1->normalized()) + } + if (att0->normalized() != att1->normalized()) { return false; - if (att0->byte_stride() != att1->byte_stride()) + } + if (att0->byte_stride() != att1->byte_stride()) { return false; + } DRACO_DCHECK(att0->IsValid()); DRACO_DCHECK(att1->IsValid()); @@ -162,8 +171,9 @@ bool MeshAreEquivalent::operator()(const Mesh &mesh0, const Mesh &mesh1) { att0->GetValue(index0, data0.get()); att1->GetValue(index1, data1.get()); // Compare the data as is in memory. - if (memcmp(data0.get(), data1.get(), att0->byte_stride()) != 0) + if (memcmp(data0.get(), data1.get(), att0->byte_stride()) != 0) { return false; + } } } } @@ -172,18 +182,21 @@ bool MeshAreEquivalent::operator()(const Mesh &mesh0, const Mesh &mesh1) { bool MeshAreEquivalent::FaceIndexLess::operator()(FaceIndex f0, FaceIndex f1) const { - if (f0 == f1) + if (f0 == f1) { return false; + } const int c0 = mesh_info.corner_index_of_smallest_vertex[f0]; const int c1 = mesh_info.corner_index_of_smallest_vertex[f1]; for (int i = 0; i < 3; ++i) { const Vector3f vf0 = GetPosition(mesh_info.mesh, f0, (c0 + i) % 3); const Vector3f vf1 = GetPosition(mesh_info.mesh, f1, (c1 + i) % 3); - if (vf0 < vf1) + if (vf0 < vf1) { return true; - if (vf1 < vf0) + } + if (vf1 < vf0) { return false; + } } // In case the two faces are equivalent. return false; diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent.h b/extern/draco/draco/src/draco/mesh/mesh_are_equivalent.h index 71ef4a93c12..71ef4a93c12 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent.h +++ b/extern/draco/draco/src/draco/mesh/mesh_are_equivalent.h diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_attribute_corner_table.cc b/extern/draco/draco/src/draco/mesh/mesh_attribute_corner_table.cc index 768d5f5e28e..28b68d5fd40 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_attribute_corner_table.cc +++ b/extern/draco/draco/src/draco/mesh/mesh_attribute_corner_table.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/mesh/mesh_attribute_corner_table.h" + #include "draco/mesh/corner_table_iterators.h" #include "draco/mesh/mesh_misc_functions.h" @@ -22,8 +23,9 @@ MeshAttributeCornerTable::MeshAttributeCornerTable() : no_interior_seams_(true), corner_table_(nullptr), valence_cache_(*this) {} bool MeshAttributeCornerTable::InitEmpty(const CornerTable *table) { - if (table == nullptr) + if (table == nullptr) { return false; + } valence_cache_.ClearValenceCache(); valence_cache_.ClearValenceCacheInaccurate(); is_edge_on_seam_.assign(table->num_corners(), false); @@ -39,8 +41,9 @@ bool MeshAttributeCornerTable::InitEmpty(const CornerTable *table) { bool MeshAttributeCornerTable::InitFromAttribute(const Mesh *mesh, const CornerTable *table, const PointAttribute *att) { - if (!InitEmpty(table)) + if (!InitEmpty(table)) { return false; + } valence_cache_.ClearValenceCache(); valence_cache_.ClearValenceCacheInaccurate(); @@ -49,8 +52,9 @@ bool MeshAttributeCornerTable::InitFromAttribute(const Mesh *mesh, // special handling. for (CornerIndex c(0); c < corner_table_->num_corners(); ++c) { const FaceIndex f = corner_table_->Face(c); - if (corner_table_->IsDegenerated(f)) + if (corner_table_->IsDegenerated(f)) { continue; // Ignore corners on degenerated faces. + } const CornerIndex opp_corner = corner_table_->Opposite(c); if (opp_corner == kInvalidCornerIndex) { // Boundary. Mark it as seam edge. @@ -63,8 +67,9 @@ bool MeshAttributeCornerTable::InitFromAttribute(const Mesh *mesh, is_vertex_on_seam_[v.value()] = true; continue; } - if (opp_corner < c) + if (opp_corner < c) { continue; // Opposite corner was already processed. + } CornerIndex act_c(c), act_sibling_c(opp_corner); for (int i = 0; i < 2; ++i) { @@ -135,11 +140,14 @@ template <bool init_vertex_to_attribute_entry_map> void MeshAttributeCornerTable::RecomputeVerticesInternal( const Mesh *mesh, const PointAttribute *att) { DRACO_DCHECK(GetValenceCache().IsCacheEmpty()); + vertex_to_attribute_entry_id_map_.clear(); + vertex_to_left_most_corner_map_.clear(); int num_new_vertices = 0; for (VertexIndex v(0); v < corner_table_->num_vertices(); ++v) { const CornerIndex c = corner_table_->LeftMostCorner(v); - if (c == kInvalidCornerIndex) + if (c == kInvalidCornerIndex) { continue; // Isolated vertex? + } AttributeValueIndex first_vert_id(num_new_vertices++); if (init_vertex_to_attribute_entry_map) { const PointIndex point_id = mesh->CornerToPointId(c.value()); @@ -184,8 +192,9 @@ void MeshAttributeCornerTable::RecomputeVerticesInternal( } int MeshAttributeCornerTable::Valence(VertexIndex v) const { - if (v == kInvalidVertexIndex) + if (v == kInvalidVertexIndex) { return -1; + } return ConfidentValence(v); } diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_attribute_corner_table.h b/extern/draco/draco/src/draco/mesh/mesh_attribute_corner_table.h index b9e938f5b7d..7dad25cf1d2 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_attribute_corner_table.h +++ b/extern/draco/draco/src/draco/mesh/mesh_attribute_corner_table.h @@ -47,8 +47,9 @@ class MeshAttributeCornerTable { } inline CornerIndex Opposite(CornerIndex corner) const { - if (corner == kInvalidCornerIndex || IsCornerOppositeToSeamEdge(corner)) + if (corner == kInvalidCornerIndex || IsCornerOppositeToSeamEdge(corner)) { return kInvalidCornerIndex; + } return corner_table_->Opposite(corner); } @@ -88,6 +89,7 @@ class MeshAttributeCornerTable { return static_cast<int>(vertex_to_attribute_entry_id_map_.size()); } int num_faces() const { return static_cast<int>(corner_table_->num_faces()); } + int num_corners() const { return corner_table_->num_corners(); } VertexIndex Vertex(CornerIndex corner) const { DRACO_DCHECK_LT(corner.value(), corner_to_vertex_map_.size()); @@ -105,11 +107,27 @@ class MeshAttributeCornerTable { return vertex_to_left_most_corner_map_[v.value()]; } + inline FaceIndex Face(CornerIndex corner) const { + return corner_table_->Face(corner); + } + + inline CornerIndex FirstCorner(FaceIndex face) const { + return corner_table_->FirstCorner(face); + } + + inline std::array<CornerIndex, 3> AllCorners(FaceIndex face) const { + return corner_table_->AllCorners(face); + } + inline bool IsOnBoundary(VertexIndex vert) const { const CornerIndex corner = LeftMostCorner(vert); - if (corner == kInvalidCornerIndex) + if (corner == kInvalidCornerIndex) { + return true; + } + if (SwingLeft(corner) == kInvalidCornerIndex) { return true; - return IsCornerOnSeam(corner); + } + return false; } bool no_interior_seams() const { return no_interior_seams_; } @@ -126,8 +144,9 @@ class MeshAttributeCornerTable { // Returns the valence of the vertex at the given corner. inline int Valence(CornerIndex c) const { DRACO_DCHECK_LT(c.value(), corner_table_->num_corners()); - if (c == kInvalidCornerIndex) + if (c == kInvalidCornerIndex) { return -1; + } return ConfidentValence(c); } inline int ConfidentValence(CornerIndex c) const { diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_cleanup.cc b/extern/draco/draco/src/draco/mesh/mesh_cleanup.cc index 8e2d393b8f3..773c1e18fe6 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_cleanup.cc +++ b/extern/draco/draco/src/draco/mesh/mesh_cleanup.cc @@ -17,12 +17,14 @@ namespace draco { bool MeshCleanup::operator()(Mesh *mesh, const MeshCleanupOptions &options) { - if (!options.remove_degenerated_faces && !options.remove_unused_attributes) + if (!options.remove_degenerated_faces && !options.remove_unused_attributes) { return true; // Nothing to cleanup. + } const PointAttribute *const pos_att = mesh->GetNamedAttribute(GeometryAttribute::POSITION); - if (pos_att == nullptr) + if (pos_att == nullptr) { return false; + } // Array that is going to store whether a corresponding point is used. std::vector<bool> is_point_used; if (options.remove_unused_attributes) { @@ -161,8 +163,9 @@ bool MeshCleanup::operator()(Mesh *mesh, const MeshCleanupOptions &options) { // The new point id that maps to the currently processed attribute // entry. const PointIndex new_point_id = point_map[i]; - if (new_point_id == kInvalidPointIndex) + if (new_point_id == kInvalidPointIndex) { continue; + } // Index of the currently processed attribute entry in the original // mesh. const AttributeValueIndex original_entry_index = diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_cleanup.h b/extern/draco/draco/src/draco/mesh/mesh_cleanup.h index b56129dce58..b56129dce58 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_cleanup.h +++ b/extern/draco/draco/src/draco/mesh/mesh_cleanup.h diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_misc_functions.cc b/extern/draco/draco/src/draco/mesh/mesh_misc_functions.cc index b55527aa85e..4485b3369ac 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_misc_functions.cc +++ b/extern/draco/draco/src/draco/mesh/mesh_misc_functions.cc @@ -18,18 +18,23 @@ namespace draco { std::unique_ptr<CornerTable> CreateCornerTableFromPositionAttribute( const Mesh *mesh) { + return CreateCornerTableFromAttribute(mesh, GeometryAttribute::POSITION); +} + +std::unique_ptr<CornerTable> CreateCornerTableFromAttribute( + const Mesh *mesh, GeometryAttribute::Type type) { typedef CornerTable::FaceType FaceType; - const PointAttribute *const att = - mesh->GetNamedAttribute(GeometryAttribute::POSITION); - if (att == nullptr) + const PointAttribute *const att = mesh->GetNamedAttribute(type); + if (att == nullptr) { return nullptr; + } IndexTypeVector<FaceIndex, FaceType> faces(mesh->num_faces()); FaceType new_face; for (FaceIndex i(0); i < mesh->num_faces(); ++i) { const Mesh::Face &face = mesh->face(i); for (int j = 0; j < 3; ++j) { - // Map general vertex indices to position indices. + // Map general vertex indices to attribute indices. new_face[j] = att->mapped_index(face[j]).value(); } faces[FaceIndex(i)] = new_face; diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_misc_functions.h b/extern/draco/draco/src/draco/mesh/mesh_misc_functions.h index b972109e679..b450bc80cd8 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_misc_functions.h +++ b/extern/draco/draco/src/draco/mesh/mesh_misc_functions.h @@ -29,6 +29,11 @@ namespace draco { std::unique_ptr<CornerTable> CreateCornerTableFromPositionAttribute( const Mesh *mesh); +// Creates a CornerTable from the first named attribute of |mesh| with a given +// type. Returns nullptr on error. +std::unique_ptr<CornerTable> CreateCornerTableFromAttribute( + const Mesh *mesh, GeometryAttribute::Type type); + // Creates a CornerTable from all attributes of |mesh|. Boundaries are // automatically introduced on all attribute seams. Returns nullptr on error. std::unique_ptr<CornerTable> CreateCornerTableFromAllAttributes( @@ -40,19 +45,22 @@ inline bool IsCornerOppositeToAttributeSeam(CornerIndex ci, const Mesh &mesh, const CornerTable &ct) { const CornerIndex opp_ci = ct.Opposite(ci); - if (opp_ci == kInvalidCornerIndex) + if (opp_ci == kInvalidCornerIndex) { return false; // No opposite corner == no attribute seam. + } // Compare attribute value indices on both ends of the opposite edge. CornerIndex c0 = ct.Next(ci); CornerIndex c1 = ct.Previous(opp_ci); if (att.mapped_index(mesh.CornerToPointId(c0)) != - att.mapped_index(mesh.CornerToPointId(c1))) + att.mapped_index(mesh.CornerToPointId(c1))) { return true; + } c0 = ct.Previous(ci); c1 = ct.Next(opp_ci); if (att.mapped_index(mesh.CornerToPointId(c0)) != - att.mapped_index(mesh.CornerToPointId(c1))) + att.mapped_index(mesh.CornerToPointId(c1))) { return true; + } return false; } @@ -71,8 +79,18 @@ InterpolatedVectorT ComputeInterpolatedAttributeValueOnMeshFace( attribute.GetMappedValue(face[c], &(val[c][0])); } // Return an interpolated value. - return barycentric_coord[0] * val[0] + barycentric_coord[1] * val[1] + - barycentric_coord[2] * val[2]; + InterpolatedVectorT res; + for (int d = 0; d < InterpolatedVectorT::dimension; ++d) { + const float interpolated_component = barycentric_coord[0] * val[0][d] + + barycentric_coord[1] * val[1][d] + + barycentric_coord[2] * val[2][d]; + if (std::is_integral<typename InterpolatedVectorT::Scalar>::value) { + res[d] = std::floor(interpolated_component + 0.5f); + } else { + res[d] = interpolated_component; + } + } + return res; } } // namespace draco diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_stripifier.cc b/extern/draco/draco/src/draco/mesh/mesh_stripifier.cc index 5b63da3023d..f68062eba68 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_stripifier.cc +++ b/extern/draco/draco/src/draco/mesh/mesh_stripifier.cc @@ -41,13 +41,15 @@ void MeshStripifier::GenerateStripsFromCorner(int local_strip_id, // Perform the backward pass only when there is no attribute seam between // the initial face and the first face of the backward traversal. if (GetOppositeCorner(corner_table_->Previous(start_ci)) == - kInvalidCornerIndex) + kInvalidCornerIndex) { break; // Attribute seam or a boundary. + } ci = corner_table_->Next(start_ci); ci = corner_table_->SwingLeft(ci); - if (ci == kInvalidCornerIndex) + if (ci == kInvalidCornerIndex) { break; + } fi = corner_table_->Face(ci); } @@ -74,8 +76,9 @@ void MeshStripifier::GenerateStripsFromCorner(int local_strip_id, } } ci = GetOppositeCorner(ci); - if (ci == kInvalidCornerIndex) + if (ci == kInvalidCornerIndex) { break; + } fi = corner_table_->Face(ci); } // Strip end reached. diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_stripifier.h b/extern/draco/draco/src/draco/mesh/mesh_stripifier.h index f7c1ead4c44..0c298f48e86 100644 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_stripifier.h +++ b/extern/draco/draco/src/draco/mesh/mesh_stripifier.h @@ -74,8 +74,9 @@ class MeshStripifier { // TODO(ostava): We may be able to avoid computing the corner table if we // already have it stored somewhere. corner_table_ = CreateCornerTableFromPositionAttribute(mesh_); - if (corner_table_ == nullptr) + if (corner_table_ == nullptr) { return false; + } // Mark all faces as unvisited. is_face_visited_.assign(mesh.num_faces(), false); @@ -144,16 +145,19 @@ class MeshStripifier { // across an attribute seam. Otherwise return kInvalidCornerIndex. CornerIndex GetOppositeCorner(CornerIndex ci) const { const CornerIndex oci = corner_table_->Opposite(ci); - if (oci < 0) + if (oci < 0) { return kInvalidCornerIndex; + } // Ensure the point ids are same on both sides of the shared edge between // the triangles. if (CornerToPointIndex(corner_table_->Next(ci)) != - CornerToPointIndex(corner_table_->Previous(oci))) + CornerToPointIndex(corner_table_->Previous(oci))) { return kInvalidCornerIndex; + } if (CornerToPointIndex(corner_table_->Previous(ci)) != - CornerToPointIndex(corner_table_->Next(oci))) + CornerToPointIndex(corner_table_->Next(oci))) { return kInvalidCornerIndex; + } return oci; } @@ -179,13 +183,15 @@ template <typename OutputIteratorT, typename IndexTypeT> bool MeshStripifier::GenerateTriangleStripsWithPrimitiveRestart( const Mesh &mesh, IndexTypeT primitive_restart_index, OutputIteratorT out_it) { - if (!Prepare(mesh)) + if (!Prepare(mesh)) { return false; + } // Go over all faces and generate strips from the first unvisited one. for (FaceIndex fi(0); fi < mesh.num_faces(); ++fi) { - if (is_face_visited_[fi]) + if (is_face_visited_[fi]) { continue; + } const int longest_strip_id = FindLongestStripFromFace(fi); @@ -203,13 +209,15 @@ bool MeshStripifier::GenerateTriangleStripsWithPrimitiveRestart( template <typename OutputIteratorT> bool MeshStripifier::GenerateTriangleStripsWithDegenerateTriangles( const Mesh &mesh, OutputIteratorT out_it) { - if (!Prepare(mesh)) + if (!Prepare(mesh)) { return false; + } // Go over all faces and generate strips from the first unvisited one. for (FaceIndex fi(0); fi < mesh.num_faces(); ++fi) { - if (is_face_visited_[fi]) + if (is_face_visited_[fi]) { continue; + } const int longest_strip_id = FindLongestStripFromFace(fi); diff --git a/extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder.cc b/extern/draco/draco/src/draco/mesh/triangle_soup_mesh_builder.cc index 7a76745342b..60b0c50b8d5 100644 --- a/extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder.cc +++ b/extern/draco/draco/src/draco/mesh/triangle_soup_mesh_builder.cc @@ -60,15 +60,17 @@ void TriangleSoupMeshBuilder::SetPerFaceAttributeValueForFace( {{PointIndex(start_index), PointIndex(start_index + 1), PointIndex(start_index + 2)}}); int8_t &element_type = attribute_element_types_[att_id]; - if (element_type < 0) + if (element_type < 0) { element_type = MESH_FACE_ATTRIBUTE; + } } std::unique_ptr<Mesh> TriangleSoupMeshBuilder::Finalize() { #ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED // First deduplicate attribute values. - if (!mesh_->DeduplicateAttributeValues()) + if (!mesh_->DeduplicateAttributeValues()) { return nullptr; + } #endif #ifdef DRACO_ATTRIBUTE_INDICES_DEDUPLICATION_SUPPORTED // Also deduplicate vertex indices. diff --git a/extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder.h b/extern/draco/draco/src/draco/mesh/triangle_soup_mesh_builder.h index 3ae652cfeee..89466e1d849 100644 --- a/extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder.h +++ b/extern/draco/draco/src/draco/mesh/triangle_soup_mesh_builder.h @@ -16,7 +16,6 @@ #define DRACO_MESH_TRIANGLE_SOUP_MESH_BUILDER_H_ #include "draco/draco_features.h" - #include "draco/mesh/mesh.h" namespace draco { diff --git a/extern/draco/dracoenc/src/draco/mesh/valence_cache.h b/extern/draco/draco/src/draco/mesh/valence_cache.h index f75d66f4b99..3540377db81 100644 --- a/extern/draco/dracoenc/src/draco/mesh/valence_cache.h +++ b/extern/draco/draco/src/draco/mesh/valence_cache.h @@ -36,13 +36,15 @@ class ValenceCache { // Do not call before CacheValences() / CacheValencesInaccurate(). inline int8_t ValenceFromCacheInaccurate(CornerIndex c) const { - if (c == kInvalidCornerIndex) + if (c == kInvalidCornerIndex) { return -1; + } return ValenceFromCacheInaccurate(table_.Vertex(c)); } inline int32_t ValenceFromCache(CornerIndex c) const { - if (c == kInvalidCornerIndex) + if (c == kInvalidCornerIndex) { return -1; + } return ValenceFromCache(table_.Vertex(c)); } @@ -65,18 +67,20 @@ class ValenceCache { if (vertex_valence_cache_8_bit_.size() == 0) { const VertexIndex vertex_count = VertexIndex(table_.num_vertices()); vertex_valence_cache_8_bit_.resize(vertex_count.value()); - for (VertexIndex v = VertexIndex(0); v < vertex_count; v += 1) + for (VertexIndex v = VertexIndex(0); v < vertex_count; v += 1) { vertex_valence_cache_8_bit_[v] = static_cast<int8_t>( (std::min)(static_cast<int32_t>(std::numeric_limits<int8_t>::max()), table_.Valence(v))); + } } } void CacheValences() const { if (vertex_valence_cache_32_bit_.size() == 0) { const VertexIndex vertex_count = VertexIndex(table_.num_vertices()); vertex_valence_cache_32_bit_.resize(vertex_count.value()); - for (VertexIndex v = VertexIndex(0); v < vertex_count; v += 1) + for (VertexIndex v = VertexIndex(0); v < vertex_count; v += 1) { vertex_valence_cache_32_bit_[v] = table_.Valence(v); + } } } @@ -90,8 +94,9 @@ class ValenceCache { } inline int8_t ValenceFromCacheInaccurate(VertexIndex v) const { DRACO_DCHECK_EQ(vertex_valence_cache_8_bit_.size(), table_.num_vertices()); - if (v == kInvalidVertexIndex || v.value() >= table_.num_vertices()) + if (v == kInvalidVertexIndex || v.value() >= table_.num_vertices()) { return -1; + } return ConfidentValenceFromCacheInaccurate(v); } inline int8_t ConfidentValenceFromCacheInaccurate(VertexIndex v) const { @@ -103,8 +108,9 @@ class ValenceCache { // TODO(draco-eng) Add unit tests for ValenceCache functions. inline int32_t ValenceFromCache(VertexIndex v) const { DRACO_DCHECK_EQ(vertex_valence_cache_32_bit_.size(), table_.num_vertices()); - if (v == kInvalidVertexIndex || v.value() >= table_.num_vertices()) + if (v == kInvalidVertexIndex || v.value() >= table_.num_vertices()) { return -1; + } return ConfidentValenceFromCache(v); } diff --git a/extern/draco/dracoenc/src/draco/metadata/geometry_metadata.cc b/extern/draco/draco/src/draco/metadata/geometry_metadata.cc index 896663ae8ab..b83898140ae 100644 --- a/extern/draco/dracoenc/src/draco/metadata/geometry_metadata.cc +++ b/extern/draco/draco/src/draco/metadata/geometry_metadata.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/metadata/geometry_metadata.h" + #include <utility> namespace draco { @@ -21,10 +22,12 @@ const AttributeMetadata *GeometryMetadata::GetAttributeMetadataByStringEntry( const std::string &entry_name, const std::string &entry_value) const { for (auto &&att_metadata : att_metadatas_) { std::string value; - if (!att_metadata->GetEntryString(entry_name, &value)) + if (!att_metadata->GetEntryString(entry_name, &value)) { continue; - if (value == entry_value) + } + if (value == entry_value) { return att_metadata.get(); + } } // No attribute has the requested entry. return nullptr; @@ -32,8 +35,9 @@ const AttributeMetadata *GeometryMetadata::GetAttributeMetadataByStringEntry( bool GeometryMetadata::AddAttributeMetadata( std::unique_ptr<AttributeMetadata> att_metadata) { - if (!att_metadata.get()) + if (!att_metadata.get()) { return false; + } att_metadatas_.push_back(std::move(att_metadata)); return true; } diff --git a/extern/draco/dracoenc/src/draco/metadata/geometry_metadata.h b/extern/draco/draco/src/draco/metadata/geometry_metadata.h index 9f668f7fa15..ec7ecb9ee68 100644 --- a/extern/draco/dracoenc/src/draco/metadata/geometry_metadata.h +++ b/extern/draco/draco/src/draco/metadata/geometry_metadata.h @@ -51,11 +51,12 @@ struct AttributeMetadataHasher { return hash; } }; + // Class for representing the metadata for a point cloud. It could have a list // of attribute metadata. class GeometryMetadata : public Metadata { public: - GeometryMetadata(){}; + GeometryMetadata() {} explicit GeometryMetadata(const Metadata &metadata) : Metadata(metadata) {} const AttributeMetadata *GetAttributeMetadataByStringEntry( @@ -63,9 +64,12 @@ class GeometryMetadata : public Metadata { bool AddAttributeMetadata(std::unique_ptr<AttributeMetadata> att_metadata); void DeleteAttributeMetadataByUniqueId(int32_t att_unique_id) { + if (att_unique_id < 0) { + return; + } for (auto itr = att_metadatas_.begin(); itr != att_metadatas_.end(); ++itr) { - if (itr->get()->att_unique_id() == att_unique_id) { + if (itr->get()->att_unique_id() == static_cast<uint32_t>(att_unique_id)) { att_metadatas_.erase(itr); return; } @@ -74,10 +78,15 @@ class GeometryMetadata : public Metadata { const AttributeMetadata *GetAttributeMetadataByUniqueId( int32_t att_unique_id) const { + if (att_unique_id < 0) { + return nullptr; + } + // TODO(draco-eng): Consider using unordered_map instead of vector to store // attribute metadata. for (auto &&att_metadata : att_metadatas_) { - if (att_metadata->att_unique_id() == att_unique_id) { + if (att_metadata->att_unique_id() == + static_cast<uint32_t>(att_unique_id)) { return att_metadata.get(); } } @@ -85,10 +94,15 @@ class GeometryMetadata : public Metadata { } AttributeMetadata *attribute_metadata(int32_t att_unique_id) { + if (att_unique_id < 0) { + return nullptr; + } + // TODO(draco-eng): Consider use unordered_map instead of vector to store // attribute metadata. for (auto &&att_metadata : att_metadatas_) { - if (att_metadata->att_unique_id() == att_unique_id) { + if (att_metadata->att_unique_id() == + static_cast<uint32_t>(att_unique_id)) { return att_metadata.get(); } } diff --git a/extern/draco/dracoenc/src/draco/metadata/metadata.cc b/extern/draco/draco/src/draco/metadata/metadata.cc index ca82d163bf8..9141907ed71 100644 --- a/extern/draco/dracoenc/src/draco/metadata/metadata.cc +++ b/extern/draco/draco/src/draco/metadata/metadata.cc @@ -13,6 +13,7 @@ // limitations under the License. // #include "draco/metadata/metadata.h" + #include <utility> namespace draco { @@ -29,8 +30,9 @@ EntryValue::EntryValue(const std::string &value) { template <> bool EntryValue::GetValue(std::string *value) const { - if (data_.empty()) + if (data_.empty()) { return false; + } value->resize(data_.size()); memcpy(&value->at(0), &data_[0], data_.size()); return true; diff --git a/extern/draco/dracoenc/src/draco/metadata/metadata.h b/extern/draco/draco/src/draco/metadata/metadata.h index bf0be36f3b1..56d05e46a3e 100644 --- a/extern/draco/dracoenc/src/draco/metadata/metadata.h +++ b/extern/draco/draco/src/draco/metadata/metadata.h @@ -16,9 +16,9 @@ #define DRACO_METADATA_METADATA_H_ #include <cstring> +#include <map> #include <memory> #include <string> -#include <map> #include <vector> #include "draco/core/hash_utils.h" @@ -59,8 +59,9 @@ class EntryValue { template <typename DataTypeT> bool GetValue(std::vector<DataTypeT> *value) const { - if (data_.empty()) + if (data_.empty()) { return false; + } const size_t data_type_size = sizeof(DataTypeT); if (data_.size() % data_type_size != 0) { return false; @@ -82,7 +83,7 @@ class EntryValue { struct EntryValueHasher { size_t operator()(const EntryValue &ev) const { size_t hash = ev.data_.size(); - for (int i = 0; i < ev.data_.size(); ++i) { + for (size_t i = 0; i < ev.data_.size(); ++i) { hash = HashCombine(ev.data_[i], hash); } return hash; @@ -150,11 +151,9 @@ class Metadata { void RemoveEntry(const std::string &name); int num_entries() const { return static_cast<int>(entries_.size()); } - const std::map<std::string, EntryValue> &entries() const { - return entries_; - } - const std::map<std::string, std::unique_ptr<Metadata>> - &sub_metadatas() const { + const std::map<std::string, EntryValue> &entries() const { return entries_; } + const std::map<std::string, std::unique_ptr<Metadata>> &sub_metadatas() + const { return sub_metadatas_; } @@ -163,8 +162,9 @@ class Metadata { template <typename DataTypeT> void AddEntry(const std::string &entry_name, const DataTypeT &entry_value) { const auto itr = entries_.find(entry_name); - if (itr != entries_.end()) + if (itr != entries_.end()) { entries_.erase(itr); + } entries_.insert(std::make_pair(entry_name, EntryValue(entry_value))); } diff --git a/extern/draco/dracoenc/src/draco/metadata/metadata_decoder.cc b/extern/draco/draco/src/draco/metadata/metadata_decoder.cc index 62acc26772a..e664e4fa524 100644 --- a/extern/draco/dracoenc/src/draco/metadata/metadata_decoder.cc +++ b/extern/draco/draco/src/draco/metadata/metadata_decoder.cc @@ -24,80 +24,119 @@ MetadataDecoder::MetadataDecoder() : buffer_(nullptr) {} bool MetadataDecoder::DecodeMetadata(DecoderBuffer *in_buffer, Metadata *metadata) { - if (!metadata) + if (!metadata) { return false; + } buffer_ = in_buffer; return DecodeMetadata(metadata); } bool MetadataDecoder::DecodeGeometryMetadata(DecoderBuffer *in_buffer, GeometryMetadata *metadata) { - if (!metadata) + if (!metadata) { return false; + } buffer_ = in_buffer; uint32_t num_att_metadata = 0; - DecodeVarint(&num_att_metadata, buffer_); + if (!DecodeVarint(&num_att_metadata, buffer_)) { + return false; + } // Decode attribute metadata. for (uint32_t i = 0; i < num_att_metadata; ++i) { uint32_t att_unique_id; - DecodeVarint(&att_unique_id, buffer_); + if (!DecodeVarint(&att_unique_id, buffer_)) { + return false; + } std::unique_ptr<AttributeMetadata> att_metadata = std::unique_ptr<AttributeMetadata>(new AttributeMetadata()); att_metadata->set_att_unique_id(att_unique_id); - if (!DecodeMetadata(static_cast<Metadata *>(att_metadata.get()))) + if (!DecodeMetadata(static_cast<Metadata *>(att_metadata.get()))) { return false; + } metadata->AddAttributeMetadata(std::move(att_metadata)); } return DecodeMetadata(static_cast<Metadata *>(metadata)); } bool MetadataDecoder::DecodeMetadata(Metadata *metadata) { - uint32_t num_entries = 0; - DecodeVarint(&num_entries, buffer_); - for (uint32_t i = 0; i < num_entries; ++i) { - if (!DecodeEntry(metadata)) + struct MetadataPair { + Metadata *parent_metadata; + Metadata *decoded_metadata; + }; + std::vector<MetadataPair> metadata_stack; + metadata_stack.push_back({nullptr, metadata}); + while (!metadata_stack.empty()) { + const MetadataPair mp = metadata_stack.back(); + metadata_stack.pop_back(); + metadata = mp.decoded_metadata; + + if (mp.parent_metadata != nullptr) { + std::string sub_metadata_name; + if (!DecodeName(&sub_metadata_name)) { + return false; + } + std::unique_ptr<Metadata> sub_metadata = + std::unique_ptr<Metadata>(new Metadata()); + metadata = sub_metadata.get(); + mp.parent_metadata->AddSubMetadata(sub_metadata_name, + std::move(sub_metadata)); + } + if (metadata == nullptr) { return false; - } - uint32_t num_sub_metadata = 0; - DecodeVarint(&num_sub_metadata, buffer_); - for (uint32_t i = 0; i < num_sub_metadata; ++i) { - std::string sub_metadata_name; - if (!DecodeName(&sub_metadata_name)) + } + + uint32_t num_entries = 0; + if (!DecodeVarint(&num_entries, buffer_)) { return false; - std::unique_ptr<Metadata> sub_metadata = - std::unique_ptr<Metadata>(new Metadata()); - if (!DecodeMetadata(sub_metadata.get())) + } + for (uint32_t i = 0; i < num_entries; ++i) { + if (!DecodeEntry(metadata)) { + return false; + } + } + uint32_t num_sub_metadata = 0; + if (!DecodeVarint(&num_sub_metadata, buffer_)) { return false; - metadata->AddSubMetadata(sub_metadata_name, std::move(sub_metadata)); + } + for (uint32_t i = 0; i < num_sub_metadata; ++i) { + metadata_stack.push_back({metadata, nullptr}); + } } return true; } bool MetadataDecoder::DecodeEntry(Metadata *metadata) { std::string entry_name; - if (!DecodeName(&entry_name)) + if (!DecodeName(&entry_name)) { return false; + } uint32_t data_size = 0; - if (!DecodeVarint(&data_size, buffer_)) + if (!DecodeVarint(&data_size, buffer_)) { return false; - if (data_size == 0) + } + if (data_size == 0) { return false; + } std::vector<uint8_t> entry_value(data_size); - if (!buffer_->Decode(&entry_value[0], data_size)) + if (!buffer_->Decode(&entry_value[0], data_size)) { return false; + } metadata->AddEntryBinary(entry_name, entry_value); return true; } bool MetadataDecoder::DecodeName(std::string *name) { uint8_t name_len = 0; - if (!buffer_->Decode(&name_len)) + if (!buffer_->Decode(&name_len)) { return false; + } name->resize(name_len); - if (name_len == 0) + if (name_len == 0) { return true; - if (!buffer_->Decode(&name->at(0), name_len)) + } + if (!buffer_->Decode(&name->at(0), name_len)) { return false; + } return true; } } // namespace draco diff --git a/extern/draco/dracoenc/src/draco/metadata/metadata_decoder.h b/extern/draco/draco/src/draco/metadata/metadata_decoder.h index b4c4943fbaa..b4c4943fbaa 100644 --- a/extern/draco/dracoenc/src/draco/metadata/metadata_decoder.h +++ b/extern/draco/draco/src/draco/metadata/metadata_decoder.h diff --git a/extern/draco/dracoenc/src/draco/metadata/metadata_encoder.cc b/extern/draco/draco/src/draco/metadata/metadata_encoder.cc index 6e85ce6f9d9..168be83c6b2 100644 --- a/extern/draco/dracoenc/src/draco/metadata/metadata_encoder.cc +++ b/extern/draco/draco/src/draco/metadata/metadata_encoder.cc @@ -25,8 +25,9 @@ bool MetadataEncoder::EncodeMetadata(EncoderBuffer *out_buffer, EncodeVarint(static_cast<uint32_t>(metadata->num_entries()), out_buffer); // Encode all entries. for (const auto &entry : entries) { - if (!EncodeString(out_buffer, entry.first)) + if (!EncodeString(out_buffer, entry.first)) { return false; + } const std::vector<uint8_t> &entry_value = entry.second.data(); const uint32_t data_size = static_cast<uint32_t>(entry_value.size()); EncodeVarint(data_size, out_buffer); @@ -38,8 +39,9 @@ bool MetadataEncoder::EncodeMetadata(EncoderBuffer *out_buffer, EncodeVarint(static_cast<uint32_t>(sub_metadatas.size()), out_buffer); // Encode each sub-metadata for (auto &&sub_metadata_entry : sub_metadatas) { - if (!EncodeString(out_buffer, sub_metadata_entry.first)) + if (!EncodeString(out_buffer, sub_metadata_entry.first)) { return false; + } EncodeMetadata(out_buffer, sub_metadata_entry.second.get()); } @@ -48,8 +50,9 @@ bool MetadataEncoder::EncodeMetadata(EncoderBuffer *out_buffer, bool MetadataEncoder::EncodeAttributeMetadata( EncoderBuffer *out_buffer, const AttributeMetadata *metadata) { - if (!metadata) + if (!metadata) { return false; + } // Encode attribute id. EncodeVarint(metadata->att_unique_id(), out_buffer); EncodeMetadata(out_buffer, static_cast<const Metadata *>(metadata)); @@ -58,8 +61,9 @@ bool MetadataEncoder::EncodeAttributeMetadata( bool MetadataEncoder::EncodeGeometryMetadata(EncoderBuffer *out_buffer, const GeometryMetadata *metadata) { - if (!metadata) + if (!metadata) { return false; + } // Encode number of attribute metadata. const std::vector<std::unique_ptr<AttributeMetadata>> &att_metadatas = metadata->attribute_metadatas(); @@ -79,8 +83,9 @@ bool MetadataEncoder::EncodeString(EncoderBuffer *out_buffer, const std::string &str) { // We only support string of maximum length 255 which is using one byte to // encode the length. - if (str.size() > 255) + if (str.size() > 255) { return false; + } if (str.empty()) { out_buffer->Encode(static_cast<uint8_t>(0)); } else { diff --git a/extern/draco/dracoenc/src/draco/metadata/metadata_encoder.h b/extern/draco/draco/src/draco/metadata/metadata_encoder.h index 5bce5d5b50e..5bce5d5b50e 100644 --- a/extern/draco/dracoenc/src/draco/metadata/metadata_encoder.h +++ b/extern/draco/draco/src/draco/metadata/metadata_encoder.h diff --git a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud.cc b/extern/draco/draco/src/draco/point_cloud/point_cloud.cc index 9552654be16..8eb638f80d4 100644 --- a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud.cc +++ b/extern/draco/draco/src/draco/point_cloud/point_cloud.cc @@ -23,8 +23,9 @@ PointCloud::PointCloud() : num_points_(0) {} int32_t PointCloud::NumNamedAttributes(GeometryAttribute::Type type) const { if (type == GeometryAttribute::INVALID || - type >= GeometryAttribute::NAMED_ATTRIBUTES_COUNT) + type >= GeometryAttribute::NAMED_ATTRIBUTES_COUNT) { return 0; + } return static_cast<int32_t>(named_attribute_index_[type].size()); } @@ -34,8 +35,9 @@ int32_t PointCloud::GetNamedAttributeId(GeometryAttribute::Type type) const { int32_t PointCloud::GetNamedAttributeId(GeometryAttribute::Type type, int i) const { - if (NumNamedAttributes(type) <= i) + if (NumNamedAttributes(type) <= i) { return -1; + } return named_attribute_index_[type][i]; } @@ -47,8 +49,9 @@ const PointAttribute *PointCloud::GetNamedAttribute( const PointAttribute *PointCloud::GetNamedAttribute( GeometryAttribute::Type type, int i) const { const int32_t att_id = GetNamedAttributeId(type, i); - if (att_id == -1) + if (att_id == -1) { return nullptr; + } return attributes_[att_id].get(); } @@ -57,8 +60,9 @@ const PointAttribute *PointCloud::GetNamedAttributeByUniqueId( for (size_t att_id = 0; att_id < named_attribute_index_[type].size(); ++att_id) { if (attributes_[named_attribute_index_[type][att_id]]->unique_id() == - unique_id) + unique_id) { return attributes_[named_attribute_index_[type][att_id]].get(); + } } return nullptr; } @@ -66,15 +70,17 @@ const PointAttribute *PointCloud::GetNamedAttributeByUniqueId( const PointAttribute *PointCloud::GetAttributeByUniqueId( uint32_t unique_id) const { const int32_t att_id = GetAttributeIdByUniqueId(unique_id); - if (att_id == -1) + if (att_id == -1) { return nullptr; + } return attributes_[att_id].get(); } int32_t PointCloud::GetAttributeIdByUniqueId(uint32_t unique_id) const { for (size_t att_id = 0; att_id < attributes_.size(); ++att_id) { - if (attributes_[att_id]->unique_id() == unique_id) + if (attributes_[att_id]->unique_id() == unique_id) { return static_cast<int32_t>(att_id); + } } return -1; } @@ -88,8 +94,9 @@ int PointCloud::AddAttribute( const GeometryAttribute &att, bool identity_mapping, AttributeValueIndex::ValueType num_attribute_values) { auto pa = CreateAttribute(att, identity_mapping, num_attribute_values); - if (!pa) + if (!pa) { return -1; + } const int32_t att_id = AddAttribute(std::move(pa)); return att_id; } @@ -97,8 +104,9 @@ int PointCloud::AddAttribute( std::unique_ptr<PointAttribute> PointCloud::CreateAttribute( const GeometryAttribute &att, bool identity_mapping, AttributeValueIndex::ValueType num_attribute_values) const { - if (att.attribute_type() == GeometryAttribute::INVALID) + if (att.attribute_type() == GeometryAttribute::INVALID) { return nullptr; + } std::unique_ptr<PointAttribute> pa = std::unique_ptr<PointAttribute>(new PointAttribute(att)); // Initialize point cloud specific attribute data. @@ -107,7 +115,7 @@ std::unique_ptr<PointAttribute> PointCloud::CreateAttribute( pa->SetExplicitMapping(num_points_); } else { pa->SetIdentityMapping(); - pa->Resize(num_points_); + num_attribute_values = std::max(num_points_, num_attribute_values); } if (num_attribute_values > 0) { pa->Reset(num_attribute_values); @@ -128,8 +136,9 @@ void PointCloud::SetAttribute(int att_id, std::unique_ptr<PointAttribute> pa) { } void PointCloud::DeleteAttribute(int att_id) { - if (att_id < 0 || att_id >= attributes_.size()) + if (att_id < 0 || att_id >= attributes_.size()) { return; // Attribute does not exist. + } const GeometryAttribute::Type att_type = attributes_[att_id]->attribute_type(); const uint32_t unique_id = attribute(att_id)->unique_id(); @@ -143,8 +152,9 @@ void PointCloud::DeleteAttribute(int att_id) { if (att_type < GeometryAttribute::NAMED_ATTRIBUTES_COUNT) { const auto it = std::find(named_attribute_index_[att_type].begin(), named_attribute_index_[att_type].end(), att_id); - if (it != named_attribute_index_[att_type].end()) + if (it != named_attribute_index_[att_type].end()) { named_attribute_index_[att_type].erase(it); + } } // Update ids of all subsequent named attributes (decrease them by one). @@ -173,8 +183,9 @@ void PointCloud::DeduplicatePointIds() { for (int32_t i = 0; i < this->num_attributes(); ++i) { const AttributeValueIndex att_id0 = attribute(i)->mapped_index(p0); const AttributeValueIndex att_id1 = attribute(i)->mapped_index(p1); - if (att_id0 != att_id1) + if (att_id0 != att_id1) { return false; + } } return true; }; @@ -196,8 +207,9 @@ void PointCloud::DeduplicatePointIds() { unique_points.push_back(i); } } - if (num_unique_points == num_points_) + if (num_unique_points == num_points_) { return; // All vertices are already unique. + } ApplyPointIdDeduplication(index_map, unique_points); set_num_points(num_unique_points); @@ -228,12 +240,14 @@ void PointCloud::ApplyPointIdDeduplication( #ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED bool PointCloud::DeduplicateAttributeValues() { // Go over all attributes and create mapping between duplicate entries. - if (num_points() == 0) + if (num_points() == 0) { return false; // Unexpected attribute size. + } // Deduplicate all attributes. for (int32_t att_id = 0; att_id < num_attributes(); ++att_id) { - if (!attribute(att_id)->DeduplicateValues(*attribute(att_id))) + if (!attribute(att_id)->DeduplicateValues(*attribute(att_id))) { return false; + } } return true; } @@ -257,7 +271,8 @@ BoundingBox PointCloud::ComputeBoundingBox() const { // Consider using pc_att->ConvertValue<float, 3>(i, &p[0]) (Enforced // transformation from Vector with any dimension to Vector3f) Vector3f p; - for (AttributeValueIndex i(0); i < pc_att->size(); ++i) { + for (AttributeValueIndex i(0); i < static_cast<uint32_t>(pc_att->size()); + ++i) { pc_att->GetValue(i, &p[0]); bounding_box.update_bounding_box(p); } diff --git a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud.h b/extern/draco/draco/src/draco/point_cloud/point_cloud.h index e15206f17c4..d11bd47a366 100644 --- a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud.h +++ b/extern/draco/draco/src/draco/point_cloud/point_cloud.h @@ -15,11 +15,10 @@ #ifndef DRACO_POINT_CLOUD_POINT_CLOUD_H_ #define DRACO_POINT_CLOUD_POINT_CLOUD_H_ -#include "draco/draco_features.h" - #include "draco/attributes/point_attribute.h" #include "draco/core/bounding_box.h" #include "draco/core/vector_d.h" +#include "draco/draco_features.h" #include "draco/metadata/geometry_metadata.h" namespace draco { @@ -131,7 +130,7 @@ class PointCloud { // Add metadata for an attribute. void AddAttributeMetadata(int32_t att_id, std::unique_ptr<AttributeMetadata> metadata) { - if (!metadata_.get()) { + if (!metadata_) { metadata_ = std::unique_ptr<GeometryMetadata>(new GeometryMetadata()); } const int32_t att_unique_id = attribute(att_id)->unique_id(); @@ -141,8 +140,9 @@ class PointCloud { const AttributeMetadata *GetAttributeMetadataByAttributeId( int32_t att_id) const { - if (metadata_ == nullptr) + if (metadata_ == nullptr) { return nullptr; + } const uint32_t unique_id = attribute(att_id)->unique_id(); return metadata_->GetAttributeMetadataByUniqueId(unique_id); } @@ -150,20 +150,23 @@ class PointCloud { // Returns the attribute metadata that has the requested metadata entry. const AttributeMetadata *GetAttributeMetadataByStringEntry( const std::string &name, const std::string &value) const { - if (metadata_ == nullptr) + if (metadata_ == nullptr) { return nullptr; + } return metadata_->GetAttributeMetadataByStringEntry(name, value); } // Returns the first attribute that has the requested metadata entry. int GetAttributeIdByMetadataEntry(const std::string &name, const std::string &value) const { - if (metadata_ == nullptr) + if (metadata_ == nullptr) { return -1; + } const AttributeMetadata *att_metadata = metadata_->GetAttributeMetadataByStringEntry(name, value); - if (!att_metadata) + if (!att_metadata) { return -1; + } return GetAttributeIdByUniqueId(att_metadata->att_unique_id()); } @@ -229,8 +232,8 @@ struct PointCloudHasher { } // Hash metadata. GeometryMetadataHasher metadata_hasher; - if (pc.metadata_.get()) { - hash = HashCombine(metadata_hasher(*pc.metadata_.get()), hash); + if (pc.metadata_) { + hash = HashCombine(metadata_hasher(*pc.metadata_), hash); } return hash; } diff --git a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder.cc b/extern/draco/draco/src/draco/point_cloud/point_cloud_builder.cc index a0381631cfd..431ae505f5f 100644 --- a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder.cc +++ b/extern/draco/draco/src/draco/point_cloud/point_cloud_builder.cc @@ -43,8 +43,9 @@ void PointCloudBuilder::SetAttributeValuesForAllPoints( PointAttribute *const att = point_cloud_->attribute(att_id); const int data_stride = DataTypeLength(att->data_type()) * att->num_components(); - if (stride == 0) + if (stride == 0) { stride = data_stride; + } if (stride == data_stride) { // Fast copy path. att->buffer()->Write(0, attribute_values, diff --git a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder.h b/extern/draco/draco/src/draco/point_cloud/point_cloud_builder.h index cf55a728b15..cf55a728b15 100644 --- a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder.h +++ b/extern/draco/draco/src/draco/point_cloud/point_cloud_builder.h diff --git a/extern/draco/dracoenc/cmake/DracoConfig.cmake b/extern/draco/dracoenc/cmake/DracoConfig.cmake deleted file mode 100644 index be5e1faefe2..00000000000 --- a/extern/draco/dracoenc/cmake/DracoConfig.cmake +++ /dev/null @@ -1,3 +0,0 @@ -@PACKAGE_INIT@ -set_and_check(draco_INCLUDE_DIR "@PACKAGE_draco_include_install_dir@") -set_and_check(draco_LIBRARY_DIR "@PACKAGE_draco_lib_install_dir@") diff --git a/extern/draco/dracoenc/cmake/FindDraco.cmake b/extern/draco/dracoenc/cmake/FindDraco.cmake deleted file mode 100644 index 5f27bf29390..00000000000 --- a/extern/draco/dracoenc/cmake/FindDraco.cmake +++ /dev/null @@ -1,58 +0,0 @@ -# Finddraco -# -# Locates draco and sets the following variables: -# -# draco_FOUND -# draco_INCLUDE_DIRS -# draco_LIBARY_DIRS -# draco_LIBRARIES -# draco_VERSION_STRING -# -# draco_FOUND is set to YES only when all other variables are successfully -# configured. - -unset(draco_FOUND) -unset(draco_INCLUDE_DIRS) -unset(draco_LIBRARY_DIRS) -unset(draco_LIBRARIES) -unset(draco_VERSION_STRING) - -mark_as_advanced(draco_FOUND) -mark_as_advanced(draco_INCLUDE_DIRS) -mark_as_advanced(draco_LIBRARY_DIRS) -mark_as_advanced(draco_LIBRARIES) -mark_as_advanced(draco_VERSION_STRING) - -set(draco_version_file_no_prefix "draco/src/draco/core/draco_version.h") - -# Set draco_INCLUDE_DIRS -find_path(draco_INCLUDE_DIRS NAMES "${draco_version_file_no_prefix}") - -# Extract the version string from draco_version.h. -if (draco_INCLUDE_DIRS) - set(draco_version_file - "${draco_INCLUDE_DIRS}/draco/src/draco/core/draco_version.h") - file(STRINGS "${draco_version_file}" draco_version - REGEX "kdracoVersion") - list(GET draco_version 0 draco_version) - string(REPLACE "static const char kdracoVersion[] = " "" draco_version - "${draco_version}") - string(REPLACE ";" "" draco_version "${draco_version}") - string(REPLACE "\"" "" draco_version "${draco_version}") - set(draco_VERSION_STRING ${draco_version}) -endif () - -# Find the library. -if (BUILD_SHARED_LIBS) - find_library(draco_LIBRARIES NAMES draco.dll libdraco.dylib libdraco.so) -else () - find_library(draco_LIBRARIES NAMES draco.lib libdraco.a) -endif () - -# Store path to library. -get_filename_component(draco_LIBRARY_DIRS ${draco_LIBRARIES} DIRECTORY) - -if (draco_INCLUDE_DIRS AND draco_LIBRARY_DIRS AND draco_LIBRARIES AND - draco_VERSION_STRING) - set(draco_FOUND YES) -endif () diff --git a/extern/draco/dracoenc/cmake/compiler_flags.cmake b/extern/draco/dracoenc/cmake/compiler_flags.cmake deleted file mode 100644 index bbfb069d2d3..00000000000 --- a/extern/draco/dracoenc/cmake/compiler_flags.cmake +++ /dev/null @@ -1,216 +0,0 @@ -if (NOT DRACO_CMAKE_COMPILER_FLAGS_CMAKE_) -set(DRACO_CMAKE_COMPILER_FLAGS_CMAKE_ 1) - -include(CheckCCompilerFlag) -include(CheckCXXCompilerFlag) -include("${draco_root}/cmake/compiler_tests.cmake") - -# Strings used to cache failed C/CXX flags. -set(DRACO_FAILED_C_FLAGS) -set(DRACO_FAILED_CXX_FLAGS) - -# Checks C compiler for support of $c_flag. Adds $c_flag to $CMAKE_C_FLAGS when -# the compile test passes. Caches $c_flag in $DRACO_FAILED_C_FLAGS when the test -# fails. -macro (add_c_flag_if_supported c_flag) - unset(C_FLAG_FOUND CACHE) - string(FIND "${CMAKE_C_FLAGS}" "${c_flag}" C_FLAG_FOUND) - unset(C_FLAG_FAILED CACHE) - string(FIND "${DRACO_FAILED_C_FLAGS}" "${c_flag}" C_FLAG_FAILED) - - if (${C_FLAG_FOUND} EQUAL -1 AND ${C_FLAG_FAILED} EQUAL -1) - unset(C_FLAG_SUPPORTED CACHE) - message("Checking C compiler flag support for: " ${c_flag}) - check_c_compiler_flag("${c_flag}" C_FLAG_SUPPORTED) - if (${C_FLAG_SUPPORTED}) - string(APPEND CMAKE_C_FLAGS " ${c_flag}" CACHE STRING "") - else () - string(APPEND DRACO_FAILED_C_FLAGS " ${c_flag}" CACHE STRING - "" FORCE) - endif () - endif () -endmacro () - -# Checks C++ compiler for support of $cxx_flag. Adds $cxx_flag to -# $CMAKE_CXX_FLAGS when the compile test passes. Caches $c_flag in -# $DRACO_FAILED_CXX_FLAGS when the test fails. -macro (add_cxx_flag_if_supported cxx_flag) - unset(CXX_FLAG_FOUND CACHE) - string(FIND "${CMAKE_CXX_FLAGS}" "${cxx_flag}" CXX_FLAG_FOUND) - unset(CXX_FLAG_FAILED CACHE) - string(FIND "${DRACO_FAILED_CXX_FLAGS}" "${cxx_flag}" CXX_FLAG_FAILED) - - if (${CXX_FLAG_FOUND} EQUAL -1 AND ${CXX_FLAG_FAILED} EQUAL -1) - unset(CXX_FLAG_SUPPORTED CACHE) - message("Checking CXX compiler flag support for: " ${cxx_flag}) - check_cxx_compiler_flag("${cxx_flag}" CXX_FLAG_SUPPORTED) - if (${CXX_FLAG_SUPPORTED}) - string(APPEND CMAKE_CXX_FLAGS " ${cxx_flag}" CACHE STRING "") - else() - string(APPEND DRACO_FAILED_CXX_FLAGS " ${cxx_flag}" CACHE - STRING "" FORCE) - endif () - endif () -endmacro () - -# Convenience method for adding a flag to both the C and C++ compiler command -# lines. -macro (add_compiler_flag_if_supported flag) - add_c_flag_if_supported(${flag}) - add_cxx_flag_if_supported(${flag}) -endmacro () - -# Checks C compiler for support of $c_flag and terminates generation when -# support is not present. -macro (require_c_flag c_flag update_c_flags) - unset(C_FLAG_FOUND CACHE) - string(FIND "${CMAKE_C_FLAGS}" "${c_flag}" C_FLAG_FOUND) - - if (${C_FLAG_FOUND} EQUAL -1) - unset(HAVE_C_FLAG CACHE) - message("Checking C compiler flag support for: " ${c_flag}) - check_c_compiler_flag("${c_flag}" HAVE_C_FLAG) - if (NOT ${HAVE_C_FLAG}) - message(FATAL_ERROR - "${PROJECT_NAME} requires support for C flag: ${c_flag}.") - endif () - if (${update_c_flags}) - set(CMAKE_C_FLAGS "${c_flag} ${CMAKE_C_FLAGS}" CACHE STRING "" FORCE) - endif () - endif () -endmacro () - -# Checks CXX compiler for support of $cxx_flag and terminates generation when -# support is not present. -macro (require_cxx_flag cxx_flag update_cxx_flags) - unset(CXX_FLAG_FOUND CACHE) - string(FIND "${CMAKE_CXX_FLAGS}" "${cxx_flag}" CXX_FLAG_FOUND) - - if (${CXX_FLAG_FOUND} EQUAL -1) - unset(HAVE_CXX_FLAG CACHE) - message("Checking CXX compiler flag support for: " ${cxx_flag}) - check_cxx_compiler_flag("${cxx_flag}" HAVE_CXX_FLAG) - if (NOT ${HAVE_CXX_FLAG}) - message(FATAL_ERROR - "${PROJECT_NAME} requires support for CXX flag: ${cxx_flag}.") - endif () - if (${update_cxx_flags}) - set(CMAKE_CXX_FLAGS "${cxx_flag} ${CMAKE_CXX_FLAGS}" CACHE STRING "" - FORCE) - endif () - endif () -endmacro () - -# Checks for support of $flag by both the C and CXX compilers. Terminates -# generation when support is not present in both compilers. -macro (require_compiler_flag flag update_cmake_flags) - require_c_flag(${flag} ${update_cmake_flags}) - require_cxx_flag(${flag} ${update_cmake_flags}) -endmacro () - -# Checks only non-MSVC targets for support of $c_flag and terminates generation -# when support is not present. -macro (require_c_flag_nomsvc c_flag update_c_flags) - if (NOT MSVC) - require_c_flag(${c_flag} ${update_c_flags}) - endif () -endmacro () - -# Checks only non-MSVC targets for support of $cxx_flag and terminates -# generation when support is not present. -macro (require_cxx_flag_nomsvc cxx_flag update_cxx_flags) - if (NOT MSVC) - require_cxx_flag(${cxx_flag} ${update_cxx_flags}) - endif () -endmacro () - -# Checks only non-MSVC targets for support of $flag by both the C and CXX -# compilers. Terminates generation when support is not present in both -# compilers. -macro (require_compiler_flag_nomsvc flag update_cmake_flags) - require_c_flag_nomsvc(${flag} ${update_cmake_flags}) - require_cxx_flag_nomsvc(${flag} ${update_cmake_flags}) -endmacro () - -# Adds $flag to assembler command line. -macro (append_as_flag flag) - unset(AS_FLAG_FOUND CACHE) - string(FIND "${DRACO_AS_FLAGS}" "${flag}" AS_FLAG_FOUND) - - if (${AS_FLAG_FOUND} EQUAL -1) - string(APPEND DRACO_AS_FLAGS " ${flag}") - endif () -endmacro () - -# Adds $flag to the C compiler command line. -macro (append_c_flag flag) - unset(C_FLAG_FOUND CACHE) - string(FIND "${CMAKE_C_FLAGS}" "${flag}" C_FLAG_FOUND) - - if (${C_FLAG_FOUND} EQUAL -1) - string(APPEND CMAKE_C_FLAGS " ${flag}") - endif () -endmacro () - -# Adds $flag to the CXX compiler command line. -macro (append_cxx_flag flag) - unset(CXX_FLAG_FOUND CACHE) - string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" CXX_FLAG_FOUND) - - if (${CXX_FLAG_FOUND} EQUAL -1) - string(APPEND CMAKE_CXX_FLAGS " ${flag}") - endif () -endmacro () - -# Adds $flag to the C and CXX compiler command lines. -macro (append_compiler_flag flag) - append_c_flag(${flag}) - append_cxx_flag(${flag}) -endmacro () - -# Adds $flag to the executable linker command line. -macro (append_exe_linker_flag flag) - unset(LINKER_FLAG_FOUND CACHE) - string(FIND "${CMAKE_EXE_LINKER_FLAGS}" "${flag}" LINKER_FLAG_FOUND) - - if (${LINKER_FLAG_FOUND} EQUAL -1) - string(APPEND CMAKE_EXE_LINKER_FLAGS " ${flag}") - endif () -endmacro () - -# Adds $flag to the link flags for $target. -function (append_link_flag_to_target target flags) - unset(target_link_flags) - get_target_property(target_link_flags ${target} LINK_FLAGS) - - if (target_link_flags) - unset(link_flag_found) - string(FIND "${target_link_flags}" "${flags}" link_flag_found) - - if (NOT ${link_flag_found} EQUAL -1) - return() - endif () - - string(APPEND target_link_flags " ${flags}") - else () - set(target_link_flags "${flags}") - endif () - - set_target_properties(${target} PROPERTIES LINK_FLAGS ${target_link_flags}) -endfunction () - -# Adds $flag to executable linker flags, and makes sure C/CXX builds still work. -macro (require_linker_flag flag) - append_exe_linker_flag(${flag}) - - unset(c_passed) - draco_check_c_compiles("LINKER_FLAG_C_TEST(${flag})" "" c_passed) - unset(cxx_passed) - draco_check_cxx_compiles("LINKER_FLAG_CXX_TEST(${flag})" "" cxx_passed) - - if (NOT c_passed OR NOT cxx_passed) - message(FATAL_ERROR "Linker flag test for ${flag} failed.") - endif () -endmacro () - -endif () # DRACO_CMAKE_COMPILER_FLAGS_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/compiler_tests.cmake b/extern/draco/dracoenc/cmake/compiler_tests.cmake deleted file mode 100644 index 7cc3fbfc67d..00000000000 --- a/extern/draco/dracoenc/cmake/compiler_tests.cmake +++ /dev/null @@ -1,124 +0,0 @@ -if (NOT DRACO_CMAKE_COMPILER_TESTS_CMAKE_) -set(DRACO_CMAKE_COMPILER_TESTS_CMAKE_ 1) - -include(CheckCSourceCompiles) -include(CheckCXXSourceCompiles) - -# The basic main() macro used in all compile tests. -set(DRACO_C_MAIN "\nint main(void) { return 0; }") -set(DRACO_CXX_MAIN "\nint main() { return 0; }") - -# Strings containing the names of passed and failed tests. -set(DRACO_C_PASSED_TESTS) -set(DRACO_C_FAILED_TESTS) -set(DRACO_CXX_PASSED_TESTS) -set(DRACO_CXX_FAILED_TESTS) - -macro(draco_push_var var new_value) - set(SAVED_${var} ${var}) - set(${var} ${new_value}) -endmacro () - -macro(draco_pop_var var) - set(var ${SAVED_${var}}) - unset(SAVED_${var}) -endmacro () - -# Confirms $test_source compiles and stores $test_name in one of -# $DRACO_C_PASSED_TESTS or $DRACO_C_FAILED_TESTS depending on out come. When the -# test passes $result_var is set to 1. When it fails $result_var is unset. -# The test is not run if the test name is found in either of the passed or -# failed test variables. -macro(draco_check_c_compiles test_name test_source result_var) - unset(C_TEST_PASSED CACHE) - unset(C_TEST_FAILED CACHE) - string(FIND "${DRACO_C_PASSED_TESTS}" "${test_name}" C_TEST_PASSED) - string(FIND "${DRACO_C_FAILED_TESTS}" "${test_name}" C_TEST_FAILED) - if (${C_TEST_PASSED} EQUAL -1 AND ${C_TEST_FAILED} EQUAL -1) - unset(C_TEST_COMPILED CACHE) - message("Running C compiler test: ${test_name}") - check_c_source_compiles("${test_source} ${DRACO_C_MAIN}" C_TEST_COMPILED) - set(${result_var} ${C_TEST_COMPILED}) - - if (${C_TEST_COMPILED}) - string(APPEND DRACO_C_PASSED_TESTS " ${test_name}") - else () - string(APPEND DRACO_C_FAILED_TESTS " ${test_name}") - message("C Compiler test ${test_name} failed.") - endif () - elseif (NOT ${C_TEST_PASSED} EQUAL -1) - set(${result_var} 1) - else () # ${C_TEST_FAILED} NOT EQUAL -1 - unset(${result_var}) - endif () -endmacro () - -# Confirms $test_source compiles and stores $test_name in one of -# $DRACO_CXX_PASSED_TESTS or $DRACO_CXX_FAILED_TESTS depending on out come. When -# the test passes $result_var is set to 1. When it fails $result_var is unset. -# The test is not run if the test name is found in either of the passed or -# failed test variables. -macro(draco_check_cxx_compiles test_name test_source result_var) - unset(CXX_TEST_PASSED CACHE) - unset(CXX_TEST_FAILED CACHE) - string(FIND "${DRACO_CXX_PASSED_TESTS}" "${test_name}" CXX_TEST_PASSED) - string(FIND "${DRACO_CXX_FAILED_TESTS}" "${test_name}" CXX_TEST_FAILED) - if (${CXX_TEST_PASSED} EQUAL -1 AND ${CXX_TEST_FAILED} EQUAL -1) - unset(CXX_TEST_COMPILED CACHE) - message("Running CXX compiler test: ${test_name}") - check_cxx_source_compiles("${test_source} ${DRACO_CXX_MAIN}" - CXX_TEST_COMPILED) - set(${result_var} ${CXX_TEST_COMPILED}) - - if (${CXX_TEST_COMPILED}) - string(APPEND DRACO_CXX_PASSED_TESTS " ${test_name}") - else () - string(APPEND DRACO_CXX_FAILED_TESTS " ${test_name}") - message("CXX Compiler test ${test_name} failed.") - endif () - elseif (NOT ${CXX_TEST_PASSED} EQUAL -1) - set(${result_var} 1) - else () # ${CXX_TEST_FAILED} NOT EQUAL -1 - unset(${result_var}) - endif () -endmacro () - -# Convenience macro that confirms $test_source compiles as C and C++. -# $result_var is set to 1 when both tests are successful, and 0 when one or both -# tests fail. -# Note: This macro is intended to be used to write to result variables that -# are expanded via configure_file(). $result_var is set to 1 or 0 to allow -# direct usage of the value in generated source files. -macro(draco_check_source_compiles test_name test_source result_var) - unset(C_PASSED) - unset(CXX_PASSED) - draco_check_c_compiles(${test_name} ${test_source} C_PASSED) - draco_check_cxx_compiles(${test_name} ${test_source} CXX_PASSED) - if (${C_PASSED} AND ${CXX_PASSED}) - set(${result_var} 1) - else () - set(${result_var} 0) - endif () -endmacro () - -# When inline support is detected for the current compiler the supported -# inlining keyword is written to $result in caller scope. -macro (draco_get_inline result) - draco_check_source_compiles("inline_check_1" - "static inline void macro(void) {}" - HAVE_INLINE_1) - if (HAVE_INLINE_1 EQUAL 1) - set(${result} "inline") - return() - endif () - - # Check __inline. - draco_check_source_compiles("inline_check_2" - "static __inline void macro(void) {}" - HAVE_INLINE_2) - if (HAVE_INLINE_2 EQUAL 1) - set(${result} "__inline") - endif () -endmacro () - -endif () # DRACO_CMAKE_COMPILER_TESTS_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/draco_features.cmake b/extern/draco/dracoenc/cmake/draco_features.cmake deleted file mode 100644 index 057b0b07ecd..00000000000 --- a/extern/draco/dracoenc/cmake/draco_features.cmake +++ /dev/null @@ -1,57 +0,0 @@ -if (NOT DRACO_CMAKE_DRACO_FEATURES_CMAKE_) -set(DRACO_CMAKE_DRACO_FEATURES_CMAKE_ 1) - -set(draco_features_file_name "${draco_build_dir}/draco/draco_features.h") -set(draco_features_list) - -# Macro that handles tracking of Draco preprocessor symbols for the purpose of -# producing draco_features.h. -# -# draco_enable_feature(FEATURE <feature_name> [TARGETS <target_name>]) -# FEATURE is required. It should be a Draco preprocessor symbol. -# TARGETS is optional. It can be one or more draco targets. -# -# When the TARGETS argument is not present the preproc symbol is added to -# draco_features.h. When it is draco_features.h is unchanged, and -# target_compile_options() is called for each target specified. -macro (draco_enable_feature) - set(def_flags) - set(def_single_arg_opts FEATURE) - set(def_multi_arg_opts TARGETS) - cmake_parse_arguments(DEF "${def_flags}" "${def_single_arg_opts}" - "${def_multi_arg_opts}" ${ARGN}) - if ("${DEF_FEATURE}" STREQUAL "") - message(FATAL_ERROR "Empty FEATURE passed to draco_enable_feature().") - endif () - - # Do nothing/return early if $DEF_FEATURE is already in the list. - list(FIND draco_features_list ${DEF_FEATURE} df_index) - if (NOT df_index EQUAL -1) - return () - endif () - - list(LENGTH DEF_TARGETS df_targets_list_length) - if (${df_targets_list_length} EQUAL 0) - list(APPEND draco_features_list ${DEF_FEATURE}) - else () - foreach (target ${DEF_TARGETS}) - target_compile_definitions(${target} PRIVATE ${DEF_FEATURE}) - endforeach () - endif () -endmacro () - -# Function for generating draco_features.h. -function (draco_generate_features_h) - file(WRITE "${draco_features_file_name}" - "// GENERATED FILE -- DO NOT EDIT\n\n" - "#ifndef DRACO_FEATURES_H_\n" - "#define DRACO_FEATURES_H_\n\n") - - foreach (feature ${draco_features_list}) - file(APPEND "${draco_features_file_name}" "#define ${feature}\n") - endforeach () - - file(APPEND "${draco_features_file_name}" "\n#endif // DRACO_FEATURES_H_") -endfunction () - -endif () # DRACO_CMAKE_DRACO_FEATURES_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/draco_test_config.h.cmake b/extern/draco/dracoenc/cmake/draco_test_config.h.cmake deleted file mode 100644 index 77a574123fd..00000000000 --- a/extern/draco/dracoenc/cmake/draco_test_config.h.cmake +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DRACO_TESTING_DRACO_TEST_CONFIG_H_ -#define DRACO_TESTING_DRACO_TEST_CONFIG_H_ - -// If this file is named draco_test_config.h.cmake: -// This file is used as input at cmake generation time. - -// If this file is named draco_test_config.h: -// GENERATED FILE, DO NOT EDIT. SEE ABOVE. - -#define DRACO_TEST_DATA_DIR "${DRACO_TEST_DATA_DIR}" -#define DRACO_TEST_TEMP_DIR "${DRACO_TEST_TEMP_DIR}" - -#endif // DRACO_TESTING_DRACO_TEST_CONFIG_H_ diff --git a/extern/draco/dracoenc/cmake/draco_version.cc.cmake b/extern/draco/dracoenc/cmake/draco_version.cc.cmake deleted file mode 100644 index 921df7de77d..00000000000 --- a/extern/draco/dracoenc/cmake/draco_version.cc.cmake +++ /dev/null @@ -1,21 +0,0 @@ -// If this file is named draco_version.cc.cmake: -// This file is used as input at cmake generation time. - -// If this file is named draco_version.cc: -// GENERATED FILE, DO NOT EDIT. SEE ABOVE. -#include "draco_version.h" - -static const char kDracoGitHash[] = "${draco_git_hash}"; -static const char kDracoGitDesc[] = "${draco_git_desc}"; - -const char *draco_git_hash() { - return kDracoGitHash; -} - -const char *draco_git_version() { - return kDracoGitDesc; -} - -const char* draco_version() { - return draco::Version(); -} diff --git a/extern/draco/dracoenc/cmake/draco_version.h.cmake b/extern/draco/dracoenc/cmake/draco_version.h.cmake deleted file mode 100644 index 506423ed34c..00000000000 --- a/extern/draco/dracoenc/cmake/draco_version.h.cmake +++ /dev/null @@ -1,21 +0,0 @@ -// If this file is named draco_version.h.cmake: -// This file is used as input at cmake generation time. - -// If this file is named draco_version.h: -// GENERATED FILE, DO NOT EDIT. SEE ABOVE. -#ifndef DRACO_DRACO_VERSION_H_ -#define DRACO_DRACO_VERSION_H_ - -#include "draco/core/draco_version.h" - -// Returns git hash of Draco git repository. -const char *draco_git_hash(); - -// Returns the output of the git describe command when run from the Draco git -// repository. -const char *draco_git_version(); - -// Returns the version string from core/draco_version.h. -const char* draco_version(); - -#endif // DRACO_DRACO_VERSION_H_ diff --git a/extern/draco/dracoenc/cmake/msvc_runtime.cmake b/extern/draco/dracoenc/cmake/msvc_runtime.cmake deleted file mode 100644 index ca8de08f9a2..00000000000 --- a/extern/draco/dracoenc/cmake/msvc_runtime.cmake +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.2) - -if (MSVC) - # Use statically linked versions of the MS standard libraries. - if (NOT "${MSVC_RUNTIME}" STREQUAL "dll") - foreach (flag_var - CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if (${flag_var} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - endif () - endforeach () - endif () -endif () diff --git a/extern/draco/dracoenc/cmake/sanitizers.cmake b/extern/draco/dracoenc/cmake/sanitizers.cmake deleted file mode 100644 index e966cd85d52..00000000000 --- a/extern/draco/dracoenc/cmake/sanitizers.cmake +++ /dev/null @@ -1,19 +0,0 @@ -if (NOT DRACO_CMAKE_SANITIZERS_CMAKE_) -set(DRACO_CMAKE_SANITIZERS_CMAKE_ 1) - -if (MSVC OR NOT SANITIZE) - return () -endif () - -include("${draco_root}/cmake/compiler_flags.cmake") - -string(TOLOWER ${SANITIZE} SANITIZE) - -# Require the sanitizer requested. -require_linker_flag("-fsanitize=${SANITIZE}") -require_compiler_flag("-fsanitize=${SANITIZE}" YES) - -# Make callstacks accurate. -require_compiler_flag("-fno-omit-frame-pointer -fno-optimize-sibling-calls" YES) - -endif() # DRACO_CMAKE_SANITIZERS_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/arm-ios-common.cmake b/extern/draco/dracoenc/cmake/toolchains/arm-ios-common.cmake deleted file mode 100644 index 48f5ce5e68c..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/arm-ios-common.cmake +++ /dev/null @@ -1,13 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_ARM_IOS_COMMON_CMAKE_) -set(DRACO_CMAKE_ARM_IOS_COMMON_CMAKE_ 1) - -set(CMAKE_SYSTEM_NAME "Darwin") -set(CMAKE_OSX_SYSROOT iphoneos) -set(CMAKE_C_COMPILER clang) -set(CMAKE_C_COMPILER_ARG1 "-arch ${CMAKE_SYSTEM_PROCESSOR}") -set(CMAKE_CXX_COMPILER clang++) -set(CMAKE_CXX_COMPILER_ARG1 "-arch ${CMAKE_SYSTEM_PROCESSOR}") - -# TODO(tomfinegan): Handle bit code embedding. - -endif () # DRACO_CMAKE_TOOLCHAINS_ARM_IOS_COMMON_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/arm64-android-ndk-libcpp.cmake b/extern/draco/dracoenc/cmake/toolchains/arm64-android-ndk-libcpp.cmake deleted file mode 100644 index bd044199063..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/arm64-android-ndk-libcpp.cmake +++ /dev/null @@ -1,12 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_ARM64_ANDROID_NDK_LIBCPP_CMAKE_) -set(DRACO_CMAKE_TOOLCHAINS_ARM64_ANDROID_NDK_LIBCPP_CMAKE_ 1) - -include("${CMAKE_CURRENT_LIST_DIR}/../util.cmake") - -set(CMAKE_SYSTEM_NAME Android) -set(CMAKE_ANDROID_ARCH_ABI arm64-v8a) -require_variable(CMAKE_ANDROID_NDK) -set_variable_if_unset(CMAKE_SYSTEM_VERSION 21) -set_variable_if_unset(CMAKE_ANDROID_STL_TYPE c++_static) - -endif () # DRACO_CMAKE_TOOLCHAINS_ARM64_ANDROID_NDK_LIBCPP_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/arm64-ios.cmake b/extern/draco/dracoenc/cmake/toolchains/arm64-ios.cmake deleted file mode 100644 index 0d4909e1be3..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/arm64-ios.cmake +++ /dev/null @@ -1,14 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_ARM64_IOS_CMAKE_) -set(DRACO_CMAKE_TOOLCHAINS_ARM64_IOS_CMAKE_ 1) - -if (XCODE) - # TODO(tomfinegan): Handle arm builds in Xcode. - message(FATAL_ERROR "This toolchain does not support Xcode.") -endif () - -set(CMAKE_SYSTEM_PROCESSOR "arm64") -set(CMAKE_OSX_ARCHITECTURES "arm64") - -include("${CMAKE_CURRENT_LIST_DIR}/arm-ios-common.cmake") - -endif () # DRACO_CMAKE_TOOLCHAINS_ARM64_IOS_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/arm64-linux-gcc.cmake b/extern/draco/dracoenc/cmake/toolchains/arm64-linux-gcc.cmake deleted file mode 100644 index 3bab482855c..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/arm64-linux-gcc.cmake +++ /dev/null @@ -1,18 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_ARM64_LINUX_GCC_CMAKE_) -set(DRACO_CMAKE_TOOLCHAINS_ARM64_LINUX_GCC_CMAKE_ 1) - -set(CMAKE_SYSTEM_NAME "Linux") - -if ("${CROSS}" STREQUAL "") - # Default the cross compiler prefix to something known to work. - set(CROSS aarch64-linux-gnu-) -endif () - -set(CMAKE_C_COMPILER ${CROSS}gcc) -set(CMAKE_CXX_COMPILER ${CROSS}g++) -set(AS_EXECUTABLE ${CROSS}as) -set(CMAKE_C_COMPILER_ARG1 "-march=armv8-a") -set(CMAKE_CXX_COMPILER_ARG1 "-march=armv8-a") -set(CMAKE_SYSTEM_PROCESSOR "arm64") - -endif () # DRACO_CMAKE_TOOLCHAINS_ARM64_LINUX_GCC_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/armv7-android-ndk-libcpp.cmake b/extern/draco/dracoenc/cmake/toolchains/armv7-android-ndk-libcpp.cmake deleted file mode 100644 index fd50defd82e..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/armv7-android-ndk-libcpp.cmake +++ /dev/null @@ -1,12 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_ARMV7_ANDROID_NDK_LIBCPP_CMAKE_) -set(DRACO_CMAKE_TOOLCHAINS_ARMV7_ANDROID_NDK_LIBCPP_CMAKE_ 1) - -include("${CMAKE_CURRENT_LIST_DIR}/../util.cmake") - -set(CMAKE_SYSTEM_NAME Android) -set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a) -require_variable(CMAKE_ANDROID_NDK) -set_variable_if_unset(CMAKE_SYSTEM_VERSION 18) -set_variable_if_unset(CMAKE_ANDROID_STL_TYPE c++_static) - -endif () # DRACO_CMAKE_TOOLCHAINS_ARMV7_ANDROID_NDK_LIBCPP_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/armv7-ios.cmake b/extern/draco/dracoenc/cmake/toolchains/armv7-ios.cmake deleted file mode 100644 index 61d67872917..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/armv7-ios.cmake +++ /dev/null @@ -1,14 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_ARMV7_IOS_CMAKE_) -set(DRACO_CMAKE_TOOLCHAINS_ARMV7_IOS_CMAKE_ 1) - -if (XCODE) - # TODO(tomfinegan): Handle arm builds in Xcode. - message(FATAL_ERROR "This toolchain does not support Xcode.") -endif () - -set(CMAKE_SYSTEM_PROCESSOR "armv7") -set(CMAKE_OSX_ARCHITECTURES "armv7") - -include("${CMAKE_CURRENT_LIST_DIR}/arm-ios-common.cmake") - -endif () # DRACO_CMAKE_TOOLCHAINS_ARMV7_IOS_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/armv7-linux-gcc.cmake b/extern/draco/dracoenc/cmake/toolchains/armv7-linux-gcc.cmake deleted file mode 100644 index e0f850f4270..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/armv7-linux-gcc.cmake +++ /dev/null @@ -1,24 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_ARMV7_LINUX_GCC_CMAKE_) -set(DRACO_CMAKE_TOOLCHAINS_ARMV7_LINUX_GCC_CMAKE_ 1) - -set(CMAKE_SYSTEM_NAME "Linux") - -if ("${CROSS}" STREQUAL "") - # Default the cross compiler prefix to something known to work. - set(CROSS arm-linux-gnueabihf-) -endif () - -if (NOT ${CROSS} MATCHES hf-$) - set(DRACO_EXTRA_TOOLCHAIN_FLAGS "-mfloat-abi=softfp") -endif () - -set(CMAKE_C_COMPILER ${CROSS}gcc) -set(CMAKE_CXX_COMPILER ${CROSS}g++) -set(AS_EXECUTABLE ${CROSS}as) -set(CMAKE_C_COMPILER_ARG1 - "-march=armv7-a -mfpu=neon ${DRACO_EXTRA_TOOLCHAIN_FLAGS}") -set(CMAKE_CXX_COMPILER_ARG1 - "-march=armv7-a -mfpu=neon ${DRACO_EXTRA_TOOLCHAIN_FLAGS}") -set(CMAKE_SYSTEM_PROCESSOR "armv7") - -endif () # DRACO_CMAKE_TOOLCHAINS_ARMV7_LINUX_GCC_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/armv7s-ios.cmake b/extern/draco/dracoenc/cmake/toolchains/armv7s-ios.cmake deleted file mode 100644 index 45097936bcb..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/armv7s-ios.cmake +++ /dev/null @@ -1,14 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_ARMV7S_IOS_CMAKE_) -set(DRACO_CMAKE_TOOLCHAINS_ARMV7S_IOS_CMAKE_ 1) - -if (XCODE) - # TODO(tomfinegan): Handle arm builds in Xcode. - message(FATAL_ERROR "This toolchain does not support Xcode.") -endif () - -set(CMAKE_SYSTEM_PROCESSOR "armv7s") -set(CMAKE_OSX_ARCHITECTURES "armv7s") - -include("${CMAKE_CURRENT_LIST_DIR}/arm-ios-common.cmake") - -endif () # DRACO_CMAKE_TOOLCHAINS_ARMV7S_IOS_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/x86-android-ndk-libcpp.cmake b/extern/draco/dracoenc/cmake/toolchains/x86-android-ndk-libcpp.cmake deleted file mode 100644 index 7bb3717971f..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/x86-android-ndk-libcpp.cmake +++ /dev/null @@ -1,12 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_X86_ANDROID_NDK_LIBCPP_CMAKE_) -set(DRACO_CMAKE_TOOLCHAINS_X86_ANDROID_NDK_LIBCPP_CMAKE_ 1) - -include("${CMAKE_CURRENT_LIST_DIR}/../util.cmake") - -set(CMAKE_SYSTEM_NAME Android) -set(CMAKE_ANDROID_ARCH_ABI x86) -require_variable(CMAKE_ANDROID_NDK) -set_variable_if_unset(CMAKE_SYSTEM_VERSION 18) -set_variable_if_unset(CMAKE_ANDROID_STL_TYPE c++_static) - -endif () # DRACO_CMAKE_TOOLCHAINS_X86_ANDROID_NDK_LIBCPP_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/toolchains/x86_64-android-ndk-libcpp.cmake b/extern/draco/dracoenc/cmake/toolchains/x86_64-android-ndk-libcpp.cmake deleted file mode 100644 index 3b86b9d6682..00000000000 --- a/extern/draco/dracoenc/cmake/toolchains/x86_64-android-ndk-libcpp.cmake +++ /dev/null @@ -1,12 +0,0 @@ -if (NOT DRACO_CMAKE_TOOLCHAINS_X86_64_ANDROID_NDK_LIBCPP_CMAKE_) -set(DRACO_CMAKE_TOOLCHAINS_X86_64_ANDROID_NDK_LIBCPP_CMAKE_ 1) - -include("${CMAKE_CURRENT_LIST_DIR}/../util.cmake") - -set(CMAKE_SYSTEM_NAME Android) -set(CMAKE_ANDROID_ARCH_ABI x86_64) -require_variable(CMAKE_ANDROID_NDK) -set_variable_if_unset(CMAKE_SYSTEM_VERSION 21) -set_variable_if_unset(CMAKE_ANDROID_STL_TYPE c++_static) - -endif () # DRACO_CMAKE_TOOLCHAINS_X86_64_ANDROID_NDK_LIBCPP_CMAKE_ diff --git a/extern/draco/dracoenc/cmake/util.cmake b/extern/draco/dracoenc/cmake/util.cmake deleted file mode 100644 index d9254c03c03..00000000000 --- a/extern/draco/dracoenc/cmake/util.cmake +++ /dev/null @@ -1,73 +0,0 @@ -if (NOT DRACO_CMAKE_UTIL_CMAKE_) -set(DRACO_CMAKE_UTIL_CMAKE_ 1) - -# Creates dummy source file in $draco_build_dir named $basename.$extension and -# returns the full path to the dummy source file via the $out_file_path -# parameter. -function (create_dummy_source_file basename extension out_file_path) - set(dummy_source_file "${draco_build_dir}/${basename}.${extension}") - file(WRITE "${dummy_source_file}" - "// Generated file. DO NOT EDIT!\n" - "// ${target_name} needs a ${extension} file to force link language, \n" - "// or to silence a harmless CMake warning: Ignore me.\n" - "void ${target_name}_dummy_function(void) {}\n") - set(${out_file_path} ${dummy_source_file} PARENT_SCOPE) -endfunction () - -# Convenience function for adding a dummy source file to $target_name using -# $extension as the file extension. Wraps create_dummy_source_file(). -function (add_dummy_source_file_to_target target_name extension) - create_dummy_source_file("${target_name}" "${extension}" "dummy_source_file") - target_sources(${target_name} PRIVATE ${dummy_source_file}) -endfunction () - -# Extracts the version number from $version_file and returns it to the user via -# $version_string_out_var. This is achieved by finding the first instance of -# the kDracoVersion variable and then removing everything but the string literal -# assigned to the variable. Quotes and semicolon are stripped from the returned -# string. -function (extract_version_string version_file version_string_out_var) - file(STRINGS "${version_file}" draco_version REGEX "kDracoVersion") - list(GET draco_version 0 draco_version) - string(REPLACE "static const char kDracoVersion[] = " "" draco_version - "${draco_version}") - string(REPLACE ";" "" draco_version "${draco_version}") - string(REPLACE "\"" "" draco_version "${draco_version}") - set("${version_string_out_var}" "${draco_version}" PARENT_SCOPE) -endfunction () - -# Sets CMake compiler launcher to $launcher_name when $launcher_name is found in -# $PATH. Warns user about ignoring build flag $launcher_flag when $launcher_name -# is not found in $PATH. -function (set_compiler_launcher launcher_flag launcher_name) - find_program(launcher_path "${launcher_name}") - if (launcher_path) - set(CMAKE_C_COMPILER_LAUNCHER "${launcher_path}" PARENT_SCOPE) - set(CMAKE_CXX_COMPILER_LAUNCHER "${launcher_path}" PARENT_SCOPE) - message("--- Using ${launcher_name} as compiler launcher.") - else () - message(WARNING - "--- Cannot find ${launcher_name}, ${launcher_flag} ignored.") - endif () -endfunction () - -# Terminates CMake execution when $var_name is unset in the environment. Sets -# CMake variable to the value of the environment variable when the variable is -# present in the environment. -macro(require_variable var_name) - if ("$ENV{${var_name}}" STREQUAL "") - message(FATAL_ERROR "${var_name} must be set in environment.") - endif () - set_variable_if_unset(${var_name} "") -endmacro () - -# Sets $var_name to $default_value if not already set in the environment. -macro (set_variable_if_unset var_name default_value) - if (NOT "$ENV{${var_name}}" STREQUAL "") - set(${var_name} $ENV{${var_name}}) - else () - set(${var_name} ${default_value}) - endif () -endmacro () - -endif() # DRACO_CMAKE_UTIL_CMAKE_ diff --git a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoding_test.cc b/extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoding_test.cc deleted file mode 100644 index 4a6491f9d0d..00000000000 --- a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_encoding_test.cc +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright 2017 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 "draco/animation/keyframe_animation.h" -#include "draco/animation/keyframe_animation_decoder.h" -#include "draco/animation/keyframe_animation_encoder.h" -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" - -namespace draco { - -class KeyframeAnimationEncodingTest : public ::testing::Test { - protected: - KeyframeAnimationEncodingTest() {} - - bool CreateAndAddTimestamps(int32_t num_frames) { - timestamps_.resize(num_frames); - for (int i = 0; i < timestamps_.size(); ++i) - timestamps_[i] = static_cast<draco::KeyframeAnimation::TimestampType>(i); - return keyframe_animation_.SetTimestamps(timestamps_); - } - - int32_t CreateAndAddAnimationData(int32_t num_frames, - uint32_t num_components) { - // Create and add animation data with. - animation_data_.resize(num_frames * num_components); - for (int i = 0; i < animation_data_.size(); ++i) - animation_data_[i] = static_cast<float>(i); - return keyframe_animation_.AddKeyframes(draco::DT_FLOAT32, num_components, - animation_data_); - } - - template <int num_components_t> - void CompareAnimationData(const KeyframeAnimation &animation0, - const KeyframeAnimation &animation1, - bool quantized) { - ASSERT_EQ(animation0.num_frames(), animation1.num_frames()); - ASSERT_EQ(animation0.num_animations(), animation1.num_animations()); - - if (quantized) { - // TODO(hemmer) : Add test for stable quantization. - // Quantization will result in slightly different values. - // Skip comparing values. - return; - } - - // Compare time stamp. - const auto timestamp_att0 = animation0.timestamps(); - const auto timestamp_att1 = animation0.timestamps(); - for (int i = 0; i < animation0.num_frames(); ++i) { - std::array<float, 1> att_value0; - std::array<float, 1> att_value1; - ASSERT_TRUE((timestamp_att0->GetValue<float, 1>( - draco::AttributeValueIndex(i), &att_value0))); - ASSERT_TRUE((timestamp_att1->GetValue<float, 1>( - draco::AttributeValueIndex(i), &att_value1))); - ASSERT_FLOAT_EQ(att_value0[0], att_value1[0]); - } - - for (int animation_id = 1; animation_id < animation0.num_animations(); - ++animation_id) { - // Compare keyframe data. - const auto keyframe_att0 = animation0.keyframes(animation_id); - const auto keyframe_att1 = animation1.keyframes(animation_id); - ASSERT_EQ(keyframe_att0->num_components(), - keyframe_att1->num_components()); - for (int i = 0; i < animation0.num_frames(); ++i) { - std::array<float, num_components_t> att_value0; - std::array<float, num_components_t> att_value1; - ASSERT_TRUE((keyframe_att0->GetValue<float, num_components_t>( - draco::AttributeValueIndex(i), &att_value0))); - ASSERT_TRUE((keyframe_att1->GetValue<float, num_components_t>( - draco::AttributeValueIndex(i), &att_value1))); - for (int j = 0; j < att_value0.size(); ++j) { - ASSERT_FLOAT_EQ(att_value0[j], att_value1[j]); - } - } - } - } - - template <int num_components_t> - void TestKeyframeAnimationEncoding() { - TestKeyframeAnimationEncoding<num_components_t>(false); - } - - template <int num_components_t> - void TestKeyframeAnimationEncoding(bool quantized) { - // Encode animation class. - draco::EncoderBuffer buffer; - draco::KeyframeAnimationEncoder encoder; - EncoderOptions options = EncoderOptions::CreateDefaultOptions(); - if (quantized) { - // Set quantization for timestamps. - options.SetAttributeInt(0, "quantization_bits", 20); - // Set quantization for keyframes. - for (int i = 1; i <= keyframe_animation_.num_animations(); ++i) { - options.SetAttributeInt(i, "quantization_bits", 20); - } - } - - ASSERT_TRUE( - encoder.EncodeKeyframeAnimation(keyframe_animation_, options, &buffer) - .ok()); - - draco::DecoderBuffer dec_decoder; - draco::KeyframeAnimationDecoder decoder; - DecoderBuffer dec_buffer; - dec_buffer.Init(buffer.data(), buffer.size()); - - // Decode animation class. - std::unique_ptr<KeyframeAnimation> decoded_animation( - new KeyframeAnimation()); - DecoderOptions dec_options; - ASSERT_TRUE( - decoder.Decode(dec_options, &dec_buffer, decoded_animation.get()).ok()); - - // Verify if animation before and after compression is identical. - CompareAnimationData<num_components_t>(keyframe_animation_, - *decoded_animation, quantized); - } - - draco::KeyframeAnimation keyframe_animation_; - std::vector<draco::KeyframeAnimation::TimestampType> timestamps_; - std::vector<float> animation_data_; -}; - -TEST_F(KeyframeAnimationEncodingTest, OneComponent) { - const int num_frames = 1; - ASSERT_TRUE(CreateAndAddTimestamps(num_frames)); - ASSERT_EQ(CreateAndAddAnimationData(num_frames, 1), 1); - TestKeyframeAnimationEncoding<1>(); -} - -TEST_F(KeyframeAnimationEncodingTest, ManyComponents) { - const int num_frames = 100; - ASSERT_TRUE(CreateAndAddTimestamps(num_frames)); - ASSERT_EQ(CreateAndAddAnimationData(num_frames, 100), 1); - TestKeyframeAnimationEncoding<100>(); -} - -TEST_F(KeyframeAnimationEncodingTest, ManyComponentsWithQuantization) { - const int num_frames = 100; - ASSERT_TRUE(CreateAndAddTimestamps(num_frames)); - ASSERT_EQ(CreateAndAddAnimationData(num_frames, 4), 1); - // Test compression with quantization. - TestKeyframeAnimationEncoding<4>(true); -} - -TEST_F(KeyframeAnimationEncodingTest, MultipleAnimations) { - const int num_frames = 5; - ASSERT_TRUE(CreateAndAddTimestamps(num_frames)); - ASSERT_EQ(CreateAndAddAnimationData(num_frames, 3), 1); - ASSERT_EQ(CreateAndAddAnimationData(num_frames, 3), 2); - TestKeyframeAnimationEncoding<3>(); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_test.cc b/extern/draco/dracoenc/src/draco/animation/keyframe_animation_test.cc deleted file mode 100644 index bc92b25ffc4..00000000000 --- a/extern/draco/dracoenc/src/draco/animation/keyframe_animation_test.cc +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2017 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 "draco/animation/keyframe_animation.h" - -#include "draco/core/draco_test_base.h" - -namespace { - -class KeyframeAnimationTest : public ::testing::Test { - protected: - KeyframeAnimationTest() {} - - bool CreateAndAddTimestamps(int32_t num_frames) { - timestamps_.resize(num_frames); - for (int i = 0; i < timestamps_.size(); ++i) - timestamps_[i] = static_cast<draco::KeyframeAnimation::TimestampType>(i); - return keyframe_animation_.SetTimestamps(timestamps_); - } - - int32_t CreateAndAddAnimationData(int32_t num_frames, - uint32_t num_components) { - // Create and add animation data with. - animation_data_.resize(num_frames * num_components); - for (int i = 0; i < animation_data_.size(); ++i) - animation_data_[i] = static_cast<float>(i); - return keyframe_animation_.AddKeyframes(draco::DT_FLOAT32, num_components, - animation_data_); - } - - template <int num_components_t> - void CompareAnimationData() { - // Compare time stamp. - const auto timestamp_att = keyframe_animation_.timestamps(); - for (int i = 0; i < timestamps_.size(); ++i) { - std::array<float, 1> att_value; - ASSERT_TRUE((timestamp_att->GetValue<float, 1>( - draco::AttributeValueIndex(i), &att_value))); - ASSERT_FLOAT_EQ(att_value[0], i); - } - - // Compare keyframe data. - const auto keyframe_att = keyframe_animation_.keyframes(1); - for (int i = 0; i < animation_data_.size() / num_components_t; ++i) { - std::array<float, num_components_t> att_value; - ASSERT_TRUE((keyframe_att->GetValue<float, num_components_t>( - draco::AttributeValueIndex(i), &att_value))); - for (int j = 0; j < num_components_t; ++j) { - ASSERT_FLOAT_EQ(att_value[j], i * num_components_t + j); - } - } - } - - template <int num_components_t> - void TestKeyframeAnimation(int32_t num_frames) { - ASSERT_TRUE(CreateAndAddTimestamps(num_frames)); - ASSERT_EQ(CreateAndAddAnimationData(num_frames, num_components_t), 1); - CompareAnimationData<num_components_t>(); - } - - draco::KeyframeAnimation keyframe_animation_; - std::vector<draco::KeyframeAnimation::TimestampType> timestamps_; - std::vector<float> animation_data_; -}; - -// Test animation with 1 component and 10 frames. -TEST_F(KeyframeAnimationTest, OneComponent) { TestKeyframeAnimation<1>(10); } - -// Test animation with 4 component and 10 frames. -TEST_F(KeyframeAnimationTest, FourComponent) { TestKeyframeAnimation<4>(10); } - -// Test adding animation data before timestamp. -TEST_F(KeyframeAnimationTest, AddingAnimationFirst) { - ASSERT_EQ(CreateAndAddAnimationData(5, 1), 1); - ASSERT_TRUE(CreateAndAddTimestamps(5)); -} - -// Test adding timestamp more than once. -TEST_F(KeyframeAnimationTest, ErrorAddingTimestampsTwice) { - ASSERT_TRUE(CreateAndAddTimestamps(5)); - ASSERT_FALSE(CreateAndAddTimestamps(5)); -} -// Test animation with multiple animation data. -TEST_F(KeyframeAnimationTest, MultipleAnimationData) { - const int num_frames = 5; - ASSERT_TRUE(CreateAndAddTimestamps(num_frames)); - ASSERT_EQ(CreateAndAddAnimationData(num_frames, 1), 1); - ASSERT_EQ(CreateAndAddAnimationData(num_frames, 2), 2); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/attributes/point_attribute_test.cc b/extern/draco/dracoenc/src/draco/attributes/point_attribute_test.cc deleted file mode 100644 index 183003abea4..00000000000 --- a/extern/draco/dracoenc/src/draco/attributes/point_attribute_test.cc +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2017 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 "draco/attributes/point_attribute.h" - -#include "draco/core/draco_test_base.h" - -namespace { - -class PointAttributeTest : public ::testing::Test { - protected: - PointAttributeTest() {} -}; - -TEST_F(PointAttributeTest, TestCopy) { - // This test verifies that PointAttribute can copy data from another point - // attribute. - draco::GeometryAttribute pos_att; - pos_att.Init(draco::GeometryAttribute::POSITION, nullptr, 1, draco::DT_INT32, - false, 4, 0); - draco::PointAttribute pa(pos_att); - pa.SetIdentityMapping(); - pa.Reset(10); - for (int32_t i = 0; i < 10; ++i) { - pa.SetAttributeValue(draco::AttributeValueIndex(i), &i); - } - - draco::PointAttribute other_pa; - other_pa.CopyFrom(pa); - - draco::PointAttributeHasher hasher; - ASSERT_EQ(hasher(pa), hasher(other_pa)); - - // The hash function does not actually compute the hash from attribute values, - // so ensure the data got copied correctly as well. - for (int32_t i = 0; i < 10; ++i) { - int32_t data; - other_pa.GetValue(draco::AttributeValueIndex(i), &data); - ASSERT_EQ(data, i); - } -} - -TEST_F(PointAttributeTest, TestGetValueFloat) { - draco::GeometryAttribute pos_att; - pos_att.Init(draco::GeometryAttribute::POSITION, nullptr, 3, - draco::DT_FLOAT32, false, 4, 0); - draco::PointAttribute pa(pos_att); - pa.SetIdentityMapping(); - pa.Reset(5); - float points[3]; - for (int32_t i = 0; i < 5; ++i) { - points[0] = i * 3.0; - points[1] = (i * 3.0) + 1.0; - points[2] = (i * 3.0) + 2.0; - pa.SetAttributeValue(draco::AttributeValueIndex(i), &points); - } - - for (int32_t i = 0; i < 5; ++i) { - pa.GetValue(draco::AttributeValueIndex(i), &points); - ASSERT_FLOAT_EQ(points[0], i * 3.0); - ASSERT_FLOAT_EQ(points[1], (i * 3.0) + 1.0); - ASSERT_FLOAT_EQ(points[2], (i * 3.0) + 2.0); - } -} - -TEST_F(PointAttributeTest, TestGetArray) { - draco::GeometryAttribute pos_att; - pos_att.Init(draco::GeometryAttribute::POSITION, nullptr, 3, - draco::DT_FLOAT32, false, 4, 0); - draco::PointAttribute pa(pos_att); - pa.SetIdentityMapping(); - pa.Reset(5); - float points[3]; - for (int32_t i = 0; i < 5; ++i) { - points[0] = i * 3.0; - points[1] = (i * 3.0) + 1.0; - points[2] = (i * 3.0) + 2.0; - pa.SetAttributeValue(draco::AttributeValueIndex(i), &points); - } - - for (int32_t i = 0; i < 5; ++i) { - std::array<float, 3> att_value; - att_value = pa.GetValue<float, 3>(draco::AttributeValueIndex(i)); - ASSERT_FLOAT_EQ(att_value[0], i * 3.0); - ASSERT_FLOAT_EQ(att_value[1], (i * 3.0) + 1.0); - ASSERT_FLOAT_EQ(att_value[2], (i * 3.0) + 2.0); - } - for (int32_t i = 0; i < 5; ++i) { - std::array<float, 3> att_value; - EXPECT_TRUE( - (pa.GetValue<float, 3>(draco::AttributeValueIndex(i), &att_value))); - ASSERT_FLOAT_EQ(att_value[0], i * 3.0); - ASSERT_FLOAT_EQ(att_value[1], (i * 3.0) + 1.0); - ASSERT_FLOAT_EQ(att_value[2], (i * 3.0) + 2.0); - } -} - -TEST_F(PointAttributeTest, TestArrayReadError) { - draco::GeometryAttribute pos_att; - pos_att.Init(draco::GeometryAttribute::POSITION, nullptr, 3, - draco::DT_FLOAT32, false, 4, 0); - draco::PointAttribute pa(pos_att); - pa.SetIdentityMapping(); - pa.Reset(5); - float points[3]; - for (int32_t i = 0; i < 5; ++i) { - points[0] = i * 3.0; - points[1] = (i * 3.0) + 1.0; - points[2] = (i * 3.0) + 2.0; - pa.SetAttributeValue(draco::AttributeValueIndex(i), &points); - } - - std::array<float, 3> att_value; - EXPECT_FALSE( - (pa.GetValue<float, 3>(draco::AttributeValueIndex(5), &att_value))); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/point_d_vector_test.cc b/extern/draco/dracoenc/src/draco/compression/attributes/point_d_vector_test.cc deleted file mode 100644 index bff10392c3d..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/attributes/point_d_vector_test.cc +++ /dev/null @@ -1,359 +0,0 @@ -// Copyright 2018 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 "draco/compression/attributes/point_d_vector.h" -#include "draco/compression/point_cloud/algorithms/point_cloud_types.h" -#include "draco/core/draco_test_base.h" - -namespace draco { - -class PointDVectorTest : public ::testing::Test { - protected: - template <typename PT> - void TestIntegrity() {} - template <typename PT> - void TestSize() { - for (uint32_t n_items = 0; n_items <= 10; ++n_items) { - for (uint32_t dimensionality = 1; dimensionality <= 10; - ++dimensionality) { - draco::PointDVector<PT> var(n_items, dimensionality); - ASSERT_EQ(n_items, var.size()); - ASSERT_EQ(n_items * dimensionality, var.GetBufferSize()); - } - } - } - template <typename PT> - void TestContentsContiguous() { - for (uint32_t n_items = 1; n_items <= 1000; n_items *= 10) { - for (uint32_t dimensionality = 1; dimensionality < 10; - dimensionality += 2) { - for (uint32_t att_dimensionality = 1; - att_dimensionality <= dimensionality; att_dimensionality += 2) { - for (uint32_t offset_dimensionality = 0; - offset_dimensionality < dimensionality - att_dimensionality; - ++offset_dimensionality) { - PointDVector<PT> var(n_items, dimensionality); - - std::vector<PT> att(n_items * att_dimensionality); - for (PT val = 0; val < n_items; val += 1) { - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - att[val * att_dimensionality + att_dim] = val; - } - } - const PT *const attribute_data = att.data(); - - var.CopyAttribute(att_dimensionality, offset_dimensionality, - attribute_data); - - for (PT val = 0; val < n_items; val += 1) { - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - ASSERT_EQ(var[val][offset_dimensionality + att_dim], val); - } - } - } - } - } - } - } - template <typename PT> - void TestContentsDiscrete() { - for (uint32_t n_items = 1; n_items <= 1000; n_items *= 10) { - for (uint32_t dimensionality = 1; dimensionality < 10; - dimensionality += 2) { - for (uint32_t att_dimensionality = 1; - att_dimensionality <= dimensionality; att_dimensionality += 2) { - for (uint32_t offset_dimensionality = 0; - offset_dimensionality < dimensionality - att_dimensionality; - ++offset_dimensionality) { - PointDVector<PT> var(n_items, dimensionality); - - std::vector<PT> att(n_items * att_dimensionality); - for (PT val = 0; val < n_items; val += 1) { - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - att[val * att_dimensionality + att_dim] = val; - } - } - const PT *const attribute_data = att.data(); - - for (PT item = 0; item < n_items; item += 1) { - var.CopyAttribute(att_dimensionality, offset_dimensionality, item, - attribute_data + item * att_dimensionality); - } - - for (PT val = 0; val < n_items; val += 1) { - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - ASSERT_EQ(var[val][offset_dimensionality + att_dim], val); - } - } - } - } - } - } - } - - template <typename PT> - void TestContentsCopy() { - for (uint32_t n_items = 1; n_items <= 1000; n_items *= 10) { - for (uint32_t dimensionality = 1; dimensionality < 10; - dimensionality += 2) { - for (uint32_t att_dimensionality = 1; - att_dimensionality <= dimensionality; att_dimensionality += 2) { - for (uint32_t offset_dimensionality = 0; - offset_dimensionality < dimensionality - att_dimensionality; - ++offset_dimensionality) { - PointDVector<PT> var(n_items, dimensionality); - PointDVector<PT> dest(n_items, dimensionality); - - std::vector<PT> att(n_items * att_dimensionality); - for (PT val = 0; val < n_items; val += 1) { - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - att[val * att_dimensionality + att_dim] = val; - } - } - const PT *const attribute_data = att.data(); - - var.CopyAttribute(att_dimensionality, offset_dimensionality, - attribute_data); - - for (PT item = 0; item < n_items; item += 1) { - dest.CopyItem(var, item, item); - } - - for (PT val = 0; val < n_items; val += 1) { - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - ASSERT_EQ(var[val][offset_dimensionality + att_dim], val); - ASSERT_EQ(dest[val][offset_dimensionality + att_dim], val); - } - } - } - } - } - } - } - template <typename PT> - void TestIterator() { - for (uint32_t n_items = 1; n_items <= 1000; n_items *= 10) { - for (uint32_t dimensionality = 1; dimensionality < 10; - dimensionality += 2) { - for (uint32_t att_dimensionality = 1; - att_dimensionality <= dimensionality; att_dimensionality += 2) { - for (uint32_t offset_dimensionality = 0; - offset_dimensionality < dimensionality - att_dimensionality; - ++offset_dimensionality) { - PointDVector<PT> var(n_items, dimensionality); - PointDVector<PT> dest(n_items, dimensionality); - - std::vector<PT> att(n_items * att_dimensionality); - for (PT val = 0; val < n_items; val += 1) { - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - att[val * att_dimensionality + att_dim] = val; - } - } - const PT *const attribute_data = att.data(); - - var.CopyAttribute(att_dimensionality, offset_dimensionality, - attribute_data); - - for (PT item = 0; item < n_items; item += 1) { - dest.CopyItem(var, item, item); - } - - auto V0 = var.begin(); - auto VE = var.end(); - auto D0 = dest.begin(); - auto DE = dest.end(); - - while (V0 != VE && D0 != DE) { - ASSERT_EQ(*D0, *V0); // compare PseudoPointD - // verify elemental values - for (auto index = 0; index < dimensionality; index += 1) { - ASSERT_EQ((*D0)[index], (*V0)[index]); - } - ++V0; - ++D0; - } - - for (PT val = 0; val < n_items; val += 1) { - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - ASSERT_EQ(var[val][offset_dimensionality + att_dim], val); - ASSERT_EQ(dest[val][offset_dimensionality + att_dim], val); - } - } - } - } - } - } - } - template <typename PT> - void TestPoint3Iterator() { - for (uint32_t n_items = 1; n_items <= 1000; n_items *= 10) { - const uint32_t dimensionality = 3; - // for (uint32_t dimensionality = 1; dimensionality < 10; - // dimensionality += 2) { - const uint32_t att_dimensionality = 3; - // for (uint32_t att_dimensionality = 1; - // att_dimensionality <= dimensionality; att_dimensionality += 2) { - for (uint32_t offset_dimensionality = 0; - offset_dimensionality < dimensionality - att_dimensionality; - ++offset_dimensionality) { - PointDVector<PT> var(n_items, dimensionality); - PointDVector<PT> dest(n_items, dimensionality); - - std::vector<PT> att(n_items * att_dimensionality); - std::vector<draco::Point3ui> att3(n_items); - for (PT val = 0; val < n_items; val += 1) { - att3[val][0] = val; - att3[val][1] = val; - att3[val][2] = val; - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - att[val * att_dimensionality + att_dim] = val; - } - } - const PT *const attribute_data = att.data(); - - var.CopyAttribute(att_dimensionality, offset_dimensionality, - attribute_data); - - for (PT item = 0; item < n_items; item += 1) { - dest.CopyItem(var, item, item); - } - - auto aV0 = att3.begin(); - auto aVE = att3.end(); - auto V0 = var.begin(); - auto VE = var.end(); - auto D0 = dest.begin(); - auto DE = dest.end(); - - while (aV0 != aVE && V0 != VE && D0 != DE) { - ASSERT_EQ(*D0, *V0); // compare PseudoPointD - // verify elemental values - for (auto index = 0; index < dimensionality; index += 1) { - ASSERT_EQ((*D0)[index], (*V0)[index]); - ASSERT_EQ((*D0)[index], (*aV0)[index]); - ASSERT_EQ((*aV0)[index], (*V0)[index]); - } - ++aV0; - ++V0; - ++D0; - } - - for (PT val = 0; val < n_items; val += 1) { - for (PT att_dim = 0; att_dim < att_dimensionality; att_dim += 1) { - ASSERT_EQ(var[val][offset_dimensionality + att_dim], val); - ASSERT_EQ(dest[val][offset_dimensionality + att_dim], val); - } - } - } - } - } - - void TestPseudoPointDSwap() { - draco::Point3ui val = {0, 1, 2}; - draco::Point3ui dest = {10, 11, 12}; - draco::PseudoPointD<uint32_t> val_src1(&val[0], 3); - draco::PseudoPointD<uint32_t> dest_src1(&dest[0], 3); - - ASSERT_EQ(val_src1[0], 0); - ASSERT_EQ(val_src1[1], 1); - ASSERT_EQ(val_src1[2], 2); - ASSERT_EQ(dest_src1[0], 10); - ASSERT_EQ(dest_src1[1], 11); - ASSERT_EQ(dest_src1[2], 12); - - ASSERT_NE(val_src1, dest_src1); - - swap(val_src1, dest_src1); - - ASSERT_EQ(dest_src1[0], 0); - ASSERT_EQ(dest_src1[1], 1); - ASSERT_EQ(dest_src1[2], 2); - ASSERT_EQ(val_src1[0], 10); - ASSERT_EQ(val_src1[1], 11); - ASSERT_EQ(val_src1[2], 12); - - ASSERT_NE(val_src1, dest_src1); - } - void TestPseudoPointDEquality() { - draco::Point3ui val = {0, 1, 2}; - draco::Point3ui dest = {0, 1, 2}; - draco::PseudoPointD<uint32_t> val_src1(&val[0], 3); - draco::PseudoPointD<uint32_t> val_src2(&val[0], 3); - draco::PseudoPointD<uint32_t> dest_src1(&dest[0], 3); - draco::PseudoPointD<uint32_t> dest_src2(&dest[0], 3); - - ASSERT_EQ(val_src1, val_src1); - ASSERT_EQ(val_src1, val_src2); - ASSERT_EQ(dest_src1, val_src1); - ASSERT_EQ(dest_src1, val_src2); - ASSERT_EQ(val_src2, val_src1); - ASSERT_EQ(val_src2, val_src2); - ASSERT_EQ(dest_src2, val_src1); - ASSERT_EQ(dest_src2, val_src2); - - for (auto i = 0; i < 3; i++) { - ASSERT_EQ(val_src1[i], val_src1[i]); - ASSERT_EQ(val_src1[i], val_src2[i]); - ASSERT_EQ(dest_src1[i], val_src1[i]); - ASSERT_EQ(dest_src1[i], val_src2[i]); - ASSERT_EQ(val_src2[i], val_src1[i]); - ASSERT_EQ(val_src2[i], val_src2[i]); - ASSERT_EQ(dest_src2[i], val_src1[i]); - ASSERT_EQ(dest_src2[i], val_src2[i]); - } - } - void TestPseudoPointDInequality() { - draco::Point3ui val = {0, 1, 2}; - draco::Point3ui dest = {1, 2, 3}; - draco::PseudoPointD<uint32_t> val_src1(&val[0], 3); - draco::PseudoPointD<uint32_t> val_src2(&val[0], 3); - draco::PseudoPointD<uint32_t> dest_src1(&dest[0], 3); - draco::PseudoPointD<uint32_t> dest_src2(&dest[0], 3); - - ASSERT_EQ(val_src1, val_src1); - ASSERT_EQ(val_src1, val_src2); - ASSERT_NE(dest_src1, val_src1); - ASSERT_NE(dest_src1, val_src2); - ASSERT_EQ(val_src2, val_src1); - ASSERT_EQ(val_src2, val_src2); - ASSERT_NE(dest_src2, val_src1); - ASSERT_NE(dest_src2, val_src2); - - for (auto i = 0; i < 3; i++) { - ASSERT_EQ(val_src1[i], val_src1[i]); - ASSERT_EQ(val_src1[i], val_src2[i]); - ASSERT_NE(dest_src1[i], val_src1[i]); - ASSERT_NE(dest_src1[i], val_src2[i]); - ASSERT_EQ(val_src2[i], val_src1[i]); - ASSERT_EQ(val_src2[i], val_src2[i]); - ASSERT_NE(dest_src2[i], val_src1[i]); - ASSERT_NE(dest_src2[i], val_src2[i]); - } - } -}; - -TEST_F(PointDVectorTest, VectorTest) { - TestSize<uint32_t>(); - TestContentsDiscrete<uint32_t>(); - TestContentsContiguous<uint32_t>(); - TestContentsCopy<uint32_t>(); - TestIterator<uint32_t>(); - TestPoint3Iterator<uint32_t>(); -} -TEST_F(PointDVectorTest, PseudoPointDTest) { - TestPseudoPointDSwap(); - TestPseudoPointDEquality(); - TestPseudoPointDInequality(); -} -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_test.cc b/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_test.cc deleted file mode 100644 index 8c8932f77c3..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_transform_test.cc +++ /dev/null @@ -1,192 +0,0 @@ -// 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 "draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_canonicalized_encoding_transform.h" -#include "draco/core/draco_test_base.h" - -namespace { - -class PredictionSchemeNormalOctahedronCanonicalizedTransformTest - : public ::testing::Test { - protected: - typedef draco::PredictionSchemeNormalOctahedronCanonicalizedEncodingTransform< - int32_t> - Transform; - typedef Transform::Point2 Point2; - - void TestComputeCorrection(const Transform &transform, const int32_t &ox, - const int32_t &oy, const int32_t &px, - const int32_t &py, const int32_t &cx, - const int32_t &cy) { - const int32_t o[2] = {ox + 7, oy + 7}; - const int32_t p[2] = {px + 7, py + 7}; - int32_t corr[2] = {500, 500}; - transform.ComputeCorrection(o, p, corr); - ASSERT_EQ(corr[0], (cx + 15) % 15); - ASSERT_EQ(corr[1], (cy + 15) % 15); - } - - void TestGetRotationCount(const Transform &transform, const Point2 &pred, - const int32_t &rot_dir) { - const int32_t rotation_count = transform.GetRotationCount(pred); - ASSERT_EQ(rot_dir, rotation_count); - } - - void TestRotateRepresentation(const Transform &transform, const Point2 &org, - const Point2 &pred, const Point2 &rot_org, - const Point2 &rot_pred) { - const int32_t rotation_count = transform.GetRotationCount(pred); - const Point2 res_org = transform.RotatePoint(org, rotation_count); - const Point2 res_pred = transform.RotatePoint(pred, rotation_count); - ASSERT_EQ(rot_org[0], res_org[0]); - ASSERT_EQ(rot_org[1], res_org[1]); - ASSERT_EQ(rot_pred[0], res_pred[0]); - ASSERT_EQ(rot_pred[1], res_pred[1]); - } -}; - -TEST_F(PredictionSchemeNormalOctahedronCanonicalizedTransformTest, Init) { - const Transform transform(15); - ASSERT_TRUE(transform.AreCorrectionsPositive()); -} - -TEST_F(PredictionSchemeNormalOctahedronCanonicalizedTransformTest, - IsInBottomLeft) { - const Transform transform(15); - ASSERT_TRUE(transform.IsInBottomLeft(Point2(0, 0))); - ASSERT_TRUE(transform.IsInBottomLeft(Point2(-1, -1))); - ASSERT_TRUE(transform.IsInBottomLeft(Point2(-7, -7))); - - ASSERT_FALSE(transform.IsInBottomLeft(Point2(1, 1))); - ASSERT_FALSE(transform.IsInBottomLeft(Point2(7, 7))); - ASSERT_FALSE(transform.IsInBottomLeft(Point2(-1, 1))); - ASSERT_FALSE(transform.IsInBottomLeft(Point2(-7, 7))); - ASSERT_FALSE(transform.IsInBottomLeft(Point2(1, -1))); - ASSERT_FALSE(transform.IsInBottomLeft(Point2(7, -7))); -} - -TEST_F(PredictionSchemeNormalOctahedronCanonicalizedTransformTest, - GetRotationCount) { - const Transform transform(15); - TestGetRotationCount(transform, Point2(1, 2), 2); // top right - TestGetRotationCount(transform, Point2(-1, 2), 3); // top left - TestGetRotationCount(transform, Point2(1, -2), 1); // bottom right - TestGetRotationCount(transform, Point2(-1, -2), 0); // bottom left - TestGetRotationCount(transform, Point2(0, 2), 3); // top left - TestGetRotationCount(transform, Point2(0, -2), 1); // bottom right - TestGetRotationCount(transform, Point2(2, 0), 2); // top right - TestGetRotationCount(transform, Point2(-2, 0), 0); // bottom left - TestGetRotationCount(transform, Point2(0, 0), 0); // bottom left -} - -TEST_F(PredictionSchemeNormalOctahedronCanonicalizedTransformTest, - RotateRepresentation) { - const Transform transform(15); - // p top left; shift clockwise by 3 - TestRotateRepresentation(transform, Point2(1, 2), Point2(-3, 1), - Point2(-2, 1), Point2(-1, -3)); // q top right - TestRotateRepresentation(transform, Point2(-1, -2), Point2(-3, 1), - Point2(2, -1), Point2(-1, -3)); // q bottom left - TestRotateRepresentation(transform, Point2(1, -2), Point2(-3, 1), - Point2(2, 1), Point2(-1, -3)); // q bottom right - TestRotateRepresentation(transform, Point2(-1, 2), Point2(-3, 1), - Point2(-2, -1), Point2(-1, -3)); // q top left - // p top right; shift clockwise by 2 (flip) - TestRotateRepresentation(transform, Point2(1, 1), Point2(1, 3), - Point2(-1, -1), Point2(-1, -3)); // q top right - TestRotateRepresentation(transform, Point2(-1, -2), Point2(1, 3), - Point2(1, 2), Point2(-1, -3)); // q bottom left - TestRotateRepresentation(transform, Point2(-1, 2), Point2(1, 3), - Point2(1, -2), Point2(-1, -3)); // q top left - TestRotateRepresentation(transform, Point2(1, -2), Point2(1, 3), - Point2(-1, 2), Point2(-1, -3)); // q bottom right - // p bottom right; shift clockwise by 1 - TestRotateRepresentation(transform, Point2(1, 2), Point2(3, -1), - Point2(2, -1), Point2(-1, -3)); // q top right - TestRotateRepresentation(transform, Point2(1, -2), Point2(3, -1), - Point2(-2, -1), Point2(-1, -3)); // q bottom right - TestRotateRepresentation(transform, Point2(-1, -2), Point2(3, -1), - Point2(-2, 1), Point2(-1, -3)); // q bottom left - TestRotateRepresentation(transform, Point2(-1, 2), Point2(3, -1), - Point2(2, 1), Point2(-1, -3)); // q top left - // p bottom left; no change - TestRotateRepresentation(transform, Point2(1, 2), Point2(-1, -3), - Point2(1, 2), Point2(-1, -3)); // q top right - TestRotateRepresentation(transform, Point2(-1, 2), Point2(-1, -3), - Point2(-1, 2), Point2(-1, -3)); // q top left - TestRotateRepresentation(transform, Point2(1, -2), Point2(-1, -3), - Point2(1, -2), Point2(-1, -3)); // q bottom right - TestRotateRepresentation(transform, Point2(-1, -2), Point2(-1, -3), - Point2(-1, -2), Point2(-1, -3)); // q bottom left -} - -TEST_F(PredictionSchemeNormalOctahedronCanonicalizedTransformTest, - ComputeCorrection) { - const Transform transform(15); - TestComputeCorrection(transform, 0, 0, 0, 0, 0, 0); - TestComputeCorrection(transform, 1, 1, 1, 1, 0, 0); - // inside diamond; p top right - TestComputeCorrection(transform, 3, 4, 1, 2, -2, -2); // q top right - TestComputeCorrection(transform, -3, 4, 1, 2, 4, -2); // q top left - TestComputeCorrection(transform, 3, -4, 1, 2, -2, 6); // q bottom right - TestComputeCorrection(transform, -3, -4, 1, 2, 4, 6); // q bottom left - // inside diamond; p top left - TestComputeCorrection(transform, 3, 4, -1, 2, -2, 4); // q top right - TestComputeCorrection(transform, -3, 4, -1, 2, -2, -2); // q top left - TestComputeCorrection(transform, 3, -4, -1, 2, 6, 4); // q bottom right - TestComputeCorrection(transform, -3, -4, -1, 2, 6, -2); // q bottom left - // inside diamond; p bottom right - TestComputeCorrection(transform, 3, 4, 1, -2, 6, -2); // q top right - TestComputeCorrection(transform, -3, 4, 1, -2, 6, 4); // q top left - TestComputeCorrection(transform, 3, -4, 1, -2, -2, -2); // q bottom right - TestComputeCorrection(transform, -3, -4, 1, -2, -2, 4); // q bottom left - // inside diamond; p bottom left - TestComputeCorrection(transform, 3, 4, -1, -2, 4, 6); // q top right - TestComputeCorrection(transform, -3, 4, -1, -2, -2, 6); // q top left - TestComputeCorrection(transform, 3, -4, -1, -2, 4, -2); // q bottom right - TestComputeCorrection(transform, -3, -4, -1, -2, -2, -2); // q bottom left - // outside diamond; p top right - TestComputeCorrection(transform, 1, 2, 5, 4, -2, -4); // q top right - TestComputeCorrection(transform, -1, 2, 5, 4, -7, -4); // q top left - TestComputeCorrection(transform, 1, -2, 5, 4, -2, -7); // q bottom right - TestComputeCorrection(transform, -1, -2, 5, 4, -7, -7); // q bottom left - // outside diamond; p top left - TestComputeCorrection(transform, 1, 2, -5, 4, -4, -7); // q top right - TestComputeCorrection(transform, -1, 2, -5, 4, -4, -2); // q top left - TestComputeCorrection(transform, 1, -2, -5, 4, -7, -7); // q bottom right - TestComputeCorrection(transform, -1, -2, -5, 4, -7, -2); // q bottom left - // outside diamond; p bottom right - TestComputeCorrection(transform, 1, 2, 5, -4, -7, -2); // q top right - TestComputeCorrection(transform, -1, 2, 5, -4, -7, -7); // q top left - TestComputeCorrection(transform, 1, -2, 5, -4, -4, -2); // q bottom right - TestComputeCorrection(transform, -1, -2, 5, -4, -4, -7); // q bottom left - // outside diamond; p bottom left - TestComputeCorrection(transform, 1, 2, -5, -4, -7, -7); // q top right - TestComputeCorrection(transform, -1, 2, -5, -4, -2, -7); // q top left - TestComputeCorrection(transform, 1, -2, -5, -4, -7, -4); // q bottom right - TestComputeCorrection(transform, -1, -2, -5, -4, -2, -4); // q bottom left - - TestComputeCorrection(transform, -1, -2, 7, 7, -5, -6); - TestComputeCorrection(transform, 0, 0, 7, 7, 7, 7); - TestComputeCorrection(transform, -1, -2, 0, -2, 0, 1); -} - -TEST_F(PredictionSchemeNormalOctahedronCanonicalizedTransformTest, Interface) { - const Transform transform(15); - ASSERT_EQ(transform.max_quantized_value(), 15); - ASSERT_EQ(transform.center_value(), 7); - ASSERT_EQ(transform.quantization_bits(), 4); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_test.cc b/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_test.cc deleted file mode 100644 index 1001b19fa50..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_transform_test.cc +++ /dev/null @@ -1,71 +0,0 @@ -// 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 "draco/compression/attributes/prediction_schemes/prediction_scheme_normal_octahedron_encoding_transform.h" -#include "draco/core/draco_test_base.h" - -namespace { - -class PredictionSchemeNormalOctahedronTransformTest : public ::testing::Test { - protected: - typedef draco::PredictionSchemeNormalOctahedronEncodingTransform<int32_t> - Transform; - typedef Transform::Point2 Point2; - - void TestComputeCorrection(const Transform &transform, const int32_t &ox, - const int32_t &oy, const int32_t &px, - const int32_t &py, const int32_t &cx, - const int32_t &cy) { - const int32_t o[2] = {ox + 7, oy + 7}; - const int32_t p[2] = {px + 7, py + 7}; - int32_t corr[2] = {500, 500}; - transform.ComputeCorrection(o, p, corr); - ASSERT_EQ(corr[0], (cx + 15) % 15); - ASSERT_EQ(corr[1], (cy + 15) % 15); - } -}; - -TEST_F(PredictionSchemeNormalOctahedronTransformTest, Init) { - const Transform transform(15); - ASSERT_TRUE(transform.AreCorrectionsPositive()); -} - -TEST_F(PredictionSchemeNormalOctahedronTransformTest, ComputeCorrections) { - const Transform transform(15); - // checks inside diamond - TestComputeCorrection(transform, 0, 0, 0, 0, 0, 0); - TestComputeCorrection(transform, 1, 1, 1, 1, 0, 0); - TestComputeCorrection(transform, 3, 4, 1, 1, 2, 3); - TestComputeCorrection(transform, -1, -1, -1, -1, 0, 0); - TestComputeCorrection(transform, -3, -4, -1, -1, -2, -3); - // checks outside diamond - TestComputeCorrection(transform, 4, 4, 4, 4, 0, 0); - TestComputeCorrection(transform, 5, 6, 4, 4, -2, -1); - TestComputeCorrection(transform, 3, 2, 4, 4, 2, 1); - // checks on outer edges - TestComputeCorrection(transform, 7, 7, 4, 4, -3, -3); - TestComputeCorrection(transform, 6, 7, 4, 4, -3, -2); - TestComputeCorrection(transform, -6, 7, 4, 4, -3, -2); - TestComputeCorrection(transform, 7, 6, 4, 4, -2, -3); - TestComputeCorrection(transform, 7, -6, 4, 4, -2, -3); -} - -TEST_F(PredictionSchemeNormalOctahedronTransformTest, Interface) { - const Transform transform(15); - ASSERT_EQ(transform.max_quantized_value(), 15); - ASSERT_EQ(transform.center_value(), 7); - ASSERT_EQ(transform.quantization_bits(), 4); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoding_test.cc b/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoding_test.cc deleted file mode 100644 index d7b0cd25df6..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/attributes/sequential_integer_attribute_encoding_test.cc +++ /dev/null @@ -1,67 +0,0 @@ -// 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 <numeric> - -#include "draco/compression/attributes/sequential_integer_attribute_decoder.h" -#include "draco/compression/attributes/sequential_integer_attribute_encoder.h" -#include "draco/compression/config/compression_shared.h" -#include "draco/core/draco_test_base.h" - -namespace draco { - -class SequentialIntegerAttributeEncodingTest : public ::testing::Test { - protected: -}; - -TEST_F(SequentialIntegerAttributeEncodingTest, DoesCompress) { - // This test verifies that IntegerEncoding encodes and decodes the given data. - const std::vector<int32_t> values{1, 8, 7, 5, 5, 5, 9, - 155, -6, -9, 9, 125, 1, 0}; - GeometryAttribute ga; - PointAttribute pa; - pa.Init(GeometryAttribute::GENERIC, nullptr, 1, DT_INT32, false, 4, 0); - pa.Reset(values.size()); - pa.SetIdentityMapping(); - for (uint32_t i = 0; i < values.size(); ++i) { - pa.SetAttributeValue(AttributeValueIndex(i), &values[i]); - } - // List of point ids from 0 to point_ids.size() - 1. - std::vector<PointIndex> point_ids(values.size()); - std::iota(point_ids.begin(), point_ids.end(), 0); - - EncoderBuffer out_buf; - SequentialIntegerAttributeEncoder ie; - ASSERT_TRUE(ie.InitializeStandalone(&pa)); - ASSERT_TRUE(ie.TransformAttributeToPortableFormat(point_ids)); - ASSERT_TRUE(ie.EncodePortableAttribute(point_ids, &out_buf)); - ASSERT_TRUE(ie.EncodeDataNeededByPortableTransform(&out_buf)); - - DecoderBuffer in_buf; - in_buf.Init(out_buf.data(), out_buf.size()); - in_buf.set_bitstream_version(kDracoMeshBitstreamVersion); - SequentialIntegerAttributeDecoder id; - ASSERT_TRUE(id.InitializeStandalone(&pa)); - ASSERT_TRUE(id.DecodePortableAttribute(point_ids, &in_buf)); - ASSERT_TRUE(id.DecodeDataNeededByPortableTransform(point_ids, &in_buf)); - ASSERT_TRUE(id.TransformAttributeToOriginalFormat(point_ids)); - - for (uint32_t i = 0; i < values.size(); ++i) { - int32_t entry_val; - pa.GetValue(AttributeValueIndex(i), &entry_val); - ASSERT_EQ(entry_val, values[i]); - } -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_coding_test.cc b/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_coding_test.cc deleted file mode 100644 index 9509ad9f354..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/bit_coders/rans_coding_test.cc +++ /dev/null @@ -1,9 +0,0 @@ -#include "draco/compression/bit_coders/adaptive_rans_bit_decoder.h" -#include "draco/compression/bit_coders/adaptive_rans_bit_encoder.h" -#include "draco/compression/bit_coders/rans_bit_decoder.h" -#include "draco/compression/bit_coders/rans_bit_encoder.h" -#include "draco/core/draco_test_base.h" - -// Just including rans_coding.h and adaptive_rans_coding.h gets an asan error -// when compiling (blaze test :rans_coding_test --config=asan) -TEST(RansCodingTest, LinkerTest) {} diff --git a/extern/draco/dracoenc/src/draco/compression/config/decoder_options_test.cc b/extern/draco/dracoenc/src/draco/compression/config/decoder_options_test.cc deleted file mode 100644 index a5cd7f10640..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/config/decoder_options_test.cc +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2017 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 "draco/compression/config/decoder_options.h" - -#include "draco/core/draco_test_base.h" - -namespace { - -class DecoderOptionsTest : public ::testing::Test { - protected: - DecoderOptionsTest() {} -}; - -TEST_F(DecoderOptionsTest, TestOptions) { - // This test verifies that we can update global and attribute options of the - // DecoderOptions class instance. - draco::DecoderOptions options; - options.SetGlobalInt("test", 3); - ASSERT_EQ(options.GetGlobalInt("test", -1), 3); - - options.SetAttributeInt(draco::GeometryAttribute::POSITION, "test", 1); - options.SetAttributeInt(draco::GeometryAttribute::GENERIC, "test", 2); - ASSERT_EQ( - options.GetAttributeInt(draco::GeometryAttribute::TEX_COORD, "test", -1), - 3); - ASSERT_EQ( - options.GetAttributeInt(draco::GeometryAttribute::POSITION, "test", -1), - 1); - ASSERT_EQ( - options.GetAttributeInt(draco::GeometryAttribute::GENERIC, "test", -1), - 2); -} - -TEST_F(DecoderOptionsTest, TestAttributeOptionsAccessors) { - // This test verifies that we can query options stored in DecoderOptions - // class instance. - draco::DecoderOptions options; - options.SetGlobalInt("test", 1); - options.SetAttributeInt(draco::GeometryAttribute::POSITION, "test", 2); - options.SetAttributeInt(draco::GeometryAttribute::TEX_COORD, "test", 3); - - ASSERT_EQ( - options.GetAttributeInt(draco::GeometryAttribute::POSITION, "test", -1), - 2); - ASSERT_EQ( - options.GetAttributeInt(draco::GeometryAttribute::POSITION, "test2", -1), - -1); - ASSERT_EQ( - options.GetAttributeInt(draco::GeometryAttribute::TEX_COORD, "test", -1), - 3); - ASSERT_EQ( - options.GetAttributeInt(draco::GeometryAttribute::NORMAL, "test", -1), 1); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/compression/decode_test.cc b/extern/draco/dracoenc/src/draco/compression/decode_test.cc deleted file mode 100644 index c57542069dd..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/decode_test.cc +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright 2017 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 "draco/compression/decode.h" - -#include <cinttypes> -#include <fstream> -#include <sstream> - -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" - -namespace { - -class DecodeTest : public ::testing::Test { - protected: - DecodeTest() {} -}; - -#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED -TEST_F(DecodeTest, TestSkipAttributeTransform) { - const std::string file_name = "test_nm_quant.0.9.0.drc"; - // Tests that decoders can successfully skip attribute transform. - std::ifstream input_file(draco::GetTestFileFullPath(file_name), - std::ios::binary); - ASSERT_TRUE(input_file); - - // Read the file stream into a buffer. - std::streampos file_size = 0; - input_file.seekg(0, std::ios::end); - file_size = input_file.tellg() - file_size; - input_file.seekg(0, std::ios::beg); - std::vector<char> data(file_size); - input_file.read(data.data(), file_size); - - ASSERT_FALSE(data.empty()); - - // Create a draco decoding buffer. Note that no data is copied in this step. - draco::DecoderBuffer buffer; - buffer.Init(data.data(), data.size()); - - draco::Decoder decoder; - // Make sure we skip dequantization for the position attribute. - decoder.SetSkipAttributeTransform(draco::GeometryAttribute::POSITION); - - // Decode the input data into a geometry. - std::unique_ptr<draco::PointCloud> pc = - decoder.DecodePointCloudFromBuffer(&buffer).value(); - ASSERT_NE(pc, nullptr); - - const draco::PointAttribute *const pos_att = - pc->GetNamedAttribute(draco::GeometryAttribute::POSITION); - ASSERT_NE(pos_att, nullptr); - - // Ensure the position attribute is of type int32_t and that it has a valid - // attribute transform. - ASSERT_EQ(pos_att->data_type(), draco::DT_INT32); - ASSERT_NE(pos_att->GetAttributeTransformData(), nullptr); - - // Normal attribute should be left transformed. - const draco::PointAttribute *const norm_att = - pc->GetNamedAttribute(draco::GeometryAttribute::NORMAL); - ASSERT_EQ(norm_att->data_type(), draco::DT_FLOAT32); - ASSERT_EQ(norm_att->GetAttributeTransformData(), nullptr); -} -#endif - -void TestSkipAttributeTransformOnPointCloudWithColor(const std::string &file) { - std::ifstream input_file(draco::GetTestFileFullPath(file), std::ios::binary); - ASSERT_TRUE(input_file); - - // Read the file stream into a buffer. - std::streampos file_size = 0; - input_file.seekg(0, std::ios::end); - file_size = input_file.tellg() - file_size; - input_file.seekg(0, std::ios::beg); - std::vector<char> data(file_size); - input_file.read(data.data(), file_size); - - ASSERT_FALSE(data.empty()); - - // Create a draco decoding buffer. Note that no data is copied in this step. - draco::DecoderBuffer buffer; - buffer.Init(data.data(), data.size()); - - draco::Decoder decoder; - // Make sure we skip dequantization for the position attribute. - decoder.SetSkipAttributeTransform(draco::GeometryAttribute::POSITION); - - // Decode the input data into a geometry. - std::unique_ptr<draco::PointCloud> pc = - decoder.DecodePointCloudFromBuffer(&buffer).value(); - ASSERT_NE(pc, nullptr); - - const draco::PointAttribute *const pos_att = - pc->GetNamedAttribute(draco::GeometryAttribute::POSITION); - ASSERT_NE(pos_att, nullptr); - - // Ensure the position attribute is of type int32_t or uint32_t and that it - // has a valid attribute transform. - ASSERT_TRUE(pos_att->data_type() == draco::DT_INT32 || - pos_att->data_type() == draco::DT_UINT32); - ASSERT_NE(pos_att->GetAttributeTransformData(), nullptr); - - const draco::PointAttribute *const clr_att = - pc->GetNamedAttribute(draco::GeometryAttribute::COLOR); - ASSERT_EQ(clr_att->data_type(), draco::DT_UINT8); - - // Ensure the color attribute was decoded correctly. Perform the decoding - // again without skipping the position dequantization and compare the - // attribute values. - - draco::DecoderBuffer buffer_2; - buffer_2.Init(data.data(), data.size()); - - draco::Decoder decoder_2; - - // Decode the input data into a geometry. - std::unique_ptr<draco::PointCloud> pc_2 = - decoder_2.DecodePointCloudFromBuffer(&buffer_2).value(); - ASSERT_NE(pc_2, nullptr); - - const draco::PointAttribute *const clr_att_2 = - pc_2->GetNamedAttribute(draco::GeometryAttribute::COLOR); - ASSERT_NE(clr_att_2, nullptr); - for (draco::PointIndex pi(0); pi < pc_2->num_points(); ++pi) { - // Colors should be exactly the same for both cases. - ASSERT_EQ(std::memcmp(clr_att->GetAddress(clr_att->mapped_index(pi)), - clr_att_2->GetAddress(clr_att_2->mapped_index(pi)), - clr_att->byte_stride()), - 0); - } -} - -TEST_F(DecodeTest, TestSkipAttributeTransformOnPointCloud) { - // Tests that decoders can successfully skip attribute transform on a point - // cloud with multiple attributes encoded with one attributes encoder. - TestSkipAttributeTransformOnPointCloudWithColor("pc_color.drc"); - TestSkipAttributeTransformOnPointCloudWithColor("pc_kd_color.drc"); -} - -TEST_F(DecodeTest, TestSkipAttributeTransformWithNoQuantization) { - // Tests that decoders can successfully skip attribute transform even though - // the input model was not quantized (it has no attribute transform). - const std::string file_name = "point_cloud_no_qp.drc"; - std::ifstream input_file(draco::GetTestFileFullPath(file_name), - std::ios::binary); - ASSERT_TRUE(input_file); - - // Read the file stream into a buffer. - std::streampos file_size = 0; - input_file.seekg(0, std::ios::end); - file_size = input_file.tellg() - file_size; - input_file.seekg(0, std::ios::beg); - std::vector<char> data(file_size); - input_file.read(data.data(), file_size); - - ASSERT_FALSE(data.empty()); - - // Create a draco decoding buffer. Note that no data is copied in this step. - draco::DecoderBuffer buffer; - buffer.Init(data.data(), data.size()); - - draco::Decoder decoder; - // Make sure we skip dequantization for the position attribute. - decoder.SetSkipAttributeTransform(draco::GeometryAttribute::POSITION); - - // Decode the input data into a geometry. - std::unique_ptr<draco::PointCloud> pc = - decoder.DecodePointCloudFromBuffer(&buffer).value(); - ASSERT_NE(pc, nullptr); - - const draco::PointAttribute *const pos_att = - pc->GetNamedAttribute(draco::GeometryAttribute::POSITION); - ASSERT_NE(pos_att, nullptr); - - // Ensure the position attribute is of type float32 since the attribute was - // not quantized. - ASSERT_EQ(pos_att->data_type(), draco::DT_FLOAT32); - - // Make sure there is no attribute transform available for the attribute. - ASSERT_EQ(pos_att->GetAttributeTransformData(), nullptr); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/compression/encode_test.cc b/extern/draco/dracoenc/src/draco/compression/encode_test.cc deleted file mode 100644 index 2eadb73b343..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/encode_test.cc +++ /dev/null @@ -1,293 +0,0 @@ -// Copyright 2017 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 <cinttypes> -#include <fstream> -#include <sstream> - -#include "draco/attributes/attribute_quantization_transform.h" -#include "draco/compression/decode.h" -#include "draco/compression/encode.h" -#include "draco/compression/expert_encode.h" -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/core/vector_d.h" -#include "draco/io/obj_decoder.h" -#include "draco/mesh/triangle_soup_mesh_builder.h" -#include "draco/point_cloud/point_cloud_builder.h" - -namespace { - -class EncodeTest : public ::testing::Test { - protected: - EncodeTest() {} - std::unique_ptr<draco::Mesh> CreateTestMesh() const { - draco::TriangleSoupMeshBuilder mesh_builder; - - // Create a simple mesh with one face. - mesh_builder.Start(1); - - // Add one position attribute and two texture coordinate attributes. - const int32_t pos_att_id = mesh_builder.AddAttribute( - draco::GeometryAttribute::POSITION, 3, draco::DT_FLOAT32); - const int32_t tex_att_id_0 = mesh_builder.AddAttribute( - draco::GeometryAttribute::TEX_COORD, 2, draco::DT_FLOAT32); - const int32_t tex_att_id_1 = mesh_builder.AddAttribute( - draco::GeometryAttribute::TEX_COORD, 2, draco::DT_FLOAT32); - - // Initialize the attribute values. - mesh_builder.SetAttributeValuesForFace( - pos_att_id, draco::FaceIndex(0), draco::Vector3f(0.f, 0.f, 0.f).data(), - draco::Vector3f(1.f, 0.f, 0.f).data(), - draco::Vector3f(1.f, 1.f, 0.f).data()); - mesh_builder.SetAttributeValuesForFace( - tex_att_id_0, draco::FaceIndex(0), draco::Vector2f(0.f, 0.f).data(), - draco::Vector2f(1.f, 0.f).data(), draco::Vector2f(1.f, 1.f).data()); - mesh_builder.SetAttributeValuesForFace( - tex_att_id_1, draco::FaceIndex(0), draco::Vector2f(0.f, 0.f).data(), - draco::Vector2f(1.f, 0.f).data(), draco::Vector2f(1.f, 1.f).data()); - - return mesh_builder.Finalize(); - } - - std::unique_ptr<draco::PointCloud> CreateTestPointCloud() const { - draco::PointCloudBuilder pc_builder; - - constexpr int kNumPoints = 100; - constexpr int kNumGenAttCoords0 = 4; - constexpr int kNumGenAttCoords1 = 6; - pc_builder.Start(kNumPoints); - - // Add one position attribute and two generic attributes. - const int32_t pos_att_id = pc_builder.AddAttribute( - draco::GeometryAttribute::POSITION, 3, draco::DT_FLOAT32); - const int32_t gen_att_id_0 = pc_builder.AddAttribute( - draco::GeometryAttribute::GENERIC, kNumGenAttCoords0, draco::DT_UINT32); - const int32_t gen_att_id_1 = pc_builder.AddAttribute( - draco::GeometryAttribute::GENERIC, kNumGenAttCoords1, draco::DT_UINT8); - - std::vector<uint32_t> gen_att_data_0(kNumGenAttCoords0); - std::vector<uint32_t> gen_att_data_1(kNumGenAttCoords1); - - // 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()); - - for (int j = 0; j < kNumGenAttCoords0; ++j) { - gen_att_data_0[j] = i.value(); - } - pc_builder.SetAttributeValueForPoint(gen_att_id_0, i, - gen_att_data_0.data()); - - for (int j = 0; j < kNumGenAttCoords1; ++j) { - gen_att_data_1[j] = -i.value(); - } - pc_builder.SetAttributeValueForPoint(gen_att_id_1, i, - gen_att_data_1.data()); - } - - return pc_builder.Finalize(false); - } - - int GetQuantizationBitsFromAttribute(const draco::PointAttribute *att) const { - if (att == nullptr) - return -1; - draco::AttributeQuantizationTransform transform; - if (!transform.InitFromAttribute(*att)) - return -1; - return transform.quantization_bits(); - } - - void VerifyNumQuantizationBits(const draco::EncoderBuffer &buffer, - int pos_quantization, - int tex_coord_0_quantization, - int tex_coord_1_quantization) const { - draco::Decoder decoder; - - // Skip the dequantization for the attributes which will allow us to get - // the number of quantization bits used during encoding. - decoder.SetSkipAttributeTransform(draco::GeometryAttribute::POSITION); - decoder.SetSkipAttributeTransform(draco::GeometryAttribute::TEX_COORD); - - draco::DecoderBuffer in_buffer; - in_buffer.Init(buffer.data(), buffer.size()); - auto mesh = decoder.DecodeMeshFromBuffer(&in_buffer).value(); - ASSERT_NE(mesh, nullptr); - ASSERT_EQ(GetQuantizationBitsFromAttribute(mesh->attribute(0)), - pos_quantization); - ASSERT_EQ(GetQuantizationBitsFromAttribute(mesh->attribute(1)), - tex_coord_0_quantization); - ASSERT_EQ(GetQuantizationBitsFromAttribute(mesh->attribute(2)), - tex_coord_1_quantization); - } - - // Tests that the encoder returns the correct number of encoded points and - // faces for a given mesh or point cloud. - void TestNumberOfEncodedEntries(const std::string &file_name, - int32_t encoding_method) { - std::unique_ptr<draco::PointCloud> geometry; - draco::Mesh *mesh = nullptr; - - if (encoding_method == draco::MESH_EDGEBREAKER_ENCODING || - encoding_method == draco::MESH_SEQUENTIAL_ENCODING) { - std::unique_ptr<draco::Mesh> mesh_tmp = - draco::ReadMeshFromTestFile(file_name); - mesh = mesh_tmp.get(); - if (!mesh->DeduplicateAttributeValues()) - return; - mesh->DeduplicatePointIds(); - geometry = std::move(mesh_tmp); - } else { - geometry = draco::ReadPointCloudFromTestFile(file_name); - } - ASSERT_NE(mesh, nullptr); - - draco::Encoder encoder; - encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, 14); - encoder.SetAttributeQuantization(draco::GeometryAttribute::TEX_COORD, 12); - encoder.SetAttributeQuantization(draco::GeometryAttribute::NORMAL, 10); - - encoder.SetEncodingMethod(encoding_method); - - encoder.SetTrackEncodedProperties(true); - - draco::EncoderBuffer buffer; - if (mesh) { - encoder.EncodeMeshToBuffer(*mesh, &buffer); - } else { - encoder.EncodePointCloudToBuffer(*geometry, &buffer); - } - - // Ensure the logged number of encoded points and faces matches the number - // we get from the decoder. - - draco::DecoderBuffer decoder_buffer; - decoder_buffer.Init(buffer.data(), buffer.size()); - draco::Decoder decoder; - - if (mesh) { - auto maybe_mesh = decoder.DecodeMeshFromBuffer(&decoder_buffer); - ASSERT_TRUE(maybe_mesh.ok()); - auto decoded_mesh = std::move(maybe_mesh).value(); - ASSERT_NE(decoded_mesh, nullptr); - ASSERT_EQ(decoded_mesh->num_points(), encoder.num_encoded_points()); - ASSERT_EQ(decoded_mesh->num_faces(), encoder.num_encoded_faces()); - } else { - auto maybe_pc = decoder.DecodePointCloudFromBuffer(&decoder_buffer); - ASSERT_TRUE(maybe_pc.ok()); - auto decoded_pc = std::move(maybe_pc).value(); - ASSERT_EQ(decoded_pc->num_points(), encoder.num_encoded_points()); - } - } -}; - -TEST_F(EncodeTest, TestExpertEncoderQuantization) { - // This test verifies that the expert encoder can quantize individual - // attributes even if they have the same type. - auto mesh = CreateTestMesh(); - ASSERT_NE(mesh, nullptr); - - draco::ExpertEncoder encoder(*mesh.get()); - encoder.SetAttributeQuantization(0, 16); // Position quantization. - encoder.SetAttributeQuantization(1, 15); // Tex-coord 0 quantization. - encoder.SetAttributeQuantization(2, 14); // Tex-coord 1 quantization. - - draco::EncoderBuffer buffer; - encoder.EncodeToBuffer(&buffer); - VerifyNumQuantizationBits(buffer, 16, 15, 14); -} - -TEST_F(EncodeTest, TestEncoderQuantization) { - // This test verifies that Encoder applies the same quantization to all - // attributes of the same type. - auto mesh = CreateTestMesh(); - ASSERT_NE(mesh, nullptr); - - draco::Encoder encoder; - encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, 16); - encoder.SetAttributeQuantization(draco::GeometryAttribute::TEX_COORD, 15); - - draco::EncoderBuffer buffer; - encoder.EncodeMeshToBuffer(*mesh.get(), &buffer); - VerifyNumQuantizationBits(buffer, 16, 15, 15); -} - -TEST_F(EncodeTest, TestLinesObj) { - // This test verifies that Encoder can encode file that contains only line - // segments (that are ignored). - std::unique_ptr<draco::Mesh> mesh( - draco::ReadMeshFromTestFile("test_lines.obj")); - ASSERT_NE(mesh, nullptr); - ASSERT_EQ(mesh->num_faces(), 0); - std::unique_ptr<draco::PointCloud> pc( - draco::ReadPointCloudFromTestFile("test_lines.obj")); - ASSERT_NE(pc, nullptr); - - draco::Encoder encoder; - encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, 16); - - draco::EncoderBuffer buffer; - ASSERT_TRUE(encoder.EncodePointCloudToBuffer(*pc, &buffer).ok()); -} - -TEST_F(EncodeTest, TestKdTreeEncoding) { - // This test verifies that the API can successfully encode a point cloud - // defined by several attributes using the kd tree method. - std::unique_ptr<draco::PointCloud> pc = CreateTestPointCloud(); - ASSERT_NE(pc, nullptr); - - draco::EncoderBuffer buffer; - draco::Encoder encoder; - encoder.SetEncodingMethod(draco::POINT_CLOUD_KD_TREE_ENCODING); - // First try it without quantizing positions which should fail. - ASSERT_FALSE(encoder.EncodePointCloudToBuffer(*pc, &buffer).ok()); - - // Now set quantization for the position attribute which should make - // the encoder happy. - encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, 16); - ASSERT_TRUE(encoder.EncodePointCloudToBuffer(*pc, &buffer).ok()); -} - -TEST_F(EncodeTest, TestTrackingOfNumberOfEncodedEntries) { - TestNumberOfEncodedEntries("deg_faces.obj", draco::MESH_EDGEBREAKER_ENCODING); - TestNumberOfEncodedEntries("deg_faces.obj", draco::MESH_SEQUENTIAL_ENCODING); - TestNumberOfEncodedEntries("cube_att.obj", draco::MESH_EDGEBREAKER_ENCODING); - TestNumberOfEncodedEntries("test_nm.obj", draco::MESH_EDGEBREAKER_ENCODING); - TestNumberOfEncodedEntries("test_nm.obj", draco::MESH_SEQUENTIAL_ENCODING); - TestNumberOfEncodedEntries("cube_subd.obj", - draco::POINT_CLOUD_KD_TREE_ENCODING); - TestNumberOfEncodedEntries("cube_subd.obj", - draco::POINT_CLOUD_SEQUENTIAL_ENCODING); -} - -TEST_F(EncodeTest, TestTrackingOfNumberOfEncodedEntriesNotSet) { - // Tests that when tracing of encoded properties is disabled, the returned - // number of encoded faces and points is 0. - std::unique_ptr<draco::Mesh> mesh( - draco::ReadMeshFromTestFile("cube_att.obj")); - ASSERT_NE(mesh, nullptr); - - draco::EncoderBuffer buffer; - draco::Encoder encoder; - - ASSERT_TRUE(encoder.EncodeMeshToBuffer(*mesh, &buffer).ok()); - ASSERT_EQ(encoder.num_encoded_points(), 0); - ASSERT_EQ(encoder.num_encoded_faces(), 0); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy_test.cc b/extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy_test.cc deleted file mode 100644 index c2fe64440be..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/entropy/shannon_entropy_test.cc +++ /dev/null @@ -1,56 +0,0 @@ -#include "draco/compression/entropy/shannon_entropy.h" -#include "draco/core/draco_test_base.h" - -namespace { - -TEST(ShannonEntropyTest, TestBinaryEntropy) { - // Test verifies that computing binary entropy works as expected. - ASSERT_EQ(draco::ComputeBinaryShannonEntropy(0, 0), 0); - ASSERT_EQ(draco::ComputeBinaryShannonEntropy(10, 0), 0); - ASSERT_EQ(draco::ComputeBinaryShannonEntropy(10, 10), 0); - ASSERT_NEAR(draco::ComputeBinaryShannonEntropy(10, 5), 1.0, 1e-4); -} - -TEST(ShannonEntropyTest, TestStreamEntropy) { - // Test verifies that the entropy of streamed data is computed correctly. - const std::vector<uint32_t> symbols = {1, 5, 1, 100, 2, 1}; - - draco::ShannonEntropyTracker entropy_tracker; - - // Nothing added, 0 entropy. - ASSERT_EQ(entropy_tracker.GetNumberOfDataBits(), 0); - - // Try to push symbols one by one. - uint32_t max_symbol = 0; - for (int i = 0; i < symbols.size(); ++i) { - if (symbols[i] > max_symbol) - max_symbol = symbols[i]; - const auto entropy_data = entropy_tracker.Push(&symbols[i], 1); - - const int64_t stream_entropy_bits = entropy_tracker.GetNumberOfDataBits(); - // Ensure the returned entropy_data is in sync with the stream. - ASSERT_EQ(draco::ShannonEntropyTracker::GetNumberOfDataBits(entropy_data), - stream_entropy_bits); - - // Make sure the entropy is approximately the same as the one we compute - // directly from all symbols. - const int64_t expected_entropy_bits = draco::ComputeShannonEntropy( - symbols.data(), i + 1, max_symbol, nullptr); - - // For now hardcoded tolerance of 2 bits. - ASSERT_NEAR(expected_entropy_bits, stream_entropy_bits, 2); - } - - // Compare it also to the case when we add all symbols in one call. - draco::ShannonEntropyTracker entropy_tracker_2; - entropy_tracker_2.Push(symbols.data(), symbols.size()); - const int64_t stream_2_entropy_bits = entropy_tracker_2.GetNumberOfDataBits(); - ASSERT_EQ(entropy_tracker.GetNumberOfDataBits(), stream_2_entropy_bits); - - // Ensure that peeking does not change the entropy. - entropy_tracker_2.Peek(symbols.data(), 1); - - ASSERT_EQ(stream_2_entropy_bits, entropy_tracker_2.GetNumberOfDataBits()); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_coding_test.cc b/extern/draco/dracoenc/src/draco/compression/entropy/symbol_coding_test.cc deleted file mode 100644 index ba7166bbe75..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/entropy/symbol_coding_test.cc +++ /dev/null @@ -1,170 +0,0 @@ -// 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 "draco/compression/config/compression_shared.h" -#include "draco/compression/entropy/symbol_decoding.h" -#include "draco/compression/entropy/symbol_encoding.h" -#include "draco/core/bit_utils.h" -#include "draco/core/decoder_buffer.h" -#include "draco/core/draco_test_base.h" -#include "draco/core/encoder_buffer.h" - -namespace draco { - -class SymbolCodingTest : public ::testing::Test { - protected: - SymbolCodingTest() : bitstream_version_(kDracoMeshBitstreamVersion) {} - - template <class SignedIntTypeT> - void TestConvertToSymbolAndBack(SignedIntTypeT x) { - typedef typename std::make_unsigned<SignedIntTypeT>::type Symbol; - Symbol symbol = ConvertSignedIntToSymbol(x); - SignedIntTypeT y = ConvertSymbolToSignedInt(symbol); - ASSERT_EQ(x, y); - } - - uint16_t bitstream_version_; -}; - -TEST_F(SymbolCodingTest, TestLargeNumbers) { - // This test verifies that SymbolCoding successfully encodes an array of large - // numbers. - const uint32_t in[] = {12345678, 1223333, 111, 5}; - const int num_values = sizeof(in) / sizeof(uint32_t); - EncoderBuffer eb; - ASSERT_TRUE(EncodeSymbols(in, num_values, 1, nullptr, &eb)); - - std::vector<uint32_t> out; - out.resize(num_values); - DecoderBuffer db; - db.Init(eb.data(), eb.size()); - db.set_bitstream_version(bitstream_version_); - ASSERT_TRUE(DecodeSymbols(num_values, 1, &db, &out[0])); - for (int i = 0; i < num_values; ++i) { - EXPECT_EQ(in[i], out[i]); - } -} - -TEST_F(SymbolCodingTest, TestManyNumbers) { - // This test verifies that SymbolCoding successfully encodes an array of - // several numbers that repeat many times. - - // Value/frequency pairs. - const std::pair<uint32_t, uint32_t> in[] = { - {12, 1500}, {1025, 31000}, {7, 1}, {9, 5}, {0, 6432}}; - - const int num_pairs = sizeof(in) / sizeof(std::pair<uint32_t, uint32_t>); - - std::vector<uint32_t> in_values; - for (int i = 0; i < num_pairs; ++i) { - in_values.insert(in_values.end(), in[i].second, in[i].first); - } - for (int method = 0; method < NUM_SYMBOL_CODING_METHODS; ++method) { - // Test the encoding using all available symbol coding methods. - Options options; - SetSymbolEncodingMethod(&options, static_cast<SymbolCodingMethod>(method)); - - EncoderBuffer eb; - ASSERT_TRUE( - EncodeSymbols(in_values.data(), in_values.size(), 1, &options, &eb)); - std::vector<uint32_t> out_values; - out_values.resize(in_values.size()); - DecoderBuffer db; - db.Init(eb.data(), eb.size()); - db.set_bitstream_version(bitstream_version_); - ASSERT_TRUE(DecodeSymbols(in_values.size(), 1, &db, &out_values[0])); - for (uint32_t i = 0; i < in_values.size(); ++i) { - ASSERT_EQ(in_values[i], out_values[i]); - } - } -} - -TEST_F(SymbolCodingTest, TestEmpty) { - // This test verifies that SymbolCoding successfully encodes an empty array. - EncoderBuffer eb; - ASSERT_TRUE(EncodeSymbols(nullptr, 0, 1, nullptr, &eb)); - DecoderBuffer db; - db.Init(eb.data(), eb.size()); - db.set_bitstream_version(bitstream_version_); - ASSERT_TRUE(DecodeSymbols(0, 1, &db, nullptr)); -} - -TEST_F(SymbolCodingTest, TestOneSymbol) { - // This test verifies that SymbolCoding successfully encodes an a single - // symbol. - EncoderBuffer eb; - const std::vector<uint32_t> in(1200, 0); - ASSERT_TRUE(EncodeSymbols(in.data(), in.size(), 1, nullptr, &eb)); - - std::vector<uint32_t> out(in.size()); - DecoderBuffer db; - db.Init(eb.data(), eb.size()); - db.set_bitstream_version(bitstream_version_); - ASSERT_TRUE(DecodeSymbols(in.size(), 1, &db, &out[0])); - for (uint32_t i = 0; i < in.size(); ++i) { - ASSERT_EQ(in[i], out[i]); - } -} - -TEST_F(SymbolCodingTest, TestBitLengths) { - // This test verifies that SymbolCoding successfully encodes symbols of - // various bit lengths - EncoderBuffer eb; - std::vector<uint32_t> in; - constexpr int bit_lengths = 18; - for (int i = 0; i < bit_lengths; ++i) { - in.push_back(1 << i); - } - std::vector<uint32_t> out(in.size()); - for (int i = 0; i < bit_lengths; ++i) { - eb.Clear(); - ASSERT_TRUE(EncodeSymbols(in.data(), i + 1, 1, nullptr, &eb)); - DecoderBuffer db; - db.Init(eb.data(), eb.size()); - db.set_bitstream_version(bitstream_version_); - ASSERT_TRUE(DecodeSymbols(i + 1, 1, &db, &out[0])); - for (int j = 0; j < i + 1; ++j) { - ASSERT_EQ(in[j], out[j]); - } - } -} - -TEST_F(SymbolCodingTest, TestLargeNumberCondition) { - // This test verifies that SymbolCoding successfully encodes large symbols - // that are on the boundary between raw scheme and tagged scheme (18 bits). - EncoderBuffer eb; - constexpr int num_symbols = 1000000; - const std::vector<uint32_t> in(num_symbols, 1 << 18); - ASSERT_TRUE(EncodeSymbols(in.data(), in.size(), 1, nullptr, &eb)); - - std::vector<uint32_t> out(in.size()); - DecoderBuffer db; - db.Init(eb.data(), eb.size()); - db.set_bitstream_version(bitstream_version_); - ASSERT_TRUE(DecodeSymbols(in.size(), 1, &db, &out[0])); - for (uint32_t i = 0; i < in.size(); ++i) { - ASSERT_EQ(in[i], out[i]); - } -} - -TEST_F(SymbolCodingTest, TestConversionFullRange) { - TestConvertToSymbolAndBack(static_cast<int8_t>(-128)); - TestConvertToSymbolAndBack(static_cast<int8_t>(-127)); - TestConvertToSymbolAndBack(static_cast<int8_t>(-1)); - TestConvertToSymbolAndBack(static_cast<int8_t>(0)); - TestConvertToSymbolAndBack(static_cast<int8_t>(1)); - TestConvertToSymbolAndBack(static_cast<int8_t>(127)); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder_helpers.h b/extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder_helpers.h deleted file mode 100644 index 12ac46b3698..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_decoder_helpers.h +++ /dev/null @@ -1,84 +0,0 @@ -// 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. -// -#ifndef DRACO_COMPRESSION_MESH_MESH_DECODER_HELPERS_H_ -#define DRACO_COMPRESSION_MESH_MESH_DECODER_HELPERS_H_ - -#include "draco/compression/mesh/mesh_decoder.h" - -namespace draco { - -// Function for decoding a stream previously encoded by a MeshEncoder. The -// result is stored into a stream of single precision floating point numbers -// in a XYZ|UV format, where one value is stored for every corner of each -// triangle. -// On error, the function sets the input stream "is" to an invalid state. -template <typename InStreamT> -InStreamT &DecodePos3Tex2DataFromStream(InStreamT &&is, - std::vector<float> *out_data) { - // Determine the size of the encoded data and write it into a vector. - const auto start_pos = is.tellg(); - is.seekg(0, std::ios::end); - const std::streampos is_size = is.tellg() - start_pos; - is.seekg(start_pos); - std::vector<char> data(is_size); - is.read(&data[0], is_size); - - // Create a mesh from the data. - std::unique_ptr<Mesh> mesh = draco::DecodeMesh(&data[0], data.size()); - - if (mesh == nullptr) { - is.setstate(ios_base::badbit); - return is; - } - - const PointAttribute *pos_att = - mesh->GetNamedAttribute(GeometryAttribute::POSITION); - const PointAttribute *tex_att = - mesh->GetNamedAttribute(GeometryAttribute::TEX_COORD_0); - - // Both position and texture attributes must be present. - if (pos_att == nullptr || tex_att == nullptr) { - is.setstate(ios_base::badbit); - return is; - } - - // Copy the mesh data into the provided output. - constexpr int data_stride = 5; - // Prepare the output storage for 3 output values per face. - out_data->resize(mesh->num_faces() * 3 * data_stride); - - std::array<float, 3> pos_val; - std::array<float, 2> tex_val; - int out_it = 0; - for (int f = 0; f < mesh->num_faces(); ++f) { - const Mesh::Face &face = mesh->face(f); - for (int p = 0; p < 3; ++p) { - pos_att->ConvertValue<float, 3>(pos_att->mapped_index(face[p]), - &pos_val[0]); - memcpy(&out_data->at(0) + out_it, &pos_val[0], sizeof(pos_val)); - out_it += 3; - tex_att->ConvertValue<float, 2>(tex_att->mapped_index(face[p]), - &tex_val[0]); - memcpy(&out_data->at(0) + out_it, &tex_val[0], sizeof(tex_val)); - out_it += 2; - } - } - - return is; -} - -} // namespace draco - -#endif // DRACO_COMPRESSION_MESH_MESH_DECODER_HELPERS_H_ diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoding_test.cc b/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoding_test.cc deleted file mode 100644 index 8313882455b..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_edgebreaker_encoding_test.cc +++ /dev/null @@ -1,247 +0,0 @@ -// 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 <sstream> - -#include "draco/compression/encode.h" -#include "draco/compression/mesh/mesh_edgebreaker_decoder.h" -#include "draco/compression/mesh/mesh_edgebreaker_encoder.h" -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/io/mesh_io.h" -#include "draco/io/obj_decoder.h" -#include "draco/mesh/mesh_are_equivalent.h" -#include "draco/mesh/mesh_cleanup.h" -#include "draco/mesh/triangle_soup_mesh_builder.h" - -namespace draco { - -class MeshEdgebreakerEncodingTest : public ::testing::Test { - protected: - void TestFile(const std::string &file_name) { TestFile(file_name, -1); } - - void TestFile(const std::string &file_name, int compression_level) { - const std::unique_ptr<Mesh> mesh(ReadMeshFromTestFile(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - - TestMesh(mesh.get(), compression_level); - } - - void TestMesh(Mesh *mesh, int compression_level) { - EncoderBuffer buffer; - MeshEdgebreakerEncoder encoder; - EncoderOptions encoder_options = EncoderOptions::CreateDefaultOptions(); - encoder_options.SetSpeed(10 - compression_level, 10 - compression_level); - encoder.SetMesh(*mesh); - ASSERT_TRUE(encoder.Encode(encoder_options, &buffer).ok()); - - DecoderBuffer dec_buffer; - dec_buffer.Init(buffer.data(), buffer.size()); - MeshEdgebreakerDecoder decoder; - - std::unique_ptr<Mesh> decoded_mesh(new Mesh()); - DecoderOptions dec_options; - ASSERT_TRUE( - decoder.Decode(dec_options, &dec_buffer, decoded_mesh.get()).ok()); - - // Cleanup the input mesh to make sure that input and output can be - // compared (edgebreaker method discards degenerated triangles and isolated - // vertices). - const MeshCleanupOptions options; - MeshCleanup cleanup; - ASSERT_TRUE(cleanup(mesh, options)) << "Failed to clean the input mesh."; - - MeshAreEquivalent eq; - ASSERT_TRUE(eq(*mesh, *decoded_mesh.get())) - << "Decoded mesh is not the same as the input"; - } -}; - -TEST_F(MeshEdgebreakerEncodingTest, TestNmOBJ) { - const std::string file_name = "test_nm.obj"; - TestFile(file_name); -} - -TEST_F(MeshEdgebreakerEncodingTest, ThreeFacesOBJ) { - const std::string file_name = "extra_vertex.obj"; - TestFile(file_name); -} - -TEST_F(MeshEdgebreakerEncodingTest, TestPly) { - // Tests whether the edgebreaker successfully encodes and decodes the test - // file (ply with color). - const std::string file_name = "test_pos_color.ply"; - TestFile(file_name); -} - -TEST_F(MeshEdgebreakerEncodingTest, TestMultiAttributes) { - // Tests encoding of model with many attributes. - const std::string file_name = "cube_att.obj"; - TestFile(file_name, 10); -} - -TEST_F(MeshEdgebreakerEncodingTest, TestEncoderReuse) { - // Tests whether the edgebreaker encoder can be reused multiple times to - // encode a given mesh. - const std::string file_name = "test_pos_color.ply"; - const std::unique_ptr<Mesh> mesh(ReadMeshFromTestFile(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - - MeshEdgebreakerEncoder encoder; - EncoderOptions encoder_options = EncoderOptions::CreateDefaultOptions(); - encoder.SetMesh(*mesh); - EncoderBuffer buffer_0, buffer_1; - ASSERT_TRUE(encoder.Encode(encoder_options, &buffer_0).ok()); - ASSERT_TRUE(encoder.Encode(encoder_options, &buffer_1).ok()); - - // Make sure both buffer are identical. - ASSERT_EQ(buffer_0.size(), buffer_1.size()); - for (int i = 0; i < buffer_0.size(); ++i) { - ASSERT_EQ(buffer_0.data()[i], buffer_1.data()[i]); - } -} - -TEST_F(MeshEdgebreakerEncodingTest, TestDecoderReuse) { - // Tests whether the edgebreaker decoder can be reused multiple times to - // decode a given mesh. - const std::string file_name = "test_pos_color.ply"; - const std::unique_ptr<Mesh> mesh(ReadMeshFromTestFile(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - - MeshEdgebreakerEncoder encoder; - EncoderOptions encoder_options = EncoderOptions::CreateDefaultOptions(); - encoder.SetMesh(*mesh); - EncoderBuffer buffer; - ASSERT_TRUE(encoder.Encode(encoder_options, &buffer).ok()); - - DecoderBuffer dec_buffer; - dec_buffer.Init(buffer.data(), buffer.size()); - - MeshEdgebreakerDecoder decoder; - - // Decode the mesh two times. - std::unique_ptr<Mesh> decoded_mesh_0(new Mesh()); - DecoderOptions dec_options; - ASSERT_TRUE( - decoder.Decode(dec_options, &dec_buffer, decoded_mesh_0.get()).ok()); - - dec_buffer.Init(buffer.data(), buffer.size()); - std::unique_ptr<Mesh> decoded_mesh_1(new Mesh()); - ASSERT_TRUE( - decoder.Decode(dec_options, &dec_buffer, decoded_mesh_1.get()).ok()); - - // Make sure both of the meshes are identical. - MeshAreEquivalent eq; - ASSERT_TRUE(eq(*decoded_mesh_0.get(), *decoded_mesh_1.get())) - << "Decoded meshes are not the same"; -} - -TEST_F(MeshEdgebreakerEncodingTest, TestSingleConnectivityEncoding) { - // Tests whether the edgebreaker method successfully encodes a mesh with - // multiple attributes using single connectivity by breaking the mesh along - // attribute seams. - const std::string file_name = "cube_att.obj"; - const std::unique_ptr<Mesh> mesh(ReadMeshFromTestFile(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - - for (int i = 0; i < 2; ++i) { - // Set the option to enable/disable single connectivity encoding. - EncoderOptionsBase<GeometryAttribute::Type> options = - EncoderOptionsBase<GeometryAttribute::Type>::CreateDefaultOptions(); - options.SetGlobalBool("split_mesh_on_seams", i == 0 ? true : false); - - EncoderBuffer buffer; - draco::Encoder encoder; - encoder.Reset(options); - encoder.SetSpeedOptions(0, 0); - encoder.SetAttributeQuantization(GeometryAttribute::POSITION, 8); - encoder.SetAttributeQuantization(GeometryAttribute::TEX_COORD, 8); - encoder.SetAttributeQuantization(GeometryAttribute::NORMAL, 8); - encoder.SetEncodingMethod(MESH_EDGEBREAKER_ENCODING); - ASSERT_TRUE(encoder.EncodeMeshToBuffer(*mesh, &buffer).ok()); - - DecoderBuffer dec_buffer; - dec_buffer.Init(buffer.data(), buffer.size()); - - Decoder decoder; - auto dec_mesh = decoder.DecodeMeshFromBuffer(&dec_buffer).value(); - ASSERT_NE(dec_mesh, nullptr); - ASSERT_EQ(dec_mesh->num_points(), 24); - ASSERT_EQ(dec_mesh->num_attributes(), 3); - ASSERT_EQ(dec_mesh->attribute(0)->size(), i == 0 ? 24 : 8); - ASSERT_EQ(dec_mesh->attribute(1)->size(), 24); - ASSERT_EQ(dec_mesh->attribute(2)->size(), 24); - } -} - -TEST_F(MeshEdgebreakerEncodingTest, TestWrongAttributeOrder) { - // Tests whether the edgebreaker method successfully encodes a mesh where the - // input attributes are in wrong order (because of their internal - // dependencies). In such case the attributes should be rearranged to the - // correct order. - TriangleSoupMeshBuilder mb; - mb.Start(1); - const int32_t norm_att_id = - mb.AddAttribute(GeometryAttribute::NORMAL, 3, DT_FLOAT32); - const int32_t pos_att_id = - mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - - mb.SetAttributeValuesForFace( - pos_att_id, FaceIndex(0), Vector3f(0.f, 0.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), Vector3f(0.f, 1.f, 0.f).data()); - - mb.SetAttributeValuesForFace( - norm_att_id, FaceIndex(0), Vector3f(0.f, 0.f, 1.f).data(), - Vector3f(0.f, 0.f, 0.f).data(), Vector3f(0.f, 0.f, 1.f).data()); - std::unique_ptr<Mesh> mesh = mb.Finalize(); - ASSERT_NE(mesh, nullptr); - ASSERT_EQ(mesh->num_attributes(), 2); - ASSERT_EQ(mesh->attribute(0)->attribute_type(), GeometryAttribute::NORMAL); - ASSERT_EQ(mesh->attribute(1)->attribute_type(), GeometryAttribute::POSITION); - - EncoderBuffer buffer; - draco::Encoder encoder; - encoder.SetSpeedOptions(3, 3); - encoder.SetAttributeQuantization(GeometryAttribute::POSITION, 8); - encoder.SetAttributeQuantization(GeometryAttribute::NORMAL, 8); - encoder.SetEncodingMethod(MESH_EDGEBREAKER_ENCODING); - ASSERT_TRUE(encoder.EncodeMeshToBuffer(*mesh, &buffer).ok()); - - DecoderBuffer dec_buffer; - dec_buffer.Init(buffer.data(), buffer.size()); - - Decoder decoder; - auto dec_mesh = decoder.DecodeMeshFromBuffer(&dec_buffer).value(); - ASSERT_NE(dec_mesh, nullptr); - ASSERT_EQ(dec_mesh->num_attributes(), 2); - ASSERT_EQ(dec_mesh->attribute(0)->attribute_type(), - GeometryAttribute::POSITION); - ASSERT_EQ(dec_mesh->attribute(1)->attribute_type(), - GeometryAttribute::NORMAL); -} - -TEST_F(MeshEdgebreakerEncodingTest, TestDegenerateMesh) { - // Tests whether we can process a mesh that contains degenerate faces only. - const std::string file_name = "degenerate_mesh.obj"; - const std::unique_ptr<Mesh> mesh(ReadMeshFromTestFile(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - EncoderBuffer buffer; - MeshEdgebreakerEncoder encoder; - EncoderOptions encoder_options = EncoderOptions::CreateDefaultOptions(); - encoder.SetMesh(*mesh); - // We expect the encoding to fail as edgebreaker can only process valid faces. - ASSERT_FALSE(encoder.Encode(encoder_options, &buffer).ok()); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder_helpers.h b/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder_helpers.h deleted file mode 100644 index d809a521369..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder_helpers.h +++ /dev/null @@ -1,81 +0,0 @@ -// 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. -// -#ifndef DRACO_COMPRESSION_MESH_MESH_ENCODER_HELPERS_H_ -#define DRACO_COMPRESSION_MESH_MESH_ENCODER_HELPERS_H_ - -#include "draco/compression/mesh/mesh_encoder.h" -#include "draco/mesh/triangle_soup_mesh_builder.h" - -namespace draco { - -// Helper class for encoding data supplied in a stream of single precision -// floating point numbers formatted as XYZ|UV. The stream must contain three -// XYZ|UV values for every face of the mesh. -// The encoded data is written into the output stream "os". -// In case of error, the stream is set to an invalid state (ios_base::bad_bit). -template <typename OStreamT> -OStreamT EncodePos3Tex2DataToStream( - const float *data, int num_faces, CompressionMethod method, - const MeshCompressionOptions &compression_options, - const MeshAttributeCompressionOptions &pos_options, - const MeshAttributeCompressionOptions &tex_options, OStreamT &&os) { - // Build the mesh. - TriangleSoupMeshBuilder mb; - mb.Start(num_faces); - const int pos_att_id = - mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - const int tex_att_id = - mb.AddAttribute(GeometryAttribute::TEX_COORD_0, 2, DT_FLOAT32); - constexpr int data_stride = 5; - constexpr int tex_offset = 3; - for (int f = 0; f < num_faces; ++f) { - int offset = 3 * f * data_stride; - // Add position data for the face. - mb.SetAttributeValuesForFace(pos_att_id, f, data + offset, - data + offset + data_stride, - data + offset + 2 * data_stride); - // Add texture data for the face. - offset += tex_offset; - mb.SetAttributeValuesForFace(tex_att_id, f, data + offset, - data + offset + data_stride, - data + offset + 2 * data_stride); - } - std::unique_ptr<Mesh> mesh = mb.Finalize(); - if (mesh == nullptr) { - os.setstate(ios_base::badbit); - return os; - } - - // Set up the encoder. - std::unique_ptr<MeshEncoder> encoder = - MeshEncoder::CreateEncoderForMethod(method); - encoder->SetGlobalOptions(compression_options); - encoder->SetAttributeOptions(GeometryAttribute::POSITION, pos_options); - encoder->SetAttributeOptions(GeometryAttribute::TEX_COORD_0, tex_options); - - if (!encoder->EncodeMesh(mesh.get())) { - os.setstate(ios_base::badbit); - return os; - } - - // Write the encoded data into the stream. - os.write(static_cast<const char *>(encoder->buffer()->data()), - encoder->buffer()->size()); - return os; -} - -} // namespace draco - -#endif // DRACO_COMPRESSION_MESH_MESH_ENCODER_HELPERS_H_ diff --git a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder_test.cc b/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder_test.cc deleted file mode 100644 index 9f056fc22e3..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/mesh/mesh_encoder_test.cc +++ /dev/null @@ -1,93 +0,0 @@ -// 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 "draco/compression/mesh/mesh_encoder.h" - -#include "draco/compression/expert_encode.h" -#include "draco/core/decoder_buffer.h" -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/io/obj_decoder.h" - -namespace draco { - -class MeshEncoderTest : public ::testing::TestWithParam<const char *> { - protected: - MeshEncoderTest() {} - - // Fills out_method with id of the encoding method used for the test. - // Returns false if the encoding method is not set properly. - bool GetMethod(MeshEncoderMethod *out_method) const { - if (strcmp(GetParam(), "sequential") == 0) { - *out_method = MESH_SEQUENTIAL_ENCODING; - return true; - } - if (strcmp(GetParam(), "edgebreaker") == 0) { - *out_method = MESH_EDGEBREAKER_ENCODING; - return true; - } - return false; - } -}; - -TEST_P(MeshEncoderTest, EncodeGoldenMesh) { - // This test verifies that a given set of meshes are encoded to an expected - // output. This is useful for catching bugs in code changes that are not - // supposed to change the encoding. - // The test is expected to fail when the encoding is modified. In such case, - // the golden files need to be updated to reflect the changes. - MeshEncoderMethod method; - ASSERT_TRUE(GetMethod(&method)) - << "Test is run for an unknown encoding method"; - - const std::string file_name = "test_nm.obj"; - std::string golden_file_name = file_name; - golden_file_name += '.'; - golden_file_name += GetParam(); - golden_file_name += ".1.2.0.drc"; - const std::unique_ptr<Mesh> mesh(ReadMeshFromTestFile(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - - ExpertEncoder encoder(*mesh.get()); - encoder.SetEncodingMethod(method); - encoder.SetAttributeQuantization(0, 20); - EncoderBuffer buffer; - ASSERT_TRUE(encoder.EncodeToBuffer(&buffer).ok()) - << "Failed encoding test mesh " << file_name << " with method " - << GetParam(); - // Check that the encoded mesh was really encoded with the selected method. - DecoderBuffer decoder_buffer; - decoder_buffer.Init(buffer.data(), buffer.size()); - decoder_buffer.Advance(8); // Skip the header to the encoding method id. - uint8_t encoded_method; - decoder_buffer.Decode(&encoded_method); - ASSERT_EQ(encoded_method, method); - if (!FLAGS_update_golden_files) { - EXPECT_TRUE( - CompareGoldenFile(golden_file_name, buffer.data(), buffer.size())) - << "Encoded data is different from the golden file. Please verify that " - "the encoding works as expected and update the golden file if " - "necessary (run the test with --update_golden_files flag)."; - } else { - // Save the files into the local folder. - EXPECT_TRUE( - GenerateGoldenFile(golden_file_name, buffer.data(), buffer.size())) - << "Failed to generate new golden file for " << file_name; - } -} - -INSTANTIATE_TEST_SUITE_P(MeshEncoderTests, MeshEncoderTest, - ::testing::Values("sequential", "edgebreaker")); - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoding_test.cc b/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoding_test.cc deleted file mode 100644 index 6156cfe02b5..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_kd_tree_encoding_test.cc +++ /dev/null @@ -1,456 +0,0 @@ -// 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 "draco/compression/point_cloud/point_cloud_kd_tree_decoder.h" -#include "draco/compression/point_cloud/point_cloud_kd_tree_encoder.h" -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/core/vector_d.h" -#include "draco/io/obj_decoder.h" -#include "draco/point_cloud/point_cloud_builder.h" - -namespace draco { - -class PointCloudKdTreeEncodingTest : public ::testing::Test { - protected: - void ComparePointClouds(const PointCloud &p0, const PointCloud &p1) const { - ASSERT_EQ(p0.num_points(), p1.num_points()); - ASSERT_EQ(p0.num_attributes(), p1.num_attributes()); - // Currently works only with one attribute. - ASSERT_EQ(p0.num_attributes(), p1.num_attributes()); - for (auto index = 0; index < p0.num_attributes(); index += 1) { - ASSERT_EQ(p0.attribute(index)->num_components(), - p1.attribute(index)->num_components()); - std::vector<double> points_0, points_1; - std::vector<double> att_entry_0(p0.attribute(index)->num_components()); - std::vector<double> att_entry_1(p0.attribute(index)->num_components()); - for (PointIndex i(0); i < p0.num_points(); ++i) { - p0.attribute(index)->ConvertValue(p0.attribute(index)->mapped_index(i), - &att_entry_0[0]); - p1.attribute(index)->ConvertValue(p1.attribute(index)->mapped_index(i), - &att_entry_1[0]); - for (int d = 0; d < p0.attribute(index)->num_components(); ++d) { - points_0.push_back(att_entry_0[d]); - points_1.push_back(att_entry_1[d]); - } - } - // To compare the point clouds we sort points components from both inputs - // separately, and then we compare all matching coordinates one by one. - // TODO(ostava): Note that this is not guaranteed to work for quantized - // point clouds because the order of points may actually change because - // of the quantization. The test should be make more robust to handle such - // case. - std::sort(points_0.begin(), points_0.end()); - std::sort(points_1.begin(), points_1.end()); - for (uint32_t i = 0; i < points_0.size(); ++i) { - ASSERT_LE(std::fabs(points_0[i] - points_1[i]), 1e-2); - } - } - } - - void TestKdTreeEncoding(const PointCloud &pc) { - EncoderBuffer buffer; - PointCloudKdTreeEncoder encoder; - EncoderOptions options = EncoderOptions::CreateDefaultOptions(); - options.SetGlobalInt("quantization_bits", 16); - for (int compression_level = 0; compression_level <= 6; - ++compression_level) { - options.SetSpeed(10 - compression_level, 10 - compression_level); - encoder.SetPointCloud(pc); - ASSERT_TRUE(encoder.Encode(options, &buffer).ok()); - - DecoderBuffer dec_buffer; - dec_buffer.Init(buffer.data(), buffer.size()); - PointCloudKdTreeDecoder decoder; - - std::unique_ptr<PointCloud> out_pc(new PointCloud()); - DecoderOptions dec_options; - ASSERT_TRUE(decoder.Decode(dec_options, &dec_buffer, out_pc.get()).ok()); - - ComparePointClouds(pc, *out_pc); - } - } - - void TestFloatEncoding(const std::string &file_name) { - std::unique_ptr<PointCloud> pc = ReadPointCloudFromTestFile(file_name); - ASSERT_NE(pc, nullptr); - - TestKdTreeEncoding(*pc.get()); - } -}; - -TEST_F(PointCloudKdTreeEncodingTest, TestFloatKdTreeEncoding) { - TestFloatEncoding("cube_subd.obj"); -} - -TEST_F(PointCloudKdTreeEncodingTest, TestIntKdTreeEncoding) { - constexpr int num_points = 120; - std::vector<std::array<uint32_t, 3>> points(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint32_t, 3> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127); - pos[1] = 13 * ((i * 3) % 321); - pos[2] = 29 * ((i * 19) % 450); - points[i] = pos; - } - - PointCloudBuilder builder; - builder.Start(num_points); - const int att_id = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_UINT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id, PointIndex(i), - &(points[i.value()])[0]); - } - std::unique_ptr<PointCloud> pc = builder.Finalize(false); - ASSERT_NE(pc, nullptr); - - TestKdTreeEncoding(*pc); -} - -// test higher dimensions with more attributes -TEST_F(PointCloudKdTreeEncodingTest, TestIntKdTreeEncodingHigherDimension) { - constexpr int num_points = 120; - std::vector<std::array<uint32_t, 3>> points3(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint32_t, 3> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127); - pos[1] = 13 * ((i * 3) % 321); - pos[2] = 29 * ((i * 19) % 450); - points3[i] = pos; - } - std::vector<std::array<uint32_t, 2>> points2(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint32_t, 2> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127) + 1; - pos[1] = 13 * ((i * 3) % 321) + 1; - points2[i] = pos; - } - std::vector<std::array<uint32_t, 1>> points1(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint32_t, 1> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127) + 11; - points1[i] = pos; - } - - PointCloudBuilder builder; - builder.Start(num_points); - const int att_id3 = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_UINT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id3, PointIndex(i), - &(points3[i.value()])[0]); - } - const int att_id2 = - builder.AddAttribute(GeometryAttribute::POSITION, 2, DT_UINT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id2, PointIndex(i), - &(points2[i.value()])[0]); - } - const int att_id1 = - builder.AddAttribute(GeometryAttribute::GENERIC, 1, DT_UINT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id1, PointIndex(i), - &(points1[i.value()])[0]); - } - - std::unique_ptr<PointCloud> pc = builder.Finalize(false); - ASSERT_NE(pc, nullptr); - - TestKdTreeEncoding(*pc); -} - -// Test 16 and 8 bit encoding. -TEST_F(PointCloudKdTreeEncodingTest, - TestIntKdTreeEncodingHigherDimensionVariedTypes) { - constexpr int num_points = 120; - std::vector<std::array<uint32_t, 3>> points3(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint32_t, 3> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127); - pos[1] = 13 * ((i * 3) % 321); - pos[2] = 29 * ((i * 19) % 450); - points3[i] = pos; - } - std::vector<std::array<uint16_t, 2>> points2(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint16_t, 2> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127) + 1; - pos[1] = 13 * ((i * 3) % 321) + 1; - points2[i] = pos; - } - std::vector<std::array<uint8_t, 1>> points1(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint8_t, 1> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127) + 11; - points1[i] = pos; - } - - PointCloudBuilder builder; - builder.Start(num_points); - const int att_id3 = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_UINT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id3, PointIndex(i), - &(points3[i.value()])[0]); - } - const int att_id2 = - builder.AddAttribute(GeometryAttribute::POSITION, 2, DT_UINT16); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id2, PointIndex(i), - &(points2[i.value()])[0]); - } - const int att_id1 = - builder.AddAttribute(GeometryAttribute::GENERIC, 1, DT_UINT8); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id1, PointIndex(i), - &(points1[i.value()])[0]); - } - - std::unique_ptr<PointCloud> pc = builder.Finalize(false); - ASSERT_NE(pc, nullptr); - - TestKdTreeEncoding(*pc); -} - -// Test 16 only encoding for one attribute. -TEST_F(PointCloudKdTreeEncodingTest, TestIntKdTreeEncoding16Bit) { - constexpr int num_points = 120; - std::vector<std::array<uint16_t, 3>> points3(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint16_t, 3> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127); - pos[1] = 13 * ((i * 3) % 321); - pos[2] = 29 * ((i * 19) % 450); - points3[i] = pos; - } - - PointCloudBuilder builder; - builder.Start(num_points); - const int att_id3 = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_UINT16); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id3, PointIndex(i), - &(points3[i.value()])[0]); - } - - std::unique_ptr<PointCloud> pc = builder.Finalize(false); - ASSERT_NE(pc, nullptr); - - TestKdTreeEncoding(*pc); -} - -// Test 16 and 8 bit encoding with size bigger than 32bit encoding. -TEST_F(PointCloudKdTreeEncodingTest, - TestIntKdTreeEncodingHigherDimensionVariedTypesBig16BitEncoding) { - constexpr int num_points = 120; - std::vector<std::array<uint32_t, 3>> points3(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint32_t, 3> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127); - pos[1] = 13 * ((i * 3) % 321); - pos[2] = 29 * ((i * 19) % 450); - points3[i] = pos; - } - // The total size of the 16bit encoding must be bigger than the total size of - // the 32bit encoding. - std::vector<std::array<uint16_t, 7>> points7(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint16_t, 7> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127) + 1; - pos[1] = 13 * ((i * 3) % 321) + 1; - pos[2] = pos[0] + 13; - pos[3] = pos[2] + 13; - pos[4] = pos[3] + 13; - pos[5] = pos[4] + 13; - pos[6] = pos[5] + 13; - points7[i] = pos; - } - std::vector<std::array<uint8_t, 1>> points1(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint8_t, 1> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127) + 11; - points1[i] = pos; - } - - PointCloudBuilder builder; - builder.Start(num_points); - const int att_id3 = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_UINT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id3, PointIndex(i), - &(points3[i.value()])[0]); - } - const int att_id2 = - builder.AddAttribute(GeometryAttribute::POSITION, 7, DT_UINT16); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id2, PointIndex(i), - &(points7[i.value()])[0]); - } - const int att_id1 = - builder.AddAttribute(GeometryAttribute::GENERIC, 1, DT_UINT8); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id1, PointIndex(i), - &(points1[i.value()])[0]); - } - - std::unique_ptr<PointCloud> pc = builder.Finalize(false); - ASSERT_NE(pc, nullptr); - - TestKdTreeEncoding(*pc); -} - -// Test encoding of quantized values. -TEST_F(PointCloudKdTreeEncodingTest, - TestIntKdTreeEncodingHigherDimensionFloatTypes) { - constexpr int num_points = 130; - std::vector<std::array<uint32_t, 3>> points3(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint32_t, 3> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 125); - pos[1] = 13 * ((i * 3) % 334); - pos[2] = 29 * ((i * 19) % 470); - points3[i] = pos; - } - std::vector<std::array<float, 2>> points_float(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<float, 2> pos; - // Generate some pseudo-random points. - pos[0] = static_cast<float>(8 * ((i * 7) % 127) + 1) / 2.5f; - pos[1] = static_cast<float>(13 * ((i * 3) % 321) + 1) / 3.2f; - points_float[i] = pos; - } - - PointCloudBuilder builder; - builder.Start(num_points); - const int att_id3 = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_UINT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id3, PointIndex(i), - &(points3[i.value()])[0]); - } - const int att_id_float = - builder.AddAttribute(GeometryAttribute::GENERIC, 2, DT_FLOAT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id_float, PointIndex(i), - &(points_float[i.value()])[0]); - } - - std::unique_ptr<PointCloud> pc = builder.Finalize(false); - ASSERT_NE(pc, nullptr); - - TestKdTreeEncoding(*pc); -} - -// Test encoding of signed integer values -TEST_F(PointCloudKdTreeEncodingTest, TestIntKdTreeEncodingSignedTypes) { - constexpr int num_points = 120; - std::vector<std::array<uint32_t, 3>> points3(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint32_t, 3> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127); - pos[1] = 13 * ((i * 3) % 321); - pos[2] = 29 * ((i * 19) % 450); - points3[i] = pos; - } - std::vector<std::array<int32_t, 2>> points2(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<int32_t, 2> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127) + 1; - if (i % 3 == 0) - pos[0] = -pos[0]; - pos[1] = 13 * ((i * 3) % 321) + 1; - points2[i] = pos; - } - std::vector<std::array<int16_t, 1>> points1(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<int16_t, 1> pos; - // Generate some pseudo-random points. - pos[0] = 8 * ((i * 7) % 127) + 11; - if (i % 5 == 0) - pos[0] = -pos[0]; - points1[i] = pos; - } - - PointCloudBuilder builder; - builder.Start(num_points); - const int att_id3 = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_UINT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id3, PointIndex(i), - &(points3[i.value()])[0]); - } - const int att_id2 = - builder.AddAttribute(GeometryAttribute::POSITION, 2, DT_INT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id2, PointIndex(i), - &(points2[i.value()])[0]); - } - - const int att_id1 = - builder.AddAttribute(GeometryAttribute::GENERIC, 1, DT_INT16); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id1, PointIndex(i), - &(points1[i.value()])[0]); - } - - std::unique_ptr<PointCloud> pc = builder.Finalize(false); - ASSERT_NE(pc, nullptr); - - TestKdTreeEncoding(*pc); -} - -// Test encoding of integer point clouds with > 16 dimensions. -TEST_F(PointCloudKdTreeEncodingTest, TestIntKdTreeEncodingHighDimensional) { - constexpr int num_points = 120; - constexpr int num_dims = 42; - std::vector<std::array<uint32_t, num_dims>> points(num_points); - for (int i = 0; i < num_points; ++i) { - std::array<uint32_t, num_dims> pos; - // Generate some pseudo-random points. - for (int d = 0; d < num_dims; ++d) { - pos[d] = 8 * ((i + d) * (7 + (d % 4)) % (127 + d % 3)); - } - points[i] = pos; - } - PointCloudBuilder builder; - builder.Start(num_points); - const int att_id = - builder.AddAttribute(GeometryAttribute::POSITION, num_dims, DT_UINT32); - for (PointIndex i(0); i < num_points; ++i) { - builder.SetAttributeValueForPoint(att_id, PointIndex(i), - &(points[i.value()])[0]); - } - - std::unique_ptr<PointCloud> pc = builder.Finalize(false); - ASSERT_NE(pc, nullptr); - - TestKdTreeEncoding(*pc); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoding_test.cc b/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoding_test.cc deleted file mode 100644 index beab4bcd7e9..00000000000 --- a/extern/draco/dracoenc/src/draco/compression/point_cloud/point_cloud_sequential_encoding_test.cc +++ /dev/null @@ -1,90 +0,0 @@ -// 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 "draco/compression/point_cloud/point_cloud_sequential_decoder.h" -#include "draco/compression/point_cloud/point_cloud_sequential_encoder.h" -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/io/obj_decoder.h" - -namespace draco { - -class PointCloudSequentialEncodingTest : public ::testing::Test { - protected: - std::unique_ptr<PointCloud> EncodeAndDecodePointCloud(const PointCloud *pc) { - EncoderBuffer buffer; - PointCloudSequentialEncoder encoder; - EncoderOptions options = EncoderOptions::CreateDefaultOptions(); - encoder.SetPointCloud(*pc); - if (!encoder.Encode(options, &buffer).ok()) - return nullptr; - - DecoderBuffer dec_buffer; - dec_buffer.Init(buffer.data(), buffer.size()); - PointCloudSequentialDecoder decoder; - - std::unique_ptr<PointCloud> out_pc(new PointCloud()); - DecoderOptions dec_options; - if (!decoder.Decode(dec_options, &dec_buffer, out_pc.get()).ok()) - return nullptr; - return out_pc; - } - - void TestEncoding(const std::string &file_name) { - std::unique_ptr<PointCloud> pc = ReadPointCloudFromTestFile(file_name); - ASSERT_NE(pc, nullptr); - - std::unique_ptr<PointCloud> decoded_pc = - EncodeAndDecodePointCloud(pc.get()); - ASSERT_NE(decoded_pc.get(), nullptr); - ASSERT_EQ(decoded_pc->num_points(), pc->num_points()); - } -}; - -TEST_F(PointCloudSequentialEncodingTest, DoesEncodeAndDecode) { - TestEncoding("test_nm.obj"); -} - -TEST_F(PointCloudSequentialEncodingTest, EncodingPointCloudWithMetadata) { - std::unique_ptr<PointCloud> pc = ReadPointCloudFromTestFile("test_nm.obj"); - ASSERT_NE(pc, nullptr); - // Add metadata to point cloud. - std::unique_ptr<GeometryMetadata> metadata = - std::unique_ptr<GeometryMetadata>(new GeometryMetadata()); - const uint32_t pos_att_id = - pc->GetNamedAttributeId(GeometryAttribute::POSITION); - std::unique_ptr<AttributeMetadata> pos_metadata = - std::unique_ptr<AttributeMetadata>(new AttributeMetadata()); - pos_metadata->AddEntryString("name", "position"); - pc->AddAttributeMetadata(pos_att_id, std::move(pos_metadata)); - - std::unique_ptr<PointCloud> decoded_pc = EncodeAndDecodePointCloud(pc.get()); - ASSERT_NE(decoded_pc.get(), nullptr); - - const GeometryMetadata *const pc_metadata = decoded_pc->GetMetadata(); - ASSERT_NE(pc_metadata, nullptr); - // Test getting attribute metadata by id. - ASSERT_NE(pc->GetAttributeMetadataByAttributeId(pos_att_id), nullptr); - // Test getting attribute metadata by entry name value pair. - const AttributeMetadata *const requested_att_metadata = - pc_metadata->GetAttributeMetadataByStringEntry("name", "position"); - ASSERT_NE(requested_att_metadata, nullptr); - ASSERT_EQ(requested_att_metadata->att_unique_id(), - pc->attribute(pos_att_id)->unique_id()); -} - -// TODO(ostava): Test the reusability of a single instance of the encoder and -// decoder class. - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/core/buffer_bit_coding_test.cc b/extern/draco/dracoenc/src/draco/core/buffer_bit_coding_test.cc deleted file mode 100644 index e761284e236..00000000000 --- a/extern/draco/dracoenc/src/draco/core/buffer_bit_coding_test.cc +++ /dev/null @@ -1,116 +0,0 @@ -// 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 "draco/core/decoder_buffer.h" -#include "draco/core/encoder_buffer.h" - -#include "draco/core/draco_test_base.h" - -namespace draco { - -class BufferBitCodingTest : public ::testing::Test { - public: - typedef DecoderBuffer::BitDecoder BitDecoder; - typedef EncoderBuffer::BitEncoder BitEncoder; -}; - -TEST_F(BufferBitCodingTest, TestBitCodersByteAligned) { - constexpr int buffer_size = 32; - char buffer[buffer_size]; - BitEncoder encoder(buffer); - const uint8_t data[] = {0x76, 0x54, 0x32, 0x10, 0x76, 0x54, 0x32, 0x10}; - const int bytes_to_encode = sizeof(data); - - for (int i = 0; i < bytes_to_encode; ++i) { - encoder.PutBits(data[i], sizeof(data[i]) * 8); - ASSERT_EQ((i + 1) * sizeof(data[i]) * 8, encoder.Bits()); - } - - BitDecoder decoder; - decoder.reset(static_cast<const void *>(buffer), bytes_to_encode); - for (int i = 0; i < bytes_to_encode; ++i) { - uint32_t x = 0; - ASSERT_TRUE(decoder.GetBits(8, &x)); - ASSERT_EQ(x, data[i]); - } - - ASSERT_EQ(bytes_to_encode * 8u, decoder.BitsDecoded()); -} - -TEST_F(BufferBitCodingTest, TestBitCodersNonByte) { - constexpr int buffer_size = 32; - char buffer[buffer_size]; - BitEncoder encoder(buffer); - const uint8_t data[] = {0x76, 0x54, 0x32, 0x10, 0x76, 0x54, 0x32, 0x10}; - const uint32_t bits_to_encode = 51; - const int bytes_to_encode = (bits_to_encode / 8) + 1; - - for (int i = 0; i < bytes_to_encode; ++i) { - const int num_bits = (encoder.Bits() + 8 <= bits_to_encode) - ? 8 - : bits_to_encode - encoder.Bits(); - encoder.PutBits(data[i], num_bits); - } - - BitDecoder decoder; - decoder.reset(static_cast<const void *>(buffer), bytes_to_encode); - int64_t bits_to_decode = encoder.Bits(); - for (int i = 0; i < bytes_to_encode; ++i) { - uint32_t x = 0; - const int num_bits = (bits_to_decode > 8) ? 8 : bits_to_decode; - ASSERT_TRUE(decoder.GetBits(num_bits, &x)); - const int bits_to_shift = 8 - num_bits; - const uint8_t test_byte = - ((data[i] << bits_to_shift) & 0xff) >> bits_to_shift; - ASSERT_EQ(x, test_byte); - bits_to_decode -= 8; - } - - ASSERT_EQ(bits_to_encode, decoder.BitsDecoded()); -} - -TEST_F(BufferBitCodingTest, TestSingleBits) { - const int data = 0xaaaa; - - BitDecoder decoder; - decoder.reset(static_cast<const void *>(&data), sizeof(data)); - - for (uint32_t i = 0; i < 16; ++i) { - uint32_t x = 0; - ASSERT_TRUE(decoder.GetBits(1, &x)); - ASSERT_EQ(x, (i % 2)); - } - - ASSERT_EQ(16u, decoder.BitsDecoded()); -} - -TEST_F(BufferBitCodingTest, TestMultipleBits) { - const uint8_t data[] = {0x76, 0x54, 0x32, 0x10, 0x76, 0x54, 0x32, 0x10}; - - BitDecoder decoder; - decoder.reset(static_cast<const void *>(data), sizeof(data)); - - uint32_t x = 0; - for (uint32_t i = 0; i < 2; ++i) { - ASSERT_TRUE(decoder.GetBits(16, &x)); - ASSERT_EQ(x, 0x5476u); - ASSERT_EQ(16 + (i * 32), decoder.BitsDecoded()); - - ASSERT_TRUE(decoder.GetBits(16, &x)); - ASSERT_EQ(x, 0x1032u); - ASSERT_EQ(32 + (i * 32), decoder.BitsDecoded()); - } -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/core/draco_test_base.h b/extern/draco/dracoenc/src/draco/core/draco_test_base.h deleted file mode 100644 index f5c9d751e03..00000000000 --- a/extern/draco/dracoenc/src/draco/core/draco_test_base.h +++ /dev/null @@ -1,11 +0,0 @@ -// Wrapper for including googletest indirectly. Useful when the location of the -// googletest sources must change depending on build environment and repository -// source location. -#ifndef DRACO_CORE_DRACO_TEST_BASE_H_ -#define DRACO_CORE_DRACO_TEST_BASE_H_ - -static bool FLAGS_update_golden_files; -#include "gtest/gtest.h" -#include "testing/draco_test_config.h" - -#endif // DRACO_CORE_DRACO_TEST_BASE_H_ diff --git a/extern/draco/dracoenc/src/draco/core/draco_test_utils.cc b/extern/draco/dracoenc/src/draco/core/draco_test_utils.cc deleted file mode 100644 index a39e19f6b15..00000000000 --- a/extern/draco/dracoenc/src/draco/core/draco_test_utils.cc +++ /dev/null @@ -1,83 +0,0 @@ -// 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 "draco/core/draco_test_utils.h" - -#include <fstream> - -#include "draco/core/macros.h" -#include "draco_test_base.h" - -namespace draco { - -namespace { -static constexpr char kTestDataDir[] = DRACO_TEST_DATA_DIR; -static constexpr char kTestTempDir[] = DRACO_TEST_TEMP_DIR; -} // namespace - -std::string GetTestFileFullPath(const std::string &file_name) { - return std::string(kTestDataDir) + std::string("/") + file_name; -} - -std::string GetTestTempFileFullPath(const std::string &file_name) { - return std::string(kTestTempDir) + std::string("/") + file_name; -} - -bool GenerateGoldenFile(const std::string &golden_file_name, const void *data, - int data_size) { - const std::string path = GetTestFileFullPath(golden_file_name); - std::ofstream file(path, std::ios::binary); - if (!file) - return false; - file.write(static_cast<const char *>(data), data_size); - file.close(); - return true; -} - -bool CompareGoldenFile(const std::string &golden_file_name, const void *data, - int data_size) { - const std::string golden_path = GetTestFileFullPath(golden_file_name); - std::ifstream in_file(golden_path, std::ios::binary); - if (!in_file || data_size < 0) - return false; - const char *const data_c8 = static_cast<const char *>(data); - constexpr int buffer_size = 1024; - char buffer[buffer_size]; - size_t extracted_size = 0; - size_t remaining_data_size = data_size; - int offset = 0; - while ((extracted_size = in_file.read(buffer, buffer_size).gcount()) > 0) { - if (remaining_data_size <= 0) - break; // Input and golden sizes are different. - size_t size_to_check = extracted_size; - if (remaining_data_size < size_to_check) - size_to_check = remaining_data_size; - for (uint32_t i = 0; i < size_to_check; ++i) { - if (buffer[i] != data_c8[offset++]) { - LOG(INFO) << "Test output differed from golden file at byte " - << offset - 1; - return false; - } - } - remaining_data_size -= extracted_size; - } - if (remaining_data_size != extracted_size) { - // Both of these values should be 0 at the end. - LOG(INFO) << "Test output size differed from golden file size"; - return false; - } - return true; -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/core/draco_test_utils.h b/extern/draco/dracoenc/src/draco/core/draco_test_utils.h deleted file mode 100644 index 3113a5d2676..00000000000 --- a/extern/draco/dracoenc/src/draco/core/draco_test_utils.h +++ /dev/null @@ -1,70 +0,0 @@ -// 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. -// -#ifndef DRACO_CORE_DRACO_TEST_UTILS_H_ -#define DRACO_CORE_DRACO_TEST_UTILS_H_ - -#include "draco/core/draco_test_base.h" -#include "draco/io/mesh_io.h" -#include "draco/io/point_cloud_io.h" - -namespace draco { - -// Returns the full path to a given file system entry, such as test file or test -// directory. -std::string GetTestFileFullPath(const std::string &entry_name); - -// Returns the full path to a given temporary file (a location where tests store -// generated files). -std::string GetTestTempFileFullPath(const std::string &file_name); - -// Generates a new golden file and saves it into the correct folder. -// Returns false if the file couldn't be created. -bool GenerateGoldenFile(const std::string &golden_file_name, const void *data, - int data_size); - -// Compare a golden file content with the input data. -// Function will log the first byte position where the data differ. -// Returns false if there are any differences. -bool CompareGoldenFile(const std::string &golden_file_name, const void *data, - int data_size); - -// Loads a mesh / point cloud specified by a |file_name| that is going to be -// automatically converted to the correct path available to the testing -// instance. -inline std::unique_ptr<Mesh> ReadMeshFromTestFile( - const std::string &file_name) { - const std::string path = GetTestFileFullPath(file_name); - return ReadMeshFromFile(path).value(); -} -inline std::unique_ptr<Mesh> ReadMeshFromTestFile(const std::string &file_name, - bool use_metadata) { - const std::string path = GetTestFileFullPath(file_name); - return ReadMeshFromFile(path, use_metadata).value(); -} -inline std::unique_ptr<Mesh> ReadMeshFromTestFile(const std::string &file_name, - const Options &options) { - const std::string path = GetTestFileFullPath(file_name); - return ReadMeshFromFile(path, options).value(); -} - -inline std::unique_ptr<PointCloud> ReadPointCloudFromTestFile( - const std::string &file_name) { - const std::string path = GetTestFileFullPath(file_name); - return ReadPointCloudFromFile(path).value(); -} - -} // namespace draco - -#endif // DRACO_CORE_DRACO_TEST_UTILS_H_ diff --git a/extern/draco/dracoenc/src/draco/core/draco_tests.cc b/extern/draco/dracoenc/src/draco/core/draco_tests.cc deleted file mode 100644 index fdaa14da508..00000000000 --- a/extern/draco/dracoenc/src/draco/core/draco_tests.cc +++ /dev/null @@ -1,6 +0,0 @@ -#include "draco/core/draco_test_base.h" - -int main(int argc, char *argv[]) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/extern/draco/dracoenc/src/draco/core/math_utils_test.cc b/extern/draco/dracoenc/src/draco/core/math_utils_test.cc deleted file mode 100644 index 8c255d04680..00000000000 --- a/extern/draco/dracoenc/src/draco/core/math_utils_test.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include "draco/core/math_utils.h" - -#include <cmath> -#include <random> - -#include "draco/core/draco_test_base.h" - -using draco::Vector3f; - -TEST(MathUtils, Mod) { EXPECT_EQ(DRACO_INCREMENT_MOD(1, 1 << 1), 0); } - -TEST(MathUtils, IntSqrt) { - ASSERT_EQ(IntSqrt(0), 0); - // 64-bit pseudo random number generator seeded with a predefined number. - std::mt19937_64 generator(109); - std::uniform_int_distribution<uint64_t> distribution(0, 1ull << 60); - - for (int i = 0; i < 10000; ++i) { - const uint64_t number = distribution(generator); - ASSERT_EQ(IntSqrt(number), static_cast<uint64_t>(floor(std::sqrt(number)))); - } -} diff --git a/extern/draco/dracoenc/src/draco/core/quantization_utils_test.cc b/extern/draco/dracoenc/src/draco/core/quantization_utils_test.cc deleted file mode 100644 index b4f0473f204..00000000000 --- a/extern/draco/dracoenc/src/draco/core/quantization_utils_test.cc +++ /dev/null @@ -1,91 +0,0 @@ -// 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 "draco/core/quantization_utils.h" - -#include "draco/core/draco_test_base.h" - -namespace draco { - -class QuantizationUtilsTest : public ::testing::Test {}; - -TEST_F(QuantizationUtilsTest, TestQuantizer) { - Quantizer quantizer; - quantizer.Init(10.f, 255); - EXPECT_EQ(quantizer.QuantizeFloat(0.f), 0); - EXPECT_EQ(quantizer.QuantizeFloat(10.f), 255); - EXPECT_EQ(quantizer.QuantizeFloat(-10.f), -255); - EXPECT_EQ(quantizer.QuantizeFloat(4.999f), 127); - EXPECT_EQ(quantizer.QuantizeFloat(5.f), 128); - EXPECT_EQ(quantizer.QuantizeFloat(-4.9999f), -127); - // Note: Both -5.f and +5.f lie exactly on the boundary between two - // quantized values (127.5f and -127.5f). Due to rounding, both values are - // then converted to 128 and -127 respectively. - EXPECT_EQ(quantizer.QuantizeFloat(-5.f), -127); - EXPECT_EQ(quantizer.QuantizeFloat(-5.0001f), -128); - - // Out of range quantization. - // The behavior is technically undefined, but both quantizer and dequantizer - // should still work correctly unless the quantized values overflow. - EXPECT_LT(quantizer.QuantizeFloat(-15.f), -255); - EXPECT_GT(quantizer.QuantizeFloat(15.f), 255); -} - -TEST_F(QuantizationUtilsTest, TestDequantizer) { - Dequantizer dequantizer; - ASSERT_TRUE(dequantizer.Init(10.f, 255)); - EXPECT_EQ(dequantizer.DequantizeFloat(0), 0.f); - EXPECT_EQ(dequantizer.DequantizeFloat(255), 10.f); - EXPECT_EQ(dequantizer.DequantizeFloat(-255), -10.f); - EXPECT_EQ(dequantizer.DequantizeFloat(128), 10.f * (128.f / 255.f)); - - // Test that the dequantizer fails to initialize with invalid input - // parameters. - ASSERT_FALSE(dequantizer.Init(1.f, 0)); - ASSERT_FALSE(dequantizer.Init(1.f, -4)); -} - -TEST_F(QuantizationUtilsTest, TestDeltaQuantization) { - // Test verifies that the quantizer and dequantizer work correctly when - // initialized with a delta value. - Quantizer quantizer_delta; - quantizer_delta.Init(0.5f); - - Quantizer quantizer_range; - quantizer_range.Init(50.f, 100); - - EXPECT_EQ(quantizer_delta.QuantizeFloat(1.2f), 2); - EXPECT_EQ(quantizer_delta.QuantizeFloat(10.f), - quantizer_range.QuantizeFloat(10.f)); - EXPECT_EQ(quantizer_delta.QuantizeFloat(-3.3f), - quantizer_range.QuantizeFloat(-3.3f)); - EXPECT_EQ(quantizer_delta.QuantizeFloat(0.25f), - quantizer_range.QuantizeFloat(0.25f)); - - Dequantizer dequantizer_delta; - dequantizer_delta.Init(0.5f); - - Dequantizer dequantizer_range; - dequantizer_range.Init(50.f, 100); - - EXPECT_EQ(dequantizer_delta.DequantizeFloat(2), 1.f); - EXPECT_EQ(dequantizer_delta.DequantizeFloat(-4), - dequantizer_range.DequantizeFloat(-4)); - EXPECT_EQ(dequantizer_delta.DequantizeFloat(9), - dequantizer_range.DequantizeFloat(9)); - EXPECT_EQ(dequantizer_delta.DequantizeFloat(0), - dequantizer_range.DequantizeFloat(0)); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/core/status_test.cc b/extern/draco/dracoenc/src/draco/core/status_test.cc deleted file mode 100644 index c1ad4ab30f4..00000000000 --- a/extern/draco/dracoenc/src/draco/core/status_test.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 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 "draco/core/status.h" - -#include <sstream> - -#include "draco/core/draco_test_base.h" - -namespace { - -class StatusTest : public ::testing::Test { - protected: - StatusTest() {} -}; - -TEST_F(StatusTest, TestStatusOutput) { - // Tests that the Status can be stored in a provided std::ostream. - const draco::Status status(draco::Status::DRACO_ERROR, "Error msg."); - ASSERT_EQ(status.code(), draco::Status::DRACO_ERROR); - - std::stringstream str; - str << status; - ASSERT_EQ(str.str(), "Error msg."); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/core/statusor.h b/extern/draco/dracoenc/src/draco/core/statusor.h deleted file mode 100644 index 7fa42098442..00000000000 --- a/extern/draco/dracoenc/src/draco/core/statusor.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2017 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. -// -#ifndef DRACO_CORE_STATUSOR_H_ -#define DRACO_CORE_STATUSOR_H_ - -#include "draco/core/macros.h" -#include "draco/core/status.h" - -namespace draco { - -// Class StatusOr is used to wrap a Status along with a value of a specified -// type |T|. StatusOr is intended to be returned from functions in situations -// where it is desirable to carry over more information about the potential -// errors encountered during the function execution. If there are not errors, -// the caller can simply use the return value, otherwise the Status object -// provides more info about the encountered problem. -template <class T> -class StatusOr { - public: - StatusOr() {} - // Note: Constructors are intentionally not explicit to allow returning - // Status or the return value directly from functions. - StatusOr(const StatusOr &) = default; - StatusOr(StatusOr &&) = default; - StatusOr(const Status &status) : status_(status) {} - StatusOr(const T &value) : status_(OkStatus()), value_(value) {} - StatusOr(T &&value) : status_(OkStatus()), value_(std::move(value)) {} - StatusOr(const Status &status, const T &value) - : status_(status), value_(value) {} - - const Status &status() const { return status_; } - const T &value() const & { return value_; } - const T &&value() const && { return std::move(value_); } - T &&value() && { return std::move(value_); } - - // For consistency with existing Google StatusOr API we also include - // ValueOrDie() that currently returns the value(). - const T &ValueOrDie() const & { return value(); } - T &&ValueOrDie() && { return std::move(value()); } - - bool ok() const { return status_.ok(); } - - private: - Status status_; - T value_; -}; - -// In case StatusOr<T> is ok(), this macro assigns value stored in StatusOr<T> -// to |lhs|, otherwise it returns the error Status. -// -// DRACO_ASSIGN_OR_RETURN(lhs, expression) -// -#define DRACO_ASSIGN_OR_RETURN(lhs, expression) \ - DRACO_ASSIGN_OR_RETURN_IMPL_(DRACO_MACROS_IMPL_CONCAT_(_statusor, __LINE__), \ - lhs, expression, _status) - -// The actual implementation of the above macro. -#define DRACO_ASSIGN_OR_RETURN_IMPL_(statusor, lhs, expression, error_expr) \ - auto statusor = (expression); \ - if (!statusor.ok()) { \ - auto _status = std::move(statusor.status()); \ - (void)_status; /* error_expression may not use it */ \ - return error_expr; \ - } \ - lhs = std::move(statusor).value(); - -} // namespace draco - -#endif // DRACO_CORE_STATUSOR_H_ diff --git a/extern/draco/dracoenc/src/draco/core/vector_d_test.cc b/extern/draco/dracoenc/src/draco/core/vector_d_test.cc deleted file mode 100644 index bc2bdadaa9f..00000000000 --- a/extern/draco/dracoenc/src/draco/core/vector_d_test.cc +++ /dev/null @@ -1,235 +0,0 @@ -// 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 "draco/core/vector_d.h" - -#include <sstream> - -#include "draco/core/draco_test_base.h" - -namespace { - -typedef draco::Vector2f Vector2f; -typedef draco::Vector3f Vector3f; -typedef draco::Vector4f Vector4f; -typedef draco::Vector5f Vector5f; -typedef draco::Vector2ui Vector2ui; -typedef draco::Vector3ui Vector3ui; -typedef draco::Vector4ui Vector4ui; -typedef draco::Vector5ui Vector5ui; - -typedef draco::VectorD<int32_t, 3> Vector3i; -typedef draco::VectorD<int32_t, 4> Vector4i; - -template <class CoeffT, int dimension_t> -void TestSquaredDistance(const draco::VectorD<CoeffT, dimension_t> v1, - const draco::VectorD<CoeffT, dimension_t> v2, - const CoeffT result) { - CoeffT squared_distance = SquaredDistance(v1, v2); - ASSERT_EQ(squared_distance, result); - squared_distance = SquaredDistance(v2, v1); - ASSERT_EQ(squared_distance, result); -} - -TEST(VectorDTest, TestOperators) { - { - const Vector3f v; - ASSERT_EQ(v[0], 0); - ASSERT_EQ(v[1], 0); - ASSERT_EQ(v[2], 0); - } - Vector3f v(1, 2, 3); - ASSERT_EQ(v[0], 1); - ASSERT_EQ(v[1], 2); - ASSERT_EQ(v[2], 3); - - Vector3f w = v; - ASSERT_TRUE(v == w); - ASSERT_FALSE(v != w); - ASSERT_EQ(w[0], 1); - ASSERT_EQ(w[1], 2); - ASSERT_EQ(w[2], 3); - - w = -v; - ASSERT_EQ(w[0], -1); - ASSERT_EQ(w[1], -2); - ASSERT_EQ(w[2], -3); - - w = v + v; - ASSERT_EQ(w[0], 2); - ASSERT_EQ(w[1], 4); - ASSERT_EQ(w[2], 6); - - w = w - v; - ASSERT_EQ(w[0], 1); - ASSERT_EQ(w[1], 2); - ASSERT_EQ(w[2], 3); - - // Scalar multiplication from left and right. - w = v * 2.f; - ASSERT_EQ(w[0], 2); - ASSERT_EQ(w[1], 4); - ASSERT_EQ(w[2], 6); - w = 2.f * v; - ASSERT_EQ(w[0], 2); - ASSERT_EQ(w[1], 4); - ASSERT_EQ(w[2], 6); - - ASSERT_EQ(v.SquaredNorm(), 14); - ASSERT_EQ(v.Dot(v), 14); - - Vector3f new_v = v; - new_v.Normalize(); - const float eps = 0.001; - const float magnitude = std::sqrt(v.SquaredNorm()); - const float new_magnitude = std::sqrt(new_v.SquaredNorm()); - ASSERT_LE(new_magnitude, 1 + eps); - ASSERT_GE(new_magnitude, 1 - eps); - for (int i = 0; i < 3; ++i) { - new_v[i] *= magnitude; - ASSERT_LE(new_v[i], v[i] + eps); - ASSERT_GE(new_v[i], v[i] - eps); - } - - Vector3f x(0, 0, 0); - x.Normalize(); - for (int i = 0; i < 3; ++i) { - ASSERT_EQ(0, x[i]); - } -} - -TEST(VectorDTest, TestSquaredDistance) { - // Test Vector2f: float, 2D. - Vector2f v1_2f(5.5, 10.5); - Vector2f v2_2f(3.5, 15.5); - float result_f = 29; - TestSquaredDistance(v1_2f, v2_2f, result_f); - - // Test Vector3f: float, 3D. - Vector3f v1_3f(5.5, 10.5, 2.3); - Vector3f v2_3f(3.5, 15.5, 0); - result_f = 34.29; - TestSquaredDistance(v1_3f, v2_3f, result_f); - - // Test Vector4f: float, 4D. - Vector4f v1_4f(5.5, 10.5, 2.3, 7.2); - Vector4f v2_4f(3.5, 15.5, 0, 9.9); - result_f = 41.58; - TestSquaredDistance(v1_4f, v2_4f, result_f); - - // Test Vector5f: float, 5D. - Vector5f v1_5f(5.5, 10.5, 2.3, 7.2, 1.0); - Vector5f v2_5f(3.5, 15.5, 0, 9.9, 0.2); - result_f = 42.22; - TestSquaredDistance(v1_5f, v2_5f, result_f); - - // Test Vector 2ui: uint32_t, 2D. - Vector2ui v1_2ui(5, 10); - Vector2ui v2_2ui(3, 15); - uint32_t result_ui = 29; - TestSquaredDistance(v1_2ui, v2_2ui, result_ui); - - // Test Vector 3ui: uint32_t, 3D. - Vector3ui v1_3ui(5, 10, 2); - Vector3ui v2_3ui(3, 15, 0); - result_ui = 33; - TestSquaredDistance(v1_3ui, v2_3ui, result_ui); - - // Test Vector 4ui: uint32_t, 4D. - Vector4ui v1_4ui(5, 10, 2, 7); - Vector4ui v2_4ui(3, 15, 0, 9); - result_ui = 37; - TestSquaredDistance(v1_4ui, v2_4ui, result_ui); - - // Test Vector 5ui: uint32_t, 5D. - Vector5ui v1_5ui(5, 10, 2, 7, 1); - Vector5ui v2_5ui(3, 15, 0, 9, 12); - result_ui = 158; - TestSquaredDistance(v1_5ui, v2_5ui, result_ui); -} - -TEST(VectorDTest, TestCrossProduct3D) { - const Vector3i e1(1, 0, 0); - const Vector3i e2(0, 1, 0); - const Vector3i e3(0, 0, 1); - const Vector3i o(0, 0, 0); - ASSERT_EQ(e3, draco::CrossProduct(e1, e2)); - ASSERT_EQ(e1, draco::CrossProduct(e2, e3)); - ASSERT_EQ(e2, draco::CrossProduct(e3, e1)); - ASSERT_EQ(-e3, draco::CrossProduct(e2, e1)); - ASSERT_EQ(-e1, draco::CrossProduct(e3, e2)); - ASSERT_EQ(-e2, draco::CrossProduct(e1, e3)); - ASSERT_EQ(o, draco::CrossProduct(e1, e1)); - ASSERT_EQ(o, draco::CrossProduct(e2, e2)); - ASSERT_EQ(o, draco::CrossProduct(e3, e3)); - - // Orthogonality of result for some general vectors. - const Vector3i v1(123, -62, 223); - const Vector3i v2(734, 244, -13); - const Vector3i orth = draco::CrossProduct(v1, v2); - ASSERT_EQ(0, v1.Dot(orth)); - ASSERT_EQ(0, v2.Dot(orth)); -} - -TEST(VectorDTest, TestAbsSum) { - // Testing const of function and zero. - const Vector3i v(0, 0, 0); - ASSERT_EQ(v.AbsSum(), 0); - // Testing semantic. - ASSERT_EQ(Vector3i(0, 0, 0).AbsSum(), 0); - ASSERT_EQ(Vector3i(1, 2, 3).AbsSum(), 6); - ASSERT_EQ(Vector3i(-1, -2, -3).AbsSum(), 6); - ASSERT_EQ(Vector3i(-2, 4, -8).AbsSum(), 14); - // Other dimension. - ASSERT_EQ(Vector4i(-2, 4, -8, 3).AbsSum(), 17); -} - -TEST(VectorDTest, TestMinMaxCoeff) { - // Test verifies that MinCoeff() and MaxCoeff() functions work as intended. - const Vector4i vi(-10, 5, 2, 3); - ASSERT_EQ(vi.MinCoeff(), -10); - ASSERT_EQ(vi.MaxCoeff(), 5); - - const Vector3f vf(6.f, 1000.f, -101.f); - ASSERT_EQ(vf.MinCoeff(), -101.f); - ASSERT_EQ(vf.MaxCoeff(), 1000.f); -} - -TEST(VectorDTest, TestOstream) { - // Tests that the vector can be stored in a provided std::ostream. - const draco::VectorD<int64_t, 3> vector(1, 2, 3); - std::stringstream str; - str << vector << " "; - ASSERT_EQ(str.str(), "1 2 3 "); -} - -TEST(VectorDTest, TestConvertConstructor) { - // Tests that a vector can be constructed from another vector with a different - // type. - const draco::VectorD<int64_t, 3> vector(1, 2, 3); - - const draco::VectorD<float, 3> vector3f(vector); - ASSERT_EQ(vector3f, draco::Vector3f(1.f, 2.f, 3.f)); - - const draco::VectorD<float, 2> vector2f(vector); - ASSERT_EQ(vector2f, draco::Vector2f(1.f, 2.f)); - - const draco::VectorD<float, 4> vector4f(vector3f); - ASSERT_EQ(vector4f, draco::Vector4f(1.f, 2.f, 3.f, 0.f)); - - const draco::VectorD<double, 1> vector1d(vector3f); - ASSERT_EQ(vector1d[0], 1.0); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/draco_features.h b/extern/draco/dracoenc/src/draco/draco_features.h deleted file mode 100644 index f067ca44dd0..00000000000 --- a/extern/draco/dracoenc/src/draco/draco_features.h +++ /dev/null @@ -1,8 +0,0 @@ -// GENERATED FILE -- DO NOT EDIT - -#ifndef DRACO_FEATURES_H_ -#define DRACO_FEATURES_H_ - -#define DRACO_ATTRIBUTE_DEDUPLICATION_SUPPORTED - -#endif // DRACO_FEATURES_H_
\ No newline at end of file diff --git a/extern/draco/dracoenc/src/draco/io/mesh_io.cc b/extern/draco/dracoenc/src/draco/io/mesh_io.cc deleted file mode 100644 index 5e2f9f51d7a..00000000000 --- a/extern/draco/dracoenc/src/draco/io/mesh_io.cc +++ /dev/null @@ -1,69 +0,0 @@ -// 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 "draco/io/mesh_io.h" - -#include <fstream> - -#include "draco/io/file_utils.h" -#include "draco/io/obj_decoder.h" -#include "draco/io/ply_decoder.h" - -namespace draco { - -StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name) { - const Options options; - return ReadMeshFromFile(file_name, options); -} - -StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name, - bool use_metadata) { - Options options; - options.SetBool("use_metadata", use_metadata); - return ReadMeshFromFile(file_name, options); -} - -StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name, - const Options &options) { - std::unique_ptr<Mesh> mesh(new Mesh()); - // Analyze file extension. - const std::string extension = LowercaseFileExtension(file_name); - if (extension == "obj") { - // Wavefront OBJ file format. - ObjDecoder obj_decoder; - obj_decoder.set_use_metadata(options.GetBool("use_metadata", false)); - const Status obj_status = obj_decoder.DecodeFromFile(file_name, mesh.get()); - if (!obj_status.ok()) - return obj_status; - return std::move(mesh); - } - if (extension == "ply") { - // Wavefront PLY file format. - PlyDecoder ply_decoder; - DRACO_RETURN_IF_ERROR(ply_decoder.DecodeFromFile(file_name, mesh.get())); - return std::move(mesh); - } - - // Otherwise not an obj file. Assume the file was encoded with one of the - // draco encoding methods. - std::ifstream is(file_name.c_str(), std::ios::binary); - if (!is) - return Status(Status::DRACO_ERROR, "Invalid input stream."); - if (!ReadMeshFromStream(&mesh, is).good()) - return Status(Status::DRACO_ERROR, - "Unknown error."); // Error reading the stream. - return std::move(mesh); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/mesh_io.h b/extern/draco/dracoenc/src/draco/io/mesh_io.h deleted file mode 100644 index 15cfbb30b97..00000000000 --- a/extern/draco/dracoenc/src/draco/io/mesh_io.h +++ /dev/null @@ -1,102 +0,0 @@ -// 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. -// -#ifndef DRACO_MESH_MESH_IO_H_ -#define DRACO_MESH_MESH_IO_H_ - -#include "draco/compression/config/compression_shared.h" -#include "draco/compression/decode.h" -#include "draco/compression/expert_encode.h" -#include "draco/core/options.h" - -namespace draco { - -template <typename OutStreamT> -OutStreamT WriteMeshIntoStream(const Mesh *mesh, OutStreamT &&os, - MeshEncoderMethod method, - const EncoderOptions &options) { - EncoderBuffer buffer; - EncoderOptions local_options = options; - ExpertEncoder encoder(*mesh); - encoder.Reset(local_options); - encoder.SetEncodingMethod(method); - if (!encoder.EncodeToBuffer(&buffer).ok()) { - os.setstate(std::ios_base::badbit); - return os; - } - - os.write(static_cast<const char *>(buffer.data()), buffer.size()); - - return os; -} - -template <typename OutStreamT> -OutStreamT WriteMeshIntoStream(const Mesh *mesh, OutStreamT &&os, - MeshEncoderMethod method) { - const EncoderOptions options = EncoderOptions::CreateDefaultOptions(); - return WriteMeshIntoStream(mesh, os, method, options); -} - -template <typename OutStreamT> -OutStreamT &WriteMeshIntoStream(const Mesh *mesh, OutStreamT &&os) { - return WriteMeshIntoStream(mesh, os, MESH_EDGEBREAKER_ENCODING); -} - -template <typename InStreamT> -InStreamT &ReadMeshFromStream(std::unique_ptr<Mesh> *mesh, InStreamT &&is) { - // Determine size of stream and write into a vector - const auto start_pos = is.tellg(); - is.seekg(0, std::ios::end); - const std::streampos is_size = is.tellg() - start_pos; - is.seekg(start_pos); - std::vector<char> data(is_size); - is.read(&data[0], is_size); - - // Create a mesh from that data. - DecoderBuffer buffer; - buffer.Init(&data[0], data.size()); - Decoder decoder; - auto statusor = decoder.DecodeMeshFromBuffer(&buffer); - *mesh = std::move(statusor).value(); - if (!statusor.ok() || *mesh == nullptr) { - is.setstate(std::ios_base::badbit); - } - - return is; -} - -// Reads a mesh from a file. The function automatically chooses the correct -// decoder based on the extension of the files. Currently, .obj and .ply files -// are supported. Other file extensions are processed by the default -// draco::MeshDecoder. -// Returns nullptr with an error status if the decoding failed. -StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name); - -// Reads a mesh from a file. The function does the same thing as the previous -// one except using metadata to encode additional information when -// |use_metadata| is set to true. -// Returns nullptr with an error status if the decoding failed. -StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name, - bool use_metadata); - -// Reads a mesh from a file. Reading is configured with |options|: -// use_metadata : Read obj file info like material names and object names into -// metadata. Default is false. -// Returns nullptr with an error status if the decoding failed. -StatusOr<std::unique_ptr<Mesh>> ReadMeshFromFile(const std::string &file_name, - const Options &options); - -} // namespace draco - -#endif // DRACO_MESH_MESH_IO_H_ diff --git a/extern/draco/dracoenc/src/draco/io/obj_decoder.cc b/extern/draco/dracoenc/src/draco/io/obj_decoder.cc deleted file mode 100644 index 88f470f8b4a..00000000000 --- a/extern/draco/dracoenc/src/draco/io/obj_decoder.cc +++ /dev/null @@ -1,689 +0,0 @@ -// 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 "draco/io/obj_decoder.h" - -#include <cctype> -#include <cmath> -#include <fstream> - -#include "draco/io/file_utils.h" -#include "draco/io/parser_utils.h" -#include "draco/metadata/geometry_metadata.h" - -namespace draco { - -ObjDecoder::ObjDecoder() - : counting_mode_(true), - num_obj_faces_(0), - num_positions_(0), - num_tex_coords_(0), - num_normals_(0), - num_materials_(0), - last_sub_obj_id_(0), - pos_att_id_(-1), - tex_att_id_(-1), - norm_att_id_(-1), - material_att_id_(-1), - sub_obj_att_id_(-1), - deduplicate_input_values_(true), - last_material_id_(0), - use_metadata_(false), - out_mesh_(nullptr), - out_point_cloud_(nullptr) {} - -Status ObjDecoder::DecodeFromFile(const std::string &file_name, - Mesh *out_mesh) { - out_mesh_ = out_mesh; - return DecodeFromFile(file_name, static_cast<PointCloud *>(out_mesh)); -} - -Status ObjDecoder::DecodeFromFile(const std::string &file_name, - PointCloud *out_point_cloud) { - std::ifstream file(file_name, std::ios::binary); - if (!file) - return Status(Status::IO_ERROR); - // Read the whole file into a buffer. - auto pos0 = file.tellg(); - file.seekg(0, std::ios::end); - auto file_size = file.tellg() - pos0; - if (file_size == 0) - return Status(Status::IO_ERROR); - file.seekg(0, std::ios::beg); - std::vector<char> data(file_size); - file.read(&data[0], file_size); - buffer_.Init(&data[0], file_size); - - out_point_cloud_ = out_point_cloud; - input_file_name_ = file_name; - return DecodeInternal(); -} - -Status ObjDecoder::DecodeFromBuffer(DecoderBuffer *buffer, Mesh *out_mesh) { - out_mesh_ = out_mesh; - return DecodeFromBuffer(buffer, static_cast<PointCloud *>(out_mesh)); -} - -Status ObjDecoder::DecodeFromBuffer(DecoderBuffer *buffer, - PointCloud *out_point_cloud) { - out_point_cloud_ = out_point_cloud; - buffer_.Init(buffer->data_head(), buffer->remaining_size()); - return DecodeInternal(); -} - -Status ObjDecoder::DecodeInternal() { - // In the first pass, count the number of different elements in the geometry. - // In case the desired output is just a point cloud (i.e., when - // out_mesh_ == nullptr) the decoder will ignore all information about the - // connectivity that may be included in the source data. - counting_mode_ = true; - ResetCounters(); - material_name_to_id_.clear(); - last_sub_obj_id_ = 0; - // Parse all lines. - Status status(Status::OK); - while (ParseDefinition(&status) && status.ok()) { - } - if (!status.ok()) - return status; - bool use_identity_mapping = false; - if (num_obj_faces_ == 0) { - // Mesh has no faces. In this case we try to read the geometry as a point - // cloud where every attribute entry is a point. - - // Ensure the number of all entries is same for all attributes. - if (num_positions_ == 0) - return Status(Status::DRACO_ERROR, "No position attribute"); - if (num_tex_coords_ > 0 && num_tex_coords_ != num_positions_) - return Status(Status::DRACO_ERROR, - "Invalid number of texture coordinates for a point cloud"); - if (num_normals_ > 0 && num_normals_ != num_positions_) - return Status(Status::DRACO_ERROR, - "Invalid number of normals for a point cloud"); - - out_mesh_ = nullptr; // Treat the output geometry as a point cloud. - use_identity_mapping = true; - } - - // Initialize point cloud and mesh properties. - if (out_mesh_) { - // Start decoding a mesh with the given number of faces. For point clouds we - // silently ignore all data about the mesh connectivity. - out_mesh_->SetNumFaces(num_obj_faces_); - } - if (num_obj_faces_ > 0) { - out_point_cloud_->set_num_points(3 * num_obj_faces_); - } else { - out_point_cloud_->set_num_points(num_positions_); - } - - // Add attributes if they are present in the input data. - if (num_positions_ > 0) { - GeometryAttribute va; - va.Init(GeometryAttribute::POSITION, nullptr, 3, DT_FLOAT32, false, - sizeof(float) * 3, 0); - pos_att_id_ = out_point_cloud_->AddAttribute(va, use_identity_mapping, - num_positions_); - } - if (num_tex_coords_ > 0) { - GeometryAttribute va; - va.Init(GeometryAttribute::TEX_COORD, nullptr, 2, DT_FLOAT32, false, - sizeof(float) * 2, 0); - tex_att_id_ = out_point_cloud_->AddAttribute(va, use_identity_mapping, - num_tex_coords_); - } - if (num_normals_ > 0) { - GeometryAttribute va; - va.Init(GeometryAttribute::NORMAL, nullptr, 3, DT_FLOAT32, false, - sizeof(float) * 3, 0); - norm_att_id_ = - out_point_cloud_->AddAttribute(va, use_identity_mapping, num_normals_); - } - if (num_materials_ > 0 && num_obj_faces_ > 0) { - GeometryAttribute va; - const auto geometry_attribute_type = GeometryAttribute::GENERIC; - if (num_materials_ < 256) { - va.Init(geometry_attribute_type, nullptr, 1, DT_UINT8, false, 1, 0); - } else if (num_materials_ < (1 << 16)) { - va.Init(geometry_attribute_type, nullptr, 1, DT_UINT16, false, 2, 0); - } else { - va.Init(geometry_attribute_type, nullptr, 1, DT_UINT32, false, 4, 0); - } - material_att_id_ = - out_point_cloud_->AddAttribute(va, false, num_materials_); - - // Fill the material entries. - for (int i = 0; i < num_materials_; ++i) { - const AttributeValueIndex avi(i); - out_point_cloud_->attribute(material_att_id_)->SetAttributeValue(avi, &i); - } - - if (use_metadata_) { - // Use metadata to store the name of materials. - std::unique_ptr<AttributeMetadata> material_metadata = - std::unique_ptr<AttributeMetadata>(new AttributeMetadata()); - material_metadata->AddEntryString("name", "material"); - // Add all material names. - for (const auto &itr : material_name_to_id_) { - material_metadata->AddEntryInt(itr.first, itr.second); - } - if (!material_file_name_.empty()) { - material_metadata->AddEntryString("file_name", material_file_name_); - } - - out_point_cloud_->AddAttributeMetadata(material_att_id_, - std::move(material_metadata)); - } - } - if (!obj_name_to_id_.empty() && num_obj_faces_ > 0) { - GeometryAttribute va; - if (obj_name_to_id_.size() < 256) { - va.Init(GeometryAttribute::GENERIC, nullptr, 1, DT_UINT8, false, 1, 0); - } else if (obj_name_to_id_.size() < (1 << 16)) { - va.Init(GeometryAttribute::GENERIC, nullptr, 1, DT_UINT16, false, 2, 0); - } else { - va.Init(GeometryAttribute::GENERIC, nullptr, 1, DT_UINT32, false, 4, 0); - } - sub_obj_att_id_ = out_point_cloud_->AddAttribute( - va, false, static_cast<uint32_t>(obj_name_to_id_.size())); - // Fill the sub object id entries. - for (const auto &itr : obj_name_to_id_) { - const AttributeValueIndex i(itr.second); - out_point_cloud_->attribute(sub_obj_att_id_)->SetAttributeValue(i, &i); - } - if (use_metadata_) { - // Use metadata to store the name of materials. - std::unique_ptr<AttributeMetadata> sub_obj_metadata = - std::unique_ptr<AttributeMetadata>(new AttributeMetadata()); - sub_obj_metadata->AddEntryString("name", "sub_obj"); - // Add all sub object names. - for (const auto &itr : obj_name_to_id_) { - const AttributeValueIndex i(itr.second); - sub_obj_metadata->AddEntryInt(itr.first, itr.second); - } - out_point_cloud_->AddAttributeMetadata(sub_obj_att_id_, - std::move(sub_obj_metadata)); - } - } - - // Perform a second iteration of parsing and fill all the data. - counting_mode_ = false; - ResetCounters(); - // Start parsing from the beginning of the buffer again. - buffer()->StartDecodingFrom(0); - while (ParseDefinition(&status) && status.ok()) { - } - if (!status.ok()) - return status; - if (out_mesh_) { - // Add faces with identity mapping between vertex and corner indices. - // Duplicate vertices will get removed later. - Mesh::Face face; - for (FaceIndex i(0); i < num_obj_faces_; ++i) { - for (int c = 0; c < 3; ++c) - face[c] = 3 * i.value() + c; - out_mesh_->SetFace(i, face); - } - } - -#ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED - if (deduplicate_input_values_) { - out_point_cloud_->DeduplicateAttributeValues(); - } -#endif -#ifdef DRACO_ATTRIBUTE_INDICES_DEDUPLICATION_SUPPORTED - out_point_cloud_->DeduplicatePointIds(); -#endif - return status; -} - -void ObjDecoder::ResetCounters() { - num_obj_faces_ = 0; - num_positions_ = 0; - num_tex_coords_ = 0; - num_normals_ = 0; - last_material_id_ = 0; - last_sub_obj_id_ = 0; -} - -bool ObjDecoder::ParseDefinition(Status *status) { - char c; - parser::SkipWhitespace(buffer()); - if (!buffer()->Peek(&c)) { - // End of file reached?. - return false; - } - if (c == '#') { - // Comment, ignore the line. - parser::SkipLine(buffer()); - return true; - } - if (ParseVertexPosition(status)) - return true; - if (ParseNormal(status)) - return true; - if (ParseTexCoord(status)) - return true; - if (ParseFace(status)) - return true; - if (ParseMaterial(status)) - return true; - if (ParseMaterialLib(status)) - return true; - if (ParseObject(status)) - return true; - // No known definition was found. Ignore the line. - parser::SkipLine(buffer()); - return true; -} - -bool ObjDecoder::ParseVertexPosition(Status *status) { - std::array<char, 2> c; - if (!buffer()->Peek(&c)) { - return false; - } - if (c[0] != 'v' || c[1] != ' ') - return false; - // Vertex definition found! - buffer()->Advance(2); - if (!counting_mode_) { - // Parse three float numbers for vertex position coordinates. - float val[3]; - for (int i = 0; i < 3; ++i) { - parser::SkipWhitespace(buffer()); - if (!parser::ParseFloat(buffer(), val + i)) { - *status = Status(Status::DRACO_ERROR, "Failed to parse a float number"); - // The definition is processed so return true. - return true; - } - } - out_point_cloud_->attribute(pos_att_id_) - ->SetAttributeValue(AttributeValueIndex(num_positions_), val); - } - ++num_positions_; - parser::SkipLine(buffer()); - return true; -} - -bool ObjDecoder::ParseNormal(Status *status) { - std::array<char, 2> c; - if (!buffer()->Peek(&c)) { - return false; - } - if (c[0] != 'v' || c[1] != 'n') - return false; - // Normal definition found! - buffer()->Advance(2); - if (!counting_mode_) { - // Parse three float numbers for the normal vector. - float val[3]; - for (int i = 0; i < 3; ++i) { - parser::SkipWhitespace(buffer()); - if (!parser::ParseFloat(buffer(), val + i)) { - *status = Status(Status::DRACO_ERROR, "Failed to parse a float number"); - // The definition is processed so return true. - return true; - } - } - out_point_cloud_->attribute(norm_att_id_) - ->SetAttributeValue(AttributeValueIndex(num_normals_), val); - } - ++num_normals_; - parser::SkipLine(buffer()); - return true; -} - -bool ObjDecoder::ParseTexCoord(Status *status) { - std::array<char, 2> c; - if (!buffer()->Peek(&c)) { - return false; - } - if (c[0] != 'v' || c[1] != 't') - return false; - // Texture coord definition found! - buffer()->Advance(2); - if (!counting_mode_) { - // Parse two float numbers for the texture coordinate. - float val[2]; - for (int i = 0; i < 2; ++i) { - parser::SkipWhitespace(buffer()); - if (!parser::ParseFloat(buffer(), val + i)) { - *status = Status(Status::DRACO_ERROR, "Failed to parse a float number"); - // The definition is processed so return true. - return true; - } - } - out_point_cloud_->attribute(tex_att_id_) - ->SetAttributeValue(AttributeValueIndex(num_tex_coords_), val); - } - ++num_tex_coords_; - parser::SkipLine(buffer()); - return true; -} - -bool ObjDecoder::ParseFace(Status *status) { - char c; - if (!buffer()->Peek(&c)) { - return false; - } - if (c != 'f') - return false; - // Face definition found! - buffer()->Advance(1); - if (!counting_mode_) { - std::array<int32_t, 3> indices[4]; - // Parse face indices (we try to look for up to four to support quads). - int num_valid_indices = 0; - for (int i = 0; i < 4; ++i) { - if (!ParseVertexIndices(&indices[i])) { - if (i == 3) { - break; // It's OK if there is no fourth vertex index. - } - *status = Status(Status::DRACO_ERROR, "Failed to parse vertex indices"); - return true; - } - ++num_valid_indices; - } - // Process the first face. - for (int i = 0; i < 3; ++i) { - const PointIndex vert_id(3 * num_obj_faces_ + i); - MapPointToVertexIndices(vert_id, indices[i]); - } - ++num_obj_faces_; - if (num_valid_indices == 4) { - // Add an additional triangle for the quad. - // - // 3----2 - // | / | - // | / | - // 0----1 - // - const PointIndex vert_id(3 * num_obj_faces_); - MapPointToVertexIndices(vert_id, indices[0]); - MapPointToVertexIndices(vert_id + 1, indices[2]); - MapPointToVertexIndices(vert_id + 2, indices[3]); - ++num_obj_faces_; - } - } else { - // We are in the counting mode. - // We need to determine how many triangles are in the obj face. - // Go over the line and check how many gaps there are between non-empty - // sub-strings. - parser::SkipWhitespace(buffer()); - int num_indices = 0; - bool is_end = false; - while (buffer()->Peek(&c) && c != '\n') { - if (parser::PeekWhitespace(buffer(), &is_end)) { - buffer()->Advance(1); - } else { - // Non-whitespace reached.. assume it's index declaration, skip it. - num_indices++; - while (!parser::PeekWhitespace(buffer(), &is_end) && !is_end) { - buffer()->Advance(1); - } - } - } - if (num_indices < 3 || num_indices > 4) { - *status = - Status(Status::DRACO_ERROR, "Invalid number of indices on a face"); - return false; - } - // Either one or two new triangles. - num_obj_faces_ += num_indices - 2; - } - parser::SkipLine(buffer()); - return true; -} - -bool ObjDecoder::ParseMaterialLib(Status *status) { - // Allow only one material library per file for now. - if (material_name_to_id_.size() > 0) - return false; - std::array<char, 6> c; - if (!buffer()->Peek(&c)) { - return false; - } - if (std::memcmp(&c[0], "mtllib", 6) != 0) - return false; - buffer()->Advance(6); - DecoderBuffer line_buffer = parser::ParseLineIntoDecoderBuffer(buffer()); - parser::SkipWhitespace(&line_buffer); - material_file_name_.clear(); - if (!parser::ParseString(&line_buffer, &material_file_name_)) { - *status = Status(Status::DRACO_ERROR, "Failed to parse material file name"); - return true; - } - parser::SkipLine(&line_buffer); - - if (material_file_name_.size() > 0) { - if (!ParseMaterialFile(material_file_name_, status)) { - // Silently ignore problems with material files for now. - return true; - } - } - return true; -} - -bool ObjDecoder::ParseMaterial(Status * /* status */) { - // In second pass, skip when we don't use materials. - if (!counting_mode_ && material_att_id_ < 0) - return false; - std::array<char, 6> c; - if (!buffer()->Peek(&c)) { - return false; - } - if (std::memcmp(&c[0], "usemtl", 6) != 0) - return false; - buffer()->Advance(6); - DecoderBuffer line_buffer = parser::ParseLineIntoDecoderBuffer(buffer()); - parser::SkipWhitespace(&line_buffer); - std::string mat_name; - parser::ParseLine(&line_buffer, &mat_name); - if (mat_name.length() == 0) - return false; - auto it = material_name_to_id_.find(mat_name); - if (it == material_name_to_id_.end()) { - // In first pass, materials found in obj that's not in the .mtl file - // will be added to the list. - last_material_id_ = num_materials_; - material_name_to_id_[mat_name] = num_materials_++; - - return true; - } - last_material_id_ = it->second; - return true; -} - -bool ObjDecoder::ParseObject(Status *status) { - std::array<char, 2> c; - if (!buffer()->Peek(&c)) { - return false; - } - if (std::memcmp(&c[0], "o ", 2) != 0) - return false; - buffer()->Advance(1); - DecoderBuffer line_buffer = parser::ParseLineIntoDecoderBuffer(buffer()); - parser::SkipWhitespace(&line_buffer); - std::string obj_name; - if (!parser::ParseString(&line_buffer, &obj_name)) - return false; - if (obj_name.length() == 0) - return true; // Ignore empty name entries. - auto it = obj_name_to_id_.find(obj_name); - if (it == obj_name_to_id_.end()) { - const int num_obj = static_cast<int>(obj_name_to_id_.size()); - obj_name_to_id_[obj_name] = num_obj; - last_sub_obj_id_ = num_obj; - } else { - last_sub_obj_id_ = it->second; - } - return true; -} - -bool ObjDecoder::ParseVertexIndices(std::array<int32_t, 3> *out_indices) { - // Parsed attribute indices can be in format: - // 1. POS_INDEX - // 2. POS_INDEX/TEX_COORD_INDEX - // 3. POS_INDEX/TEX_COORD_INDEX/NORMAL_INDEX - // 4. POS_INDEX//NORMAL_INDEX - parser::SkipCharacters(buffer(), " \t"); - if (!parser::ParseSignedInt(buffer(), &(*out_indices)[0]) || - (*out_indices)[0] == 0) - return false; // Position index must be present and valid. - (*out_indices)[1] = (*out_indices)[2] = 0; - char ch; - if (!buffer()->Peek(&ch)) - return true; // It may be OK if we cannot read any more characters. - if (ch != '/') - return true; - buffer()->Advance(1); - // Check if we should skip texture index or not. - if (!buffer()->Peek(&ch)) - return false; // Here, we should be always able to read the next char. - if (ch != '/') { - // Must be texture coord index. - if (!parser::ParseSignedInt(buffer(), &(*out_indices)[1]) || - (*out_indices)[1] == 0) - return false; // Texture index must be present and valid. - } - if (!buffer()->Peek(&ch)) - return true; - if (ch == '/') { - buffer()->Advance(1); - // Read normal index. - if (!parser::ParseSignedInt(buffer(), &(*out_indices)[2]) || - (*out_indices)[2] == 0) - return false; // Normal index must be present and valid. - } - return true; -} - -void ObjDecoder::MapPointToVertexIndices( - PointIndex vert_id, const std::array<int32_t, 3> &indices) { - // Use face entries to store mapping between vertex and attribute indices - // (positions, texture coordinates and normal indices). - // Any given index is used when indices[x] != 0. For positive values, the - // point is mapped directly to the specified attribute index. Negative input - // indices indicate addressing from the last element (e.g. -1 is the last - // attribute value of a given type, -2 the second last, etc.). - if (indices[0] > 0) { - out_point_cloud_->attribute(pos_att_id_) - ->SetPointMapEntry(vert_id, AttributeValueIndex(indices[0] - 1)); - } else if (indices[0] < 0) { - out_point_cloud_->attribute(pos_att_id_) - ->SetPointMapEntry(vert_id, - AttributeValueIndex(num_positions_ + indices[0])); - } - - if (tex_att_id_ >= 0) { - if (indices[1] > 0) { - out_point_cloud_->attribute(tex_att_id_) - ->SetPointMapEntry(vert_id, AttributeValueIndex(indices[1] - 1)); - } else if (indices[1] < 0) { - out_point_cloud_->attribute(tex_att_id_) - ->SetPointMapEntry(vert_id, - AttributeValueIndex(num_tex_coords_ + indices[1])); - } else { - // Texture index not provided but expected. Insert 0 entry as the - // default value. - out_point_cloud_->attribute(tex_att_id_) - ->SetPointMapEntry(vert_id, AttributeValueIndex(0)); - } - } - - if (norm_att_id_ >= 0) { - if (indices[2] > 0) { - out_point_cloud_->attribute(norm_att_id_) - ->SetPointMapEntry(vert_id, AttributeValueIndex(indices[2] - 1)); - } else if (indices[2] < 0) { - out_point_cloud_->attribute(norm_att_id_) - ->SetPointMapEntry(vert_id, - AttributeValueIndex(num_normals_ + indices[2])); - } else { - // Normal index not provided but expected. Insert 0 entry as the default - // value. - out_point_cloud_->attribute(norm_att_id_) - ->SetPointMapEntry(vert_id, AttributeValueIndex(0)); - } - } - - // Assign material index to the point if it is available. - if (material_att_id_ >= 0) { - out_point_cloud_->attribute(material_att_id_) - ->SetPointMapEntry(vert_id, AttributeValueIndex(last_material_id_)); - } - - // Assign sub-object index to the point if it is available. - if (sub_obj_att_id_ >= 0) { - out_point_cloud_->attribute(sub_obj_att_id_) - ->SetPointMapEntry(vert_id, AttributeValueIndex(last_sub_obj_id_)); - } -} - -bool ObjDecoder::ParseMaterialFile(const std::string &file_name, - Status *status) { - const std::string full_path = GetFullPath(file_name, input_file_name_); - std::ifstream file(full_path, std::ios::binary); - if (!file) - return false; - // Read the whole file into a buffer. - file.seekg(0, std::ios::end); - const std::string::size_type file_size = file.tellg(); - if (file_size == 0) - return false; - file.seekg(0, std::ios::beg); - std::vector<char> data(file_size); - file.read(&data[0], file_size); - - // Backup the original decoder buffer. - DecoderBuffer old_buffer = buffer_; - - buffer_.Init(&data[0], file_size); - - num_materials_ = 0; - while (ParseMaterialFileDefinition(status)) { - } - - // Restore the original buffer. - buffer_ = old_buffer; - return true; -} - -bool ObjDecoder::ParseMaterialFileDefinition(Status * /* status */) { - char c; - parser::SkipWhitespace(buffer()); - if (!buffer()->Peek(&c)) { - // End of file reached?. - return false; - } - if (c == '#') { - // Comment, ignore the line. - parser::SkipLine(buffer()); - return true; - } - std::string str; - if (!parser::ParseString(buffer(), &str)) - return false; - if (str == "newmtl") { - parser::SkipWhitespace(buffer()); - parser::ParseLine(buffer(), &str); - if (str.empty()) - return false; - // Add new material to our map. - material_name_to_id_[str] = num_materials_++; - } - return true; -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/obj_decoder.h b/extern/draco/dracoenc/src/draco/io/obj_decoder.h deleted file mode 100644 index 33b9dee2414..00000000000 --- a/extern/draco/dracoenc/src/draco/io/obj_decoder.h +++ /dev/null @@ -1,130 +0,0 @@ -// 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. -// -#ifndef DRACO_IO_OBJ_DECODER_H_ -#define DRACO_IO_OBJ_DECODER_H_ - -#include <string> -#include <unordered_map> - -#include "draco/draco_features.h" - -#include "draco/core/decoder_buffer.h" -#include "draco/core/status.h" -#include "draco/mesh/mesh.h" - -namespace draco { - -// Decodes a Wavefront OBJ file into draco::Mesh (or draco::PointCloud if the -// connectivity data is not needed).. This decoder can handle decoding of -// positions, texture coordinates, normals and triangular faces. -// All other geometry properties are ignored. -class ObjDecoder { - public: - ObjDecoder(); - - // Decodes an obj file stored in the input file. - // Returns nullptr if the decoding failed. - Status DecodeFromFile(const std::string &file_name, Mesh *out_mesh); - Status DecodeFromFile(const std::string &file_name, - PointCloud *out_point_cloud); - - Status DecodeFromBuffer(DecoderBuffer *buffer, Mesh *out_mesh); - Status DecodeFromBuffer(DecoderBuffer *buffer, PointCloud *out_point_cloud); - - // Flag that can be used to turn on/off deduplication of input values. - // This should be disabled only when we are sure that the input data does not - // contain any duplicate entries. - // Default: true - void set_deduplicate_input_values(bool v) { deduplicate_input_values_ = v; } - // Flag for whether using metadata to record other information in the obj - // file, e.g. material names, object names. - void set_use_metadata(bool flag) { use_metadata_ = flag; } - - protected: - Status DecodeInternal(); - DecoderBuffer *buffer() { return &buffer_; } - - private: - // Resets internal counters for attributes and faces. - void ResetCounters(); - - // Parses the next mesh property definition (position, tex coord, normal, or - // face). If the parsed data is unrecognized, it will be skipped. - // Returns false when the end of file was reached. - bool ParseDefinition(Status *status); - - // Attempts to parse definition of position, normal, tex coord, or face - // respectively. - // Returns false when the parsed data didn't contain the given definition. - bool ParseVertexPosition(Status *status); - bool ParseNormal(Status *status); - bool ParseTexCoord(Status *status); - bool ParseFace(Status *status); - bool ParseMaterialLib(Status *status); - bool ParseMaterial(Status *status); - bool ParseObject(Status *status); - - // Parses triplet of position, tex coords and normal indices. - // Returns false on error. - bool ParseVertexIndices(std::array<int32_t, 3> *out_indices); - - // Maps specified point index to the parsed vertex indices (triplet of - // position, texture coordinate, and normal indices) . - void MapPointToVertexIndices(PointIndex pi, - const std::array<int32_t, 3> &indices); - - // Parses material file definitions from a separate file. - bool ParseMaterialFile(const std::string &file_name, Status *status); - bool ParseMaterialFileDefinition(Status *status); - - // If set to true, the parser will count the number of various definitions - // but it will not parse the actual data or add any new entries to the mesh. - bool counting_mode_; - int num_obj_faces_; - int num_positions_; - int num_tex_coords_; - int num_normals_; - int num_materials_; - int last_sub_obj_id_; - - int pos_att_id_; - int tex_att_id_; - int norm_att_id_; - int material_att_id_; - int sub_obj_att_id_; // Attribute id for storing sub-objects. - - bool deduplicate_input_values_; - - int last_material_id_; - std::string material_file_name_; - - std::string input_file_name_; - - std::unordered_map<std::string, int> material_name_to_id_; - std::unordered_map<std::string, int> obj_name_to_id_; - - bool use_metadata_; - - DecoderBuffer buffer_; - - // Data structure that stores the decoded data. |out_point_cloud_| must be - // always set but |out_mesh_| is optional. - Mesh *out_mesh_; - PointCloud *out_point_cloud_; -}; - -} // namespace draco - -#endif // DRACO_IO_OBJ_DECODER_H_ diff --git a/extern/draco/dracoenc/src/draco/io/obj_decoder_test.cc b/extern/draco/dracoenc/src/draco/io/obj_decoder_test.cc deleted file mode 100644 index 3d319a9d44a..00000000000 --- a/extern/draco/dracoenc/src/draco/io/obj_decoder_test.cc +++ /dev/null @@ -1,190 +0,0 @@ -// 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 <sstream> - -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/io/obj_decoder.h" - -namespace draco { - -class ObjDecoderTest : public ::testing::Test { - protected: - template <class Geometry> - std::unique_ptr<Geometry> DecodeObj(const std::string &file_name) const { - return DecodeObj<Geometry>(file_name, false); - } - - template <class Geometry> - std::unique_ptr<Geometry> DecodeObj(const std::string &file_name, - bool deduplicate_input_values) const { - const std::string path = GetTestFileFullPath(file_name); - ObjDecoder decoder; - decoder.set_deduplicate_input_values(deduplicate_input_values); - std::unique_ptr<Geometry> geometry(new Geometry()); - if (!decoder.DecodeFromFile(path, geometry.get()).ok()) - return nullptr; - return geometry; - } - - template <class Geometry> - std::unique_ptr<Geometry> DecodeObjWithMetadata( - const std::string &file_name) const { - const std::string path = GetTestFileFullPath(file_name); - ObjDecoder decoder; - decoder.set_use_metadata(true); - std::unique_ptr<Geometry> geometry(new Geometry()); - if (!decoder.DecodeFromFile(path, geometry.get()).ok()) - return nullptr; - return geometry; - } - - void test_decoding(const std::string &file_name) { - const std::unique_ptr<Mesh> mesh(DecodeObj<Mesh>(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - ASSERT_GT(mesh->num_faces(), 0); - - const std::unique_ptr<PointCloud> pc(DecodeObj<PointCloud>(file_name)); - ASSERT_NE(pc, nullptr) << "Failed to load test model " << file_name; - ASSERT_GT(pc->num_points(), 0); - } -}; - -TEST_F(ObjDecoderTest, ExtraVertexOBJ) { - const std::string file_name = "extra_vertex.obj"; - test_decoding(file_name); -} - -TEST_F(ObjDecoderTest, PartialAttributesOBJ) { - const std::string file_name = "cube_att_partial.obj"; - test_decoding(file_name); -} - -TEST_F(ObjDecoderTest, SubObjects) { - // Tests loading an Obj with sub objects. - const std::string file_name = "cube_att_sub_o.obj"; - const std::unique_ptr<Mesh> mesh(DecodeObj<Mesh>(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - ASSERT_GT(mesh->num_faces(), 0); - - // A sub object attribute should be the fourth attribute of the mesh (in this - // case). - ASSERT_EQ(mesh->num_attributes(), 4); - ASSERT_EQ(mesh->attribute(3)->attribute_type(), GeometryAttribute::GENERIC); - // There should be 3 different sub objects used in the model. - ASSERT_EQ(mesh->attribute(3)->size(), 3); - // Verify that the sub object attribute has unique id == 3. - ASSERT_EQ(mesh->attribute(3)->unique_id(), 3); -} - -TEST_F(ObjDecoderTest, SubObjectsWithMetadata) { - // Tests loading an Obj with sub objects. - const std::string file_name = "cube_att_sub_o.obj"; - const std::unique_ptr<Mesh> mesh(DecodeObjWithMetadata<Mesh>(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - ASSERT_GT(mesh->num_faces(), 0); - - ASSERT_EQ(mesh->num_attributes(), 4); - ASSERT_EQ(mesh->attribute(3)->attribute_type(), GeometryAttribute::GENERIC); - // There should be 3 different sub objects used in the model. - ASSERT_EQ(mesh->attribute(3)->size(), 3); - - // Test material names stored in metadata. - ASSERT_NE(mesh->GetMetadata(), nullptr); - ASSERT_NE(mesh->GetAttributeMetadataByAttributeId(3), nullptr); - int32_t sub_obj_id = 0; - ASSERT_TRUE(mesh->GetAttributeMetadataByAttributeId(3)->GetEntryInt( - "obj2", &sub_obj_id)); - ASSERT_EQ(sub_obj_id, 2); -} - -TEST_F(ObjDecoderTest, QuadOBJ) { - // Tests loading an Obj with quad faces. - const std::string file_name = "cube_quads.obj"; - const std::unique_ptr<Mesh> mesh(DecodeObj<Mesh>(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - ASSERT_EQ(mesh->num_faces(), 12); - - ASSERT_EQ(mesh->num_attributes(), 3); - ASSERT_EQ(mesh->num_points(), 4 * 6); // Four points per quad face. -} - -TEST_F(ObjDecoderTest, ComplexPolyOBJ) { - // Tests that we fail to load an obj with complex polygon (expected failure). - const std::string file_name = "invalid/complex_poly.obj"; - const std::unique_ptr<Mesh> mesh(DecodeObj<Mesh>(file_name)); - ASSERT_EQ(mesh, nullptr); -} - -TEST_F(ObjDecoderTest, EmptyNameOBJ) { - // Tests that we load an obj file that has an sub-object defined with an empty - // name. - const std::string file_name = "empty_name.obj"; - const std::unique_ptr<Mesh> mesh(DecodeObj<Mesh>(file_name)); - ASSERT_NE(mesh, nullptr); - ASSERT_EQ(mesh->num_attributes(), 1); - // Three valid entries in the attribute are expected. - ASSERT_EQ(mesh->attribute(0)->size(), 3); -} - -TEST_F(ObjDecoderTest, PointCloudOBJ) { - // Tests that we load an obj file that does not contain any faces. - const std::string file_name = "test_lines.obj"; - const std::unique_ptr<Mesh> mesh(DecodeObj<Mesh>(file_name, false)); - ASSERT_NE(mesh, nullptr); - ASSERT_EQ(mesh->num_faces(), 0); - ASSERT_EQ(mesh->num_attributes(), 1); - ASSERT_EQ(mesh->attribute(0)->size(), 484); -} - -TEST_F(ObjDecoderTest, WrongAttributeMapping) { - // Tests that we load an obj file that contains invalid mapping between - // attribute indices and values. In such case the invalid indices should be - // ignored. - const std::string file_name = "test_wrong_attribute_mapping.obj"; - const std::unique_ptr<Mesh> mesh(DecodeObj<Mesh>(file_name, false)); - ASSERT_NE(mesh, nullptr); - ASSERT_EQ(mesh->num_faces(), 1); - ASSERT_EQ(mesh->num_attributes(), 1); - ASSERT_EQ(mesh->attribute(0)->size(), 3); -} - -TEST_F(ObjDecoderTest, TestObjDecodingAll) { - // test if we can read all obj that are currently in test folder. - test_decoding("bunny_norm.obj"); - // test_decoding("complex_poly.obj"); // not supported see test above - test_decoding("cube_att.obj"); - test_decoding("cube_att_partial.obj"); - test_decoding("cube_att_sub_o.obj"); - test_decoding("cube_quads.obj"); - test_decoding("cube_subd.obj"); - test_decoding("eof_test.obj"); - test_decoding("extra_vertex.obj"); - test_decoding("mat_test.obj"); - test_decoding("one_face_123.obj"); - test_decoding("one_face_312.obj"); - test_decoding("one_face_321.obj"); - test_decoding("sphere.obj"); - test_decoding("test_nm.obj"); - test_decoding("test_nm_trans.obj"); - test_decoding("test_sphere.obj"); - test_decoding("three_faces_123.obj"); - test_decoding("three_faces_312.obj"); - test_decoding("two_faces_123.obj"); - test_decoding("two_faces_312.obj"); - test_decoding("inf_nan.obj"); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/obj_encoder.cc b/extern/draco/dracoenc/src/draco/io/obj_encoder.cc deleted file mode 100644 index 807506e3536..00000000000 --- a/extern/draco/dracoenc/src/draco/io/obj_encoder.cc +++ /dev/null @@ -1,314 +0,0 @@ -// 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 "draco/io/obj_encoder.h" - -#include <fstream> - -#include "draco/metadata/geometry_metadata.h" - -namespace draco { - -ObjEncoder::ObjEncoder() - : pos_att_(nullptr), - tex_coord_att_(nullptr), - normal_att_(nullptr), - material_att_(nullptr), - sub_obj_att_(nullptr), - out_buffer_(nullptr), - in_point_cloud_(nullptr), - in_mesh_(nullptr), - current_sub_obj_id_(-1), - current_material_id_(-1) {} - -bool ObjEncoder::EncodeToFile(const PointCloud &pc, - const std::string &file_name) { - std::ofstream file(file_name); - if (!file) - return false; // File could not be opened. - file_name_ = file_name; - // Encode the mesh into a buffer. - EncoderBuffer buffer; - if (!EncodeToBuffer(pc, &buffer)) - return false; - // Write the buffer into the file. - file.write(buffer.data(), buffer.size()); - return true; -} - -bool ObjEncoder::EncodeToFile(const Mesh &mesh, const std::string &file_name) { - in_mesh_ = &mesh; - return EncodeToFile(static_cast<const PointCloud &>(mesh), file_name); -} - -bool ObjEncoder::EncodeToBuffer(const PointCloud &pc, - EncoderBuffer *out_buffer) { - in_point_cloud_ = &pc; - out_buffer_ = out_buffer; - if (!EncodeInternal()) - return ExitAndCleanup(false); - return ExitAndCleanup(true); -} - -bool ObjEncoder::EncodeToBuffer(const Mesh &mesh, EncoderBuffer *out_buffer) { - in_mesh_ = &mesh; - return EncodeToBuffer(static_cast<const PointCloud &>(mesh), out_buffer); -} - -bool ObjEncoder::EncodeInternal() { - pos_att_ = nullptr; - tex_coord_att_ = nullptr; - normal_att_ = nullptr; - material_att_ = nullptr; - sub_obj_att_ = nullptr; - current_sub_obj_id_ = -1; - current_material_id_ = -1; - if (!GetSubObjects()) - return false; - if (!EncodeMaterialFileName()) - return false; - if (!EncodePositions()) - return false; - if (!EncodeTextureCoordinates()) - return false; - if (!EncodeNormals()) - return false; - if (in_mesh_ && !EncodeFaces()) - return false; - return true; -} - -bool ObjEncoder::ExitAndCleanup(bool return_value) { - in_mesh_ = nullptr; - in_point_cloud_ = nullptr; - out_buffer_ = nullptr; - pos_att_ = nullptr; - tex_coord_att_ = nullptr; - normal_att_ = nullptr; - material_att_ = nullptr; - sub_obj_att_ = nullptr; - current_sub_obj_id_ = -1; - current_material_id_ = -1; - file_name_.clear(); - return return_value; -} - -bool ObjEncoder::GetSubObjects() { - const GeometryMetadata *pc_metadata = in_point_cloud_->GetMetadata(); - if (!pc_metadata) - return true; - const AttributeMetadata *sub_obj_metadata = - pc_metadata->GetAttributeMetadataByStringEntry("name", "sub_obj"); - if (!sub_obj_metadata) - return true; - sub_obj_id_to_name_.clear(); - for (const auto &entry : sub_obj_metadata->entries()) { - // Sub-object id must be int. - int value = 0; - if (!entry.second.GetValue(&value)) - continue; - sub_obj_id_to_name_[value] = entry.first; - } - sub_obj_att_ = in_point_cloud_->GetAttributeByUniqueId( - sub_obj_metadata->att_unique_id()); - if (sub_obj_att_ == nullptr || sub_obj_att_->size() == 0) - return false; - return true; -} - -bool ObjEncoder::EncodeMaterialFileName() { - const GeometryMetadata *pc_metadata = in_point_cloud_->GetMetadata(); - const AttributeMetadata *material_metadata = nullptr; - if (pc_metadata) { - material_metadata = - pc_metadata->GetAttributeMetadataByStringEntry("name", "material"); - } - std::string material_file_name; - std::string material_full_path; - if (!material_metadata) - return true; - if (!material_metadata->GetEntryString("file_name", &material_file_name)) - return false; - buffer()->Encode("mtllib ", 7); - buffer()->Encode(material_file_name.c_str(), material_file_name.size()); - buffer()->Encode("\n", 1); - material_id_to_name_.clear(); - for (const auto &entry : material_metadata->entries()) { - // Material id must be int. - int value = 0; - // Found entry that are not material id, e.g. file name as a string. - if (!entry.second.GetValue(&value)) - continue; - material_id_to_name_[value] = entry.first; - } - material_att_ = in_point_cloud_->GetAttributeByUniqueId( - material_metadata->att_unique_id()); - if (material_att_ == nullptr || material_att_->size() == 0) - return false; - return true; -} - -bool ObjEncoder::EncodePositions() { - const PointAttribute *const att = - in_point_cloud_->GetNamedAttribute(GeometryAttribute::POSITION); - if (att == nullptr || att->size() == 0) - return false; // Position attribute must be valid. - std::array<float, 3> value; - for (AttributeValueIndex i(0); i < static_cast<uint32_t>(att->size()); ++i) { - if (!att->ConvertValue<float, 3>(i, &value[0])) - return false; - buffer()->Encode("v ", 2); - EncodeFloatList(&value[0], 3); - buffer()->Encode("\n", 1); - } - pos_att_ = att; - return true; -} - -bool ObjEncoder::EncodeTextureCoordinates() { - const PointAttribute *const att = - in_point_cloud_->GetNamedAttribute(GeometryAttribute::TEX_COORD); - if (att == nullptr || att->size() == 0) - return true; // It's OK if we don't have texture coordinates. - std::array<float, 2> value; - for (AttributeValueIndex i(0); i < static_cast<uint32_t>(att->size()); ++i) { - if (!att->ConvertValue<float, 2>(i, &value[0])) - return false; - buffer()->Encode("vt ", 3); - EncodeFloatList(&value[0], 2); - buffer()->Encode("\n", 1); - } - tex_coord_att_ = att; - return true; -} - -bool ObjEncoder::EncodeNormals() { - const PointAttribute *const att = - in_point_cloud_->GetNamedAttribute(GeometryAttribute::NORMAL); - if (att == nullptr || att->size() == 0) - return true; // It's OK if we don't have normals. - std::array<float, 3> value; - for (AttributeValueIndex i(0); i < static_cast<uint32_t>(att->size()); ++i) { - if (!att->ConvertValue<float, 3>(i, &value[0])) - return false; - buffer()->Encode("vn ", 3); - EncodeFloatList(&value[0], 3); - buffer()->Encode("\n", 1); - } - normal_att_ = att; - return true; -} - -bool ObjEncoder::EncodeFaces() { - for (FaceIndex i(0); i < in_mesh_->num_faces(); ++i) { - if (sub_obj_att_) - if (!EncodeSubObject(i)) - return false; - if (material_att_) - if (!EncodeMaterial(i)) - return false; - buffer()->Encode('f'); - for (int j = 0; j < 3; ++j) { - if (!EncodeFaceCorner(i, j)) - return false; - } - buffer()->Encode("\n", 1); - } - return true; -} - -bool ObjEncoder::EncodeMaterial(FaceIndex face_id) { - int material_id = 0; - // Pick the first corner, all corners of a face should have same id. - const PointIndex vert_index = in_mesh_->face(face_id)[0]; - const AttributeValueIndex index_id(material_att_->mapped_index(vert_index)); - if (!material_att_->ConvertValue<int>(index_id, &material_id)) { - return false; - } - - if (material_id != current_material_id_) { - // Update material information. - buffer()->Encode("usemtl ", 7); - const auto mat_ptr = material_id_to_name_.find(material_id); - // If the material id is not found. - if (mat_ptr == material_id_to_name_.end()) - return false; - buffer()->Encode(mat_ptr->second.c_str(), mat_ptr->second.size()); - buffer()->Encode("\n", 1); - current_material_id_ = material_id; - } - return true; -} - -bool ObjEncoder::EncodeSubObject(FaceIndex face_id) { - int sub_obj_id = 0; - // Pick the first corner, all corners of a face should have same id. - const PointIndex vert_index = in_mesh_->face(face_id)[0]; - const AttributeValueIndex index_id(sub_obj_att_->mapped_index(vert_index)); - if (!sub_obj_att_->ConvertValue<int>(index_id, &sub_obj_id)) { - return false; - } - if (sub_obj_id != current_sub_obj_id_) { - buffer()->Encode("o ", 2); - const auto sub_obj_ptr = sub_obj_id_to_name_.find(sub_obj_id); - if (sub_obj_ptr == sub_obj_id_to_name_.end()) - return false; - buffer()->Encode(sub_obj_ptr->second.c_str(), sub_obj_ptr->second.size()); - buffer()->Encode("\n", 1); - current_sub_obj_id_ = sub_obj_id; - } - return true; -} - -bool ObjEncoder::EncodeFaceCorner(FaceIndex face_id, int local_corner_id) { - buffer()->Encode(' '); - const PointIndex vert_index = in_mesh_->face(face_id)[local_corner_id]; - // Note that in the OBJ format, all indices are encoded starting from index 1. - // Encode position index. - EncodeInt(pos_att_->mapped_index(vert_index).value() + 1); - if (tex_coord_att_ || normal_att_) { - // Encoding format is pos_index/tex_coord_index/normal_index. - // If tex_coords are not present, we must encode pos_index//normal_index. - buffer()->Encode('/'); - if (tex_coord_att_) { - EncodeInt(tex_coord_att_->mapped_index(vert_index).value() + 1); - } - if (normal_att_) { - buffer()->Encode('/'); - EncodeInt(normal_att_->mapped_index(vert_index).value() + 1); - } - } - return true; -} - -void ObjEncoder::EncodeFloat(float val) { - snprintf(num_buffer_, sizeof(num_buffer_), "%f", val); - buffer()->Encode(num_buffer_, strlen(num_buffer_)); -} - -void ObjEncoder::EncodeFloatList(float *vals, int num_vals) { - for (int i = 0; i < num_vals; ++i) { - if (i > 0) { - buffer()->Encode(' '); - } - EncodeFloat(vals[i]); - } -} - -void ObjEncoder::EncodeInt(int32_t val) { - snprintf(num_buffer_, sizeof(num_buffer_), "%d", val); - buffer()->Encode(num_buffer_, strlen(num_buffer_)); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/obj_encoder.h b/extern/draco/dracoenc/src/draco/io/obj_encoder.h deleted file mode 100644 index 509d39baf39..00000000000 --- a/extern/draco/dracoenc/src/draco/io/obj_encoder.h +++ /dev/null @@ -1,92 +0,0 @@ -// 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. -// -#ifndef DRACO_IO_OBJ_ENCODER_H_ -#define DRACO_IO_OBJ_ENCODER_H_ - -#include <unordered_map> - -#include "draco/core/encoder_buffer.h" -#include "draco/mesh/mesh.h" - -namespace draco { - -// Class for encoding input draco::Mesh or draco::PointCloud into the Wavefront -// OBJ format. -class ObjEncoder { - public: - ObjEncoder(); - - // Encodes the mesh or a point cloud and saves it into a file. - // Returns false when either the encoding failed or when the file couldn't be - // opened. - bool EncodeToFile(const PointCloud &pc, const std::string &file_name); - bool EncodeToFile(const Mesh &mesh, const std::string &file_name); - - // Encodes the mesh or the point cloud into a buffer. - bool EncodeToBuffer(const PointCloud &pc, EncoderBuffer *out_buffer); - bool EncodeToBuffer(const Mesh &mesh, EncoderBuffer *out_buffer); - - protected: - bool EncodeInternal(); - EncoderBuffer *buffer() const { return out_buffer_; } - bool ExitAndCleanup(bool return_value); - - private: - bool GetSubObjects(); - bool EncodeMaterialFileName(); - bool EncodePositions(); - bool EncodeTextureCoordinates(); - bool EncodeNormals(); - bool EncodeFaces(); - bool EncodeSubObject(FaceIndex face_id); - bool EncodeMaterial(FaceIndex face_id); - bool EncodeFaceCorner(FaceIndex face_id, int local_corner_id); - - void EncodeFloat(float val); - void EncodeFloatList(float *vals, int num_vals); - void EncodeInt(int32_t val); - - // Various attributes used by the encoder. If an attribute is not used, it is - // set to nullptr. - const PointAttribute *pos_att_; - const PointAttribute *tex_coord_att_; - const PointAttribute *normal_att_; - const PointAttribute *material_att_; - const PointAttribute *sub_obj_att_; - - // Buffer used for encoding float/int numbers. - char num_buffer_[20]; - - EncoderBuffer *out_buffer_; - - const PointCloud *in_point_cloud_; - const Mesh *in_mesh_; - - // Store sub object name for each value. - std::unordered_map<int, std::string> sub_obj_id_to_name_; - // Current sub object id of faces. - int current_sub_obj_id_; - - // Store material name for each value in material attribute. - std::unordered_map<int, std::string> material_id_to_name_; - // Current material id of faces. - int current_material_id_; - - std::string file_name_; -}; - -} // namespace draco - -#endif // DRACO_IO_OBJ_ENCODER_H_ diff --git a/extern/draco/dracoenc/src/draco/io/obj_encoder_test.cc b/extern/draco/dracoenc/src/draco/io/obj_encoder_test.cc deleted file mode 100644 index 79ea1712806..00000000000 --- a/extern/draco/dracoenc/src/draco/io/obj_encoder_test.cc +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2017 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 <fstream> -#include <sstream> - -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/io/obj_decoder.h" -#include "draco/io/obj_encoder.h" - -namespace draco { - -class ObjEncoderTest : public ::testing::Test { - protected: - void CompareMeshes(const Mesh *mesh0, const Mesh *mesh1) { - ASSERT_EQ(mesh0->num_faces(), mesh1->num_faces()); - ASSERT_EQ(mesh0->num_attributes(), mesh1->num_attributes()); - for (size_t att_id = 0; att_id < mesh0->num_attributes(); ++att_id) { - ASSERT_EQ(mesh0->attribute(att_id)->size(), - mesh1->attribute(att_id)->size()); - } - } - - // Encode a mesh using the ObjEncoder and then decode to verify the encoding. - std::unique_ptr<Mesh> EncodeAndDecodeMesh(const Mesh *mesh) { - EncoderBuffer encoder_buffer; - ObjEncoder encoder; - if (!encoder.EncodeToBuffer(*mesh, &encoder_buffer)) - return nullptr; - - DecoderBuffer decoder_buffer; - decoder_buffer.Init(encoder_buffer.data(), encoder_buffer.size()); - std::unique_ptr<Mesh> decoded_mesh(new Mesh()); - ObjDecoder decoder; - decoder.set_use_metadata(true); - if (!decoder.DecodeFromBuffer(&decoder_buffer, decoded_mesh.get()).ok()) - return nullptr; - return decoded_mesh; - } - - void test_encoding(const std::string &file_name) { - const std::unique_ptr<Mesh> mesh(ReadMeshFromTestFile(file_name, true)); - - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - ASSERT_GT(mesh->num_faces(), 0); - - const std::unique_ptr<Mesh> decoded_mesh = EncodeAndDecodeMesh(mesh.get()); - CompareMeshes(mesh.get(), decoded_mesh.get()); - } -}; - -TEST_F(ObjEncoderTest, HasSubObject) { test_encoding("cube_att_sub_o.obj"); } - -TEST_F(ObjEncoderTest, HasMaterial) { - const std::unique_ptr<Mesh> mesh0(ReadMeshFromTestFile("mat_test.obj", true)); - ASSERT_NE(mesh0, nullptr); - const std::unique_ptr<Mesh> mesh1 = EncodeAndDecodeMesh(mesh0.get()); - ASSERT_NE(mesh1, nullptr); - ASSERT_EQ(mesh0->num_faces(), mesh1->num_faces()); - ASSERT_EQ(mesh0->num_attributes(), mesh1->num_attributes()); - // Position attribute should be the same. - ASSERT_EQ(mesh0->attribute(0)->size(), mesh1->attribute(0)->size()); - // Since |mesh1| is decoded from buffer, it has not material file. So the - // size of material attribute is the number of materials used in the obj - // file which is 7. The size of material attribute of |mesh0| decoded from - // the obj file will be the number of materials defined in the .mtl file. - ASSERT_EQ(mesh0->attribute(1)->size(), 29); - ASSERT_EQ(mesh1->attribute(1)->size(), 7); -} - -TEST_F(ObjEncoderTest, TestObjEncodingAll) { - // Test decoded mesh from encoded obj file stays the same. - test_encoding("bunny_norm.obj"); - test_encoding("cube_att.obj"); - test_encoding("cube_att_partial.obj"); - test_encoding("cube_quads.obj"); - test_encoding("cube_subd.obj"); - test_encoding("extra_vertex.obj"); - test_encoding("multiple_isolated_triangles.obj"); - test_encoding("multiple_tetrahedrons.obj"); - test_encoding("one_face_123.obj"); - test_encoding("one_face_312.obj"); - test_encoding("one_face_321.obj"); - test_encoding("sphere.obj"); - test_encoding("test_nm.obj"); - test_encoding("test_nm_trans.obj"); - test_encoding("test_sphere.obj"); - test_encoding("three_faces_123.obj"); - test_encoding("three_faces_312.obj"); - test_encoding("two_faces_123.obj"); - test_encoding("two_faces_312.obj"); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/parser_utils.cc b/extern/draco/dracoenc/src/draco/io/parser_utils.cc deleted file mode 100644 index 0a22ba114ab..00000000000 --- a/extern/draco/dracoenc/src/draco/io/parser_utils.cc +++ /dev/null @@ -1,232 +0,0 @@ -// 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 "draco/io/parser_utils.h" - -#include <algorithm> -#include <cctype> -#include <cmath> -#include <iterator> - -namespace draco { -namespace parser { - -void SkipCharacters(DecoderBuffer *buffer, const char *skip_chars) { - if (skip_chars == nullptr) - return; - const int num_skip_chars = static_cast<int>(strlen(skip_chars)); - char c; - while (buffer->Peek(&c)) { - // Check all characters in the pattern. - bool skip = false; - for (int i = 0; i < num_skip_chars; ++i) { - if (c == skip_chars[i]) { - skip = true; - break; - } - } - if (!skip) - return; - buffer->Advance(1); - } -} - -void SkipWhitespace(DecoderBuffer *buffer) { - bool end_reached = false; - while (PeekWhitespace(buffer, &end_reached) && !end_reached) { - // Skip the whitespace character - buffer->Advance(1); - } -} - -bool PeekWhitespace(DecoderBuffer *buffer, bool *end_reached) { - uint8_t c; - if (!buffer->Peek(&c)) { - *end_reached = true; - return false; // eof reached. - } - if (!isspace(c)) - return false; // Non-whitespace character reached. - return true; -} - -void SkipLine(DecoderBuffer *buffer) { - char c; - while (buffer->Peek(&c)) { - // Skip the character. - buffer->Advance(1); - if (c == '\n') - return; // Return at the end of line - } -} - -bool ParseFloat(DecoderBuffer *buffer, float *value) { - // Read optional sign. - char ch; - if (!buffer->Peek(&ch)) - return false; - int sign = GetSignValue(ch); - if (sign != 0) { - buffer->Advance(1); - } else { - sign = 1; - } - - // Parse integer component. - bool have_digits = false; - double v = 0.0; - while (buffer->Peek(&ch) && ch >= '0' && ch <= '9') { - v *= 10.0; - v += (ch - '0'); - buffer->Advance(1); - have_digits = true; - } - if (ch == '.') { - // Parse fractional component. - buffer->Advance(1); - double fraction = 1.0; - while (buffer->Peek(&ch) && ch >= '0' && ch <= '9') { - fraction *= 0.1; - v += (ch - '0') * fraction; - buffer->Advance(1); - have_digits = true; - } - } - - if (!have_digits) { - // Check for special constants (inf, nan, ...). - std::string text; - if (!ParseString(buffer, &text)) - return false; - if (text == "inf" || text == "Inf") { - v = std::numeric_limits<double>::infinity(); - } else if (text == "nan" || text == "NaN") { - v = nan(""); - } else { - // Invalid string. - return false; - } - } else { - // Handle exponent if present. - if (ch == 'e' || ch == 'E') { - buffer->Advance(1); // Skip 'e' marker. - - // Parse integer exponent. - int32_t exponent = 0; - if (!ParseSignedInt(buffer, &exponent)) - return false; - - // Apply exponent scaling to value. - v *= pow(static_cast<double>(10.0), exponent); - } - } - - *value = (sign < 0) ? static_cast<float>(-v) : static_cast<float>(v); - return true; -} - -bool ParseSignedInt(DecoderBuffer *buffer, int32_t *value) { - // Parse any explicit sign and set the appropriate largest magnitude - // value that can be represented without overflow. - char ch; - if (!buffer->Peek(&ch)) - return false; - const int sign = GetSignValue(ch); - if (sign != 0) - buffer->Advance(1); - - // Attempt to parse integer body. - uint32_t v; - if (!ParseUnsignedInt(buffer, &v)) - return false; - *value = (sign < 0) ? -v : v; - return true; -} - -bool ParseUnsignedInt(DecoderBuffer *buffer, uint32_t *value) { - // Parse the number until we run out of digits. - uint32_t v = 0; - char ch; - bool have_digits = false; - while (buffer->Peek(&ch) && ch >= '0' && ch <= '9') { - v *= 10; - v += (ch - '0'); - buffer->Advance(1); - have_digits = true; - } - if (!have_digits) - return false; - *value = v; - return true; -} - -int GetSignValue(char c) { - if (c == '-') - return -1; - if (c == '+') - return 1; - return 0; -} - -bool ParseString(DecoderBuffer *buffer, std::string *out_string) { - out_string->clear(); - SkipWhitespace(buffer); - bool end_reached = false; - while (!PeekWhitespace(buffer, &end_reached) && !end_reached) { - char c; - if (!buffer->Decode(&c)) - return false; - *out_string += c; - } - return true; -} - -void ParseLine(DecoderBuffer *buffer, std::string *out_string) { - out_string->clear(); - char c; - while (buffer->Peek(&c)) { - // Skip the character. - buffer->Advance(1); - if (c == '\n') - return; // Return at the end of line. - if (c == '\r') - continue; // Ignore extra line ending characters. - *out_string += c; - } -} - -DecoderBuffer ParseLineIntoDecoderBuffer(DecoderBuffer *buffer) { - const char *const head = buffer->data_head(); - char c; - while (buffer->Peek(&c)) { - // Skip the character. - buffer->Advance(1); - if (c == '\n') - break; // End of the line reached. - if (c == '\r') - continue; // Ignore extra line ending characters. - } - DecoderBuffer out_buffer; - out_buffer.Init(head, buffer->data_head() - head); - return out_buffer; -} - -std::string ToLower(const std::string &str) { - std::string out; - std::transform(str.begin(), str.end(), std::back_inserter(out), tolower); - return out; -} - -} // namespace parser -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/parser_utils.h b/extern/draco/dracoenc/src/draco/io/parser_utils.h deleted file mode 100644 index aa629053068..00000000000 --- a/extern/draco/dracoenc/src/draco/io/parser_utils.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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. -// -#ifndef DRACO_IO_PARSER_UTILS_H_ -#define DRACO_IO_PARSER_UTILS_H_ - -#include "draco/core/decoder_buffer.h" - -namespace draco { -namespace parser { - -// Skips to first character not included in |skip_chars|. -void SkipCharacters(DecoderBuffer *buffer, const char *skip_chars); - -// Skips any whitespace until a regular character is reached. -void SkipWhitespace(DecoderBuffer *buffer); - -// Returns true if the next character is a whitespace. -// |end_reached| is set to true when the end of the stream is reached. -bool PeekWhitespace(DecoderBuffer *buffer, bool *end_reached); -void SkipLine(DecoderBuffer *buffer); - -// Parses signed floating point number or returns false on error. -bool ParseFloat(DecoderBuffer *buffer, float *value); - -// Parses a signed integer (can be preceded by '-' or '+' characters. -bool ParseSignedInt(DecoderBuffer *buffer, int32_t *value); - -// Parses an unsigned integer. It cannot be preceded by '-' or '+' -// characters. -bool ParseUnsignedInt(DecoderBuffer *buffer, uint32_t *value); - -// Returns -1 if c == '-'. -// Returns +1 if c == '+'. -// Returns 0 otherwise. -int GetSignValue(char c); - -// Parses a string until a whitespace or end of file is reached. -bool ParseString(DecoderBuffer *buffer, std::string *out_string); - -// Parses the entire line into the buffer (excluding the new line character). -void ParseLine(DecoderBuffer *buffer, std::string *out_string); - -// Parses line and stores into a new decoder buffer. -DecoderBuffer ParseLineIntoDecoderBuffer(DecoderBuffer *buffer); - -// Returns a string with all characters converted to lower case. -std::string ToLower(const std::string &str); - -} // namespace parser -} // namespace draco - -#endif // DRACO_IO_PARSER_UTILS_H_ diff --git a/extern/draco/dracoenc/src/draco/io/ply_decoder.cc b/extern/draco/dracoenc/src/draco/io/ply_decoder.cc deleted file mode 100644 index 69a1c546cf7..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_decoder.cc +++ /dev/null @@ -1,295 +0,0 @@ -// 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 "draco/io/ply_decoder.h" - -#include <fstream> - -#include "draco/core/macros.h" -#include "draco/core/status.h" -#include "draco/io/ply_property_reader.h" - -namespace draco { - -PlyDecoder::PlyDecoder() : out_mesh_(nullptr), out_point_cloud_(nullptr) {} - -Status PlyDecoder::DecodeFromFile(const std::string &file_name, - Mesh *out_mesh) { - out_mesh_ = out_mesh; - return DecodeFromFile(file_name, static_cast<PointCloud *>(out_mesh)); -} - -Status PlyDecoder::DecodeFromFile(const std::string &file_name, - PointCloud *out_point_cloud) { - std::ifstream file(file_name, std::ios::binary); - if (!file) - return Status(Status::IO_ERROR, "Couldn't open file"); - // Read the whole file into a buffer. - auto pos0 = file.tellg(); - file.seekg(0, std::ios::end); - auto file_size = file.tellg() - pos0; - if (file_size == 0) - return Status(Status::IO_ERROR, "Zero file size"); - file.seekg(0, std::ios::beg); - std::vector<char> data(file_size); - file.read(&data[0], file_size); - - buffer_.Init(&data[0], file_size); - return DecodeFromBuffer(&buffer_, out_point_cloud); -} - -Status PlyDecoder::DecodeFromBuffer(DecoderBuffer *buffer, Mesh *out_mesh) { - out_mesh_ = out_mesh; - return DecodeFromBuffer(buffer, static_cast<PointCloud *>(out_mesh)); -} - -Status PlyDecoder::DecodeFromBuffer(DecoderBuffer *buffer, - PointCloud *out_point_cloud) { - out_point_cloud_ = out_point_cloud; - buffer_.Init(buffer->data_head(), buffer->remaining_size()); - return DecodeInternal(); -} - -Status PlyDecoder::DecodeInternal() { - PlyReader ply_reader; - DRACO_RETURN_IF_ERROR(ply_reader.Read(buffer())); - // First, decode the connectivity data. - if (out_mesh_) - DRACO_RETURN_IF_ERROR(DecodeFaceData(ply_reader.GetElementByName("face"))); - // Decode all attributes. - DRACO_RETURN_IF_ERROR( - DecodeVertexData(ply_reader.GetElementByName("vertex"))); - // In case there are no faces this is just a point cloud which does - // not require deduplication. - if (out_mesh_ && out_mesh_->num_faces() != 0) { -#ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED - if (!out_point_cloud_->DeduplicateAttributeValues()) - return Status(Status::DRACO_ERROR, - "Could not deduplicate attribute values"); -#endif -#ifdef DRACO_ATTRIBUTE_INDICES_DEDUPLICATION_SUPPORTED - out_point_cloud_->DeduplicatePointIds(); -#endif - } - return OkStatus(); -} - -Status PlyDecoder::DecodeFaceData(const PlyElement *face_element) { - // We accept point clouds now. - if (face_element == nullptr) { - return Status(Status::INVALID_PARAMETER, "face_element is null"); - } - const int64_t num_faces = face_element->num_entries(); - out_mesh_->SetNumFaces(num_faces); - const PlyProperty *vertex_indices = - face_element->GetPropertyByName("vertex_indices"); - if (vertex_indices == nullptr) { - // The property name may be named either "vertex_indices" or "vertex_index". - vertex_indices = face_element->GetPropertyByName("vertex_index"); - } - if (vertex_indices == nullptr || !vertex_indices->is_list()) { - return Status(Status::DRACO_ERROR, "No faces defined"); - } - - PlyPropertyReader<PointIndex::ValueType> vertex_index_reader(vertex_indices); - Mesh::Face face; - FaceIndex face_index(0); - for (int i = 0; i < num_faces; ++i) { - const int64_t list_offset = vertex_indices->GetListEntryOffset(i); - const int64_t list_size = vertex_indices->GetListEntryNumValues(i); - // TODO(ostava): Assume triangular faces only for now. - if (list_size != 3) - continue; // All non-triangular faces are skipped. - for (int64_t c = 0; c < 3; ++c) - face[c] = - vertex_index_reader.ReadValue(static_cast<int>(list_offset + c)); - out_mesh_->SetFace(face_index, face); - face_index++; - } - out_mesh_->SetNumFaces(face_index.value()); - return OkStatus(); -} - -template <typename DataTypeT> -bool PlyDecoder::ReadPropertiesToAttribute( - const std::vector<const PlyProperty *> &properties, - PointAttribute *attribute, int num_vertices) { - std::vector<std::unique_ptr<PlyPropertyReader<DataTypeT>>> readers; - readers.reserve(properties.size()); - for (int prop = 0; prop < properties.size(); ++prop) { - readers.push_back(std::unique_ptr<PlyPropertyReader<DataTypeT>>( - new PlyPropertyReader<DataTypeT>(properties[prop]))); - } - std::vector<DataTypeT> memory(properties.size()); - for (PointIndex::ValueType i = 0; i < static_cast<uint32_t>(num_vertices); - ++i) { - for (int prop = 0; prop < properties.size(); ++prop) { - memory[prop] = readers[prop]->ReadValue(i); - } - attribute->SetAttributeValue(AttributeValueIndex(i), memory.data()); - } - return true; -} - -Status PlyDecoder::DecodeVertexData(const PlyElement *vertex_element) { - if (vertex_element == nullptr) - return Status(Status::INVALID_PARAMETER, "vertex_element is null"); - // TODO(ostava): For now, try to load x,y,z vertices and red,green,blue,alpha - // colors. We need to add other properties later. - const PlyProperty *const x_prop = vertex_element->GetPropertyByName("x"); - const PlyProperty *const y_prop = vertex_element->GetPropertyByName("y"); - const PlyProperty *const z_prop = vertex_element->GetPropertyByName("z"); - if (!x_prop || !y_prop || !z_prop) { - // Currently, we require 3 vertex coordinates (this should be generalized - // later on). - return Status(Status::INVALID_PARAMETER, "x, y, or z property is missing"); - } - const PointIndex::ValueType num_vertices = vertex_element->num_entries(); - out_point_cloud_->set_num_points(num_vertices); - // Decode vertex positions. - { - // All properties must have the same type. - if (x_prop->data_type() != y_prop->data_type() || - y_prop->data_type() != z_prop->data_type()) { - return Status(Status::INVALID_PARAMETER, - "x, y, and z properties must have the same type"); - } - // TODO(ostava): For now assume the position types are float32 or int32. - const DataType dt = x_prop->data_type(); - if (dt != DT_FLOAT32 && dt != DT_INT32) - return Status(Status::INVALID_PARAMETER, - "x, y, and z properties must be of type float32 or int32"); - - GeometryAttribute va; - va.Init(GeometryAttribute::POSITION, nullptr, 3, dt, false, - DataTypeLength(dt) * 3, 0); - const int att_id = out_point_cloud_->AddAttribute(va, true, num_vertices); - std::vector<const PlyProperty *> properties; - properties.push_back(x_prop); - properties.push_back(y_prop); - properties.push_back(z_prop); - if (dt == DT_FLOAT32) { - ReadPropertiesToAttribute<float>( - properties, out_point_cloud_->attribute(att_id), num_vertices); - } else if (dt == DT_INT32) { - ReadPropertiesToAttribute<int32_t>( - properties, out_point_cloud_->attribute(att_id), num_vertices); - } - } - - // Decode normals if present. - const PlyProperty *const n_x_prop = vertex_element->GetPropertyByName("nx"); - const PlyProperty *const n_y_prop = vertex_element->GetPropertyByName("ny"); - const PlyProperty *const n_z_prop = vertex_element->GetPropertyByName("nz"); - if (n_x_prop != nullptr && n_y_prop != nullptr && n_z_prop != nullptr) { - // For now, all normal properties must be set and of type float32 - if (n_x_prop->data_type() == DT_FLOAT32 && - n_y_prop->data_type() == DT_FLOAT32 && - n_z_prop->data_type() == DT_FLOAT32) { - PlyPropertyReader<float> x_reader(n_x_prop); - PlyPropertyReader<float> y_reader(n_y_prop); - PlyPropertyReader<float> z_reader(n_z_prop); - GeometryAttribute va; - va.Init(GeometryAttribute::NORMAL, nullptr, 3, DT_FLOAT32, false, - sizeof(float) * 3, 0); - const int att_id = out_point_cloud_->AddAttribute(va, true, num_vertices); - for (PointIndex::ValueType i = 0; i < num_vertices; ++i) { - std::array<float, 3> val; - val[0] = x_reader.ReadValue(i); - val[1] = y_reader.ReadValue(i); - val[2] = z_reader.ReadValue(i); - out_point_cloud_->attribute(att_id)->SetAttributeValue( - AttributeValueIndex(i), &val[0]); - } - } - } - - // Decode color data if present. - int num_colors = 0; - const PlyProperty *const r_prop = vertex_element->GetPropertyByName("red"); - const PlyProperty *const g_prop = vertex_element->GetPropertyByName("green"); - const PlyProperty *const b_prop = vertex_element->GetPropertyByName("blue"); - const PlyProperty *const a_prop = vertex_element->GetPropertyByName("alpha"); - if (r_prop) - ++num_colors; - if (g_prop) - ++num_colors; - if (b_prop) - ++num_colors; - if (a_prop) - ++num_colors; - - if (num_colors) { - std::vector<std::unique_ptr<PlyPropertyReader<uint8_t>>> color_readers; - const PlyProperty *p; - if (r_prop) { - p = r_prop; - // TODO(ostava): For now ensure the data type of all components is uint8. - DRACO_DCHECK_EQ(true, p->data_type() == DT_UINT8); - if (p->data_type() != DT_UINT8) - return Status(Status::INVALID_PARAMETER, - "Type of 'red' property must be uint8"); - color_readers.push_back(std::unique_ptr<PlyPropertyReader<uint8_t>>( - new PlyPropertyReader<uint8_t>(p))); - } - if (g_prop) { - p = g_prop; - // TODO(ostava): For now ensure the data type of all components is uint8. - DRACO_DCHECK_EQ(true, p->data_type() == DT_UINT8); - if (p->data_type() != DT_UINT8) - return Status(Status::INVALID_PARAMETER, - "Type of 'green' property must be uint8"); - color_readers.push_back(std::unique_ptr<PlyPropertyReader<uint8_t>>( - new PlyPropertyReader<uint8_t>(p))); - } - if (b_prop) { - p = b_prop; - // TODO(ostava): For now ensure the data type of all components is uint8. - DRACO_DCHECK_EQ(true, p->data_type() == DT_UINT8); - if (p->data_type() != DT_UINT8) - return Status(Status::INVALID_PARAMETER, - "Type of 'blue' property must be uint8"); - color_readers.push_back(std::unique_ptr<PlyPropertyReader<uint8_t>>( - new PlyPropertyReader<uint8_t>(p))); - } - if (a_prop) { - p = a_prop; - // TODO(ostava): For now ensure the data type of all components is uint8. - DRACO_DCHECK_EQ(true, p->data_type() == DT_UINT8); - if (p->data_type() != DT_UINT8) - return Status(Status::INVALID_PARAMETER, - "Type of 'alpha' property must be uint8"); - color_readers.push_back(std::unique_ptr<PlyPropertyReader<uint8_t>>( - new PlyPropertyReader<uint8_t>(p))); - } - - GeometryAttribute va; - va.Init(GeometryAttribute::COLOR, nullptr, num_colors, DT_UINT8, true, - sizeof(uint8_t) * num_colors, 0); - const int32_t att_id = - out_point_cloud_->AddAttribute(va, true, num_vertices); - for (PointIndex::ValueType i = 0; i < num_vertices; ++i) { - std::array<uint8_t, 4> val; - for (int j = 0; j < num_colors; j++) { - val[j] = color_readers[j]->ReadValue(i); - } - out_point_cloud_->attribute(att_id)->SetAttributeValue( - AttributeValueIndex(i), &val[0]); - } - } - - return OkStatus(); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/ply_decoder.h b/extern/draco/dracoenc/src/draco/io/ply_decoder.h deleted file mode 100644 index 9e667ab192f..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_decoder.h +++ /dev/null @@ -1,69 +0,0 @@ -// 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. -// -#ifndef DRACO_IO_MESH_PLY_DECODER_H_ -#define DRACO_IO_MESH_PLY_DECODER_H_ - -#include <string> - -#include "draco/draco_features.h" - -#include "draco/core/decoder_buffer.h" -#include "draco/core/status.h" -#include "draco/io/ply_reader.h" -#include "draco/mesh/mesh.h" - -namespace draco { - -// Decodes a Wavefront OBJ file into draco::Mesh (or draco::PointCloud if the -// connectivity data is not needed). -// TODO(ostava): The current implementation assumes that the input vertices are -// defined with x, y, z properties. The decoder also reads uint8 red, green, -// blue, alpha color information, but all other attributes are ignored for now. -class PlyDecoder { - public: - PlyDecoder(); - - // Decodes an obj file stored in the input file. - Status DecodeFromFile(const std::string &file_name, Mesh *out_mesh); - Status DecodeFromFile(const std::string &file_name, - PointCloud *out_point_cloud); - - Status DecodeFromBuffer(DecoderBuffer *buffer, Mesh *out_mesh); - Status DecodeFromBuffer(DecoderBuffer *buffer, PointCloud *out_point_cloud); - - protected: - Status DecodeInternal(); - DecoderBuffer *buffer() { return &buffer_; } - - private: - Status DecodeFaceData(const PlyElement *face_element); - Status DecodeVertexData(const PlyElement *vertex_element); - - template <typename DataTypeT> - bool ReadPropertiesToAttribute( - const std::vector<const PlyProperty *> &properties, - PointAttribute *attribute, int num_vertices); - - DecoderBuffer buffer_; - - // Data structure that stores the decoded data. |out_point_cloud_| must be - // always set but |out_mesh_| is optional. - Mesh *out_mesh_; - PointCloud *out_point_cloud_; -}; - -} // namespace draco - -#endif // DRACO_IO_MESH_PLY_DECODER_H_ diff --git a/extern/draco/dracoenc/src/draco/io/ply_decoder_test.cc b/extern/draco/dracoenc/src/draco/io/ply_decoder_test.cc deleted file mode 100644 index 647324ea904..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_decoder_test.cc +++ /dev/null @@ -1,90 +0,0 @@ -// 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 "draco/io/ply_decoder.h" - -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" - -namespace draco { - -class PlyDecoderTest : public ::testing::Test { - protected: - template <class Geometry> - std::unique_ptr<Geometry> DecodePly(const std::string &file_name) const { - const std::string path = GetTestFileFullPath(file_name); - PlyDecoder decoder; - std::unique_ptr<Geometry> geometry(new Geometry()); - Status status = decoder.DecodeFromFile(path, geometry.get()); - if (!status.ok()) { - LOG(DRACO_ERROR) << "Failed to decode " << file_name << ": " << status; - return nullptr; - } - return geometry; - } - - void test_decoding(const std::string &file_name, int num_faces, - uint32_t num_points, std::unique_ptr<Mesh> *out_mesh) { - // Don't test mesh decoding when the input is point cloud. - if (num_faces > 0) { - std::unique_ptr<Mesh> mesh(DecodePly<Mesh>(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - ASSERT_EQ(mesh->num_faces(), num_faces); - if (out_mesh) - *out_mesh = std::move(mesh); - } - - const std::unique_ptr<PointCloud> pc(DecodePly<PointCloud>(file_name)); - ASSERT_NE(pc, nullptr) << "Failed to load test model " << file_name; - ASSERT_EQ(pc->num_points(), num_points); - } - void test_decoding(const std::string &file_name) { - const std::unique_ptr<Mesh> mesh(DecodePly<Mesh>(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model " << file_name; - ASSERT_GT(mesh->num_faces(), 0); - - const std::unique_ptr<PointCloud> pc(DecodePly<PointCloud>(file_name)); - ASSERT_NE(pc, nullptr) << "Failed to load test model " << file_name; - ASSERT_GT(pc->num_points(), 0); - } -}; - -TEST_F(PlyDecoderTest, TestPlyDecoding) { - const std::string file_name = "test_pos_color.ply"; - test_decoding(file_name, 224, 114, nullptr); -} - -TEST_F(PlyDecoderTest, TestPlyNormals) { - const std::string file_name = "cube_att.ply"; - std::unique_ptr<Mesh> mesh; - test_decoding(file_name, 12, 3 * 8, &mesh); - ASSERT_NE(mesh, nullptr); - const int att_id = mesh->GetNamedAttributeId(GeometryAttribute::NORMAL); - ASSERT_GE(att_id, 0); - const PointAttribute *const att = mesh->attribute(att_id); - ASSERT_EQ(att->size(), 6); // 6 unique normal values. -} - -TEST_F(PlyDecoderTest, TestPlyDecodingAll) { - // test if we can read all ply that are currently in test folder. - test_decoding("bun_zipper.ply"); - // test_decoding("cube_att.ply"); // tested - test_decoding("test_extra_whitespace.ply"); - test_decoding("test_more_datatypes.ply"); - test_decoding("test_pos_color_ascii.ply"); - test_decoding("int_point_cloud.ply", 0, 16, nullptr); - // test_decoding("test_pos_color.ply"); // tested -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/ply_encoder.cc b/extern/draco/dracoenc/src/draco/io/ply_encoder.cc deleted file mode 100644 index cb25b21d4f8..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_encoder.cc +++ /dev/null @@ -1,201 +0,0 @@ -// 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 "draco/io/ply_encoder.h" - -#include <fstream> -#include <sstream> - -namespace draco { - -PlyEncoder::PlyEncoder() - : out_buffer_(nullptr), in_point_cloud_(nullptr), in_mesh_(nullptr) {} - -bool PlyEncoder::EncodeToFile(const PointCloud &pc, - const std::string &file_name) { - std::ofstream file(file_name, std::ios::binary); - if (!file) - return false; // File couldn't be opened. - // Encode the mesh into a buffer. - EncoderBuffer buffer; - if (!EncodeToBuffer(pc, &buffer)) - return false; - // Write the buffer into the file. - file.write(buffer.data(), buffer.size()); - return true; -} - -bool PlyEncoder::EncodeToFile(const Mesh &mesh, const std::string &file_name) { - in_mesh_ = &mesh; - return EncodeToFile(static_cast<const PointCloud &>(mesh), file_name); -} - -bool PlyEncoder::EncodeToBuffer(const PointCloud &pc, - EncoderBuffer *out_buffer) { - in_point_cloud_ = &pc; - out_buffer_ = out_buffer; - if (!EncodeInternal()) - return ExitAndCleanup(false); - return ExitAndCleanup(true); -} - -bool PlyEncoder::EncodeToBuffer(const Mesh &mesh, EncoderBuffer *out_buffer) { - in_mesh_ = &mesh; - return EncodeToBuffer(static_cast<const PointCloud &>(mesh), out_buffer); -} -bool PlyEncoder::EncodeInternal() { - // Write PLY header. - // TODO(ostava): Currently works only for xyz positions and rgb(a) colors. - std::stringstream out; - out << "ply" << std::endl; - out << "format binary_little_endian 1.0" << std::endl; - out << "element vertex " << in_point_cloud_->num_points() << std::endl; - - const int pos_att_id = - in_point_cloud_->GetNamedAttributeId(GeometryAttribute::POSITION); - int normal_att_id = - in_point_cloud_->GetNamedAttributeId(GeometryAttribute::NORMAL); - int tex_coord_att_id = - in_point_cloud_->GetNamedAttributeId(GeometryAttribute::TEX_COORD); - const int color_att_id = - in_point_cloud_->GetNamedAttributeId(GeometryAttribute::COLOR); - - if (pos_att_id < 0) - return false; - - // Ensure normals are 3 component. Don't encode them otherwise. - if (normal_att_id >= 0 && - in_point_cloud_->attribute(normal_att_id)->num_components() != 3) - normal_att_id = -1; - - // Ensure texture coordinates have only 2 components. Don't encode them - // otherwise. TODO(ostava): Add support for 3 component normals (uvw). - if (tex_coord_att_id >= 0 && - in_point_cloud_->attribute(tex_coord_att_id)->num_components() != 2) - tex_coord_att_id = -1; - - out << "property " << GetAttributeDataType(pos_att_id) << " x" << std::endl; - out << "property " << GetAttributeDataType(pos_att_id) << " y" << std::endl; - out << "property " << GetAttributeDataType(pos_att_id) << " z" << std::endl; - if (normal_att_id >= 0) { - out << "property " << GetAttributeDataType(normal_att_id) << " nx" - << std::endl; - out << "property " << GetAttributeDataType(normal_att_id) << " ny" - << std::endl; - out << "property " << GetAttributeDataType(normal_att_id) << " nz" - << std::endl; - } - if (color_att_id >= 0) { - const auto *const attribute = in_point_cloud_->attribute(color_att_id); - if (attribute->num_components() > 0) { - out << "property " << GetAttributeDataType(color_att_id) << " red" - << std::endl; - } - if (attribute->num_components() > 1) { - out << "property " << GetAttributeDataType(color_att_id) << " green" - << std::endl; - } - if (attribute->num_components() > 2) { - out << "property " << GetAttributeDataType(color_att_id) << " blue" - << std::endl; - } - if (attribute->num_components() > 3) { - out << "property " << GetAttributeDataType(color_att_id) << " alpha" - << std::endl; - } - } - if (in_mesh_) { - out << "element face " << in_mesh_->num_faces() << std::endl; - out << "property list uchar int vertex_indices" << std::endl; - if (tex_coord_att_id >= 0) { - // Texture coordinates are usually encoded in the property list (one value - // per corner). - out << "property list uchar " << GetAttributeDataType(tex_coord_att_id) - << " texcoord" << std::endl; - } - } - out << "end_header" << std::endl; - - // Not very efficient but the header should be small so just copy the stream - // to a string. - const std::string header_str = out.str(); - buffer()->Encode(header_str.data(), header_str.length()); - - // Store point attributes. - for (PointIndex v(0); v < in_point_cloud_->num_points(); ++v) { - const auto *const pos_att = in_point_cloud_->attribute(pos_att_id); - buffer()->Encode(pos_att->GetAddress(pos_att->mapped_index(v)), - pos_att->byte_stride()); - if (normal_att_id >= 0) { - const auto *const normal_att = in_point_cloud_->attribute(normal_att_id); - buffer()->Encode(normal_att->GetAddress(normal_att->mapped_index(v)), - normal_att->byte_stride()); - } - if (color_att_id >= 0) { - const auto *const color_att = in_point_cloud_->attribute(color_att_id); - buffer()->Encode(color_att->GetAddress(color_att->mapped_index(v)), - color_att->byte_stride()); - } - } - - if (in_mesh_) { - // Write face data. - for (FaceIndex i(0); i < in_mesh_->num_faces(); ++i) { - // Write the number of face indices (always 3). - buffer()->Encode(static_cast<uint8_t>(3)); - - const auto &f = in_mesh_->face(i); - buffer()->Encode(f[0]); - buffer()->Encode(f[1]); - buffer()->Encode(f[2]); - - if (tex_coord_att_id >= 0) { - // Two coordinates for every corner -> 6. - buffer()->Encode(static_cast<uint8_t>(6)); - - const auto *const tex_att = - in_point_cloud_->attribute(tex_coord_att_id); - for (int c = 0; c < 3; ++c) { - buffer()->Encode(tex_att->GetAddress(tex_att->mapped_index(f[c])), - tex_att->byte_stride()); - } - } - } - } - return true; -} - -bool PlyEncoder::ExitAndCleanup(bool return_value) { - in_mesh_ = nullptr; - in_point_cloud_ = nullptr; - out_buffer_ = nullptr; - return return_value; -} - -const char *PlyEncoder::GetAttributeDataType(int attribute) { - // TODO(ostava): Add support for more types. - switch (in_point_cloud_->attribute(attribute)->data_type()) { - case DT_FLOAT32: - return "float"; - case DT_UINT8: - return "uchar"; - case DT_INT32: - return "int"; - default: - break; - } - return nullptr; -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/ply_encoder.h b/extern/draco/dracoenc/src/draco/io/ply_encoder.h deleted file mode 100644 index 242bbd6d464..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_encoder.h +++ /dev/null @@ -1,54 +0,0 @@ -// 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. -// -#ifndef DRACO_IO_PLY_ENCODER_H_ -#define DRACO_IO_PLY_ENCODER_H_ - -#include "draco/core/encoder_buffer.h" -#include "draco/mesh/mesh.h" - -namespace draco { - -// Class for encoding draco::Mesh or draco::PointCloud into the PLY file format. -class PlyEncoder { - public: - PlyEncoder(); - - // Encodes the mesh or a point cloud and saves it into a file. - // Returns false when either the encoding failed or when the file couldn't be - // opened. - bool EncodeToFile(const PointCloud &pc, const std::string &file_name); - bool EncodeToFile(const Mesh &mesh, const std::string &file_name); - - // Encodes the mesh or the point cloud into a buffer. - bool EncodeToBuffer(const PointCloud &pc, EncoderBuffer *out_buffer); - bool EncodeToBuffer(const Mesh &mesh, EncoderBuffer *out_buffer); - - protected: - bool EncodeInternal(); - EncoderBuffer *buffer() const { return out_buffer_; } - bool ExitAndCleanup(bool return_value); - - private: - const char *GetAttributeDataType(int attribute); - - EncoderBuffer *out_buffer_; - - const PointCloud *in_point_cloud_; - const Mesh *in_mesh_; -}; - -} // namespace draco - -#endif // DRACO_IO_PLY_ENCODER_H_ diff --git a/extern/draco/dracoenc/src/draco/io/ply_property_reader.h b/extern/draco/dracoenc/src/draco/io/ply_property_reader.h deleted file mode 100644 index efb8a3a1f9d..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_property_reader.h +++ /dev/null @@ -1,96 +0,0 @@ -// 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. -// -#ifndef DRACO_IO_PLY_PROPERTY_READER_H_ -#define DRACO_IO_PLY_PROPERTY_READER_H_ - -#include <functional> - -#include "draco/io/ply_reader.h" - -namespace draco { - -// Class for reading PlyProperty with a given type, performing data conversion -// if necessary. -template <typename ReadTypeT> -class PlyPropertyReader { - public: - explicit PlyPropertyReader(const PlyProperty *property) - : property_(property) { - // Find the suitable function for converting values. - switch (property->data_type()) { - case DT_UINT8: - convert_value_func_ = [=](int val_id) { - return this->ConvertValue<uint8_t>(val_id); - }; - break; - case DT_INT8: - convert_value_func_ = [=](int val_id) { - return this->ConvertValue<int8_t>(val_id); - }; - break; - case DT_UINT16: - convert_value_func_ = [=](int val_id) { - return this->ConvertValue<uint16_t>(val_id); - }; - break; - case DT_INT16: - convert_value_func_ = [=](int val_id) { - return this->ConvertValue<int16_t>(val_id); - }; - break; - case DT_UINT32: - convert_value_func_ = [=](int val_id) { - return this->ConvertValue<uint32_t>(val_id); - }; - break; - case DT_INT32: - convert_value_func_ = [=](int val_id) { - return this->ConvertValue<int32_t>(val_id); - }; - break; - case DT_FLOAT32: - convert_value_func_ = [=](int val_id) { - return this->ConvertValue<float>(val_id); - }; - break; - case DT_FLOAT64: - convert_value_func_ = [=](int val_id) { - return this->ConvertValue<double>(val_id); - }; - break; - default: - break; - } - } - - ReadTypeT ReadValue(int value_id) const { - return convert_value_func_(value_id); - } - - private: - template <typename SourceTypeT> - ReadTypeT ConvertValue(int value_id) const { - const void *const address = property_->GetDataEntryAddress(value_id); - const SourceTypeT src_val = *reinterpret_cast<const SourceTypeT *>(address); - return static_cast<ReadTypeT>(src_val); - } - - const PlyProperty *property_; - std::function<ReadTypeT(int)> convert_value_func_; -}; - -} // namespace draco - -#endif // DRACO_IO_PLY_PROPERTY_READER_H_ diff --git a/extern/draco/dracoenc/src/draco/io/ply_property_writer.h b/extern/draco/dracoenc/src/draco/io/ply_property_writer.h deleted file mode 100644 index 4f243b2860f..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_property_writer.h +++ /dev/null @@ -1,94 +0,0 @@ -// 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. -// -#ifndef DRACO_IO_PLY_PROPERTY_WRITER_H_ -#define DRACO_IO_PLY_PROPERTY_WRITER_H_ - -#include <functional> - -#include "draco/io/ply_reader.h" - -namespace draco { - -// Class for writing PlyProperty with a given type, performing data conversion -// if necessary. -template <typename WriteTypeT> -class PlyPropertyWriter { - public: - explicit PlyPropertyWriter(PlyProperty *property) : property_(property) { - // Find the suitable function for converting values. - switch (property->data_type()) { - case DT_UINT8: - convert_value_func_ = [=](WriteTypeT val) { - return this->ConvertValue<uint8_t>(val); - }; - break; - case DT_INT8: - convert_value_func_ = [=](WriteTypeT val) { - return this->ConvertValue<int8_t>(val); - }; - break; - case DT_UINT16: - convert_value_func_ = [=](WriteTypeT val) { - return this->ConvertValue<uint16_t>(val); - }; - break; - case DT_INT16: - convert_value_func_ = [=](WriteTypeT val) { - return this->ConvertValue<int16_t>(val); - }; - break; - case DT_UINT32: - convert_value_func_ = [=](WriteTypeT val) { - return this->ConvertValue<uint32_t>(val); - }; - break; - case DT_INT32: - convert_value_func_ = [=](WriteTypeT val) { - return this->ConvertValue<int32_t>(val); - }; - break; - case DT_FLOAT32: - convert_value_func_ = [=](WriteTypeT val) { - return this->ConvertValue<float>(val); - }; - break; - case DT_FLOAT64: - convert_value_func_ = [=](WriteTypeT val) { - return this->ConvertValue<double>(val); - }; - break; - default: - break; - } - } - - void PushBackValue(WriteTypeT value) const { - return convert_value_func_(value); - } - - private: - template <typename SourceTypeT> - void ConvertValue(WriteTypeT value) const { - const SourceTypeT src_val = static_cast<SourceTypeT>(value); - property_->push_back_value(&src_val); - } - - PlyProperty *property_; - std::function<void(WriteTypeT)> convert_value_func_; -}; - -} // namespace draco - -#endif // DRACO_IO_PLY_PROPERTY_WRITER_H_ diff --git a/extern/draco/dracoenc/src/draco/io/ply_reader.cc b/extern/draco/dracoenc/src/draco/io/ply_reader.cc deleted file mode 100644 index 772c4381176..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_reader.cc +++ /dev/null @@ -1,295 +0,0 @@ -// 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 "draco/io/ply_reader.h" - -#include <array> -#include <regex> - -#include "draco/core/status.h" -#include "draco/io/parser_utils.h" -#include "draco/io/ply_property_writer.h" - -namespace draco { - -PlyProperty::PlyProperty(const std::string &name, DataType data_type, - DataType list_type) - : name_(name), data_type_(data_type), list_data_type_(list_type) { - data_type_num_bytes_ = DataTypeLength(data_type); - list_data_type_num_bytes_ = DataTypeLength(list_type); -} - -PlyElement::PlyElement(const std::string &name, int64_t num_entries) - : name_(name), num_entries_(num_entries) {} - -PlyReader::PlyReader() : format_(kLittleEndian) {} - -Status PlyReader::Read(DecoderBuffer *buffer) { - std::string value; - // The first line needs to by "ply". - if (!parser::ParseString(buffer, &value) || value != "ply") { - return Status(Status::INVALID_PARAMETER, "Not a valid ply file"); - } - parser::SkipLine(buffer); - - // The second line needs to be the format of the ply file. - parser::ParseLine(buffer, &value); - std::string format, version; - const std::vector<std::string> words = SplitWords(value); - if (words.size() >= 3 && words[0] == "format") { - format = words[1]; - version = words[2]; - } else { - return Status(Status::INVALID_PARAMETER, "Missing or wrong format line"); - } - if (version != "1.0") { - return Status(Status::UNSUPPORTED_VERSION, "Unsupported PLY version"); - } - if (format == "binary_big_endian") { - return Status(Status::UNSUPPORTED_VERSION, - "Unsupported format. Currently we support only ascii and" - " binary_little_endian format."); - } - if (format == "ascii") { - format_ = kAscii; - } else { - format_ = kLittleEndian; - } - DRACO_RETURN_IF_ERROR(ParseHeader(buffer)); - if (!ParsePropertiesData(buffer)) { - return Status(Status::INVALID_PARAMETER, "Couldn't parse properties"); - } - return OkStatus(); -} - -Status PlyReader::ParseHeader(DecoderBuffer *buffer) { - while (true) { - DRACO_ASSIGN_OR_RETURN(bool end, ParseEndHeader(buffer)); - if (end) - break; - if (ParseElement(buffer)) - continue; - DRACO_ASSIGN_OR_RETURN(bool property_parsed, ParseProperty(buffer)); - if (property_parsed) - continue; - parser::SkipLine(buffer); - } - return OkStatus(); -} - -StatusOr<bool> PlyReader::ParseEndHeader(DecoderBuffer *buffer) { - parser::SkipWhitespace(buffer); - std::array<char, 10> c; - if (!buffer->Peek(&c)) { - return Status(Status::INVALID_PARAMETER, - "End of file reached before the end_header"); - } - if (std::memcmp(&c[0], "end_header", 10) != 0) - return false; - parser::SkipLine(buffer); - return true; -} - -bool PlyReader::ParseElement(DecoderBuffer *buffer) { - DecoderBuffer line_buffer(*buffer); - std::string line; - parser::ParseLine(&line_buffer, &line); - - std::string element_name; - int64_t count; - const std::vector<std::string> words = SplitWords(line); - if (words.size() >= 3 && words[0] == "element") { - element_name = words[1]; - const std::string count_str = words[2]; - count = strtoll(count_str.c_str(), NULL, 10); - } else { - return false; - } - element_index_[element_name] = static_cast<uint32_t>(elements_.size()); - elements_.emplace_back(PlyElement(element_name, count)); - *buffer = line_buffer; - return true; -} - -StatusOr<bool> PlyReader::ParseProperty(DecoderBuffer *buffer) { - if (elements_.empty()) - return false; // Ignore properties if there is no active element. - DecoderBuffer line_buffer(*buffer); - std::string line; - parser::ParseLine(&line_buffer, &line); - - std::string data_type_str, list_type_str, property_name; - bool property_search = false; - const std::vector<std::string> words = SplitWords(line); - if (words.size() >= 3 && words[0] == "property" && words[1] != "list") { - property_search = true; - data_type_str = words[1]; - property_name = words[2]; - } - - bool property_list_search = false; - if (words.size() >= 5 && words[0] == "property" && words[1] == "list") { - property_list_search = true; - list_type_str = words[2]; - data_type_str = words[3]; - property_name = words[4]; - } - if (!property_search && !property_list_search) { - return false; - } - const DataType data_type = GetDataTypeFromString(data_type_str); - if (data_type == DT_INVALID) { - return Status(Status::INVALID_PARAMETER, "Wrong property data type"); - } - DataType list_type = DT_INVALID; - if (property_list_search) { - list_type = GetDataTypeFromString(list_type_str); - if (list_type == DT_INVALID) { - return Status(Status::INVALID_PARAMETER, "Wrong property list type"); - } - } - elements_.back().AddProperty( - PlyProperty(property_name, data_type, list_type)); - *buffer = line_buffer; - return true; -} - -bool PlyReader::ParsePropertiesData(DecoderBuffer *buffer) { - for (int i = 0; i < static_cast<int>(elements_.size()); ++i) { - if (format_ == kLittleEndian) { - if (!ParseElementData(buffer, i)) { - return false; - } - } else if (format_ == kAscii) { - if (!ParseElementDataAscii(buffer, i)) { - return false; - } - } - } - return true; -} - -bool PlyReader::ParseElementData(DecoderBuffer *buffer, int element_index) { - PlyElement &element = elements_[element_index]; - for (int entry = 0; entry < element.num_entries(); ++entry) { - for (int i = 0; i < element.num_properties(); ++i) { - PlyProperty &prop = element.property(i); - if (prop.is_list()) { - // Parse the number of entries for the list element. - int64_t num_entries = 0; - buffer->Decode(&num_entries, prop.list_data_type_num_bytes()); - // Store offset to the main data entry. - prop.list_data_.push_back(prop.data_.size() / - prop.data_type_num_bytes_); - // Store the number of entries. - prop.list_data_.push_back(num_entries); - // Read and store the actual property data - const int64_t num_bytes_to_read = - prop.data_type_num_bytes() * num_entries; - prop.data_.insert(prop.data_.end(), buffer->data_head(), - buffer->data_head() + num_bytes_to_read); - buffer->Advance(num_bytes_to_read); - } else { - // Non-list property - prop.data_.insert(prop.data_.end(), buffer->data_head(), - buffer->data_head() + prop.data_type_num_bytes()); - buffer->Advance(prop.data_type_num_bytes()); - } - } - } - return true; -} - -bool PlyReader::ParseElementDataAscii(DecoderBuffer *buffer, - int element_index) { - PlyElement &element = elements_[element_index]; - for (int entry = 0; entry < element.num_entries(); ++entry) { - for (int i = 0; i < element.num_properties(); ++i) { - PlyProperty &prop = element.property(i); - PlyPropertyWriter<double> prop_writer(&prop); - int32_t num_entries = 1; - if (prop.is_list()) { - parser::SkipWhitespace(buffer); - // Parse the number of entries for the list element. - if (!parser::ParseSignedInt(buffer, &num_entries)) - return false; - - // Store offset to the main data entry. - prop.list_data_.push_back(prop.data_.size() / - prop.data_type_num_bytes_); - // Store the number of entries. - prop.list_data_.push_back(num_entries); - } - // Read and store the actual property data. - for (int v = 0; v < num_entries; ++v) { - parser::SkipWhitespace(buffer); - if (prop.data_type() == DT_FLOAT32 || prop.data_type() == DT_FLOAT64) { - float val; - if (!parser::ParseFloat(buffer, &val)) - return false; - prop_writer.PushBackValue(val); - } else { - int32_t val; - if (!parser::ParseSignedInt(buffer, &val)) - return false; - prop_writer.PushBackValue(val); - } - } - } - } - return true; -} - -std::vector<std::string> PlyReader::SplitWords(const std::string &line) { - std::vector<std::string> output; - std::string::size_type start = 0; - std::string::size_type end = 0; - - // Check for isspace chars. - while ((end = line.find_first_of(" \t\n\v\f\r", start)) != - std::string::npos) { - const std::string word(line.substr(start, end - start)); - if (!std::all_of(word.begin(), word.end(), isspace)) - output.push_back(word); - start = end + 1; - } - - const std::string last_word(line.substr(start)); - if (!std::all_of(last_word.begin(), last_word.end(), isspace)) - output.push_back(last_word); - return output; -} - -DataType PlyReader::GetDataTypeFromString(const std::string &name) const { - if (name == "char" || name == "int8") - return DT_INT8; - if (name == "uchar" || name == "uint8") - return DT_UINT8; - if (name == "short" || name == "int16") - return DT_INT16; - if (name == "ushort" || name == "uint16") - return DT_UINT16; - if (name == "int" || name == "int32") - return DT_INT32; - if (name == "uint" || name == "uint32") - return DT_UINT32; - if (name == "float" || name == "float32") - return DT_FLOAT32; - if (name == "double" || name == "float64") { - return DT_FLOAT64; - } - return DT_INVALID; -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/ply_reader.h b/extern/draco/dracoenc/src/draco/io/ply_reader.h deleted file mode 100644 index 845ef2326ae..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_reader.h +++ /dev/null @@ -1,152 +0,0 @@ -// 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. -// -// File contains helper classes used for parsing of PLY files. The classes are -// used by the PlyDecoder (ply_decoder.h) to read a point cloud or mesh from a -// source PLY file. -// TODO(ostava): Currently, we support only binary PLYs encoded in the little -// endian format ("format binary_little_endian 1.0"). - -#ifndef DRACO_IO_PLY_READER_H_ -#define DRACO_IO_PLY_READER_H_ - -#include <map> -#include <vector> - -#include "draco/core/decoder_buffer.h" -#include "draco/core/draco_types.h" -#include "draco/core/status.h" -#include "draco/core/status_or.h" - -namespace draco { - -// A single PLY property of a given PLY element. For "vertex" element this can -// contain data such as "x", "y", or "z" coordinate of the vertex, while for -// "face" element this usually contains corner indices. -class PlyProperty { - public: - friend class PlyReader; - - PlyProperty(const std::string &name, DataType data_type, DataType list_type); - void ReserveData(int num_entries) { - data_.reserve(DataTypeLength(data_type_) * num_entries); - } - - int64_t GetListEntryOffset(int entry_id) const { - return list_data_[entry_id * 2]; - } - int64_t GetListEntryNumValues(int entry_id) const { - return list_data_[entry_id * 2 + 1]; - } - const void *GetDataEntryAddress(int entry_id) const { - return data_.data() + entry_id * data_type_num_bytes_; - } - void push_back_value(const void *data) { - data_.insert(data_.end(), static_cast<const uint8_t *>(data), - static_cast<const uint8_t *>(data) + data_type_num_bytes_); - } - - const std::string &name() const { return name_; } - bool is_list() const { return list_data_type_ != DT_INVALID; } - DataType data_type() const { return data_type_; } - int data_type_num_bytes() const { return data_type_num_bytes_; } - DataType list_data_type() const { return list_data_type_; } - int list_data_type_num_bytes() const { return list_data_type_num_bytes_; } - - private: - std::string name_; - std::vector<uint8_t> data_; - // List data contain pairs of <offset, number_of_values> - std::vector<int64_t> list_data_; - DataType data_type_; - int data_type_num_bytes_; - DataType list_data_type_; - int list_data_type_num_bytes_; -}; - -// A single PLY element such as "vertex" or "face". Each element can store -// arbitrary properties such as vertex coordinates or face indices. -class PlyElement { - public: - PlyElement(const std::string &name, int64_t num_entries); - void AddProperty(const PlyProperty &prop) { - property_index_[prop.name()] = static_cast<int>(properties_.size()); - properties_.emplace_back(prop); - if (!properties_.back().is_list()) - properties_.back().ReserveData(static_cast<int>(num_entries_)); - } - - const PlyProperty *GetPropertyByName(const std::string &name) const { - const auto it = property_index_.find(name); - if (it != property_index_.end()) - return &properties_[it->second]; - return nullptr; - } - - int num_properties() const { return static_cast<int>(properties_.size()); } - int num_entries() const { return static_cast<int>(num_entries_); } - const PlyProperty &property(int prop_index) const { - return properties_[prop_index]; - } - PlyProperty &property(int prop_index) { return properties_[prop_index]; } - - private: - std::string name_; - int64_t num_entries_; - std::vector<PlyProperty> properties_; - std::map<std::string, int> property_index_; -}; - -// Class responsible for parsing PLY data. It produces a list of PLY elements -// and their properties that can be used to construct a mesh or a point cloud. -class PlyReader { - public: - PlyReader(); - Status Read(DecoderBuffer *buffer); - - const PlyElement *GetElementByName(const std::string &name) const { - const auto it = element_index_.find(name); - if (it != element_index_.end()) - return &elements_[it->second]; - return nullptr; - } - - int num_elements() const { return static_cast<int>(elements_.size()); } - const PlyElement &element(int element_index) const { - return elements_[element_index]; - } - - private: - enum Format { kLittleEndian = 0, kAscii }; - - Status ParseHeader(DecoderBuffer *buffer); - StatusOr<bool> ParseEndHeader(DecoderBuffer *buffer); - bool ParseElement(DecoderBuffer *buffer); - StatusOr<bool> ParseProperty(DecoderBuffer *buffer); - bool ParsePropertiesData(DecoderBuffer *buffer); - bool ParseElementData(DecoderBuffer *buffer, int element_index); - bool ParseElementDataAscii(DecoderBuffer *buffer, int element_index); - - // Splits |line| by whitespace characters. - std::vector<std::string> SplitWords(const std::string &line); - DataType GetDataTypeFromString(const std::string &name) const; - - std::vector<PlyElement> elements_; - std::map<std::string, int> element_index_; - Format format_; -}; - -} // namespace draco - -#endif // DRACO_IO_PLY_READER_H_ diff --git a/extern/draco/dracoenc/src/draco/io/ply_reader_test.cc b/extern/draco/dracoenc/src/draco/io/ply_reader_test.cc deleted file mode 100644 index 6804dc33de3..00000000000 --- a/extern/draco/dracoenc/src/draco/io/ply_reader_test.cc +++ /dev/null @@ -1,147 +0,0 @@ -// 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 "draco/io/ply_reader.h" - -#include <fstream> - -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/io/ply_property_reader.h" - -namespace draco { - -class PlyReaderTest : public ::testing::Test { - protected: - std::vector<char> ReadPlyFile(const std::string &file_name) const { - const std::string path = GetTestFileFullPath(file_name); - std::ifstream file(path.c_str(), std::ios::binary); - if (!file) - return std::vector<char>(); - auto is_size = file.tellg(); - file.seekg(0, std::ios::end); - is_size = file.tellg() - is_size; - file.seekg(0, std::ios::beg); - std::vector<char> data(is_size); - file.read(&data[0], is_size); - return data; - } -}; - -TEST_F(PlyReaderTest, TestReader) { - const std::string file_name = "test_pos_color.ply"; - const std::vector<char> data = ReadPlyFile(file_name); - DecoderBuffer buf; - buf.Init(data.data(), data.size()); - PlyReader reader; - Status status = reader.Read(&buf); - ASSERT_TRUE(status.ok()) << status; - ASSERT_EQ(reader.num_elements(), 2); - ASSERT_EQ(reader.element(0).num_properties(), 7); - ASSERT_EQ(reader.element(1).num_properties(), 1); - ASSERT_TRUE(reader.element(1).property(0).is_list()); - - ASSERT_TRUE(reader.element(0).GetPropertyByName("red") != nullptr); - const PlyProperty *const prop = reader.element(0).GetPropertyByName("red"); - PlyPropertyReader<uint8_t> reader_uint8(prop); - PlyPropertyReader<uint32_t> reader_uint32(prop); - PlyPropertyReader<float> reader_float(prop); - for (int i = 0; i < reader.element(0).num_entries(); ++i) { - ASSERT_EQ(reader_uint8.ReadValue(i), reader_uint32.ReadValue(i)); - ASSERT_EQ(reader_uint8.ReadValue(i), reader_float.ReadValue(i)); - } -} - -TEST_F(PlyReaderTest, TestReaderAscii) { - const std::string file_name = "test_pos_color.ply"; - const std::vector<char> data = ReadPlyFile(file_name); - DecoderBuffer buf; - buf.Init(data.data(), data.size()); - PlyReader reader; - Status status = reader.Read(&buf); - ASSERT_TRUE(status.ok()) << status; - - const std::string file_name_ascii = "test_pos_color_ascii.ply"; - const std::vector<char> data_ascii = ReadPlyFile(file_name_ascii); - buf.Init(data_ascii.data(), data_ascii.size()); - PlyReader reader_ascii; - status = reader_ascii.Read(&buf); - ASSERT_TRUE(status.ok()) << status; - ASSERT_EQ(reader.num_elements(), reader_ascii.num_elements()); - ASSERT_EQ(reader.element(0).num_properties(), - reader_ascii.element(0).num_properties()); - - ASSERT_TRUE(reader.element(0).GetPropertyByName("x") != nullptr); - const PlyProperty *const prop = reader.element(0).GetPropertyByName("x"); - const PlyProperty *const prop_ascii = - reader_ascii.element(0).GetPropertyByName("x"); - PlyPropertyReader<float> reader_float(prop); - PlyPropertyReader<float> reader_float_ascii(prop_ascii); - for (int i = 0; i < reader.element(0).num_entries(); ++i) { - ASSERT_NEAR(reader_float.ReadValue(i), reader_float_ascii.ReadValue(i), - 1e-4f); - } -} - -TEST_F(PlyReaderTest, TestReaderExtraWhitespace) { - const std::string file_name = "test_extra_whitespace.ply"; - const std::vector<char> data = ReadPlyFile(file_name); - DecoderBuffer buf; - buf.Init(data.data(), data.size()); - PlyReader reader; - Status status = reader.Read(&buf); - ASSERT_TRUE(status.ok()) << status; - - ASSERT_EQ(reader.num_elements(), 2); - ASSERT_EQ(reader.element(0).num_properties(), 7); - ASSERT_EQ(reader.element(1).num_properties(), 1); - ASSERT_TRUE(reader.element(1).property(0).is_list()); - - ASSERT_TRUE(reader.element(0).GetPropertyByName("red") != nullptr); - const PlyProperty *const prop = reader.element(0).GetPropertyByName("red"); - PlyPropertyReader<uint8_t> reader_uint8(prop); - PlyPropertyReader<uint32_t> reader_uint32(prop); - PlyPropertyReader<float> reader_float(prop); - for (int i = 0; i < reader.element(0).num_entries(); ++i) { - ASSERT_EQ(reader_uint8.ReadValue(i), reader_uint32.ReadValue(i)); - ASSERT_EQ(reader_uint8.ReadValue(i), reader_float.ReadValue(i)); - } -} - -TEST_F(PlyReaderTest, TestReaderMoreDataTypes) { - const std::string file_name = "test_more_datatypes.ply"; - const std::vector<char> data = ReadPlyFile(file_name); - DecoderBuffer buf; - buf.Init(data.data(), data.size()); - PlyReader reader; - Status status = reader.Read(&buf); - ASSERT_TRUE(status.ok()) << status; - - ASSERT_EQ(reader.num_elements(), 2); - ASSERT_EQ(reader.element(0).num_properties(), 7); - ASSERT_EQ(reader.element(1).num_properties(), 1); - ASSERT_TRUE(reader.element(1).property(0).is_list()); - - ASSERT_TRUE(reader.element(0).GetPropertyByName("red") != nullptr); - const PlyProperty *const prop = reader.element(0).GetPropertyByName("red"); - PlyPropertyReader<uint8_t> reader_uint8(prop); - PlyPropertyReader<uint32_t> reader_uint32(prop); - PlyPropertyReader<float> reader_float(prop); - for (int i = 0; i < reader.element(0).num_entries(); ++i) { - ASSERT_EQ(reader_uint8.ReadValue(i), reader_uint32.ReadValue(i)); - ASSERT_EQ(reader_uint8.ReadValue(i), reader_float.ReadValue(i)); - } -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/point_cloud_io.cc b/extern/draco/dracoenc/src/draco/io/point_cloud_io.cc deleted file mode 100644 index e91142eaaea..00000000000 --- a/extern/draco/dracoenc/src/draco/io/point_cloud_io.cc +++ /dev/null @@ -1,58 +0,0 @@ -// 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 "draco/io/point_cloud_io.h" - -#include <fstream> - -#include "draco/io/obj_decoder.h" -#include "draco/io/parser_utils.h" -#include "draco/io/ply_decoder.h" - -namespace draco { - -StatusOr<std::unique_ptr<PointCloud>> ReadPointCloudFromFile( - const std::string &file_name) { - std::unique_ptr<PointCloud> pc(new PointCloud()); - // Analyze file extension. - const std::string extension = parser::ToLower( - file_name.size() >= 4 ? file_name.substr(file_name.size() - 4) - : file_name); - if (extension == ".obj") { - // Wavefront OBJ file format. - ObjDecoder obj_decoder; - const Status obj_status = obj_decoder.DecodeFromFile(file_name, pc.get()); - if (!obj_status.ok()) - return obj_status; - return std::move(pc); - } - if (extension == ".ply") { - // Wavefront PLY file format. - PlyDecoder ply_decoder; - DRACO_RETURN_IF_ERROR(ply_decoder.DecodeFromFile(file_name, pc.get())); - return std::move(pc); - } - - // Otherwise not an obj file. Assume the file was encoded with one of the - // draco encoding methods. - std::ifstream is(file_name.c_str(), std::ios::binary); - if (!is) - return Status(Status::DRACO_ERROR, "Invalid input stream."); - if (!ReadPointCloudFromStream(&pc, is).good()) - return Status(Status::DRACO_ERROR, - "Unknown error."); // Error reading the stream. - return std::move(pc); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/io/point_cloud_io.h b/extern/draco/dracoenc/src/draco/io/point_cloud_io.h deleted file mode 100644 index 4e1eb359644..00000000000 --- a/extern/draco/dracoenc/src/draco/io/point_cloud_io.h +++ /dev/null @@ -1,89 +0,0 @@ -// 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. -// -#ifndef DRACO_IO_POINT_CLOUD_IO_H_ -#define DRACO_IO_POINT_CLOUD_IO_H_ - -#include "draco/compression/config/compression_shared.h" -#include "draco/compression/decode.h" -#include "draco/compression/expert_encode.h" - -namespace draco { - -template <typename OutStreamT> -OutStreamT WritePointCloudIntoStream(const PointCloud *pc, OutStreamT &&os, - PointCloudEncodingMethod method, - const EncoderOptions &options) { - EncoderBuffer buffer; - EncoderOptions local_options = options; - ExpertEncoder encoder(*pc); - encoder.Reset(local_options); - encoder.SetEncodingMethod(method); - if (!encoder.EncodeToBuffer(&buffer).ok()) { - os.setstate(std::ios_base::badbit); - return os; - } - - os.write(static_cast<const char *>(buffer.data()), buffer.size()); - - return os; -} - -template <typename OutStreamT> -OutStreamT WritePointCloudIntoStream(const PointCloud *pc, OutStreamT &&os, - PointCloudEncodingMethod method) { - const EncoderOptions options = EncoderOptions::CreateDefaultOptions(); - return WritePointCloudIntoStream(pc, os, method, options); -} - -template <typename OutStreamT> -OutStreamT &WritePointCloudIntoStream(const PointCloud *pc, OutStreamT &&os) { - return WritePointCloudIntoStream(pc, os, POINT_CLOUD_SEQUENTIAL_ENCODING); -} - -template <typename InStreamT> -InStreamT &ReadPointCloudFromStream(std::unique_ptr<PointCloud> *point_cloud, - InStreamT &&is) { - // Determine size of stream and write into a vector - const auto start_pos = is.tellg(); - is.seekg(0, std::ios::end); - const std::streampos is_size = is.tellg() - start_pos; - is.seekg(start_pos); - std::vector<char> data(is_size); - is.read(&data[0], is_size); - - // Create a point cloud from that data. - DecoderBuffer buffer; - buffer.Init(&data[0], data.size()); - Decoder decoder; - auto statusor = decoder.DecodePointCloudFromBuffer(&buffer); - *point_cloud = std::move(statusor).value(); - if (!statusor.ok() || *point_cloud == nullptr) { - is.setstate(std::ios_base::badbit); - } - - return is; -} - -// Reads a point cloud from a file. The function automatically chooses the -// correct decoder based on the extension of the files. Currently, .obj and .ply -// files are supported. Other file extensions are processed by the default -// draco::PointCloudDecoder. -// Returns nullptr with an error status if the decoding failed. -StatusOr<std::unique_ptr<PointCloud>> ReadPointCloudFromFile( - const std::string &file_name); - -} // namespace draco - -#endif // DRACO_IO_POINT_CLOUD_IO_H_ diff --git a/extern/draco/dracoenc/src/draco/io/point_cloud_io_test.cc b/extern/draco/dracoenc/src/draco/io/point_cloud_io_test.cc deleted file mode 100644 index 73674d06f55..00000000000 --- a/extern/draco/dracoenc/src/draco/io/point_cloud_io_test.cc +++ /dev/null @@ -1,115 +0,0 @@ -// 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 "draco/io/point_cloud_io.h" - -#include <sstream> - -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/io/obj_decoder.h" - -namespace draco { - -class IoPointCloudIoTest : public ::testing::Test { - protected: - void test_compression_method(PointCloudEncodingMethod method, - int expected_num_attributes, - const std::string &file_name) { - const std::unique_ptr<PointCloud> encoded_pc = - ReadPointCloudFromTestFile(file_name); - ASSERT_NE(encoded_pc, nullptr) << "Failed to load test model " << file_name; - ASSERT_GE(encoded_pc->num_attributes(), expected_num_attributes) - << "Failed to load test model: " << file_name - << " wrong number of attributes" << std::endl; - - // Set quantization. - EncoderOptions options = EncoderOptions::CreateDefaultOptions(); - for (int i = 0; i <= GeometryAttribute::NAMED_ATTRIBUTES_COUNT; i++) { - options.SetAttributeInt(GeometryAttribute::Type(i), "quantization_bits", - 14); - } - - std::stringstream ss; - WritePointCloudIntoStream(encoded_pc.get(), ss, method, options); - ASSERT_TRUE(ss.good()); - - std::unique_ptr<PointCloud> decoded_pc; - ReadPointCloudFromStream(&decoded_pc, ss); - ASSERT_TRUE(ss.good()); - - for (int i = 0; i <= GeometryAttribute::NAMED_ATTRIBUTES_COUNT; i++) { - ASSERT_EQ(encoded_pc->NumNamedAttributes(GeometryAttribute::Type(i)), - decoded_pc->NumNamedAttributes(GeometryAttribute::Type(i))); - } - - ASSERT_EQ(encoded_pc->num_points(), decoded_pc->num_points()); - } -}; - -TEST_F(IoPointCloudIoTest, EncodeSequentialPointCloudTestNmObj) { - test_compression_method(POINT_CLOUD_SEQUENTIAL_ENCODING, 2, "test_nm.obj"); -} -TEST_F(IoPointCloudIoTest, EncodeSequentialPointCloudTestPosObj) { - test_compression_method(POINT_CLOUD_SEQUENTIAL_ENCODING, 1, - "point_cloud_test_pos.obj"); -} -TEST_F(IoPointCloudIoTest, EncodeSequentialPointCloudTestPosPly) { - test_compression_method(POINT_CLOUD_SEQUENTIAL_ENCODING, 1, - "point_cloud_test_pos.ply"); -} -TEST_F(IoPointCloudIoTest, EncodeSequentialPointCloudTestPosNormObj) { - test_compression_method(POINT_CLOUD_SEQUENTIAL_ENCODING, 2, - "point_cloud_test_pos_norm.obj"); -} -TEST_F(IoPointCloudIoTest, EncodeSequentialPointCloudTestPosNormPly) { - test_compression_method(POINT_CLOUD_SEQUENTIAL_ENCODING, 2, - "point_cloud_test_pos_norm.ply"); -} - -TEST_F(IoPointCloudIoTest, EncodeKdTreePointCloudTestPosObj) { - test_compression_method(POINT_CLOUD_KD_TREE_ENCODING, 1, - "point_cloud_test_pos.obj"); -} -TEST_F(IoPointCloudIoTest, EncodeKdTreePointCloudTestPosPly) { - test_compression_method(POINT_CLOUD_KD_TREE_ENCODING, 1, - "point_cloud_test_pos.ply"); -} - -TEST_F(IoPointCloudIoTest, ObjFileInput) { - // Tests whether loading obj point clouds from files works as expected. - const std::unique_ptr<PointCloud> pc = - ReadPointCloudFromTestFile("test_nm.obj"); - ASSERT_NE(pc, nullptr) << "Failed to load the obj point cloud."; - EXPECT_EQ(pc->num_points(), 97) << "Obj point cloud not loaded properly."; -} - -// Test if we handle wrong input for all file extensions. -TEST_F(IoPointCloudIoTest, WrongFileObj) { - const std::unique_ptr<PointCloud> pc = - ReadPointCloudFromTestFile("wrong_file_name.obj"); - ASSERT_EQ(pc, nullptr); -} -TEST_F(IoPointCloudIoTest, WrongFilePly) { - const std::unique_ptr<PointCloud> pc = - ReadPointCloudFromTestFile("wrong_file_name.ply"); - ASSERT_EQ(pc, nullptr); -} -TEST_F(IoPointCloudIoTest, WrongFile) { - const std::unique_ptr<PointCloud> pc = - ReadPointCloudFromTestFile("wrong_file_name"); - ASSERT_EQ(pc, nullptr); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent_test.cc b/extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent_test.cc deleted file mode 100644 index ff633bc73d1..00000000000 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_are_equivalent_test.cc +++ /dev/null @@ -1,99 +0,0 @@ -// 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 "draco/mesh/mesh_are_equivalent.h" - -#include <sstream> - -#include "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" -#include "draco/io/mesh_io.h" -#include "draco/io/obj_decoder.h" -#include "draco/mesh/mesh.h" - -namespace draco { - -class MeshAreEquivalentTest : public ::testing::Test {}; - -TEST_F(MeshAreEquivalentTest, TestOnIndenticalMesh) { - const std::string file_name = "test_nm.obj"; - const std::unique_ptr<Mesh> mesh(ReadMeshFromTestFile(file_name)); - ASSERT_NE(mesh, nullptr) << "Failed to load test model." << file_name; - MeshAreEquivalent equiv; - ASSERT_TRUE(equiv(*mesh, *mesh)); -} - -TEST_F(MeshAreEquivalentTest, TestPermutedOneFace) { - const std::string file_name_0 = "one_face_123.obj"; - const std::string file_name_1 = "one_face_312.obj"; - const std::string file_name_2 = "one_face_321.obj"; - const std::unique_ptr<Mesh> mesh_0(ReadMeshFromTestFile(file_name_0)); - const std::unique_ptr<Mesh> mesh_1(ReadMeshFromTestFile(file_name_1)); - const std::unique_ptr<Mesh> mesh_2(ReadMeshFromTestFile(file_name_2)); - ASSERT_NE(mesh_0, nullptr) << "Failed to load test model." << file_name_0; - ASSERT_NE(mesh_1, nullptr) << "Failed to load test model." << file_name_1; - ASSERT_NE(mesh_2, nullptr) << "Failed to load test model." << file_name_2; - MeshAreEquivalent equiv; - ASSERT_TRUE(equiv(*mesh_0, *mesh_0)); - ASSERT_TRUE(equiv(*mesh_0, *mesh_1)); // Face rotated. - ASSERT_FALSE(equiv(*mesh_0, *mesh_2)); // Face inverted. -} - -TEST_F(MeshAreEquivalentTest, TestPermutedTwoFaces) { - const std::string file_name_0 = "two_faces_123.obj"; - const std::string file_name_1 = "two_faces_312.obj"; - const std::unique_ptr<Mesh> mesh_0(ReadMeshFromTestFile(file_name_0)); - const std::unique_ptr<Mesh> mesh_1(ReadMeshFromTestFile(file_name_1)); - ASSERT_NE(mesh_0, nullptr) << "Failed to load test model." << file_name_0; - ASSERT_NE(mesh_1, nullptr) << "Failed to load test model." << file_name_1; - MeshAreEquivalent equiv; - ASSERT_TRUE(equiv(*mesh_0, *mesh_0)); - ASSERT_TRUE(equiv(*mesh_1, *mesh_1)); - ASSERT_TRUE(equiv(*mesh_0, *mesh_1)); -} - -// -TEST_F(MeshAreEquivalentTest, TestPermutedThreeFaces) { - const std::string file_name_0 = "three_faces_123.obj"; - const std::string file_name_1 = "three_faces_312.obj"; - const std::unique_ptr<Mesh> mesh_0(ReadMeshFromTestFile(file_name_0)); - const std::unique_ptr<Mesh> mesh_1(ReadMeshFromTestFile(file_name_1)); - ASSERT_NE(mesh_0, nullptr) << "Failed to load test model." << file_name_0; - ASSERT_NE(mesh_1, nullptr) << "Failed to load test model." << file_name_1; - MeshAreEquivalent equiv; - ASSERT_TRUE(equiv(*mesh_0, *mesh_0)); - ASSERT_TRUE(equiv(*mesh_1, *mesh_1)); - ASSERT_TRUE(equiv(*mesh_0, *mesh_1)); -} - -// This test checks that the edgebreaker algorithm does not change the mesh up -// to the order of faces and vertices. -TEST_F(MeshAreEquivalentTest, TestOnBigMesh) { - const std::string file_name = "test_nm.obj"; - const std::unique_ptr<Mesh> mesh0(ReadMeshFromTestFile(file_name)); - ASSERT_NE(mesh0, nullptr) << "Failed to load test model." << file_name; - - std::unique_ptr<Mesh> mesh1; - std::stringstream ss; - WriteMeshIntoStream(mesh0.get(), ss, MESH_EDGEBREAKER_ENCODING); - ReadMeshFromStream(&mesh1, ss); - ASSERT_TRUE(ss.good()) << "Mesh IO failed."; - - MeshAreEquivalent equiv; - ASSERT_TRUE(equiv(*mesh0, *mesh0)); - ASSERT_TRUE(equiv(*mesh1, *mesh1)); - ASSERT_TRUE(equiv(*mesh0, *mesh1)); -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/mesh/mesh_cleanup_test.cc b/extern/draco/dracoenc/src/draco/mesh/mesh_cleanup_test.cc deleted file mode 100644 index 1051d193d87..00000000000 --- a/extern/draco/dracoenc/src/draco/mesh/mesh_cleanup_test.cc +++ /dev/null @@ -1,131 +0,0 @@ -// 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 "draco/mesh/mesh_cleanup.h" - -#include "draco/core/draco_test_base.h" -#include "draco/core/vector_d.h" -#include "draco/mesh/triangle_soup_mesh_builder.h" - -namespace draco { - -class MeshCleanupTest : public ::testing::Test {}; - -TEST_F(MeshCleanupTest, TestDegneratedFaces) { - // This test verifies that the mesh cleanup tools removes degenerated faces. - TriangleSoupMeshBuilder mb; - mb.Start(2); - const int pos_att_id = - mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - // clang-format off - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(0), - Vector3f(0.f, 0.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(0.f, 1.f, 0.f).data()); - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(1), - Vector3f(0.f, 1.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data()); - // clang-format on - - std::unique_ptr<Mesh> mesh = mb.Finalize(); - ASSERT_NE(mesh, nullptr) << "Failed to build the test mesh."; - ASSERT_EQ(mesh->num_faces(), 2) << "Wrong number of faces in the input mesh."; - MeshCleanupOptions cleanup_options; - MeshCleanup cleanup; - ASSERT_TRUE(cleanup(mesh.get(), cleanup_options)) - << "Failed to cleanup the mesh."; - ASSERT_EQ(mesh->num_faces(), 1) << "Failed to remove degenerated faces."; -} - -TEST_F(MeshCleanupTest, TestDegneratedFacesAndIsolatedVertices) { - // This test verifies that the mesh cleanup tools removes degenerated faces - // and isolated vertices. - TriangleSoupMeshBuilder mb; - mb.Start(2); - const int pos_att_id = - mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - // clang-format off - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(0), - Vector3f(0.f, 0.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(0.f, 1.f, 0.f).data()); - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(1), - Vector3f(10.f, 1.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(10.f, 1.f, 0.f).data()); - // clang-format on - - std::unique_ptr<Mesh> mesh = mb.Finalize(); - ASSERT_NE(mesh, nullptr) << "Failed to build the test mesh."; - ASSERT_EQ(mesh->num_faces(), 2) << "Wrong number of faces in the input mesh."; - ASSERT_EQ(mesh->num_points(), 4) - << "Wrong number of point ids in the input mesh."; - const MeshCleanupOptions cleanup_options; - MeshCleanup cleanup; - ASSERT_TRUE(cleanup(mesh.get(), cleanup_options)) - << "Failed to cleanup the mesh."; - ASSERT_EQ(mesh->num_faces(), 1) << "Failed to remove degenerated faces."; - ASSERT_EQ(mesh->num_points(), 3) - << "Failed to remove isolated attribute indices."; -} - -TEST_F(MeshCleanupTest, TestAttributes) { - TriangleSoupMeshBuilder mb; - mb.Start(2); - const int pos_att_id = - mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - const int generic_att_id = - mb.AddAttribute(GeometryAttribute::GENERIC, 2, DT_FLOAT32); - // clang-format off - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(0), - Vector3f(0.f, 0.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(0.f, 1.f, 0.f).data()); - mb.SetAttributeValuesForFace(generic_att_id, FaceIndex(0), - Vector2f(0.f, 0.f).data(), - Vector2f(0.f, 0.f).data(), - Vector2f(0.f, 0.f).data()); - - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(1), - Vector3f(10.f, 1.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(10.f, 1.f, 0.f).data()); - mb.SetAttributeValuesForFace(generic_att_id, FaceIndex(1), - Vector2f(1.f, 0.f).data(), - Vector2f(1.f, 0.f).data(), - Vector2f(1.f, 0.f).data()); - // clang-format on - - std::unique_ptr<Mesh> mesh = mb.Finalize(); - ASSERT_NE(mesh, nullptr) << "Failed to build the test mesh."; - ASSERT_EQ(mesh->num_faces(), 2) << "Wrong number of faces in the input mesh."; - ASSERT_EQ(mesh->num_points(), 5) - << "Wrong number of point ids in the input mesh."; - ASSERT_EQ(mesh->attribute(1)->size(), 2u) - << "Wrong number of generic attribute entries."; - const MeshCleanupOptions cleanup_options; - MeshCleanup cleanup; - ASSERT_TRUE(cleanup(mesh.get(), cleanup_options)) - << "Failed to cleanup the mesh."; - ASSERT_EQ(mesh->num_faces(), 1) << "Failed to remove degenerated faces."; - ASSERT_EQ(mesh->num_points(), 3) - << "Failed to remove isolated attribute indices."; - ASSERT_EQ(mesh->attribute(0)->size(), 3u) - << "Wrong number of unique positions after cleanup."; - ASSERT_EQ(mesh->attribute(1)->size(), 1u) - << "Wrong number of generic attribute entries after cleanup."; -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder_test.cc b/extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder_test.cc deleted file mode 100644 index 171f8fe24a1..00000000000 --- a/extern/draco/dracoenc/src/draco/mesh/triangle_soup_mesh_builder_test.cc +++ /dev/null @@ -1,197 +0,0 @@ -// 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 "draco/mesh/triangle_soup_mesh_builder.h" - -#include "draco/core/draco_test_base.h" -#include "draco/core/vector_d.h" - -namespace draco { - -class TriangleSoupMeshBuilderTest : public ::testing::Test {}; - -TEST_F(TriangleSoupMeshBuilderTest, CubeTest) { - // This tests, verifies that the mesh builder constructs a valid cube out - // of the provided triangle soup data. - TriangleSoupMeshBuilder mb; - mb.Start(12); - const int pos_att_id = - mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - // clang-format off - // Front face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(0), - Vector3f(0.f, 0.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(0.f, 1.f, 0.f).data()); - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(1), - Vector3f(0.f, 1.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(1.f, 1.f, 0.f).data()); - - // Back face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(2), - Vector3f(0.f, 1.f, 1.f).data(), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(0.f, 0.f, 1.f).data()); - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(3), - Vector3f(1.f, 1.f, 1.f).data(), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(0.f, 1.f, 1.f).data()); - - // Top face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(4), - Vector3f(0.f, 1.f, 0.f).data(), - Vector3f(1.f, 1.f, 0.f).data(), - Vector3f(0.f, 1.f, 1.f).data()); - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(5), - Vector3f(0.f, 1.f, 1.f).data(), - Vector3f(1.f, 1.f, 0.f).data(), - Vector3f(1.f, 1.f, 1.f).data()); - - // Bottom face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(6), - Vector3f(0.f, 0.f, 1.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(0.f, 0.f, 0.f).data()); - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(7), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(0.f, 0.f, 1.f).data()); - - // Right face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(8), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(1.f, 1.f, 0.f).data()); - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(9), - Vector3f(1.f, 1.f, 0.f).data(), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(1.f, 1.f, 1.f).data()); - - // Left face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(10), - Vector3f(0.f, 1.f, 0.f).data(), - Vector3f(0.f, 0.f, 1.f).data(), - Vector3f(0.f, 0.f, 0.f).data()); - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(11), - Vector3f(0.f, 1.f, 1.f).data(), - Vector3f(0.f, 0.f, 1.f).data(), - Vector3f(0.f, 1.f, 0.f).data()); - // clang-format on - - std::unique_ptr<Mesh> mesh = mb.Finalize(); - ASSERT_NE(mesh, nullptr) << "Failed to build the cube mesh."; - EXPECT_EQ(mesh->num_points(), 8) << "Unexpected number of vertices."; - EXPECT_EQ(mesh->num_faces(), 12) << "Unexpected number of faces."; -} - -TEST_F(TriangleSoupMeshBuilderTest, TestPerFaceAttribs) { - // This tests, verifies that the mesh builder constructs a valid cube with - // per face Boolean attributes. - TriangleSoupMeshBuilder mb; - mb.Start(12); - const int pos_att_id = - mb.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - const int gen_att_id = - mb.AddAttribute(GeometryAttribute::GENERIC, 1, DT_BOOL); - uint8_t bool_true = 1; - uint8_t bool_false = 0; - // clang-format off - // Front face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(0), - Vector3f(0.f, 0.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(0.f, 1.f, 0.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(0), &bool_false); - - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(1), - Vector3f(0.f, 1.f, 0.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(1.f, 1.f, 0.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(1), &bool_true); - - // Back face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(2), - Vector3f(0.f, 1.f, 1.f).data(), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(0.f, 0.f, 1.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(2), &bool_true); - - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(3), - Vector3f(1.f, 1.f, 1.f).data(), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(0.f, 1.f, 1.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(3), &bool_true); - - // Top face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(4), - Vector3f(0.f, 1.f, 0.f).data(), - Vector3f(1.f, 1.f, 0.f).data(), - Vector3f(0.f, 1.f, 1.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(4), &bool_false);; - - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(5), - Vector3f(0.f, 1.f, 1.f).data(), - Vector3f(1.f, 1.f, 0.f).data(), - Vector3f(1.f, 1.f, 1.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(5), &bool_false); - - // Bottom face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(6), - Vector3f(0.f, 0.f, 1.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(0.f, 0.f, 0.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(6), &bool_true); - - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(7), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(0.f, 0.f, 1.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(7), &bool_true); - - // Right face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(8), - Vector3f(1.f, 0.f, 0.f).data(), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(1.f, 1.f, 0.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(8), &bool_false); - - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(9), - Vector3f(1.f, 1.f, 0.f).data(), - Vector3f(1.f, 0.f, 1.f).data(), - Vector3f(1.f, 1.f, 1.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(9), &bool_true); - - // Left face. - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(10), - Vector3f(0.f, 1.f, 0.f).data(), - Vector3f(0.f, 0.f, 1.f).data(), - Vector3f(0.f, 0.f, 0.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(10), &bool_true); - - mb.SetAttributeValuesForFace(pos_att_id, FaceIndex(11), - Vector3f(0.f, 1.f, 1.f).data(), - Vector3f(0.f, 0.f, 1.f).data(), - Vector3f(0.f, 1.f, 0.f).data()); - mb.SetPerFaceAttributeValueForFace(gen_att_id, FaceIndex(11), &bool_false); - // clang-format on - - std::unique_ptr<Mesh> mesh = mb.Finalize(); - ASSERT_NE(mesh, nullptr) << "Failed to build the cube mesh."; - EXPECT_EQ(mesh->num_faces(), 12) << "Unexpected number of faces."; - EXPECT_EQ(mesh->GetAttributeElementType(gen_att_id), MESH_FACE_ATTRIBUTE) - << "Unexpected attribute element type."; -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/metadata/metadata_encoder_test.cc b/extern/draco/dracoenc/src/draco/metadata/metadata_encoder_test.cc deleted file mode 100644 index d8f7f2f6649..00000000000 --- a/extern/draco/dracoenc/src/draco/metadata/metadata_encoder_test.cc +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2017 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 "draco/metadata/metadata_encoder.h" -#include "draco/core/decoder_buffer.h" -#include "draco/core/draco_test_base.h" -#include "draco/core/encoder_buffer.h" -#include "draco/metadata/metadata.h" -#include "draco/metadata/metadata_decoder.h" - -namespace { - -class MetadataEncoderTest : public ::testing::Test { - protected: - MetadataEncoderTest() {} - - void TestEncodingMetadata() { - ASSERT_TRUE(encoder.EncodeMetadata(&encoder_buffer, &metadata)); - - draco::Metadata decoded_metadata; - decoder_buffer.Init(encoder_buffer.data(), encoder_buffer.size()); - ASSERT_TRUE(decoder.DecodeMetadata(&decoder_buffer, &decoded_metadata)); - CheckMetadatasAreEqual(metadata, decoded_metadata); - } - - void TestEncodingGeometryMetadata() { - ASSERT_TRUE( - encoder.EncodeGeometryMetadata(&encoder_buffer, &geometry_metadata)); - - draco::GeometryMetadata decoded_metadata; - decoder_buffer.Init(encoder_buffer.data(), encoder_buffer.size()); - ASSERT_TRUE( - decoder.DecodeGeometryMetadata(&decoder_buffer, &decoded_metadata)); - CheckGeometryMetadatasAreEqual(geometry_metadata, decoded_metadata); - } - - void CheckBlobOfDataAreEqual(const std::vector<uint8_t> &data0, - const std::vector<uint8_t> &data1) { - ASSERT_EQ(data0.size(), data1.size()); - for (int i = 0; i < data0.size(); ++i) - ASSERT_EQ(data0[i], data1[i]); - } - - void CheckGeometryMetadatasAreEqual( - const draco::GeometryMetadata &metadata0, - const draco::GeometryMetadata &metadata1) { - ASSERT_EQ(metadata0.attribute_metadatas().size(), - metadata1.attribute_metadatas().size()); - const std::vector<std::unique_ptr<draco::AttributeMetadata>> - &att_metadatas0 = metadata0.attribute_metadatas(); - const std::vector<std::unique_ptr<draco::AttributeMetadata>> - &att_metadatas1 = metadata1.attribute_metadatas(); - // Compare each attribute metadata. - for (int i = 0; i < metadata0.attribute_metadatas().size(); ++i) { - CheckMetadatasAreEqual( - static_cast<const draco::Metadata &>(*att_metadatas0[i]), - static_cast<const draco::Metadata &>(*att_metadatas1[i])); - } - // Compare entries and sub metadata. - CheckMetadatasAreEqual(static_cast<const draco::Metadata &>(metadata0), - static_cast<const draco::Metadata &>(metadata1)); - } - - void CheckMetadatasAreEqual(const draco::Metadata &metadata0, - const draco::Metadata &metadata1) { - ASSERT_EQ(metadata0.num_entries(), metadata1.num_entries()); - const std::map<std::string, draco::EntryValue> &entries0 = - metadata0.entries(); - const std::map<std::string, draco::EntryValue> &entries1 = - metadata1.entries(); - for (const auto &entry : entries0) { - const std::string &entry_name = entry.first; - const std::vector<uint8_t> &data0 = entry.second.data(); - const auto entry1_ptr = entries1.find(entry_name); - ASSERT_NE(entry1_ptr, entries1.end()); - const std::vector<uint8_t> &data1 = entry1_ptr->second.data(); - CheckBlobOfDataAreEqual(data0, data1); - } - // Check nested metadata. - ASSERT_EQ(metadata0.sub_metadatas().size(), - metadata1.sub_metadatas().size()); - const std::map<std::string, std::unique_ptr<draco::Metadata>> - &sub_metadatas0 = metadata0.sub_metadatas(); - // Encode each sub-metadata - for (auto &&sub_metadata_entry0 : sub_metadatas0) { - const auto sub_metadata_ptr1 = - metadata1.GetSubMetadata(sub_metadata_entry0.first); - ASSERT_NE(sub_metadata_ptr1, nullptr); - CheckMetadatasAreEqual(*sub_metadata_entry0.second, *sub_metadata_ptr1); - } - } - - draco::MetadataEncoder encoder; - draco::MetadataDecoder decoder; - draco::EncoderBuffer encoder_buffer; - draco::DecoderBuffer decoder_buffer; - draco::Metadata metadata; - draco::GeometryMetadata geometry_metadata; -}; - -TEST_F(MetadataEncoderTest, TestSingleEntry) { - metadata.AddEntryInt("int", 100); - ASSERT_EQ(metadata.num_entries(), 1); - - TestEncodingMetadata(); -} - -TEST_F(MetadataEncoderTest, TestMultipleEntries) { - metadata.AddEntryInt("int", 100); - metadata.AddEntryDouble("double", 1.234); - const std::string entry_value = "test string entry"; - metadata.AddEntryString("string", entry_value); - ASSERT_EQ(metadata.num_entries(), 3); - - TestEncodingMetadata(); -} - -TEST_F(MetadataEncoderTest, TestEncodingArrayEntries) { - std::vector<int32_t> int_array({1, 2, 3}); - metadata.AddEntryIntArray("int_array", int_array); - std::vector<double> double_array({0.1, 0.2, 0.3}); - metadata.AddEntryDoubleArray("double_array", double_array); - ASSERT_EQ(metadata.num_entries(), 2); - - TestEncodingMetadata(); -} - -TEST_F(MetadataEncoderTest, TestEncodingBinaryEntry) { - const std::vector<uint8_t> binarydata({0x1, 0x2, 0x3, 0x4}); - metadata.AddEntryBinary("binary_data", binarydata); - - TestEncodingMetadata(); -} - -TEST_F(MetadataEncoderTest, TestEncodingNestedMetadata) { - metadata.AddEntryDouble("double", 1.234); - std::unique_ptr<draco::Metadata> sub_metadata = - std::unique_ptr<draco::Metadata>(new draco::Metadata()); - sub_metadata->AddEntryInt("int", 100); - metadata.AddSubMetadata("sub0", std::move(sub_metadata)); - - TestEncodingMetadata(); -} - -TEST_F(MetadataEncoderTest, TestEncodingGeometryMetadata) { - std::unique_ptr<draco::AttributeMetadata> att_metadata = - std::unique_ptr<draco::AttributeMetadata>(new draco::AttributeMetadata); - att_metadata->AddEntryInt("int", 100); - att_metadata->AddEntryString("name", "pos"); - ASSERT_TRUE(geometry_metadata.AddAttributeMetadata(std::move(att_metadata))); - - TestEncodingGeometryMetadata(); -} -} // namespace diff --git a/extern/draco/dracoenc/src/draco/metadata/metadata_test.cc b/extern/draco/dracoenc/src/draco/metadata/metadata_test.cc deleted file mode 100644 index ba6a764446c..00000000000 --- a/extern/draco/dracoenc/src/draco/metadata/metadata_test.cc +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2017 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 <memory> -#include <string> - -#include "draco/core/draco_test_base.h" -#include "draco/metadata/geometry_metadata.h" -#include "draco/metadata/metadata.h" - -namespace { - -class MetadataTest : public ::testing::Test { - protected: - MetadataTest() {} - - draco::Metadata metadata; - draco::GeometryMetadata geometry_metadata; -}; - -TEST_F(MetadataTest, TestRemoveEntry) { - metadata.AddEntryInt("int", 100); - metadata.RemoveEntry("int"); - int32_t int_value = 0; - ASSERT_FALSE(metadata.GetEntryInt("int", &int_value)); -} - -TEST_F(MetadataTest, TestSingleEntry) { - metadata.AddEntryInt("int", 100); - int32_t int_value = 0; - ASSERT_TRUE(metadata.GetEntryInt("int", &int_value)); - ASSERT_EQ(int_value, 100); - - metadata.AddEntryDouble("double", 1.234); - double double_value = 0.0; - ASSERT_TRUE(metadata.GetEntryDouble("double", &double_value)); - ASSERT_EQ(double_value, 1.234); -} - -TEST_F(MetadataTest, TestWriteOverEntry) { - metadata.AddEntryInt("int", 100); - metadata.AddEntryInt("int", 200); - int32_t int_value = 0; - ASSERT_TRUE(metadata.GetEntryInt("int", &int_value)); - ASSERT_EQ(int_value, 200); -} - -TEST_F(MetadataTest, TestArrayEntry) { - std::vector<int32_t> int_array({1, 2, 3}); - metadata.AddEntryIntArray("int_array", int_array); - std::vector<int32_t> return_int_array; - ASSERT_TRUE(metadata.GetEntryIntArray("int_array", &return_int_array)); - ASSERT_EQ(return_int_array.size(), 3); - ASSERT_EQ(return_int_array[0], 1); - ASSERT_EQ(return_int_array[1], 2); - ASSERT_EQ(return_int_array[2], 3); - - std::vector<double> double_array({0.1, 0.2, 0.3}); - metadata.AddEntryDoubleArray("double_array", double_array); - std::vector<double> return_double_array; - ASSERT_TRUE( - metadata.GetEntryDoubleArray("double_array", &return_double_array)); - ASSERT_EQ(return_double_array.size(), 3); - ASSERT_EQ(return_double_array[0], 0.1); - ASSERT_EQ(return_double_array[1], 0.2); - ASSERT_EQ(return_double_array[2], 0.3); -} - -TEST_F(MetadataTest, TestStringEntry) { - const std::string entry_value = "test string entry"; - metadata.AddEntryString("string", entry_value); - std::string return_value; - ASSERT_TRUE(metadata.GetEntryString("string", &return_value)); - ASSERT_EQ(entry_value.size(), return_value.size()); - ASSERT_EQ(entry_value, return_value); -} - -TEST_F(MetadataTest, TestBinaryEntry) { - const std::vector<uint8_t> binarydata({0x1, 0x2, 0x3, 0x4}); - metadata.AddEntryBinary("binary_data", binarydata); - std::vector<uint8_t> return_binarydata; - ASSERT_TRUE(metadata.GetEntryBinary("binary_data", &return_binarydata)); - ASSERT_EQ(binarydata.size(), return_binarydata.size()); - for (int i = 0; i < binarydata.size(); ++i) { - ASSERT_EQ(binarydata[i], return_binarydata[i]); - } -} - -TEST_F(MetadataTest, TestNestedMetadata) { - std::unique_ptr<draco::Metadata> sub_metadata = - std::unique_ptr<draco::Metadata>(new draco::Metadata()); - sub_metadata->AddEntryInt("int", 100); - - metadata.AddSubMetadata("sub0", std::move(sub_metadata)); - const auto sub_metadata_ptr = metadata.GetSubMetadata("sub0"); - ASSERT_NE(sub_metadata_ptr, nullptr); - - int32_t int_value = 0; - ASSERT_TRUE(sub_metadata_ptr->GetEntryInt("int", &int_value)); - ASSERT_EQ(int_value, 100); -} - -TEST_F(MetadataTest, TestHardCopyMetadata) { - metadata.AddEntryInt("int", 100); - std::unique_ptr<draco::Metadata> sub_metadata = - std::unique_ptr<draco::Metadata>(new draco::Metadata()); - sub_metadata->AddEntryInt("int", 200); - metadata.AddSubMetadata("sub0", std::move(sub_metadata)); - - draco::Metadata copied_metadata(metadata); - - int32_t int_value = 0; - ASSERT_TRUE(copied_metadata.GetEntryInt("int", &int_value)); - ASSERT_EQ(int_value, 100); - - const auto sub_metadata_ptr = copied_metadata.GetSubMetadata("sub0"); - ASSERT_NE(sub_metadata_ptr, nullptr); - - int32_t sub_int_value = 0; - ASSERT_TRUE(sub_metadata_ptr->GetEntryInt("int", &sub_int_value)); - ASSERT_EQ(sub_int_value, 200); -} - -TEST_F(MetadataTest, TestGeometryMetadata) { - std::unique_ptr<draco::AttributeMetadata> att_metadata = - std::unique_ptr<draco::AttributeMetadata>(new draco::AttributeMetadata()); - att_metadata->set_att_unique_id(10); - att_metadata->AddEntryInt("int", 100); - att_metadata->AddEntryString("name", "pos"); - - ASSERT_FALSE(geometry_metadata.AddAttributeMetadata(nullptr)); - ASSERT_TRUE(geometry_metadata.AddAttributeMetadata(std::move(att_metadata))); - - ASSERT_NE(geometry_metadata.GetAttributeMetadataByUniqueId(10), nullptr); - ASSERT_EQ(geometry_metadata.GetAttributeMetadataByUniqueId(1), nullptr); - - const draco::AttributeMetadata *requested_att_metadata = - geometry_metadata.GetAttributeMetadataByStringEntry("name", "pos"); - ASSERT_NE(requested_att_metadata, nullptr); - ASSERT_EQ( - geometry_metadata.GetAttributeMetadataByStringEntry("name", "not_exists"), - nullptr); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder_test.cc b/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder_test.cc deleted file mode 100644 index 3222a4c8da8..00000000000 --- a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_builder_test.cc +++ /dev/null @@ -1,171 +0,0 @@ -// 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 "draco/point_cloud/point_cloud_builder.h" - -#include "draco/core/draco_test_base.h" - -namespace draco { - -class PointCloudBuilderTest : public ::testing::Test { - protected: - // Test data. - // clang-format off - std::vector<float> pos_data_ = {10.f, 0.f, 1.f, - 11.f, 1.f, 2.f, - 12.f, 2.f, 8.f, - 13.f, 4.f, 7.f, - 14.f, 5.f, 6.f, - 15.f, 6.f, 5.f, - 16.f, 1.f, 3.f, - 17.f, 1.f, 2.f, - 11.f, 1.f, 2.f, - 10.f, 0.f, 1.f}; - std::vector<int16_t> intensity_data_ = {100, - 200, - 500, - 700, - 400, - 400, - 400, - 100, - 100, - 100}; - // clang-format on -}; - -TEST_F(PointCloudBuilderTest, IndividualTest_NoDedup) { - // This test verifies that PointCloudBuilder can construct point cloud using - // SetAttributeValueForPoint API without deduplication. - PointCloudBuilder builder; - builder.Start(10); - const int pos_att_id = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - const int intensity_att_id = - builder.AddAttribute(GeometryAttribute::GENERIC, 1, DT_INT16); - for (PointIndex i(0); i < 10; ++i) { - builder.SetAttributeValueForPoint(pos_att_id, i, - pos_data_.data() + 3 * i.value()); - builder.SetAttributeValueForPoint(intensity_att_id, i, - intensity_data_.data() + i.value()); - } - std::unique_ptr<PointCloud> res = builder.Finalize(false); - ASSERT_TRUE(res != nullptr); - ASSERT_EQ(res->num_points(), 10); -} - -TEST_F(PointCloudBuilderTest, IndividualTest_Dedup) { - // This test verifies that PointCloudBuilder can construct point cloud using - // SetAttributeValueForPoint API with deduplication. - PointCloudBuilder builder; - builder.Start(10); - const int pos_att_id = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - const int intensity_att_id = - builder.AddAttribute(GeometryAttribute::GENERIC, 1, DT_INT16); - for (PointIndex i(0); i < 10; ++i) { - builder.SetAttributeValueForPoint(pos_att_id, i, - pos_data_.data() + 3 * i.value()); - builder.SetAttributeValueForPoint(intensity_att_id, i, - intensity_data_.data() + i.value()); - } - std::unique_ptr<PointCloud> res = builder.Finalize(true); - ASSERT_TRUE(res != nullptr); - ASSERT_EQ(res->num_points(), 9); -} - -TEST_F(PointCloudBuilderTest, BatchTest) { - // This test verifies that PointCloudBuilder can construct point cloud using - // SetAttributeValuesForAllPoints API. - PointCloudBuilder builder; - builder.Start(10); - const int pos_att_id = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - const int intensity_att_id = - builder.AddAttribute(GeometryAttribute::GENERIC, 1, DT_INT16); - builder.SetAttributeValuesForAllPoints(pos_att_id, pos_data_.data(), 0); - builder.SetAttributeValuesForAllPoints(intensity_att_id, - intensity_data_.data(), 0); - std::unique_ptr<PointCloud> res = builder.Finalize(false); - ASSERT_TRUE(res != nullptr); - ASSERT_EQ(res->num_points(), 10); - for (PointIndex i(0); i < 10; ++i) { - float pos_val[3]; - res->attribute(pos_att_id)->GetMappedValue(i, pos_val); - for (int c = 0; c < 3; ++c) { - ASSERT_EQ(pos_val[c], pos_data_[3 * i.value() + c]); - } - int16_t int_val; - res->attribute(intensity_att_id)->GetMappedValue(i, &int_val); - ASSERT_EQ(intensity_data_[i.value()], int_val); - } -} - -TEST_F(PointCloudBuilderTest, MultiUse) { - // This test verifies that PointCloudBuilder can be used multiple times - PointCloudBuilder builder; - { - builder.Start(10); - const int pos_att_id = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - const int intensity_att_id = - builder.AddAttribute(GeometryAttribute::GENERIC, 1, DT_INT16); - builder.SetAttributeValuesForAllPoints(pos_att_id, pos_data_.data(), 0); - builder.SetAttributeValuesForAllPoints(intensity_att_id, - intensity_data_.data(), 0); - std::unique_ptr<PointCloud> res = builder.Finalize(false); - ASSERT_TRUE(res != nullptr); - ASSERT_EQ(res->num_points(), 10); - for (PointIndex i(0); i < 10; ++i) { - float pos_val[3]; - res->attribute(pos_att_id)->GetMappedValue(i, pos_val); - for (int c = 0; c < 3; ++c) { - ASSERT_EQ(pos_val[c], pos_data_[3 * i.value() + c]); - } - int16_t int_val; - res->attribute(intensity_att_id)->GetMappedValue(i, &int_val); - ASSERT_EQ(intensity_data_[i.value()], int_val); - } - } - - { - // Use only a sub-set of data (offsetted to avoid possible reuse of old - // data). - builder.Start(4); - const int pos_att_id = - builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32); - const int intensity_att_id = - builder.AddAttribute(GeometryAttribute::GENERIC, 1, DT_INT16); - constexpr int offset = 5; - builder.SetAttributeValuesForAllPoints(pos_att_id, - pos_data_.data() + 3 * offset, 0); - builder.SetAttributeValuesForAllPoints(intensity_att_id, - intensity_data_.data() + offset, 0); - std::unique_ptr<PointCloud> res = builder.Finalize(false); - ASSERT_TRUE(res != nullptr); - ASSERT_EQ(res->num_points(), 4); - for (PointIndex i(0); i < 4; ++i) { - float pos_val[3]; - res->attribute(pos_att_id)->GetMappedValue(i, pos_val); - for (int c = 0; c < 3; ++c) { - ASSERT_EQ(pos_val[c], pos_data_[3 * (i.value() + offset) + c]); - } - int16_t int_val; - res->attribute(intensity_att_id)->GetMappedValue(i, &int_val); - ASSERT_EQ(intensity_data_[i.value() + offset], int_val); - } - } -} - -} // namespace draco diff --git a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_test.cc b/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_test.cc deleted file mode 100644 index 00491b7309a..00000000000 --- a/extern/draco/dracoenc/src/draco/point_cloud/point_cloud_test.cc +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2017 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 "draco/core/draco_test_base.h" -#include "draco/core/draco_test_utils.h" - -#include "draco/point_cloud/point_cloud.h" - -namespace { - -class PointCloudTest : public ::testing::Test { - protected: - PointCloudTest() {} -}; - -TEST_F(PointCloudTest, TestAttributeDeletion) { - draco::PointCloud pc; - // Test whether we can correctly delete an attribute from a point cloud. - // Create some attributes for the point cloud. - draco::GeometryAttribute pos_att; - pos_att.Init(draco::GeometryAttribute::POSITION, nullptr, 3, - draco::DT_FLOAT32, false, 12, 0); - draco::GeometryAttribute norm_att; - norm_att.Init(draco::GeometryAttribute::NORMAL, nullptr, 3, draco::DT_FLOAT32, - false, 12, 0); - draco::GeometryAttribute gen_att; - gen_att.Init(draco::GeometryAttribute::GENERIC, nullptr, 3, draco::DT_FLOAT32, - false, 12, 0); - - // Add one position, two normal and two generic attributes. - pc.AddAttribute(pos_att, false, 0); - pc.AddAttribute(gen_att, false, 0); - pc.AddAttribute(norm_att, false, 0); - pc.AddAttribute(gen_att, false, 0); - pc.AddAttribute(norm_att, false, 0); - - ASSERT_EQ(pc.num_attributes(), 5); - ASSERT_EQ(pc.attribute(0)->attribute_type(), - draco::GeometryAttribute::POSITION); - ASSERT_EQ(pc.attribute(3)->attribute_type(), - draco::GeometryAttribute::GENERIC); - - // Delete generic attribute. - pc.DeleteAttribute(1); - ASSERT_EQ(pc.num_attributes(), 4); - ASSERT_EQ(pc.attribute(1)->attribute_type(), - draco::GeometryAttribute::NORMAL); - ASSERT_EQ(pc.NumNamedAttributes(draco::GeometryAttribute::NORMAL), 2); - ASSERT_EQ(pc.GetNamedAttributeId(draco::GeometryAttribute::NORMAL, 1), 3); - - // Delete the first normal attribute. - pc.DeleteAttribute(1); - ASSERT_EQ(pc.num_attributes(), 3); - ASSERT_EQ(pc.attribute(1)->attribute_type(), - draco::GeometryAttribute::GENERIC); - ASSERT_EQ(pc.NumNamedAttributes(draco::GeometryAttribute::NORMAL), 1); - ASSERT_EQ(pc.GetNamedAttributeId(draco::GeometryAttribute::NORMAL, 0), 2); -} - -TEST_F(PointCloudTest, TestPointCloudWithMetadata) { - draco::PointCloud pc; - std::unique_ptr<draco::GeometryMetadata> metadata = - std::unique_ptr<draco::GeometryMetadata>(new draco::GeometryMetadata()); - - // Add a position attribute metadata. - draco::GeometryAttribute pos_att; - pos_att.Init(draco::GeometryAttribute::POSITION, nullptr, 3, - draco::DT_FLOAT32, false, 12, 0); - const uint32_t pos_att_id = pc.AddAttribute(pos_att, false, 0); - ASSERT_EQ(pos_att_id, 0); - std::unique_ptr<draco::AttributeMetadata> pos_metadata = - std::unique_ptr<draco::AttributeMetadata>(new draco::AttributeMetadata()); - pos_metadata->AddEntryString("name", "position"); - pc.AddAttributeMetadata(pos_att_id, std::move(pos_metadata)); - const draco::GeometryMetadata *pc_metadata = pc.GetMetadata(); - ASSERT_NE(pc_metadata, nullptr); - // Add a generic material attribute metadata. - draco::GeometryAttribute material_att; - material_att.Init(draco::GeometryAttribute::GENERIC, nullptr, 3, - draco::DT_FLOAT32, false, 12, 0); - const uint32_t material_att_id = pc.AddAttribute(material_att, false, 0); - ASSERT_EQ(material_att_id, 1); - std::unique_ptr<draco::AttributeMetadata> material_metadata = - std::unique_ptr<draco::AttributeMetadata>(new draco::AttributeMetadata()); - material_metadata->AddEntryString("name", "material"); - // The material attribute has id of 1 now. - pc.AddAttributeMetadata(material_att_id, std::move(material_metadata)); - - // Test if the attribute metadata is correctly added. - const draco::AttributeMetadata *requested_pos_metadata = - pc.GetAttributeMetadataByStringEntry("name", "position"); - ASSERT_NE(requested_pos_metadata, nullptr); - const draco::AttributeMetadata *requested_mat_metadata = - pc.GetAttributeMetadataByStringEntry("name", "material"); - ASSERT_NE(requested_mat_metadata, nullptr); - - // Attribute id should be preserved. - ASSERT_EQ( - pc.GetAttributeIdByUniqueId(requested_pos_metadata->att_unique_id()), 0); - ASSERT_EQ( - pc.GetAttributeIdByUniqueId(requested_mat_metadata->att_unique_id()), 1); - - // Test deleting attribute with metadata. - pc.DeleteAttribute(pos_att_id); - ASSERT_EQ(pc.GetAttributeMetadataByStringEntry("name", "position"), nullptr); - - requested_mat_metadata = - pc.GetAttributeMetadataByStringEntry("name", "material"); - // The unique id should not be changed. - ASSERT_EQ(requested_mat_metadata->att_unique_id(), 1); - // Now position attribute is removed, material attribute should have the - // attribute id of 0. - ASSERT_EQ( - pc.GetAttributeIdByUniqueId(requested_mat_metadata->att_unique_id()), 0); - // Should be able to get metadata using the current attribute id. - // Attribute id of material attribute is changed from 1 to 0. - ASSERT_NE(pc.GetAttributeMetadataByAttributeId(0), nullptr); -} - -} // namespace diff --git a/extern/draco/dracoenc/src/draco/tools/draco_decoder.cc b/extern/draco/dracoenc/src/draco/tools/draco_decoder.cc deleted file mode 100644 index 5b06e8caa3b..00000000000 --- a/extern/draco/dracoenc/src/draco/tools/draco_decoder.cc +++ /dev/null @@ -1,178 +0,0 @@ -// 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 <cinttypes> -#include <fstream> - -#include "draco/compression/decode.h" -#include "draco/core/cycle_timer.h" -#include "draco/io/obj_encoder.h" -#include "draco/io/parser_utils.h" -#include "draco/io/ply_encoder.h" - -namespace { - -struct Options { - Options(); - - std::string input; - std::string output; -}; - -Options::Options() {} - -void Usage() { - printf("Usage: draco_decoder [options] -i input\n"); - printf("\n"); - printf("Main options:\n"); - printf(" -h | -? show help.\n"); - printf(" -o <output> output file name.\n"); -} - -int ReturnError(const draco::Status &status) { - printf("Failed to decode the input file %s\n", status.error_msg()); - return -1; -} - -} // namespace - -int main(int argc, char **argv) { - Options options; - const int argc_check = argc - 1; - - for (int i = 1; i < argc; ++i) { - if (!strcmp("-h", argv[i]) || !strcmp("-?", argv[i])) { - Usage(); - return 0; - } else if (!strcmp("-i", argv[i]) && i < argc_check) { - options.input = argv[++i]; - } else if (!strcmp("-o", argv[i]) && i < argc_check) { - options.output = argv[++i]; - } - } - if (argc < 3 || options.input.empty()) { - Usage(); - return -1; - } - - std::ifstream input_file(options.input, std::ios::binary); - if (!input_file) { - printf("Failed opening the input file.\n"); - return -1; - } - - // Read the file stream into a buffer. - std::streampos file_size = 0; - input_file.seekg(0, std::ios::end); - file_size = input_file.tellg() - file_size; - input_file.seekg(0, std::ios::beg); - std::vector<char> data(file_size); - input_file.read(data.data(), file_size); - - if (data.empty()) { - printf("Empty input file.\n"); - return -1; - } - - // Create a draco decoding buffer. Note that no data is copied in this step. - draco::DecoderBuffer buffer; - buffer.Init(data.data(), data.size()); - - draco::CycleTimer timer; - // Decode the input data into a geometry. - std::unique_ptr<draco::PointCloud> pc; - draco::Mesh *mesh = nullptr; - auto type_statusor = draco::Decoder::GetEncodedGeometryType(&buffer); - if (!type_statusor.ok()) { - return ReturnError(type_statusor.status()); - } - const draco::EncodedGeometryType geom_type = type_statusor.value(); - if (geom_type == draco::TRIANGULAR_MESH) { - timer.Start(); - draco::Decoder decoder; - auto statusor = decoder.DecodeMeshFromBuffer(&buffer); - if (!statusor.ok()) { - return ReturnError(statusor.status()); - } - std::unique_ptr<draco::Mesh> in_mesh = std::move(statusor).value(); - timer.Stop(); - if (in_mesh) { - mesh = in_mesh.get(); - pc = std::move(in_mesh); - } - } else if (geom_type == draco::POINT_CLOUD) { - // Failed to decode it as mesh, so let's try to decode it as a point cloud. - timer.Start(); - draco::Decoder decoder; - auto statusor = decoder.DecodePointCloudFromBuffer(&buffer); - if (!statusor.ok()) { - return ReturnError(statusor.status()); - } - pc = std::move(statusor).value(); - timer.Stop(); - } - - if (pc == nullptr) { - printf("Failed to decode the input file.\n"); - return -1; - } - - if (options.output.empty()) { - // Save the output model into a ply file. - options.output = options.input + ".ply"; - } - - // Save the decoded geometry into a file. - // TODO(fgalligan): Change extension code to look for '.'. - const std::string extension = draco::parser::ToLower( - options.output.size() >= 4 - ? options.output.substr(options.output.size() - 4) - : options.output); - - if (extension == ".obj") { - draco::ObjEncoder obj_encoder; - if (mesh) { - if (!obj_encoder.EncodeToFile(*mesh, options.output)) { - printf("Failed to store the decoded mesh as OBJ.\n"); - return -1; - } - } else { - if (!obj_encoder.EncodeToFile(*pc.get(), options.output)) { - printf("Failed to store the decoded point cloud as OBJ.\n"); - return -1; - } - } - } else if (extension == ".ply") { - draco::PlyEncoder ply_encoder; - if (mesh) { - if (!ply_encoder.EncodeToFile(*mesh, options.output)) { - printf("Failed to store the decoded mesh as PLY.\n"); - return -1; - } - } else { - if (!ply_encoder.EncodeToFile(*pc.get(), options.output)) { - printf("Failed to store the decoded point cloud as PLY.\n"); - return -1; - } - } - } else { - printf( - "Invalid extension of the output file. Use either .ply, .obj, or " - ".gltf\n"); - return -1; - } - printf("Decoded geometry saved to %s (%" PRId64 " ms to decode)\n", - options.output.c_str(), timer.GetInMs()); - return 0; -} diff --git a/extern/draco/dracoenc/src/draco/tools/draco_encoder.cc b/extern/draco/dracoenc/src/draco/tools/draco_encoder.cc deleted file mode 100644 index e44d0939048..00000000000 --- a/extern/draco/dracoenc/src/draco/tools/draco_encoder.cc +++ /dev/null @@ -1,373 +0,0 @@ -// 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 <cinttypes> -#include <cstdlib> -#include <fstream> - -#include "draco/compression/encode.h" -#include "draco/core/cycle_timer.h" -#include "draco/io/mesh_io.h" -#include "draco/io/point_cloud_io.h" - -namespace { - -struct Options { - Options(); - - bool is_point_cloud; - int pos_quantization_bits; - int tex_coords_quantization_bits; - bool tex_coords_deleted; - int normals_quantization_bits; - bool normals_deleted; - int generic_quantization_bits; - bool generic_deleted; - int compression_level; - bool use_metadata; - std::string input; - std::string output; -}; - -Options::Options() - : is_point_cloud(false), - pos_quantization_bits(14), - tex_coords_quantization_bits(12), - tex_coords_deleted(false), - normals_quantization_bits(10), - normals_deleted(false), - generic_quantization_bits(8), - generic_deleted(false), - compression_level(7), - use_metadata(false) {} - -void Usage() { - printf("Usage: draco_encoder [options] -i input\n"); - printf("\n"); - printf("Main options:\n"); - printf(" -h | -? show help.\n"); - printf(" -i <input> input file name.\n"); - printf(" -o <output> output file name.\n"); - printf( - " -point_cloud forces the input to be encoded as a point " - "cloud.\n"); - printf( - " -qp <value> quantization bits for the position " - "attribute, default=14.\n"); - printf( - " -qt <value> quantization bits for the texture coordinate " - "attribute, default=12.\n"); - printf( - " -qn <value> quantization bits for the normal vector " - "attribute, default=10.\n"); - printf( - " -qg <value> quantization bits for any generic attribute, " - "default=8.\n"); - printf( - " -cl <value> compression level [0-10], most=10, least=0, " - "default=7.\n"); - printf( - " --skip ATTRIBUTE_NAME skip a given attribute (NORMAL, TEX_COORD, " - "GENERIC)\n"); - printf( - " --metadata use metadata to encode extra information in " - "mesh files.\n"); - printf( - "\nUse negative quantization values to skip the specified attribute\n"); -} - -int StringToInt(const std::string &s) { - char *end; - return strtol(s.c_str(), &end, 10); // NOLINT -} - -void PrintOptions(const draco::PointCloud &pc, const Options &options) { - printf("Encoder options:\n"); - printf(" Compression level = %d\n", options.compression_level); - if (options.pos_quantization_bits == 0) { - printf(" Positions: No quantization\n"); - } else { - printf(" Positions: Quantization = %d bits\n", - options.pos_quantization_bits); - } - - if (pc.GetNamedAttributeId(draco::GeometryAttribute::TEX_COORD) >= 0) { - if (options.tex_coords_quantization_bits == 0) { - printf(" Texture coordinates: No quantization\n"); - } else { - printf(" Texture coordinates: Quantization = %d bits\n", - options.tex_coords_quantization_bits); - } - } else if (options.tex_coords_deleted) { - printf(" Texture coordinates: Skipped\n"); - } - - if (pc.GetNamedAttributeId(draco::GeometryAttribute::NORMAL) >= 0) { - if (options.normals_quantization_bits == 0) { - printf(" Normals: No quantization\n"); - } else { - printf(" Normals: Quantization = %d bits\n", - options.normals_quantization_bits); - } - } else if (options.normals_deleted) { - printf(" Normals: Skipped\n"); - } - - if (pc.GetNamedAttributeId(draco::GeometryAttribute::GENERIC) >= 0) { - if (options.generic_quantization_bits == 0) { - printf(" Generic: No quantization\n"); - } else { - printf(" Generic: Quantization = %d bits\n", - options.generic_quantization_bits); - } - } else if (options.generic_deleted) { - printf(" Generic: Skipped\n"); - } - printf("\n"); -} - -int EncodePointCloudToFile(const draco::PointCloud &pc, const std::string &file, - draco::Encoder *encoder) { - draco::CycleTimer timer; - // Encode the geometry. - draco::EncoderBuffer buffer; - timer.Start(); - const draco::Status status = encoder->EncodePointCloudToBuffer(pc, &buffer); - if (!status.ok()) { - printf("Failed to encode the point cloud.\n"); - printf("%s\n", status.error_msg()); - return -1; - } - timer.Stop(); - // Save the encoded geometry into a file. - std::ofstream out_file(file, std::ios::binary); - if (!out_file) { - printf("Failed to create the output file.\n"); - return -1; - } - out_file.write(buffer.data(), buffer.size()); - printf("Encoded point cloud saved to %s (%" PRId64 " ms to encode).\n", - file.c_str(), timer.GetInMs()); - printf("\nEncoded size = %zu bytes\n\n", buffer.size()); - return 0; -} - -int EncodeMeshToFile(const draco::Mesh &mesh, const std::string &file, - draco::Encoder *encoder) { - draco::CycleTimer timer; - // Encode the geometry. - draco::EncoderBuffer buffer; - timer.Start(); - const draco::Status status = encoder->EncodeMeshToBuffer(mesh, &buffer); - if (!status.ok()) { - printf("Failed to encode the mesh.\n"); - printf("%s\n", status.error_msg()); - return -1; - } - timer.Stop(); - // Save the encoded geometry into a file. - std::ofstream out_file(file, std::ios::binary); - if (!out_file) { - printf("Failed to create the output file.\n"); - return -1; - } - out_file.write(buffer.data(), buffer.size()); - printf("Encoded mesh saved to %s (%" PRId64 " ms to encode).\n", file.c_str(), - timer.GetInMs()); - printf("\nEncoded size = %zu bytes\n\n", buffer.size()); - return 0; -} - -} // anonymous namespace - -int main(int argc, char **argv) { - Options options; - const int argc_check = argc - 1; - - for (int i = 1; i < argc; ++i) { - if (!strcmp("-h", argv[i]) || !strcmp("-?", argv[i])) { - Usage(); - return 0; - } else if (!strcmp("-i", argv[i]) && i < argc_check) { - options.input = argv[++i]; - } else if (!strcmp("-o", argv[i]) && i < argc_check) { - options.output = argv[++i]; - } else if (!strcmp("-point_cloud", argv[i])) { - options.is_point_cloud = true; - } else if (!strcmp("-qp", argv[i]) && i < argc_check) { - options.pos_quantization_bits = StringToInt(argv[++i]); - if (options.pos_quantization_bits > 30) { - printf( - "Error: The maximum number of quantization bits for the position " - "attribute is 30.\n"); - return -1; - } - } else if (!strcmp("-qt", argv[i]) && i < argc_check) { - options.tex_coords_quantization_bits = StringToInt(argv[++i]); - if (options.tex_coords_quantization_bits > 30) { - printf( - "Error: The maximum number of quantization bits for the texture " - "coordinate attribute is 30.\n"); - return -1; - } - } else if (!strcmp("-qn", argv[i]) && i < argc_check) { - options.normals_quantization_bits = StringToInt(argv[++i]); - if (options.normals_quantization_bits > 30) { - printf( - "Error: The maximum number of quantization bits for the normal " - "attribute is 30.\n"); - return -1; - } - } else if (!strcmp("-qg", argv[i]) && i < argc_check) { - options.generic_quantization_bits = StringToInt(argv[++i]); - if (options.generic_quantization_bits > 30) { - printf( - "Error: The maximum number of quantization bits for generic " - "attributes is 30.\n"); - return -1; - } - } else if (!strcmp("-cl", argv[i]) && i < argc_check) { - options.compression_level = StringToInt(argv[++i]); - } else if (!strcmp("--skip", argv[i]) && i < argc_check) { - if (!strcmp("NORMAL", argv[i + 1])) { - options.normals_quantization_bits = -1; - } else if (!strcmp("TEX_COORD", argv[i + 1])) { - options.tex_coords_quantization_bits = -1; - } else if (!strcmp("GENERIC", argv[i + 1])) { - options.generic_quantization_bits = -1; - } else { - printf("Error: Invalid attribute name after --skip\n"); - return -1; - } - ++i; - } else if (!strcmp("--metadata", argv[i])) { - options.use_metadata = true; - } - } - if (argc < 3 || options.input.empty()) { - Usage(); - return -1; - } - - std::unique_ptr<draco::PointCloud> pc; - draco::Mesh *mesh = nullptr; - if (!options.is_point_cloud) { - auto maybe_mesh = - draco::ReadMeshFromFile(options.input, options.use_metadata); - if (!maybe_mesh.ok()) { - printf("Failed loading the input mesh: %s.\n", - maybe_mesh.status().error_msg()); - return -1; - } - mesh = maybe_mesh.value().get(); - pc = std::move(maybe_mesh).value(); - } else { - auto maybe_pc = draco::ReadPointCloudFromFile(options.input); - if (!maybe_pc.ok()) { - printf("Failed loading the input point cloud: %s.\n", - maybe_pc.status().error_msg()); - return -1; - } - pc = std::move(maybe_pc).value(); - } - - if (options.pos_quantization_bits < 0) { - printf("Error: Position attribute cannot be skipped.\n"); - return -1; - } - - // Delete attributes if needed. This needs to happen before we set any - // quantization settings. - if (options.tex_coords_quantization_bits < 0) { - if (pc->NumNamedAttributes(draco::GeometryAttribute::TEX_COORD) > 0) { - options.tex_coords_deleted = true; - } - while (pc->NumNamedAttributes(draco::GeometryAttribute::TEX_COORD) > 0) { - pc->DeleteAttribute( - pc->GetNamedAttributeId(draco::GeometryAttribute::TEX_COORD, 0)); - } - } - if (options.normals_quantization_bits < 0) { - if (pc->NumNamedAttributes(draco::GeometryAttribute::NORMAL) > 0) { - options.normals_deleted = true; - } - while (pc->NumNamedAttributes(draco::GeometryAttribute::NORMAL) > 0) { - pc->DeleteAttribute( - pc->GetNamedAttributeId(draco::GeometryAttribute::NORMAL, 0)); - } - } - if (options.generic_quantization_bits < 0) { - if (pc->NumNamedAttributes(draco::GeometryAttribute::GENERIC) > 0) { - options.generic_deleted = true; - } - while (pc->NumNamedAttributes(draco::GeometryAttribute::GENERIC) > 0) { - pc->DeleteAttribute( - pc->GetNamedAttributeId(draco::GeometryAttribute::GENERIC, 0)); - } - } -#ifdef DRACO_ATTRIBUTE_INDICES_DEDUPLICATION_SUPPORTED - // If any attribute has been deleted, run deduplication of point indices again - // as some points can be possibly combined. - if (options.tex_coords_deleted || options.normals_deleted || - options.generic_deleted) { - pc->DeduplicatePointIds(); - } -#endif - - // Convert compression level to speed (that 0 = slowest, 10 = fastest). - const int speed = 10 - options.compression_level; - - draco::Encoder encoder; - - // Setup encoder options. - if (options.pos_quantization_bits > 0) { - encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, - options.pos_quantization_bits); - } - if (options.tex_coords_quantization_bits > 0) { - encoder.SetAttributeQuantization(draco::GeometryAttribute::TEX_COORD, - options.tex_coords_quantization_bits); - } - if (options.normals_quantization_bits > 0) { - encoder.SetAttributeQuantization(draco::GeometryAttribute::NORMAL, - options.normals_quantization_bits); - } - if (options.generic_quantization_bits > 0) { - encoder.SetAttributeQuantization(draco::GeometryAttribute::GENERIC, - options.generic_quantization_bits); - } - encoder.SetSpeedOptions(speed, speed); - - if (options.output.empty()) { - // Create a default output file by attaching .drc to the input file name. - options.output = options.input + ".drc"; - } - - PrintOptions(*pc.get(), options); - - int ret = -1; - const bool input_is_mesh = mesh && mesh->num_faces() > 0; - if (input_is_mesh) - ret = EncodeMeshToFile(*mesh, options.output, &encoder); - else - ret = EncodePointCloudToFile(*pc.get(), options.output, &encoder); - - if (ret != -1 && options.compression_level < 10) { - printf( - "For better compression, increase the compression level up to '-cl 10' " - ".\n\n"); - } - - return ret; -} diff --git a/extern/draco/src/common.cpp b/extern/draco/src/common.cpp new file mode 100644 index 00000000000..6f98d8db7ef --- /dev/null +++ b/extern/draco/src/common.cpp @@ -0,0 +1,77 @@ +/* + * 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 "common.h" + +#include <cstring> + +size_t getNumberOfComponents(char *dataType) +{ + if (!strcmp(dataType, "SCALAR")) + { + return 1; + } + if (!strcmp(dataType, "VEC2")) + { + return 2; + } + if (!strcmp(dataType, "VEC3")) + { + return 3; + } + if (!strcmp(dataType, "VEC4")) + { + return 4; + } + if (!strcmp(dataType, "MAT2")) + { + return 4; + } + if (!strcmp(dataType, "MAT3")) + { + return 9; + } + if (!strcmp(dataType, "MAT4")) + { + return 16; + } + + return 0; +} + +size_t getComponentByteLength(size_t componentType) +{ + switch (componentType) + { + case ComponentType::Byte: + case ComponentType::UnsignedByte: + return 1; + + case ComponentType::Short: + case ComponentType::UnsignedShort: + return 2; + + case ComponentType::UnsignedInt: + case ComponentType::Float: + return 4; + + default: + return 0; + } +} + +size_t getAttributeStride(size_t componentType, char *dataType) +{ + return getComponentByteLength(componentType) * getNumberOfComponents(dataType); +} diff --git a/extern/draco/src/common.h b/extern/draco/src/common.h new file mode 100644 index 00000000000..beaf7d91adb --- /dev/null +++ b/extern/draco/src/common.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +/** + * Library for the Draco encoding/decoding feature inside the glTF-Blender-IO project. + * + * The python script within glTF-Blender-IO uses the CTypes library to open the DLL, + * load function pointers add pass the raw data to the encoder. + * + * @author Jim Eckerlein <eckerlein@ux3d.io> + * @date 2020-11-18 + */ + +#pragma once + +#include <cstdint> +#include <cstddef> + +#if defined(_MSC_VER) +#define API(returnType) extern "C" __declspec(dllexport) returnType __cdecl +#else +#define API(returnType) extern "C" returnType +#endif + +enum ComponentType: size_t +{ + Byte = 5120, + UnsignedByte = 5121, + Short = 5122, + UnsignedShort = 5123, + UnsignedInt = 5125, + Float = 5126, +}; + +size_t getNumberOfComponents(char *dataType); + +size_t getComponentByteLength(size_t componentType); + +size_t getAttributeStride(size_t componentType, char *dataType); diff --git a/extern/draco/src/decoder.cpp b/extern/draco/src/decoder.cpp new file mode 100644 index 00000000000..3f3e03bd9f2 --- /dev/null +++ b/extern/draco/src/decoder.cpp @@ -0,0 +1,222 @@ +/* + * 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. + */ + +/** + * @author Jim Eckerlein <eckerlein@ux3d.io> + * @date 2020-11-18 + */ + + +#include "decoder.h" + +#include <memory> +#include <vector> +#include <cinttypes> + +#include "draco/mesh/mesh.h" +#include "draco/core/decoder_buffer.h" +#include "draco/compression/decode.h" + +#define LOG_PREFIX "DracoDecoder | " + +struct Decoder { + std::unique_ptr<draco::Mesh> mesh; + std::vector<uint8_t> indexBuffer; + std::map<uint32_t, std::vector<uint8_t>> buffers; + draco::DecoderBuffer decoderBuffer; + uint32_t vertexCount; + uint32_t indexCount; +}; + +Decoder *decoderCreate() +{ + return new Decoder; +} + +void decoderRelease(Decoder *decoder) +{ + delete decoder; +} + +bool decoderDecode(Decoder *decoder, void *data, size_t byteLength) +{ + draco::Decoder dracoDecoder; + draco::DecoderBuffer dracoDecoderBuffer; + dracoDecoderBuffer.Init(reinterpret_cast<char *>(data), byteLength); + + auto decoderStatus = dracoDecoder.DecodeMeshFromBuffer(&dracoDecoderBuffer); + if (!decoderStatus.ok()) + { + printf(LOG_PREFIX "Error during Draco decoding: %s\n", decoderStatus.status().error_msg()); + return false; + } + + decoder->mesh = std::move(decoderStatus).value(); + decoder->vertexCount = decoder->mesh->num_points(); + decoder->indexCount = decoder->mesh->num_faces() * 3; + + printf(LOG_PREFIX "Decoded %" PRIu32 " vertices, %" PRIu32 " indices\n", decoder->vertexCount, decoder->indexCount); + + return true; +} + +uint32_t decoderGetVertexCount(Decoder *decoder) +{ + return decoder->vertexCount; +} + +uint32_t decoderGetIndexCount(Decoder *decoder) +{ + return decoder->indexCount; +} + +bool decoderAttributeIsNormalized(Decoder *decoder, uint32_t id) +{ + const draco::PointAttribute* attribute = decoder->mesh->GetAttributeByUniqueId(id); + return attribute != nullptr && attribute->normalized(); +} + +bool decoderReadAttribute(Decoder *decoder, uint32_t id, size_t componentType, char *dataType) +{ + const draco::PointAttribute* attribute = decoder->mesh->GetAttributeByUniqueId(id); + + if (attribute == nullptr) + { + printf(LOG_PREFIX "Attribute with id=%" PRIu32 " does not exist in Draco data\n", id); + return false; + } + + size_t stride = getAttributeStride(componentType, dataType); + + std::vector<uint8_t> decodedData; + decodedData.resize(stride * decoder->vertexCount); + + for (uint32_t i = 0; i < decoder->vertexCount; ++i) + { + auto index = attribute->mapped_index(draco::PointIndex(i)); + uint8_t *value = decodedData.data() + i * stride; + + bool converted = false; + + switch (componentType) + { + case ComponentType::Byte: + converted = attribute->ConvertValue(index, reinterpret_cast<int8_t *>(value)); + break; + case ComponentType::UnsignedByte: + converted = attribute->ConvertValue(index, reinterpret_cast<uint8_t *>(value)); + break; + case ComponentType::Short: + converted = attribute->ConvertValue(index, reinterpret_cast<int16_t *>(value)); + break; + case ComponentType::UnsignedShort: + converted = attribute->ConvertValue(index, reinterpret_cast<uint16_t *>(value)); + break; + case ComponentType::UnsignedInt: + converted = attribute->ConvertValue(index, reinterpret_cast<uint32_t *>(value)); + break; + case ComponentType::Float: + converted = attribute->ConvertValue(index, reinterpret_cast<float *>(value)); + break; + default: + break; + } + + if (!converted) + { + printf(LOG_PREFIX "Failed to convert Draco attribute type to glTF accessor type for attribute with id=%" PRIu32 "\n", id); + return false; + } + } + + decoder->buffers[id] = decodedData; + return true; +} + +size_t decoderGetAttributeByteLength(Decoder *decoder, size_t id) +{ + auto iter = decoder->buffers.find(id); + if (iter != decoder->buffers.end()) + { + return iter->second.size(); + } + else + { + return 0; + } +} + +void decoderCopyAttribute(Decoder *decoder, size_t id, void *output) +{ + auto iter = decoder->buffers.find(id); + if (iter != decoder->buffers.end()) + { + memcpy(output, iter->second.data(), iter->second.size()); + } +} + +template<class T> +void decodeIndices(Decoder *decoder) +{ + std::vector<uint8_t> decodedIndices; + decodedIndices.resize(decoder->indexCount * sizeof(T)); + T *typedView = reinterpret_cast<T *>(decodedIndices.data()); + + for (uint32_t faceIndex = 0; faceIndex < decoder->mesh->num_faces(); ++faceIndex) + { + const draco::Mesh::Face &face = decoder->mesh->face(draco::FaceIndex(faceIndex)); + typedView[faceIndex * 3 + 0] = face[0].value(); + typedView[faceIndex * 3 + 1] = face[1].value(); + typedView[faceIndex * 3 + 2] = face[2].value(); + } + + decoder->indexBuffer = decodedIndices; +} + +bool decoderReadIndices(Decoder *decoder, size_t indexComponentType) +{ + switch (indexComponentType) + { + case ComponentType::Byte: + decodeIndices<int8_t>(decoder); + break; + case ComponentType::UnsignedByte: + decodeIndices<uint8_t>(decoder); + break; + case ComponentType::Short: + decodeIndices<int16_t>(decoder); + break; + case ComponentType::UnsignedShort: + decodeIndices<uint16_t>(decoder); + break; + case ComponentType::UnsignedInt: + decodeIndices<uint32_t>(decoder); + break; + default: + printf(LOG_PREFIX "Index component type %zu not supported\n", indexComponentType); + return false; + } + + return true; +} + +size_t decoderGetIndicesByteLength(Decoder *decoder) +{ + return decoder->indexBuffer.size(); +} + +void decoderCopyIndices(Decoder *decoder, void *output) +{ + memcpy(output, decoder->indexBuffer.data(), decoder->indexBuffer.size()); +} diff --git a/extern/draco/src/decoder.h b/extern/draco/src/decoder.h new file mode 100644 index 00000000000..914eb776e8f --- /dev/null +++ b/extern/draco/src/decoder.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +/** + * Library for the Draco encoding/decoding feature inside the glTF-Blender-IO project. + * + * The python script within glTF-Blender-IO uses the CTypes library to open the DLL, + * load function pointers add pass the raw data to the encoder. + * + * @author Jim Eckerlein <eckerlein@ux3d.io> + * @date 2020-11-18 + */ + +#pragma once + +#include "common.h" + +struct Decoder; + +API(Decoder *) decoderCreate(); + +API(void) decoderRelease(Decoder *decoder); + +API(bool) decoderDecode(Decoder *decoder, void *data, size_t byteLength); + +API(uint32_t) decoderGetVertexCount(Decoder *decoder); + +API(uint32_t) decoderGetIndexCount(Decoder *decoder); + +API(bool) decoderAttributeIsNormalized(Decoder *decoder, uint32_t id); + +API(bool) decoderReadAttribute(Decoder *decoder, uint32_t id, size_t componentType, char *dataType); + +API(size_t) decoderGetAttributeByteLength(Decoder *decoder, size_t id); + +API(void) decoderCopyAttribute(Decoder *decoder, size_t id, void *output); + +API(bool) decoderReadIndices(Decoder *decoder, size_t indexComponentType); + +API(size_t) decoderGetIndicesByteLength(Decoder *decoder); + +API(void) decoderCopyIndices(Decoder *decoder, void *output); diff --git a/extern/draco/src/draco-compressor.cpp b/extern/draco/src/draco-compressor.cpp deleted file mode 100644 index 4ae528888fe..00000000000 --- a/extern/draco/src/draco-compressor.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* - * 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. - */ - -/** - * @author Jim Eckerlein <eckerlein@ux3d.io> - * @date 2019-11-29 - */ - -#include "draco-compressor.h" - -#include <memory> -#include <vector> - -#include "draco/mesh/mesh.h" -#include "draco/core/encoder_buffer.h" -#include "draco/compression/encode.h" - -/** - * Prefix used for logging messages. - */ -const char *logTag = "DRACO-COMPRESSOR"; - -struct DracoCompressor { - draco::Mesh mesh; - - // One data buffer per attribute. - std::vector<std::unique_ptr<draco::DataBuffer>> buffers; - - // The buffer the mesh is compressed into. - draco::EncoderBuffer encoderBuffer; - - // Level of compression [0-10]. - // Higher values mean slower encoding. - uint32_t compressionLevel = 7; - - struct { - uint32_t positions = 14; - uint32_t normals = 10; - uint32_t uvs = 12; - uint32_t generic = 12; - } quantization; -}; - -DracoCompressor *create_compressor() { - return new DracoCompressor; -} - -void set_compression_level( - DracoCompressor *const compressor, - uint32_t const compressionLevel -) { - compressor->compressionLevel = compressionLevel; -} - -void set_position_quantization( - DracoCompressor *const compressor, - uint32_t const quantizationBitsPosition -) { - compressor->quantization.positions = quantizationBitsPosition; -} - -void set_normal_quantization( - DracoCompressor *const compressor, - uint32_t const quantizationBitsNormal -) { - compressor->quantization.normals = quantizationBitsNormal; -} - -void set_uv_quantization( - DracoCompressor *const compressor, - uint32_t const quantizationBitsTexCoord -) { - compressor->quantization.uvs = quantizationBitsTexCoord; -} - -void set_generic_quantization( - DracoCompressor *const compressor, - uint32_t const bits -) { - compressor->quantization.generic = bits; -} - -bool compress( - DracoCompressor *const compressor -) { - draco::Encoder encoder; - - encoder.SetSpeedOptions(10 - (int)compressor->compressionLevel, 10 - (int)compressor->compressionLevel); - encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, compressor->quantization.positions); - encoder.SetAttributeQuantization(draco::GeometryAttribute::NORMAL, compressor->quantization.normals); - encoder.SetAttributeQuantization(draco::GeometryAttribute::TEX_COORD, compressor->quantization.uvs); - encoder.SetAttributeQuantization(draco::GeometryAttribute::GENERIC, compressor->quantization.generic); - - return encoder.EncodeMeshToBuffer(compressor->mesh, &compressor->encoderBuffer).ok(); -} - -bool compress_morphed( - DracoCompressor *const compressor -) { - draco::Encoder encoder; - - encoder.SetSpeedOptions(10 - (int)compressor->compressionLevel, 10 - (int)compressor->compressionLevel); - - // For some reason, `EncodeMeshToBuffer` crashes when not disabling prediction or when enabling quantization - // for attributes other position. - encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, compressor->quantization.positions); - encoder.SetAttributePredictionScheme(draco::GeometryAttribute::POSITION, draco::PREDICTION_NONE); - encoder.SetAttributePredictionScheme(draco::GeometryAttribute::NORMAL, draco::PREDICTION_NONE); - encoder.SetAttributePredictionScheme(draco::GeometryAttribute::TEX_COORD, draco::PREDICTION_NONE); - encoder.SetAttributePredictionScheme(draco::GeometryAttribute::GENERIC, draco::PREDICTION_NONE); - - // Enforce triangle order preservation. - encoder.SetEncodingMethod(draco::MESH_SEQUENTIAL_ENCODING); - - return encoder.EncodeMeshToBuffer(compressor->mesh, &compressor->encoderBuffer).ok(); -} - -uint64_t get_compressed_size( - DracoCompressor const *const compressor -) { - return compressor->encoderBuffer.size(); -} - -void copy_to_bytes( - DracoCompressor const *const compressor, - uint8_t *const o_data -) { - memcpy(o_data, compressor->encoderBuffer.data(), compressor->encoderBuffer.size()); -} - -void destroy_compressor( - DracoCompressor *const compressor -) { - delete compressor; -} - -template<class T> -void set_faces_impl( - draco::Mesh &mesh, - int const index_count, - T const *const indices -) { - mesh.SetNumFaces((size_t) index_count / 3); - - for (int i = 0; i < index_count; i += 3) - { - const auto a = draco::PointIndex(indices[i]); - const auto b = draco::PointIndex(indices[i + 1]); - const auto c = draco::PointIndex(indices[i + 2]); - mesh.SetFace(draco::FaceIndex((uint32_t) i), {a, b, c}); - } -} - -void set_faces( - DracoCompressor *const compressor, - uint32_t const index_count, - uint32_t const index_byte_length, - uint8_t const *const indices -) { - switch (index_byte_length) - { - case 1: - { - set_faces_impl(compressor->mesh, index_count, (uint8_t *) indices); - break; - } - case 2: - { - set_faces_impl(compressor->mesh, index_count, (uint16_t *) indices); - break; - } - case 4: - { - set_faces_impl(compressor->mesh, index_count, (uint32_t *) indices); - break; - } - default: - { - printf("%s: Unsupported index size %d\n", logTag, index_byte_length); - break; - } - } -} - -uint32_t add_attribute_to_mesh( - DracoCompressor *const compressor, - draco::GeometryAttribute::Type const semantics, - draco::DataType const data_type, - uint32_t const count, - uint8_t const component_count, - uint8_t const component_size, - uint8_t const *const data -) { - auto buffer = std::make_unique<draco::DataBuffer>(); - - draco::GeometryAttribute attribute; - - attribute.Init( - semantics, - &*buffer, - component_count, - data_type, - false, - component_size * component_count, - 0 - ); - - auto const id = (uint32_t)compressor->mesh.AddAttribute(attribute, true, count); - - for (uint32_t i = 0; i < count; i++) - { - compressor->mesh.attribute(id)->SetAttributeValue( - draco::AttributeValueIndex(i), - data + i * component_count * component_size - ); - } - - compressor->buffers.emplace_back(std::move(buffer)); - - return id; -} - -uint32_t add_positions_f32( - DracoCompressor *const compressor, - uint32_t const count, - uint8_t const *const data -) { - return add_attribute_to_mesh(compressor, draco::GeometryAttribute::POSITION, - draco::DT_FLOAT32, count, 3, sizeof(float), data); -} - -uint32_t add_normals_f32( - DracoCompressor *const compressor, - uint32_t const count, - uint8_t const *const data -) { - return add_attribute_to_mesh(compressor, draco::GeometryAttribute::NORMAL, - draco::DT_FLOAT32, count, 3, sizeof(float), data); -} - -uint32_t add_uvs_f32( - DracoCompressor *const compressor, - uint32_t const count, - uint8_t const *const data -) { - return add_attribute_to_mesh(compressor, draco::GeometryAttribute::TEX_COORD, - draco::DT_FLOAT32, count, 2, sizeof(float), data); -} - -uint32_t add_joints_u16( - DracoCompressor *compressor, - uint32_t const count, - uint8_t const *const data -) { - return add_attribute_to_mesh(compressor, draco::GeometryAttribute::GENERIC, - draco::DT_UINT16, count, 4, sizeof(uint16_t), data); -} - -uint32_t add_weights_f32( - DracoCompressor *compressor, - uint32_t const count, - uint8_t const *const data -) { - return add_attribute_to_mesh(compressor, draco::GeometryAttribute::GENERIC, - draco::DT_FLOAT32, count, 4, sizeof(float), data); -} diff --git a/extern/draco/src/draco-compressor.h b/extern/draco/src/draco-compressor.h deleted file mode 100644 index fb6168a61af..00000000000 --- a/extern/draco/src/draco-compressor.h +++ /dev/null @@ -1,173 +0,0 @@ -/* - * 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. - */ - -/** - * C++ library for the Draco compression feature inside the glTF-Blender-IO project. - * - * The python side uses the CTypes library to open the DLL, load function - * pointers add pass the data to the compressor as raw bytes. - * - * The compressor intercepts the regular glTF exporter after data has been - * gathered and right before the data is converted to a JSON representation, - * which is going to be written out. - * - * The original uncompressed data is removed and replaces an extension, - * pointing to the newly created buffer containing the compressed data. - * - * @author Jim Eckerlein <eckerlein@ux3d.io> - * @date 2019-11-29 - */ - -#include <cstdint> - -#if defined(_MSC_VER) -#define DLL_EXPORT(retType) extern "C" __declspec(dllexport) retType __cdecl -#else -#define DLL_EXPORT(retType) extern "C" retType -#endif - -/** - * This tuple is opaquely exposed to Python through a pointer. - * It encapsulates the complete current compressor state. - * - * A single instance is only intended to compress a single primitive. - */ -struct DracoCompressor; - -DLL_EXPORT(DracoCompressor *) -create_compressor (); - -DLL_EXPORT(void) -set_compression_level ( - DracoCompressor *compressor, - uint32_t compressionLevel -); - -DLL_EXPORT(void) -set_position_quantization ( - DracoCompressor *compressor, - uint32_t quantizationBitsPosition -); - -DLL_EXPORT(void) -set_normal_quantization ( - DracoCompressor *compressor, - uint32_t quantizationBitsNormal -); - -DLL_EXPORT(void) -set_uv_quantization ( - DracoCompressor *compressor, - uint32_t quantizationBitsTexCoord -); - -DLL_EXPORT(void) -set_generic_quantization ( - DracoCompressor *compressor, - uint32_t bits -); - -/// Compresses a mesh. -/// Use `compress_morphed` when compressing primitives which have morph targets. -DLL_EXPORT(bool) -compress ( - DracoCompressor *compressor -); - -/// Compresses the mesh. -/// Use this instead of `compress`, because this procedure takes into account that mesh triangles must not be reordered. -DLL_EXPORT(bool) -compress_morphed ( - DracoCompressor *compressor -); - -/** - * Returns the size of the compressed data in bytes. - */ -DLL_EXPORT(uint64_t) -get_compressed_size ( - DracoCompressor const *compressor -); - -/** - * Copies the compressed mesh into the given byte buffer. - * - * @param[o_data] A Python `bytes` object. - */ -DLL_EXPORT(void) -copy_to_bytes ( - DracoCompressor const *compressor, - uint8_t *o_data -); - -/** - * Releases all memory allocated by the compressor. - */ -DLL_EXPORT(void) -destroy_compressor ( - DracoCompressor *compressor -); - -DLL_EXPORT(void) -set_faces ( - DracoCompressor *compressor, - uint32_t index_count, - uint32_t index_byte_length, - uint8_t const *indices -); - -/// Adds a `float` position attribute to the current mesh. -/// Returns the id Draco has assigned to this attribute. -DLL_EXPORT(uint32_t) -add_positions_f32 ( - DracoCompressor *compressor, - uint32_t count, - uint8_t const *data -); - -/// Adds a `float` normal attribute to the current mesh. -/// Returns the id Draco has assigned to this attribute. -DLL_EXPORT(uint32_t) -add_normals_f32 ( - DracoCompressor *compressor, - uint32_t count, - uint8_t const *data -); - -/// Adds a `float` texture coordinate attribute to the current mesh. -/// Returns the id Draco has assigned to this attribute. -DLL_EXPORT(uint32_t) -add_uvs_f32 ( - DracoCompressor *compressor, - uint32_t count, - uint8_t const *data -); - -/// Adds a `unsigned short` joint attribute to the current mesh. -/// Returns the id Draco has assigned to this attribute. -DLL_EXPORT(uint32_t) -add_joints_u16 ( - DracoCompressor *compressor, - uint32_t count, - uint8_t const *data -); - -/// Adds a `float` weight attribute to the current mesh. -/// Returns the id Draco has assigned to this attribute. -DLL_EXPORT(uint32_t) -add_weights_f32 ( - DracoCompressor *compressor, - uint32_t count, - uint8_t const *data -); diff --git a/extern/draco/src/encoder.cpp b/extern/draco/src/encoder.cpp new file mode 100644 index 00000000000..ff7570ecfcd --- /dev/null +++ b/extern/draco/src/encoder.cpp @@ -0,0 +1,247 @@ +/* + * 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. + */ + +/** + * @author Jim Eckerlein <eckerlein@ux3d.io> + * @date 2019-11-18 + */ + +#include "encoder.h" + +#include <memory> +#include <vector> + +#include "draco/mesh/mesh.h" +#include "draco/core/encoder_buffer.h" +#include "draco/compression/encode.h" + +#define LOG_PREFIX "DracoEncoder | " + +struct Encoder +{ + draco::Mesh mesh; + uint32_t encodedVertices; + uint32_t encodedIndices; + std::vector<std::unique_ptr<draco::DataBuffer>> buffers; + draco::EncoderBuffer encoderBuffer; + uint32_t compressionLevel = 7; + size_t rawSize = 0; + struct + { + uint32_t position = 14; + uint32_t normal = 10; + uint32_t uv = 12; + uint32_t color = 10; + uint32_t generic = 12; + } quantization; +}; + +Encoder *encoderCreate(uint32_t vertexCount) +{ + Encoder *encoder = new Encoder; + encoder->mesh.set_num_points(vertexCount); + return encoder; +} + +void encoderRelease(Encoder *encoder) +{ + delete encoder; +} + +void encoderSetCompressionLevel(Encoder *encoder, uint32_t compressionLevel) { + encoder->compressionLevel = compressionLevel; +} + +void encoderSetQuantizationBits(Encoder *encoder, uint32_t position, uint32_t normal, uint32_t uv, uint32_t color, uint32_t generic) +{ + encoder->quantization.position = position; + encoder->quantization.normal = normal; + encoder->quantization.uv = uv; + encoder->quantization.color = color; + encoder->quantization.generic = generic; +} + +bool encoderEncode(Encoder *encoder, uint8_t preserveTriangleOrder) +{ + printf(LOG_PREFIX "Preserve triangle order: %s\n", preserveTriangleOrder ? "yes" : "no"); + + draco::Encoder dracoEncoder; + + int speed = 10 - static_cast<int>(encoder->compressionLevel); + dracoEncoder.SetSpeedOptions(speed, speed); + + dracoEncoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, encoder->quantization.position); + dracoEncoder.SetAttributeQuantization(draco::GeometryAttribute::NORMAL, encoder->quantization.normal); + dracoEncoder.SetAttributeQuantization(draco::GeometryAttribute::TEX_COORD, encoder->quantization.uv); + dracoEncoder.SetAttributeQuantization(draco::GeometryAttribute::COLOR, encoder->quantization.color); + dracoEncoder.SetAttributeQuantization(draco::GeometryAttribute::GENERIC, encoder->quantization.generic); + dracoEncoder.SetTrackEncodedProperties(true); + + if (preserveTriangleOrder) + { + dracoEncoder.SetEncodingMethod(draco::MESH_SEQUENTIAL_ENCODING); + } + + auto encoderStatus = dracoEncoder.EncodeMeshToBuffer(encoder->mesh, &encoder->encoderBuffer); + if (encoderStatus.ok()) + { + encoder->encodedVertices = static_cast<uint32_t>(dracoEncoder.num_encoded_points()); + encoder->encodedIndices = static_cast<uint32_t>(dracoEncoder.num_encoded_faces() * 3); + size_t encodedSize = encoder->encoderBuffer.size(); + float compressionRatio = static_cast<float>(encoder->rawSize) / static_cast<float>(encodedSize); + printf(LOG_PREFIX "Encoded %" PRIu32 " vertices, %" PRIu32 " indices, raw size: %zu, encoded size: %zu, compression ratio: %.2f\n", encoder->encodedVertices, encoder->encodedIndices, encoder->rawSize, encodedSize, compressionRatio); + return true; + } + else + { + printf(LOG_PREFIX "Error during Draco encoding: %s\n", encoderStatus.error_msg()); + return false; + } +} + +uint32_t encoderGetEncodedVertexCount(Encoder *encoder) +{ + return encoder->encodedVertices; +} + +uint32_t encoderGetEncodedIndexCount(Encoder *encoder) +{ + return encoder->encodedIndices; +} + +uint64_t encoderGetByteLength(Encoder *encoder) +{ + return encoder->encoderBuffer.size(); +} + +void encoderCopy(Encoder *encoder, uint8_t *data) +{ + memcpy(data, encoder->encoderBuffer.data(), encoder->encoderBuffer.size()); +} + +template<class T> +void encodeIndices(Encoder *encoder, uint32_t indexCount, T *indices) +{ + int face_count = indexCount / 3; + encoder->mesh.SetNumFaces(static_cast<size_t>(face_count)); + encoder->rawSize += indexCount * sizeof(T); + + for (int i = 0; i < face_count; ++i) + { + draco::Mesh::Face face = { + draco::PointIndex(indices[3 * i + 0]), + draco::PointIndex(indices[3 * i + 1]), + draco::PointIndex(indices[3 * i + 2]) + }; + encoder->mesh.SetFace(draco::FaceIndex(static_cast<uint32_t>(i)), face); + } +} + +void encoderSetIndices(Encoder *encoder, size_t indexComponentType, uint32_t indexCount, void *indices) +{ + switch (indexComponentType) + { + case ComponentType::Byte: + encodeIndices(encoder, indexCount, reinterpret_cast<int8_t *>(indices)); + break; + case ComponentType::UnsignedByte: + encodeIndices(encoder, indexCount, reinterpret_cast<uint8_t *>(indices)); + break; + case ComponentType::Short: + encodeIndices(encoder, indexCount, reinterpret_cast<int16_t *>(indices)); + break; + case ComponentType::UnsignedShort: + encodeIndices(encoder, indexCount, reinterpret_cast<uint16_t *>(indices)); + break; + case ComponentType::UnsignedInt: + encodeIndices(encoder, indexCount, reinterpret_cast<uint32_t *>(indices)); + break; + default: + printf(LOG_PREFIX "Index component type %zu not supported\n", indexComponentType); + } +} + +draco::GeometryAttribute::Type getAttributeSemantics(char *attribute) +{ + if (!strcmp(attribute, "POSITION")) + { + return draco::GeometryAttribute::POSITION; + } + if (!strcmp(attribute, "NORMAL")) + { + return draco::GeometryAttribute::NORMAL; + } + if (!strncmp(attribute, "TEXCOORD", strlen("TEXCOORD"))) + { + return draco::GeometryAttribute::TEX_COORD; + } + if (!strncmp(attribute, "COLOR", strlen("COLOR"))) + { + return draco::GeometryAttribute::COLOR; + } + + return draco::GeometryAttribute::GENERIC; +} + +draco::DataType getDataType(size_t componentType) +{ + switch (componentType) + { + case ComponentType::Byte: + return draco::DataType::DT_INT8; + + case ComponentType::UnsignedByte: + return draco::DataType::DT_UINT8; + + case ComponentType::Short: + return draco::DataType::DT_INT16; + + case ComponentType::UnsignedShort: + return draco::DataType::DT_UINT16; + + case ComponentType::UnsignedInt: + return draco::DataType::DT_UINT32; + + case ComponentType::Float: + return draco::DataType::DT_FLOAT32; + + default: + return draco::DataType::DT_INVALID; + } +} + +API(uint32_t) encoderSetAttribute(Encoder *encoder, char *attributeName, size_t componentType, char *dataType, void *data) +{ + auto buffer = std::make_unique<draco::DataBuffer>(); + uint32_t count = encoder->mesh.num_points(); + size_t componentCount = getNumberOfComponents(dataType); + size_t stride = getAttributeStride(componentType, dataType); + draco::DataType dracoDataType = getDataType(componentType); + + draco::GeometryAttribute::Type semantics = getAttributeSemantics(attributeName); + draco::GeometryAttribute attribute; + attribute.Init(semantics, &*buffer, componentCount, getDataType(componentType), false, stride, 0); + + auto id = static_cast<uint32_t>(encoder->mesh.AddAttribute(attribute, true, count)); + auto dataBytes = reinterpret_cast<uint8_t *>(data); + + for (uint32_t i = 0; i < count; i++) + { + encoder->mesh.attribute(id)->SetAttributeValue(draco::AttributeValueIndex(i), dataBytes + i * stride); + } + + encoder->buffers.emplace_back(std::move(buffer)); + encoder->rawSize += count * stride; + return id; +} diff --git a/extern/draco/src/encoder.h b/extern/draco/src/encoder.h new file mode 100644 index 00000000000..2f7f21a469b --- /dev/null +++ b/extern/draco/src/encoder.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +/** + * Library for the Draco encoding/decoding feature inside the glTF-Blender-IO project. + * + * The python script within glTF-Blender-IO uses the CTypes library to open the DLL, + * load function pointers add pass the raw data to the encoder. + * + * @author Jim Eckerlein <eckerlein@ux3d.io> + * @date 2020-11-18 + */ + +#pragma once + +#include "common.h" + +struct Encoder; + +API(Encoder *) encoderCreate(uint32_t vertexCount); + +API(void) encoderRelease(Encoder *encoder); + +API(void) encoderSetCompressionLevel(Encoder *encoder, uint32_t compressionLevel); + +API(void) encoderSetQuantizationBits(Encoder *encoder, uint32_t position, uint32_t normal, uint32_t uv, uint32_t color, uint32_t generic); + +API(bool) encoderEncode(Encoder *encoder, uint8_t preserveTriangleOrder); + +API(uint64_t) encoderGetByteLength(Encoder *encoder); + +API(void) encoderCopy(Encoder *encoder, uint8_t *data); + +API(void) encoderSetIndices(Encoder *encoder, size_t indexComponentType, uint32_t indexCount, void *indices); + +API(uint32_t) encoderSetAttribute(Encoder *encoder, char *attributeName, size_t componentType, char *dataType, void *data); + +API(uint32_t) encoderGetEncodedVertexCount(Encoder *encoder); + +API(uint32_t) encoderGetEncodedIndexCount(Encoder *encoder); |