GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
point_cloud_builder.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_BUILDER_H_
16#define DRACO_POINT_CLOUD_POINT_CLOUD_BUILDER_H_
17
18#include <utility>
19
21
22namespace draco {
23
24// A helper class for constructing PointCloud instances from other data sources.
25// Usage:
26// PointCloudBuilder builder;
27// // Initialize the builder for a given number of points (required).
28// builder.Start(num_points);
29// // Specify desired attributes.
30// int pos_att_id =
31// builder.AddAttribute(GeometryAttribute::POSITION, 3, DT_FLOAT32);
32// // Add attribute values.
33// for (PointIndex i(0); i < num_points; ++i) {
34// builder.SetAttributeValueForPoint(pos_att_id, i, input_pos[i.value()]);
35// }
36// // Get the final PointCloud.
37// constexpr bool deduplicate_points = false;
38// std::unique_ptr<PointCloud> pc = builder.Finalize(deduplicate_points);
39
41 public:
42 // Index type of the inserted element.
44
46
47 // Starts collecting point cloud data.
48 // The behavior of other functions is undefined before this method is called.
49 void Start(PointIndex::ValueType num_points);
50
51 int AddAttribute(GeometryAttribute::Type attribute_type,
52 int8_t num_components, DataType data_type);
53
54 // Sets attribute value for a specific point.
55 // |attribute_value| must contain data in the format specified by the
56 // AddAttribute method.
57 void SetAttributeValueForPoint(int att_id, PointIndex point_index,
58 const void *attribute_value);
59
60 // Sets attribute values for all points. All the values must be stored in the
61 // input |attribute_values| buffer. |stride| can be used to define the byte
62 // offset between two consecutive attribute values. If |stride| is set to 0,
63 // the stride is automatically computed based on the format of the given
64 // attribute.
65 void SetAttributeValuesForAllPoints(int att_id, const void *attribute_values,
66 int stride);
67
68 // Finalizes the PointCloud or returns nullptr on error.
69 // If |deduplicate_points| is set to true, the following happens:
70 // 1. Attribute values with duplicate entries are deduplicated.
71 // 2. Point ids that are mapped to the same attribute values are
72 // deduplicated.
73 // Therefore, if |deduplicate_points| is true the final PointCloud can have
74 // a different number of point from the value specified in the Start method.
75 // Once this function is called, the builder becomes invalid and cannot be
76 // used until the method Start() is called again.
77 std::unique_ptr<PointCloud> Finalize(bool deduplicate_points);
78
79 // Add metadata for an attribute.
80 void AddAttributeMetadata(int32_t att_id,
81 std::unique_ptr<AttributeMetadata> metadata) {
82 point_cloud_->AddAttributeMetadata(att_id, std::move(metadata));
83 }
84
85 private:
86 std::unique_ptr<PointCloud> point_cloud_;
87};
88
89} // namespace draco
90
91#endif // DRACO_POINT_CLOUD_POINT_CLOUD_BUILDER_H_
Type
Definition geometry_attribute.h:46
PointIndex ElementIndex
Definition point_cloud_builder.h:43
PointCloudBuilder()
Definition point_cloud_builder.cc:21
int AddAttribute(GeometryAttribute::Type attribute_type, int8_t num_components, DataType data_type)
Definition point_cloud_builder.cc:28
void Start(PointIndex::ValueType num_points)
Definition point_cloud_builder.cc:23
void SetAttributeValuesForAllPoints(int att_id, const void *attribute_values, int stride)
Definition point_cloud_builder.cc:43
std::unique_ptr< PointCloud > Finalize(bool deduplicate_points)
Definition point_cloud_builder.cc:65
void AddAttributeMetadata(int32_t att_id, std::unique_ptr< AttributeMetadata > metadata)
Definition point_cloud_builder.h:80
void SetAttributeValueForPoint(int att_id, PointIndex point_index, const void *attribute_value)
Definition point_cloud_builder.cc:36
Definition attribute_octahedron_transform.cc:21
DataType
Definition draco_types.h:26
Definition GameApi_pl.cc:29382