DGtal  1.5.beta
digitalPolyhedronBuilder3D.cpp File Reference
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/viewers/Viewer3D.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

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

Typedefs

typedef Z3i::Space Space
 
typedef Z3i::Integer Integer
 
typedef Z3i::KSpace KSpace
 
typedef Z3i::Domain Domain
 
typedef Z3i::SCell SCell
 
typedef Space::Point Point
 
typedef Space::RealPoint RealPoint
 
typedef Space::RealVector RealVector
 
typedef Space::Vector Vector
 
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.

◆ KSpace

Definition at line 77 of file digitalPolyhedronBuilder3D.cpp.

◆ Point

Definition at line 80 of file digitalPolyhedronBuilder3D.cpp.

◆ PointRange

◆ RealPoint

Definition at line 81 of file digitalPolyhedronBuilder3D.cpp.

◆ RealVector

◆ SCell

◆ Space

typedef Z3i::Space Space

Definition at line 75 of file digitalPolyhedronBuilder3D.cpp.

◆ Vector

Definition at line 83 of file digitalPolyhedronBuilder3D.cpp.

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  QApplication application(argc,argv);
108  typedef Viewer3D<Space,KSpace> MViewer;
109  MViewer viewer;
110  viewer.setWindowTitle("digitalPolyhedronBuilder3D");
111  viewer.show();
112 
113  Point lo(-500,-500,-500);
114  Point up(500,500,500);
115  DigitalConvexity< KSpace > dconv( lo, up );
117 
118  auto vertices = std::vector<Point>( surfmesh.nbVertices() );
119  for ( auto v : surfmesh )
120  {
121  RealPoint p = (1.0 / h) * surfmesh.position( v );
122  Point q ( (Integer) round( p[ 0 ] ),
123  (Integer) round( p[ 1 ] ),
124  (Integer) round( p[ 2 ] ) );
125  vertices[ v ] = q;
126  }
127  std::set< Point > faces_set, edges_set;
128  auto faceVertices = surfmesh.allIncidentVertices();
129  auto edgeVertices = surfmesh.allEdgeVertices();
130 
131  trace.beginBlock( "Computing polyhedron" );
132  for ( int f = 0; f < surfmesh.nbFaces(); ++f )
133  {
134  PointRange X;
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() );
139  }
140  for ( int e = 0; e < surfmesh.nbEdges(); ++e )
141  {
142  PointRange X =
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() );
147  }
148  trace.endBlock();
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;
163 
164  // display everything
165  Color colors[] = { Color::Black, Color( 100, 100, 100 ), Color( 200, 200, 200 ) };
166  if ( view & 0x1 )
167  {
168  viewer.setLineColor( colors[ 0 ] );
169  viewer.setFillColor( colors[ 0 ] );
170  for ( auto p : vertices ) viewer << p;
171  }
172  if ( view & 0x2 )
173  {
174  viewer.setLineColor( colors[ 1 ] );
175  viewer.setFillColor( colors[ 1 ] );
176  for ( auto p : edge_points ) viewer << p;
177  }
178  if ( view & 0x4 )
179  {
180  viewer.setLineColor( colors[ 2 ] );
181  viewer.setFillColor( colors[ 2 ] );
182  for ( auto p : face_points ) viewer << p;
183  }
184  viewer << MViewer::updateDisplay;
185  return application.exec();
186 
187 }
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
PointRange envelope(const PointRange &Z, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
SurfMesh surfmesh
std::vector< Point > PointRange
Trace trace
Definition: Common.h:153
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
Aim: An helper class for reading mesh files (Wavefront OBJ at this point) and creating a SurfaceMesh.
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition: SurfaceMesh.h:92
RealPoint & position(Vertex v)
Definition: SurfaceMesh.h:647
const std::vector< VertexPair > & allEdgeVertices() const
Definition: SurfaceMesh.h:391
Size nbFaces() const
Definition: SurfaceMesh.h:296
Size nbEdges() const
Definition: SurfaceMesh.h:292
const std::vector< Vertices > & allIncidentVertices() const
Definition: SurfaceMesh.h:371
Size nbVertices() const
Definition: SurfaceMesh.h:288
MyPointD Point
Definition: testClone2.cpp:383

References DGtal::SurfaceMesh< TRealPoint, TRealVector >::allEdgeVertices(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::allIncidentVertices(), DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::DigitalConvexity< TKSpace >::envelope(), DGtal::Trace::error(), DGtal::Trace::info(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::nbEdges(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::nbFaces(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::nbVertices(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::position(), DGtal::Viewer3D< TSpace, TKSpace >::show(), surfmesh, and DGtal::trace.