1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2016 Imperial College London
5  * Copyright 2016 Christian Ledig
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #include "mirtk/Common.h"
21 #include "mirtk/Options.h"
22 
23 #include "mirtk/Matrix.h"
24 #include "mirtk/HomogeneousTransformation.h"
25 
26 using namespace mirtk;
27 
28 
29 // ===========================================================================
30 // Help
31 // ===========================================================================
32 
33 // ---------------------------------------------------------------------------
PrintHelp(const char * name)34 void PrintHelp(const char *name)
35 {
36   cout << endl;
37   cout << "Usage: " << name << " <dofin> <dofout>" << endl;
38   cout << endl;
39   cout << "Description:" << endl;
40   cout << "  This command bisects a rigid or affine transformation by calculating the" << endl;
41   cout << "  matrix square root of the transformation matrix." << endl;
42   PrintStandardOptions(cout);
43   cout << endl;
44 }
45 
46 // ===========================================================================
47 // Main
48 // ===========================================================================
49 
50 // ---------------------------------------------------------------------------
main(int argc,char * argv[])51 int main(int argc, char *argv[])
52 {
53   REQUIRES_POSARGS(2);
54   UniquePtr<Transformation> dof(Transformation::New(POSARG(1)));
55   HomogeneousTransformation *lin = dynamic_cast<HomogeneousTransformation *>(dof.get());
56   if (!lin) {
57     FatalError("Input transformation must be either Rigid, Similarity, or Affine");
58   }
59   lin->PutMatrix(lin->GetMatrix().Sqrt());
60   lin->Write(POSARG(2));
61   return 0;
62 }
63