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"
105 using 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;
136 auto cmap = SH3::getColorMap( 0.0, maxDist );
138 for (
Index f = 0; f < fvalues.size(); ++f )
139 fcolors[ f ] = cmap( quantify( fvalues[ f ] - minValue, maxDist, 50 ) );
140 SMeshWriter::writeOBJ( cobjname,
surfmesh, fcolors );
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 )
150 ? Color::Red : Color::Black;
152 SMeshWriter::writeIsoLinesOBJ( cisoname,
surfmesh, fvalues, vvalues,
153 isolines, thickness, isocolors );
158 int 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);
169 auto params = SH3::defaultParameters();
170 params(
"polynomial",
"sphere1" )(
"gridstep", h );
171 params(
"minAABB", -2)(
"maxAABB", 2)(
"offset", 1.0 )(
"closed", 1 );
172 auto implicit_shape = SH3::makeImplicitShape3D ( params );
173 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
174 auto K = SH3::getKSpace( params );
175 auto binary_image = SH3::makeBinaryImage(digitized_shape,
185 auto embedder = SH3::getCellEmbedder(
K );
186 std::vector< Point > lattice_points;
188 std::vector< Vertices > faces;
190 auto pointels = SH3::getPointelRange( c2i,
surface );
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 )
200 const auto primal_surfel_vtcs = SH3::getPointelRange(
K, surfel );
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.
Point uCoords(const Cell &c) const
Return its digital coordinates.
const Point & upperBound() const
Return the upper bound for digital points in this space.
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
std::map< Cell, IdxVertex > Cell2Index
std::vector< RealPoint > RealPoints
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
int main(int argc, char **argv)
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...
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::vector< AnyRing > computeFaceValuesFromVertexValues(const std::vector< AnyRing > &vvalues) const
std::size_t Index
The type used for numbering vertices and faces.
bool init(RealPointIterator itPos, RealPointIterator itPosEnd, VerticesIterator itVertices, VerticesIterator itVerticesEnd)