57 std::cout <<
timestamp <<
"Load HDF5 file structure..." << std::endl;
65 boost::filesystem::path selectedFile(options.
getInputFile());
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())
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;
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;
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;
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;
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 " 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 " 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 "
size_t simpleMeshReduction(BaseMesh< BaseVecT > &mesh, const size_t count, FaceMap< Normal< typename BaseVecT::CoordType >> &faceNormals)
Like iterativeEdgeCollapse but with a fixed cost function.
size_t numVertices() const final
Returns the number of vertices in the mesh.
Handle to access vertices of the mesh.
const kaboom::Options * options
std::shared_ptr< MeshBuffer > MeshBufferPtr
DenseVertexMap< Normal< typename BaseVecT::CoordType > > calcVertexNormals(const BaseMesh< BaseVecT > &mesh, const FaceMap< Normal< typename BaseVecT::CoordType >> &normals, const PointsetSurface< BaseVecT > &surface)
Calculates a normal for each vertex in the mesh.
static Timestamp timestamp
A global time stamp object for program runtime measurement.
static ModelPtr readModel(std::string filename)
DenseFaceMap< Normal< typename BaseVecT::CoordType > > calcFaceNormals(const BaseMesh< BaseVecT > &mesh)
Calculates a normal for each face in the mesh.
void reserve(size_t newCap)
boost::optional< ValueT > insert(HandleT key, const ValueT &value) final
Inserts the given value at the given key position.
An exception denoting an internal bug.
FaceHandle addFace(VertexHandle v1H, VertexHandle v2H, VertexHandle v3H) final
Creates a face connecting the three given vertices.
boost::shared_array< unsigned int > indexArray
Manager Class for all Hdf5IO components located in hdf5 directory.
Hdf5IO Feature for handling MeshBuffer related IO.
boost::shared_array< float > floatArr
DenseVertexMap< float > calcAverageVertexAngles(const BaseMesh< BaseVecT > &mesh, const VertexMap< Normal< typename BaseVecT::CoordType >> &normals)
Calculates the average angle for each vertex.
Half-edge data structure implementing the BaseMesh interface.
size_t numFaces() const final
Returns the number of faces in the mesh.
size_t numEdges() const final
Returns the number of edges in the mesh.
DenseVertexMap< float > calcVertexHeightDifferences(const BaseMesh< BaseVecT > &mesh, double radius)
Calculate the height difference value for each vertex of the given BaseMesh.
FloatChannel::Optional FloatChannelOptional
Hdf5IO Feature for handling VariantChannel related IO.
std::shared_ptr< Model > ModelPtr
MeshBufferPtr loadMesh(std::string name)
A map with constant lookup overhead using small-ish integer-keys.
typename Channel< T >::Optional ChannelOptional
size_t numValues() const final
Returns the number of values in this map.
DenseVertexMap< float > calcVertexRoughness(const BaseMesh< BaseVecT > &mesh, double radius, const VertexMap< Normal< typename BaseVecT::CoordType >> &normals)
Calculates the roughness for each vertex.
VertexHandle addVertex(BaseVecT pos) final
Adds a vertex with the given position to the mesh.