MEPP2 Project
Header_handler.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 
12 #pragma once
13 
15 
16 #include <iostream>
17 #include <vector>
18 #include <fstream>
19 #include <string>
20 
21 #ifdef _MSC_VER
22 #pragma warning(push)
23 #pragma warning(disable : 4146 26812 26451)
24 #endif
25 
27 
28 #if defined _MSC_VER
29 #pragma warning(pop)
30 #endif
31 
32 namespace FEVV {
33 
35 {
36 public:
37  Header_handler(const std::vector< double >& dimension,
38  const std::vector< double >& init_coord,
41  int bit_quantization)
42  {
43  _dimension = dimension;
44  _init_coord = init_coord;
45  _vkept = vkept;
46  _pred = pred;
47  _bit_quantization = bit_quantization;
48  };
49 
51  {
52  _bit_quantization = 16;
53  _vkept = FEVV::Filters::VKEPT_POSITION::MIDPOINT;
55  };
57 
58  void encode_text_header(std::ofstream& file_encode)
59  {
60  unsigned int kept_int = static_cast< unsigned int >(_vkept);
61  file_encode << (kept_int) << std::endl;
62  unsigned int prediction_int = static_cast< unsigned int >(_pred);
63  file_encode << prediction_int << std::endl;
64  unsigned int quantif = static_cast< unsigned int >(_bit_quantization);
65  file_encode << quantif << std::endl;
66 
67  for(size_t i = 0; i < 3; i++)
68  {
69  file_encode << _dimension[i] << std::endl;
70  }
71  for(size_t i = 0; i < 3; i++)
72  {
73  file_encode << _init_coord[i] << std::endl;
74  }
75  }
76 
77  void decode_text_header(std::ifstream &file_decode)
78  {
79  if(file_decode)
80  {
81  std::string current_line;
82  getline(file_decode, current_line, '\n');
83  _vkept =
84  static_cast< FEVV::Filters::VKEPT_POSITION >(std::stoi(current_line));
85  getline(file_decode, current_line, '\n');
86  _pred = static_cast< FEVV::Filters::PREDICTION_TYPE >(
87  std::stoi(current_line));
88  getline(file_decode, current_line, '\n');
89  _bit_quantization = std::stoi(current_line);
90  for(size_t i = 0; i < 3; i++)
91  {
92  getline(file_decode, current_line, '\n');
93  _dimension.push_back(std::stod(current_line));
94  }
95  for(size_t i = 0; i < 3; i++)
96  {
97  getline(file_decode, current_line, '\n');
98  _init_coord.push_back(std::stod(current_line));
99  }
100  }
101  }
102 
105  size_t encode_binary_header(draco::EncoderBuffer& buffer
106  )
107  {
108  int vkept_position = static_cast< int >(_vkept);
109  int prediction_type = static_cast< int >(_pred);
110  draco::EncodeVarint(vkept_position, &buffer);
111  draco::EncodeVarint(prediction_type, &buffer);
112  draco::EncodeVarint(_bit_quantization, &buffer);
113  buffer.Encode(_dimension[0]);
114  buffer.Encode(_dimension[1]);
115  buffer.Encode(_dimension[2]);
116  buffer.Encode(_init_coord[0]);
117  buffer.Encode(_init_coord[1]);
118  buffer.Encode(_init_coord[2]);
119 
120  std::list< char > file_buffer;
121  file_buffer.insert(file_buffer.begin(),
122  (buffer.buffer())->begin(),
123  (buffer.buffer())->end());
124  size_t size_header = file_buffer.size() * 8;
125  return size_header;
126  }
127 
128  bool getUseTexture() const
129  { return false;
130  }
133  void decode_binary_header(draco::DecoderBuffer &buffer)
134  {
135  int vk;
136  draco::DecodeVarint(&vk, &buffer);
137  _vkept = static_cast< FEVV::Filters::VKEPT_POSITION >(vk);
138  int pred;
139  draco::DecodeVarint(&pred, &buffer);
140  _pred = static_cast< FEVV::Filters::PREDICTION_TYPE >(pred);
141  draco::DecodeVarint(&_bit_quantization, &buffer);
142  for(size_t i = 0; i < 3; i++)
143  {
144  double curr;
145  buffer.Decode(&curr);
146  _dimension.push_back(curr);
147  }
148  for(size_t i = 0; i < 3; i++)
149  {
150  double curr;
151  buffer.Decode(&curr);
152  _init_coord.push_back(curr);
153  }
154  }
155 
156 
159  int get_quantization() const { return _bit_quantization; }
160  const std::vector< double >& get_dimension() const { return _dimension; }
161  const std::vector< double >& get_init_coord() const { return _init_coord; }
162 
163 private:
164  std::vector< double > _dimension;
165  std::vector< double > _init_coord;
169 };
170 
171 } // namespace FEVV
FEVV::Header_handler::get_pred
FEVV::Filters::PREDICTION_TYPE get_pred() const
Definition: Header_handler.h:158
FEVV::Header_handler::get_init_coord
const std::vector< double > & get_init_coord() const
Definition: Header_handler.h:161
Parameters.h
FEVV::Header_handler::getUseTexture
bool getUseTexture() const
Definition: Header_handler.h:128
FEVV::Header_handler::get_quantization
int get_quantization() const
Definition: Header_handler.h:159
FEVV::Filters::PREDICTION_TYPE
PREDICTION_TYPE
Definition: Parameters.h:19
FEVV::Header_handler::get_dimension
const std::vector< double > & get_dimension() const
Definition: Header_handler.h:160
FEVV::Header_handler::_pred
FEVV::Filters::PREDICTION_TYPE _pred
Definition: Header_handler.h:167
FEVV::Header_handler::_dimension
std::vector< double > _dimension
Definition: Header_handler.h:164
FEVV::Header_handler::decode_text_header
void decode_text_header(std::ifstream &file_decode)
Definition: Header_handler.h:77
Header_handler_draco_nowarning.h
FEVV::Header_handler::get_vkept
FEVV::Filters::VKEPT_POSITION get_vkept() const
Definition: Header_handler.h:157
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Header_handler::_bit_quantization
int _bit_quantization
Definition: Header_handler.h:168
FEVV::Filters::VKEPT_POSITION
VKEPT_POSITION
Definition: Parameters.h:28
FEVV::Header_handler::decode_binary_header
void decode_binary_header(draco::DecoderBuffer &buffer)
Definition: Header_handler.h:133
FEVV::Header_handler::_vkept
FEVV::Filters::VKEPT_POSITION _vkept
Definition: Header_handler.h:166
FEVV::Header_handler::_init_coord
std::vector< double > _init_coord
Definition: Header_handler.h:165
FEVV::Header_handler::Header_handler
Header_handler(const std::vector< double > &dimension, const std::vector< double > &init_coord, FEVV::Filters::VKEPT_POSITION vkept, FEVV::Filters::PREDICTION_TYPE pred, int bit_quantization)
Definition: Header_handler.h:37
FEVV::Header_handler
Definition: Header_handler.h:35
FEVV::Header_handler::encode_text_header
void encode_text_header(std::ofstream &file_encode)
Definition: Header_handler.h:58
FEVV::Header_handler::encode_binary_header
size_t encode_binary_header(draco::EncoderBuffer &buffer)
Definition: Header_handler.h:105
FEVV::Header_handler::~Header_handler
~Header_handler()
Definition: Header_handler.h:56
FEVV::Header_handler::Header_handler
Header_handler()
Definition: Header_handler.h:50
FEVV::Filters::PREDICTION_TYPE::POSITION
@ POSITION