00001
00002
00003
00004
00005 #include "spheredistance.h"
00006 #include "adf.h"
00007 #include <string>
00008 #include <stdlib.h>
00009 static double tolerance = 0.001;
00010 static double iso = 0;
00011
00012 static char *options = "hi:t:";
00013 static char *usage_string =
00014 "-t <tolerance> Use a different tolerance. [0.001]\n"
00015 "-i <iso> Achieve tolerance from 0 to iso iso-surfaces. [0]\n"
00016 "\n";
00017
00018 double random1() { return (double)rand() / (double)RAND_MAX;}
00019
00020 static void test_usage(int code, const char * msg=NULL, std::ostream& out= std::cerr)
00021 {
00022 if ( msg )
00023 out << msg << std::endl << std::endl;
00024
00025 out << "Adaptively-Sampled Distance Field test program." << std::endl;
00026 out << "Copyright (C) 2001 Steve Zelinka. All rights reserved." << std::endl;
00027 out << "This software is NOT for public distribution." << std::endl;
00028
00029 out << std::endl << "Usage: adftest <options>";
00030 out << std::endl;
00031 out << "-h This message." << std::endl;
00032 out << "-t <tolerance> Use a difference tolerance. [0.001]" << std::endl;
00033 out << "-i <iso> Achieve tolerance from 0 to <iso> away. [0]\n";
00034
00035 exit(code);
00036 }
00037
00038
00039 static int test_cmdline_option(int argc, char **argv, int& index)
00040 {
00041 std::string opt = argv[index];
00042 if ( opt == "-h" )
00043 test_usage(0);
00044 else if ( opt == "-t" )
00045 tolerance = atof(argv[++index]);
00046 else if ( opt == "-i" )
00047 iso = atof(argv[++index]);
00048 else
00049 return 0;
00050
00051 ++index;
00052 return 1;
00053 }
00054
00055
00056 int main(int argc, char *argv[])
00057 {
00058 int i = 1;
00059
00060 while( i < argc )
00061 if ( !test_cmdline_option(i, argv, i) )
00062 test_usage(0, "Invalid option");
00063
00064 SphereDistance sd(gmVector3(0, 0, 0), 0.4);
00065 ADF adf(&sd, iso);
00066 ADFRefiner refiner;
00067 refiner.refine(&adf, tolerance);
00068
00069 ADFPruner pruner;
00070 pruner.prune(&adf);
00071
00072 ADFAnalyzer analyzer;
00073 analyzer.collect_statistics(&adf);
00074 analyzer.report_statistics();
00075
00076 double worst = 0;
00077 double avgbad = 0;
00078 double avg = 0;
00079 int bad = 0;
00080 for( i=0; i<10000; i++ )
00081 {
00082 gmVector3 p(random1()-0.5, random1()-0.5, random1()-0.5);
00083 double d = fabs(adf.get_distance(p) - sd.get_distance(p));
00084 if ( d > tolerance )
00085 {
00086 avgbad += d;
00087 bad++;
00088 }
00089 avg += d;
00090 if ( d > worst )
00091 worst = d;
00092 }
00093
00094 std::cout << bad << " bad tests.\n";
00095 std::cout << worst << " worst deviation.\n";
00096 std::cout << avg/10000 << " average deviation.\n";
00097 std::cout << avgbad/bad << " average deviation in bad samples.\n";
00098
00099
00100
00101 return 1;
00102 }