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