GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
prediction_scheme_decoder_factory.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// Functions for creating prediction schemes for decoders using the provided
16// prediction method id.
17
18#ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_FACTORY_H_
19#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_FACTORY_H_
20
23#ifdef DRACO_NORMAL_ENCODING_SUPPORTED
25#endif
34
35namespace draco {
36
37// Factory class for creating mesh prediction schemes. The factory implements
38// operator() that is used to create an appropriate mesh prediction scheme in
39// CreateMeshPredictionScheme() function in prediction_scheme_factory.h
40template <typename DataTypeT>
42 // Operator () specialized for the wrap transform. Wrap transform can be used
43 // for all mesh prediction schemes. The specialization is done in compile time
44 // to prevent instantiations of unneeded combinations of prediction schemes +
45 // prediction transforms.
46 template <class TransformT, class MeshDataT,
49 std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>> operator()(
50 PredictionSchemeMethod method, const PointAttribute *attribute,
51 const TransformT &transform, const MeshDataT &mesh_data,
52 uint16_t bitstream_version) {
53 if (method == MESH_PREDICTION_PARALLELOGRAM) {
54 return std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>(
55 new MeshPredictionSchemeParallelogramDecoder<DataTypeT, TransformT,
56 MeshDataT>(
57 attribute, transform, mesh_data));
58 }
59#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
60 else if (method == MESH_PREDICTION_MULTI_PARALLELOGRAM) {
61 return std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>(
62 new MeshPredictionSchemeMultiParallelogramDecoder<
63 DataTypeT, TransformT, MeshDataT>(attribute, transform,
64 mesh_data));
65 }
66#endif
68 return std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>(
70 DataTypeT, TransformT, MeshDataT>(attribute, transform,
71 mesh_data));
72 }
73#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
74 else if (method == MESH_PREDICTION_TEX_COORDS_DEPRECATED) {
75 return std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>(
76 new MeshPredictionSchemeTexCoordsDecoder<DataTypeT, TransformT,
77 MeshDataT>(
78 attribute, transform, mesh_data, bitstream_version));
79 }
80#endif
81 else if (method == MESH_PREDICTION_TEX_COORDS_PORTABLE) {
82 return std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>(
84 DataTypeT, TransformT, MeshDataT>(attribute, transform,
85 mesh_data));
86 }
87#ifdef DRACO_NORMAL_ENCODING_SUPPORTED
88 else if (method == MESH_PREDICTION_GEOMETRIC_NORMAL) {
89 return std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>(
91 DataTypeT, TransformT, MeshDataT>(attribute, transform,
92 mesh_data));
93 }
94#endif
95 return nullptr;
96 }
97 };
98
99#ifdef DRACO_NORMAL_ENCODING_SUPPORTED
100 // Operator () specialized for normal octahedron transforms. These transforms
101 // are currently used only by the geometric normal prediction scheme (the
102 // transform is also used by delta coding, but delta predictor is not
103 // constructed in this function).
104 template <class TransformT, class MeshDataT>
105 struct DispatchFunctor<TransformT, MeshDataT,
107 std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>> operator()(
108 PredictionSchemeMethod method, const PointAttribute *attribute,
109 const TransformT &transform, const MeshDataT &mesh_data,
110 uint16_t bitstream_version) {
111 if (method == MESH_PREDICTION_GEOMETRIC_NORMAL) {
112 return std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>(
114 DataTypeT, TransformT, MeshDataT>(attribute, transform,
115 mesh_data));
116 }
117 return nullptr;
118 }
119 };
120 template <class TransformT, class MeshDataT>
121 struct DispatchFunctor<TransformT, MeshDataT,
123 std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>> operator()(
124 PredictionSchemeMethod method, const PointAttribute *attribute,
125 const TransformT &transform, const MeshDataT &mesh_data,
126 uint16_t bitstream_version) {
127 if (method == MESH_PREDICTION_GEOMETRIC_NORMAL) {
128 return std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>(
129 new MeshPredictionSchemeGeometricNormalDecoder<
130 DataTypeT, TransformT, MeshDataT>(attribute, transform,
131 mesh_data));
132 }
133 return nullptr;
134 }
135 };
136#endif
137
138 template <class TransformT, class MeshDataT>
139 std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>> operator()(
140 PredictionSchemeMethod method, const PointAttribute *attribute,
141 const TransformT &transform, const MeshDataT &mesh_data,
142 uint16_t bitstream_version) {
144 method, attribute, transform, mesh_data, bitstream_version);
145 }
146};
147
148// Creates a prediction scheme for a given decoder and given prediction method.
149// The prediction schemes are automatically initialized with decoder specific
150// data if needed.
151template <typename DataTypeT, class TransformT>
152std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>
154 const PointCloudDecoder *decoder,
155 const TransformT &transform) {
156 if (method == PREDICTION_NONE) {
157 return nullptr;
158 }
159 const PointAttribute *const att = decoder->point_cloud()->attribute(att_id);
160 if (decoder->GetGeometryType() == TRIANGULAR_MESH) {
161 // Cast the decoder to mesh decoder. This is not necessarily safe if there
162 // is some other decoder decides to use TRIANGULAR_MESH as the return type,
163 // but unfortunately there is not nice work around for this without using
164 // RTTI (double dispatch and similar concepts will not work because of the
165 // template nature of the prediction schemes).
166 const MeshDecoder *const mesh_decoder =
167 static_cast<const MeshDecoder *>(decoder);
168
172 mesh_decoder, method, att_id, transform, decoder->bitstream_version());
173 if (ret) {
174 return ret;
175 }
176 // Otherwise try to create another prediction scheme.
177 }
178 // Create delta decoder.
179 return std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>(
181}
182
183// Create a prediction scheme using a default transform constructor.
184template <typename DataTypeT, class TransformT>
185std::unique_ptr<PredictionSchemeDecoder<DataTypeT, TransformT>>
187 const PointCloudDecoder *decoder) {
189 method, att_id, decoder, TransformT());
190}
191
192} // namespace draco
193
194#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_PREDICTION_SCHEME_DECODER_FACTORY_H_
Definition mesh_decoder.h:27
Definition mesh_prediction_scheme_constrained_multi_parallelogram_decoder.h:36
Definition mesh_prediction_scheme_geometric_normal_decoder.h:28
Definition mesh_prediction_scheme_parallelogram_decoder.h:28
Definition mesh_prediction_scheme_tex_coords_portable_decoder.h:29
Definition point_attribute.h:33
Definition point_cloud_decoder.h:28
PointCloud * point_cloud()
Definition point_cloud_decoder.h:76
virtual EncodedGeometryType GetGeometryType() const
Definition point_cloud_decoder.h:33
uint16_t bitstream_version() const
Definition point_cloud_decoder.h:63
const PointAttribute * attribute(int32_t att_id) const
Definition point_cloud.h:68
Definition prediction_scheme_decoder.h:36
Definition prediction_scheme_delta_decoder.h:26
ret($return)
Definition mesh_login_result.php:5
Definition attribute_octahedron_transform.cc:21
@ TRIANGULAR_MESH
Definition compression_shared.h:44
std::unique_ptr< PredictionSchemeT > CreateMeshPredictionScheme(const EncodingDataSourceT *source, PredictionSchemeMethod method, int att_id, const typename PredictionSchemeT::Transform &transform, uint16_t bitstream_version)
Definition prediction_scheme_factory.h:34
PredictionSchemeTransformType
Definition compression_shared.h:96
@ PREDICTION_TRANSFORM_NORMAL_OCTAHEDRON_CANONICALIZED
Definition compression_shared.h:108
@ PREDICTION_TRANSFORM_NORMAL_OCTAHEDRON
Definition compression_shared.h:105
std::unique_ptr< PredictionSchemeDecoder< DataTypeT, TransformT > > CreatePredictionSchemeForDecoder(PredictionSchemeMethod method, int att_id, const PointCloudDecoder *decoder, const TransformT &transform)
Definition prediction_scheme_decoder_factory.h:153
PredictionSchemeMethod
Definition compression_shared.h:80
@ MESH_PREDICTION_PARALLELOGRAM
Definition compression_shared.h:86
@ PREDICTION_NONE
Definition compression_shared.h:82
@ MESH_PREDICTION_TEX_COORDS_DEPRECATED
Definition compression_shared.h:88
@ MESH_PREDICTION_CONSTRAINED_MULTI_PARALLELOGRAM
Definition compression_shared.h:89
@ MESH_PREDICTION_GEOMETRIC_NORMAL
Definition compression_shared.h:91
@ MESH_PREDICTION_TEX_COORDS_PORTABLE
Definition compression_shared.h:90
@ MESH_PREDICTION_MULTI_PARALLELOGRAM
Definition compression_shared.h:87
Definition prediction_scheme_decoder_factory.h:48
std::unique_ptr< PredictionSchemeDecoder< DataTypeT, TransformT > > operator()(PredictionSchemeMethod method, const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data, uint16_t bitstream_version)
Definition prediction_scheme_decoder_factory.h:49
Definition prediction_scheme_decoder_factory.h:41
std::unique_ptr< PredictionSchemeDecoder< DataTypeT, TransformT > > operator()(PredictionSchemeMethod method, const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data, uint16_t bitstream_version)
Definition prediction_scheme_decoder_factory.h:139