GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
draco_options.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_CONFIG_DRACO_OPTIONS_H_
16#define DRACO_COMPRESSION_CONFIG_DRACO_OPTIONS_H_
17
18#include <map>
19#include <memory>
20
21#include "draco/core/options.h"
22
23namespace draco {
24
25// Base option class used to control encoding and decoding. The geometry coding
26// can be controlled through the following options:
27// 1. Global options - Options specific to overall geometry or options common
28// for all attributes
29// 2. Per attribute options - Options specific to a given attribute.
30// Each attribute is identified by the template
31// argument AttributeKeyT that can be for example
32// the attribute type or the attribute id.
33//
34// Example:
35//
36// DracoOptions<AttributeKey> options;
37//
38// // Set an option common for all attributes.
39// options.SetGlobalInt("some_option_name", 2);
40//
41// // Geometry with two attributes.
42// AttributeKey att_key0 = in_key0;
43// AttributeKey att_key1 = in_key1;
44//
45// options.SetAttributeInt(att_key0, "some_option_name", 3);
46//
47// options.GetAttributeInt(att_key0, "some_option_name"); // Returns 3
48// options.GetAttributeInt(att_key1, "some_option_name"); // Returns 2
49// options.GetGlobalInt("some_option_name"); // Returns 2
50//
51template <typename AttributeKeyT>
53 public:
54 typedef AttributeKeyT AttributeKey;
55
56 // Get an option for a specific attribute key. If the option is not found in
57 // an attribute specific storage, the implementation will return a global
58 // option of the given name (if available). If the option is not found, the
59 // provided default value |default_val| is returned instead.
60 int GetAttributeInt(const AttributeKey &att_key, const std::string &name,
61 int default_val) const;
62
63 // Sets an option for a specific attribute key.
64 void SetAttributeInt(const AttributeKey &att_key, const std::string &name,
65 int val);
66
67 float GetAttributeFloat(const AttributeKey &att_key, const std::string &name,
68 float default_val) const;
69 void SetAttributeFloat(const AttributeKey &att_key, const std::string &name,
70 float val);
71 bool GetAttributeBool(const AttributeKey &att_key, const std::string &name,
72 bool default_val) const;
73 void SetAttributeBool(const AttributeKey &att_key, const std::string &name,
74 bool val);
75 template <typename DataTypeT>
76 bool GetAttributeVector(const AttributeKey &att_key, const std::string &name,
77 int num_dims, DataTypeT *val) const;
78 template <typename DataTypeT>
79 void SetAttributeVector(const AttributeKey &att_key, const std::string &name,
80 int num_dims, const DataTypeT *val);
81
83 const std::string &name) const;
84
85 // Gets/sets a global option that is not specific to any attribute.
86 int GetGlobalInt(const std::string &name, int default_val) const {
87 return global_options_.GetInt(name, default_val);
88 }
89 void SetGlobalInt(const std::string &name, int val) {
90 global_options_.SetInt(name, val);
91 }
92 float GetGlobalFloat(const std::string &name, float default_val) const {
93 return global_options_.GetFloat(name, default_val);
94 }
95 void SetGlobalFloat(const std::string &name, float val) {
96 global_options_.SetFloat(name, val);
97 }
98 bool GetGlobalBool(const std::string &name, bool default_val) const {
99 return global_options_.GetBool(name, default_val);
100 }
101 void SetGlobalBool(const std::string &name, bool val) {
102 global_options_.SetBool(name, val);
103 }
104 template <typename DataTypeT>
105 bool GetGlobalVector(const std::string &name, int num_dims,
106 DataTypeT *val) const {
107 return global_options_.GetVector(name, num_dims, val);
108 }
109 template <typename DataTypeT>
110 void SetGlobalVector(const std::string &name, int num_dims,
111 const DataTypeT *val) {
112 global_options_.SetVector(name, val, num_dims);
113 }
114 bool IsGlobalOptionSet(const std::string &name) const {
115 return global_options_.IsOptionSet(name);
116 }
117
118 // Sets or replaces attribute options with the provided |options|.
119 void SetAttributeOptions(const AttributeKey &att_key, const Options &options);
120 void SetGlobalOptions(const Options &options) { global_options_ = options; }
121
122 // Returns |Options| instance for the specified options class if it exists.
123 const Options *FindAttributeOptions(const AttributeKeyT &att_key) const;
124 const Options &GetGlobalOptions() const { return global_options_; }
125
126 private:
127 Options *GetAttributeOptions(const AttributeKeyT &att_key);
128
129 Options global_options_;
130
131 // Storage for options related to geometry attributes.
132 std::map<AttributeKey, Options> attribute_options_;
133};
134
135template <typename AttributeKeyT>
137 const AttributeKeyT &att_key) const {
138 auto it = attribute_options_.find(att_key);
139 if (it == attribute_options_.end()) {
140 return nullptr;
141 }
142 return &it->second;
143}
144
145template <typename AttributeKeyT>
146Options *DracoOptions<AttributeKeyT>::GetAttributeOptions(
147 const AttributeKeyT &att_key) {
148 auto it = attribute_options_.find(att_key);
149 if (it != attribute_options_.end()) {
150 return &it->second;
151 }
152 Options new_options;
153 it = attribute_options_.insert(std::make_pair(att_key, new_options)).first;
154 return &it->second;
155}
156
157template <typename AttributeKeyT>
158int DracoOptions<AttributeKeyT>::GetAttributeInt(const AttributeKeyT &att_key,
159 const std::string &name,
160 int default_val) const {
161 const Options *const att_options = FindAttributeOptions(att_key);
162 if (att_options && att_options->IsOptionSet(name)) {
163 return att_options->GetInt(name, default_val);
164 }
165 return global_options_.GetInt(name, default_val);
166}
167
168template <typename AttributeKeyT>
169void DracoOptions<AttributeKeyT>::SetAttributeInt(const AttributeKeyT &att_key,
170 const std::string &name,
171 int val) {
172 GetAttributeOptions(att_key)->SetInt(name, val);
173}
174
175template <typename AttributeKeyT>
177 const AttributeKeyT &att_key, const std::string &name,
178 float default_val) const {
179 const Options *const att_options = FindAttributeOptions(att_key);
180 if (att_options && att_options->IsOptionSet(name)) {
181 return att_options->GetFloat(name, default_val);
182 }
183 return global_options_.GetFloat(name, default_val);
184}
185
186template <typename AttributeKeyT>
188 const AttributeKeyT &att_key, const std::string &name, float val) {
189 GetAttributeOptions(att_key)->SetFloat(name, val);
190}
191
192template <typename AttributeKeyT>
193bool DracoOptions<AttributeKeyT>::GetAttributeBool(const AttributeKeyT &att_key,
194 const std::string &name,
195 bool default_val) const {
196 const Options *const att_options = FindAttributeOptions(att_key);
197 if (att_options && att_options->IsOptionSet(name)) {
198 return att_options->GetBool(name, default_val);
199 }
200 return global_options_.GetBool(name, default_val);
201}
202
203template <typename AttributeKeyT>
204void DracoOptions<AttributeKeyT>::SetAttributeBool(const AttributeKeyT &att_key,
205 const std::string &name,
206 bool val) {
207 GetAttributeOptions(att_key)->SetBool(name, val);
208}
209
210template <typename AttributeKeyT>
211template <typename DataTypeT>
213 const AttributeKey &att_key, const std::string &name, int num_dims,
214 DataTypeT *val) const {
215 const Options *const att_options = FindAttributeOptions(att_key);
216 if (att_options && att_options->IsOptionSet(name)) {
217 return att_options->GetVector(name, num_dims, val);
218 }
219 return global_options_.GetVector(name, num_dims, val);
220}
221
222template <typename AttributeKeyT>
223template <typename DataTypeT>
225 const AttributeKey &att_key, const std::string &name, int num_dims,
226 const DataTypeT *val) {
227 GetAttributeOptions(att_key)->SetVector(name, val, num_dims);
228}
229
230template <typename AttributeKeyT>
232 const AttributeKey &att_key, const std::string &name) const {
233 const Options *const att_options = FindAttributeOptions(att_key);
234 if (att_options) {
235 return att_options->IsOptionSet(name);
236 }
237 return global_options_.IsOptionSet(name);
238}
239
240template <typename AttributeKeyT>
242 const AttributeKey &att_key, const Options &options) {
243 Options *att_options = GetAttributeOptions(att_key);
244 *att_options = options;
245}
246
247} // namespace draco
248
249#endif // DRACO_COMPRESSION_CONFIG_DRACO_OPTIONS_H_
Definition draco_options.h:52
void SetAttributeBool(const AttributeKey &att_key, const std::string &name, bool val)
Definition draco_options.h:204
bool IsAttributeOptionSet(const AttributeKey &att_key, const std::string &name) const
Definition draco_options.h:231
void SetAttributeVector(const AttributeKey &att_key, const std::string &name, int num_dims, const DataTypeT *val)
Definition draco_options.h:224
void SetAttributeOptions(const AttributeKey &att_key, const Options &options)
Definition draco_options.h:241
bool GetGlobalVector(const std::string &name, int num_dims, DataTypeT *val) const
Definition draco_options.h:105
void SetGlobalInt(const std::string &name, int val)
Definition draco_options.h:89
void SetAttributeInt(const AttributeKey &att_key, const std::string &name, int val)
Definition draco_options.h:169
const Options & GetGlobalOptions() const
Definition draco_options.h:124
float GetGlobalFloat(const std::string &name, float default_val) const
Definition draco_options.h:92
void SetGlobalBool(const std::string &name, bool val)
Definition draco_options.h:101
bool GetAttributeVector(const AttributeKey &att_key, const std::string &name, int num_dims, DataTypeT *val) const
Definition draco_options.h:212
int GetGlobalInt(const std::string &name, int default_val) const
Definition draco_options.h:86
bool GetGlobalBool(const std::string &name, bool default_val) const
Definition draco_options.h:98
void SetAttributeFloat(const AttributeKey &att_key, const std::string &name, float val)
Definition draco_options.h:187
void SetGlobalFloat(const std::string &name, float val)
Definition draco_options.h:95
float GetAttributeFloat(const AttributeKey &att_key, const std::string &name, float default_val) const
Definition draco_options.h:176
GeometryAttribute::Type AttributeKey
Definition draco_options.h:54
const Options * FindAttributeOptions(const AttributeKeyT &att_key) const
Definition draco_options.h:136
int GetAttributeInt(const AttributeKey &att_key, const std::string &name, int default_val) const
Definition draco_options.h:158
bool GetAttributeBool(const AttributeKey &att_key, const std::string &name, bool default_val) const
Definition draco_options.h:193
void SetGlobalVector(const std::string &name, int num_dims, const DataTypeT *val)
Definition draco_options.h:110
bool IsGlobalOptionSet(const std::string &name) const
Definition draco_options.h:114
void SetGlobalOptions(const Options &options)
Definition draco_options.h:120
Definition options.h:30
bool GetBool(const std::string &name) const
Definition options.cc:68
bool IsOptionSet(const std::string &name) const
Definition options.h:70
int GetInt(const std::string &name) const
Definition options.cc:46
VectorT GetVector(const std::string &name, const VectorT &default_val) const
Definition options.h:101
float GetFloat(const std::string &name) const
Definition options.cc:56
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
< h2 > I want smooth transition from jpg png webp to the engine</h2 > There s few options
Definition meshpage.php:1181
Definition attribute_octahedron_transform.cc:21