Example #1
0
int
limnPolyDataCopy(limnPolyData *pldB, const limnPolyData *pldA) {
  char me[]="limnPolyDataCopy", err[BIFF_STRLEN];

  if (!( pldB && pldA )) {
    sprintf(err, "%s: got NULL pointer", me);
    biffAdd(LIMN, err); return 1;
  }
  if (limnPolyDataAlloc(pldB, limnPolyDataInfoBitFlag(pldA),
                        pldA->xyzwNum, pldA->indxNum, pldA->primNum)) {
    sprintf(err, "%s: couldn't allocate output", me);
    biffAdd(LIMN, err); return 1;
  }
  memcpy(pldB->xyzw, pldA->xyzw, pldA->xyzwNum*sizeof(float)*4);
  if (pldA->rgba) {
    memcpy(pldB->rgba, pldA->rgba, pldA->rgbaNum*sizeof(unsigned char)*4);
  }
  if (pldA->norm) {
    memcpy(pldB->norm, pldA->norm, pldA->normNum*sizeof(float)*3);
  }
  if (pldA->tex2) {
    memcpy(pldB->tex2, pldA->tex2, pldA->tex2Num*sizeof(float)*2);
  }
  memcpy(pldB->indx, pldA->indx, pldA->indxNum*sizeof(unsigned int));
  memcpy(pldB->type, pldA->type, pldA->primNum*sizeof(signed char));
  memcpy(pldB->icnt, pldA->icnt, pldA->primNum*sizeof(unsigned int));
  return 0;
}
Example #2
0
File: clip.c Project: BRAINSia/teem
int
main(int argc, const char *argv[]) {
  const char *me;
  char *err, *outS;
  hestOpt *hopt=NULL;
  airArray *mop;

  limnPolyData *pld;
  FILE *file;
  Nrrd *nin;
  double thresh;
  int bitflag;

  me = argv[0];
  hestOptAdd(&hopt, "vi", "nin", airTypeOther, 1, 1, &nin, NULL,
             "input values",
             NULL, NULL, nrrdHestNrrd);
  hestOptAdd(&hopt, "pi", "lpld", airTypeOther, 1, 1, &pld, NULL,
             "input polydata",
             NULL, NULL, limnHestPolyDataLMPD);
  hestOptAdd(&hopt, "th", "thresh", airTypeDouble, 1, 1, &thresh, NULL,
             "threshold value");
  hestOptAdd(&hopt, "o", "output LMPD", airTypeString, 1, 1, &outS, "out.lmpd",
             "output file to save LMPD into");
  hestParseOrDie(hopt, argc-1, argv+1, NULL,
                 me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  mop = airMopNew();
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  bitflag = limnPolyDataInfoBitFlag(pld);
  fprintf(stderr, "!%s: bitflag = %d\n", me, bitflag);
  fprintf(stderr, "!%s: rgba %d,  norm %d,   tex2 %d\n", me,
          (1 << limnPolyDataInfoRGBA) & bitflag,
          (1 << limnPolyDataInfoNorm) & bitflag,
          (1 << limnPolyDataInfoTex2) & bitflag);

  file = airFopen(outS, stdout, "w");
  if (!file) {
    fprintf(stderr, "%s: couldn't open \"%s\" for writing", me, outS);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

  if (limnPolyDataClip(pld, nin, thresh)
      || limnPolyDataWriteLMPD(file, pld)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:\n%s\n", me, err);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
Example #3
0
int
limnPolyDataCopyN(limnPolyData *pldB, const limnPolyData *pldA,
                  unsigned int num) {
  char me[]="limnPolyDataCopyN", err[BIFF_STRLEN];
  unsigned int ii, jj, size;

  if (!( pldB && pldA )) {
    sprintf(err, "%s: got NULL pointer", me);
    biffAdd(LIMN, err); return 1;
  }
  if (limnPolyDataAlloc(pldB, limnPolyDataInfoBitFlag(pldA),
                        num*pldA->xyzwNum,
                        num*pldA->indxNum,
                        num*pldA->primNum)) {
    sprintf(err, "%s: couldn't allocate output", me);
    biffAdd(LIMN, err); return 1;
  }
  for (ii=0; ii<num; ii++) {
    /* fprintf(stderr, "!%s: ii = %u/%u\n", me, ii, num); */
    size = pldA->xyzwNum*4;
    /*
    char *_beg = (char *)(pldB->xyzw + ii*size);
    char *_end = _beg + size - 1;
    fprintf(stderr, "!%s: memcpy(%p+%u=%p,%u) --> [%p,%p] inside: %d %d\n", me,
            pldB->xyzw, ii*size, pldB->xyzw + ii*size, size,
            _beg, _end, AIR_IN_CL(_xyzwBeg, _beg, _xyzwEnd), 
            AIR_IN_CL(_xyzwBeg, _end, _xyzwEnd));
    */
    memcpy(pldB->xyzw + ii*size, pldA->xyzw, size*sizeof(float));
    for (jj=0; jj<pldA->indxNum; jj++) {
      (pldB->indx + ii*pldA->indxNum)[jj] = pldA->indx[jj] + ii*pldA->xyzwNum;
    }
    size = pldA->primNum;
    memcpy(pldB->type + ii*size, pldA->type, size*sizeof(unsigned char));
    memcpy(pldB->icnt + ii*size, pldA->icnt, size*sizeof(unsigned int));
    if (pldA->rgba) {
      size = pldA->rgbaNum*4;
      memcpy(pldB->rgba + ii*size, pldA->rgba, size*sizeof(unsigned char));
    }
    if (pldA->norm) {
      size = pldA->normNum*3;
      memcpy(pldB->norm + ii*size, pldA->norm, size*sizeof(float));
    }
    if (pldA->tex2) {
      size = pldA->tex2Num*2;
      memcpy(pldB->tex2 + ii*size, pldA->tex2, size*sizeof(float));
    }
  }
  return 0;
}