Loading [MathJax]/extensions/MathMenu.js
DGtal 2.0.0
Shortcuts.h
1
16
17#pragma once
18
30
31#if defined(Shortcuts_RECURSES)
32#error Recursive header files inclusion detected in Shortcuts.h
33#else // defined(Shortcuts_RECURSES)
35#define Shortcuts_RECURSES
36
37#if !defined Shortcuts_h
39#define Shortcuts_h
40
42// Inclusions
43#include <cstdlib>
44#include <iostream>
45#include <fstream>
46#include <sstream>
47#include <tuple>
48#include <iterator>
49#include <string>
50#include "DGtal/base/Common.h"
51#include "DGtal/base/CountedPtr.h"
52#include "DGtal/kernel/domains/HyperRectDomain.h"
53#include "DGtal/kernel/RegularPointEmbedder.h"
54#include "DGtal/math/MPolynomial.h"
55#include "DGtal/math/Statistic.h"
56#include "DGtal/images/ImageContainerBySTLVector.h"
57#include "DGtal/images/IntervalForegroundPredicate.h"
58#include <DGtal/images/ImageLinearCellEmbedder.h>
59#include "DGtal/shapes/implicit/ImplicitPolynomial3Shape.h"
60#include "DGtal/shapes/GaussDigitizer.h"
61#include "DGtal/shapes/ShapeGeometricFunctors.h"
62#include "DGtal/shapes/MeshHelpers.h"
63#include "DGtal/topology/CCellularGridSpaceND.h"
64#include "DGtal/topology/LightImplicitDigitalSurface.h"
65#include "DGtal/topology/SetOfSurfels.h"
66#include "DGtal/topology/DigitalSurface.h"
67#include "DGtal/topology/IndexedDigitalSurface.h"
68#include "DGtal/topology/SurfelAdjacency.h"
69#include "DGtal/topology/CCellEmbedder.h"
70#include "DGtal/topology/CanonicCellEmbedder.h"
71#include "DGtal/topology/CanonicSCellEmbedder.h"
72#include "DGtal/topology/helpers/Surfaces.h"
73#include "DGtal/geometry/volumes/KanungoNoise.h"
74#include "DGtal/shapes/Mesh.h"
75#include "DGtal/io/Color.h"
76#include "DGtal/io/colormaps/GradientColorMap.h"
77#include "DGtal/io/colormaps/TickedColorMap.h"
78#include "DGtal/io/readers/MPolynomialReader.h"
79#include "DGtal/io/readers/GenericReader.h"
80#include "DGtal/io/readers/SurfaceMeshReader.h"
81#include "DGtal/io/writers/GenericWriter.h"
82#include "DGtal/io/writers/MeshWriter.h"
83#include "DGtal/graph/BreadthFirstVisitor.h"
84#include "DGtal/graph/DepthFirstVisitor.h"
85#include "DGtal/graph/GraphVisitorRange.h"
86#include "DGtal/helpers/Parameters.h"
88
89namespace DGtal
90{
91
93 // template class Shortcuts
104 template < typename TKSpace >
106 {
108
109 // ----------------------- Usual space types --------------------------------------
110 public:
112 typedef TKSpace KSpace;
114 typedef typename KSpace::Space Space;
116 typedef typename Space::Integer Integer;
118 typedef typename Space::Point Point;
120 typedef typename Space::Vector Vector;
124 typedef typename Space::RealPoint RealPoint;
130 typedef unsigned char GrayScale;
131
132 // ----------------------- Shortcut types --------------------------------------
133 public:
150 typedef typename KSpace::SurfelSet SurfelSet;
155 typedef ::DGtal::DigitalSurface< LightSurfaceContainer > LightDigitalSurface;
159 typedef ::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface;
166 typedef typename LightDigitalSurface::Arc Arc;
167 typedef typename LightDigitalSurface::Face Face;
173 typedef std::set< IdxSurfel > IdxSurfelSet;
174 typedef std::vector< SCell > SCellRange;
175 typedef std::vector< Cell > CellRange;
178 typedef std::vector< IdxSurfel > IdxSurfelRange;
179 typedef std::vector< Scalar > Scalars;
180 typedef std::vector< RealVector > RealVectors;
181 typedef std::vector< RealPoint > RealPoints;
182 typedef IdxVertex Idx;
183 typedef std::vector< IdxVertex > IdxRange;
184
185 typedef ::DGtal::Mesh<RealPoint> Mesh;
186 typedef ::DGtal::TriangulatedSurface<RealPoint> TriangulatedSurface;
187 typedef ::DGtal::PolygonalSurface<RealPoint> PolygonalSurface;
188 typedef ::DGtal::SurfaceMesh<RealPoint,RealPoint> SurfaceMesh;
189 typedef std::map<Surfel, IdxSurfel> Surfel2Index;
190 typedef std::map<Cell, IdxVertex> Cell2Index;
191
193 typedef std::vector< Color > Colors;
196
197 // ----------------------- Static services --------------------------------------
198 public:
199
200 // ----------------------- General static services ------------------------------
201 public:
202
215
216 // ----------------------- ImplicitShape3D static services ------------------------
217 public:
218
236 static std::map< std::string, std::string >
238 {
239 std::vector< std::pair< std::string, std::string > >
240 Ps = { { "sphere1", "x^2+y^2+z^2-1" },
241 { "sphere9", "x^2+y^2+z^2-81" },
242 { "ellipsoid", "3*x^2+2*y^2+z^2-90" },
243 { "cylinder", "x^2+2*z^2-90" },
244 { "torus", "(x^2+y^2+z^2+6*6-2*2)^2-4*6*6*(x^2+y^2)" },
245 { "rcube", "x^4+y^4+z^4-6561" },
246 { "goursat", "-1*(8-0.03*x^4-0.03*y^4-0.03*z^4+2*x^2+2*y^2+2*z^2)" },
247 { "goursat-hole", "x^4+y^4+z^4-2*4*(x^2+y^2+z^2)+2*4*4-2" },
248 { "distel", "10000-(x^2+y^2+z^2+1000*(x^2+y^2)*(x^2+z^2)*(y^2+z^2))"},
249 { "leopold", "(x^2*y^2*z^2+4*x^2+4*y^2+3*z^2)-100" },
250 { "diabolo", "x^2-(y^2+z^2)^2" },
251 { "heart", "-1*(x^2+2.25*y^2+z^2-1)^3+x^2*z^3+0.1125*y^2*z^3" },
252 { "crixxi", "-0.9*(y^2+z^2-1)^2-(x^2+y^2-1)^3" } };
253 std::map< std::string, std::string > L;
254 for ( auto p : Ps )
255 L[ p.first ] = p.second;
256 return L;
257 }
258
267 {
268 return Parameters
269 ( "polynomial", "sphere1" )
270 ( "projectionMaxIter", 20 )
271 ( "projectionAccuracy", 0.0001 )
272 ( "projectionGamma", 0.5 );
273 }
274
284 {
286 std::string poly_str = params[ "polynomial" ].as<std::string>();
287 // Recognizes specific strings as polynomials.
288 auto PL = getPolynomialList();
289 if ( PL[ poly_str ] != "" ) poly_str = PL[ poly_str ];
290 ScalarPolynomial poly;
291 Polynomial3Reader reader;
292 std::string::const_iterator iter
293 = reader.read( poly, poly_str.begin(), poly_str.end() );
294 if ( iter != poly_str.end() )
295 {
296 trace.error() << "[Shortcuts::makeImplicitShape3D]"
297 << " ERROR reading polynomial: I read only <"
298 << poly_str.substr( 0, iter - poly_str.begin() )
299 << ">, and I built P=" << poly << std::endl;
300 }
301 return CountedPtr<ImplicitShape3D>( new ImplicitShape3D( poly ) );
302 }
303
304 // ----------------------- KSpace static services ------------------------------
305 public:
306
313 {
314 return Parameters
315 ( "closed", 1 )
316 ( "gridsizex", 1.0 )
317 ( "gridsizey", 1.0 )
318 ( "gridsizez", 1.0 );
319 }
320
333 static KSpace getKSpace( const Point& low, const Point& up,
334 Parameters params = parametersKSpace() )
335 {
336 int closed = params[ "closed" ].as<int>();
337 KSpace K;
338 if ( ! K.init( low, up, closed ) )
339 trace.error() << "[Shortcuts::getKSpace]"
340 << " Error building Khalimsky space K=" << K << std::endl;
341 return K;
342 }
343
356 Parameters params = parametersKSpace() )
357 {
358 int closed = params[ "closed" ].as<int>();
359 KSpace K;
360 if ( ! K.init( bimage->domain().lowerBound(),
361 bimage->domain().upperBound(),
362 closed ) )
363 trace.error() << "[Shortcuts::getKSpace]"
364 << " Error building Khalimsky space K=" << K << std::endl;
365 return K;
366 }
367
380 Parameters params = parametersKSpace() )
381 {
382 int closed = params[ "closed" ].as<int>();
383 KSpace K;
384 if ( ! K.init( gimage->domain().lowerBound(),
385 gimage->domain().upperBound(),
386 closed ) )
387 trace.error() << "[Shortcuts::getKSpace]"
388 << " Error building Khalimsky space K=" << K << std::endl;
389 return K;
390 }
391
395 template <typename TDigitalSurfaceContainer>
396 static KSpace
399 {
400 return surface->container().space();
401 }
402
406 template <typename TDigitalSurfaceContainer>
407 static KSpace
413
417 template <typename TDigitalSurfaceContainer>
418 static const KSpace&
421 {
422 return surface->container().space();
423 }
424
428 template <typename TDigitalSurfaceContainer>
429 static const KSpace&
435
440 {
442 }
443
448 {
450 }
451
452
453 // ----------------------- DigitizedImplicitShape3D static services --------------
454 public:
455
463 {
464 return Parameters
465 ( "minAABB", -10.0 )
466 ( "maxAABB", 10.0 )
467 ( "gridstep", 1.0 )
468 ( "offset", 5.0 );
469 }
470
471
486 static KSpace
489 {
490 Scalar min_x = params[ "minAABB" ].as<Scalar>();
491 Scalar max_x = params[ "maxAABB" ].as<Scalar>();
492 Scalar h = params[ "gridstep" ].as<Scalar>();
493 Scalar offset = params[ "offset" ].as<Scalar>();
494 bool closed = params[ "closed" ].as<int>();
495 RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
496 RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
498 dshape->init( p1, p2, h );
499 Domain domain = dshape->getDomain();
500 KSpace K;
501 if ( ! K.init( domain.lowerBound(), domain.upperBound(), closed ) )
502 trace.error() << "[Shortcuts::getKSpace]"
503 << " Error building Khalimsky space K=" << K << std::endl
504 << "Note: if you use decimal values, check your locale for decimal point '.' or ','."
505 << std::endl;
506 return K;
507 }
508
526 {
527 Scalar min_x = params[ "minAABB" ].as<Scalar>();
528 Scalar max_x = params[ "maxAABB" ].as<Scalar>();
529 Scalar h = params[ "gridstep" ].as<Scalar>();
530 Scalar offset = params[ "offset" ].as<Scalar>();
531 RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
532 RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
534 dshape->attach( shape );
535 dshape->init( p1, p2, h );
536 return dshape;
537 }
538
539
540 // ----------------------- BinaryImage static services --------------------------
541 public:
542
549 {
550 return Parameters
551 ( "noise", 0.0 )
552 ( "thresholdMin", 0 )
553 ( "thresholdMax", 255 );
554 }
555
562 makeBinaryImage( Domain shapeDomain )
563 {
564 return CountedPtr<BinaryImage>( new BinaryImage( shapeDomain ) );
565 }
566
579 {
580 return makeBinaryImage( shape_digitization,
581 shape_digitization->getDomain(),
582 params );
583 }
584
598 Domain shapeDomain,
600 {
601 const Scalar noise = params[ "noise" ].as<Scalar>();
602 CountedPtr<BinaryImage> img ( new BinaryImage( shapeDomain ) );
603 if ( noise <= 0.0 )
604 {
605 std::transform( shapeDomain.begin(), shapeDomain.end(),
606 img->begin(),
607 [&shape_digitization]
608 ( const Point& p ) { return (*shape_digitization)(p); } );
609 }
610 else
611 {
613 KanungoPredicate noisy_dshape( *shape_digitization, shapeDomain, noise );
614 std::transform( shapeDomain.begin(), shapeDomain.end(),
615 img->begin(),
616 [&noisy_dshape] ( const Point& p ) { return noisy_dshape(p); } );
617 }
618 return img;
619 }
620
631 {
632 const Scalar noise = params[ "noise" ].as<Scalar>();
633 if ( noise <= 0.0 ) return bimage;
634 typedef KanungoNoise< BinaryImage, Domain > KanungoPredicate;
635 const Domain shapeDomain = bimage->domain();
636 CountedPtr<BinaryImage> img ( new BinaryImage( shapeDomain ) );
637 KanungoPredicate noisy_dshape( *bimage, shapeDomain, noise );
638 std::transform( shapeDomain.begin(), shapeDomain.end(),
639 img->begin(),
640 [&noisy_dshape] ( const Point& p ) { return noisy_dshape(p); } );
641 return img;
642 }
643
657 ( std::string input,
659 {
660 int thresholdMin = params["thresholdMin"].as<int>();
661 int thresholdMax = params["thresholdMax"].as<int>();
663 Domain domain = image.domain();
665 ThresholdedImage tImage( image, thresholdMin, thresholdMax );
667 std::transform( domain.begin(), domain.end(),
668 img->begin(),
669 [tImage] ( const Point& p ) { return tImage(p); } );
670 return makeBinaryImage( img, params );
671 }
672
686 ( CountedPtr<GrayScaleImage> gray_scale_image,
688 {
689 int thresholdMin = params["thresholdMin"].as<int>();
690 int thresholdMax = params["thresholdMax"].as<int>();
691 Domain domain = gray_scale_image->domain();
693 ThresholdedImage tImage( *gray_scale_image, thresholdMin, thresholdMax );
695 std::transform( domain.begin(), domain.end(),
696 img->begin(),
697 [tImage] ( const Point& p ) { return tImage(p); } );
698 return makeBinaryImage( img, params );
699 }
700
701
707 static bool
709 ( CountedPtr<BinaryImage> bimage, std::string output )
710 {
711 auto gray_scale_image = makeGrayScaleImage( bimage );
712 return saveGrayScaleImage( gray_scale_image, output );
713 }
714
715
716 // ----------------------- GrayScaleImage static services -------------------------
717 public:
718
725 {
726 return Parameters
727 ( "qShift", 128.0 )
728 ( "qSlope", 1.0 );
729 }
730
738 {
739 return CountedPtr<GrayScaleImage>( new GrayScaleImage( aDomain ) );
740 }
741
750 ( std::string input )
751 {
754 }
755
765 std::function< GrayScale( bool ) > const & bool2grayscale
766 = [] ( bool v ) { return v ? (unsigned char) 255 : (unsigned char) 0; }
767 // JOL: (GrayScale) was not working with visual C++: error C2065
768 )
769 {
770 const Domain domain = binary_image->domain();
771 CountedPtr<GrayScaleImage> gray_scale_image( new GrayScaleImage( domain ) );
772 std::transform( binary_image->begin(), binary_image->end(),
773 gray_scale_image->begin(),
774 bool2grayscale );
775 return gray_scale_image;
776 }
777
783 static bool
785 ( CountedPtr<GrayScaleImage> gray_scale_image, std::string output )
786 {
788 ::exportFile( output, *gray_scale_image );
789 }
790
791
805 ( CountedPtr<FloatImage> fimage,
807 {
808 float qShift = params[ "qShift" ].as<float>();
809 float qSlope = params[ "qSlope" ].as<float>();
810 std::function< unsigned char( float ) > f
811 = [qShift,qSlope] (float v)
812 { return (unsigned char) std::min( 255.0f, std::max( 0.0f, qSlope * v + qShift ) ); };
813 Domain domain = fimage->domain();
814 auto gimage = makeGrayScaleImage( domain );
815 auto it = gimage->begin();
816 for ( auto p : domain )
817 {
818 float val = (*fimage)( p );
819 *it++ = f( val );
820 }
821 return gimage;
822 }
823
839 {
840 double qShift = params[ "qShift" ].as<double>();
841 double qSlope = params[ "qSlope" ].as<double>();
842 std::function< unsigned char( double ) > f
843 = [qShift,qSlope] (double v)
844 { return (unsigned char) std::min( 255.0, std::max( 0.0, qSlope * v + qShift ) ); };
845 Domain domain = fimage->domain();
846 auto gimage = makeGrayScaleImage( domain );
847 auto it = gimage->begin();
848 for ( auto p : domain )
849 {
850 double val = (*fimage)( p );
851 *it++ = f( val );
852 }
853 return gimage;
854 }
855
856 // ----------------------- FloatImage static services -------------------------
857 public:
858
866 {
867 return CountedPtr<FloatImage>( new FloatImage( aDomain ) );
868 }
869
878 ( std::string input )
879 {
881 return CountedPtr<FloatImage>( new FloatImage( image ) );
882 }
883
901 {
902 Scalar min_x = params[ "minAABB" ].as<Scalar>();
903 Scalar max_x = params[ "maxAABB" ].as<Scalar>();
904 Scalar h = params[ "gridstep" ].as<Scalar>();
905 Scalar offset = params[ "offset" ].as<Scalar>();
906 RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
907 RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
909 dshape->attach( shape );
910 dshape->init( p1, p2, h );
911 Domain domain = dshape->getDomain();
912 auto fimage = makeFloatImage( domain );
913 auto it = fimage->begin();
914 for ( auto p : domain )
915 {
916 float val = (float) (*shape)( p );
917 *it++ = val;
918 }
919 return fimage;
920 }
921
922 // ----------------------- DoubleImage static services -------------------------
923 public:
924
932 {
933 return CountedPtr<DoubleImage>( new DoubleImage( aDomain ) );
934 }
935
944 ( std::string input )
945 {
948 }
949
967 {
968 Scalar min_x = params[ "minAABB" ].as<Scalar>();
969 Scalar max_x = params[ "maxAABB" ].as<Scalar>();
970 Scalar h = params[ "gridstep" ].as<Scalar>();
971 Scalar offset = params[ "offset" ].as<Scalar>();
972 RealPoint p1( min_x - offset * h, min_x - offset * h, min_x - offset * h );
973 RealPoint p2( max_x + offset * h, max_x + offset * h, max_x + offset * h );
975 dshape->attach( shape );
976 dshape->init( p1, p2, h );
977 Domain domain = dshape->getDomain();
978 auto fimage = makeDoubleImage( domain );
979 auto it = fimage->begin();
980 for ( auto p : domain )
981 {
982 double val = (double) (*shape)( p );
983 *it++ = val;
984 }
985 return fimage;
986 }
987
988 // ----------------------- DigitalSurface static services ------------------------
989 public:
990
998 {
999 return Parameters
1000 ( "surfelAdjacency", 0 )
1001 ( "nbTriesToFindABel", 100000 )
1002 ( "surfaceComponents", "AnyBig" )
1003 ( "surfaceTraversal", "Default" );
1004 }
1005
1009 template <typename TDigitalSurfaceContainer>
1016
1020 template <typename TDigitalSurfaceContainer>
1027
1031 template <typename TDigitalSurfaceContainer>
1038
1042 template <typename TDigitalSurfaceContainer>
1049
1063 ( CountedPtr<BinaryImage> bimage,
1064 const KSpace& K,
1065 const Parameters& params = parametersDigitalSurface() )
1066 {
1067 bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1068 int nb_tries_to_find_a_bel = params[ "nbTriesToFindABel" ].as<int>();
1069 SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1070
1071 // We have to search for a surfel that belongs to a big connected component.
1073 Surfel bel;
1074 Scalar minsize = bimage->extent().norm();
1075 unsigned int nb_surfels = 0;
1076 unsigned int tries = 0;
1077 do
1078 {
1079 try { // Search initial bel
1080 bel = Surfaces<KSpace>::findABel( K, *bimage, nb_tries_to_find_a_bel );
1081 } catch (DGtal::InputException& e) {
1082 trace.error() << "[Shortcuts::makeLightDigitalSurface]"
1083 << " ERROR Unable to find bel. " << e << std::endl;
1084 return ptrSurface;
1085 }
1086 // this pointer will be acquired by the surface.
1087 LightSurfaceContainer* surfContainer
1088 = new LightSurfaceContainer( K, *bimage, surfAdj, bel );
1090 ( new LightDigitalSurface( surfContainer ) ); // acquired
1091 nb_surfels = ptrSurface->size();
1092 }
1093 while ( ( nb_surfels < 2 * minsize ) && ( tries++ < 150 ) );
1094 if( tries >= 150 )
1095 trace.warning() << "[Shortcuts::makeLightDigitalSurface]"
1096 << "ERROR cannot find a proper bel in a big enough component."
1097 << std::endl;
1098 return ptrSurface;
1099 }
1100
1118 static std::vector< CountedPtr<LightDigitalSurface> >
1120 ( CountedPtr<BinaryImage> bimage,
1121 const KSpace& K,
1122 const Parameters& params = parametersDigitalSurface() )
1123 {
1124 SurfelRange surfel_reps;
1125 return makeLightDigitalSurfaces( surfel_reps, bimage, K, params );
1126 }
1127
1148 static std::vector< CountedPtr<LightDigitalSurface> >
1150 ( SurfelRange& surfel_reps,
1152 const KSpace& K,
1153 const Parameters& params = parametersDigitalSurface() )
1154 {
1155 std::vector< CountedPtr<LightDigitalSurface> > result;
1156 std::string component = params[ "surfaceComponents" ].as<std::string>();
1157 if ( component == "AnyBig" )
1158 {
1159 result.push_back( makeLightDigitalSurface( bimage, K, params ) );
1160 surfel_reps.push_back( *( result[ 0 ]->begin() ) );
1161 return result;
1162 }
1163 bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1164 SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1165 // Extracts all boundary surfels
1166 SurfelSet all_surfels;
1167 Surfaces<KSpace>::sMakeBoundary( all_surfels, K, *bimage,
1168 K.lowerBound(), K.upperBound() );
1169 // Builds all connected components of surfels.
1170 SurfelSet marked_surfels;
1172 for ( auto bel : all_surfels )
1173 {
1174 if ( marked_surfels.count( bel ) != 0 ) continue;
1175 surfel_reps.push_back( bel );
1176 LightSurfaceContainer* surfContainer
1177 = new LightSurfaceContainer( K, *bimage, surfAdj, bel );
1179 ( new LightDigitalSurface( surfContainer ) ); // acquired
1180 // mark all surfels of the surface component.
1181 marked_surfels.insert( ptrSurface->begin(), ptrSurface->end() );
1182 // add surface component to result.
1183 result.push_back( ptrSurface );
1184 }
1185 return result;
1186 }
1187
1188
1207 template <typename TPointPredicate>
1211 const KSpace& K,
1212 const Parameters& params = parametersDigitalSurface() )
1213 {
1214 SurfelSet all_surfels;
1215 bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1216 SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1217 // Extracts all boundary surfels
1218 Surfaces<KSpace>::sMakeBoundary( all_surfels, K, *bimage,
1219 K.lowerBound(), K.upperBound() );
1220 ExplicitSurfaceContainer* surfContainer
1221 = new ExplicitSurfaceContainer( K, surfAdj, all_surfels );
1223 ( new DigitalSurface( surfContainer ) ); // acquired
1224 }
1225
1226
1241 ( CountedPtr<IdxDigitalSurface> idx_surface,
1242 const Parameters& params = parametersDigitalSurface() )
1243 {
1244 bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1245 const KSpace& K = refKSpace( idx_surface );
1246 SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1247 auto all_idx_surfels
1248 = getIdxSurfelRange( idx_surface, Parameters( "surfaceTraversal", "Default" ) );
1249 auto idx2surfel = idx_surface->surfels();
1250 SurfelSet all_surfels;
1251 for ( auto idx : all_idx_surfels ) all_surfels.insert( idx2surfel[ idx ] );
1252 ExplicitSurfaceContainer* surfContainer
1253 = new ExplicitSurfaceContainer( K, surfAdj, all_surfels );
1255 ( new DigitalSurface( surfContainer ) ); // acquired
1256 }
1257
1276 ( CountedPtr<BinaryImage> bimage,
1277 const KSpace& K,
1278 const Parameters& params = parametersDigitalSurface() )
1279 {
1280 std::string component = params[ "surfaceComponents" ].as<std::string>();
1281 SurfelSet surfels;
1282 if ( component == "AnyBig" )
1283 {
1284 auto light_surface = makeLightDigitalSurface( bimage, K, params );
1285 surfels.insert( light_surface->begin(), light_surface->end() );
1286 }
1287 else if ( component == "All" )
1288 {
1289 Surfaces<KSpace>::sMakeBoundary( surfels, K, *bimage,
1290 K.lowerBound(), K.upperBound() );
1291 }
1292 return makeIdxDigitalSurface( surfels, K, params );
1293 }
1294
1306 template <typename TSurfelRange>
1309 ( const TSurfelRange& surfels,
1311 const Parameters& params = parametersDigitalSurface() )
1312 {
1313 bool surfel_adjacency = params[ "surfelAdjacency" ].as<int>();
1314 SurfelAdjacency< KSpace::dimension > surfAdj( surfel_adjacency );
1315 // Build indexed digital surface.
1317 ( new ExplicitSurfaceContainer( K, surfAdj, surfels ) );
1319 ( new IdxDigitalSurface() );
1320 bool ok = ptrSurface->build( ptrSurfContainer );
1321 if ( !ok )
1322 trace.warning() << "[Shortcuts::makeIdxDigitalSurface]"
1323 << " Error building indexed digital surface." << std::endl;
1324 return ptrSurface;
1325 }
1326
1339 template <typename TDigitalSurfaceContainer>
1343 const Parameters& params = parametersDigitalSurface() )
1344 {
1345 const KSpace& K = refKSpace( surface );
1346 SurfelSet surfels;
1347 surfels.insert( surface->begin(), surface->end() );
1348 return makeIdxDigitalSurface( surfels, K, params );
1349 }
1350
1365 ( const std::vector< CountedPtr<LightDigitalSurface> >& surfaces,
1366 const Parameters& params = parametersDigitalSurface() )
1367 {
1368 if ( surfaces.empty() ) return CountedPtr<IdxDigitalSurface>( 0 );
1369 const KSpace& K = surfaces[ 0 ]->container().space();
1370 SurfelSet surfels;
1371 for ( std::size_t i = 0; i < surfaces.size(); ++i )
1372 {
1373 const KSpace& Ki = surfaces[ i ]->container().space();
1374 if ( ( Ki.lowerBound() != K.lowerBound() )
1375 || ( Ki.upperBound() != K.upperBound() ) )
1376 trace.warning() << "[Shortcuts::makeIdxDigitalSurface]"
1377 << " Incompatible digital spaces for surface " << i << std::endl;
1378 surfels.insert( surfaces[ i ]->begin(), surfaces[ i ]->end() );
1379 }
1380 return makeIdxDigitalSurface( surfels, K, params );
1381 }
1382
1383
1397 template <typename TDigitalSurfaceContainer>
1398 static CellRange
1400 ( Cell2Index& c2i,
1402 const Dimension k )
1403 {
1404 CellRange result;
1405 // Approximate number of pointels given the number of 2-cells (valid for 2d surfaces in nD).
1406 result.reserve( 2 * surface->size() + 100 );
1407 const KSpace& K = refKSpace( surface );
1408 Idx n = 0;
1409 for ( auto&& surfel : *surface )
1410 {
1411 CellRange primal_cells = getPrimalCells( K, surfel, k );
1412 for ( auto&& primal_cell : primal_cells )
1413 {
1414 if ( ! c2i.count( primal_cell ) )
1415 {
1416 result.push_back( primal_cell );
1417 c2i[ primal_cell ] = n++;
1418 }
1419 }
1420 }
1421 return result;
1422 }
1423
1436 template <typename TDigitalSurfaceContainer>
1437 static PointelRange
1439 (
1441 const Dimension k )
1442 {
1443 Cell2Index c2i;
1444 return getCellRange( c2i, surface, k );
1445 }
1446
1467 template <typename TDigitalSurfaceContainer>
1468 static PointelRange
1470 ( Cell2Index& c2i,
1472 {
1473 PointelRange result;
1474 result.reserve( surface->size() );
1475 const KSpace& K = refKSpace( surface );
1476 Idx n = 0;
1477 for ( auto&& surfel : *surface )
1478 {
1479 CellRange primal_vtcs = getPointelRange( K, surfel );
1480 for ( auto&& primal_vtx : primal_vtcs )
1481 {
1482 if ( ! c2i.count( primal_vtx ) )
1483 {
1484 result.push_back( primal_vtx );
1485 c2i[ primal_vtx ] = n++;
1486 }
1487 }
1488 }
1489 return result;
1490 }
1491
1508 template <typename TDigitalSurfaceContainer>
1509 static PointelRange
1516
1525 static PointelRange
1527 ( const KSpace& K, const SCell& surfel )
1528 {
1529 return KSpace::dimension == 3
1530 ? getPrimalVertices( K, surfel, true )
1531 : getPrimalVertices( K, surfel );
1532 }
1533
1545 template <typename TDigitalSurfaceContainer>
1546 static SurfelRange
1549 const Parameters& params = parametersDigitalSurface() )
1550 {
1551 return getSurfelRange( surface, *( surface->begin() ), params );
1552 }
1553
1568 template <typename TDigitalSurfaceContainer>
1569 static SurfelRange
1572 const Surfel& start_surfel,
1573 const Parameters& params = parametersDigitalSurface() )
1574 {
1575 typedef ::DGtal::DigitalSurface<TDigitalSurfaceContainer> AnyDigitalSurface;
1576 SurfelRange result;
1577 std::string traversal = params[ "surfaceTraversal" ].as<std::string>();
1578 if ( traversal == "DepthFirst" )
1579 {
1581 typedef GraphVisitorRange< Visitor > VisitorRange;
1582 VisitorRange range( new Visitor( *surface, start_surfel ) );
1583 std::for_each( range.begin(), range.end(),
1584 [&result] ( Surfel s ) { result.push_back( s ); } );
1585 }
1586 else if ( traversal == "BreadthFirst" )
1587 {
1589 typedef GraphVisitorRange< Visitor > VisitorRange;
1590 VisitorRange range( new Visitor( *surface, start_surfel ) );
1591 std::for_each( range.begin(), range.end(),
1592 [&result] ( Surfel s ) { result.push_back( s ); } );
1593 }
1594 else
1595 {
1596 std::for_each( surface->begin(), surface->end(),
1597 [&result] ( Surfel s ) { result.push_back( s ); } );
1598 }
1599 return result;
1600 }
1601
1611 static IdxSurfelRange
1614 const Parameters& params = parametersDigitalSurface() )
1615 {
1616 return getIdxSurfelRange( surface, (IdxSurfel) 0, params );
1617 }
1618
1631 static IdxSurfelRange
1634 const IdxSurfel& start_surfel,
1635 const Parameters& params = parametersDigitalSurface() )
1636 {
1637 IdxSurfelRange result;
1638 std::string traversal = params[ "surfaceTraversal" ].as<std::string>();
1639 if ( traversal == "DepthFirst" )
1640 {
1642 typedef GraphVisitorRange< Visitor > VisitorRange;
1643 VisitorRange range( new Visitor( *surface, start_surfel ) );
1644 std::for_each( range.begin(), range.end(),
1645 [&result] ( IdxSurfel s ) { result.push_back( s ); } );
1646 }
1647 else if ( traversal == "BreadthFirst" )
1648 {
1650 typedef GraphVisitorRange< Visitor > VisitorRange;
1651 VisitorRange range( new Visitor( *surface, start_surfel ) );
1652 std::for_each( range.begin(), range.end(),
1653 [&result] ( IdxSurfel s ) { result.push_back( s ); } );
1654 }
1655 else return surface->allVertices();
1656 return result;
1657 }
1658
1670 template <typename TDigitalSurfaceContainer,
1671 typename TCellEmbedder>
1672 static bool
1675 const TCellEmbedder& embedder,
1676 std::string off_file,
1677 const Color& face_color=DGtal::Color::None)
1678
1679 {
1680 BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1681
1682 std::ofstream output_off( off_file.c_str() );
1683 output_off << "OFF" << std::endl;
1684 output_off << "# Generated from DGtal::Shortcuts from the DGTal library" << std::endl;
1685 Cell2Index c2i;
1686 auto pointels = getPointelRange( c2i, digsurf );
1687 output_off << pointels.size() << " " << digsurf->size() << " " << 0 << " " << std::endl;
1688
1689
1690 // Number and output vertices.
1691 const KSpace& K = refKSpace( digsurf );
1692 for ( auto&& pointel : pointels )
1693 {
1694 RealPoint p = embedder( pointel );
1695 output_off << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1696 }
1697
1698 // Taking care of faces
1699 for ( auto&& surfel : *digsurf )
1700 {
1701 auto primal_vtcs = getPointelRange( K, surfel );
1702 output_off << primal_vtcs.size();
1703 {
1704 for ( auto&& primal_vtx : primal_vtcs )
1705 output_off << " " << (c2i[ primal_vtx ]);
1706 }
1707 if(face_color != DGtal::Color::None)
1708 {
1709 output_off << " ";
1710 output_off << face_color.r() << " " << face_color.g()
1711 << " " << face_color.b() << " " << face_color.a();
1712 }
1713 output_off << std::endl;
1714 }
1715 return output_off.good();
1716 }
1717
1718
1736 template <typename TDigitalSurfaceContainer,
1737 typename TCellEmbedder>
1738 static bool
1741 const TCellEmbedder& embedder,
1742 const RealVectors& normals,
1743 const Colors& diffuse_colors,
1744 std::string objfile,
1745 const Color& ambient_color = Color( 32, 32, 32 ),
1746 const Color& diffuse_color = Color( 200, 200, 255 ),
1747 const Color& specular_color = Color::White )
1748 {
1749 BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1750 std::string mtlfile;
1751 auto lastindex = objfile.find_last_of(".");
1752 if ( lastindex == std::string::npos )
1753 {
1754 mtlfile = objfile + ".mtl";
1755 objfile = objfile + ".obj";
1756 }
1757 else
1758 {
1759 mtlfile = objfile.substr(0, lastindex) + ".mtl";
1760 }
1761
1762 std::ofstream output_obj( objfile.c_str() );
1763 output_obj << "# OBJ format" << std::endl;
1764 output_obj << "# DGtal::MeshHelpers::exportOBJwithFaceNormalAndColor" << std::endl;
1765 output_obj << "o anObject" << std::endl;
1766 //remove directory to write material
1767 auto indexpath = objfile.find_last_of("/");
1768 output_obj << "mtllib " << mtlfile.substr(indexpath+1) << std::endl;
1769 std::ofstream output_mtl( mtlfile.c_str() );
1770 output_mtl << "# MTL format"<< std::endl;
1771 output_mtl << "# generated from MeshWriter from the DGTal library"<< std::endl;
1772 // Number and output vertices.
1773 const KSpace& K = refKSpace( digsurf );
1774 Cell2Index c2i;
1775 auto pointels = getPointelRange( c2i, digsurf );
1776 for ( auto&& pointel : pointels )
1777 {
1778 RealPoint p = embedder( pointel );
1779 output_obj << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1780 }
1781 // Taking care of normals
1782 Idx nbfaces = digsurf->size();
1783 bool has_normals = ( nbfaces == normals.size() );
1784 if ( has_normals )
1785 {
1786 for ( Idx f = 0; f < nbfaces; ++f )
1787 {
1788 const auto& p = normals[ f ];
1789 output_obj << "vn " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
1790 }
1791 }
1792 // Taking care of materials
1793 bool has_material = ( nbfaces == diffuse_colors.size() );
1794 Idx idxMaterial = 0;
1795 std::map<Color, Idx > mapMaterial;
1796 if ( has_material )
1797 {
1798 for ( Idx f = 0; f < nbfaces; ++f )
1799 {
1800 Color c = diffuse_colors[ f ];
1801 if ( mapMaterial.count( c ) == 0 )
1802 {
1804 ( output_mtl, idxMaterial, ambient_color, c, specular_color );
1805 mapMaterial[ c ] = idxMaterial++;
1806 }
1807 }
1808 }
1809 else
1810 {
1812 ( output_mtl, idxMaterial, ambient_color, diffuse_color, specular_color );
1813 }
1814
1815 // Taking care of faces
1816 Idx f = 0;
1817 for ( auto&& surfel : *digsurf )
1818 {
1819 output_obj << "usemtl material_"
1820 << ( has_material ? mapMaterial[ diffuse_colors[ f ] ] : idxMaterial )
1821 << std::endl;
1822 output_obj << "f";
1823 auto primal_vtcs = getPointelRange( K, surfel );
1824 // The +1 in lines below is because indexing starts at 1 in OBJ file format.
1825 if ( has_normals )
1826 {
1827 for ( auto&& primal_vtx : primal_vtcs )
1828 output_obj << " " << (c2i[ primal_vtx ]+1) << "//" << (f+1);
1829 }
1830 else
1831 {
1832 for ( auto&& primal_vtx : primal_vtcs )
1833 output_obj << " " << (c2i[ primal_vtx ]+1);
1834 }
1835 output_obj << std::endl;
1836 f += 1;
1837 }
1838 output_mtl.close();
1839 return output_obj.good();
1840 }
1841
1857 template <typename TDigitalSurfaceContainer>
1858 static bool
1861 const RealVectors& normals,
1862 const Colors& diffuse_colors,
1863 std::string objfile,
1864 const Color& ambient_color = Color( 32, 32, 32 ),
1865 const Color& diffuse_color = Color( 200, 200, 255 ),
1866 const Color& specular_color = Color::White )
1867 {
1868 auto embedder = getCellEmbedder( digsurf );
1869 return saveOBJ( digsurf, embedder, normals, diffuse_colors, objfile,
1870 ambient_color, diffuse_color, specular_color );
1871 }
1872
1886 template <typename TDigitalSurfaceContainer>
1887 static bool
1890 std::string off_file,
1891 const Color& face_color = Color( 32, 32, 32 ))
1892 {
1893 auto embedder = getCellEmbedder( digsurf );
1894 return saveOFF( digsurf, embedder, off_file, face_color);
1895 }
1896
1908 template <typename TDigitalSurfaceContainer>
1909 static bool
1912 std::string objfile,
1913 const Color& ambient_color = Color( 32, 32, 32 ),
1914 const Color& diffuse_color = Color( 200, 200, 255 ),
1915 const Color& specular_color = Color::White )
1916 {
1917 auto embedder = getCellEmbedder( digsurf );
1918 return saveOBJ( digsurf, embedder, RealVectors(), Colors(), objfile,
1919 ambient_color, diffuse_color, specular_color );
1920 }
1921
1922
1938 static bool
1940 ( const RealPoints& positions,
1941 const RealVectors& vf,
1942 double thickness,
1943 const Colors& diffuse_colors,
1944 std::string objfile,
1945 const Color& ambient_color = Color( 32, 32, 32 ),
1946 const Color& diffuse_color = Color( 200, 200, 255 ),
1947 const Color& specular_color = Color::White )
1948 {
1949 BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
1950 std::string mtlfile;
1951 auto lastindex = objfile.find_last_of(".");
1952 if ( lastindex == std::string::npos )
1953 {
1954 mtlfile = objfile + ".mtl";
1955 objfile = objfile + ".obj";
1956 }
1957 else
1958 {
1959 mtlfile = objfile.substr(0, lastindex) + ".mtl";
1960 }
1961 std::ofstream output_obj( objfile.c_str() );
1962 output_obj << "# OBJ format" << std::endl;
1963 output_obj << "# DGtal::saveOBJ" << std::endl;
1964 output_obj << "o vectors" << std::endl;
1965 output_obj << "mtllib " << mtlfile << std::endl;
1966 std::ofstream output_mtl( mtlfile.c_str() );
1967 output_mtl << "# MTL format"<< std::endl;
1968 output_mtl << "# generated from MeshWriter from the DGTal library"<< std::endl;
1969 // Output vertices
1970 auto n = std::min( positions.size(), vf.size() );
1971 for ( unsigned int i = 0; i < n; ++i )
1972 {
1973 RealPoint p0 = positions[ i ];
1974 RealPoint p1 = p0 + vf[ i ];
1975 RealVector v = vf[ i ];
1976 RealVector absv = RealVector( fabs( v[ 0 ] ), fabs( v[ 1 ] ), fabs( v[ 2 ] ) );
1977 auto mc = std::max_element( absv.begin(), absv.end() ) - absv.begin();
1978 RealVector b =
1979 mc == 2 ? RealVector( 1, 0, 0 ) :
1980 mc == 1 ? RealVector( 0, 0, 1 ) : RealVector( 0, 1, 0 );
1981 RealVector e0 = v.crossProduct( b ).getNormalized();
1982 RealVector e1 = v.crossProduct( e0 ).getNormalized();
1983 RealPoint t[4] = { thickness * e0, thickness * e1,
1984 -thickness * e0, -thickness * e1 };
1985 for ( unsigned int j = 0; j < 4; ++j ) {
1986 RealPoint pt0 = p0 + t[ j ];
1987 RealPoint pt1 = p1 + t[ j ];
1988 output_obj << "v " << pt0[ 0 ] << " " << pt0[ 1 ] << " " << pt0[ 2 ]
1989 << std::endl;
1990 output_obj << "v " << pt1[ 0 ] << " " << pt1[ 1 ] << " " << pt1[ 2 ]
1991 << std::endl;
1992 }
1993 }
1994 // Simplify materials (very useful for blender).
1995 std::map<Color,Idx> map_colors;
1996 {
1997 Idx j = 0;
1998 for ( auto && c : diffuse_colors )
1999 if ( ! map_colors.count( c ) )
2000 map_colors[ c ] = j++;
2001 }
2002
2003 // Output materials
2004 bool has_material = ! diffuse_colors.empty();
2005 if ( has_material )
2006 for ( auto&& pair : map_colors )
2008 ( output_mtl, pair.second, ambient_color, pair.first, specular_color);
2009 else
2011 ( output_mtl, 0, ambient_color, diffuse_color, specular_color );
2012 // Output faces
2013 for ( Idx i = 0; i < n; ++i )
2014 {
2015 output_obj << "usemtl material_" // << ( has_material ? i : 0 )
2016 << ( has_material ? map_colors[ diffuse_colors[ i ] ] : 0 )
2017 << std::endl;
2018 Idx b = 8*i+1;
2019 for ( Idx j = 0; j < 8; j += 2 )
2020 output_obj << "f " << (b+j) << " " << (b+j+1)
2021 << " " << (b+(j+3)%8) << " " << (b+(j+2)%8) << std::endl;
2022 output_obj << "f " << b << " " << (b+2)
2023 << " " << (b+4) << " " << (b+6) << std::endl;
2024 output_obj << "f " << (b+1) << " " << (b+7)
2025 << " " << (b+5) << " " << (b+3) << std::endl;
2026 }
2027 output_mtl.close();
2028 return output_obj.good();
2029 }
2030
2031 // ----------------------- Mesh services ------------------------------
2032 public:
2033
2038 {
2039 return Parameters
2040 ( "faceSubdivision", "Centroid" );
2041 }
2042
2056 {
2057 auto pTriSurf = CountedPtr<TriangulatedSurface>
2058 ( new TriangulatedSurface ); // acquired
2059 bool ok = MeshHelpers::mesh2TriangulatedSurface( *aMesh, *pTriSurf );
2060 return ok ? pTriSurf : CountedPtr< TriangulatedSurface >( nullptr );
2061 }
2062
2071 static CountedPtr< Mesh >
2073 const Color& aColor = Color::White )
2074 {
2075 auto pMesh = CountedPtr<Mesh>( new Mesh( aColor ) ); // acquired
2076 MeshHelpers::triangulatedSurface2Mesh( *triSurf, *pMesh );
2077 return pMesh;
2078 }
2079
2088 static CountedPtr< Mesh >
2090 const Color& aColor = Color::White )
2091 {
2092 auto pMesh = CountedPtr<Mesh>( new Mesh( aColor ) ); // acquired
2093 MeshHelpers::polygonalSurface2Mesh( *polySurf, *pMesh );
2094 return pMesh;
2095 }
2096
2103 template < typename TContainer >
2107 {
2108 auto embedder = getCellEmbedder( aSurface );
2109 auto pTriSurf = CountedPtr<TriangulatedSurface>
2110 ( new TriangulatedSurface ); // acquired
2112 ( *aSurface, embedder, *pTriSurf, s2i );
2113 return pTriSurf;
2114 }
2115
2121 template < typename TContainer >
2124 {
2125 Surfel2Index s2i;
2126 return makeTriangulatedSurface( s2i, aSurface );
2127 }
2128
2148 const Parameters& params = parametersMesh() )
2149 {
2150 std::string faceSubdivision = params[ "faceSubdivision" ].as<std::string>();
2151 bool centroid = ( faceSubdivision == "Centroid" );
2152 auto pTriSurf = CountedPtr<TriangulatedSurface>
2153 ( new TriangulatedSurface ); // acquired
2154 MeshHelpers::polygonalSurface2TriangulatedSurface( *polySurf, *pTriSurf, centroid );
2155 return pTriSurf;
2156 }
2157
2168 {
2169 auto pPolySurf = CountedPtr<PolygonalSurface>
2170 ( new PolygonalSurface ); // acquired
2171 bool ok = MeshHelpers::mesh2PolygonalSurface( *aMesh, *pPolySurf );
2172 return ok ? pPolySurf : CountedPtr< PolygonalSurface >( nullptr );
2173 }
2174
2190 const Parameters& params =
2194 {
2195 auto K = getKSpace( gray_scale_image );
2196 auto bimage = makeBinaryImage( gray_scale_image, params );
2197 auto digSurf = makeDigitalSurface( bimage, K, params );
2198 RealVector gh = { params[ "gridsizex" ].as<double>(),
2199 params[ "gridsizey" ].as<double>(),
2200 params[ "gridsizez" ].as<double>() };
2201 double threshold = params[ "thresholdMin" ].as<double>() + 0.5;
2202 typedef RegularPointEmbedder<Space> PointEmbedder;
2204 < KSpace, GrayScaleImage, PointEmbedder > ImageCellEmbedder;
2205 PointEmbedder pembedder;
2206 pembedder.init( gh );
2207 ImageCellEmbedder cembedder;
2208 cembedder.init( K, *gray_scale_image, pembedder, threshold );
2209 auto pPolySurf = CountedPtr<PolygonalSurface>
2210 ( new PolygonalSurface ); // acquired
2211 Surfel2Index s2i;
2213 ( *digSurf, cembedder, *pPolySurf, s2i );
2214 return pPolySurf;
2215 }
2216
2233 const Parameters& params =
2237 {
2238 auto K = getKSpace( gray_scale_image );
2239 auto bimage = makeBinaryImage( gray_scale_image, params );
2240 auto digSurf = makeDigitalSurface( bimage, K, params );
2241 RealVector gh = { params[ "gridsizex" ].as<double>(),
2242 params[ "gridsizey" ].as<double>(),
2243 params[ "gridsizez" ].as<double>() };
2244 double threshold = params[ "thresholdMin" ].as<double>() + 0.5;
2245 typedef RegularPointEmbedder<Space> PointEmbedder;
2247 < KSpace, GrayScaleImage, PointEmbedder > ImageCellEmbedder;
2248 PointEmbedder pembedder;
2249 pembedder.init( gh );
2250 ImageCellEmbedder cembedder;
2251 cembedder.init( K, *gray_scale_image, pembedder, threshold );
2252 auto pPolySurf = CountedPtr<TriangulatedSurface>
2253 ( new TriangulatedSurface ); // acquired
2254 Surfel2Index s2i;
2256 ( *digSurf, cembedder, *pPolySurf, s2i );
2257 return pPolySurf;
2258 }
2259
2267 template < typename TContainer >
2271 {
2272 BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2273 auto embedder = getCellEmbedder( aSurface );
2274 auto pPolySurf = CountedPtr<PolygonalSurface>
2275 ( new PolygonalSurface ); // acquired
2277 ( *aSurface, embedder, *pPolySurf, s2i );
2278 return pPolySurf;
2279 }
2280
2287 template < typename TContainer >
2290 {
2291 Surfel2Index s2i;
2292 return makeDualPolygonalSurface( s2i, aSurface );
2293 }
2294
2301 template < typename TContainer >
2305 {
2306 BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2307 auto pPolySurf = CountedPtr<PolygonalSurface>
2308 ( new PolygonalSurface( aSurface->heds(),
2309 aSurface->positions().storage() ) );
2310 return pPolySurf;
2311 }
2312
2320 template < typename TContainer >
2324 {
2325 BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2326 auto embedder = getCellEmbedder( aSurface );
2327 auto pPolySurf = CountedPtr<PolygonalSurface>
2328 ( new PolygonalSurface ); // acquired
2330 ( *aSurface, embedder, *pPolySurf, c2i );
2331 return ok ? pPolySurf : CountedPtr< PolygonalSurface >( nullptr );
2332 }
2333
2340 template < typename TContainer >
2343 {
2344 Cell2Index c2i;
2345 return makePrimalPolygonalSurface( c2i, aSurface );
2346 }
2347
2354 template < typename TContainer >
2358 {
2359 auto dsurf = makeDigitalSurface( aSurface );
2360 Cell2Index c2i;
2361 return makePrimalPolygonalSurface( c2i, dsurf );
2362 }
2363
2371 template < typename TContainer >
2375 {
2376 BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2377 auto embedder = getCellEmbedder( aSurface );
2378 auto pPolySurf = CountedPtr<SurfaceMesh>( new SurfaceMesh ); // acquired
2379 bool ok = MeshHelpers::digitalSurface2PrimalSurfaceMesh( *aSurface, embedder, *pPolySurf, c2i );
2380 return ok ? pPolySurf : CountedPtr< SurfaceMesh >( nullptr );
2381 }
2382
2389 template < typename TContainer >
2392 {
2393 Cell2Index c2i;
2394 return makePrimalSurfaceMesh( c2i, aSurface );
2395 }
2396
2403 template < typename TContainer >
2406 {
2407 auto dsurf = makeDigitalSurface( aSurface );
2408 Cell2Index c2i;
2409 return makePrimalSurfaceMesh( c2i, dsurf );
2410 }
2411
2417 makeSurfaceMesh(const std::string& path)
2418 {
2419 std::ifstream file(path);
2420 if (file.is_open())
2421 {
2422 auto surf = CountedPtr<SurfaceMesh>( new SurfaceMesh );
2424
2425 return ok ? surf : CountedPtr<SurfaceMesh>( nullptr );
2426 }
2427
2428 return CountedPtr<SurfaceMesh>( nullptr );
2429 }
2430
2431
2439 template <typename TPoint, typename TVector>
2440 static bool
2443 const std::string& objfile )
2444 {
2445 std::ofstream output( objfile.c_str() );
2446 bool ok = MeshHelpers::exportOBJ( output, *surf );
2447 output.close();
2448 return ok;
2449 }
2450
2457 template <typename TPoint>
2458 static bool
2461 const std::string& objfile )
2462 {
2463 std::ofstream output( objfile.c_str() );
2464 bool ok = MeshHelpers::exportOBJ( output, *polysurf );
2465 output.close();
2466 return ok;
2467 }
2468
2477 template <typename TPoint>
2478 static bool
2480 std::string off_file,
2481 const Color& face_color = DGtal::Color::None)
2482
2483 {
2486 std::ofstream output( off_file.c_str() );
2487 for (unsigned int i=0; i< m.nbFaces(); i++)
2488 {
2489 m.setFaceColor(i, face_color);
2490 }
2491 bool ok = MeshWriter< TPoint >::export2OFF( output, m, true );
2492 output.close();
2493 return ok;
2494 }
2495
2502 template <typename TPoint>
2503 static bool
2506 const std::string& objfile )
2507 {
2508 std::ofstream output( objfile.c_str() );
2509 bool ok = MeshHelpers::exportOBJ( output, *trisurf );
2510 output.close();
2511 return ok;
2512 }
2513
2526 template <typename TPoint>
2527 static bool
2530 const RealVectors& normals,
2531 const Colors& diffuse_colors,
2532 std::string objfile,
2533 const Color& ambient_color = Color( 32, 32, 32 ),
2534 const Color& diffuse_color = Color( 200, 200, 255 ),
2535 const Color& specular_color = Color::White )
2536 {
2537 std::string mtlfile;
2538 auto lastindex = objfile.find_last_of(".");
2539 if ( lastindex == std::string::npos )
2540 {
2541 mtlfile = objfile + ".mtl";
2542 objfile = objfile + ".obj";
2543 }
2544 else
2545 {
2546 mtlfile = objfile.substr(0, lastindex) + ".mtl";
2547 }
2548 std::ofstream output( objfile.c_str() );
2550 ( output, mtlfile, *polysurf, normals, diffuse_colors,
2551 ambient_color, diffuse_color, specular_color );
2552 output.close();
2553 return ok;
2554 }
2555
2568 template <typename TPoint>
2569 static bool
2572 const RealVectors& normals,
2573 const Colors& diffuse_colors,
2574 std::string objfile,
2575 const Color& ambient_color = Color( 32, 32, 32 ),
2576 const Color& diffuse_color = Color( 200, 200, 255 ),
2577 const Color& specular_color = Color::White )
2578 {
2579 std::string mtlfile;
2580 auto lastindex = objfile.find_last_of(".");
2581 if ( lastindex == std::string::npos )
2582 {
2583 mtlfile = objfile + ".mtl";
2584 objfile = objfile + ".obj";
2585 }
2586 else
2587 {
2588 mtlfile = objfile.substr(0, lastindex) + ".mtl";
2589 }
2590 std::ofstream output( objfile.c_str() );
2592 ( output, mtlfile, *trisurf, normals, diffuse_colors,
2593 ambient_color, diffuse_color, specular_color );
2594 output.close();
2595 return ok;
2596 }
2597
2611 template <typename TPoint, typename TVector>
2612 static bool
2615 const RealVectors& normals,
2616 const Colors& diffuse_colors,
2617 std::string objfile,
2618 const Color& ambient_color = Color( 32, 32, 32 ),
2619 const Color& diffuse_color = Color( 200, 200, 255 ),
2620 const Color& specular_color = Color::White )
2621 {
2622 std::string mtlfile;
2623 auto lastindex = objfile.find_last_of(".");
2624 if ( lastindex == std::string::npos )
2625 {
2626 mtlfile = objfile + ".mtl";
2627 objfile = objfile + ".obj";
2628 }
2629 else
2630 {
2631 mtlfile = objfile.substr(0, lastindex) + ".mtl";
2632 }
2633 std::ofstream output( objfile.c_str() );
2635 ( output, mtlfile, *surf, normals, diffuse_colors,
2636 ambient_color, diffuse_color, specular_color );
2637 output.close();
2638 return ok;
2639 }
2640
2649 template <typename TPoint>
2650 static bool
2652 std::string off_file,
2653 const Color& face_color = DGtal::Color::None)
2654
2655 {
2658 std::ofstream output( off_file.c_str() );
2659 for (unsigned int i=0; i< m.nbFaces(); i++)
2660 {
2661 m.setFaceColor(i, face_color);
2662 }
2663 bool ok = MeshWriter< TPoint >::export2OFF( output, m, true );
2664 output.close();
2665 return ok;
2666 }
2667
2668
2669 // ------------------------------ utilities ------------------------------
2670 public:
2671
2677 {
2678 return Parameters
2679 ( "colormap", "Custom" )
2680 ( "zero-tic", 0.0 );
2681 }
2682
2699 template <typename TValue>
2700 static IdxRange
2701 getRangeMatch( const std::vector< TValue >& s1, const std::vector< TValue >& s2,
2702 bool perfect = false )
2703 {
2704 if ( perfect && ( s1.size() != s2.size() ) ) return IdxRange();
2705 std::map<TValue, Idx> M;
2706 Idx idx = 0;
2707 for ( auto val : s2 ) M[ val ] = idx++;
2708 IdxRange V( s1.size() );
2709 idx = 0;
2710 for ( auto val : s1 )
2711 {
2712 auto it = M.find( val );
2713 if ( it != M.end() ) V[ idx++ ] = it->second;
2714 else
2715 {
2716 if ( perfect ) return IdxRange();
2717 V[ idx++ ] = s2.size();
2718 }
2719 }
2720 return V;
2721 }
2722
2734 template <typename TValue>
2735 static std::vector< TValue >
2736 getMatchedRange( const std::vector< TValue >& range, const IdxRange& match )
2737 {
2738 std::vector< TValue > result( match.size() );
2739 for ( Idx i = 0; i < result.size(); i++ )
2740 result[ i ] = range[ match[ i ] ];
2741 return result;
2742 }
2743
2744
2750 static ColorMap
2752 Scalar max,
2753 const Parameters& params = parametersUtilities() )
2754 {
2755 std::string cmap = params[ "colormap" ].as<std::string>();
2756 if ( cmap == "Cool" ) return ColorMap( min, max, CMAP_COOL );
2757 else if ( cmap == "Copper" ) return ColorMap( min, max, CMAP_COPPER );
2758 else if ( cmap == "Hot" ) return ColorMap( min, max, CMAP_HOT );
2759 else if ( cmap == "Jet" ) return ColorMap( min, max, CMAP_JET );
2760 else if ( cmap == "Spring" ) return ColorMap( min, max, CMAP_SPRING );
2761 else if ( cmap == "Summer" ) return ColorMap( min, max, CMAP_SUMMER );
2762 else if ( cmap == "Autumn" ) return ColorMap( min, max, CMAP_AUTUMN );
2763 else if ( cmap == "Winter" ) return ColorMap( min, max, CMAP_WINTER );
2764 else if ( cmap == "Error" )
2765 {
2766 ColorMap gradcmap( min, max );
2767 gradcmap.addColor( Color( 255, 255, 255 ) );
2768 gradcmap.addColor( Color( 255, 0, 0 ) );
2769 gradcmap.addColor( Color( 0, 0, 0 ) );
2770 return gradcmap;
2771 }
2772 // Custom colormap
2773 ColorMap gradcmap( min, max );
2774 gradcmap.addColor( Color( 0, 0, 255 ) );
2775 gradcmap.addColor( Color( 0, 255, 255 ) );
2776 gradcmap.addColor( Color( 255, 255, 255 ) );
2777 gradcmap.addColor( Color( 255, 255, 0 ) );
2778 gradcmap.addColor( Color( 255, 0, 0 ) );
2779 return gradcmap;
2780 }
2781
2788 static ZeroTickedColorMap
2790 Scalar max,
2791 const Parameters& params = parametersUtilities() )
2792 {
2793 auto cmap = getColorMap( min, max, params );
2794 auto ztic = params[ "zero-tic" ].as<double>();
2795 ZeroTickedColorMap ztic_cmap( cmap, Color::Black );
2796 if ( ztic <= 0.0 ) return ztic_cmap;
2797 if ( min <= 0.0 && 0.0 <= max )
2798 ztic_cmap.addTick( 0.0, ztic );
2799 ztic_cmap.finalize();
2800 return ztic_cmap;
2801 }
2802
2803
2812 template <typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2813 static bool
2815 ( std::ostream& output,
2816 const SurfelRange& surfels,
2817 const TCellEmbedder& embedder )
2818 {
2819 typedef unsigned long Size;
2820 BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
2822 const KSpace& K = embedder.space();
2823 // Number and output vertices.
2824 std::map< Cell, Size > vtx_numbering;
2825 Size n = 1; // OBJ vertex numbering start at 1
2826 for ( auto&& s : surfels )
2827 {
2828 auto primal_vtcs = getPointelRange( K, s, true );
2829 for ( auto&& primal_vtx : primal_vtcs )
2830 {
2831 if ( ! vtx_numbering.count( primal_vtx ) )
2832 {
2833 vtx_numbering[ primal_vtx ] = n++;
2834 // Output vertex positions
2835 RealPoint p = embedder( primal_vtx );
2836 output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
2837 }
2838 }
2839 }
2840 // Outputs all faces
2841 for ( auto&& s : surfels )
2842 {
2843 output << "f";
2844 auto primal_vtcs = getPointelRange( K, s, true );
2845 for ( auto&& primal_vtx : primal_vtcs )
2846 output << " " << vtx_numbering[ primal_vtx ];
2847 output << std::endl;
2848 }
2849 return output.good();
2850 }
2851
2863 template <typename TAnyDigitalSurface>
2864 static bool
2866 ( std::ostream& output,
2868 {
2869 auto embedder = getCellEmbedder( surface );
2870 return outputPrimalDigitalSurfaceAsObj( output, surface, embedder );
2871 }
2872
2890 template < typename TAnyDigitalSurface,
2891 typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2892 static bool
2894 ( std::ostream& output,
2896 const TCellEmbedder& embedder )
2897 {
2898 auto surfels = getSurfelRange( surface, Parameters( "Traversal", "Default" ) );
2899 return outputSurfelsAsObj( output, surfels, embedder );
2900 }
2901
2910 static bool
2912 ( std::ostream& output,
2914 {
2915 auto embedder = getCellEmbedder( surface );
2916 return outputPrimalIdxDigitalSurfaceAsObj( output, surface, embedder );
2917 }
2918
2932 template <typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2933 static bool
2935 ( std::ostream& output,
2937 const TCellEmbedder& embedder )
2938 {
2939 auto idxsurfels = getIdxSurfelRange( surface, Parameters( "Traversal", "Default" ) );
2940 auto surfelmap = surface->surfels();
2941 SurfelRange surfels;
2942 for ( auto&& idx : idxsurfels )
2943 surfels.push_back( surfelmap[ idx ] );
2944 return outputSurfelsAsObj( output, surfels, embedder );
2945 }
2946
2963 template <typename TDigitalSurfaceContainer>
2964 static bool
2966 ( std::ostream& output,
2968 const Parameters& params = parametersMesh() )
2969 {
2970 auto embedder = getCellEmbedder( surface );
2971 return outputDualDigitalSurfaceAsObj( output, surface, embedder, params );
2972 }
2973
2996 template < typename TDigitalSurfaceContainer,
2997 typename TCellEmbedder = CanonicCellEmbedder< KSpace > >
2998 static bool
3000 ( std::ostream& output,
3002 const TCellEmbedder& embedder,
3003 const Parameters& params = parametersMesh() )
3004 {
3005 typedef unsigned long Size;
3006 BOOST_STATIC_ASSERT (( KSpace::dimension == 3 ));
3008 std::string dualFaceSubdivision = params[ "faceSubdivision" ].as<std::string>();
3009 const int subdivide
3010 = dualFaceSubdivision == "Naive" ? 1
3011 : dualFaceSubdivision == "Centroid" ? 2
3012 : 0;
3013 const KSpace& K = embedder.space();
3014 // Number and ouput vertices.
3015 std::map< Vertex, Size > vtx_numbering;
3016 std::map< Face, Size > sub_numbering;
3017 Size n = 1; // OBJ vertex numbering start at 1
3018 for ( auto && s : *surface )
3019 {
3020 if ( ! vtx_numbering.count( s ) )
3021 {
3022 vtx_numbering[ s ] = n++;
3023 // Output vertex positions
3024 RealPoint p = embedder( K.unsigns( s ) );
3025 output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
3026 }
3027 }
3028 auto faces = surface->allClosedFaces();
3029 // Prepare centroids if necessary
3030 if ( subdivide == 2 )
3031 {
3032 for ( auto&& f : faces )
3033 {
3034 auto vtcs = surface->verticesAroundFace( f );
3035 Size nv = vtcs.size();
3036 if ( nv > 3 )
3037 {
3038 sub_numbering[ f ] = n++;
3040 for ( auto&& s : vtcs ) p += embedder( K.unsigns( s ) );
3041 p /= nv;
3042 output << "v " << p[ 0 ] << " " << p[ 1 ] << " " << p[ 2 ] << std::endl;
3043 }
3044 }
3045 }
3046 // Outputs closed faces.
3047 if ( subdivide == 0 )
3048 { // No subdivision
3049 for ( auto&& f : faces )
3050 {
3051 output << "f";
3052 auto vtcs = surface->verticesAroundFace( f );
3053 std::reverse( vtcs.begin(), vtcs.end() );
3054 for ( auto&& s : vtcs )
3055 output << " " << vtx_numbering[ s ];
3056 output << std::endl;
3057 }
3058 }
3059 else if ( subdivide == 1 )
3060 { // naive subdivision
3061 for ( auto&& f : faces )
3062 {
3063 auto vtcs = surface->verticesAroundFace( f );
3064 Size nv = vtcs.size();
3065 for ( Size i = 1; i < nv - 1; ++i )
3066 output << "f " << vtx_numbering[ vtcs[ 0 ] ]
3067 << " " << vtx_numbering[ vtcs[ i+1 ] ]
3068 << " " << vtx_numbering[ vtcs[ i ] ] << std::endl;
3069 }
3070 }
3071 else if ( subdivide == 2 )
3072 { // centroid subdivision
3073 for ( auto&& f : faces )
3074 {
3075 auto vtcs = surface->verticesAroundFace( f );
3076 Size nv = vtcs.size();
3077 if ( nv == 3 )
3078 output << "f " << vtx_numbering[ vtcs[ 0 ] ]
3079 << " " << vtx_numbering[ vtcs[ 2 ] ]
3080 << " " << vtx_numbering[ vtcs[ 1 ] ] << std::endl;
3081 else {
3082 Size c = sub_numbering[ f ];
3083 for ( Size i = 0; i < nv; ++i )
3084 {
3085 output << "f " << c
3086 << " " << vtx_numbering[ vtcs[ (i+1)%nv ] ]
3087 << " " << vtx_numbering[ vtcs[ i ] ] << std::endl;
3088 }
3089 }
3090 }
3091 }
3092 return output.good();
3093 }
3094
3095
3096 // -------------------- map I/O services ------------------------------------------
3097 public:
3098 struct CellWriter {
3099 void operator()( std::ostream& output, const KSpace& K, const Cell & cell )
3100 {
3101 for ( Dimension d = 0; d < KSpace::dimension; ++d )
3102 output << " " << K.sKCoord( cell, d );
3103 }
3104 };
3105 struct CellReader {
3106 Cell operator()( std::istream& input, const KSpace& K )
3107 {
3108 Point kp;
3109 for ( Dimension d = 0; d < KSpace::dimension; ++d )
3110 input >> kp[ d ];
3111 return K.uCell( kp );
3112 }
3113 };
3115 void operator()( std::ostream& output, const KSpace& K, const SCell & scell )
3116 {
3117 CellWriter::operator()( output, K, K.unsigns( scell ) );
3118 output << " " << K.sSign( scell );
3119 }
3120 };
3122 SCell operator()( std::istream& input, const KSpace& K )
3123 {
3124 Point kp;
3125 typename KSpace::Sign s;
3126 for ( Dimension d = 0; d < KSpace::dimension; ++d )
3127 input >> kp[ d ];
3128 input >> s;
3129 return K.sCell( kp, s );
3130 }
3131 };
3132
3133 template <typename Value>
3135 void operator()( std::ostream& output, const Value& v )
3136 {
3137 output << " " << v;
3138 }
3139 void operator()( std::ostream& output, const std::vector<Value>& vv )
3140 {
3141 for ( auto&& v : vv ) output << " " << v;
3142 }
3143 };
3144
3145 template <typename Value>
3147 bool operator()( std::istream& input, Value& value )
3148 {
3149 std::string str;
3150 std::getline( input, str );
3151 // construct a stream from the string
3152 std::stringstream strstr(str);
3153 // use stream iterators to copy the stream to the vector as whitespace separated strings
3154 std::istream_iterator<std::string> it(strstr);
3155 std::istream_iterator<std::string> end;
3156 std::vector<std::string> results(it, end);
3157 std::stringstream sstr( results[ 0 ] );
3158 sstr >> value;
3159 return ( results.size() == 1 ) && input.good();
3160 }
3161
3162 bool operator()( std::istream& input, std::vector<Value>& values )
3163 {
3164 std::string str;
3165 std::getline( input, str );
3166 // construct a stream from the string
3167 std::stringstream strstr(str);
3168 // use stream iterators to copy the stream to the vector as whitespace separated strings
3169 std::istream_iterator<std::string> it(strstr);
3170 std::istream_iterator<std::string> end;
3171 std::vector<std::string> results(it, end);
3172 values.resize( results.size() );
3173 for ( unsigned int i = 0; i < results.size(); ++i ) {
3174 std::stringstream sstr( results[ i ] );
3175 sstr >> values[ i ];
3176 }
3177 return input.good();
3178 }
3179 };
3180
3181 // Outputs in \a output a map \a anyMap: SCell -> Value given the
3182 // appropriate value \a writer.
3183 //
3184 // @tparam TSCellMap any model of map SCell -> Value., e.g. std::map<SCell,double>
3185 // @tparam TValueWriter any model of value writer, e.g. ValueWriter<double>
3186 //
3187 // @param[out] output the output stream
3188 // @param[in] K the Khalimsky space where cells are defined.
3189 // @param[in] anyMap the map associated a value to signed cells.
3190 // @param[in] writer the writer that can write values on the ouput
3191 // stream, e.g. ValueWriter<double> to write double value or
3192 // vector<double> values.
3193 template <typename TSCellMap, typename TValueWriter>
3194 static
3196 ( std::ostream& output,
3197 const KSpace& K,
3198 const TSCellMap& anyMap,
3199 const TValueWriter& writer )
3200 {
3201 SCellWriter w;
3202 for ( auto&& v : anyMap )
3203 {
3204 w( output, K, v.first );
3205 writer( output, v.second );
3206 output << std::endl;
3207 }
3208 return output.good();
3209 }
3210
3211 // Outputs in \a output a map \a anyMap: SCell -> value given the
3212 // appropriate value \a writer.
3213 //
3214 // @tparam TCellMap any model of map Cell -> Value., e.g. std::map<Cell,double>
3215 // @tparam TValueWriter any model of value writer, e.g. ValueWriter<double>
3216 //
3217 // @param[out] output the output stream
3218 // @param[in] K the Khalimsky space where cells are defined.
3219 // @param[in] anyMap the map associated a value to signed cells.
3220 // @param[in] writer the writer that can write values on the ouput
3221 // stream, e.g. ValueWriter<double> to write double value or
3222 // vector<double> values.
3223 template <typename TCellMap, typename TValueWriter>
3224 static
3226 ( std::ostream& output,
3227 const KSpace& K,
3228 const TCellMap& anyMap,
3229 const TValueWriter& writer )
3230 {
3231 CellWriter w;
3232 for ( auto&& v : anyMap )
3233 {
3234 w( output, K, v.first );
3235 writer( output, v.second );
3236 output << std::endl;
3237 }
3238 return output.good();
3239 }
3240
3246 static
3247 CellRange getPrimalCells( const KSpace& K, const SCell& s, const Dimension k )
3248 {
3249 auto faces = K.uFaces( K.unsigns( s ) );
3250 CellRange primal_cells;
3251 for ( auto&& f : faces )
3252 {
3253 if ( K.uDim( f ) == k ) primal_cells.push_back( f );
3254 }
3255 return primal_cells;
3256 }
3257
3262 static
3264 {
3265 return getPrimalCells( K, s, 0 );
3266 }
3267
3274 static
3275 CellRange getPrimalVertices( const KSpace& K, const Surfel& s, bool ccw )
3276 {
3277 BOOST_STATIC_ASSERT(( KSpace::dimension == 3 ));
3278 CellRange vtcs = getPrimalVertices( K, s );
3279 std::swap( vtcs[ 2 ], vtcs[ 3 ] );
3280 auto orth_dir = K.sOrthDir( s );
3281 auto direct = K.sDirect( s, orth_dir ) ? ccw : ! ccw;
3282 Vector s0s1 = K.uCoords( vtcs[ 1 ] ) - K.uCoords( vtcs[ 0 ] );
3283 Vector s0s2 = K.uCoords( vtcs[ 2 ] ) - K.uCoords( vtcs[ 0 ] );
3284 Vector t = s0s1.crossProduct( s0s2 );
3285 if ( ( ( t[ orth_dir ] > 0.0 ) && direct )
3286 || ( ( t[ orth_dir ] < 0.0 ) && ! direct ) )
3287 std::reverse( vtcs.begin(), vtcs.end() );
3288 return vtcs;
3289 }
3290
3291
3292 // ----------------------- Standard services ------------------------------
3293 public:
3294
3298 Shortcuts() = delete;
3299
3303 ~Shortcuts() = delete;
3304
3309 Shortcuts ( const Shortcuts & other ) = delete;
3310
3315 Shortcuts ( Shortcuts && other ) = delete;
3316
3322 Shortcuts & operator= ( const Shortcuts & other ) = delete;
3323
3329 Shortcuts & operator= ( Shortcuts && other ) = delete;
3330
3331 // ----------------------- Interface --------------------------------------
3332 public:
3333
3338 void selfDisplay ( std::ostream & out ) const
3339 {
3340 out << "[Shortcuts]";
3341 }
3342
3347 bool isValid() const
3348 {
3349 return true;
3350 }
3351
3352 // ------------------------- Protected Datas ------------------------------
3353 protected:
3354
3355 // ------------------------- Private Datas --------------------------------
3356 private:
3357
3358 // ------------------------- Hidden services ------------------------------
3359 protected:
3360
3361 // ------------------------- Internals ------------------------------------
3362 private:
3363
3364 }; // end of class Shortcuts
3365
3366
3373 template <typename T>
3374 std::ostream&
3375 operator<< ( std::ostream & out, const Shortcuts<T> & object );
3376
3377} // namespace DGtal
3378
3379
3381// Includes inline functions.
3382
3383// //
3385
3386#endif // !defined Shortcuts_h
3387
3388#undef Shortcuts_RECURSES
3389#endif // else defined(Shortcuts_RECURSES)
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
Structure representing an RGB triple with alpha component.
Definition Color.h:77
static const Color None
Definition Color.h:421
static const Color Black
Definition Color.h:422
static const Color White
Definition Color.h:424
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition ConstAlias.h:187
Aim: Smart pointer based on reference counts.
Definition CountedPtr.h:80
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: Transforms a graph visitor into a single pass input range.
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: a cellular embedder for images. (default constructible, copy constructible, assignable)....
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Aim: From a point predicate (model of concepts::CPointPredicate), this class constructs another point...
const Point & lowerBound() const
Return the lower bound for digital points in this space.
const Point & upperBound() const
Return the upper bound for digital points in this space.
static const constexpr Dimension dimension
Aim: This class converts a string polynomial expression in a multivariate polynomial.
Iterator read(Polynomial &p, Iterator begin, Iterator end)
static bool exportOBJ(std::ostream &output, const TriangulatedSurface< Point > &trisurf)
static bool digitalSurface2PrimalSurfaceMesh(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, SurfaceMesh< typename CellEmbedder::Value, typename CellEmbedder::Value > &polysurf, CellMap &cellmap)
static bool digitalSurface2PrimalPolygonalSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, PolygonalSurface< typename CellEmbedder::Value > &polysurf, CellMap &cellmap)
static bool mesh2TriangulatedSurface(const Mesh< Point > &mesh, TriangulatedSurface< Point > &trisurf)
static void polygonalSurface2TriangulatedSurface(const PolygonalSurface< Point > &polysurf, TriangulatedSurface< Point > &trisurf, bool centroid=true)
static bool exportMTLNewMaterial(std::ostream &output_mtl, unsigned long idxMaterial, const Color &ambient_color, const Color &diffuse_color, const Color &specular_color)
static void polygonalSurface2Mesh(const PolygonalSurface< Point > &polysurf, Mesh< Point > &mesh)
static bool exportOBJwithFaceNormalAndColor(std::ostream &output_obj, const std::string &mtl_filename, const SurfaceMesh &surf, const std::vector< typename SurfaceMesh::RealPoint > &normals, const std::vector< Color > &diffuse_colors, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
static void digitalSurface2DualTriangulatedSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, TriangulatedSurface< typename CellEmbedder::Value > &trisurf, VertexMap &vertexmap)
static void digitalSurface2DualPolygonalSurface(const DigitalSurface< DigitalSurfaceContainer > &dsurf, const CellEmbedder &cembedder, PolygonalSurface< typename CellEmbedder::Value > &polysurf, VertexMap &vertexmap)
static void triangulatedSurface2Mesh(const TriangulatedSurface< Point > &trisurf, Mesh< Point > &mesh)
static bool mesh2PolygonalSurface(const Mesh< Point > &mesh, PolygonalSurface< Point > &polysurf)
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition Mesh.h:92
Size nbFaces() const
void setFaceColor(Index i, const DGtal::Color &aColor)
auto crossProduct(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::crossProduct(*this, v))
Cross product with a PointVector.
Aim: Represents a polygon mesh, i.e. a 2-dimensional combinatorial surface whose faces are (topologic...
Aim: A simple point embedder where grid steps are given for each axis. Note that the real point (0,...
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition Shortcuts.h:106
static Parameters parametersUtilities()
Definition Shortcuts.h:2676
GradientColorMap< Scalar > ColorMap
Definition Shortcuts.h:194
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< BinaryImage > bimage, Parameters params=parametersBinaryImage())
Definition Shortcuts.h:629
ImageContainerBySTLVector< Domain, bool > BinaryImage
Definition Shortcuts.h:142
static bool outputPrimalDigitalSurfaceAsObj(std::ostream &output, CountedPtr< TAnyDigitalSurface > surface, const TCellEmbedder &embedder)
Definition Shortcuts.h:2894
static bool saveOBJ(CountedPtr< ::DGtal::TriangulatedSurface< TPoint > > trisurf, const RealVectors &normals, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
Definition Shortcuts.h:2571
static CountedPtr< DoubleImage > makeDoubleImage(Domain aDomain)
Definition Shortcuts.h:931
LightDigitalSurface::ArcRange ArcRange
Definition Shortcuts.h:168
static KSpace getKSpace(CountedPtr< BinaryImage > bimage, Parameters params=parametersKSpace())
Definition Shortcuts.h:355
static std::map< std::string, std::string > getPolynomialList()
Definition Shortcuts.h:237
static Parameters parametersImplicitShape3D()
Definition Shortcuts.h:266
static Parameters parametersKSpace()
Definition Shortcuts.h:312
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2123
static CountedPtr< DoubleImage > makeDoubleImage(std::string input)
Definition Shortcuts.h:944
LightDigitalSurface::Surfel Surfel
Definition Shortcuts.h:162
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition Shortcuts.h:333
SetOfSurfels< KSpace, SurfelSet > ExplicitSurfaceContainer
Definition Shortcuts.h:157
LightDigitalSurface::Vertex Vertex
Definition Shortcuts.h:165
static KSpace getKSpace(Parameters params=parametersKSpace()|parametersDigitizedImplicitShape3D())
Definition Shortcuts.h:487
static bool saveOFF(CountedPtr< ::DGtal::PolygonalSurface< TPoint > > polysurf, std::string off_file, const Color &face_color=DGtal::Color::None)
Definition Shortcuts.h:2479
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition Shortcuts.h:524
std::map< Surfel, IdxSurfel > Surfel2Index
Definition Shortcuts.h:189
static bool outputCellMapAsCSV(std::ostream &output, const KSpace &K, const TCellMap &anyMap, const TValueWriter &writer)
Definition Shortcuts.h:3226
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< IdxDigitalSurface > idx_surface, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1241
static bool outputPrimalIdxDigitalSurfaceAsObj(std::ostream &output, CountedPtr< IdxDigitalSurface > surface)
Definition Shortcuts.h:2912
static CellRange getCellRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Dimension k)
Definition Shortcuts.h:1400
static CountedPtr< SurfaceMesh > makeSurfaceMesh(const std::string &path)
Definition Shortcuts.h:2417
Shortcuts(Shortcuts &&other)=delete
static bool saveOBJ(CountedPtr< ::DGtal::SurfaceMesh< TPoint, TVector > > surf, 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:2614
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Surfel &start_surfel, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1571
RealVector::Component Scalar
Definition Shortcuts.h:126
::DGtal::TriangulatedSurface< RealPoint > TriangulatedSurface
Definition Shortcuts.h:186
std::map< Cell, IdxVertex > Cell2Index
Definition Shortcuts.h:190
static bool outputDualDigitalSurfaceAsObj(std::ostream &output, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const TCellEmbedder &embedder, const Parameters &params=parametersMesh())
Definition Shortcuts.h:3000
static CountedPtr< PolygonalSurface > makePolygonalSurface(CountedPtr< Mesh > aMesh)
Definition Shortcuts.h:2167
ImageContainerBySTLVector< Domain, float > FloatImage
Definition Shortcuts.h:146
static bool saveGrayScaleImage(CountedPtr< GrayScaleImage > gray_scale_image, std::string output)
Definition Shortcuts.h:785
static PointelRange getPointelRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:1470
static bool saveOFF(CountedPtr< ::DGtal::TriangulatedSurface< TPoint > > trisurf, std::string off_file, const Color &face_color=DGtal::Color::None)
Definition Shortcuts.h:2651
::DGtal::SurfaceMesh< RealPoint, RealPoint > SurfaceMesh
Definition Shortcuts.h:188
static CellRange getPrimalVertices(const KSpace &K, const Surfel &s, bool ccw)
Definition Shortcuts.h:3275
static CellRange getPrimalCells(const KSpace &K, const SCell &s, const Dimension k)
Definition Shortcuts.h:3247
static KSpace getKSpace(CountedPtr< GrayScaleImage > gimage, Parameters params=parametersKSpace())
Definition Shortcuts.h:379
Shortcuts()=delete
std::vector< Color > Colors
Definition Shortcuts.h:193
static Parameters parametersMesh()
Definition Shortcuts.h:2037
static CountedPtr< Mesh > makeMesh(CountedPtr< TriangulatedSurface > triSurf, const Color &aColor=Color::White)
Definition Shortcuts.h:2072
~Shortcuts()=delete
static CountedPtr< FloatImage > makeFloatImage(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition Shortcuts.h:899
static bool saveOBJ(CountedPtr< ::DGtal::TriangulatedSurface< TPoint > > trisurf, const std::string &objfile)
Definition Shortcuts.h:2505
static std::vector< CountedPtr< LightDigitalSurface > > makeLightDigitalSurfaces(SurfelRange &surfel_reps, CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1150
static Parameters parametersDigitalSurface()
Definition Shortcuts.h:997
static CountedPtr< DoubleImage > makeDoubleImage(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition Shortcuts.h:965
ImplicitPolynomial3Shape< Space > ImplicitShape3D
Definition Shortcuts.h:138
Shortcuts & operator=(const Shortcuts &other)=delete
static CountedPtr< FloatImage > makeFloatImage(std::string input)
Definition Shortcuts.h:878
static KSpace getKSpace(CountedPtr< ::DGtal::IndexedDigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:409
LightDigitalSurface::Face Face
Definition Shortcuts.h:167
::DGtal::Mesh< RealPoint > Mesh
Definition Shortcuts.h:185
static std::vector< CountedPtr< LightDigitalSurface > > makeLightDigitalSurfaces(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1120
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< PolygonalSurface > polySurf, const Parameters &params=parametersMesh())
Definition Shortcuts.h:2147
static bool outputPrimalDigitalSurfaceAsObj(std::ostream &output, CountedPtr< TAnyDigitalSurface > surface)
Definition Shortcuts.h:2866
static bool saveOFF(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, std::string off_file, const Color &face_color=Color(32, 32, 32))
Definition Shortcuts.h:1889
LightImplicitDigitalSurface< KSpace, BinaryImage > LightSurfaceContainer
Definition Shortcuts.h:153
static CellRange getPrimalVertices(const KSpace &K, const SCell &s)
Definition Shortcuts.h:3263
static CountedPtr< GrayScaleImage > makeGrayScaleImage(Domain aDomain)
Definition Shortcuts.h:737
MPolynomial< Space::dimension, Scalar > ScalarPolynomial
Definition Shortcuts.h:135
static CountedPtr< FloatImage > makeFloatImage(Domain aDomain)
Definition Shortcuts.h:865
static CountedPtr< SurfaceMesh > makePrimalSurfaceMesh(CountedPtr< ::DGtal::IndexedDigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2405
static bool outputPrimalIdxDigitalSurfaceAsObj(std::ostream &output, CountedPtr< IdxDigitalSurface > surface, const TCellEmbedder &embedder)
Definition Shortcuts.h:2935
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1548
KSpace::SurfelSet SurfelSet
Definition Shortcuts.h:150
static CountedPtr< LightDigitalSurface > makeLightDigitalSurface(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1063
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(CountedPtr< ::DGtal::IndexedDigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2357
static CountedPtr< Mesh > makeMesh(CountedPtr< PolygonalSurface > polySurf, const Color &aColor=Color::White)
Definition Shortcuts.h:2089
static const KSpace & refKSpace(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:420
static CanonicSCellEmbedder< KSpace > getSCellEmbedder(const KSpace &K)
Definition Shortcuts.h:447
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1210
std::vector< Cell > CellRange
Definition Shortcuts.h:175
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< DigitizedImplicitShape3D > shape_digitization, Parameters params=parametersBinaryImage())
Definition Shortcuts.h:577
static KSpace getKSpace(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:398
static bool outputSurfelsAsObj(std::ostream &output, const SurfelRange &surfels, const TCellEmbedder &embedder)
Definition Shortcuts.h:2815
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2322
static IdxRange getRangeMatch(const std::vector< TValue > &s1, const std::vector< TValue > &s2, bool perfect=false)
Definition Shortcuts.h:2701
bool isValid() const
Definition Shortcuts.h:3347
ImageContainerBySTLVector< Domain, GrayScale > GrayScaleImage
Definition Shortcuts.h:144
static CanonicSCellEmbedder< KSpace > getSCellEmbedder(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:1023
::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface
Definition Shortcuts.h:159
std::vector< IdxVertex > IdxRange
Definition Shortcuts.h:183
IdxDigitalSurface::Vertex IdxSurfel
Definition Shortcuts.h:169
void selfDisplay(std::ostream &out) const
Definition Shortcuts.h:3338
std::vector< RealPoint > RealPoints
Definition Shortcuts.h:181
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(Surfel2Index &s2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2269
static CountedPtr< PolygonalSurface > makePolygonalSurface(CountedPtr< GrayScaleImage > gray_scale_image, const Parameters &params=parametersKSpace()|parametersBinaryImage()|parametersDigitalSurface())
Definition Shortcuts.h:2189
static bool saveOBJ(CountedPtr< ::DGtal::SurfaceMesh< TPoint, TVector > > surf, const std::string &objfile)
Definition Shortcuts.h:2442
static bool saveOBJ(CountedPtr< ::DGtal::PolygonalSurface< TPoint > > polysurf, const std::string &objfile)
Definition Shortcuts.h:2460
static ZeroTickedColorMap getZeroTickedColorMap(Scalar min, Scalar max, const Parameters &params=parametersUtilities())
Definition Shortcuts.h:2789
IdxDigitalSurface::ArcRange IdxArcRange
Definition Shortcuts.h:172
std::vector< RealVector > RealVectors
Definition Shortcuts.h:180
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
Definition Shortcuts.h:1911
std::vector< Scalar > Scalars
Definition Shortcuts.h:179
static CountedPtr< BinaryImage > makeBinaryImage(std::string input, Parameters params=parametersBinaryImage())
Definition Shortcuts.h:657
IndexedDigitalSurface< ExplicitSurfaceContainer > IdxDigitalSurface
Definition Shortcuts.h:161
std::vector< SCell > SCellRange
Definition Shortcuts.h:174
static CountedPtr< GrayScaleImage > makeGrayScaleImage(std::string input)
Definition Shortcuts.h:750
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(const std::vector< CountedPtr< LightDigitalSurface > > &surfaces, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1365
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:1940
::DGtal::PolygonalSurface< RealPoint > PolygonalSurface
Definition Shortcuts.h:187
static CanonicSCellEmbedder< KSpace > getSCellEmbedder(CountedPtr< ::DGtal::IndexedDigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:1045
Shortcuts(const Shortcuts &other)=delete
BOOST_CONCEPT_ASSERT((concepts::CCellularGridSpaceND< TKSpace >))
static const KSpace & refKSpace(CountedPtr< ::DGtal::IndexedDigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:431
GaussDigitizer< Space, ImplicitShape3D > DigitizedImplicitShape3D
Definition Shortcuts.h:140
static bool saveBinaryImage(CountedPtr< BinaryImage > bimage, std::string output)
Definition Shortcuts.h:709
std::vector< IdxSurfel > IdxSurfelRange
Definition Shortcuts.h:178
static Parameters parametersBinaryImage()
Definition Shortcuts.h:548
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< GrayScaleImage > gray_scale_image, Parameters params=parametersBinaryImage())
Definition Shortcuts.h:686
IdxDigitalSurface::Arc IdxArc
Definition Shortcuts.h:171
static Parameters defaultParameters()
Definition Shortcuts.h:204
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(CountedPtr< BinaryImage > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1276
static CountedPtr< GrayScaleImage > makeGrayScaleImage(CountedPtr< BinaryImage > binary_image, std::function< GrayScale(bool) > const &bool2grayscale=[](bool v) { return v ?(unsigned char) 255 :(unsigned char) 0;})
Definition Shortcuts.h:764
Space::RealVector RealVector
Definition Shortcuts.h:122
static bool saveOBJ(CountedPtr< ::DGtal::PolygonalSurface< TPoint > > polysurf, const RealVectors &normals, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
Definition Shortcuts.h:2529
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< GrayScaleImage > gray_scale_image, const Parameters &params=parametersKSpace()|parametersBinaryImage()|parametersDigitalSurface())
Definition Shortcuts.h:2232
static bool outputDualDigitalSurfaceAsObj(std::ostream &output, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersMesh())
Definition Shortcuts.h:2966
static Parameters parametersDigitizedImplicitShape3D()
Definition Shortcuts.h:462
LightDigitalSurface::Arc Arc
Definition Shortcuts.h:166
ImageContainerBySTLVector< Domain, double > DoubleImage
Definition Shortcuts.h:148
static CountedPtr< GrayScaleImage > makeGrayScaleImage(CountedPtr< FloatImage > fimage, Parameters params=parametersGrayScaleImage())
Definition Shortcuts.h:805
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(const TSurfelRange &surfels, ConstAlias< KSpace > K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1309
IdxDigitalSurface::Vertex IdxVertex
Definition Shortcuts.h:170
static PointelRange getCellRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Dimension k)
Definition Shortcuts.h:1439
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(Surfel2Index &s2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2105
static CountedPtr< SurfaceMesh > makePrimalSurfaceMesh(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2391
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2289
static CountedPtr< SurfaceMesh > makePrimalSurfaceMesh(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2373
static ColorMap getColorMap(Scalar min, Scalar max, const Parameters &params=parametersUtilities())
Definition Shortcuts.h:2751
static PointelRange getPointelRange(const KSpace &K, const SCell &surfel)
Definition Shortcuts.h:1527
std::set< IdxSurfel > IdxSurfelSet
Definition Shortcuts.h:173
HyperRectDomain< Space > Domain
Definition Shortcuts.h:128
static PointelRange getPointelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:1511
static CanonicCellEmbedder< KSpace > getCellEmbedder(CountedPtr< ::DGtal::IndexedDigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:1034
static bool outputSCellMapAsCSV(std::ostream &output, const KSpace &K, const TSCellMap &anyMap, const TValueWriter &writer)
Definition Shortcuts.h:3196
static IdxSurfelRange getIdxSurfelRange(CountedPtr< IdxDigitalSurface > surface, const IdxSurfel &start_surfel, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1633
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, const RealVectors &normals, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
Definition Shortcuts.h:1860
static std::vector< TValue > getMatchedRange(const std::vector< TValue > &range, const IdxRange &match)
Definition Shortcuts.h:2736
LightDigitalSurface::SCell SCell
Definition Shortcuts.h:164
static IdxSurfelRange getIdxSurfelRange(CountedPtr< IdxDigitalSurface > surface, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1613
static CountedPtr< BinaryImage > makeBinaryImage(CountedPtr< DigitizedImplicitShape3D > shape_digitization, Domain shapeDomain, Parameters params=parametersBinaryImage())
Definition Shortcuts.h:597
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:1740
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:1674
TickedColorMap< Scalar, ColorMap > ZeroTickedColorMap
Definition Shortcuts.h:195
::DGtal::DigitalSurface< LightSurfaceContainer > LightDigitalSurface
Definition Shortcuts.h:155
static Parameters parametersGrayScaleImage()
Definition Shortcuts.h:724
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition Shortcuts.h:562
static CanonicCellEmbedder< KSpace > getCellEmbedder(const KSpace &K)
Definition Shortcuts.h:439
static CountedPtr< IdxDigitalSurface > makeIdxDigitalSurface(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1342
static CountedPtr< PolygonalSurface > makePrimalPolygonalSurface(CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2342
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters &params=parametersImplicitShape3D())
Definition Shortcuts.h:283
static CountedPtr< GrayScaleImage > makeGrayScaleImage(CountedPtr< DoubleImage > fimage, Parameters params=parametersGrayScaleImage())
Definition Shortcuts.h:837
static CanonicCellEmbedder< KSpace > getCellEmbedder(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
Definition Shortcuts.h:1012
static CountedPtr< PolygonalSurface > makeDualPolygonalSurface(CountedPtr< ::DGtal::IndexedDigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2304
static CountedPtr< TriangulatedSurface > makeTriangulatedSurface(CountedPtr< Mesh > aMesh)
Definition Shortcuts.h:2055
LightDigitalSurface::Cell Cell
Definition Shortcuts.h:163
PointVector< dim, Integer > Point
Definition SpaceND.h:110
PointVector< dim, double > RealPoint
Definition SpaceND.h:117
PointVector< dim, double > RealVector
Definition SpaceND.h:121
PointVector< dim, Integer > Vector
Definition SpaceND.h:113
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
static void sMakeBoundary(SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
Aim: This class adapts any colormap to add "ticks" in the colormap colors.
Aim: Represents a triangulated surface. The topology is stored with a half-edge data structure....
Aim: Define a simple Foreground predicate thresholding image values between two constant values (the ...
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
BreadthFirstVisitor< MyDigitalSurface > Visitor
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::uint32_t Dimension
Definition Common.h:119
Trace trace
Aim: A trivial embedder for signed and unsigned cell, which corresponds to the canonic injection of c...
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
Aim: Provide a mechanism to save image (2D or 3D) into file with the best saver loader according to a...
static bool export2OFF(std::ostream &out, const Mesh< TPoint > &aMesh, bool exportColor=true)
Cell operator()(std::istream &input, const KSpace &K)
Definition Shortcuts.h:3106
void operator()(std::ostream &output, const KSpace &K, const Cell &cell)
Definition Shortcuts.h:3099
SCell operator()(std::istream &input, const KSpace &K)
Definition Shortcuts.h:3122
void operator()(std::ostream &output, const KSpace &K, const SCell &scell)
Definition Shortcuts.h:3115
bool operator()(std::istream &input, Value &value)
Definition Shortcuts.h:3147
bool operator()(std::istream &input, std::vector< Value > &values)
Definition Shortcuts.h:3162
void operator()(std::ostream &output, const Value &v)
Definition Shortcuts.h:3135
void operator()(std::ostream &output, const std::vector< Value > &vv)
Definition Shortcuts.h:3139
static bool readOBJ(std::istream &input, SurfaceMesh &smesh)
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition SurfaceMesh.h:92
Aim: A cell embedder is a mapping from unsigned cells to Euclidean points. It adds inner types to fun...
Aim: This concept describes a cellular grid space in nD. In these spaces obtained by cartesian produc...
int max(int a, int b)
KSpace K
HalfEdgeDataStructure::Size Size
MPolynomialReader< 3, Ring > Polynomial3Reader
Domain domain
Image image(domain)