Welcome to mirror list, hosted at ThFree Co, Russian Federation.

decode_test.cc « compression « draco « src « dracoenc « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c57542069dd9fade630783e0a48a0016549b4202 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// 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