GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_prediction_scheme_parallelogram_shared.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// Shared functionality for different parallelogram prediction schemes.
16
17#ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_PARALLELOGRAM_SHARED_H_
18#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_PARALLELOGRAM_SHARED_H_
19
21#include "draco/mesh/mesh.h"
22
23namespace draco {
24
25// TODO(draco-eng) consolidate Vertex/next/previous queries to one call
26// (performance).
27template <class CornerTableT>
29 const CornerIndex ci, const CornerTableT *table,
30 const std::vector<int32_t> &vertex_to_data_map, int *opp_entry,
31 int *next_entry, int *prev_entry) {
32 // One vertex of the input |table| correspond to exactly one attribute value
33 // entry. The |table| can be either CornerTable for per-vertex attributes,
34 // or MeshAttributeCornerTable for attributes with interior seams.
35 *opp_entry = vertex_to_data_map[table->Vertex(ci).value()];
36 *next_entry = vertex_to_data_map[table->Vertex(table->Next(ci)).value()];
37 *prev_entry = vertex_to_data_map[table->Vertex(table->Previous(ci)).value()];
38}
39
40// Computes parallelogram prediction for a given corner and data entry id.
41// The prediction is stored in |out_prediction|.
42// Function returns false when the prediction couldn't be computed, e.g. because
43// not all entry points were available.
44template <class CornerTableT, typename DataTypeT>
46 int data_entry_id, const CornerIndex ci, const CornerTableT *table,
47 const std::vector<int32_t> &vertex_to_data_map, const DataTypeT *in_data,
48 int num_components, DataTypeT *out_prediction) {
49 const CornerIndex oci = table->Opposite(ci);
50 if (oci == kInvalidCornerIndex) {
51 return false;
52 }
53 int vert_opp, vert_next, vert_prev;
54 GetParallelogramEntries<CornerTableT>(oci, table, vertex_to_data_map,
55 &vert_opp, &vert_next, &vert_prev);
56 if (vert_opp < data_entry_id && vert_next < data_entry_id &&
57 vert_prev < data_entry_id) {
58 // Apply the parallelogram prediction.
59 const int v_opp_off = vert_opp * num_components;
60 const int v_next_off = vert_next * num_components;
61 const int v_prev_off = vert_prev * num_components;
62 for (int c = 0; c < num_components; ++c) {
63 const int64_t in_data_next_off = in_data[v_next_off + c];
64 const int64_t in_data_prev_off = in_data[v_prev_off + c];
65 const int64_t in_data_opp_off = in_data[v_opp_off + c];
66 const int64_t result =
67 (in_data_next_off + in_data_prev_off) - in_data_opp_off;
68
69 out_prediction[c] = static_cast<DataTypeT>(result);
70 }
71 return true;
72 }
73 return false; // Not all data is available for prediction
74}
75
76} // namespace draco
77
78#endif // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_PARALLELOGRAM_SHARED_H_
Definition attribute_octahedron_transform.cc:21
bool ComputeParallelogramPrediction(int data_entry_id, const CornerIndex ci, const CornerTableT *table, const std::vector< int32_t > &vertex_to_data_map, const DataTypeT *in_data, int num_components, DataTypeT *out_prediction)
Definition mesh_prediction_scheme_parallelogram_shared.h:45
void GetParallelogramEntries(const CornerIndex ci, const CornerTableT *table, const std::vector< int32_t > &vertex_to_data_map, int *opp_entry, int *next_entry, int *prev_entry)
Definition mesh_prediction_scheme_parallelogram_shared.h:28
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35