Esempio n. 1
0
void HGU_XmFileListWriteHeader(
  FILE	*fp)
{
  BibFileRecord		*bibfileRecord;
  time_t		tmpTime;
  char			*tmpS, tmpBuf[256];
  char  		*dateS = NULL;
  char  		*hostS = NULL;
  char  		*userS = NULL;
  static char		unknownS[] = "unknown";

  /* write some sort of identifier */
  bibfileRecord = 
    BibFileRecordMake("Ident", "0",
		      BibFileFieldMakeVa("Text",
					 "HGU_Xm Image File List",
					 "Version",	"1.0",
					 NULL));
  BibFileRecordWrite(fp, NULL, bibfileRecord);
  BibFileRecordFree(&bibfileRecord);

  /* now a comment with user, machine, date etc. */
  tmpS = getenv("USER");
  (void )sprintf(tmpBuf, "User: %s", tmpS?tmpS:unknownS);
  userS = AlcStrDup(tmpBuf);

  tmpTime = time(NULL);
  tmpS = ctime(&tmpTime);
  *(tmpS + strlen(tmpS) - 1) = '\0';
  (void )sprintf(tmpBuf, "Date: %s", tmpS?tmpS:unknownS);
  dateS = AlcStrDup(tmpBuf);

  tmpS = getenv("HOST");
  (void )sprintf(tmpBuf, "Host: %s", tmpS?tmpS:unknownS);
  hostS = AlcStrDup(tmpBuf);

  bibfileRecord = 
    BibFileRecordMake("Comment", "0",
		      BibFileFieldMakeVa("Text", userS,
					 "Text", dateS,
					 "Text", hostS,
					 NULL));
  BibFileRecordWrite(fp, NULL, bibfileRecord);
  BibFileRecordFree(&bibfileRecord);
  AlcFree(userS);
  AlcFree(dateS);
  AlcFree(hostS);

  return;
}
Esempio n. 2
0
const char	*WlzGetPropName(WlzObject *obj)
{
  WlzErrorNum errNum = WLZ_ERR_NONE;
  WlzProperty prop;
  const char *name = NULL;
  char *dst = NULL;

  if(obj->plist)
  {
    prop = WlzGetProperty(obj->plist->list, WLZ_PROPERTY_NAME, &errNum);
    if(prop.core && (errNum == WLZ_ERR_NONE))
    {
      switch(prop.core->type)
      {
	case WLZ_PROPERTY_NAME:
	  dst = prop.name->name;
	  break;
	case WLZ_PROPERTY_GREY:
	  dst = prop.greyV->name;
	  break;
	default:
	  errNum = WLZ_ERR_PROPERTY_TYPE;
	  break;
      }
    }
  }
  name = AlcStrDup((const char *) dst);
  return(name);
}
Esempio n. 3
0
/*!
* \return	New registration section.
* \ingroup	Reconstruct
* \brief	Makes a registration section using the given member values.
* \param	index			Section index.
* \param	iterations		Number of iterations to find
*                                       section transform.
* \param	correlation		Section correlation value.
* \param	imageFile		Image file path, this is duplicated
*					so that the original may be freed
*					The image file path must not be NULL.
* \param	transform		Section transform, if NULL an identity
* 					transform is created.
* \param	obj			Woolz object corresponding to the given
* 					image file. This may be NULL without
* 					causing the object to be read from the
* 					associated file.
*/
RecSection	*RecSecMake(int index, int iterations, double correlation,
			    char *imageFile,
			    WlzAffineTransform *transform, WlzObject *obj)
{
  RecSection	*sec = NULL;
  char		*newImageFile = NULL;
  WlzAffineTransform	*newTransform = NULL;
  WlzErrorNum	wlzErr = WLZ_ERR_NONE;

  REC_DBG((REC_DBG_SEC|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecSecMake FE %d %d %g 0x%lx 0x%lx 0x%lx\n",
	   index, iterations, correlation,
	   (unsigned long )imageFile, (unsigned long )transform,
	   (unsigned long )obj));
  if(imageFile)
  {
    newImageFile = AlcStrDup(imageFile);
  }
  if(newImageFile && (transform == NULL))
  {
    newTransform = WlzAffineTransformFromPrimVal(WLZ_TRANSFORM_2D_AFFINE,
    					         0.0, 0.0, 0.0,
					         1.0, 0.0, 0.0,
					         0.0, 0.0, 0.0, 0, &wlzErr);
  }
  if(newImageFile && (newTransform || transform) && (wlzErr == WLZ_ERR_NONE))
  {
    sec = (RecSection *)AlcMalloc(sizeof(RecSection));
  }
  if(sec == NULL)
  {
    if(newImageFile)
    {
      AlcFree(newImageFile);
    }
    if(newTransform)
    {
      WlzFreeAffineTransform(newTransform);
    }
  }
  else
  {
    sec->linkcount = 0;
    sec->index = index;
    sec->iterations = iterations;
    sec->correl = correlation;
    sec->obj = WlzAssignObject(obj, NULL);
    sec->imageFile = newImageFile;
    sec->transform = WlzAssignAffineTransform(transform? transform:
    							 newTransform, NULL);
    sec->transObj = NULL;
    sec->cumTransform = NULL;
    sec->cumTransObj = NULL;
  }
  REC_DBG((REC_DBG_SEC|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecSecMake FX 0x%lx\n",
	   (unsigned long )sec));
  return(sec);
}
Esempio n. 4
0
/*!
* \return	Error code.
* \ingroup	Reconstruct
* \brief	Reads section image object from file.
* \param	sec			Section with obj to be read.
* \param	eMsg			Destination pointer for messages.
*/
RecError	RecFileSecObjRead(RecSection *sec, char **eMsg)
{
  RecError	errFlag = REC_ERR_NONE;
  char		errBuf[256];
  FILE		*fP = NULL;
  WlzObject	*obj;
  WlzErrorNum	wlzErr = WLZ_ERR_NONE;

  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecFileSecObjRead FE 0x%lx 0x%lx\n",
	   (unsigned long )sec, (unsigned long )eMsg));
  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_1),
  	  ("RecFileSecObjRead 01 0x%lx  0x%lx %d\n",
	   (unsigned long )sec,
	   (sec)? ((unsigned long )(sec->obj)): (unsigned long)0,
	   (sec)? ((sec->obj)? (sec->obj->linkcount): -999): -999));
  if((sec->obj = WlzAssignObject(sec->obj, NULL)) == NULL)
  {
    if((sec->imageFile == NULL) || (strlen(sec->imageFile) == 0))
    {
      errFlag = REC_ERR_READ;
    }
    else if(RecSecIsEmpty(sec))
    {
      obj = WlzAssignObject(WlzMakeEmpty(&wlzErr), NULL);
      errFlag = RecErrorFromWlz(wlzErr);
    }
    else
    {
      if(((fP = fopen(sec->imageFile, "r")) == NULL) ||
	 ((obj = WlzAssignObject(WlzReadObj(fP, &wlzErr), NULL)) == NULL))
      {
	errFlag = (wlzErr == WLZ_ERR_NONE)? REC_ERR_READ:
				            RecErrorFromWlz(wlzErr);
	(void )sprintf(errBuf, "failed to open section image file %s.",
		       sec->imageFile);
      }
      if(fP)
      {
	(void )fclose(fP);
      }
    }
    if(errFlag == REC_ERR_NONE)
    {
      sec->obj = obj;
    }
    else if(*eMsg == NULL)
    {
      *eMsg = AlcStrDup(errBuf);
    }
  }
  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecFileSecObjRead FX %d\n",
	   errFlag));
  return(errFlag);
}
Esempio n. 5
0
WlzErrorNum HGU_XmFileListAddFile(
  AlcDLPList	*fileList,
  String	file,
  WlzEffFormat	format)
{
  HGU_XmFileListCallbackStruct	*cbs;
  AlcDLPItem	*item;
  WlzErrorNum	errNum=WLZ_ERR_NONE;
  AlcErrno	alcErr;

  /* check inputs */
  if((fileList == NULL) || (file == NULL)){
    errNum = WLZ_ERR_PARAM_NULL;
  }

  /* create new item and add to head of the list */
  if( errNum == WLZ_ERR_NONE ){
    /* check if already in the list, in which case bring
       it to the top */
    item = fileList->head;
    while( item ){
      cbs = (HGU_XmFileListCallbackStruct *) item->entry;
      if( !strcmp(file, cbs->file) ){
	break;
      }

      if( item->next == fileList->head ){
	item = NULL;
      }
      else {
	item = item->next;
      }
    }

    /* move or create new list item */
    if( item ){
      AlcDLPItemUnlink(fileList, item, 0, &alcErr);
      AlcDLPItemInsert(fileList, NULL, item);
    }
    else {
      cbs = (HGU_XmFileListCallbackStruct *)
	AlcMalloc(sizeof(HGU_XmFileListCallbackStruct));
      cbs->file = AlcStrDup(file);
      cbs->format = format;
      AlcDLPListEntryInsert(fileList, NULL, (void *) cbs,
			    HGU_XmFileListItemFree);
    }
  }

  while( AlcDLPListCount(fileList, &alcErr) > HGU_XMFILELIST_MAXNUMITEMS ){
    AlcDLPItemUnlink( fileList, fileList->head->prev, 1, &alcErr);
  }

  return errNum;
}
Esempio n. 6
0
char *getNextName(
  FILE	*inFile)
{
  char	*name=NULL;
  char	*tag;
  char	c;
  char	buffer[128];
  int	i;

  /* check file pointer */
  if( inFile == NULL ){
    return NULL;
  }

  /* search for name tag */
  while((tag = nextStartTag(inFile)) != NULL){
    if(strcmp(tag, "name") == 0){
      break;
    }
  }

  /* read until end tag */
  if( tag ){
    i = 0;
    while( (c = fgetc(inFile)) != '<' ){
      if( c == EOF ){
	break;
      }
      buffer[i++] = c;
    }
    buffer[i] = '\0';
    while( (c = fgetc(inFile)) != '>' ){
      if( c == EOF ){
	break;
      }
    }

    /* extract name */
    name = AlcStrDup(buffer);
  }

  return name;
}
Esempio n. 7
0
/*!
* \return	Duplicated section, NULL on error.
* \ingroup	Reconstruct
* \brief	Duplicates the given section.
* \param	sec			Section to be duplicated.
*/
RecSection	*RecSecDup(RecSection *sec)
{
  RecSection	*newSec = NULL;
  WlzErrorNum	wlzErr = WLZ_ERR_NONE;

  REC_DBG((REC_DBG_SEC|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecSecDup FE 0x%lx\n",
	   (unsigned long )sec));
  if(sec)
  {
    if(((newSec = (RecSection *)AlcCalloc(1, sizeof(RecSection))) != NULL) &&
       sec->imageFile &&
       ((newSec->imageFile = AlcStrDup(sec->imageFile)) != NULL) &&
       sec->transform &&
       ((newSec->transform = WlzAssignAffineTransform(
			 WlzAffineTransformFromMatrix(sec->transform->type,
       					      sec->transform->mat, &wlzErr),
					      NULL)) != NULL) &&
       (wlzErr == WLZ_ERR_NONE))
    {
      newSec->index = sec->index;
      newSec->iterations = sec->iterations;
      newSec->correl = sec->correl;
    }
    else
    {
      if(newSec)
      {
        if(newSec->imageFile)
	{
	  AlcFree(newSec->imageFile);
	}
        AlcFree(newSec);
        newSec = NULL;
      }
    }
  }
  REC_DBG((REC_DBG_SEC|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecSecDup FX 0x%lx\n",
	   (unsigned long )newSec));
  return(newSec);
}
Esempio n. 8
0
/*!
* \return	Property name string.
* \ingroup	LibWlzBnd
* \brief	Get's an object's property name string.
* \param	obj			Given object.
* \param	dstErr			Destination error pointer, may be NULL.
*/
const char	*WlzGetPropName(WlzObject *obj, WlzErrorNum *dstErr)
{
  const char *name = NULL;
  char *dst = NULL;
  WlzErrorNum errNum = WLZ_ERR_NONE;

  if(obj == NULL)
  {
    errNum = WLZ_ERR_OBJECT_NULL;
  }
  else if(obj->plist)
  {
    WlzProperty prop;

    prop = WlzGetProperty(obj->plist->list, WLZ_PROPERTY_NAME, &errNum);
    if((errNum == WLZ_ERR_NONE) && prop.core)
    {
      switch(prop.core->type)
      {
	case WLZ_PROPERTY_NAME:
	  dst = prop.name->name;
	  break;
	case WLZ_PROPERTY_GREY:
	  dst = prop.greyV->name;
	  break;
	default:
	  errNum = WLZ_ERR_PROPERTY_TYPE;
	  break;
      }
      name = AlcStrDup((const char *)dst);
    }
  }
  if(dstErr)
  {
    *dstErr = errNum;
  }
  return(name);
}
Esempio n. 9
0
char *nextStartTag(
  FILE	*inFile)
{
  char 	*tag=NULL;
  char 	buf[256];
  char	c;
  int	i;

  while( (c = fgetc(inFile)) != EOF ){
    if( c == '<' ){
      i = 0;
      c = fgetc(inFile);
      if( c == EOF ){
	break;
      }
      else if( c != '/' ){
	buf[i++] = c;
	while( (c = fgetc(inFile)) != '>' ){
	  if( c == EOF ){
	    break;
	  }
	  buf[i++] = c;
	}
	if( c == '>' ){
	  buf[i] = '\0';
	  break;
	}
      }
    }
  }

  if( i ){
    tag = AlcStrDup(buf);
  }
  return tag;
}
Esempio n. 10
0
/*!
* \return	Woolz error code.
* \brief	Outputs a section parameters file with the reference and source
* 		file object file names, the 3D view transform and the
*		tie-points.
* \param	fP			Output section parameters file.
* \param	view			3D view transform.
* \param	refObjFileStr		Reference object file name.
* \param	refObjFileType		Reference object file type.
* \param	srcObjFileStr		Source object file name.
* \param	srcObjFileType		Source object file type.
* \param	nMatch			Number of tie-points.
* \param	tieRP			Reference object tie-points.
* \param	tieSP			Source object tie-points.
* \param	refObj2DOrg		Origin of the 2D reference object to
*					be subtracted if non NULL.
*/
static WlzErrorNum WlzMatchICPPlaneWriteSecParam(FILE *fP,
			      WlzThreeDViewStruct *view,
			      char *refObjFileStr, WlzEffFormat refObjFileType,
			      char *srcObjFileStr, WlzEffFormat srcObjFileType,
			      int nMatch,
			      WlzDVertex2 *tieRP, WlzDVertex2 *tieSP,
			      WlzDVertex2 *refObj2DOrg)
{
  int		idx;
  char		*tmpS,
		*dateS = NULL,
		*hostS = NULL,
		*userS = NULL,
		*refFileS = NULL,
		*srcFileS = NULL,
		*sgnlFileS = NULL;
  time_t	tmpTime;
  BibFileRecord	*bibRec;
  WlzDVertex3	refVx,
  		srcVx;
  char		tmpBufS[256];
  static char	unknownS[] = "unknown";
  WlzErrorNum	errNum = WLZ_ERR_NONE;

  if((bibRec = BibFileRecordMake("Ident", "0",
  			     BibFileFieldMakeVa("Text",
					"MAPaint 2D warp input parameters",
					"Version", "1",
					NULL))) == NULL)
  {
    errNum = WLZ_ERR_MEM_ALLOC;
  }
  /* Comment with user, machine, date etc. */
  if(errNum == WLZ_ERR_NONE)
  {
    if(BibFileRecordWrite(fP, NULL, bibRec) != BIBFILE_ER_NONE)
    {
      errNum = WLZ_ERR_WRITE_EOF;
    }
    BibFileRecordFree(&bibRec);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    tmpS = getenv("USER");
    (void )sprintf(tmpBufS, "User: %s", tmpS? tmpS: unknownS);
    if((userS = AlcStrDup(tmpBufS)) == NULL)
    {
      errNum = WLZ_ERR_MEM_ALLOC;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    tmpTime = time(NULL);
    tmpS = ctime(&tmpTime);
    *(tmpS + strlen(tmpS) - 1) = '\0';
    (void )sprintf(tmpBufS, "Date: %s", tmpS? tmpS: unknownS);
    if((dateS = AlcStrDup(tmpBufS)) == NULL)
    {
      errNum = WLZ_ERR_MEM_ALLOC;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    tmpS = getenv("HOST");
    (void )sprintf(tmpBufS, "Host: %s", tmpS? tmpS: unknownS);
    hostS = AlcStrDup(tmpBufS);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    (void )sprintf(tmpBufS, "RefFile: %s", refObjFileStr);
    refFileS = AlcStrDup(tmpBufS);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    (void )sprintf(tmpBufS, "SrcFile: %s", srcObjFileStr);
    srcFileS = AlcStrDup(tmpBufS);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    (void )sprintf(tmpBufS, "SignalFile: %s", unknownS);
    sgnlFileS = AlcStrDup(tmpBufS);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    if((bibRec = BibFileRecordMake("Comment", "0",
			     BibFileFieldMakeVa("Text", userS,
					        "Text", dateS,
					        "Text", hostS,
					        "Text", refFileS,
					        "Text", srcFileS,
					        "Text", sgnlFileS,
					        NULL))) == NULL)
    {
      errNum = WLZ_ERR_MEM_ALLOC;
    }
  }
  AlcFree(dateS);
  AlcFree(hostS);
  AlcFree(userS);
  AlcFree(refFileS);
  AlcFree(srcFileS);
  AlcFree(sgnlFileS);
  if(errNum == WLZ_ERR_NONE)
  {
    if(BibFileRecordWrite(fP, NULL, bibRec) != BIBFILE_ER_NONE)
    {
      errNum = WLZ_ERR_WRITE_INCOMPLETE;
    }
    BibFileRecordFree(&bibRec);
  }
  /* Source file string. */
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzEffBibWriteFileRecord(fP, "MAPaintWarpInputSourceFile",
				      srcObjFileStr, srcObjFileType);
  }
  /* Reference file string. */
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzEffBibWriteFileRecord(fP, "MAPaintWarpInputReferenceFile",
				      refObjFileStr, refObjFileType);
  }
  /* View parameters. */
  if(errNum == WLZ_ERR_NONE)
  {
    WlzEffBibWrite3DSectionViewParamsRecord(fP, "Wlz3DSectionViewParams",
					    view);
    
  }
  /* Tie points. */
  idx = 0;
  refVx.vtZ = 0.0;
  srcVx.vtZ = 0.0;
  while((errNum == WLZ_ERR_NONE) && (idx < nMatch))
  {
    refVx.vtX = (tieRP + idx)->vtX - view->fixed.vtX;
    refVx.vtY = (tieRP + idx)->vtY - view->fixed.vtY;
    if(refObj2DOrg)
    {
      refVx.vtX -= refObj2DOrg->vtX;
      refVx.vtY -= refObj2DOrg->vtY;
    }
    srcVx.vtX = (tieSP + idx)->vtX;
    srcVx.vtY = (tieSP + idx)->vtY;
    if(errNum == WLZ_ERR_NONE)
    {
      errNum = WlzEffBibWriteTiePointVtxsRecord(fP, "WlzTiePointVtxs", idx,
	  refVx, srcVx, 0);
    }
    ++idx;
  }
  return(errNum);
}
Esempio n. 11
0
/*!
* \return	Error code.
* \ingroup	Reconstruct
* \brief	Given a destination directory and file body and a 3D
*		Woolz object, the 3D object is and exploded into a series of 2D
*		section files (in the destination directory) each with a name
*		formed from the given file body and the source plane index. A
*		section list is also created in the directory using the given
*		file body together with the  '.bib' file extension.
* \param	dstDirStr		Destination directory.
* \param	dstBodyStr		Destination file body.
* \param	srcObj			Source 3D woolz object.
* \param	srcFName		Source file name, may be NULL.
* \param	srcFFormat		Source file format, may be
*					WLZEFF_FORMAT_NONE.
* \param	eMsg			Destinagtion pointer for messages.
*/
RecError	RecExplode3DObjToFile(char *dstDirStr, char *dstBodyStr,
				      WlzObject *srcObj, char *srcFName,
				      WlzEffFormat srcFFormat, char **eMsg)
{
  int		objIdx,
		planeIdx,
  		objVecCount,
		fileStrSpace;
  char		*fileStr = NULL,
  		*fileTemplateStr = NULL;
  FILE		*fP;
  WlzObject	**objVec = NULL;
  RecSectionList *secList = NULL;
  RecError	errFlag = REC_ERR_NONE;
  struct stat	statBuf;
  const char 	*errDirAccessStr = "Failed to access directory",
		*errDirCreateStr = "Failed to create directory",
  		*errExplodeStr = "Failed to explode 3D object",
  		*errWriteWoolzStr = "Failed to write 2D section file",
		*errListAppendStr = "Failed to build section list",
		*errWriteListStr = "Failed to write section list to file";
  const char	*errStr = NULL;

  REC_DBG((REC_DBG_3D|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecExplode3DObjToFile FE 0x%lx 0x%lx 0x%lx 0x%lx %d 0x%lx\n",
	   (unsigned long )dstDirStr, (unsigned long )dstBodyStr,
	   (unsigned long )srcObj, (unsigned long )srcFName,
	   srcFFormat, (unsigned long )eMsg));
  if((dstDirStr == NULL) || (strlen(dstDirStr) == 0) ||
     (dstBodyStr == NULL) || (strlen(dstBodyStr) == 0) || 
     (srcObj == NULL) || (srcObj->type != WLZ_3D_DOMAINOBJ) ||
     (srcObj->domain.core == NULL))
  {
    errFlag = REC_ERR_FUNC;
  }
  if(errFlag == REC_ERR_NONE)       /* Check for/create destination directory */
  {
    if(stat(dstDirStr, &statBuf) == 0)			 /* Directory exists */
    {
#ifdef LINUX2
      if((statBuf.st_mode & (__S_IFDIR|__S_IREAD|__S_IWRITE|__S_IEXEC)) == 0)
#else /* LINUX2 */
      if((statBuf.st_mode & (S_IFDIR | S_IRWXU)) == 0)
#endif /* LINUX2 */
      {
	errStr = errDirAccessStr;
	errFlag = REC_ERR_WRITE;         /* Can't read/write/search directory */
      }
    }
    else
    {
      if(mkdir(dstDirStr, S_IRWXU))
      {
	errStr = errDirCreateStr;
	errFlag = REC_ERR_WRITE;
      }
      
    }
    REC_DBG((REC_DBG_3D|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	    ("RecExplode3DObjToFile 01 %d\n",
	     (int )errFlag));
  }
  if(errFlag == REC_ERR_NONE) 	  	      /* Explode the 3D Woolz object */
  {
    if((errFlag = RecErrorFromWlz(
    		  WlzExplode3D(&objVecCount, &objVec, srcObj))) != REC_ERR_NONE)
    {
      errStr = errExplodeStr;
    }
    REC_DBG((REC_DBG_3D|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	    ("RecExplode3DObjToFile 02 %d\n",
	     (int )errFlag));
  }
  if(errFlag == REC_ERR_NONE)                       /* Create a section list */
  {
    if(((secList = RecSecNewSectionList(NULL)) == NULL) ||
       ((secList->list = HGUDlpListCreate(NULL)) == NULL))
    {
      errFlag = REC_ERR_MALLOC;
    }
    else
    {
      secList->reconstruction.fileName = srcFName;
      secList->reconstruction.fileFormat = srcFFormat;
    }
    REC_DBG((REC_DBG_3D|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	    ("RecExplode3DObjToFile 03 %d\n",
	     (int )errFlag));
  }
  if(errFlag == REC_ERR_NONE)     /* Write 2D files, build/write section list */
  {
    fP = NULL;
    objIdx = 0;
    planeIdx = srcObj->domain.p->plane1;
    fileStrSpace = (int )strlen(dstDirStr) + (int )strlen(dstBodyStr) + 64;
    if(((fileStr = AlcMalloc(sizeof(char) * fileStrSpace)) == NULL) ||
       ((fileTemplateStr = AlcMalloc(sizeof(char) * fileStrSpace)) == NULL))
    {
      errFlag = REC_ERR_MALLOC;
    }
    else
    {
      (void )sprintf(fileTemplateStr, "%s/%s", dstDirStr, dstBodyStr);
    }
    while((errFlag == REC_ERR_NONE) && (objIdx < objVecCount))
    {
      (void )sprintf(fileStr, "%s_%06d.wlz", fileTemplateStr, planeIdx);
      if((fP = fopen(fileStr, "w")) == NULL)
      {
	errStr = errWriteWoolzStr;
        errFlag = REC_ERR_WRITE;
      }
      if(errFlag == REC_ERR_NONE)
      {
	if((errFlag = RecErrorFromWlz(
		      WlzWriteObj(fP, *(objVec + objIdx)))) != REC_ERR_NONE)
	{
	  errStr = errWriteWoolzStr;
	}
        fclose(fP);
      }
      if(errFlag == REC_ERR_NONE)
      {
        errFlag = RecSecAppendListFromFiles(secList->list, NULL, &fileStr, 1,
					    planeIdx, 1);
        if(errFlag != REC_ERR_NONE)
	{
	  errStr = errListAppendStr;
	}
      }
      if(errFlag == REC_ERR_NONE)
      {
	++objIdx;
	++planeIdx;
      }
    }
    if(objVec && (objVecCount > 0))
    {
      for(objIdx = 0; objIdx < objVecCount; ++objIdx)
      {
	if(*(objVec + objIdx))
	{
	  (void )WlzFreeObj(*(objVec + objIdx));
	}
      }
      free(objVec);
    }
    if(errFlag == REC_ERR_NONE)
    {
      (void )sprintf(fileStr, "%s.bib", fileTemplateStr);
      if((fP = fopen(fileStr, "w")) == NULL)
      {
        errStr = errWriteListStr;
	errFlag = REC_ERR_WRITE;
      }
      else
      {
	errFlag = RecFileSecListWrite(fP, secList, objVecCount, eMsg);
	fclose(fP);
      }
    }
    if(fileStr)
    {
      free(fileStr);
    }
    if(fileTemplateStr)
    {
      free(fileTemplateStr);
    }
    if(secList)
    {
      HGUDlpListDestroy(secList->list);
      AlcFree(secList);
    }
    REC_DBG((REC_DBG_3D|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	    ("RecExplode3DObjToFile 04 %d\n",
	     (int )errFlag));
  }
  if((errFlag != REC_ERR_NONE) && eMsg && (*eMsg == NULL) && (errStr != NULL))
  {
    *eMsg = AlcStrDup(errStr);
  }
  REC_DBG((REC_DBG_3D|REC_DBG_LVL_FN|REC_DBG_LVL_1),
  	  ("RecExplode3DObjToFile FX %d\n",
	   (int )errFlag));
  return(errFlag);
}
Esempio n. 12
0
/*!
* \return	Non zero if registration fails.
* \ingroup	Reconstruct
* \brief	Performs the automatic registration of serial sections.
* \param	rCtrl			The registration control data
* 					structure.
* \param	ppCtrl			Pre-processing control data
*					structure.
* \param	secList			Section list.
* \param	cancelFlag		Cancel if flag pointed to is non-zero.
* \param	secFn			application supplied section update
*					function. This function is responsible
*					for replacing the section in the list,
*					it may also display it, etc, ....
* \param	secData			Application supplied data for section
* 					update function.
* \param	workFn			Application supplied work function.
* \param	workData		Application supplied data for the
*					work function.
* \param	eMsg			Pointer for error message strings.
*/
RecError	RecAuto(RecControl *rCtrl, RecPPControl *ppCtrl,
			HGUDlpList *secList, int *cancelFlag,
			RecSecUpdateFunction secFn, void *secData,
			RecWorkFunction workFn, void *workData,
			char **eMsg)
{
  RecSection	*oSec0,
		*oSec1,
		*nSec0,
		*nSec1;
  HGUDlpListItem *item;
  RecState	rState;
  static char	errMsgInvalidListStr[] =
	     		"Section list or the registration limits are invalid.",
	     	errMsgMallocStr[] = "Not enough memory available.";
  RecError	errFlag = REC_ERR_NONE;

  REC_DBG((REC_DBG_AUTO|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecAuto FE 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
	   (unsigned long )rCtrl, (unsigned long )ppCtrl,
	   (unsigned long )secList, (unsigned long )cancelFlag,
	   (unsigned long )secFn, (unsigned long )secData,
	   (unsigned long )workFn, (unsigned long )workData,
	   (unsigned long )eMsg));
  if((rCtrl == NULL) || (ppCtrl == NULL) || (secList == NULL))
  {
    errFlag = REC_ERR_FUNC;
  }
  if(errFlag == REC_ERR_NONE)
  {
    if(((item = RecSecFindItemIndex(secList, NULL, rCtrl->firstIdx,
     				    HGU_DLPLIST_DIR_TOTAIL)) == NULL) ||
       ((oSec0 = (RecSection *)HGUDlpListEntryGet(secList, item)) == NULL))
    {
      errFlag = REC_ERR_LIST;
    }
  }
  if(errFlag == REC_ERR_NONE)
  {
    if(RecSecIsEmpty(oSec0))
    {
      if((oSec0 = RecSecNext(secList, item, &item, 1)) == NULL)
      {
        errFlag = REC_ERR_LIST;
      }
    }
  }
  if(errFlag == REC_ERR_NONE)
  {
    if((oSec1 = RecSecNext(secList, item, &item, 1)) == NULL)
    {
      errFlag = REC_ERR_LIST;
    }
  }
  if(errFlag == REC_ERR_NONE)
  {
    if((oSec0->index != rCtrl->firstIdx) ||
       (oSec1->index < rCtrl->firstIdx) ||
       (oSec1->index > rCtrl->lastIdx))
    {
      errFlag = REC_ERR_LIST;
    }
  }
  if(errFlag == REC_ERR_NONE)
  {
    if(((nSec0 = RecSecDup(oSec0)) == NULL) ||
       ((nSec1 = RecSecDup(oSec1)) == NULL))
    {
      errFlag = REC_ERR_MALLOC;
    }
  }
  if(errFlag == REC_ERR_NONE)
  {
    errFlag = RecFileSecObjRead(nSec0, eMsg);
  }
  while((errFlag == REC_ERR_NONE) && (*cancelFlag == 0) && (nSec1 != NULL))
  {
    if(secFn && nSec0)
    {
      (*secFn)(nSec0, secData);	/* Replaces oSec0 with copy of nSec0 in list */
    }
    errFlag = RecFileSecObjRead(nSec1, eMsg);
    if(errFlag == REC_ERR_NONE)
    {
      errFlag = RecRegisterPair(&(nSec1->transform),
				&(nSec1->correl), &(nSec1->iterations),
      				rCtrl, ppCtrl,
				nSec0->obj, nSec1->obj,
      				workFn, workData, eMsg);
    }
    if(errFlag == REC_ERR_NONE)
    {
      RecSecFree(nSec0);
      nSec0 = nSec1;
      nSec1 = NULL;
      if(nSec0->index < rCtrl->lastIdx)
      {
        if((oSec1 = RecSecNext(secList, item, &item, 1)) == NULL)
	{
	  errFlag = REC_ERR_LIST;
	}
	else if(oSec1->index <= rCtrl->lastIdx)
	{
	  if((nSec1 = RecSecDup(oSec1)) == NULL)
	  {
	    errFlag = REC_ERR_MALLOC;
	  }
	}
      }
    }
  }
  if((errFlag == REC_ERR_NONE) && secFn && nSec0)
  {
    (*secFn)(nSec0, secData);   /* Replaces oSec0 with copy of nSec0 in list */
  }
  if(nSec0)
  {
    RecSecFree(nSec0);
  }
  if(nSec1)
  {
    RecSecFree(nSec1);
  }
  if(*cancelFlag && (errFlag == REC_ERR_NONE))
  {
    errFlag = REC_ERR_CANCEL;
  }
  if((errFlag != REC_ERR_NONE) && (*eMsg == NULL))
  {
    switch(errFlag)
    {
      case REC_ERR_MALLOC:
        *eMsg = AlcStrDup(errMsgMallocStr);
        break;
      case REC_ERR_LIST:
        *eMsg = AlcStrDup(errMsgInvalidListStr);
        break;
      default:
        break;
    }
  }
  if(workFn && workData)
  {
    rState.approach = 0;
    rState.iteration = 0;
    rState.lastMethod = REC_MTHD_NONE;
    rState.transform = NULL;
    rState.correl = 0.0;
    rState.errFlag = errFlag;
    (*workFn)(&rState, workData);
  }
  REC_DBG((REC_DBG_AUTO|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecAuto FX %d\n",
	   errFlag));
  return(errFlag);
}
/*!
* - Function:   WlzEffWriteMeshTransform3DWithoutDisplacementVTK
* - Returns:    none 
* - Purpose:    output the orginal mesh.	
* - Parameters:	
*     -# *fp:               pointer pointing to a specific file.
*     -#  wmt3D:            mesh transform.
* - Author:       J. Rao, R. Baldock and B. Hill
*/
static WlzErrorNum WriteBibFile(FILE *outFile, char *outFileStr,  char *inFileStrw, char *inFileStrSec,WlzThreeDViewStruct  *wlzViewStr)
{
   WlzErrorNum	    errNum = WLZ_ERR_NONE;
   BibFileRecord	*bibfileRecord;
   /* BibFileError      bibFileErr; */
   /* char             *errMsg; */
   char             *tmpS,
                    *dateS = NULL,
		    *hostS = NULL,
                    *userS = NULL,
                    *refFileS = NULL,
     *srcFileS; /*,     sgnlFileS; */
   time_t		tmpTime;   
   char			tmpBuf[256];
   static char		unknownS[] = "unknown";
   /* WlzBasisFnType     bt = WLZ_BASISFN_MQ; */
   WlzFnType          bt = WLZ_FN_BASIS_3DMQ;

   WlzTransformType   at = WLZ_TRANSFORM_2D_NOSHEAR;
   WlzMeshGenMethod     wmgmd  = WLZ_MESH_GENMETHOD_GRADIENT;
   WlzEffFormat    weft =  WLZEFF_FORMAT_WLZ;
   /* WlzObjectType    wtp =    WLZ_2D_DOMAINOBJ; */
   if((outFile = fopen(outFileStr, "w")) == NULL )
   {
       printf("cannot open the output bib file.\n");
       exit(1);
   }
   /* write some sort of identifier */
      bibfileRecord = 
	BibFileRecordMake("Ident", "0",
			  BibFileFieldMakeVa("Text",
					     "MAPaint 2D warp input parameters",
					     "Version",	"1",
					     NULL));
      BibFileRecordWrite(outFile, NULL, bibfileRecord);
      BibFileRecordFree(&bibfileRecord);


   /* now a comment with user, machine, date etc. */
      tmpS = getenv("USER");
      (void )sprintf(tmpBuf, "User: %s", tmpS?tmpS:unknownS);
      userS = AlcStrDup(tmpBuf);

      tmpTime = time(NULL);
      tmpS = ctime(&tmpTime);
      *(tmpS + strlen(tmpS) - 1) = '\0';
      (void )sprintf(tmpBuf, "Date: %s", tmpS?tmpS:unknownS);
      dateS = AlcStrDup(tmpBuf);

      tmpS = getenv("HOST");
      (void )sprintf(tmpBuf, "Host: %s", tmpS?tmpS:unknownS);
      hostS = AlcStrDup(tmpBuf);

      (void )sprintf(tmpBuf, "RefFile: %s", "WlzFileName");
      refFileS = AlcStrDup(tmpBuf);

      (void )sprintf(tmpBuf, "SrcFile: %s",outFileStr );
      srcFileS = AlcStrDup(tmpBuf);

      bibfileRecord = 
	BibFileRecordMake("Comment", "0",
			  BibFileFieldMakeVa("Text", userS,
					     "Text", dateS,
					     "Text", hostS,
					     "Text", refFileS,
					     "Text", srcFileS,
					     "Text", "no need",
					     NULL));
      BibFileRecordWrite(outFile, NULL, bibfileRecord);
      BibFileRecordFree(&bibfileRecord);

       /* if write a file record for the reference file */
      if( inFileStrw ){
	WlzEffBibWriteFileRecord(outFile, "MAPaintReferenceFile",
			 inFileStrw,
			  weft);
      }

      /* if defined write a file record for the source */
      if( inFileStrSec ){
	WlzEffBibWriteFileRecord(outFile, "MAPaintWarpInputSourceFile",
			  inFileStrSec,
			  weft);
      }

      /* write the section data */
      if( WlzEffBibWrite3DSectionViewParamsRecord(outFile, "Wlz3DSectionViewParams", 
					      wlzViewStr) != WLZ_ERR_NONE ){
	printf(
			"Save Warp Parameters:\n"
			"    Error in writing the bibfile\n"
			"    Please check disk space or quotas\n"
			"    Section parameters not saved"
			);
      }

      /* write the warp transform parameters */
       if( WlzEffBibWriteWarpTransformParamsRecord(outFile, "WlzWarpTransformParams",
					      bt,
					      at,
					      wmgmd,
					      20,
					      40)
     	 != WLZ_ERR_NONE ){
     	printf(
			"Save Warp Parameters:\n"
			"    Error in writing the bibfile\n"
			"    Please check disk space or quotas\n"
			"    Section parameters not saved"
			);
      }

    /* write the warp transform parameters */
   /*
   if( WlzEffBibWrite3DSectionViewParamsRecord(outFile, outFileStr, 
					      wlzViewStr) != WLZ_ERR_NONE ) {
		printf("can not output:");	
		exit(0);
					      
   }
   */
   fclose(outFile);
   outFile = NULL;
   return errNum;
}
Esempio n. 14
0
/* options_menu initialisation procedure */
void options_menu_init(
Widget	topl)
{
    Widget	widget;
    String	filestr, dirstr;
    char	lineBuf[1024], fileBuf[512], dateBuf[64];
    char	authorBuf[64], stageBuf[16];
    MAPaintExpressMapStatus	status;
    MAPaintExpressMapQuality	quality;
    int		bibfileStartIndex=0;

    /* create the tool controls dialog */
    tool_controls_dialog = create_tool_controls_dialog( topl );
    
    /* create the surgery controls dialog */
    surgeryDialog = createDomainSurgeryDialog( topl );
    XtManageChild( surgeryDialog );
    HGU_XmSaveRestoreAddWidget( surgeryDialog, NULL, NULL, NULL, NULL );

    /* create the review controls dialog */
    reviewDialog = createDomainReviewDialog( topl );
    XtManageChild( reviewDialog );
    HGU_XmSaveRestoreAddWidget( reviewDialog, NULL, NULL, NULL, NULL );

    /* create the colormap controls */
    colormap_dialog = create_colormap_dialog( topl );
    XtManageChild( colormap_dialog );
    HGU_XmSaveRestoreAddWidget( colormap_dialog, NULL, NULL, NULL, NULL );

    /* get option menu resources */
    XtGetApplicationResources(globals.topl, &globals,
			      autosave_res, XtNumber(autosave_res),
			      NULL, 0);

    /* add an autosave timeout */
    filestr = globals.autosave_file;
    dirstr = globals.autosave_dir;
    if( strlen(dirstr) < 1 ){
      globals.autosave_file = (String)
	AlcMalloc(sizeof(char) * (strlen(filestr) + 16 ));
      sprintf(globals.autosave_file, "%s.%d", filestr, getpid());
    }
    else {
      globals.autosave_file = (String)
	AlcMalloc(sizeof(char) * (strlen(dirstr) + strlen(filestr) + 16 ));
      sprintf(globals.autosave_file, "%s/%s.%d", dirstr, filestr, getpid());
    }
    
    /* no autosave in sectionView mode */
    if( globals.sectViewFlg ){
      globals.autosavetimeoutID = 0;
    }
    else {
      globals.autosavetimeoutID =
	XtAppAddTimeOut(globals.app_con, globals.autosave_time*1000,
			autosavetimeout_cb, NULL);
    }

    /* create the autosave controls */
    autosave_dialog = create_autosave_dialog( topl );
    XtManageChild( autosave_dialog );
    HGU_XmSaveRestoreAddWidget( autosave_dialog, NULL, NULL, NULL, NULL );

    globals.stipple                = (Pixmap) 0;
    globals.paint_action_quit_flag = 0;
    globals.currentPaintAction = MAPAINT_PAINT_BALL_2D;
    globals.currentPaintActionCbFunc = MAPaintPaintBall2DCb;
    globals.currentPaintActionInitFunc = MAPaintPaintBall2DInit;
    globals.currentPaintActionQuitFunc = MAPaintPaintBall2DQuit;
    globals.review_domain_obj = NULL;

    /* remove the editing options in sectionView mode */
    if( globals.sectViewFlg ){
      char nameBuf[64];
      int i;
      for(i=0; options_menu_itemsP[i].name != NULL; i++){
	if( strstr(options_menu_itemsP[i].name, "colormap") ){
	  continue;
	}
	else if( options_menu_itemsP[i].name ){
	  sprintf(nameBuf, "*.options_menu*%s",
		  options_menu_itemsP[i].name);
	  if((widget = XtNameToWidget(topl, nameBuf))){
	    XtSetSensitive(widget, False);
	  }
	}
      }
    }

    /* create the save sequence controls */
    save_seq_dialog = create_save_seq_dialog( topl );
    XtManageChild( save_seq_dialog );
    HGU_XmSaveRestoreAddWidget( save_seq_dialog, NULL, NULL, NULL, NULL );

    /* get the current working directory */
    if((dirstr = getcwd(lineBuf, 256))){
      globals.origDir = AlcStrDup(dirstr);
    }
    else {
      globals.origDir = NULL;
    }

    /* check for rapid-map or express-map */
    if( globals.rapidMapFlg || globals.expressMapFlg ){

      /* check for bibfile list file */
      if( globals.bibfileListFile ){
	FILE	*fp;
	int		i, j, linecount, csvCount;
	WlzObject	*dummyObj;
	WlzPixelV	bgdV;
	Widget		toggle, notebook, matrix, textField;
	XmNotebookPageInfo	pageInfo;
	XmToggleButtonCallbackStruct	cbs;

	/* set the default csv file */
	if( globals.bibfileListFile[0] == '/' ){
	  if( strstr(globals.bibfileListFile, ".csv") ){
	    sprintf(lineBuf, "%s", globals.bibfileListFile);
	  }
	  else {
	    sprintf(lineBuf, "%s.csv", globals.bibfileListFile);
	  }
	}
	else {
	  if( strstr(globals.bibfileListFile, ".csv") ){
	    sprintf(lineBuf, "%s/%s", globals.origDir, globals.bibfileListFile);
	  }
	  else {
	    sprintf(lineBuf, "%s/%s.csv", globals.origDir, globals.bibfileListFile);
	  }
	}
	warpGlobals.bibfileListCSVFile = AlcStrDup(lineBuf);

	/* read file and create lists */
	if((fp = fopen(globals.bibfileListFile, "r"))){
	  /* count lines */
	  linecount = 1;
	  while( fgets(lineBuf, 1024, fp) ){
	    linecount++;
	  }
	  warpGlobals.bibfileList = (char **) AlcCalloc(linecount, sizeof(char *));
	  warpGlobals.statusList = (MAPaintExpressMapStatus *)
	    AlcCalloc(linecount, sizeof(MAPaintExpressMapStatus));
	  warpGlobals.dateList = (char **) AlcCalloc(linecount, sizeof(char *));
	  warpGlobals.authorList = (char **) AlcCalloc(linecount, sizeof(char *));
	  warpGlobals.stageList = (char **) AlcCalloc(linecount, sizeof(char *));
	  warpGlobals.qualityList = (MAPaintExpressMapQuality *)
	    AlcCalloc(linecount, sizeof(MAPaintExpressMapQuality));
	  rewind(fp);
	  linecount = 0;
	  while( fgets(lineBuf, 1024, fp) ){
	    int	statusTmp, qualityTmp;
	    csvCount = sscanf(lineBuf, "%[^,\n], %d, %[^,\n], %[^,\n], %[^,\n], %d", fileBuf,
			      &statusTmp, dateBuf, authorBuf, stageBuf, &qualityTmp);
	    status = statusTmp;
	    quality = qualityTmp;
	    if( csvCount > 0 ){
	      if((fileBuf[0] != '/') && globals.origDir ){
		warpGlobals.bibfileList[linecount] = 
		  (char *) AlcMalloc(sizeof(char)*
				     (strlen(fileBuf) +
				      strlen(globals.origDir) + 4));
		sprintf(warpGlobals.bibfileList[linecount],
			"%s/%s", globals.origDir, fileBuf);
	      }
	      else {
		warpGlobals.bibfileList[linecount] = AlcStrDup(fileBuf);
	      }
	    }
	    if( csvCount > 1 ){
		warpGlobals.statusList[linecount] = status;
	    }
	    else {
	      warpGlobals.statusList[linecount] = MA_EXPRESSMAP_STATUS_NONE;
	    }
	    if( csvCount > 2 ){
		warpGlobals.dateList[linecount] = AlcStrDup(dateBuf);
	    }
	    else {
	      warpGlobals.dateList[linecount] = AlcStrDup("Unknown");
	    }
	    if( csvCount > 3 ){
		warpGlobals.authorList[linecount] = AlcStrDup(authorBuf);
	    }
	    else {
	      warpGlobals.authorList[linecount] = AlcStrDup("Unknown");
	    }
	    if( csvCount > 4 ){
		warpGlobals.stageList[linecount] = AlcStrDup(stageBuf);
	    }
	    else {
	      warpGlobals.stageList[linecount] = AlcStrDup("TS23");
	    }
	    if( csvCount > 5 ){
		warpGlobals.qualityList[linecount] = quality;
	    }
	    else {
	      warpGlobals.qualityList[linecount] = MA_EXPRESSMAP_QUALITY_NONE;
	    }
	    linecount++;
	  }
	  warpGlobals.bibfileListCount = linecount;
	  fclose(fp);
	}

	/* create dummy reference object and install */
	bgdV.type = WLZ_GREY_UBYTE;
	bgdV.v.ubv = 255;
	dummyObj = WlzAssignObject(WlzMakeCuboid(0, 5, 0, 5, 0, 5,
						 WLZ_GREY_UBYTE, bgdV,
						 NULL, NULL, NULL), NULL);
	set_topl_title("dummy");
	globals.file = NULL;
	globals.origObjType = WLZ_3D_DOMAINOBJ;
	install_paint_reference_object(dummyObj);
	WlzFreeObj(dummyObj);

	/* create warp input dialog */
	warpInput2DCb(globals.topl, NULL, NULL);

	/* get the warp controls toggle */
	if((toggle = XtNameToWidget(globals.topl, "*warp_input_2d_frame_title"))){
	  XtVaSetValues(toggle, XmNset, True, NULL);
	  cbs.set = True;
	  XtCallCallbacks(toggle, XmNvalueChangedCallback, &cbs);
	}

	/* set the files names etc in the table widget */
	if((matrix = XtNameToWidget(globals.topl, "*expressmap_matrix"))){
	  String	*rows, bibfileStr, tailStr, *labels;
	  int		numRows;
	  Boolean	*rowButtonLabels;

	  XtVaGetValues(matrix,
			XmNrows, &numRows,
			XmNtextField, &textField,
			NULL);
	  if( numRows > 0 ){
	    XbaeMatrixDeleteRows(matrix, 0, numRows);
	  }
	  rows = (String *) AlcMalloc(sizeof(String) * warpGlobals.bibfileListCount * 6);
	  labels = (String *) AlcMalloc(sizeof(String) * warpGlobals.bibfileListCount);
	  rowButtonLabels  = (Boolean *)AlcMalloc(sizeof(Boolean) *
						  warpGlobals.bibfileListCount);
       
	  bibfileStartIndex = -1;
	  for(i=0; i < warpGlobals.bibfileListCount; i++){
	    bibfileStr = tailStr = warpGlobals.bibfileList[i];
	    for(j=0; j < strlen(bibfileStr); j++){
	      if( bibfileStr[j] == '/' ){
		tailStr = bibfileStr + (j + 1);
	      }
	    }
	    rows[i*6 + 0] = tailStr;
	    rows[i*6 + 1] = expressMapStatusStrs[warpGlobals.statusList[i]];
	    rows[i*6 + 2] = warpGlobals.dateList[i];
	    rows[i*6 + 3] = warpGlobals.authorList[i];
	    rows[i*6 + 4] = warpGlobals.stageList[i];
	    rows[i*6 + 5] = expressMapQualityStrs[warpGlobals.qualityList[i]];
	    labels[i] = "->";
	    rowButtonLabels[i] = True;

	    /* check for first "None" */
	    if((bibfileStartIndex == -1) &&
	       (warpGlobals.statusList[i] == MA_EXPRESSMAP_STATUS_NONE)){
	      bibfileStartIndex = i;
	    }
	  }
	  XbaeMatrixAddRows(matrix, 0, rows, labels, NULL, i);
	  for(i=0; i < warpGlobals.bibfileListCount; i++){
	    XbaeMatrixSetRowUserData(matrix, i, (XtPointer) (long) i);
	  }
	  XtVaSetValues(matrix,
			XmNbuttonLabels, True,
			XmNrowButtonLabels, rowButtonLabels,
			XmNrowLabelAlignment, XmALIGNMENT_CENTER,
			NULL);
	  AlcFree(rows);
	  AlcFree(labels);
	  AlcFree(rowButtonLabels);
	  XtVaSetValues(textField, XmNeditable, False, NULL);
	}
	

	/* set rapidMap mode */
	if( globals.rapidMapFlg ){
	  if((notebook = XtNameToWidget(globals.topl,
					"*warp_cntrl_notebook"))){
	    XtVaSetValues(notebook,
			  XmNcurrentPageNumber, 2,
			  NULL);

	    /* call the activate callback */
	    if( XmNotebookGetPageInfo(notebook, 2,
				      &pageInfo) == XmPAGE_FOUND ){
	      XmPushButtonCallbackStruct cbs;

	      cbs.reason = XmCR_ACTIVATE;
	      cbs.event = NULL;
	      cbs.click_count = 1;
	      XtCallCallbacks(pageInfo.major_tab_widget,
			      XmNactivateCallback, &cbs);
	    }
	  }
	}
	else {
	  if((notebook = XtNameToWidget(globals.topl,
					"*warp_cntrl_notebook"))){
	    XtVaSetValues(notebook,
			  XmNcurrentPageNumber, 3,
			  NULL);

	    /* call the activate callback */
	    if( XmNotebookGetPageInfo(notebook, 3,
				      &pageInfo) == XmPAGE_FOUND ){
	      XmPushButtonCallbackStruct cbs;

	      cbs.reason = XmCR_ACTIVATE;
	      cbs.event = NULL;
	      cbs.click_count = 1;
	      XtCallCallbacks(pageInfo.major_tab_widget,
			      XmNactivateCallback, &cbs);
	    }
	  }
	}

	/* read first bibfile */
	warpGlobals.bibfileSavedFlg = 1;
	if( bibfileStartIndex < 0 ){
	  bibfileStartIndex = 0;
	}
	warpGlobals.bibfileListIndex = bibfileStartIndex - 1;
	if( globals.rapidMapFlg ){
	  if((toggle = XtNameToWidget(globals.topl, "*warp_input_rapid_form*next"))){
	    XtCallCallbacks(toggle, XmNactivateCallback, NULL);
	  }
	}
	else {
	  if((toggle = XtNameToWidget(globals.topl, "*warp_input_express_form*next"))){
	    XtCallCallbacks(toggle, XmNactivateCallback, NULL);
	  }
	}
      }
      else {
	warpGlobals.bibfileListCSVFile = NULL;
	/* should report an error here */
      }
    }
    else {
      warpGlobals.matrix = NULL;
    }

    return;
}
Esempio n. 15
0
int             main(int argc, char **argv)
{
  int		tI,
		errIdx,
  		option,
		keep2D = 0,
		ok = 1,
		usage = 0;
  WlzDDOVxSzSrc voxSzSrc = WLZDDO_VSS_UNIT;
  WlzDVertex2	org;
  WlzThreeDViewStruct *view = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  WlzObject	*dwnObj = NULL,
  		*refObj = NULL;
  FILE		*fP = NULL;
  char 		*errMsg0,
  		*cmdStr = NULL,
		*refFileStr = NULL,
  		*outFileStr,
        	*inFileStr;
  double	voxSz[3];
  const char	*errMsg;
  static char	optList[] = "a:b:d:E:f:g:m:o:r:s:u:2eh",
		outFileStrDef[] = "-",
  		inFileStrDef[] = "-";

  opterr = 0;
  errMsg = errMsg0 = "";
  org.vtX = org.vtY = 0.0;
  inFileStr = inFileStrDef;
  outFileStr = outFileStrDef;
  voxSz[0] = voxSz[1] = voxSz[2] = 1.0;
  if((view = WlzMake3DViewStruct(WLZ_3D_VIEW_STRUCT, &errNum)) == NULL)
  {
    ok = 0;
    (void )WlzStringFromErrorNum(errNum, &errMsg);
    (void )fprintf(stderr,
		   "%s: failed to create view structure (%s)\n",
		   *argv, errMsg);
  }
  if(ok)
  {
    view->dist = 0.0;
    view->scale = 1.0;
    view->ref_obj = NULL;
    view->view_mode = WLZ_UP_IS_UP_MODE;
    view->phi = view->theta = view->zeta = 0.0;
    view->up.vtX = view->up.vtY = 0.0; view->up.vtZ = 1.0;
    view->fixed.vtX = view->fixed.vtY = view->fixed.vtZ = 0.0;
    while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
    {
      switch(option)
      {
	case '2':
	  keep2D = 1;
	  break;
	case 'a':
	  usage = WlzDrawDomObjScanTriple(optarg,
	                                  &(view->phi),
					  &(view->theta),
					  &(view->zeta)) < 1;
	  break;
	case 'e':
	  voxSzSrc = WLZDDO_VSS_OBJ;
	  break;
	case 'E':
	  voxSzSrc = WLZDDO_VSS_GVN;
	  usage = WlzDrawDomObjScanTriple(optarg,
	                                  &(voxSz[0]),
					  &(voxSz[1]),
					  &(voxSz[2])) < 1;
	  break;
	case 'f':
	  usage = WlzDrawDomObjScanTriple(optarg,
	                                  &(view->fixed.vtX),
					  &(view->fixed.vtY),
					  &(view->fixed.vtZ)) < 1;
	  break;
	case 'd':
	  usage = sscanf(optarg, "%lg", &(view->dist)) != 1;
	  break;
	case 'b':
	  usage = WlzDrawDomObjReadView(optarg, view,
					&errMsg0) != WLZ_ERR_NONE;
	  if(usage)
	  {
	    (void )fprintf(stderr,
			   "%s: failed to read view parameters from file "
			   "%s (%s)\n",
			   *argv, optarg, errMsg0);
	  }
	  break;
	case 'm':
	  if(WlzStringMatchValue(&tI, optarg,
				 "up-is-up", WLZ_UP_IS_UP_MODE,
				 "statue", WLZ_STATUE_MODE,
				 "absolute", WLZ_ZETA_MODE,
				 NULL))
	  {
	    view->view_mode = (WlzThreeDViewMode )tI;
	  }
	  else
	  {
	    usage = 1;
	  }
	  break;
	case 'u':
	  usage = WlzDrawDomObjScanTriple(optarg,
					  &(view->up.vtX),
					  &(view->up.vtY),
					  &(view->up.vtZ)) < 1;
	  break;
	case 'g':
	  usage = WlzDrawDomObjScanPair(optarg, &(org.vtX), &(org.vtY)) < 1;
	  break;
	case 'o':
	  outFileStr = optarg;
	  break;
	case 'r':
	  refFileStr = optarg;
          errNum = WLZ_ERR_READ_EOF;
	  if((refFileStr == NULL) ||
             (*refFileStr == '\0') ||
	     ((fP = (strcmp(refFileStr, "-")?
		     fopen(refFileStr, "r"): stdin)) == NULL) ||
	     ((refObj = WlzAssignObject(
			WlzReadObj(fP, &errNum), NULL)) == NULL) ||
	     (errNum != WLZ_ERR_NONE))
	  {
	    usage = 1;
            (void )WlzStringFromErrorNum(errNum, &errMsg);
	    (void )fprintf(stderr,
		   "%s: failed to read 3D reference object from %s (%s)\n",
		   *argv, refFileStr, errMsg);
	  }
	  if(fP)
	  {
	    if(strcmp(refFileStr, "-"))
	    {
	      (void )fclose(fP);
	    }
	    fP = NULL;
	  }
	  break;
	case 's':
	  if((cmdStr = AlcStrDup(optarg)) == NULL)
	  {
	    usage = 1;
	    errNum = WLZ_ERR_MEM_ALLOC;
	  }
	  break;
	case 'h':
	default:
	  usage = 1;
	  ok = 0;
	  break;
      }
    }
    if((usage == 0) && (cmdStr == NULL))
    {
      if((optind == argc))
      {
	inFileStr = inFileStrDef;
      }
      else if(optind + 1 == argc )
      {
	inFileStr = *(argv + optind);
      }
      else
      {
	usage = 1;
      }
      if(usage == 0)
      {
	cmdStr = WlzDrawDomObjReadStr(inFileStr, &errNum);
      }
    }
    ok = usage == 0;
  }
  if(ok)
  {
    switch(voxSzSrc)
    {
      case WLZDDO_VSS_UNIT:
	view->voxelRescaleFlg = 0;
	view->voxelSize[0] = 1.0f;
	view->voxelSize[1] = 1.0f;
	view->voxelSize[2] = 1.0f;
	break;
       case WLZDDO_VSS_GVN:
	view->voxelRescaleFlg = 1;
	 view->voxelSize[0] = (float )WLZ_CLAMP(voxSz[0], FLT_MIN, FLT_MAX);
	 view->voxelSize[1] = (float )WLZ_CLAMP(voxSz[1], FLT_MIN, FLT_MAX);
	 view->voxelSize[2] = (float )WLZ_CLAMP(voxSz[2], FLT_MIN, FLT_MAX);
	 break;
      case WLZDDO_VSS_OBJ:
	/* Handled below. */
        break;
    }
  }
  if(ok && refObj)
  {
    WlzObject	*sObj = NULL;
    WlzThreeDViewStruct *v = NULL;

    v = WlzMake3DViewStruct(WLZ_3D_VIEW_STRUCT, &errNum);
    if(errNum == WLZ_ERR_NONE)
    {
      v->type = view->type;
      v->fixed = view->fixed;
      v->theta = view->theta;
      v->phi = view->phi;
      v->zeta = view->zeta;
      v->dist = view->dist;
      v->scale = view->scale;
      if(voxSzSrc == WLZDDO_VSS_OBJ)
      {
	view->voxelRescaleFlg = 1;
	if((refObj->type == WLZ_3D_DOMAINOBJ) &&
	   (refObj->domain.core != NULL) &&
	   (refObj->domain.core->type == WLZ_PLANEDOMAIN_DOMAIN))
	{
	  view->voxelSize[0] = refObj->domain.p->voxel_size[0];
	  view->voxelSize[1] = refObj->domain.p->voxel_size[1];
	  view->voxelSize[2] = refObj->domain.p->voxel_size[2];
	}
      }
      v->voxelRescaleFlg = view->voxelRescaleFlg;
      v->voxelSize[0] = view->voxelSize[0];
      v->voxelSize[1] = view->voxelSize[1];
      v->voxelSize[2] = view->voxelSize[2];
      v->interp = view->interp;
      v->view_mode = view->view_mode;
      v->up = view->up;
      v->fixed_2 = view->fixed_2;
      v->fixed_line_angle = view->fixed_line_angle;
      errNum = WlzInit3DViewStruct(v, refObj);
    }
    if(errNum == WLZ_ERR_NONE)
    {
      sObj = WlzGetSectionFromObject(refObj, v, WLZ_INTERPOLATION_NEAREST,
                                     &errNum);
    }
    if(errNum == WLZ_ERR_NONE)
    {
      if((sObj->type != WLZ_2D_DOMAINOBJ) || (sObj->domain.core == NULL))
      {
        errNum = WLZ_ERR_DOMAIN_DATA;
      }
      else
      {
        org.vtX += sObj->domain.i->kol1;
        org.vtY += sObj->domain.i->line1;
      }
    }
    (void )WlzFree3DViewStruct(v);
    (void )WlzFreeObj(sObj); 
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: failed find offset from reference object (%s).\n",
		     *argv, errMsg);
    }
  }
  if(ok)
  {
    dwnObj = WlzDrawDomainObj(org, view, keep2D, cmdStr, &errIdx, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: failed to draw object in command prior to string\n"
		     "position %d (%s)\n",
		     *argv, errIdx, errMsg);
    }
  }
  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).\n",
		     *argv, errMsg);
    }
    else
    {
      if((errNum = WlzWriteObj(fP, dwnObj)) != 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(outFileStr, "-"))
    {
      fclose(fP);
    }
  }
  AlcFree(cmdStr);
  (void )WlzFreeObj(refObj);
  (void )WlzFree3DViewStruct(view);
  (void )WlzFreeObj(dwnObj);
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%sExample: %s%s",
    *argv,
    " [-2] [-a<pitch,yaw,roll>]\n"
    "                 [-f <fx,fy,fz>]\n"
    "                 [-d <dist> [-b <view bib file>]\n"
    "                 [-m <mode>] [-u<ux,uy,uz>]\n"
    "                 [-e] [-E<vx,vy,vz>]\n"
    "                 [-g <ox,oy,oz>] [-h] [-o<output>]\n"
    "                 [-r <ref object>]\n"
    "                 [-s <cmd str>] [<cmd str file>>]\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -2  Ignore the view struct and keep as a 2D object.\n"
    "  -a  Viewing angles: pitch (phi), yaw (theta) and roll (zeta),\n"
    "      default 0.0,0.0,0.0.\n"
    "  -f  Fixed point position, default 0.0,0.0,0.0.\n"
    "  -d  Distance parameter, default 0.0.\n"
    "  -b  Bib file with view parameters, e.g. saved from MAPaint.\n"
    "  -m  Viewing mode, one of: up-is-up, statue or absolute, default\n"
    "      is up-is-up.\n"
    "  -u  Up vector, default 0.0,0.0,1.0.\n"
    "  -e  Use object voxel size, default is voxel size 1.0,1.0,1.0.\n"
    "  -E  Use supplied voxel size rather than the object voxel size,\n"
    "      default 1.0,1.0,1.0.\n"
    "  -g  Origin of the drawing with respect to the 2D Woolz object\n"
    "      cut using the view transform, default 0.0,0.0.\n"
    "  -r  Reference object. If given this is must be a 3D spatial domain\n"
    "      object. The object is used to determine an additional offset\n"
    "      for the origin of the 2D plane with respect to the section in 3D\n"
    "      (i.e. it is added to any offset given using the -g option).\n"
    "  -s  Drawing command string.\n"
    "  -h  Help, prints this usage message.\n"
    "  -o  Output file name.\n"
    "Reads drawing commands from either a string given on the command line,\n"
    "a file given on the command line or the standard input (in this order\n"
    "of precidence). The drawing commands are used to create a drawn\n"
    "section which is placed into 3D using the view transform.\n"
    "\n"
    "The command string must have the following syntax:\n"
    "  <command string> = <init command>[<command>]+<end command>\n"
    "  <init command> = <ident>:<version>;\n"
    "  <end command> = END:;\n"
    "  <ident> = WLZ_DRAW_DOMAIN\n"
    "  <version> = 1\n"
    "  <command> = <command name>:[<parameter>[,<parameter>]*];\n"
    "  <command name> = PEN | LINE | CIRCLE\n"
    "In addition to the init and end commands, the following\n"
    "drawing commands are recognised:\n"
    "  CIRCLE:<action>:<radius>,<x>,<y>;\n"
    "  LINE:<action>:<width>,<x>,<y>,<x>,<y>;\n"
    "  PEN:<action>,<width>,<x>,<y>[,<x>,<y>]*;\n"
    "Where:\n"
    " <action> = DRAW | ERASE\n"
    "The circle command draws or erases a filled circle which is specified\n"
    "by it's radius and centre parameters.\n"
    "The line command draws a rectangle using the given width and end\n"
    "coordinates of the mid-line.\n"
    "The pen command draws a polyline which is composed of a series of\n"
    "rectangular segments, with each segment ending in a semi-circular cap.\n"
    "The parameters of the pen command are the width and line segment end\n"
    "point coordinates.\n"
    "All widths, radii and coordinates may be in any floating point format\n"
    "recognised by scanf(3).\n"
    "Other commands may be present provided they have the same syntax\n"
    "described above, but they will be ignored.\n"
    "All white space characters are ignored.\n",
    *argv,
    " -o out.wlz -s 'WLZ_DRAW_DOMAIN:1; CIRCLE:DRAW,100,200,300; END:;'\n"
    "This creates a 3D domain object with a single plane at z = 0\n"
    "which has a domain that is  a single circle (radius = 100,\n"
    "centre = 200,300).\n");
  }
  return(!ok);
}
Esempio n. 16
0
void installNewDomain(
  WlzObject	*obj,
  char		*file,
  int		displayIndx)
{
  DomainListItem	*newItem, *matchItem=NULL;
  HGUDlpListItem	*item;
  int			i;
  WlzObject		*obj1;
  WlzErrorNum		errNum;

  /* check for repeats - need confirm to continue */
  obj = WlzAssignObject(obj, NULL);
  item = HGUDlpListHead(globals.dmnList);
  while( item ){
    newItem = (DomainListItem *) HGUDlpListEntryGet(globals.dmnList, item);
    if( strcmp(newItem->file, file) ){
      item = HGUDlpListNext(globals.dmnList, item);
    }
    else {
      /* may want to reset this object */
      if( !HGU_XmUserConfirm(globals.topl,
			     "This domain is already on installed.\n"
			     "Do you want to re-read the domain\n"
			     "to extend the existing region?\n"
			     "Note: to reset a domain then delete\n"
			     "it first then re-read.",
			     "Yes", "No", 1) ){
	WlzFreeObj(obj);
	return;
      }
      matchItem = newItem;
      break;
    }
  }

  /* remove overlaps with existing domains  - the new dominates */
  item = HGUDlpListHead(globals.dmnList);
  while( item ){
    newItem = (DomainListItem *) HGUDlpListEntryGet(globals.dmnList, item);
    if( strcmp(newItem->file, file) ){
      obj1 = WlzDiffDomain(newItem->obj, obj, &errNum);
      if( errNum == WLZ_ERR_NONE ){
	WlzFreeObj(newItem->obj);
	if( obj1 ){
	  newItem->obj = WlzAssignObject(obj1, NULL);
	}
	else {
	  newItem->obj = NULL;
	}
      }
    }
    item = HGUDlpListNext(globals.dmnList, item);
  }


  /* OK extend old or create a new list item */
  if( matchItem ){
    obj1 = WlzUnion2(matchItem->obj, obj, &errNum);
    if( errNum == WLZ_ERR_NONE ){
      WlzFreeObj(matchItem->obj);
      if( obj1 ){
	matchItem->obj = WlzAssignObject(obj1, NULL);
      }
      else {
	matchItem->obj = NULL;
      }
    }
  }
  else if( newItem = (DomainListItem *) AlcCalloc(sizeof(DomainListItem), 1) ){
    newItem->file = AlcStrDup(file);
    newItem->fileDisplayIndx = displayIndx;
    newItem->obj = WlzAssignObject(obj, NULL);
    newItem->listStr = XmStringCreateLocalized(newItem->file+displayIndx);

    /* add it to the domain list and domain list widget */
    (void) HGUDlpListInsert(globals.dmnList, NULL, newItem,
			    freeDomainListItem);
    XmListAddItem(globals.dmnListWidget, newItem->listStr, 0);
    XmListSelectItem(globals.dmnListWidget, newItem->listStr, True);
  }

  /* re-display the view */
/*  canvasExposeCb(globals.canvas, NULL, NULL);*/

  WlzFreeObj(obj);
  return;
}
Esempio n. 17
0
int             main(int argc, char **argv)
{
  int		option,
  		ok = 1,
		debug = 0,
		usage = 0,
		verbose = 0,
		verboseDat = 0,
		idx0,
		index,
		binFlg = 0,
  		nMatch = 0,
		useCOfM = 0,
		maxItr = 200,
		minSpx = 15,
		minSegSpx = 10,
		matchImpNN = 7,
		noMatching = 0,
		decompLimit = INT_MAX,
		removeRefOrg = 1,
		refMedianSz = 0,
		srcMedianSz = 0,
		multipleFiles = 0;
  double	tD0,
  		tD1,
		delta = 0.01,	
  		maxAng = 30 * (ALG_M_PI / 180.0),
  		maxDeform = 0.5,
  		maxDisp = 20.0,
		refCThr = 20.0,
		srcCThr = 20.0,
		refThr = 254.0,
		srcThr = 254.0,
		matchImpThr = 2.5,
		refSmooth = 3.0,
		srcSmooth = 3.0;
  FILE		*vFP,
  		*lFP = NULL,
  		*fP = NULL;
  char		*inFileStr = NULL,
		*inTrFileStr = NULL,
  		*outFileBaseStr = NULL,
		*ctrFileBaseStr = NULL;
  char		secParFile[256];
  char		*refObjFileStr = NULL,
  		*srcObjFileStr = NULL;
  WlzThresholdType thrType = WLZ_THRESH_LOW;
  WlzEffFormat	refObjFileType = WLZEFF_FORMAT_WLZ,
  		srcObjFileType = WLZEFF_FORMAT_WLZ;
  WlzObject	*tObj0 = NULL,
  		*refObj3D = NULL,
		*refObj2D = NULL,
  		*srcObj2D = NULL,
		*refCObj2D = NULL,
  		*srcCObj2D = NULL;
  WlzDVertex2	tDV0,
  		refCOfM,
  		srcCOfM,
		refObj2DOrg;
  WlzAffineTransform *inTr = NULL,
		*inPTr = NULL;
  WlzThreeDViewStruct *view = NULL;
  WlzVertexP	matchRP,
  		matchSP;
  WlzInterpolationType interp = WLZ_INTERPOLATION_NEAREST;
  WlzMatchICPWeightCbData cbData;
  WlzAffineTransformPrim inTrPrim;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  char		fileNameBuf[FILENAME_MAX];
  const char	*errMsg;
  static char	optList[] =
                "dhvVo:r:Yt:x:y:a:s:efg:k:u:b:B:i:p:A:E:S:F:P:m:n:c:NL";
  const int	nScatter = 5;
  const char	nullStr[] = "<NULL>",
  		inFileStrDef[] = "-",
  	        outFileStrDef[] = "-";

  matchRP.v = matchSP.v = NULL;
  srcCOfM.vtX = srcCOfM.vtY = 0.0;
  inFileStr = (char *)inFileStrDef;
  outFileBaseStr = (char *)outFileStrDef;
  (void )memset(&inTrPrim, 0, sizeof(WlzAffineTransformPrim));
  inTrPrim.scale = 1.0;
  while((usage == 0) && ok &&
        ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case 'd':
        debug = 1;
	break;
      case 'h':
        usage = 1;
	break;
      case 'v':
        verbose = 1;
	break;
      case 'V':
        verboseDat = 1;
	break;
      case 'o':
        outFileBaseStr = optarg;
	break;
      case 'r':
        if((refObjFileStr = AlcStrDup(optarg)) == NULL)
	{
	  ok = 0;
	  (void )fprintf(stderr, "%s Failed to allocate enough memory.\n",
	     	         *argv);
	}
        break;
      case 'Y':
        multipleFiles = 1;
	break;
      case 't':
        inTrFileStr = optarg;
	break;
      case 'x':
        if(sscanf(optarg, "%lg", &(inTrPrim.tx)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'y':
        if(sscanf(optarg, "%lg", &(inTrPrim.ty)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'a':
        if(sscanf(optarg, "%lg", &(inTrPrim.theta)) != 1)
	{
	  usage = 1;
	}
	else
	{
	  inTrPrim.theta *= ALG_M_PI / 180.0;
	}
	break;
      case 's':
        if(sscanf(optarg, "%lg", &(inTrPrim.scale)) != 1)
	{
	  usage = 1;
	}
	break;
      case 'e':
        useCOfM = 1;
	break;
      case 'f':
        removeRefOrg = 0;
	break;
      case 'b':
	binFlg = 1;
        thrType = WLZ_THRESH_LOW;
        usage = WlzMatchICPPlaneParseDPair(optarg, &refThr, &srcThr) != 3;
	break;
      case 'B':
	binFlg = 1;
        thrType = WLZ_THRESH_HIGH;
        usage = WlzMatchICPPlaneParseDPair(optarg, &refThr, &srcThr) != 3;
	break;
      case 'g':
        usage = WlzMatchICPPlaneParseDPair(optarg, &refCThr, &srcCThr) != 3;
	break;
      case 'k':
        usage = WlzMatchICPPlaneParseDPair(optarg, &tD0, &tD1) != 3;
	refMedianSz = WLZ_NINT(tD0);
	srcMedianSz = WLZ_NINT(tD1);
	break;
      case 'u':
        usage = WlzMatchICPPlaneParseDPair(optarg,
					   &refSmooth, &srcSmooth) != 3;
	break;
      case 'i':
        if((sscanf(optarg, "%d", &maxItr) != 1) || (maxItr <= 0))
	{
	  usage = 1;
	}
	break;
      case 'p':
        if((sscanf(optarg, "%d", &minSpx) != 1) || (minSpx <= 10))
	{
	  usage = 1;
	}
	break;
      case 'P':
        if(sscanf(optarg, "%d", &minSegSpx) != 1)
	{
	  usage = 1;
	}
	break;
      case 'A':
        if((sscanf(optarg, "%lg", &maxAng) != 1) ||
	   (maxAng < 0.0) || (maxAng > 180.0))
	{
	  usage = 1;
	}
	else
	{
	  maxAng *= ALG_M_PI / 180;
	}
	break;
      case 'E':
        if((sscanf(optarg, "%lg", &delta) != 1) || (delta < 0.0))
	{
	  usage = 1;
	}
      case 'F':
        if((sscanf(optarg, "%lg", &maxDeform) != 1) || (maxDeform < 0.0))
	{
	  usage = 1;
	}
	break;
      case 'S':
        if((sscanf(optarg, "%lg", &maxDisp) != 1) || (maxDisp <= 0.0))
	{
	  usage = 1;
	}
	break;
      case 'm':
        if((sscanf(optarg, "%lg", &matchImpThr) != 1) || (matchImpThr < 0.0))
	{
	  usage = 1;
	}
	break;
      case 'n':
        if((sscanf(optarg, "%d", &matchImpNN) != 1) || (matchImpNN < 1))
	{
	  usage = 1;
	}
	break;
      case 'c':
        ctrFileBaseStr = optarg;
        if(strlen(ctrFileBaseStr) > (FILENAME_MAX - 16))
	{
	  usage = 1;
	}
	break;
      case 'N':
        noMatching = 1;
	break;
      case 'L':
        interp = WLZ_INTERPOLATION_LINEAR;
	break;
      default:
        usage = 1;
	break;
    }
  }
  if(usage)
  {
    ok = 0;
  }
  if(ok)
  {
    if((inFileStr == NULL) || (*inFileStr == '\0') ||
       (outFileBaseStr == NULL) || (*outFileBaseStr == '\0'))
    {
      ok = 0;
      usage = 1;
    }
    if(ok && (optind < argc))
    {
      if((optind + 1) != argc)
      {
        usage = 1;
	ok = 0;
      }
      else
      {
        inFileStr = *(argv + optind);
      }
    }
  }
  if(verbose)
  {
    (void )fprintf(stderr, "Parameter and other internal variable values:\n");
    (void )fprintf(stderr, "  ok = %d\n", ok);
    (void )fprintf(stderr, "  debug = %d\n", debug);
    (void )fprintf(stderr, "  verbose = %d\n", verbose);
    (void )fprintf(stderr, "  verboseDat = %d\n", verboseDat);
    (void )fprintf(stderr, "  outFileBaseStr = %s\n",
		   outFileBaseStr? outFileBaseStr: nullStr);
    (void )fprintf(stderr, "  refObjFileStr = %s\n",
		   refObjFileStr? refObjFileStr: nullStr);
    (void )fprintf(stderr, "  multipleFiles = %d\n", multipleFiles);
    (void )fprintf(stderr, "  inTrFileStr = %s\n",
                   inTrFileStr? inTrFileStr: nullStr);
    (void )fprintf(stderr, "  inTrPrim.tx = %g\n", inTrPrim.tx);
    (void )fprintf(stderr, "  inTrPrim.ty = %g\n", inTrPrim.ty);
    (void )fprintf(stderr, "  inTrPrim.theta = %g (Radians)\n",
    		   inTrPrim.theta);
    (void )fprintf(stderr, "  inTrPrim.scale = %g\n", inTrPrim.scale);
    (void )fprintf(stderr, "  useCOfM = %d\n", useCOfM);
    (void )fprintf(stderr, "  removeRefOrg = %d\n", removeRefOrg);
    (void )fprintf(stderr, "  binFlg = %d\n", binFlg);
    (void )fprintf(stderr, "  thrType = %s\n",
	    (thrType == WLZ_THRESH_LOW)? "WLZ_THRESH_LOW": "WLZ_THRESH_HIGH");
    (void )fprintf(stderr, "  refThr = %g\n", refThr);
    (void )fprintf(stderr, "  srcThr = %g\n", srcThr);
    (void )fprintf(stderr, "  refCThr = %g\n", refCThr);
    (void )fprintf(stderr, "  srcCThr = %g\n", srcCThr);
    (void )fprintf(stderr, "  refMedianSz = %d\n", refMedianSz);
    (void )fprintf(stderr, "  srcMedianSz = %d\n", srcMedianSz);
    (void )fprintf(stderr, "  refSmooth = %g\n", refSmooth);
    (void )fprintf(stderr, "  srcSmooth = %g\n", srcSmooth);
    (void )fprintf(stderr, "  delta = %g\n", delta);
    (void )fprintf(stderr, "  maxItr = %d\n", maxItr);
    (void )fprintf(stderr, "  minSpx = %d\n", minSpx);
    (void )fprintf(stderr, "  maxAng = %g (Radians)\n", maxAng);
    (void )fprintf(stderr, "  maxDeform = %g\n", maxDeform);
    (void )fprintf(stderr, "  maxDisp = %g\n", maxDisp);
    (void )fprintf(stderr, "  matchImpThr = %g\n", matchImpThr);
    (void )fprintf(stderr, "  matchImpNN = %d\n", matchImpNN);
    (void )fprintf(stderr, "  ctrFileBaseStr = %s\n",
		   ctrFileBaseStr? ctrFileBaseStr: nullStr);
    (void )fprintf(stderr, "  noMatching = %d\n", noMatching);
    (void )fprintf(stderr, "  usage = %d\n", usage);
  }
  /* Create the initial affine transform and it's inverse. */
  if(ok)
  {
    if(inTrFileStr)
    {
      tObj0 = NULL;
      if(((fP = fopen(inTrFileStr, "r")) == NULL) ||
         ((tObj0 = WlzReadObj(fP, &errNum)) == NULL) ||
	 (tObj0->type != WLZ_AFFINE_TRANS) ||
	 (tObj0->domain.core == NULL))
      {
        errNum = WLZ_ERR_READ_INCOMPLETE;
      }
      else
      {
        inTr = WlzAffineTransformCopy(tObj0->domain.t, &errNum);
      }
      if(fP)
      {
        (void )fclose(fP);
	fP = NULL;
      }
      if(tObj0)
      {
        WlzFreeObj(tObj0);
	tObj0 = NULL;
      }
    }
    else
    {
      inTr = WlzMakeAffineTransform(WLZ_TRANSFORM_2D_AFFINE, &errNum);
      if(errNum == WLZ_ERR_NONE)
      {
	errNum = WlzAffineTransformPrimSet(inTr, inTrPrim);
      }
    }
    if(errNum == WLZ_ERR_NONE)
    {
      if(verbose)
      {
        (void )fprintf(stderr, "Affine transform inTr = \n");
	(void )AlcDouble2WriteAsci(stderr, inTr->mat, 3, 3);
      }
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: Failed to set initial affine transform (%s).\n",
		     *argv, errMsg);
    }
  }
  /* If the reference file name was given on the command line then it use it
   * in place of the reference file name in the section parameters bibfile. */
  if(ok && refObjFileStr)
  {
    if(((refObj3D = WlzAssignObject(
		    WlzEffReadObj(NULL, refObjFileStr, refObjFileType,
				  0, 0, 0, &errNum), NULL)) == NULL) ||
       (errNum != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      "%s Failed to read the reference object from file %s (%s).\n",
      *argv, refObjFileStr, errMsg);
    }
  }
  if(ok)
  {
    if((lFP = (strcmp(inFileStr, "-")?
             fopen(inFileStr, "r"): stdin)) == NULL)
    {
      ok = 0;
      (void )fprintf(stderr,
		   "%s Failed to open the input section parameters file %s.\n",
		    *argv, inFileStr);
    }
  }
  /* Get each input section parameters file and process it. */
  index = 0;
  while(ok &&
        ((fP = WlzMatchICPPlaneSecParFile(lFP, multipleFiles, index,
					  secParFile)) != NULL))
  {
    errNum = WlzMatchICPPlaneReadSecParam(fP, &view,
	refObjFileStr? NULL: &refObjFileStr, &refObjFileType,
	refObj3D? NULL: &refObj3D,
	&srcObjFileStr, &srcObjFileType, &srcObj2D);
    /* Note: srcObj2D assigned in WlzMatchICPPlaneReadSecParam(). */
    if(errNum == WLZ_ERR_NONE)
    {
      if(verboseDat)
      {
	if(verbose)
	{
	  (void )fprintf(stderr,
			 "Writing srcObj2D to dbg-srcObj2D.wlz.\n");
	}
	if((vFP = fopen("dbg-srcObj2D.wlz", "w")) != NULL)
	{
	  (void )WlzWriteObj(vFP, srcObj2D);
	  (void )fclose(vFP);
	}
      }
      errNum = WlzInit3DViewStruct(view, refObj3D);
    }
    if(fP)
    {
      fclose(fP);
      fP = NULL;
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
       "%s Failed to read input section parameters from file %s (%s).\n",
       argv[0], secParFile, errMsg);
    }
    /* Create the section object. */
    if(ok)
    {
      refObj2D = WlzAssignObject(
      		 WlzMatchICPPlaneGetSection(refObj3D, view, interp,
		 		            &errNum), NULL);
      if((errNum == WLZ_ERR_NONE) && (refObj2D != NULL) &&
	  (refObj2D->type = WLZ_2D_DOMAINOBJ) && (refObj2D->domain.core))
      {
	refObj2DOrg.vtX = refObj2D->domain.i->kol1;
	refObj2DOrg.vtY = refObj2D->domain.i->line1;
	if(verboseDat)
	{
	  if(verbose)
	  {
	    (void )fprintf(stderr,
			   "Writing refObj2D to dbg-refObj2D.wlz.\n");
	  }
	  if((vFP = fopen("dbg-refObj2D.wlz", "w")) != NULL)
	  {
	    (void )WlzWriteObj(vFP, refObj2D);
	    (void )fclose(vFP);
	  }
	}
      }
      else
      {
	ok = 0;
        (void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
	"%s Failed to get section from reference object (%s).\n",
	argv[0], errMsg);
      }
    }
    /* Create the contour objects. */
    if(ok)
    {
      refCObj2D = WlzMatchICPPlaneCreateContourObj(refObj2D,
				binFlg, thrType, refThr,
      				refMedianSz, refSmooth,
				refCThr, minSpx, debug,
				verboseDat? "dbg-refObj2D.wlz": NULL,
				&errNum);
      if(errNum == WLZ_ERR_NONE)
      {
	srcCObj2D = WlzMatchICPPlaneCreateContourObj(srcObj2D,
				binFlg, thrType, srcThr,
				srcMedianSz, srcSmooth,
				srcCThr, minSpx, debug,
				verboseDat? "dbg-srcObj2D.wlz": NULL,
				&errNum);
      }
      if(errNum != WLZ_ERR_NONE)
      {
	ok = 0;
        (void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr, "%s Failed to compute contours (%s).\n",
		       argv[0], errMsg);
      }
    }
    /* Compute translation using centre of mass if required. Then create
     * modified initial and inverse transforms for this plane. */
    if(ok)
    {
      if(useCOfM)
      {
	if(verbose)
	{
	  (void )fprintf(stderr,
	  "Using centre of mass to refine initial affine transform.\n");
	}
	refCOfM = WlzCentreOfMass2D(refCObj2D, 0, NULL, &errNum);
	tObj0 = NULL;
	if(errNum == WLZ_ERR_NONE)
	{
	  tObj0 = WlzAssignObject(
		  WlzAffineTransformObj(srcCObj2D, inTr,
					WLZ_INTERPOLATION_NEAREST,
					&errNum), NULL);
	}
	if(errNum == WLZ_ERR_NONE)
	{
	  srcCOfM = WlzCentreOfMass2D(tObj0, 0, NULL, &errNum);
	}
	(void )WlzFreeObj(tObj0);
	if(errNum == WLZ_ERR_NONE)
	{
	  if(verbose)
	  {
	    (void )fprintf(stderr,
	    "centres of mass are: refCOfM = {%g,%g}, srcCOfM = {%g,%g}.\n",
	    refCOfM.vtX, refCOfM.vtY, srcCOfM.vtX, srcCOfM.vtY);
	  }
	  inPTr = WlzAffineTransformCopy(inTr, &errNum);
	}
	if(errNum == WLZ_ERR_NONE)
	{
	  WLZ_VTX_2_SUB(tDV0, refCOfM, srcCOfM);
	  inPTr->mat[0][2] += tDV0.vtX;
	  inPTr->mat[1][2] += tDV0.vtY;
	}
	if(errNum != WLZ_ERR_NONE)
	{
	  ok = 0;
	  (void )WlzStringFromErrorNum(errNum, &errMsg);
	  (void )fprintf(stderr,
	  "%s Failed to modify transform using centre of mass (%s).\n",
			 argv[0], errMsg);
	}
      }
      if(errNum == WLZ_ERR_NONE)
      {
	if(verbose)
	{
	  (void )fprintf(stderr, "Affine transform inPTr = ");
	  if(inPTr)
	  {
	    (void )fprintf(stderr, "\n");
	    (void )AlcDouble2WriteAsci(stderr, inPTr->mat, 3, 3);
	  }
	  else
	  {
	    (void )fprintf(stderr, "Identity\n");
	  }
	}
      }
    }
    if(ok && ctrFileBaseStr)
    {
      if(multipleFiles)
      {
        sprintf(fileNameBuf, "%s_%06d_ctr_ref.wlz", ctrFileBaseStr, index);
      }
      else
      {
        sprintf(fileNameBuf, "%s_ctr_ref.wlz", ctrFileBaseStr);
      }
      errNum = WLZ_ERR_FILE_OPEN;
      ok = (fP = fopen(fileNameBuf, "w")) != NULL;
      if(ok)
      {
	ok = (errNum = WlzWriteObj(fP, refCObj2D)) == WLZ_ERR_NONE;
      }
      if(fP)
      {
	(void )fclose(fP);
	fP = NULL;
      }
      if(ok)
      {
	if(multipleFiles)
	{
	  sprintf(fileNameBuf, "%s_%06d_ctr_src.wlz", ctrFileBaseStr, index);
	}
	else
	{
	  sprintf(fileNameBuf, "%s_ctr_src.wlz", ctrFileBaseStr);
	}
	ok = (fP = fopen(fileNameBuf, "w")) != NULL;
      }
      if(ok)
      {
	ok = (errNum = WlzWriteObj(fP, srcCObj2D)) == WLZ_ERR_NONE;
      }
      if(fP)
      {
	(void )fclose(fP);
	fP = NULL;
      }
      tObj0 = NULL;
      if(ok)
      {
        tObj0 = WlzAffineTransformObj(srcCObj2D, inPTr,
				      WLZ_INTERPOLATION_NEAREST, &errNum);
        ok = errNum == WLZ_ERR_NONE;
      }
      if(ok)
      {
        if(multipleFiles)
	{
	  sprintf(fileNameBuf, "%s_%06d_ctr_itrsrc.wlz", ctrFileBaseStr,
	  	  index);
	}
	else
	{
	  sprintf(fileNameBuf, "%s_ctr_itrsrc.wlz", ctrFileBaseStr);
	}
	ok = (fP = fopen(fileNameBuf, "w")) != NULL;
      }
      if(ok)
      {
	ok = (errNum = WlzWriteObj(fP, tObj0)) == WLZ_ERR_NONE;
      }
      (void )WlzFreeObj(tObj0);
      if(fP)
      {
        (void )fclose(fP);
	fP = NULL;
      }
      if(!ok)
      {
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s Failed to write contour to file %s (%s)\n",
		       argv[0], fileNameBuf, errMsg);
      }
    }
    if(ok && (noMatching == 0))
    {
      /* Set up weighting function callback data. */
      cbData.tGM = refCObj2D->domain.ctr->model;
      cbData.sGM = srcCObj2D->domain.ctr->model;
      cbData.maxDisp = maxDisp;
      cbData.nScatter = nScatter;
      errNum = WlzMatchICPCtr(refCObj2D->domain.ctr, srcCObj2D->domain.ctr,
			      inPTr, maxItr, minSpx, minSegSpx,
			      &nMatch, &matchRP, &matchSP, decompLimit,
			      maxDisp, maxAng, maxDeform,
			      matchImpNN, matchImpThr,
			      WlzMatchICPWeightMatches, &cbData,
			      delta);
      if(errNum != WLZ_ERR_NONE)
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s Failed to compute tie-points from contours (%s).\n",
		       argv[0], errMsg);
      }
    }
    if(ok && verboseDat)
    {
	if(verbose)
	{
	  (void )fprintf(stderr,
			 "Writing tie points to dbg-tiepoints.num.\n");
	}
	if((vFP = fopen("dbg-tiepoints.num", "w")) != NULL)
	{
	  for(idx0 = 0; idx0 < nMatch; ++ idx0)
	  {
	    (void )fprintf(vFP, "%g %g %g %g\n",
		       (matchSP.d2 + idx0)->vtX,
		       (matchSP.d2 + idx0)->vtY,
		       (matchRP.d2 + idx0)->vtX - (matchSP.d2 + idx0)->vtX,
		       (matchRP.d2 + idx0)->vtY - (matchSP.d2 + idx0)->vtY);
	  }
	  (void )fclose(vFP);
	}
    }
    if(ok && ctrFileBaseStr)
    {
      if(multipleFiles)
      {
	sprintf(fileNameBuf, "%s_%06d_ctr_dcp.wlz", ctrFileBaseStr, index);
      }
      else
      {
	sprintf(fileNameBuf, "%s_ctr_dcp.wlz", ctrFileBaseStr);
      }
      if((fP = fopen(fileNameBuf, "w")) == NULL)
      {
	ok = 0;
	(void )fprintf(stderr, "%s Failed to open contour file %s\n",
		       argv[0], fileNameBuf);
      }
      else
      {
	if((errNum = WlzWriteObj(fP, srcCObj2D)) != WLZ_ERR_NONE)
	{
	  ok = 0;
	  (void )WlzStringFromErrorNum(errNum, &errMsg);
	  (void )fprintf(stderr,
	  		 "%s Failed to write contour to file %s (%s)\n",
			 argv[0], fileNameBuf, errMsg);
	}
	(void )fclose(fP);
	fP = NULL;
      }
    }
    /* Write the new section parameters file together with the computed
     * tie-points. */
    if(ok)
    {
      if(multipleFiles)
      {
        sprintf(fileNameBuf, "%s_%06d.bib", outFileBaseStr, index);
      }
      else
      {
        sprintf(fileNameBuf, "%s.bib", outFileBaseStr);
      }
      if((fP = fopen(fileNameBuf, "w")) == NULL)
      {
	ok = 0;
	(void )fprintf(stderr,
		 "%s Failed to open the output section parameters file %s.\n",
		 *argv, fileNameBuf);
      }
    }
    if(ok)
    {
      if(verbose)
      {
	(void )fprintf(stderr, "Writing section parameters.\n");
      }
      errNum = WlzMatchICPPlaneWriteSecParam(fP, view,
	  refObjFileStr, refObjFileType,
	  srcObjFileStr, srcObjFileType,
	  nMatch, matchRP.d2, matchSP.d2,
	  removeRefOrg? &refObj2DOrg: NULL);
      if(fP && strcmp(outFileBaseStr, "-"))
      {
	fclose(fP);
	fP = NULL;
      }
      if(errNum != WLZ_ERR_NONE)
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
	"%s Failed to write output section parameters to file %s (%s).\n",
	argv[0], fileNameBuf, errMsg);
      }
    }
    WlzFreeAffineTransform(inPTr); inPTr = NULL;
    ++index;
  }
  (void )WlzFree3DViewStruct(view);
  AlcFree(refObjFileStr);
  AlcFree(srcObjFileStr);
  AlcFree(matchRP.v);
  AlcFree(matchSP.v);
  (void )WlzFreeAffineTransform(inTr);
  (void )WlzFreeObj(refObj3D);
  (void )WlzFreeObj(refObj2D);
  (void )WlzFreeObj(srcObj2D);
  (void )WlzFreeObj(refCObj2D);
  (void )WlzFreeObj(srcCObj2D);
  if(usage)
  {
      (void )fprintf(stderr,
      "Usage: %s%s%s%s",
      *argv,
      " [-h] [-d] [-v] [-V]\n"
      "                        [-o<output file base>] [-r <reference file>]\n"
      "                        [-Y] [-t#] [-x#] [-y#] [-a#] [-s#] [-e]\n"
      "                        [-g#,#] [-k#,#] [-u#,#] [-b #] [-B #]\n"
      "                        [-f] [-i#] [-s#] [-A#] [-S#] [-F#] [-m#] [-n#]\n"
      "                        [-c<contour file base>] [-N] [-L]\n"
      "                        [<section parameters file>]\n"
      "Version: ",
      WlzVersion(),
      "\n"
      "Options:\n"
      "  -h  Prints this usage information.\n"
      "  -d  Perform extra tests to aid debuging.\n"
      "  -E  Tolerance in mean registration metric value.\n"
      "  -v  Be verbose, lots of text output to the standard error output!\n"
      "  -V  Be verbose with Woolz objects and data, with file name names\n"
      "      prefixed by dbg-.\n"
      "  -o  Output file base.\n"
      "  -r  Reference file.\n"
      "  -Y  The section parameters file is a list of section parameters\n"
      "      files, one per line.\n"
      "  -e  Use centres of mass of geometric models to compute translation,\n"
      "      with this translaton being applied after the optional initial\n"
      "      affine transform.\n"
      "  -t  Initial affine transform (if given all initial affine\n"
      "      transform primitives are ignored).\n"
      "  -x  Initial horizontal translation.\n"
      "  -y  Initial vertical translation.\n"
      "  -a  Initial angle of rotation (degrees).\n"
      "  -s  Initial scale factor.\n"
      "  -g  Maximal gradient contour thresholds, with the format:\n"
      "      <ref threshold>,<src threshold>, either may be omitted.\n"
      "  -k  Median filter size, with the format:\n"
      "      <ref size>,<src size>, either may be omitted.\n"
      "  -u  Gaussian smoothing factors, with the format:\n"
      "      <ref smooth>,<src smooth>, either may be omitted.\n"
      "  -b  Low threshold values used to produce binary mask images for\n"
      "      matching instead of the grey valued images, with objects\n"
      "      having values at or below the given thresholds.\n"
      "  -B  High threshold values used to produce binary mask images for\n"
      "      matching instead of the grey valued images, with objects\n"
      "      having values above the given thresholds.\n"
      "  -f  Keep the reference offset in the reference tie-points (MAPaint\n"
      "      doesn't do this).\n"
      "  -i  Maximum number of iterations.\n"
      "  -p  Minimum number of simplices per shell.\n"
      "  -P  Minimum number of simplices per matched shell segment, with a\n"
      "      pair of correspondence points possibly being generated per\n"
      "      matched shell segment.\n"
      "  -A  Maximum angle (degrees) from a global transformation.\n"
      "  -S  Maximum displacement from a global transformed position.\n"
      "  -F  Maximum deformation from a global transformation.\n"
      "  -m  Implausibility threshold for rejecting implausible\n"
      "      correspondence points which should be greater than zero,\n"
      "      although the useful range is probably [0.5-5.0]. Higher\n"
      "      values allow more implausible matches to be returned.\n"
      "  -n  Number of match points in neighbourhood when checking the\n"
      "	     plausibility of the correspondence points.\n"
      "  -c  Outputs the computed and decomposed geometric models using\n"
      "	     the given file base.\n"
      "  -N  Don't compute the tie-points.\n"
      "  -L  Use linear interpolation (instead of nearest neighbour) when\n"
      "      cuting sections.\n"
      "  Reads either a 2D or 3D reference object and an MAPaint section\n"
      "parameters file. Computes tie-points and then writes a new MAPaint\n"
      "section parameters file which includes the tie-points.\n"
      "  An initial affine transform is computed from the (optional) initial\n"
      "translation, rotation and scale parameters. A centre of mass can be\n"
      "computed to improve the initial translation estimates. If a centre of\n"
      "mass computation is used then the images must have background with\n"
      "high values and foreground with low values. This initial affine\n"
      "transform is appiled to the source image before computing the\n"
      "tie-points. Once computed, the tie-points are transformed using the\n"
      "inverse of the intial transform, before output.\n"
      "  The tie-points are computed using an ICP based matching algorithm\n"
      "in which geometric models built from the maximal gradient edges\n"
      "extracted from the computed section of the reference object and\n"
      "the source object (refered to in the section parameters file).\n"
      "  To aid rejection of poor tie-points, the tie-points are ranked by\n"
      "plausibility, with the most plausible first.\n");
  }
  return(!ok);
}
Esempio n. 18
0
MenuItem *HGU_XmFileListCreateMenuItems(
  AlcDLPList	*fileList,
  XtCallbackProc	callbackProc,
  WlzErrorNum	*dstErr)
{
  MenuItem	*items=NULL;
  int		i, p, numItems;
  AlcDLPItem	*listItem;
  
  WlzErrorNum	errNum=WLZ_ERR_NONE;
  AlcErrno	alcErrno;
  HGU_XmFileListCallbackStruct	*cbs;

  /* check inputs */
  if( fileList == NULL ){
    errNum = WLZ_ERR_PARAM_NULL;
  }

  /* create menu */
  if( errNum == WLZ_ERR_NONE ){
    /* create menu items */
    numItems = AlcDLPListCount(fileList, &alcErrno);
    items = (MenuItem *) AlcMalloc(sizeof(MenuItem) * (numItems+4));

    /* set menu items */
    i = 0;
    listItem = fileList->head;
    while( listItem ){
      cbs = (HGU_XmFileListCallbackStruct *) listItem->entry;

      /* copy in the required fields and generate short name
	 for the menu item */
      for(p=strlen(cbs->file)-1; p >= 0; p--){
	if( cbs->file[p] == '/' ){
	  break;
	}
      }
      items[i].name = (String) AlcMalloc(strlen((&(cbs->file[p+1]))) + 8);
      sprintf(items[i].name, "  %s  ", &(cbs->file[p+1]));
      items[i].wclass = &xmPushButtonWidgetClass;
      items[i].mnemonic = '\0';
      items[i].accelerator = NULL;
      items[i].accel_text = NULL;
      items[i].item_set = False;
      items[i].callback = callbackProc;
      items[i].callback_data = (XtPointer) cbs;
      items[i].help_callback = NULL;
      items[i].help_callback_data = NULL;
      items[i].tear_off_model = XmTEAR_OFF_DISABLED;
      items[i].radio_behavior = False;
      items[i].always_one = False;
      items[i].subitems = NULL;

      i++;
      listItem = listItem->next;
      if( listItem == fileList->head ){
	listItem = NULL;
      }
    }

    /* add a separator */
    items[i].name = AlcStrDup("separator");
    items[i].wclass = &xmSeparatorWidgetClass;
    items[i].mnemonic = '\0';
    items[i].accelerator = NULL;
    items[i].accel_text = NULL;
    items[i].item_set = False;
    items[i].callback = NULL;
    items[i].callback_data = NULL;
    items[i].help_callback = NULL;
    items[i].help_callback_data = NULL;
    items[i].tear_off_model = XmTEAR_OFF_DISABLED;
    items[i].radio_behavior = False;
    items[i].always_one = False;
    items[i].subitems = NULL;
    i++;

    /* add button to clear the list */
    items[i].name = AlcStrDup("Clear list");
    items[i].wclass = &xmPushButtonWidgetClass;
    items[i].mnemonic = '\0';
    items[i].accelerator = NULL;
    items[i].accel_text = NULL;
    items[i].item_set = False;
    items[i].callback = callbackProc;
    items[i].callback_data = NULL;
    items[i].help_callback = NULL;
    items[i].help_callback_data = NULL;
    items[i].tear_off_model = XmTEAR_OFF_DISABLED;
    items[i].radio_behavior = False;
    items[i].always_one = False;
    items[i].subitems = NULL;
    i++;

    items[i].name = NULL;
  }

  /* assign error */
  if( dstErr ){
    *dstErr = errNum;
  }
  return items;
}
Esempio n. 19
0
/*!
* \return	Woolz error code.
* \ingroup	WlzExtFF
* \brief	Reads the materials list from the file into the file header
*		data structure.
*		There are two formats for materials lists:
*		\verbatim
		  {
		    { Id 0, Name "Exterior" )
		    { Id 4, Name "Somites" }
		  }
		\endverbatim
*		and		
*		\verbatim
		  {
		    Exterior {
		    }
		    Inside {
		    }
		    Somites {
		      Id 4,
		      Color 0.2 0.8 0.4
		    }
		    Ventricles
		  }
		\endverbatim
*		Dispite id's being given in the file they are ignored and
*		the id's are given values from 0, incrementing by 1 with
*		each material parsed.
*		The default colour is 0.0 0.0 0.0 for the first material
*		and 1.0 1.0 1.0 for all others.
*		This function has been written to parse either of these
*		materials formats, to generate a materials list in the
*		header data structure.
* \param	fP			Given file.
* \param	buf			Buffer for workspace.
* \param	bufLen			Buffer length.
* \param	head			The Amira lattice header data
*					structure.
*/
static WlzErrorNum WlzEffAmReadMaterials(FILE *fP, char *buf, const int bufLen,
				  WlzEffAmHead *head)
{

  int		tmpI;
  WlzEffAmToken	tok;
  WlzEffAmMaterial *lastMat = NULL,
  		*newMat = NULL;
  WlzErrorNum   errNum;
  const char	tokSepDQ[] = "\"",
  		tokSepWS[] = " \t\n\r\f\v",
            	tokSepWSC[] = " \t\n,\r\f\v",
            	tokSepWSCQ[] = " \t\n,\"\r\f\v";

  errNum =  WlzEffAmReadAndCheckAToken(fP, tokSepWS, buf, bufLen, "{");
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzEffAmReadAToken(fP, tokSepWS, buf, bufLen);
  }
  do
  {
    if((errNum == WLZ_ERR_NONE) && (strcmp(buf, "}")))
    {
      /* Create a new material and set the defaults. */
      if((newMat = (WlzEffAmMaterial *)
      		   AlcCalloc(1, sizeof(WlzEffAmMaterial))) == NULL)
      {
        errNum = WLZ_ERR_MEM_ALLOC;
      }
      else if(head->matCount > 0)
      {
        newMat->color[0] = newMat->color[1] = newMat->color[2] = 1.0;
      }
    }
    if(errNum == WLZ_ERR_NONE)
    {
      if(strcmp(buf, "{"))
      {
	if((newMat->name = AlcStrDup(buf)) == NULL)
	{
	  errNum = WLZ_ERR_MEM_ALLOC;
	}
	else
	{
	  errNum = WlzEffAmReadAToken(fP, tokSepWS, buf, bufLen);
	}
      }
    }
    if((errNum == WLZ_ERR_NONE) && strcmp(buf, "{") && strcmp(buf, "}"))
    {
      errNum = WLZ_ERR_READ_INCOMPLETE;
    }
    if((errNum == WLZ_ERR_NONE) && strcmp(buf, "}"))
    {
      do
      {
	errNum = WlzEffAmReadAToken(fP, tokSepWS, buf, bufLen);
	if((errNum == WLZ_ERR_NONE) && (strcmp(buf, "}")))
	{
	  tok = WLZEFF_AM_TOKEN_NONE;
	  (void )WlzStringMatchValue((int *)&tok, buf,
				     "Color", WLZEFF_AM_TOKEN_COLOR,
				     "Id", WLZEFF_AM_TOKEN_ID,
				     "Name", WLZEFF_AM_TOKEN_NAME,
				     NULL);
	  switch(tok)
	  {
	    case WLZEFF_AM_TOKEN_COLOR:

	      errNum = WlzEffAmReadAValD(fP, tokSepWS, buf, bufLen,
	      				 &(newMat->color[0]));
	      if(errNum == WLZ_ERR_NONE)
	      {
		errNum = WlzEffAmReadAValD(fP, tokSepWS, buf, bufLen,
					   &(newMat->color[1]));
	      }
	      if(errNum == WLZ_ERR_NONE)
	      {
		errNum = WlzEffAmReadAValD(fP, tokSepWS, buf, bufLen,
					   &(newMat->color[2]));
	      }
	      break;
	    case WLZEFF_AM_TOKEN_ID:
	      errNum = WlzEffAmReadAValI(fP, tokSepWSC, buf, bufLen, &tmpI);
	      if(errNum == WLZ_ERR_NONE)
	      {
                errNum = WlzEffAmSkip(fP, tokSepWSC);
	      }
	      break;
	    case WLZEFF_AM_TOKEN_NAME:
	      errNum = WlzEffAmSkip(fP, tokSepWS);
	      if(errNum == WLZ_ERR_NONE)
	      {
	        errNum = WlzEffAmReadAToken(fP, tokSepDQ, buf, bufLen);
	      }
	      if(errNum == WLZ_ERR_NONE)
	      {
	        errNum = WlzEffAmSkip(fP, tokSepWSCQ);
	      }
	      if((errNum == WLZ_ERR_NONE) &&
	      	 ((newMat->name = AlcStrDup(buf)) == NULL))
	      {
		errNum = WLZ_ERR_MEM_ALLOC;
	      }
	      break;
	    default:
	      errNum = WLZ_ERR_READ_INCOMPLETE;
	      break;
	  }
	}
      }while((errNum == WLZ_ERR_NONE) && strcmp(buf, "}"));
      *buf = '\0';
    }
    if(errNum == WLZ_ERR_NONE)
    {
      /* Insert new material into list keeping the order of the materials
       * in which they were read from the file. */
      newMat->id = (head->matCount)++;
      if(lastMat == NULL)
      {
	head->materials = newMat;
      }
      else
      {
        lastMat->next = newMat;
	newMat->prev = lastMat;
      }
      lastMat = newMat;
      newMat = NULL;
    }
    if((errNum == WLZ_ERR_NONE) && strcmp(buf, "}"))
    {
      errNum = WlzEffAmReadAToken(fP, tokSepWS, buf, bufLen);
    }
  } while((errNum == WLZ_ERR_NONE) && strcmp(buf, "}"));
  if(newMat)
  {
    AlcFree(newMat->name);
    AlcFree(newMat);
  }
  return(errNum);
}
Esempio n. 20
0
void file_menu_init(
  Widget	topl)
{
  Widget	rc, form, toggle;
  Visual	*visual;
  Arg		arg[1];
  char		fileStr[128];
  FILE 		*fp;
  WlzEffFormat	image_type=WLZEFF_FORMAT_WLZ;

  /* set the top-level title */
  set_topl_title(NULL);

  /* get the visual explicitly */
  visual = HGU_XmWidgetToVisual(topl);
  XtSetArg(arg[0], XmNvisual, visual);

  /* create the read-model file selection dialog */
  read_model_dialog = XmCreateFileSelectionDialog(topl,
						  "read_model_dialog", arg, 1);
  XtAddCallback(read_model_dialog, XmNokCallback,
		read_reference_object_cb, (XtPointer) WLZEFF_FORMAT_WLZ);
  XtAddCallback(read_model_dialog, XmNokCallback, PopdownCallback, NULL);
  XtAddCallback( read_model_dialog, XmNcancelCallback, 
		PopdownCallback, NULL);
  XtAddCallback(read_model_dialog, XmNmapCallback,
		FSBPopupCallback, NULL);
  XtManageChild( read_model_dialog );

  /* create the read-obj file selection dialog */
  read_obj_dialog = HGU_XmCreateExtFFObjectFSB(topl, "read_obj_dialog",
					      read_reference_object_cb, NULL);
  if((rc = XtNameToWidget(read_obj_dialog, "*.formatFormRC"))){

    /* add a form to include file type and fill-blanks toggle */
    form = XtVaCreateManagedWidget("read_file_form", xmFormWidgetClass,
				   rc,
				   XmNborderWidth,	0,
				   NULL);

    /* add a fill-blanks toggles */
    toggle = XtVaCreateManagedWidget("fill_blanks", xmToggleButtonGadgetClass,
				     form,
				     XmNindicatorOn, 	True,
				     XmNindicatorType,	XmN_OF_MANY,
				     XmNset,		False,
				     XmNtopAttachment,	XmATTACH_FORM,
				     XmNleftAttachment,	XmATTACH_FORM,
				     NULL);

    toggle = XtVaCreateManagedWidget("min_domain", xmToggleButtonGadgetClass,
				     form,
				     XmNindicatorOn, 	True,
				     XmNindicatorType,	XmN_OF_MANY,
				     XmNset,		True,
				     XmNtopAttachment,	XmATTACH_FORM,
				     XmNleftAttachment,	XmATTACH_WIDGET,
				     XmNleftWidget,	toggle,
				     NULL);
  }

  HGU_XmExtFFObjectFSBSetType(read_obj_dialog, WLZEFF_FORMAT_WLZ);
  XtManageChild( read_obj_dialog );

  /* add to the save restore list */
  HGU_XmSaveRestoreAddWidget( read_obj_dialog, HGU_XmFSD_SaveFunc,
			     (XtPointer) XtName(topl), NULL, NULL );

  /* create the write-obj file selection dialog */
  write_obj_dialog = HGU_XmCreateExtFFObjectFSB(topl, "write_obj_dialog",
					       write_reference_object_cb,
					       NULL);
  HGU_XmExtFFObjectFSBSetType(write_obj_dialog, WLZEFF_FORMAT_WLZ);


  /* initialise the reference file list pulldown */
  if( !globals.sectViewFlg ){
    Widget	cascade;

    if((cascade = XtNameToWidget(globals.topl,
				 "*file_menu*_pulldown*Recent"))){
      globals.resourceFile = (String) 
	AlcMalloc(sizeof(char) * (strlen(getenv("HOME")) + 16));
      sprintf(globals.resourceFile, "%s/%s", getenv("HOME"), ".maRecentFiles");
      globals.fileList = HGU_XmFileListCreateList(globals.resourceFile, NULL);
      HGU_XmFileListResetMenu(globals.fileList, cascade, referenceFileListCb);
    }
  }

  /* add to the save restore list */
  HGU_XmSaveRestoreAddWidget( write_obj_dialog, HGU_XmFSD_SaveFunc,
			     (XtPointer) XtName(topl), NULL, NULL );

  /* create the object properties dialog */
  obj_props_dialog_init( topl );

  globals.file      = NULL;
  globals.obj       = NULL;
  globals.orig_obj  = NULL;
  globals.fb_obj    = NULL;
  globals.origObjExtType = image_type;

  /* setup the theiler directory and menu item - check for stage */
  XtGetApplicationResources(topl, &globals, set_att_res,
			    XtNumber(set_att_res), NULL, 0);

  /* check the logfile */
  if( globals.logfile ){
    if( (globals.logfileFp = fopen(globals.logfile, "w")) == NULL ){
      fprintf(stderr,
	      "MAPaint: something wrong with the logfile %s\n"
	      "Please check name and permissions\n"
	      "Logging not enabled\n\007", globals.logfile);
    }
    else {
      char		timeBuf[16];
      struct hostent 	*hstnt;
      fprintf(stderr, "MAPaint: logging enabled to %s\n", globals.logfile);
      MAPaintLogData("Filename", globals.logfile, 0, NULL);
      MAPaintLogData("User", getenv("USER"), 0, NULL);
#if defined (LINUX2) || defined (DARWIN)
      strcpy(timeBuf, "00/00/00");
#else
      tmpTime = time(NULL);
      cftime(timeBuf, "%d/%m/%Y", &tmpTime);
#endif /* LINUX2 */
      MAPaintLogData("Date", timeBuf, 0, NULL);
#if defined (LINUX2) || defined (DARWIN)
      strcpy(timeBuf, "00.00");
#else
      cftime(timeBuf, "%H.%M", &tmpTime);
#endif /* LINUX2 */
      MAPaintLogData("Time", timeBuf, 0, NULL);
      hstnt = gethostbyname(getenv("HOST"));
      MAPaintLogData("Host", getenv("HOST"), 0, NULL);
      MAPaintLogData("Hostname", hstnt->h_name, 0, NULL);
    }
  }
  else {
    globals.logfileFp = NULL;
  }

  /* check base directory - if the string has come from the resources then
     we need to duplicate it to allow it to be freed
     possibly some memory leakage here */
  /* note: only non-NULL if set by the user, if NULL then attempt to find
     the cdrom or copied data */
  if( globals.base_theiler_dir ){
    globals.base_theiler_dir = AlcStrDup( globals.base_theiler_dir );
  }
/*  else {
    FILE	*pp;*/
    
    /* search for the Theiler mode directory as per the CDROM 
       should search local disc first */
/*#if defined (LINUX2)
    if((pp = popen("find /mnt -maxdepth 4 -name Models", "r"))){
      while( fscanf(pp, "%s", fileStr) != EOF ){
	if( strstr(fileStr, "Models") ){
	  globals.base_theiler_dir = AlcStrDup(fileStr);
	  break;
	}
      }
      pclose(pp);
    }
#elif defined (DARWIN)
    if( (pp = popen("find /Volumes -maxdepth 4 -name Models", "r")) ){
      while( fscanf(pp, "%s", fileStr) != EOF ){
	if( strstr(fileStr, "Models") ){
	  globals.base_theiler_dir = AlcStrDup(fileStr);
	  break;
	}
      }
      pclose(pp);
    }
#elif defined (SUNOS4) || defined (SUNOS5)
    if( pp = popen("find /cdrom -maxdepth 4 -name Models", "r") ){
      while( fscanf(pp, "%s", fileStr) != EOF ){
	if( strstr(fileStr, "Models") ){
	  globals.base_theiler_dir = AlcStrDup(fileStr);
	  break;
	}
      }
      pclose(pp);
    }
#else
    globals.base_theiler_dir = NULL;
#endif
  }*/
  if( globals.theiler_stage ){
    char *tStr;
    if((tStr = theilerString(globals.theiler_stage))){
      globals.theiler_stage = AlcStrDup(tStr);
    }
    else {
      globals.theiler_stage = NULL;
    }
  }
  theiler_menu_init( topl );

  /* check for an initial reference file else check Theiler stage */
  if( initial_reference_file != NULL ){
    WlzObject 	*obj;

    /* open the reference object file and install */
    if( (fp = fopen(initial_reference_file, "r")) ){
      HGU_XmSetHourGlassCursor(topl);
      if((obj = WlzReadObj( fp, NULL ))){
        WlzDomain	domain;
        WlzValues	values;
        WlzObject	*newObj;
	switch( obj->type ){

	case WLZ_2D_DOMAINOBJ:
	  domain.p = WlzMakePlaneDomain(WLZ_PLANEDOMAIN_DOMAIN, 0, 0,
					obj->domain.i->line1,
					obj->domain.i->lastln,
					obj->domain.i->kol1,
					obj->domain.i->lastkl,
					NULL);
	  domain.p->domains[0] = WlzAssignDomain(obj->domain, NULL);
	  values.vox = WlzMakeVoxelValueTb(WLZ_VOXELVALUETABLE_GREY,
					   0, 0, WlzGetBackground(obj, NULL),
					   NULL, NULL);
	  values.vox->values[0] = WlzAssignValues(obj->values, NULL);
	  newObj = WlzMakeMain(WLZ_3D_DOMAINOBJ, domain, values,
			       NULL, NULL, NULL);
	  WlzFreeObj(obj);
	  obj = newObj;
	  globals.origObjType = WLZ_2D_DOMAINOBJ;
	  break;

	case WLZ_3D_DOMAINOBJ:
	  globals.origObjType = WLZ_3D_DOMAINOBJ;
	  break;

	default:
	  HGU_XmUserError(globals.topl,
			  "Read Reference Object:\n"
			  "    The reference object must be a 2- or 3-D woolz\n"
			  "    grey-level image. Please select an alternate\n"
			  "    object",
			  XmDIALOG_FULL_APPLICATION_MODAL);
	  WlzFreeObj( obj );
	  /* set hour glass cursor */
	  HGU_XmUnsetHourGlassCursor(globals.topl);
	  return;

	}
	HGU_XmFileListAddFile(globals.fileList, initial_reference_file,
			      image_type);
	HGU_XmFileListWriteResourceFile(globals.fileList,
					globals.resourceFile);
	MAPaintLogData("ReferenceFile", initial_reference_file, 0, NULL);
	install_paint_reference_object( obj );

	/* set the globals reference file */
	globals.file = initial_reference_file;

	/* set the title of the top-level window */
	set_topl_title(globals.file);
      }
      else {
	/* if it fails to read, check the file name
	   or the file content for special options */
	if( strstr(initial_reference_file, "MAPaint") ){
	  /* standard MAPaint startup */
	  globals.app_name = "MAPaint";
	  /* set the title of the top-level window */
	  set_topl_title(globals.file);
	}
	else if( strstr(initial_reference_file, "SectionView") ){
	  /* restricted section view startup */
	  globals.app_name = "SectionView";
	  globals.sectViewFlg = 1;
	  /* set the title of the top-level window */
	  set_topl_title(globals.file);
	}
	else if( theilerString(initial_reference_file) ){
	  /* load in theiler stage anatomy etc. */
	  globals.app_name = "SectionView";
	  globals.sectViewFlg = 1;
	  set_theiler_stage_cb(topl, theilerString(initial_reference_file),
			       NULL);
	}
	else {
	  char	strBuf[33];
	  /* check the content */
	  rewind(fp);
	  fscanf(fp, "%32s", strBuf);
	  if( strstr(strBuf, "MAPaint") ){
	    /* standard MAPaint startup */
	    globals.app_name = "MAPaint";
	    /* set the title of the top-level window */
	    set_topl_title(globals.file);
	  }
	  else if( strstr(strBuf, "SectionView") ){
	    /* restricted section view startup */
	    globals.app_name = "SectionView";
	    globals.sectViewFlg = 1;
	    /* set the title of the top-level window */
	    set_topl_title(globals.file);
	  }
	  else if( theilerString(strBuf) ){
	    /* load in theiler stage anatomy etc. */
	    globals.app_name = "SectionView";
	    globals.sectViewFlg = 1;
	    set_theiler_stage_cb(topl,
				 theilerString(strBuf),
				 NULL);
	  }
	}

	/* set the globals reference file */
	globals.file = NULL;
      }
      (void) fclose( fp );

      HGU_XmUnsetHourGlassCursor(topl);
    }
  }
  else if( globals.theiler_stage ){
    globals.app_name = "MAPaint";
    set_theiler_stage_cb(topl, theilerString(globals.theiler_stage), NULL);
  }

  /* reset the colormap */
  if( globals.sectViewFlg == 1 ){
    init_paint_cmapstruct(globals.topl);
  }

  /* check for an initial domain file */
  if( initial_domain_file != NULL ){
    WlzObject 	*obj;

    /* open the domain object file and put it in as a 3D feedback option */
    if( (fp = fopen(initial_domain_file, "rb")) ){
      HGU_XmSetHourGlassCursor(topl);
      if((obj = WlzReadObj( fp, NULL ))){
	if( globals.fb_obj ){
	  WlzFreeObj(globals.fb_obj);
	}
	globals.fb_obj = WlzAssignObject(obj, NULL);
	setup_ref_display_list_cb(read_obj_dialog, NULL, NULL);
      }
      (void) fclose( fp );
      HGU_XmUnsetHourGlassCursor(topl);
    }
  }

  return;
}
Esempio n. 21
0
/*!
* \return	Error code.
* \ingroup	Reconstruct
* \brief	Reads the reconstruct reconstruction information.
* \param	rec			Reconstruct information data structure
* 					to be filled in.
* \param	version			Version number.
* \param	fP			File pointer.
* \param	eMsg			Destination pointer for messages.
*/
static RecError	 RecFileSecRecRead(RecReconstruction *rec, int version,
				   FILE *fP, char **eMsg)
{
  BibFileRecord	*rcRecord = NULL,
  		*lastRecord = NULL;
  char		*fileS = NULL,
  		*formatS = NULL,
		*scaleS = NULL,
		*srcBoxS = NULL,
		*dstBoxS = NULL,
		*bibErrMsg = NULL;
  char		errBuf[256];
  RecError	errFlag = REC_ERR_NONE;
  BibFileError	bibErrFlag = BIBFILE_ER_NONE;

  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	  ("RecFileSecRecRead FE 0x%lx %d 0x%lx 0x%lx\n",
	   (unsigned long )rec, version,
	   (unsigned long )fP, (unsigned long)eMsg));
  switch(version)
  {
    case 1:
      RecSecRecSetDefaults(rec);
      break;
    case 2:
      RecSecRecSetDefaults(rec);
      while(((bibErrFlag = BibFileRecordRead(&rcRecord, &bibErrMsg,
					     fP)) == BIBFILE_ER_NONE) &&
	    rcRecord && rcRecord->name &&
	    strcmp(rcRecord->name, "Reconstruction"))
      {
	if(lastRecord)
	{
	  BibFileRecordFree(&lastRecord);
	}
	lastRecord = rcRecord;
      }
      if(bibErrMsg)
      {
	AlcFree(bibErrMsg);
      }
      if(bibErrFlag != BIBFILE_ER_NONE)
      {
        errFlag = REC_ERR_READ;
      }
      else
      {
        if(rcRecord && rcRecord->name && rcRecord->field &&
	   (BibFileFieldParseFmt(rcRecord->field,
				 &fileS, "%s", "File",
				 &formatS, "%s", "Format",
				 &(rec->gaussFlt), "%d", "Filter",
				 &(rec->fastSam), "%d", "FastSampling",
				 &(rec->intScale), "%d", "IntScale",
				 &(rec->greedy), "%d", "Greedy",
				 &scaleS, "%s", "Scale",
				 &(rec->matchHst), "%d", "MatchHistograms",
				 &(rec->matchSec), "%d", "MatchSection",
				 &(rec->clipSrc), "%d", "ClipSrc",
				 &srcBoxS, "%s", "SrcBox",
				 &(rec->clipDst), "%d", "ClipDst",
				 &dstBoxS, "%s", "DstBox",
				 NULL) > 0))
	{
	  if(fileS)
	  {
	    rec->fileName = fileS;
	    fileS = NULL;
	  }
	  if(formatS)
	  {
	    if(errFlag == REC_ERR_NONE)
	    {
	      rec->fileFormat = WlzEffStringExtToFormat(formatS);
	      if(rec->fileFormat == WLZEFF_FORMAT_NONE)
	      {
		errFlag = REC_ERR_READ;
		(void )sprintf(errBuf,
			       "unsupported reconstruction file format %s.",
			       formatS);
	      }
	    }
	    AlcFree(formatS);
	  }
	  if(scaleS)
	  {
	    if(errFlag == REC_ERR_NONE)
	    {
	      if(sscanf(scaleS, "%lg %lg %lg",
			&(rec->scale.vtX), &(rec->scale.vtY),
			&(rec->scale.vtZ)) != 3)
	      {
		errFlag = REC_ERR_READ;
		(void )sprintf(errBuf,
			       "failed to parse reconstruction scale.");
	      }
	    }
	    AlcFree(scaleS);
	  }
	  if(srcBoxS)
	  {
	    if((errFlag == REC_ERR_NONE) && rec->clipSrc)
	    {
	      if(sscanf(srcBoxS, "%lg %lg %lg %lg %lg %lg",
	      		&(rec->srcBox.xMin), &(rec->srcBox.yMin),
			&(rec->srcBox.zMin), &(rec->srcBox.xMax),
			&(rec->srcBox.yMax), &(rec->srcBox.zMax)) != 6)
	      {
	        errFlag = REC_ERR_READ;
		(void )sprintf(errBuf,
			       "failed to parse reconstruction source box.");
	      }
	    }
	    AlcFree(srcBoxS);
	  }
	  if(dstBoxS)
	  {
	    if((errFlag == REC_ERR_NONE) && rec->clipDst)
	    {
	      if(sscanf(dstBoxS, "%lg %lg %lg %lg %lg %lg",
	      		&(rec->dstBox.xMin), &(rec->dstBox.yMin),
			&(rec->dstBox.zMin), &(rec->dstBox.xMax),
			&(rec->dstBox.yMax), &(rec->dstBox.zMax)) != 6)
	      {
	        errFlag = REC_ERR_READ;
		(void )sprintf(errBuf,
			       "failed to parse reconstruction source box.");
	      }
	    }
	    AlcFree(dstBoxS);
	  }
	}
      }
      if(rcRecord)
      {
	BibFileRecordFree(&rcRecord);
      }
      REC_DBG((REC_DBG_FILE|REC_DBG_LVL_2),
      	      ("RecFileSecRecRead 01 %d 0x%lx %s %d "
	       "%d %d %d %d "
	       "{%g %g %g} "
	       "%d %d "
	       "%d {%g %g %g %g %g %g} "
	       "%d {%g %g %g %g %g %g}\n",
	       errFlag, (unsigned long )(rec->obj),
	       (rec->fileName)? rec->fileName: "(null)", rec->fileFormat,
	       rec->gaussFlt, rec->fastSam, rec->intScale, rec->greedy,
	       rec->scale.vtX, rec->scale.vtY, rec->scale.vtZ,
	       rec->matchHst, rec->matchSec,
	       rec->clipSrc, rec->srcBox.xMin, rec->srcBox.yMin,
	       rec->srcBox.zMin, rec->srcBox.xMax,
	       rec->srcBox.yMax, rec->srcBox.zMax,
	       rec->clipDst, rec->dstBox.xMin, rec->dstBox.yMin,
	       rec->dstBox.zMin, rec->dstBox.xMax,
	       rec->dstBox.yMax, rec->dstBox.zMax));
      break;
    default:
      errFlag = REC_ERR_READ;
      (void )sprintf(errBuf,
		     "unsupported file version %d.",
		     version);
     break;
  }
  if((errFlag != REC_ERR_NONE) && (*eMsg == NULL))
  {
    *eMsg = AlcStrDup(errBuf);
  }
  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	  ("RecFileSecRecRead FX 0x%lx\n",
	   errFlag));
  return(errFlag);
}
Esempio n. 22
0
/*!
* \return	Error code.
* \ingroup	Reconstruct
* \brief	Reads the reconstruct section list attributes.
* \param	atrb			Section list attributres data 
* 					attributres to be filled in.
* \param	version			Version number.
* \param	fP			File pointer.
* \param	eMsg			Destination pointer for messages.
*/
static RecError	 RecFileSecAtrbRead(RecSectionListAtrb *atrb, int version,
				    FILE *fP, char **eMsg)
{

  BibFileRecord	*atRecord = NULL,
		*lastRecord = NULL;
  char		*trModeS = NULL,
  		*bibErrMsg = NULL;
  char		errBuf[256];
  BibFileError	bibErrFlag = BIBFILE_ER_NONE;
  RecError	errFlag = REC_ERR_NONE;

  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
  	  ("RecFileSecAtrbRead FE 0x%lx %d 0x%lx 0x%lx\n",
	   (unsigned long )atrb, version,
	   (unsigned long )fP, (unsigned long)eMsg));
  switch(version)
  {
    case 1:
      atrb->trMode = REC_TRMODE_REL;
      atrb->currentItem = NULL;
      break;
    case 2:
      atrb->currentItem = NULL;
      while(((bibErrFlag = BibFileRecordRead(&atRecord, &bibErrMsg,
					     fP)) == BIBFILE_ER_NONE) &&
	    atRecord && atRecord->name &&
	    strcmp(atRecord->name, "Attributes"))
      {
	if(lastRecord)
	{
	  BibFileRecordFree(&lastRecord);
	}
	lastRecord = atRecord;
      }
      if(bibErrMsg)
      {
	AlcFree(bibErrMsg);
      }
      if((bibErrFlag != BIBFILE_ER_NONE) ||
	 (atRecord == NULL) || (atRecord->name == NULL) ||
	 (atRecord->field == NULL) ||
	 ((BibFileFieldParseFmt(atRecord->field,
	 			&trModeS, "%s", "TransformMode",
				NULL) == 0)) ||
	 (trModeS == NULL) ||
         (WlzStringMatchValue((int *)&(atrb->trMode), trModeS,
		  recFileAtrbValueS[REC_FILE_SECATRB_REL], REC_TRMODE_REL,
		  recFileAtrbValueS[REC_FILE_SECATRB_ABS], REC_TRMODE_ABS,
		  NULL) == 0))
      {
	errFlag = REC_ERR_READ;
	(void )sprintf(errBuf,
		       "failed to read list attributes.");
      }
      if(trModeS)
      {
        AlcFree(trModeS);
      }
      if(atRecord)
      {
	BibFileRecordFree(&atRecord);
      }
      REC_DBG((REC_DBG_FILE|REC_DBG_LVL_2),
      	      ("RecFileSecAtrbRead 01 %d\n",
	       atrb->trMode));
      break;
    default:
      errFlag = REC_ERR_READ;
      (void )sprintf(errBuf,
		     "unsupported file version %d.",
		     version);
     break;
  }
  if((errFlag != REC_ERR_NONE) && (*eMsg == NULL))
  {
    *eMsg = AlcStrDup(errBuf);
  }
  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	  ("RecFileSecAtrbRead FX 0x%lx\n",
	   errFlag));
  return(errFlag);
}
Esempio n. 23
0
int		main(int argc, char *argv[])
{
  FILE		*inFile, *outFile;
  char 		optList[] = "hv";
  int		option;
  int		verboseFlg=0;
  WlzObject	*obj;
  WlzDomain	domain;
  WlzValues	values;
  WlzBoundList	*tmpBnd;
  char		*name;
  AlcDLPList	*bndDLPList;
  AlcDLPItem	*bndItem;
  NamedBndItem	*namedBndItem;
  int		noNameCntr=0;
  char		noNameBuf[32];

  /* read the argument list and check for an input file */
  opterr = 0;
  while( (option = getopt(argc, argv, optList)) != EOF ){
    switch( option ){

    case 'v':
      verboseFlg = 1;
      break;

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

    default:
      usage(argv[0]);
      return WLZ_ERR_UNSPECIFIED;
    }
  }

  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 XML file building boundary lists */
  /* quick fix read  - read until no new names */
  bndDLPList = AlcDLPListNew(NULL);
  name = NULL;
  while((name = getNextName(inFile)) != NULL){
    /* check for empty name */
    if( strcmp(name, " ") == 0 ){
      noNameCntr++;
      sprintf(noNameBuf, "NoName_%03d", noNameCntr);
      name = AlcStrDup(noNameBuf);
    }
    /* convert comma to underscore */
    tmpBnd = getNextBoundary(inFile);
    addToBndList(bndDLPList, name, tmpBnd);
  }

  /* write boundary lists */
  bndItem = bndDLPList->head;
  while( bndItem ){
    namedBndItem = (NamedBndItem *) bndItem->entry;
    name = (char *) AlcMalloc(sizeof(char)*(strlen(namedBndItem->name)+16));
    sprintf(name, "%s.wlz", namedBndItem->name);
    if((outFile = fopen(name, "w")) != NULL){
      domain.b = namedBndItem->bnd;
      values.core = NULL;
      obj = WlzMakeMain(WLZ_BOUNDLIST, domain, values, NULL, NULL, NULL);
      WlzWriteObj(outFile, obj);
      WlzFreeObj(obj);
      fclose(outFile);
    }
    AlcFree(name);
    bndItem = bndItem->next;
    if( bndItem == bndDLPList->head ){
      break;
    }
  }

  exit(0);
}
Esempio n. 24
0
WlzErrorNum WriteMAPaintRealignTransforms(
  FILE		*fp,
  WlzObject	*transformsObj,
  int		relFlg)
{
  WlzErrorNum	errNum=WLZ_ERR_NONE;
  int			i, p;
  WlzAffineTransformPrim prim;
  BibFileRecord	*record = NULL;
  BibFileField	*field0 = NULL;
  char		tmpBuf[256], *eMsg;
  char		*tmpS,
		*idxS = NULL,
		*dateS = NULL,
		*hostS = NULL,
		*userS = NULL,
                *fileS = NULL;
  char 		tTypeS[32],
		tTxS[32],
		tTyS[32],
		tTzS[32],
		tScaleS[32],
		tThetaS[32],
		tPhiS[32],
		tAlphaS[32],
		tPsiS[32],
		tXsiS[32],
		tInvertS[32];
  static char	unknownS[] = "unknown";
  char		*typeStr;
  time_t	tmpTime;

  /* run through the transform list writing a bibfile for each
     plane. Use correct plane numbers but do not define a
     file name (since its not known)
  */

  /* an identifier record - who, when, how */
  if( relFlg ){
    typeStr = "relative";
  }
  else {
    typeStr = "absolute";
  }
  if((((field0 = BibFileFieldMakeVa("Text",
				    "MAPaint realignment section file",
				    "Version", "1",
				    "TransformType", typeStr,
				    NULL)) == NULL) ||
      ((record = BibFileRecordMake("Ident", "0", field0)) == NULL)))
  {
    return WLZ_ERR_UNSPECIFIED;
  }
  BibFileRecordWrite(fp, &eMsg, record);
  BibFileRecordFree(&record);
  
  tmpS = getenv("USER");
  (void )sprintf(tmpBuf, "User: %s", tmpS?tmpS:unknownS);
  userS = AlcStrDup(tmpBuf);
  
  tmpTime = time(NULL);
  tmpS = ctime(&tmpTime);
  *(tmpS + strlen(tmpS) - 1) = '\0';
  (void )sprintf(tmpBuf, "Date: %s", tmpS?tmpS:unknownS);
  dateS = AlcStrDup(tmpBuf);
  
  tmpS = getenv("HOST");
  (void )sprintf(tmpBuf, "Host: %s", tmpS?tmpS:unknownS);
  hostS = AlcStrDup(tmpBuf);
  
  (void )sprintf(tmpBuf, "File: %s", unknownS);
  fileS = AlcStrDup(tmpBuf);
  
  if((((field0 = BibFileFieldMakeVa("Text", userS,
				    "Text", dateS,
				    "Text", hostS,
				    "Text", fileS,
				    NULL)) == NULL) ||
      ((record = BibFileRecordMake("Comment", "0", field0)) == NULL)))
  {
    return WLZ_ERR_UNSPECIFIED;
  }
  BibFileRecordWrite(fp, &eMsg, record);
  BibFileRecordFree(&record);
  AlcFree(dateS);
  AlcFree(hostS);
  AlcFree(userS);

  /* now the section records */
  if( transformsObj ){
    for(p=transformsObj->domain.p->plane1, i=0;
	(p <= transformsObj->domain.p->lastpl) && (errNum == WLZ_ERR_NONE);
	p++, i++){
      WlzAffineTransform  *transf=transformsObj->domain.p->domains[i].t;
      if( transf == NULL ){
	continue;
      }
      sprintf(tmpBuf, "%d", p);
      idxS = AlcStrDup(tmpBuf);

      errNum = WlzAffineTransformPrimGet(transf, &prim);
      if(errNum == WLZ_ERR_NONE)
      {
	(void )sprintf(tTypeS, "%d", transf->type);
	(void )sprintf(tTxS, "%g", prim.tx);
	(void )sprintf(tTyS, "%g", prim.ty);
	(void )sprintf(tTzS, "%g", prim.tz);
	(void )sprintf(tScaleS, "%g", prim.scale);
	(void )sprintf(tThetaS, "%g", prim.theta);
	(void )sprintf(tPhiS, "%g", prim.phi);
	(void )sprintf(tAlphaS, "%g", prim.alpha);
	(void )sprintf(tPsiS, "%g", prim.psi);
	(void )sprintf(tXsiS, "%g", prim.xsi);
	(void )sprintf(tInvertS, "%d", prim.invert);
	field0 = BibFileFieldMakeVa(
	  "TransformType", tTypeS,
	  "TransformTx", tTxS,
	  "TransformTy", tTyS,
	  "TransformTz", tTzS,
	  "TransformScale", tScaleS,
	  "TransformTheta", tThetaS,
	  "TransformPhi", tPhiS,
	  "TransformAlpha", tAlphaS,
	  "TransformPsi", tPsiS,
	  "TransformXsi", tXsiS,
	  "TransformInvert", tInvertS,
	  NULL);

	record = BibFileRecordMake("Section", idxS, field0);
	BibFileRecordWrite(fp, &eMsg, record);
	BibFileRecordFree(&record);
      }
      AlcFree(idxS);
    }
  }

  return errNum;
}
Esempio n. 25
0
/*!
* \return	Error code.
* \ingroup	Reconstruct
* \brief	Reads the body of a bibtex style list of section
*		transform records from the given file stream, parsing
*		them and building a linked list of sections.
* \param	secList			Section list.
* \param	numSec			Ptr for number of sections in
*					the list.
* \param	version			Version number.
* \param	fP			File pointer.
* \param	eMsg			Destination pointer for messages.
*/
static RecError	RecFileSecSecListRead(HGUDlpList *secList, int *numSec,
				      int version, FILE *fP, char **eMsg)
{
  int		doneFlag = 0,
		secCount = 0,
		recCount = 0;
  RecSection	*sec = NULL;
  RecError	errFlag = REC_ERR_NONE;
  char		errBuf[256];

  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecFileSecSecListRead FE 0x%lx 0x%lx %d 0x%lx 0x%lx\n",
	   (unsigned long )secList, (unsigned long )numSec,
	   version, (unsigned long )fP, (unsigned long )eMsg));
  if((secList == NULL) || (numSec == NULL))
  {
    errFlag = REC_ERR_FUNC;
  }
  if(errFlag == REC_ERR_NONE)
  {
    switch(version)
    {
      case 1: /* FALLTHROUGH */
      case 2:
	while((errFlag == REC_ERR_NONE) && (doneFlag == 0))
	{
	  if((sec = (RecSection *)AlcCalloc(1, sizeof(RecSection))) == NULL)
	  {
	    errFlag = REC_ERR_MALLOC;
	  }
	  if(errFlag == REC_ERR_NONE)
	  {
	    errFlag = RecFileSecRecordReadAndParse(sec, &doneFlag, &recCount,
						   fP, eMsg);
	  }
	  if((errFlag == REC_ERR_NONE) && (doneFlag == 0))
	  {
	    ++(sec->linkcount);
	    if(HGUDlpListAppend(secList, NULL, (void *)sec,
				(void (*)(void *) )RecSecFree) == NULL)
	    {
	      errFlag = REC_ERR_MALLOC; 		 /* May not be true! */
	    }
	    else
	    {
	      sec = NULL;
	      ++secCount;
	    }
	  }
	  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_2),
		  ("RecFileSecSecListRead 01 0x%lx %d %d %d\n",
		   (unsigned long )sec, secCount, doneFlag, errFlag));
	}
	if(((errFlag != REC_ERR_NONE) || doneFlag) && sec)
	{
	  RecSecFree(sec);
	}
	if((errFlag == REC_ERR_NONE) && (secCount < 2))
	{
	  errFlag = REC_ERR_READ;
	  (void )strcpy(errBuf,
			"at least two sections required in a section list.");
	}
	if(errFlag == REC_ERR_NONE)
	{
	  *numSec = secCount;
	}
	break;
      default:
	errFlag = REC_ERR_READ;
	(void )sprintf(errBuf,
		       "unsupported file version %d.",
		       version);
        break;
    }
  }
  if(errFlag != REC_ERR_NONE)
  {
    if(*eMsg == NULL)
    {
      *eMsg = AlcStrDup(errBuf);
    }
  }
  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_1),
	  ("RecFileSecSecListRead FX %d\n",
	   errFlag));
  return(errFlag);
}
Esempio n. 26
0
/*!
* \return	Error code.
* \ingroup	Reconstruct
* \brief	Reads the file identification to establish that this is
*		a valid  reconstruction file and that is's version
* 		number is reasonable.
* \param	version			Destination pinter for version number.
* \param	fP			File pointer.
* \param	eMsg			Destination pointer for messages.
*/
static RecError	RecFileSecIdentRead(int *version, FILE *fP, char **eMsg)
/*!
* \return	Error code.
* \ingroup	Reconstruct
* \brief
* \param	(REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2)
*/
{
  BibFileField	*idField,
		*vField;
  BibFileRecord	*idRecord = NULL,
		*lastRecord = NULL;
  const char	**idWord;
  char		*bibErrMsg = NULL,
		*idTok,
		*tmpPtr;
  char		errBuf[256];
  BibFileError	bibErrFlag = BIBFILE_ER_NONE;
  RecError	errFlag = REC_ERR_NONE;
  const int	versionMin = 1,
		versionMax = 2;
  const char   *fileIdent[] =
		{
		  "registration",
		  "section",
		  "file",
		  ""
		};

  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	  ("RecFileSecIdentRead FE 0x%lx 0x%lx 0x%lx\n",
	   (unsigned long )version, (unsigned long )fP,
	   (unsigned long )eMsg));
  while(((bibErrFlag = BibFileRecordRead(&idRecord, &bibErrMsg,
					 fP)) == BIBFILE_ER_NONE) &&
	idRecord && idRecord->name && idRecord->id &&
	strcmp(idRecord->name, "Ident"))
  {
    if(lastRecord)
    {
      BibFileRecordFree(&lastRecord);
    }
    lastRecord = idRecord;
  }
  if(bibErrMsg)
  {
    AlcFree(bibErrMsg);
  }
  if((bibErrFlag != BIBFILE_ER_NONE) ||
     (idRecord == NULL) ||
     (idRecord->name == NULL) || (idRecord->id == NULL) ||
     ((idField = idRecord->field) == NULL) ||
     (idField->name == NULL) || strcmp(idField->name, "Text") ||
     (idField->value  == NULL) ||
     ((vField = idField->next) == NULL) ||
     (vField->name == NULL) || strcmp(vField->name, "Version") ||
     (idField->value  == NULL))
  {
    errFlag = REC_ERR_READ;
  }
  if(errFlag == REC_ERR_NONE)
  {
    idWord = fileIdent;
    tmpPtr = idField->value;
    while((errFlag == REC_ERR_NONE) &&
	  idWord && *idWord && **idWord &&
	  ((idTok = strtok(tmpPtr, " \t")) != NULL) && *idTok)
    {
      if(strcmp(*idWord, idTok))
      {
	errFlag = REC_ERR_READ;
      }
      else
      {
        ++idWord;
	tmpPtr = NULL;
      }
    }
  }
  if(errFlag != REC_ERR_NONE)
  {
    (void )sprintf(errBuf,
		   "inappropriate file identification record.");
  }
  if(errFlag == REC_ERR_NONE)
  {
    idTok = strtok(vField->value, "\t\n");
    if((version == NULL) || (idTok == NULL) || (*idTok == '\0') ||
       (sscanf(idTok, "%d", version) != 1) ||
       (*version < versionMin) || (*version > versionMax))
    {
      errFlag = REC_ERR_READ;
      (void )sprintf(errBuf,
		     "unsupported file version %d, versions %d to %d only.",
		     *version, versionMin, versionMax);
    }
  }
  if(idRecord)
  {
    BibFileRecordFree(&idRecord);
  }
  if((errFlag != REC_ERR_NONE) && (*eMsg == NULL))
  {
    *eMsg = AlcStrDup(errBuf);
  }
  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	  ("RecFileSecIdentRead FX %d\n",
	   errFlag));
  return(errFlag);
}
Esempio n. 27
0
void referenceFileListCb(
  Widget	w,
  XtPointer	client_data,
  XtPointer	call_data)
{
  HGU_XmFileListCallbackStruct	*cbs=
    (HGU_XmFileListCallbackStruct *) client_data;
  WlzObject	*obj;
  Widget	cascade;
  WlzErrorNum	errNum=WLZ_ERR_NONE;

  HGU_XmSetHourGlassCursor(globals.topl);
  if( cbs == NULL ){
    /* clear list selection */
    HGU_XmFileListClearList(globals.fileList);
    HGU_XmFileListWriteResourceFile(globals.fileList,
				    globals.resourceFile);
    if((cascade = XtNameToWidget(globals.topl,
				 "*file_menu*_pulldown*Recent"))){
      HGU_XmFileListResetMenu(globals.fileList, cascade, referenceFileListCb);
    }
  }
  else if((obj = HGU_XmFileListReadObject(w, cbs, &errNum))){
    WlzDomain	domain;
    WlzValues	values;
    WlzObject	*newObj;

    switch( obj->type ){

    case WLZ_2D_DOMAINOBJ:
      if((domain.p = WlzMakePlaneDomain(WLZ_PLANEDOMAIN_DOMAIN, 0, 0,
					obj->domain.i->line1,
					obj->domain.i->lastln,
					obj->domain.i->kol1,
					obj->domain.i->lastkl,
					&errNum))){
	domain.p->domains[0] = WlzAssignDomain(obj->domain, NULL);
	if((values.vox = WlzMakeVoxelValueTb(WLZ_VOXELVALUETABLE_GREY,
					     0, 0, WlzGetBackground(obj, NULL),
					     NULL, &errNum))){
	  values.vox->values[0] = WlzAssignValues(obj->values, NULL);
	  newObj = WlzMakeMain(WLZ_3D_DOMAINOBJ, domain, values,
			       NULL, NULL, NULL);
	  WlzFreeObj(obj);
	  obj = newObj;
	}
      }
      globals.origObjType = WLZ_2D_DOMAINOBJ;
      break;

    case WLZ_3D_DOMAINOBJ:
      globals.origObjType = WLZ_3D_DOMAINOBJ;
      break;

    default:
      HGU_XmUserError(globals.topl,
		      "Read Reference Object:\n"
		      "    The reference object must be a 2- or 3-D\n"
		      "    grey-level image. Please select an alternate\n"
		      "    object",
		      XmDIALOG_FULL_APPLICATION_MODAL);
      WlzFreeObj( obj );
      /* set hour glass cursor */
      HGU_XmUnsetHourGlassCursor(globals.topl);
      return;
    }
    MAPaintLogData("ReferenceFile", refFileList[0], 0, NULL);
    install_paint_reference_object( obj );

    /* set the title of the top-level window */
    set_topl_title(cbs->file);
    globals.file = AlcStrDup(cbs->file);
    globals.origObjExtType = cbs->format;

    /* add to the file list and write file */
    HGU_XmFileListAddFile(globals.fileList, cbs->file, cbs->format);
    HGU_XmFileListWriteResourceFile(globals.fileList,
				    globals.resourceFile);
    if((cascade = XtNameToWidget(globals.topl,
				 "*file_menu*_pulldown*Recent"))){
      HGU_XmFileListResetMenu(globals.fileList, cascade, referenceFileListCb);
    }
  }

  HGU_XmUnsetHourGlassCursor(globals.topl);

  if( errNum != WLZ_ERR_NONE ){
    MAPaintReportWlzError(globals.topl, "ReferenceFileListCb", errNum);
  }
  return;
}
Esempio n. 28
0
/*!
* \return	Error code
* \ingroup	Reconstruct
* \brief	Writes the comments section of an output file.
* \param	fP			Output file.
* \param	eMsg			Destination pointer for messages.
*/
static RecError	RecFileSecCommentsWrite(FILE *fP, char **eMsg)
{
  time_t	tmpTime;
  char		*tmpS,
		*dateS = NULL,
		*hostS = NULL,
		*userS = NULL;
  BibFileRecord	*record = NULL;
  BibFileField	*field = NULL;
  char		tmpBuf[256];
  const char	unknownS[] = "unknown";
  RecError	errFlag = REC_ERR_NONE;

  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
  	  ("RecFileSecListCommentsWrite FE 0x%lx 0x%lx\n",
	   (unsigned long )fP, (unsigned long )eMsg));
  if(errFlag == REC_ERR_NONE)
  {
    tmpS = getenv("USER");
    (void )sprintf(tmpBuf, "User: %s", tmpS? tmpS: unknownS);
    if((userS = AlcStrDup(tmpBuf)) == NULL)
    {
      errFlag = REC_ERR_MALLOC;
    }
  }
  if(errFlag == REC_ERR_NONE)
  {
    tmpTime = time(NULL);
    tmpS = ctime(&tmpTime);
    *(tmpS + strlen(tmpS) - 1) = '\0';
    (void )sprintf(tmpBuf, "Date: %s", tmpS?tmpS:unknownS);
    if((dateS = AlcStrDup(tmpBuf)) == NULL)
    {
      errFlag = REC_ERR_MALLOC;
    }
  }
  if(errFlag == REC_ERR_NONE)
  {
    tmpS = getenv("HOST");
    (void )sprintf(tmpBuf, "Host: %s", tmpS?tmpS:unknownS);
    if((hostS = AlcStrDup(tmpBuf)) == NULL)
    {
      errFlag = REC_ERR_MALLOC;
    }
  }
  if((errFlag == REC_ERR_NONE) &&
     (((field = BibFileFieldMakeVa("Text", userS,
				   "Text", dateS,
				   "Text", hostS,
				   NULL)) == NULL) ||
       ((record = BibFileRecordMake("Comment", "0", field)) == NULL)))
  {
      errFlag = REC_ERR_MALLOC;
  }
  if((errFlag == REC_ERR_NONE) &&
     (BibFileRecordWrite(fP, eMsg, record) != BIBFILE_ER_NONE))
  {
    errFlag = REC_ERR_WRITE;
  }
  if(dateS)
  {
    AlcFree(dateS);
  }
  if(hostS)
  {
    AlcFree(hostS);
  }
  if(userS)
  {
    AlcFree(userS);
  }
  if(record)
  {
    BibFileRecordFree(&record);
  }
  else
  {
    BibFileFieldFree(&field);
  }
  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
  	  ("RecFileSecListCommentsWrite FX %d\n",
	   errFlag));
  return(errFlag);
}
Esempio n. 29
0
/*!
* \return	Woolz error code.
* \ingroup	WlzExtFF
* \brief	Parses the Amira file header filling in the fields
*		of the header structure. 
* \param	fP			Input file ready to read first
*					datum.
* \param	head			Pointer to an Amira file header
*					data structure.
*/
static WlzErrorNum WlzEffAmReadHead(FILE *fP, WlzEffAmHead *head)
{
  int		skip,
  		labelId,
  		done = 0;
  long		fRecPos;
  WlzEffAmDatType latDatType;
  int		tok[8];
  char		tokBuf[WLZ_EFF_AM_REC_MAXC];
  const int	tokBufMax = WLZ_EFF_AM_REC_MAXC;
  const char   	tokSepWS[] = " \t\n\r\f\v",
  	   	tokSepWSC[] = " \t\n,\r\f\v",
		tokSepWSQ[] = " \t\n\"\r\f\v";
  WlzErrorNum	errNum = WLZ_ERR_NONE;

  /* Read identifier, data format and version numbers. */
  errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
  if((errNum == WLZ_ERR_NONE) && strcmp(tokBuf, "#"))
  {
    errNum = WLZ_ERR_READ_INCOMPLETE;
  }
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
  }
  if((errNum == WLZ_ERR_NONE) && strcmp(tokBuf, "AmiraMesh"))
  {
    errNum = WLZ_ERR_READ_INCOMPLETE;
  }
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    tok[0] = WLZEFF_AM_DIM_NONE;
    head->dim = WLZEFF_AM_DIM_3;
    head->fmt = WLZEFF_AM_FMT_BINARY;
    head->endian = WLZEFF_AM_ENDIAN_BIG;
    (void )WlzStringMatchValue((int *)&(tok[0]), tokBuf,
			     "2D", WLZEFF_AM_DIM_2,
			     "3D", WLZEFF_AM_DIM_3,
			     "BINARY-BIG-ENDIAN", WLZEFF_AM_ENDIAN_BIG,
			     "BINARY-LITTLE-ENDIAN", WLZEFF_AM_ENDIAN_LITTLE,
			     NULL);
    switch(tok[0])
    {
      case WLZEFF_AM_DIM_2: /* FALLTHROUGH */
      case WLZEFF_AM_DIM_3:
	head->dim = tok[0];
        errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
	tok[0] = WLZEFF_AM_FMT_NONE;
	(void )WlzStringMatchValue((int *)&(tok[0]), tokBuf,
				   "ASCII", WLZEFF_AM_FMT_ASCII,
				   "BINARY", WLZEFF_AM_FMT_BINARY,
				   NULL);
	if(tok[0] == WLZEFF_AM_TOKEN_NONE)
	{
	  errNum = WLZ_ERR_READ_INCOMPLETE;
	}
	else
	{
	  head->fmt = tok[0];
	}
	if(errNum == WLZ_ERR_NONE)
	{
	  errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
	}
	if(errNum == WLZ_ERR_NONE)
	{
	  if(sscanf(tokBuf, "%d.%d",
		    &(head->versionMajor), &(head->versionMinor)) != 2)
	  {
	    errNum = WLZ_ERR_READ_INCOMPLETE;
	  }
	}
        break;
      case WLZEFF_AM_ENDIAN_BIG: /* FALLTHROUGH */
      case WLZEFF_AM_ENDIAN_LITTLE:
	head->endian = tok[0];
	errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
	if(errNum == WLZ_ERR_NONE)
	{
	  if(sscanf(tokBuf, "%d.%d",
	             &(head->versionMajor), &(head->versionMinor)) != 2)
          {
	    errNum = WLZ_ERR_READ_INCOMPLETE;
	  }
	}
        break;
      default:
        errNum = WLZ_ERR_READ_INCOMPLETE;
	break;
    }
  }
  /* Read rest of header. */
  while((errNum == WLZ_ERR_NONE) && (done == 0))
  {
    errNum = WlzEffAmSkip(fP, tokSepWS);
    fRecPos = ftell(fP);
    tok[0] = WLZEFF_AM_TOKEN_NONE;
    errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
    if(errNum == WLZ_ERR_NONE)
    {
      (void )WlzStringMatchValue((int *)&(tok[0]), tokBuf,
				 "#", WLZEFF_AM_TOKEN_HASH,
				 "define", WLZEFF_AM_TOKEN_DEFINE,
				 "Parameters", WLZEFF_AM_TOKEN_PARAMETERS,
				 "Lattice", WLZEFF_AM_TOKEN_LATTICE,
				 "Materials", WLZEFF_AM_TOKEN_MATERIALS,
				 NULL);
      switch(tok[0])
      {
	case WLZEFF_AM_TOKEN_HASH:
	  /* Comment. */
	  errNum = WlzEffAmSkipEOL(fP);
	  break;
	case WLZEFF_AM_TOKEN_DEFINE:
	  errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
	  if(errNum == WLZ_ERR_NONE)
	  {
	    tok[1] = WLZEFF_AM_TOKEN_NONE;
	    (void )WlzStringMatchValue((int *)&(tok[1]), tokBuf,
				       "Lattice", WLZEFF_AM_TOKEN_LATTICE,
				       NULL);
	    if(tok[1] == WLZEFF_AM_TOKEN_NONE)
	    {
	      errNum = WLZ_ERR_READ_INCOMPLETE;
	    }
	    else
	    {
	      errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
	    }
	    if(errNum == WLZ_ERR_NONE)
	    {
	      if(sscanf(tokBuf, "%d", &(head->latSize.vtX)) != 1)
	      {
		errNum = WLZ_ERR_READ_INCOMPLETE;
	      }
	    }
	    if(errNum == WLZ_ERR_NONE)
	    {
	      errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
	    }
	    if(errNum == WLZ_ERR_NONE)
	    {
	      if(sscanf(tokBuf, "%d", &(head->latSize.vtY)) != 1)
	      {
		errNum = WLZ_ERR_READ_INCOMPLETE;
	      }
	    }
	    if(errNum == WLZ_ERR_NONE)
	    {
	      errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf, tokBufMax);
	    }
	    if(errNum == WLZ_ERR_NONE)
	    {
	      if(sscanf(tokBuf, "%d", &(head->latSize.vtZ)) != 1)
	      {
		errNum = WLZ_ERR_READ_INCOMPLETE;
	      }
	    }
	  }
	  break;
	case WLZEFF_AM_TOKEN_PARAMETERS:
	  errNum = WlzEffAmReadAndCheckAToken(fP, tokSepWS, tokBuf, 
					      tokBufMax, "{");
	  /* Read parameters. */
	  do
	  {
	    errNum = WlzEffAmReadAToken(fP, tokSepWS, tokBuf,
	    			        tokBufMax);
	    if((errNum == WLZ_ERR_NONE) && strcmp(tokBuf, "}"))
	    {
              tok[1] = WLZEFF_AM_TOKEN_NONE;
	      (void )WlzStringMatchValue((int *)&(tok[1]), tokBuf,
			   "BoundingBox", WLZEFF_AM_TOKEN_BOUNDINGBOX,
			   "Colormap", WLZEFF_AM_TOKEN_COLORMAP,
			   "Content", WLZEFF_AM_TOKEN_CONTENT,
			   "CoordType", WLZEFF_AM_TOKEN_COORDTYPE,
			   "Expression", WLZEFF_AM_TOKEN_EXPRESSION,
			   "ImageData", WLZEFF_AM_TOKEN_IMAGEDATA,
			   "Materials", WLZEFF_AM_TOKEN_MATERIALS,
			   "Seeds", WLZEFF_AM_TOKEN_SEEDS,
			   "Limits", WLZEFF_AM_TOKEN_LIMITS,
			   "TIFF", WLZEFF_AM_TOKEN_TIFF,
			   "TransformationMatrix", WLZEFF_AM_TOKEN_TRANSFORM,
			   NULL);
	      switch(tok[1])
	      {
	        case WLZEFF_AM_TOKEN_BOUNDINGBOX:
		  errNum = WlzEffAmReadBBox(fP, tokBuf, tokBufMax,
					    &(head->bBox));
		  *tokBuf = '\0';
		  break;
	        case WLZEFF_AM_TOKEN_COLORMAP:
		  errNum = WlzEffAmSkipEOL(fP);
		  *tokBuf = '\0';
		  break;
	        case WLZEFF_AM_TOKEN_CONTENT:
		  errNum = WlzEffAmCheckContent(fP, tokBuf, tokBufMax);
		  *tokBuf = '\0';
		  break;
	        case WLZEFF_AM_TOKEN_COORDTYPE:
		  errNum = WlzEffAmReadCoordType(fP, tokBuf, tokBufMax,
		  				 &(head->coordType));
		  *tokBuf = '\0';
		  break;
	        case WLZEFF_AM_TOKEN_EXPRESSION:
		  errNum = WlzEffAmSkipEOL(fP);
		  *tokBuf = '\0';
		  break;
	        case WLZEFF_AM_TOKEN_MATERIALS:
		  errNum = WlzEffAmReadMaterials(fP, tokBuf, tokBufMax, head);
		  *tokBuf = '\0';
		  break;
		case WLZEFF_AM_TOKEN_IMAGEDATA:
		  errNum = WlzEffAmReadAToken(fP, tokSepWSQ, tokBuf,
		  			      tokBufMax);
		  if(errNum == WLZ_ERR_NONE)
		  {
		    errNum = WlzEffAmSkip(fP, tokSepWSQ);
		  }
		  if(errNum == WLZ_ERR_NONE)
		  {
		    if((head->imageData = AlcStrDup(tokBuf)) == NULL)
		    {
		      errNum = WLZ_ERR_MEM_ALLOC;
		    }
		  }
		  *tokBuf = '\0';
		  break;
		case WLZEFF_AM_TOKEN_SEEDS:
		  errNum = WlzEffAmReadAndSkipValues(fP, tokBuf, tokBufMax);
		  *tokBuf = '\0';
		  break;
		case WLZEFF_AM_TOKEN_LIMITS:
		  errNum = WlzEffAmReadAndSkipValues(fP, tokBuf, tokBufMax);
		  *tokBuf = '\0';
		  break;
		case WLZEFF_AM_TOKEN_TIFF:
		  errNum = WlzEffAmReadAndSkipValues(fP, tokBuf, tokBufMax);
		  *tokBuf = '\0';
		  break;
		case WLZEFF_AM_TOKEN_TRANSFORM:
		  errNum = WlzEffAmSkipEOL(fP);
		  *tokBuf = '\0';
		  break;
		default:
		  errNum = WLZ_ERR_READ_INCOMPLETE;
		  break;
	      }
	    }
	    if(errNum == WLZ_ERR_NONE)
	    {
	      errNum = WlzEffAmSkip(fP, tokSepWSC);
	    }
	  } while((errNum == WLZ_ERR_NONE) && strcmp(tokBuf, "}"));
	  break;
	case WLZEFF_AM_TOKEN_LATTICE:
	  errNum = WlzEffAmReadAndCheckAToken(fP, tokSepWS, tokBuf,
					      tokBufMax, "{");
	  /* Read lattice spec. */
	  if(errNum == WLZ_ERR_NONE)
	  {
	    errNum = WlzEffAmReadLatticeDatType(fP, tokBuf, tokBufMax,
	    					&latDatType);
	  }
	  if(errNum == WLZ_ERR_NONE)
	  {
	    errNum = WlzEffAmReadLatticeType(fP, tokBuf, tokBufMax,
					     &(head->latType), &skip);
	    if(skip == 0)
	    {
	      head->latDatType = latDatType;
	    }
	  }
	  if(errNum == WLZ_ERR_NONE)
	  {
	    errNum = WlzEffAmReadAndCheckAToken(fP, tokSepWS, tokBuf,
						tokBufMax, "}");
	  }
	  /* Read lattice label. */
	  if(errNum == WLZ_ERR_NONE)
	  {
	    errNum = WlzEffAmReadLatticeLabel(fP, tokBuf, tokBufMax, skip,
	    				      head);
	  }
	  break;
	case WLZEFF_AM_TOKEN_MATERIALS:
	  errNum = WlzEffAmReadMaterials(fP, tokBuf, tokBufMax, head);
	  break;
	default:
	  /* Check for label. */
	  if(sscanf(tokBuf, "@%d", &labelId) == 1)
	  {
	    /* Rewind back before label. */
	    if(fseek(fP, fRecPos, SEEK_SET) == -1)
	    {
	      errNum = WLZ_ERR_READ_INCOMPLETE;
	    }
	    else
	    {
	      done = 1;
	    }
	  }
	  break;
      }
    }
  }
  return(errNum);
}
Esempio n. 30
0
/*!
* \return	Error code.
* \ingroup	Reconstruct
* \brief	Writes the body of the section list to the given file.
* \param	fP			Output file.
* \param	secList			Section list to write.
* \param	numSec			Number of sections to write.
* \param	eMsg			Destination pointer for messages.
*/
static RecError	RecFileSecSecListWrite(FILE *fP, HGUDlpList *secList,
				       int numSec, char **eMsg)
{
  int		idx;
  char		*idxS = NULL,
		*itrS = NULL,
		*corS = NULL;
  RecSection 	*sec;
  HGUDlpListItem *secItem;
  BibFileRecord	*record = NULL;
  BibFileField	*field0 = NULL,
		*field1 = NULL,
		*field2 = NULL;
  char		tmpBuf[256];
  RecError	errFlag = REC_ERR_NONE;

  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	  ("RecFileSecListBodyWrite FE 0x%lx 0x%lx %d 0x%lx\n",
	   (unsigned long )fP, (unsigned long )secList,
	   numSec, (unsigned long )eMsg));
  idx = 0;
  secItem = HGUDlpListHead(secList);
  while((errFlag == REC_ERR_NONE) && (idx < numSec) && secItem &&
        ((sec = (RecSection *)HGUDlpListEntryGet(secList, secItem)) != NULL))
  {
    if((sprintf(tmpBuf, "%d", sec->index) <= 0) ||
       ((idxS = AlcStrDup(tmpBuf)) == NULL))
    {
      errFlag = REC_ERR_MALLOC;
    }
    if((errFlag == REC_ERR_NONE) &&
       ((sprintf(tmpBuf, "%d", sec->iterations) <= 0) ||
       ((itrS = AlcStrDup(tmpBuf)) == NULL)))
    {
      errFlag = REC_ERR_MALLOC;
    }
    if((errFlag == REC_ERR_NONE) &&
       ((sprintf(tmpBuf, "%1.7g", sec->correl) <= 0) ||
       ((corS = AlcStrDup(tmpBuf)) == NULL)))
    {
      errFlag = REC_ERR_MALLOC;
    }
    if((errFlag == REC_ERR_NONE) &&
       (((field0 = RecFileTransfToField(sec->transform)) == NULL) ||
        ((field1 = BibFileFieldMakeVa("Iterations", itrS,
				      "Correlation", corS,
			              "File", sec->imageFile,
			              NULL)) == NULL) ||
        ((field2 = BibFileFieldJoin(field1, field0, NULL)) == NULL) ||
        ((record = BibFileRecordMake("Section", idxS,
				     field2)) == NULL) ||
        (BibFileRecordWrite(fP, eMsg, record) != BIBFILE_ER_NONE)))
    {
      errFlag = REC_ERR_WRITE;
    }
    if(idxS)
    {
      AlcFree(idxS);
    }
    if(itrS)
    {
      AlcFree(itrS);
    }
    if(corS)
    {
      AlcFree(corS);
    }
    if(record)
    {
      BibFileRecordFree(&record);
    }
    else if(field2)
    {
      BibFileFieldFree(&field2);
    }
    else
    {
      BibFileFieldFree(&field0);
      BibFileFieldFree(&field1);
    }
    if(errFlag == REC_ERR_NONE)
    {
      secItem = HGUDlpListNext(secList, secItem);
    }
    ++idx;
  }
  REC_DBG((REC_DBG_FILE|REC_DBG_LVL_FN|REC_DBG_LVL_2),
	  ("RecFileSecListBodyWrite FX %d\n",
	   errFlag));
  return(errFlag);
}