[10207] | 1 | /*<html><pre> -<a href="../libqhull/index.htm#TOC"
|
---|
| 2 | >-------------------------------</a><a name="TOP">-</a>
|
---|
| 3 |
|
---|
| 4 | rbox.c
|
---|
| 5 | rbox program for generating input points for qhull.
|
---|
| 6 |
|
---|
| 7 | notes:
|
---|
| 8 | 50 points generated for 'rbox D4'
|
---|
| 9 |
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | #include "random.h"
|
---|
| 13 | #include "libqhull.h"
|
---|
| 14 |
|
---|
| 15 | #include <stdarg.h>
|
---|
| 16 | #include <stdio.h>
|
---|
| 17 | #include <stdlib.h>
|
---|
| 18 |
|
---|
| 19 | #if __MWERKS__ && __POWERPC__
|
---|
| 20 | #include <SIOUX.h>
|
---|
| 21 | #include <Files.h>
|
---|
| 22 | #include <console.h>
|
---|
| 23 | #include <Desk.h>
|
---|
| 24 | #endif
|
---|
| 25 |
|
---|
| 26 | #ifdef _MSC_VER /* Microsoft Visual C++ -- warning level 4 */
|
---|
| 27 | #pragma warning( disable : 4706) /* assignment within conditional function */
|
---|
| 28 | #endif
|
---|
| 29 |
|
---|
| 30 | char prompt[]= "\n\
|
---|
| 31 | -rbox- generate various point distributions. Default is random in cube.\n\
|
---|
| 32 | \n\
|
---|
| 33 | args (any order, space separated): Version: 2001/06/24\n\
|
---|
| 34 | 3000 number of random points in cube, lens, spiral, sphere or grid\n\
|
---|
| 35 | D3 dimension 3-d\n\
|
---|
| 36 | c add a unit cube to the output ('c G2.0' sets size)\n\
|
---|
| 37 | d add a unit diamond to the output ('d G2.0' sets size)\n\
|
---|
| 38 | l generate a regular 3-d spiral\n\
|
---|
| 39 | r generate a regular polygon, ('r s Z1 G0.1' makes a cone)\n\
|
---|
| 40 | s generate cospherical points\n\
|
---|
| 41 | x generate random points in simplex, may use 'r' or 'Wn'\n\
|
---|
| 42 | y same as 'x', plus simplex\n\
|
---|
| 43 | Pn,m,r add point [n,m,r] first, pads with 0\n\
|
---|
| 44 | \n\
|
---|
| 45 | Ln lens distribution of radius n. Also 's', 'r', 'G', 'W'.\n\
|
---|
| 46 | Mn,m,r lattice(Mesh) rotated by [n,-m,0], [m,n,0], [0,0,r], ...\n\
|
---|
| 47 | '27 M1,0,1' is {0,1,2} x {0,1,2} x {0,1,2}. Try 'M3,4 z'.\n\
|
---|
| 48 | W0.1 random distribution within 0.1 of the cube's or sphere's surface\n\
|
---|
| 49 | Z0.5 s random points in a 0.5 disk projected to a sphere\n\
|
---|
| 50 | Z0.5 s G0.6 same as Z0.5 within a 0.6 gap\n\
|
---|
| 51 | \n\
|
---|
| 52 | Bn bounding box coordinates, default %2.2g\n\
|
---|
| 53 | h output as homogeneous coordinates for cdd\n\
|
---|
| 54 | n remove command line from the first line of output\n\
|
---|
| 55 | On offset coordinates by n\n\
|
---|
| 56 | t use time as the random number seed(default is command line)\n\
|
---|
| 57 | tn use n as the random number seed\n\
|
---|
| 58 | z print integer coordinates, default 'Bn' is %2.2g\n\
|
---|
| 59 | ";
|
---|
| 60 |
|
---|
| 61 | /*--------------------------------------------
|
---|
| 62 | -rbox- main procedure of rbox application
|
---|
| 63 | */
|
---|
| 64 | int main(int argc, char **argv) {
|
---|
| 65 | char *command;
|
---|
| 66 | int command_size;
|
---|
| 67 | int return_status;
|
---|
| 68 |
|
---|
| 69 | #if __MWERKS__ && __POWERPC__
|
---|
| 70 | char inBuf[BUFSIZ], outBuf[BUFSIZ], errBuf[BUFSIZ];
|
---|
| 71 | SIOUXSettings.showstatusline= False;
|
---|
| 72 | SIOUXSettings.tabspaces= 1;
|
---|
| 73 | SIOUXSettings.rows= 40;
|
---|
| 74 | if (setvbuf(stdin, inBuf, _IOFBF, sizeof(inBuf)) < 0 /* w/o, SIOUX I/O is slow*/
|
---|
| 75 | || setvbuf(stdout, outBuf, _IOFBF, sizeof(outBuf)) < 0
|
---|
| 76 | || (stdout != stderr && setvbuf(stderr, errBuf, _IOFBF, sizeof(errBuf)) < 0))
|
---|
| 77 | fprintf(stderr, "qhull internal warning (main): could not change stdio to fully buffered.\n");
|
---|
| 78 | argc= ccommand(&argv);
|
---|
| 79 | #endif
|
---|
| 80 |
|
---|
| 81 | if (argc == 1) {
|
---|
| 82 | printf(prompt, qh_DEFAULTbox, qh_DEFAULTzbox);
|
---|
| 83 | return 1;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | command_size= qh_argv_to_command_size(argc, argv);
|
---|
| 87 | if ((command= (char *)qh_malloc((size_t)command_size))) {
|
---|
| 88 | if (!qh_argv_to_command(argc, argv, command, command_size)) {
|
---|
| 89 | fprintf(stderr, "rbox internal error: allocated insufficient memory (%d) for arguments\n", command_size);
|
---|
| 90 | return_status= qh_ERRinput;
|
---|
| 91 | }else{
|
---|
| 92 | return_status= qh_rboxpoints(stdout, stderr, command);
|
---|
| 93 | }
|
---|
| 94 | qh_free(command);
|
---|
| 95 | }else {
|
---|
| 96 | fprintf(stderr, "rbox error: insufficient memory for %d bytes\n", command_size);
|
---|
| 97 | return_status= qh_ERRmem;
|
---|
| 98 | }
|
---|
| 99 | return return_status;
|
---|
| 100 | }/*main*/
|
---|
| 101 |
|
---|