Beispiel #1
0
int main( int argc, char *argv[])
{
     Imod *imod;
     FILE *fout  = NULL;

     if (argc < 3){
	  printf("imod2rib, Version 1.0 %s %s\n", __DATE__,__TIME__);
	  printf("\tUsage,  imod2rib <infile.imod> <outfile.rib>\n");
	  exit(1);
     }
     
     fout = fopen(argv[2], "w");

     if (fout == NULL){
	  printf("Couldn't open output file %s.\n", argv[2]);
	  exit(10);
     }
     
     imod = imodRead(argv[1]);
     if (!imod){
	  fprintf(stderr, "Imod2RIB: Error reading model.\n");
	  exit(3);
     }
     
      
     if (imod_to_RIB(imod, fout))
	  fprintf(stderr, "Imod2RIB: Error!\n");
     
     fclose(fout);
     exit(0);
}
Beispiel #2
0
// load a specified model (only in standalone model)
int imodvLoadModel()
{
  Imod **tmoda;
  Imod *tmod;
  ImodvApp *a = Imodv;
  int i, ob, co;
  QString qname;
  const char *filter[] = {"Model files (*.*mod)"};
  
  if (ImodvClosed || !a->standalone)
    return -1;

  // Need to release the keyboard because window grabs it on ctrl
  a->mainWin->releaseKeyboard();
  qname = utilOpenFileName(NULL, "Select Model file to load", 1, filter);

  if (qname.isEmpty())
    return 1;

  tmod = imodRead(LATIN1(qname));
  if (!tmod)
    return(-1);
  utilExchangeFlipRotation(tmod, FLIP_TO_ROTATION);

  /* DNM 6/20/01: find out max time and set current time */
  tmod->tmax = 0;
  for (ob = 0; ob < tmod->objsize; ob++)
    for (co = 0; co < tmod->obj[ob].contsize; co++)
      if (tmod->tmax < tmod->obj[ob].cont[co].time)
        tmod->tmax = tmod->obj[ob].cont[co].time;
  tmod->ctime = tmod->tmax ? 1 : 0;

  tmoda = (Imod **)malloc(sizeof(Imod *) * (a->numMods + 1));
  for (i = 0; i < a->numMods; i++)
    tmoda[i] = a->mod[i];
  tmoda[i] = tmod;
  if (a->numMods)
    free(a->mod);
  a->mod = tmoda;

  /*     a->curMod = a->numMods; */
  a->numMods++;
  /*     a->imod = tmod; */

  /* DNM: changes for storage of object properties in view and 
     relying on default scaling - switched to new method 6/26/03 */

  imodvViewsInitialize(tmod);

  imodvSelectModel(a, a->numMods - 1);
  return(0);
}
Beispiel #3
0
int main(int argc, char **argv)
{
     
  int i;
  FILE *fout;
  Imod *imod;

  extern double meshDiameterSize;
  int ch;
     
  if (argc < 2){
    usage();
    exit(1);
  }

  for (i = 1; i < argc ; i++){
    if (argv[i][0] == '-'){
      switch (argv[i][1]){
      case 'o':
        ObjectOnly = atoi(argv[++i]);
        break;
      case 'l':
        LinesOnly = 1;
        break;
      case 'm':
        puts("mesh");
        break;

      case '?':
        usage();
        exit(1);
        break;
      default:
        exit(1);
        break;
        fprintf(stderr, "imod2meta: unknown option %s\n", argv[i]);
      }
    } else
      break;
  }
     

  if (i >= (argc -1)){
    usage();
    exit(1);
  }
     
  imod = imodRead(argv[i]);
  if (!imod){
    fprintf(stderr, "Imod2meta: Error reading imod model. (%s)\n",
            argv[i]);
    exit(3);
  }
  i = argc-1;
  fout = fopen( argv[i] , "w");
  if (fout == NULL){
    printf("Couldn't open output file %s.\n", argv[i]);
    exit(10);
  }

  printModel(fout, imod);
     
  fclose(fout);
  exit(0);
}
Beispiel #4
0
int main( int argc, char *argv[])
{
  int i;
  FILE *fin, *fout;
  struct Mod_Model *mod;
  int npatch = 0;
  int nvalue = 0, nvalue2 = 0;
  int ix, iy, iz;
  float dx, dy, dz;
  float value, maxval = -1.e30;
  float value2, maxval2 = -1.e30;
  int ob, co, listInd, listStart;
  Ipoint *pts;
  char format[10] = "%10.4f";
  char format2[10] = "%10.4f";

  setExitPrefix("ERROR: imod2patch - ");


  if (argc != 3){
    if (argc != 1)
      printf("ERROR: imod2patch - wrong # of arguments\n");
    printf("imod2patch usage:\n");
    printf("imod2patch imod_model patch_file\n");
    exit(1);
  }


  i = 1;

  mod = imodRead(argv[i]);
  if (!mod)
    exitError("Reading model %s\n", argv[i]);
  
  if (imodBackupFile(argv[++i]))
    exitError("Renaming existing output file to %s\n", argv[i]);
  
  fout = fopen(argv[i], "w");
  if (!fout)
    exitError("Could not open %s\n", argv[i]);

  /* Count up patches and values and find max of values */
  for (ob = 0; ob < mod->objsize; ob++) {
    listInd = 0;
    for (co = 0; co < mod->obj[ob].contsize; co++) {
      listStart = listInd;
      if (mod->obj[ob].cont[co].psize >= 2) {
        npatch++;
        if (istoreFindValue(mod->obj[ob].store, co, GEN_STORE_VALUE1, &value,
                            &listInd)) {
          maxval = B3DMAX(maxval, value);
          nvalue++;
        }
        listInd = listStart;
        if (istoreFindValue(mod->obj[ob].store, co, GEN_STORE_VALUE2, &value2,
                            &listInd)) {
          maxval2 = B3DMAX(maxval2, value2);
          nvalue2++;
        }
      }
    }
  }

  /* If values are greater than one they are probably residuals and only need
     2 decimal places */
  if (nvalue && maxval > 1.01)
    strcpy(format, "%10.2f");
  if (nvalue2 && maxval2 > 1.01)
    strcpy(format, "%10.2f");

  fprintf(fout, "%d   edited positions\n", npatch);
  for (ob = 0; ob < mod->objsize; ob++) {
    listInd = 0;
    for (co = 0; co < mod->obj[ob].contsize; co++) {
      listStart = listInd;
      if (mod->obj[ob].cont[co].psize >= 2) {
        pts = mod->obj[ob].cont[co].pts;
        ix = pts[0].x + 0.5;
        iy = pts[0].y + 0.5;
        iz = pts[0].z + 0.5;
        dx = (pts[1].x - pts[0].x) / mod->pixsize;
        dy = (pts[1].y - pts[0].y) / mod->pixsize;
        dz = (pts[1].z - pts[0].z) / mod->pixsize;
        if (mod->flags & IMODF_FLIPYZ)
          fprintf(fout, "%6d %5d %5d %8.2f %8.2f %8.2f", 
                  ix, iz, iy, dx, dz, dy);
        else
          fprintf(fout, "%6d %5d %5d %8.2f %8.2f %8.2f", 
                  ix, iy, iz, dx, dy, dz);
        if (nvalue) {
          value = 0.;
          istoreFindValue(mod->obj[ob].store, co, GEN_STORE_VALUE1, &value,
                          &listInd);
          fprintf(fout, format, value);
          
        }
        if (nvalue2) {
          listInd = listStart;
          value2 = 0.;
          istoreFindValue(mod->obj[ob].store, co, GEN_STORE_VALUE2, &value2,
                          &listInd);
          fprintf(fout, format2, value2);
          
        }
        fprintf(fout, "\n");

      }
    }
  }
  fclose(fout);
  exit(0);
}
Beispiel #5
0
int main( int argc, char *argv[])
{
  int i, ind, col, maxValType;
  FILE *fout;
  Imod *mod;
  int npatch = 0;
  int numValues[MAX_VALUE_COLS], valueIDs[MAX_VALUE_COLS];
  int ix, iy, iz;
  int colForVal1 = 1;
  float dx, dy, dz;
  float value, maxVal[MAX_VALUE_COLS];
  int ob, co, listInd, listStart, numCols;
  Ipoint *pts;
  char format[MAX_VALUE_COLS][10];
  int colToTypeMap[MAX_VALUE_COLS];

  setExitPrefix("ERROR: imod2patch - ");


  if (argc < 3){
    if (argc != 1)
      printf("ERROR: imod2patch - wrong # of arguments\n");
    printf("imod2patch usage:\n");
    printf("imod2patch [-v col] imod_model patch_file\n");
    exit(1);
  }
  for (ind = 0; ind < MAX_VALUE_COLS; ind++) {
    numValues[ind] = 0;
    valueIDs[ind] = 0;
    colToTypeMap[ind] = -1;
    maxVal[ind] = -1.e37;
  }

  i = 1;
  if (!strcmp(argv[i], "-v")) {
    i++;
    colForVal1 = atoi(argv[i++]);
  }

  mod = imodRead(argv[i]);
  if (!mod)
    exitError("Reading model %s\n", argv[i]);
  
  if (imodBackupFile(argv[++i]))
    exitError("Renaming existing output file to %s\n", argv[i]);
  
  fout = fopen(argv[i], "w");
  if (!fout)
    exitError("Could not open %s\n", argv[i]);

  /* Count up patches and values and find max of values */
  for (ob = 0; ob < mod->objsize; ob++) {
    listInd = 0;
    for (co = 0; co < mod->obj[ob].contsize; co++) {
      listStart = listInd;
      if (mod->obj[ob].cont[co].psize >= 2) {
        npatch++;
        for (ind = 0; ind < MAX_VALUE_COLS; ind++) {
          listInd = listStart;
          if (istoreFindValue(mod->obj[ob].store, co, GEN_STORE_VALUE1 + 2 * ind, &value,
                              &listInd)) {
            maxVal[ind] = B3DMAX(maxVal[ind], value);
            numValues[ind]++;
          }
        }
      }
    }
  }
  /* printf("numval %d %d %d %f %f %f\n", numValues[0], numValues[1], numValues[2], 
     maxVal[0], maxVal[1], maxVal[2]); */

  /* Get the value ID's if any and convert an entered ID to a type #.  Also set format
     for output based on maximum value */
  maxValType = -1;
  numCols = 0;
  for (ind = 0; ind < MAX_VALUE_COLS; ind++) {
    strcpy(format[ind], "%10.4f");
    if (numValues[ind]) {
      numCols++;
      maxValType = ind;
      if (maxVal[ind] > 10.1)
        strcpy(format[ind], "%10.2f");
      else if (maxVal[ind] > 1.01)
        strcpy(format[ind], "%10.3f");
    }
  }
  for (ind = 0; ind < B3DMIN(maxValType + 1, mod->obj[0].extra[IOBJ_EXSIZE - 1]); ind++)
    valueIDs[ind] = mod->obj[0].extra[IOBJ_EXSIZE - 2 - ind];
  /*printf("# vla ID %d %d %d %d\n", maxValType, valueIDs[0],valueIDs[1],valueIDs[2]);*/

  /* Error checks on the column for value 1 */
  if (colForVal1 < 1 || colForVal1 > numCols) {
      if (numCols)
        exitError("The column for general value type must be between 1 and %d", numCols);
      exitError("There are no general values stored in the model");
  }
  colForVal1--;
  
  /* Set up map from column to value type index */
  if (numValues[0])
    colToTypeMap[colForVal1] = 0;
  col = 0;
  for (ind = 1; ind <= maxValType; ind++) {
    if (numValues[ind]) {
      if (!colToTypeMap[col])
        col++;
      colToTypeMap[col++] = ind;
    }
  }
  /*printf("%d %d %d %d\n", numCols, colToTypeMap[0], colToTypeMap[1], colToTypeMap[2]);*/

  /* Output the header line */
  fprintf(fout, "%d   edited positions", npatch);
  if (mod->obj[0].extra[IOBJ_EXSIZE - 1] > 0)
    for (col = 0; col < numCols; col++)
      fprintf(fout, "  %d", valueIDs[colToTypeMap[col]]);
  fprintf(fout, "\n");

  for (ob = 0; ob < mod->objsize; ob++) {
    listInd = 0;
    for (co = 0; co < mod->obj[ob].contsize; co++) {
      listStart = listInd;
      if (mod->obj[ob].cont[co].psize >= 2) {
        pts = mod->obj[ob].cont[co].pts;
        ix = pts[0].x + 0.5;
        iy = pts[0].y + 0.5;
        iz = pts[0].z + 0.5;
        dx = (pts[1].x - pts[0].x) / mod->pixsize;
        dy = (pts[1].y - pts[0].y) / mod->pixsize;
        dz = (pts[1].z - pts[0].z) / mod->pixsize;
        if (mod->flags & IMODF_FLIPYZ)
          fprintf(fout, "%6d %5d %5d %8.2f %8.2f %8.2f", 
                  ix, iz, iy, dx, dz, dy);
        else
          fprintf(fout, "%6d %5d %5d %8.2f %8.2f %8.2f", 
                  ix, iy, iz, dx, dy, dz);
        for (col = 0; col < numCols; col++) {
          ind = colToTypeMap[col];
          if (numValues[ind]) {
            listInd = listStart;
            value = 0.;
            istoreFindValue(mod->obj[ob].store, co, GEN_STORE_VALUE1 + 2 * ind, &value,
                            &listInd);
            fprintf(fout, format[ind], value);
          }
        }
        fprintf(fout, "\n");

      }
    }
  }
  fclose(fout);
  exit(0);
}