GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
point_cloud.h
Go to the documentation of this file.
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#ifndef DRACO_POINT_CLOUD_POINT_CLOUD_H_
16#define DRACO_POINT_CLOUD_POINT_CLOUD_H_
17
20#include "draco/core/vector_d.h"
23
24namespace draco {
25
26// PointCloud is a collection of n-dimensional points that are described by a
27// set of PointAttributes that can represent data such as positions or colors
28// of individual points (see point_attribute.h).
30 public:
31 PointCloud();
32 virtual ~PointCloud() = default;
33
34#ifdef DRACO_TRANSCODER_SUPPORTED
35 // Copies all data from the |src| point cloud.
36 void Copy(const PointCloud &src);
37#endif
38
39 // Returns the number of named attributes of a given type.
41
42 // Returns attribute id of the first named attribute with a given type or -1
43 // when the attribute is not used by the point cloud.
45
46 // Returns the id of the i-th named attribute of a given type.
47 int32_t GetNamedAttributeId(GeometryAttribute::Type type, int i) const;
48
49 // Returns the first named attribute of a given type or nullptr if the
50 // attribute is not used by the point cloud.
52
53 // Returns the i-th named attribute of a given type.
55 int i) const;
56
57 // Returns the named attribute of a given unique id.
59 GeometryAttribute::Type type, uint32_t id) const;
60
61 // Returns the attribute of a given unique id.
62 const PointAttribute *GetAttributeByUniqueId(uint32_t id) const;
63 int32_t GetAttributeIdByUniqueId(uint32_t unique_id) const;
64
65 int32_t num_attributes() const {
66 return static_cast<int32_t>(attributes_.size());
67 }
68 const PointAttribute *attribute(int32_t att_id) const {
69 DRACO_DCHECK_LE(0, att_id);
70 DRACO_DCHECK_LT(att_id, static_cast<int32_t>(attributes_.size()));
71 return attributes_[att_id].get();
72 }
73
74 // Returned attribute can be modified, but it's caller's responsibility to
75 // maintain the attribute's consistency with draco::PointCloud.
76 PointAttribute *attribute(int32_t att_id) {
77 DRACO_DCHECK_LE(0, att_id);
78 DRACO_DCHECK_LT(att_id, static_cast<int32_t>(attributes_.size()));
79 return attributes_[att_id].get();
80 }
81
82 // Adds a new attribute to the point cloud.
83 // Returns the attribute id.
84 int AddAttribute(std::unique_ptr<PointAttribute> pa);
85
86 // Creates and adds a new attribute to the point cloud. The attribute has
87 // properties derived from the provided GeometryAttribute |att|.
88 // If |identity_mapping| is set to true, the attribute will use identity
89 // mapping between point indices and attribute value indices (i.e., each
90 // point has a unique attribute value). If |identity_mapping| is false, the
91 // mapping between point indices and attribute value indices is set to
92 // explicit, and it needs to be initialized manually using the
93 // PointAttribute::SetPointMapEntry() method. |num_attribute_values| can be
94 // used to specify the number of attribute values that are going to be
95 // stored in the newly created attribute. Returns attribute id of the newly
96 // created attribute or -1 in case of failure.
97 int AddAttribute(const GeometryAttribute &att, bool identity_mapping,
98 AttributeValueIndex::ValueType num_attribute_values);
99
100 // Creates and returns a new attribute or nullptr in case of failure. This
101 // method is similar to AddAttribute(), except that it returns the new
102 // attribute instead of adding it to the point cloud.
103 std::unique_ptr<PointAttribute> CreateAttribute(
104 const GeometryAttribute &att, bool identity_mapping,
105 AttributeValueIndex::ValueType num_attribute_values) const;
106
107 // Assigns an attribute id to a given PointAttribute. If an attribute with
108 // the same attribute id already exists, it is deleted.
109 virtual void SetAttribute(int att_id, std::unique_ptr<PointAttribute> pa);
110
111 // Deletes an attribute with specified attribute id. Note that this changes
112 // attribute ids of all subsequent attributes.
113 virtual void DeleteAttribute(int att_id);
114
115#ifdef DRACO_ATTRIBUTE_VALUES_DEDUPLICATION_SUPPORTED
116 // Deduplicates all attribute values (all attribute entries with the same
117 // value are merged into a single entry).
118 virtual bool DeduplicateAttributeValues();
119#endif
120
121#ifdef DRACO_ATTRIBUTE_INDICES_DEDUPLICATION_SUPPORTED
122 // Removes duplicate point ids (two point ids are duplicate when all of their
123 // attributes are mapped to the same entry ids).
124 virtual void DeduplicatePointIds();
125#endif
126
127 // Get bounding box.
129
130 // Add metadata.
131 void AddMetadata(std::unique_ptr<GeometryMetadata> metadata) {
132 metadata_ = std::move(metadata);
133 }
134
135 // Add metadata for an attribute.
136 void AddAttributeMetadata(int32_t att_id,
137 std::unique_ptr<AttributeMetadata> metadata) {
138 if (!metadata_) {
139 metadata_ = std::unique_ptr<GeometryMetadata>(new GeometryMetadata());
140 }
141 const int32_t att_unique_id = attribute(att_id)->unique_id();
142 metadata->set_att_unique_id(att_unique_id);
143 metadata_->AddAttributeMetadata(std::move(metadata));
144 }
145
147 int32_t att_id) const {
148 if (metadata_ == nullptr) {
149 return nullptr;
150 }
151 const uint32_t unique_id = attribute(att_id)->unique_id();
152 return metadata_->GetAttributeMetadataByUniqueId(unique_id);
153 }
154
155 // Returns the attribute metadata that has the requested metadata entry.
157 const std::string &name, const std::string &value) const {
158 if (metadata_ == nullptr) {
159 return nullptr;
160 }
161 return metadata_->GetAttributeMetadataByStringEntry(name, value);
162 }
163
164 // Returns the first attribute that has the requested metadata entry.
165 int GetAttributeIdByMetadataEntry(const std::string &name,
166 const std::string &value) const {
167 if (metadata_ == nullptr) {
168 return -1;
169 }
170 const AttributeMetadata *att_metadata =
171 metadata_->GetAttributeMetadataByStringEntry(name, value);
172 if (!att_metadata) {
173 return -1;
174 }
175 return GetAttributeIdByUniqueId(att_metadata->att_unique_id());
176 }
177
178 // Get a const pointer of the metadata of the point cloud.
179 const GeometryMetadata *GetMetadata() const { return metadata_.get(); }
180
181 // Get a pointer to the metadata of the point cloud.
182 GeometryMetadata *metadata() { return metadata_.get(); }
183
184 // Returns the number of n-dimensional points stored within the point cloud.
185 PointIndex::ValueType num_points() const { return num_points_; }
186
187 // Sets the number of points. It's the caller's responsibility to ensure the
188 // new number is valid with respect to the PointAttributes stored in the point
189 // cloud.
190 void set_num_points(PointIndex::ValueType num) { num_points_ = num; }
191
192 protected:
193#ifdef DRACO_TRANSCODER_SUPPORTED
194 // Copies metadata from the |src| point cloud.
195 void CopyMetadata(const PointCloud &src);
196#endif
197
198#ifdef DRACO_ATTRIBUTE_INDICES_DEDUPLICATION_SUPPORTED
199 // Applies id mapping of deduplicated points (called by DeduplicatePointIds).
200 virtual void ApplyPointIdDeduplication(
202 const std::vector<PointIndex> &unique_point_ids);
203#endif
204
205 private:
206 // Metadata for the point cloud.
207 std::unique_ptr<GeometryMetadata> metadata_;
208
209 // Attributes describing the point cloud.
210 std::vector<std::unique_ptr<PointAttribute>> attributes_;
211
212 // Ids of named attributes of the given type.
213 std::vector<int32_t>
214 named_attribute_index_[GeometryAttribute::NAMED_ATTRIBUTES_COUNT];
215
216 // The number of n-dimensional points. All point attribute values are stored
217 // in corresponding PointAttribute instances in the |attributes_| array.
218 PointIndex::ValueType num_points_;
219
220 friend struct PointCloudHasher;
221};
222
223// Functor for computing a hash from data stored within a point cloud.
224// Note that this can be quite slow. Two point clouds will have the same hash
225// only when all points have the same order and when all attribute values are
226// exactly the same.
228 size_t operator()(const PointCloud &pc) const {
229 size_t hash = pc.num_points_;
230 hash = HashCombine(pc.attributes_.size(), hash);
231 for (int i = 0; i < GeometryAttribute::NAMED_ATTRIBUTES_COUNT; ++i) {
232 hash = HashCombine(pc.named_attribute_index_[i].size(), hash);
233 for (int j = 0; j < static_cast<int>(pc.named_attribute_index_[i].size());
234 ++j) {
235 hash = HashCombine(pc.named_attribute_index_[i][j], hash);
236 }
237 }
238 // Hash attributes.
239 for (int i = 0; i < static_cast<int>(pc.attributes_.size()); ++i) {
240 PointAttributeHasher att_hasher;
241 hash = HashCombine(att_hasher(*pc.attributes_[i]), hash);
242 }
243 // Hash metadata.
244 GeometryMetadataHasher metadata_hasher;
245 if (pc.metadata_) {
246 hash = HashCombine(metadata_hasher(*pc.metadata_), hash);
247 }
248 return hash;
249 }
250};
251
252} // namespace draco
253
254#endif // DRACO_POINT_CLOUD_POINT_CLOUD_H_
std::string unique_id()
Definition GameApi_shm.cc:50
Definition geometry_metadata.h:25
uint32_t att_unique_id() const
Definition geometry_metadata.h:36
Definition bounding_box.h:23
Definition geometry_attribute.h:43
uint32_t unique_id() const
Definition geometry_attribute.h:277
Type
Definition geometry_attribute.h:46
@ NAMED_ATTRIBUTES_COUNT
Definition geometry_attribute.h:72
Definition geometry_metadata.h:58
Definition draco_index_type_vector.h:32
Definition point_attribute.h:33
Definition point_cloud.h:29
PointIndex::ValueType num_points() const
Definition point_cloud.h:185
const AttributeMetadata * GetAttributeMetadataByStringEntry(const std::string &name, const std::string &value) const
Definition point_cloud.h:156
std::unique_ptr< PointAttribute > CreateAttribute(const GeometryAttribute &att, bool identity_mapping, AttributeValueIndex::ValueType num_attribute_values) const
Definition point_cloud.cc:134
int32_t num_attributes() const
Definition point_cloud.h:65
int AddAttribute(std::unique_ptr< PointAttribute > pa)
Definition point_cloud.cc:118
const PointAttribute * GetAttributeByUniqueId(uint32_t id) const
Definition point_cloud.cc:100
void AddMetadata(std::unique_ptr< GeometryMetadata > metadata)
Definition point_cloud.h:131
virtual void SetAttribute(int att_id, std::unique_ptr< PointAttribute > pa)
Definition point_cloud.cc:156
PointAttribute * attribute(int32_t att_id)
Definition point_cloud.h:76
void AddAttributeMetadata(int32_t att_id, std::unique_ptr< AttributeMetadata > metadata)
Definition point_cloud.h:136
virtual ~PointCloud()=default
virtual void DeleteAttribute(int att_id)
Definition point_cloud.cc:168
int32_t GetAttributeIdByUniqueId(uint32_t unique_id) const
Definition point_cloud.cc:109
const PointAttribute * attribute(int32_t att_id) const
Definition point_cloud.h:68
void set_num_points(PointIndex::ValueType num)
Definition point_cloud.h:190
PointCloud()
Definition point_cloud.cc:27
int GetAttributeIdByMetadataEntry(const std::string &name, const std::string &value) const
Definition point_cloud.h:165
const PointAttribute * GetNamedAttributeByUniqueId(GeometryAttribute::Type type, uint32_t id) const
Definition point_cloud.cc:88
const PointAttribute * GetNamedAttribute(GeometryAttribute::Type type) const
Definition point_cloud.cc:74
friend struct PointCloudHasher
Definition point_cloud.h:220
int32_t NumNamedAttributes(GeometryAttribute::Type type) const
Definition point_cloud.cc:54
const GeometryMetadata * GetMetadata() const
Definition point_cloud.h:179
BoundingBox ComputeBoundingBox() const
Definition point_cloud.cc:287
const AttributeMetadata * GetAttributeMetadataByAttributeId(int32_t att_id) const
Definition point_cloud.h:146
GeometryMetadata * metadata()
Definition point_cloud.h:182
int32_t GetNamedAttributeId(GeometryAttribute::Type type) const
Definition point_cloud.cc:62
#define DRACO_DCHECK_LT(a, b)
Definition macros.h:86
#define DRACO_DCHECK_LE(a, b)
Definition macros.h:85
iVBORw0KGgoAAAANSUhEUgAAANcAAAB5CAMAAACdtUQZAAAA51BMVEX</div ></div >< div style="padding: 0px 0px; width: 1324px;">< div style="height: 400px; width: 1324px;"></div >< div itemscope itemtype="https: </div><div itemscope itemtype="https:</div >< div itemscope itemtype="https: </div></div><p><div style="padding:0px 0px;width:1324px;"><div></div><div itemscope itemtype="https:< ul >< li >< b > Application name
8AkrcAgqgAs9wqQ0ey2tkAo8gAuuQfeI4hPUH09fXHy8z4+fng4uNKXF/Lz9BzfoAcgpkQMTUAKjAbOT4Qr9AXhJ8Rl7ktMCwTosA...
Definition meshpage.php:1610
tag src
Definition meshpage.php:1786
Definition attribute_octahedron_transform.cc:21
size_t HashCombine(T1 a, T2 b)
Definition hash_utils.h:26
Definition geometry_metadata.h:126
Definition point_attribute.h:171
Definition point_cloud.h:227
size_t operator()(const PointCloud &pc) const
Definition point_cloud.h:228
num
Definition view.php:2821