DGtal  1.2.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)
35 #define Shortcuts_RECURSES
36 
37 #if !defined Shortcuts_h
39 #define Shortcuts_h
40 
42 // Inclusions
43 #include <cstdlib>
44 #include <iostream>
45 #include <fstream>
46 #include <sstream>
47 #include <tuple>
48 #include <iterator>
49 #include <string>
50 #include "DGtal/base/Common.h"
51 #include "DGtal/base/CountedPtr.h"
52 #include "DGtal/kernel/domains/HyperRectDomain.h"
53 #include "DGtal/kernel/RegularPointEmbedder.h"
54 #include "DGtal/math/MPolynomial.h"
55 #include "DGtal/math/Statistic.h"
56 #include "DGtal/images/ImageContainerBySTLVector.h"
57 #include "DGtal/images/IntervalForegroundPredicate.h"
58 #include <DGtal/images/ImageLinearCellEmbedder.h>
59 #include "DGtal/shapes/implicit/ImplicitPolynomial3Shape.h"
60 #include "DGtal/shapes/GaussDigitizer.h"
61 #include "DGtal/shapes/ShapeGeometricFunctors.h"
62 #include "DGtal/shapes/MeshHelpers.h"
63 #include "DGtal/topology/CCellularGridSpaceND.h"
64 #include "DGtal/topology/LightImplicitDigitalSurface.h"
65 #include "DGtal/topology/SetOfSurfels.h"
66 #include "DGtal/topology/DigitalSurface.h"
67 #include "DGtal/topology/IndexedDigitalSurface.h"
68 #include "DGtal/topology/SurfelAdjacency.h"
69 #include "DGtal/topology/CCellEmbedder.h"
70 #include "DGtal/topology/CanonicCellEmbedder.h"
71 #include "DGtal/topology/CanonicSCellEmbedder.h"
72 #include "DGtal/topology/helpers/Surfaces.h"
73 #include "DGtal/geometry/volumes/KanungoNoise.h"
74 #include "DGtal/shapes/Mesh.h"
75 #include "DGtal/io/Color.h"
76 #include "DGtal/io/colormaps/GradientColorMap.h"
77 #include "DGtal/io/colormaps/TickedColorMap.h"
78 #include "DGtal/io/readers/MPolynomialReader.h"
79 #include "DGtal/io/readers/GenericReader.h"
80 #include "DGtal/io/writers/GenericWriter.h"
81 #include "DGtal/io/writers/MeshWriter.h"
82 #include "DGtal/graph/BreadthFirstVisitor.h"
83 #include "DGtal/graph/DepthFirstVisitor.h"
84 #include "DGtal/graph/GraphVisitorRange.h"
85 #include "DGtal/helpers/Parameters.h"
87 
88 namespace DGtal
89 {
90 
92  // template class Shortcuts
103  template < typename TKSpace >
104  class Shortcuts
105  {
107 
108  // ----------------------- Usual space types --------------------------------------
109  public:
111  typedef TKSpace KSpace;
113  typedef typename KSpace::Space Space;
115  typedef typename Space::Integer Integer;
117  typedef typename Space::Point Point;
119  typedef typename Space::Vector Vector;
121  typedef typename Space::RealVector RealVector;
123  typedef typename Space::RealPoint RealPoint;
125  typedef typename RealVector::Component Scalar;
129  typedef unsigned char GrayScale;
130 
131  // ----------------------- Shortcut types --------------------------------------
132  public:
149  typedef typename KSpace::SurfelSet SurfelSet;
154  typedef ::DGtal::DigitalSurface< LightSurfaceContainer > LightDigitalSurface;
158  typedef ::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface;
162  typedef typename LightDigitalSurface::Cell Cell;
165  typedef typename LightDigitalSurface::Arc Arc;
166  typedef typename LightDigitalSurface::Face Face;
170  typedef typename IdxDigitalSurface::Arc IdxArc;
172  typedef std::set< IdxSurfel > IdxSurfelSet;
173  typedef std::vector< SCell > SCellRange;
174  typedef std::vector< Cell > CellRange;
177  typedef std::vector< IdxSurfel > IdxSurfelRange;
178  typedef std::vector< Scalar > Scalars;
179  typedef std::vector< RealVector > RealVectors;
180  typedef std::vector< RealPoint > RealPoints;
181  typedef IdxVertex Idx;
182  typedef std::vector< IdxVertex > IdxRange;
183 
184  typedef ::DGtal::Mesh<RealPoint> Mesh;
185  typedef ::DGtal::TriangulatedSurface<RealPoint> TriangulatedSurface;
186  typedef ::DGtal::PolygonalSurface<RealPoint> PolygonalSurface;
187  typedef std::map<Surfel, IdxSurfel> Surfel2Index;
188  typedef std::map<Cell, IdxVertex> Cell2Index;
189 
190  typedef ::DGtal::Color Color;
191  typedef std::vector< Color > Colors;
194 
195  // ----------------------- Static services --------------------------------------
196  public:
197 
198  // ----------------------- General static services ------------------------------
199  public:
200 
203  {
205  | parametersKSpace()
210  | parametersMesh()
212  }
213 
214  // ----------------------- ImplicitShape3D static services ------------------------
215  public:
216 
234  static std::map< std::string, std::string >
236  {
237  std::vector< std::pair< std::string, std::string > >
238  Ps = { { "sphere1", "x^2+y^2+z^2-1" },
239  { "sphere9", "x^2+y^2+z^2-81" },
240  { "ellipsoid", "3*x^2+2*y^2+z^2-90" },
241  { "cylinder", "x^2+2*z^2-90" },
242  { "torus", "(x^2+y^2+z^2+6*6-2*2)^2-4*6*6*(x^2+y^2)" },
243  { "rcube", "x^4+y^4+z^4-6561" },
244  { "goursat", "-1*(8-0.03*x^4-0.03*y^4-0.03*z^4+2*x^2+2*y^2+2*z^2)" },
245  { "goursat-hole", "x^4+y^4+z^4-2*4*(x^2+y^2+z^2)+2*4*4-2" },
246  { "distel", "10000-(x^2+y^2+z^2+1000*(x^2+y^2)*(x^2+z^2)*(y^2+z^2))"},
247  { "leopold", "(x^2*y^2*z^2+4*x^2+4*y^2+3*z^2)-100" },
248  { "diabolo", "x^2-(y^2+z^2)^2" },
249  { "heart", "-1*(x^2+2.25*y^2+z^2-1)^3+x^2*z^3+0.1125*y^2*z^3" },
250  { "crixxi", "-0.9*(y^2+z^2-1)^2-(x^2+y^2-1)^3" } };
251  std::map< std::string, std::string > L;
252  for ( auto p : Ps )
253  L[ p.first ] = p.second;
254  return L;
255  }
256 
265  {
266  return Parameters
267  ( "polynomial", "sphere1" )
268  ( "projectionMaxIter", 20 )
269  ( "projectionAccuracy", 0.0001 )
270  ( "projectionGamma", 0.5 );
271  }
272 
282  {
283  typedef MPolynomialReader< Space::dimension, Scalar> Polynomial3Reader;
284  std::string poly_str = params[ "polynomial" ].as<std::string>();
285  // Recognizes specific strings as polynomials.
286  auto PL = getPolynomialList();
287  if ( PL[ poly_str ] != "" ) poly_str = PL[ poly_str ];
288  ScalarPolynomial poly;
289  Polynomial3Reader reader;
290  std::string::const_iterator iter
291  = reader.read( poly, poly_str.begin(), poly_str.end() );
292  if ( iter != poly_str.end() )
293  {
294  trace.error() << "[Shortcuts::makeImplicitShape3D]"
295  << " ERROR reading polynomial: I read only <"
296  << poly_str.substr( 0, iter - poly_str.begin() )
297  << ">, and I built P=" << poly << std::endl;
298  }
299  return CountedPtr<ImplicitShape3D>( new ImplicitShape3D( poly ) );
300  }
301 
302  // ----------------------- KSpace static services ------------------------------
303  public:
304 
311  {
312  return Parameters
313  ( "closed", 1 )
314  ( "gridsizex", 1.0 )
315  ( "gridsizey", 1.0 )
316  ( "gridsizez", 1.0 );
317  }
318 
331  static KSpace getKSpace( const Point& low, const Point& up,
332  Parameters params = parametersKSpace() )
333  {
334  int closed = params[ "closed" ].as<int>();
335  KSpace K;
336  if ( ! K.init( low, up, closed ) )
337  trace.error() << "[Shortcuts::getKSpace]"
338  << " Error building Khalimsky space K=" << K << std::endl;
339  return K;
340  }
341 
354  Parameters params = parametersKSpace() )
355  {
356  int closed = params[ "closed" ].as<int>();
357  KSpace K;
358  if ( ! K.init( bimage->domain().lowerBound(),
359  bimage->domain().upperBound(),
360  closed ) )
361  trace.error() << "[Shortcuts::getKSpace]"
362  << " Error building Khalimsky space K=" << K << std::endl;
363  return K;
364  }
365 
378  Parameters params = parametersKSpace() )
379  {
380  int closed = params[ "closed" ].as<int>();
381  KSpace K;
382  if ( ! K.init( gimage->domain().lowerBound(),
383  gimage->domain().upperBound(),
384  closed ) )
385  trace.error() << "[Shortcuts::getKSpace]"
386  << " Error building Khalimsky space K=" << K << std::endl;
387  return K;
388  }
389 
393  template <typename TDigitalSurfaceContainer>
394  static KSpace
397  {
398  return surface->container().space();
399  }
400 
404  template <typename TDigitalSurfaceContainer>
405  static KSpace
408  {
409  return surface->container().space();
410  }
411 
415  template <typename TDigitalSurfaceContainer>
416  static const KSpace&
419  {
420  return surface->container().space();
421  }
422 
426  template <typename TDigitalSurfaceContainer>
427  static const KSpace&
430  {
431  return surface->container().space();
432  }
433 
438  {
439  return CanonicCellEmbedder<KSpace>( K );
440  }
441 
446  {
448  }
449 
450 
451  // ----------------------- DigitizedImplicitShape3D static services --------------
452  public:
453 
461  {
462  return Parameters
463  ( "minAABB", -10.0 )
464  ( "maxAABB", 10.0 )
465  ( "gridstep", 1.0 )
466  ( "offset", 5.0 );
467  }
468 
469 
484  static KSpace
487  {
488  Scalar min_x = params[ "minAABB" ].as<Scalar>();
489  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
490  Scalar h = params[ "gridstep" ].as<Scalar>();
491  Scalar offset = params[ "offset" ].as<Scalar>();
492  bool closed = params[ "closed" ].as<int>();
493  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
494  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
496  dshape->init( p1, p2, h );
497  Domain domain = dshape->getDomain();
498  KSpace K;
499  if ( ! K.init( domain.lowerBound(), domain.upperBound(), closed ) )
500  trace.error() << "[Shortcuts::getKSpace]"
501  << " Error building Khalimsky space K=" << K << std::endl
502  << "Note: if you use decimal values, check your locale for decimal point '.' or ','."
503  << std::endl;
504  return K;
505  }
506 
524  {
525  Scalar min_x = params[ "minAABB" ].as<Scalar>();
526  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
527  Scalar h = params[ "gridstep" ].as<Scalar>();
528  Scalar offset = params[ "offset" ].as<Scalar>();
529  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
530  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
532  dshape->attach( shape );
533  dshape->init( p1, p2, h );
534  return dshape;
535  }
536 
537 
538  // ----------------------- BinaryImage static services --------------------------
539  public:
540 
547  {
548  return Parameters
549  ( "noise", 0.0 )
550  ( "thresholdMin", 0 )
551  ( "thresholdMax", 255 );
552  }
553 
560  makeBinaryImage( Domain shapeDomain )
561  {
562  return CountedPtr<BinaryImage>( new BinaryImage( shapeDomain ) );
563  }
564 
576  Parameters params = parametersBinaryImage() )
577  {
578  return makeBinaryImage( shape_digitization,
579  shape_digitization->getDomain(),
580  params );
581  }
582 
596  Domain shapeDomain,
597  Parameters params = parametersBinaryImage() )
598  {
599  const Scalar noise = params[ "noise" ].as<Scalar>();
600  CountedPtr<BinaryImage> img ( new BinaryImage( shapeDomain ) );
601  if ( noise <= 0.0 )
602  {
603  std::transform( shapeDomain.begin(), shapeDomain.end(),
604  img->begin(),
605  [&shape_digitization]
606  ( const Point& p ) { return (*shape_digitization)(p); } );
607  }
608  else
609  {
610  typedef KanungoNoise< DigitizedImplicitShape3D, Domain > KanungoPredicate;
611  KanungoPredicate noisy_dshape( *shape_digitization, shapeDomain, noise );
612  std::transform( shapeDomain.begin(), shapeDomain.end(),
613  img->begin(),
614  [&noisy_dshape] ( const Point& p ) { return noisy_dshape(p); } );
615  }
616  return img;
617  }
618 
628  Parameters params = parametersBinaryImage() )
629  {
630  const Scalar noise = params[ "noise" ].as<Scalar>();
631  if ( noise <= 0.0 ) return bimage;
632  typedef KanungoNoise< BinaryImage, Domain > KanungoPredicate;
633  const Domain shapeDomain = bimage->domain();
634  CountedPtr<BinaryImage> img ( new BinaryImage( shapeDomain ) );
635  KanungoPredicate noisy_dshape( *bimage, shapeDomain, noise );
636  std::transform( shapeDomain.begin(), shapeDomain.end(),
637  img->begin(),
638  [&noisy_dshape] ( const Point& p ) { return noisy_dshape(p); } );
639  return img;
640  }
641 
655  ( std::string input,
656  Parameters params = parametersBinaryImage() )
657  {
658  int thresholdMin = params["thresholdMin"].as<int>();
659  int thresholdMax = params["thresholdMax"].as<int>();
661  Domain domain = image.domain();
663  ThresholdedImage tImage( image, thresholdMin, thresholdMax );
665  std::transform( domain.begin(), domain.end(),
666  img->begin(),
667  [tImage] ( const Point& p ) { return tImage(p); } );
668  return makeBinaryImage( img, params );
669  }
670 
684  ( CountedPtr<GrayScaleImage> gray_scale_image,
685  Parameters params = parametersBinaryImage() )
686  {
687  int thresholdMin = params["thresholdMin"].as<int>();
688  int thresholdMax = params["thresholdMax"].as<int>();
689  Domain domain = gray_scale_image->domain();
691  ThresholdedImage tImage( *gray_scale_image, thresholdMin, thresholdMax );
693  std::transform( domain.begin(), domain.end(),
694  img->begin(),
695  [tImage] ( const Point& p ) { return tImage(p); } );
696  return makeBinaryImage( img, params );
697  }
698 
699 
705  static bool
707  ( CountedPtr<BinaryImage> bimage, std::string output )
708  {
709  auto gray_scale_image = makeGrayScaleImage( bimage );
710  return saveGrayScaleImage( gray_scale_image, output );
711  }
712 
713 
714  // ----------------------- GrayScaleImage static services -------------------------
715  public:
716 
723  {
724  return Parameters
725  ( "qShift", 128.0 )
726  ( "qSlope", 1.0 );
727  }
728 
736  {
737  return CountedPtr<GrayScaleImage>( new GrayScaleImage( aDomain ) );
738  }
739 
748  ( std::string input )
749  {
751  return CountedPtr<GrayScaleImage>( new GrayScaleImage( image ) );
752  }
753 
762  ( CountedPtr<BinaryImage> binary_image,
763  std::function< GrayScale( bool ) > const & bool2grayscale
764  = [] ( bool v ) { return v ? (unsigned char) 255 : (unsigned char) 0; }
765  // JOL: (GrayScale) was not working with visual C++: error C2065
766  )
767  {
768  const Domain domain = binary_image->domain();
769  CountedPtr<GrayScaleImage> gray_scale_image( new GrayScaleImage( domain ) );
770  std::transform( binary_image->begin(), binary_image->end(),
771  gray_scale_image->begin(),
772  bool2grayscale );
773  return gray_scale_image;
774  }
775 
781  static bool
783  ( CountedPtr<GrayScaleImage> gray_scale_image, std::string output )
784  {
786  ::exportFile( output, *gray_scale_image );
787  }
788 
789 
803  ( CountedPtr<FloatImage> fimage,
805  {
806  float qShift = params[ "qShift" ].as<float>();
807  float qSlope = params[ "qSlope" ].as<float>();
808  std::function< unsigned char( float ) > f
809  = [qShift,qSlope] (float v)
810  { return (unsigned char) std::min( 255.0f, std::max( 0.0f, qSlope * v + qShift ) ); };
811  Domain domain = fimage->domain();
812  auto gimage = makeGrayScaleImage( domain );
813  auto it = gimage->begin();
814  for ( auto p : domain )
815  {
816  float val = (*fimage)( p );
817  *it++ = f( val );
818  }
819  return gimage;
820  }
821 
835  ( CountedPtr<DoubleImage> fimage,
837  {
838  double qShift = params[ "qShift" ].as<double>();
839  double qSlope = params[ "qSlope" ].as<double>();
840  std::function< unsigned char( double ) > f
841  = [qShift,qSlope] (double v)
842  { return (unsigned char) std::min( 255.0, std::max( 0.0, qSlope * v + qShift ) ); };
843  Domain domain = fimage->domain();
844  auto gimage = makeGrayScaleImage( domain );
845  auto it = gimage->begin();
846  for ( auto p : domain )
847  {
848  double val = (*fimage)( p );
849  *it++ = f( val );
850  }
851  return gimage;
852  }
853 
854  // ----------------------- FloatImage static services -------------------------
855  public:
856 
864  {
865  return CountedPtr<FloatImage>( new FloatImage( aDomain ) );
866  }
867 
876  ( std::string input )
877  {
879  return CountedPtr<FloatImage>( new FloatImage( image ) );
880  }
881 
899  {
900  Scalar min_x = params[ "minAABB" ].as<Scalar>();
901  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
902  Scalar h = params[ "gridstep" ].as<Scalar>();
903  Scalar offset = params[ "offset" ].as<Scalar>();
904  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
905  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
907  dshape->attach( shape );
908  dshape->init( p1, p2, h );
909  Domain domain = dshape->getDomain();
910  auto fimage = makeFloatImage( domain );
911  auto it = fimage->begin();
912  for ( auto p : domain )
913  {
914  float val = (float) (*shape)( p );
915  *it++ = val;
916  }
917  return fimage;
918  }
919 
920  // ----------------------- DoubleImage static services -------------------------
921  public:
922 
930  {
931  return CountedPtr<DoubleImage>( new DoubleImage( aDomain ) );
932  }
933 
942  ( std::string input )
943  {
945  return CountedPtr<DoubleImage>( new DoubleImage( image ) );
946  }
947 
965  {
966  Scalar min_x = params[ "minAABB" ].as<Scalar>();
967  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
968  Scalar h = params[ "gridstep" ].as<Scalar>();
969  Scalar offset = params[ "offset" ].as<Scalar>();
970  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
971  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
973  dshape->attach( shape );
974  dshape->init( p1, p2, h );
975  Domain domain = dshape->getDomain();
976  auto fimage = makeDoubleImage( domain );
977  auto it = fimage->begin();
978  for ( auto p : domain )
979  {
980  double val = (double) (*shape)( p );
981  *it++ = val;
982  }
983  return fimage;
984  }
985 
986  // ----------------------- DigitalSurface static services ------------------------
987  public:
988 
996  {
997  return Parameters
998  ( "surfelAdjacency", 0 )
999  ( "nbTriesToFindABel", 100000 )
1000  ( "surfaceComponents", "AnyBig" )
1001  ( "surfaceTraversal", "Default" );
1002  }
1003 
1007  template <typename TDigitalSurfaceContainer>
1011  {
1012  return getCellEmbedder( refKSpace( surface ) );
1013  }
1014 
1018  template <typename TDigitalSurfaceContainer>
1022  {
1023  return getSCellEmbedder( refKSpace( surface ) );
1024  }
1025 
1029  template <typename TDigitalSurfaceContainer>
1033  {
1034  return getCellEmbedder( refKSpace( surface ) );
1035  }
1036 
1040  template <typename TDigitalSurfaceContainer>
1044  {
1045  return getSCellEmbedder( refKSpace( surface ) );
1046  }
1047 
1061  ( CountedPtr<BinaryImage> bimage,
1062  const KSpace& K,
1063  const Parameters& params = parametersDigitalSurface() )
1064  {
1065  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1066  int nb_tries_to_find_a_bel = params[ "nbTriesToFindABel" ].as<int>();
1067  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1068 
1069  // We have to search for a surfel that belongs to a big connected component.
1071  Surfel bel;
1072  Scalar minsize = bimage->extent().norm();
1073  unsigned int nb_surfels = 0;
1074  unsigned int tries = 0;
1075  do
1076  {
1077  try { // Search initial bel
1078  bel = Surfaces<KSpace>::findABel( K, *bimage, nb_tries_to_find_a_bel );
1079  } catch (DGtal::InputException& e) {
1080  trace.error() << "[Shortcuts::makeLightDigitalSurface]"
1081  << " ERROR Unable to find bel. " << e << std::endl;
1082  return ptrSurface;
1083  }
1084  // this pointer will be acquired by the surface.
1085  LightSurfaceContainer* surfContainer
1086  = new LightSurfaceContainer( K, *bimage, surfAdj, bel );
1087  ptrSurface = CountedPtr<LightDigitalSurface>
1088  ( new LightDigitalSurface( surfContainer ) ); // acquired
1089  nb_surfels = ptrSurface->size();
1090  }
1091  while ( ( nb_surfels < 2 * minsize ) && ( tries++ < 150 ) );
1092  if( tries >= 150 )
1093  trace.warning() << "[Shortcuts::makeLightDigitalSurface]"
1094  << "ERROR cannot find a proper bel in a big enough component."
1095  << std::endl;
1096  return ptrSurface;
1097  }
1098 
1116  static std::vector< CountedPtr<LightDigitalSurface> >
1118  ( CountedPtr<BinaryImage> bimage,
1119  const KSpace& K,
1120  const Parameters& params = parametersDigitalSurface() )
1121  {
1122  SurfelRange surfel_reps;
1123  return makeLightDigitalSurfaces( surfel_reps, bimage, K, params );
1124  }
1125 
1146  static std::vector< CountedPtr<LightDigitalSurface> >
1148  ( SurfelRange& surfel_reps,
1149  CountedPtr<BinaryImage> bimage,
1150  const KSpace& K,
1151  const Parameters& params = parametersDigitalSurface() )
1152  {
1153  std::vector< CountedPtr<LightDigitalSurface> > result;
1154  std::string component = params[ "surfaceComponents" ].as<std::string>();
1155  if ( component == "AnyBig" )
1156  {
1157  result.push_back( makeLightDigitalSurface( bimage, K, params ) );
1158  surfel_reps.push_back( *( result[ 0 ]->begin() ) );
1159  return result;
1160  }
1161  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1162  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1163  // Extracts all boundary surfels
1164  SurfelSet all_surfels;
1165  Surfaces<KSpace>::sMakeBoundary( all_surfels, K, *bimage,
1166  K.lowerBound(), K.upperBound() );
1167  // Builds all connected components of surfels.
1168  SurfelSet marked_surfels;
1170  for ( auto bel : all_surfels )
1171  {
1172  if ( marked_surfels.count( bel ) != 0 ) continue;
1173  surfel_reps.push_back( bel );
1174  LightSurfaceContainer* surfContainer
1175  = new LightSurfaceContainer( K, *bimage, surfAdj, bel );
1176  ptrSurface = CountedPtr<LightDigitalSurface>
1177  ( new LightDigitalSurface( surfContainer ) ); // acquired
1178  // mark all surfels of the surface component.
1179  marked_surfels.insert( ptrSurface->begin(), ptrSurface->end() );
1180  // add surface component to result.
1181  result.push_back( ptrSurface );
1182  }
1183  return result;
1184  }
1185 
1186 
1205  template <typename TPointPredicate>
1209  const KSpace& K,
1210  const Parameters& params = parametersDigitalSurface() )
1211  {
1212  SurfelSet all_surfels;
1213  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1214  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1215  // Extracts all boundary surfels
1216  Surfaces<KSpace>::sMakeBoundary( all_surfels, K, *bimage,
1217  K.lowerBound(), K.upperBound() );
1218  ExplicitSurfaceContainer* surfContainer
1219  = new ExplicitSurfaceContainer( K, surfAdj, all_surfels );
1221  ( new DigitalSurface( surfContainer ) ); // acquired
1222  }
1223 
1224 
1239  ( CountedPtr<IdxDigitalSurface> idx_surface,
1240  const Parameters& params = parametersDigitalSurface() )
1241  {
1242  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1243  const KSpace& K = refKSpace( idx_surface );
1244  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1245  auto all_idx_surfels
1246  = getIdxSurfelRange( idx_surface, Parameters( "surfaceTraversal", "Default" ) );
1247  auto idx2surfel = idx_surface->surfels();
1248  SurfelSet all_surfels;
1249  for ( auto idx : all_idx_surfels ) all_surfels.insert( idx2surfel[ idx ] );
1250  ExplicitSurfaceContainer* surfContainer
1251  = new ExplicitSurfaceContainer( K, surfAdj, all_surfels );
1253  ( new DigitalSurface( surfContainer ) ); // acquired
1254  }
1255 
1274  ( CountedPtr<BinaryImage> bimage,
1275  const KSpace& K,
1276  const Parameters& params = parametersDigitalSurface() )
1277  {
1278  std::string component = params[ "surfaceComponents" ].as<std::string>();
1279  SurfelSet surfels;
1280  if ( component == "AnyBig" )
1281  {
1282  auto light_surface = makeLightDigitalSurface( bimage, K, params );
1283  surfels.insert( light_surface->begin(), light_surface->end() );
1284  }
1285  else if ( component == "All" )
1286  {
1287  Surfaces<KSpace>::sMakeBoundary( surfels, K, *bimage,
1288  K.lowerBound(), K.upperBound() );
1289  }
1290  return makeIdxDigitalSurface( surfels, K, params );
1291  }
1292 
1304  template <typename TSurfelRange>
1307  ( const TSurfelRange& surfels,
1309  const Parameters& params = parametersDigitalSurface() )
1310  {
1311  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1312  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1313  // Build indexed digital surface.
1314  CountedPtr<ExplicitSurfaceContainer> ptrSurfContainer
1315  ( new ExplicitSurfaceContainer( K, surfAdj, surfels ) );
1317  ( new IdxDigitalSurface() );
1318  bool ok = ptrSurface->build( ptrSurfContainer );
1319  if ( !ok )
1320  trace.warning() << "[Shortcuts::makeIdxDigitalSurface]"
1321  << " Error building indexed digital surface." << std::endl;
1322  return ptrSurface;
1323  }
1324 
1337  template <typename TDigitalSurfaceContainer>
1341  const Parameters& params = parametersDigitalSurface() )
1342  {
1343  const KSpace& K = refKSpace( surface );
1344  SurfelSet surfels;
1345  surfels.insert( surface->begin(), surface->end() );
1346  return makeIdxDigitalSurface( surfels, K, params );
1347  }
1348 
1363  ( const std::vector< CountedPtr<LightDigitalSurface> >& surfaces,
1364  const Parameters& params = parametersDigitalSurface() )
1365  {
1366  if ( surfaces.empty() ) return CountedPtr<IdxDigitalSurface>( 0 );
1367  const KSpace& K = surfaces[ 0 ]->container().space();
1368  SurfelSet surfels;
1369  for ( std::size_t i = 0; i < surfaces.size(); ++i )
1370  {
1371  const KSpace& Ki = surfaces[ i ]->container().space();
1372  if ( ( Ki.lowerBound() != K.lowerBound() )
1373  || ( Ki.upperBound() != K.upperBound() ) )
1374  trace.warning() << "[Shortcuts::makeIdxDigitalSurface]"
1375  << " Incompatible digital spaces for surface " << i << std::endl;
1376  surfels.insert( surfaces[ i ]->begin(), surfaces[ i ]->end() );
1377  }
1378  return makeIdxDigitalSurface( surfels, K, params );
1379  }
1380 
1381 
1395  template <typename TDigitalSurfaceContainer>
1396  static CellRange
1398  ( Cell2Index& c2i,
1400  const Dimension k )
1401  {
1402  CellRange result;
1403  // Approximate number of pointels given the number of 2-cells (valid for 2d surfaces in nD).
1404  result.reserve( 2 * surface->size() + 100 );
1405  const KSpace& K = refKSpace( surface );
1406  Idx n = 0;
1407  for ( auto&& surfel : *surface )
1408  {
1409  CellRange primal_cells = getPrimalCells( K, surfel, k );
1410  for ( auto&& primal_cell : primal_cells )
1411  {
1412  if ( ! c2i.count( primal_cell ) )
1413  {
1414  result.push_back( primal_cell );
1415  c2i[ primal_cell ] = n++;
1416  }
1417  }
1418  }
1419  return result;
1420  }
1421 
1434  template <typename TDigitalSurfaceContainer>
1435  static PointelRange
1437  (
1439  const Dimension k )
1440  {
1441  Cell2Index c2i;
1442  return getCellRange( c2i, surface, k );
1443  }
1444 
1465  template <typename TDigitalSurfaceContainer>
1466  static PointelRange
1468  ( Cell2Index& c2i,
1470  {
1471  PointelRange result;
1472  result.reserve( surface->size() );
1473  const KSpace& K = refKSpace( surface );
1474  Idx n = 0;
1475  for ( auto&& surfel : *surface )
1476  {
1477  CellRange primal_vtcs = getPointelRange( K, surfel );
1478  for ( auto&& primal_vtx : primal_vtcs )
1479  {
1480  if ( ! c2i.count( primal_vtx ) )
1481  {
1482  result.push_back( primal_vtx );
1483  c2i[ primal_vtx ] = n++;
1484  }
1485  }
1486  }
1487  return result;
1488  }
1489 
1506  template <typename TDigitalSurfaceContainer>
1507  static PointelRange
1510  {
1511  Cell2Index c2i;
1512  return getPointelRange( c2i, surface );
1513  }
1514 
1523  static PointelRange
1525  ( const KSpace& K, const SCell& surfel )
1526  {
1527  return KSpace::dimension == 3
1528  ? getPrimalVertices( K, surfel, true )
1529  : getPrimalVertices( K, surfel );
1530  }
1531 
1543  template <typename TDigitalSurfaceContainer>
1544  static SurfelRange
1547  const Parameters& params = parametersDigitalSurface() )
1548  {
1549  return getSurfelRange( surface, *( surface->begin() ), params );
1550  }
1551 
1566  template <typename TDigitalSurfaceContainer>
1567  static SurfelRange
1570  const Surfel& start_surfel,
1571  const Parameters& params = parametersDigitalSurface() )
1572  {
1573  typedef ::DGtal::DigitalSurface<TDigitalSurfaceContainer> AnyDigitalSurface;
1574  SurfelRange result;
1575  std::string traversal = params[ "surfaceTraversal" ].as<std::string>();
1576  if ( traversal == "DepthFirst" )
1577  {
1579  typedef GraphVisitorRange< Visitor > VisitorRange;
1580  VisitorRange range( new Visitor( *surface, start_surfel ) );
1581  std::for_each( range.begin(), range.end(),
1582  [&result] ( Surfel s ) { result.push_back( s ); } );
1583  }
1584  else if ( traversal == "BreadthFirst" )
1585  {
1587  typedef GraphVisitorRange< Visitor > VisitorRange;
1588  VisitorRange range( new Visitor( *surface, start_surfel ) );
1589  std::for_each( range.begin(), range.end(),
1590  [&result] ( Surfel s ) { result.push_back( s ); } );
1591  }
1592  else
1593  {
1594  std::for_each( surface->begin(), surface->end(),
1595  [&result] ( Surfel s ) { result.push_back( s ); } );
1596  }
1597  return result;
1598  }
1599 
1609  static IdxSurfelRange
1612  const Parameters& params = parametersDigitalSurface() )
1613  {
1614  return getIdxSurfelRange( surface, (IdxSurfel) 0, params );
1615  }
1616 
1629  static IdxSurfelRange
1632  const IdxSurfel& start_surfel,
1633  const Parameters& params = parametersDigitalSurface() )
1634  {
1635  IdxSurfelRange result;
1636  std::string traversal = params[ "surfaceTraversal" ].as<std::string>();
1637  if ( traversal == "DepthFirst" )
1638  {
1640  typedef GraphVisitorRange< Visitor > VisitorRange;
1641  VisitorRange range( new Visitor( *surface, start_surfel ) );
1642  std::for_each( range.begin(), range.end(),
1643  [&result] ( IdxSurfel s ) { result.push_back( s ); } );
1644  }
1645  else if ( traversal == "BreadthFirst" )
1646  {
1648  typedef GraphVisitorRange< Visitor > VisitorRange;
1649  VisitorRange range( new Visitor( *surface, start_surfel ) );
1650  std::for_each( range.begin(), range.end(),
1651  [&result] ( IdxSurfel s ) { result.push_back( s ); } );
1652  }
1653  else return surface->allVertices();
1654  return result;
1655  }
1668  template <typename TDigitalSurfaceContainer,
1669  typename TCellEmbedder>
1670  static bool
1673  const TCellEmbedder& embedder,
1674  std::string off_file,
1675  const Color& face_color=DGtal::Color::None)
1676 
1677  {
1678  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1679 
1680  std::ofstream output_off( off_file.c_str() );
1681  output_off << "OFF" << std::endl;
1682  output_off << "# Generated from DGtal::Shortcuts from the DGTal library" << std::endl;
1683  Cell2Index c2i;
1684  auto pointels = getPointelRange( c2i, digsurf );
1685  output_off << pointels.size() << " " << digsurf->size() << " " << 0 << " " << std::endl;
1686 
1687 
1688  // Number and output vertices.
1689  const KSpace& K = refKSpace( digsurf );
1690  for ( auto&& pointel : pointels )
1691  {
1692  RealPoint p = embedder( pointel );
1693  output_off << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1694  }
1695 
1696  // Taking care of faces
1697  for ( auto&& surfel : *digsurf )
1698  {
1699  auto primal_vtcs = getPointelRange( K, surfel );
1700  output_off << primal_vtcs.size();
1701  {
1702  for ( auto&& primal_vtx : primal_vtcs )
1703  output_off << " " << (c2i[ primal_vtx ]);
1704  }
1705  if(face_color != DGtal::Color::None)
1706  {
1707  output_off << " ";
1708  output_off << face_color.r() << " " << face_color.g()
1709  << " " << face_color.b() << " " << face_color.a();
1710  }
1711  output_off << std::endl;
1712  }
1713  return output_off.good();
1714  }
1715 
1716 
1734  template <typename TDigitalSurfaceContainer,
1735  typename TCellEmbedder>
1736  static bool
1739  const TCellEmbedder& embedder,
1740  const RealVectors& normals,
1741  const Colors& diffuse_colors,
1742  std::string objfile,
1743  const Color& ambient_color = Color( 32, 32, 32 ),
1744  const Color& diffuse_color = Color( 200, 200, 255 ),
1745  const Color& specular_color = Color::White )
1746  {
1747  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1748  std::string mtlfile;
1749  auto lastindex = objfile.find_last_of(".");
1750  if ( lastindex == std::string::npos )
1751  {
1752  mtlfile = objfile + ".mtl";
1753  objfile = objfile + ".obj";
1754  }
1755  else
1756  {
1757  mtlfile = objfile.substr(0, lastindex) + ".mtl";
1758  }
1759 
1760  std::ofstream output_obj( objfile.c_str() );
1761  output_obj << "# OBJ format" << std::endl;
1762  output_obj << "# DGtal::MeshHelpers::exportOBJwithFaceNormalAndColor" << std::endl;
1763  output_obj << "o anObject" << std::endl;
1764  //remove directory to write material
1765  auto indexpath = objfile.find_last_of("/");
1766  output_obj << "mtllib " << mtlfile.substr(indexpath+1) << std::endl;
1767  std::ofstream output_mtl( mtlfile.c_str() );
1768  output_mtl << "# MTL format"<< std::endl;
1769  output_mtl << "# generated from MeshWriter from the DGTal library"<< std::endl;
1770  // Number and output vertices.
1771  const KSpace& K = refKSpace( digsurf );
1772  Cell2Index c2i;
1773  auto pointels = getPointelRange( c2i, digsurf );
1774  for ( auto&& pointel : pointels )
1775  {
1776  RealPoint p = embedder( pointel );
1777  output_obj << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1778  }
1779  // Taking care of normals
1780  Idx nbfaces = digsurf->size();
1781  bool has_normals = ( nbfaces == normals.size() );
1782  if ( has_normals )
1783  {
1784  for ( Idx f = 0; f < nbfaces; ++f )
1785  {
1786  const auto& p = normals[ f ];
1787  output_obj << "vn " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1788  }
1789  }
1790  // Taking care of materials
1791  bool has_material = ( nbfaces == diffuse_colors.size() );
1792  Idx idxMaterial = 0;
1793  std::map<Color, unsigned int > mapMaterial;
1794  if ( has_material )
1795  {
1796  for ( Idx f = 0; f < nbfaces; ++f )
1797  {
1798  Color c = diffuse_colors[ f ];
1799  if ( mapMaterial.count( c ) == 0 )
1800  {
1802  ( output_mtl, idxMaterial, ambient_color, c, specular_color );
1803  mapMaterial[ c ] = idxMaterial++;
1804  }
1805  }
1806  }
1807  else
1808  {
1810  ( output_mtl, idxMaterial, ambient_color, diffuse_color, specular_color );
1811  }
1812 
1813  // Taking care of faces
1814  Idx f = 0;
1815  for ( auto&& surfel : *digsurf )
1816  {
1817  output_obj << "usemtl material_"
1818  << ( has_material ? mapMaterial[ diffuse_colors[ f ] ] : idxMaterial )
1819  << std::endl;
1820  output_obj << "f";
1821  auto primal_vtcs = getPointelRange( K, surfel );
1822  // The +1 in lines below is because indexing starts at 1 in OBJ file format.
1823  if ( has_normals )
1824  {
1825  for ( auto&& primal_vtx : primal_vtcs )
1826  output_obj << " " << (c2i[ primal_vtx ]+1) << "//" << (f+1);
1827  }
1828  else
1829  {
1830  for ( auto&& primal_vtx : primal_vtcs )
1831  output_obj << " " << (c2i[ primal_vtx ]+1);
1832  }
1833  output_obj << std::endl;
1834  f += 1;
1835  }
1836  output_mtl.close();
1837  return output_obj.good();
1838  }
1839 
1855  template <typename TDigitalSurfaceContainer>
1856  static bool
1859  const RealVectors& normals,
1860  const Colors& diffuse_colors,
1861  std::string objfile,
1862  const Color& ambient_color = Color( 32, 32, 32 ),
1863  const Color& diffuse_color = Color( 200, 200, 255 ),
1864  const Color& specular_color = Color::White )
1865  {
1866  auto embedder = getCellEmbedder( digsurf );
1867  return saveOBJ( digsurf, embedder, normals, diffuse_colors, objfile,
1868  ambient_color, diffuse_color, specular_color );
1869  }
1870 
1884  template <typename TDigitalSurfaceContainer>
1885  static bool
1888  std::string off_file,
1889  const Color& face_color = Color( 32, 32, 32 ))
1890  {
1891  auto embedder = getCellEmbedder( digsurf );
1892  return saveOFF( digsurf, embedder, off_file, face_color);
1893  }
1906  template <typename TDigitalSurfaceContainer>
1907  static bool
1910  std::string objfile,
1911  const Color& ambient_color = Color( 32, 32, 32 ),
1912  const Color& diffuse_color = Color( 200, 200, 255 ),
1913  const Color& specular_color = Color::White )
1914  {
1915  auto embedder = getCellEmbedder( digsurf );
1916  return saveOBJ( digsurf, embedder, RealVectors(), Colors(), objfile,
1917  ambient_color, diffuse_color, specular_color );
1918  }
1919 
1920 
1936  static bool
1938  ( const RealPoints& positions,
1939  const RealVectors& vf,
1940  double thickness,
1941  const Colors& diffuse_colors,
1942  std::string objfile,
1943  const Color& ambient_color = Color( 32, 32, 32 ),
1944  const Color& diffuse_color = Color( 200, 200, 255 ),
1945  const Color& specular_color = Color::White )
1946  {
1947  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1948  std::string mtlfile;
1949  auto lastindex = objfile.find_last_of(".");
1950  if ( lastindex == std::string::npos )
1951  {
1952  mtlfile = objfile + ".mtl";
1953  objfile = objfile + ".obj";
1954  }
1955  else
1956  {
1957  mtlfile = objfile.substr(0, lastindex) + ".mtl";
1958  }
1959  std::ofstream output_obj( objfile.c_str() );
1960  output_obj << "# OBJ format" << std::endl;
1961  output_obj << "# DGtal::saveOBJ" << std::endl;
1962  output_obj << "o vectors" << std::endl;
1963  output_obj << "mtllib " << mtlfile << std::endl;
1964  std::ofstream output_mtl( mtlfile.c_str() );
1965  output_mtl << "# MTL format"<< std::endl;
1966  output_mtl << "# generated from MeshWriter from the DGTal library"<< std::endl;
1967  // Output vertices
1968  unsigned int n = std::min( positions.size(), vf.size() );
1969  for ( unsigned int i = 0; i < n; ++i )
1970  {
1971  RealPoint p0 = positions[ i ];
1972  RealPoint p1 = p0 + vf[ i ];
1973  RealVector v = vf[ i ];
1974  RealVector absv = RealVector( fabs( v[ 0 ] ), fabs( v[ 1 ] ), fabs( v[ 2 ] ) );
1975  unsigned int mc = std::max_element( absv.begin(), absv.end() ) - absv.begin();
1976  RealVector b =
1977  mc == 2 ? RealVector( 1, 0, 0 ) :
1978  mc == 1 ? RealVector( 0, 0, 1 ) : RealVector( 0, 1, 0 );
1979  RealVector e0 = v.crossProduct( b ).getNormalized();
1980  RealVector e1 = v.crossProduct( e0 ).getNormalized();
1981  RealPoint t[4] = { thickness * e0, thickness * e1,
1982  -thickness * e0, -thickness * e1 };
1983  for ( unsigned int j = 0; j < 4; ++j ) {
1984  RealPoint pt0 = p0 + t[ j ];
1985  RealPoint pt1 = p1 + t[ j ];
1986  output_obj << "v " << pt0[ 0 ] << " " << pt0[ 1 ] << " " << pt0[ 2 ]
1987  << std::endl;
1988  output_obj << "v " << pt1[ 0 ] << " " << pt1[ 1 ] << " " << pt1[ 2 ]
1989  << std::endl;
1990  }
1991  }
1992  // Simplify materials (very useful for blender).
1993  std::map<Color,Idx> map_colors;
1994  {
1995  Idx j = 0;
1996  for ( auto && c : diffuse_colors )
1997  if ( ! map_colors.count( c ) )
1998  map_colors[ c ] = j++;
1999  }
2000 
2001  // Output materials
2002  bool has_material = ! diffuse_colors.empty();
2003  if ( has_material )
2004  for ( auto&& pair : map_colors )
2006  ( output_mtl, pair.second, ambient_color, pair.first, specular_color);
2007  else
2009  ( output_mtl, 0, ambient_color, diffuse_color, specular_color );
2010  // Output faces
2011  for ( Idx i = 0; i < n; ++i )
2012  {
2013  output_obj << "usemtl material_" // << ( has_material ? i : 0 )
2014  << ( has_material ? map_colors[ diffuse_colors[ i ] ] : 0 )
2015  << std::endl;
2016  Idx b = 8*i+1;
2017  for ( Idx j = 0; j < 8; j += 2 )
2018  output_obj << "f " << (b+j) << " " << (b+j+1)
2019  << " " << (b+(j+3)%8) << " " << (b+(j+2)%8) << std::endl;
2020  output_obj << "f " << b << " " << (b+2)
2021  << " " << (b+4) << " " << (b+6) << std::endl;
2022  output_obj << "f " << (b+1) << " " << (b+7)
2023  << " " << (b+5) << " " << (b+3) << std::endl;
2024  }
2025  output_mtl.close();
2026  return output_obj.good();
2027  }
2028 
2029  // ----------------------- Mesh services ------------------------------
2030  public:
2031 
2036  {
2037  return Parameters
2038  ( "faceSubdivision", "Centroid" );
2039  }
2040 
2054  {
2055  auto pTriSurf = CountedPtr<TriangulatedSurface>
2056  ( new TriangulatedSurface ); // acquired
2057  bool ok = MeshHelpers::mesh2TriangulatedSurface( *aMesh, *pTriSurf );
2058  return ok ? pTriSurf : CountedPtr< TriangulatedSurface >( nullptr );
2059  }
2060 
2069  static CountedPtr< Mesh >
2071  const Color& aColor = Color::White )
2072  {
2073  auto pMesh = CountedPtr<Mesh>( new Mesh( aColor ) ); // acquired
2074  MeshHelpers::triangulatedSurface2Mesh( *triSurf, *pMesh );
2075  return pMesh;
2076  }
2077 
2086  static CountedPtr< Mesh >
2088  const Color& aColor = Color::White )
2089  {
2090  auto pMesh = CountedPtr<Mesh>( new Mesh( aColor ) ); // acquired
2091  MeshHelpers::polygonalSurface2Mesh( *polySurf, *pMesh );
2092  return pMesh;
2093  }
2094 
2101  template < typename TContainer >
2105  {
2106  auto embedder = getCellEmbedder( aSurface );
2107  auto pTriSurf = CountedPtr<TriangulatedSurface>
2108  ( new TriangulatedSurface ); // acquired
2110  ( *aSurface, embedder, *pTriSurf, s2i );
2111  return pTriSurf;
2112  }
2113 
2119  template < typename TContainer >
2122  {
2123  Surfel2Index s2i;
2124  return makeTriangulatedSurface( s2i, aSurface );
2125  }
2126 
2146  const Parameters& params = parametersMesh() )
2147  {
2148  std::string faceSubdivision = params[ "faceSubdivision" ].as<std::string>();
2149  bool centroid = ( faceSubdivision == "Centroid" );
2150  auto pTriSurf = CountedPtr<TriangulatedSurface>
2151  ( new TriangulatedSurface ); // acquired
2152  MeshHelpers::polygonalSurface2TriangulatedSurface( *polySurf, *pTriSurf, centroid );
2153  return pTriSurf;
2154  }
2155 
2166  {
2167  auto pPolySurf = CountedPtr<PolygonalSurface>
2168  ( new PolygonalSurface ); // acquired
2169  bool ok = MeshHelpers::mesh2PolygonalSurface( *aMesh, *pPolySurf );
2170  return ok ? pPolySurf : CountedPtr< PolygonalSurface >( nullptr );
2171  }
2172 
2188  const Parameters& params =
2192  {
2193  auto K = getKSpace( gray_scale_image );
2194  auto bimage = makeBinaryImage( gray_scale_image, params );
2195  auto digSurf = makeDigitalSurface( bimage, K, params );
2196  RealVector gh = { params[ "gridsizex" ].as<double>(),
2197  params[ "gridsizey" ].as<double>(),
2198  params[ "gridsizez" ].as<double>() };
2199  double threshold = params[ "thresholdMin" ].as<double>() + 0.5;
2200  typedef RegularPointEmbedder<Space> PointEmbedder;
2201  typedef ImageLinearCellEmbedder
2202  < KSpace, GrayScaleImage, PointEmbedder > ImageCellEmbedder;
2203  PointEmbedder pembedder;
2204  pembedder.init( gh );
2205  ImageCellEmbedder cembedder;
2206  cembedder.init( K, *gray_scale_image, pembedder, threshold );
2207  auto pPolySurf = CountedPtr<PolygonalSurface>
2208  ( new PolygonalSurface ); // acquired
2209  Surfel2Index s2i;
2211  ( *digSurf, cembedder, *pPolySurf, s2i );
2212  return pPolySurf;
2213  }
2214 
2231  const Parameters& params =
2235  {
2236  auto K = getKSpace( gray_scale_image );
2237  auto bimage = makeBinaryImage( gray_scale_image, params );
2238  auto digSurf = makeDigitalSurface( bimage, K, params );
2239  RealVector gh = { params[ "gridsizex" ].as<double>(),
2240  params[ "gridsizey" ].as<double>(),
2241  params[ "gridsizez" ].as<double>() };
2242  double threshold = params[ "thresholdMin" ].as<double>() + 0.5;
2243  typedef RegularPointEmbedder<Space> PointEmbedder;
2244  typedef ImageLinearCellEmbedder
2245  < KSpace, GrayScaleImage, PointEmbedder > ImageCellEmbedder;
2246  PointEmbedder pembedder;
2247  pembedder.init( gh );
2248  ImageCellEmbedder cembedder;
2249  cembedder.init( K, *gray_scale_image, pembedder, threshold );
2250  auto pPolySurf = CountedPtr<TriangulatedSurface>
2251  ( new TriangulatedSurface ); // acquired
2252  Surfel2Index s2i;
2254  ( *digSurf, cembedder, *pPolySurf, s2i );
2255  return pPolySurf;
2256  }
2257 
2265  template < typename TContainer >
2269  {
2270  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2271  auto embedder = getCellEmbedder( aSurface );
2272  auto pPolySurf = CountedPtr<PolygonalSurface>
2273  ( new PolygonalSurface ); // acquired
2275  ( *aSurface, embedder, *pPolySurf, s2i );
2276  return pPolySurf;
2277  }
2278 
2285  template < typename TContainer >
2288  {
2289  Surfel2Index s2i;
2290  return makeDualPolygonalSurface( s2i, aSurface );
2291  }
2292 
2299  template < typename TContainer >
2303  {
2304  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2305  auto pPolySurf = CountedPtr<PolygonalSurface>
2306  ( new PolygonalSurface( aSurface->heds(),
2307  aSurface->positions().storage() ) );
2308  return pPolySurf;
2309  }
2310 
2318  template < typename TContainer >
2322  {
2323  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2324  auto embedder = getCellEmbedder( aSurface );
2325  auto pPolySurf = CountedPtr<PolygonalSurface>
2326  ( new PolygonalSurface ); // acquired
2328  ( *aSurface, embedder, *pPolySurf, c2i );
2329  return ok ? pPolySurf : CountedPtr< PolygonalSurface >( nullptr );
2330  }
2331 
2338  template < typename TContainer >
2341  {
2342  Cell2Index c2i;
2343  return makePrimalPolygonalSurface( c2i, aSurface );
2344  }
2345 
2352  template < typename TContainer >
2356  {
2357  auto dsurf = makeDigitalSurface( aSurface );
2358  Cell2Index c2i;
2359  return makePrimalPolygonalSurface( c2i, dsurf );
2360  }
2361 
2368  template <typename TPoint>
2369  static bool
2372  const std::string& objfile )
2373  {
2374  std::ofstream output( objfile.c_str() );
2375  bool ok = MeshHelpers::exportOBJ( output, *polysurf );
2376  output.close();
2377  return ok;
2378  }
2379 
2388  template <typename TPoint>
2389  static bool
2391  std::string off_file,
2392  const Color& face_color = DGtal::Color::None)
2393 
2394  {
2397  std::ofstream output( off_file.c_str() );
2398  for (unsigned int i=0; i< m.nbFaces(); i++)
2399  {
2400  m.setFaceColor(i, face_color);
2401  }
2402  bool ok = MeshWriter< TPoint >::export2OFF( output, m, true );
2403  output.close();
2404  return ok;
2405  }
2406 
2413  template <typename TPoint>
2414  static bool
2417  const std::string& objfile )
2418  {
2419  std::ofstream output( objfile.c_str() );
2420  bool ok = MeshHelpers::exportOBJ( output, *trisurf );
2421  output.close();
2422  return ok;
2423  }
2424 
2437  template <typename TPoint>
2438  static bool
2441  const RealVectors& normals,
2442  const Colors& diffuse_colors,
2443  std::string objfile,
2444  const Color& ambient_color = Color( 32, 32, 32 ),
2445  const Color& diffuse_color = Color( 200, 200, 255 ),
2446  const Color& specular_color = Color::White )
2447  {
2448  std::string mtlfile;
2449  auto lastindex = objfile.find_last_of(".");
2450  if ( lastindex == std::string::npos )
2451  {
2452  mtlfile = objfile + ".mtl";
2453  objfile = objfile + ".obj";
2454  }
2455  else
2456  {
2457  mtlfile = objfile.substr(0, lastindex) + ".mtl";
2458  }
2459  std::ofstream output( objfile.c_str() );
2461  ( output, mtlfile, *polysurf, normals, diffuse_colors,
2462  ambient_color, diffuse_color, specular_color );
2463  output.close();
2464  return ok;
2465  }
2466 
2479  template <typename TPoint>
2480  static bool
2483  const RealVectors& normals,
2484  const Colors& diffuse_colors,
2485  std::string objfile,
2486  const Color& ambient_color = Color( 32, 32, 32 ),
2487  const Color& diffuse_color = Color( 200, 200, 255 ),
2488  const Color& specular_color = Color::White )
2489  {
2490  std::string mtlfile;
2491  auto lastindex = objfile.find_last_of(".");
2492  if ( lastindex == std::string::npos )
2493  {
2494  mtlfile = objfile + ".mtl";
2495  objfile = objfile + ".obj";
2496  }
2497  else
2498  {
2499  mtlfile = objfile.substr(0, lastindex) + ".mtl";
2500  }
2501  std::ofstream output( objfile.c_str() );
2503  ( output, mtlfile, *trisurf, normals, diffuse_colors,
2504  ambient_color, diffuse_color, specular_color );
2505  output.close();
2506  return ok;
2507  }
2508 
2517  template <typename TPoint>
2518  static bool
2520  std::string off_file,
2521  const Color& face_color = DGtal::Color::None)
2522 
2523  {
2526  std::ofstream output( off_file.c_str() );
2527  for (unsigned int i=0; i< m.nbFaces(); i++)
2528  {
2529  m.setFaceColor(i, face_color);
2530  }
2531  bool ok = MeshWriter< TPoint >::export2OFF( output, m, true );
2532  output.close();
2533  return ok;
2534  }
2535 
2536 
2537  // ------------------------------ utilities ------------------------------
2538  public:
2539 
2545  {
2546  return Parameters
2547  ( "colormap", "Custom" )
2548  ( "zero-tic", 0.0 );
2549  }
2550 
2567  template <typename TValue>
2568  static IdxRange
2569  getRangeMatch( const std::vector< TValue >& s1, const std::vector< TValue >& s2,
2570  bool perfect = false )
2571  {
2572  if ( perfect && ( s1.size() != s2.size() ) ) return IdxRange();
2573  std::map<TValue, Idx> M;
2574  Idx idx = 0;
2575  for ( auto val : s2 ) M[ val ] = idx++;
2576  IdxRange V( s1.size() );
2577  idx = 0;
2578  for ( auto val : s1 )
2579  {
2580  auto it = M.find( val );
2581  if ( it != M.end() ) V[ idx++ ] = it->second;
2582  else
2583  {
2584  if ( perfect ) return IdxRange();
2585  V[ idx++ ] = s2.size();
2586  }
2587  }
2588  return V;
2589  }
2590 
2602  template <typename TValue>
2603  static std::vector< TValue >
2604  getMatchedRange( const std::vector< TValue >& range, const IdxRange& match )
2605  {
2606  std::vector< TValue > result( match.size() );
2607  for ( Idx i = 0; i < result.size(); i++ )
2608  result[ i ] = range[ match[ i ] ];
2609  return result;
2610  }
2611 
2612 
2618  static ColorMap
2620  Scalar max,
2621  const Parameters& params = parametersUtilities() )
2622  {
2623  std::string cmap = params[ "colormap" ].as<std::string>();
2624  if ( cmap == "Cool" ) return ColorMap( min, max, CMAP_COOL );
2625  else if ( cmap == "Copper" ) return ColorMap( min, max, CMAP_COPPER );
2626  else if ( cmap == "Hot" ) return ColorMap( min, max, CMAP_HOT );
2627  else if ( cmap == "Jet" ) return ColorMap( min, max, CMAP_JET );
2628  else if ( cmap == "Spring" ) return ColorMap( min, max, CMAP_SPRING );
2629  else if ( cmap == "Summer" ) return ColorMap( min, max, CMAP_SUMMER );
2630  else if ( cmap == "Autumn" ) return ColorMap( min, max, CMAP_AUTUMN );
2631  else if ( cmap == "Winter" ) return ColorMap( min, max, CMAP_WINTER );
2632  else if ( cmap == "Error" )
2633  {
2634  ColorMap gradcmap( min, max );
2635  gradcmap.addColor( Color( 255, 255, 255 ) );
2636  gradcmap.addColor( Color( 255, 0, 0 ) );
2637  gradcmap.addColor( Color( 0, 0, 0 ) );
2638  return gradcmap;
2639  }
2640  // Custom colormap
2641  ColorMap gradcmap( min, max );
2642  gradcmap.addColor( Color( 0, 0, 255 ) );
2643  gradcmap.addColor( Color( 0, 255, 255 ) );
2644  gradcmap.addColor( Color( 255, 255, 255 ) );
2645  gradcmap.addColor( Color( 255, 255, 0 ) );
2646  gradcmap.addColor( Color( 255, 0, 0 ) );
2647  return gradcmap;
2648  }
2649 
2656  static ZeroTickedColorMap
2658  Scalar max,
2659  const Parameters& params = parametersUtilities() )
2660  {
2661  auto cmap = getColorMap( min, max, params );
2662  auto ztic = params[ "zero-tic" ].as<double>();
2663  ZeroTickedColorMap ztic_cmap( cmap, Color::Black );
2664  if ( ztic <= 0.0 ) return ztic_cmap;
2665  if ( min <= 0.0 && 0.0 <= max )
2666  ztic_cmap.addTick( 0.0, ztic );
2667  ztic_cmap.finalize();
2668  return ztic_cmap;
2669  }
2670 
2671 
2680  template <typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2681  static bool
2683  ( std::ostream& output,
2684  const SurfelRange& surfels,
2685  const TCellEmbedder& embedder )
2686  {
2687  typedef unsigned long Size;
2688  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2690  const KSpace& K = embedder.space();
2691  // Number and output vertices.
2692  std::map< Cell, Size > vtx_numbering;
2693  Size n = 1; // OBJ vertex numbering start at 1
2694  for ( auto&& s : surfels )
2695  {
2696  auto primal_vtcs = getPointelRange( K, s, true );
2697  for ( auto&& primal_vtx : primal_vtcs )
2698  {
2699  if ( ! vtx_numbering.count( primal_vtx ) )
2700  {
2701  vtx_numbering[ primal_vtx ] = n++;
2702  // Output vertex positions
2703  RealPoint p = embedder( primal_vtx );
2704  output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2705  }
2706  }
2707  }
2708  // Outputs all faces
2709  for ( auto&& s : surfels )
2710  {
2711  output << "f";
2712  auto primal_vtcs = getPointelRange( K, s, true );
2713  for ( auto&& primal_vtx : primal_vtcs )
2714  output << " " << vtx_numbering[ primal_vtx ];
2715  output << std::endl;
2716  }
2717  return output.good();
2718  }
2719 
2731  template <typename TAnyDigitalSurface>
2732  static bool
2734  ( std::ostream& output,
2736  {
2737  auto embedder = getCellEmbedder( surface );
2738  return outputPrimalDigitalSurfaceAsObj( output, surface, embedder );
2739  }
2740 
2758  template < typename TAnyDigitalSurface,
2759  typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2760  static bool
2762  ( std::ostream& output,
2764  const TCellEmbedder& embedder )
2765  {
2766  auto surfels = getSurfelRange( surface, Parameters( "Traversal", "Default" ) );
2767  return outputSurfelsAsObj( output, surfels, embedder );
2768  }
2769 
2778  static bool
2780  ( std::ostream& output,
2782  {
2783  auto embedder = getCellEmbedder( surface );
2784  return outputPrimalIdxDigitalSurfaceAsObj( output, surface, embedder );
2785  }
2786 
2800  template <typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2801  static bool
2803  ( std::ostream& output,
2805  const TCellEmbedder& embedder )
2806  {
2807  auto idxsurfels = getIdxSurfelRange( surface, Parameters( "Traversal", "Default" ) );
2808  auto surfelmap = surface->surfels();
2809  SurfelRange surfels;
2810  for ( auto&& idx : idxsurfels )
2811  surfels.push_back( surfelmap[ idx ] );
2812  return outputSurfelsAsObj( output, surfels, embedder );
2813  }
2814 
2831  template <typename TDigitalSurfaceContainer>
2832  static bool
2834  ( std::ostream& output,
2836  const Parameters& params = parametersMesh() )
2837  {
2838  auto embedder = getCellEmbedder( surface );
2839  return outputDualDigitalSurfaceAsObj( output, surface, embedder, params );
2840  }
2841 
2864  template < typename TDigitalSurfaceContainer,
2865  typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2866  static bool
2868  ( std::ostream& output,
2870  const TCellEmbedder& embedder,
2871  const Parameters& params = parametersMesh() )
2872  {
2873  typedef unsigned long Size;
2874  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2876  std::string dualFaceSubdivision = params[ "faceSubdivision" ].as<std::string>();
2877  const int subdivide
2878  = dualFaceSubdivision == "Naive" ? 1
2879  : dualFaceSubdivision == "Centroid" ? 2
2880  : 0;
2881  const KSpace& K = embedder.space();
2882  // Number and ouput vertices.
2883  std::map< Vertex, Size > vtx_numbering;
2884  std::map< Face, Size > sub_numbering;
2885  Size n = 1; // OBJ vertex numbering start at 1
2886  for ( auto && s : *surface )
2887  {
2888  if ( ! vtx_numbering.count( s ) )
2889  {
2890  vtx_numbering[ s ] = n++;
2891  // Output vertex positions
2892  RealPoint p = embedder( K.unsigns( s ) );
2893  output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2894  }
2895  }
2896  auto faces = surface->allClosedFaces();
2897  // Prepare centroids if necessary
2898  if ( subdivide == 2 )
2899  {
2900  for ( auto&& f : faces )
2901  {
2902  auto vtcs = surface->verticesAroundFace( f );
2903  Size nv = vtcs.size();
2904  if ( nv > 3 )
2905  {
2906  sub_numbering[ f ] = n++;
2908  for ( auto&& s : vtcs ) p += embedder( K.unsigns( s ) );
2909  p /= nv;
2910  output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2911  }
2912  }
2913  }
2914  // Outputs closed faces.
2915  if ( subdivide == 0 )
2916  { // No subdivision
2917  for ( auto&& f : faces )
2918  {
2919  output << "f";
2920  auto vtcs = surface->verticesAroundFace( f );
2921  std::reverse( vtcs.begin(), vtcs.end() );
2922  for ( auto&& s : vtcs )
2923  output << " " << vtx_numbering[ s ];
2924  output << std::endl;
2925  }
2926  }
2927  else if ( subdivide == 1 )
2928  { // naive subdivision
2929  for ( auto&& f : faces )
2930  {
2931  auto vtcs = surface->verticesAroundFace( f );
2932  Size nv = vtcs.size();
2933  for ( Size i = 1; i < nv - 1; ++i )
2934  output << "f " << vtx_numbering[ vtcs[ 0 ] ]
2935  << " " << vtx_numbering[ vtcs[ i+1 ] ]
2936  << " " << vtx_numbering[ vtcs[ i ] ] << std::endl;
2937  }
2938  }
2939  else if ( subdivide == 2 )
2940  { // centroid subdivision
2941  for ( auto&& f : faces )
2942  {
2943  auto vtcs = surface->verticesAroundFace( f );
2944  Size nv = vtcs.size();
2945  if ( nv == 3 )
2946  output << "f " << vtx_numbering[ vtcs[ 0 ] ]
2947  << " " << vtx_numbering[ vtcs[ 2 ] ]
2948  << " " << vtx_numbering[ vtcs[ 1 ] ] << std::endl;
2949  else {
2950  Size c = sub_numbering[ f ];
2951  for ( Size i = 0; i < nv; ++i )
2952  {
2953  output << "f " << c
2954  << " " << vtx_numbering[ vtcs[ (i+1)%nv ] ]
2955  << " " << vtx_numbering[ vtcs[ i ] ] << std::endl;
2956  }
2957  }
2958  }
2959  }
2960  return output.good();
2961  }
2962 
2963 
2964  // -------------------- map I/O services ------------------------------------------
2965  public:
2966  struct CellWriter {
2967  void operator()( std::ostream& output, const KSpace& K, const Cell & cell )
2968  {
2969  for ( Dimension d = 0; d < KSpace::dimension; ++d )
2970  output << " " << K.sKCoord( cell, d );
2971  }
2972  };
2973  struct CellReader {
2974  Cell operator()( std::istream& input, const KSpace& K )
2975  {
2976  Point kp;
2977  for ( Dimension d = 0; d < KSpace::dimension; ++d )
2978  input >> kp[ d ];
2979  return K.uCell( kp );
2980  }
2981  };
2982  struct SCellWriter {
2983  void operator()( std::ostream& output, const KSpace& K, const SCell & scell )
2984  {
2985  CellWriter::operator()( output, K, K.unsigns( scell ) );
2986  output << " " << K.sSign( scell );
2987  }
2988  };
2989  struct SCellReader {
2990  SCell operator()( std::istream& input, const KSpace& K )
2991  {
2992  Point kp;
2993  typename KSpace::Sign s;
2994  for ( Dimension d = 0; d < KSpace::dimension; ++d )
2995  input >> kp[ d ];
2996  input >> s;
2997  return K.sCell( kp, s );
2998  }
2999  };
3000 
3001  template <typename Value>
3002  struct ValueWriter {
3003  void operator()( std::ostream& output, const Value& v )
3004  {
3005  output << " " << v;
3006  }
3007  void operator()( std::ostream& output, const std::vector<Value>& vv )
3008  {
3009  for ( auto&& v : vv ) output << " " << v;
3010  }
3011  };
3012 
3013  template <typename Value>
3014  struct ValueReader {
3015  bool operator()( std::istream& input, Value& value )
3016  {
3017  std::string str;
3018  std::getline( input, str );
3019  // construct a stream from the string
3020  std::stringstream strstr(str);
3021  // use stream iterators to copy the stream to the vector as whitespace separated strings
3022  std::istream_iterator<std::string> it(strstr);
3023  std::istream_iterator<std::string> end;
3024  std::vector<std::string> results(it, end);
3025  std::stringstream sstr( results[ 0 ] );
3026  sstr >> value;
3027  return ( results.size() == 1 ) && input.good();
3028  }
3029 
3030  bool operator()( std::istream& input, std::vector<Value>& values )
3031  {
3032  std::string str;
3033  std::getline( input, str );
3034  // construct a stream from the string
3035  std::stringstream strstr(str);
3036  // use stream iterators to copy the stream to the vector as whitespace separated strings
3037  std::istream_iterator<std::string> it(strstr);
3038  std::istream_iterator<std::string> end;
3039  std::vector<std::string> results(it, end);
3040  values.resize( results.size() );
3041  for ( unsigned int i = 0; i < results.size(); ++i ) {
3042  std::stringstream sstr( results[ i ] );
3043  sstr >> values[ i ];
3044  }
3045  return input.good();
3046  }
3047  };
3048 
3049  // Outputs in \a output a map \a anyMap: SCell -> Value given the
3050  // appropriate value \a writer.
3051  //
3052  // @tparam TSCellMap any model of map SCell -> Value., e.g. std::map<SCell,double>
3053  // @tparam TValueWriter any model of value writer, e.g. ValueWriter<double>
3054  //
3055  // @param[out] output the output stream
3056  // @param[in] K the Khalimsky space where cells are defined.
3057  // @param[in] anyMap the map associated a value to signed cells.
3058  // @param[in] writer the writer that can write values on the ouput
3059  // stream, e.g. ValueWriter<double> to write double value or
3060  // vector<double> values.
3061  template <typename TSCellMap, typename TValueWriter>
3062  static
3064  ( std::ostream& output,
3065  const KSpace& K,
3066  const TSCellMap& anyMap,
3067  const TValueWriter& writer )
3068  {
3069  SCellWriter w;
3070  for ( auto&& v : anyMap )
3071  {
3072  w( output, K, v.first );
3073  writer( output, v.second );
3074  output << std::endl;
3075  }
3076  return output.good();
3077  }
3078 
3079  // Outputs in \a output a map \a anyMap: SCell -> value given the
3080  // appropriate value \a writer.
3081  //
3082  // @tparam TCellMap any model of map Cell -> Value., e.g. std::map<Cell,double>
3083  // @tparam TValueWriter any model of value writer, e.g. ValueWriter<double>
3084  //
3085  // @param[out] output the output stream
3086  // @param[in] K the Khalimsky space where cells are defined.
3087  // @param[in] anyMap the map associated a value to signed cells.
3088  // @param[in] writer the writer that can write values on the ouput
3089  // stream, e.g. ValueWriter<double> to write double value or
3090  // vector<double> values.
3091  template <typename TCellMap, typename TValueWriter>
3092  static
3094  ( std::ostream& output,
3095  const KSpace& K,
3096  const TCellMap& anyMap,
3097  const TValueWriter& writer )
3098  {
3099  CellWriter w;
3100  for ( auto&& v : anyMap )
3101  {
3102  w( output, K, v.first );
3103  writer( output, v.second );
3104  output << std::endl;
3105  }
3106  return output.good();
3107  }
3108 
3114  static
3115  CellRange getPrimalCells( const KSpace& K, const SCell& s, const Dimension k )
3116  {
3117  auto faces = K.uFaces( K.unsigns( s ) );
3118  CellRange primal_cells;
3119  for ( auto&& f : faces )
3120  {
3121  if ( K.uDim( f ) == k ) primal_cells.push_back( f );
3122  }
3123  return primal_cells;
3124  }
3125 
3130  static
3132  {
3133  return getPrimalCells( K, s, 0 );
3134  }
3135 
3142  static
3143  CellRange getPrimalVertices( const KSpace& K, const Surfel& s, bool ccw )
3144  {
3145  BOOST_STATIC_ASSERT(( KSpace::dimension == 3 ));
3146  CellRange vtcs = getPrimalVertices( K, s );
3147  std::swap( vtcs[ 2 ], vtcs[ 3 ] );
3148  auto orth_dir = K.sOrthDir( s );
3149  auto direct = K.sDirect( s, orth_dir ) ? ccw : ! ccw;
3150  Vector s0s1 = K.uCoords( vtcs[ 1 ] ) - K.uCoords( vtcs[ 0 ] );
3151  Vector s0s2 = K.uCoords( vtcs[ 2 ] ) - K.uCoords( vtcs[ 0 ] );
3152  Vector t = s0s1.crossProduct( s0s2 );
3153  if ( ( ( t[ orth_dir ] > 0.0 ) && direct )
3154  || ( ( t[ orth_dir ] < 0.0 ) && ! direct ) )
3155  std::reverse( vtcs.begin(), vtcs.end() );
3156  return vtcs;
3157  }
3158 
3159 
3160  // ----------------------- Standard services ------------------------------
3161  public:
3162 
3166  Shortcuts() = delete;
3167 
3171  ~Shortcuts() = delete;
3172 
3177  Shortcuts ( const Shortcuts & other ) = delete;
3178 
3183  Shortcuts ( Shortcuts && other ) = delete;
3184 
3190  Shortcuts & operator= ( const Shortcuts & other ) = delete;
3191 
3197  Shortcuts & operator= ( Shortcuts && other ) = delete;
3198 
3199  // ----------------------- Interface --------------------------------------
3200  public:
3201 
3206  void selfDisplay ( std::ostream & out ) const
3207  {
3208  out << "[Shortcuts]";
3209  }
3210 
3215  bool isValid() const
3216  {
3217  return true;
3218  }
3219 
3220  // ------------------------- Protected Datas ------------------------------
3221  protected:
3222 
3223  // ------------------------- Private Datas --------------------------------
3224  private:
3225 
3226  // ------------------------- Hidden services ------------------------------
3227  protected:
3228 
3229  // ------------------------- Internals ------------------------------------
3230  private:
3231 
3232  }; // end of class Shortcuts
3233 
3234 
3241  template <typename T>
3242  std::ostream&
3243  operator<< ( std::ostream & out, const Shortcuts<T> & object );
3244 
3245 } // namespace DGtal
3246 
3247 
3249 // Includes inline functions.
3250 
3251 // //
3253 
3254 #endif // !defined Shortcuts_h
3255 
3256 #undef Shortcuts_RECURSES
3257 #endif // else defined(Shortcuts_RECURSES)
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
static const Color None
Definition: Color.h:388
static const Color White
Definition: Color.h:391
static const Color Black
Definition: Color.h:389
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
Aim: Smart pointer based on reference counts.
Definition: CountedPtr.h:80
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::Surfel Surfel
DigitalSurfaceContainer::Cell Cell
Surfel Vertex
Defines the type for a vertex.
std::vector< Arc > ArcRange
The range of arcs is defined as a vector.
DigitalSurfaceContainer::SCell SCell
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: Transforms a graph visitor into a single pass input range.
const ConstIterator & end() const
const ConstIterator & begin() const
const Point & lowerBound() const
const Point & upperBound() const
Aim: a cellular embedder for images. (default constructible, copy constructible, assignable)....
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Aim: Represents a digital surface with the topology of its dual surface. Its aim is to mimick the sta...
HalfEdgeDataStructure::HalfEdgeIndex Arc
Aim: From a point predicate (model of concepts::CPointPredicate), this class constructs another point...
Definition: KanungoNoise.h:85
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: This class converts a string polynomial expression in a multivariate polynomial.
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
Definition: MPolynomial.h:955
static bool exportOBJ(std::ostream &output, const TriangulatedSurface< Point > &trisurf)
static bool digitalSurface2PrimalPolygonalSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, PolygonalSurface< typename CellEmbedder::Value > &polysurf, CellMap &cellmap)
static bool mesh2TriangulatedSurface(const Mesh< Point > &mesh, TriangulatedSurface< Point > &trisurf)
static void polygonalSurface2TriangulatedSurface(const PolygonalSurface< Point > &polysurf, TriangulatedSurface< Point > &trisurf, bool centroid=true)
static bool exportMTLNewMaterial(std::ostream &output_mtl, unsigned int idxMaterial, const Color &ambient_color, const Color &diffuse_color, const Color &specular_color)
static void polygonalSurface2Mesh(const PolygonalSurface< Point > &polysurf, Mesh< Point > &mesh)
static void digitalSurface2DualTriangulatedSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, TriangulatedSurface< typename CellEmbedder::Value > &trisurf, VertexMap &vertexmap)
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)
static void digitalSurface2DualPolygonalSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, PolygonalSurface< typename CellEmbedder::Value > &polysurf, VertexMap &vertexmap)
static void triangulatedSurface2Mesh(const TriangulatedSurface< Point > &trisurf, Mesh< Point > &mesh)
static bool mesh2PolygonalSurface(const Mesh< Point > &mesh, PolygonalSurface< Point > &polysurf)
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition: Mesh.h:92
auto crossProduct(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::crossProduct(*this, v))
Cross product with a PointVector.
TEuclideanRing Component
Type for Vector elements.
Definition: PointVector.h:614
static Self zero
Static const for zero PointVector.
Definition: PointVector.h:1595
Aim: Represents a polygon mesh, i.e. a 2-dimensional combinatorial surface whose faces are (topologic...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: SetOfSurfels.h:74
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:105
static Parameters parametersUtilities()
Definition: Shortcuts.h:2544
static CanonicSCellEmbedder< KSpace > getSCellEmbedder(const KSpace &K)
Definition: Shortcuts.h:445
GradientColorMap< Scalar > ColorMap
Definition: Shortcuts.h:192
CellRange PointelRange
Definition: Shortcuts.h:175
ImageContainerBySTLVector< Domain, bool > BinaryImage
defines a black and white image with (hyper-)rectangular domain.
Definition: Shortcuts.h:141
static CountedPtr< GrayScaleImage > makeGrayScaleImage(CountedPtr< DoubleImage > fimage, Parameters params=parametersGrayScaleImage())
Definition: Shortcuts.h:835
static std::vector< CountedPtr< LightDigitalSurface > > makeLightDigitalSurfaces(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1118
static bool outputPrimalDigitalSurfaceAsObj(std::ostream &output, CountedPtr< TAnyDigitalSurface > surface, const TCellEmbedder &embedder)
Definition: Shortcuts.h:2762
Space::Vector Vector
Vector with integer coordinates.
Definition: Shortcuts.h:119
static bool saveOBJ(CountedPtr< ::DGtal::TriangulatedSurface< TPoint > > trisurf, 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:2482
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters &params=parametersImplicitShape3D())
Definition: Shortcuts.h:281
static CountedPtr< GrayScaleImage > makeGrayScaleImage(CountedPtr< FloatImage > fimage, Parameters params=parametersGrayScaleImage())
Definition: Shortcuts.h:803
LightDigitalSurface::ArcRange ArcRange
Definition: Shortcuts.h:167
static KSpace getKSpace(CountedPtr< BinaryImage > bimage, Parameters params=parametersKSpace())
Definition: Shortcuts.h:353
static std::map< std::string, std::string > getPolynomialList()
Definition: Shortcuts.h:235
static CountedPtr< FloatImage > makeFloatImage(Domain aDomain)
Definition: Shortcuts.h:863
static Parameters parametersImplicitShape3D()
Definition: Shortcuts.h:264
static Parameters parametersKSpace()
Definition: Shortcuts.h:310
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2121
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition: Shortcuts.h:560
LightDigitalSurface::Surfel Surfel
Definition: Shortcuts.h:161
Space::RealPoint RealPoint
Point with floating-point coordinates.
Definition: Shortcuts.h:123
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:331
SetOfSurfels< KSpace, SurfelSet > ExplicitSurfaceContainer
defines a heavy container that represents any digital surface.
Definition: Shortcuts.h:156
LightDigitalSurface::Vertex Vertex
Definition: Shortcuts.h:164
static CountedPtr< GrayScaleImage > makeGrayScaleImage(Domain aDomain)
Definition: Shortcuts.h:735
static KSpace getKSpace(Parameters params=parametersKSpace()|parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:485
static bool saveOFF(CountedPtr< ::DGtal::PolygonalSurface< TPoint > > polysurf, std::string off_file, const Color &face_color=DGtal::Color::None)
Definition: Shortcuts.h:2390
std::map< Surfel, IdxSurfel > Surfel2Index
Definition: Shortcuts.h:187
static bool outputCellMapAsCSV(std::ostream &output, const KSpace &K, const TCellMap &anyMap, const TValueWriter &writer)
Definition: Shortcuts.h:3094
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< IdxDigitalSurface > idx_surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1239
static bool outputPrimalIdxDigitalSurfaceAsObj(std::ostream &output, CountedPtr< IdxDigitalSurface > surface)
Definition: Shortcuts.h:2780
static CellRange getCellRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Dimension k)
Definition: Shortcuts.h:1398
static const KSpace & refKSpace(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:418
static CountedPtr< DoubleImage > makeDoubleImage(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:963
Shortcuts(Shortcuts &&other)=delete
static CanonicCellEmbedder< KSpace > getCellEmbedder(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:1010
static CanonicSCellEmbedder< KSpace > getSCellEmbedder(CountedPtr< ::DGtal::IndexedDigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:1043
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:522
static CanonicSCellEmbedder< KSpace > getSCellEmbedder(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:1021
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Surfel &start_surfel, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1569
RealVector::Component Scalar
Floating-point numbers.
Definition: Shortcuts.h:125
::DGtal::TriangulatedSurface< RealPoint > TriangulatedSurface
Definition: Shortcuts.h:185
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< DigitizedImplicitShape3D > shape_digitization, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:575
std::map< Cell, IdxVertex > Cell2Index
Definition: Shortcuts.h:188
static bool outputDualDigitalSurfaceAsObj(std::ostream &output, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const TCellEmbedder &embedder, const Parameters &params=parametersMesh())
Definition: Shortcuts.h:2868
static CountedPtr< PolygonalSurface > makePolygonalSurface(CountedPtr< Mesh > aMesh)
Definition: Shortcuts.h:2165
ImageContainerBySTLVector< Domain, float > FloatImage
defines a float image with (hyper-)rectangular domain.
Definition: Shortcuts.h:145
static bool saveGrayScaleImage(CountedPtr< GrayScaleImage > gray_scale_image, std::string output)
Definition: Shortcuts.h:783
static PointelRange getPointelRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:1468
static bool saveOFF(CountedPtr< ::DGtal::TriangulatedSurface< TPoint > > trisurf, std::string off_file, const Color &face_color=DGtal::Color::None)
Definition: Shortcuts.h:2519
Space::Point Point
Point with integer coordinates.
Definition: Shortcuts.h:117
static CellRange getPrimalVertices(const KSpace &K, const Surfel &s, bool ccw)
Definition: Shortcuts.h:3143
static CellRange getPrimalCells(const KSpace &K, const SCell &s, const Dimension k)
Definition: Shortcuts.h:3115
static KSpace getKSpace(CountedPtr< GrayScaleImage > gimage, Parameters params=parametersKSpace())
Definition: Shortcuts.h:377
Shortcuts()=delete
std::vector< Color > Colors
Definition: Shortcuts.h:191
static Parameters parametersMesh()
Definition: Shortcuts.h:2035
static CountedPtr< Mesh > makeMesh(CountedPtr< TriangulatedSurface > triSurf, const Color &aColor=Color::White)
Definition: Shortcuts.h:2070
~Shortcuts()=delete
static bool saveOBJ(CountedPtr< ::DGtal::TriangulatedSurface< TPoint > > trisurf, const std::string &objfile)
Definition: Shortcuts.h:2416
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< BinaryImage > bimage, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:627
static Parameters parametersDigitalSurface()
Definition: Shortcuts.h:995
ImplicitPolynomial3Shape< Space > ImplicitShape3D
Definition: Shortcuts.h:137
Space::Integer Integer
Integer numbers.
Definition: Shortcuts.h:115
static KSpace getKSpace(CountedPtr< ::DGtal::IndexedDigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:407
LightDigitalSurface::Face Face
Definition: Shortcuts.h:166
::DGtal::Mesh< RealPoint > Mesh
Definition: Shortcuts.h:184
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< PolygonalSurface > polySurf, const Parameters &params=parametersMesh())
Definition: Shortcuts.h:2145
static bool outputPrimalDigitalSurfaceAsObj(std::ostream &output, CountedPtr< TAnyDigitalSurface > surface)
Definition: Shortcuts.h:2734
static bool saveOFF(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, std::string off_file, const Color &face_color=Color(32, 32, 32))
Definition: Shortcuts.h:1887
SCellRange SurfelRange
Definition: Shortcuts.h:176
LightImplicitDigitalSurface< KSpace, BinaryImage > LightSurfaceContainer
Definition: Shortcuts.h:152
static CellRange getPrimalVertices(const KSpace &K, const SCell &s)
Definition: Shortcuts.h:3131
MPolynomial< Space::dimension, Scalar > ScalarPolynomial
defines a multi-variate polynomial : RealPoint -> Scalar
Definition: Shortcuts.h:134
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1340
static CountedPtr< GrayScaleImage > makeGrayScaleImage(CountedPtr< BinaryImage > binary_image, std::function< GrayScale(bool) > const &bool2grayscale=[](bool v) { return v ?(unsigned char) 255 :(unsigned char) 0;})
Definition: Shortcuts.h:762
static bool outputPrimalIdxDigitalSurfaceAsObj(std::ostream &output, CountedPtr< IdxDigitalSurface > surface, const TCellEmbedder &embedder)
Definition: Shortcuts.h:2803
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1546
KSpace::SurfelSet SurfelSet
defines a set of surfels
Definition: Shortcuts.h:149
static CountedPtr< FloatImage > makeFloatImage(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:897
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(CountedPtr< ::DGtal::IndexedDigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2355
static CountedPtr< Mesh > makeMesh(CountedPtr< PolygonalSurface > polySurf, const Color &aColor=Color::White)
Definition: Shortcuts.h:2087
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1208
std::vector< Cell > CellRange
Definition: Shortcuts.h:174
static KSpace getKSpace(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:396
static bool outputSurfelsAsObj(std::ostream &output, const SurfelRange &surfels, const TCellEmbedder &embedder)
Definition: Shortcuts.h:2683
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2320
static IdxRange getRangeMatch(const std::vector< TValue > &s1, const std::vector< TValue > &s2, bool perfect=false)
Definition: Shortcuts.h:2569
bool isValid() const
Definition: Shortcuts.h:3215
static CountedPtr< BinaryImage > makeBinaryImage(std::string input, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:655
ImageContainerBySTLVector< Domain, GrayScale > GrayScaleImage
defines a grey-level image with (hyper-)rectangular domain.
Definition: Shortcuts.h:143
Shortcuts & operator=(const Shortcuts &other)=delete
::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface
defines an arbitrary digital surface over a binary image.
Definition: Shortcuts.h:158
::DGtal::Color Color
Definition: Shortcuts.h:190
std::vector< IdxVertex > IdxRange
Definition: Shortcuts.h:182
IdxDigitalSurface::Vertex IdxSurfel
Definition: Shortcuts.h:168
void selfDisplay(std::ostream &out) const
Definition: Shortcuts.h:3206
KSpace::Space Space
Digital space.
Definition: Shortcuts.h:113
std::vector< RealPoint > RealPoints
Definition: Shortcuts.h:180
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(const TSurfelRange &surfels, ConstAlias< KSpace > K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1307
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(Surfel2Index &s2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2267
static CountedPtr< PolygonalSurface > makePolygonalSurface(CountedPtr< GrayScaleImage > gray_scale_image, const Parameters &params=parametersKSpace()|parametersBinaryImage()|parametersDigitalSurface())
Definition: Shortcuts.h:2187
static bool saveOBJ(CountedPtr< ::DGtal::PolygonalSurface< TPoint > > polysurf, const std::string &objfile)
Definition: Shortcuts.h:2371
static ZeroTickedColorMap getZeroTickedColorMap(Scalar min, Scalar max, const Parameters &params=parametersUtilities())
Definition: Shortcuts.h:2657
IdxDigitalSurface::ArcRange IdxArcRange
Definition: Shortcuts.h:171
std::vector< RealVector > RealVectors
Definition: Shortcuts.h:179
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, 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:1909
std::vector< Scalar > Scalars
Definition: Shortcuts.h:178
IndexedDigitalSurface< ExplicitSurfaceContainer > IdxDigitalSurface
defines a connected or not indexed digital surface.
Definition: Shortcuts.h:160
std::vector< SCell > SCellRange
Definition: Shortcuts.h:173
static CanonicCellEmbedder< KSpace > getCellEmbedder(CountedPtr< ::DGtal::IndexedDigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:1032
static bool saveVectorFieldOBJ(const RealPoints &positions, const RealVectors &vf, double thickness, 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:1938
::DGtal::PolygonalSurface< RealPoint > PolygonalSurface
Definition: Shortcuts.h:186
Shortcuts(const Shortcuts &other)=delete
BOOST_CONCEPT_ASSERT((concepts::CCellularGridSpaceND< TKSpace >))
GaussDigitizer< Space, ImplicitShape3D > DigitizedImplicitShape3D
defines the digitization of an implicit shape.
Definition: Shortcuts.h:139
static bool saveBinaryImage(CountedPtr< BinaryImage > bimage, std::string output)
Definition: Shortcuts.h:707
IdxVertex Idx
Definition: Shortcuts.h:181
std::vector< IdxSurfel > IdxSurfelRange
Definition: Shortcuts.h:177
static Parameters parametersBinaryImage()
Definition: Shortcuts.h:546
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1274
IdxDigitalSurface::Arc IdxArc
Definition: Shortcuts.h:170
static Parameters defaultParameters()
Definition: Shortcuts.h:202
static CountedPtr< DoubleImage > makeDoubleImage(std::string input)
Definition: Shortcuts.h:942
Space::RealVector RealVector
Vector with floating-point coordinates.
Definition: Shortcuts.h:121
static bool saveOBJ(CountedPtr< ::DGtal::PolygonalSurface< TPoint > > polysurf, 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:2440
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< GrayScaleImage > gray_scale_image, const Parameters &params=parametersKSpace()|parametersBinaryImage()|parametersDigitalSurface())
Definition: Shortcuts.h:2230
static bool outputDualDigitalSurfaceAsObj(std::ostream &output, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersMesh())
Definition: Shortcuts.h:2834
static CountedPtr< LightDigitalSurface > makeLightDigitalSurface(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1061
static Parameters parametersDigitizedImplicitShape3D()
Definition: Shortcuts.h:460
LightDigitalSurface::Arc Arc
Definition: Shortcuts.h:165
ImageContainerBySTLVector< Domain, double > DoubleImage
defines a double image with (hyper-)rectangular domain.
Definition: Shortcuts.h:147
IdxDigitalSurface::Vertex IdxVertex
Definition: Shortcuts.h:169
unsigned char GrayScale
The type for 8-bits gray-scale elements.
Definition: Shortcuts.h:129
static PointelRange getCellRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Dimension k)
Definition: Shortcuts.h:1437
static const KSpace & refKSpace(CountedPtr< ::DGtal::IndexedDigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:429
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(Surfel2Index &s2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2103
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2287
static ColorMap getColorMap(Scalar min, Scalar max, const Parameters &params=parametersUtilities())
Definition: Shortcuts.h:2619
static PointelRange getPointelRange(const KSpace &K, const SCell &surfel)
Definition: Shortcuts.h:1525
std::set< IdxSurfel > IdxSurfelSet
Definition: Shortcuts.h:172
HyperRectDomain< Space > Domain
An (hyper-)rectangular domain.
Definition: Shortcuts.h:127
static CountedPtr< FloatImage > makeFloatImage(std::string input)
Definition: Shortcuts.h:876
static CanonicCellEmbedder< KSpace > getCellEmbedder(const KSpace &K)
Definition: Shortcuts.h:437
static PointelRange getPointelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:1509
static bool outputSCellMapAsCSV(std::ostream &output, const KSpace &K, const TSCellMap &anyMap, const TValueWriter &writer)
Definition: Shortcuts.h:3064
static IdxSurfelRange getIdxSurfelRange(CountedPtr< IdxDigitalSurface > surface, const IdxSurfel &start_surfel, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1631
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(const std::vector< CountedPtr< LightDigitalSurface > > &surfaces, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1363
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, 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:1858
static std::vector< TValue > getMatchedRange(const std::vector< TValue > &range, const IdxRange &match)
Definition: Shortcuts.h:2604
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< DigitizedImplicitShape3D > shape_digitization, Domain shapeDomain, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:595
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< GrayScaleImage > gray_scale_image, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:684
TKSpace KSpace
Digital cellular space.
Definition: Shortcuts.h:111
LightDigitalSurface::SCell SCell
Definition: Shortcuts.h:163
static IdxSurfelRange getIdxSurfelRange(CountedPtr< IdxDigitalSurface > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1611
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:1738
static bool saveOFF(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, const TCellEmbedder &embedder, std::string off_file, const Color &face_color=DGtal::Color::None)
Definition: Shortcuts.h:1672
TickedColorMap< Scalar, ColorMap > ZeroTickedColorMap
Definition: Shortcuts.h:193
::DGtal::DigitalSurface< LightSurfaceContainer > LightDigitalSurface
defines a connected digital surface over a binary image.
Definition: Shortcuts.h:154
static Parameters parametersGrayScaleImage()
Definition: Shortcuts.h:722
static std::vector< CountedPtr< LightDigitalSurface > > makeLightDigitalSurfaces(SurfelRange &surfel_reps, CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1148
static CountedPtr< DoubleImage > makeDoubleImage(Domain aDomain)
Definition: Shortcuts.h:929
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2340
static CountedPtr< GrayScaleImage > makeGrayScaleImage(std::string input)
Definition: Shortcuts.h:748
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(CountedPtr< ::DGtal::IndexedDigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2302
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< Mesh > aMesh)
Definition: Shortcuts.h:2053
LightDigitalSurface::Cell Cell
Definition: Shortcuts.h:162
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
static void sMakeBoundary(SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
Aim: This class adapts any colormap to add "ticks" in the colormap colors.
std::ostream & error()
std::ostream & warning()
Aim: Represents a triangulated surface. The topology is stored with a half-edge data structure....
Aim: Define a simple Foreground predicate thresholding image values between two constant values (the ...
BreadthFirstVisitor< MyDigitalSurface > Visitor
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::uint32_t Dimension
Definition: Common.h:137
Trace trace
Definition: Common.h:154
Aim: A trivial embedder for signed and unsigned cell, which corresponds to the canonic injection of c...
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
static bool exportFile(const std::string &filename, const TContainer &anImage, const TFunctor &aFunctor=TFunctor())
static bool export2OFF(std::ostream &out, const Mesh< TPoint > &aMesh, bool exportColor=true)
Cell operator()(std::istream &input, const KSpace &K)
Definition: Shortcuts.h:2974
void operator()(std::ostream &output, const KSpace &K, const Cell &cell)
Definition: Shortcuts.h:2967
SCell operator()(std::istream &input, const KSpace &K)
Definition: Shortcuts.h:2990
void operator()(std::ostream &output, const KSpace &K, const SCell &scell)
Definition: Shortcuts.h:2983
bool operator()(std::istream &input, Value &value)
Definition: Shortcuts.h:3015
bool operator()(std::istream &input, std::vector< Value > &values)
Definition: Shortcuts.h:3030
void operator()(std::ostream &output, const Value &v)
Definition: Shortcuts.h:3003
void operator()(std::ostream &output, const std::vector< Value > &vv)
Definition: Shortcuts.h:3007
Aim: A cell embedder is a mapping from unsigned cells to Euclidean points. It adds inner types to fun...
Definition: CCellEmbedder.h:97
Aim: This concept describes a cellular grid space in nD. In these spaces obtained by cartesian produc...
int max(int a, int b)
ch reverse()
KSpace K
HalfEdgeDataStructure::Size Size
Domain domain
HyperRectDomain< Space > Domain