GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_prediction_scheme_geometric_normal_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_GEOMETRIC_NORMAL_ENCODER_H_
16#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_GEOMETRIC_NORMAL_ENCODER_H_
17
22
23namespace draco {
24
25// Prediction scheme for normals based on the underlying geometry.
26// At a smooth vertices normals are computed by weighting the normals of
27// adjacent faces with the area of these faces. At seams, the same approach
28// applies for seam corners.
29template <typename DataTypeT, class TransformT, class MeshDataT>
31 : public MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT> {
32 public:
33 using CorrType = typename MeshPredictionSchemeEncoder<DataTypeT, TransformT,
34 MeshDataT>::CorrType;
36 const TransformT &transform,
37 const MeshDataT &mesh_data)
38 : MeshPredictionSchemeEncoder<DataTypeT, TransformT, MeshDataT>(
40 predictor_(mesh_data) {}
41
43 const DataTypeT *in_data, CorrType *out_corr, int size,
44 int num_components, const PointIndex *entry_to_point_id_map) override;
45
46 bool EncodePredictionData(EncoderBuffer *buffer) override;
47
51
52 bool IsInitialized() const override {
53 if (!predictor_.IsInitialized()) {
54 return false;
55 }
56 if (!this->mesh_data().IsInitialized()) {
57 return false;
58 }
59 return true;
60 }
61
62 int GetNumParentAttributes() const override { return 1; }
63
65 DRACO_DCHECK_EQ(i, 0);
66 (void)i;
68 }
69
70 bool SetParentAttribute(const PointAttribute *att) override {
72 return false; // Invalid attribute type.
73 }
74 if (att->num_components() != 3) {
75 return false; // Currently works only for 3 component positions.
76 }
77 predictor_.SetPositionAttribute(*att);
78 return true;
79 }
80
81 private:
82 void SetQuantizationBits(int q) {
83 DRACO_DCHECK_GE(q, 2);
84 DRACO_DCHECK_LE(q, 30);
85 octahedron_tool_box_.SetQuantizationBits(q);
86 }
87 MeshPredictionSchemeGeometricNormalPredictorArea<DataTypeT, TransformT,
88 MeshDataT>
89 predictor_;
90
91 OctahedronToolBox octahedron_tool_box_;
92 RAnsBitEncoder flip_normal_bit_encoder_;
93};
94
95template <typename DataTypeT, class TransformT, class MeshDataT>
96bool MeshPredictionSchemeGeometricNormalEncoder<DataTypeT, TransformT,
97 MeshDataT>::
98 ComputeCorrectionValues(const DataTypeT *in_data, CorrType *out_corr,
99 int size, int num_components,
100 const PointIndex *entry_to_point_id_map) {
101 this->SetQuantizationBits(this->transform().quantization_bits());
102 predictor_.SetEntryToPointIdMap(entry_to_point_id_map);
104 // Expecting in_data in octahedral coordinates, i.e., portable attribute.
105 DRACO_DCHECK_EQ(num_components, 2);
106
107 flip_normal_bit_encoder_.StartEncoding();
108
109 const int corner_map_size =
110 static_cast<int>(this->mesh_data().data_to_corner_map()->size());
111
112 VectorD<int32_t, 3> pred_normal_3d;
113 VectorD<int32_t, 2> pos_pred_normal_oct;
114 VectorD<int32_t, 2> neg_pred_normal_oct;
115 VectorD<int32_t, 2> pos_correction;
116 VectorD<int32_t, 2> neg_correction;
117 for (int data_id = 0; data_id < corner_map_size; ++data_id) {
118 const CornerIndex corner_id =
119 this->mesh_data().data_to_corner_map()->at(data_id);
120 predictor_.ComputePredictedValue(corner_id, pred_normal_3d.data());
121
122 // Compute predicted octahedral coordinates.
123 octahedron_tool_box_.CanonicalizeIntegerVector(pred_normal_3d.data());
124 DRACO_DCHECK_EQ(pred_normal_3d.AbsSum(),
125 octahedron_tool_box_.center_value());
126
127 // Compute octahedral coordinates for both possible directions.
128 octahedron_tool_box_.IntegerVectorToQuantizedOctahedralCoords(
129 pred_normal_3d.data(), pos_pred_normal_oct.data(),
130 pos_pred_normal_oct.data() + 1);
131 pred_normal_3d = -pred_normal_3d;
132 octahedron_tool_box_.IntegerVectorToQuantizedOctahedralCoords(
133 pred_normal_3d.data(), neg_pred_normal_oct.data(),
134 neg_pred_normal_oct.data() + 1);
135
136 // Choose the one with the best correction value.
137 const int data_offset = data_id * 2;
138 this->transform().ComputeCorrection(in_data + data_offset,
139 pos_pred_normal_oct.data(),
140 pos_correction.data());
141 this->transform().ComputeCorrection(in_data + data_offset,
142 neg_pred_normal_oct.data(),
143 neg_correction.data());
144 pos_correction[0] = octahedron_tool_box_.ModMax(pos_correction[0]);
145 pos_correction[1] = octahedron_tool_box_.ModMax(pos_correction[1]);
146 neg_correction[0] = octahedron_tool_box_.ModMax(neg_correction[0]);
147 neg_correction[1] = octahedron_tool_box_.ModMax(neg_correction[1]);
148 if (pos_correction.AbsSum() < neg_correction.AbsSum()) {
149 flip_normal_bit_encoder_.EncodeBit(false);
150 (out_corr + data_offset)[0] =
151 octahedron_tool_box_.MakePositive(pos_correction[0]);
152 (out_corr + data_offset)[1] =
153 octahedron_tool_box_.MakePositive(pos_correction[1]);
154 } else {
155 flip_normal_bit_encoder_.EncodeBit(true);
156 (out_corr + data_offset)[0] =
157 octahedron_tool_box_.MakePositive(neg_correction[0]);
158 (out_corr + data_offset)[1] =
159 octahedron_tool_box_.MakePositive(neg_correction[1]);
160 }
161 }
162 return true;
163}
164
165template <typename DataTypeT, class TransformT, class MeshDataT>
167 DataTypeT, TransformT, MeshDataT>::EncodePredictionData(EncoderBuffer
168 *buffer) {
169 if (!this->transform().EncodeTransformData(buffer)) {
170 return false;
171 }
172
173 // Encode normal flips.
174 flip_normal_bit_encoder_.EndEncoding(buffer);
175 return true;
176}
177
178} // namespace draco
179
180#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_GEOMETRIC_NORMAL_ENCODER_H_
Definition encoder_buffer.h:29
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_geometric_normal_encoder.h:31
bool SetParentAttribute(const PointAttribute *att) override
Definition mesh_prediction_scheme_geometric_normal_encoder.h:70
MeshPredictionSchemeGeometricNormalEncoder(const PointAttribute *attribute, const TransformT &transform, const MeshDataT &mesh_data)
Definition mesh_prediction_scheme_geometric_normal_encoder.h:35
bool IsInitialized() const override
Definition mesh_prediction_scheme_geometric_normal_encoder.h:52
int GetNumParentAttributes() const override
Definition mesh_prediction_scheme_geometric_normal_encoder.h:62
PredictionSchemeMethod GetPredictionMethod() const override
Definition mesh_prediction_scheme_geometric_normal_encoder.h:48
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_geometric_normal_encoder.h:98
GeometryAttribute::Type GetParentAttributeType(int i) const override
Definition mesh_prediction_scheme_geometric_normal_encoder.h:64
typename MeshPredictionSchemeEncoder< DataTypeT, TransformT, MeshDataT >::CorrType CorrType
Definition mesh_prediction_scheme_geometric_normal_encoder.h:33
bool EncodePredictionData(EncoderBuffer *buffer) override
Definition mesh_prediction_scheme_geometric_normal_encoder.h:167
bool SetQuantizationBits(int32_t q)
Definition normal_compression_utils.h:59
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 vector_d.h:30
Scalar AbsSum() const
Definition vector_d.h:237
Scalar * data()
Definition vector_d.h:282
#define DRACO_DCHECK_EQ(a, b)
Definition macros.h:81
#define DRACO_DCHECK(x)
Definition macros.h:80
#define DRACO_DCHECK_LE(a, b)
Definition macros.h:85
#define DRACO_DCHECK_GE(a, b)
Definition macros.h:83
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_GEOMETRIC_NORMAL
Definition compression_shared.h:91
Definition GameApi_pl.cc:29382