Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /benchmarks/programs/lic2d/bmark-teem.c
ViewVC logotype

Diff of /benchmarks/programs/lic2d/bmark-teem.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1611, Fri Nov 4 14:53:00 2011 UTC revision 1612, Fri Nov 4 16:30:15 2011 UTC
# Line 1  Line 1 
1  /*! \file /lic2d/bmark-teem.c  /*! \file /lic2d/bmark-teem.c
2   *   *
3   * \author Nick Seltzer   * \author Nick Seltzer and Gordon Kindlmann
4   */   */
5    
6  /*  /*
# Line 12  Line 12 
12  #include <math.h>  #include <math.h>
13  #include <stdbool.h>  #include <stdbool.h>
14  #include "teem/nrrd.h"  #include "teem/nrrd.h"
15    #include "teem/ell.h"
16  #include "teem/gage.h"  #include "teem/gage.h"
17    
18  #include "teem-defs.h"  #include "teem-defs.h"
# Line 162  Line 163 
163    return (unsigned char)((0.0f * (in_max - in) + 255.0f * (in - in_min)) / (in_max - in_min));    return (unsigned char)((0.0f * (in_max - in) + 255.0f * (in - in_min)) / (in_max - in_min));
164  }  }
165    
166  int main ()  int main (int argc, const char *argv[])
167  {  {
168      const char *me;
169    char *inFile = "../../data/v.nrrd";    char *inFile = "../../data/v.nrrd";
170    char *randFile = "../../data/R.nrrd";    char *randFile = "../../data/R.nrrd";
171    char *outFile = "lic2d.ppm";    char *outFile = "bmark-teem.nrrd";
172    int imgSizeX = 1020;    int imgSizeX = 1020;
173    int imgSizeY = 561;    int imgSizeY = 561;
174    double h = 0.005;    double h = 0.005;
175    int stepNum = 10;    int stepNum = 10;
176    
177      me = argv[0];
178      airArray *mop;
179      mop = airMopNew();
180    
181    // Read in the data    // Read in the data
182    char* err;    char* err;
183    Nrrd *V;    Nrrd *V = nrrdNew();
184    int status;    airMopAdd(mop, V, (airMopper)nrrdNuke, airMopAlways);
185    V = nrrdNew();    Nrrd *R =  nrrdNew();
186    if (V == NULL) {    airMopAdd(mop, R, (airMopper)nrrdNuke, airMopAlways);
187      err = biffGetDone(NRRD);    if (nrrdLoad(V, inFile, NULL)
188      fprintf(stderr, "Trouble allocating nrrd struct:\n%s", err);        || nrrdLoad(R, randFile, NULL)) {
189      free(err);      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
190      return -1;      fprintf(stderr, "%s: Trouble reading:\n%s", me, err);
191    }      airMopError(mop);
   
   status = nrrdLoad(V, inFile, NULL);  
   if (status) {  
     err = biffGetDone(NRRD);  
     fprintf(stderr, "Trouble reading \"%s\":\n%s", inFile, err);  
     free(err);  
     nrrdNix(V);  
     return -1;  
   }  
   
   // Read in the noise  
   Nrrd *R;  
   R = nrrdNew();  
   if (R == NULL) {  
     err = biffGetDone(NRRD);  
     fprintf(stderr, "Trouble allocating nrrd struct:\n%s", err);  
     free(err);  
     nrrdNuke(V);  
     return -1;  
   }  
   
   status = nrrdLoad(R, randFile, NULL);  
   if (status) {  
     err = biffGetDone(NRRD);  
     fprintf(stderr, "Trouble reading \"%s\":\n%s", randFile, err);  
     free(err);  
     nrrdNix(R);  
     nrrdNuke(V);  
192      return -1;      return -1;
193    }    }
194    
195    double *out_data = malloc(sizeof(double) * 3 * 1020 * 561);    Nrrd *nout = nrrdNew();
196    if (out_data == NULL) {    airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
197      fprintf(stderr, "Trouble with malloc\n");    if (nrrdAlloc_va(nout, nrrdTypeDouble, 3,
198      nrrdNuke(V);                     AIR_CAST(size_t, 3),
199      nrrdNuke(R);                     AIR_CAST(size_t, 1020),
200                       AIR_CAST(size_t, 561))) {
201        airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
202        fprintf(stderr, "%s: Trouble allocating:\n%s", me, err);
203        airMopError(mop);
204      return -1;      return -1;
205    }    }
206      double *out_data = AIR_CAST(double *, nout->data);
207    
208    double t0 = airTime(); // start timing    double t0 = airTime(); // start timing
209    double pos0[2];    double pos0[2];
# Line 287  Line 270 
270    
271            c = (1 - (((2 * l - 1)>0)?(2 * l - 1):(1 - 2 * l))) * s;            c = (1 - (((2 * l - 1)>0)?(2 * l - 1):(1 - 2 * l))) * s;
272            m = l - c / 2;            m = l - c / 2;
273            if (crl < 0) {            if (crl > 0) {
274              *(out_data + xi * 3 + yi * 3060 + 0) = c + m;              ELL_3V_SET(out_data + 3*(xi + 1020*yi), c+m, m, c+m);
             *(out_data + xi * 3 + yi * 3060 + 1) = m;  
             *(out_data + xi * 3 + yi * 3060 + 2) = c + m;  
275            }            }
276            else {            else {
277              *(out_data + xi * 3 + yi * 3060 + 0) = m;              ELL_3V_SET(out_data + 3*(xi + 1020*yi), m, c+m, m);
             *(out_data + xi * 3 + yi * 3060 + 1) = c + m;  
             *(out_data + xi * 3 + yi * 3060 + 2) = m;  
278            }            }
279            break;            break;
280          }          }
# Line 303  Line 282 
282      }      }
283    }    }
284    
   nrrdNuke(V);  
   nrrdNuke(R);  
   
285    double totalTime = airTime() - t0;    double totalTime = airTime() - t0;
286    printf("usr=%f\n", totalTime);    printf("usr=%f\n", totalTime);
287    
288    unsigned char *uc_out_data = malloc(sizeof(unsigned char) * 3 * 1020 * 561);    if (nrrdSave(outFile, nout, NULL)) {
289    if (uc_out_data == NULL) {      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
290      fprintf(stderr, "Trouble with malloc\n");      fprintf(stderr, "%s: Trouble saving:\n%s", me, err);
291      free(out_data);      airMopError(mop);
   }  
   for (int i = 0; i < 3; i++) {  
     for (int j = 0; j < 1020; j++) {  
       for (int k = 0; k < 561; k++) {  
         *(uc_out_data + k * 3060 + j * 3 + i) = ulerp(0, *(out_data + k * 3060 + j * 3 + i), 1);  
       }  
     }  
   }  
   
   free(out_data);  
   
   // Write out data  
   Nrrd *nout;  
   nout = nrrdNew();  
   if (nout == NULL) {  
     err = biffGetDone(NRRD);  
     fprintf(stderr, "Trouble allocating nrrd struct:\n%s", err);  
     free(err);  
     free(uc_out_data);  
     return -1;  
   }  
   
   size_t sizes[3] = {3, 1020, 561};  
   status = nrrdWrap_nva(nout, uc_out_data, nrrdTypeUChar, 3, sizes);  
   if (status) {  
     err = biffGetDone(NRRD);  
     fprintf(stderr, "Trouble wrapping nrrd struct:\n%s", err);  
     free(err);  
     free(uc_out_data);  
     nrrdNix(nout);  
     return -1;  
   }  
   
   status = nrrdSave(outFile, nout, NULL);  
   if (status) {  
     err = biffGetDone(NRRD);  
     fprintf(stderr, "Trouble wrapping nrrd struct:\n%s", err);  
     free(err);  
     nrrdNuke(nout);  
292      return -1;      return -1;
293    }    }
294    
295    nrrdNuke(nout);    airMopOkay(mop);
296    return 0;    return 0;
297  }  }

Legend:
Removed from v.1611  
changed lines
  Added in v.1612

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0