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

point_cloud_sequential_encoding_test.cc « point_cloud « compression « draco « src « dracoenc « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: beab4bcd7e932ee9e0c4994ec05965211322b28d (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
// 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