[37] | 1 | /* |
---|
| 2 | |
---|
| 3 | Name: main.c |
---|
| 4 | |
---|
| 5 | Coded: Paul Ning |
---|
| 6 | |
---|
| 7 | Modified by: Brian Curless |
---|
| 8 | Computer Graphics Laboratory |
---|
| 9 | Stanford University |
---|
| 10 | |
---|
| 11 | Comment: Isosurface reconstruction using Marching Cubes-style |
---|
| 12 | table lookup on cube topologies. |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | Copyright (1997) The Board of Trustees of the Leland Stanford Junior |
---|
| 16 | University. Except for commercial resale, lease, license or other |
---|
| 17 | commercial transactions, permission is hereby given to use, copy, |
---|
| 18 | modify this software for academic purposes only. No part of this |
---|
| 19 | software or any derivatives thereof may be used in the production of |
---|
| 20 | computer models for resale or for use in a commercial |
---|
| 21 | product. STANFORD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND |
---|
| 22 | CONCERNING THIS SOFTWARE. No support is implied or provided. |
---|
| 23 | |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | #include <stdio.h> |
---|
| 28 | #include "mc.h" |
---|
| 29 | #include "var.h" |
---|
| 30 | #include <stdlib.h> |
---|
| 31 | #include <string.h> |
---|
| 32 | #include <unistd.h> |
---|
| 33 | #include <sys/types.h> |
---|
| 34 | #include <sys/times.h> |
---|
| 35 | #include <limits.h> |
---|
| 36 | //#include <iostream> |
---|
| 37 | #include <time.h> |
---|
| 38 | |
---|
| 39 | clock_t tm; |
---|
| 40 | |
---|
| 41 | void printUsage(); |
---|
| 42 | static void start_time(); |
---|
| 43 | static void end_time(); |
---|
| 44 | static void print_time(); |
---|
| 45 | static float time_elapsed(); |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | int |
---|
| 49 | main(int argc, char **argv) |
---|
| 50 | { |
---|
| 51 | int index; |
---|
| 52 | |
---|
| 53 | start_time(); |
---|
| 54 | |
---|
| 55 | if (argc < 3 || argc > 5) { |
---|
| 56 | printUsage(); |
---|
| 57 | exit(1); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | WriteNormals = FALSE; |
---|
| 61 | UseValueWeightProduct = FALSE; |
---|
| 62 | SaveGradientAsConfidence = FALSE; |
---|
| 63 | |
---|
| 64 | index = 1; |
---|
| 65 | char dash[2] = "-"; |
---|
| 66 | |
---|
| 67 | threshold = 128; |
---|
| 68 | |
---|
| 69 | // Need to fix this; should use a loop, and thresh should be -thresh |
---|
| 70 | while (argv[index][0] == dash[0]) { |
---|
| 71 | if (strstr(argv[index], "-n")) { |
---|
| 72 | WriteNormals = TRUE; |
---|
| 73 | index++; |
---|
| 74 | } |
---|
| 75 | else if (strstr(argv[index], "-vw")) { |
---|
| 76 | UseValueWeightProduct = TRUE; |
---|
| 77 | index++; |
---|
| 78 | } |
---|
| 79 | else if (strstr(argv[index], "-gc")) { |
---|
| 80 | SaveGradientAsConfidence = TRUE; |
---|
| 81 | index++; |
---|
| 82 | } |
---|
| 83 | else if (strstr(argv[index], "-thresh")) { |
---|
| 84 | index++; |
---|
| 85 | threshold = atoi(argv[index])/256.0; |
---|
| 86 | index++; |
---|
| 87 | } else { |
---|
| 88 | fprintf(stderr, "Invalid command line argument '%s'\n", argv[index]); |
---|
| 89 | exit(1); |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | /* |
---|
| 94 | if (strstr(argv[1], "-n")) { |
---|
| 95 | WriteNormals = TRUE; |
---|
| 96 | index++; |
---|
| 97 | } |
---|
| 98 | else if (strstr(argv[1], "-vw")) { |
---|
| 99 | UseValueWeightProduct = TRUE; |
---|
| 100 | index++; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | if (strstr(argv[2], "-n")) { |
---|
| 104 | WriteNormals = TRUE; |
---|
| 105 | index++; |
---|
| 106 | } |
---|
| 107 | else if (strstr(argv[2], "-vw")) { |
---|
| 108 | UseValueWeightProduct = TRUE; |
---|
| 109 | index++; |
---|
| 110 | } |
---|
| 111 | */ |
---|
| 112 | |
---|
| 113 | strcpy(infile, argv[index++]); |
---|
| 114 | strcpy(outfile, argv[index++]); |
---|
| 115 | |
---|
| 116 | if (index < argc) |
---|
| 117 | OCC_CONF_THRESHOLD = atoi((char *)argv[index++]); |
---|
| 118 | else |
---|
| 119 | OCC_CONF_THRESHOLD = 0; |
---|
| 120 | |
---|
| 121 | FirstSliceFileNumber = 0; |
---|
| 122 | i0 = j_0 = k0 = 1; |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | Init(); |
---|
| 126 | /* DoSlices();*/ |
---|
| 127 | DoSlicesOccRLE(); |
---|
| 128 | |
---|
| 129 | end_time(); |
---|
| 130 | |
---|
| 131 | /* print_time();*/ |
---|
| 132 | |
---|
| 133 | Quit(); |
---|
| 134 | |
---|
| 135 | return 0; |
---|
| 136 | |
---|
| 137 | } /* main */ |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | void |
---|
| 142 | printUsage() |
---|
| 143 | { |
---|
| 144 | printf("Usage: mc <in-rle-file> <out-ply-file> [weight-threshold]\n"); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | static void |
---|
| 149 | start_time() |
---|
| 150 | { |
---|
| 151 | struct tms buffer; |
---|
| 152 | times(&buffer); |
---|
| 153 | tm = buffer.tms_utime; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | static void |
---|
| 157 | end_time() |
---|
| 158 | { |
---|
| 159 | struct tms buffer; |
---|
| 160 | times(&buffer); |
---|
| 161 | tm = buffer.tms_utime - tm; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | static void |
---|
| 165 | print_time() |
---|
| 166 | { |
---|
| 167 | printf("%f seconds\n", (double) tm / (double) CLOCKS_PER_SEC); |
---|
| 168 | //std::cout << (double) tm / (double) CLOCKS_PER_SEC << " seconds" << std::endl; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | static float |
---|
| 173 | time_elapsed() |
---|
| 174 | { |
---|
| 175 | return (double) tm / (double) CLOCKS_PER_SEC; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | |
---|