93#include "DGtal/base/Common.h"
94#include "DGtal/shapes/Shapes.h"
95#include "DGtal/shapes/SurfaceMesh.h"
96#include "DGtal/helpers/StdDefs.h"
97#include "DGtal/helpers/Shortcuts.h"
98#include "DGtal/images/ImageContainerBySTLVector.h"
99#include "DGtal/io/writers/SurfaceMeshWriter.h"
100#include "DGtal/geometry/volumes/TangencyComputer.h"
105using namespace DGtal;
122 const std::vector< double >& vvalues,
123 int nb_isolines_per_unit = 10,
124 const double thickness = 0.1 )
126 std::string cobjname = output;
127 std::string cisoname = output +
"-iso";
128 auto quantify = [] (
double v,
double m,
double nb )
129 {
return round( v/m*nb )*m/nb; };
132 double maxValue = * ( std::max_element( vvalues.cbegin(), vvalues.cend() ) );
133 double minValue = * ( std::min_element( vvalues.cbegin(), vvalues.cend() ) );
134 double maxDist = maxValue - minValue;
135 trace.
info() <<
"Max distance is " << maxDist << std::endl;
138 for (
Index f = 0; f < fvalues.size(); ++f )
139 fcolors[ f ] = cmap( quantify( fvalues[ f ] - minValue, maxDist, 50 ) );
141 double unit = pow( 10.0, floor( log( maxDist ) / log( 10.0 ) ) - 1.0 );
142 const int N = 10 * nb_isolines_per_unit;
143 std::vector< double > isolines( N );
144 std::vector< Color > isocolors( N );
145 for (
int i = 0; i < N; i++ )
147 isolines [ i ] = (double) i * 10.0 * unit / (
double) nb_isolines_per_unit
149 isocolors[ i ] = ( i % nb_isolines_per_unit == 0 )
153 isolines, thickness, isocolors );
158int main(
int argc,
char** argv )
160 trace.
info() <<
"Usage: " << argv[ 0 ] <<
" <h> <opt>" << std::endl;
161 trace.
info() <<
"\tComputes shortest paths to a source point on a sphere digitized with gridstep <h>." << std::endl;
162 trace.
info() <<
"\t- h [==1.0]: digitization gridstep" << std::endl;
163 trace.
info() <<
"\t- opt [==sqrt(3)]: >= sqrt(3): secure shortest paths, 0: fast" << std::endl;
164 double h = argc > 1 ? atof( argv[ 1 ] ) : 0.0625;
165 double opt = argc > 2 ? atof( argv[ 2 ] ) : sqrt(3.0);
170 params(
"polynomial",
"sphere1" )(
"gridstep", h );
171 params(
"minAABB", -2)(
"maxAABB", 2)(
"offset", 1.0 )(
"closed", 1 );
186 std::vector< Point > lattice_points;
188 std::vector< Vertices > faces;
191 for (
auto p : pointels ) lattice_points.push_back(
K.
uCoords( p ) );
193 trace.
info() <<
"#pointels=" << pointels.size() << std::endl;
195 std::transform( pointels.cbegin(), pointels.cend(), vertices.begin(),
196 [&] (
const SH3::Cell& c) { return h * embedder( c ); } );
198 for (
auto&& surfel : *
surface )
201 std::vector< Index > face;
202 for (
auto&& primal_vtx : primal_surfel_vtcs )
203 face.push_back( c2i[ primal_vtx ] );
204 faces.push_back( face );
206 smesh.
init( vertices.cbegin(), vertices.cend(),
207 faces.cbegin(), faces.cend() );
212 const Index nb = lattice_points.size();
215 for (
Index i = 1; i < nb; i++ )
217 if ( lattice_points[ i ] < lattice_points[ lowest ] ) lowest = i;
218 if ( lattice_points[ uppest ] < lattice_points[ i ] ) uppest = i;
225 TC.init( lattice_points.cbegin(), lattice_points.cend() );
226 auto SP = TC.makeShortestPaths( opt );
228 double last_distance = 0.0;
230 while ( ! SP.finished() )
232 last = std::get<0>( SP.current() );
233 last_distance = std::get<2>( SP.current() );
237 std::cout <<
"Max distance is " << last_distance*h << std::endl;
238 std::cout <<
"Comput. time is " << time << std::endl;
239 std::cout <<
"Last index is " << last << std::endl;
240 std::cout <<
"Uppest index is " << uppest << std::endl;
243 std::vector<double> distances = SP.distances();
244 for (
Index i = 0; i < distances.size(); i++ )
246 saveToObj(
"sphere1-geodesics", smesh, distances, 10, 0.1 );
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
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.
Point uCoords(const Cell &c) const
Return its digital coordinates.
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
std::map< Cell, IdxVertex > Cell2Index
static PointelRange getPointelRange(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface)
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters ¶ms=parametersDigitalSurface())
std::vector< RealPoint > RealPoints
static Parameters defaultParameters()
static ColorMap getColorMap(Scalar min, Scalar max, const Parameters ¶ms=parametersUtilities())
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
static CanonicCellEmbedder< KSpace > getCellEmbedder(const KSpace &K)
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters ¶ms=parametersImplicitShape3D())
LightDigitalSurface::Cell Cell
Aim: A class that computes tangency to a given digital set. It provides services to compute all the c...
void beginBlock(const std::string &keyword="")
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
SurfaceMesh< RealPoint, RealVector > SMesh
void saveToObj(const std::string &output, const SMesh &surfmesh, const std::vector< double > &vvalues, int nb_isolines_per_unit=10, const double thickness=0.1)
SurfaceMeshWriter< RealPoint, RealVector > SMeshWriter
Space::RealPoint RealPoint
Space::RealVector RealVector
DGtal is the top-level namespace which contains all DGtal functions and types.
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: An helper class for writing mesh file formats (Waverfront OBJ at this point) and creating a Surf...
static bool writeOBJ(std::ostream &output, const SurfaceMesh &smesh)
static bool writeIsoLinesOBJ(std::string objfile, const SurfaceMesh &smesh, const Scalars &face_values, const Scalars &vertex_values, const Scalar iso_value, const double relative_thickness=0.05, const Color &ambient_color=Color::Black, const Color &diffuse_color=Color::Black, const Color &specular_color=Color::Black)
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
std::vector< Vertex > Vertices
The type that defines a list/range of vertices (e.g. to define faces)
std::size_t Index
The type used for numbering vertices and faces.
bool init(RealPointIterator itPos, RealPointIterator itPosEnd, VerticesIterator itVertices, VerticesIterator itVerticesEnd)
std::vector< AnyRing > computeFaceValuesFromVertexValues(const std::vector< AnyRing > &vvalues) const