Пример #1
0
/*!
* \return       New 3D domain object with values or NULL on error.
* \ingroup      LibWlzBnd
* \brief        Wrapper avoiding pixel type for WlzMakeCuboid() which
* 		creates a 3D domain object with values, for which the
*               domain is a cuboid and the values are of the given
*               type and initialized to have given double background value.
*               See also WlzMakeCuboidD().
* \param        plane1                  First plane.
* \param        lastpl                  Last plane.
* \param        line1                   First line.
* \param        lastln                  Last line.
* \param        kol1                    First column.
* \param        lastkl                  Last column.
* \param        pixType                 Pixel type for the grey values. If
*                                       WLZ_GREY_ERROR is given then no values
*                                       are created.
* \param        bgd                     Double background value.
* \param        plist                   Property list to be attached.
* \param        assocObj                Associated object.
* \param        dstErr                  Destination error pointer, may be NULL.
*/
WlzObject			*WlzMakeCuboidD(
				  int plane1,
				  int lastpl,
				  int line1,
				  int lastln,
				  int kol1,
				  int lastkl,
				  WlzGreyType pixType,
				  double bgd,
				  WlzPropertyList *plist,
				  WlzObject *assocObj,
				  WlzErrorNum *dstErr)
{
  WlzObject	*obj = NULL;
  WlzPixelV	bgdV;

  bgdV.type = WLZ_GREY_DOUBLE;
  bgdV.v.dbv = bgd;
  obj = WlzMakeCuboid(plane1, lastpl, line1, lastln, kol1, lastkl,
                      pixType, bgdV, plist, assocObj, dstErr);
  return(obj);
}
Пример #2
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;
}
Пример #3
0
/*!
* \return	New Woolz object or NULL on error.
* \ingroup	WlzExtFF
* \brief	Reads a Woolz object from the given stream using the
*		ANALYZE 7.5 format. The given file name is used to
*		generate the '.hdr' and '.img' filenames.
* \param	gvnFileName		Given file name.
* \param	dstErr			Destination error code, may be NULL.
*/
WlzObject	*WlzEffReadObjAnl(const char *gvnFileName, WlzErrorNum *dstErr)
{
  int		idx,
  		timePoints = 0;
  FILE		*fP = NULL;
  char		*fileName = NULL,
  		*hdrFileName = NULL,
		*imgFileName = NULL;
  WlzVertex	org,
  		sz;
  WlzEffAnlDsr 	dsr;
  int 		swap = 0;
  WlzObject	*obj = NULL;
  WlzGreyType	gType = WLZ_GREY_ERROR;
  WlzPixelV	bgdV;
  WlzErrorNum	errNum = WLZ_ERR_NONE;

  sz.i3.vtX = sz.i3.vtY = sz.i3.vtZ = 0;
  /* Compute .hdr and .img file names. */
  if((gvnFileName == NULL) || (*gvnFileName == '\0'))
  {
    errNum = WLZ_ERR_PARAM_NULL;
  }
  else
  {
    errNum = WlzEffAnlFileNames(&fileName, &hdrFileName, &imgFileName,
				gvnFileName);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    if((hdrFileName == NULL) || (*hdrFileName == '\0') ||
       ((fP = fopen(hdrFileName, "r")) == NULL))
    {
      errNum = WLZ_ERR_READ_EOF;
    }
#ifdef _WIN32
    else
    {
      if(fP != NULL)
      {
	if(_setmode(_fileno(fP), 0x8000) == -1)
	{
	  errNum = WLZ_ERR_READ_EOF;
	}
      }
    }
#endif
  }
  /* Read the .hdr (header) file. */
  if(errNum == WLZ_ERR_NONE)
  {
    (void )memset((void *)&dsr, 0, sizeof(WlzEffAnlDsr));
    errNum = WlzEffReadAnlHdrKey(fP, &dsr, &swap);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzEffReadAnlHdrImageDim(fP, &dsr, swap);
  }
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzEffReadAnlHdrDataHistory(fP, &dsr, swap);
  }
  if(fP)
  {
    (void )fclose(fP);
    fP = NULL;
  }
  /* Check header data is valid. */
  if(errNum == WLZ_ERR_NONE)
  {
    if('r' != dsr.hk.regular)
    {
      errNum = WLZ_ERR_OBJECT_DATA;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    switch(dsr.dim.bitPix)
    {
      case 8:  /* FALLTHROUGH */
      case 16: /* FALLTHROUGH */
      case 32: /* FALLTHROUGH */
      case 64:
        break;
      case 1:
      default:
        errNum = WLZ_ERR_OBJECT_DATA;
	break;
    }
  }
  /* Compute the image parameters. */
  if(errNum == WLZ_ERR_NONE)
  {
    switch(dsr.dim.dataType)
    {
      case WLZEFF_ANL_DT_UNSIGNED_CHAR:
        gType = WLZ_GREY_UBYTE;
	bgdV.type = gType;
	bgdV.v.ubv = 0;
	break;
      case WLZEFF_ANL_DT_SIGNED_SHORT:
        gType = WLZ_GREY_SHORT;
	bgdV.type = gType;
	bgdV.v.shv = 0;
	break;
      case WLZEFF_ANL_DT_SIGNED_INT:
        gType = WLZ_GREY_INT;
	bgdV.type = gType;
	bgdV.v.inv = 0;
	break;
      case WLZEFF_ANL_DT_FLOAT:
        gType = WLZ_GREY_FLOAT;
	bgdV.type = gType;
	bgdV.v.flv = 0.0;
	break;
      case WLZEFF_ANL_DT_DOUBLE:
        gType = WLZ_GREY_DOUBLE;
	bgdV.type = gType;
	bgdV.v.dbv = 0.0;
	break;
      default:
	errNum = WLZ_ERR_GREY_TYPE;
	break;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    switch(dsr.dim.dim[0])
    {
      case 2:
	org.i2.vtX = 0;
	org.i2.vtY = 0;
	sz.i2.vtX = dsr.dim.dim[1];
	sz.i2.vtY = dsr.dim.dim[2];
	timePoints = 1;
	if((sz.i2.vtX < 1) || (sz.i2.vtY < 1))
	{
	  errNum = WLZ_ERR_OBJECT_DATA;
	}
	break;
      case 3:
        org.i3.vtX = 0;
	org.i3.vtY = 0;
	org.i3.vtZ = 0;
	sz.i3.vtX = dsr.dim.dim[1];
	sz.i3.vtY = dsr.dim.dim[2];
	sz.i3.vtZ = dsr.dim.dim[3];
	if((sz.i3.vtX < 1) || (sz.i3.vtY < 1) || (sz.i3.vtZ < 1))
	{
	  errNum = WLZ_ERR_OBJECT_DATA;
	}
        break;
      case 4:
        org.i3.vtX = 0;
	org.i3.vtY = 0;
	org.i3.vtZ = 0;
	sz.i3.vtX = dsr.dim.dim[1];
	sz.i3.vtY = dsr.dim.dim[2];
	sz.i3.vtZ = dsr.dim.dim[3];
	timePoints = dsr.dim.dim[4];
	if((sz.i3.vtX < 1) || (sz.i3.vtY < 1) || (sz.i3.vtZ < 1) ||
	   (timePoints < 1))
	{
	  errNum = WLZ_ERR_OBJECT_DATA;
	}
        break;
      default:
	errNum = WLZ_ERR_OBJECT_DATA;
        break;
        
    }
  }
  /* Create object. */
  if(errNum == WLZ_ERR_NONE)
  {
    if(timePoints > 1)
    {
      obj = (WlzObject *)
            WlzMakeCompoundArray(WLZ_3D_DOMAINOBJ, 1, timePoints, NULL,
	                         WLZ_3D_DOMAINOBJ, &errNum);
      if(obj)
      {
        idx = 0;
	do
	{
	  ((WlzCompoundArray *)obj)->o[idx] = WlzAssignObject(
		WlzMakeCuboid(org.i3.vtZ, org.i3.vtZ + sz.i3.vtZ - 1,
			      org.i3.vtY, org.i3.vtY + sz.i3.vtY - 1,
			      org.i3.vtX, org.i3.vtX + sz.i3.vtX - 1,
			      gType, bgdV, NULL, NULL, &errNum), NULL);
	} while((++idx < timePoints) && (WLZ_ERR_NONE == errNum));
      }
    }
    else if(3 <= dsr.dim.dim[0])
    {
      obj = WlzMakeCuboid(org.i3.vtZ, org.i3.vtZ + sz.i3.vtZ - 1,
                          org.i3.vtY, org.i3.vtY + sz.i3.vtY - 1,
			  org.i3.vtX, org.i3.vtX + sz.i3.vtX - 1,
			  gType, bgdV, NULL, NULL, &errNum);
    }
    else /* 2 == dsr.dim.dim[0] */
    {
      obj = WlzMakeRect(org.i2.vtY, org.i2.vtY + sz.i2.vtY - 1,
			org.i2.vtX, org.i2.vtX + sz.i2.vtX - 1,
			gType, NULL, bgdV, NULL, NULL, &errNum);
    }
  }
  /* Open the .img (image data) file. */
  if(errNum == WLZ_ERR_NONE)
  {
    if((imgFileName == NULL) || (*imgFileName == '\0') ||
       ((fP = fopen(imgFileName, "r")) == NULL))
    {
      errNum = WLZ_ERR_READ_EOF;
    }
#ifdef _WIN32
    else
    {
      if(fP != NULL)
      {
	if(_setmode(_fileno(fP), 0x8000) == -1)
	{
	  errNum = WLZ_ERR_READ_EOF;
	}
      }
    }
#endif
  }
  /* Read the object values. */
  if(errNum == WLZ_ERR_NONE)
  {
    errNum = WlzEffReadAnlImgData(obj, gType, &dsr, fP, swap);
  }
  if(fP)
  {
    (void )fclose(fP);
  }
  (void )AlcFree(fileName);
  (void )AlcFree(hdrFileName);
  (void )AlcFree(imgFileName);
  if(errNum != WLZ_ERR_NONE)
  {
    (void )WlzFreeObj(obj);
    obj = NULL;
  }
  if(dstErr)
  {
    *dstErr = errNum;
  }
  return(obj);
}
Пример #4
0
int             main(int argc, char **argv)
{
  int		idx,
  		option,
		dim = 2,
		ok = 1,
		usage = 0;
  WlzIBox3	domBox;
  WlzPixelV	dumV;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  FILE		*fP = NULL;
  WlzObject	*obj = NULL;
  char 		*outFileStr;
  int		domVal[2];
  char		*domStr[2];
  const char	*errMsg;
  static char	optList[] = "23ho:x:y:z:",
		outFileStrDef[] = "-";

  opterr = 0;
  domBox.xMin = 0;
  domBox.xMax = 0;
  domBox.yMin = 0;
  domBox.yMax = 0;
  domBox.zMin = 0;
  domBox.zMax = 0;
  dumV.type = WLZ_GREY_UBYTE;
  dumV.v.ubv = 0;
  outFileStr = outFileStrDef;
  while((usage == 0) && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case '2':
        dim = 2;
	break;
      case '3':
        dim = 3;
	break;
      case 'o':
        outFileStr = optarg;
	break;
      case 'x':
      case 'y':
      case 'z':
	if(optarg)
	{
	  while(*optarg && isspace(*optarg))
	  {
	    ++optarg;
	  }
	  if(*optarg == ',')
	  {
	    domStr[0] = NULL;
	    domStr[1] = strtok(optarg, ",");
	  }
	  else
	  {
	    domStr[0] = strtok(optarg, ",");
	    domStr[1] = strtok(NULL, ",");
	  }
	  if((domStr[0] == NULL) && (domStr[1] == NULL))
	  {
	    usage = 1;
	    usage = 1;
	  }
	  else
	  {
	    idx = 0;
	    while((usage == 0) && (idx < 2))
	    {
	      if(domStr[idx] && (sscanf(domStr[idx], "%d",
					 domVal + idx) != 1))
	      {
		usage = 1;
		usage = 1;
	      }
	      ++idx;
	    }
	  }
	}
	if(usage == 0)
	{
	  switch(option)
	  {
	    case 'x':
	      if(domStr[0])
	      {
		domBox.xMin = domVal[0];
	      }
	      if(domStr[1])
	      {
		domBox.xMax = domVal[1];
	      }
	      break;
	    case 'y':
	      if(domStr[0])
	      {
		domBox.yMin = domVal[0];
	      }
	      if(domStr[1])
	      {
		domBox.yMax = domVal[1];
	      }
	      break;
	    case 'z':
	      dim = 3;
	      if(domStr[0])
	      {
		domBox.zMin = domVal[0];
	      }
	      if(domStr[1])
	      {
		domBox.zMax = domVal[1];
	      }
	      break;
	  }
	}
	break;
      case 'h':
      default:
        usage = 1;
	break;
    }
  }
  if((usage == 0) &&
     ((outFileStr == NULL) || (*outFileStr == '\0')))
  {
    usage = 1;
  }
  if(ok && (optind != argc))
  {
    usage = 1;
  }
  ok = !usage;
  if(ok)
  {
    switch(dim)
    {
      case 2:
	obj = WlzMakeRect(domBox.yMin, domBox.yMax,
	                  domBox.xMin, domBox.xMax,
			  WLZ_GREY_ERROR, NULL, dumV, NULL, NULL,
			  &errNum);
        break;
      case 3:
	obj = WlzMakeCuboid(domBox.zMin, domBox.zMax,
			    domBox.yMin, domBox.yMax,
	                    domBox.xMin, domBox.xMax,
			    WLZ_GREY_ERROR, dumV, NULL, NULL,
			    &errNum);
        break;
      default:
        break;
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to make %s domain object (%s).\n",
		     *argv, (dim == 2)? "rectangular": "cuboid", errMsg);
    }
  }
  if(ok)
  {
    errNum = WLZ_ERR_WRITE_EOF;
    if(((fP = (strcmp(outFileStr, "-")?
              fopen(outFileStr, "w"): stdout)) == NULL) ||
       ((errNum = WlzWriteObj(fP, obj)) != WLZ_ERR_NONE))
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
      		     "%s: failed to write domain object (%s).\n",
		     *argv, errMsg);
    }
    if(fP && strcmp(outFileStr, "-"))
    {
      fclose(fP);
    }
  }
  if(obj)
  {
    WlzFreeObj(obj);
  }
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s%s%sExamples:\n%s%s%s%s%s%s",
    *argv,
    " [-23h] [-o<out object>]\n"
         "       [-x<x min>,<x max>] [-y<y min>,<y max>] [-z<z min>,<z max>]\n"
    "Makes a either a 2D or 3D domain object with either a rectanglar domain\n"
    "or a plane domain with rectangular domains. By default an object is\n"
    "created for a single 2D pixel at the origin and the output object is\n"
    "written to the standard output.\n"
    "Version: ",
    WlzVersion(),
    "\n"
    "Options:\n"
    "  -2  Create a 2D rectangular domain object (default).\n"
    "  -3  Create a 3D cuboid domain object.\n"
    "  -x  Column domain limits (default 0,0).\n"
    "  -y  Line domain limits (default 0,0).\n"
    "  -z  Plane domain limits (default 0,0 and makes the default dimension\n"
    "      3.\n",
    *argv,
    " -3\n"
    "A Single voxel object with origin (0,0,0) is written to the standard\n"
    "output.\n",
    *argv,
    " -x 1 -y 2\n"
    "A single pixel object with origin (1,2) is written to the standard\n"
    "output.\n",
    *argv,
    " -x5,8, -y4,7 -z3,6 -o dom.wlz\n"
    "A 3D domain object with planes from 3 to 6, lines from 4 to 7 and\n"
    "column from 5 to 8 is written to the file dom.wlz.\n");
  }
  return(!ok);
}
Пример #5
0
int             main(int argc, char **argv)
{
  int		dim = 3,
  		nSPts,
  		nIPts,
		nOPts,
		option,
		planeFlg = 0,
		planeIdx = 0,
		ok = 1,
		usage = 0;
  double	delta,
  		tau,
		sAlpha,
		iAlpha,
		oAlpha,
		iDist,
		oDist,
		samFac = 1.0;
  WlzObject 	*dObj = NULL;
  WlzBox	bBox0,
  		bBox1;
  WlzVertexP	sPts,
  		iPts,
		oPts;
  WlzPixelV	bgdV;
  WlzDomain	outDom;
  WlzValues	dumVal;
  WlzObject	*outObj = NULL;
  FILE		*fP = NULL;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  char 		*sFileStr,
  		*iFileStr,
  		*oFileStr,
		*outObjFileStr;
  const char    *errMsg;
  static char	optList[] = "h23o:S:I:O:a:b:c:d:e:D:M:T:X:",
		defFileStr[] = "-";

  bgdV.type = WLZ_GREY_DOUBLE;
  outDom.core = NULL;
  dumVal.core = NULL;
  sPts.v = iPts.v = oPts.v = NULL;
  /* Parse the command line. */
  opterr = 0;
  sFileStr = iFileStr = oFileStr = outObjFileStr = defFileStr;
  while(ok && ((option = getopt(argc, argv, optList)) != -1))
  {
    switch(option)
    {
      case '2':
        dim = 2;
	break;
      case '3':
        dim = 3;
	break;
      case 'o':
        outObjFileStr = optarg;
	break;
      case 'S':
        sFileStr = optarg;
	break;
      case 'I':
        iFileStr = optarg;
	break;
      case 'O':
        oFileStr = optarg;
	break;
      case 'a':
        if(sscanf(optarg, "%lg", &sAlpha) != 1)
	{
	  usage = 1;
	}
	break;
      case 'b':
        if(sscanf(optarg, "%lg", &iAlpha) != 1)
	{
	  usage = 1;
	}
	break;
      case 'c':
        if(sscanf(optarg, "%lg", &oAlpha) != 1)
	{
	  usage = 1;
	}
	break;
      case 'd':
        if(sscanf(optarg, "%lg", &iDist) != 1)
	{
	  usage = 1;
	}
	break;
      case 'e':
        if(sscanf(optarg, "%lg", &oDist) != 1)
	{
	  usage = 1;
	}
	break;
      case 'D':
        if(sscanf(optarg, "%lg", &delta) != 1)
	{
	  usage = 1;
	}
	break;
      case 'M':
        if(sscanf(optarg, "%lg", &samFac) != 1)
	{
	  usage = 1;
	}
	break;
      case 'T':
        if(sscanf(optarg, "%lg", &tau) != 1)
	{
	  usage = 1;
	}
	break;
      case 'X':
        if(sscanf(optarg, "%d", &planeIdx) != 1)
	{
	  usage = 1;
	}
	else
	{
	  planeFlg = 1;
	}
	break;
      case 'h':
      default:
        usage = 1;
	break;
    }
  }
  if(ok && (optind < argc))
  {
    usage = 1;
  }
  if((outObjFileStr == NULL) || (*outObjFileStr == '\0') ||
     (sFileStr == NULL) || (*sFileStr == '\0') ||
     (iFileStr == NULL) || (*iFileStr == '\0') ||
     (oFileStr == NULL) || (*oFileStr == '\0'))
  {
    usage = 1;
  }
  ok = ok && !usage;
  /* Read the surface, inside and outside points. */
  if(ok)
  {
    if(strcmp(sFileStr, "-"))
    {
      if((fP = fopen(sFileStr, "r")) == NULL)
      {
	ok = 0;
	errNum = WLZ_ERR_READ_EOF;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to open surface points file %s (%s).\n",
		       *argv, sFileStr, errMsg);
      }
    }
    else
    {
      fP = stdin;
    }
  }
  if(ok)
  {
    sPts = WlzCFPReadVtxArray(fP, dim, &nSPts, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	             "%s: failed to read points from file %s (%s).\n",
		     *argv, sFileStr, errMsg);
    }
  }
  if(fP)
  {
    if(strcmp(sFileStr, "-"))
    {
      (void )fclose(fP);
    }
    fP = NULL;
  }
  if(ok)
  {
    if(strcmp(sFileStr, "-"))
    {
      if((fP = fopen(iFileStr, "r")) == NULL)
      {
	ok = 0;
	errNum = WLZ_ERR_READ_EOF;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to open inside points file %s (%s).\n",
		       *argv, iFileStr, errMsg);
      }
    }
    else
    {
      fP = stdin;
    }
  }
  if(ok)
  {
    iPts = WlzCFPReadVtxArray(fP, dim, &nIPts, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	             "%s: failed to read points from file %s (%s).\n",
		     *argv, sFileStr, errMsg);
    }
  }
  if(fP)
  {
    if(strcmp(iFileStr, "-"))
    {
      (void )fclose(fP);
    }
    fP = NULL;
  }
  if(ok)
  {
    if(strcmp(sFileStr, "-"))
    {
      if((fP = fopen(oFileStr, "r")) == NULL)
      {
	ok = 0;
	errNum = WLZ_ERR_READ_EOF;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to open outside points file %s (%s).\n",
		       *argv, oFileStr, errMsg);
      }
    }
    else
    {
      fP = stdin;
    }
  }
  if(ok)
  {
    oPts = WlzCFPReadVtxArray(fP, dim, &nOPts, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	             "%s: failed to read points from file %s (%s).\n",
		     *argv, oFileStr, errMsg);
    }
  }
  if(fP)
  {
    if(strcmp(oFileStr, "-"))
    {
      (void )fclose(fP);
    }
    fP = NULL;
  }
  if(ok)
  {
    bgdV.v.dbv = oDist;
    bgdV.type = WLZ_GREY_DOUBLE;
    switch(dim)
    {
      case 2:
        errNum = WLZ_ERR_UNIMPLEMENTED;
	break;
      case 3:
	/* Compute ounding box of points. */
	bBox0.d3 = WlzBoundingBoxVtx3D(nSPts, sPts.d3, NULL);
	bBox1.d3 = WlzBoundingBoxVtx3D(nIPts, iPts.d3, NULL);
	bBox0.d3 = WlzBoundingBoxUnion3D(bBox0.d3, bBox1.d3);
	bBox1.d3 = WlzBoundingBoxVtx3D(nOPts, oPts.d3, NULL);
	bBox0.d3 = WlzBoundingBoxUnion3D(bBox0.d3, bBox1.d3);
	/* Create distance object that will be used to accumulate distance
	   values. If only a 2D contour is required then create a distance
	   object with a single plane. */
	dObj = WlzMakeCuboid((planeFlg)?
	                     planeIdx: (int )floor(bBox0.d3.zMin) - 2,
			     (planeFlg)?
			     planeIdx: (int )ceil(bBox0.d3.zMax) + 2,
			     (int )floor(bBox0.d3.yMin) - 2,
			     (int )ceil(bBox0.d3.yMax) + 2,
			     (int )floor(bBox0.d3.xMin) - 2,
			     (int )ceil(bBox0.d3.xMax) + 2,
			     WLZ_GREY_DOUBLE, bgdV,
			     NULL, NULL, &errNum);
	if((dObj == NULL) || (errNum != WLZ_ERR_NONE))
	{
	  ok = 0;
	  if(errNum == WLZ_ERR_NONE)
	  {
	    errNum = WLZ_ERR_MEM_ALLOC;
	  }
	  (void )WlzStringFromErrorNum(errNum, &errMsg);
	  (void )fprintf(stderr,
	  		 "%s: failed to allocate distance object (%s).\n",
			 *argv, errMsg);

	}
	/* Compute contour using given distance object. */
	outDom.ctr = WlzContourFromPoints(dObj, WLZ_VERTEX_D3,
					  nSPts, sPts, sAlpha,
					  nIPts, iPts, iDist, iAlpha,
					  nOPts, oPts, oDist, oAlpha,
					  delta, tau, samFac,
					  &errNum);
	WlzFreeObj(dObj);
	break;
    }
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
	             "%s: failed to compute contour from points (%s).\n",
		     *argv, errMsg);
    }
  }
  /* Compute the contour from the point sets. */
  if(ok)
  {
    outObj = WlzMakeMain(WLZ_CONTOUR, outDom, dumVal, NULL, NULL, &errNum);
    if(errNum != WLZ_ERR_NONE)
    {
      ok = 0;
      (void )WlzStringFromErrorNum(errNum, &errMsg);
      (void )fprintf(stderr,
                     "%s: Failed to create output woolz object (%s).\n",
                     argv[0], errMsg);
    }
    if(outObj)
    {
      outDom.core = NULL;
    }
  }
  /* Write out the contour object. */
  if(ok)
  {
    if(strcmp(outObjFileStr, "-"))
    {
      if((fP = fopen(outObjFileStr, "w")) == NULL)
      {
	ok = 0;
	errNum = WLZ_ERR_WRITE_EOF;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to open output object file %s (%s).\n",
		       *argv, outObjFileStr, errMsg);
      }
    }
    else
    {
      fP = stdout;
    }
    if(ok)
    {
      if((errNum = WlzWriteObj(fP, outObj)) != WLZ_ERR_NONE)
      {
	ok = 0;
	(void )WlzStringFromErrorNum(errNum, &errMsg);
	(void )fprintf(stderr,
		       "%s: failed to write output object to file %s (%s).\n",
		       *argv, outObjFileStr, errMsg);
      }
    }
    if(strcmp(outObjFileStr, "-"))
    {
      (void )fclose(fP);
    }
    fP = NULL;
  }
  AlcFree(sPts.v);
  AlcFree(iPts.v);
  AlcFree(oPts.v);
  (void )WlzFreeDomain(outDom);
  (void )WlzFreeObj(outObj);
  /* Tidy up and exit. */
  if(usage)
  {
    (void )fprintf(stderr,
    "Usage: %s%s",
    *argv,
    "WlzContourFromPoints [-h] [-2] [-3] [-o<out object>]\n"
    "                     [-S<surface points file>]\n"
    "                     [-I<inside points file>] [-O<outside points file>]\n"
    "                     [-a#] [-b#] [-c#] [-d#] [-e#] [-D#] [-M#] [-T#]\n"
    "                     [-X#]\n"
    "Options:\n"
    "  -h  Print this usage message.\n"
    "  -2  Points are 2D and contour is a curve in 2D.\n"
    "  -3  Points are 3D and contour is a surface in 3D.\n"
    "  -o  Output object file name.\n"
    "  -S  On surface points file.\n"
    "  -I  Inside points file.\n"
    "  -O  Outside points file.\n"
    "  -a  Surface points alpha value.\n"
    "  -b  Inside points alpha value.\n"
    "  -c  Outside points alpha value.\n"
    "  -d  Inside points distance value.\n"
    "  -e  Outside points distance value.\n"
    "  -D  Delta multiorder spline soothing value.\n"
    "  -M  Distance object sampling factor (can be used to reduce the\n"
    "      number of surface facets.)\n"
    "  -T  Tau multiorder spline soothing value.\n"
    "  -X  Plane for 2D contour from 3D point sets.\n"
    "Computes a contour from three point sets: inside; outside and on a\n"
    "surface.\n"
    "All points are given using the following ascii format:\n"
    "  <vertex x> <vertex y> [<vertex z>]\n");
  }
  return(!ok);
}