Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes for DGtal for dummies #1364

Merged
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
- Fix bug in ImageLinearCellEmbedder.
(Jacques-Olivier Lachaud, [#1356](https:/DGtal-team/DGtal/pull/1356))

- *Helpers*
- Small fixes in Shortcuts and ShortcutsGeometry, doc, and colormaps. (Jacques-Olivier Lachaud, [#1364](https:/DGtal-team/DGtal/pull/1364))


# DGtal 0.9.4.1

## Bug Fixes
Expand Down
35 changes: 35 additions & 0 deletions examples/tutorial-examples/shortcuts-geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,41 @@ int main( int /* argc */, char** /* argv */ )
++nb, nbok += ( ok_H && ii_mean_curv.size() == ii_mean_curv2.size() ) ? 1 : 0;
}
trace.endBlock();

trace.beginBlock ( "Build polynomial shape -> save several projected quadrangulated surface and digitized boundaries." );
{
auto params = SH3::defaultParameters() | SHG3::defaultParameters();
std::vector<double> gridsteps {0.5, 0.25, 0.125};
for ( auto h : gridsteps ) {
params( "polynomial", "goursat" )( "gridstep", h );
auto implicit_shape = SH3::makeImplicitShape3D ( params );
auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
auto binary_image = SH3::makeBinaryImage ( digitized_shape, params );
auto K = SH3::getKSpace( params );
auto embedder = SH3::getCellEmbedder( K );
auto surface = SH3::makeLightDigitalSurface( binary_image, K, params );
SH3::Cell2Index c2i;
auto pointels = SH3::getPointelRange( c2i, surface );
SH3::RealPoints pos( pointels.size() );
std::transform( pointels.cbegin(), pointels.cend(), pos.begin(),
[&] (const SH3::Cell& c) { return h * embedder( c ); } );
auto ppos = SHG3::getPositions( implicit_shape, pos, params );
auto fname = std::string( "goursat-quad-" ) + std::to_string( h ) + std::string( ".obj" );
bool ok = SH3::saveOBJ( surface,
[&] (const SH3::Cell& c){ return pos[ c2i[ c ] ];},
SH3::RealVectors(), SH3::Colors(),
fname );
auto proj_fname = std::string( "goursat-quad-proj-" ) + std::to_string( h ) + std::string( ".obj" );
bool proj_ok = SH3::saveOBJ( surface,
[&] (const SH3::Cell& c){ return ppos[ c2i[ c ] ];},
SH3::RealVectors(), SH3::Colors(),
proj_fname );
++nb, nbok += ok ? 1 : 0;
++nb, nbok += proj_ok ? 1 : 0;
}
}
trace.endBlock();


trace.info() << nbok << "/" << nb << " passed tests." << std::endl;
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/DGtal/doc/tutorials/moduleShortcuts.dox
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ Shortcuts::Point is Z3i::KSpace::Point.
-# Utilities
- Shortcuts::parametersUtilities: parameters related to colormaps.
- Shortcuts::getColorMap: returns the specified colormap.
- Shortcuts::getTicsColorMap: returns the specified colormap used for tics.
- Shortcuts::getZeroTickedColorMap: returns the specified colormap with a tic around zero.
- Shortcuts::getRangeMatch: returns the perfect or approximate match/correspondence between two ranges.
- Shortcuts::getMatchedRange: returns the perfectly or approximately matched/corresponding range.
- Shortcuts::getPrimalVertices: returns the vertices (possibly consistently ordered along the face) of the given signed cell.
Expand Down
5,447 changes: 2,732 additions & 2,715 deletions src/DGtal/helpers/Shortcuts.h

Large diffs are not rendered by default.

2,010 changes: 1,005 additions & 1,005 deletions src/DGtal/helpers/ShortcutsGeometry.h

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion src/DGtal/io/colormaps/TickedColorMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ namespace DGtal
*/
TickedColorMap(const Value & aMin,
const Value & aMax,
const Color &color = Color::White);
const Color &color = Color::White );

/**
* Constructor from colormap
*
* @pre aMin < aMax.
*
* @param other the background colormap (copied).
* @param color the color of the ticks.
*/
TickedColorMap( const ColorMap & other,
const Color & color = Color::White );

/**
* Computes the color associated with a value in a given range.
Expand Down
11 changes: 11 additions & 0 deletions src/DGtal/io/colormaps/TickedColorMap.ih
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ DGtal::TickedColorMap<Value,CMAP>::TickedColorMap
myColorMap = new ColorMap(myMin,myMax);
}

template <typename Value, typename CMAP>
inline
DGtal::TickedColorMap<Value,CMAP>::TickedColorMap
( const ColorMap& other,
const Color & color )
: myMin( other.min() ), myMax( other.max() ), myTickColor( color )
{
ASSERT_MSG(myMin < myMax, "Max should be strictly greather than Min in a colormap.");
myColorMap = new ColorMap( other );
}


template <typename Value, typename CMAP>
inline
Expand Down
138 changes: 69 additions & 69 deletions src/DGtal/shapes/MeshHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ namespace DGtal
/// @return 'true' on success, 'false' if the input \a mesh was
/// not a combinatorial surface.
template <typename Point>
static
bool mesh2TriangulatedSurface
( const Mesh<Point>& mesh,
TriangulatedSurface<Point>& trisurf );
static
bool mesh2TriangulatedSurface
( const Mesh<Point>& mesh,
TriangulatedSurface<Point>& trisurf );

/// Builds a polygon mesh (class PolygonalSurface) from
/// a mesh (class Mesh). The output polygonal
Expand All @@ -93,10 +93,10 @@ namespace DGtal
/// @return 'true' on success, 'false' if the input \a mesh was
/// not a combinatorial surface.
template <typename Point>
static
bool mesh2PolygonalSurface
( const Mesh<Point>& mesh,
PolygonalSurface<Point>& polysurf );
static
bool mesh2PolygonalSurface
( const Mesh<Point>& mesh,
PolygonalSurface<Point>& polysurf );

/// Builds a polygonal surface from a triangulated
/// surface. Polygonal faces are triangulated according to \a
Expand Down Expand Up @@ -126,11 +126,11 @@ namespace DGtal
/// (e.g. (0,1,2,3) gives (0,1,2) and (2,0,3) and (3,2,1,0) gives
/// (3,2,0) and (0,2,1): then edge {2,0} is shared by four faces).
template <typename Point>
static
void polygonalSurface2TriangulatedSurface
( const PolygonalSurface<Point>& polysurf,
TriangulatedSurface<Point>& trisurf,
bool centroid = true );
static
void polygonalSurface2TriangulatedSurface
( const PolygonalSurface<Point>& polysurf,
TriangulatedSurface<Point>& trisurf,
bool centroid = true );

/// Builds a triangulated surface (class TriangulatedSurface) from
/// the dual graph of a 2-dimensional digital surface in K^3 (class
Expand All @@ -149,14 +149,14 @@ namespace DGtal
/// @param[out] trisurf the output triangulated surface mesh.
/// @param[out] vertexmap the output mapping between a Vertex of \a dsurf and an Index in \a trisurf.
template < typename DigitalSurfaceContainer,
typename CellEmbedder,
typename VertexMap >
static
void digitalSurface2DualTriangulatedSurface
( const DigitalSurface<DigitalSurfaceContainer>& dsurf,
const CellEmbedder& cembedder,
TriangulatedSurface<typename CellEmbedder::Value>& trisurf,
VertexMap& vertexmap );
typename CellEmbedder,
typename VertexMap >
static
void digitalSurface2DualTriangulatedSurface
( const DigitalSurface<DigitalSurfaceContainer>& dsurf,
const CellEmbedder& cembedder,
TriangulatedSurface<typename CellEmbedder::Value>& trisurf,
VertexMap& vertexmap );

/// Builds a polygonal surface (class PolygonalSurface) from
/// the dual graph of a 2-dimensional digital surface in K^3 (class
Expand All @@ -170,14 +170,14 @@ namespace DGtal
/// @param[out] polysurf the output polygonal surface mesh.
/// @param[out] vertexmap the output mapping between a Vertex of \a dsurf and an Index in \a polysurf.
template < typename DigitalSurfaceContainer,
typename CellEmbedder,
typename VertexMap >
static
void digitalSurface2DualPolygonalSurface
( const DigitalSurface<DigitalSurfaceContainer>& dsurf,
const CellEmbedder& cembedder,
PolygonalSurface<typename CellEmbedder::Value>& polysurf,
VertexMap& vertexmap );
typename CellEmbedder,
typename VertexMap >
static
void digitalSurface2DualPolygonalSurface
( const DigitalSurface<DigitalSurfaceContainer>& dsurf,
const CellEmbedder& cembedder,
PolygonalSurface<typename CellEmbedder::Value>& polysurf,
VertexMap& vertexmap );

/// Builds a polygonal surface (class PolygonalSurface) from
/// the primal graph of a 2-dimensional digital surface in K^3 (class
Expand All @@ -193,14 +193,14 @@ namespace DGtal
/// @param[out] cellmap the output mapping between a 0-cell of \a dsurf and an Index in \a polysurf.
/// @return 'true' if it was able to build the primal polygonal surface, otherwise the digital surface was not a combinatorial 2-manifold and is not valid.
template < typename DigitalSurfaceContainer,
typename CellEmbedder,
typename CellMap >
static
bool digitalSurface2PrimalPolygonalSurface
( const DigitalSurface<DigitalSurfaceContainer>& dsurf,
const CellEmbedder& cembedder,
PolygonalSurface<typename CellEmbedder::Value>& polysurf,
CellMap& cellmap );
typename CellEmbedder,
typename CellMap >
static
bool digitalSurface2PrimalPolygonalSurface
( const DigitalSurface<DigitalSurfaceContainer>& dsurf,
const CellEmbedder& cembedder,
PolygonalSurface<typename CellEmbedder::Value>& polysurf,
CellMap& cellmap );


/// Builds a mesh (class Mesh) from a triangulated surface (class
Expand All @@ -212,10 +212,10 @@ namespace DGtal
/// @param[in] trisurf the input triangulated surface mesh.
/// @param[in,out] mesh the output mesh (which should be empty).
template <typename Point>
static
void triangulatedSurface2Mesh
( const TriangulatedSurface<Point>& trisurf,
Mesh<Point>& mesh );
static
void triangulatedSurface2Mesh
( const TriangulatedSurface<Point>& trisurf,
Mesh<Point>& mesh );

/// Builds a mesh (class Mesh) from a polygon mesh (class
/// PolygonalSurface). Note that the mesh looses the topology
Expand All @@ -226,10 +226,10 @@ namespace DGtal
/// @param[in] polysurf the input polygonal surface (ie a polygon mesh).
/// @param[in,out] mesh the output mesh (which should be empty).
template <typename Point>
static
void polygonalSurface2Mesh
( const PolygonalSurface<Point>& polysurf,
Mesh<Point>& mesh );
static
void polygonalSurface2Mesh
( const PolygonalSurface<Point>& polysurf,
Mesh<Point>& mesh );

/// Exports a triangulated surface as an OBJ file (with topology)
/// into the given output stream.
Expand All @@ -238,10 +238,10 @@ namespace DGtal
/// @param[in,out] output an output stream
/// @param[in] trisurf the input triangulated surface mesh.
template <typename Point>
static
bool exportOBJ
( std::ostream& output,
const TriangulatedSurface<Point>& trisurf );
static
bool exportOBJ
( std::ostream& output,
const TriangulatedSurface<Point>& trisurf );

/// Exports a polygonal surface as an OBJ file (with topology)
/// into the given output stream.
Expand All @@ -250,10 +250,10 @@ namespace DGtal
/// @param[in,out] output an output stream
/// @param[in] polysurf the input polygonal surface mesh.
template <typename Point>
static
bool exportOBJ
( std::ostream& output,
const PolygonalSurface<Point>& polysurf );
static
bool exportOBJ
( std::ostream& output,
const PolygonalSurface<Point>& polysurf );


/// Exports a triangulated or polygonal surface as an OBJ file
Expand All @@ -270,16 +270,16 @@ namespace DGtal
/// @param[in] diffuse_color the diffuse color of all faces if \a diffuse_colors was empty.
/// @param[in] specular_color the specular color of all faces.
template <typename TTriangulatedOrPolygonalSurface>
static
bool exportOBJwithFaceNormalAndColor
( std::ostream& output_obj,
const std::string& mtl_filename,
const TTriangulatedOrPolygonalSurface& polysurf,
const std::vector< typename TTriangulatedOrPolygonalSurface::Point >& normals,
const std::vector< Color >& diffuse_colors,
const Color& ambient_color = Color( 32, 32, 32 ),
const Color& diffuse_color = Color( 200, 200, 255 ),
const Color& specular_color = Color::White );
static
bool exportOBJwithFaceNormalAndColor
( std::ostream& output_obj,
const std::string& mtl_filename,
const TTriangulatedOrPolygonalSurface& polysurf,
const std::vector< typename TTriangulatedOrPolygonalSurface::Point >& normals,
const std::vector< Color >& diffuse_colors,
const Color& ambient_color = Color( 32, 32, 32 ),
const Color& diffuse_color = Color( 200, 200, 255 ),
const Color& specular_color = Color::White );


/// Exports a new material in a MTL stream.
Expand All @@ -290,12 +290,12 @@ namespace DGtal
/// @param[in] diffuse_color the diffuse color for the material.
/// @param[in] specular_color the specular color for the material.
static
bool exportMTLNewMaterial
( std::ostream& output_mtl,
unsigned int idxMaterial,
const Color& ambient_color,
const Color& diffuse_color,
const Color& specular_color );
bool exportMTLNewMaterial
( std::ostream& output_mtl,
unsigned int idxMaterial,
const Color& ambient_color,
const Color& diffuse_color,
const Color& specular_color );

}; // end of class MeshHelpers

Expand Down
4 changes: 2 additions & 2 deletions src/DGtal/shapes/MeshHelpers.ih
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ DGtal::MeshHelpers::exportOBJwithFaceNormalAndColor
Color c = diffuse_colors[ f ];
if ( mapMaterial.count( c ) == 0 ) {
exportMTLNewMaterial( output_mtl, idxMaterial,
ambient_color, c, specular_color );
ambient_color, c, specular_color );
mapMaterial[ c ] = idxMaterial++;
}
}
} else {
exportMTLNewMaterial( output_mtl, idxMaterial,
ambient_color, diffuse_color, specular_color );
ambient_color, diffuse_color, specular_color );
}
// Taking care of faces
for ( auto f : faces ) {
Expand Down
18 changes: 18 additions & 0 deletions src/DGtal/shapes/PolygonalSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ namespace DGtal
* @tparam TPoint a type defining the position in space of vertices.
*
* @see HalfEdgeDataStructure
*
* @note You may access the underlying half-edge data structure
* through PolygonalSurface::heds method.
*/
template <typename TPoint>
class PolygonalSurface
Expand Down Expand Up @@ -264,6 +267,10 @@ namespace DGtal
/// @return the corresponding index of the polygonal face.
FaceIndex addPolygonalFace( const PolygonalFace& f );

/// @return a const reference to the half-edge data structure.
const HalfEdgeDataStructure& heds() const
{ return myHEDS; }

// ------------------------- standard services ------------------------------
public:
/// @return the number of half edges in the structure.
Expand Down Expand Up @@ -502,6 +509,17 @@ namespace DGtal
*/
VertexRange verticesAroundFace( const Face & f ) const;

/**
@param f any valid face on the surface. (open or closed ).

@note By construction, each @e anArc returned by the method on
a face @a f is such that `this->faceAroundArc(anArc) == f`.

@return the sequence of arcs that touches this face in their
JacquesOlivierLachaud marked this conversation as resolved.
Show resolved Hide resolved
natural order (the range size should be 3).
*/
ArcRange arcsAroundFace( const Face & f ) const;

/**
@param v any vertex.
@return 'true' if and only if vertex \a v lies on a boundary.
Expand Down
Loading