62#include "DGtal/base/Common.h"
63#include "DGtal/helpers/StdDefs.h"
64#include "DGtal/io/viewers/Viewer3D.h"
65#include "DGtal/shapes/Shapes.h"
66#include "DGtal/shapes/SurfaceMesh.h"
67#include "DGtal/io/readers/SurfaceMeshReader.h"
68#include "DGtal/geometry/volumes/DigitalConvexity.h"
69#include "ConfigExamples.h"
86int main(
int argc,
char** argv )
88 trace.
info() <<
"Usage: " << argv[ 0 ] <<
" <input.obj> <h> <view>" << std::endl;
89 trace.
info() <<
"\tComputes a digital polyhedron from an OBJ file" << std::endl;
90 trace.
info() <<
"\t- input.obj: choose your favorite mesh" << std::endl;
91 trace.
info() <<
"\t- h [==1]: the digitization gridstep" << std::endl;
92 trace.
info() <<
"\t- view [==7]: display vertices(1), edges(2), faces(4)" << std::endl;
93 string filename = examplesPath +
"samples/lion.obj";
94 std::string fn = argc > 1 ? argv[ 1 ] : filename;
95 double h = argc > 2 ? atof( argv[ 2 ] ) : 1.0;
96 int view = argc > 3 ? atoi( argv[ 3 ] ) : 7;
98 std::ifstream input( fn.c_str() );
103 trace.
error() <<
"Unable to read obj file : " << fn << std::endl;
107 QApplication application(argc,argv);
110 viewer.setWindowTitle(
"digitalPolyhedronBuilder3D");
113 Point lo(-500,-500,-500);
114 Point up(500,500,500);
118 auto vertices = std::vector<Point>( surfmesh.
nbVertices() );
119 for (
auto v : surfmesh )
127 std::set< Point > faces_set, edges_set;
132 for (
int f = 0; f < surfmesh.
nbFaces(); ++f )
135 for (
auto v : faceVertices[ f ] )
136 X.push_back( vertices[ v ] );
137 auto F = dconv.
envelope( X, Algorithm::DIRECT );
138 faces_set.insert( F.cbegin(), F.cend() );
140 for (
int e = 0; e < surfmesh.
nbEdges(); ++e )
143 { vertices[ edgeVertices[ e ].first ],
144 vertices[ edgeVertices[ e ].second ] };
145 auto E = dconv.
envelope( X, Algorithm::DIRECT );
146 edges_set.insert( E.cbegin(), E.cend() );
149 std::vector< Point > face_points, edge_points;
150 std::vector< Point > vertex_points = vertices;
151 std::sort( vertex_points.begin(), vertex_points.end() );
152 std::set_difference( faces_set.cbegin(), faces_set.cend(),
153 edges_set.cbegin(), edges_set.cend(),
154 std::back_inserter( face_points ) );
155 std::set_difference( edges_set.cbegin(), edges_set.cend(),
156 vertex_points.cbegin(), vertex_points.cend(),
157 std::back_inserter( edge_points ) );
158 auto total = vertex_points.size() + edge_points.size() + face_points.size();
159 trace.
info() <<
"#vertex points=" << vertex_points.size() << std::endl;
160 trace.
info() <<
"#edge points=" << edge_points.size() << std::endl;
161 trace.
info() <<
"#face points=" << face_points.size() << std::endl;
162 trace.
info() <<
"#total points=" << total << std::endl;
168 viewer.setLineColor( colors[ 0 ] );
169 viewer.setFillColor( colors[ 0 ] );
170 for (
auto p : vertices ) viewer << p;
174 viewer.setLineColor( colors[ 1 ] );
175 viewer.setFillColor( colors[ 1 ] );
176 for (
auto p : edge_points ) viewer << p;
180 viewer.setLineColor( colors[ 2 ] );
181 viewer.setFillColor( colors[ 2 ] );
182 for (
auto p : face_points ) viewer << p;
184 viewer << MViewer::updateDisplay;
185 return application.exec();
Structure representing an RGB triple with alpha component.
PointRange envelope(const PointRange &Z, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
void beginBlock(const std::string &keyword="")
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
std::vector< Point > PointRange
Space::RealPoint RealPoint
Space::RealVector RealVector
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
static bool readOBJ(std::istream &input, SurfaceMesh &smesh)
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
const std::vector< Vertices > & allIncidentVertices() const
RealPoint & position(Vertex v)
const std::vector< VertexPair > & allEdgeVertices() const