DGtal  1.5.beta
fullConvexitySphereGeodesics.cpp File Reference
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/io/writers/SurfaceMeshWriter.h"
#include "DGtal/geometry/volumes/TangencyComputer.h"
Include dependency graph for fullConvexitySphereGeodesics.cpp:

Go to the source code of this file.

Typedefs

typedef Z3i::Space Space
 
typedef Z3i::KSpace KSpace
 
typedef Z3i::Domain Domain
 
typedef Z3i::SCell SCell
 
typedef Shortcuts< KSpaceSH3
 
typedef Space::Point Point
 
typedef Space::RealPoint RealPoint
 
typedef Space::RealVector RealVector
 
typedef Space::Vector Vector
 
typedef SurfaceMesh< RealPoint, RealVectorSMesh
 
typedef SurfaceMeshWriter< RealPoint, RealVectorSMeshWriter
 
typedef SMesh::Index Index
 
typedef SMesh::Vertices Vertices
 

Functions

void saveToObj (const std::string &output, const SMesh &surfmesh, const std::vector< double > &vvalues, int nb_isolines_per_unit=10, const double thickness=0.1)
 
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/05/09

An example file named fullConvexitySphereGeodesics

This file is part of the DGtal library.

Definition in file fullConvexitySphereGeodesics.cpp.

Typedef Documentation

◆ Domain

Definition at line 108 of file fullConvexitySphereGeodesics.cpp.

◆ Index

◆ KSpace

Definition at line 107 of file fullConvexitySphereGeodesics.cpp.

◆ Point

Definition at line 111 of file fullConvexitySphereGeodesics.cpp.

◆ RealPoint

Definition at line 112 of file fullConvexitySphereGeodesics.cpp.

◆ RealVector

◆ SCell

typedef Z3i::SCell SCell

Definition at line 109 of file fullConvexitySphereGeodesics.cpp.

◆ SH3

typedef Shortcuts< KSpace > SH3

Definition at line 110 of file fullConvexitySphereGeodesics.cpp.

◆ SMesh

◆ SMeshWriter

◆ Space

typedef Z3i::Space Space

Definition at line 106 of file fullConvexitySphereGeodesics.cpp.

◆ Vector

Definition at line 114 of file fullConvexitySphereGeodesics.cpp.

◆ Vertices

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 158 of file fullConvexitySphereGeodesics.cpp.

159 {
160  trace.info() << "Usage: " << argv[ 0 ] << " <h> <opt>" << std::endl;
161  trace.info() << "\tComputes shortest paths to a source point on a sphere digitized with gridstep <h>." << std::endl;
162  trace.info() << "\t- h [==1.0]: digitization gridstep" << std::endl;
163  trace.info() << "\t- opt [==sqrt(3)]: >= sqrt(3): secure shortest paths, 0: fast" << std::endl;
164  double h = argc > 1 ? atof( argv[ 1 ] ) : 0.0625; //< exact (sqrt(3)) or inexact (0) computations
165  double opt = argc > 2 ? atof( argv[ 2 ] ) : sqrt(3.0); //< exact (sqrt(3)) or inexact (0) computations
166 
167  // Domain creation from two bounding points.
168  trace.beginBlock( "Building sphere1 shape ... " );
169  auto params = SH3::defaultParameters();
170  params( "polynomial", "sphere1" )( "gridstep", h );
171  params( "minAABB", -2)( "maxAABB", 2)( "offset", 1.0 )( "closed", 1 );
172  auto implicit_shape = SH3::makeImplicitShape3D ( params );
173  auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
174  auto K = SH3::getKSpace( params );
175  auto binary_image = SH3::makeBinaryImage(digitized_shape,
177  params );
178  trace.endBlock();
179 
180  trace.beginBlock( "Build mesh from primal surface" );
181  // Compute surface
182  auto surface = SH3::makeDigitalSurface( binary_image, K, params );
183  // Build a mesh
184  SMesh smesh;
185  auto embedder = SH3::getCellEmbedder( K );
186  std::vector< Point > lattice_points;
188  std::vector< Vertices > faces;
189  SH3::Cell2Index c2i;
190  auto pointels = SH3::getPointelRange( c2i, surface );
191  for ( auto p : pointels ) lattice_points.push_back( K.uCoords( p ) );
192  trace.info() << "#surfels =" << surface->size() << std::endl;
193  trace.info() << "#pointels=" << pointels.size() << std::endl;
194  vertices = SH3::RealPoints( pointels.size() );
195  std::transform( pointels.cbegin(), pointels.cend(), vertices.begin(),
196  [&] (const SH3::Cell& c) { return h * embedder( c ); } );
197  // Build faces
198  for ( auto&& surfel : *surface )
199  {
200  const auto primal_surfel_vtcs = SH3::getPointelRange( K, surfel );
201  std::vector< Index > face;
202  for ( auto&& primal_vtx : primal_surfel_vtcs )
203  face.push_back( c2i[ primal_vtx ] );
204  faces.push_back( face );
205  }
206  smesh.init( vertices.cbegin(), vertices.cend(),
207  faces.cbegin(), faces.cend() );
208  trace.info() << smesh << std::endl;
209  trace.endBlock();
210 
211  // Find lowest and uppest point.
212  const Index nb = lattice_points.size();
213  Index lowest = 0;
214  Index uppest = 0;
215  for ( Index i = 1; i < nb; i++ )
216  {
217  if ( lattice_points[ i ] < lattice_points[ lowest ] ) lowest = i;
218  if ( lattice_points[ uppest ] < lattice_points[ i ] ) uppest = i;
219  }
220 
221  // Extracts shortest paths to a target
223  trace.beginBlock( "Compute geodesics" );
225  TC.init( lattice_points.cbegin(), lattice_points.cend() );
226  auto SP = TC.makeShortestPaths( opt );
227  SP.init( lowest ); //< set source
228  double last_distance = 0.0;
229  Index last = 0;
230  while ( ! SP.finished() )
231  {
232  last = std::get<0>( SP.current() );
233  last_distance = std::get<2>( SP.current() );
234  SP.expand();
235  }
236  double time = trace.endBlock();
237  std::cout << "Max distance is " << last_distance*h << std::endl;
238  std::cout << "Comput. time is " << time << std::endl;
239  std::cout << "Last index is " << last << std::endl;
240  std::cout << "Uppest index is " << uppest << std::endl;
241 
242  // Export surface for display
243  std::vector<double> distances = SP.distances();
244  for ( Index i = 0; i < distances.size(); i++ )
245  distances[ i ] *= h;
246  saveToObj( "sphere1-geodesics", smesh, distances, 10, 0.1 );
247  return 0;
248 }
const Point & lowerBound() const
Return the lower bound for digital points in this space.
Point uCoords(const Cell &c) const
Return its digital coordinates.
const Point & upperBound() const
Return the upper bound for digital points in this space.
std::map< Cell, IdxVertex > Cell2Index
Definition: Shortcuts.h:189
std::vector< RealPoint > RealPoints
Definition: Shortcuts.h:180
LightDigitalSurface::Cell Cell
Definition: Shortcuts.h:162
Aim: A class that computes tangency to a given digital set. It provides services to compute all the c...
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
void saveToObj(const std::string &output, const SMesh &surfmesh, const std::vector< double > &vvalues, int nb_isolines_per_unit=10, const double thickness=0.1)
SMesh::Index Index
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: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition: SurfaceMesh.h:92
bool init(RealPointIterator itPos, RealPointIterator itPosEnd, VerticesIterator itVertices, VerticesIterator itVerticesEnd)
KSpace K

