13 #include "QhullError.h"
15 #include "QhullStat.h"
29 #pragma warning( disable : 4611)
30 #pragma warning( disable : 4996)
36 const double QhullQh::
37 default_factor_epsilon= 1.0;
44 : qhull_status(qh_ERRnone)
48 , factor_epsilon(QhullQh::default_factor_epsilon)
49 , use_output_stream(false)
52 qh_meminit(
this, NULL);
53 qh_initstatistics(
this);
54 qh_initqhull_start2(
this, NULL, NULL, qh_FILEstderr);
55 this->ISqhullQh= True;
61 qh_freeqhull(
this, qh_ALL);
72 checkAndFreeQhullMemory()
75 qh_freeqhull(
this, qh_ALL);
78 qh_freeqhull(
this, !qh_ALL);
81 qh_memfreeshort(
this, &curlong, &totlong);
82 if (curlong || totlong)
83 throw QhullError(10026,
"Qhull error: qhull did not free %d bytes of long memory (%d pieces).", totlong, curlong);
90 appendQhullMessage(
const string &
s)
92 if(output_stream && use_output_stream && this->USEstdout){
94 }
else if(error_stream){
105 qhull_status= qh_ERRnone;
106 qhull_message.clear();
107 RoadError::clearGlobalLog();
112 hasQhullMessage()
const
114 return (!qhull_message.empty() || qhull_status!=qh_ERRnone);
119 maybeThrowQhullMessage(
int exitCode)
122 if(qhull_message.size()>0){
123 qhull_message.append(
"\n");
125 if(exitCode || qhull_status==qh_ERRnone){
128 qhull_message.append(
"QH10073: ");
130 qhull_message.append(
"Cannot call maybeThrowQhullMessage() from QH_TRY_(). Or missing 'qh->NOerrexit=true;' after QH_TRY_(){...}.");
132 if(qhull_status==qh_ERRnone){
133 qhull_status= exitCode;
135 if(qhull_status!=qh_ERRnone){
136 QhullError e(qhull_status, qhull_message);
143 maybeThrowQhullMessage(
int exitCode,
int noThrow)
throw()
145 QHULL_UNUSED(noThrow);
147 if(qhull_status==qh_ERRnone){
148 qhull_status= exitCode;
150 if(qhull_status!=qh_ERRnone){
151 QhullError e(qhull_status, qhull_message);
152 e.logErrorLastResort();
157 std::string QhullQh::
160 if(qhull_message.empty() && qhull_status!=qh_ERRnone){
161 return "qhull: no message for error. Check cerr or error stream\n";
163 return qhull_message;
174 setErrorStream(ostream *os)
181 setOutputStream(ostream *os)
184 use_output_stream= (os!=0);
202 void qh_fprintf(qhT *qh, FILE *fp,
int msgcode,
const char *fmt, ... ) {
208 qh_fprintf_stderr(10025,
"Qhull error: qh_fprintf called from a Qhull instance without QhullQh defined\n");
211 QhullQh *qhullQh=
static_cast<QhullQh *
>(qh);
213 if(msgcode<MSG_OUTPUT || fp == qh_FILEstderr){
214 if(msgcode>=MSG_ERROR && msgcode<MSG_WARNING){
215 if(qhullQh->qhull_status<MSG_ERROR || qhullQh->qhull_status>=MSG_WARNING){
216 qhullQh->qhull_status= msgcode;
219 char newMessage[MSG_MAXLEN];
221 vsnprintf(newMessage,
sizeof(newMessage), fmt, args);
222 qhullQh->appendQhullMessage(newMessage);
226 if(qhullQh->output_stream && qhullQh->use_output_stream){
227 char newMessage[MSG_MAXLEN];
228 vsnprintf(newMessage,
sizeof(newMessage), fmt, args);
229 *qhullQh->output_stream << newMessage;
234 char newMessage[MSG_MAXLEN];
235 vsnprintf(newMessage,
sizeof(newMessage), fmt, args);
236 qhullQh->appendQhullMessage(newMessage);
std::set< std::string > & s
void qh_fprintf(qhT *qh, FILE *fp, int msgcode, const char *fmt,...)
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.