29 #include <DGtal/base/Common.h>
30 #include <DGtal/io/readers/GenericReader.h>
31 #include <DGtal/io/writers/GenericWriter.h>
32 #include <DGtal/helpers/StdDefs.h>
33 #include <DGtal/images/Image.h>
34 #include <DGtal/images/ImageSelector.h>
35 #include <DGtal/images/ConstImageAdapter.h>
36 #include <DGtal/images/RigidTransformation3D.h>
41 using namespace DGtal;
43 using namespace functors;
79 int main(
int argc,
char**argv)
85 std::string outputFileName;
88 double ox {0}, oy {0}, oz {0};
89 double ax {1}, ay {0}, az {0};
90 double tx {0}, ty {0}, tz {0};
92 app.description(
"Apply rigid transformation on a given volumic image.\n Typical use example:\n \t rigidTrans3D <RawFileName> <VolOutputFileName> --ox 1.0 --oy 1.0 --oz 1 -a 1.2 --ax 1 --ay 1 --az 0 --tx 1 --ty 0 --tz 0 --m <forward|backward>\n");
93 app.add_option(
"-i,--input,1",filename,
"Input file.")->required()->check(CLI::ExistingFile);
94 app.add_option(
"-o,--output,2",outputFileName,
"Output file.")->required();
95 app.add_option(
"-m,--model",model,
"Transformation model: backward, forward.")->required();
96 app.add_option(
"-a,--angle",angle,
"Rotation angle in radians (default 0)",
true);
97 app.add_option(
"--ox",ox,
"X coordinate of origin (default 0)",
true);
98 app.add_option(
"--oy",oy,
"Y coordinate of origin (default 0)",
true);
99 app.add_option(
"--oz",oz,
"Z coordinate of origin (default 0)",
true);
100 app.add_option(
"--ax",ax,
"X component of rotation axis (default 1)",
true);
101 app.add_option(
"--ay",ay,
"Y component of rotation axis (default 0)",
true);
102 app.add_option(
"--az",az,
"Z component of rotation axis (default 0)",
true);
103 app.add_option(
"--tx",tx,
"X component of translation vector (default 0)",
true);
104 app.add_option(
"--ty",ty,
"Y component of translation vector (default 0)",
true);
105 app.add_option(
"--tz",tz,
"Y component of translation vector (default 0)",
true);
107 app.get_formatter()->column_width(40);
108 CLI11_PARSE(app, argc, argv);
111 typedef ImageSelector<Domain, unsigned char >::Type Image;
112 typedef ForwardRigidTransformation3D < Space > ForwardTrans;
113 typedef BackwardRigidTransformation3D < Space > BackwardTrans;
114 typedef ConstImageAdapter<Image, Domain, BackwardTrans, Image::Value, Identity > MyImageBackwardAdapter;
115 typedef DomainRigidTransformation3D < Domain, ForwardTrans > MyTransformedDomain;
116 typedef MyTransformedDomain::Bounds Bounds;
118 Image image = GenericReader <Image, 3>::import(filename);
119 ForwardTrans forwardTrans( RealPoint ( ox, oy, oz ), RealPoint ( ax, ay, az ), angle, RealVector( tx, ty, tz ) );
120 BackwardTrans backwardTrans( RealPoint ( ox, oy, oz ), RealPoint ( ax, ay, az ), angle, RealVector( tx, ty, tz ) );
121 MyTransformedDomain domainForwardTrans ( forwardTrans );
122 Bounds bounds = domainForwardTrans ( image.domain() );
123 Domain transformedDomain ( bounds.first, bounds.second );
126 if ( model ==
"forward" )
128 Image forwardTransformedImage ( transformedDomain );
129 for ( Domain::ConstIterator it = image.domain().begin(); it != image.domain().end(); ++it )
131 forwardTransformedImage.setValue ( forwardTrans ( *it ), image ( *it ) );
133 GenericWriter<Image, 3, unsigned char, Identity>::exportFile(outputFileName, forwardTransformedImage,
" ", idD);
137 MyImageBackwardAdapter backwardImageAdapter ( image, transformedDomain , backwardTrans, idD );
138 GenericWriter<MyImageBackwardAdapter, 3, unsigned char, Identity>::exportFile(outputFileName, backwardImageAdapter,
" ", idD);