37 #include "DGtal/base/Common.h"
38 #include "DGtal/helpers/StdDefs.h"
39 #include "DGtal/kernel/BasicPointFunctors.h"
41 #include "DGtal/geometry/curves/parametric/EllipticHelix.h"
42 #include "DGtal/geometry/curves/parametric/Knot_3_1.h"
43 #include "DGtal/geometry/curves/parametric/Knot_3_2.h"
44 #include "DGtal/geometry/curves/parametric/Knot_4_1.h"
45 #include "DGtal/geometry/curves/parametric/Knot_4_3.h"
46 #include "DGtal/geometry/curves/parametric/Knot_5_1.h"
47 #include "DGtal/geometry/curves/parametric/Knot_5_2.h"
48 #include "DGtal/geometry/curves/parametric/Knot_6_2.h"
49 #include "DGtal/geometry/curves/parametric/Knot_7_4.h"
50 #include "DGtal/geometry/curves/parametric/NaiveParametricCurveDigitizer3D.h"
51 #include "DGtal/geometry/curves/parametric/DecoratorParametricCurveTransformation.h"
52 #include "DGtal/images/RigidTransformation3D.h"
54 using namespace DGtal;
127 std::vector<std::string> curves3D;
128 std::vector<std::string> curvesDesc;
136 curves3D.push_back(
"EllipticHelix");
137 curvesDesc.push_back(
"A helix with two axes.");
139 curves3D.push_back(
"Knot_3_1");
140 curvesDesc.push_back(
"A parametric polynomial knot.");
142 curves3D.push_back(
"Knot_3_2");
143 curvesDesc.push_back(
"A parametric knot having period 2 * Pi.");
145 curves3D.push_back(
"Knot_4_1");
146 curvesDesc.push_back(
"A parametric polynomial knot.");
148 curves3D.push_back(
"Knot_4_3");
149 curvesDesc.push_back(
"A parametric knot having period 2 * Pi.");
151 curves3D.push_back(
"Knot_5_1");
152 curvesDesc.push_back(
"A parametric polynomial knot.");
154 curves3D.push_back(
"Knot_5_2");
155 curvesDesc.push_back(
"A parametric knot having period 2 * Pi.");
157 curves3D.push_back(
"Knot_6_2");
158 curvesDesc.push_back(
"A parametric polynomial knot.");
160 curves3D.push_back(
"Knot_7_4");
161 curvesDesc.push_back(
"A parametric polynomial knot.");
170 trace.emphase()<<
"3D Curves:"<<std::endl;
171 for (
unsigned int i = 0; i < curves3D.size(); ++i )
172 trace.info()<<
"\t"<<curves3D[i]<<
"\t" <<curvesDesc[i]<<std::endl;
184 unsigned int checkAndRetrunIndex(
const std::string &curveName)
186 unsigned int pos = 0;
188 while ((pos < curves3D.size()) && (curves3D[pos] != curveName))
191 if ( pos == curves3D.size ( ) )
193 trace.error ( ) <<
"The specified shape has not found.";
194 trace.info ( ) << std::endl;
209 template <
typename Iterator>
222 void save ( Iterator begin, Iterator end,
const std::string outputName )
224 std::ofstream outfile;
225 outfile.open ( outputName +
".dat", std::ofstream::out );
226 for (
auto it = begin; it != end; ++it )
227 outfile << (*it)[0] <<
" " << (*it)[1] <<
" " << (*it)[2] << std::endl;
236 void missingParam(std::string param)
238 trace.error() <<
" Parameter: "<<param<<
" is required..";
239 trace.info()<<std::endl;
245 int main(
int argc,
char** argv )
249 std::string curveName;
250 std::string outputName;
257 unsigned int knext {5};
259 double ox {0}, oy {0}, oz {0};
260 double ax {1}, ay {0}, az {0};
262 app.description(
"Digitizes 3D parametric curves using DGtal library.\n Typical use example:\n \t 3dParametricCurveDigitizer [options] --curve <curve> --param1 <double> --param2 <double> --param3 <double> --tstart <double> --tend <double> --step <double> --output <basename>\n");
263 app.add_option(
"--param1",param1,
"a radius or a scaling factor (default 0)",
true);
264 app.add_option(
"--param2",param2,
"a radius or a scaling factor (default 0)",
true);
265 app.add_option(
"--param3",param3,
"a radius or a scaling factor (default 0)",
true);
266 auto tstartOpt = app.add_option(
"--tstart",tstart,
"start time");
267 auto tendOpt = app.add_option(
"--tend",tend,
"end time");
268 auto stepOpt = app.add_option(
"--step, -s",step,
"step");
269 app.add_option(
"--knext, -k",knext,
"K_NEXT value (default 5)",
true);
270 auto listOpt = app.add_flag(
"--list,-l",
"List all available shapes");
271 auto curveNameOpt = app.add_option(
"--curve,-c",curveName,
"Shape name");
272 app.add_option(
"--angle,-a",angle,
"Rotation angle in radians(default 0)",
true);
273 app.add_option(
"--ox",ox,
"X coordinate of origin (default 0)",
true);
274 app.add_option(
"--oy",oy,
"Y coordinate of origin (default 0)",
true);
275 app.add_option(
"--oz",oz,
"Z coordinate of origin (default 0)",
true);
276 app.add_option(
"--ax",ax,
"X component of rotation axis (default 1)",
true);
277 app.add_option(
"--ay",ay,
"Y component of rotation axis (default 0)",
true);
278 app.add_option(
"--az",az,
"Z component of rotation axis (default 0)",
true);
279 auto outputNameOpt = app.add_option(
"--output,-o",outputName,
"Basename of the output file");
281 app.get_formatter()->column_width(40);
282 CLI11_PARSE(app, argc, argv);
288 if ( listOpt->count() > 0 )
294 if ( curveNameOpt->count() == 0) missingParam(
"--curve");
295 if ( outputNameOpt->count() == 0) missingParam(
"--output");
296 if ( tstartOpt->count() == 0) missingParam(
"--tstart");
297 if ( tendOpt->count() == 0) missingParam(
"--tend");
298 if ( stepOpt->count() == 0) missingParam(
"--step");
300 typedef functors::ForwardRigidTransformation3D < Z3i::Space, Z3i::RealPoint, Z3i::RealPoint, functors::Identity > ForwardTrans;
301 ForwardTrans trans ( Z3i::RealPoint ( ox, oy, oz ), Z3i::RealPoint ( ax, ay, az ), angle, Z3i::RealVector ( 0, 0, 0 ) );
303 unsigned int id = checkAndRetrunIndex ( curveName );
307 typedef EllipticHelix < Z3i::Space > MyHelix;
308 typedef DecoratorParametricCurveTransformation < MyHelix, ForwardTrans > MyRotatedCurve;
309 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
310 typedef typename NaiveParametricCurveDigitizer3D < MyRotatedCurve >::DigitalCurve MyDigitalCurve;
311 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::MetaData MyMetaData;
313 MyDigitalCurve digitalCurve;
314 MyHelix helix ( param1, param2, param3 );
315 MyRotatedCurve rotCurve ( helix, trans );
317 digitize.init ( tstart, tend, step );
318 digitize.setKNext ( knext );
319 digitize.attach ( &rotCurve );
320 digitize.digitize ( std::back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
321 Exporter < MyDigitalCurve::const_iterator >::save ( digitalCurve.begin ( ), digitalCurve.end ( ), outputName );
326 typedef Knot_3_1 < Z3i::Space > MyKnot;
327 typedef DecoratorParametricCurveTransformation < MyKnot, ForwardTrans > MyRotatedCurve;
328 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
329 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::DigitalCurve MyDigitalCurve;
330 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::MetaData MyMetaData;
332 MyDigitalCurve digitalCurve;
333 MyKnot knot ( param1, param2, param3 );
334 MyRotatedCurve rotCurve ( knot, trans );
336 digitize.init ( tstart, tend, step );
337 digitize.setKNext ( knext );
338 digitize.attach ( &rotCurve );
339 digitize.digitize ( std::back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
340 Exporter < MyDigitalCurve::const_iterator >::save ( digitalCurve.begin ( ), digitalCurve.end ( ), outputName );
345 typedef Knot_3_2 < Z3i::Space > MyKnot;
346 typedef DecoratorParametricCurveTransformation < MyKnot, ForwardTrans > MyRotatedCurve;
347 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
348 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::DigitalCurve MyDigitalCurve;
349 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::MetaData MyMetaData;
351 MyDigitalCurve digitalCurve;
352 MyKnot knot ( param1, param2, param3 );
353 MyRotatedCurve rotCurve ( knot, trans );
355 digitize.init ( tstart, tend, step );
356 digitize.setKNext ( knext );
357 digitize.attach ( &rotCurve );
358 digitize.digitize ( std::back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
359 Exporter < MyDigitalCurve::const_iterator >::save ( digitalCurve.begin ( ), digitalCurve.end ( ), outputName );
364 typedef Knot_4_1 < Z3i::Space > MyKnot;
365 typedef DecoratorParametricCurveTransformation < MyKnot, ForwardTrans > MyRotatedCurve;
366 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
367 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::DigitalCurve MyDigitalCurve;
368 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::MetaData MyMetaData;
370 MyDigitalCurve digitalCurve;
371 MyKnot knot ( param1, param2, param3 );
372 MyRotatedCurve rotCurve ( knot, trans );
374 digitize.init ( tstart, tend, step );
375 digitize.setKNext ( knext );
376 digitize.attach ( &rotCurve );
377 digitize.digitize ( std::back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
378 Exporter < MyDigitalCurve::const_iterator >::save ( digitalCurve.begin ( ), digitalCurve.end ( ), outputName );
383 typedef Knot_4_3 < Z3i::Space > MyKnot;
384 typedef DecoratorParametricCurveTransformation < MyKnot, ForwardTrans > MyRotatedCurve;
385 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
386 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::DigitalCurve MyDigitalCurve;
387 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::MetaData MyMetaData;
389 MyDigitalCurve digitalCurve;
390 MyKnot knot ( param1, param2, param3 );
391 MyRotatedCurve rotCurve ( knot, trans );
393 digitize.init ( tstart, tend, step );
394 digitize.setKNext ( knext );
395 digitize.attach ( &rotCurve );
396 digitize.digitize ( std::back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
397 Exporter < MyDigitalCurve::const_iterator >::save ( digitalCurve.begin ( ), digitalCurve.end ( ), outputName );
402 typedef Knot_5_1 < Z3i::Space > MyKnot;
403 typedef DecoratorParametricCurveTransformation < MyKnot, ForwardTrans > MyRotatedCurve;
404 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
405 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::DigitalCurve MyDigitalCurve;
406 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::MetaData MyMetaData;
408 MyDigitalCurve digitalCurve;
409 MyKnot knot ( param1, param2, param3 );
410 MyRotatedCurve rotCurve ( knot, trans );
412 digitize.init ( tstart, tend, step );
413 digitize.setKNext ( knext );
414 digitize.attach ( &rotCurve );
415 digitize.digitize ( std::back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
416 Exporter < MyDigitalCurve::const_iterator >::save ( digitalCurve.begin ( ), digitalCurve.end ( ), outputName );
421 typedef Knot_5_2 < Z3i::Space > MyKnot;
422 typedef DecoratorParametricCurveTransformation < MyKnot, ForwardTrans > MyRotatedCurve;
423 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
424 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::DigitalCurve MyDigitalCurve;
425 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::MetaData MyMetaData;
427 MyDigitalCurve digitalCurve;
428 MyKnot knot ( param1, param2, param3 );
429 MyRotatedCurve rotCurve ( knot, trans );
431 digitize.init ( tstart, tend, step );
432 digitize.setKNext ( knext );
433 digitize.attach ( &rotCurve );
434 digitize.digitize ( std::back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
435 Exporter < MyDigitalCurve::const_iterator >::save ( digitalCurve.begin ( ), digitalCurve.end ( ), outputName );
440 typedef Knot_6_2 < Z3i::Space > MyKnot;
441 typedef DecoratorParametricCurveTransformation < MyKnot, ForwardTrans > MyRotatedCurve;
442 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
443 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::DigitalCurve MyDigitalCurve;
444 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::MetaData MyMetaData;
446 MyDigitalCurve digitalCurve;
447 MyKnot knot ( param1, param2, param3 );
448 MyRotatedCurve rotCurve ( knot, trans );
450 digitize.init ( tstart, tend, step );
451 digitize.setKNext ( knext );
452 digitize.attach ( &rotCurve );
453 digitize.digitize ( std::back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
454 Exporter < MyDigitalCurve::const_iterator >::save ( digitalCurve.begin ( ), digitalCurve.end ( ), outputName );
459 typedef Knot_7_4 < Z3i::Space > MyKnot;
460 typedef DecoratorParametricCurveTransformation < MyKnot, ForwardTrans > MyRotatedCurve;
461 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
462 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::DigitalCurve MyDigitalCurve;
463 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve >::MetaData MyMetaData;
465 MyDigitalCurve digitalCurve;
466 MyKnot knot ( param1, param2, param3 );
467 MyRotatedCurve rotCurve ( knot, trans );
469 digitize.init ( tstart, tend, step );
470 digitize.setKNext ( knext );
471 digitize.attach ( &rotCurve );
472 digitize.digitize ( std::back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
473 Exporter < MyDigitalCurve::const_iterator >::save ( digitalCurve.begin ( ), digitalCurve.end ( ), outputName );