mtest.cc

 1 const char *help = "\
 2 progname: mtest.cc\n\
 3 code2html: This program tests matrix2D class methods.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Dan Sunday (http:www.softsurfer.com) and Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "general.h"
 8 #include "Matrix2D.h"
 9 #include "CmdLine.h"
10 
11 using namespace Torch;
12 
13 int main(int argc, char **argv)
14 {
15  	real x1, y1;
16  	real x2, y2;
17 	bool verbose;
18 
19 	// Construct the command line
20   	CmdLine cmd;
21 	cmd.setBOption("write log", false);
22 	
23   	// Put the help line at the beginning
24   	cmd.info(help);
25 
26   	cmd.addText("\nArguments:");
27   	cmd.addRCmdArg("x1", &x1, "x1");
28   	cmd.addRCmdArg("y1", &y1, "y1");
29   	cmd.addRCmdArg("x2", &x2, "x2");
30   	cmd.addRCmdArg("y2", &y2, "y2");
31   	cmd.addText("\nOptions:");
32   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
33 
34 	cmd.read(argc, argv);
35 
36 	Matrix2D v;
37 
38 	v.ptr[0][0] = x1; v.ptr[0][1] = x2;
39 	v.ptr[1][0] = y1; v.ptr[1][1] = y2;
40 
41 	print("v = %s\n", v.sprint());
42 
43 	Matrix2D u;
44 	Matrix2D w(1, 0, 0, 1);
45 	
46 	print("w = %s\n", w.sprint());
47 
48 	// test operators
49 	u = -v;			print("-v \t\t= %s\n", u.sprint());
50 	u = 2*v;		print("2*v \t\t= %s\n", u.sprint());
51 	u = v + w;		print("v + w \t\t= %s\n", u.sprint());
52 	u = (v + w)/2;		print("(v + w)/2 \t= %s\n", u.sprint());
53 	u = v - w;		print("v - w \t\t= %s\n", u.sprint());
54 	u = (v - w)*0.5;	print("(v - w)*0.5 \t= %s\n", u.sprint());
55 	//a = v * w;		print("v * w = %g\n", a);
56 	print("\n");
57 
58 }