testPoint3D.cc

 1 const char *help = "\
 2 progname: testPoint3D.cc\n\
 3 code2html: This program tests Point3D 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 "Point3D.h"
 9 #include "Vector3D.h"
10 #include "CmdLine.h"
11 
12 using namespace Torch;
13 
14 int main(int argc, char **argv)
15 {
16  	real x1, y1, z1;
17  	real x2, y2, z2;
18 	bool verbose;
19 
20 	// Construct the command line
21   	CmdLine cmd;
22 	cmd.setBOption("write log", false);
23 	
24   	// Put the help line at the beginning
25   	cmd.info(help);
26 
27   	cmd.addText("\nArguments:");
28   	cmd.addRCmdArg("x1", &x1, "x1");
29   	cmd.addRCmdArg("y1", &y1, "y1");
30   	cmd.addRCmdArg("z1", &z1, "z1");
31   	cmd.addRCmdArg("x2", &x2, "x2");
32   	cmd.addRCmdArg("y2", &y2, "y2");
33   	cmd.addRCmdArg("z2", &z2, "z2");
34   	cmd.addText("\nOptions:");
35   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
36 
37 	cmd.read(argc, argv);
38 
39 	double	 a, c[3];
40 	Point3D	 P1(1), P2(0,1);
41 	Point3D	 Q[3], R;
42 	Vector3D v, w;
43 
44 	// output preset coords of P1 and P2
45 	print("Initial P1 = %s\n", P1.sprint());
46 	print("Initial P2 = %s\n", P2.sprint());
47 
48 	// input new values for Points P1 and P2
49 	P1.x = x1;
50 	P1.y = y1;
51 	P1.z = z1;
52 
53 	P2.x = x2;
54 	P2.y = y2;
55 	P2.z = z2;
56 
57 	print("P1 = %s\n", P1.sprint());
58 	print("P2 = %s\n", P2.sprint());
59 	
60 	// test all operators
61 	v = P1 - P2;		print("P1 - P2 = %s\n", v.sprint());
62 	R = 2*P1;		print("2*P1 = %s\n", R.sprint());
63 	R = P1/2;		print("P1/2 = %s\n", R.sprint());
64 	R = P1 + P2;		print("P1 + P2 = %s\n", R.sprint());
65 	R = 2*P1 + P2;		print("2*P1 + P2 = %s\n", R.sprint());
66 	R = (P1 + P2)/2;	print("(P1 + P2)/2 = %s\n", R.sprint());
67 	R = (P1 + P2)*0.5;	print("(P1 + P2)*0.5 = %s\n", R.sprint());
68 	print("\n");
69 
70 	// test all functions
71 	a = d(P1,P2);		print("d(P1,P2) = %g\n", a);
72 	a = d2(P1,P2);		print("d2(P1,P2) = %g\n", a);
73 
74 	c[0]= 0.5; c[1]= 0.5;	print("c[]= {%g, %g}\n", c[0], c[1]);
75 	Q[0]= P1;  Q[1]= P2;	print("Q[]= {%s, %s}\n", Q[0].sprint(), Q[1].sprint());
76 	R = asum(2,c,Q);	print("asum(2,c,Q) = %s\n", R.sprint());
77 }