DGtal 2.1.0
Loading...
Searching...
No Matches
fullConvexityThinning3D.cpp File Reference
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/io/Color.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/geometry/volumes/NeighborhoodConvexityAnalyzer.h"
Include dependency graph for fullConvexityThinning3D.cpp:

Go to the source code of this file.

Typedefs

typedef Shortcuts< KSpaceSH3
 
typedef NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA
 

Functions

int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2021/06/16

An example file named fullConvexityThinning3D

This file is part of the DGtal library.

Definition in file fullConvexityThinning3D.cpp.

Typedef Documentation

◆ NCA

◆ SH3

typedef Shortcuts< KSpace > SH3

Definition at line 55 of file fullConvexityThinning3D.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 61 of file fullConvexityThinning3D.cpp.

62{
63 trace.info() << "Usage: " << argv[ 0 ] << " <thickness> <convexity> <input.vol> <m> <M>" << std::endl;
64 trace.info() << " - convexity in {0,1}: 0=0-convexity, 1=full-convexity"<< std::endl;
65
66 int thickness = argc > 1 ? atoi( argv[ 1 ] ) : 2;
67 bool full_cvx = argc > 2 ? atoi( argv[ 2 ] ) == 1 : false;
68 std::string fn= argc > 3 ? argv[ 3 ] : "";
69 int m = argc > 4 ? atoi( argv[ 4 ] ) : 0;
70 int M = argc > 5 ? atoi( argv[ 5 ] ) : 255;
71 trace.beginBlock ( "Example of 3D shape thinning with full convexity properties" );
72
73 PolyscopeViewer<> viewer;
74
75 auto params = SH3::defaultParameters();
76
77 // Domain creation from two bounding points.
78 trace.info() << "Building set or importing vol ... ";
79 Point c( 0, 0, 0 );
80 Point p1( -50, -50, -50 );
81 Point p2( 50, 50, 50 );
82 Domain domain( p1, p2 );
83 KSpace K;
84 std::set< Point > shape_set;
85 CountedPtr< SH3::BinaryImage > bimage( new SH3::BinaryImage( domain ) );
86 if ( fn == "" )
87 {
88 K.init( p1, p2, true );
89 for (Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
90 {
91 Point p = *it;
92 if ( ((p - c ).norm() <= 22+thickness ) && ((p - c ).norm() >= 20-thickness)
93 && ( ((p[0] <= thickness)&& (p[0] >= -thickness))
94 || ((p[1] <= thickness)&& (p[1] >= -thickness))))
95 {
96 shape_set.insert( p );
97 bimage->setValue( p, true );
98 }
99 else
100 bimage->setValue( p, false );
101 }
102 }
103 else
104 {
105 params( "thresholdMin", m );
106 params( "thresholdMax", M );
107 bimage = SH3::makeBinaryImage( fn, params );
108 K = SH3::getKSpace( bimage );
109 p1 = K.lowerBound();
110 p2 = K.upperBound();
111 domain = Domain( p1, p2 );
112 for ( auto p : domain )
113 if ( (*bimage)( p ) ) shape_set.insert( p );
114 }
115 std::set< Point > origin_set( shape_set );
116 trace.info() << " [Done]" << std::endl;
117
118 {
119 params( "surfaceComponents" , "All" );
120 auto surface = SH3::makeDigitalSurface( bimage, K, params );
121 SH3::saveOBJ( surface, "source.obj" );
122 }
123
124 trace.beginBlock ( "Thinning" );
125 SH3::BinaryImage& image = *bimage;
126 NCA nca( p1, p2, 10000 );
127 int nb_simple=0;
128 std::set< Point >::iterator it, itE;
129 std::set< Point > to_process( shape_set );
130 do
131 {
132 std::set< Point > next_to_process;
133 nb_simple = 0;
134 trace.info() << "Pass #S=" << shape_set.size()
135 << " #Q=" << to_process.size() << std::endl;
136 for ( it = to_process.begin(), itE = to_process.end(); it != itE; ++it )
137 {
138 Point p = *it;
139 if ( ! image( p ) ) continue; // already removed
140 nca.setCenter( p, image );
141 if ( full_cvx
142 ? nca.isFullyConvexCollapsible()
143 : nca.is0ConvexCollapsible() )
144 {
145 std::vector< Point > neighbors;
146 nca.getLocalX( neighbors, false );
147 for ( auto q : neighbors ) next_to_process.insert( q );
148 shape_set.erase( p );
149 image.setValue( p, false );
150 ++nb_simple;
151 }
152 }
153 trace.info() << " => nb_removed=" << nb_simple<< std::endl;
154 if ( nb_simple != 0 )
155 std::swap( to_process, next_to_process );
156 }
157 while ( nb_simple != 0 );
158 trace.endBlock();
159
160 {
161 params( "surfaceComponents" , "All" );
162 auto surface = SH3::makeDigitalSurface( bimage, K, params );
163 SH3::saveOBJ( surface, "geom-thinned.obj" );
164 }
165
166 // Display by using two different list to manage OpenGL transparency.
167 DigitalSet origin( domain );
168 DigitalSet output( domain );
169 for ( auto p : origin_set ) origin.insert( p );
170 for ( auto p : shape_set ) output.insert( p );
171
172 viewer << Color(25,25,255, 255);
173 viewer << output;
174
175 viewer << Color(250, 0,0, 25);
176 viewer << origin;
177
178 trace.endBlock();
179 viewer.show();
180 return 0;
181
182}
Structure representing an RGB triple with alpha component.
Definition Color.h:77
Aim: Smart pointer based on reference counts.
Definition CountedPtr.h:80
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
const ConstIterator & begin() const
const ConstIterator & end() const
void setValue(const Point &aPoint, const Value &aValue)
Definition Image.h:247
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.
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
const Point & upperBound() const
Return the upper bound for digital points in this space.
void show() override
Starts the event loop and display of elements.
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
CountedPtr< SH3::DigitalSurface > surface
NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA
HyperRectDomain< Space > Domain
Definition StdDefs.h:172
Trace trace
KSpace K
void insert(VContainer1 &c1, LContainer2 &c2, unsigned int idx, double v)
Domain domain
Image image(domain)

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), domain, DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insert(), K, DGtal::KhalimskySpaceND< dim, TInteger >::lowerBound(), DGtal::Image< TImageContainer >::setValue(), DGtal::PolyscopeViewer< Space, KSpace >::show(), surface, DGtal::trace, and DGtal::KhalimskySpaceND< dim, TInteger >::upperBound().