GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_prediction_scheme_tex_coords_portable_encoder.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_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_ENCODER_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_ENCODER_H_
17
21
22namespace draco {
23
24// Prediction scheme designed for predicting texture coordinates from known
25// spatial position of vertices. For isometric parametrizations, the ratios
26// between triangle edge lengths should be about the same in both the spatial
27// and UV coordinate spaces, which makes the positions a good predictor for the
28// UV coordinates. Note that this may not be the optimal approach for other
29// parametrizations such as projective ones.
30template <typename DataTypeT, class TransformT, class MeshDataT>
32 : public MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT> {
33 public:
34 using CorrType = typename MeshPredictionSchemeEncoder<DataTypeT, TransformT,
35 MeshDataT>::CorrType;
37 const TransformT &transform,
38 const MeshDataT &mesh_data)
39 : MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT>(
41 predictor_(mesh_data) {}
42
44 const DataTypeT *in_data, CorrType *out_corr, int size,
45 int num_components, const PointIndex *entry_to_point_id_map) override;
46
47 bool EncodePredictionData(EncoderBuffer *buffer) override;
48
52
53 bool IsInitialized() const override {
54 if (!predictor_.IsInitialized()) {
55 return false;
56 }
57 if (!this->mesh_data().IsInitialized()) {
58 return false;
59 }
60 return true;
61 }
62
63 int GetNumParentAttributes() const override { return 1; }
64
66 DRACO_DCHECK_EQ(i, 0);
67 (void)i;
69 }
70
71 bool SetParentAttribute(const PointAttribute *att) override {
73 return false; // Invalid attribute type.
74 }
75 if (att->num_components() != 3) {
76 return false; // Currently works only for 3 component positions.
77 }
78 predictor_.SetPositionAttribute(*att);
79 return true;
80 }
81
82 private:
84 predictor_;
85};
86
87template <typename DataTypeT, class TransformT, class MeshDataT>
88bool MeshPredictionSchemeTexCoordsPortableEncoder<DataTypeT, TransformT,
89 MeshDataT>::
90 ComputeCorrectionValues(const DataTypeT *in_data, CorrType *out_corr,
91 int size, int num_components,
92 const PointIndex *entry_to_point_id_map) {
93 predictor_.SetEntryToPointIdMap(entry_to_point_id_map);
94 this->transform().Init(in_data, size, num_components);
95 // We start processing from the end because this prediction uses data from
96 // previous entries that could be overwritten when an entry is processed.
97 for (int p =
98 static_cast<int>(this->mesh_data().data_to_corner_map()->size() - 1);
99 p >= 0; --p) {
100 const CornerIndex corner_id = this->mesh_data().data_to_corner_map()->at(p);
101 if (!predictor_.template ComputePredictedValue<true>(corner_id, in_data,
102 p)) {
103 return false;
104 }
105
106 const int dst_offset = p * num_components;
107 this->transform().ComputeCorrection(in_data + dst_offset,
108 predictor_.predicted_value(),
109 out_corr + dst_offset);
110 }
111 return true;
112}
113
114template <typename DataTypeT, class TransformT, class MeshDataT>
116 DataTypeT, TransformT, MeshDataT>::EncodePredictionData(EncoderBuffer
117 *buffer) {
118 // Encode the delta-coded orientations using arithmetic coding.
119 const int32_t num_orientations = predictor_.num_orientations();
120 buffer->Encode(num_orientations);
121 bool last_orientation = true;
122 RAnsBitEncoder encoder;
123 encoder.StartEncoding();
124 for (int i = 0; i < num_orientations; ++i) {
125 const bool orientation = predictor_.orientation(i);
126 encoder.EncodeBit(orientation == last_orientation);
127 last_orientation = orientation;
128 }
129 encoder.EndEncoding(buffer);
130 return MeshPredictionSchemeEncoder<DataTypeT, TransformT,
131 MeshDataT>::EncodePredictionData(buffer);
132}
133
134} // namespace draco
135
136#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_TEX_COORDS_PORTABLE_ENCODER_H_
Definition encoder_buffer.h:29
bool Encode(const T &data)
Definition encoder_buffer.h:60
uint8_t num_components() const
Definition geometry_attribute.h:263
Type attribute_type() const
Definition geometry_attribute.h:256
Type
Definition geometry_attribute.h:46
@ POSITION
Definition geometry_attribute.h:52
MeshPredictionSchemeEncoder(const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data)
Definition mesh_prediction_scheme_encoder.h:31
const MeshData & mesh_data() const
Definition mesh_prediction_scheme_encoder.h:38
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:32
MeshPredictionSchemeTexCoordsPortableEncoder(const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data)
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:36
typename MeshPredictionSchemeEncoder< DataTypeT, TransformT, MeshDataT >::CorrType CorrType
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:34
bool SetParentAttribute(const PointAttribute *att) override
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:71
bool IsInitialized() const override
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:53
int GetNumParentAttributes() const override
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:63
bool ComputeCorrectionValues(const DataTypeT *in_data, CorrType *out_corr, int size, int num_components, const PointIndex *entry_to_point_id_map) override
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:90
bool EncodePredictionData(EncoderBuffer *buffer) override
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:116
GeometryAttribute::Type GetParentAttributeType(int i) const override
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:65
PredictionSchemeMethod GetPredictionMethod() const override
Definition mesh_prediction_scheme_tex_coords_portable_encoder.h:49
Definition mesh_prediction_scheme_tex_coords_portable_predictor.h:33
void SetEntryToPointIdMap(const PointIndex *map)
Definition mesh_prediction_scheme_tex_coords_portable_predictor.h:44
Definition point_attribute.h:33
const PointAttribute * attribute() const
Definition prediction_scheme_encoder.h:79
const Transform & transform() const
Definition prediction_scheme_encoder.h:80
Definition rans_bit_encoder.h:28
void EndEncoding(EncoderBuffer *target_buffer)
Definition rans_bit_encoder.cc:75
void EncodeBit(bool bit)
Definition rans_bit_encoder.cc:31
void StartEncoding()
Definition rans_bit_encoder.cc:29
#define DRACO_DCHECK_EQ(a, b)
Definition macros.h:81
n< br > font size
Definition meshpage.php:3536
Definition attribute_octahedron_transform.cc:21
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35
PredictionSchemeMethod
Definition compression_shared.h:80
@ MESH_PREDICTION_TEX_COORDS_PORTABLE
Definition compression_shared.h:90
Definition GameApi_pl.cc:29382