57 std::cout <<
timestamp <<
"Load HDF5 file structure..." << std::endl;
66 std::string extension = selectedFile.extension().string();
68 HDF5MeshToolIO hdf5In;
69 bool readFromHdf5 =
false;
72 if (extension ==
".h5")
75 if (hdf5In.m_hdf5_file->isValid())
79 meshBuffer = hdf5In.loadMesh(
options.getMeshName());
84 meshBuffer = model->m_mesh;
87 if (meshBuffer !=
nullptr)
90 size_t numFaces = meshBuffer->
numFaces();
91 size_t numVertices = meshBuffer->numVertices();
92 std::cout <<
timestamp <<
"Building mesh from buffers with " << numFaces
93 <<
" faces and " << numVertices <<
" vertices..." << std::endl;
95 floatArr vertices = meshBuffer->getVertices();
96 indexArray indices = meshBuffer->getFaceIndices();
98 for(
size_t i = 0; i < numVertices; i++)
107 size_t invalid_face_cnt = 0;
108 for(
size_t i = 0; i < numFaces; i++) {
123 bool writeToHdf5Input =
false;
127 writeToHdf5Input =
true;
133 hdf5.setMeshName(
options.getMeshName());
137 boost::optional<DenseFaceMap<Normal<float>>> faceNormalsOpt;
144 std::cout <<
timestamp <<
"Using existing face normals..." << std::endl;
145 faceNormals = *faceNormalsOpt;
149 std::cout <<
timestamp <<
"Computing face normals..." << std::endl;
152 if(
options.getEdgeCollapseNum() > 0)
154 double percent =
options.getEdgeCollapseNum() > 100 ? 1 :
options.getEdgeCollapseNum() / 100.0;
155 size_t numCollapse =
static_cast<size_t>(percent * hem.
numEdges());
156 std::cout <<
timestamp <<
"Reduce mesh by collapsing " << percent * 100
157 <<
"% of the edges (" << numCollapse <<
" out of " << hem.
numEdges() <<
")" << std::endl;
162 if(
options.getEdgeCollapseNum() > 0 || !writeToHdf5Input)
164 std::cout <<
timestamp <<
"Adding mesh to file..." << std::endl;
166 bool addedMesh = hdf5.addMesh(hem);
169 std::cout <<
timestamp <<
"successfully added mesh" << std::endl;
173 std::cout <<
timestamp <<
"could not add the mesh!" << std::endl;
178 std::cout <<
timestamp <<
"Mesh already included." << std::endl;
182 if(!faceNormalsOpt ||
options.getEdgeCollapseNum() > 0 || !writeToHdf5Input)
185 hem, faceNormals,
"face_normals");
188 std::cout <<
timestamp <<
"successfully added face normals" << std::endl;
192 std::cout <<
timestamp <<
"could not add face normals!" << std::endl;
197 std::cout <<
timestamp <<
"Face normals already included." << std::endl;
202 boost::optional<DenseVertexMap<Normal<float>>> vertexNormalsOpt;
207 if (vertexNormalsOpt)
209 std::cout <<
timestamp <<
"Using existing vertex normals..." << std::endl;
210 vertexNormals = *vertexNormalsOpt;
212 else if (meshBuffer !=
nullptr && meshBuffer->hasVertexNormals())
214 std::cout <<
timestamp <<
"Using existing vertex normals from mesh buffer..." << std::endl;
216 if (channel_opt && channel_opt.get().width() == 3 and channel_opt.get().numElements() == hem.
numVertices())
218 auto &channel = channel_opt.get();
219 vertexNormals.
reserve(channel.numElements());
220 for (
size_t i = 0; i < channel.numElements(); i++)
227 std::cerr <<
timestamp <<
"Error while reading vertex normals..." << std::endl;
233 std::cout <<
timestamp <<
"Computing vertex normals..." << std::endl;
236 if (!vertexNormalsOpt || !writeToHdf5Input)
238 std::cout <<
timestamp <<
"Adding vertex normals..." << std::endl;
240 hem, vertexNormals,
"vertex_normals");
241 if (addedVertexNormals)
243 std::cout <<
timestamp <<
"successfully added vertex normals" << std::endl;
247 std::cout <<
timestamp <<
"could not add vertex normals!" << std::endl;
252 std::cout <<
timestamp <<
"Vertex normals already included." << std::endl;
256 using color = std::array<uint8_t, 3>;
258 boost::optional<DenseVertexMap<color>> colorsOpt;
266 std::cout <<
timestamp <<
"Using existing vertex colors..." << std::endl;
269 else if (meshBuffer !=
nullptr && (channel_opt = meshBuffer->getChannel<uint8_t>(
"vertex_colors"))
270 && channel_opt && channel_opt.get().width() == 3 && channel_opt.get().numElements() == hem.
numVertices()) {
271 std::cout <<
timestamp <<
"Using existing colors from mesh buffer..." << std::endl;
273 auto &channel = channel_opt.get();
274 colors.reserve(channel.numElements());
275 for (
size_t i = 0; i < channel.numElements(); i++)
280 if (!colorsOpt || !writeToHdf5Input)
282 std::cout <<
timestamp <<
"Adding vertex colors..." << std::endl;
284 hem,
colors,
"vertex_colors");
285 if (addedVertexColors)
287 std::cout <<
timestamp <<
"successfully added vertex colors" << std::endl;
291 std::cout <<
timestamp <<
"could not add vertex colors!" << std::endl;
296 std::cout <<
timestamp <<
"Vertex colors already included." << std::endl;
302 boost::optional<DenseVertexMap<float>> averageAnglesOpt;
307 if (averageAnglesOpt)
309 std::cout <<
timestamp <<
"Using existing vertex average angles..." << std::endl;
310 averageAngles = *averageAnglesOpt;
314 std::cout <<
timestamp <<
"Computing vertex average angles..." << std::endl;
317 if (!averageAnglesOpt || !writeToHdf5Input)
319 std::cout <<
timestamp <<
"Adding vertex average angles..." << std::endl;
321 hem, averageAngles,
"average_angles");
322 if (addedAverageAngles)
324 std::cout <<
timestamp <<
"successfully added vertex average angles" << std::endl;
328 std::cout <<
timestamp <<
"could not add vertex average angles!" << std::endl;
333 std::cout <<
timestamp <<
"Vertex average angles already included." << std::endl;
338 boost::optional<DenseVertexMap<float>> roughnessOpt;
345 std::cout <<
timestamp <<
"Using existing roughness..." << std::endl;
346 roughness = *roughnessOpt;
350 std::cout <<
timestamp <<
"Computing roughness with a local radius of "
351 <<
options.getLocalRadius() <<
"m ..." << std::endl;
354 if (!roughnessOpt || !writeToHdf5Input)
356 std::cout <<
timestamp <<
"Adding roughness..." << std::endl;
358 hem, roughness,
"roughness");
361 std::cout <<
timestamp <<
"successfully added roughness." << std::endl;
365 std::cout <<
timestamp <<
"could not add roughness!" << std::endl;
370 std::cout <<
timestamp <<
"Roughness already included." << std::endl;
375 boost::optional<DenseVertexMap<float>> heightDifferencesOpt;
380 if (heightDifferencesOpt)
382 std::cout <<
timestamp <<
"Using existing height differences..." << std::endl;
383 heightDifferences = *heightDifferencesOpt;
387 std::cout <<
timestamp <<
"Computing height diff with a local radius of "
388 <<
options.getLocalRadius() <<
"m ..." << std::endl;
391 if (!heightDifferencesOpt || !writeToHdf5Input)
393 std::cout <<
timestamp <<
"Adding roughness..." << std::endl;
395 hem, heightDifferences,
"height_diff");
398 std::cout <<
timestamp <<
"successfully added height differences." << std::endl;
402 std::cout <<
timestamp <<
"could not add height differences!" << std::endl;
407 std::cout <<
timestamp <<
"Height differences already included." << std::endl;
412 std::cout <<
timestamp <<
"Error reading mesh data from "