DGtal  1.3.beta
Shortcuts.h
1 
17 #pragma once
18 
31 #if defined(Shortcuts_RECURSES)
32 #error Recursive header files inclusion detected in Shortcuts.h
33 #else // defined(Shortcuts_RECURSES)
34 
35 #define Shortcuts_RECURSES
36 
37 #if !defined Shortcuts_h
38 
39 #define Shortcuts_h
40 
42 // Inclusions
43 #include <cstdlib>
44 #include <iostream>
45 #include <fstream>
46 #include <sstream>
47 #include <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 ::DGtal::SurfaceMesh<RealPoint,RealPoint> SurfaceMesh;
188  typedef std::map<Surfel, IdxSurfel> Surfel2Index;
189  typedef std::map<Cell, IdxVertex> Cell2Index;
190 
191  typedef ::DGtal::Color Color;
192  typedef std::vector< Color > Colors;
195 
196  // ----------------------- Static services --------------------------------------
197  public:
198 
199  // ----------------------- General static services ------------------------------
200  public:
201 
204  {
206  | parametersKSpace()
211  | parametersMesh()
213  }
214 
215  // ----------------------- ImplicitShape3D static services ------------------------
216  public:
217 
235  static std::map< std::string, std::string >
237  {
238  std::vector< std::pair< std::string, std::string > >
239  Ps = { { "sphere1", "x^2+y^2+z^2-1" },
240  { "sphere9", "x^2+y^2+z^2-81" },
241  { "ellipsoid", "3*x^2+2*y^2+z^2-90" },
242  { "cylinder", "x^2+2*z^2-90" },
243  { "torus", "(x^2+y^2+z^2+6*6-2*2)^2-4*6*6*(x^2+y^2)" },
244  { "rcube", "x^4+y^4+z^4-6561" },
245  { "goursat", "-1*(8-0.03*x^4-0.03*y^4-0.03*z^4+2*x^2+2*y^2+2*z^2)" },
246  { "goursat-hole", "x^4+y^4+z^4-2*4*(x^2+y^2+z^2)+2*4*4-2" },
247  { "distel", "10000-(x^2+y^2+z^2+1000*(x^2+y^2)*(x^2+z^2)*(y^2+z^2))"},
248  { "leopold", "(x^2*y^2*z^2+4*x^2+4*y^2+3*z^2)-100" },
249  { "diabolo", "x^2-(y^2+z^2)^2" },
250  { "heart", "-1*(x^2+2.25*y^2+z^2-1)^3+x^2*z^3+0.1125*y^2*z^3" },
251  { "crixxi", "-0.9*(y^2+z^2-1)^2-(x^2+y^2-1)^3" } };
252  std::map< std::string, std::string > L;
253  for ( auto p : Ps )
254  L[ p.first ] = p.second;
255  return L;
256  }
257 
266  {
267  return Parameters
268  ( "polynomial", "sphere1" )
269  ( "projectionMaxIter", 20 )
270  ( "projectionAccuracy", 0.0001 )
271  ( "projectionGamma", 0.5 );
272  }
273 
283  {
285  std::string poly_str = params[ "polynomial" ].as<std::string>();
286  // Recognizes specific strings as polynomials.
287  auto PL = getPolynomialList();
288  if ( PL[ poly_str ] != "" ) poly_str = PL[ poly_str ];
289  ScalarPolynomial poly;
290  Polynomial3Reader reader;
291  std::string::const_iterator iter
292  = reader.read( poly, poly_str.begin(), poly_str.end() );
293  if ( iter != poly_str.end() )
294  {
295  trace.error() << "[Shortcuts::makeImplicitShape3D]"
296  << " ERROR reading polynomial: I read only <"
297  << poly_str.substr( 0, iter - poly_str.begin() )
298  << ">, and I built P=" << poly << std::endl;
299  }
300  return CountedPtr<ImplicitShape3D>( new ImplicitShape3D( poly ) );
301  }
302 
303  // ----------------------- KSpace static services ------------------------------
304  public:
305 
312  {
313  return Parameters
314  ( "closed", 1 )
315  ( "gridsizex", 1.0 )
316  ( "gridsizey", 1.0 )
317  ( "gridsizez", 1.0 );
318  }
319 
332  static KSpace getKSpace( const Point& low, const Point& up,
333  Parameters params = parametersKSpace() )
334  {
335  int closed = params[ "closed" ].as<int>();
336  KSpace K;
337  if ( ! K.init( low, up, closed ) )
338  trace.error() << "[Shortcuts::getKSpace]"
339  << " Error building Khalimsky space K=" << K << std::endl;
340  return K;
341  }
342 
355  Parameters params = parametersKSpace() )
356  {
357  int closed = params[ "closed" ].as<int>();
358  KSpace K;
359  if ( ! K.init( bimage->domain().lowerBound(),
360  bimage->domain().upperBound(),
361  closed ) )
362  trace.error() << "[Shortcuts::getKSpace]"
363  << " Error building Khalimsky space K=" << K << std::endl;
364  return K;
365  }
366 
379  Parameters params = parametersKSpace() )
380  {
381  int closed = params[ "closed" ].as<int>();
382  KSpace K;
383  if ( ! K.init( gimage->domain().lowerBound(),
384  gimage->domain().upperBound(),
385  closed ) )
386  trace.error() << "[Shortcuts::getKSpace]"
387  << " Error building Khalimsky space K=" << K << std::endl;
388  return K;
389  }
390 
394  template <typename TDigitalSurfaceContainer>
395  static KSpace
396  getKSpace
398  {
399  return surface->container().space();
400  }
401 
405  template <typename TDigitalSurfaceContainer>
406  static KSpace
407  getKSpace
409  {
410  return surface->container().space();
411  }
412 
416  template <typename TDigitalSurfaceContainer>
417  static const KSpace&
418  refKSpace
420  {
421  return surface->container().space();
422  }
423 
427  template <typename TDigitalSurfaceContainer>
428  static const KSpace&
429  refKSpace
431  {
432  return surface->container().space();
433  }
434 
439  {
440  return CanonicCellEmbedder<KSpace>( K );
441  }
442 
447  {
449  }
450 
451 
452  // ----------------------- DigitizedImplicitShape3D static services --------------
453  public:
454 
462  {
463  return Parameters
464  ( "minAABB", -10.0 )
465  ( "maxAABB", 10.0 )
466  ( "gridstep", 1.0 )
467  ( "offset", 5.0 );
468  }
469 
470 
485  static KSpace
488  {
489  Scalar min_x = params[ "minAABB" ].as<Scalar>();
490  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
491  Scalar h = params[ "gridstep" ].as<Scalar>();
492  Scalar offset = params[ "offset" ].as<Scalar>();
493  bool closed = params[ "closed" ].as<int>();
494  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
495  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
497  dshape->init( p1, p2, h );
498  Domain domain = dshape->getDomain();
499  KSpace K;
500  if ( ! K.init( domain.lowerBound(), domain.upperBound(), closed ) )
501  trace.error() << "[Shortcuts::getKSpace]"
502  << " Error building Khalimsky space K=" << K << std::endl
503  << "Note: if you use decimal values, check your locale for decimal point '.' or ','."
504  << std::endl;
505  return K;
506  }
507 
525  {
526  Scalar min_x = params[ "minAABB" ].as<Scalar>();
527  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
528  Scalar h = params[ "gridstep" ].as<Scalar>();
529  Scalar offset = params[ "offset" ].as<Scalar>();
530  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
531  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
533  dshape->attach( shape );
534  dshape->init( p1, p2, h );
535  return dshape;
536  }
537 
538 
539  // ----------------------- BinaryImage static services --------------------------
540  public:
541 
548  {
549  return Parameters
550  ( "noise", 0.0 )
551  ( "thresholdMin", 0 )
552  ( "thresholdMax", 255 );
553  }
554 
561  makeBinaryImage( Domain shapeDomain )
562  {
563  return CountedPtr<BinaryImage>( new BinaryImage( shapeDomain ) );
564  }
565 
577  Parameters params = parametersBinaryImage() )
578  {
579  return makeBinaryImage( shape_digitization,
580  shape_digitization->getDomain(),
581  params );
582  }
583 
597  Domain shapeDomain,
598  Parameters params = parametersBinaryImage() )
599  {
600  const Scalar noise = params[ "noise" ].as<Scalar>();
601  CountedPtr<BinaryImage> img ( new BinaryImage( shapeDomain ) );
602  if ( noise <= 0.0 )
603  {
604  std::transform( shapeDomain.begin(), shapeDomain.end(),
605  img->begin(),
606  [&shape_digitization]
607  ( const Point& p ) { return (*shape_digitization)(p); } );
608  }
609  else
610  {
611  typedef KanungoNoise< DigitizedImplicitShape3D, Domain > KanungoPredicate;
612  KanungoPredicate noisy_dshape( *shape_digitization, shapeDomain, noise );
613  std::transform( shapeDomain.begin(), shapeDomain.end(),
614  img->begin(),
615  [&noisy_dshape] ( const Point& p ) { return noisy_dshape(p); } );
616  }
617  return img;
618  }
619 
629  Parameters params = parametersBinaryImage() )
630  {
631  const Scalar noise = params[ "noise" ].as<Scalar>();
632  if ( noise <= 0.0 ) return bimage;
633  typedef KanungoNoise< BinaryImage, Domain > KanungoPredicate;
634  const Domain shapeDomain = bimage->domain();
635  CountedPtr<BinaryImage> img ( new BinaryImage( shapeDomain ) );
636  KanungoPredicate noisy_dshape( *bimage, shapeDomain, noise );
637  std::transform( shapeDomain.begin(), shapeDomain.end(),
638  img->begin(),
639  [&noisy_dshape] ( const Point& p ) { return noisy_dshape(p); } );
640  return img;
641  }
642 
656  ( std::string input,
657  Parameters params = parametersBinaryImage() )
658  {
659  int thresholdMin = params["thresholdMin"].as<int>();
660  int thresholdMax = params["thresholdMax"].as<int>();
662  Domain domain = image.domain();
664  ThresholdedImage tImage( image, thresholdMin, thresholdMax );
666  std::transform( domain.begin(), domain.end(),
667  img->begin(),
668  [tImage] ( const Point& p ) { return tImage(p); } );
669  return makeBinaryImage( img, params );
670  }
671 
685  ( CountedPtr<GrayScaleImage> gray_scale_image,
686  Parameters params = parametersBinaryImage() )
687  {
688  int thresholdMin = params["thresholdMin"].as<int>();
689  int thresholdMax = params["thresholdMax"].as<int>();
690  Domain domain = gray_scale_image->domain();
692  ThresholdedImage tImage( *gray_scale_image, thresholdMin, thresholdMax );
694  std::transform( domain.begin(), domain.end(),
695  img->begin(),
696  [tImage] ( const Point& p ) { return tImage(p); } );
697  return makeBinaryImage( img, params );
698  }
699 
700 
706  static bool
708  ( CountedPtr<BinaryImage> bimage, std::string output )
709  {
710  auto gray_scale_image = makeGrayScaleImage( bimage );
711  return saveGrayScaleImage( gray_scale_image, output );
712  }
713 
714 
715  // ----------------------- GrayScaleImage static services -------------------------
716  public:
717 
724  {
725  return Parameters
726  ( "qShift", 128.0 )
727  ( "qSlope", 1.0 );
728  }
729 
737  {
738  return CountedPtr<GrayScaleImage>( new GrayScaleImage( aDomain ) );
739  }
740 
749  ( std::string input )
750  {
752  return CountedPtr<GrayScaleImage>( new GrayScaleImage( image ) );
753  }
754 
763  ( CountedPtr<BinaryImage> binary_image,
764  std::function< GrayScale( bool ) > const & bool2grayscale
765  = [] ( bool v ) { return v ? (unsigned char) 255 : (unsigned char) 0; }
766  // JOL: (GrayScale) was not working with visual C++: error C2065
767  )
768  {
769  const Domain domain = binary_image->domain();
770  CountedPtr<GrayScaleImage> gray_scale_image( new GrayScaleImage( domain ) );
771  std::transform( binary_image->begin(), binary_image->end(),
772  gray_scale_image->begin(),
773  bool2grayscale );
774  return gray_scale_image;
775  }
776 
782  static bool
784  ( CountedPtr<GrayScaleImage> gray_scale_image, std::string output )
785  {
787  ::exportFile( output, *gray_scale_image );
788  }
789 
790 
806  {
807  float qShift = params[ "qShift" ].as<float>();
808  float qSlope = params[ "qSlope" ].as<float>();
809  std::function< unsigned char( float ) > f
810  = [qShift,qSlope] (float v)
811  { return (unsigned char) std::min( 255.0f, std::max( 0.0f, qSlope * v + qShift ) ); };
812  Domain domain = fimage->domain();
813  auto gimage = makeGrayScaleImage( domain );
814  auto it = gimage->begin();
815  for ( auto p : domain )
816  {
817  float val = (*fimage)( p );
818  *it++ = f( val );
819  }
820  return gimage;
821  }
822 
838  {
839  double qShift = params[ "qShift" ].as<double>();
840  double qSlope = params[ "qSlope" ].as<double>();
841  std::function< unsigned char( double ) > f
842  = [qShift,qSlope] (double v)
843  { return (unsigned char) std::min( 255.0, std::max( 0.0, qSlope * v + qShift ) ); };
844  Domain domain = fimage->domain();
845  auto gimage = makeGrayScaleImage( domain );
846  auto it = gimage->begin();
847  for ( auto p : domain )
848  {
849  double val = (*fimage)( p );
850  *it++ = f( val );
851  }
852  return gimage;
853  }
854 
855  // ----------------------- FloatImage static services -------------------------
856  public:
857 
865  {
866  return CountedPtr<FloatImage>( new FloatImage( aDomain ) );
867  }
868 
877  ( std::string input )
878  {
880  return CountedPtr<FloatImage>( new FloatImage( image ) );
881  }
882 
900  {
901  Scalar min_x = params[ "minAABB" ].as<Scalar>();
902  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
903  Scalar h = params[ "gridstep" ].as<Scalar>();
904  Scalar offset = params[ "offset" ].as<Scalar>();
905  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
906  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
908  dshape->attach( shape );
909  dshape->init( p1, p2, h );
910  Domain domain = dshape->getDomain();
911  auto fimage = makeFloatImage( domain );
912  auto it = fimage->begin();
913  for ( auto p : domain )
914  {
915  float val = (float) (*shape)( p );
916  *it++ = val;
917  }
918  return fimage;
919  }
920 
921  // ----------------------- DoubleImage static services -------------------------
922  public:
923 
931  {
932  return CountedPtr<DoubleImage>( new DoubleImage( aDomain ) );
933  }
934 
943  ( std::string input )
944  {
946  return CountedPtr<DoubleImage>( new DoubleImage( image ) );
947  }
948 
966  {
967  Scalar min_x = params[ "minAABB" ].as<Scalar>();
968  Scalar max_x = params[ "maxAABB" ].as<Scalar>();
969  Scalar h = params[ "gridstep" ].as<Scalar>();
970  Scalar offset = params[ "offset" ].as<Scalar>();
971  RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
972  RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
974  dshape->attach( shape );
975  dshape->init( p1, p2, h );
976  Domain domain = dshape->getDomain();
977  auto fimage = makeDoubleImage( domain );
978  auto it = fimage->begin();
979  for ( auto p : domain )
980  {
981  double val = (double) (*shape)( p );
982  *it++ = val;
983  }
984  return fimage;
985  }
986 
987  // ----------------------- DigitalSurface static services ------------------------
988  public:
989 
997  {
998  return Parameters
999  ( "surfelAdjacency", 0 )
1000  ( "nbTriesToFindABel", 100000 )
1001  ( "surfaceComponents", "AnyBig" )
1002  ( "surfaceTraversal", "Default" );
1003  }
1004 
1008  template <typename TDigitalSurfaceContainer>
1012  {
1013  return getCellEmbedder( refKSpace( surface ) );
1014  }
1015 
1019  template <typename TDigitalSurfaceContainer>
1023  {
1024  return getSCellEmbedder( refKSpace( surface ) );
1025  }
1026 
1030  template <typename TDigitalSurfaceContainer>
1034  {
1035  return getCellEmbedder( refKSpace( surface ) );
1036  }
1037 
1041  template <typename TDigitalSurfaceContainer>
1045  {
1046  return getSCellEmbedder( refKSpace( surface ) );
1047  }
1048 
1063  const KSpace& K,
1064  const Parameters& params = parametersDigitalSurface() )
1065  {
1066  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1067  int nb_tries_to_find_a_bel = params[ "nbTriesToFindABel" ].as<int>();
1068  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1069 
1070  // We have to search for a surfel that belongs to a big connected component.
1072  Surfel bel;
1073  Scalar minsize = bimage->extent().norm();
1074  unsigned int nb_surfels = 0;
1075  unsigned int tries = 0;
1076  do
1077  {
1078  try { // Search initial bel
1079  bel = Surfaces<KSpace>::findABel( K, *bimage, nb_tries_to_find_a_bel );
1080  } catch (DGtal::InputException& e) {
1081  trace.error() << "[Shortcuts::makeLightDigitalSurface]"
1082  << " ERROR Unable to find bel. " << e << std::endl;
1083  return ptrSurface;
1084  }
1085  // this pointer will be acquired by the surface.
1086  LightSurfaceContainer* surfContainer
1087  = new LightSurfaceContainer( K, *bimage, surfAdj, bel );
1088  ptrSurface = CountedPtr<LightDigitalSurface>
1089  ( new LightDigitalSurface( surfContainer ) ); // acquired
1090  nb_surfels = ptrSurface->size();
1091  }
1092  while ( ( nb_surfels < 2 * minsize ) && ( tries++ < 150 ) );
1093  if( tries >= 150 )
1094  trace.warning() << "[Shortcuts::makeLightDigitalSurface]"
1095  << "ERROR cannot find a proper bel in a big enough component."
1096  << std::endl;
1097  return ptrSurface;
1098  }
1099 
1117  static std::vector< CountedPtr<LightDigitalSurface> >
1120  const KSpace& K,
1121  const Parameters& params = parametersDigitalSurface() )
1122  {
1123  SurfelRange surfel_reps;
1124  return makeLightDigitalSurfaces( surfel_reps, bimage, K, params );
1125  }
1126 
1147  static std::vector< CountedPtr<LightDigitalSurface> >
1149  ( SurfelRange& surfel_reps,
1150  CountedPtr<BinaryImage> bimage,
1151  const KSpace& K,
1152  const Parameters& params = parametersDigitalSurface() )
1153  {
1154  std::vector< CountedPtr<LightDigitalSurface> > result;
1155  std::string component = params[ "surfaceComponents" ].as<std::string>();
1156  if ( component == "AnyBig" )
1157  {
1158  result.push_back( makeLightDigitalSurface( bimage, K, params ) );
1159  surfel_reps.push_back( *( result[ 0 ]->begin() ) );
1160  return result;
1161  }
1162  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1163  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1164  // Extracts all boundary surfels
1165  SurfelSet all_surfels;
1166  Surfaces<KSpace>::sMakeBoundary( all_surfels, K, *bimage,
1167  K.lowerBound(), K.upperBound() );
1168  // Builds all connected components of surfels.
1169  SurfelSet marked_surfels;
1171  for ( auto bel : all_surfels )
1172  {
1173  if ( marked_surfels.count( bel ) != 0 ) continue;
1174  surfel_reps.push_back( bel );
1175  LightSurfaceContainer* surfContainer
1176  = new LightSurfaceContainer( K, *bimage, surfAdj, bel );
1177  ptrSurface = CountedPtr<LightDigitalSurface>
1178  ( new LightDigitalSurface( surfContainer ) ); // acquired
1179  // mark all surfels of the surface component.
1180  marked_surfels.insert( ptrSurface->begin(), ptrSurface->end() );
1181  // add surface component to result.
1182  result.push_back( ptrSurface );
1183  }
1184  return result;
1185  }
1186 
1187 
1206  template <typename TPointPredicate>
1210  const KSpace& K,
1211  const Parameters& params = parametersDigitalSurface() )
1212  {
1213  SurfelSet all_surfels;
1214  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1215  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1216  // Extracts all boundary surfels
1217  Surfaces<KSpace>::sMakeBoundary( all_surfels, K, *bimage,
1218  K.lowerBound(), K.upperBound() );
1219  ExplicitSurfaceContainer* surfContainer
1220  = new ExplicitSurfaceContainer( K, surfAdj, all_surfels );
1222  ( new DigitalSurface( surfContainer ) ); // acquired
1223  }
1224 
1225 
1241  const Parameters& params = parametersDigitalSurface() )
1242  {
1243  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1244  const KSpace& K = refKSpace( idx_surface );
1245  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1246  auto all_idx_surfels
1247  = getIdxSurfelRange( idx_surface, Parameters( "surfaceTraversal", "Default" ) );
1248  auto idx2surfel = idx_surface->surfels();
1249  SurfelSet all_surfels;
1250  for ( auto idx : all_idx_surfels ) all_surfels.insert( idx2surfel[ idx ] );
1251  ExplicitSurfaceContainer* surfContainer
1252  = new ExplicitSurfaceContainer( K, surfAdj, all_surfels );
1254  ( new DigitalSurface( surfContainer ) ); // acquired
1255  }
1256 
1276  const KSpace& K,
1277  const Parameters& params = parametersDigitalSurface() )
1278  {
1279  std::string component = params[ "surfaceComponents" ].as<std::string>();
1280  SurfelSet surfels;
1281  if ( component == "AnyBig" )
1282  {
1283  auto light_surface = makeLightDigitalSurface( bimage, K, params );
1284  surfels.insert( light_surface->begin(), light_surface->end() );
1285  }
1286  else if ( component == "All" )
1287  {
1288  Surfaces<KSpace>::sMakeBoundary( surfels, K, *bimage,
1289  K.lowerBound(), K.upperBound() );
1290  }
1291  return makeIdxDigitalSurface( surfels, K, params );
1292  }
1293 
1305  template <typename TSurfelRange>
1308  ( const TSurfelRange& surfels,
1310  const Parameters& params = parametersDigitalSurface() )
1311  {
1312  bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1313  SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1314  // Build indexed digital surface.
1315  CountedPtr<ExplicitSurfaceContainer> ptrSurfContainer
1316  ( new ExplicitSurfaceContainer( K, surfAdj, surfels ) );
1318  ( new IdxDigitalSurface() );
1319  bool ok = ptrSurface->build( ptrSurfContainer );
1320  if ( !ok )
1321  trace.warning() << "[Shortcuts::makeIdxDigitalSurface]"
1322  << " Error building indexed digital surface." << std::endl;
1323  return ptrSurface;
1324  }
1325 
1338  template <typename TDigitalSurfaceContainer>
1342  const Parameters& params = parametersDigitalSurface() )
1343  {
1344  const KSpace& K = refKSpace( surface );
1345  SurfelSet surfels;
1346  surfels.insert( surface->begin(), surface->end() );
1347  return makeIdxDigitalSurface( surfels, K, params );
1348  }
1349 
1364  ( const std::vector< CountedPtr<LightDigitalSurface> >& surfaces,
1365  const Parameters& params = parametersDigitalSurface() )
1366  {
1367  if ( surfaces.empty() ) return CountedPtr<IdxDigitalSurface>( 0 );
1368  const KSpace& K = surfaces[ 0 ]->container().space();
1369  SurfelSet surfels;
1370  for ( std::size_t i = 0; i < surfaces.size(); ++i )
1371  {
1372  const KSpace& Ki = surfaces[ i ]->container().space();
1373  if ( ( Ki.lowerBound() != K.lowerBound() )
1374  || ( Ki.upperBound() != K.upperBound() ) )
1375  trace.warning() << "[Shortcuts::makeIdxDigitalSurface]"
1376  << " Incompatible digital spaces for surface " << i << std::endl;
1377  surfels.insert( surfaces[ i ]->begin(), surfaces[ i ]->end() );
1378  }
1379  return makeIdxDigitalSurface( surfels, K, params );
1380  }
1381 
1382 
1396  template <typename TDigitalSurfaceContainer>
1397  static CellRange
1398  getCellRange
1399  ( Cell2Index& c2i,
1401  const Dimension k )
1402  {
1403  CellRange result;
1404  // Approximate number of pointels given the number of 2-cells (valid for 2d surfaces in nD).
1405  result.reserve( 2 * surface->size() + 100 );
1406  const KSpace& K = refKSpace( surface );
1407  Idx n = 0;
1408  for ( auto&& surfel : *surface )
1409  {
1410  CellRange primal_cells = getPrimalCells( K, surfel, k );
1411  for ( auto&& primal_cell : primal_cells )
1412  {
1413  if ( ! c2i.count( primal_cell ) )
1414  {
1415  result.push_back( primal_cell );
1416  c2i[ primal_cell ] = n++;
1417  }
1418  }
1419  }
1420  return result;
1421  }
1422 
1435  template <typename TDigitalSurfaceContainer>
1436  static PointelRange
1437  getCellRange
1438  (
1440  const Dimension k )
1441  {
1442  Cell2Index c2i;
1443  return getCellRange( c2i, surface, k );
1444  }
1445 
1466  template <typename TDigitalSurfaceContainer>
1467  static PointelRange
1469  ( Cell2Index& c2i,
1471  {
1472  PointelRange result;
1473  result.reserve( surface->size() );
1474  const KSpace& K = refKSpace( surface );
1475  Idx n = 0;
1476  for ( auto&& surfel : *surface )
1477  {
1478  CellRange primal_vtcs = getPointelRange( K, surfel );
1479  for ( auto&& primal_vtx : primal_vtcs )
1480  {
1481  if ( ! c2i.count( primal_vtx ) )
1482  {
1483  result.push_back( primal_vtx );
1484  c2i[ primal_vtx ] = n++;
1485  }
1486  }
1487  }
1488  return result;
1489  }
1490 
1507  template <typename TDigitalSurfaceContainer>
1508  static PointelRange
1511  {
1512  Cell2Index c2i;
1513  return getPointelRange( c2i, surface );
1514  }
1515 
1524  static PointelRange
1526  ( const KSpace& K, const SCell& surfel )
1527  {
1528  return KSpace::dimension == 3
1529  ? getPrimalVertices( K, surfel, true )
1530  : getPrimalVertices( K, surfel );
1531  }
1532 
1544  template <typename TDigitalSurfaceContainer>
1545  static SurfelRange
1548  const Parameters& params = parametersDigitalSurface() )
1549  {
1550  return getSurfelRange( surface, *( surface->begin() ), params );
1551  }
1552 
1567  template <typename TDigitalSurfaceContainer>
1568  static SurfelRange
1571  const Surfel& start_surfel,
1572  const Parameters& params = parametersDigitalSurface() )
1573  {
1574  typedef ::DGtal::DigitalSurface<TDigitalSurfaceContainer> AnyDigitalSurface;
1575  SurfelRange result;
1576  std::string traversal = params[ "surfaceTraversal" ].as<std::string>();
1577  if ( traversal == "DepthFirst" )
1578  {
1580  typedef GraphVisitorRange< Visitor > VisitorRange;
1581  VisitorRange range( new Visitor( *surface, start_surfel ) );
1582  std::for_each( range.begin(), range.end(),
1583  [&result] ( Surfel s ) { result.push_back( s ); } );
1584  }
1585  else if ( traversal == "BreadthFirst" )
1586  {
1588  typedef GraphVisitorRange< Visitor > VisitorRange;
1589  VisitorRange range( new Visitor( *surface, start_surfel ) );
1590  std::for_each( range.begin(), range.end(),
1591  [&result] ( Surfel s ) { result.push_back( s ); } );
1592  }
1593  else
1594  {
1595  std::for_each( surface->begin(), surface->end(),
1596  [&result] ( Surfel s ) { result.push_back( s ); } );
1597  }
1598  return result;
1599  }
1600 
1610  static IdxSurfelRange
1613  const Parameters& params = parametersDigitalSurface() )
1614  {
1615  return getIdxSurfelRange( surface, (IdxSurfel) 0, params );
1616  }
1617 
1630  static IdxSurfelRange
1633  const IdxSurfel& start_surfel,
1634  const Parameters& params = parametersDigitalSurface() )
1635  {
1636  IdxSurfelRange result;
1637  std::string traversal = params[ "surfaceTraversal" ].as<std::string>();
1638  if ( traversal == "DepthFirst" )
1639  {
1641  typedef GraphVisitorRange< Visitor > VisitorRange;
1642  VisitorRange range( new Visitor( *surface, start_surfel ) );
1643  std::for_each( range.begin(), range.end(),
1644  [&result] ( IdxSurfel s ) { result.push_back( s ); } );
1645  }
1646  else if ( traversal == "BreadthFirst" )
1647  {
1649  typedef GraphVisitorRange< Visitor > VisitorRange;
1650  VisitorRange range( new Visitor( *surface, start_surfel ) );
1651  std::for_each( range.begin(), range.end(),
1652  [&result] ( IdxSurfel s ) { result.push_back( s ); } );
1653  }
1654  else return surface->allVertices();
1655  return result;
1656  }
1669  template <typename TDigitalSurfaceContainer,
1670  typename TCellEmbedder>
1671  static bool
1672  saveOFF
1674  const TCellEmbedder& embedder,
1675  std::string off_file,
1676  const Color& face_color=DGtal::Color::None)
1677 
1678  {
1679  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1680 
1681  std::ofstream output_off( off_file.c_str() );
1682  output_off << "OFF" << std::endl;
1683  output_off << "# Generated from DGtal::Shortcuts from the DGTal library" << std::endl;
1684  Cell2Index c2i;
1685  auto pointels = getPointelRange( c2i, digsurf );
1686  output_off << pointels.size() << " " << digsurf->size() << " " << 0 << " " << std::endl;
1687 
1688 
1689  // Number and output vertices.
1690  const KSpace& K = refKSpace( digsurf );
1691  for ( auto&& pointel : pointels )
1692  {
1693  RealPoint p = embedder( pointel );
1694  output_off << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1695  }
1696 
1697  // Taking care of faces
1698  for ( auto&& surfel : *digsurf )
1699  {
1700  auto primal_vtcs = getPointelRange( K, surfel );
1701  output_off << primal_vtcs.size();
1702  {
1703  for ( auto&& primal_vtx : primal_vtcs )
1704  output_off << " " << (c2i[ primal_vtx ]);
1705  }
1706  if(face_color != DGtal::Color::None)
1707  {
1708  output_off << " ";
1709  output_off << face_color.r() << " " << face_color.g()
1710  << " " << face_color.b() << " " << face_color.a();
1711  }
1712  output_off << std::endl;
1713  }
1714  return output_off.good();
1715  }
1716 
1717 
1735  template <typename TDigitalSurfaceContainer,
1736  typename TCellEmbedder>
1737  static bool
1738  saveOBJ
1740  const TCellEmbedder& embedder,
1741  const RealVectors& normals,
1742  const Colors& diffuse_colors,
1743  std::string objfile,
1744  const Color& ambient_color = Color( 32, 32, 32 ),
1745  const Color& diffuse_color = Color( 200, 200, 255 ),
1746  const Color& specular_color = Color::White )
1747  {
1748  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1749  std::string mtlfile;
1750  auto lastindex = objfile.find_last_of(".");
1751  if ( lastindex == std::string::npos )
1752  {
1753  mtlfile = objfile + ".mtl";
1754  objfile = objfile + ".obj";
1755  }
1756  else
1757  {
1758  mtlfile = objfile.substr(0, lastindex) + ".mtl";
1759  }
1760 
1761  std::ofstream output_obj( objfile.c_str() );
1762  output_obj << "# OBJ format" << std::endl;
1763  output_obj << "# DGtal::MeshHelpers::exportOBJwithFaceNormalAndColor" << std::endl;
1764  output_obj << "o anObject" << std::endl;
1765  //remove directory to write material
1766  auto indexpath = objfile.find_last_of("/");
1767  output_obj << "mtllib " << mtlfile.substr(indexpath+1) << std::endl;
1768  std::ofstream output_mtl( mtlfile.c_str() );
1769  output_mtl << "# MTL format"<< std::endl;
1770  output_mtl << "# generated from MeshWriter from the DGTal library"<< std::endl;
1771  // Number and output vertices.
1772  const KSpace& K = refKSpace( digsurf );
1773  Cell2Index c2i;
1774  auto pointels = getPointelRange( c2i, digsurf );
1775  for ( auto&& pointel : pointels )
1776  {
1777  RealPoint p = embedder( pointel );
1778  output_obj << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1779  }
1780  // Taking care of normals
1781  Idx nbfaces = digsurf->size();
1782  bool has_normals = ( nbfaces == normals.size() );
1783  if ( has_normals )
1784  {
1785  for ( Idx f = 0; f < nbfaces; ++f )
1786  {
1787  const auto& p = normals[ f ];
1788  output_obj << "vn " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1789  }
1790  }
1791  // Taking care of materials
1792  bool has_material = ( nbfaces == diffuse_colors.size() );
1793  Idx idxMaterial = 0;
1794  std::map<Color, unsigned int > mapMaterial;
1795  if ( has_material )
1796  {
1797  for ( Idx f = 0; f < nbfaces; ++f )
1798  {
1799  Color c = diffuse_colors[ f ];
1800  if ( mapMaterial.count( c ) == 0 )
1801  {
1803  ( output_mtl, idxMaterial, ambient_color, c, specular_color );
1804  mapMaterial[ c ] = idxMaterial++;
1805  }
1806  }
1807  }
1808  else
1809  {
1811  ( output_mtl, idxMaterial, ambient_color, diffuse_color, specular_color );
1812  }
1813 
1814  // Taking care of faces
1815  Idx f = 0;
1816  for ( auto&& surfel : *digsurf )
1817  {
1818  output_obj << "usemtl material_"
1819  << ( has_material ? mapMaterial[ diffuse_colors[ f ] ] : idxMaterial )
1820  << std::endl;
1821  output_obj << "f";
1822  auto primal_vtcs = getPointelRange( K, surfel );
1823  // The +1 in lines below is because indexing starts at 1 in OBJ file format.
1824  if ( has_normals )
1825  {
1826  for ( auto&& primal_vtx : primal_vtcs )
1827  output_obj << " " << (c2i[ primal_vtx ]+1) << "//" << (f+1);
1828  }
1829  else
1830  {
1831  for ( auto&& primal_vtx : primal_vtcs )
1832  output_obj << " " << (c2i[ primal_vtx ]+1);
1833  }
1834  output_obj << std::endl;
1835  f += 1;
1836  }
1837  output_mtl.close();
1838  return output_obj.good();
1839  }
1840 
1856  template <typename TDigitalSurfaceContainer>
1857  static bool
1858  saveOBJ
1860  const RealVectors& normals,
1861  const Colors& diffuse_colors,
1862  std::string objfile,
1863  const Color& ambient_color = Color( 32, 32, 32 ),
1864  const Color& diffuse_color = Color( 200, 200, 255 ),
1865  const Color& specular_color = Color::White )
1866  {
1867  auto embedder = getCellEmbedder( digsurf );
1868  return saveOBJ( digsurf, embedder, normals, diffuse_colors, objfile,
1869  ambient_color, diffuse_color, specular_color );
1870  }
1871 
1885  template <typename TDigitalSurfaceContainer>
1886  static bool
1887  saveOFF
1889  std::string off_file,
1890  const Color& face_color = Color( 32, 32, 32 ))
1891  {
1892  auto embedder = getCellEmbedder( digsurf );
1893  return saveOFF( digsurf, embedder, off_file, face_color);
1894  }
1907  template <typename TDigitalSurfaceContainer>
1908  static bool
1909  saveOBJ
1911  std::string objfile,
1912  const Color& ambient_color = Color( 32, 32, 32 ),
1913  const Color& diffuse_color = Color( 200, 200, 255 ),
1914  const Color& specular_color = Color::White )
1915  {
1916  auto embedder = getCellEmbedder( digsurf );
1917  return saveOBJ( digsurf, embedder, RealVectors(), Colors(), objfile,
1918  ambient_color, diffuse_color, specular_color );
1919  }
1920 
1921 
1937  static bool
1939  ( const RealPoints& positions,
1940  const RealVectors& vf,
1941  double thickness,
1942  const Colors& diffuse_colors,
1943  std::string objfile,
1944  const Color& ambient_color = Color( 32, 32, 32 ),
1945  const Color& diffuse_color = Color( 200, 200, 255 ),
1946  const Color& specular_color = Color::White )
1947  {
1948  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1949  std::string mtlfile;
1950  auto lastindex = objfile.find_last_of(".");
1951  if ( lastindex == std::string::npos )
1952  {
1953  mtlfile = objfile + ".mtl";
1954  objfile = objfile + ".obj";
1955  }
1956  else
1957  {
1958  mtlfile = objfile.substr(0, lastindex) + ".mtl";
1959  }
1960  std::ofstream output_obj( objfile.c_str() );
1961  output_obj << "# OBJ format" << std::endl;
1962  output_obj << "# DGtal::saveOBJ" << std::endl;
1963  output_obj << "o vectors" << std::endl;
1964  output_obj << "mtllib " << mtlfile << std::endl;
1965  std::ofstream output_mtl( mtlfile.c_str() );
1966  output_mtl << "# MTL format"<< std::endl;
1967  output_mtl << "# generated from MeshWriter from the DGTal library"<< std::endl;
1968  // Output vertices
1969  unsigned int n = std::min( positions.size(), vf.size() );
1970  for ( unsigned int i = 0; i < n; ++i )
1971  {
1972  RealPoint p0 = positions[ i ];
1973  RealPoint p1 = p0 + vf[ i ];
1974  RealVector v = vf[ i ];
1975  RealVector absv = RealVector( fabs( v[ 0 ] ), fabs( v[ 1 ] ), fabs( v[ 2 ] ) );
1976  unsigned int mc = std::max_element( absv.begin(), absv.end() ) - absv.begin();
1977  RealVector b =
1978  mc == 2 ? RealVector( 1, 0, 0 ) :
1979  mc == 1 ? RealVector( 0, 0, 1 ) : RealVector( 0, 1, 0 );
1980  RealVector e0 = v.crossProduct( b ).getNormalized();
1981  RealVector e1 = v.crossProduct( e0 ).getNormalized();
1982  RealPoint t[4] = { thickness * e0, thickness * e1,
1983  -thickness * e0, -thickness * e1 };
1984  for ( unsigned int j = 0; j < 4; ++j ) {
1985  RealPoint pt0 = p0 + t[ j ];
1986  RealPoint pt1 = p1 + t[ j ];
1987  output_obj << "v " << pt0[ 0 ] << " " << pt0[ 1 ] << " " << pt0[ 2 ]
1988  << std::endl;
1989  output_obj << "v " << pt1[ 0 ] << " " << pt1[ 1 ] << " " << pt1[ 2 ]
1990  << std::endl;
1991  }
1992  }
1993  // Simplify materials (very useful for blender).
1994  std::map<Color,Idx> map_colors;
1995  {
1996  Idx j = 0;
1997  for ( auto && c : diffuse_colors )
1998  if ( ! map_colors.count( c ) )
1999  map_colors[ c ] = j++;
2000  }
2001 
2002  // Output materials
2003  bool has_material = ! diffuse_colors.empty();
2004  if ( has_material )
2005  for ( auto&& pair : map_colors )
2007  ( output_mtl, pair.second, ambient_color, pair.first, specular_color);
2008  else
2010  ( output_mtl, 0, ambient_color, diffuse_color, specular_color );
2011  // Output faces
2012  for ( Idx i = 0; i < n; ++i )
2013  {
2014  output_obj << "usemtl material_" // << ( has_material ? i : 0 )
2015  << ( has_material ? map_colors[ diffuse_colors[ i ] ] : 0 )
2016  << std::endl;
2017  Idx b = 8*i+1;
2018  for ( Idx j = 0; j < 8; j += 2 )
2019  output_obj << "f " << (b+j) << " " << (b+j+1)
2020  << " " << (b+(j+3)%8) << " " << (b+(j+2)%8) << std::endl;
2021  output_obj << "f " << b << " " << (b+2)
2022  << " " << (b+4) << " " << (b+6) << std::endl;
2023  output_obj << "f " << (b+1) << " " << (b+7)
2024  << " " << (b+5) << " " << (b+3) << std::endl;
2025  }
2026  output_mtl.close();
2027  return output_obj.good();
2028  }
2029 
2030  // ----------------------- Mesh services ------------------------------
2031  public:
2032 
2037  {
2038  return Parameters
2039  ( "faceSubdivision", "Centroid" );
2040  }
2041 
2055  {
2056  auto pTriSurf = CountedPtr<TriangulatedSurface>
2057  ( new TriangulatedSurface ); // acquired
2058  bool ok = MeshHelpers::mesh2TriangulatedSurface( *aMesh, *pTriSurf );
2059  return ok ? pTriSurf : CountedPtr< TriangulatedSurface >( nullptr );
2060  }
2061 
2070  static CountedPtr< Mesh >
2072  const Color& aColor = Color::White )
2073  {
2074  auto pMesh = CountedPtr<Mesh>( new Mesh( aColor ) ); // acquired
2075  MeshHelpers::triangulatedSurface2Mesh( *triSurf, *pMesh );
2076  return pMesh;
2077  }
2078 
2087  static CountedPtr< Mesh >
2089  const Color& aColor = Color::White )
2090  {
2091  auto pMesh = CountedPtr<Mesh>( new Mesh( aColor ) ); // acquired
2092  MeshHelpers::polygonalSurface2Mesh( *polySurf, *pMesh );
2093  return pMesh;
2094  }
2095 
2102  template < typename TContainer >
2106  {
2107  auto embedder = getCellEmbedder( aSurface );
2108  auto pTriSurf = CountedPtr<TriangulatedSurface>
2109  ( new TriangulatedSurface ); // acquired
2111  ( *aSurface, embedder, *pTriSurf, s2i );
2112  return pTriSurf;
2113  }
2114 
2120  template < typename TContainer >
2123  {
2124  Surfel2Index s2i;
2125  return makeTriangulatedSurface( s2i, aSurface );
2126  }
2127 
2147  const Parameters& params = parametersMesh() )
2148  {
2149  std::string faceSubdivision = params[ "faceSubdivision" ].as<std::string>();
2150  bool centroid = ( faceSubdivision == "Centroid" );
2151  auto pTriSurf = CountedPtr<TriangulatedSurface>
2152  ( new TriangulatedSurface ); // acquired
2153  MeshHelpers::polygonalSurface2TriangulatedSurface( *polySurf, *pTriSurf, centroid );
2154  return pTriSurf;
2155  }
2156 
2167  {
2168  auto pPolySurf = CountedPtr<PolygonalSurface>
2169  ( new PolygonalSurface ); // acquired
2170  bool ok = MeshHelpers::mesh2PolygonalSurface( *aMesh, *pPolySurf );
2171  return ok ? pPolySurf : CountedPtr< PolygonalSurface >( nullptr );
2172  }
2173 
2189  const Parameters& params =
2193  {
2194  auto K = getKSpace( gray_scale_image );
2195  auto bimage = makeBinaryImage( gray_scale_image, params );
2196  auto digSurf = makeDigitalSurface( bimage, K, params );
2197  RealVector gh = { params[ "gridsizex" ].as<double>(),
2198  params[ "gridsizey" ].as<double>(),
2199  params[ "gridsizez" ].as<double>() };
2200  double threshold = params[ "thresholdMin" ].as<double>() + 0.5;
2201  typedef RegularPointEmbedder<Space> PointEmbedder;
2202  typedef ImageLinearCellEmbedder
2203  < KSpace, GrayScaleImage, PointEmbedder > ImageCellEmbedder;
2204  PointEmbedder pembedder;
2205  pembedder.init( gh );
2206  ImageCellEmbedder cembedder;
2207  cembedder.init( K, *gray_scale_image, pembedder, threshold );
2208  auto pPolySurf = CountedPtr<PolygonalSurface>
2209  ( new PolygonalSurface ); // acquired
2210  Surfel2Index s2i;
2212  ( *digSurf, cembedder, *pPolySurf, s2i );
2213  return pPolySurf;
2214  }
2215 
2232  const Parameters& params =
2236  {
2237  auto K = getKSpace( gray_scale_image );
2238  auto bimage = makeBinaryImage( gray_scale_image, params );
2239  auto digSurf = makeDigitalSurface( bimage, K, params );
2240  RealVector gh = { params[ "gridsizex" ].as<double>(),
2241  params[ "gridsizey" ].as<double>(),
2242  params[ "gridsizez" ].as<double>() };
2243  double threshold = params[ "thresholdMin" ].as<double>() + 0.5;
2244  typedef RegularPointEmbedder<Space> PointEmbedder;
2245  typedef ImageLinearCellEmbedder
2246  < KSpace, GrayScaleImage, PointEmbedder > ImageCellEmbedder;
2247  PointEmbedder pembedder;
2248  pembedder.init( gh );
2249  ImageCellEmbedder cembedder;
2250  cembedder.init( K, *gray_scale_image, pembedder, threshold );
2251  auto pPolySurf = CountedPtr<TriangulatedSurface>
2252  ( new TriangulatedSurface ); // acquired
2253  Surfel2Index s2i;
2255  ( *digSurf, cembedder, *pPolySurf, s2i );
2256  return pPolySurf;
2257  }
2258 
2266  template < typename TContainer >
2270  {
2271  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2272  auto embedder = getCellEmbedder( aSurface );
2273  auto pPolySurf = CountedPtr<PolygonalSurface>
2274  ( new PolygonalSurface ); // acquired
2276  ( *aSurface, embedder, *pPolySurf, s2i );
2277  return pPolySurf;
2278  }
2279 
2286  template < typename TContainer >
2289  {
2290  Surfel2Index s2i;
2291  return makeDualPolygonalSurface( s2i, aSurface );
2292  }
2293 
2300  template < typename TContainer >
2304  {
2305  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2306  auto pPolySurf = CountedPtr<PolygonalSurface>
2307  ( new PolygonalSurface( aSurface->heds(),
2308  aSurface->positions().storage() ) );
2309  return pPolySurf;
2310  }
2311 
2319  template < typename TContainer >
2323  {
2324  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2325  auto embedder = getCellEmbedder( aSurface );
2326  auto pPolySurf = CountedPtr<PolygonalSurface>
2327  ( new PolygonalSurface ); // acquired
2329  ( *aSurface, embedder, *pPolySurf, c2i );
2330  return ok ? pPolySurf : CountedPtr< PolygonalSurface >( nullptr );
2331  }
2332 
2339  template < typename TContainer >
2342  {
2343  Cell2Index c2i;
2344  return makePrimalPolygonalSurface( c2i, aSurface );
2345  }
2346 
2353  template < typename TContainer >
2357  {
2358  auto dsurf = makeDigitalSurface( aSurface );
2359  Cell2Index c2i;
2360  return makePrimalPolygonalSurface( c2i, dsurf );
2361  }
2362 
2370  template < typename TContainer >
2374  {
2375  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2376  auto embedder = getCellEmbedder( aSurface );
2377  auto pPolySurf = CountedPtr<SurfaceMesh>( new SurfaceMesh ); // acquired
2378  bool ok = MeshHelpers::digitalSurface2PrimalSurfaceMesh( *aSurface, embedder, *pPolySurf, c2i );
2379  return ok ? pPolySurf : CountedPtr< SurfaceMesh >( nullptr );
2380  }
2381 
2388  template < typename TContainer >
2391  {
2392  Cell2Index c2i;
2393  return makePrimalSurfaceMesh( c2i, aSurface );
2394  }
2395 
2402  template < typename TContainer >
2405  {
2406  auto dsurf = makeDigitalSurface( aSurface );
2407  Cell2Index c2i;
2408  return makePrimalSurfaceMesh( c2i, dsurf );
2409  }
2410 
2417  template <typename TPoint>
2418  static bool
2419  saveOBJ
2421  const std::string& objfile )
2422  {
2423  std::ofstream output( objfile.c_str() );
2424  bool ok = MeshHelpers::exportOBJ( output, *polysurf );
2425  output.close();
2426  return ok;
2427  }
2428 
2437  template <typename TPoint>
2438  static bool
2440  std::string off_file,
2441  const Color& face_color = DGtal::Color::None)
2442 
2443  {
2446  std::ofstream output( off_file.c_str() );
2447  for (unsigned int i=0; i< m.nbFaces(); i++)
2448  {
2449  m.setFaceColor(i, face_color);
2450  }
2451  bool ok = MeshWriter< TPoint >::export2OFF( output, m, true );
2452  output.close();
2453  return ok;
2454  }
2455 
2462  template <typename TPoint>
2463  static bool
2464  saveOBJ
2466  const std::string& objfile )
2467  {
2468  std::ofstream output( objfile.c_str() );
2469  bool ok = MeshHelpers::exportOBJ( output, *trisurf );
2470  output.close();
2471  return ok;
2472  }
2473 
2486  template <typename TPoint>
2487  static bool
2488  saveOBJ
2490  const RealVectors& normals,
2491  const Colors& diffuse_colors,
2492  std::string objfile,
2493  const Color& ambient_color = Color( 32, 32, 32 ),
2494  const Color& diffuse_color = Color( 200, 200, 255 ),
2495  const Color& specular_color = Color::White )
2496  {
2497  std::string mtlfile;
2498  auto lastindex = objfile.find_last_of(".");
2499  if ( lastindex == std::string::npos )
2500  {
2501  mtlfile = objfile + ".mtl";
2502  objfile = objfile + ".obj";
2503  }
2504  else
2505  {
2506  mtlfile = objfile.substr(0, lastindex) + ".mtl";
2507  }
2508  std::ofstream output( objfile.c_str() );
2510  ( output, mtlfile, *polysurf, normals, diffuse_colors,
2511  ambient_color, diffuse_color, specular_color );
2512  output.close();
2513  return ok;
2514  }
2515 
2528  template <typename TPoint>
2529  static bool
2530  saveOBJ
2532  const RealVectors& normals,
2533  const Colors& diffuse_colors,
2534  std::string objfile,
2535  const Color& ambient_color = Color( 32, 32, 32 ),
2536  const Color& diffuse_color = Color( 200, 200, 255 ),
2537  const Color& specular_color = Color::White )
2538  {
2539  std::string mtlfile;
2540  auto lastindex = objfile.find_last_of(".");
2541  if ( lastindex == std::string::npos )
2542  {
2543  mtlfile = objfile + ".mtl";
2544  objfile = objfile + ".obj";
2545  }
2546  else
2547  {
2548  mtlfile = objfile.substr(0, lastindex) + ".mtl";
2549  }
2550  std::ofstream output( objfile.c_str() );
2552  ( output, mtlfile, *trisurf, normals, diffuse_colors,
2553  ambient_color, diffuse_color, specular_color );
2554  output.close();
2555  return ok;
2556  }
2557 
2566  template <typename TPoint>
2567  static bool
2569  std::string off_file,
2570  const Color& face_color = DGtal::Color::None)
2571 
2572  {
2575  std::ofstream output( off_file.c_str() );
2576  for (unsigned int i=0; i< m.nbFaces(); i++)
2577  {
2578  m.setFaceColor(i, face_color);
2579  }
2580  bool ok = MeshWriter< TPoint >::export2OFF( output, m, true );
2581  output.close();
2582  return ok;
2583  }
2584 
2585 
2586  // ------------------------------ utilities ------------------------------
2587  public:
2588 
2594  {
2595  return Parameters
2596  ( "colormap", "Custom" )
2597  ( "zero-tic", 0.0 );
2598  }
2599 
2616  template <typename TValue>
2617  static IdxRange
2618  getRangeMatch( const std::vector< TValue >& s1, const std::vector< TValue >& s2,
2619  bool perfect = false )
2620  {
2621  if ( perfect && ( s1.size() != s2.size() ) ) return IdxRange();
2622  std::map<TValue, Idx> M;
2623  Idx idx = 0;
2624  for ( auto val : s2 ) M[ val ] = idx++;
2625  IdxRange V( s1.size() );
2626  idx = 0;
2627  for ( auto val : s1 )
2628  {
2629  auto it = M.find( val );
2630  if ( it != M.end() ) V[ idx++ ] = it->second;
2631  else
2632  {
2633  if ( perfect ) return IdxRange();
2634  V[ idx++ ] = s2.size();
2635  }
2636  }
2637  return V;
2638  }
2639 
2651  template <typename TValue>
2652  static std::vector< TValue >
2653  getMatchedRange( const std::vector< TValue >& range, const IdxRange& match )
2654  {
2655  std::vector< TValue > result( match.size() );
2656  for ( Idx i = 0; i < result.size(); i++ )
2657  result[ i ] = range[ match[ i ] ];
2658  return result;
2659  }
2660 
2661 
2667  static ColorMap
2669  Scalar max,
2670  const Parameters& params = parametersUtilities() )
2671  {
2672  std::string cmap = params[ "colormap" ].as<std::string>();
2673  if ( cmap == "Cool" ) return ColorMap( min, max, CMAP_COOL );
2674  else if ( cmap == "Copper" ) return ColorMap( min, max, CMAP_COPPER );
2675  else if ( cmap == "Hot" ) return ColorMap( min, max, CMAP_HOT );
2676  else if ( cmap == "Jet" ) return ColorMap( min, max, CMAP_JET );
2677  else if ( cmap == "Spring" ) return ColorMap( min, max, CMAP_SPRING );
2678  else if ( cmap == "Summer" ) return ColorMap( min, max, CMAP_SUMMER );
2679  else if ( cmap == "Autumn" ) return ColorMap( min, max, CMAP_AUTUMN );
2680  else if ( cmap == "Winter" ) return ColorMap( min, max, CMAP_WINTER );
2681  else if ( cmap == "Error" )
2682  {
2683  ColorMap gradcmap( min, max );
2684  gradcmap.addColor( Color( 255, 255, 255 ) );
2685  gradcmap.addColor( Color( 255, 0, 0 ) );
2686  gradcmap.addColor( Color( 0, 0, 0 ) );
2687  return gradcmap;
2688  }
2689  // Custom colormap
2690  ColorMap gradcmap( min, max );
2691  gradcmap.addColor( Color( 0, 0, 255 ) );
2692  gradcmap.addColor( Color( 0, 255, 255 ) );
2693  gradcmap.addColor( Color( 255, 255, 255 ) );
2694  gradcmap.addColor( Color( 255, 255, 0 ) );
2695  gradcmap.addColor( Color( 255, 0, 0 ) );
2696  return gradcmap;
2697  }
2698 
2705  static ZeroTickedColorMap
2707  Scalar max,
2708  const Parameters& params = parametersUtilities() )
2709  {
2710  auto cmap = getColorMap( min, max, params );
2711  auto ztic = params[ "zero-tic" ].as<double>();
2712  ZeroTickedColorMap ztic_cmap( cmap, Color::Black );
2713  if ( ztic <= 0.0 ) return ztic_cmap;
2714  if ( min <= 0.0 && 0.0 <= max )
2715  ztic_cmap.addTick( 0.0, ztic );
2716  ztic_cmap.finalize();
2717  return ztic_cmap;
2718  }
2719 
2720 
2729  template <typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2730  static bool
2732  ( std::ostream& output,
2733  const SurfelRange& surfels,
2734  const TCellEmbedder& embedder )
2735  {
2736  typedef unsigned long Size;
2737  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2739  const KSpace& K = embedder.space();
2740  // Number and output vertices.
2741  std::map< Cell, Size > vtx_numbering;
2742  Size n = 1; // OBJ vertex numbering start at 1
2743  for ( auto&& s : surfels )
2744  {
2745  auto primal_vtcs = getPointelRange( K, s, true );
2746  for ( auto&& primal_vtx : primal_vtcs )
2747  {
2748  if ( ! vtx_numbering.count( primal_vtx ) )
2749  {
2750  vtx_numbering[ primal_vtx ] = n++;
2751  // Output vertex positions
2752  RealPoint p = embedder( primal_vtx );
2753  output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2754  }
2755  }
2756  }
2757  // Outputs all faces
2758  for ( auto&& s : surfels )
2759  {
2760  output << "f";
2761  auto primal_vtcs = getPointelRange( K, s, true );
2762  for ( auto&& primal_vtx : primal_vtcs )
2763  output << " " << vtx_numbering[ primal_vtx ];
2764  output << std::endl;
2765  }
2766  return output.good();
2767  }
2768 
2780  template <typename TAnyDigitalSurface>
2781  static bool
2783  ( std::ostream& output,
2785  {
2786  auto embedder = getCellEmbedder( surface );
2787  return outputPrimalDigitalSurfaceAsObj( output, surface, embedder );
2788  }
2789 
2807  template < typename TAnyDigitalSurface,
2808  typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2809  static bool
2811  ( std::ostream& output,
2813  const TCellEmbedder& embedder )
2814  {
2815  auto surfels = getSurfelRange( surface, Parameters( "Traversal", "Default" ) );
2816  return outputSurfelsAsObj( output, surfels, embedder );
2817  }
2818 
2827  static bool
2829  ( std::ostream& output,
2831  {
2832  auto embedder = getCellEmbedder( surface );
2833  return outputPrimalIdxDigitalSurfaceAsObj( output, surface, embedder );
2834  }
2835 
2849  template <typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2850  static bool
2852  ( std::ostream& output,
2854  const TCellEmbedder& embedder )
2855  {
2856  auto idxsurfels = getIdxSurfelRange( surface, Parameters( "Traversal", "Default" ) );
2857  auto surfelmap = surface->surfels();
2858  SurfelRange surfels;
2859  for ( auto&& idx : idxsurfels )
2860  surfels.push_back( surfelmap[ idx ] );
2861  return outputSurfelsAsObj( output, surfels, embedder );
2862  }
2863 
2880  template <typename TDigitalSurfaceContainer>
2881  static bool
2883  ( std::ostream& output,
2885  const Parameters& params = parametersMesh() )
2886  {
2887  auto embedder = getCellEmbedder( surface );
2888  return outputDualDigitalSurfaceAsObj( output, surface, embedder, params );
2889  }
2890 
2913  template < typename TDigitalSurfaceContainer,
2914  typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2915  static bool
2917  ( std::ostream& output,
2919  const TCellEmbedder& embedder,
2920  const Parameters& params = parametersMesh() )
2921  {
2922  typedef unsigned long Size;
2923  BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2925  std::string dualFaceSubdivision = params[ "faceSubdivision" ].as<std::string>();
2926  const int subdivide
2927  = dualFaceSubdivision == "Naive" ? 1
2928  : dualFaceSubdivision == "Centroid" ? 2
2929  : 0;
2930  const KSpace& K = embedder.space();
2931  // Number and ouput vertices.
2932  std::map< Vertex, Size > vtx_numbering;
2933  std::map< Face, Size > sub_numbering;
2934  Size n = 1; // OBJ vertex numbering start at 1
2935  for ( auto && s : *surface )
2936  {
2937  if ( ! vtx_numbering.count( s ) )
2938  {
2939  vtx_numbering[ s ] = n++;
2940  // Output vertex positions
2941  RealPoint p = embedder( K.unsigns( s ) );
2942  output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2943  }
2944  }
2945  auto faces = surface->allClosedFaces();
2946  // Prepare centroids if necessary
2947  if ( subdivide == 2 )
2948  {
2949  for ( auto&& f : faces )
2950  {
2951  auto vtcs = surface->verticesAroundFace( f );
2952  Size nv = vtcs.size();
2953  if ( nv > 3 )
2954  {
2955  sub_numbering[ f ] = n++;
2957  for ( auto&& s : vtcs ) p += embedder( K.unsigns( s ) );
2958  p /= nv;
2959  output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2960  }
2961  }
2962  }
2963  // Outputs closed faces.
2964  if ( subdivide == 0 )
2965  { // No subdivision
2966  for ( auto&& f : faces )
2967  {
2968  output << "f";
2969  auto vtcs = surface->verticesAroundFace( f );
2970  std::reverse( vtcs.begin(), vtcs.end() );
2971  for ( auto&& s : vtcs )
2972  output << " " << vtx_numbering[ s ];
2973  output << std::endl;
2974  }
2975  }
2976  else if ( subdivide == 1 )
2977  { // naive subdivision
2978  for ( auto&& f : faces )
2979  {
2980  auto vtcs = surface->verticesAroundFace( f );
2981  Size nv = vtcs.size();
2982  for ( Size i = 1; i < nv - 1; ++i )
2983  output << "f " << vtx_numbering[ vtcs[ 0 ] ]
2984  << " " << vtx_numbering[ vtcs[ i+1 ] ]
2985  << " " << vtx_numbering[ vtcs[ i ] ] << std::endl;
2986  }
2987  }
2988  else if ( subdivide == 2 )
2989  { // centroid subdivision
2990  for ( auto&& f : faces )
2991  {
2992  auto vtcs = surface->verticesAroundFace( f );
2993  Size nv = vtcs.size();
2994  if ( nv == 3 )
2995  output << "f " << vtx_numbering[ vtcs[ 0 ] ]
2996  << " " << vtx_numbering[ vtcs[ 2 ] ]
2997  << " " << vtx_numbering[ vtcs[ 1 ] ] << std::endl;
2998  else {
2999  Size c = sub_numbering[ f ];
3000  for ( Size i = 0; i < nv; ++i )
3001  {
3002  output << "f " << c
3003  << " " << vtx_numbering[ vtcs[ (i+1)%nv ] ]
3004  << " " << vtx_numbering[ vtcs[ i ] ] << std::endl;
3005  }
3006  }
3007  }
3008  }
3009  return output.good();
3010  }
3011 
3012 
3013  // -------------------- map I/O services ------------------------------------------
3014  public:
3015  struct CellWriter {
3016  void operator()( std::ostream& output, const KSpace& K, const Cell & cell )
3017  {
3018  for ( Dimension d = 0; d < KSpace::dimension; ++d )
3019  output << " " << K.sKCoord( cell, d );
3020  }
3021  };
3022  struct CellReader {
3023  Cell operator()( std::istream& input, const KSpace& K )
3024  {
3025  Point kp;
3026  for ( Dimension d = 0; d < KSpace::dimension; ++d )
3027  input >> kp[ d ];
3028  return K.uCell( kp );
3029  }
3030  };
3031  struct SCellWriter {
3032  void operator()( std::ostream& output, const KSpace& K, const SCell & scell )
3033  {
3034  CellWriter::operator()( output, K, K.unsigns( scell ) );
3035  output << " " << K.sSign( scell );
3036  }
3037  };
3038  struct SCellReader {
3039  SCell operator()( std::istream& input, const KSpace& K )
3040  {
3041  Point kp;
3042  typename KSpace::Sign s;
3043  for ( Dimension d = 0; d < KSpace::dimension; ++d )
3044  input >> kp[ d ];
3045  input >> s;
3046  return K.sCell( kp, s );
3047  }
3048  };
3049 
3050  template <typename Value>
3051  struct ValueWriter {
3052  void operator()( std::ostream& output, const Value& v )
3053  {
3054  output << " " << v;
3055  }
3056  void operator()( std::ostream& output, const std::vector<Value>& vv )
3057  {
3058  for ( auto&& v : vv ) output << " " << v;
3059  }
3060  };
3061 
3062  template <typename Value>
3063  struct ValueReader {
3064  bool operator()( std::istream& input, Value& value )
3065  {
3066  std::string str;
3067  std::getline( input, str );
3068  // construct a stream from the string
3069  std::stringstream strstr(str);
3070  // use stream iterators to copy the stream to the vector as whitespace separated strings
3071  std::istream_iterator<std::string> it(strstr);
3072  std::istream_iterator<std::string> end;
3073  std::vector<std::string> results(it, end);
3074  std::stringstream sstr( results[ 0 ] );
3075  sstr >> value;
3076  return ( results.size() == 1 ) && input.good();
3077  }
3078 
3079  bool operator()( std::istream& input, std::vector<Value>& values )
3080  {
3081  std::string str;
3082  std::getline( input, str );
3083  // construct a stream from the string
3084  std::stringstream strstr(str);
3085  // use stream iterators to copy the stream to the vector as whitespace separated strings
3086  std::istream_iterator<std::string> it(strstr);
3087  std::istream_iterator<std::string> end;
3088  std::vector<std::string> results(it, end);
3089  values.resize( results.size() );
3090  for ( unsigned int i = 0; i < results.size(); ++i ) {
3091  std::stringstream sstr( results[ i ] );
3092  sstr >> values[ i ];
3093  }
3094  return input.good();
3095  }
3096  };
3097 
3098  // Outputs in \a output a map \a anyMap: SCell -> Value given the
3099  // appropriate value \a writer.
3100  //
3101  // @tparam TSCellMap any model of map SCell -> Value., e.g. std::map<SCell,double>
3102  // @tparam TValueWriter any model of value writer, e.g. ValueWriter<double>
3103  //
3104  // @param[out] output the output stream
3105  // @param[in] K the Khalimsky space where cells are defined.
3106  // @param[in] anyMap the map associated a value to signed cells.
3107  // @param[in] writer the writer that can write values on the ouput
3108  // stream, e.g. ValueWriter<double> to write double value or
3109  // vector<double> values.
3110  template <typename TSCellMap, typename TValueWriter>
3111  static
3112  bool outputSCellMapAsCSV
3113  ( std::ostream& output,
3114  const KSpace& K,
3115  const TSCellMap& anyMap,
3116  const TValueWriter& writer )
3117  {
3118  SCellWriter w;
3119  for ( auto&& v : anyMap )
3120  {
3121  w( output, K, v.first );
3122  writer( output, v.second );
3123  output << std::endl;
3124  }
3125  return output.good();
3126  }
3127 
3128  // Outputs in \a output a map \a anyMap: SCell -> value given the
3129  // appropriate value \a writer.
3130  //
3131  // @tparam TCellMap any model of map Cell -> Value., e.g. std::map<Cell,double>
3132  // @tparam TValueWriter any model of value writer, e.g. ValueWriter<double>
3133  //
3134  // @param[out] output the output stream
3135  // @param[in] K the Khalimsky space where cells are defined.
3136  // @param[in] anyMap the map associated a value to signed cells.
3137  // @param[in] writer the writer that can write values on the ouput
3138  // stream, e.g. ValueWriter<double> to write double value or
3139  // vector<double> values.
3140  template <typename TCellMap, typename TValueWriter>
3141  static
3142  bool outputCellMapAsCSV
3143  ( std::ostream& output,
3144  const KSpace& K,
3145  const TCellMap& anyMap,
3146  const TValueWriter& writer )
3147  {
3148  CellWriter w;
3149  for ( auto&& v : anyMap )
3150  {
3151  w( output, K, v.first );
3152  writer( output, v.second );
3153  output << std::endl;
3154  }
3155  return output.good();
3156  }
3157 
3163  static
3164  CellRange getPrimalCells( const KSpace& K, const SCell& s, const Dimension k )
3165  {
3166  auto faces = K.uFaces( K.unsigns( s ) );
3167  CellRange primal_cells;
3168  for ( auto&& f : faces )
3169  {
3170  if ( K.uDim( f ) == k ) primal_cells.push_back( f );
3171  }
3172  return primal_cells;
3173  }
3174 
3179  static
3181  {
3182  return getPrimalCells( K, s, 0 );
3183  }
3184 
3191  static
3192  CellRange getPrimalVertices( const KSpace& K, const Surfel& s, bool ccw )
3193  {
3194  BOOST_STATIC_ASSERT(( KSpace::dimension == 3 ));
3195  CellRange vtcs = getPrimalVertices( K, s );
3196  std::swap( vtcs[ 2 ], vtcs[ 3 ] );
3197  auto orth_dir = K.sOrthDir( s );
3198  auto direct = K.sDirect( s, orth_dir ) ? ccw : ! ccw;
3199  Vector s0s1 = K.uCoords( vtcs[ 1 ] ) - K.uCoords( vtcs[ 0 ] );
3200  Vector s0s2 = K.uCoords( vtcs[ 2 ] ) - K.uCoords( vtcs[ 0 ] );
3201  Vector t = s0s1.crossProduct( s0s2 );
3202  if ( ( ( t[ orth_dir ] > 0.0 ) && direct )
3203  || ( ( t[ orth_dir ] < 0.0 ) && ! direct ) )
3204  std::reverse( vtcs.begin(), vtcs.end() );
3205  return vtcs;
3206  }
3207 
3208 
3209  // ----------------------- Standard services ------------------------------
3210  public:
3211 
3215  Shortcuts() = delete;
3216 
3220  ~Shortcuts() = delete;
3221 
3226  Shortcuts ( const Shortcuts & other ) = delete;
3227 
3232  Shortcuts ( Shortcuts && other ) = delete;
3233 
3239  Shortcuts & operator= ( const Shortcuts & other ) = delete;
3240 
3246  Shortcuts & operator= ( Shortcuts && other ) = delete;
3247 
3248  // ----------------------- Interface --------------------------------------
3249  public:
3250 
3255  void selfDisplay ( std::ostream & out ) const
3256  {
3257  out << "[Shortcuts]";
3258  }
3259 
3264  bool isValid() const
3265  {
3266  return true;
3267  }
3268 
3269  // ------------------------- Protected Datas ------------------------------
3270  protected:
3271 
3272  // ------------------------- Private Datas --------------------------------
3273  private:
3274 
3275  // ------------------------- Hidden services ------------------------------
3276  protected:
3277 
3278  // ------------------------- Internals ------------------------------------
3279  private:
3280 
3281  }; // end of class Shortcuts
3282 
3283 
3290  template <typename T>
3291  std::ostream&
3292  operator<< ( std::ostream & out, const Shortcuts<T> & object );
3293 
3294 } // namespace DGtal
3295 
3296 
3298 // Includes inline functions.
3299 
3300 // //
3302 
3303 #endif // !defined Shortcuts_h
3304 
3305 #undef Shortcuts_RECURSES
3306 #endif // else defined(Shortcuts_RECURSES)
DGtal::DigitalSurface::ArcRange
std::vector< Arc > ArcRange
The range of arcs is defined as a vector.
Definition: DigitalSurface.h:301
DGtal::CanonicCellEmbedder
Aim: A trivial embedder for signed and unsigned cell, which corresponds to the canonic injection of c...
Definition: CanonicCellEmbedder.h:65
DGtal::Shortcuts::Color
::DGtal::Color Color
Definition: Shortcuts.h:191
DGtal::Shortcuts::makePrimalPolygonalSurface
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2321
DGtal::Shortcuts::makeTriangulatedSurface
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2122
DGtal::GaussDigitizer
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Definition: GaussDigitizer.h:79
DGtal::DigitalSurface::Face
Definition: DigitalSurface.h:278
DGtal::CMAP_SUMMER
@ CMAP_SUMMER
Definition: GradientColorMap.h:63
DGtal::Shortcuts::ValueReader::operator()
bool operator()(std::istream &input, std::vector< Value > &values)
Definition: Shortcuts.h:3079
DGtal::Shortcuts::SurfelSet
KSpace::SurfelSet SurfelSet
defines a set of surfels
Definition: Shortcuts.h:149
DGtal::CMAP_SPRING
@ CMAP_SPRING
Definition: GradientColorMap.h:62
DGtal::Shortcuts::IdxArcRange
IdxDigitalSurface::ArcRange IdxArcRange
Definition: Shortcuts.h:171
DGtal::GaussDigitizer::getDomain
Domain getDomain() const
DGtal::Shortcuts::Cell2Index
std::map< Cell, IdxVertex > Cell2Index
Definition: Shortcuts.h:189
DGtal::PointVector::zero
static Self zero
Static const for zero PointVector.
Definition: PointVector.h:1595
DGtal::Shortcuts::makeDualPolygonalSurface
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2288
DGtal::Shortcuts::outputSCellMapAsCSV
static bool outputSCellMapAsCSV(std::ostream &output, const KSpace &K, const TSCellMap &anyMap, const TValueWriter &writer)
Definition: Shortcuts.h:3113
DGtal::KhalimskySpaceND::upperBound
const Point & upperBound() const
Return the upper bound for digital points in this space.
DGtal::Shortcuts::makeBinaryImage
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< DigitizedImplicitShape3D > shape_digitization, Domain shapeDomain, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:596
DGtal::KhalimskySpaceND::uCell
Cell uCell(const PreCell &c) const
From an unsigned cell, returns an unsigned cell lying into this Khalismky space.
DGtal::ConstAlias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
DGtal::GenericReader::import
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
DGtal::HyperRectDomain< Space >
DGtal::Shortcuts::PointelRange
CellRange PointelRange
Definition: Shortcuts.h:175
DGtal::KhalimskySpaceND::uDim
Dimension uDim(const Cell &p) const
Return the dimension of the cell [p].
DGtal::Shortcuts::Shortcuts
Shortcuts()=delete
DGtal::Shortcuts::TriangulatedSurface
::DGtal::TriangulatedSurface< RealPoint > TriangulatedSurface
Definition: Shortcuts.h:185
DGtal::Shortcuts::makeGrayScaleImage
static CountedPtr< GrayScaleImage > makeGrayScaleImage(Domain aDomain)
Definition: Shortcuts.h:736
DGtal::Shortcuts::getCellEmbedder
static CanonicCellEmbedder< KSpace > getCellEmbedder(const KSpace &K)
Definition: Shortcuts.h:438
DGtal::Shortcuts::getRangeMatch
static IdxRange getRangeMatch(const std::vector< TValue > &s1, const std::vector< TValue > &s2, bool perfect=false)
Definition: Shortcuts.h:2618
DGtal::KhalimskySpaceND::SurfelSet
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
Definition: KhalimskySpaceND.h:450
DGtal::Shortcuts::Cell
LightDigitalSurface::Cell Cell
Definition: Shortcuts.h:162
DGtal::Shortcuts::makePrimalSurfaceMesh
static CountedPtr< SurfaceMesh > makePrimalSurfaceMesh(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2390
DGtal::IndexedDigitalSurface::Arc
HalfEdgeDataStructure::HalfEdgeIndex Arc
Definition: IndexedDigitalSurface.h:132
max
int max(int a, int b)
Definition: testArithmeticalDSS.cpp:1108
DGtal::IndexedDigitalSurface::Vertex
VertexIndex Vertex
Definition: IndexedDigitalSurface.h:121
DGtal::Shortcuts::outputCellMapAsCSV
static bool outputCellMapAsCSV(std::ostream &output, const KSpace &K, const TCellMap &anyMap, const TValueWriter &writer)
Definition: Shortcuts.h:3143
DGtal::MeshHelpers::polygonalSurface2Mesh
static void polygonalSurface2Mesh(const PolygonalSurface< Point > &polysurf, Mesh< Point > &mesh)
DGtal::GraphVisitorRange
Aim: Transforms a graph visitor into a single pass input range.
Definition: GraphVisitorRange.h:71
DGtal::Shortcuts::saveOFF
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:1673
DGtal::Shortcuts::getCellRange
static CellRange getCellRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Dimension k)
Definition: Shortcuts.h:1399
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::Shortcuts::IdxSurfel
IdxDigitalSurface::Vertex IdxSurfel
Definition: Shortcuts.h:168
DGtal::Trace::error
std::ostream & error()
DGtal::Shortcuts::makeDoubleImage
static CountedPtr< DoubleImage > makeDoubleImage(Domain aDomain)
Definition: Shortcuts.h:930
DGtal::Shortcuts::ValueReader::operator()
bool operator()(std::istream &input, Value &value)
Definition: Shortcuts.h:3064
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
DGtal::IndexedDigitalSurface
Aim: Represents a digital surface with the topology of its dual surface. Its aim is to mimick the sta...
Definition: IndexedDigitalSurface.h:96
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::TickedColorMap
Aim: This class adapts any colormap to add "ticks" in the colormap colors.
Definition: TickedColorMap.h:78
DGtal::DigitalSurface::size
Size size() const
DGtal::Shortcuts::makeTriangulatedSurface
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< GrayScaleImage > gray_scale_image, const Parameters &params=parametersKSpace()|parametersBinaryImage()|parametersDigitalSurface())
Definition: Shortcuts.h:2231
DGtal::Shortcuts::IdxSurfelSet
std::set< IdxSurfel > IdxSurfelSet
Definition: Shortcuts.h:172
DGtal::KhalimskySpaceND::sCell
SCell sCell(const SPreCell &c) const
From a signed cell, returns a signed cell lying into this Khalismky space.
DGtal::Shortcuts::Arc
LightDigitalSurface::Arc Arc
Definition: Shortcuts.h:165
DGtal::Shortcuts::ExplicitSurfaceContainer
SetOfSurfels< KSpace, SurfelSet > ExplicitSurfaceContainer
defines a heavy container that represents any digital surface.
Definition: Shortcuts.h:156
DGtal::Shortcuts::ColorMap
GradientColorMap< Scalar > ColorMap
Definition: Shortcuts.h:193
DGtal::concepts::CCellularGridSpaceND
Aim: This concept describes a cellular grid space in nD. In these spaces obtained by cartesian produc...
Definition: CCellularGridSpaceND.h:162
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::BreadthFirstVisitor
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
Definition: BreadthFirstVisitor.h:94
DGtal::Shortcuts::Colors
std::vector< Color > Colors
Definition: Shortcuts.h:192
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Shortcuts::IdxDigitalSurface
IndexedDigitalSurface< ExplicitSurfaceContainer > IdxDigitalSurface
defines a connected or not indexed digital surface.
Definition: Shortcuts.h:160
DGtal::Dimension
DGtal::uint32_t Dimension
Definition: Common.h:137
DGtal::SurfaceMesh
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition: SurfaceMesh.h:91
DGtal::Shortcuts::refKSpace
static const KSpace & refKSpace(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:419
DGtal::Shortcuts::makeDigitalSurface
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1209
DGtal::Shortcuts::FloatImage
ImageContainerBySTLVector< Domain, float > FloatImage
defines a float image with (hyper-)rectangular domain.
Definition: Shortcuts.h:145
DGtal::ImageContainerBySTLVector::extent
const Vector & extent() const
DGtal::Shortcuts::BinaryImage
ImageContainerBySTLVector< Domain, bool > BinaryImage
defines a black and white image with (hyper-)rectangular domain.
Definition: Shortcuts.h:141
DGtal::MeshWriter::export2OFF
static bool export2OFF(std::ostream &out, const Mesh< TPoint > &aMesh, bool exportColor=true)
DGtal::ImageContainerBySTLVector::domain
const Domain & domain() const
DGtal::Shortcuts::CellReader
Definition: Shortcuts.h:3022
DGtal::Shortcuts::makePolygonalSurface
static CountedPtr< PolygonalSurface > makePolygonalSurface(CountedPtr< GrayScaleImage > gray_scale_image, const Parameters &params=parametersKSpace()|parametersBinaryImage()|parametersDigitalSurface())
Definition: Shortcuts.h:2188
DGtal::Shortcuts::parametersDigitalSurface
static Parameters parametersDigitalSurface()
Definition: Shortcuts.h:996
DGtal::Shortcuts::makePrimalSurfaceMesh
static CountedPtr< SurfaceMesh > makePrimalSurfaceMesh(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2372
DGtal::KhalimskySpaceND::lowerBound
const Point & lowerBound() const
Return the lower bound for digital points in this space.
DGtal::Color::Black
static const Color Black
Definition: Color.h:413
DGtal::Shortcuts::parametersBinaryImage
static Parameters parametersBinaryImage()
Definition: Shortcuts.h:547
DGtal::Shortcuts::Surfel2Index
std::map< Surfel, IdxSurfel > Surfel2Index
Definition: Shortcuts.h:188
Visitor
BreadthFirstVisitor< MyDigitalSurface > Visitor
Definition: greedy-plane-segmentation-ex2.cpp:97
DGtal::Shortcuts::SCellReader::operator()
SCell operator()(std::istream &input, const KSpace &K)
Definition: Shortcuts.h:3039
DGtal::Shortcuts
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:104
DGtal::Shortcuts::makeMesh
static CountedPtr< Mesh > makeMesh(CountedPtr< TriangulatedSurface > triSurf, const Color &aColor=Color::White)
Definition: Shortcuts.h:2071
DGtal::Shortcuts::saveVectorFieldOBJ
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:1939
DGtal::RegularPointEmbedder< Space >
DGtal::Shortcuts::RealVectors
std::vector< RealVector > RealVectors
Definition: Shortcuts.h:179
DGtal::Shortcuts::SCellWriter::operator()
void operator()(std::ostream &output, const KSpace &K, const SCell &scell)
Definition: Shortcuts.h:3032
DGtal::Shortcuts::ZeroTickedColorMap
TickedColorMap< Scalar, ColorMap > ZeroTickedColorMap
Definition: Shortcuts.h:194
DGtal::MeshHelpers::exportMTLNewMaterial
static bool exportMTLNewMaterial(std::ostream &output_mtl, unsigned int idxMaterial, const Color &ambient_color, const Color &diffuse_color, const Color &specular_color)
DGtal::MeshHelpers::digitalSurface2DualPolygonalSurface
static void digitalSurface2DualPolygonalSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, PolygonalSurface< typename CellEmbedder::Value > &polysurf, VertexMap &vertexmap)
DGtal::MeshHelpers::mesh2PolygonalSurface
static bool mesh2PolygonalSurface(const Mesh< Point > &mesh, PolygonalSurface< Point > &polysurf)
DGtal::MeshHelpers::digitalSurface2PrimalPolygonalSurface
static bool digitalSurface2PrimalPolygonalSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, PolygonalSurface< typename CellEmbedder::Value > &polysurf, CellMap &cellmap)
DGtal::MeshHelpers::triangulatedSurface2Mesh
static void triangulatedSurface2Mesh(const TriangulatedSurface< Point > &trisurf, Mesh< Point > &mesh)
DGtal::MPolynomialReader::read
Iterator read(Polynomial &p, Iterator begin, Iterator end)
Definition: MPolynomialReader.h:284
Size
HalfEdgeDataStructure::Size Size
Definition: testHalfEdgeDataStructure.cpp:50
DGtal::KhalimskySpaceND::sDirect
bool sDirect(const SCell &p, Dimension k) const
Return 'true' if the direct orientation of [p] along [k] is in the positive coordinate direction.
DGtal::Shortcuts::makePrimalPolygonalSurface
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2341
DGtal::PointVector::Component
TEuclideanRing Component
Type for Vector elements.
Definition: PointVector.h:614
DGtal::KhalimskySpaceND::sSign
Sign sSign(const SCell &c) const
Return its sign.
DGtal::KhalimskySpaceND::uFaces
Cells uFaces(const Cell &c) const
Return the proper faces of [c] (chain of lower incidence) that belong to the space.
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::Parameters
Definition: Parameters.h:146
DGtal::Shortcuts::DigitizedImplicitShape3D
GaussDigitizer< Space, ImplicitShape3D > DigitizedImplicitShape3D
defines the digitization of an implicit shape.
Definition: Shortcuts.h:139
DGtal::Shortcuts::DoubleImage
ImageContainerBySTLVector< Domain, double > DoubleImage
defines a double image with (hyper-)rectangular domain.
Definition: Shortcuts.h:147
DGtal::SpaceND
Definition: SpaceND.h:95
DGtal::Color::White
static const Color White
Definition: Color.h:415
DGtal::MeshHelpers::exportOBJ
static bool exportOBJ(std::ostream &output, const TriangulatedSurface< Point > &trisurf)
DGtal::IndexedDigitalSurface::allVertices
VertexRange allVertices() const
DGtal::Shortcuts::getPrimalVertices
static CellRange getPrimalVertices(const KSpace &K, const Surfel &s, bool ccw)
Definition: Shortcuts.h:3192
DGtal::PointVector::crossProduct
auto crossProduct(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::crossProduct(*this, v))
Cross product with a PointVector.
DGtal::GaussDigitizer::init
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
KSpace
Z3i::KSpace KSpace
Definition: testArithmeticalDSSComputerOnSurfels.cpp:48
DGtal::Shortcuts::~Shortcuts
~Shortcuts()=delete
DGtal::CMAP_HOT
@ CMAP_HOT
Definition: GradientColorMap.h:68
DGtal::Shortcuts::RealVector
Space::RealVector RealVector
Vector with floating-point coordinates.
Definition: Shortcuts.h:121
DGtal::Shortcuts::RealPoint
Space::RealPoint RealPoint
Point with floating-point coordinates.
Definition: Shortcuts.h:123
DGtal::Shortcuts::makeFloatImage
static CountedPtr< FloatImage > makeFloatImage(Domain aDomain)
Definition: Shortcuts.h:864
DGtal::KhalimskySpaceND::dimension
static const constexpr Dimension dimension
Definition: KhalimskySpaceND.h:430
DGtal::Shortcuts::CellWriter::operator()
void operator()(std::ostream &output, const KSpace &K, const Cell &cell)
Definition: Shortcuts.h:3016
DGtal::Shortcuts::IdxVertex
IdxDigitalSurface::Vertex IdxVertex
Definition: Shortcuts.h:169
DGtal::Shortcuts::CellWriter
Definition: Shortcuts.h:3015
DGtal::Surfaces::sMakeBoundary
static void sMakeBoundary(SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
DGtal::MeshHelpers::exportOBJwithFaceNormalAndColor
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)
DGtal::Shortcuts::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CCellularGridSpaceND< TKSpace >))
DGtal::Shortcuts::ValueWriter::operator()
void operator()(std::ostream &output, const Value &v)
Definition: Shortcuts.h:3052
DGtal::Shortcuts::DigitalSurface
::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface
defines an arbitrary digital surface over a binary image.
Definition: Shortcuts.h:158
DGtal::LightImplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Definition: LightImplicitDigitalSurface.h:115
DGtal::Shortcuts::makeTriangulatedSurface
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< PolygonalSurface > polySurf, const Parameters &params=parametersMesh())
Definition: Shortcuts.h:2146
DGtal::Shortcuts::parametersMesh
static Parameters parametersMesh()
Definition: Shortcuts.h:2036
DGtal::Shortcuts::parametersKSpace
static Parameters parametersKSpace()
Definition: Shortcuts.h:311
DGtal::Shortcuts::GrayScaleImage
ImageContainerBySTLVector< Domain, GrayScale > GrayScaleImage
defines a grey-level image with (hyper-)rectangular domain.
Definition: Shortcuts.h:143
DGtal::Shortcuts::defaultParameters
static Parameters defaultParameters()
Definition: Shortcuts.h:203
DGtal::Shortcuts::ValueReader
Definition: Shortcuts.h:3063
DGtal::Shortcuts::KSpace
TKSpace KSpace
Digital cellular space.
Definition: Shortcuts.h:111
DGtal::DigitalSurface::begin
ConstIterator begin() const
DGtal::DigitalSurface::Cell
DigitalSurfaceContainer::Cell Cell
Definition: DigitalSurface.h:160
DGtal::Mesh
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition: Mesh.h:91
DGtal::Shortcuts::Scalar
RealVector::Component Scalar
Floating-point numbers.
Definition: Shortcuts.h:125
DGtal::Shortcuts::parametersDigitizedImplicitShape3D
static Parameters parametersDigitizedImplicitShape3D()
Definition: Shortcuts.h:461
DGtal::Shortcuts::makeImplicitShape3D
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters &params=parametersImplicitShape3D())
Definition: Shortcuts.h:282
reverse
ch reverse()
DGtal::Surfaces::findABel
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::Shortcuts::saveBinaryImage
static bool saveBinaryImage(CountedPtr< BinaryImage > bimage, std::string output)
Definition: Shortcuts.h:708
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::Shortcuts::Vertex
LightDigitalSurface::Vertex Vertex
Definition: Shortcuts.h:164
DGtal::Shortcuts::makeIdxDigitalSurface
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1275
DGtal::Shortcuts::ScalarPolynomial
MPolynomial< Space::dimension, Scalar > ScalarPolynomial
defines a multi-variate polynomial : RealPoint -> Scalar
Definition: Shortcuts.h:134
DGtal::Shortcuts::SCellRange
std::vector< SCell > SCellRange
Definition: Shortcuts.h:173
DGtal::Shortcuts::Point
Space::Point Point
Point with integer coordinates.
Definition: Shortcuts.h:117
DGtal::CMAP_JET
@ CMAP_JET
Definition: GradientColorMap.h:69
DGtal::Shortcuts::outputDualDigitalSurfaceAsObj
static bool outputDualDigitalSurfaceAsObj(std::ostream &output, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersMesh())
Definition: Shortcuts.h:2883
DGtal::Shortcuts::Scalars
std::vector< Scalar > Scalars
Definition: Shortcuts.h:178
DGtal::DigitalSurface::SCell
DigitalSurfaceContainer::SCell SCell
Definition: DigitalSurface.h:161
DGtal::Shortcuts::getKSpace
static KSpace getKSpace(Parameters params=parametersKSpace()|parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:486
DGtal::KanungoNoise
Aim: From a point predicate (model of concepts::CPointPredicate), this class constructs another point...
Definition: KanungoNoise.h:84
DGtal::Shortcuts::parametersGrayScaleImage
static Parameters parametersGrayScaleImage()
Definition: Shortcuts.h:723
DGtal::IndexedDigitalSurface::build
bool build(ConstAlias< DigitalSurfaceContainer > surfContainer)
DGtal::Shortcuts::ArcRange
LightDigitalSurface::ArcRange ArcRange
Definition: Shortcuts.h:167
DGtal::Shortcuts::getSCellEmbedder
static CanonicSCellEmbedder< KSpace > getSCellEmbedder(const KSpace &K)
Definition: Shortcuts.h:446
DGtal::KhalimskySpaceND::sKCoord
Integer sKCoord(const SCell &c, Dimension k) const
Return its Khalimsky coordinate along [k].
DGtal::ImplicitPolynomial3Shape
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Definition: ImplicitPolynomial3Shape.h:67
DGtal::Shortcuts::getKSpace
static KSpace getKSpace(CountedPtr< GrayScaleImage > gimage, Parameters params=parametersKSpace())
Definition: Shortcuts.h:378
DGtal::Shortcuts::ValueWriter
Definition: Shortcuts.h:3051
DGtal::PointVector::end
Iterator end()
DGtal::KhalimskySpaceND::uCoords
Point uCoords(const Cell &c) const
Return its digital coordinates.
DGtal::Shortcuts::SCell
LightDigitalSurface::SCell SCell
Definition: Shortcuts.h:163
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
DGtal::Shortcuts::isValid
bool isValid() const
Definition: Shortcuts.h:3264
DGtal::Shortcuts::LightSurfaceContainer
LightImplicitDigitalSurface< KSpace, BinaryImage > LightSurfaceContainer
Definition: Shortcuts.h:152
DGtal::MeshHelpers::polygonalSurface2TriangulatedSurface
static void polygonalSurface2TriangulatedSurface(const PolygonalSurface< Point > &polysurf, TriangulatedSurface< Point > &trisurf, bool centroid=true)
DGtal::Shortcuts::Idx
IdxVertex Idx
Definition: Shortcuts.h:181
DGtal::Shortcuts::getColorMap
static ColorMap getColorMap(Scalar min, Scalar max, const Parameters &params=parametersUtilities())
Definition: Shortcuts.h:2668
DGtal::CountedPtr
Aim: Smart pointer based on reference counts.
Definition: CountedPtr.h:79
DGtal::Shortcuts::SurfelRange
SCellRange SurfelRange
Definition: Shortcuts.h:176
DGtal::PointVector::begin
Iterator begin()
DGtal::Shortcuts::getZeroTickedColorMap
static ZeroTickedColorMap getZeroTickedColorMap(Scalar min, Scalar max, const Parameters &params=parametersUtilities())
Definition: Shortcuts.h:2706
DGtal::DigitalSurface::Arc
Definition: DigitalSurface.h:238
DGtal::CMAP_COOL
@ CMAP_COOL
Definition: GradientColorMap.h:66
DGtal::Shortcuts::SCellReader
Definition: Shortcuts.h:3038
DGtal::CMAP_AUTUMN
@ CMAP_AUTUMN
Definition: GradientColorMap.h:64
DGtal::Shortcuts::CellReader::operator()
Cell operator()(std::istream &input, const KSpace &K)
Definition: Shortcuts.h:3023
DGtal::TriangulatedSurface
Aim: Represents a triangulated surface. The topology is stored with a half-edge data structure....
Definition: TriangulatedSurface.h:85
DGtal::Shortcuts::makeDigitizedImplicitShape3D
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:523
DGtal::Shortcuts::LightDigitalSurface
::DGtal::DigitalSurface< LightSurfaceContainer > LightDigitalSurface
defines a connected digital surface over a binary image.
Definition: Shortcuts.h:154
DGtal::Shortcuts::Vector
Space::Vector Vector
Vector with integer coordinates.
Definition: Shortcuts.h:119
DGtal::Shortcuts::parametersImplicitShape3D
static Parameters parametersImplicitShape3D()
Definition: Shortcuts.h:265
DGtal::IndexedDigitalSurface::surfels
IndexedPropertyMap< SCell > surfels()
Definition: IndexedDigitalSurface.h:317
DGtal::Shortcuts::RealPoints
std::vector< RealPoint > RealPoints
Definition: Shortcuts.h:180
DGtal::Shortcuts::makeBinaryImage
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< DigitizedImplicitShape3D > shape_digitization, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:576
DGtal::DigitalSurface::end
ConstIterator end() const
DGtal::Shortcuts::getPrimalCells
static CellRange getPrimalCells(const KSpace &K, const SCell &s, const Dimension k)
Definition: Shortcuts.h:3164
DGtal::KhalimskySpaceND::sOrthDir
Dimension sOrthDir(const SCell &s) const
Given a signed surfel [s], returns its orthogonal direction (ie, the coordinate where the surfel is c...
DGtal::Shortcuts::selfDisplay
void selfDisplay(std::ostream &out) const
Definition: Shortcuts.h:3255
DGtal::PointVector::norm
double norm(const NormType type=L_2) const
DGtal::Shortcuts::IdxRange
std::vector< IdxVertex > IdxRange
Definition: Shortcuts.h:182
DGtal::Shortcuts::getKSpace
static KSpace getKSpace(CountedPtr< BinaryImage > bimage, Parameters params=parametersKSpace())
Definition: Shortcuts.h:354
DGtal::Shortcuts::makePrimalSurfaceMesh
static CountedPtr< SurfaceMesh > makePrimalSurfaceMesh(CountedPtr< ::DGtal::IndexedDigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2404
DGtal::Shortcuts::makeLightDigitalSurface
static CountedPtr< LightDigitalSurface > makeLightDigitalSurface(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1062
DGtal::Shortcuts::getKSpace
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:332
DGtal::Shortcuts::makePolygonalSurface
static CountedPtr< PolygonalSurface > makePolygonalSurface(CountedPtr< Mesh > aMesh)
Definition: Shortcuts.h:2166
DGtal::GradientColorMap::addColor
void addColor(const Color &color)
DGtal::MPolynomialReader
Aim: This class converts a string polynomial expression in a multivariate polynomial.
Definition: MPolynomialReader.h:258
DGtal::DigitalSurface::Vertex
Surfel Vertex
Defines the type for a vertex.
Definition: DigitalSurface.h:177
DGtal::Shortcuts::getPointelRange
static PointelRange getPointelRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition: Shortcuts.h:1469
DGtal::Shortcuts::CellRange
std::vector< Cell > CellRange
Definition: Shortcuts.h:174
DGtal::Shortcuts::Surfel
LightDigitalSurface::Surfel Surfel
Definition: Shortcuts.h:161
DGtal::IndexedDigitalSurface::ArcRange
std::vector< Arc > ArcRange
Definition: IndexedDigitalSurface.h:134
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::Shortcuts::makeMesh
static CountedPtr< Mesh > makeMesh(CountedPtr< PolygonalSurface > polySurf, const Color &aColor=Color::White)
Definition: Shortcuts.h:2088
DGtal::DigitalSurface::Surfel
DigitalSurfaceContainer::Surfel Surfel
Definition: DigitalSurface.h:162
DGtal::Shortcuts::GrayScale
unsigned char GrayScale
The type for 8-bits gray-scale elements.
Definition: Shortcuts.h:129
DGtal::PointVector< dim, Integer >
DGtal::Shortcuts::ImplicitShape3D
ImplicitPolynomial3Shape< Space > ImplicitShape3D
Definition: Shortcuts.h:137
DGtal::Shortcuts::parametersUtilities
static Parameters parametersUtilities()
Definition: Shortcuts.h:2593
DGtal::MeshHelpers::digitalSurface2PrimalSurfaceMesh
static bool digitalSurface2PrimalSurfaceMesh(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, SurfaceMesh< typename CellEmbedder::Value, typename CellEmbedder::Value > &polysurf, CellMap &cellmap)
DGtal::Shortcuts::getIdxSurfelRange
static IdxSurfelRange getIdxSurfelRange(CountedPtr< IdxDigitalSurface > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1612
DGtal::Shortcuts::Space
KSpace::Space Space
Digital space.
Definition: Shortcuts.h:113
DGtal::Shortcuts::PolygonalSurface
::DGtal::PolygonalSurface< RealPoint > PolygonalSurface
Definition: Shortcuts.h:186
DGtal::MeshHelpers::mesh2TriangulatedSurface
static bool mesh2TriangulatedSurface(const Mesh< Point > &mesh, TriangulatedSurface< Point > &trisurf)
DGtal::SetOfSurfels
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: SetOfSurfels.h:73
DGtal::CMAP_COPPER
@ CMAP_COPPER
Definition: GradientColorMap.h:67
DGtal::Shortcuts::saveOFF
static bool saveOFF(CountedPtr< ::DGtal::TriangulatedSurface< TPoint > > trisurf, std::string off_file, const Color &face_color=DGtal::Color::None)
Definition: Shortcuts.h:2568
DGtal::DepthFirstVisitor
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Definition: DepthFirstVisitor.h:95
DGtal::Shortcuts::getPrimalVertices
static CellRange getPrimalVertices(const KSpace &K, const SCell &s)
Definition: Shortcuts.h:3180
DGtal::MPolynomial
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
Definition: MPolynomial.h:58
DGtal::Color::None
static const Color None
Definition: Color.h:412
DGtal::Shortcuts::ValueWriter::operator()
void operator()(std::ostream &output, const std::vector< Value > &vv)
Definition: Shortcuts.h:3056
DGtal::GenericWriter::exportFile
static bool exportFile(const std::string &filename, const TContainer &anImage, const TFunctor &aFunctor=TFunctor())
DGtal::Shortcuts::saveOBJ
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:1739
DGtal::Shortcuts::IdxSurfelRange
std::vector< IdxSurfel > IdxSurfelRange
Definition: Shortcuts.h:177
DGtal::Shortcuts::makeLightDigitalSurfaces
static std::vector< CountedPtr< LightDigitalSurface > > makeLightDigitalSurfaces(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1119
DGtal::KhalimskySpaceND::unsigns
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
DGtal::Shortcuts::Face
LightDigitalSurface::Face Face
Definition: Shortcuts.h:166
DGtal::Shortcuts::makeDualPolygonalSurface
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(Surfel2Index &s2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2268
DGtal::Trace::warning
std::ostream & warning()
DGtal::functors::IntervalForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values between two constant values (the ...
Definition: IntervalForegroundPredicate.h:64
DGtal::Shortcuts::SCellWriter
Definition: Shortcuts.h:3031
DGtal::Shortcuts::getSurfelRange
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1547
DGtal::Shortcuts::makeBinaryImage
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< BinaryImage > bimage, Parameters params=parametersBinaryImage())
Definition: Shortcuts.h:628
DGtal::Shortcuts::saveOFF
static bool saveOFF(CountedPtr< ::DGtal::PolygonalSurface< TPoint > > polysurf, std::string off_file, const Color &face_color=DGtal::Color::None)
Definition: Shortcuts.h:2439
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
DGtal::Shortcuts::makeBinaryImage
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition: Shortcuts.h:561
DGtal::Shortcuts::outputPrimalIdxDigitalSurfaceAsObj
static bool outputPrimalIdxDigitalSurfaceAsObj(std::ostream &output, CountedPtr< IdxDigitalSurface > surface)
Definition: Shortcuts.h:2829
DGtal::CanonicSCellEmbedder< KSpace >
DGtal::ImageLinearCellEmbedder
Aim: a cellular embedder for images. (default constructible, copy constructible, assignable)....
Definition: ImageLinearCellEmbedder.h:69
DGtal::Shortcuts::operator=
Shortcuts & operator=(const Shortcuts &other)=delete
DGtal::PolygonalSurface
Aim: Represents a polygon mesh, i.e. a 2-dimensional combinatorial surface whose faces are (topologic...
Definition: PolygonalSurface.h:86
DGtal::Shortcuts::saveGrayScaleImage
static bool saveGrayScaleImage(CountedPtr< GrayScaleImage > gray_scale_image, std::string output)
Definition: Shortcuts.h:784
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119
DGtal::Shortcuts::Mesh
::DGtal::Mesh< RealPoint > Mesh
Definition: Shortcuts.h:184
DGtal::Shortcuts::outputSurfelsAsObj
static bool outputSurfelsAsObj(std::ostream &output, const SurfelRange &surfels, const TCellEmbedder &embedder)
Definition: Shortcuts.h:2732
DGtal::SpaceND::Integer
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
DGtal::CMAP_WINTER
@ CMAP_WINTER
Definition: GradientColorMap.h:65
DGtal::Shortcuts::getMatchedRange
static std::vector< TValue > getMatchedRange(const std::vector< TValue > &range, const IdxRange &match)
Definition: Shortcuts.h:2653
DGtal::Shortcuts::SurfaceMesh
::DGtal::SurfaceMesh< RealPoint, RealPoint > SurfaceMesh
Definition: Shortcuts.h:187
DGtal::Shortcuts::makeTriangulatedSurface
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< Mesh > aMesh)
Definition: Shortcuts.h:2054
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38
DGtal::Shortcuts::getPolynomialList
static std::map< std::string, std::string > getPolynomialList()
Definition: Shortcuts.h:236
DGtal::Shortcuts::Domain
HyperRectDomain< Space > Domain
An (hyper-)rectangular domain.
Definition: Shortcuts.h:127
DGtal::Shortcuts::makeTriangulatedSurface
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(Surfel2Index &s2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition: Shortcuts.h:2104
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
DGtal::MeshHelpers::digitalSurface2DualTriangulatedSurface
static void digitalSurface2DualTriangulatedSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, TriangulatedSurface< typename CellEmbedder::Value > &trisurf, VertexMap &vertexmap)
DGtal::Shortcuts::outputPrimalDigitalSurfaceAsObj
static bool outputPrimalDigitalSurfaceAsObj(std::ostream &output, CountedPtr< TAnyDigitalSurface > surface)
Definition: Shortcuts.h:2783
DGtal::Shortcuts::IdxArc
IdxDigitalSurface::Arc IdxArc
Definition: Shortcuts.h:170
DGtal::InputException
Definition: Exceptions.h:63
DGtal::KhalimskySpaceND::Sign
bool Sign
Definition: KhalimskySpaceND.h:421
DGtal::Shortcuts::Integer
Space::Integer Integer
Integer numbers.
Definition: Shortcuts.h:115
DGtal::concepts::CCellEmbedder
Aim: A cell embedder is a mapping from unsigned cells to Euclidean points. It adds inner types to fun...
Definition: CCellEmbedder.h:96