File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
digitalPolyhedronBuilder3D.cpp File Reference
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/io/readers/SurfaceMeshReader.h"
#include "DGtal/geometry/volumes/DigitalConvexity.h"
#include "ConfigExamples.h"
Include dependency graph for digitalPolyhedronBuilder3D.cpp:

Go to the source code of this file.

Namespaces

namespace  DGtal
 DGtal is the top-level namespace which contains all DGtal functions and types.

Typedefs

typedef Z3i::Integer Integer
typedef Z3i::Domain Domain
typedef Z3i::SCell SCell
typedef std::vector< PointPointRange

Functions

int main (int argc, char **argv)

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2022/06/20

An example file named digitalPolyhedronBuilder3D

This file is part of the DGtal library.

Definition in file digitalPolyhedronBuilder3D.cpp.

Typedef Documentation

◆ Domain

Definition at line 78 of file digitalPolyhedronBuilder3D.cpp.

◆ Integer

Definition at line 76 of file digitalPolyhedronBuilder3D.cpp.

◆ PointRange

◆ SCell

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 86 of file digitalPolyhedronBuilder3D.cpp.

87{
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; //< vol filename
95 double h = argc > 2 ? atof( argv[ 2 ] ) : 1.0;
96 int view = argc > 3 ? atoi( argv[ 3 ] ) : 7;
97 // Read OBJ file
98 std::ifstream input( fn.c_str() );
101 if ( ! ok )
102 {
103 trace.error() << "Unable to read obj file : " << fn << std::endl;
104 return 1;
105 }
106
107 typedef PolyscopeViewer<Space,KSpace> MViewer;
108 MViewer viewer;
109
110 Point lo(-500,-500,-500);
111 Point up(500,500,500);
112 DigitalConvexity< KSpace > dconv( lo, up );
114
115 auto vertices = std::vector<Point>( surfmesh.nbVertices() );
116 for ( auto v : surfmesh )
117 {
118 RealPoint p = (1.0 / h) * surfmesh.position( v );
119 Point q ( (Integer) round( p[ 0 ] ),
120 (Integer) round( p[ 1 ] ),
121 (Integer) round( p[ 2 ] ) );
122 vertices[ v ] = q;
123 }
124 std::set< Point > faces_set, edges_set;
125 auto faceVertices = surfmesh.allIncidentVertices();
126 auto edgeVertices = surfmesh.allEdgeVertices();
127
128 trace.beginBlock( "Computing polyhedron" );
129 for ( int f = 0; f < surfmesh.nbFaces(); ++f )
130 {
131 PointRange X;
132 for ( auto v : faceVertices[ f ] )
133 X.push_back( vertices[ v ] );
134 auto F = dconv.envelope( X, Algorithm::DIRECT );
135 faces_set.insert( F.cbegin(), F.cend() );
136 }
137 for ( int e = 0; e < surfmesh.nbEdges(); ++e )
138 {
139 PointRange X =
140 { vertices[ edgeVertices[ e ].first ],
141 vertices[ edgeVertices[ e ].second ] };
142 auto E = dconv.envelope( X, Algorithm::DIRECT );
143 edges_set.insert( E.cbegin(), E.cend() );
144 }
145 trace.endBlock();
146 std::vector< Point > face_points, edge_points;
147 std::vector< Point > vertex_points = vertices;
148 std::sort( vertex_points.begin(), vertex_points.end() );
149 std::set_difference( faces_set.cbegin(), faces_set.cend(),
150 edges_set.cbegin(), edges_set.cend(),
151 std::back_inserter( face_points ) );
152 std::set_difference( edges_set.cbegin(), edges_set.cend(),
153 vertex_points.cbegin(), vertex_points.cend(),
154 std::back_inserter( edge_points ) );
155 auto total = vertex_points.size() + edge_points.size() + face_points.size();
156 trace.info() << "#vertex points=" << vertex_points.size() << std::endl;
157 trace.info() << "#edge points=" << edge_points.size() << std::endl;
158 trace.info() << "#face points=" << face_points.size() << std::endl;
159 trace.info() << "#total points=" << total << std::endl;
160
161 // display everything
162 Color colors[] = { Color::Black, Color( 100, 100, 100 ), Color( 200, 200, 200 ) };
163 if ( view & 0x1 )
164 {
165 viewer.drawColor( colors[ 0 ] );
166 viewer.drawColor( colors[ 0 ] );
167 for ( auto p : vertices ) viewer << p;
168 }
169 if ( view & 0x2 )
170 {
171 viewer.drawColor( colors[ 1 ] );
172 viewer.drawColor( colors[ 1 ] );
173 for ( auto p : edge_points ) viewer << p;
174 }
175 if ( view & 0x4 )
176 {
177 viewer.drawColor( colors[ 2 ] );
178 viewer.drawColor( colors[ 2 ] );
179 for ( auto p : face_points ) viewer << p;
180 }
181
182 viewer.show();
183 return 0;
184
185}
Structure representing an RGB triple with alpha component.
Definition Color.h:77
static const Color Black
Definition Color.h:422
SurfMesh surfmesh
std::vector< Point > PointRange
Trace trace
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
static bool readOBJ(std::istream &input, SurfaceMesh &smesh)
PointVector< 3, double > RealPoint

References DGtal::Color::Black, DGtal::SurfaceMeshReader< TRealPoint, TRealVector >::readOBJ(), surfmesh, and DGtal::trace.