References DGtal::Trace::beginBlock(), binary_image, DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::init(), K, DGtal::KhalimskySpaceND< dim, TInteger >::lowerBound(), saveToObj(), surface, DGtal::trace, DGtal::KhalimskySpaceND< dim, TInteger >::uCoords(), and DGtal::KhalimskySpaceND< dim, TInteger >::upperBound().

◆ saveToObj()

void saveToObj ( const std::string &  output,
const SMesh surfmesh,
const std::vector< double > &  vvalues,
int  nb_isolines_per_unit = 10,
const double  thickness = 0.1 
)
Examples
geometry/volumes/fullConvexitySphereGeodesics.cpp.

Definition at line 120 of file fullConvexitySphereGeodesics.cpp.

125 {
126  std::string cobjname = output;
127  std::string cisoname = output + "-iso";
128  auto quantify = [] ( double v, double m, double nb )
129  { return round( v/m*nb )*m/nb; };
130  trace.beginBlock( "Output Corrected HD OBJ files" );
131  const auto fvalues = surfmesh.computeFaceValuesFromVertexValues( vvalues );
132  double maxValue = * ( std::max_element( vvalues.cbegin(), vvalues.cend() ) );
133  double minValue = * ( std::min_element( vvalues.cbegin(), vvalues.cend() ) );
134  double maxDist = maxValue - minValue;
135  trace.info() << "Max distance is " << maxDist << std::endl;
136  auto cmap = SH3::getColorMap( 0.0, maxDist );
137  std::vector< Color > fcolors( surfmesh.nbFaces() );
138  for ( Index f = 0; f < fvalues.size(); ++f )
139  fcolors[ f ] = cmap( quantify( fvalues[ f ] - minValue, maxDist, 50 ) );
140  SMeshWriter::writeOBJ( cobjname, surfmesh, fcolors );
141  double unit = pow( 10.0, floor( log( maxDist ) / log( 10.0 ) ) - 1.0 );
142  const int N = 10 * nb_isolines_per_unit;
143  std::vector< double > isolines( N );
144  std::vector< Color > isocolors( N );
145  for ( int i = 0; i < N; i++ )
146  {
147  isolines [ i ] = (double) i * 10.0 * unit / (double) nb_isolines_per_unit
148  + minValue;
149  isocolors[ i ] = ( i % nb_isolines_per_unit == 0 )
150  ? Color::Red : Color::Black;
151  }
152  SMeshWriter::writeIsoLinesOBJ( cisoname, surfmesh, fvalues, vvalues,
153  isolines, thickness, isocolors );
154  trace.endBlock();
155 }
SurfMesh surfmesh
std::vector< AnyRing > computeFaceValuesFromVertexValues(const std::vector< AnyRing > &vvalues) const
Size nbFaces() const
Definition: SurfaceMesh.h:296

References DGtal::Trace::beginBlock(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::computeFaceValuesFromVertexValues(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::nbFaces(), surfmesh, and DGtal::trace.

Referenced by main().