00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "QhullError.h"
00010 #include "RboxPoints.h"
00011
00012 #include <iostream>
00013
00014 using std::cerr;
00015 using std::endl;
00016 using std::istream;
00017 using std::ostream;
00018 using std::ostringstream;
00019 using std::string;
00020 using std::vector;
00021 using std::ws;
00022
00023 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
00024 #pragma warning( disable : 4996) // function was declared deprecated(strcpy, localtime, etc.)
00025 #endif
00026
00027 namespace orgQhull {
00028
00029 #//! RboxPoints -- generate random PointCoordinates for qhull (rbox)
00030
00031 #//Global
00032
00034 RboxPoints *rbox_output= 0;
00035
00036 #//Construct
00037 RboxPoints::
00038 RboxPoints()
00039 : PointCoordinates("rbox")
00040 , rbox_new_count(0)
00041 , rbox_status(qh_ERRnone)
00042 , rbox_message()
00043 {}
00044
00045 RboxPoints::
00046 RboxPoints(const char *rboxCommand)
00047 : PointCoordinates("rbox")
00048 , rbox_new_count(0)
00049 , rbox_status(qh_ERRnone)
00050 , rbox_message()
00051 {
00052 appendPoints(rboxCommand);
00053 }
00054
00055 RboxPoints::
00056 RboxPoints(const RboxPoints &other)
00057 : PointCoordinates(other)
00058 , rbox_new_count(0)
00059 , rbox_status(other.rbox_status)
00060 , rbox_message(other.rbox_message)
00061 {}
00062
00063 RboxPoints & RboxPoints::
00064 operator=(const RboxPoints &other)
00065 {
00066 PointCoordinates::operator=(other);
00067 rbox_new_count= other.rbox_new_count;
00068 rbox_status= other.rbox_status;
00069 rbox_message= other.rbox_message;
00070 return *this;
00071 }
00072
00073
00074 RboxPoints::
00075 ~RboxPoints()
00076 {}
00077
00078 #//Error
00079
00080 void RboxPoints::
00081 clearRboxMessage()
00082 {
00083 rbox_status= qh_ERRnone;
00084 rbox_message.clear();
00085 }
00086
00087 std::string RboxPoints::
00088 rboxMessage() const
00089 {
00090 if(rbox_status!=qh_ERRnone){
00091 return rbox_message;
00092 }
00093 if(isEmpty()){
00094 return "rbox warning: no points generated\n";
00095 }
00096 return "rbox: OK\n";
00097 }
00098
00099 int RboxPoints::
00100 rboxStatus() const
00101 {
00102 return rbox_status;
00103 }
00104
00105 bool RboxPoints::
00106 hasRboxMessage() const
00107 {
00108 return (rbox_status!=qh_ERRnone);
00109 }
00110
00111 #//Modify
00112
00113 void RboxPoints::
00114 appendPoints(const char *rboxCommand)
00115 {
00116 string s("rbox ");
00117 s += rboxCommand;
00118 char *command= const_cast<char*>(s.c_str());
00119 if(rbox_output){
00120 throw QhullError(10001, "Qhull error: Two simultaneous calls to RboxPoints::appendPoints(). Prevent two processes calling appendPoints() at the same time. Other RboxPoints '%s'", 0, 0, 0, rbox_output->comment().c_str());
00121 }
00122 if(extraCoordinatesCount()!=0){
00123 throw QhullError(10067, "Qhull error: Extra coordinates (%d) prior to calling RboxPoints::appendPoints. Was %s", extraCoordinatesCount(), 0, 0.0, comment().c_str());
00124 }
00125 int previousCount= count();
00126 rbox_output= this;
00127 int status= ::qh_rboxpoints(0, 0, command);
00128 rbox_output= 0;
00129 if(rbox_status==qh_ERRnone){
00130 rbox_status= status;
00131 }
00132 if(rbox_status!=qh_ERRnone){
00133 throw QhullError(rbox_status, rbox_message);
00134 }
00135 if(extraCoordinatesCount()!=0){
00136 throw QhullError(10002, "Qhull error: extra coordinates (%d) for PointCoordinates (%x)", extraCoordinatesCount(), 0, 0.0, coordinates());
00137 }
00138 if(previousCount+newCount()!=count()){
00139 throw QhullError(10068, "Qhull error: rbox specified %d points but got %d points for command '%s'", newCount(), count()-previousCount, 0.0, comment().c_str());
00140 }
00141 }
00142
00143 }
00144
00145 #//Global functions
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 extern "C"
00161 void qh_fprintf_rbox(FILE*, int msgcode, const char *fmt, ... ) {
00162 va_list args;
00163
00164 using namespace orgQhull;
00165
00166 RboxPoints *out= rbox_output;
00167 va_start(args, fmt);
00168 if(msgcode<MSG_OUTPUT){
00169 char newMessage[MSG_MAXLEN];
00170
00171 vsnprintf(newMessage, sizeof(newMessage), fmt, args);
00172 out->rbox_message += newMessage;
00173 if(out->rbox_status<MSG_ERROR || out->rbox_status>=MSG_STDERR){
00174 out->rbox_status= msgcode;
00175 }
00176 va_end(args);
00177 return;
00178 }
00179 switch(msgcode){
00180 case 9391:
00181 case 9392:
00182 out->rbox_message += "RboxPoints error: options 'h', 'n' not supported.\n";
00183 qh_errexit_rbox(10010);
00184
00185 case 9393:
00186 {
00187 int dimension= va_arg(args, int);
00188 string command(va_arg(args, char*));
00189 int count= va_arg(args, int);
00190 out->setDimension(dimension);
00191 out->appendComment(" \"");
00192 out->appendComment(command.substr(command.find(' ')+1));
00193 out->appendComment("\"");
00194 out->setNewCount(count);
00195 out->reservePoints();
00196 }
00197 break;
00198 case 9407:
00199 *out << va_arg(args, int);
00200
00201 case 9405:
00202 *out << va_arg(args, int);
00203
00204 case 9403:
00205 *out << va_arg(args, int);
00206 break;
00207 case 9408:
00208 *out << va_arg(args, double);
00209
00210 case 9406:
00211 *out << va_arg(args, double);
00212
00213 case 9404:
00214 *out << va_arg(args, double);
00215 break;
00216 }
00217 va_end(args);
00218 }
00219