RboxPoints.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2008-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/libqhullcpp/RboxPoints.cpp#3 $$Change: 1441 $
00005 ** $DateTime: 2011/11/23 22:39:03 $$Author: bbarber $
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 }//operator=
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 }//clearRboxMessage
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 }//rboxMessage
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;              // set rbox_output for qh_fprintf()
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 }//appendPoints
00142 
00143 }//namespace orgQhull
00144 
00145 #//Global functions
00146 
00147 /*-<a                             href="qh-user.htm#TOC"
00148 >-------------------------------</a><a name="qh_fprintf_rbox">-</a>
00149 
00150   qh_fprintf_rbox(fp, msgcode, format, list of args )
00151     fp is ignored (replaces qh_fprintf_rbox() in userprintf_rbox.c)
00152     rbox_output == RboxPoints
00153 
00154 notes:
00155     only called from qh_rboxpoints()
00156     same as fprintf() and Qhull::qh_fprintf()
00157     fgets() is not trapped like fprintf()
00158     Do not throw errors from here.  Use qh_errexit_rbox;
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         // RoadError provides the message tag
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         /* never returns */
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         // fall through
00201     case 9405:
00202         *out << va_arg(args, int);
00203         // fall through
00204     case 9403:
00205         *out << va_arg(args, int);
00206         break;
00207     case 9408:
00208         *out << va_arg(args, double);
00209         // fall through
00210     case 9406:
00211         *out << va_arg(args, double);
00212         // fall through
00213     case 9404:
00214         *out << va_arg(args, double);
00215         break;
00216     }
00217     va_end(args);
00218 } /* qh_fprintf_rbox */
00219 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


libqhull
Author(s): Robert Krug
autogenerated on Tue Jun 18 2013 12:38:50