Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mesh_prediction_scheme_parallelogram_shared.h « prediction_schemes « attributes « compression « draco « src « draco « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 485d457ccf65f9746d838c58e4021fa0c7d361b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2016 The Draco Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Shared functionality for different parallelogram prediction schemes.

#ifndef DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_PARALLELOGRAM_SHARED_H_
#define DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_PARALLELOGRAM_SHARED_H_

#include "draco/mesh/corner_table.h"
#include "draco/mesh/mesh.h"

namespace draco {

// TODO(draco-eng) consolidate Vertex/next/previous queries to one call
// (performance).
template <class CornerTableT>
inline 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) {
  // One vertex of the input |table| correspond to exactly one attribute value
  // entry. The |table| can be either CornerTable for per-vertex attributes,
  // or MeshAttributeCornerTable for attributes with interior seams.
  *opp_entry = vertex_to_data_map[table->Vertex(ci).value()];
  *next_entry = vertex_to_data_map[table->Vertex(table->Next(ci)).value()];
  *prev_entry = vertex_to_data_map[table->Vertex(table->Previous(ci)).value()];
}

// Computes parallelogram prediction for a given corner and data entry id.
// The prediction is stored in |out_prediction|.
// Function returns false when the prediction couldn't be computed, e.g. because
// not all entry points were available.
template <class CornerTableT, typename DataTypeT>
inline 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) {
  const CornerIndex oci = table->Opposite(ci);
  if (oci == kInvalidCornerIndex) {
    return false;
  }
  int vert_opp, vert_next, vert_prev;
  GetParallelogramEntries<CornerTableT>(oci, table, vertex_to_data_map,
                                        &vert_opp, &vert_next, &vert_prev);
  if (vert_opp < data_entry_id && vert_next < data_entry_id &&
      vert_prev < data_entry_id) {
    // Apply the parallelogram prediction.
    const int v_opp_off = vert_opp * num_components;
    const int v_next_off = vert_next * num_components;
    const int v_prev_off = vert_prev * num_components;
    for (int c = 0; c < num_components; ++c) {
      out_prediction[c] = (in_data[v_next_off + c] + in_data[v_prev_off + c]) -
                          in_data[v_opp_off + c];
    }
    return true;
  }
  return false;  // Not all data is available for prediction
}

}  // namespace draco

#endif  // DRACO_COMPRESSION_ATTRIBUTES_PREDICTION_SCHEMES_MESH_PREDICTION_SCHEME_PARALLELOGRAM_SHARED_H_