DGtalTools 2.1.0
Loading...
Searching...
No Matches
curvatureMCMS.cpp
1
32#include <iostream>
33
34#include "DGtal/base/Common.h"
35
36#include "DGtal/shapes/ShapeFactory.h"
37#include "DGtal/shapes/Shapes.h"
38#include "DGtal/helpers/StdDefs.h"
39#include "DGtal/topology/helpers/Surfaces.h"
40
41//Grid curve
42#include "DGtal/geometry/curves/FreemanChain.h"
43#include "DGtal/geometry/curves/GridCurve.h"
44
45//Estimators
46#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
47#include "DGtal/geometry/curves/estimation/MostCenteredMaximalSegmentEstimator.h"
48#include "DGtal/geometry/curves/estimation/SegmentComputerEstimators.h"
49
50#include "CLI11.hpp"
51
52#include <vector>
53#include <string>
54#include <iomanip>
55
56
57using namespace DGtal;
58using namespace std;
59
60
112/*
113 Curvature estimation from the length of the most centered maximal segments
114 @param h grid step
115 @param itb begin iterator on points
116 @param ite end iterator on points
117 @param ito output iterator on curvature
118 */
119template<typename I, typename O>
120void estimationFromLength( double h, const I& itb, const I& ite, const O& ito )
121{
122 typedef ArithmeticalDSSComputer<I,int,4> SegmentComputer;
123 SegmentComputer sc;
124 typedef CurvatureFromDSSLengthEstimator<SegmentComputer> SCEstimator;
125 SCEstimator f;
126 typedef MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator> Estimator;
127 Estimator CurvatureEstimator(sc, f);
128
129 CurvatureEstimator.eval( itb, ite, ito, h );
130}
131
132/*
133 Curvature estimation from the length and width
134 of the most centered maximal segments
135 @param h grid step
136 @param itb begin iterator on points
137 @param ite end iterator on points
138 @param ito output iterator on curvature
139 */
140template<typename I, typename O>
141void estimationFromLengthAndWidth( double h, const I& itb, const I& ite, const O& ito )
142{
143 typedef ArithmeticalDSSComputer<I,int,4> SegmentComputer;
144 SegmentComputer sc;
145 typedef CurvatureFromDSSEstimator<SegmentComputer> SCEstimator;
146 SCEstimator f;
147 typedef MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator> Estimator;
148 Estimator CurvatureEstimator(sc, f);
149
150 CurvatureEstimator.eval( itb, ite, ito, h );
151}
152
153
155
156int main( int argc, char** argv )
157{
158 // parse command line CLI ----------------------------------------------
159 CLI::App app;
160 string fileName;
161 double h {1.0};
162
163 app.description("Estimates curvature using length of most centered segment computers.\n Typical use example:\n \t curvatureMCMS [options] --input <fileName>\n");
164 app.add_option("-i,--input, 1",fileName,"Input FreemanChain file name")->required()->check(CLI::ExistingFile);
165 app.add_option("--GridStep", h, "Grid step");
166
167 app.get_formatter()->column_width(40);
168 CLI11_PARSE(app, argc, argv);
169 // END parse command line using CLI ----------------------------------------------
170
171 typedef Z2i::Space Space;
172 typedef Space::Point Point;
173 typedef Space::Integer Integer;
174 typedef Z2i::KSpace KSpace;
175 typedef FreemanChain<Integer> FreemanChain;
176
177 vector< FreemanChain > vectFcs = PointListReader< Point >::getFreemanChainsFromFile<Integer> (fileName);
178
179 for(unsigned int i=0; i<vectFcs.size(); i++){
180
181 // Freeman chain
182 FreemanChain fc = vectFcs.at(i);
183 // Create GridCurve
184 GridCurve<> gridcurve;
185 gridcurve.initFromPointsRange( fc.begin(), fc.end() );
186
187 cout << "# grid curve " << i+1 << "/"
188 << gridcurve.size() << " "
189 << ( (gridcurve.isClosed())?"closed":"open" ) << endl;
190
191 // Create range of incident points
192 typedef GridCurve<KSpace>::PointsRange Range;
193 Range r = gridcurve.getPointsRange();//building range
194
195 // Estimation
196 cout << "# Curvature estimation from maximal segments" << endl;
197 std::vector<double> estimations1;
198 std::vector<double> estimations2;
199 if (gridcurve.isOpen())
200 {
201 cout << "# open grid curve" << endl;
202 estimationFromLength( h, r.begin(), r.end(), back_inserter(estimations1) );
203 estimationFromLengthAndWidth( h, r.begin(), r.end(), back_inserter(estimations2) );
204 }
205 else
206 {
207 cout << "# closed grid curve" << endl;
208 estimationFromLength( h, r.c(), r.c(), back_inserter(estimations1) );
209 estimationFromLengthAndWidth( h, r.c(), r.c(), back_inserter(estimations2) );
210 }
211
212 // Output
213 cout << "# id curvatureFromLength curvatureFromLengthAndWidth" << endl;
214 unsigned int j = 0;
215 for ( Range::ConstIterator it = r.begin(), itEnd = r.end();
216 it != itEnd; ++it, ++j ) {
217cout << j << setprecision( 15 )
218 << " " << estimations1[ j ]
219 << " " << estimations2[ j ] << endl;
220 }
221
222 }
223
224
225 return 0;
226}
227
Definition ATu0v1.h:57