1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (c) 2008-2012 C.B. Barber. All rights reserved.
|
---|
4 | ** $Id: //main/2011/qhull/src/libqhullcpp/RboxPoints.cpp#4 $$Change: 1464 $
|
---|
5 | ** $DateTime: 2012/01/25 22:58:41 $$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 | #//! RboxPoints -- generate random PointCoordinates for qhull (rbox)
|
---|
30 |
|
---|
31 | #//Global
|
---|
32 |
|
---|
33 | //! pointer to RboxPoints for qh_fprintf callback
|
---|
34 | RboxPoints *rbox_output= 0;
|
---|
35 |
|
---|
36 | #//Construct
|
---|
37 | RboxPoints::
|
---|
38 | RboxPoints()
|
---|
39 | : PointCoordinates("rbox")
|
---|
40 | , rbox_new_count(0)
|
---|
41 | , rbox_status(qh_ERRnone)
|
---|
42 | , rbox_message()
|
---|
43 | {}
|
---|
44 |
|
---|
45 | RboxPoints::
|
---|
46 | RboxPoints(const char *rboxCommand)
|
---|
47 | : PointCoordinates("rbox")
|
---|
48 | , rbox_new_count(0)
|
---|
49 | , rbox_status(qh_ERRnone)
|
---|
50 | , rbox_message()
|
---|
51 | {
|
---|
52 | appendPoints(rboxCommand);
|
---|
53 | }
|
---|
54 |
|
---|
55 | RboxPoints::
|
---|
56 | RboxPoints(const RboxPoints &other)
|
---|
57 | : PointCoordinates(other)
|
---|
58 | , rbox_new_count(0)
|
---|
59 | , rbox_status(other.rbox_status)
|
---|
60 | , rbox_message(other.rbox_message)
|
---|
61 | {}
|
---|
62 |
|
---|
63 | RboxPoints & RboxPoints::
|
---|
64 | operator=(const RboxPoints &other)
|
---|
65 | {
|
---|
66 | PointCoordinates::operator=(other);
|
---|
67 | rbox_new_count= other.rbox_new_count;
|
---|
68 | rbox_status= other.rbox_status;
|
---|
69 | rbox_message= other.rbox_message;
|
---|
70 | return *this;
|
---|
71 | }//operator=
|
---|
72 |
|
---|
73 |
|
---|
74 | RboxPoints::
|
---|
75 | ~RboxPoints()
|
---|
76 | {}
|
---|
77 |
|
---|
78 | #//Error
|
---|
79 |
|
---|
80 | void RboxPoints::
|
---|
81 | clearRboxMessage()
|
---|
82 | {
|
---|
83 | rbox_status= qh_ERRnone;
|
---|
84 | rbox_message.clear();
|
---|
85 | }//clearRboxMessage
|
---|
86 |
|
---|
87 | std::string RboxPoints::
|
---|
88 | rboxMessage() const
|
---|
89 | {
|
---|
90 | if(rbox_status!=qh_ERRnone){
|
---|
91 | return rbox_message;
|
---|
92 | }
|
---|
93 | if(isEmpty()){
|
---|
94 | return "rbox warning: no points generated\n";
|
---|
95 | }
|
---|
96 | return "rbox: OK\n";
|
---|
97 | }//rboxMessage
|
---|
98 |
|
---|
99 | int RboxPoints::
|
---|
100 | rboxStatus() const
|
---|
101 | {
|
---|
102 | return rbox_status;
|
---|
103 | }
|
---|
104 |
|
---|
105 | bool RboxPoints::
|
---|
106 | hasRboxMessage() const
|
---|
107 | {
|
---|
108 | return (rbox_status!=qh_ERRnone);
|
---|
109 | }
|
---|
110 |
|
---|
111 | #//Modify
|
---|
112 |
|
---|
113 | 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(rbox_output){
|
---|
120 | 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());
|
---|
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 | int previousCount= count();
|
---|
126 | rbox_output= this; // set rbox_output for qh_fprintf()
|
---|
127 | int status= ::qh_rboxpoints(0, 0, command);
|
---|
128 | rbox_output= 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 | #//Global functions
|
---|
146 |
|
---|
147 | /*-<a href="qh-user.htm#TOC"
|
---|
148 | >-------------------------------</a><a name="qh_fprintf_rbox">-</a>
|
---|
149 |
|
---|
150 | qh_fprintf_rbox(fp, msgcode, format, list of args )
|
---|
151 | fp is ignored (replaces qh_fprintf_rbox() in userprintf_rbox.c)
|
---|
152 | rbox_output == 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 | */
|
---|
160 | extern "C"
|
---|
161 | void qh_fprintf_rbox(FILE*, int msgcode, const char *fmt, ... ) {
|
---|
162 | va_list args;
|
---|
163 |
|
---|
164 | using namespace orgQhull;
|
---|
165 |
|
---|
166 | RboxPoints *out= rbox_output;
|
---|
167 | va_start(args, fmt);
|
---|
168 | if(msgcode<MSG_OUTPUT){
|
---|
169 | char newMessage[MSG_MAXLEN];
|
---|
170 | // RoadError provides the message tag
|
---|
171 | vsnprintf(newMessage, sizeof(newMessage), fmt, args);
|
---|
172 | out->rbox_message += newMessage;
|
---|
173 | if(out->rbox_status<MSG_ERROR || out->rbox_status>=MSG_STDERR){
|
---|
174 | out->rbox_status= msgcode;
|
---|
175 | }
|
---|
176 | va_end(args);
|
---|
177 | return;
|
---|
178 | }
|
---|
179 | switch(msgcode){
|
---|
180 | case 9391:
|
---|
181 | case 9392:
|
---|
182 | out->rbox_message += "RboxPoints error: options 'h', 'n' not supported.\n";
|
---|
183 | qh_errexit_rbox(10010);
|
---|
184 | /* never returns */
|
---|
185 | case 9393:
|
---|
186 | {
|
---|
187 | int dimension= va_arg(args, int);
|
---|
188 | string command(va_arg(args, char*));
|
---|
189 | int count= va_arg(args, int);
|
---|
190 | out->setDimension(dimension);
|
---|
191 | out->appendComment(" \"");
|
---|
192 | out->appendComment(command.substr(command.find(' ')+1));
|
---|
193 | out->appendComment("\"");
|
---|
194 | out->setNewCount(count);
|
---|
195 | out->reservePoints();
|
---|
196 | }
|
---|
197 | break;
|
---|
198 | case 9407:
|
---|
199 | *out << va_arg(args, int);
|
---|
200 | // fall through
|
---|
201 | case 9405:
|
---|
202 | *out << va_arg(args, int);
|
---|
203 | // fall through
|
---|
204 | case 9403:
|
---|
205 | *out << va_arg(args, int);
|
---|
206 | break;
|
---|
207 | case 9408:
|
---|
208 | *out << va_arg(args, double);
|
---|
209 | // fall through
|
---|
210 | case 9406:
|
---|
211 | *out << va_arg(args, double);
|
---|
212 | // fall through
|
---|
213 | case 9404:
|
---|
214 | *out << va_arg(args, double);
|
---|
215 | break;
|
---|
216 | }
|
---|
217 | va_end(args);
|
---|
218 | } /* qh_fprintf_rbox */
|
---|
219 |
|
---|