user_eg3.cpp
Go to the documentation of this file.
00001 #//! user_eg3.cpp -- Invoke rbox and qhull from C++
00002 
00003 #include "RboxPoints.h"
00004 #include "QhullError.h"
00005 #include "QhullQh.h"
00006 #include "QhullFacet.h"
00007 #include "QhullFacetList.h"
00008 #include "QhullLinkedList.h"
00009 #include "QhullVertex.h"
00010 #include "Qhull.h"
00011 
00012 #include <cstdio>   /* for printf() of help message */
00013 #include <ostream>
00014 
00015 using std::cerr;
00016 using std::cin;
00017 using std::cout;
00018 using std::endl;
00019 
00020 using orgQhull::Qhull;
00021 using orgQhull::QhullError;
00022 using orgQhull::QhullFacet;
00023 using orgQhull::QhullFacetList;
00024 using orgQhull::QhullQh;
00025 using orgQhull::RboxPoints;
00026 using orgQhull::QhullVertex;
00027 using orgQhull::QhullVertexSet;
00028 
00029 int main(int argc, char **argv);
00030 int user_eg3(int argc, char **argv);
00031 
00032 char prompt[]= "\n\
00033 user_eg3 -- demonstrate calling rbox and qhull from C++.\n\
00034 \n\
00035   eg-100                       Run the example in qh-code.htm\n\
00036   rbox \"200 D4\" ...            Generate points from rbox\n\
00037   qhull \"d p\" ...              Run qhull and produce output\n\
00038   qhull-cout \"o\" ...           Run qhull and produce output to cout\n\
00039   facets                       Print facets when done\n\
00040 \n\
00041 For example\n\
00042   user_eg3 rbox qhull\n\
00043   user_eg3 rbox qhull d\n\
00044   user_eg3 rbox \"10 D2\"  \"2 D2\" qhull  \"s p\" facets\n\
00045 \n\
00046 ";
00047 
00048 
00049 /*--------------------------------------------
00050 -user_eg3-  main procedure of user_eg3 application
00051 */
00052 int main(int argc, char **argv) {
00053 
00054     if(argc==1){
00055         cout << prompt;
00056         return 1;
00057     }
00058     try{
00059         return user_eg3(argc, argv);
00060     }catch(QhullError &e){
00061         cerr << e.what() << std::endl;
00062         return e.errorCode();
00063     }
00064 }//main
00065 
00066 int user_eg3(int argc, char **argv)
00067 {
00068     bool printFacets= false;
00069     if(strcmp(argv[1], "eg-100")==0){
00070         RboxPoints rbox;
00071         rbox.appendPoints("100");
00072         Qhull qhull;
00073         qhull.runQhull(rbox, "");
00074         QhullFacetList facets= qhull.facetList();
00075         cout << facets;
00076         return 0;
00077     }
00078     RboxPoints rbox;
00079     Qhull qhull;
00080     int readingRbox= 0;
00081     int readingQhull= 0;
00082     for(int i=1; i<argc; i++){
00083         if(strcmp(argv[i], "rbox")==0){
00084             if(readingRbox!=0 || readingQhull!=0){
00085                 cerr << "user_eg3 -- \"rbox\" must be first" << endl;
00086                 return 1;
00087             }
00088             readingRbox++;
00089         }else if(strcmp(argv[i], "qhull")==0
00090         || strcmp(argv[i], "qhull-cout")==0){
00091             if(readingQhull){
00092                 cerr << "user_eg3 -- only one \"qhull\" or \"qhull-cout\" allowed." << endl;
00093                 return 1;
00094             }
00095             if(strcmp(argv[i], "qhull-cout")==0){
00096                 qhull.setOutputStream(&cout);
00097             }
00098             if(rbox.isEmpty()){
00099                 if(readingRbox){
00100                     rbox.appendPoints("10 D2");
00101                 }else{
00102                     cerr << "Enter dimension count coordinates.  End with ^Z (Windows) or ^D (Unix).\n";
00103                     rbox.appendPoints(cin);
00104                 }
00105             }
00106             readingQhull++;
00107             readingRbox= 0;
00108         }else if(strcmp(argv[i], "facets")==0){
00109             printFacets= true;
00110         }else if(readingRbox){
00111             readingRbox++;
00112             cerr << "rbox " << argv[i] << endl;
00113             rbox.appendPoints(argv[i]);
00114             if(rbox.hasRboxMessage()){
00115                 cerr << "user_eg3 " << argv[i] << " -- " << rbox.rboxMessage();
00116                 return rbox.rboxStatus();
00117             }
00118         }else if(readingQhull){
00119             if(readingQhull==1){
00120                 qhull.runQhull(rbox, argv[i]);
00121                 qhull.outputQhull();
00122             }else{
00123                 qhull.outputQhull(argv[i]);
00124             }
00125             readingQhull++;
00126             if(qhull.hasQhullMessage()){
00127                 cerr << "\nResults of " << argv[i] << "\n" << qhull.qhullMessage();
00128                 qhull.clearQhullMessage();
00129             }
00130         }else{
00131             cerr << "user_eg3 error: Expecting qhull, qhull-cout, or rbox.  Got " << argv[i] << endl;
00132             return 1;
00133         }
00134     }//foreach argv
00135     if(readingRbox){
00136         cout << rbox;
00137         return 0;
00138     }
00139     if(readingQhull==1){ // e.g., rbox 10 qhull
00140         qhull.runQhull(rbox, "");
00141         qhull.outputQhull();
00142         if(qhull.hasQhullMessage()){
00143             cerr << "\nResults of qhull\n" << qhull.qhullMessage();
00144             qhull.clearQhullMessage();
00145         }
00146     }
00147     if(qhull.useOutputStream){
00148         return 0;
00149     }
00150     if(printFacets){
00151         QhullFacetList facets= qhull.facetList();
00152         cout << "\nFacets created by Qhull::runQhull()\n" << facets;
00153     }
00154     return 0;
00155 }//user_eg3
00156 


libqhull-ours
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:11