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

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