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

encode_base.h « compression « draco « src « draco « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c63a972bf46c0f273a168e8f86b6d147b14927b (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2017 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.
//
#ifndef DRACO_SRC_DRACO_COMPRESSION_ENCODE_BASE_H_
#define DRACO_SRC_DRACO_COMPRESSION_ENCODE_BASE_H_

#include "draco/attributes/geometry_attribute.h"
#include "draco/compression/config/compression_shared.h"
#include "draco/core/status.h"

namespace draco {

// Base class for our geometry encoder classes. |EncoderOptionsT| specifies
// options class used by the encoder. Please, see encode.h and expert_encode.h
// for more details and method descriptions.
template <class EncoderOptionsT>
class EncoderBase {
 public:
  typedef EncoderOptionsT OptionsType;

  EncoderBase()
      : options_(EncoderOptionsT::CreateDefaultOptions()),
        num_encoded_points_(0),
        num_encoded_faces_(0) {}
  virtual ~EncoderBase() {}

  const EncoderOptionsT &options() const { return options_; }
  EncoderOptionsT &options() { return options_; }

  // If enabled, it tells the encoder to keep track of the number of encoded
  // points and faces (default = false).
  // Note that this can slow down encoding for certain encoders.
  void SetTrackEncodedProperties(bool flag);

  // Returns the number of encoded points and faces during the last encoding
  // operation. Returns 0 if SetTrackEncodedProperties() was not set.
  size_t num_encoded_points() const { return num_encoded_points_; }
  size_t num_encoded_faces() const { return num_encoded_faces_; }

 protected:
  void Reset(const EncoderOptionsT &options) { options_ = options; }

  void Reset() { options_ = EncoderOptionsT::CreateDefaultOptions(); }

  void SetSpeedOptions(int encoding_speed, int decoding_speed) {
    options_.SetSpeed(encoding_speed, decoding_speed);
  }

  void SetEncodingMethod(int encoding_method) {
    options_.SetGlobalInt("encoding_method", encoding_method);
  }

  void SetEncodingSubmethod(int encoding_submethod) {
    options_.SetGlobalInt("encoding_submethod", encoding_submethod);
  }

  Status CheckPredictionScheme(GeometryAttribute::Type att_type,
                               int prediction_scheme) const {
    // Out of bound checks:
    if (prediction_scheme < PREDICTION_NONE) {
      return Status(Status::DRACO_ERROR,
                    "Invalid prediction scheme requested.");
    }
    if (prediction_scheme >= NUM_PREDICTION_SCHEMES) {
      return Status(Status::DRACO_ERROR,
                    "Invalid prediction scheme requested.");
    }
    // Deprecated prediction schemes:
    if (prediction_scheme == MESH_PREDICTION_TEX_COORDS_DEPRECATED) {
      return Status(Status::DRACO_ERROR,
                    "MESH_PREDICTION_TEX_COORDS_DEPRECATED is deprecated.");
    }
    if (prediction_scheme == MESH_PREDICTION_MULTI_PARALLELOGRAM) {
      return Status(Status::DRACO_ERROR,
                    "MESH_PREDICTION_MULTI_PARALLELOGRAM is deprecated.");
    }
    // Attribute specific checks:
    if (prediction_scheme == MESH_PREDICTION_TEX_COORDS_PORTABLE) {
      if (att_type != GeometryAttribute::TEX_COORD) {
        return Status(Status::DRACO_ERROR,
                      "Invalid prediction scheme for attribute type.");
      }
    }
    if (prediction_scheme == MESH_PREDICTION_GEOMETRIC_NORMAL) {
      if (att_type != GeometryAttribute::NORMAL) {
        return Status(Status::DRACO_ERROR,
                      "Invalid prediction scheme for attribute type.");
      }
    }
    // TODO(hemmer): Try to enable more prediction schemes for normals.
    if (att_type == GeometryAttribute::NORMAL) {
      if (!(prediction_scheme == PREDICTION_DIFFERENCE ||
            prediction_scheme == MESH_PREDICTION_GEOMETRIC_NORMAL)) {
        return Status(Status::DRACO_ERROR,
                      "Invalid prediction scheme for attribute type.");
      }
    }
    return OkStatus();
  }

 protected:
  void set_num_encoded_points(size_t num) { num_encoded_points_ = num; }
  void set_num_encoded_faces(size_t num) { num_encoded_faces_ = num; }

 private:
  EncoderOptionsT options_;

  size_t num_encoded_points_;
  size_t num_encoded_faces_;
};

template <class EncoderOptionsT>
void EncoderBase<EncoderOptionsT>::SetTrackEncodedProperties(bool flag) {
  options_.SetGlobalBool("store_number_of_encoded_points", flag);
  options_.SetGlobalBool("store_number_of_encoded_faces", flag);
}

}  // namespace draco

#endif  // DRACO_SRC_DRACO_COMPRESSION_ENCODE_BASE_H_