user_eg3_r.cpp
Go to the documentation of this file.
1 #
2 
5 #include "libqhullcpp/QhullQh.h"
10 #include "libqhullcpp/Qhull.h"
11 
12 #include <cstdio> /* for printf() of help message */
13 #include <ostream>
14 #include <stdexcept>
15 
16 using std::cerr;
17 using std::cin;
18 using std::cout;
19 using std::endl;
20 
21 using orgQhull::Qhull;
25 using orgQhull::QhullQh;
29 
30 int main(int argc, char **argv);
31 int user_eg3(int argc, char **argv);
32 
33 char prompt[]= "\n\
34 user_eg3 -- demonstrate calling rbox and qhull from C++.\n\
35 \n\
36 user_eg3 is statically linked to reentrant qhull. If user_eg3\n\
37 fails immediately, it is probably linked to the non-reentrant qhull.\n\
38 Try 'user_eg3 rbox qhull \"T1\"'\n\
39 \n\
40  eg-100 Run the example in qh-code.htm\n\
41  rbox \"200 D4\" ... Generate points from rbox\n\
42  qhull \"d p\" ... Run qhull and produce output\n\
43  qhull-cout \"o\" ... Run qhull and produce output to cout\n\
44  qhull \"T1\" ... Run qhull with level-1 trace to cerr\n\
45  facets Print facets when done\n\
46 \n\
47 For example\n\
48  user_eg3 rbox qhull\n\
49  user_eg3 rbox qhull d\n\
50  user_eg3 rbox \"10 D2\" \"2 D2\" qhull \"s p\" facets\n\
51 \n\
52 ";
53 
54 
55 /*--------------------------------------------
56 -user_eg3- main procedure of user_eg3 application
57 */
58 int main(int argc, char **argv) {
59 
61 
62  if(argc==1){
63  cout << prompt;
64  return 1;
65  }
66  try{
67  return user_eg3(argc, argv);
68  }catch(QhullError &e){
69  cerr << e.what() << std::endl;
70  return e.errorCode();
71  }
72 }//main
73 
74 int user_eg3(int argc, char **argv)
75 {
76  if(strcmp(argv[1], "eg-100")==0){
77  RboxPoints rbox("100");
78  Qhull q(rbox, "");
79  QhullFacetList facets= q.facetList();
80  cout << facets;
81  return 0;
82  }
83  bool printFacets= false;
85  Qhull qhull;
86  int readingRbox= 0;
87  int readingQhull= 0;
88  for(int i=1; i<argc; i++){
89  if(strcmp(argv[i], "rbox")==0){
90  if(readingRbox!=0 || readingQhull!=0){
91  cerr << "user_eg3 -- \"rbox\" must be first" << endl;
92  return 1;
93  }
94  readingRbox++;
95  }else if(strcmp(argv[i], "qhull")==0
96  || strcmp(argv[i], "qhull-cout")==0){
97  if(readingQhull){
98  cerr << "user_eg3 -- only one \"qhull\" or \"qhull-cout\" allowed." << endl;
99  return 1;
100  }
101  if(strcmp(argv[i], "qhull-cout")==0){
102  qhull.setOutputStream(&cout);
103  }
104  if(rbox.isEmpty()){
105  if(readingRbox){
106  rbox.appendPoints("10 D2");
107  }else{
108  cerr << "Enter dimension count coordinates. End with ^Z (Windows) or ^D (Unix).\n";
109  rbox.appendPoints(cin);
110  }
111  }
112  readingQhull++;
113  readingRbox= 0;
114  }else if(strcmp(argv[i], "facets")==0){
115  printFacets= true;
116  }else if(readingRbox){
117  readingRbox++;
118  cerr << "rbox " << argv[i] << endl;
119  rbox.appendPoints(argv[i]);
120  if(rbox.hasRboxMessage()){
121  cerr << "user_eg3 " << argv[i] << " -- " << rbox.rboxMessage();
122  return rbox.rboxStatus();
123  }
124  }else if(readingQhull){
125  if(readingQhull==1){
126  qhull.runQhull(rbox, argv[i]);
127  qhull.outputQhull();
128  }else{
129  qhull.outputQhull(argv[i]);
130  }
131  readingQhull++;
132  if(qhull.hasQhullMessage()){
133  cerr << "\nResults of " << argv[i] << "\n" << qhull.qhullMessage();
134  qhull.clearQhullMessage();
135  }
136  }else{
137  cerr << "user_eg3 error: Expecting qhull, qhull-cout, or rbox. Got " << argv[i] << endl;
138  return 1;
139  }
140  }//foreach argv
141  if(readingRbox){
142  cout << rbox;
143  return 0;
144  }
145  if(readingQhull==1){ // e.g., rbox 10 qhull
146  qhull.runQhull(rbox, "");
147  qhull.outputQhull();
148  if(qhull.hasQhullMessage()){
149  cerr << "\nResults of qhull\n" << qhull.qhullMessage();
150  qhull.clearQhullMessage();
151  }
152  }
153  if(qhull.hasOutputStream()){
154  return 0;
155  }
156  if(printFacets){
157  QhullFacetList facets= qhull.facetList();
158  cout << "\nFacets created by Qhull::runQhull()\n" << facets;
159  }
160  return 0;
161 }//user_eg3
162 
QhullFacet.h
orgQhull::QhullVertexSet
Definition: QhullVertexSet.h:33
QHULL_LIB_CHECK
#define QHULL_LIB_CHECK
Definition: libqhull.h:462
orgQhull::RoadError::what
virtual const char * what() const
Definition: RoadError.cpp:137
main
int main(int argc, char **argv)
Definition: user_eg3_r.cpp:58
orgQhull::Qhull::hasOutputStream
bool hasOutputStream() const
Definition: Qhull.h:81
orgQhull::Qhull::runQhull
void runQhull(const RboxPoints &rboxPoints, const char *qhullCommand2)
For qhull commands, see http://www.qhull.org/html/qhull.htm or html/qhull.htm.
Definition: Qhull.cpp:256
orgQhull::Qhull::outputQhull
void outputQhull()
Definition: Qhull.cpp:211
Qhull.h
orgQhull::QhullVertex
Definition: QhullVertex.h:48
QhullFacetList.h
rbox
rboxT rbox
Definition: rboxlib.c:65
orgQhull::QhullFacetList
Definition: QhullFacetList.h:41
orgQhull::Qhull::qhullMessage
std::string qhullMessage() const
Definition: Qhull.h:100
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
orgQhull::Qhull::clearQhullMessage
void clearQhullMessage()
Definition: Qhull.h:97
orgQhull::QhullQh
POD type equivalent to qhT. No virtual members.
Definition: QhullQh.h:58
q
q
orgQhull::Qhull::facetList
QhullFacetList facetList() const
Definition: Qhull.cpp:186
orgQhull::Qhull::setOutputStream
void setOutputStream(std::ostream *os)
Definition: Qhull.h:105
orgQhull::QhullFacet
A QhullFacet is the C++ equivalent to Qhull's facetT*.
Definition: QhullFacet.h:43
orgQhull::RboxPoints
Definition: RboxPoints.h:37
prompt
char prompt[]
Definition: user_eg3_r.cpp:33
QhullQh.h
orgQhull::QhullError
Definition: QhullError.h:26
QhullVertex.h
user_eg3
int user_eg3(int argc, char **argv)
Definition: user_eg3_r.cpp:74
RboxPoints.h
QhullError.h
orgQhull::RoadError::errorCode
int errorCode() const
Definition: RoadError.h:76
orgQhull::Qhull::hasQhullMessage
bool hasQhullMessage() const
Definition: Qhull.h:101
QhullLinkedList.h


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:15