It also shows how to export it as OBJ files.
#include <string>
#include <iostream>
#include <fstream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/shapes/Mesh.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/shapes/SurfaceMeshHelper.h"
#include "DGtal/shapes/MeshHelpers.h"
#include "DGtal/graph/BreadthFirstVisitor.h"
#include "DGtal/io/readers/SurfaceMeshReader.h"
#include "DGtal/io/writers/SurfaceMeshWriter.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
int main(
int argc,
char** argv )
{
trace.beginBlock (
"Reading a mesh OBJ file" );
std::string S = examplesPath + "samples/spot.obj";
std::ifstream input( S.c_str() );
input.close();
trace.info() <<
"Read " << ( ok_read ?
"OK" :
"ERROR" )
<< " mesh=" << smesh << std::endl;
trace.beginBlock (
"Building a torus" );
auto torus_mesh = Helper::makeTorus
( 2.5, 0.5,
RealPoint { 0.0, 0.0, 0.0 }, 40, 40, 0, Helper::NormalsType::NO_NORMALS );
trace.beginBlock (
"Building a pyramid" );
std::vector< RealPoint > positions =
{ { 0, 0, 5 }, { 1, 1, 3 }, { -1, 1, 3 }, { -1, -1, 3 }, { 1, -1, 3 } };
std::vector< Vertices > faces =
{ { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 4 }, { 0, 4, 1 }, { 4, 3, 2, 1 } };
auto pyramid_mesh =
SurfMesh( positions.cbegin(), positions.cend(),
faces.cbegin(), faces.cend() );
trace.beginBlock (
"Traversing a mesh by BF" );
std::vector<double> distances( smesh.nbVertices() );
double biggest_d = 0.0;
{
biggest_d = (double) d;
distances[ v ] = biggest_d;
}
trace.beginBlock (
"Colored output of BF traversal" );
auto face_distances = smesh.computeFaceValuesFromVertexValues( distances );
std::vector<Color> face_colors( smesh.nbFaces() );
for ( SurfMesh::Face j = 0; j < smesh.nbFaces(); ++j )
face_colors[ j ] = cmap( face_distances[ j ] );
Writer::writeOBJ( "spot-bft.obj", smesh, face_colors );
Writer::writeIsoLinesOBJ( "spot-iso-0_25.obj", smesh,
face_distances, distances, distances.back() * 0.25, 0.2 );
Writer::writeIsoLinesOBJ( "spot-iso-0_5.obj", smesh,
face_distances, distances, distances.back() * 0.5, 0.2 );
Writer::writeIsoLinesOBJ( "spot-iso-0_75.obj", smesh,
face_distances, distances, distances.back() * 0.75, 0.2 );
PolyscopeViewer<> viewer;
viewer << viewmesh << viewmesh2 << viewmesh3;
return 0;
}
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
const Node & current() const
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
static void surfaceMesh2Mesh(const SurfaceMesh< RealPoint, RealVector > &smesh, Mesh< RealPoint > &mesh, const std::vector< Color > &cols={})
void show() override
Starts the event loop and display of elements.
SurfaceMesh< RealPoint, RealVector > SurfMesh
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: An helper class for reading mesh files (Wavefront OBJ at this point) and creating a SurfaceMesh.
PointVector< 3, double > RealPoint