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

geometry_metadata.h « metadata « draco « src « draco « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec7ecb9ee68c9f1a4f172b5fb2ad76310115cc7c (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
// 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_METADATA_GEOMETRY_METADATA_H_
#define DRACO_METADATA_GEOMETRY_METADATA_H_

#include "draco/metadata/metadata.h"

namespace draco {

// Class for representing specifically metadata of attributes. It must have an
// attribute id which should be identical to it's counterpart attribute in
// the point cloud it belongs to.
class AttributeMetadata : public Metadata {
 public:
  AttributeMetadata() : att_unique_id_(0) {}
  explicit AttributeMetadata(const Metadata &metadata)
      : Metadata(metadata), att_unique_id_(0) {}

  void set_att_unique_id(uint32_t att_unique_id) {
    att_unique_id_ = att_unique_id;
  }
  // The unique id of the attribute that this metadata belongs to.
  uint32_t att_unique_id() const { return att_unique_id_; }

 private:
  uint32_t att_unique_id_;

  friend struct AttributeMetadataHasher;
  friend class PointCloud;
};

// Functor for computing a hash from data stored in a AttributeMetadata class.
struct AttributeMetadataHasher {
  size_t operator()(const AttributeMetadata &metadata) const {
    size_t hash = metadata.att_unique_id_;
    MetadataHasher metadata_hasher;
    hash = HashCombine(metadata_hasher(static_cast<const Metadata &>(metadata)),
                       hash);
    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() {}
  explicit GeometryMetadata(const Metadata &metadata) : Metadata(metadata) {}

  const AttributeMetadata *GetAttributeMetadataByStringEntry(
      const std::string &entry_name, const std::string &entry_value) const;
  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() == static_cast<uint32_t>(att_unique_id)) {
        att_metadatas_.erase(itr);
        return;
      }
    }
  }

  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() ==
          static_cast<uint32_t>(att_unique_id)) {
        return att_metadata.get();
      }
    }
    return nullptr;
  }

  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() ==
          static_cast<uint32_t>(att_unique_id)) {
        return att_metadata.get();
      }
    }
    return nullptr;
  }

  const std::vector<std::unique_ptr<AttributeMetadata>> &attribute_metadatas()
      const {
    return att_metadatas_;
  }

 private:
  std::vector<std::unique_ptr<AttributeMetadata>> att_metadatas_;

  friend struct GeometryMetadataHasher;
};

// Functor for computing a hash from data stored in a GeometryMetadata class.
struct GeometryMetadataHasher {
  size_t operator()(const GeometryMetadata &metadata) const {
    size_t hash = metadata.att_metadatas_.size();
    AttributeMetadataHasher att_metadata_hasher;
    for (auto &&att_metadata : metadata.att_metadatas_) {
      hash = HashCombine(att_metadata_hasher(*att_metadata), hash);
    }
    MetadataHasher metadata_hasher;
    hash = HashCombine(metadata_hasher(static_cast<const Metadata &>(metadata)),
                       hash);
    return hash;
  }
};

}  // namespace draco

#endif  // THIRD_PARTY_DRACO_METADATA_GEOMETRY_METADATA_H_