Coverage Report

Created: 2024-09-08 06:47

/src/draco/src/draco/compression/attributes/sequential_normal_attribute_decoder.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2016 The Draco Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
#include "draco/compression/attributes/sequential_normal_attribute_decoder.h"
16
17
#include "draco/compression/attributes/normal_compression_utils.h"
18
19
namespace draco {
20
21
254
SequentialNormalAttributeDecoder::SequentialNormalAttributeDecoder() {}
22
23
bool SequentialNormalAttributeDecoder::Init(PointCloudDecoder *decoder,
24
254
                                            int attribute_id) {
25
254
  if (!SequentialIntegerAttributeDecoder::Init(decoder, attribute_id)) {
26
0
    return false;
27
0
  }
28
  // Currently, this encoder works only for 3-component normal vectors.
29
254
  if (attribute()->num_components() != 3) {
30
2
    return false;
31
2
  }
32
  // Also the data type must be DT_FLOAT32.
33
252
  if (attribute()->data_type() != DT_FLOAT32) {
34
0
    return false;
35
0
  }
36
252
  return true;
37
252
}
38
39
bool SequentialNormalAttributeDecoder::DecodeIntegerValues(
40
31
    const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) {
41
31
#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
42
31
  if (decoder()->bitstream_version() < DRACO_BITSTREAM_VERSION(2, 0)) {
43
    // Note: in older bitstreams, we do not have a PortableAttribute() decoded
44
    // at this stage so we cannot pass it down to the DecodeParameters() call.
45
    // It still works fine for octahedral transform because it does not need to
46
    // use any data from the attribute.
47
0
    if (!octahedral_transform_.DecodeParameters(*attribute(), in_buffer)) {
48
0
      return false;
49
0
    }
50
0
  }
51
31
#endif
52
31
  return SequentialIntegerAttributeDecoder::DecodeIntegerValues(point_ids,
53
31
                                                                in_buffer);
54
31
}
55
56
bool SequentialNormalAttributeDecoder::DecodeDataNeededByPortableTransform(
57
19
    const std::vector<PointIndex> &point_ids, DecoderBuffer *in_buffer) {
58
19
  if (decoder()->bitstream_version() >= DRACO_BITSTREAM_VERSION(2, 0)) {
59
    // For newer file version, decode attribute transform data here.
60
19
    if (!octahedral_transform_.DecodeParameters(*GetPortableAttribute(),
61
19
                                                in_buffer)) {
62
0
      return false;
63
0
    }
64
19
  }
65
66
  // Store the decoded transform data in portable attribute.
67
19
  return octahedral_transform_.TransferToAttribute(portable_attribute());
68
19
}
69
70
19
bool SequentialNormalAttributeDecoder::StoreValues(uint32_t num_points) {
71
  // Convert all quantized values back to floats.
72
19
  return octahedral_transform_.InverseTransformAttribute(
73
19
      *GetPortableAttribute(), attribute());
74
19
}
75
76
}  // namespace draco