14 #include <boost/graph/graph_traits.hpp>
15 #include <boost/graph/properties.hpp>
27 #pragma warning(disable : 4146 26812 26451)
45 typename HalfedgeGraph,
62 std::ofstream csv_file;
63 csv_file.open(csv_file_path);
65 <<
"NUM_BATCH,SIZE_BITMASK,SIZE_CONNECTIVITY,SIZE_RESIDUALS,BITMASK_"
66 "ENTROPY,CONNECTIVITY_ENTROPY,RESIDUALS_ENTROPY,DISTORTION_RMSE,"
67 "DISTORTION_HAUSDORFF,NBVALUESBITMASK,NBVALUESCONNECTIVITY,NBVALUESOTHERINFO,"
68 "SIZEOTHERINFO,ENTROPYOTHERINFO,SIZE_HEADER,NUM_VERTICES"
76 std::pair< int, double > &data_bitmask,
77 std::pair< int, double > &data_connectivity,
78 std::pair< int, double > &data_residuals,
79 std::pair< int, double > &data_other_info,
81 double dist_hausdorff,
82 size_t num_values_bitmask,
83 size_t num_values_connectivity,
84 size_t num_values_other_info,
88 std::ofstream csv_file;
90 csv_file.open(csv_file_path, std::ofstream::app);
91 csv_file << num_batch <<
"," << data_bitmask.first <<
","
92 << data_connectivity.first <<
"," << data_residuals.first <<
","
93 << data_bitmask.second <<
"," << data_connectivity.second <<
","
94 << data_residuals.second <<
"," << dist_RMSE <<
"," << dist_hausdorff <<
","
95 << num_values_bitmask <<
"," << num_values_connectivity <<
","
96 << num_values_other_info <<
"," << data_other_info.first <<
","
97 << data_other_info.second <<
"," << size_header <<
","
108 draco::EncoderBuffer &buffer
112 auto faces_pair =
faces(g);
113 auto num_faces_ = std::distance(faces_pair.first, faces_pair.second);
114 auto num_positions_ =
115 std::distance(iterator_pair.first, iterator_pair.second);
116 size_t original_size = buffer.size();
122 g_draco.SetNumFaces(num_faces_);
123 draco::PointCloud *out_point_cloud_ =
124 static_cast< draco::PointCloud *
>(&
g_draco);
125 out_point_cloud_->set_num_points(
126 3 *
static_cast<unsigned int>(num_faces_));
128 draco::GeometryAttribute va;
129 va.Init(draco::GeometryAttribute::POSITION,
136 int pos_att_id_ = out_point_cloud_->AddAttribute(va,
false,
static_cast<unsigned int>(num_positions_));
139 std::map< vertex_descriptor, int > vertex_pos;
142 auto vi = iterator_pair.first;
143 std::vector< uint32_t > vertex_data;
144 vertex_data.reserve(num_positions_ * 3);
145 for( ; vi != iterator_pair.second; ++vi, ++pos_num)
147 vertex_pos.insert(std::pair< vertex_descriptor, int >(*vi, pos_num));
150 val[0] =
static_cast< uint32_t
>(gt.get_x(pos));
151 val[1] =
static_cast< uint32_t
>(gt.get_y(pos));
152 val[2] =
static_cast< uint32_t
>(gt.get_z(pos));
153 vertex_data.push_back(val[0]);
154 vertex_data.push_back(val[1]);
155 vertex_data.push_back(val[2]);
156 out_point_cloud_->attribute(pos_att_id_)
157 ->SetAttributeValue(draco::AttributeValueIndex(pos_num), val);
162 auto iterator_pair_f =
faces(g);
163 auto fi = iterator_pair_f.first;
164 for( ; fi != iterator_pair_f.second; ++fi, ++pos_face)
166 std::vector< vertex_descriptor > vertices_of_face;
167 vertices_of_face.reserve(3);
168 boost::iterator_range<
169 CGAL::Vertex_around_face_iterator< HalfedgeGraph > >
170 iterator_range_vf = CGAL::vertices_around_face(
halfedge(*fi, g), g);
171 for(
auto vf : iterator_range_vf)
172 vertices_of_face.push_back(vf);
173 for(
int i = 0; i < 3; ++i)
175 const draco::PointIndex vert_id(3 * pos_face + i);
177 int vertex_id = (vertex_pos.find(vertex))->second;
178 out_point_cloud_->attribute(pos_att_id_)
179 ->SetPointMapEntry(vert_id, draco::AttributeValueIndex(vertex_id));
182 draco::Mesh::Face
face;
183 for(draco::FaceIndex i(0); i < static_cast<uint32_t>(num_faces_); ++i)
185 for(
int c = 0; c < 3; ++c)
186 face[c] = 3 * i.value() + c;
190 draco::Encoder encoder;
192 encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, -1);
193 const draco::Status status = encoder.EncodeMeshToBuffer(
g_draco, &buffer);
195 return (buffer.size() - original_size) * 8;
200 draco::EncoderBuffer &buffer)
202 draco::RAnsBitEncoder encoder;
203 int size_buffer =
static_cast< int >(buffer.size());
204 draco::EncodeVarint((
int)bitmask.size(), &buffer);
207 encoder.StartEncoding();
208 auto it = bitmask.begin(), it_e = bitmask.end();
209 for( ; it != it_e; ++it)
211 encoder.EncodeBit(*it);
217 encoder.EndEncoding(&buffer);
219 double bitmask_entropy = draco::ComputeBinaryShannonEntropy(
220 static_cast< uint32_t
>(bitmask.size()), nb_true);
222 return std::make_pair(
static_cast< int >((buffer.size()) - size_buffer) * 8,
227 std::pair< int, double >
229 draco::EncoderBuffer &buffer,
230 int bit_quantization)
232 int size_buffer =
static_cast< int >(buffer.size());
233 draco::EncodeVarint((
int)residuals.size(), &buffer);
234 if((
int)residuals.size() > 0)
236 size_t nb_residuals = residuals.front().size();
240 int32_t *p_in =
new int32_t[residuals.size() * nb_residuals * 3];
241 uint32_t *p_out =
new uint32_t[residuals.size() * nb_residuals * 3];
243 auto residuals_it = residuals.begin(), residuals_it_e = residuals.end();
245 for( ; residuals_it != residuals_it_e; ++residuals_it, ++i)
247 for(
size_t j = 0; j < nb_residuals; j++)
250 int32_t x =
static_cast< int32_t
>(((*residuals_it)[j])[0]);
251 int32_t y =
static_cast< int32_t
>(((*residuals_it)[j])[1]);
252 int32_t z =
static_cast< int32_t
>(((*residuals_it)[j])[2]);
254 p_in[nb_residuals * 3 * i + 3 * j + 0] = x;
255 p_in[nb_residuals * 3 * i + 3 * j + 1] = y;
256 p_in[nb_residuals * 3 * i + 3 * j + 2] = z;
259 draco::ConvertSignedIntsToSymbols(
260 p_in,
static_cast< int >(residuals.size() * nb_residuals * 3), p_out);
263 for(
size_t i = 0; i < residuals.size() * nb_residuals * 3; i++)
270 auto stream_2_entropy_bits = draco::ComputeShannonEntropy(
272 static_cast< int >(residuals.size() * nb_residuals * 3),
282 draco::SymbolBitEncoder symbolBitEncoder;
283 symbolBitEncoder.StartEncoding();
284 for(
size_t count = 0; count < residuals.size() * nb_residuals * 3; count++)
287 symbolBitEncoder.EncodeLeastSignificantBits32(bit_quantization + 1,
291 symbolBitEncoder.EndEncoding(&buffer);
293 size_t num_values = residuals.size() * nb_residuals * 3;
294 int num_values_int = (int)num_values;
295 draco::EncoderBuffer buffer_max_comp;
297 draco::Options *opt =
new draco::Options();
298 draco::SetSymbolEncodingCompressionLevel(opt,
static_cast< int >(10));
299 draco::EncodeSymbols(p_out, num_values_int, 1, opt, &buffer_max_comp);
300 int size_original_method =
301 (
static_cast< int >(buffer.size()) - size_buffer) * 8;
305 return std::make_pair(size_original_method, stream_2_entropy_bits /
static_cast<double>(residuals.size() * nb_residuals * 3));
307 return std::make_pair(0, 0);