RboxPoints.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2008-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/libqhullcpp/RboxPoints.cpp#3 $$Change: 2066 $
5 ** $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
10 
11 #include "libqhullcpp/QhullError.h"
12 
13 #include <iostream>
14 
15 using std::cerr;
16 using std::endl;
17 using std::istream;
18 using std::ostream;
19 using std::ostringstream;
20 using std::string;
21 using std::vector;
22 using std::ws;
23 
24 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
25 #pragma warning( disable : 4996) // function was declared deprecated(strcpy, localtime, etc.)
26 #endif
27 
28 namespace orgQhull {
29 
30 #
31 
32 
33 #
34 RboxPoints::
36 : PointCoordinates("rbox")
37 , rbox_new_count(0)
38 , rbox_status(qh_ERRnone)
39 , rbox_message()
40 {
41  allocateQhullQh();
42 }
43 
48 RboxPoints(const char *rboxCommand)
49 : PointCoordinates("rbox")
50 , rbox_new_count(0)
51 , rbox_status(qh_ERRnone)
52 , rbox_message()
53 {
55  // rbox arguments added to comment() via qh_rboxpoints > qh_fprintf_rbox
56  appendPoints(rboxCommand);
57 }
58 
61 {
62  delete qh();
63  resetQhullQh(0);
64 }
65 
66 // RboxPoints and qh_rboxpoints has several fields in qhT (rbox_errexit..cpp_object)
67 // It shares last_random with qh_rand and qh_srand
68 // The other fields are unused
69 void RboxPoints::
71 {
72  QHULL_LIB_CHECK /* Check for compatible library */
73  resetQhullQh(new QhullQh);
74 }//allocateQhullQh
75 
76 #
77 
78 void RboxPoints::
80 {
82  rbox_message.clear();
83 }//clearRboxMessage
84 
85 std::string RboxPoints::
86 rboxMessage() const
87 {
89  return rbox_message;
90  }
91  if(isEmpty()){
92  return "rbox warning: no points generated\n";
93  }
94  return "rbox: OK\n";
95 }//rboxMessage
96 
97 int RboxPoints::
98 rboxStatus() const
99 {
100  return rbox_status;
101 }
102 
103 bool RboxPoints::
105 {
106  return (rbox_status!=qh_ERRnone);
107 }
108 
109 #
110 
111 void RboxPoints::
115 appendPoints(const char *rboxCommand)
116 {
117  string s("rbox ");
118  s += rboxCommand;
119  char *command= const_cast<char*>(s.c_str());
120  if(qh()->cpp_object){
121  throw QhullError(10001, "Qhull error: conflicting user of cpp_object for RboxPoints::appendPoints() or corrupted qh_qh");
122  }
123  if(extraCoordinatesCount()!=0){
124  throw QhullError(10067, "Qhull error: Extra coordinates (%d) prior to calling RboxPoints::appendPoints. Was %s", extraCoordinatesCount(), 0, 0.0, comment().c_str());
125  }
126  countT previousCount= count();
127  qh()->cpp_object= this; // for qh_fprintf_rbox()
128  int status= qh_rboxpoints(qh(), command);
129  qh()->cpp_object= 0;
130  if(rbox_status==qh_ERRnone){
131  rbox_status= status;
132  }
133  if(rbox_status!=qh_ERRnone){
135  }
136  if(extraCoordinatesCount()!=0){
137  throw QhullError(10002, "Qhull error: extra coordinates (%d) for PointCoordinates (%x)", extraCoordinatesCount(), 0, 0.0, coordinates());
138  }
139  if(previousCount+newCount()!=count()){
140  throw QhullError(10068, "Qhull error: rbox specified %d points but got %d points for command '%s'", newCount(), count()-previousCount, 0.0, comment().c_str());
141  }
142 }//appendPoints
143 
144 }//namespace orgQhull
145 
146 #
147 
148 /*-<a href="qh-user.htm#TOC"
149 >-------------------------------</a><a name="qh_fprintf_rbox">-</a>
150 
151  qh_fprintf_rbox(qh, fp, msgcode, format, list of args )
152  fp is ignored (replaces qh_fprintf_rbox() in userprintf_rbox.c)
153  cpp_object == RboxPoints
154 
155 notes:
156  only called from qh_rboxpoints()
157  same as fprintf() and Qhull.qh_fprintf()
158  fgets() is not trapped like fprintf()
159  Do not throw errors from here. Use qh_errexit_rbox;
160  A similar technique can be used for qh_fprintf to capture all of its output
161 */
162 extern "C"
163 void qh_fprintf_rbox(qhT *qh, FILE*, int msgcode, const char *fmt, ... ) {
164  va_list args;
165 
166  using namespace orgQhull;
167 
168  if(!qh->cpp_object){
169  qh_errexit_rbox(qh, 10072);
170  }
171  RboxPoints *out= reinterpret_cast<RboxPoints *>(qh->cpp_object);
172  va_start(args, fmt);
173  if(msgcode<MSG_OUTPUT){
174  char newMessage[MSG_MAXLEN];
175  // RoadError provides the message tag
176  vsnprintf(newMessage, sizeof(newMessage), fmt, args);
177  out->rbox_message += newMessage;
178  if(out->rbox_status<MSG_ERROR || out->rbox_status>=MSG_STDERR){
179  out->rbox_status= msgcode;
180  }
181  va_end(args);
182  return;
183  }
184  switch(msgcode){
185  case 9391:
186  case 9392:
187  out->rbox_message += "RboxPoints error: options 'h', 'n' not supported.\n";
188  qh_errexit_rbox(qh, 10010);
189  /* never returns */
190  case 9393: // FIXUP QH11026 countT vs. int
191  {
192  int dimension= va_arg(args, int);
193  string command(va_arg(args, char*));
194  countT count= va_arg(args, countT);
195  out->setDimension(dimension);
196  out->appendComment(" \"");
197  out->appendComment(command.substr(command.find(' ')+1));
198  out->appendComment("\"");
199  out->setNewCount(count);
200  out->reservePoints();
201  }
202  break;
203  case 9407:
204  *out << va_arg(args, int);
205  // fall through
206  case 9405:
207  *out << va_arg(args, int);
208  // fall through
209  case 9403:
210  *out << va_arg(args, int);
211  break;
212  case 9408:
213  *out << va_arg(args, double);
214  // fall through
215  case 9406:
216  *out << va_arg(args, double);
217  // fall through
218  case 9404:
219  *out << va_arg(args, double);
220  break;
221  }
222  va_end(args);
223 } /* qh_fprintf_rbox */
224 
qh_fprintf_rbox
void qh_fprintf_rbox(qhT *qh, FILE *, int msgcode, const char *fmt,...)
Definition: RboxPoints.cpp:163
orgQhull::QhullPoints::coordinates
coordT * coordinates() const
Definition: QhullPoints.h:90
QHULL_LIB_CHECK
#define QHULL_LIB_CHECK
Definition: libqhull.h:462
countT
int countT
Definition: user_r.h:182
obb.fmt
fmt
Definition: obb.py:145
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::PointCoordinates
Definition: PointCoordinates.h:38
orgQhull::RboxPoints::rboxMessage
std::string rboxMessage() const
Definition: RboxPoints.cpp:86
orgQhull::RboxPoints::~RboxPoints
~RboxPoints()
Definition: RboxPoints.cpp:60
qh_errexit_rbox
void qh_errexit_rbox(int exitcode)
Definition: rboxlib.c:866
orgQhull::PointCoordinates::setDimension
void setDimension(int i)
Definition: PointCoordinates.cpp:162
qhT
Definition: libqhull.h:465
orgQhull::RboxPoints::rboxStatus
int rboxStatus() const
Definition: RboxPoints.cpp:98
orgQhull::PointCoordinates::comment
std::string comment() const
Definition: PointCoordinates.h:82
qh_rboxpoints
int qh_rboxpoints(FILE *fout, FILE *ferr, char *rbox_command)
Definition: rboxlib.c:90
orgQhull::RboxPoints::clearRboxMessage
void clearRboxMessage()
Definition: RboxPoints.cpp:79
orgQhull::QhullPoints::isEmpty
bool isEmpty() const
Definition: QhullPoints.h:110
orgQhull::RboxPoints::rbox_message
std::string rbox_message
error status from rboxpoints. qh_ERRnone if none.
Definition: RboxPoints.h:44
orgQhull::QhullPoints::qh
QhullQh * qh() const
Definition: QhullPoints.h:117
orgQhull::RboxPoints::reservePoints
void reservePoints()
Definition: RboxPoints.h:72
doxygen_xml_parser.args
args
Definition: doxygen_xml_parser.py:887
qh_ERRnone
#define qh_ERRnone
Definition: libqhull.h:193
MSG_ERROR
#define MSG_ERROR
Definition: user.h:74
MSG_OUTPUT
#define MSG_OUTPUT
Definition: user.h:77
qh
#define qh
Definition: libqhull.h:457
orgQhull::QhullPoints::extraCoordinatesCount
countT extraCoordinatesCount() const
Definition: QhullPoints.cpp:93
orgQhull::QhullQh
POD type equivalent to qhT. No virtual members.
Definition: QhullQh.h:58
orgQhull::RboxPoints::newCount
countT newCount() const
Definition: RboxPoints.h:63
orgQhull::RboxPoints::rbox_status
int rbox_status
Number of points for PointCoordinates.
Definition: RboxPoints.h:43
orgQhull::QhullPoints::count
countT count() const
Definition: QhullPoints.h:92
orgQhull::RboxPoints::hasRboxMessage
bool hasRboxMessage() const
Definition: RboxPoints.cpp:104
orgQhull::RboxPoints::appendPoints
void appendPoints(const char *rboxCommand)
Definition: RboxPoints.cpp:115
orgQhull::RboxPoints
Definition: RboxPoints.h:37
MSG_MAXLEN
#define MSG_MAXLEN
Definition: user.h:80
qhT::cpp_object
void * cpp_object
Definition: libqhull_r.h:782
orgQhull::QhullError
Definition: QhullError.h:26
MSG_STDERR
#define MSG_STDERR
Definition: user.h:76
orgQhull::RboxPoints::setNewCount
void setNewCount(countT pointCount)
Definition: RboxPoints.h:67
orgQhull::RboxPoints::RboxPoints
RboxPoints()
Definition: RboxPoints.cpp:35
orgQhull::RboxPoints::allocateQhullQh
void allocateQhullQh()
Definition: RboxPoints.cpp:70
RboxPoints.h
QhullError.h
orgQhull::PointCoordinates::appendComment
void appendComment(const std::string &s)
Definition: PointCoordinates.cpp:219
orgQhull::QhullPoints::resetQhullQh
void resetQhullQh(QhullQh *qqh)
Definition: QhullPoints.cpp:138


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:59