Files Classes Functions Hierarchy
00001 #include <cassert> 00002 #include <iostream> 00003 #include <vector> 00004 using namespace std; 00005 00006 #include <aclock.h> 00007 #include <commandline.h> 00008 #include <halfspaceD3.h> 00009 #include <halfspaceD3indexed.h> 00010 #include <halfspaceD3indexedfull.h> 00011 #include <halfspaceD3test.h> 00012 #include <point.h> 00013 #include <random.h> 00014 00015 00016 void halfspaceD3test::test01() 00017 { 00018 typedef point3<double> pt3; 00019 00020 pt3 p0(0.0,0.0,0.0); 00021 pt3 p1(0.0,0.0,1.0); 00022 pt3 p2(1.0,0.0,0.0); 00023 00024 00025 halfspaceD3<pt3,double> h1(p0,p1,p2); 00026 00027 cout << endl; 00028 cout << "Half space (plane) from the ordered points." << endl; 00029 cout << SHOW(p0) << endl; 00030 cout << SHOW(p1) << endl; 00031 cout << SHOW(p2) << endl; 00032 cout << SHOW(h1.normal) << endl; 00033 00034 cout << "Enter a point: "; 00035 00036 pt3 p; 00037 cin >> p; 00038 00039 cout << SHOW(h1.isInside(p)) << endl; 00040 cout << SHOW(h1.isInsideOrOnBoundary(p)) << endl; 00041 00042 } 00043 00044 void halfspaceD3test::test02() 00045 { 00046 typedef point3<double> pt3; 00047 00048 pt3 p0(0.0,0.0,0.0); 00049 pt3 p1(0.0,0.0,1.0); 00050 pt3 p2(1.0,0.0,0.0); 00051 halfspaceD3<pt3,double> h1(p0,p1,p2); 00052 00053 cout << endl; 00054 cout << "Half space (plane) from the ordered points." << endl; 00055 cout << SHOW(p0) << endl; 00056 cout << SHOW(p1) << endl; 00057 cout << SHOW(p2) << endl; 00058 00059 cout << SHOW(h1.normal) << endl; 00060 00061 cout << "Enter a point: "; 00062 00063 pt3 p; 00064 cin >> p; 00065 00066 cout << SHOW(h1.distancefromhalfspace(p)) << endl; 00067 00068 00069 } 00070 00071 void halfspaceD3test::test03(int argc, char** argv) 00072 { 00073 typedef point3<double> pt3; 00074 00075 random11<> r; 00076 00077 pt3 pts0[3] = 00078 { 00079 pt3(r(),r(),r()), 00080 pt3(r(),r(),r()), 00081 pt3(r(),r(),r()) 00082 // pt3(0.0,0.0,0.0), 00083 // pt3(0.0,0.0,1.0), 00084 // pt3(1.0,0.0,0.0) 00085 }; 00086 00087 halfspaceD3<pt3,double> h1(pts0,0,1,2); 00088 cout << SHOW(sizeof(h1)) << endl; 00089 00090 halfspaceD3indexed<pt3,double,uint> h2(pts0,0,1,2); 00091 cout << SHOW(sizeof(h2)) << endl; 00092 00093 halfspaceD3indexedfull<pt3,double,uint> h3(pts0,0,1,2); 00094 cout << SHOW(sizeof(h3)) << endl; 00095 00096 00097 commandline cmd(argc,argv); 00098 00099 uint N(1000); 00100 cmd.mapvar(N,"N"); 00101 00102 vector< pt3 > pts(N); 00103 for (uint i=0; i<N; ++i) 00104 pts[i] = pt3(r(),r(),r()); 00105 00106 uint count[3]; 00107 00108 partitionspace<pt3>* part[3]; 00109 part[0] = & h1; 00110 part[1] = & h2; 00111 part[2] = & h3; 00112 00113 for (uint k=0; k<3; ++k) 00114 { 00115 count[k]=0; 00116 00117 aclock ac; 00118 ac.measure(); 00119 00120 for (uint i=0; i<N; ++i) 00121 { 00122 if ( part[k]->isInside( pts[i] ) ) 00123 ++count[k]; 00124 } 00125 00126 ac.measure(); 00127 cout << "The event took " << ac.diff_ms() << "ms" << endl; 00128 } 00129 00130 cout << SHOW(count[0]) << endl; 00131 00132 assert(count[0]==count[1]); 00133 } 00134 00135 00136
1.5.8