DGtal 1.3.0
Loading...
Searching...
No Matches
Typedefs | Functions
fullConvexityThinning3D.cpp File Reference
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/DrawWithDisplay3DModifier.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"

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 56 of file fullConvexityThinning3D.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 62 of file fullConvexityThinning3D.cpp.

63{
64 trace.info() << "Usage: " << argv[ 0 ] << " <thickness> <convexity> <input.vol> <m> <M>" << std::endl;
65 trace.info() << " - convexity in {0,1}: 0=0-convexity, 1=full-convexity"<< std::endl;
66
67 int thickness = argc > 1 ? atoi( argv[ 1 ] ) : 2;
68 bool full_cvx = argc > 2 ? atoi( argv[ 2 ] ) == 1 : false;
69 std::string fn= argc > 3 ? argv[ 3 ] : "";
70 int m = argc > 4 ? atoi( argv[ 4 ] ) : 0;
71 int M = argc > 5 ? atoi( argv[ 5 ] ) : 255;
72 trace.beginBlock ( "Example of 3D shape thinning with full convexity properties" );
73
74 QApplication application(argc,argv);
75 Viewer3D<> viewer;
76 viewer.setWindowTitle("fullConvexityThinning3D");
77 viewer.show();
78
79 auto params = SH3::defaultParameters();
80
81 // Domain creation from two bounding points.
82 trace.info() << "Building set or importing vol ... ";
83 Point c( 0, 0, 0 );
84 Point p1( -50, -50, -50 );
85 Point p2( 50, 50, 50 );
86 Domain domain( p1, p2 );
87 KSpace K;
88 std::set< Point > shape_set;
90 if ( fn == "" )
91 {
92 K.init( p1, p2, true );
93 for (Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
94 {
95 Point p = *it;
96 if ( ((p - c ).norm() <= 22+thickness ) && ((p - c ).norm() >= 20-thickness)
97 && ( ((p[0] <= thickness)&& (p[0] >= -thickness))
98 || ((p[1] <= thickness)&& (p[1] >= -thickness))))
99 {
100 shape_set.insert( p );
101 bimage->setValue( p, true );
102 }
103 else
104 bimage->setValue( p, false );
105 }
106 }
107 else
108 {
109 params( "thresholdMin", m );
110 params( "thresholdMax", M );
111 bimage = SH3::makeBinaryImage( fn, params );
112 K = SH3::getKSpace( bimage );
113 p1 = K.lowerBound();
114 p2 = K.upperBound();
115 domain = Domain( p1, p2 );
116 for ( auto p : domain )
117 if ( (*bimage)( p ) ) shape_set.insert( p );
118 }
119 std::set< Point > origin_set( shape_set );
120 trace.info() << " [Done]" << std::endl;
121
122 {
123 params( "surfaceComponents" , "All" );
124 auto surface = SH3::makeDigitalSurface( bimage, K, params );
125 bool ok = SH3::saveOBJ( surface, "source.obj" );
126 }
127
128 trace.beginBlock ( "Thinning" );
129 SH3::BinaryImage& image = *bimage;
130 NCA nca( p1, p2, 10000 );
131 int nb_simple=0;
132 std::set< Point >::iterator it, itE;
133 std::set< Point > to_process( shape_set );
134 do
135 {
136 std::set< Point > next_to_process;
137 nb_simple = 0;
138 trace.info() << "Pass #S=" << shape_set.size()
139 << " #Q=" << to_process.size() << std::endl;
140 for ( auto it = to_process.begin(), itE = to_process.end(); it != itE; ++it )
141 {
142 Point p = *it;
143 if ( ! image( p ) ) continue; // already removed
144 nca.setCenter( p, image );
145 if ( full_cvx
146 ? nca.isFullyConvexCollapsible()
147 : nca.is0ConvexCollapsible() )
148 {
149 std::vector< Point > neighbors;
150 nca.getLocalX( neighbors, false );
151 for ( auto q : neighbors ) next_to_process.insert( q );
152 shape_set.erase( p );
153 image.setValue( p, false );
154 ++nb_simple;
155 }
156 }
157 trace.info() << " => nb_removed=" << nb_simple<< std::endl;
158 if ( nb_simple != 0 )
159 std::swap( to_process, next_to_process );
160 }
161 while ( nb_simple != 0 );
162 trace.endBlock();
163
164 {
165 params( "surfaceComponents" , "All" );
166 auto surface = SH3::makeDigitalSurface( bimage, K, params );
167 SH3::saveOBJ( surface, "geom-thinned.obj" );
168 }
169
170 // Display by using two different list to manage OpenGL transparency.
171 DigitalSet origin( domain );
172 DigitalSet output( domain );
173 for ( auto p : origin_set ) origin.insert( p );
174 for ( auto p : shape_set ) output.insert( p );
175 viewer << SetMode3D( output.className(), "Paving" );
176 viewer << CustomColors3D(Color(25,25,255, 255), Color(25,25,255, 255));
177 viewer << output;
178
179 viewer << SetMode3D( origin.className(), "PavingTransp" );
180 viewer << CustomColors3D(Color(250, 0,0, 25), Color(250, 0,0, 5));
181 viewer << origin;
182
183 viewer<< Viewer3D<>::updateDisplay;
184
185
186 trace.endBlock();
187 return application.exec();
188
189}
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
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...
Iterator for HyperRectDomain.
const ConstIterator & begin() const
const ConstIterator & end() const
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.
Aim: A class that models a neighborhood and that provides services to analyse the convexity properti...
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:332
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1209
static Parameters defaultParameters()
Definition: Shortcuts.h:203
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)
Definition: Shortcuts.h:1739
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition: Shortcuts.h:561
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
HyperRectDomain< Space > Domain
Definition: StdDefs.h:172
Trace trace
Definition: Common.h:154
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
KSpace K
Domain domain

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::className(), DGtal::Shortcuts< TKSpace >::defaultParameters(), domain, DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::NeighborhoodConvexityAnalyzer< TKSpace, K >::getLocalX(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insert(), DGtal::NeighborhoodConvexityAnalyzer< TKSpace, K >::is0ConvexCollapsible(), DGtal::NeighborhoodConvexityAnalyzer< TKSpace, K >::isFullyConvexCollapsible(), K, DGtal::KhalimskySpaceND< dim, TInteger >::lowerBound(), DGtal::Shortcuts< TKSpace >::makeBinaryImage(), DGtal::Shortcuts< TKSpace >::makeDigitalSurface(), DGtal::Shortcuts< TKSpace >::saveOBJ(), DGtal::NeighborhoodConvexityAnalyzer< TKSpace, K >::setCenter(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::trace, and DGtal::KhalimskySpaceND< dim, TInteger >::upperBound().