Example #1
0
int main(int	argc,
	 char	**argv)
{

  WlzObject	*obj;
  FILE		*inFile;
  char 		optList[] = "b:hv";
  int		option;
  WlzPixelV	bckgrnd;
  int		verboseFlg=0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
    
  /* read the argument list and check for an input file */
  opterr = 0;
  bckgrnd.type = WLZ_GREY_DOUBLE;
  bckgrnd.v.dbv = 0.0;
  
  while( (option = getopt(argc, argv, optList)) != EOF ){
    switch( option ){

    case 'b':
      bckgrnd.v.dbv = atof(optarg);
      break;

    case 'v':
      verboseFlg = 1;
      break;

    case 'h':
    default:
      usage(argv[0]);
      return 1;

    }
  }

  inFile = stdin;
  if( optind < argc ){
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
  }

  /* read objects and threshold if possible */
  while(((obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) != NULL) &&
        (errNum == WLZ_ERR_NONE))
  {
    switch( obj->type )
    {
    case WLZ_2D_DOMAINOBJ:
    case WLZ_3D_DOMAINOBJ:
      errNum = WlzSetBackground(obj, bckgrnd);
      if( errNum == WLZ_ERR_NONE ){
	if( verboseFlg ){
	  fprintf(stderr,
		  "%s:background set to %f\n",
		  argv[0], bckgrnd.v.dbv);
	}

	if((errNum = WlzWriteObj(stdout, obj)) != WLZ_ERR_NONE) {
	  (void )WlzStringFromErrorNum(errNum, &errMsg);
	  (void )fprintf(stderr,
			 "%s: failed to write object (%s).\n",
			 argv[0], errMsg);
	  return(1);
	}
      }
      break;

    default:
      if((errNum = WlzWriteObj(stdout, obj)) != WLZ_ERR_NONE) {
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write object (%s).\n",
		       argv[0], errMsg);
	return(1);
      }
      break;
    }
    WlzFreeObj(obj);
  }

  return 0;
}
Example #2
0
int             main(int argc, char **argv)
{
    int		option,
            ok = 1,
            usage = 0;
    double	disp = 0.0;
    WlzObject     *inObj = NULL,
                   *outObj = NULL;
    FILE		*fP = NULL;
    char		*inObjFileStr,
                *outObjFileStr;
    WlzErrorNum	errNum = WLZ_ERR_NONE;
    const char	*errMsg;
    static char	optList[] = "hd:o:",
                            fileStrDef[] = "-";

    opterr = 0;
    inObjFileStr = fileStrDef;
    outObjFileStr = fileStrDef;
    while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
    {
        switch(option)
        {
        case 'o':
            outObjFileStr = optarg;
            break;
        case 'd':
            if(sscanf(optarg, "%lg", &disp) != 1)
            {
                usage = 1;
            }
            break;
        case 'h': /* FALLTHROUGH */
        default:
            usage = 1;
            break;
        }
    }
    if((usage == 0) && (optind < argc))
    {
        if((optind + 1) != argc)
        {
            usage = 1;
        }
        else
        {
            inObjFileStr = *(argv + optind);
        }
    }
    ok = (usage == 0);
    if(ok)
    {
        if((inObjFileStr == NULL) ||
                (*inObjFileStr == '\0') ||
                ((fP = (strcmp(inObjFileStr, "-")?
                        fopen(inObjFileStr, "r"): stdin)) == NULL) ||
                ((inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
                (errNum != WLZ_ERR_NONE))
        {
            ok = 0;
        }
        if(fP)
        {
            if(strcmp(inObjFileStr, "-"))
            {
                (void )fclose(fP);
            }
            fP = NULL;
        }
    }
    if(ok)
    {
        outObj = WlzCMeshToContour(inObj, disp, &errNum);
        if(errNum != WLZ_ERR_NONE)
        {
            ok = 0;
            (void )WlzStringFromErrorNum(errNum, &errMsg);
            (void )fprintf(stderr,
                           "%s: Failed to create contour from conforming mesh (%s).\n",
                           *argv, errMsg);

        }
    }
    if(ok)
    {
        errNum = WLZ_ERR_WRITE_EOF;
        if(((fP = (strcmp(outObjFileStr, "-")?
                   fopen(outObjFileStr, "w"): stdout)) == NULL) ||
                ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
        {
            ok = 0;
            (void )WlzStringFromErrorNum(errNum, &errMsg);
            (void )fprintf(stderr,
                           "%s: Failed to write output object (%s).\n",
                           *argv, errMsg);
        }
        if(fP && strcmp(outObjFileStr, "-"))
        {
            (void )fclose(fP);
        }
    }
    (void )WlzFreeObj(inObj);
    (void )WlzFreeObj(outObj);
    if(usage)
    {
        (void )fprintf(stderr,
                       "Usage: %s%s%s%sExample: %s%s",
                       *argv,
                       " [-h] [-d #] [-o<output object>] [<input object>]\n"
                       "Version: ",
                       WlzVersion(),
                       "\n"
                       "Options:\n"
                       "  -h  Help, prints usage message.\n"
                       "  -d  Apply given scale factor to mesh displacements if they exist.\n"
                       "      The default is no mesh displacements are applied.\n"
                       "  -o  Output object file.\n"
                       "Creates a contour object from a conforming mesh. This is currently\n"
                       "only possible for a 2D5 conforming mesh, which results in a 3D contour\n"
                       "(collection of surfaces).  By default the input file is read from the\n"
                       "standard input and the output file is written to the standard output.\n",
                       *argv,
                       "  -o out.wlz -d 1.0 in.wlz\n"
                       "Reads a 2D5 conforming mesh from the file in.wlz, applies the meshes\n"
                       "displacements to it's nodes and then outputs the corresponding contour\n"
                       "to the file out.wlz.\n");
    }
    return(!ok);
}
Example #3
0
int             main(int argc, char **argv)
{
  int		idx,
  		option,
		asciiFlag = 0,
		nBins = 0,
		ok = 1,
		usage = 0;
  double	binOrigin = 0.0,
  		binSize = 1.0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  WlzHistogramDomain *histDom;
  WlzObject	*inObj = NULL,
		*outObj = NULL;
  const char	*errMsg;
  char 		*outObjFileStr,
  		*inObjFileStr;
  static char	optList[] = "o:n:s:w:ah",
		outObjFileStrDef[] = "-",
  		inObjFileStrDef[] = "-";

  opterr = 0;
  outObjFileStr = outObjFileStrDef;
  inObjFileStr = inObjFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'a':
        asciiFlag = 1;
	break;
      case 'o':
        outObjFileStr = optarg;
	break;
      case 'n':
	if(sscanf(optarg, "%d", &nBins) != 1)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 's':
	if(sscanf(optarg, "%lg", &binOrigin) != 1)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 'w':
	if(sscanf(optarg, "%lg", &binSize) != 1)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 'h':
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if((inObjFileStr == NULL) || (*inObjFileStr == '\0') ||
     (outObjFileStr == NULL) || (*outObjFileStr == '\0'))
  {
    ok = 0;
    usage = 1;
  }
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      inObjFileStr = *(argv + optind);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_READ_EOF;
    if((inObjFileStr == NULL) ||
       (*inObjFileStr == '\0') ||
       ((fP = (strcmp(inObjFileStr, "-")?
	      fopen(inObjFileStr, "r"): stdin)) == NULL) ||
       ((inObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to read object from file %s (%s)\n",
		     *argv, inObjFileStr, errMsg);
    }
    if(fP && strcmp(inObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  if(ok)
  {
    if(((outObj = WlzHistogramObj(inObj, nBins, binOrigin,
    				  binSize, &errNum)) == NULL) ||
       (errNum != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to compute histogram object (%s)\n",
		     *argv,
		     WlzStringFromErrorNum(errNum, NULL));
    }
  }
  if(ok)
  {
    if(asciiFlag)
    {
      if((fP = (strcmp(outObjFileStr, "-")?
               fopen(outObjFileStr, "w"): stdout)) == NULL)
      {
        ok = 0;
	(void )fprintf(stderr,
		       "%s: failed to write output data\n",
		       *argv);
      }
      else
      {
	histDom = outObj->domain.hist;
	switch(histDom->type)
	{
	  case WLZ_HISTOGRAMDOMAIN_INT:
	    for(idx = 0; idx < histDom->nBins; ++idx)
	    {
	      fprintf(fP, "%8g %8d\n",
		      histDom->origin + (idx * histDom->binSize),
		      *(histDom->binValues.inp + idx));
	    }
	    break;
	  case WLZ_HISTOGRAMDOMAIN_FLOAT:
	    for(idx = 0; idx < histDom->nBins; ++idx)
	    {
	      fprintf(fP, "%8g %8g\n",
		      histDom->origin + (idx * histDom->binSize),
		      *(histDom->binValues.dbp + idx));
	    }
	    break;
	  default:
	    break;
	}
      }
    }
    else
    {
      errNum = WLZ_ERR_WRITE_EOF;
      if(((fP = (strcmp(outObjFileStr, "-")?
		fopen(outObjFileStr, "w"):
		stdout)) == NULL) ||
	 ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write output object (%s)\n",
		       *argv, errMsg);
      }
    }
    if(fP && strcmp(outObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  if(inObj)
  {
    WlzFreeObj(inObj);
  }
  if(outObj)
  {
    WlzFreeObj(outObj);
  }
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%sExample 1: %s%sExample 2: %s%s",
    *argv,
    " [-h] [-a] [-o<out file>] [-n#] [-s#] [-w#] [<in object>]\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -a  Output the histogram as ascii data not a Woolz histogram object.\n"
    "  -o  Output object/data file name.\n"
    "  -n  Number of histogram bins.\n"
    "  -s  Start value, lower limit of histogram.\n"
    "  -w  Histogram bin width.\n"
    "  -h  Help, prints this usage message.\n"
    "Computes a Woolz histogram object from the input Woolz object.\n"
    "Objects/data are read from stdin and written to stdout unless the\n"
    "filenames are given.\n",
    *argv,
    " -a myobj.wlz | xgraph\n"
    "The input Woolz object is read from myobj.wlz, a histogram is\n"
    "computed and written as ascii data for display by the program xgraph.\n",
    *argv,
    " -o myHist.wlz myobj.wlz\n"
    "The input Woolz object is read from myobj.wlz, a histogram is computed\n"
    "and written as a Woolz histogram object to the file myHist.wlz\n");
  }
  return(!ok);
}
Example #4
0
WlzObject	*WlzGetContourObj(WlzObject *inObj){
  int		flip = 1,
		nrm = 0,
		nItr = 10,
		nonMan = 0,
		filterGeom = 1,
		setbackVz = 0;
  double 	lambda = 0,
		mu = 0,
		ctrVal = 100,
		ctrWth = 1.0,
		filterPB = 0.1,
		filterSB = 1.1,
		xsize = 1,
		ysize = 1,
		zsize = 1;
  WlzDomain	ctrDom;
  WlzValues	dumVal;
  WlzContourMethod ctrMtd = WLZ_CONTOUR_MTD_BND;
  const double	filterDPB = 0.25,
		filterDSB = 0.10;
  const char	*errMsgStr;
  WlzObject	*outObj = NULL;
  WlzErrorNum   errNum = WLZ_ERR_NONE;

  ctrDom.core = NULL;
  dumVal.core = NULL;
  if(inObj && (inObj->type == WLZ_3D_DOMAINOBJ) && (inObj->domain.core) &&
     (inObj->domain.core->type == WLZ_2D_DOMAINOBJ))
  {
    xsize = inObj->domain.p->voxel_size[0];
    ysize = inObj->domain.p->voxel_size[1];
    zsize = inObj->domain.p->voxel_size[2];
    inObj->domain.p->voxel_size[0] = 1.0;
    inObj->domain.p->voxel_size[1] = 1.0;
    inObj->domain.p->voxel_size[2] = 1.0;
  }
  else
  {
    errNum = WLZ_ERR_OBJECT_TYPE;
  }
  if(errNum == WLZ_ERR_NONE)
  {
    ctrDom.ctr = WlzContourObj(inObj, ctrMtd,ctrVal, ctrWth, nrm, &errNum);
    if((errNum != WLZ_ERR_NONE) && filterGeom)
    {
      errNum = WlzGMFilterGeomLPParam(&lambda, &mu, &nItr, 
	                              filterPB, filterSB, filterDPB,
				      filterDSB);
      if(errNum != WLZ_ERR_NONE)
      {
	errNum = WlzGMFilterGeomLPLM(ctrDom.ctr->model,
	                             lambda, mu, nItr, nonMan);
	if(errNum != WLZ_ERR_NONE)
	{
	  outObj = WlzMakeMain(WLZ_CONTOUR, ctrDom, 
	                       dumVal, NULL, NULL, &errNum);
	  if(setbackVz)
	  {
	    inObj->domain.p->voxel_size[0] = xsize;
	    inObj->domain.p->voxel_size[1] = ysize;
	    inObj->domain.p->voxel_size[2] = zsize;
	  }
	  if((errNum != WLZ_ERR_NONE) &&
	     flip && ctrDom.core && ctrDom.ctr->model)
	  {
	    errNum  = WlzGMFilterFlipOrient(ctrDom.ctr->model);
	  }
	}
      }
    }
  }
  (void)WlzStringFromErrorNum(errNum, &errMsgStr);
  return(outObj);
}
int		main(int argc, char *argv[])
{
  int		ok = 1,
  		option,
  		usage = 0,
		markerSep = 16,
		markerSz = 4;
  FILE		*fP = NULL;
  char		*iFile,
  		*oFile;
  const char	*errMsg;
  WlzObject	*iObj = NULL,
  		*oObj = NULL;
  WlzMarkerType	markerType = WLZ_MARKER_SPHERE;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  static char   optList[] = "ho:s:t:z:";
  const char    defFile[] = "-";

  opterr = 0;
  iFile = (char *)defFile;
  oFile = (char *)defFile;
  while(ok && ((option = getopt(argc, argv, optList)) != EOF))
  {
    switch(option)
    {
      case 'o':
        oFile = optarg;
	break;
      case 's':
	if(sscanf(optarg, "%d", &markerSep) != 1)
	{
	  usage = 1;
	}
        break;
      case 't':
	markerType = WlzStringToMarkerType(optarg, &errNum);
	if(errNum != WLZ_ERR_NONE)
	{
	  usage = 1;
	}
        break;
      case 'z':
	if(sscanf(optarg, "%d", &markerSz) != 1)
	{
	  usage = 1;
	}
        break;
      case 'h': /* FALLTROUGH */
      default:
	usage = 1;
	break;
    }
  }
  if(usage == 0)
  {
    if((oFile == NULL) || (*oFile == '\0') ||
       (iFile == NULL) || (*iFile == '\0'))
    {
      usage = 1;
    }
  }
  if((usage == 0) && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
    }
    else
    {
      iFile = *(argv + optind);
    }
  }
  ok = !usage;
  if(ok)
  {
    if((fP = (strcmp(iFile, "-")? fopen(iFile, "r"): stdin)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
		     "%s: Failed to open input file %s.\n",
		     argv[0], iFile);
    }
  }
  if(ok)
  {
    iObj = WlzReadObj(fP, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to read input domain object, %s.\n",
		     argv[0], errMsg);
    }
  }
  if(fP && strcmp(iFile, "-"))
  {
    (void )fclose(fP);
  }
  if(ok)
  {
    oObj = WlzMarkerLattice(iObj, markerType, markerSz, markerSep, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: Failed to create domain from vertices (%s).\n",
      		     argv[0],
		     errMsg);
    }
  }
  if(ok)
  {
    if((fP = (strcmp(oFile, "-")? fopen(oFile, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
		     "%s: Failed to open output file %s.\n",
		     argv[0], oFile);
    }
  }
  if(ok)
  {
    errNum = WlzWriteObj(fP, oObj);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to write output object, %s.\n",
		     argv[0], errMsg);
    }
  }
  if(fP && strcmp(oFile, "-"))
  {
    (void )fclose(fP);
  }
  (void )WlzFreeObj(iObj);
  (void )WlzFreeObj(oObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-h] [-o<output>] [-s #] [-t <type>] [-z #]\n"
    "                                  [<input>]\n"
    "Version: %s\n"
    "Options:\n"
    "  -h  Output this usage message.\n"
    "  -o  Output file name, default is the standard output.\n"
    "  -s  Marker separation.\n"
    "  -t  Marker type: Only valid type is 'sphere'.\n"
    "  -z  Marker size.\n"
    "Reads either a 2D or 3D spatial domain object from a given file or\n"
    "the standard input (default). A new domainis then constructed which\n"
    "covers the given domain with a lattice of markers.\n",
    argv[0],
    WlzVersion());
  }
  return(!ok);
}
int             main(int argc, char **argv)
{
  int		option,
		ok = 1,
		usage = 0;
  LUTEntry	LUTEntries[256];
  int		LUTEntryCount;
  int		entryIdx, index;
  int		val = 0, indexGap, indexDist;
  WlzObject	*outObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  const char	*errMsg;
  char 		*outFileStr;
  char		*inFileStr;
  static char	optList[] = "ho:",
		outFileStrDef[] = "-",
  		inFileStrDef[] = "-";

  opterr = 0;
  outFileStr = outFileStrDef;
  inFileStr = inFileStrDef;
  /* Parse the command line. */
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
    case 'o':
      outFileStr = optarg;
      break;
    case 'h':
    default:
      usage = 1;
      break;
    }
  }
  if(usage == 0)
  {
    if((outFileStr == NULL) || (*outFileStr == '\0'))
    {
      usage = 1;
    }
    if(usage == 0)
    {
      if((argc - optind) > 0)
      {
	inFileStr = *(argv+optind);
      }
    }
  }
  ok = (usage == 0);
  /* Read  input LUT from infile or stdin. */
  if(ok)
  {
    if( *inFileStr == '-' ){
      fP = stdin;
    } else {
      if( (fP = fopen(inFileStr, "r")) == NULL ){
	 ok = 0;
	 (void) fprintf(stderr,
	                 "%s: failed to open input file %s\n",
			 *argv, inFileStr);
      }
    }
    if(ok){
      /* read the LUT index and values */
      for( LUTEntryCount=0; LUTEntryCount < 256; LUTEntryCount++){
	if( fscanf(fP, "%d,%d", &LUTEntries[LUTEntryCount].index, &LUTEntries[LUTEntryCount].value) < 2 ){
	  break;
	}
      }
      /* check for no data */
      if( LUTEntryCount == 0 ) {
	ok = 0;
	(void) fprintf(stderr,
		       "%s: No LUT entries found please check the input file\n",
		       *argv);
      } else {
	/* sort the LUTEntries */
	(void )AlgSort(LUTEntries, (size_t) LUTEntryCount, sizeof(LUTEntry),
		       ComparLUTEntry);

	/* check highest index add endpoint if needed */
	if( LUTEntries[LUTEntryCount-1].index < 255 ){
	  LUTEntries[LUTEntryCount].index = 255;
	  LUTEntries[LUTEntryCount].value = LUTEntries[LUTEntryCount - 1].value;
	  LUTEntryCount++;
	}
	
	/* check lowest index add startpoint if needed */
	if( LUTEntries[0].index > 0 ){
	  LUTEntries[LUTEntryCount].index = 0;
	  LUTEntries[LUTEntryCount].value = LUTEntries[0].value;
	  LUTEntryCount++;
	}

	/* re-sort the LUTEntries */
	(void )AlgSort(LUTEntries, (size_t) LUTEntryCount, sizeof(LUTEntry),
		       ComparLUTEntry);

      }
    }
  }

  /* Create a LUT object for the range 0-255 */
  if(ok)
  {
    outObj = WlzAssignObject(
             WlzMakeLUTObject(WLZ_GREY_INT, 0, 255, &errNum), NULL);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to create new LUT object (%s)\n",
		     *argv, errMsg);
    }
  }
  /* Calculate the new LUT from the LUTEntries */
  if(ok){
    entryIdx = 0;
    for(index=0; index < 256; index++){
      if( index == LUTEntries[entryIdx].index ){
	val = LUTEntries[entryIdx].value;
	entryIdx++;
      }
      else if( index < LUTEntries[entryIdx].index ){
	indexGap = LUTEntries[entryIdx].index - LUTEntries[entryIdx-1].index;
	indexDist = index - LUTEntries[entryIdx-1].index;
	if( indexGap == 0 ){
	  /* shouldn't get here - something weird */
	  val =  LUTEntries[entryIdx].value;
	} else {
	  val = ((indexGap - indexDist) * LUTEntries[entryIdx-1].value + \
		 indexDist * LUTEntries[entryIdx].value) / indexGap;
	}
      }
      *((outObj->values.lut->val.inp) + index) = val;
    }
  }

  /* write object as required */
  if(ok)
  {
    if(((fP = (strcmp(outFileStr, "-")?
	      fopen(outFileStr, "w"): stdout)) == NULL) ||
	(WlzWriteObj(fP, outObj) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to write LUT object to file %s (%s).\n",
		     *argv, outFileStr, errMsg);
    }
    if(fP && strcmp(outFileStr, "-"))
    {
      fclose(fP);
      fP = NULL;
    }
  }
  WlzFreeObj(outObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s",
    *argv,
    " [-o<output object>] [-h]\n" 
    "Options:\n"
    "  -h  Help, prints this usage message.\n"
    "  -o  Output object.\n"
    "Reads the LUT values from a text file or from standard input. Assumes\n"
    "value-pairs (index, value) and in this version a LUT will be created\n"
    "with 0 <= index <= 255. If the \"-f\" flag is used then values wil be\n"
    "interpolated from 0-255 using the values that are set. Values below\n"
    "the minimum index value and above the maximum index value are set to\n"
    "the min and max values respectively.\n");
  }
  return(!ok);
}
Example #7
0
int		main(int argc, char *argv[])
{
  int		ok,
		binFlg = 0,
  		nAng = 360,
		maxRFlg = 0,
  		option,
		usage = 0;
  double	cen = 0.0,
  		maxR = 0.0;
  char		*fFileStr,
  		*rFileStr,
		*oFileStr;
  FILE		*fP = NULL;
  WlzObject	*fObj = NULL,
		*rObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsgStr;
  static char	optList[] = "bhn:o:R";
  const char    fileStrDef[] = "-";

  /* Parse the argument list and check for input files. */
  opterr = 0;
  fFileStr = (char *)fileStrDef;
  rFileStr = (char *)fileStrDef;
  oFileStr = (char *)fileStrDef;
  while((option = getopt(argc, argv, optList)) != EOF)
  {
    switch(option)
    {
      case 'b':
        binFlg = 1;
	break;
      case 'n':
	if((sscanf(optarg, "%d", &nAng) != 1) || (nAng <= 0))
	{
	  usage = 1;
	}
	break;
      case 'o':
	oFileStr = optarg;
	break;
      case 'R':
        maxRFlg = 1;
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  ok = !usage;
  if(ok && (optind < argc))
  {
    if((optind + 1) == argc)
    {
      fFileStr = argv[optind];
    }
    else if((optind + 2) == argc)
    {
      fFileStr = argv[optind];
      rFileStr = argv[optind + 1];
    }
    else
    {
      usage = 1;
    }
  }
  ok = !usage;
  /* Read the feature object. */
  if(ok)
  {
    if((fFileStr == NULL) ||
       (*fFileStr == '\0') ||
       ((fP = (strcmp(fFileStr, "-")?
              fopen(fFileStr, "r"): stdin)) == NULL) ||
       ((fObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read feature object from file %s.\n",
                     argv[0], fFileStr);
    }
    if(fP && strcmp(fFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Read the reference object. */
  if(ok)
  {
    if((rFileStr == NULL) ||
       (*rFileStr == '\0') ||
       ((fP = (strcmp(rFileStr, "-")?
              fopen(rFileStr, "r"): stdin)) == NULL) ||
       ((rObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read reference object from file %s.\n",
                     argv[0], rFileStr);
    }
    if(fP && strcmp(rFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Check object types and parse the promote the default distance function
   * if required. */
  if(ok)
  {
    if(rObj->type != fObj->type)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Feature and reference object types differ.\n",
		     argv[0]);
    }
  }
  /* Compute centrality feature. */
  if(ok)
  {
    cen = WlzCentrality(fObj, rObj, nAng, binFlg, &maxR, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to compute centrality feature value (%s).\n",
                     argv[0], errMsgStr);
    }
  }
  /* Output the centrality feature value. */
  if(ok)
  {
    if((fP = (strcmp(oFileStr, "-")?
             fopen(oFileStr, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to open output file %s.\n",
                     argv[0], oFileStr);
    }
  }
  if(ok)
  {
    if(((maxRFlg == 0) && (fprintf(fP, "%lg\n", cen) <= 0)) ||
       ((maxRFlg != 0) && (fprintf(fP, "%lg %lg\n", cen, maxR) <= 0)))
    {
      ok = 0;
      errNum = WLZ_ERR_WRITE_INCOMPLETE;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to write output feature value (%s).\n",
                     argv[0], errMsgStr);
    }
  }
  (void )WlzFreeObj(fObj);
  (void )WlzFreeObj(rObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-b] [-h] [-n#] [-o <output file>] [-R]\n"
    "                        [<feat obj>] [<ref obj>]\n"
    "Version: %s\n"
    "Computes the centrality of the feature object's domain with respect to\n"
    "the reference object's domain.\n"
    "\n"
    "Options are:\n"
    "  -b  Treat the feature object as a binary object with constant values.\n"
    "  -h  Help - prints this usage message\n"
    "  -n  Number of angle increments to use (default 360).\n"
    "  -o  Output file for centrality feature value.\n"
    "  -R  Output maximum radius value after centrality value.\n"
    "By default the feature and reference objects are read from the standard\n"
    "input. This may be made explicit if only one of these is given by using\n"
    "- to specify the standard input.\n",
    argv[0],
    WlzVersion());
  }
  return(!ok);
}
Example #8
0
int             main(int argc, char **argv)
{
  int		option,
		ok = 1,
		usage = 0;
  WlzObject	*inObj = NULL,
		*outObj = NULL;
  FILE		*fP = NULL;
  WlzFnType	fn = WLZ_FN_SCALAR_MOD;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  char 		*inObjFileStr,
  		*outObjFileStr;
  const char    *errMsg;
  static char	optList[] = "ehlmsSo:",
  		inObjFileStrDef[] = "-",
		outObjFileStrDef[] = "-";

  opterr = 0;
  outObjFileStr = outObjFileStrDef;
  inObjFileStr = inObjFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
        outObjFileStr = optarg;
	break;
      case 'e':
        fn = WLZ_FN_SCALAR_EXP;
	break;
      case 'm':
        fn = WLZ_FN_SCALAR_MOD;
	break;
      case 'l':
	fn = WLZ_FN_SCALAR_LOG;
	break;
      case 's':
	fn = WLZ_FN_SCALAR_SQRT;
	break;
      case 'S':
	fn = WLZ_FN_SCALAR_INVSQRT;
	break;
      case 'h':
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if((inObjFileStr == NULL) || (*inObjFileStr == '\0') ||
     (outObjFileStr == NULL) || (*outObjFileStr == '\0'))
  {
    ok = 0;
    usage = 1;
  }
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      inObjFileStr = *(argv + optind);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_READ_EOF;
    if((inObjFileStr == NULL) ||
	(*inObjFileStr == '\0') ||
	((fP = (strcmp(inObjFileStr, "-")?
		fopen(inObjFileStr, "r"): stdin)) == NULL) ||
	((inObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
	(errNum != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )fprintf(stderr,
		     "%s: failed to read object from file %s\n",
		     *argv, inObjFileStr);
    }
    if(fP)
    {
      if(strcmp(inObjFileStr, "-"))
      {
	fclose(fP);
      }
      fP = NULL;
    }
  }
  if(ok)
  {
    outObj = WlzScalarFn(inObj, fn, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to apply scalar function to object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    if(errNum == WLZ_ERR_NONE)
    {
      errNum = WLZ_ERR_WRITE_EOF;
      if(((fP = (strcmp(outObjFileStr, "-")?
		fopen(outObjFileStr, "w"):
		stdout)) == NULL) ||
	 ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write output object (%s).\n",
		       *argv, errMsg);
      }
      if(fP && strcmp(outObjFileStr, "-"))
      {
	fclose(fP);
      }
    }
  }
  (void )WlzFreeObj(inObj);
  (void )WlzFreeObj(outObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s",
    *argv,
    " [-o<out object>] [-h>]\n"
    "                  [-e] [-m] [-l]\n"
    "                  [<in object>]\n"
    "Options:\n"
    "  -e  Exponential function (g_out = exp(g_in)).\n"
    "  -m  Mudulus function (g_out = |g_in|).\n"
    "  -l  Log function (g_out = log(g_in)).\n"
    "  -s  Square root function (g_out = sqrt(g_in)).\n"
    "  -S  Inverse square root function (g_out = 1.0 / sqrt(g_in)).\n"
    "  -o  Output object file name.\n"
    "  -h  Help, prints this usage message.\n"
    "Applies a scalar function to the values of a Woolz object.\n");
  }
  return(!ok);
}
Example #9
0
int main(int	argc,
	 char	**argv)
{

  WlzObject	*obj;
  FILE		*inFile;
  char 		optList[] = "x:y:z:hv";
  int		option;
  int		xFlg=0, yFlg=0, zFlg=0;
  float		x_size=1.0, y_size=1.0, z_size=1.0;
  int		verboseFlg=0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
    
  /* read the argument list and check for an input file */
  opterr = 0;
  
  while( (option = getopt(argc, argv, optList)) != EOF ){
    switch( option ){

    case 'x':
      x_size = atof(optarg);
      xFlg = 1;
      break;

    case 'y':
      y_size = atof(optarg);
      yFlg = 1;
      break;

    case 'z':
      z_size = atof(optarg);
      zFlg = 1;
      break;

    case 'v':
      verboseFlg = 1;
      break;

    case 'h':
    default:
      usage(argv[0]);
      return 1;

    }
  }

  if( (x_size <= 0.0) || (y_size <= 0.0) || (z_size <= 0.0) ){
    fprintf(stderr, "%s: voxel sizes must be non-zero and positive\n",
	    argv[0]);
    return 1;
  }

  inFile = stdin;
  if( optind < argc ){
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
  }

  /* read objects and threshold if possible */
  while(((obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) != NULL) &&
        (errNum == WLZ_ERR_NONE))
  {
    switch( obj->type )
    {
    case WLZ_3D_DOMAINOBJ:
      if( obj->domain.p && (obj->domain.p->type == WLZ_2D_DOMAINOBJ) ){
	if( xFlg ){
	  obj->domain.p->voxel_size[0] = x_size;
	}
	if( yFlg ){
	  obj->domain.p->voxel_size[1] = y_size;
	}
	if( zFlg ){
	  obj->domain.p->voxel_size[2] = z_size;
	}
      }
      if((errNum = WlzWriteObj(stdout, obj)) != WLZ_ERR_NONE) {
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write object (%s).\n",
		       argv[0], errMsg);
	return(1);
      }
      break;

    default:
      if((errNum = WlzWriteObj(stdout, obj)) != WLZ_ERR_NONE) {
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write object (%s).\n",
		       argv[0], errMsg);
	return(1);
      }
      break;
    }
    WlzFreeObj(obj);
  }

  return 0;
}
Example #10
0
int		main(int argc, char *argv[])
{
  int		option,
  		ok = 1,
		usage = 0;
  WlzPixelV	a,
  		m;
  WlzGreyType	gType = WLZ_GREY_UBYTE;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  WlzObject	*inObj = NULL,
  		*outObj = NULL;
  char		*inFileStr,
		*outFileStr;
  const char	*errMsg;
  static char	optList[] = "a:g:hm:o:",
  		inFileStrDef[] = "-",
		outFileStrDef[] = "-";

  opterr = 0;
  a.type = WLZ_GREY_DOUBLE;
  a.v.dbv = 0.0;
  m.type = WLZ_GREY_DOUBLE;
  m.v.dbv = 1.0;
  inFileStr = inFileStrDef;
  outFileStr = outFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'a':
	if(sscanf(optarg, "%lg", &(a.v.dbv)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'g':
        switch(*optarg)
	{
	  case 'i':
	    gType = WLZ_GREY_INT;
	    break;
	  case 's':
	    gType = WLZ_GREY_SHORT;
	    break;
	  case 'u':
	    gType = WLZ_GREY_UBYTE;
	    break;
	  case 'f':
	    gType = WLZ_GREY_FLOAT;
	    break;
	  case 'd':
	    gType = WLZ_GREY_DOUBLE;
	    break;
	  case 'r':
	    gType = WLZ_GREY_RGBA;
	    break;
	  default:
	    usage = 1;
	    break;
	}
	break;
      case 'o':
        outFileStr = optarg;
	break;
      case 'm':
	if(sscanf(optarg, "%lg", &(m.v.dbv)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'h': /* FALLTHROUGH */
      default:
	usage = 1;
	break;
    }
  }
  if((usage == 0) && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
    }
    else
    {
      inFileStr = *(argv + optind);
    }
  }
  ok = !usage;
  if(ok)
  {
    fP = NULL;
    errNum = WLZ_ERR_READ_EOF;
    if(((fP = (strcmp(inFileStr, "-")? fopen(inFileStr, "r"):
                                       stdin)) == NULL) ||
       ((inObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to read object from file %s (%s).\n",
		     *argv, inFileStr, errMsg);
    }
    if(fP && strcmp(inFileStr, "-"))
    {
      (void )fclose(fP);
    }
  }
  if(ok)
  {
    outObj = WlzScalarMulAdd(inObj, m, a, gType, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to create scaled object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok && (outFileStr != NULL))
  {
    if(((fP = (strcmp(outFileStr, "-")? fopen(outFileStr, "w"):
                                        stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
    
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed to write scaled object to file %s (%s).\n",
		     *argv, outFileStr, errMsg);
    }
    if(fP!= NULL)
    {
      (void )fclose(fP);
    }
  }
  (void )WlzFreeObj(outObj);
  (void )WlzFreeObj(inObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%s",
    *argv,
    " [-a#] [-g#] [-h] [-o<output object>] [-m #]\n"
    "                      [<input object>]\n"
    "Scales the grey values of an object using a linear scaling with\n"
    "v_out = m v_{in} + a.\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -a  Value for addition.\n"
    "  -g  Grey type specified using one of the characters:\n"
    "      i, s, u, f, d, r for int, short, unsigned byte, float, double\n"
    "      or RGBA.\n"
    "  -h  Prints this usage information.\n"
    "  -o  Output tiled object.\n"
    "  -m Value for product.\n");
  }
  return(!ok);
}
Example #11
0
int             main(int argc, char **argv)
{
  int		idN,
		option,
		useRadians = 0,
		ok = 1,
		usage = 0;
  double	minDistWgt = 0.25,
  		rMin = 0.0,
  		rMax = 20.0,
		rStep = 1.0,
		xMin = 0.0,
		xMax = 20.0,
		xStep = 1.0,
		yMin = 0.0,
		yMax = 20.0,
		yStep = 1.0;
  char		*comma,
  		*colon;
  double	*range[3];
  char		*buf[3];
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzObject	*inTrObj = NULL,
  		*outObj = NULL;
  WlzObject	*inObj[2];
  FILE		*fP = NULL;
  char 		*inTrObjFileStr = NULL,
  		*outObjFileStr;
  char  	*inObjFileStr[2];
  const char	*errMsg;
  static char	optList[] = "M:i:o:r:x:y:Rh",
		outObjFileStrDef[] = "-",
  		inObjFileStrDef[] = "-";

  opterr = 0;
  inObj[0] = NULL;
  inObj[1] = NULL;
  outObjFileStr = outObjFileStrDef;
  inObjFileStr[0] = inObjFileStrDef;
  inObjFileStr[1] = inObjFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'R':
        useRadians = 1;
	break;
      case 'M':
        if((sscanf(optarg, "%lg", &minDistWgt) != 1) ||
	   (minDistWgt < 0.0) || (minDistWgt > 1.0))
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 'i':
        inTrObjFileStr = optarg;
	break;
      case 'o':
        outObjFileStr = optarg;
	break;
      case 'r': /* FALLTHROUGH */
      case 'x': /* FALLTHROUGH */
      case 'y':
	if(optarg)
	{
	  comma = strchr(optarg, ',');
	  colon = strchr(optarg, ':');
	  if(comma && colon)
	  {
	    *comma = *colon = '\0';
	    switch(option)
	    {
	      case 'r':
		range[0] = &rMin; 
		range[1] = &rMax; 
		range[2] = &rStep; 
		break;
	      case 'x':
		range[0] = &xMin; 
		range[1] = &xMax; 
		range[2] = &xStep; 
		break;
	      case 'y':
		range[0] = &yMin; 
		range[1] = &yMax; 
		range[2] = &yStep; 
		break;
	    }
	    buf[0] = optarg;
	    buf[1] = comma + 1;
	    buf[2] = colon + 1;
	    for(idN = 0; (idN < 3) && (usage == 0); ++idN)
	    {
	      while(*buf[idN] && isspace(*buf[idN]))
	      {
	        ++buf[idN];
	      }
	      if(*buf[idN])
	      {
	        if(sscanf(buf[idN], "%lg", range[idN]) != 1)
		{
		  usage = 1;
		}
	      }
	    }
	  }
	  else
	  {
	    usage = 1;
	  }
	}
        break;
      case 'h':
      default:
        usage = 1;
	break;
    }
  }
  if(useRadians == 0)
  {
    rMin *= ALG_M_PI / 180.0;
    rMax *= ALG_M_PI / 180.0;
    rStep *= ALG_M_PI / 180.0;
  }
  if((inObjFileStr[0] == NULL) || (*inObjFileStr[0] == '\0') ||
     (inObjFileStr[1] == NULL) || (*inObjFileStr[1] == '\0') ||
     (outObjFileStr == NULL) || (*outObjFileStr == '\0'))
  {
    usage = 1;
  }
  ok = !usage;
  if(ok && (optind < argc))
  {
    idN = 0;
    while((idN < 2) && (optind < argc))
    {
      inObjFileStr[idN] = *(argv + optind);
      ++optind;
      ++idN;
    }
  }
  if(ok && (optind != argc))
  {
    usage = 1;
    ok = 0;
  }
  if(ok && inTrObjFileStr)
  {
    /* Read initial affine transform. */
    if(((fP = (strcmp(inTrObjFileStr, "-")?
               fopen(inTrObjFileStr, "r"): stdin)) == NULL) ||
       ((inTrObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	     "%s: Failed to read initial affine transform from file %s (%s)\n",
	     *argv, inTrObjFileStr, errMsg);
    }
    if(fP && strcmp(inTrObjFileStr, "-"))
    {
      fclose(fP);
    }
    if(inTrObj &&
       ((inTrObj->type != WLZ_AFFINE_TRANS) || (inTrObj->domain.core == NULL)))
    {
      ok = 0;
      (void )fprintf(stderr,
      		     "%s: Initial affine transform object invalid type\n",
		     *argv);
    }
  }
  if(ok)
  {
    /* Read objects. */
    idN = 0;
    while((errNum == WLZ_ERR_NONE) && (idN < 2))
    {
      errNum = WLZ_ERR_READ_EOF;
      if((inObjFileStr[idN] == NULL) ||
	  (*inObjFileStr[idN] == '\0') ||
	  ((fP = (strcmp(inObjFileStr[idN], "-")?
		  fopen(inObjFileStr[idN], "r"): stdin)) == NULL) ||
	  ((inObj[idN] = WlzAssignObject(WlzReadObj(fP,
	  					    &errNum), NULL)) == NULL))
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: Failed to read object %d from file %s (%s)\n",
		       *argv, idN, inObjFileStr[idN], errMsg);
      }
      if(fP && strcmp(inObjFileStr[idN], "-"))
      {
	fclose(fP);
      }
      ++idN;
    }
  }
  if(ok)
  {
    /* Check object types. */
    if(inObj[0]->type != inObj[1]->type)
    {
      errNum = WLZ_ERR_OBJECT_TYPE;
    }
    else if((inObj[0]->domain.core == NULL) ||
            (inObj[1]->domain.core == NULL))
    {
      errNum = WLZ_ERR_DOMAIN_NULL;
    }
    else
    {
      switch(inObj[0]->type)
      {
        case WLZ_2D_DOMAINOBJ:
          break;
        case WLZ_CONTOUR:
          if((inObj[0]->domain.core == NULL) ||
             (inObj[0]->domain.ctr->model == NULL))
          {
            errNum = WLZ_ERR_DOMAIN_NULL;
          }
          else
          {
            switch(inObj[0]->domain.ctr->model->type)
            {
              case WLZ_GMMOD_2I: /* FALLTHROUGH */
              case WLZ_GMMOD_2D:
              case WLZ_GMMOD_2N:
                break;
              default:
                errNum = WLZ_ERR_DOMAIN_TYPE;
                ok = 0;
                break;
            }
          }
          break;
        default:
          errNum = WLZ_ERR_OBJECT_TYPE;
          ok = 0;
          break;
      }
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr, "%s: Input object(s) not appropriate (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    outObj = WlzRegICPObjWSD2D(inObj[0], inObj[1],
    			       inTrObj? inTrObj->domain.t: NULL,
			       xMin, xMax, xStep,
			       yMin, yMax, yStep,
			       rMin, rMax, rStep,
			       minDistWgt, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		   "%s: Failed to compute weighted sums of distances (%s).\n",
		   *argv, errMsg);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((fP = (strcmp(outObjFileStr, "-")?  fopen(outObjFileStr, "w"):
	      				    stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed to write output object (%s).\n",
		     *argv, errMsg);
    }
    if(fP && strcmp(outObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  if(inObj[0])
  {
    (void )WlzFreeObj(inObj[0]);
  }
  if(inObj[1])
  {
    (void )WlzFreeObj(inObj[1]);
  }
  if(outObj)
  {
    (void )WlzFreeObj(outObj);
  }
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%sExample: %s%s",
    *argv,
    " [-M #] [-R] [-i <init tr>] [-o<out obj>]\n"
    "                      [-r #,#:#] [-x #,#:#] [-y #,#:#]\n"
    "                      [<in obj 0>] [<in obj 1>]\n"
    "Options:\n"
    "  -M  Minimum distance weight, range [0.0-1.0]: Useful values are\n"
    "      0.25 (default) for global matching and 0.0 for local matching.\n"
    "  -R  Rotations are in radians not degrees.\n"
    "  -i  Initial affine transform object.\n"
    "  -o  Output file name.\n"
    "  -r  Range and step size for rotation in degrees.\n"
    "  -x  Range and step size for translation through columns.\n"
    "  -y  Range and step size for translation through lines.\n"
    "  -h  Help, prints this usage message.\n"
    "Computes a 3D double precission valued object in which the values\n"
    "are the weighted sums of distances as used for ICP registration.\n"
    "In specifying the ranges the defaults are 0.0 -> 20.0, step 1.0.\n"
    "The input objects are read from stdin and values are written to stdout\n"
    "unless the filenames are given.\n",
    *argv,
    " -o out.wlz -r 0,90:0.5 -x 100,200: -y ,200: in0.wlz in1.wlz\n"
    "A weighted sums of distances object is computed for rotations of\n"
    "0 to 90 degrees with a step size of 0.5 degrees, the x and y\n"
    "translations are from 100 to 200 and 0 to 200 in unit steps.\n"
    "The weighted sums of distances object is then written to out.wlz.\n");
  }
  return(!ok);
}
Example #12
0
int             main(int argc, char **argv)
{
  int		option,
		cVal = 0,
		ok = 1,
		usage = 0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char    *errMsg;
  FILE		*fP = NULL;
  WlzObject	*inObj = NULL,
		*outObj = NULL;
  char 		*outObjFileStr,
  		*inObjFileStr;
  static char	optList[] = "o:c:h",
		outObjFileStrDef[] = "-",
  		inObjFileStrDef[] = "-";

  opterr = 0;
  outObjFileStr = outObjFileStrDef;
  inObjFileStr = inObjFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'c':
	if(sscanf(optarg, "%d", &cVal) != 1)
	{
	  usage = 1;
	  ok = 0;
	}
        break;
      case 'o':
        outObjFileStr = optarg;
	break;
      case 'h':
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if((inObjFileStr == NULL) || (*inObjFileStr == '\0') ||
     (outObjFileStr == NULL) || (*outObjFileStr == '\0'))
  {
    ok = 0;
    usage = 1;
  }
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      inObjFileStr = *(argv + optind);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_READ_EOF;
    if((inObjFileStr == NULL) ||
       (*inObjFileStr == '\0') ||
       ((fP = (strcmp(inObjFileStr, "-")?
	      fopen(inObjFileStr, "r"): stdin)) == NULL) ||
       ((inObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to read object from file %s (%s).\n",
		     *argv, inObjFileStr, errMsg);
    }
    if(fP && strcmp(inObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  if(ok)
  {
    if((outObj = WlzGreyCrossing(inObj, 0, cVal, &errNum)) == NULL)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to compute grey crossing object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((fP = (strcmp(outObjFileStr, "-")?
              fopen(outObjFileStr, "w"):
	      stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to write output object (%s).\n",
		     *argv, errMsg);
    }
    if(fP && strcmp(outObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%s%d%sExample: %s%s",
    *argv,
    " [-o<out object>] [-c #] [-h] [<in object>]\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -o  Output object file name.\n"
    "  -c  grey crossing value, set to ",
    cVal,
    ".\n"
    "  -h  Help, prints this usage message.\n"
    "Computes a grey value crossing image from a 2D domain object with\n"
    "integral grey values.\n"
    "Objects are read from stdin and written to stdout unless the filenames\n"
    "are given.\n",
    *argv,
    " -o crossing.wlz myobj.wlz\n"
    "The input Woolz object is read from myobj.wlz, filtered and written\n"
    "to crossing.wlz.\n");
  }
  return(!ok);
}
Example #13
0
int		main(int argc, char *argv[])
{
  int		ok = 1,
  		option,
		usage = 0,
		cpt = 0;
  char		*inFileStr,
		*outFileStr;
  FILE		*fP = NULL;
  WlzObject	*inObj = NULL,
		*outObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsgStr;
  static char	optList[] = "hc:o:";
  const char    fileStrDef[] = "-";

  /* Parse the argument list and check for input files. */
  opterr = 0;
  inFileStr = (char *)fileStrDef;
  outFileStr = (char *)fileStrDef;
  while(ok && !usage && ((option = getopt(argc, argv, optList)) != EOF))
  {
    switch(option)
    {
      case 'c':
	if(sscanf(optarg, "%d", &cpt) != 1)
        {
	  usage = 1;
	}
	break;
      case 'o':
	outFileStr = optarg;
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  if(ok)
  {
    ok = !usage;
  }
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      inFileStr = argv[optind];
    }
  }
  /* Read the input object. */
  if(ok)
  {
    if((inFileStr == NULL) ||
       (*inFileStr == '\0') ||
       ((fP = (strcmp(inFileStr, "-")?
              fopen(inFileStr, "r"): stdin)) == NULL) ||
       ((inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read input object from file %s.\n",
                     argv[0], inFileStr);
    }
    if(fP && strcmp(inFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Extract component to a new object. */
  if(ok)
  {
    outObj = WlzTensorGetComponent(inObj, cpt, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to extract component with index %d, %s.\n",
                     argv[0], cpt, errMsgStr);
    }
  }
  /* Output the component object. */
  if(ok)
  {
    if((fP = (strcmp(outFileStr, "-")?
             fopen(outFileStr, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to open output file %s.\n",
                     argv[0], outFileStr);
    }
  }
  if(ok)
  {
    errNum = WlzWriteObj(fP, outObj);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to write output object, %s.\n",
                     argv[0], errMsgStr);
    }
  }
  if(fP && strcmp(outFileStr, "-"))
  {
    (void )fclose(fP); fP = NULL;
  }
  (void )WlzFreeObj(inObj);
  (void )WlzFreeObj(outObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-c<cpt>] [-o<output object>] [-h]\n"
    "\t\t[<input object>]\n"
    "Version: %s\n"
    "Options:\n"
    "  -c  Component index which must be in the range [0-(1-V_n)] where\n"
    "      V_n is the number of component values per element in the object,\n"
    "      eg for a scalar image 0 and for a rank 2 3x3 tensor this would\n"
    "      be 9.\n"
    "  -o  Output file.\n"
    "  -h  Help, prints usage message.\n"
    "Extracts tensor component values from a tensor image object.\n"
    "Because the resulting object is always a non-tiled object this\n"
    "filter may also be used to convert a tiled to non-tiled object.\n"
    "It is safe to supply a non-tiled object as the input (provided that\n"
    "the component index is zero). By default all files are read from the\n"
    "standard input and written to the standard output.\n"
    "Example:\n"
    "  %s -o c_0.wlz -c 0 in.wlz\n"
    "creates a scalar object containing just the first component of\n"
    "the given tensor image. Alternatively this would also convert\n"
    "a tiled object (in.wlz) to a non-tiled object (retaining only\n"
    "the zeroth component of it's values). The object is written to the\n"
    "file c_0.wlz\n",
    argv[0],
    WlzVersion(),
    argv[0]);
  }
  return(!ok);
}
Example #14
0
int		main(int argc, char *argv[])
{
  int		tSz1,
  		option,
		nT = 255,
		debug = 0,
  		ok = 1,
  		usage = 0;
  char		*outFileS;
  WlzGreyP	bufP;
  WlzIVertex2	tSz;
  WlzIBox3	bBox;
  FILE		*fP = NULL;
  WlzObject	*obj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsgS = NULL;
  static char   optList[] = "dhn:o:s:x:y:z:";

  opterr = 0;
  tSz.vtX = tSz.vtY = 64;
  bBox.xMin = 0;
  bBox.yMin = 0;
  bBox.zMin = 0;
  bBox.xMax = 255;
  bBox.yMax = 255;
  bBox.zMax = 255;
  bufP.v = NULL;
  outFileS = "-";
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != EOF))
  {
    switch(option)
    {
      case 'd':
	debug = 1;
	break;
      case 'o':
	outFileS = optarg;
	break;
      case 'n':
	if((sscanf(optarg, "%d", &nT) != 1) || (nT < 0))
	{
	  usage = 1;
	}
	break;
      case 's':
	if((sscanf(optarg, "%d,%d", &(tSz.vtX), &(tSz.vtY)) != 2) ||
	   (tSz.vtX < 0) || (tSz.vtY < 0))
	{
	  usage = 1;
	}
	break;
      case 'x':
        usage = ParseDimLim(&(bBox.xMin), &(bBox.xMax), optarg);
	break;
      case 'y':
        usage = ParseDimLim(&(bBox.yMin), &(bBox.yMax), optarg);
	break;
      case 'z':
        usage = ParseDimLim(&(bBox.zMin), &(bBox.zMax), optarg);
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  tSz1 = tSz.vtX * tSz.vtY;
  if(debug)
  {
    (void )fprintf(stderr, "nT   = %d\n",
		   nT);
    (void )fprintf(stderr, "tSz  = %d,%d\n",
		   tSz.vtX, tSz.vtY);
    (void )fprintf(stderr, "bBox = %d,%d,%d,%d,%d,%d\n",
		   bBox.xMin, bBox.xMax,
		   bBox.yMin, bBox.yMax,
		   bBox.zMin, bBox.zMax);
  }
  ok = !usage;
  if(ok)
  {
    if((bufP.v = AlcMalloc(sizeof(WlzUByte) * tSz1)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to allocate buffer.\n",
                     *argv);
    }
  }
  if(ok)
  {
    int		idN;

    AlgRandSeed(0L);
    for(idN = 0; idN < nT; ++idN)
    {
      WlzIVertex3 og;
      WlzObject *nObj = NULL;

      og.vtX = bBox.xMin +
               (int )floor(AlgRandUniform() *
	                   (bBox.xMax - bBox.xMin - tSz.vtX));
      og.vtY = bBox.yMin +
               (int )floor(AlgRandUniform() *
	                   (bBox.yMax - bBox.yMin - tSz.vtY));
      og.vtZ = bBox.zMin + 
               (int )floor(AlgRandUniform() *
	                   (bBox.zMax - bBox.zMin));
      (void )memset(bufP.v, idN % 255, tSz1);
      nObj = WlzBuildObj3(obj, og, tSz, WLZ_GREY_UBYTE, tSz1, bufP,
      			  &errNum);
      if(errNum != WLZ_ERR_NONE)
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsgS);
	(void )fprintf(stderr,
	               "%s: Failed to add tile #%d to object (%s)\n",
		       *argv, idN, errMsgS);
        break;
      }
      else
      {
        (void )WlzFreeObj(obj);
	obj = nObj;
      }
    }
  }
  if(ok)
  {
    if(((fP = (strcmp(outFileS, "-")?
        fopen(outFileS, "w"): stdout)) == NULL))
    {
      ok = 0;
      errNum = WLZ_ERR_WRITE_EOF;
      (void )WlzStringFromErrorNum(errNum, &errMsgS);
      (void )fprintf(stderr,
                     "%s: Failed to open file %s (%s).\n",
		     *argv, outFileS, errMsgS);
    }
  }
  if(ok)
  {
    if((errNum = WlzWriteObj(fP, obj)) != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgS);
      (void )fprintf(stderr,
                     "%s: Failed to write to file %s (%s).\n",
		     *argv, outFileS, errMsgS);
    }
  }
  if(fP && strcmp(outFileS, "-"))
  {
    (void )fclose(fP);
  }
  AlcFree(bufP.v);
  (void )WlzFreeObj(obj);
  if(usage)
  {
  static char   optList[] = "dhn:o:s:x:y:z:";
    (void )fprintf(stderr,
    "Usage: %s [-d] [-h] [-n#] [-o<file>] [-s#,#]\n"
    "\t\t[-x[#][,[#]]] [-y[#][,[#]]] [-z[#][,[#]]]\n"
    "Creates 3D domain object to test WlzBuildObj3().\n"
    "Options are:\n"
    "  -d  Print debug information to stderr (set to %d).\n"
    "  -h  Help, prints this usage message.\n"
    "  -n  NUmber of 2D rectangular buffers to add (set to %d).\n"
    "  -o  Output file (set to %s).\n"
    "  -s  Rectangular buffer size (side lengths) (set to %d,%d).\n"
    "  -x  Bounding column limits (set to %d,%d).\n"
    "  -y  Bounding line limits (set to %d,%d).\n"
    "  -z  Bounding plane limits (set to %d,%d).\n",
    argv[0], debug, nT, outFileS, tSz.vtX, tSz.vtY,
    bBox.xMin, bBox.xMax, bBox.yMin, bBox.yMax, bBox.zMin, bBox.zMax);
  }
  return(!ok);
}
int		main(int argc, char *argv[])
{
  int		idN,
		eIdx = -1,
		nIdx = -1,
  		ok = 1,
		exhaustive = 0,
  		option,
		repeats = 1,
  		usage = 0;
  WlzDVertex3	vtx;
  FILE		*fP = NULL;
  char		*inObjFileStr,
  		*outFileStr;
  const char	*errMsgStr;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzObject	*inObj = NULL;
  WlzCMeshP 	mesh;
  static char   optList[] = "eho:p:R:";
  const char    inObjFileStrDef[] = "-",
  	        outFileStrDef[] = "-";

  opterr = 0;
  mesh.v = NULL;
  inObjFileStr = (char *)inObjFileStrDef;
  outFileStr = (char *)outFileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != EOF))
  {
    switch(option)
    {
      case 'e':
        exhaustive = 1;
	break;
      case 'o':
        outFileStr = optarg;
	break;
      case 'p':
	if(sscanf(optarg, "%lg,%lg,%lg",
		  &(vtx.vtX), &(vtx.vtY), &(vtx.vtZ)) != 3)
	{
	  usage = 1;
	}
	break;
      case 'R':
        if(sscanf(optarg, "%d", &repeats) != 1)
	{
	  usage = 1;
	}
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  if(usage == 0)
  {
    if((inObjFileStr == NULL) || (*inObjFileStr == '\0') ||
       (outFileStr == NULL) || (*outFileStr == '\0'))
    {
      usage = 1;
    }
    if((usage == 0) && (optind < argc))
    {
      if((optind + 1) != argc)
      {
        usage = 1;
      }
      else
      {
        inObjFileStr = *(argv + optind);
      }
    }
  }
  ok = usage == 0;
  if(ok)
  {
    if((inObjFileStr == NULL) ||
       (*inObjFileStr == '\0') ||
       ((fP = (strcmp(inObjFileStr, "-")?
              fopen(inObjFileStr, "r"): stdin)) == NULL) ||
       ((inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
       (errNum != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read object from file (%s)\n",
                     *argv, inObjFileStr);
    }
    if(fP && strcmp(inObjFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  if(ok)
  {
    switch(inObj->type)
    {
      case WLZ_CMESH_2D:
        mesh.m2 = inObj->domain.cm2;
	break;
      case WLZ_CMESH_3D:
        mesh.m3 = inObj->domain.cm3;
	break;
      default:
        ok = 0;
	errNum = WLZ_ERR_OBJECT_TYPE;
        (void )WlzStringFromErrorNum(errNum, &errMsgStr);
	(void )fprintf(stderr,
		   "%s: Invalid object type, must be WLZ_CMESH_[23]D (%s),\n",
		       argv[0],
		       errMsgStr);
        break;
    }
  }
  if(ok)
  {
    for(idN = 0; idN < repeats; ++idN)
    {
      eIdx = WlzCMeshElmEnclosingPos(mesh, -1, vtx.vtX, vtx.vtY, vtx.vtZ,
                                     exhaustive, &nIdx);
    }
    if((fP = (strcmp(outFileStr, "-")?
	     fopen(outFileStr, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
		     "%s: Failed to open output file %s.\n",
		     argv[0], outFileStr);
    }
  }
  if(ok)
  {
    if(fprintf(fP, "%d %d\n", eIdx, nIdx) <= 0)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to write to file %s.\n",
		     argv[0], outFileStr);
    }
  }
  (void )WlzFreeObj(inObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-h] [-o<output file>] [-p<position>] [-R<repeats>]\n"
    "       [<input cmesh object>]\n"
    "Reads a conforming mesh and then searches for the element which\n"
    "contains the given vertex.\n"
    "The output is either:\n"
    "  <element index> <node index>\n"
    "where the element index is the index of the mesh element enclosing the\n"
    "given vertex and the node index is the index of the node closest to\n"
    "the given vertex. If the vertex is not within a mesh element then the\n"
    "index will be a negative value. If the element index is not negative\n"
    "then the node index may not be the closest node.\n"
    "Options are:\n"
    "  -e  Exhaustive search (slow), every element in the mesh searched.\n"
    "  -h  Help, prints this usage message.\n"
    "  -o  Output file.\n"
    "  -p  Given vertex position given as <vx>,<vy>,<vz>.\n"
    "  -R  number of times to repeat the computation.\n",
    argv[0]);

  }
  return(!ok);
}
Example #16
0
int		main(int argc, char **argv)
{
  WlzCompoundArray *inObj;
  WlzObject        *objX,
                   *objY;
  WlzErrorNum      errNum = WLZ_ERR_NONE;
  FILE	           *inFile = NULL, 
                   *outFile = NULL;
  static char 	   optList[] = "c:v:h";
  const char       *inFileStr = NULL,
                   *outFileStr = NULL,
                   *errMsg;
  int	           option;
    
  /* read the argument list and check for an input and output file */
  while( (option = getopt(argc, argv, optList)) != EOF ){
    switch( option )
    {
      case 'c':
        inFileStr = optarg;
	break;
      case 'v':
        outFileStr = optarg;
	break;
      case 'h':
        usage(argv[0]);
        return( WLZ_ERR_NONE );

      default:
        usage(argv[0]);
        return( WLZ_ERR_PARAM_TYPE );
    }
  }
    
  errNum = WLZ_ERR_READ_EOF;
  if((inFileStr == NULL) || (*inFileStr == '\0') ||
       ((inFile = fopen(inFileStr, "r")) == NULL) ||
       ((inObj= (WlzCompoundArray *)WlzReadObj(inFile, &errNum)) == NULL))
  {
      errNum = WLZ_ERR_PARAM_DATA ;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to read object from file %s (%s).\n",
		     *argv, inFileStr, errMsg);
  }
  if(inFile)
  {
    fclose(inFile);
  }
  if((outFileStr == NULL) || (*outFileStr == '\0') ||
       ((outFile = fopen(outFileStr, "w")) == NULL))
  {
      errNum = WLZ_ERR_PARAM_DATA;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to open file %s (%s).\n",
		     *argv, outFileStr, errMsg);
  }
  /* read  X and Y objects */
  if(errNum == WLZ_ERR_NONE)
  {
    switch(inObj->type)
    {
      case WLZ_COMPOUND_ARR_1:
	if (inObj->n == 2)
	{
	  if ((objX = inObj->o[0]) != 0)
	  {
	    if ((objY = inObj->o[1]) == 0)
	    {
	      objX = NULL;
	      errNum = WLZ_ERR_OBJECT_NULL;
	    }
	  }
	  else
	    errNum = WLZ_ERR_OBJECT_NULL;
	}
	else
	  errNum = WLZ_ERR_OBJECT_DATA;
        break;

      default:
	errNum = WLZ_ERR_OBJECT_DATA;
	break;
    }
  }
  /* combine x and y displacements into a VTK file format */
  if (errNum == WLZ_ERR_NONE)
  {
    errNum = WlzDisplacementsToVtk(outFile, objX, objY);
  }

  if (outFile)
  {
    fclose(outFile);
  }
  
  return(errNum);
}
Example #17
0
int             main(int argc, char **argv)
{
  int		option,
		ok = 1,
		usage = 0,
      		nVx = 0,
		inputWlz = 0,
		testFlg = 0;
  WlzVertexP	vxp;
  WlzDVertex3	up,
  		nrm,
		pip;
  WlzObject	*outObj = NULL;
  WlzVertexType vtxType = WLZ_VERTEX_D3;
  WlzObjectType	outObjType = WLZ_NULL;
  WlzDomain	outDomain;
  WlzValues	outValues;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzFitPlaneAlg alg = WLZ_FITPLANE_ALG_SVD;
  WlzFitPlaneOut out = WLZ_FITPLANE_OUT_SECTION;
  char		*inFileStr = NULL,
		*outFileStr = NULL;
  const char	*errMsg;
  static char	optList[] = "ahstTwA:o:u:",
		fileStrDef[] = "-";

  /* These vertices correspond to a plane in EMA27 with
   * fp=0,0,0, dist=123, pitch=123, yaw=45 which should give
   * the following text output:
   * -0.593865 -0.592398 0.544417 211.6 137.7 154.4 57.0152 224.929
   */
  const int	     testVxCount = 10;
  static WlzDVertex3 testVx[10] =
  {
    {181,62,39},
    {105,192,97},
    {281,185,282},
    {342,81,235},
    {118,139,54},
    {221,146,173},
    {312,147,274},
    {225,69,94},
    {190,148,142},
    {141,208,154}
  };

  opterr = 0;
  vxp.v = NULL;
  up.vtX = 0.0;
  up.vtY = 0.0;
  up.vtZ = 0.0;
  outDomain.core = NULL;
  outValues.core = NULL;
  inFileStr = fileStrDef;
  outFileStr = fileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'A':
	if(WlzStringMatchValue((int *)&alg, optarg,
			       "SVD",  WLZ_FITPLANE_ALG_SVD,
			       NULL) == 0)
	{
	  usage = 1;
	  ok = 0;
	}
        break;
      case 'a':
        out = WLZ_FITPLANE_OUT_AFFINE;
	break;
      case 'o':
        outFileStr = optarg;
	break;
      case 's':
        out = WLZ_FITPLANE_OUT_SECTION;
	break;
      case 't':
        out = WLZ_FITPLANE_OUT_TEXT;
	break;
      case 'T':
        testFlg = 1;
	break;
      case 'u':
        if(sscanf(optarg, "%lg,%lg,%lg", &(up.vtX), &(up.vtY), &(up.vtZ)) < 3)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 'w':
        inputWlz = 1;
	break;
      case 'h':
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      inFileStr = *(argv + optind);
    }
  }
  if(ok)
  {
    if(testFlg)
    {
      nVx = testVxCount;
      vxp.d3 = testVx;
    }
    else
    {
      FILE	*fP = NULL;

      if((*inFileStr == '\0') ||
	 ((fP = (strcmp(inFileStr, "-")?
		fopen(inFileStr, "r"): stdin)) == NULL))
      {
	ok = 0;
	errNum = WLZ_ERR_READ_EOF;
      }
      else
      {
        if(inputWlz)
	{
	  WlzObject *inObj = NULL;

	  if((inObj = WlzReadObj(fP, &errNum)) != NULL)
	  {
	    WlzVertexP inVxP;
	    WlzVertexType inVxType;

	    inVxP = WlzVerticesFromObj(inObj, NULL, &nVx, &inVxType, &errNum);
	    if(errNum == WLZ_ERR_NONE)
	    {
	      switch(inVxType)
	      {
	        case WLZ_VERTEX_I3: /* FALLTHROUGH */
		case WLZ_VERTEX_F3: /* FALLTHROUGH */
		case WLZ_VERTEX_D3:
		  vtxType = inVxType;
		  vxp.v = inVxP.v;
		  inVxP.v = NULL;
		  break;
	        default:
		  errNum = WLZ_ERR_OBJECT_TYPE;
		  break;
	      }
	      AlcFree(inVxP.v);
	    }
	    (void )WlzFreeObj(inObj);
	  }
	}
	else
	{
	  size_t nM = 0,
		 nN = 0;
	  double **inData = NULL;

	  if((AlcDouble2ReadAsci(fP, &inData, &nM, &nN) != ALC_ER_NONE) ||
	     (nM < 1) || (nN != 3))
	  {
	    ok = 0;
	    errNum = WLZ_ERR_PARAM_DATA;
	  }
	  (void )fclose(fP);
	  if(ok)
	  {
	    nVx = nM;
	    if((vxp.d3 = (WlzDVertex3 *)
			 AlcMalloc(nVx * sizeof(WlzDVertex3))) == NULL)
	    {
	      ok = 0;
	      errNum = WLZ_ERR_MEM_ALLOC;
	    }
	  }
	  if(ok)
	  {
	    int	idx;

	    for(idx = 0; idx < nVx; ++idx)
	    {
	      vxp.d3[idx].vtX = inData[idx][0];
	      vxp.d3[idx].vtY = inData[idx][1];
	      vxp.d3[idx].vtZ = inData[idx][2];
	    }
	  }
	  (void )AlcDouble2Free(inData);
	}
	if(strcmp(inFileStr, "-"))
	{
	  (void )fclose(fP);
	}
      }
      if(!ok)
      {
        (void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
	               "%s: failed to input vertices from file %s (%s).\n",
		       *argv, inFileStr, errMsg);
      }
    }
  }
  if(ok)
  {
    switch(alg)
    {
      case WLZ_FITPLANE_ALG_SVD:
	errNum = WlzFitPlaneSVD(vtxType, nVx, vxp, &pip, &nrm);
	if(errNum == WLZ_ERR_NONE)
	{
	  outDomain.vs3d = Wlz3DViewStructFromNormal(nrm, pip, up, &errNum);
	}
	break;
      default:
	errNum = WLZ_ERR_PARAM_TYPE;
        break;
    }
    if(errNum == WLZ_ERR_NONE)
    {
      switch(out)
      {
        case WLZ_FITPLANE_OUT_AFFINE:
	  outObjType = WLZ_AFFINE_TRANS;
	  {
	    WlzAffineTransform *tr = NULL;

	    errNum = WlzInit3DViewStructAffineTransform(outDomain.vs3d);
	    if(errNum == WLZ_ERR_NONE)
	    {
	      tr = WlzAffineTransformCopy(outDomain.vs3d->trans, &errNum);
	      (void )WlzFree3DViewStruct(outDomain.vs3d);
	      outDomain.t = tr;
	    }
	  }
	  break;
        case WLZ_FITPLANE_OUT_SECTION:
	  outObjType = WLZ_3D_VIEW_STRUCT;
	  break;
	case WLZ_FITPLANE_OUT_TEXT:
	  outObjType = WLZ_NULL;
	  break;
        default:
	  errNum = WLZ_ERR_PARAM_TYPE;
	  break;
      }
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to compute best fit plane (%s).\n",
		     *argv, errMsg);
    }
  }
  if((testFlg == 0) && (vxp.v != NULL))
  {
    AlcFree(vxp.v);
  }
  if(ok && (outObjType != WLZ_NULL))
  {
    outObj = WlzMakeMain(outObjType, outDomain, outValues,
    		        NULL, NULL, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to make output object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    FILE	*fP = NULL;

    errNum = WLZ_ERR_WRITE_EOF;
    if((fP = (strcmp(outFileStr, "-")?
             fopen(outFileStr, "w"): stdout)) != NULL)
    {
      if(outObjType == WLZ_NULL)
      {
	double	theta,
		phi;

	theta = outDomain.vs3d->theta * 180.0 / ALG_M_PI;
	phi =   outDomain.vs3d->phi   * 180.0 / ALG_M_PI;
	while(theta < 0.0)
	{
	  theta += 360.0;
	}
	while(phi < 0.0)
	{
	  phi += 360.0;
	}

        if(fprintf(fP, "%g %g %g %g %g %g %g %g\n",
	           nrm.vtX, nrm.vtY, nrm.vtZ,
		   pip.vtX, pip.vtY, pip.vtZ,
		   phi,
		   theta) > 16)
        {
	  errNum = WLZ_ERR_NONE;
	}
      }
      else
      {
        errNum = WlzWriteObj(fP, outObj);
      }
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to write output object "
		     "to file %s (%s).\n",
		     *argv, outFileStr, errMsg);
    }
    if(fP && strcmp(outFileStr, "-"))
    {
      (void )fclose(fP);
    }
  }
  if(outObj)
  {
    WlzFreeObj(outObj);
  }
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%s",
    *argv,
    " [-a] [-A <alg>] [-o <output file>] [-h]\n"
    "\t\t[-s] [-t] [-T] [-u<x>,<y>,<z>] [<input file>]\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -A  Force the algorithm selection, valid algorithms are:\n"
    "        SVD  Singular Value Decomposition based least squares\n"
    "             (the default).\n"
    "  -a  Output is an affine transform.\n"
    "  -h  Help, prints this usage message.\n"
    "  -o  Output file name.\n"
    "  -s  Output is a 3D view struct (default).\n"
    "  -t  Output is a text description of the plane.\n"
    "  -T  Use test data, probably only useful for debugging.\n"
    "  -u  Up vector, the default is (0, 0, 0) which implies that\n"
    "      the up vector is not explicitly set.\n"
    "  -w  Input is a Woolz object rather than ascii vertices.\n"
    "Calculates the best (least squares) plane through the given input\n"
    "vertices or object.\n"
    "Text output is of the form:\n"
    "  <nx> <ny> <nz> <cx> <cy> <cz> <pitch> <yaw>\n"
    "where these are the normal components, centroid location in the plane\n"
    "and the Euler angles (in degrees).\n"
    "The input vertices are read from an ascii file with the format:\n"
    "  <vtx x> <vtx y> <vtx z>\n"
    "The input data are read from stdin and the output object is written\n"
    "to stdout unless the filenames are given.\n");
  }
  return(!ok);
}
Example #18
0
int		main(int argc, char *argv[])
{
  int		ok,
		bnd = 0,
  		con,
  		option,
		usage = 0;
  char		*inFileStr,
  		*forFileStr,
  		*refFileStr,
		*outFileStr;
  double	dParam = 10.0;
  FILE		*fP = NULL;
  WlzObject	*tObj0,
  		*tObj1,
		*forObj = NULL,
		*refObj = NULL,
		*dstObj = NULL;
  WlzDistanceType dFn;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsgStr;
  static char	optList[] = "bhd:f:p:o:";
  const char    fileStrDef[] = "-";
  const WlzConnectType defDFn = WLZ_OCTAGONAL_DISTANCE;

  /* Parse the argument list and check for input files. */
  opterr = 0;
  inFileStr = (char *)fileStrDef;
  forFileStr = (char *)fileStrDef;
  outFileStr = (char *)fileStrDef;
  dFn = defDFn;
  while((option = getopt(argc, argv, optList)) != EOF)
  {
    switch(option)
    {
      case 'b':
        bnd = 1;
	break;
      case 'd':
	if(sscanf(optarg, "%d", &con) != 1)
	{
	  usage = 1;
	}
	else
	{
	  switch(con)
	  {
	    case 0:
	      dFn = WLZ_EUCLIDEAN_DISTANCE;
	      break;
	    case 1:
	      dFn = WLZ_OCTAGONAL_DISTANCE;
	      break;
	    case 2:
	      dFn = WLZ_APX_EUCLIDEAN_DISTANCE;
	      break;
	    case 4:
	      dFn = WLZ_4_DISTANCE;
	      break;
	    case 6:
	      dFn = WLZ_6_DISTANCE;
	      break;
	    case 8:
	      dFn = WLZ_8_DISTANCE;
	      break;
	    case 18:
	      dFn = WLZ_18_DISTANCE;
	      break;
	    case 26:
	      dFn = WLZ_26_DISTANCE;
	      break;
	    default:
	      usage = 1;
	      break;
	  }
	}
	break;
      case 'f':
	forFileStr = optarg;
	break;
      case 'p':
	if(sscanf(optarg, "%lg", &dParam) != 1)
	{
	  usage = 1;
	}
	break;
      case 'o':
	outFileStr = optarg;
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  ok = !usage;
  if(ok && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
      ok = 0;
    }
    else
    {
      refFileStr = argv[optind];
    }
  }
  /* Read the reference object. */
  if(ok)
  {
    if((refFileStr == NULL) ||
       (*refFileStr == '\0') ||
       ((fP = (strcmp(refFileStr, "-")?
              fopen(refFileStr, "r"): stdin)) == NULL) ||
       ((refObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read reference object from file %s.\n",
                     argv[0], refFileStr);
    }
    if(fP && strcmp(refFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Read the foreground object. */
  if(ok)
  {
    if((forFileStr == NULL) ||
       (*forFileStr == '\0') ||
       ((fP = (strcmp(forFileStr, "-")?
              fopen(forFileStr, "r"): stdin)) == NULL) ||
       ((forObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to read foreground object from file %s.\n",
                     argv[0], forFileStr);
    }
    if(fP && strcmp(forFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  /* Check object types and parse the promote the default distance function
   * if required. */
  if(ok)
  {
    if(refObj->type != forObj->type)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Foreground and reference object types differ.\n",
		     argv[0]);
    }
  }
  if((errNum == WLZ_ERR_NONE) && bnd)
  {
    tObj0 = tObj1 = NULL;
    tObj0 = WlzObjToBoundary(refObj, 1, &errNum);
    if(errNum == WLZ_ERR_NONE)
    {
      tObj1 = WlzBoundaryToObj(tObj0, WLZ_VERTEX_FILL, &errNum);
    }
    if(errNum == WLZ_ERR_NONE)
    {
      (void )WlzFreeObj(refObj);
      refObj = tObj1;
      tObj1 = NULL;
    }
    (void )WlzFreeObj(tObj0);
    (void )WlzFreeObj(tObj1);
  }
  /* Compute the distance transform object. */
  if(ok)
  {
    dstObj = WlzAssignObject(
    	     WlzDistanceTransform(forObj, refObj, dFn, dParam, &errNum), NULL);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
      		     "%s: Failed to compute distance object, %s.\n",
		     argv[0], errMsgStr);
    }
  }
  /* Output the distance transform object. */
  if(ok)
  {
    if((fP = (strcmp(outFileStr, "-")?
             fopen(outFileStr, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
                     "%s: Failed to open output file %s.\n",
                     argv[0], outFileStr);
    }
  }
  if(ok)
  {
    errNum = WlzWriteObj(fP, dstObj);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsgStr);
      (void )fprintf(stderr,
                     "%s: Failed to write output object, %s.\n",
                     argv[0], errMsgStr);
    }
  }
  (void )WlzFreeObj(forObj);
  (void )WlzFreeObj(refObj);
  (void )WlzFreeObj(dstObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-b] [-d#] [-f#] [-p#] [-o#] [-h] [<Reference input file>]\n"
    "Computes a distance transform object which has the domain of the\n"
    "foreground object and values which are the distance from the reference\n"
    "object.\n"
    "Options are:\n"
    "  -b  Use the boundary of the reference object.\n"
    "  -d  Distance function:\n"
    "              0: Euclidean (2D and 3D, unimplemented)\n"
    "              1: octagonal (2D and 3D) - default\n"
    "              2: approximate Euclidean (2D and 3D)\n"
    "              4: 4-connected (2D)\n"
    "              8: 8-connected (2D)\n"
    "              6: 6-connected (3D)\n"
    "             18: 18-connected (3D)\n"
    "             26: 26-connected (3D)\n"
    "  -f  The foreground object file.\n" 
    "  -p  Distance function parameter, which is curently only used for\n"
    "      approximate Euclidean distance transforms. The value should\n"
    "      be >= 1, with larger values giving greater accuracy at the\n"
    "      cost of increased time. Default value - 10.0.\n"
    "  -o  Output object file.\n"
    "  -h  Help - prints this usage message\n",
    argv[0]);
  }
  return(!ok);
}
Example #19
0
int             main(int argc, char **argv)
{
  int		option,
		ok = 1,
		usage = 0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  WlzObject	*oObj = NULL;
  WlzObject	*iObj[2];
  char 		*oObjFileStr;
  char  	*iObjFileStr[2];
  const char	*errMsg;
  static char	optList[] = "o:h",
		fileStrDef[] = "-";

  opterr = 0;
  iObj[0] = NULL;
  iObj[1] = NULL;
  oObjFileStr = fileStrDef;
  iObjFileStr[0] = fileStrDef;
  iObjFileStr[1] = fileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
	oObjFileStr = optarg;
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  if((iObjFileStr[0] == NULL) || (*iObjFileStr[0] == '\0') ||
     (iObjFileStr[1] == NULL) || (*iObjFileStr[1] == '\0') ||
     (oObjFileStr == NULL) || (*oObjFileStr == '\0'))
  {
    usage = 1;
  }
  if((usage == 0) && (optind < argc))
  {
    int 	i;

    i = 0;
    while((i < 2) && (optind < argc))
    {
      iObjFileStr[i] = *(argv + optind);
      ++optind;
      ++i;
    }
  }
  if((usage == 0) && (optind != argc))
  {
    usage = 1;
  }
  ok = !usage;
  if(ok)
  {
    int		i;

    i = 0;
    while((errNum == WLZ_ERR_NONE) && (i < 2))
    {
      errNum = WLZ_ERR_READ_EOF;
      if((iObjFileStr[i] == NULL) ||
	  (*iObjFileStr[i] == '\0') ||
	  ((fP = (strcmp(iObjFileStr[i], "-")?
		  fopen(iObjFileStr[i], "r"): stdin)) == NULL) ||
	  ((iObj[i]= WlzAssignObject(WlzReadObj(fP,
	  					   &errNum), NULL)) == NULL))
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: Failed to read object %d from file %s (%s).\n",
		       *argv, i, iObjFileStr[i], errMsg);
      }
      if(fP && strcmp(iObjFileStr[i], "-"))
      {
	fclose(fP);
      }
      ++i;
    }
  }
  if(ok)
  {
    oObj = WlzXORDom(iObj[0], iObj[1], &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed to compute set xor object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((fP = (strcmp(oObjFileStr, "-")? fopen(oObjFileStr, "w"):
	      				 stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, oObj)) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed to write output object (%s).\n",
		     *argv, errMsg);
    }
    if(fP && strcmp(oObjFileStr, "-"))
    {
      fclose(fP);
    }
  }
  WlzFreeObj(iObj[0]);
  WlzFreeObj(iObj[1]);
  WlzFreeObj(oObj);
  if(usage)
  {

    (void )fprintf(stderr,
	"Usage: %s"
	" [-o <out file>] [-h] [<in file 0>] [<in file 1>]\n"
	"Version: %s\n"
	"Options:\n"
	"  -o        Output file name.\n"
	"  -h        Help, prints this usage message.\n"
	"Computes the set exclusive or of the two given objects.\n"
	"The input objects are read from stdin and values are written\n"
	"to stdout unless the filenames are given.\n"
	"Example:\n%s -o out.wlz in0.wlz in1.wlz\n"
	"The exclusive of the the domains objects read from in0.wlz\n"
	"and in1.wlz is computed and written to out.wlz\n",
	*argv,
	WlzVersion(),
	*argv);
  }
  return(!ok);
}
int		main(int argc, char *argv[])
{
  int		option,
  		ok = 1,
		nVtx = 0,
  		usage = 0,
		verbose = 0;
  WlzDVertex3	c,
  		n;
  char		*inFileStr,
  		*outFileStr;
  FILE          *fP = NULL;
  WlzDVertex3	*vtx = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
  static char   optList[] = "ho:v";
  const char	inFileStrDef[] = "-",
  		outFileStrDef[] = "-";

  inFileStr = (char *)inFileStrDef;
  outFileStr = (char *)outFileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != EOF))
  {
    switch(option)
    {
      case 'v':
        verbose = 1;
	break;
      case 'o':
        outFileStr = optarg;
	break;
      case 'h': /* FALLTHROUGH */
      default:
        usage = 1;
	break;
    }
  }
  if(usage == 0)
  {
    if((inFileStr == NULL) || (*inFileStr == '\0') ||
       (outFileStr == NULL) || (*outFileStr == '\0'))
    {
      usage = 1;
    }
    if((usage == 0) && (optind < argc))
    {
      if((optind + 1) != argc)
      {
        usage = 1;
      }
      else
      {
        inFileStr = *(argv + optind);
      }
    }
  }
  ok = usage == 0;
  if(ok)
  {
    fP = NULL;
    if((inFileStr == NULL) ||
       (*inFileStr == '\0') ||
       ((fP = (strcmp(inFileStr, "-")?
              fopen(inFileStr, "r"): stdin)) == NULL))
    {
      ok = 0;
      errNum = WLZ_ERR_READ_EOF;
      (void )fprintf(stderr,
                     "%s: Failed to open vertex file (%s)\n",
                     *argv, inFileStr);
    }
    if(ok)
    {
      nVtx = WlzTstReadVtxList(&vtx, fP);
      if(nVtx < 1)
      {
        ok = 0;
	errNum = WLZ_ERR_READ_EOF;
	(void )fprintf(stderr,
	               "%s: Failed to read vertices from file (%s)\n",
		       *argv, inFileStr);
      }
    }
    if(fP && strcmp(inFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
  }
  if(ok)
  {
    errNum = WlzGeometryLSqOPlane(&n, &c, nVtx, vtx);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to compute least squares plane (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    fP = NULL;
    if((outFileStr == NULL) ||
       (*outFileStr == '\0') ||
       ((fP = (strcmp(outFileStr, "-")?
              fopen(outFileStr, "w"): stdout)) == NULL))
    {
      ok = 0;
      errNum = WLZ_ERR_WRITE_EOF;
      (void )fprintf(stderr,
                     "%s: Failed to open output file (%s)\n",
                     *argv, outFileStr);
    }
    if(ok)
    {
      if(verbose)
      {
	(void )fprintf(fP,
		       "normal = %lg %lg %lg\n"
		       "centroid = %lg %lg %lg\n",
		       n.vtX, n.vtY, n.vtZ,
		       c.vtX, c.vtY, c.vtZ);
      }
      else
      {
	(void )fprintf(fP,
		       "%lg %lg %lg\n"
		       "%lg %lg %lg\n",
		       n.vtX, n.vtY, n.vtZ,
		       c.vtX, c.vtY, c.vtZ);
      }
    }
    if(fP && strcmp(outFileStr, "-"))
    {
      (void )fclose(fP); fP = NULL;
    }
    
  }
  AlcFree(vtx);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-h] [-o<file>] [-v] [<file>]\n"
    "Options are:\n"
    "  -h  Outputs this usage message.\n"
    "  -o  Output file.\n"
    "  -v  Verbose output.\n"
    "Computes the plane with least square orthogonal distance to the given\n"
    "3D vertices.\n",
    argv[0]);
  }
  exit(!ok);
}
Example #21
0
int             main(int argc, char **argv)
{
  int		option,
		meanCrv = 0,
  		ok = 1,
		usage = 0;
  double	scale = 1.0;
  WlzInterpolationType interp = WLZ_INTERPOLATION_LINEAR;
  WlzObject     *inObj = NULL,
  		*outObj = NULL;
  FILE		*fP = NULL;
  char		*inObjFileStr,
  		*outObjFileStr;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
  static char	optList[] = "hmNLQo:s:",
  		fileStrDef[] = "-";

  opterr = 0;
  inObjFileStr = fileStrDef;
  outObjFileStr = fileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'N':
        interp = WLZ_INTERPOLATION_NEAREST;
	break;
      case 'L':
        interp = WLZ_INTERPOLATION_LINEAR;
	break;
      case 'Q':
        interp = WLZ_INTERPOLATION_ORDER_2;
	break;
      case 'm':
        meanCrv = 1;
	break;
      case 'o':
        outObjFileStr = optarg;
	break;
      case 's':
        if(sscanf(optarg, "%lg", &scale) != 1)
	{
	  usage = 1;
	}
	break;
      case 'h': /* FALLTHROUGH */
      default:
        usage = 1;
	break;
    }
  }
  if((usage == 0) && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
    }
    else
    {
      inObjFileStr = *(argv + optind);
    }
  }
  ok = (usage == 0);
  if(ok)
  {
    if((inObjFileStr == NULL) ||
	(*inObjFileStr == '\0') ||
	((fP = (strcmp(inObjFileStr, "-")?
	       fopen(inObjFileStr, "r"): stdin)) == NULL) ||
	((inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
	(errNum != WLZ_ERR_NONE))
    {
      ok = 0;
    }
    if(fP)
    {
      if(strcmp(inObjFileStr, "-"))
      {
	(void )fclose(fP);
      }
      fP = NULL;
    }
  }
  if(ok)
  {
    outObj = WlzCMeshCurvToImage(inObj, scale, meanCrv, interp, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	     "%s: Failed to create contour from conforming mesh (%s).\n",
	     *argv, errMsg);

    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((fP = (strcmp(outObjFileStr, "-")?
              fopen(outObjFileStr, "w"): stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to write output object (%s).\n",
		     *argv, errMsg);
    }
    if(fP && strcmp(outObjFileStr, "-"))
    {
      (void )fclose(fP);
    }
  }
  (void )WlzFreeObj(inObj);
  (void )WlzFreeObj(outObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%sExample: %s%s",
    *argv,
    " [-h] [-m] [-N] [-L] [-Q] [-o<output object>] [-s#]\n"
    "      [<input object>]\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -h  Help, prints usage message.\n"
    "  -N  Nearest neighbour interpolation from nearest element node value.\n"
    "  -L  Linear interpolation from element node values.\n"
    "  -Q  Interpolation from nodes surrounding element.\n"
    "  -m  Set image values to the mean rather than the Gaussian curvature.\n"
    "  -o  Output object file.\n"
    "  -s  Additional scale factor to be used in going from the mesh to the\n"
    "      spatial domain.\n"
    "Creates a 2D domain object with grey values (image) in which the values\n"
    "that are interpolated from the Gaussian curvature of the mesh. The 2D\n"
    "domain is created to cover the mesh following it's displacement. The\n"
    "displaced mesh must have been computed so that the displacements\n"
    "transform it to a plane (as by WlzCMeshSurfaceMap(1)).\n"
    "By default files are read from the standard input and written to the\n"
    "standard output.\n",
    *argv,
    " -o out.wlz in.wlz\n"
    "Reads a 2D5 conforming mesh from the file in.wlz, applies the meshes\n"
    "displacements to create a 2D domain object with the values set using\n"
    "the Gaussian curvature of the mesh prior to he application of it's\n"
    "displacements. The 2D domain object image is then writen to the file\n"
    "out.wlz.\n");
  }
  return(!ok);
}
Example #22
0
int             main(int argc, char **argv)
{
  int		idx,
		hFlag = 0,
		mFlag = 0,
		nFlag = 0,
		iFlag = 0,
		option,
		ok = 1,
		usage = 0;
  double	hDist,
  		mDist,
		nDist,
		iDist;
  char		hStr[64],
  		mStr[64],
		nStr[64],
		iStr[64];
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzObject	*inObj[2];
  FILE		*fP = NULL;
  char 		*outFileStr;
  char  	*inObjFileStr[2];
  const char	*errMsg;
  static char	optList[] = "ho:HMNI",
		fileStrDef[] = "-";

  opterr = 0;
  inObj[0] = NULL;
  inObj[1] = NULL;
  inObjFileStr[0] = inObjFileStr[1] = outFileStr = fileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
        outFileStr = optarg;
	break;
      case 'H':
        hFlag = 1;
	break;
      case 'M':
        mFlag = 1;
	break;
      case 'N':
        nFlag = 1;
	break;
      case 'I':
        iFlag = 1;
	break;
      case 'h':
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if((inObjFileStr[0] == NULL) || (*inObjFileStr[0] == '\0') ||
     (inObjFileStr[1] == NULL) || (*inObjFileStr[1] == '\0') ||
     (outFileStr == NULL) || (*outFileStr == '\0'))
  {
    ok = 0;
    usage = 1;
  }
  if(ok && (optind < argc))
  {
    idx = 0;
    while((idx < 2) && (optind < argc))
    {
      inObjFileStr[idx] = *(argv + optind);
      ++optind;
      ++idx;
    }
  }
  if(ok && (optind != argc))
  {
    usage = 1;
    ok = 0;
  }
  if(ok)
  {
    /* Set default to all metrics if none have been specified. */
    if((hFlag == 0) && (mFlag == 0) && (nFlag == 0) && (iFlag == 0))
    {
      hFlag = mFlag = nFlag = iFlag = 1;
    }
    /* Read objects. */
    idx = 0;
    while((errNum == WLZ_ERR_NONE) && (idx < 2))
    {
      errNum = WLZ_ERR_READ_EOF;
      if((inObjFileStr[idx] == NULL) ||
	  (*inObjFileStr[idx] == '\0') ||
	  ((fP = (strcmp(inObjFileStr[idx], "-")?
		  fopen(inObjFileStr[idx], "r"): stdin)) == NULL) ||
	  ((inObj[idx] = WlzAssignObject(WlzReadObj(fP,
	  					    &errNum), NULL)) == NULL))
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: Failed to read object %d from file %s (%s)\n",
		       *argv, idx, inObjFileStr[idx], errMsg);
      }
      if(fP && strcmp(inObjFileStr[idx], "-"))
      {
	fclose(fP);
      }
      ++idx;
    }
  }
  if(ok)
  {
    /* Check object types. */
    if(inObj[0]->type != inObj[1]->type)
    {
      errNum = WLZ_ERR_OBJECT_TYPE;
    }
    else if((inObj[0]->domain.core == NULL) ||
            (inObj[1]->domain.core == NULL))
    {
      errNum = WLZ_ERR_DOMAIN_NULL;
    }
    else
    {
      switch(inObj[0]->type)
      {
        case WLZ_CONTOUR:
          if((inObj[0]->domain.core == NULL) ||
             (inObj[0]->domain.core == NULL) ||
             (inObj[0]->domain.ctr->model == NULL) ||
             (inObj[1]->domain.ctr->model == NULL))
          {
            errNum = WLZ_ERR_DOMAIN_NULL;
          }
          else
          {
	    errNum = WlzDistMetricGM(inObj[0]->domain.ctr->model,
	    			     inObj[1]->domain.ctr->model,
				     (hFlag)? &hDist: NULL,
				     (mFlag)? &mDist: NULL,
				     (nFlag)? &nDist: NULL,
				     (iFlag)? &iDist: NULL);
          }
          break;
        default:
          errNum = WLZ_ERR_OBJECT_TYPE;
          ok = 0;
          break;
      }
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr, "%s: Failed to compute distance metric (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    if(((fP = (strcmp(outFileStr, "-")?
              fopen(outFileStr, "w"): stdout)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: Failed open output file (%s).\n",
		     *argv, errMsg);
    }
    else
    {
      hStr[0] = mStr[0] = nStr[0] = iStr[0] = '\0';
      if(hFlag)
      {
        (void )sprintf(hStr, " %g", hDist);
      }
      if(mFlag)
      {
        (void )sprintf(mStr, " %g", mDist);
      }
      if(nFlag)
      {
        (void )sprintf(nStr, " %g", nDist);
      }
      if(iFlag)
      {
        (void )sprintf(iStr, " %g", iDist);
      }
      (void )fprintf(fP, "%s%s%s%s\n", hStr, mStr, nStr, iStr);
    }
    if(fP && strcmp(outFileStr, "-"))
    {
      fclose(fP);
    }
  }
  (void )WlzFreeObj(inObj[0]);
  (void )WlzFreeObj(inObj[1]);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%sExample: %s%s",
    *argv,
    " [-h] [-o <output file>] [-H] [-M] [-N] [-I]\n"
    "                         [<in obj 0>] [<in obj 1>]\n"
    "Options:\n"
    "  -h  Help, prints this usage message.\n"
    "  -o  Output file for distance metrics.\n"
    "  -H  Hausdorff distance metric.\n"
    "  -M  Mean of nearest neighbours distance metrics.\n"
    "  -N  Median of nearest neighbours distance metrics.\n"
    "  -I  Minimum nearest neighbour distance.\n"
    "Computes distance metrics for the given pair of objects.\n"
    "If no distance metrics are specified on the command line then all\n"
    "the metrics will be be computed and output, but if any metrics are\n"
    "specified on the computed line then only those metrics will be\n"
    "computed and output.\n"
    "The selected distance metrics are written on a single line as,\n"
    "ascii floating point values, separated by white spaces characters\n"
    "and in the order: Hausdorff; mean; median and minimum distance.\n"
    "The input objects are read from stdin and the distances are written\n"
    "to stdout unless the filenames are given.\n",
    *argv,
    " -H -N -o out.num in0.wlz in1.wlz\n"
    "Two objects are read from in0.wlz and in1.wlz, the Hausdorff and\n"
    "median of nearest neighbours distance metrics are computed and\n"
    "written to the file out.num on a single line in that order.\n");
  }
  return(!ok);
}
Example #23
0
int main(int	argc,
	 char	**argv)
{

  WlzObject	*obj, *mask, *newobj;
  FILE		*inFile = NULL;
  char 		optList[] = "m:h";
  int		option;
  WlzPixelV	maskVal;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
    
  /* read the argument list and check for an input file */
  opterr = 0;
  maskVal.type = WLZ_GREY_FLOAT;
  maskVal.v.flv = 0.0;
  
  while( (option = getopt(argc, argv, optList)) != EOF ){
    switch( option ){
    case 'm':
      maskVal.v.flv = atof(optarg);
      break;
    case 'h':
    default:
      usage(argv[0]);
      return 1;
    }
  }

  /* check for read from file, note if one file is defined then
     it is the mask and the object should be on stdin */
  if( (argc - optind) >= 2 ){
    /* read the mask */
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    if( (mask = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read mask from file %s\n", argv[0],
	      *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    fclose( inFile );
    optind++;

    /* read the object */
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    if( (obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read obj from file %s\n", argv[0],
	      *(argv+optind));

      usage(argv[0]);
      return 1;
    }
    fclose( inFile );
  }
  else if( (argc - optind) == 1 ){
    /* read the mask */
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    if( (mask = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read mask from file %s\n", argv[0],
	      *(argv+optind));
      usage(argv[0]);
      return 1;
    }
    fclose( inFile );
    inFile = stdin;
    if( (obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read obj from stdin\n", argv[0]);
      usage(argv[0]);
      return 1;
    }
  }
  else {
    /* else read objects from stdin */
    if( (obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read obj from stdin\n", argv[0]);
      usage(argv[0]);
      return 1;
    }
    if( (mask = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) == NULL ){
      fprintf(stderr, "%s: can't read mask from stdin\n", argv[0]);
      usage(argv[0]);
      return 1;
    }
  }
    
  /* apply mask and write resultant object */
  if((newobj = WlzGreyMask(obj, mask, maskVal, &errNum)) != NULL){
    if((errNum = WlzWriteObj(stdout, newobj)) != WLZ_ERR_NONE) {
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
		     "%s: failed to write object (%s).\n",
		     argv[0], errMsg);
      return(1);
    }
    WlzFreeObj(newobj);
  }
  WlzFreeObj(mask);
  WlzFreeObj(obj);

  return 0;
}
Example #24
0
int             main(int argc, char **argv)
{
  int		nTiePP,
		option,
		vxCount = 0,
		vxLimit = 0,
		basisFnPolyOrder = 3,
                index,
                relFlag,
                meshMinDist,
                meshMaxDist;
  char 		*srcFileStr,
		*bibFileStr = NULL,
                *outFileStr,
                *bibErrMsg;
  const char    *errMsg;
  FILE		*inFile = NULL,
                *outFile = NULL;
  WlzDVertex2   *sVtx2 = NULL,
                *dVtx2 = NULL,
                *srcVtx2 = NULL,
                *dstVtx2 = NULL;
  WlzDVertex3   *dVtx = NULL, 
                *sVtx = NULL,
                *srcVtx = NULL,   
                *dstVtx = NULL;
  WlzObject	*inObj = NULL;
  WlzCompoundArray  *outObj = NULL;              
  WlzBasisFnTransform  *basisTr;
  WlzTransformType     trType;
  WlzFnType basisFnType;
  WlzMeshGenMethod genMethod;
  WlzErrorNum	errNum = WLZ_ERR_NONE; 
  BibFileRecord	       *bibfileRecord;
  BibFileError         bibFileErr;
  
  /* read the argument list and check for an input file */

  static char	       optList[] = "s:b:t:h";
 
   while( (option = getopt(argc, argv, optList)) != EOF )
   {
      switch( option )
      {
        case 'h':
             usage(argv[0]);
	     return(0);
        case 'b':
	    bibFileStr = optarg;
	    break;
        case 's':
	    srcFileStr = optarg;
	    break;
        case 't':
	    outFileStr = optarg;
	    break;
        default:
              return(0);
      }
   }
   if((inFile = fopen(bibFileStr, "r")) == NULL )
   {
       printf("cannot open the input bib file.\n");
       exit(1);
   }
   /* read the bibfile until we get the WlzWarptransformParams part */

   while( !feof(inFile) ){
      bibFileErr = BibFileRecordRead(&bibfileRecord, &bibErrMsg, inFile);
      if(bibFileErr != BIBFILE_ER_EOF)
      {
	bibFileErr = WlzEffBibParseWarpTransformParamsRecord(
						bibfileRecord,
						&basisFnType,
						&trType,
						&genMethod,
						&meshMinDist,
						&meshMaxDist);
	 if (bibFileErr == BIBFILE_ER_NONE)
	   break;
      }
      else
	break;
   }

   /* read the bibfile until we get the TiePointVtxs part */
   if(  bibFileErr == BIBFILE_ER_NONE )
   {
     while( !feof(inFile) ){
       bibFileErr = BibFileRecordRead(&bibfileRecord, &bibErrMsg, inFile);
       if(bibFileErr != BIBFILE_ER_EOF)
       {
	    if(vxCount >= vxLimit)
	    {
	      vxLimit = (vxLimit + 1024) * 2;
	      if(((srcVtx = (WlzDVertex3 *)AlcRealloc(srcVtx,
			     vxLimit * sizeof(WlzDVertex3))) == NULL) ||
		 ((dstVtx = (WlzDVertex3 *)AlcRealloc(dstVtx,
			     vxLimit * sizeof(WlzDVertex3))) == NULL))
	      {
		errNum = WLZ_ERR_MEM_ALLOC;
	      }
	      else
	      {
		sVtx = srcVtx + vxCount;
		dVtx = dstVtx + vxCount;
	      }
	    }
	    if(errNum == WLZ_ERR_NONE)
	    {
	      bibFileErr = WlzEffBibParseTiePointVtxsRecord(
						bibfileRecord,
						&index,
						dVtx,
						sVtx,
						&relFlag);
	      if (bibFileErr == BIBFILE_ER_NONE)
	      {	      
		++sVtx;
		++dVtx;
		++vxCount;
	      }
	    }
      }
      else
	break;
     }
   }

   nTiePP = vxCount;

   BibFileRecordFree(&bibfileRecord);

   fclose(inFile);

   if(  bibFileErr == BIBFILE_ER_EOF )
   {
     errNum = WLZ_ERR_NONE;
   }
   else
   {
     printf("Read bib file error.\n");
     exit(1);
   }

   /* copy 3D verices to 2D vertices - cast won't work */
   if(((srcVtx2 = (WlzDVertex2 *)AlcRealloc(srcVtx2,
		  vxCount * sizeof(WlzDVertex2))) == NULL) ||
		  ((dstVtx2 = (WlzDVertex2 *)AlcRealloc(dstVtx2,
		  vxCount * sizeof(WlzDVertex2))) == NULL))
   {
     errNum = WLZ_ERR_MEM_ALLOC;
   }
   else
   {
     sVtx = srcVtx;
     dVtx = dstVtx;
     sVtx2 = srcVtx2;
     dVtx2 = dstVtx2;
     for (vxCount = 0; vxCount < nTiePP;  vxCount++)
     {
       sVtx2->vtX = sVtx->vtX;
       sVtx2->vtY = sVtx->vtY;
       dVtx2->vtX = dVtx->vtX;
       dVtx2->vtY = dVtx->vtY;
       ++sVtx2;
       ++dVtx2;
       ++sVtx;
       ++dVtx;
     }
   }

   errNum = WLZ_ERR_READ_EOF;
   if((srcFileStr == NULL) ||
	(*srcFileStr == '\0') ||
	((inFile = (strcmp(srcFileStr, "-")?
		fopen(srcFileStr, "r"): stdin)) == NULL) ||
       	((inObj= WlzAssignObject(WlzReadObj(inFile, &errNum), NULL)) == NULL) 
               || (errNum != WLZ_ERR_NONE))
   {
      (void )fprintf(stderr,
		     "%s: failed to read object from file %s\n",
		     *argv, srcFileStr);
   }
   if(inFile)
   {
      if(strcmp(srcFileStr, "-"))
      {
	fclose(inFile);
      }
      inFile = NULL;
   }
  if(errNum == WLZ_ERR_NONE)
  {
      basisTr = WlzAffineBasisFnTransformFromCPtsT(inObj, basisFnType, 
					    basisFnPolyOrder,
					    nTiePP, srcVtx2, nTiePP, dstVtx2, 
					    &errNum);
  }
  
  /* Calculate tensor components and then write them out. */
  if(errNum == WLZ_ERR_NONE)
  {
    outObj = WlzBasisFnTensorTransformObjPrv(inObj, basisTr, &errNum);
  }
  if(errNum != WLZ_ERR_NONE)
  {
    (void )WlzStringFromErrorNum(errNum, &errMsg);
    (void )fprintf(stderr,
    	       "%s: failed to transform object (%s).\n",
       	       *argv, errMsg);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((outFile = (strcmp(outFileStr, "-")?
		  fopen(outFileStr, "w"):
		  stdout)) == NULL) ||
	          ((errNum = WlzWriteObj(outFile, (WlzObject *)outObj)) 
		   != WLZ_ERR_NONE))
    {
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
			 "%s: failed to write output compound array (%s).\n",
			 *argv, errMsg);
    }
    if(outFile && strcmp(outFileStr, "-"))
    {
      fclose(outFile);
    }
  }

  /* free memory */
  AlcFree(srcVtx);
  AlcFree(dstVtx);
  AlcFree(srcVtx2);
  AlcFree(dstVtx2);
  WlzBasisFnFreeTransform(basisTr);
  return(errNum);
}
Example #25
0
int             main(int argc, char **argv)
{
  int		option,
  		ok = 1,
		usage = 0;
  FILE		*fP = NULL;
  char 		*inObjFileStr,
  		*outFileStr;
  WlzObject     *inObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
  static char	optList[] = "ho:",
  		fileStrDef[] = "-";

  opterr = 0;
  inObjFileStr = fileStrDef;
  outFileStr = fileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
        outFileStr = optarg;
	break;
      case 'h': /* FALLTHROUGH */
      default:
        usage = 1;
	break;
    }
  }
  if((usage == 0) && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
    }
    else
    {
      inObjFileStr = *(argv + optind);
    }
  }
  ok = (usage == 0);
  if(ok)
  {
    if((inObjFileStr == NULL) ||
	(*inObjFileStr == '\0') ||
	((fP = (strcmp(inObjFileStr, "-")?
	       fopen(inObjFileStr, "r"): stdin)) == NULL) ||
	((inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
	(errNum != WLZ_ERR_NONE))
    {
      ok = 0;
    }
    if(fP)
    {
      if(strcmp(inObjFileStr, "-"))
      {
	(void )fclose(fP);
      }
      fP = NULL;
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if((fP = (strcmp(outFileStr, "-")?
              fopen(outFileStr, "w"): stdout)) == NULL)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to open output file %s (%s).\n",
		     *argv, outFileStr, errMsg);
    }
    else
    {
      switch(inObj->type)
      {
        case WLZ_CMESH_2D:  /* FALLTHROUGH */
	case WLZ_CMESH_2D5: /* FALLTHROUGH */
	case WLZ_CMESH_3D:
	  errNum = WlzBoundaryVerticesCMesh(fP, inObj);
	  break;
        default:
	  errNum = WLZ_ERR_OBJECT_TYPE;
	  break;
      }
      if(errNum != WLZ_ERR_NONE)
      {
        ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: Failed to output boundary vertices (%s).\n",
		       *argv, errMsg);
      }
    }
    if(fP && strcmp(outFileStr, "-"))
    {
      (void )fclose(fP);
    }
  }
  (void )WlzFreeObj(inObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%sExample: %s%s",
    *argv,
    " [-h] [-o<output file>] [<input object>]\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -h  Help, prints usage message.\n"
    "  -o  Output file.\n"
    "Given an object that is represented by connected vertices (eg a mesh)\n"
    "this filter outputs the coordinates of the vertices that are on\n"
    "the boundary of the object.\n"
    "By default the input object if read from the standard input and the\n"
    "vertices are written to the standard output.\n",
    *argv,
    " -o out.num in.wlz\n"
    "The boundary vertices of the object read from the file in.wlz are\n"
    "written to the file out.num as white space seperated acsii text.\n");
  }
  return(!ok);
}
Example #26
0
int             main(int argc, char **argv)
{
  int		option,
		ok = 1,
		usage = 0;
  double	ftrMlt = 1.0,
  		ftrPrm = 1.0;
  WlzRsvFilterName ftrName = WLZ_RSVFILTER_NAME_DERICHE_1;
  WlzRsvFilter *ftr = NULL;
  WlzObject	*inObj = NULL,
  		*outObj = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  char 		*outFileStr,
  		*inObjFileStr;
  static char	optList[] = "ho:gdm:p:",
		outFileStrDef[] = "-",
  		inObjFileStrDef[] = "-";

  opterr = 0;
  outFileStr = outFileStrDef;
  inObjFileStr = inObjFileStrDef;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
        outFileStr = optarg;
	break;
      case 'h':
        usage = 1;
	ok = 0;
	break;
      case 'g':
        ftrName = WLZ_RSVFILTER_NAME_GAUSS_1;
	break;
      case 'd':
        ftrName = WLZ_RSVFILTER_NAME_DERICHE_1;
	break;
      case 'm':
	if(sscanf(optarg, "%lg", &ftrMlt) != 1)
	{
	  usage = 1;
	  ok = 0;
	}
        break;
      case 'p':
	if(sscanf(optarg, "%lg", &ftrPrm) != 1)
	{
	  usage = 1;
	  ok = 0;
	}
        break;
      default:
        usage = 1;
	ok = 0;
	break;
    }
  }
  if(ok)
  {
    if((inObjFileStr == NULL) || (*inObjFileStr == '\0') ||
       (outFileStr == NULL) || (*outFileStr == '\0'))
    {
      ok = 0;
      usage = 1;
    }
    if(ok && (optind < argc))
    {
      if((optind + 1) != argc)
      {
	usage = 1;
	ok = 0;
      }
      else
      {
	inObjFileStr = *(argv + optind);
      }
    }
    if(ok)
    {
      if(((ftr = WlzRsvFilterMakeFilter(ftrName, ftrPrm, &errNum)) == NULL) ||
         (errNum != WLZ_ERR_NONE))
      {
        ok = 0;
	(void )fprintf(stderr, "%s Failed to create filter (%s)\n",
		       *argv, WlzStringFromErrorNum(errNum, NULL));
      }
      else
      {
	ftr->c *= ftrMlt;
      }
    }
    if(ok)
    {
      if((inObjFileStr == NULL) ||
	 (*inObjFileStr == '\0') ||
	 ((fP = (strcmp(inObjFileStr, "-")?
		fopen(inObjFileStr, "r"): stdin)) == NULL) ||
	 ((inObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL) ||
	 (errNum != WLZ_ERR_NONE))
      {
	ok = 0;
	(void )fprintf(stderr,
		       "%s: failed to read object from file %s\n",
		       *argv, inObjFileStr);
      }
      if(fP && strcmp(inObjFileStr, "-"))
      {
	fclose(fP);
      }
      if(ok)
      {
        if(((outObj = WlzAssignObject(
		      WlzGreyGradient(NULL, NULL, NULL,
		      		      inObj, ftr, &errNum), NULL)) == NULL) ||
	   (errNum != WLZ_ERR_NONE))

        {
	  ok = 0;
	  (void )fprintf(stderr, "%s Failed to compute gradient object (%s)\n",
	  		 *argv, WlzStringFromErrorNum(errNum, NULL));
	}
      }
      if(ok)
      {
	if(((fP = (strcmp(outFileStr, "-")?
		  fopen(outFileStr, "w"):
		  stdout)) == NULL) ||
	   (WlzWriteObj(fP, outObj) != WLZ_ERR_NONE))
	{
	  ok = 0;
	  (void )fprintf(stderr,
			 "%s: failed to write output object\n",
			 *argv);
	}
	if(fP && strcmp(outFileStr, "-"))
	{
	  fclose(fP);
	}
      }
    }
  }
  if(inObj)
  {
    WlzFreeObj(inObj);
  }
  if(outObj)
  {
    WlzFreeObj(outObj);
  }
  if(ftr)
  {
    WlzRsvFilterFreeFilter(ftr);
  }
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%sExample: %s%s",
    *argv,
    " [-o<output object>] [-h] [-o] [-g] [-d] [-m#] [-p#]\n"
    "        [<input object>]\n"
    "Options:\n"
    "  -h  Prints this usage information\n"
    "  -o  Output object file name.\n"
    "  -g  Use approximate Gaussian filter.\n"
    "  -d  Use Deriche filter.\n"
    "  -p  Filter parameter for Gaussian (sigma) and Deriche (alpha) filters\n"
    "  -m  Extra multiplication factor for gradient grey levels.\n"
    "Computes a grey gradient object from the input object.\n"
    "The input object is read from stdin and the gradient object is\n"
    "written to stdout unless the filenames are given.\n",
    *argv,
    " -d -m 2.0 -o grad.wlz in.wlz\n"
    "The input Woolz object is read from in.wlz, and the grey gradient\n"
    "image is computed using a Deriche filter and an additional multiplying\n"
    "factor of 2.0. The gradient object is written to grad.wlz.\n"
    "Objects with unsigned byte grey values will be promoted to short\n"
    "grey valued objects.\n");
  }
  return(!ok);
}
Example #27
0
int		main(int argc, char *argv[])
{
  int		ok,
  		option,
  		usage = 0;
  char		*inFileStr,
  		*outFileStr;
  WlzObject	*inObj = NULL;
  FILE		*fP = NULL;
  const char	*errMsg;
  static char	optList[] = "o:h",
  		fileStrDef[] = "-";
  WlzErrorNum	errNum = WLZ_ERR_NONE;


  opterr = 0;
  inFileStr = outFileStr = fileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'o':
	outFileStr = optarg;
	break;
      case 'h':
      default:
	usage = 1;
	break;
    }
  }
  if((usage == 0) && (optind < argc))
  {
    if((optind + 1) != argc)
    {
      usage = 1;
    }
    else
    {
      inFileStr = *(argv + optind);
    }
  }
  ok = (usage == 0);
  if(ok)
  {
    errNum = WLZ_ERR_READ_EOF;
    if(((fP = (strcmp(inFileStr, "-")?
        fopen(inFileStr, "r"): stdin)) == NULL) ||
       ((inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to read object from file %s (%s)\n",
		     argv[0], inFileStr, errMsg);
    }
    if(fP && strcmp(inFileStr, "-"))
    {
      (void )fclose(fP);
      fP = NULL;
    }
  }
  if(ok)
  {
    /* Check object is valid for tensor export. */
    if(inObj == NULL)
    {
      errNum = WLZ_ERR_OBJECT_NULL;
    }
    else if(inObj->domain.core == NULL)
    {
      errNum = WLZ_ERR_DOMAIN_NULL;
    }
    else if(inObj->values.core == NULL)
    {
      errNum = WLZ_ERR_VALUES_NULL;
    }
    else
    {
      switch(inObj->type)
      {
        case WLZ_CMESH_3D:
	  if(inObj->domain.core->type  != WLZ_CMESH_3D)
	  {
	    errNum = WLZ_ERR_DOMAIN_TYPE;
	  }
	  if(inObj->values.core->type != WLZ_INDEXED_VALUES)
	  {
	    errNum = WLZ_ERR_VALUES_TYPE;
	  }
	  else if((inObj->values.x->attach != WLZ_VALUE_ATTACH_ELM) ||
		  (inObj->values.x->vType != WLZ_GREY_DOUBLE) ||
		  (inObj->values.x->rank != 2) ||
		  (inObj->values.x->dim[0] != 3) ||
		  (inObj->values.x->dim[1] != 3))
	  {
	    errNum = WLZ_ERR_VALUES_DATA;
	  }
	  break;
        case WLZ_POINTS:
	  if(inObj->domain.core->type  != WLZ_POINTS_3D)
	  {
	    errNum = WLZ_ERR_DOMAIN_TYPE;
	  }
	  else if(inObj->values.core->type != WLZ_POINT_VALUES)
	  {
	    errNum = WLZ_ERR_VALUES_TYPE;
	  }
	  else if((inObj->values.pts->vType != WLZ_GREY_DOUBLE) ||
	          (inObj->values.pts->rank != 2) ||
		  (inObj->values.pts->dim[0] != 3) ||
		  (inObj->values.pts->dim[1] != 3))
	  {
	    errNum = WLZ_ERR_VALUES_DATA;
	  }
	  break;
	default:
	  errNum = WLZ_ERR_OBJECT_TYPE;
	  break;
      }
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Input object read from %s is inappropriate.\n"
		     "Only 3D conforming mesh objects with tensor values\n"
		     "attached to elements or points objects with tensor\n"
		     "values are aupported. (%s)\n",
		     argv[0], inFileStr, errMsg);
    }
  }
  if(ok)   
  {
    if((fP = (strcmp(outFileStr, "-")?
        fopen(outFileStr, "w"): stdin)) == NULL)
    {
      ok = 0;
      errNum = WLZ_ERR_WRITE_EOF;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to open output file %s (%s)\n",
		     argv[0], outFileStr, errMsg);
    }
  }
  if(ok)   
  {
    switch(inObj->type)
    {
      case WLZ_CMESH_3D:
        errNum = WlzVTKTensorFromCMesh(argv[0], inFileStr, fP, inObj);
	break;
      case WLZ_POINTS:
        errNum = WlzVTKTensorFromPoints(argv[0], inFileStr, fP, inObj);
	break;
      default:
        errNum = WLZ_ERR_OBJECT_TYPE;   
	break;
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to write tesnsor data to file %s (%s).\n",
		     argv[0], outFileStr, errMsg);
      
    }
  }
  if(fP && strcmp(outFileStr, "-"))
  {
    (void )fclose(fP);
  }
  (void )WlzFreeObj(inObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s [-h] [-o<out vtk file>] [-s<x>,<y>[,<z>]]\n"
    "\t\t[<in woolz file>]\n"
    "Version: %s\n"
    "Options:\n"
    "  -h        Help, prints this usage message.\n"
    "  -o        Output vtk file name.\n"
    "  -s	 Sampling interval.\n"
    "Reads either a 3D Woolz conforming mesh object with tensor data\n"
    "attached to it's elements or a points object with 3D points and\n"
    "tensor values, then writes the tensor data to a VTK polydata file\n"
    "with points at either the conforming mesh centroids or at given\n"
    "points.\n"
    "By default files are read from the standard input and written to\n"
    "the standard output.\n"
    "Example:\n"
    "  %s -o out.vtk in.wlz\n"
    "Creates a VTK polydata file with tensor dataset attributes from the\n"
    "given Woolz file.\n",
    argv[0],
    WlzVersion(),
    argv[0]);
  }
  return(!ok);
}
Example #28
0
int             main(int argc, char **argv)
{
  int           option,
                ok = 1,
                usage = 0,
		dim = 0,
		transform = 0;
  WlzIBox3	bBox[2];
  WlzEffFormat  outFmt = WLZEFF_FORMAT_NONE;
  WlzEffFormat  inFmt[2] = {WLZEFF_FORMAT_NONE};
  WlzObject     *outObj = NULL;
  WlzObject	*inObj[2] = {NULL};
  char          *outFileStr;
  char		*inFileStr[2] = {NULL};
  WlzAffineTransform *tr = NULL;
  WlzErrorNum   errNum = WLZ_ERR_NONE;
  const char    *errMsg;
  static char   optList[] = "s:t:o:u:hT",
                fileStrDef[] = "-";

  opterr = 0;
  inFileStr[0] = fileStrDef;
  inFileStr[1] = fileStrDef;
  outFileStr = fileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 's':
	if((inFmt[0] = WlzEffStringExtToFormat(optarg)) == 0)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 't':
	if((inFmt[1] = WlzEffStringExtToFormat(optarg)) == 0)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 'u':
	if((outFmt = WlzEffStringExtToFormat(optarg)) == 0)
	{
	  usage = 1;
	  ok = 0;
	}
	break;
      case 'o':
	outFileStr = optarg;
	break;
      case 'T':
	transform = 1;
	break;
      case 'h': /* FALLTHROUGH */
      default:
	usage = 1;
	break;
    }
  }
  if(usage == 0)
  {
    usage = (optind + 2 != argc);
  }
  if(usage == 0)
  {
    inFileStr[0] = *(argv + optind);
    inFileStr[1] = *(argv + optind + 1);
  }
  if(usage == 0)
  {
    if(inFmt[0] == WLZEFF_FORMAT_NONE)
    {
      inFmt[0] = WlzEffStringFormatFromFileName(inFileStr[0]);
    }
    if(inFmt[1] == WLZEFF_FORMAT_NONE)
    {
      inFmt[1] = WlzEffStringFormatFromFileName(inFileStr[1]);
    }
    if(outFmt == WLZEFF_FORMAT_NONE)
    {
      outFmt = WlzEffStringFormatFromFileName(outFileStr);
    }
    if((inFmt[0] == WLZEFF_FORMAT_NONE) || (inFmt[1] == WLZEFF_FORMAT_NONE) ||
       (outFmt == WLZEFF_FORMAT_NONE))
    {
      usage = 1;
    }
  }
  ok = (usage == 0);
  /* Read source and target objects. */
  if(ok)
  {
    int		idx;

    for(idx = 0; ok && (idx < 2); ++idx)
    {
      char *fStr;
      FILE *fP;

      if(strcmp(inFileStr[idx], "-") == 0)
      {
        fP = stdin;
	fStr = NULL;
      }
      else
      {
        fP = NULL;
	fStr = inFileStr[idx];
      }
      if((inObj[idx] = WlzAssignObject(WlzEffReadObj(fP, fStr, inFmt[idx],
                                       0, 0, 0, &errNum), NULL)) == NULL)
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
	    "%s: Failed to read object from file(s) %s (%s)\n",
	    *argv, inFileStr[idx], errMsg);
      }
    }
  }
  /* Check object dimension */
  if(ok)
  {
    int		idx;
    int		d[2];

    d[0] = 0;
    for(idx = 0; ok && (idx < 2); ++idx)
    {
      d[idx] = WlzObjectDimension(inObj[idx], &errNum);
      ok = (errNum == WLZ_ERR_NONE);
    }
    if(errNum == WLZ_ERR_NONE)
    {
      if((d[0] == 0) || (d[0] != d[1]))
      {
	ok = 0;
        errNum = WLZ_ERR_OBJECT_TYPE;
      }
    }
    dim = d[0];
    if(errNum != WLZ_ERR_NONE)
    {
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
          "%s: Failed to establish object dimensions (%s)\n",
	  *argv, errMsg);
    }
  }
  /* Compute the bounding box of the source and target objects. */
  if(ok)
  {
    int		idx;

    for(idx = 0; ok && (idx < 2); ++idx)
    {
      bBox[idx] = WlzBoundingBox3I(inObj[idx], &errNum);
      if(errNum != WLZ_ERR_NONE)
      {
        ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
	    "%s: Failed to compute bounding box of object read from file\n"
	    "%s (%s).\n",
	    *argv, inFileStr[idx], errMsg);
      }
    }
  }
  /* Compute affine transform which will register the source to target
   * bounding box. */
  if(ok)
  {
    int		idx,
    		nVtx;
    WlzVertexType vType;
    WlzTransformType tType;
    WlzVertexP vP[2];
    WlzDVertex3	wSp[48];

    vP[0].d3 = wSp;
    vP[1].d3 = wSp + 24;
    if(dim == 2)
    {
      nVtx = 4;
      vType = WLZ_VERTEX_D2;
      tType = WLZ_TRANSFORM_2D_AFFINE;
      for(idx = 0; idx < 2; ++idx)
      {
        (vP[idx].d2)[0].vtX = bBox[idx].xMin;
	(vP[idx].d2)[0].vtY = bBox[idx].yMin;
        (vP[idx].d2)[1].vtX = bBox[idx].xMax;
	(vP[idx].d2)[1].vtY = bBox[idx].yMin;
        (vP[idx].d2)[2].vtX = bBox[idx].xMax;
	(vP[idx].d2)[2].vtY = bBox[idx].yMax;
        (vP[idx].d2)[3].vtX = bBox[idx].xMin;
	(vP[idx].d2)[3].vtY = bBox[idx].yMax;
      }
    }
    else /* dim == 3 */
    {
      nVtx = 8;
      vType = WLZ_VERTEX_D3;
      tType = WLZ_TRANSFORM_3D_AFFINE;
      for(idx = 0; idx < 2; ++idx)
      {
        (vP[idx].d3)[0].vtX = bBox[idx].xMin;
	(vP[idx].d3)[0].vtY = bBox[idx].yMin;
	(vP[idx].d3)[0].vtZ = bBox[idx].zMin;
        (vP[idx].d3)[1].vtX = bBox[idx].xMax;
	(vP[idx].d3)[1].vtY = bBox[idx].yMin;
	(vP[idx].d3)[1].vtZ = bBox[idx].zMin;
        (vP[idx].d3)[2].vtX = bBox[idx].xMax;
	(vP[idx].d3)[2].vtY = bBox[idx].yMax;
	(vP[idx].d3)[2].vtZ = bBox[idx].zMin;
        (vP[idx].d3)[3].vtX = bBox[idx].xMin;
	(vP[idx].d3)[3].vtY = bBox[idx].yMax;
	(vP[idx].d3)[3].vtZ = bBox[idx].zMin;
        (vP[idx].d3)[4].vtX = bBox[idx].xMin;
	(vP[idx].d3)[4].vtY = bBox[idx].yMin;
	(vP[idx].d3)[4].vtZ = bBox[idx].zMax;
        (vP[idx].d3)[5].vtX = bBox[idx].xMax;
	(vP[idx].d3)[5].vtY = bBox[idx].yMin;
	(vP[idx].d3)[5].vtZ = bBox[idx].zMax;
        (vP[idx].d3)[6].vtX = bBox[idx].xMax;
	(vP[idx].d3)[6].vtY = bBox[idx].yMax;
	(vP[idx].d3)[6].vtZ = bBox[idx].zMax;
        (vP[idx].d3)[7].vtX = bBox[idx].xMin;
	(vP[idx].d3)[7].vtY = bBox[idx].yMax;
	(vP[idx].d3)[7].vtZ = bBox[idx].zMax;
      }
    }
    tr = WlzAffineTransformLSq(vType, nVtx, vP[1], nVtx, vP[0], 0, NULL,
                               tType, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	  "%s: Failed to compute affine transform (%s).\n",
	  *argv, errMsg);
    }
  }
  /* Create affine transform object or affine transform the source object
   * as required. */
  if(ok)
  {
    int		idx,
    		idy;
    const double eps = 1.0e-12;

    /* Tidy up the transform, |t_{ij}| < eps => t_{ij} = 0.0. */
    for(idy = 0; idy < 4; ++idy)
    {
      for(idx = 0; idx < 4; ++idx)
      {
        if(fabs(tr->mat[idy][idx]) < eps)
	{
	  tr->mat[idy][idx] = 0.0;
	}
      }
    }
    if(transform)
    {
      outObj = WlzAffineTransformObj(inObj[0], tr, WLZ_INTERPOLATION_NEAREST,
                                     &errNum);
      if(outObj)
      {
        tr = NULL;
      }
    }
    else
    {
      WlzDomain dom;
      WlzValues val;

      dom.t = tr;
      val.core = NULL;
      outObj = WlzMakeMain(WLZ_AFFINE_TRANS, dom, val, NULL, NULL, &errNum);
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to %saffine transform object (%s).\n",
		     *argv, (transform)? "create ": "", errMsg);
    }
  }
  /* Write the output object. */
  if(ok)
  {
    char *fStr;
    FILE *fP;

    if(strcmp(outFileStr, "-") == 0)
    {
      fP = stdout;
      fStr = NULL;
    }
    else
    {
      fP = NULL;
      fStr = outFileStr;
    }
    errNum = WlzEffWriteObj(fP, fStr, outObj, outFmt);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	  "%s: Failed to write object to file %s (%s)\n",
	  *argv, outFileStr, errMsg);
    }
  }
  (void )WlzFreeObj(inObj[0]);
  (void )WlzFreeObj(inObj[1]);
  (void )WlzFreeObj(outObj);
  if(usage)
  {
    char *fmtStr = NULL;

    fmtStr = WlzEffFormatTable(2, 50, 10, NULL);
    (void )fprintf(
        stderr,
	"Usage: %s%s%s%s%s%s%s%s\n",
	*argv,
	" [-h] [-T]\n"
	"\t\t[-o<out file>] [-s<src fmt>] [-t<tgt fmt>] [-u<out fmt>]\n"
	"\t\t<source object> <target object>\n"
        "Computes the Woolz affine transform which makes the bounding box of\n"
	"the source object equal to that of the target object.\n"
	"Version: ",
	WlzVersion(),
	"\n"
	"  -h Help, prints this usage information.\n"
	"  -o Output file.\n"
	"  -s Source file format.\n"
	"  -t Target file format.\n"
	"  -u Output file format.\n"
	"  -T Transform the source object and write it to the output file\n"
	"     rather than the affine transform.\n"
        "The known file formats are:\n"
	"  Description                                       Extension\n"
	"  ***********                                       *********\n",
	fmtStr,
	"Simple example:\n  ",
	*argv,
	"-o out.wlz small.vtk big.stl\n"
	"Reads the source object from the file small.vtk and the target\n"
	"object from big.stl then computes the affine transform which scales\n"
	"the source objects bounding box to fit that of the target object.\n"
	"The output transform is written to the file out.wlz.\n");
  }
  return(!ok);
}
Example #29
0
int main(int	argc,
	 char	**argv)
{

  WlzObject	*obj;
  FILE		*inFile;
  char 		optList[] = "l:L:u:U:dhv";
  int		dither = 0,
  		option;
  WlzPixelV	max, min, Max, Min;
  WlzPixelV	gmin, gmax;
  int		getminFlg=1, getmaxFlg=1, verboseFlg=0;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  const char	*errMsg;
  int		objCount=0;
    
  /* read the argument list and check for an input file */
  opterr = 0;
  Max.type = Min.type = max.type = min.type = WLZ_GREY_DOUBLE;
  Max.v.dbv = 255.0;
  Min.v.dbv = 0.0;
  
  while( (option = getopt(argc, argv, optList)) != EOF ){
    switch( option ){
      case 'd':
	dither = 1;
	break;
      case 'l':
	min.v.dbv = atof(optarg);
	getminFlg = 0;
	break;
      case 'L':
	Min.v.dbv = atof(optarg);
	break;
      case 'u':
	max.v.dbv = atof(optarg);
	getmaxFlg = 0;
	break;
      case 'U':
	Max.v.dbv = atof(optarg);
	break;
      case 'v':
	verboseFlg = 1;
	break;
      case 'h':
      default:
	usage(argv[0]);
	return 1;
    }
  }

  inFile = stdin;
  if( optind < argc ){
    if( (inFile = fopen(*(argv+optind), "r")) == NULL ){
      fprintf(stderr, "%s: can't open file %s\n", argv[0], *(argv+optind));
      usage(argv[0]);
      return 1;
    }
  }

  /* read objects and threshold if possible */
  while(((obj = WlzAssignObject(WlzReadObj(inFile, NULL), NULL)) != NULL) &&
        (errNum == WLZ_ERR_NONE))
  {
    objCount++;
    switch( obj->type )
    {
    case WLZ_2D_DOMAINOBJ:
    case WLZ_3D_DOMAINOBJ:
      /* get the existing min and max grey values */
      if( (errNum = WlzGreyRange(obj, &gmin, &gmax)) == WLZ_ERR_NONE ){
	if( getminFlg ){
	  WlzValueConvertPixel(&min, gmin, WLZ_GREY_DOUBLE);
	}
	if( getmaxFlg ){
	  WlzValueConvertPixel(&max, gmax, WLZ_GREY_DOUBLE);
	}

	if( verboseFlg ){
	  fprintf(stderr,
		  "%s:\nconverting object %d with parameters:\n"
		  "\tSource (l, u) = (%f, %f)\n"
		  "\tDestination (L, U) = (%f, %f)\n",
		  argv[0], objCount, min.v.dbv, max.v.dbv,
		  Min.v.dbv, Max.v.dbv);
	}

	errNum = WlzGreySetRange(obj, min, max, Min, Max, dither);
	if( errNum == WLZ_ERR_NONE ){
	  errNum = WlzWriteObj(stdout, obj);
	}
      }
      if( errNum != WLZ_ERR_NONE ){
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write object (%s).\n",
		       argv[0], errMsg);
	return(errNum);
      }
      break;

    default:
      if((errNum = WlzWriteObj(stdout, obj)) != WLZ_ERR_NONE) {
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write object (%s).\n",
		       argv[0], errMsg);
	return(1);
      }
      break;
    }
    WlzFreeObj(obj);
  }

  return 0;
}
Example #30
0
int		main(int argc, char *argv[])
{
  int		option,
  		ok = 1,
  		nFiles = 0,
		usage = 0;
  WlzIVertex3	offset;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzObject	*tlObj = NULL;
  char		*tlFileStr;
  const char	*errMsg;
  static char	optList[] = "ht:x:y:z:",
		tlFileStrDef[] = "-";

  opterr = 0;
  tlFileStr = tlFileStrDef;
  WLZ_VTX_3_SET(offset, 0, 0, 0);
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 't':
        tlFileStr = optarg;
	break;
      case 'x':
        if(sscanf(optarg, "%d", &(offset.vtX)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'y':
        if(sscanf(optarg, "%d", &(offset.vtY)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'z':
        if(sscanf(optarg, "%d", &(offset.vtZ)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'h': /* FALLTHROUGH */
      default:
	usage = 1;
	break;
    }
  }
  if(usage == 0)
  {
    if((nFiles = argc - optind) <= 0)
    {
      usage = 1;
    }
  }
  ok = !usage;
  if(ok)
  {
    FILE	*fP = NULL;

    errNum = WLZ_ERR_READ_EOF;
    if(((fP = fopen(tlFileStr, "r+")) == NULL) ||
       ((tlObj= WlzAssignObject(WlzReadObj(fP, &errNum), NULL)) == NULL))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to open tiled object in file %s (%s).\n",
		     *argv, tlFileStr, errMsg);
    }
    if(fP)
    {
      (void )fclose(fP);
    }
  }
  if(ok)
  {
    if(tlObj == NULL)
    {
      errNum = WLZ_ERR_OBJECT_NULL;
    }
    else if(tlObj->domain.core == NULL)
    {
      errNum = WLZ_ERR_DOMAIN_NULL;
    }
    else if(tlObj->values.core == NULL)
    {
      errNum = WLZ_ERR_VALUES_NULL;
    }
    else if(WlzGreyTableIsTiled(tlObj->values.core->type) == 0)
    {
      errNum = WLZ_ERR_VALUES_TYPE;
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: invalid tiled object in file %s (%s).\n",
		     *argv, tlFileStr, errMsg);
    }
  }
  if(ok)
  {
    int	idx;

    for(idx = 0; idx < nFiles; ++idx)
    {
      char	*inFileStr;

      if((inFileStr = *(argv + optind + idx)) != NULL)
      {
        FILE	*fP = NULL;

        if((fP = (strcmp(inFileStr, "-")?
	         fopen(inFileStr, "r"): stdin)) == NULL)
        {
	  ok = 0;
	  (void )fprintf(stderr,
	                 "%s: Failed to open input file %s.\n",
			 argv[0], inFileStr);
	}
	if(ok)
	{
	  WlzObject	*obj1 = NULL,
	  		*obj2 = NULL,
			*inObj = NULL;

	  inObj = WlzAssignObject(WlzReadObj(fP, &errNum), NULL);
	  if(errNum == WLZ_ERR_NONE)
	  {
	    if(inObj == NULL)
	    {
	      errNum = WLZ_ERR_OBJECT_NULL;
	    }
	    else
	    {
	      switch(inObj->type)
	      {
	        case WLZ_2D_DOMAINOBJ:
		  if(tlObj->type == WLZ_3D_DOMAINOBJ)
		  {
		    obj1 = WlzConstruct3DObjFromObj(1, &inObj, 0,
						    1.0f, 1.0f, 1.0f,
						    &errNum);
		  }
		  else
		  {
		    obj1 = WlzAssignObject(inObj, NULL);
		  }
		  break;
	        case WLZ_3D_DOMAINOBJ:
		  obj1 = WlzAssignObject(inObj, NULL);
		  break;
	        default:
		  errNum = WLZ_ERR_OBJECT_TYPE;
		  break;
	      }
	    }
	  }
	  if(errNum == WLZ_ERR_NONE)
	  {
	    obj2 = WlzShiftObject(obj1, offset.vtX, offset.vtY, offset.vtZ,
	                          &errNum);
	  }
	  if(errNum == WLZ_ERR_NONE)
	  {
	    errNum = WlzCopyObjectGreyValues(tlObj, obj2);
	  }
          (void )WlzFreeObj(obj1);
          (void )WlzFreeObj(obj2);
          (void )WlzFreeObj(inObj);
	}
      }
    }
  }
  (void )WlzFreeObj(tlObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%s",
    *argv,
    " [-h] [-t <tiled object>] [-x #] [-y #] [-z #]\n"
    "                         [<input objects>]\n"
    "Sets the values in the tiled object using the values in the given\n"
    "input object(s).\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -h  Prints this usage information.\n"
    "  -t  The tiled object.\n"
    "  -x  Column offset.\n"
    "  -y  Line offset.\n"
    "  -z  Plane offset.\n");
  }
  return(!ok);
}