GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
expert_encode.h
Go to the documentation of this file.
1// Copyright 2017 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_COMPRESSION_EXPERT_ENCODE_H_
16#define DRACO_COMPRESSION_EXPERT_ENCODE_H_
17
22#include "draco/core/status.h"
23#include "draco/mesh/mesh.h"
24
25namespace draco {
26
27// Advanced helper class for encoding geometry using the Draco compression
28// library. Unlike the basic Encoder (encode.h), this class allows users to
29// specify options for each attribute individually using provided attribute ids.
30// The drawback of this encoder is that it can be used to encode only one model
31// at a time, and for each new model the options need to be set again,
32class ExpertEncoder : public EncoderBase<EncoderOptions> {
33 public:
36
37 explicit ExpertEncoder(const PointCloud &point_cloud);
38 explicit ExpertEncoder(const Mesh &mesh);
39
40 // Encodes the geometry provided in the constructor to the target buffer.
42
43 // Set encoder options used during the geometry encoding. Note that this call
44 // overwrites any modifications to the options done with the functions below.
45 void Reset(const EncoderOptions &options);
46 void Reset();
47
48 // Sets the desired encoding and decoding speed for the given options.
49 //
50 // 0 = slowest speed, but the best compression.
51 // 10 = fastest, but the worst compression.
52 // -1 = undefined.
53 //
54 // Note that both speed options affect the encoder choice of used methods and
55 // algorithms. For example, a requirement for fast decoding may prevent the
56 // encoder from using the best compression methods even if the encoding speed
57 // is set to 0. In general, the faster of the two options limits the choice of
58 // features that can be used by the encoder. Additionally, setting
59 // |decoding_speed| to be faster than the |encoding_speed| may allow the
60 // encoder to choose the optimal method out of the available features for the
61 // given |decoding_speed|.
62 void SetSpeedOptions(int encoding_speed, int decoding_speed);
63
64 // Sets the quantization compression options for a specific attribute. The
65 // attribute values will be quantized in a box defined by the maximum extent
66 // of the attribute values. I.e., the actual precision of this option depends
67 // on the scale of the attribute values.
68 void SetAttributeQuantization(int32_t attribute_id, int quantization_bits);
69
70 // Sets the explicit quantization compression for a named attribute. The
71 // attribute values will be quantized in a coordinate system defined by the
72 // provided origin and range (the input values should be within interval:
73 // <origin, origin + range>).
74 void SetAttributeExplicitQuantization(int32_t attribute_id,
75 int quantization_bits, int num_dims,
76 const float *origin, float range);
77
78 // Enables/disables built in entropy coding of attribute values. Disabling
79 // this option may be useful to improve the performance when third party
80 // compression is used on top of the Draco compression. Default: [true].
81 void SetUseBuiltInAttributeCompression(bool enabled);
82
83 // Sets the desired encoding method for a given geometry. By default, encoding
84 // method is selected based on the properties of the input geometry and based
85 // on the other options selected in the used EncoderOptions (such as desired
86 // encoding and decoding speed). This function should be called only when a
87 // specific method is required.
88 //
89 // |encoding_method| can be one of the values defined in
90 // compression/config/compression_shared.h based on the type of the input
91 // geometry that is going to be encoded. For point clouds, allowed entries are
92 // POINT_CLOUD_SEQUENTIAL_ENCODING
93 // POINT_CLOUD_KD_TREE_ENCODING
94 //
95 // For meshes the input can be
96 // MESH_SEQUENTIAL_ENCODING
97 // MESH_EDGEBREAKER_ENCODING
98 //
99 // If the selected method cannot be used for the given input, the subsequent
100 // call of EncodePointCloudToBuffer or EncodeMeshToBuffer is going to fail.
101 void SetEncodingMethod(int encoding_method);
102
103 // Sets the desired encoding submethod, only for MESH_EDGEBREAKER_ENCODING.
104 // Valid values for |encoding_submethod| are:
105 // MESH_EDGEBREAKER_STANDARD_ENCODING
106 // MESH_EDGEBREAKER_VALENCE_ENCODING
107 // see also compression/config/compression_shared.h.
108 void SetEncodingSubmethod(int encoding_submethod);
109
110 // Sets the desired prediction method for a given attribute. By default,
111 // prediction scheme is selected automatically by the encoder using other
112 // provided options (such as speed) and input geometry type (mesh, point
113 // cloud). This function should be called only when a specific prediction is
114 // preferred (e.g., when it is known that the encoder would select a less
115 // optimal prediction for the given input data).
116 //
117 // |prediction_scheme_method| should be one of the entries defined in
118 // compression/config/compression_shared.h :
119 //
120 // PREDICTION_NONE - use no prediction.
121 // PREDICTION_DIFFERENCE - delta coding
122 // MESH_PREDICTION_PARALLELOGRAM - parallelogram prediction for meshes.
123 // MESH_PREDICTION_CONSTRAINED_PARALLELOGRAM
124 // - better and more costly version of the parallelogram prediction.
125 // MESH_PREDICTION_TEX_COORDS_PORTABLE
126 // - specialized predictor for tex coordinates.
127 // MESH_PREDICTION_GEOMETRIC_NORMAL
128 // - specialized predictor for normal coordinates.
129 //
130 // Note that in case the desired prediction cannot be used, the default
131 // prediction will be automatically used instead.
132 Status SetAttributePredictionScheme(int32_t attribute_id,
133 int prediction_scheme_method);
134
135 private:
136 Status EncodePointCloudToBuffer(const PointCloud &pc,
137 EncoderBuffer *out_buffer);
138
139 Status EncodeMeshToBuffer(const Mesh &m, EncoderBuffer *out_buffer);
140
141#ifdef DRACO_TRANSCODER_SUPPORTED
142 // Applies compression options stored in |mesh|.
143 Status ApplyCompressionOptions(const Mesh &mesh);
144 Status ApplyGridQuantization(const Mesh &mesh, int attribute_index);
145#endif // DRACO_TRANSCODER_SUPPORTED
146
147 const PointCloud *point_cloud_;
148 const Mesh *mesh_;
149};
150
151} // namespace draco
152
153#endif // DRACO_COMPRESSION_EXPERT_ENCODE_H_
EncoderBase()
Definition encode_base.h:32
const EncoderOptions & options() const
Definition encode_base.h:38
Definition encoder_buffer.h:29
void SetAttributeQuantization(int32_t attribute_id, int quantization_bits)
Definition expert_encode.cc:153
void SetEncodingSubmethod(int encoding_submethod)
Definition expert_encode.cc:179
ExpertEncoder(const PointCloud &point_cloud)
Definition expert_encode.cc:35
EncoderBase< EncoderOptions > Base
Definition expert_encode.h:34
void SetAttributeExplicitQuantization(int32_t attribute_id, int quantization_bits, int num_dims, const float *origin, float range)
Definition expert_encode.cc:159
void SetEncodingMethod(int encoding_method)
Definition expert_encode.cc:175
Status SetAttributePredictionScheme(int32_t attribute_id, int prediction_scheme_method)
Definition expert_encode.cc:183
Status EncodeToBuffer(EncoderBuffer *out_buffer)
Definition expert_encode.cc:41
void SetUseBuiltInAttributeCompression(bool enabled)
Definition expert_encode.cc:171
void SetSpeedOptions(int encoding_speed, int decoding_speed)
Definition expert_encode.cc:149
EncoderOptions OptionsType
Definition expert_encode.h:35
void Reset()
Definition expert_encode.cc:147
Definition mesh.h:52
Definition point_cloud.h:29
Definition status.h:25
Definition attribute_octahedron_transform.cc:21
EncoderOptionsBase< int32_t > EncoderOptions
Definition encoder_options.h:97