73#include "DGtal/base/Common.h"
74#include "DGtal/io/viewers/Viewer3D.h"
75#include "DGtal/io/DrawWithDisplay3DModifier.h"
76#include "DGtal/io/Color.h"
77#include "DGtal/shapes/Shapes.h"
78#include "DGtal/helpers/StdDefs.h"
79#include "DGtal/helpers/Shortcuts.h"
80#include "DGtal/images/ImageContainerBySTLVector.h"
81#include "DGtal/geometry/volumes/NeighborhoodConvexityAnalyzer.h"
93template <
typename KSpace,
int N >
98 template <
typename ImagePtr >
101 debug_one(
const KSpace& aK,
Point p, ImagePtr bimage )
105 auto& image = *bimage;
108 bool cvx = nca.isFullyConvex(
true );
109 bool ccvx = nca.isComplementaryFullyConvex(
false );
110 auto cfg = nca.makeConfiguration( nca.configuration(),
true, false );
111 std::vector< Point > localCompX;
112 nca.getLocalCompX( localCompX,
false );
113 std::cout <<
"InC=" << nca.configuration() << std::endl;
114 std::cout <<
"Cfg=" << cfg << std::endl;
115 for (
auto q : localCompX ) std::cout << q;
116 std::cout << std::endl;
117 geom = ( cvx ? 0x1 : 0x0 ) | ( ccvx ? 0x2 : 0x0 );
118 std::cout <<
"cvx=" << cvx <<
" ccvx=" << ccvx << std::endl;
119 std::cout <<
"geom=" << geom << std::endl;
123 template <
typename ImagePtr >
126 run(
const KSpace& aK, std::vector<Point> pts, ImagePtr bimage )
130 auto& image = *bimage;
131 std::vector<int> result;
132 std::map< Point, int > computed;
141 auto it = computed.find( p );
142 if ( it == computed.end() )
147 if ( cvx ) nb_cvx += 1;
148 if ( ccvx ) nb_ccvx += 1;
149 geom = ( cvx ? 0x1 : 0x0 ) | ( ccvx ? 0x2 : 0x0 );
150 computed[ p ] = geom;
152 else geom = it->second;
153 result.push_back( geom );
156 trace.
info() <<
"nb_cvx=" << nb_cvx <<
" nb_ccvx=" << nb_ccvx << std::endl;
160 template <
typename ImagePtr >
163 run( std::vector<int> & to_update,
164 const KSpace& aK, std::vector<Point> pts, ImagePtr bimage )
168 auto& image = *bimage;
169 std::map< Point, int > computed;
176 auto it = computed.find( p );
177 if ( it == computed.end() )
180 bool cvx = ( to_update[ i ] & 0x1 )
183 bool ccvx = ( to_update[ i ] & 0x2 )
186 geom = ( cvx ? 0x1 : 0x0 ) | ( ccvx ? 0x2 : 0x0 );
187 computed[ p ] = geom;
189 else geom = it->second;
190 to_update[ i++ ] = geom;
195template <
typename KSpace,
int N >
196struct MultiScaleAnalyzer {
199 typedef std::pair< int, int > Geometry;
201 template <
typename ImagePtr >
203 std::vector< Geometry >
204 multiscale_run(
const KSpace& aK,
205 std::vector<Point> pts,
209 = MultiScaleAnalyzer< KSpace, N-1>::multiscale_run( aK, pts, bimage );
210 trace.
info() <<
"------- Analyzing scale " << N <<
" --------" << std::endl;
211 std::vector< int > geom( prev_geometry.size() );
212 for (
int i = 0; i < geom.size(); i++ )
213 geom[ i ] = ( prev_geometry[ i ].first == N-1 ? 0x1 : 0x0 )
214 | ( prev_geometry[ i ].second == N-1 ? 0x2 : 0x0 );
215 Analyzer< KSpace, N>::run( geom, aK, pts, bimage );
216 for (
int i = 0; i < geom.size(); i++ ) {
217 prev_geometry[ i ].first += ( geom[ i ] & 0x1 ) ? 1 : 0;
218 prev_geometry[ i ].second += ( geom[ i ] & 0x2 ) ? 1 : 0;
220 return prev_geometry;
225template <
typename KSpace>
226struct MultiScaleAnalyzer<
KSpace, 0 > {
228 typedef std::pair< int, int > Geometry;
230 template <
typename ImagePtr >
232 std::vector< Geometry >
233 multiscale_run(
const KSpace& aK,
234 std::vector<Point> pts,
237 return std::vector< Geometry >( pts.size(), std::make_pair( 0, 0 ) );
241int main(
int argc,
char** argv )
245 trace.
info() <<
"Usage: " << argv[ 0 ] <<
" <K> <input.vol> <m> <M>" << std::endl;
246 trace.
info() <<
"\tAnalyze the shape with local full convexity" << std::endl;
247 trace.
info() <<
"\t- 1 <= K <= 5: analysis at scale K" << std::endl;
248 trace.
info() <<
"\t- K == 0: multiscale analysis (using scales 1-5)" << std::endl;
249 trace.
info() <<
"\t- input.vol: choose your favorite shape" << std::endl;
250 trace.
info() <<
"\t- m [==0], M [==255]: used to threshold input vol image" << std::endl;
253 int N = atoi( argv[ 1 ] );
254 std::string fn= argv[ 2 ];
255 int m = argc > 3 ? atoi( argv[ 3 ] ) : 0;
256 int M = argc > 4 ? atoi( argv[ 4 ] ) : 255;
258 QApplication application(argc,argv);
263 trace.
info() <<
"Building set or importing vol ... ";
265 params(
"thresholdMin", m );
266 params(
"thresholdMax", M );
271 params(
"surfaceComponents" ,
"All" );
276 std::vector< Point > points;
277 std::map< SCell, int > surfel2idx;
278 std::map< Point, int > point2idx;
280 for (
auto s : (*surface) )
286 auto it = point2idx.find( p );
287 if ( it == point2idx.end() )
289 points.push_back( p );
290 surfel2idx[ s ] = idx;
291 point2idx [ p ] = idx++;
294 surfel2idx[ s ] = it->second;
296 trace.
info() <<
"Shape has " << points.size() <<
" interior boundary points"
300 std::vector< int > result;
302 if ( N == 1 ) result = Analyzer< KSpace, 1 >::run(
K, points, bimage );
303 if ( N == 2 ) result = Analyzer< KSpace, 2 >::run(
K, points, bimage );
304 if ( N == 3 ) result = Analyzer< KSpace, 3 >::run(
K, points, bimage );
305 if ( N == 4 ) result = Analyzer< KSpace, 4 >::run(
K, points, bimage );
306 if ( N == 5 ) result = Analyzer< KSpace, 5 >::run(
K, points, bimage );
310 {
Color( 255, 0, 0, 255 ),
Color( 0, 255, 0, 255 ),
311 Color( 0, 0, 255, 255 ),
Color( 255, 255, 255, 255 ) };
314 for (
int i = 0; i < surfels.size(); i++ )
316 const auto j = surfel2idx[ surfels[ i ] ];
317 all_colors[ i ] = colors[ result[ j ] ];
321 viewer.setWindowTitle(
"fullConvexityAnalysis3D");
325 for (
auto s : (*surface) )
331 viewer<< Viewer3D<>::updateDisplay;
338 MultiScaleAnalyzer< KSpace, 5 >::multiscale_run(
K, points, bimage );
340 Color colors_planar[ 6 ] =
341 {
Color( 0, 255, 255, 255),
342 Color( 50, 255, 255, 255),
Color( 100, 255, 255, 255),
343 Color( 150, 255, 255, 255),
Color( 200, 255, 255, 255 ),
344 Color( 255, 255, 255, 255 ) };
345 Color color_atypical( 255, 0, 0, 255 );
346 Color colors_cvx[ 5 ] =
347 {
Color( 0, 255, 0, 255 ),
Color( 50, 255, 50, 255 ),
348 Color( 100, 255, 100, 255 ),
Color( 150, 255, 150, 255 ),
349 Color( 200, 255, 200, 255 ) };
350 Color colors_ccv[ 5 ] =
351 {
Color( 0, 0, 255, 255 ),
Color( 50, 50, 255, 255 ),
352 Color( 100, 100, 255, 255 ),
Color( 150, 150, 255, 255 ),
353 Color( 200, 200, 255, 255 ) };
356 for (
int i = 0; i < surfels.size(); i++ ) {
357 const auto j = surfel2idx[ surfels[ i ] ];
358 int m0 = std::min( geometry[ j ].first, geometry[ j ].second );
359 int m1 = std::max( geometry[ j ].first, geometry[ j ].second );
360 if ( m1 == 0 ) all_colors[ i ] = color_atypical;
361 else if ( m0 == m1 ) all_colors[ i ] = colors_planar[ 5 ];
362 else if ( geometry[ j ].first > geometry[ j ].second )
363 all_colors[ i ] = colors_cvx[ 5 - abs( m0 - m1 ) ];
365 all_colors[ i ] = colors_ccv[ 5 - abs( m0 - m1 ) ];
371 viewer.setWindowTitle(
"fullConvexityAnalysis3D");
374 for (
auto s : (*surface) )
380 viewer<< Viewer3D<>::updateDisplay;
Structure representing an RGB triple with alpha component.
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.
Dimension sOrthDir(const SCell &s) const
Given a signed surfel [s], returns its orthogonal direction (ie, the coordinate where the surfel is c...
Point sCoords(const SCell &c) const
Return its digital coordinates.
bool sDirect(const SCell &p, Dimension k) const
Return 'true' if the direct orientation of [p] along [k] is in the positive coordinate direction.
const Point & upperBound() const
Return the upper bound for digital points in this space.
SCell sIncident(const SCell &c, Dimension k, bool up) const
Return the forward or backward signed cell incident to [c] along axis [k], depending on [up].
static const constexpr Dimension dimension
Aim: A class that models a neighborhood and that provides services to analyse the convexity properti...
bool isComplementaryFullyConvex(bool with_center)
bool isFullyConvex(bool with_center)
void setCenter(Point c, const PointPredicate &X)
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())
std::vector< Color > Colors
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters ¶ms=parametersDigitalSurface())
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters ¶ms=parametersDigitalSurface())
std::vector< RealVector > RealVectors
static Parameters defaultParameters()
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)
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
void beginBlock(const std::string &keyword="")
void progressBar(const double currentValue, const double maximalValue)
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
CountedPtr< SH3::DigitalSurface > surface
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
std::string className() const
Return the style name used for drawing this object.