GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
encode_base.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_ENCODE_BASE_H_
16#define DRACO_COMPRESSION_ENCODE_BASE_H_
17
20#include "draco/core/status.h"
21
22namespace draco {
23
24// Base class for our geometry encoder classes. |EncoderOptionsT| specifies
25// options class used by the encoder. Please, see encode.h and expert_encode.h
26// for more details and method descriptions.
27template <class EncoderOptionsT>
29 public:
30 typedef EncoderOptionsT OptionsType;
31
33 : options_(EncoderOptionsT::CreateDefaultOptions()),
34 num_encoded_points_(0),
35 num_encoded_faces_(0) {}
36 virtual ~EncoderBase() {}
37
38 const EncoderOptionsT &options() const { return options_; }
39 EncoderOptionsT &options() { return options_; }
40
41 // If enabled, it tells the encoder to keep track of the number of encoded
42 // points and faces (default = false).
43 // Note that this can slow down encoding for certain encoders.
45
46 // Returns the number of encoded points and faces during the last encoding
47 // operation. Returns 0 if SetTrackEncodedProperties() was not set.
48 size_t num_encoded_points() const { return num_encoded_points_; }
49 size_t num_encoded_faces() const { return num_encoded_faces_; }
50
51 protected:
52 void Reset(const EncoderOptionsT &options) { options_ = options; }
53
54 void Reset() { options_ = EncoderOptionsT::CreateDefaultOptions(); }
55
56 void SetSpeedOptions(int encoding_speed, int decoding_speed) {
57 options_.SetSpeed(encoding_speed, decoding_speed);
58 }
59
60 void SetEncodingMethod(int encoding_method) {
61 options_.SetGlobalInt("encoding_method", encoding_method);
62 }
63
64 void SetEncodingSubmethod(int encoding_submethod) {
65 options_.SetGlobalInt("encoding_submethod", encoding_submethod);
66 }
67
69 int prediction_scheme) const {
70 // Out of bound checks:
71 if (prediction_scheme < PREDICTION_NONE) {
73 "Invalid prediction scheme requested.");
74 }
75 if (prediction_scheme >= NUM_PREDICTION_SCHEMES) {
77 "Invalid prediction scheme requested.");
78 }
79 // Deprecated prediction schemes:
80 if (prediction_scheme == MESH_PREDICTION_TEX_COORDS_DEPRECATED) {
82 "MESH_PREDICTION_TEX_COORDS_DEPRECATED is deprecated.");
83 }
84 if (prediction_scheme == MESH_PREDICTION_MULTI_PARALLELOGRAM) {
86 "MESH_PREDICTION_MULTI_PARALLELOGRAM is deprecated.");
87 }
88 // Attribute specific checks:
89 if (prediction_scheme == MESH_PREDICTION_TEX_COORDS_PORTABLE) {
90 if (att_type != GeometryAttribute::TEX_COORD) {
92 "Invalid prediction scheme for attribute type.");
93 }
94 }
95 if (prediction_scheme == MESH_PREDICTION_GEOMETRIC_NORMAL) {
96 if (att_type != GeometryAttribute::NORMAL) {
98 "Invalid prediction scheme for attribute type.");
99 }
100 }
101 // TODO(b/199760123): Try to enable more prediction schemes for normals.
102 if (att_type == GeometryAttribute::NORMAL) {
103 if (!(prediction_scheme == PREDICTION_DIFFERENCE ||
104 prediction_scheme == MESH_PREDICTION_GEOMETRIC_NORMAL)) {
106 "Invalid prediction scheme for attribute type.");
107 }
108 }
109 return OkStatus();
110 }
111
112 protected:
113 void set_num_encoded_points(size_t num) { num_encoded_points_ = num; }
114 void set_num_encoded_faces(size_t num) { num_encoded_faces_ = num; }
115
116 private:
117 EncoderOptionsT options_;
118
119 size_t num_encoded_points_;
120 size_t num_encoded_faces_;
121};
122
123template <class EncoderOptionsT>
125 options_.SetGlobalBool("store_number_of_encoded_points", flag);
126 options_.SetGlobalBool("store_number_of_encoded_faces", flag);
127}
128
129} // namespace draco
130
131#endif // DRACO_COMPRESSION_ENCODE_BASE_H_
EncoderOptionsBase< GeometryAttribute::Type > OptionsType
Definition encode_base.h:30
void set_num_encoded_faces(size_t num)
Definition encode_base.h:114
void SetEncodingSubmethod(int encoding_submethod)
Definition encode_base.h:64
void SetSpeedOptions(int encoding_speed, int decoding_speed)
Definition encode_base.h:56
void Reset()
Definition encode_base.h:54
size_t num_encoded_points() const
Definition encode_base.h:48
size_t num_encoded_faces() const
Definition encode_base.h:49
void Reset(const EncoderOptionsT &options)
Definition encode_base.h:52
EncoderBase()
Definition encode_base.h:32
void SetEncodingMethod(int encoding_method)
Definition encode_base.h:60
virtual ~EncoderBase()
Definition encode_base.h:36
void set_num_encoded_points(size_t num)
Definition encode_base.h:113
void SetTrackEncodedProperties(bool flag)
Definition encode_base.h:124
Status CheckPredictionScheme(GeometryAttribute::Type att_type, int prediction_scheme) const
Definition encode_base.h:68
EncoderOptionsT & options()
Definition encode_base.h:39
const EncoderOptionsT & options() const
Definition encode_base.h:38
Type
Definition geometry_attribute.h:46
@ TEX_COORD
Definition geometry_attribute.h:55
@ NORMAL
Definition geometry_attribute.h:53
Definition status.h:25
@ DRACO_ERROR
Definition status.h:29
Definition attribute_octahedron_transform.cc:21
Status OkStatus()
Definition status.h:66
@ PREDICTION_NONE
Definition compression_shared.h:82
@ MESH_PREDICTION_TEX_COORDS_DEPRECATED
Definition compression_shared.h:88
@ MESH_PREDICTION_GEOMETRIC_NORMAL
Definition compression_shared.h:91
@ NUM_PREDICTION_SCHEMES
Definition compression_shared.h:92
@ MESH_PREDICTION_TEX_COORDS_PORTABLE
Definition compression_shared.h:90
@ MESH_PREDICTION_MULTI_PARALLELOGRAM
Definition compression_shared.h:87
@ PREDICTION_DIFFERENCE
Definition compression_shared.h:85
num
Definition view.php:2821