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