DGtal  1.0.0
Shortcuts.h
1 
17 #pragma once
18 
31 #if defined(Shortcuts_RECURSES)
32 #error Recursive header files inclusion detected in Shortcuts.h
33 #else // defined(Shortcuts_RECURSES)
34 
35 #define Shortcuts_RECURSES
36 
37 #if !defined Shortcuts_h
38 
39 #define Shortcuts_h
40 
42 // Inclusions
43 #include <cstdlib>
44 #include <iostream>
45 #include <fstream>
46 #include <sstream>
47 #include <iterator>
48 #include <string>
49 #include "DGtal/base/Common.h"
50 #include "DGtal/base/CountedPtr.h"
51 #include "DGtal/kernel/domains/HyperRectDomain.h"
52 #include "DGtal/kernel/RegularPointEmbedder.h"
53 #include "DGtal/math/MPolynomial.h"
54 #include "DGtal/math/Statistic.h"
55 #include "DGtal/images/ImageContainerBySTLVector.h"
56 #include "DGtal/images/IntervalForegroundPredicate.h"
57 #include <DGtal/images/ImageLinearCellEmbedder.h>
58 #include "DGtal/shapes/implicit/ImplicitPolynomial3Shape.h"
59 #include "DGtal/shapes/GaussDigitizer.h"
60 #include "DGtal/shapes/ShapeGeometricFunctors.h"
61 #include "DGtal/shapes/MeshHelpers.h"
62 #include "DGtal/topology/CCellularGridSpaceND.h"
63 #include "DGtal/topology/LightImplicitDigitalSurface.h"
64 #include "DGtal/topology/SetOfSurfels.h"
65 #include "DGtal/topology/DigitalSurface.h"
66 #include "DGtal/topology/IndexedDigitalSurface.h"
67 #include "DGtal/topology/SurfelAdjacency.h"
68 #include "DGtal/topology/CCellEmbedder.h"
69 #include "DGtal/topology/CanonicCellEmbedder.h"
70 #include "DGtal/topology/CanonicSCellEmbedder.h"
71 #include "DGtal/topology/helpers/Surfaces.h"
72 #include "DGtal/geometry/volumes/KanungoNoise.h"
73 #include "DGtal/io/Color.h"
74 #include "DGtal/io/colormaps/GradientColorMap.h"
75 #include "DGtal/io/colormaps/TickedColorMap.h"
76 #include "DGtal/io/readers/MPolynomialReader.h"
77 #include "DGtal/io/readers/GenericReader.h"
78 #include "DGtal/io/writers/GenericWriter.h"
79 #include "DGtal/graph/BreadthFirstVisitor.h"
80 #include "DGtal/graph/DepthFirstVisitor.h"
81 #include "DGtal/graph/GraphVisitorRange.h"
82 #include "DGtal/helpers/Parameters.h"
84 
85 namespace DGtal
86 {
87 
89  // template class Shortcuts
100  template < typename TKSpace >
101  class Shortcuts
102  {
104 
105  // ----------------------- Usual space types --------------------------------------
106  public:
108  typedef TKSpace KSpace;
110  typedef typename KSpace::Space Space;
112  typedef typename Space::Integer Integer;
114  typedef typename Space::Point Point;
116  typedef typename Space::Vector Vector;
118  typedef typename Space::RealVector RealVector;
120  typedef typename Space::RealPoint RealPoint;
122  typedef typename RealVector::Component Scalar;
126  typedef unsigned char GrayScale;
127 
128  // ----------------------- Shortcut types --------------------------------------
129  public:
146  typedef typename KSpace::SurfelSet SurfelSet;
151  typedef ::DGtal::DigitalSurface< LightSurfaceContainer > LightDigitalSurface;
155  typedef ::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface;
159  typedef typename LightDigitalSurface::Cell Cell;
162  typedef typename LightDigitalSurface::Arc Arc;
163  typedef typename LightDigitalSurface::Face Face;
167  typedef typename IdxDigitalSurface::Arc IdxArc;
169  typedef std::set< IdxSurfel > IdxSurfelSet;
170  typedef std::vector< SCell > SCellRange;
171  typedef std::vector< Cell > CellRange;
174  typedef std::vector< IdxSurfel > IdxSurfelRange;
175  typedef std::vector< Scalar > Scalars;
176  typedef std::vector< RealVector > RealVectors;
177  typedef std::vector< RealPoint > RealPoints;
178  typedef IdxVertex Idx;
179  typedef std::vector< IdxVertex > IdxRange;
180 
181  typedef ::DGtal::Mesh<RealPoint> Mesh;
182  typedef ::DGtal::TriangulatedSurface<RealPoint> TriangulatedSurface;
183  typedef ::DGtal::PolygonalSurface<RealPoint> PolygonalSurface;
184  typedef std::map<Surfel, IdxSurfel> Surfel2Index;
185  typedef std::map<Cell, IdxVertex> Cell2Index;
186 
187  typedef ::DGtal::Color Color;
188  typedef std::vector< Color > Colors;
191 
192  // ----------------------- Static services --------------------------------------
193  public:
194 
195  // ----------------------- General static services ------------------------------
196  public:
197 
200  {
202  | parametersKSpace()
207  | parametersMesh()
209  }
210 
211  // ----------------------- ImplicitShape3D static services ------------------------
212  public:
213 
231  static std::map< std::string, std::string >
233  {
234  std::vector< std::pair< std::string, std::string > >
235  Ps = { { "sphere1", "x^2+y^2+z^2-1" },
236  { "sphere9", "x^2+y^2+z^2-81" },
237  { "ellipsoid", "3*x^2+2*y^2+z^2-90" },
238  { "cylinder", "x^2+2*z^2-90" },
239  { "torus", "(x^2+y^2+z^2+6*6-2*2)^2-4*6*6*(x^2+y^2)" },
240  { "rcube", "x^4+y^4+z^4-6561" },
241  { "goursat", "-1*(8-0.03*x^4-0.03*y^4-0.03*z^4+2*x^2+2*y^2+2*z^2)" },
242  { "distel", "10000-(x^2+y^2+z^2+1000*(x^2+y^2)*(x^2+z^2)*(y^2+z^2))"},
243  { "leopold", "(x^2*y^2*z^2+4*x^2+4*y^2+3*z^2)-100" },
244  { "diabolo", "x^2-(y^2+z^2)^2" },
245  { "heart", "-1*(x^2+2.25*y^2+z^2-1)^3+x^2*z^3+0.1125*y^2*z^3" },
246  { "crixxi", "-0.9*(y^2+z^2-1)^2-(x^2+y^2-1)^3" } };
247  std::map< std::string, std::string > L;
248  for ( auto p : Ps )
249  L[ p.first ] = p.second;
250  return L;
251  }
252 
261  {
262  return Parameters
263  ( "polynomial", "sphere1" )
264  ( "projectionMaxIter", 20 )
265  ( "projectionAccuracy", 0.0001 )
266  ( "projectionGamma", 0.5 );
267  }
268 
278  {
280  std::string poly_str = params[ "polynomial" ].as<std::string>();
281  // Recognizes specific strings as polynomials.
282  auto PL = getPolynomialList();
283  if ( PL[ poly_str ] != "" ) poly_str = PL[ poly_str ];
284  ScalarPolynomial poly;
285  Polynomial3Reader reader;
286  std::string::const_iterator iter
287  = reader.read( poly, poly_str.begin(), poly_str.end() );
288  if ( iter != poly_str.end() )
289  {
290  trace.error() << "[Shortcuts::makeImplicitShape3D]"
291  << " ERROR reading polynomial: I read only <"
292  << poly_str.substr( 0, iter - poly_str.begin() )
293  << ">, and I built P=" << poly << std::endl;
294  }
295  return CountedPtr<ImplicitShape3D>( new ImplicitShape3D( poly ) );
296  }
297 
298  // ----------------------- KSpace static services ------------------------------
299  public:
300 
307  {
308  return Parameters
309  ( "closed", 1 )
310  ( "gridsizex", 1.0 )
311  ( "gridsizey", 1.0 )
312  ( "gridsizez", 1.0 );
313  }
314 
327  static KSpace getKSpace( const Point& low, const Point& up,
328  Parameters params = parametersKSpace() )
329  {
330  int closed = params[ "closed" ].as<int>();
331  KSpace K;
332  if ( ! K.init( low, up, closed ) )
333  trace.error() << "[Shortcuts::getKSpace]"
334  << " Error building Khalimsky space K=" << K << std::endl;
335  return K;
336  }
337 
350  Parameters params = parametersKSpace() )
351  {
352  int closed = params[ "closed" ].as<int>();
353  KSpace K;
354  if ( ! K.init( bimage->domain().lowerBound(),
355  bimage->domain().upperBound(),
356  closed ) )
357  trace.error() << "[Shortcuts::getKSpace]"
358  << " Error building Khalimsky space K=" << K << std::endl;
359  return K;
360  }
361 
374  Parameters params = parametersKSpace() )
375  {
376  int closed = params[ "closed" ].as<int>();
377  KSpace K;
378  if ( ! K.init( gimage->domain().lowerBound(),
379  gimage->domain().upperBound(),
380  closed ) )
381  trace.error() << "[Shortcuts::getKSpace]"
382  << " Error building Khalimsky space K=" << K << std::endl;
383  return K;
384  }
385 
389  template <typename TDigitalSurfaceContainer>
390  static KSpace
391  getKSpace
393  {
394  return surface->container().space();
395  }
396 
400  template <typename TDigitalSurfaceContainer>
401  static KSpace
402  getKSpace
404  {
405  return surface->container().space();
406  }
407 
411  template <typename TDigitalSurfaceContainer>
412  static const KSpace&
413  refKSpace
415  {
416  return surface->container().space();
417  }
418 
422  template <typename TDigitalSurfaceContainer>
423  static const KSpace&
424  refKSpace
426  {
427  return surface->container().space();
428  }
429 
434  {
435  return CanonicCellEmbedder<KSpace>( K );
436  }
437 
442  {
444  }
445 
446 
447  // ----------------------- DigitizedImplicitShape3D static services --------------
448  public:
449 
457  {
458  return Parameters
459  ( "minAABB", -10.0 )
460  ( "maxAABB", 10.0 )
461  ( "gridstep", 1.0 )
462  ( "offset", 5.0 );
463  }
464 
465 
480  static KSpace
483  {
484  Scalar min_x = params[ "minAABB" ].as<Scalar>();
485  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
486  Scalar h = params[ "gridstep" ].as<Scalar>();
487  Scalar offset = params[ "offset" ].as<Scalar>();
488  bool closed = params[ "closed" ].as<int>();
489  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
490  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
492  dshape->init( p1, p2, h );
493  Domain domain = dshape->getDomain();
494  KSpace K;
495  if ( ! K.init( domain.lowerBound(), domain.upperBound(), closed ) )
496  trace.error() << "[Shortcuts::getKSpace]"
497  << " Error building Khalimsky space K=" << K << std::endl;
498  return K;
499  }
500 
518  {
519  Scalar min_x = params[ "minAABB" ].as<Scalar>();
520  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
521  Scalar h = params[ "gridstep" ].as<Scalar>();
522  Scalar offset = params[ "offset" ].as<Scalar>();
523  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
524  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
526  dshape->attach( shape );
527  dshape->init( p1, p2, h );
528  return dshape;
529  }
530 
531 
532  // ----------------------- BinaryImage static services --------------------------
533  public:
534 
541  {
542  return Parameters
543  ( "noise", 0.0 )
544  ( "thresholdMin", 0 )
545  ( "thresholdMax", 255 );
546  }
547 
554  makeBinaryImage( Domain shapeDomain )
555  {
556  return CountedPtr<BinaryImage>( new BinaryImage( shapeDomain ) );
557  }
558 
570  Parameters params = parametersBinaryImage() )
571  {
572  return makeBinaryImage( shape_digitization,
573  shape_digitization->getDomain(),
574  params );
575  }
576 
590  Domain shapeDomain,
591  Parameters params = parametersBinaryImage() )
592  {
593  const Scalar noise = params[ "noise" ].as<Scalar>();
594  CountedPtr<BinaryImage> img ( new BinaryImage( shapeDomain ) );
595  if ( noise <= 0.0 )
596  {
597  std::transform( shapeDomain.begin(), shapeDomain.end(),
598  img->begin(),
599  [&shape_digitization]
600  ( const Point& p ) { return (*shape_digitization)(p); } );
601  }
602  else
603  {
604  typedef KanungoNoise< DigitizedImplicitShape3D, Domain > KanungoPredicate;
605  KanungoPredicate noisy_dshape( *shape_digitization, shapeDomain, noise );
606  std::transform( shapeDomain.begin(), shapeDomain.end(),
607  img->begin(),
608  [&noisy_dshape] ( const Point& p ) { return noisy_dshape(p); } );
609  }
610  return img;
611  }
612 
622  Parameters params = parametersBinaryImage() )
623  {
624  const Scalar noise = params[ "noise" ].as<Scalar>();
625  if ( noise <= 0.0 ) return bimage;
626  typedef KanungoNoise< BinaryImage, Domain > KanungoPredicate;
627  const Domain shapeDomain = bimage->domain();
628  CountedPtr<BinaryImage> img ( new BinaryImage( shapeDomain ) );
629  KanungoPredicate noisy_dshape( *bimage, shapeDomain, noise );
630  std::transform( shapeDomain.begin(), shapeDomain.end(),
631  img->begin(),
632  [&noisy_dshape] ( const Point& p ) { return noisy_dshape(p); } );
633  return img;
634  }
635 
649  ( std::string input,
650  Parameters params = parametersBinaryImage() )
651  {
652  int thresholdMin = params["thresholdMin"].as<int>();
653  int thresholdMax = params["thresholdMax"].as<int>();
655  Domain domain = image.domain();
657  ThresholdedImage tImage( image, thresholdMin, thresholdMax );
659  std::transform( domain.begin(), domain.end(),
660  img->begin(),
661  [tImage] ( const Point& p ) { return tImage(p); } );
662  return makeBinaryImage( img, params );
663  }
664 
678  ( CountedPtr<GrayScaleImage> gray_scale_image,
679  Parameters params = parametersBinaryImage() )
680  {
681  int thresholdMin = params["thresholdMin"].as<int>();
682  int thresholdMax = params["thresholdMax"].as<int>();
683  Domain domain = gray_scale_image->domain();
685  ThresholdedImage tImage( *gray_scale_image, thresholdMin, thresholdMax );
687  std::transform( domain.begin(), domain.end(),
688  img->begin(),
689  [tImage] ( const Point& p ) { return tImage(p); } );
690  return makeBinaryImage( img, params );
691  }
692 
693 
699  static bool
701  ( CountedPtr<BinaryImage> bimage, std::string output )
702  {
703  auto gray_scale_image = makeGrayScaleImage( bimage );
704  return saveGrayScaleImage( gray_scale_image, output );
705  }
706 
707 
708  // ----------------------- GrayScaleImage static services -------------------------
709  public:
710 
717  {
718  return Parameters
719  ( "qShift", 128.0 )
720  ( "qSlope", 1.0 );
721  }
722 
730  {
731  return CountedPtr<GrayScaleImage>( new GrayScaleImage( aDomain ) );
732  }
733 
742  ( std::string input )
743  {
745  return CountedPtr<GrayScaleImage>( new GrayScaleImage( image ) );
746  }
747 
756  ( CountedPtr<BinaryImage> binary_image,
757  std::function< GrayScale( bool ) > const & bool2grayscale
758  = [] ( bool v ) { return v ? (unsigned char) 255 : (unsigned char) 0; }
759  // JOL: (GrayScale) was not working with visual C++: error C2065
760  )
761  {
762  const Domain domain = binary_image->domain();
763  CountedPtr<GrayScaleImage> gray_scale_image( new GrayScaleImage( domain ) );
764  std::transform( binary_image->begin(), binary_image->end(),
765  gray_scale_image->begin(),
766  bool2grayscale );
767  return gray_scale_image;
768  }
769 
775  static bool
777  ( CountedPtr<GrayScaleImage> gray_scale_image, std::string output )
778  {
780  ::exportFile( output, *gray_scale_image );
781  }
782 
783 
799  {
800  float qShift = params[ "qShift" ].as<float>();
801  float qSlope = params[ "qSlope" ].as<float>();
802  std::function< unsigned char( float ) > f
803  = [qShift,qSlope] (float v)
804  { return (unsigned char) std::min( 255.0f, std::max( 0.0f, qSlope * v + qShift ) ); };
805  Domain domain = fimage->domain();
806  auto gimage = makeGrayScaleImage( domain );
807  auto it = gimage->begin();
808  for ( auto p : domain )
809  {
810  float val = (*fimage)( p );
811  *it++ = f( val );
812  }
813  return gimage;
814  }
815 
831  {
832  double qShift = params[ "qShift" ].as<double>();
833  double qSlope = params[ "qSlope" ].as<double>();
834  std::function< unsigned char( double ) > f
835  = [qShift,qSlope] (double v)
836  { return (unsigned char) std::min( 255.0, std::max( 0.0, qSlope * v + qShift ) ); };
837  Domain domain = fimage->domain();
838  auto gimage = makeGrayScaleImage( domain );
839  auto it = gimage->begin();
840  for ( auto p : domain )
841  {
842  double val = (*fimage)( p );
843  *it++ = f( val );
844  }
845  return gimage;
846  }
847 
848  // ----------------------- FloatImage static services -------------------------
849  public:
850 
858  {
859  return CountedPtr<FloatImage>( new FloatImage( aDomain ) );
860  }
861 
870  ( std::string input )
871  {
873  return CountedPtr<FloatImage>( new FloatImage( image ) );
874  }
875 
893  {
894  Scalar min_x = params[ "minAABB" ].as<Scalar>();
895  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
896  Scalar h = params[ "gridstep" ].as<Scalar>();
897  Scalar offset = params[ "offset" ].as<Scalar>();
898  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
899  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
901  dshape->attach( shape );
902  dshape->init( p1, p2, h );
903  Domain domain = dshape->getDomain();
904  auto fimage = makeFloatImage( domain );
905  auto it = fimage->begin();
906  for ( auto p : domain )
907  {
908  float val = (float) (*shape)( p );
909  *it++ = val;
910  }
911  return fimage;
912  }
913 
914  // ----------------------- DoubleImage static services -------------------------
915  public:
916 
924  {
925  return CountedPtr<DoubleImage>( new DoubleImage( aDomain ) );
926  }
927 
936  ( std::string input )
937  {
939  return CountedPtr<DoubleImage>( new DoubleImage( image ) );
940  }
941 
959  {
960  Scalar min_x = params[ "minAABB" ].as<Scalar>();
961  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
962  Scalar h = params[ "gridstep" ].as<Scalar>();
963  Scalar offset = params[ "offset" ].as<Scalar>();
964  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
965  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
967  dshape->attach( shape );
968  dshape->init( p1, p2, h );
969  Domain domain = dshape->getDomain();
970  auto fimage = makeDoubleImage( domain );
971  auto it = fimage->begin();
972  for ( auto p : domain )
973  {
974  double val = (double) (*shape)( p );
975  *it++ = val;
976  }
977  return fimage;
978  }
979 
980  // ----------------------- DigitalSurface static services ------------------------
981  public:
982 
990  {
991  return Parameters
992  ( "surfelAdjacency", 0 )
993  ( "nbTriesToFindABel", 100000 )
994  ( "surfaceComponents", "AnyBig" )
995  ( "surfaceTraversal", "Default" );
996  }
997 
1001  template <typename TDigitalSurfaceContainer>
1005  {
1006  return getCellEmbedder( refKSpace( surface ) );
1007  }
1008 
1012  template <typename TDigitalSurfaceContainer>
1016  {
1017  return getSCellEmbedder( refKSpace( surface ) );
1018  }
1019 
1023  template <typename TDigitalSurfaceContainer>
1027  {
1028  return getCellEmbedder( refKSpace( surface ) );
1029  }
1030 
1034  template <typename TDigitalSurfaceContainer>
1038  {
1039  return getSCellEmbedder( refKSpace( surface ) );
1040  }
1041 
1056  const KSpace& K,
1057  const Parameters& params = parametersDigitalSurface() )
1058  {
1059  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1060  int nb_tries_to_find_a_bel = params[ "nbTriesToFindABel" ].as<int>();
1061  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1062 
1063  // We have to search for a surfel that belongs to a big connected component.
1065  Surfel bel;
1066  Scalar minsize = bimage->extent().norm();
1067  unsigned int nb_surfels = 0;
1068  unsigned int tries = 0;
1069  do
1070  {
1071  try { // Search initial bel
1072  bel = Surfaces<KSpace>::findABel( K, *bimage, nb_tries_to_find_a_bel );
1073  } catch (DGtal::InputException& e) {
1074  trace.error() << "[Shortcuts::makeLightDigitalSurface]"
1075  << " ERROR Unable to find bel." << std::endl;
1076  return ptrSurface;
1077  }
1078  // this pointer will be acquired by the surface.
1079  LightSurfaceContainer* surfContainer
1080  = new LightSurfaceContainer( K, *bimage, surfAdj, bel );
1081  ptrSurface = CountedPtr<LightDigitalSurface>
1082  ( new LightDigitalSurface( surfContainer ) ); // acquired
1083  nb_surfels = ptrSurface->size();
1084  }
1085  while ( ( nb_surfels < 2 * minsize ) && ( tries++ < 150 ) );
1086  if( tries >= 150 )
1087  trace.warning() << "[Shortcuts::makeLightDigitalSurface]"
1088  << "ERROR cannot find a proper bel in a big enough component."
1089  << std::endl;
1090  return ptrSurface;
1091  }
1092 
1110  static std::vector< CountedPtr<LightDigitalSurface> >
1113  const KSpace& K,
1114  const Parameters& params = parametersDigitalSurface() )
1115  {
1116  SurfelRange surfel_reps;
1117  return makeLightDigitalSurfaces( surfel_reps, bimage, K, params );
1118  }
1119 
1140  static std::vector< CountedPtr<LightDigitalSurface> >
1142  ( SurfelRange& surfel_reps,
1143  CountedPtr<BinaryImage> bimage,
1144  const KSpace& K,
1145  const Parameters& params = parametersDigitalSurface() )
1146  {
1147  std::vector< CountedPtr<LightDigitalSurface> > result;
1148  std::string component = params[ "surfaceComponents" ].as<std::string>();
1149  if ( component == "AnyBig" )
1150  {
1151  result.push_back( makeLightDigitalSurface( bimage, K, params ) );
1152  surfel_reps.push_back( *( result[ 0 ]->begin() ) );
1153  return result;
1154  }
1155  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1156  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1157  // Extracts all boundary surfels
1158  SurfelSet all_surfels;
1159  Surfaces<KSpace>::sMakeBoundary( all_surfels, K, *bimage,
1160  K.lowerBound(), K.upperBound() );
1161  // Builds all connected components of surfels.
1162  SurfelSet marked_surfels;
1164  for ( auto bel : all_surfels )
1165  {
1166  if ( marked_surfels.count( bel ) != 0 ) continue;
1167  surfel_reps.push_back( bel );
1168  LightSurfaceContainer* surfContainer
1169  = new LightSurfaceContainer( K, *bimage, surfAdj, bel );
1170  ptrSurface = CountedPtr<LightDigitalSurface>
1171  ( new LightDigitalSurface( surfContainer ) ); // acquired
1172  // mark all surfels of the surface component.
1173  marked_surfels.insert( ptrSurface->begin(), ptrSurface->end() );
1174  // add surface component to result.
1175  result.push_back( ptrSurface );
1176  }
1177  return result;
1178  }
1179 
1180 
1199  template <typename TPointPredicate>
1203  const KSpace& K,
1204  const Parameters& params = parametersDigitalSurface() )
1205  {
1206  SurfelSet all_surfels;
1207  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1208  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1209  // Extracts all boundary surfels
1210  Surfaces<KSpace>::sMakeBoundary( all_surfels, K, *bimage,
1211  K.lowerBound(), K.upperBound() );
1212  ExplicitSurfaceContainer* surfContainer
1213  = new ExplicitSurfaceContainer( K, surfAdj, all_surfels );
1215  ( new DigitalSurface( surfContainer ) ); // acquired
1216  }
1217 
1218 
1234  const Parameters& params = parametersDigitalSurface() )
1235  {
1236  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1237  const KSpace& K = refKSpace( idx_surface );
1238  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1239  auto all_idx_surfels
1240  = getIdxSurfelRange( idx_surface, Parameters( "surfaceTraversal", "Default" ) );
1241  auto idx2surfel = idx_surface->surfels();
1242  SurfelSet all_surfels;
1243  for ( auto idx : all_idx_surfels ) all_surfels.insert( idx2surfel[ idx ] );
1244  ExplicitSurfaceContainer* surfContainer
1245  = new ExplicitSurfaceContainer( K, surfAdj, all_surfels );
1247  ( new DigitalSurface( surfContainer ) ); // acquired
1248  }
1249 
1269  const KSpace& K,
1270  const Parameters& params = parametersDigitalSurface() )
1271  {
1272  std::string component = params[ "surfaceComponents" ].as<std::string>();
1273  SurfelSet surfels;
1274  if ( component == "AnyBig" )
1275  {
1276  auto light_surface = makeLightDigitalSurface( bimage, K, params );
1277  surfels.insert( light_surface->begin(), light_surface->end() );
1278  }
1279  else if ( component == "All" )
1280  {
1281  Surfaces<KSpace>::sMakeBoundary( surfels, K, *bimage,
1282  K.lowerBound(), K.upperBound() );
1283  }
1284  return makeIdxDigitalSurface( surfels, K, params );
1285  }
1286 
1298  template <typename TSurfelRange>
1301  ( const TSurfelRange& surfels,
1303  const Parameters& params = parametersDigitalSurface() )
1304  {
1305  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1306  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1307  // Build indexed digital surface.
1308  CountedPtr<ExplicitSurfaceContainer> ptrSurfContainer
1309  ( new ExplicitSurfaceContainer( K, surfAdj, surfels ) );
1311  ( new IdxDigitalSurface() );
1312  bool ok = ptrSurface->build( ptrSurfContainer );
1313  if ( !ok )
1314  trace.warning() << "[Shortcuts::makeIdxDigitalSurface]"
1315  << " Error building indexed digital surface." << std::endl;
1316  return ptrSurface;
1317  }
1318 
1331  template <typename TDigitalSurfaceContainer>
1335  const Parameters& params = parametersDigitalSurface() )
1336  {
1337  const KSpace& K = refKSpace( surface );
1338  SurfelSet surfels;
1339  surfels.insert( surface->begin(), surface->end() );
1340  return makeIdxDigitalSurface( surfels, K, params );
1341  }
1342 
1357  ( const std::vector< CountedPtr<LightDigitalSurface> >& surfaces,
1358  const Parameters& params = parametersDigitalSurface() )
1359  {
1360  if ( surfaces.empty() ) return CountedPtr<IdxDigitalSurface>( 0 );
1361  const KSpace& K = surfaces[ 0 ]->container().space();
1362  SurfelSet surfels;
1363  for ( std::size_t i = 0; i < surfaces.size(); ++i )
1364  {
1365  const KSpace& Ki = surfaces[ i ]->container().space();
1366  if ( ( Ki.lowerBound() != K.lowerBound() )
1367  || ( Ki.upperBound() != K.upperBound() ) )
1368  trace.warning() << "[Shortcuts::makeIdxDigitalSurface]"
1369  << " Incompatible digital spaces for surface " << i << std::endl;
1370  surfels.insert( surfaces[ i ]->begin(), surfaces[ i ]->end() );
1371  }
1372  return makeIdxDigitalSurface( surfels, K, params );
1373  }
1374 
1375 
1393  template <typename TDigitalSurfaceContainer>
1394  static PointelRange
1396  ( Cell2Index& c2i,
1398  {
1399  PointelRange result;
1400  result.reserve( surface->size() );
1401  const KSpace& K = refKSpace( surface );
1402  Idx n = 0;
1403  for ( auto&& surfel : *surface )
1404  {
1405  CellRange primal_vtcs = getPointelRange( K, surfel );
1406  for ( auto&& primal_vtx : primal_vtcs )
1407  {
1408  if ( ! c2i.count( primal_vtx ) )
1409  {
1410  result.push_back( primal_vtx );
1411  c2i[ primal_vtx ] = n++;
1412  }
1413  }
1414  }
1415  return result;
1416  }
1417 
1434  template <typename TDigitalSurfaceContainer>
1435  static PointelRange
1438  {
1439  Cell2Index c2i;
1440  return getPointelRange( c2i, surface );
1441  }
1442 
1451  static PointelRange
1453  ( const KSpace& K, const SCell& surfel )
1454  {
1455  return getPrimalVertices( K, surfel, true );
1456  }
1457 
1469  template <typename TDigitalSurfaceContainer>
1470  static SurfelRange
1473  const Parameters& params = parametersDigitalSurface() )
1474  {
1475  return getSurfelRange( surface, *( surface->begin() ), params );
1476  }
1477 
1492  template <typename TDigitalSurfaceContainer>
1493  static SurfelRange
1496  const Surfel& start_surfel,
1497  const Parameters& params = parametersDigitalSurface() )
1498  {
1499  typedef ::DGtal::DigitalSurface<TDigitalSurfaceContainer> AnyDigitalSurface;
1500  SurfelRange result;
1501  std::string traversal = params[ "surfaceTraversal" ].as<std::string>();
1502  if ( traversal == "DepthFirst" )
1503  {
1505  typedef GraphVisitorRange< Visitor > VisitorRange;
1506  VisitorRange range( new Visitor( *surface, start_surfel ) );
1507  std::for_each( range.begin(), range.end(),
1508  [&result] ( Surfel s ) { result.push_back( s ); } );
1509  }
1510  else if ( traversal == "BreadthFirst" )
1511  {
1513  typedef GraphVisitorRange< Visitor > VisitorRange;
1514  VisitorRange range( new Visitor( *surface, start_surfel ) );
1515  std::for_each( range.begin(), range.end(),
1516  [&result] ( Surfel s ) { result.push_back( s ); } );
1517  }
1518  else
1519  {
1520  std::for_each( surface->begin(), surface->end(),
1521  [&result] ( Surfel s ) { result.push_back( s ); } );
1522  }
1523  return result;
1524  }
1525 
1535  static IdxSurfelRange
1538  const Parameters& params = parametersDigitalSurface() )
1539  {
1540  return getIdxSurfelRange( surface, (IdxSurfel) 0, params );
1541  }
1542 
1555  static IdxSurfelRange
1558  const IdxSurfel& start_surfel,
1559  const Parameters& params = parametersDigitalSurface() )
1560  {
1561  IdxSurfelRange result;
1562  std::string traversal = params[ "surfaceTraversal" ].as<std::string>();
1563  if ( traversal == "DepthFirst" )
1564  {
1566  typedef GraphVisitorRange< Visitor > VisitorRange;
1567  VisitorRange range( new Visitor( *surface, start_surfel ) );
1568  std::for_each( range.begin(), range.end(),
1569  [&result] ( IdxSurfel s ) { result.push_back( s ); } );
1570  }
1571  else if ( traversal == "BreadthFirst" )
1572  {
1574  typedef GraphVisitorRange< Visitor > VisitorRange;
1575  VisitorRange range( new Visitor( *surface, start_surfel ) );
1576  std::for_each( range.begin(), range.end(),
1577  [&result] ( IdxSurfel s ) { result.push_back( s ); } );
1578  }
1579  else return surface->allVertices();
1580  return result;
1581  }
1582 
1600  template <typename TDigitalSurfaceContainer,
1601  typename TCellEmbedder>
1602  static bool
1603  saveOBJ
1605  const TCellEmbedder& embedder,
1606  const RealVectors& normals,
1607  const Colors& diffuse_colors,
1608  std::string objfile,
1609  const Color& ambient_color = Color( 32, 32, 32 ),
1610  const Color& diffuse_color = Color( 200, 200, 255 ),
1611  const Color& specular_color = Color::White )
1612  {
1613  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1614  std::string mtlfile;
1615  auto lastindex = objfile.find_last_of(".");
1616  if ( lastindex == std::string::npos )
1617  {
1618  mtlfile = objfile + ".mtl";
1619  objfile = objfile + ".obj";
1620  }
1621  else
1622  {
1623  mtlfile = objfile.substr(0, lastindex) + ".mtl";
1624  }
1625  std::ofstream output_obj( objfile.c_str() );
1626  output_obj << "# OBJ format" << std::endl;
1627  output_obj << "# DGtal::MeshHelpers::exportOBJwithFaceNormalAndColor" << std::endl;
1628  output_obj << "o anObject" << std::endl;
1629  output_obj << "mtllib " << mtlfile << std::endl;
1630  std::ofstream output_mtl( mtlfile.c_str() );
1631  output_mtl << "# MTL format"<< std::endl;
1632  output_mtl << "# generated from MeshWriter from the DGTal library"<< std::endl;
1633  // Number and output vertices.
1634  const KSpace& K = refKSpace( digsurf );
1635  Cell2Index c2i;
1636  auto pointels = getPointelRange( c2i, digsurf );
1637  for ( auto&& pointel : pointels )
1638  {
1639  RealPoint p = embedder( pointel );
1640  output_obj << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1641  }
1642  // Taking care of normals
1643  Idx nbfaces = digsurf->size();
1644  bool has_normals = ( nbfaces == normals.size() );
1645  if ( has_normals )
1646  {
1647  for ( Idx f = 0; f < nbfaces; ++f )
1648  {
1649  const auto& p = normals[ f ];
1650  output_obj << "vn " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1651  }
1652  }
1653  // Taking care of materials
1654  bool has_material = ( nbfaces == diffuse_colors.size() );
1655  Idx idxMaterial = 0;
1656  std::map<Color, unsigned int > mapMaterial;
1657  // MeshHelpers::exportMTLNewMaterial
1658  // ( output_mtl, idxMaterial, ambient_color, Color::Black, specular_color );
1659  // mapMaterial[ Color::Black ] = idxMaterial++;
1660  if ( has_material )
1661  {
1662  for ( Idx f = 0; f < nbfaces; ++f )
1663  {
1664  Color c = diffuse_colors[ f ];
1665  if ( mapMaterial.count( c ) == 0 )
1666  {
1668  ( output_mtl, idxMaterial, ambient_color, c, specular_color );
1669  mapMaterial[ c ] = idxMaterial++;
1670  }
1671  }
1672  }
1673  else
1674  {
1676  ( output_mtl, idxMaterial, ambient_color, diffuse_color, specular_color );
1677  }
1678 
1679  // Taking care of faces
1680  Idx f = 0;
1681  for ( auto&& surfel : *digsurf )
1682  {
1683  output_obj << "usemtl material_"
1684  << ( has_material ? mapMaterial[ diffuse_colors[ f ] ] : idxMaterial )
1685  << std::endl;
1686  output_obj << "f";
1687  auto primal_vtcs = getPointelRange( K, surfel );
1688  // The +1 in lines below is because indexing starts at 1 in OBJ file format.
1689  if ( has_normals )
1690  {
1691  for ( auto&& primal_vtx : primal_vtcs )
1692  output_obj << " " << (c2i[ primal_vtx ]+1) << "//" << (f+1);
1693  }
1694  else
1695  {
1696  for ( auto&& primal_vtx : primal_vtcs )
1697  output_obj << " " << (c2i[ primal_vtx ]+1);
1698  }
1699  output_obj << std::endl;
1700  f += 1;
1701  }
1702  output_mtl.close();
1703  return output_obj.good();
1704  }
1705 
1721  template <typename TDigitalSurfaceContainer>
1722  static bool
1723  saveOBJ
1725  const RealVectors& normals,
1726  const Colors& diffuse_colors,
1727  std::string objfile,
1728  const Color& ambient_color = Color( 32, 32, 32 ),
1729  const Color& diffuse_color = Color( 200, 200, 255 ),
1730  const Color& specular_color = Color::White )
1731  {
1732  auto embedder = getCellEmbedder( digsurf );
1733  return saveOBJ( digsurf, embedder, normals, diffuse_colors, objfile,
1734  ambient_color, diffuse_color, specular_color );
1735  }
1736 
1749  template <typename TDigitalSurfaceContainer>
1750  static bool
1751  saveOBJ
1753  std::string objfile,
1754  const Color& ambient_color = Color( 32, 32, 32 ),
1755  const Color& diffuse_color = Color( 200, 200, 255 ),
1756  const Color& specular_color = Color::White )
1757  {
1758  auto embedder = getCellEmbedder( digsurf );
1759  return saveOBJ( digsurf, embedder, RealVectors(), Colors(), objfile,
1760  ambient_color, diffuse_color, specular_color );
1761  }
1762 
1763 
1764  // ----------------------- Mesh services ------------------------------
1765  public:
1766 
1771  {
1772  return Parameters
1773  ( "faceSubdivision", "Centroid" );
1774  }
1775 
1789  {
1790  auto pTriSurf = CountedPtr<TriangulatedSurface>
1791  ( new TriangulatedSurface ); // acquired
1792  bool ok = MeshHelpers::mesh2TriangulatedSurface( *aMesh, *pTriSurf );
1793  return ok ? pTriSurf : CountedPtr< TriangulatedSurface >( nullptr );
1794  }
1795 
1804  static CountedPtr< Mesh >
1806  const Color& aColor = Color::White )
1807  {
1808  auto pMesh = CountedPtr<Mesh>( new Mesh( aColor ) ); // acquired
1809  MeshHelpers::triangulatedSurface2Mesh( *triSurf, *pMesh );
1810  return pMesh;
1811  }
1812 
1821  static CountedPtr< Mesh >
1823  const Color& aColor = Color::White )
1824  {
1825  auto pMesh = CountedPtr<Mesh>( new Mesh( aColor ) ); // acquired
1826  MeshHelpers::polygonalSurface2Mesh( *polySurf, *pMesh );
1827  return pMesh;
1828  }
1829 
1836  template < typename TContainer >
1840  {
1841  auto embedder = getCellEmbedder( aSurface );
1842  auto pTriSurf = CountedPtr<TriangulatedSurface>
1843  ( new TriangulatedSurface ); // acquired
1845  ( *aSurface, embedder, *pTriSurf, s2i );
1846  return pTriSurf;
1847  }
1848 
1854  template < typename TContainer >
1857  {
1858  Surfel2Index s2i;
1859  return makeTriangulatedSurface( s2i, aSurface );
1860  }
1861 
1881  const Parameters& params = parametersMesh() )
1882  {
1883  std::string faceSubdivision = params[ "faceSubdivision" ].as<std::string>();
1884  bool centroid = ( faceSubdivision == "Centroid" );
1885  auto pTriSurf = CountedPtr<TriangulatedSurface>
1886  ( new TriangulatedSurface ); // acquired
1887  MeshHelpers::polygonalSurface2TriangulatedSurface( *polySurf, *pTriSurf, centroid );
1888  return pTriSurf;
1889  }
1890 
1901  {
1902  auto pPolySurf = CountedPtr<PolygonalSurface>
1903  ( new PolygonalSurface ); // acquired
1904  bool ok = MeshHelpers::mesh2PolygonalSurface( *aMesh, *pPolySurf );
1905  return ok ? pPolySurf : CountedPtr< PolygonalSurface >( nullptr );
1906  }
1907 
1923  const Parameters& params =
1927  {
1928  auto K = getKSpace( gray_scale_image );
1929  auto bimage = makeBinaryImage( gray_scale_image, params );
1930  auto digSurf = makeDigitalSurface( bimage, K, params );
1931  RealVector gh = { params[ "gridsizex" ].as<double>(),
1932  params[ "gridsizey" ].as<double>(),
1933  params[ "gridsizez" ].as<double>() };
1934  double threshold = params[ "thresholdMin" ].as<double>() + 0.5;
1935  typedef RegularPointEmbedder<Space> PointEmbedder;
1936  typedef ImageLinearCellEmbedder
1937  < KSpace, GrayScaleImage, PointEmbedder > ImageCellEmbedder;
1938  PointEmbedder pembedder;
1939  pembedder.init( gh );
1940  ImageCellEmbedder cembedder;
1941  cembedder.init( K, *gray_scale_image, pembedder, threshold );
1942  auto pPolySurf = CountedPtr<PolygonalSurface>
1943  ( new PolygonalSurface ); // acquired
1944  Surfel2Index s2i;
1946  ( *digSurf, cembedder, *pPolySurf, s2i );
1947  return pPolySurf;
1948  }
1949 
1966  const Parameters& params =
1970  {
1971  auto K = getKSpace( gray_scale_image );
1972  auto bimage = makeBinaryImage( gray_scale_image, params );
1973  auto digSurf = makeDigitalSurface( bimage, K, params );
1974  RealVector gh = { params[ "gridsizex" ].as<double>(),
1975  params[ "gridsizey" ].as<double>(),
1976  params[ "gridsizez" ].as<double>() };
1977  double threshold = params[ "thresholdMin" ].as<double>() + 0.5;
1978  typedef RegularPointEmbedder<Space> PointEmbedder;
1979  typedef ImageLinearCellEmbedder
1980  < KSpace, GrayScaleImage, PointEmbedder > ImageCellEmbedder;
1981  PointEmbedder pembedder;
1982  pembedder.init( gh );
1983  ImageCellEmbedder cembedder;
1984  cembedder.init( K, *gray_scale_image, pembedder, threshold );
1985  auto pPolySurf = CountedPtr<TriangulatedSurface>
1986  ( new TriangulatedSurface ); // acquired
1987  Surfel2Index s2i;
1989  ( *digSurf, cembedder, *pPolySurf, s2i );
1990  return pPolySurf;
1991  }
1992 
2000  template < typename TContainer >
2004  {
2005  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2006  auto embedder = getCellEmbedder( aSurface );
2007  auto pPolySurf = CountedPtr<PolygonalSurface>
2008  ( new PolygonalSurface ); // acquired
2010  ( *aSurface, embedder, *pPolySurf, s2i );
2011  return pPolySurf;
2012  }
2013 
2020  template < typename TContainer >
2023  {
2024  Surfel2Index s2i;
2025  return makeDualPolygonalSurface( s2i, aSurface );
2026  }
2027 
2034  template < typename TContainer >
2038  {
2039  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2040  auto pPolySurf = CountedPtr<PolygonalSurface>
2041  ( new PolygonalSurface( aSurface->heds(),
2042  aSurface->positions().storage() ) );
2043  return pPolySurf;
2044  }
2045 
2053  template < typename TContainer >
2057  {
2058  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2059  auto embedder = getCellEmbedder( aSurface );
2060  auto pPolySurf = CountedPtr<PolygonalSurface>
2061  ( new PolygonalSurface ); // acquired
2063  ( *aSurface, embedder, *pPolySurf, c2i );
2064  return ok ? pPolySurf : CountedPtr< PolygonalSurface >( nullptr );
2065  }
2066 
2073  template < typename TContainer >
2076  {
2077  Cell2Index c2i;
2078  return makePrimalPolygonalSurface( c2i, aSurface );
2079  }
2080 
2087  template < typename TContainer >
2091  {
2092  auto dsurf = makeDigitalSurface( aSurface );
2093  Cell2Index c2i;
2094  return makePrimalPolygonalSurface( c2i, dsurf );
2095  }
2096 
2103  template <typename TPoint>
2104  static bool
2105  saveOBJ
2107  const std::string& objfile )
2108  {
2109  std::ofstream output( objfile.c_str() );
2110  bool ok = MeshHelpers::exportOBJ( output, *polysurf );
2111  output.close();
2112  return ok;
2113  }
2114 
2121  template <typename TPoint>
2122  static bool
2123  saveOBJ
2125  const std::string& objfile )
2126  {
2127  std::ofstream output( objfile.c_str() );
2128  bool ok = MeshHelpers::exportOBJ( output, *trisurf );
2129  output.close();
2130  return ok;
2131  }
2132 
2145  template <typename TPoint>
2146  static bool
2147  saveOBJ
2149  const RealVectors& normals,
2150  const Colors& diffuse_colors,
2151  std::string objfile,
2152  const Color& ambient_color = Color( 32, 32, 32 ),
2153  const Color& diffuse_color = Color( 200, 200, 255 ),
2154  const Color& specular_color = Color::White )
2155  {
2156  std::string mtlfile;
2157  auto lastindex = objfile.find_last_of(".");
2158  if ( lastindex == std::string::npos )
2159  {
2160  mtlfile = objfile + ".mtl";
2161  objfile = objfile + ".obj";
2162  }
2163  else
2164  {
2165  mtlfile = objfile.substr(0, lastindex) + ".mtl";
2166  }
2167  std::ofstream output( objfile.c_str() );
2169  ( output, mtlfile, *polysurf, normals, diffuse_colors,
2170  ambient_color, diffuse_color, specular_color );
2171  output.close();
2172  return ok;
2173  }
2174 
2187  template <typename TPoint>
2188  static bool
2189  saveOBJ
2191  const RealVectors& normals,
2192  const Colors& diffuse_colors,
2193  std::string objfile,
2194  const Color& ambient_color = Color( 32, 32, 32 ),
2195  const Color& diffuse_color = Color( 200, 200, 255 ),
2196  const Color& specular_color = Color::White )
2197  {
2198  std::string mtlfile;
2199  auto lastindex = objfile.find_last_of(".");
2200  if ( lastindex == std::string::npos )
2201  {
2202  mtlfile = objfile + ".mtl";
2203  objfile = objfile + ".obj";
2204  }
2205  else
2206  {
2207  mtlfile = objfile.substr(0, lastindex) + ".mtl";
2208  }
2209  std::ofstream output( objfile.c_str() );
2211  ( output, mtlfile, *trisurf, normals, diffuse_colors,
2212  ambient_color, diffuse_color, specular_color );
2213  output.close();
2214  return ok;
2215  }
2216 
2217 
2218 
2219  // ------------------------------ utilities ------------------------------
2220  public:
2221 
2227  {
2228  return Parameters
2229  ( "colormap", "Custom" )
2230  ( "zero-tic", 0.0 );
2231  }
2232 
2249  template <typename TValue>
2250  static IdxRange
2251  getRangeMatch( const std::vector< TValue >& s1, const std::vector< TValue >& s2,
2252  bool perfect = false )
2253  {
2254  if ( perfect && ( s1.size() != s2.size() ) ) return IdxRange();
2255  std::map<TValue, Idx> M;
2256  Idx idx = 0;
2257  for ( auto val : s2 ) M[ val ] = idx++;
2258  IdxRange V( s1.size() );
2259  idx = 0;
2260  for ( auto val : s1 )
2261  {
2262  auto it = M.find( val );
2263  if ( it != M.end() ) V[ idx++ ] = it->second;
2264  else
2265  {
2266  if ( perfect ) return IdxRange();
2267  V[ idx++ ] = s2.size();
2268  }
2269  }
2270  return V;
2271  }
2272 
2284  template <typename TValue>
2285  static std::vector< TValue >
2286  getMatchedRange( const std::vector< TValue >& range, const IdxRange& match )
2287  {
2288  std::vector< TValue > result( match.size() );
2289  for ( Idx i = 0; i < result.size(); i++ )
2290  result[ i ] = range[ match[ i ] ];
2291  return result;
2292  }
2293 
2294 
2300  static ColorMap
2302  Scalar max,
2303  const Parameters& params = parametersUtilities() )
2304  {
2305  std::string cmap = params[ "colormap" ].as<std::string>();
2306  if ( cmap == "Cool" ) return ColorMap( min, max, CMAP_COOL );
2307  else if ( cmap == "Copper" ) return ColorMap( min, max, CMAP_COPPER );
2308  else if ( cmap == "Hot" ) return ColorMap( min, max, CMAP_HOT );
2309  else if ( cmap == "Jet" ) return ColorMap( min, max, CMAP_JET );
2310  else if ( cmap == "Spring" ) return ColorMap( min, max, CMAP_SPRING );
2311  else if ( cmap == "Summer" ) return ColorMap( min, max, CMAP_SUMMER );
2312  else if ( cmap == "Autumn" ) return ColorMap( min, max, CMAP_AUTUMN );
2313  else if ( cmap == "Winter" ) return ColorMap( min, max, CMAP_WINTER );
2314  else if ( cmap == "Error" )
2315  {
2316  ColorMap gradcmap( min, max );
2317  gradcmap.addColor( Color( 255, 255, 255 ) );
2318  gradcmap.addColor( Color( 255, 0, 0 ) );
2319  gradcmap.addColor( Color( 0, 0, 0 ) );
2320  return gradcmap;
2321  }
2322  // Custom colormap
2323  ColorMap gradcmap( min, max );
2324  gradcmap.addColor( Color( 0, 0, 255 ) );
2325  gradcmap.addColor( Color( 0, 255, 255 ) );
2326  gradcmap.addColor( Color( 255, 255, 255 ) );
2327  gradcmap.addColor( Color( 255, 255, 0 ) );
2328  gradcmap.addColor( Color( 255, 0, 0 ) );
2329  return gradcmap;
2330  }
2331 
2338  static ZeroTickedColorMap
2340  Scalar max,
2341  const Parameters& params = parametersUtilities() )
2342  {
2343  auto cmap = getColorMap( min, max, params );
2344  auto ztic = params[ "zero-tic" ].as<double>();
2345  ZeroTickedColorMap ztic_cmap( cmap, Color::Black );
2346  if ( ztic <= 0.0 ) return ztic_cmap;
2347  if ( min <= 0.0 && 0.0 <= max )
2348  ztic_cmap.addTick( 0.0, ztic );
2349  ztic_cmap.finalize();
2350  return ztic_cmap;
2351  }
2352 
2353 
2362  template <typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2363  static bool
2364  outputSurfelsAsObj
2365  ( std::ostream& output,
2366  const SurfelRange& surfels,
2367  const TCellEmbedder& embedder )
2368  {
2369  typedef unsigned long Size;
2370  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2371  BOOST_CONCEPT_ASSERT(( concepts::CCellEmbedder< TCellEmbedder > ));
2372  const KSpace& K = embedder.space();
2373  // Number and output vertices.
2374  std::map< Cell, Size > vtx_numbering;
2375  Size n = 1; // OBJ vertex numbering start at 1
2376  for ( auto&& s : surfels )
2377  {
2378  auto primal_vtcs = getPointelRange( K, s );
2379  for ( auto&& primal_vtx : primal_vtcs )
2380  {
2381  if ( ! vtx_numbering.count( primal_vtx ) )
2382  {
2383  vtx_numbering[ primal_vtx ] = n++;
2384  // Output vertex positions
2385  RealPoint p = embedder( primal_vtx );
2386  output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2387  }
2388  }
2389  }
2390  // Outputs all faces
2391  for ( auto&& s : surfels )
2392  {
2393  output << "f";
2394  auto primal_vtcs = getPointelRange( K, s, true );
2395  for ( auto&& primal_vtx : primal_vtcs )
2396  output << " " << vtx_numbering[ primal_vtx ];
2397  output << std::endl;
2398  }
2399  return output.good();
2400  }
2401 
2413  template <typename TAnyDigitalSurface>
2414  static bool
2415  outputPrimalDigitalSurfaceAsObj
2416  ( std::ostream& output,
2418  {
2419  auto embedder = getCellEmbedder( surface );
2420  return outputPrimalDigitalSurfaceAsObj( output, surface, embedder );
2421  }
2422 
2440  template < typename TAnyDigitalSurface,
2441  typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2442  static bool
2443  outputPrimalDigitalSurfaceAsObj
2444  ( std::ostream& output,
2446  const TCellEmbedder& embedder )
2447  {
2448  auto surfels = getSurfelRange( surface, Parameters( "Traversal", "Default" ) );
2449  return outputSurfelsAsObj( output, surfels, embedder );
2450  }
2451 
2460  static bool
2461  outputPrimalIdxDigitalSurfaceAsObj
2462  ( std::ostream& output,
2464  {
2465  auto embedder = getCellEmbedder( surface );
2466  return outputPrimalIdxDigitalSurfaceAsObj( output, surface, embedder );
2467  }
2468 
2482  template <typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2483  static bool
2484  outputPrimalIdxDigitalSurfaceAsObj
2485  ( std::ostream& output,
2487  const TCellEmbedder& embedder )
2488  {
2489  auto idxsurfels = getIdxSurfelRange( surface, Parameters( "Traversal", "Default" ) );
2490  auto surfelmap = surface->surfels();
2491  SurfelRange surfels;
2492  for ( auto&& idx : idxsurfels )
2493  surfels.push_back( surfelmap[ idx ] );
2494  return outputSurfelsAsObj( output, surfels, embedder );
2495  }
2496 
2513  template <typename TDigitalSurfaceContainer>
2514  static bool
2515  outputDualDigitalSurfaceAsObj
2516  ( std::ostream& output,
2518  const Parameters& params = parametersMesh() )
2519  {
2520  auto embedder = getCellEmbedder( surface );
2521  return outputDualDigitalSurfaceAsObj( output, surface, embedder, params );
2522  }
2523 
2546  template < typename TDigitalSurfaceContainer,
2547  typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2548  static bool
2549  outputDualDigitalSurfaceAsObj
2550  ( std::ostream& output,
2552  const TCellEmbedder& embedder,
2553  const Parameters& params = parametersMesh() )
2554  {
2555  typedef unsigned long Size;
2556  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2557  BOOST_CONCEPT_ASSERT(( concepts::CCellEmbedder< TCellEmbedder > ));
2558  std::string dualFaceSubdivision = params[ "faceSubdivision" ].as<std::string>();
2559  const int subdivide
2560  = dualFaceSubdivision == "Naive" ? 1
2561  : dualFaceSubdivision == "Centroid" ? 2
2562  : 0;
2563  const KSpace& K = embedder.space();
2564  // Number and ouput vertices.
2565  std::map< Vertex, Size > vtx_numbering;
2566  std::map< Face, Size > sub_numbering;
2567  Size n = 1; // OBJ vertex numbering start at 1
2568  for ( auto && s : *surface )
2569  {
2570  if ( ! vtx_numbering.count( s ) )
2571  {
2572  vtx_numbering[ s ] = n++;
2573  // Output vertex positions
2574  RealPoint p = embedder( K.unsigns( s ) );
2575  output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2576  }
2577  }
2578  auto faces = surface->allClosedFaces();
2579  // Prepare centroids if necessary
2580  if ( subdivide == 2 )
2581  {
2582  for ( auto&& f : faces )
2583  {
2584  auto vtcs = surface->verticesAroundFace( f );
2585  Size nv = vtcs.size();
2586  if ( nv > 3 )
2587  {
2588  sub_numbering[ f ] = n++;
2590  for ( auto&& s : vtcs ) p += embedder( K.unsigns( s ) );
2591  p /= nv;
2592  output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2593  }
2594  }
2595  }
2596  // Outputs closed faces.
2597  if ( subdivide == 0 )
2598  { // No subdivision
2599  for ( auto&& f : faces )
2600  {
2601  output << "f";
2602  auto vtcs = surface->verticesAroundFace( f );
2603  std::reverse( vtcs.begin(), vtcs.end() );
2604  for ( auto&& s : vtcs )
2605  output << " " << vtx_numbering[ s ];
2606  output << std::endl;
2607  }
2608  }
2609  else if ( subdivide == 1 )
2610  { // naive subdivision
2611  for ( auto&& f : faces )
2612  {
2613  auto vtcs = surface->verticesAroundFace( f );
2614  Size nv = vtcs.size();
2615  for ( Size i = 1; i < nv - 1; ++i )
2616  output << "f " << vtx_numbering[ vtcs[ 0 ] ]
2617  << " " << vtx_numbering[ vtcs[ i+1 ] ]
2618  << " " << vtx_numbering[ vtcs[ i ] ] << std::endl;
2619  }
2620  }
2621  else if ( subdivide == 2 )
2622  { // centroid subdivision
2623  for ( auto&& f : faces )
2624  {
2625  auto vtcs = surface->verticesAroundFace( f );
2626  Size nv = vtcs.size();
2627  if ( nv == 3 )
2628  output << "f " << vtx_numbering[ vtcs[ 0 ] ]
2629  << " " << vtx_numbering[ vtcs[ 2 ] ]
2630  << " " << vtx_numbering[ vtcs[ 1 ] ] << std::endl;
2631  else {
2632  Size c = sub_numbering[ f ];
2633  for ( Size i = 0; i < nv; ++i )
2634  {
2635  output << "f " << c
2636  << " " << vtx_numbering[ vtcs[ (i+1)%nv ] ]
2637  << " " << vtx_numbering[ vtcs[ i ] ] << std::endl;
2638  }
2639  }
2640  }
2641  }
2642  return output.good();
2643  }
2644 
2645 
2646  // -------------------- map I/O services ------------------------------------------
2647  public:
2648  struct CellWriter {
2649  void operator()( std::ostream& output, const KSpace& K, const Cell & cell )
2650  {
2651  for ( Dimension d = 0; d < KSpace::dimension; ++d )
2652  output << " " << K.sKCoord( cell, d );
2653  }
2654  };
2655  struct CellReader {
2656  Cell operator()( std::istream& input, const KSpace& K )
2657  {
2658  Point kp;
2659  for ( Dimension d = 0; d < KSpace::dimension; ++d )
2660  input >> kp[ d ];
2661  return K.uCell( kp );
2662  }
2663  };
2664  struct SCellWriter {
2665  void operator()( std::ostream& output, const KSpace& K, const SCell & scell )
2666  {
2667  CellWriter::operator()( output, K, K.unsigns( scell ) );
2668  output << " " << K.sSign( scell );
2669  }
2670  };
2671  struct SCellReader {
2672  SCell operator()( std::istream& input, const KSpace& K )
2673  {
2674  Point kp;
2675  typename KSpace::Sign s;
2676  for ( Dimension d = 0; d < KSpace::dimension; ++d )
2677  input >> kp[ d ];
2678  input >> s;
2679  return K.sCell( kp, s );
2680  }
2681  };
2682 
2683  template <typename Value>
2684  struct ValueWriter {
2685  void operator()( std::ostream& output, const Value& v )
2686  {
2687  output << " " << v;
2688  }
2689  void operator()( std::ostream& output, const std::vector<Value>& vv )
2690  {
2691  for ( auto&& v : vv ) output << " " << v;
2692  }
2693  };
2694 
2695  template <typename Value>
2696  struct ValueReader {
2697  bool operator()( std::istream& input, Value& value )
2698  {
2699  std::string str;
2700  std::getline( input, str );
2701  // construct a stream from the string
2702  std::stringstream strstr(str);
2703  // use stream iterators to copy the stream to the vector as whitespace separated strings
2704  std::istream_iterator<std::string> it(strstr);
2705  std::istream_iterator<std::string> end;
2706  std::vector<std::string> results(it, end);
2707  std::stringstream sstr( results[ 0 ] );
2708  sstr >> value;
2709  return ( results.size() == 1 ) && input.good();
2710  }
2711 
2712  bool operator()( std::istream& input, std::vector<Value>& values )
2713  {
2714  std::string str;
2715  std::getline( input, str );
2716  // construct a stream from the string
2717  std::stringstream strstr(str);
2718  // use stream iterators to copy the stream to the vector as whitespace separated strings
2719  std::istream_iterator<std::string> it(strstr);
2720  std::istream_iterator<std::string> end;
2721  std::vector<std::string> results(it, end);
2722  values.resize( results.size() );
2723  for ( unsigned int i = 0; i < results.size(); ++i ) {
2724  std::stringstream sstr( results[ i ] );
2725  sstr >> values[ i ];
2726  }
2727  return input.good();
2728  }
2729  };
2730 
2731  // Outputs in \a output a map \a anyMap: SCell -> Value given the
2732  // appropriate value \a writer.
2733  //
2734  // @tparam TSCellMap any model of map SCell -> Value., e.g. std::map<SCell,double>
2735  // @tparam TValueWriter any model of value writer, e.g. ValueWriter<double>
2736  //
2737  // @param[out] output the output stream
2738  // @param[in] K the Khalimsky space where cells are defined.
2739  // @param[in] anyMap the map associated a value to signed cells.
2740  // @param[in] writer the writer that can write values on the ouput
2741  // stream, e.g. ValueWriter<double> to write double value or
2742  // vector<double> values.
2743  template <typename TSCellMap, typename TValueWriter>
2744  static
2745  bool outputSCellMapAsCSV
2746  ( std::ostream& output,
2747  const KSpace& K,
2748  const TSCellMap& anyMap,
2749  const TValueWriter& writer )
2750  {
2751  SCellWriter w;
2752  for ( auto&& v : anyMap )
2753  {
2754  w( output, K, v.first );
2755  writer( output, v.second );
2756  output << std::endl;
2757  }
2758  return output.good();
2759  }
2760 
2761  // Outputs in \a output a map \a anyMap: SCell -> value given the
2762  // appropriate value \a writer.
2763  //
2764  // @tparam TCellMap any model of map Cell -> Value., e.g. std::map<Cell,double>
2765  // @tparam TValueWriter any model of value writer, e.g. ValueWriter<double>
2766  //
2767  // @param[out] output the output stream
2768  // @param[in] K the Khalimsky space where cells are defined.
2769  // @param[in] anyMap the map associated a value to signed cells.
2770  // @param[in] writer the writer that can write values on the ouput
2771  // stream, e.g. ValueWriter<double> to write double value or
2772  // vector<double> values.
2773  template <typename TCellMap, typename TValueWriter>
2774  static
2775  bool outputCellMapAsCSV
2776  ( std::ostream& output,
2777  const KSpace& K,
2778  const TCellMap& anyMap,
2779  const TValueWriter& writer )
2780  {
2781  CellWriter w;
2782  for ( auto&& v : anyMap )
2783  {
2784  w( output, K, v.first );
2785  writer( output, v.second );
2786  output << std::endl;
2787  }
2788  return output.good();
2789  }
2790 
2795  static
2797  {
2798  auto faces = K.uFaces( K.unsigns( s ) );
2799  CellRange primal_vtcs;
2800  for ( auto&& f : faces )
2801  {
2802  if ( K.uDim( f ) == 0 ) primal_vtcs.push_back( f );
2803  }
2804  return primal_vtcs;
2805  }
2806 
2813  static
2814  CellRange getPrimalVertices( const KSpace& K, const Surfel& s, bool ccw )
2815  {
2816  BOOST_STATIC_ASSERT(( KSpace::dimension == 3 ));
2817  CellRange vtcs = getPrimalVertices( K, s );
2818  std::swap( vtcs[ 2 ], vtcs[ 3 ] );
2819  auto orth_dir = K.sOrthDir( s );
2820  auto direct = K.sDirect( s, orth_dir ) ? ccw : ! ccw;
2821  Vector s0s1 = K.uCoords( vtcs[ 1 ] ) - K.uCoords( vtcs[ 0 ] );
2822  Vector s0s2 = K.uCoords( vtcs[ 2 ] ) - K.uCoords( vtcs[ 0 ] );
2823  Vector t = s0s1.crossProduct( s0s2 );
2824  if ( ( ( t[ orth_dir ] > 0.0 ) && direct )
2825  || ( ( t[ orth_dir ] < 0.0 ) && ! direct ) )
2826  std::reverse( vtcs.begin(), vtcs.end() );
2827  return vtcs;
2828  }
2829 
2830 
2831  // ----------------------- Standard services ------------------------------
2832  public:
2833 
2837  Shortcuts() = delete;
2838 
2842  ~Shortcuts() = delete;
2843 
2848  Shortcuts ( const Shortcuts & other ) = delete;
2849 
2854  Shortcuts ( Shortcuts && other ) = delete;
2855 
2861  Shortcuts & operator= ( const Shortcuts & other ) = delete;
2862 
2868  Shortcuts & operator= ( Shortcuts && other ) = delete;
2869 
2870  // ----------------------- Interface --------------------------------------
2871  public:
2872 
2877  void selfDisplay ( std::ostream & out ) const
2878  {
2879  out << "[Shortcuts]";
2880  }
2881 
2886  bool isValid() const
2887  {
2888  return true;
2889  }
2890 
2891  // ------------------------- Protected Datas ------------------------------
2892  protected:
2893 
2894  // ------------------------- Private Datas --------------------------------
2895  private:
2896 
2897  // ------------------------- Hidden services ------------------------------
2898  protected:
2899 
2900  // ------------------------- Internals ------------------------------------
2901  private:
2902 
2903  }; // end of class Shortcuts
2904 
2905 
2912  template <typename T>
2913  std::ostream&
2914  operator<< ( std::ostream & out, const Shortcuts<T> & object );
2915 
2916 } // namespace DGtal
2917 
2918 
2920 // Includes inline functions.
2921 
2922 // //
2924 
2925 #endif // !defined Shortcuts_h
2926 
2927 #undef Shortcuts_RECURSES
2928 #endif // else defined(Shortcuts_RECURSES)
GradientColorMap< Scalar > ColorMap
Definition: Shortcuts.h:189
Iterator read(Polynomial &p, Iterator begin, Iterator end)
::DGtal::PolygonalSurface< RealPoint > PolygonalSurface
Definition: Shortcuts.h:183
static CountedPtr< PolygonalSurface > makePolygonalSurface(CountedPtr< GrayScaleImage > gray_scale_image, const Parameters &params=parametersKSpace()|parametersBinaryImage()|parametersDigitalSurface())
Definition: Shortcuts.h:1922
const ConstIterator & end() const
std::vector< Color > Colors
Definition: Shortcuts.h:188
static const Color Black
Definition: Color.h:388
bool operator()(std::istream &input, Value &value)
Definition: Shortcuts.h:2697
::DGtal::Mesh< RealPoint > Mesh
Definition: Shortcuts.h:181
HyperRectDomain< Space > Domain
std::map< Surfel, IdxSurfel > Surfel2Index
Definition: Shortcuts.h:184
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< BinaryImage > bimage, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:621
std::vector< Arc > ArcRange
The range of arcs is defined as a vector.
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition: Shortcuts.h:554
bool operator()(std::istream &input, std::vector< Value > &values)
Definition: Shortcuts.h:2712
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
std::vector< IdxSurfel > IdxSurfelRange
Definition: Shortcuts.h:174
static std::vector< CountedPtr< LightDigitalSurface > > makeLightDigitalSurfaces(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1112
Cell operator()(std::istream &input, const KSpace &K)
Definition: Shortcuts.h:2656
Integer sKCoord(const SCell &c, Dimension k) const
Return its Khalimsky coordinate along [k].
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< GrayScaleImage > gray_scale_image, const Parameters &params=parametersKSpace()|parametersBinaryImage()|parametersDigitalSurface())
Definition: Shortcuts.h:1965
VertexRange allVertices() const
static void digitalSurface2DualTriangulatedSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, TriangulatedSurface< typename CellEmbedder::Value > &trisurf, VertexMap &vertexmap)
LightDigitalSurface::Arc Arc
Definition: Shortcuts.h:162
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1202
void operator()(std::ostream &output, const std::vector< Value > &vv)
Definition: Shortcuts.h:2689
Aim: Smart pointer based on reference counts.
Definition: CountedPtr.h:79
Trace trace
Definition: Common.h:144
IndexedPropertyMap< SCell > surfels()
bool sDirect(const SCell &p, Dimension k) const
Return 'true' if the direct orientation of [p] along [k] is in the positive coordinate direction.
static std::map< std::string, std::string > getPolynomialList()
Definition: Shortcuts.h:232
::DGtal::Color Color
Definition: Shortcuts.h:187
std::vector< RealVector > RealVectors
Definition: Shortcuts.h:176
LightDigitalSurface::Face Face
Definition: Shortcuts.h:163
TickedColorMap< Scalar, ColorMap > ZeroTickedColorMap
Definition: Shortcuts.h:190
KSpace::SurfelSet SurfelSet
defines a set of surfels
Definition: Shortcuts.h:146
const Point & upperBound() const
Return the upper bound for digital points in this space.
Space::Integer Integer
Integer numbers.
Definition: Shortcuts.h:112
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
static void polygonalSurface2Mesh(const PolygonalSurface< Point > &polysurf, Mesh< Point > &mesh)
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1472
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
DGtal::uint32_t Dimension
Definition: Common.h:127
HyperRectDomain< Space > Domain
An (hyper-)rectangular domain.
Definition: Shortcuts.h:124
void attach(ConstAlias< EuclideanShape > shape)
static bool saveGrayScaleImage(CountedPtr< GrayScaleImage > gray_scale_image, std::string output)
Definition: Shortcuts.h:777
ImageContainerBySTLVector< Domain, double > DoubleImage
defines a double image with (hyper-)rectangular domain.
Definition: Shortcuts.h:144
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:101
::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface
defines an arbitrary digital surface over a binary image.
Definition: Shortcuts.h:155
void addColor(const Color &color)
ImageContainerBySTLVector< Domain, GrayScale > GrayScaleImage
defines a grey-level image with (hyper-)rectangular domain.
Definition: Shortcuts.h:140
static Parameters defaultParameters()
Definition: Shortcuts.h:199
Aim: This class converts a string polynomial expression in a multivariate polynomial.
static void digitalSurface2DualPolygonalSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, PolygonalSurface< typename CellEmbedder::Value > &polysurf, VertexMap &vertexmap)
const Point & upperBound() const
GaussDigitizer< Space, ImplicitShape3D > DigitizedImplicitShape3D
defines the digitization of an implicit shape.
Definition: Shortcuts.h:136
SCell operator()(std::istream &input, const KSpace &K)
Definition: Shortcuts.h:2672
BOOST_CONCEPT_ASSERT((concepts::CCellularGridSpaceND< TKSpace >))
IdxDigitalSurface::ArcRange IdxArcRange
Definition: Shortcuts.h:168
Aim: A cell embedder is a mapping from unsigned cells to Euclidean points. It adds inner types to fun...
Definition: CCellEmbedder.h:96
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
static bool saveBinaryImage(CountedPtr< BinaryImage > bimage, std::string output)
Definition: Shortcuts.h:701
static CountedPtr< DoubleImage > makeDoubleImage(Domain aDomain)
Definition: Shortcuts.h:923
static IdxRange getRangeMatch(const std::vector< TValue > &s1, const std::vector< TValue > &s2, bool perfect=false)
Definition: Shortcuts.h:2251
bool build(ConstAlias< DigitalSurfaceContainer > surfContainer)
BreadthFirstVisitor< MyDigitalSurface > Visitor
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
Definition: MPolynomial.h:58
MPolynomial< Space::dimension, Scalar > ScalarPolynomial
defines a multi-variate polynomial : RealPoint -> Scalar
Definition: Shortcuts.h:131
CellRange PointelRange
Definition: Shortcuts.h:172
std::map< Cell, IdxVertex > Cell2Index
Definition: Shortcuts.h:185
Domain domain
SetOfSurfels< KSpace, SurfelSet > ExplicitSurfaceContainer
defines a heavy container that represents any digital surface.
Definition: Shortcuts.h:153
static CountedPtr< GrayScaleImage > makeGrayScaleImage(Domain aDomain)
Definition: Shortcuts.h:729
ConstIterator begin() const
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1268
TKSpace KSpace
Digital cellular space.
Definition: Shortcuts.h:108
void operator()(std::ostream &output, const Value &v)
Definition: Shortcuts.h:2685
static void triangulatedSurface2Mesh(const TriangulatedSurface< Point > &trisurf, Mesh< Point > &mesh)
IndexedDigitalSurface< ExplicitSurfaceContainer > IdxDigitalSurface
defines a connected or not indexed digital surface.
Definition: Shortcuts.h:157
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< DigitizedImplicitShape3D > shape_digitization, Domain shapeDomain, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:589
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
std::vector< SCell > SCellRange
Definition: Shortcuts.h:170
auto crossProduct(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::crossProduct(*this, v))
Cross product with a PointVector.
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
std::set< IdxSurfel > IdxSurfelSet
Definition: Shortcuts.h:169
static Parameters parametersMesh()
Definition: Shortcuts.h:1770
static bool exportMTLNewMaterial(std::ostream &output_mtl, unsigned int idxMaterial, const Color &ambient_color, const Color &diffuse_color, const Color &specular_color)
static CanonicCellEmbedder< KSpace > getCellEmbedder(const KSpace &K)
Definition: Shortcuts.h:433
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
LightDigitalSurface::Vertex Vertex
Definition: Shortcuts.h:161
static bool digitalSurface2PrimalPolygonalSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, PolygonalSurface< typename CellEmbedder::Value > &polysurf, CellMap &cellmap)
static bool exportOBJ(std::ostream &output, const TriangulatedSurface< Point > &trisurf)
LightDigitalSurface::ArcRange ArcRange
Definition: Shortcuts.h:164
static void sMakeBoundary(SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
SCellRange SurfelRange
Definition: Shortcuts.h:173
Dimension sOrthDir(const SCell &s) const
Given a signed surfel [s], returns its orthogonal direction (ie, the coordinate where the surfel is c...
ch reverse()
void operator()(std::ostream &output, const KSpace &K, const SCell &scell)
Definition: Shortcuts.h:2665
ImageContainerBySTLVector< Domain, bool > BinaryImage
defines a black and white image with (hyper-)rectangular domain.
Definition: Shortcuts.h:138
DigitalSurfaceContainer::SCell SCell
static Parameters parametersGrayScaleImage()
Definition: Shortcuts.h:716
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
ImageContainerBySTLVector< Domain, float > FloatImage
defines a float image with (hyper-)rectangular domain.
Definition: Shortcuts.h:142
static bool mesh2PolygonalSurface(const Mesh< Point > &mesh, PolygonalSurface< Point > &polysurf)
static Parameters parametersImplicitShape3D()
Definition: Shortcuts.h:260
Aim: A trivial embedder for signed and unsigned cell, which corresponds to the canonic injection of c...
static Parameters parametersBinaryImage()
Definition: Shortcuts.h:540
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Space::RealVector RealVector
Vector with floating-point coordinates.
Definition: Shortcuts.h:118
Aim: Represents a triangulated surface. The topology is stored with a half-edge data structure....
Aim: From a point predicate (model of concepts::CPointPredicate), this class constructs another point...
Definition: KanungoNoise.h:84
bool isValid() const
Definition: Shortcuts.h:2886
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Space::RealPoint RealPoint
Point with floating-point coordinates.
Definition: Shortcuts.h:120
::DGtal::DigitalSurface< LightSurfaceContainer > LightDigitalSurface
defines a connected digital surface over a binary image.
Definition: Shortcuts.h:151
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:327
static Parameters parametersDigitalSurface()
Definition: Shortcuts.h:989
IdxDigitalSurface::Vertex IdxVertex
Definition: Shortcuts.h:166
DigitalSurfaceContainer::Cell Cell
IdxVertex Idx
Definition: Shortcuts.h:178
double norm(const NormType type=L_2) const
std::vector< Cell > CellRange
Definition: Shortcuts.h:171
static ZeroTickedColorMap getZeroTickedColorMap(Scalar min, Scalar max, const Parameters &params=parametersUtilities())
Definition: Shortcuts.h:2339
static CellRange getPrimalVertices(const KSpace &K, const Surfel &s, bool ccw)
Definition: Shortcuts.h:2814
static bool exportOBJwithFaceNormalAndColor(std::ostream &output_obj, const std::string &mtl_filename, const TTriangulatedOrPolygonalSurface &polysurf, const std::vector< typename TTriangulatedOrPolygonalSurface::Point > &normals, const std::vector< Color > &diffuse_colors, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Cell uCell(const PreCell &c) const
From an unsigned cell, returns an unsigned cell lying into this Khalismky space.
static CountedPtr< Mesh > makeMesh(CountedPtr< TriangulatedSurface > triSurf, const Color &aColor=Color::White)
Definition: Shortcuts.h:1805
const ConstIterator & begin() const
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2075
static KSpace getKSpace(CountedPtr< BinaryImage > bimage, Parameters params=parametersKSpace())
Definition: Shortcuts.h:349
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
static Parameters parametersUtilities()
Definition: Shortcuts.h:2226
KSpace::Space Space
Digital space.
Definition: Shortcuts.h:110
Surfel Vertex
Defines the type for a vertex.
Z3i::KSpace KSpace
Sign sSign(const SCell &c) const
Return its sign.
const Point & lowerBound() const
Return the lower bound for digital points in this space.
std::vector< IdxVertex > IdxRange
Definition: Shortcuts.h:179
static CountedPtr< Mesh > makeMesh(CountedPtr< PolygonalSurface > polySurf, const Color &aColor=Color::White)
Definition: Shortcuts.h:1822
unsigned char GrayScale
The type for 8-bits gray-scale elements.
Definition: Shortcuts.h:126
static CountedPtr< FloatImage > makeFloatImage(Domain aDomain)
Definition: Shortcuts.h:857
RealVector::Component Scalar
Floating-point numbers.
Definition: Shortcuts.h:122
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, const TCellEmbedder &embedder, const RealVectors &normals, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
Definition: Shortcuts.h:1604
static void polygonalSurface2TriangulatedSurface(const PolygonalSurface< Point > &polysurf, TriangulatedSurface< Point > &trisurf, bool centroid=true)
DGtal is the top-level namespace which contains all DGtal functions and types.
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(Surfel2Index &s2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2002
static Parameters parametersKSpace()
Definition: Shortcuts.h:306
static CellRange getPrimalVertices(const KSpace &K, const SCell &s)
Definition: Shortcuts.h:2796
Aim: Transforms a graph visitor into a single pass input range.
static KSpace getKSpace(Parameters params=parametersKSpace()|parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:481
static bool exportFile(const std::string &filename, const TContainer &anImage, const TFunctor &aFunctor=TFunctor())
Point uCoords(const Cell &c) const
Return its digital coordinates.
static Dimension size()
int max(int a, int b)
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters &params=parametersImplicitShape3D())
Definition: Shortcuts.h:277
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< PolygonalSurface > polySurf, const Parameters &params=parametersMesh())
Definition: Shortcuts.h:1880
static KSpace getKSpace(CountedPtr< GrayScaleImage > gimage, Parameters params=parametersKSpace())
Definition: Shortcuts.h:373
std::ostream & warning()
Aim: Represents a digital surface with the topology of its dual surface. Its aim is to mimick the sta...
const Domain & domain() const
static std::vector< TValue > getMatchedRange(const std::vector< TValue > &range, const IdxRange &match)
Definition: Shortcuts.h:2286
Aim: This concept describes a cellular grid space in nD. In these spaces obtained by cartesian produc...
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< Mesh > aMesh)
Definition: Shortcuts.h:1788
const Point & lowerBound() const
static ColorMap getColorMap(Scalar min, Scalar max, const Parameters &params=parametersUtilities())
Definition: Shortcuts.h:2301
ConstIterator end() const
static Parameters parametersDigitizedImplicitShape3D()
Definition: Shortcuts.h:456
std::vector< Scalar > Scalars
Definition: Shortcuts.h:175
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: SetOfSurfels.h:73
Dimension uDim(const Cell &p) const
Return the dimension of the cell [p].
Aim: Define a simple Foreground predicate thresholding image values between two constant values (the ...
IdxDigitalSurface::Arc IdxArc
Definition: Shortcuts.h:167
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:516
std::vector< RealPoint > RealPoints
Definition: Shortcuts.h:177
void operator()(std::ostream &output, const KSpace &K, const Cell &cell)
Definition: Shortcuts.h:2649
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2055
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(Surfel2Index &s2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:1838
Space::Point Point
Point with integer coordinates.
Definition: Shortcuts.h:114
HalfEdgeDataStructure::HalfEdgeIndex Arc
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:1856
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
static const Color White
Definition: Color.h:390
void selfDisplay(std::ostream &out) const
Definition: Shortcuts.h:2877
LightDigitalSurface::SCell SCell
Definition: Shortcuts.h:160
static CanonicSCellEmbedder< KSpace > getSCellEmbedder(const KSpace &K)
Definition: Shortcuts.h:441
Cells uFaces(const Cell &c) const
Return the proper faces of [c] (chain of lower incidence) that belong to the space.
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2022
static Self zero
Static const for zero PointVector.
Definition: PointVector.h:1582
static PointelRange getPointelRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:1396
KSpace K
LightDigitalSurface::Surfel Surfel
Definition: Shortcuts.h:158
Domain getDomain() const
LightImplicitDigitalSurface< KSpace, BinaryImage > LightSurfaceContainer
Definition: Shortcuts.h:149
::DGtal::TriangulatedSurface< RealPoint > TriangulatedSurface
Definition: Shortcuts.h:182
std::ostream & error()
Aim: This class adapts any colormap to add "ticks" in the colormap colors.
static IdxSurfelRange getIdxSurfelRange(CountedPtr< IdxDigitalSurface > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1537
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< DigitizedImplicitShape3D > shape_digitization, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:569
static const constexpr Dimension dimension
LightDigitalSurface::Cell Cell
Definition: Shortcuts.h:159
Aim: a cellular embedder for images. (default constructible, copy constructible, assignable)....
static bool mesh2TriangulatedSurface(const Mesh< Point > &mesh, TriangulatedSurface< Point > &trisurf)
DigitalSurfaceContainer::Surfel Surfel
ImplicitPolynomial3Shape< Space > ImplicitShape3D
Definition: Shortcuts.h:134
IdxDigitalSurface::Vertex IdxSurfel
Definition: Shortcuts.h:165
Space::Vector Vector
Vector with integer coordinates.
Definition: Shortcuts.h:116
SCell sCell(const SPreCell &c) const
From a signed cell, returns a signed cell lying into this Khalismky space.
static CountedPtr< PolygonalSurface > makePolygonalSurface(CountedPtr< Mesh > aMesh)
Definition: Shortcuts.h:1900
static const KSpace & refKSpace(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:414
static CountedPtr< LightDigitalSurface > makeLightDigitalSurface(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1055
Aim: Represents a polygon mesh, i.e. a 2-dimensional combinatorial surface whose faces are (topologic...
TEuclideanRing Component
Type for Vector elements.
Definition: PointVector.h:614