Example #1
0
/*!
* \return	void
* \brief	Outputs the mesh and displaced mesh of the given mesh
*		transform as Postscript to the standard error output.
* \param	mObj			Given mesh transform object.
* \param	sObj			Source object.
* \param	dilObj			Dilated object.
* \param	outObj			Transformed object.
*/
static void	WlzCMeshOutputPS(WlzObject *mObj,
				 WlzObject *sObj, WlzObject *dilObj,
				 WlzObject *outObj)
{
  int		idE,
  		idN,
		useElm;
  double	scale;
  double	*dsp;
  WlzDVertex2	pos,
  		offset;
  WlzDVertex2	elmVx[3];
  WlzDBox2	bBox;
  WlzCMeshNod2D	*nod;
  WlzCMeshElm2D *elm;
  WlzCMesh2D	*mesh;
  WlzIndexedValues *ixv;
  WlzObject	*bObj = NULL;
  char		buf[100];

  (void )fprintf(stderr, "%%!\n"
			 "/Times-Courier findfont\n"
			 "1 scalefont\n"
			 "setfont\n"
  			 "1 setlinecap\n"
			 "1 setlinejoin\n"
			 "0.01 setlinewidth\n");
  if((mObj != NULL) && (mObj->type == WLZ_CMESH_2D) &&
     ((mesh = mObj->domain.cm2) != NULL) &&
     ((ixv = mObj->values.x) != NULL))
  {
    /* Compute the bounding box of the mesh transform. */
    bBox.xMin = bBox.yMin = DBL_MAX;
    bBox.xMax = bBox.yMax = DBL_MIN;
    for(idN = 0; idN < mesh->res.nod.maxEnt; ++idN)
    {
      nod = (WlzCMeshNod2D *)AlcVectorItemGet(mesh->res.nod.vec, idN);
      if(nod->idx >= 0)
      {
	if(nod->pos.vtX < bBox.xMin)
	{
	  bBox.xMin = nod->pos.vtX;
	}
	else if(nod->pos.vtX > bBox.xMax)
	{
	  bBox.xMax = nod->pos.vtX;
	}
	if(nod->pos.vtY < bBox.yMin)
	{
	  bBox.yMin = nod->pos.vtY;
	}
	else if(nod->pos.vtY > bBox.yMax)
	{
	  bBox.yMax = nod->pos.vtY;
	}
        dsp = (double *)WlzIndexedValueGet(ixv, idN);
	pos.vtX = nod->pos.vtX + dsp[0];
	pos.vtY = nod->pos.vtY + dsp[1];
	if(pos.vtX < bBox.xMin)
	{
	  bBox.xMin = pos.vtX;
	}
	else if(pos.vtX > bBox.xMax)
	{
	  bBox.xMax = pos.vtX;
	}
	if(pos.vtY < bBox.yMin)
	{
	  bBox.yMin = pos.vtY;
	}
	else if(pos.vtY > bBox.yMax)
	{
	  bBox.yMax = pos.vtY;
	}
      }
    }
    if(((pos.vtX = fabs(bBox.xMax - bBox.xMin)) > 1.0) &&
       ((pos.vtY = fabs(bBox.yMax - bBox.yMin)) > 1.0))
    {
      /* Compute scale and offset for an A4 page. */
      if((4.0 * pos.vtX) > (3.0 * pos.vtY))
      {
        scale = 500.0 / (bBox.xMax - bBox.xMin);
      }
      else
      {
        scale = 700.0 / (bBox.yMax - bBox.yMin);
      }
      offset.vtX = (bBox.xMin * scale) - 50;
      offset.vtY = (bBox.yMin * -scale) - 750;
      (void )fprintf(stderr, "255 0 0 setrgbcolor\n");
      for(idE = 0; idE < mesh->res.elm.maxEnt; ++idE)
      {
        elm = (WlzCMeshElm2D *)AlcVectorItemGet(mesh->res.elm.vec, idE);
	if(elm->idx >= 0)
	{
	  for(idN = 0; idN < 3; ++idN)
	  {
	    pos = elm->edu[idN].nod->pos;
	    elmVx[idN].vtX = (pos.vtX * scale) - offset.vtX;
	    elmVx[idN].vtY = (pos.vtY * -scale) - offset.vtY;
	  }
	  (void )fprintf(stderr,
			 "%g %g moveto "
			 "%g %g lineto "
			 "%g %g lineto "
			 "%g %g lineto "
			 "stroke\n",
			 elmVx[0].vtX, elmVx[0].vtY,
			 elmVx[1].vtX, elmVx[1].vtY,
			 elmVx[2].vtX, elmVx[2].vtY,
			 elmVx[0].vtX, elmVx[0].vtY);
	  WLZ_VTX_2_ADD3(pos, elmVx[0], elmVx[1], elmVx[2]);
	  WLZ_VTX_2_SCALE(pos, pos, 0.333333);
	  (void )sprintf(buf, "%d", elm->idx);
	  (void )fprintf(stderr,
			 "%g %g moveto "
			 "(%s) show\n",
			 pos.vtX, pos.vtY,
			 buf);
	}
      }
      (void )fprintf(stderr, "0 0 255 setrgbcolor\n");
      for(idE = 0; idE < mesh->res.elm.maxEnt; ++idE)
      {
        elm = (WlzCMeshElm2D *)AlcVectorItemGet(mesh->res.elm.vec, idE);
	if(elm->idx >= 0)
	{
	  /* Display only those elements that have all nodes inside the
	   * domain.  
	  useElm = ((elm->edg[0].nod->flags | elm->edg[1].nod->flags |
	             elm->edg[2].nod->flags) &
		    WLZ_CMESH_NOD_FLAG_OUTSIDE) == 0;
	  */
	  useElm = 1;
	  if(useElm)
	  {
	    for(idN = 0; idN < 3; ++idN)
	    {
	      pos = elm->edu[idN].nod->pos;
	      dsp = (double *)WlzIndexedValueGet(ixv, elm->edu[idN].nod->idx);
	      pos.vtX += dsp[0];
	      pos.vtY += dsp[1];
	      elmVx[idN].vtX = (pos.vtX * scale) - offset.vtX;
	      elmVx[idN].vtY = (pos.vtY * -scale) - offset.vtY;
	    }
	    (void )fprintf(stderr,
			   "%g %g moveto "
			   "%g %g lineto "
			   "%g %g lineto "
			   "%g %g lineto "
			   "stroke\n",
			   elmVx[0].vtX, elmVx[0].vtY,
			   elmVx[1].vtX, elmVx[1].vtY,
			   elmVx[2].vtX, elmVx[2].vtY,
			   elmVx[0].vtX, elmVx[0].vtY);
	    WLZ_VTX_2_ADD3(pos, elmVx[0], elmVx[1], elmVx[2]);
	    WLZ_VTX_2_SCALE(pos, pos, 0.333333);
	    (void )sprintf(buf, "%d", elm->idx);
	    (void )fprintf(stderr,
	    		   "%g %g moveto "
			   "(%s) show\n",
			   pos.vtX, pos.vtY,
			   buf);
	  }
	}
      }
      (void )fprintf(stderr, "0 255 0 setrgbcolor\n");
      if((bObj = WlzObjToBoundary(sObj, 1, NULL)) != NULL)
      {
        WlzBndOutputPS(bObj->domain.b, scale, offset);
      }
      (void )fprintf(stderr, "0 255 255 setrgbcolor\n");
      if((bObj = WlzObjToBoundary(dilObj, 1, NULL)) != NULL)
      {
        WlzBndOutputPS(bObj->domain.b, scale, offset);
      }
      (void )fprintf(stderr, "127 0 127 setrgbcolor\n");
      if((bObj = WlzObjToBoundary(outObj, 1, NULL)) != NULL)
      {
        WlzBndOutputPS(bObj->domain.b, scale, offset);
      }
      (void )fprintf(stderr, "showpage\n");
    }
  }
}
Example #2
0
/*!
* \return	Woolz error code.
* \ingroup	BinWlzApp
* \brief	Outputs a VTK tensor file from a conforming mesh object.
* \param	prog:			Program name.
* \param	inFileStr		Name of input file object was read
* 					from.
* \param	fP			Opened file.
* \param	obj			Given conforming mesh object.
*/
static WlzErrorNum WlzVTKTensorFromCMesh(char *prog, char *inFileStr,
					 FILE *fP, WlzObject *obj)
{
  int		idE,
		maxElm;
  WlzCMesh3D	*mesh;
  AlcVector	*elmVec;
  WlzIndexedValues *ixv;
  WlzErrorNum	errNum = WLZ_ERR_NONE;
  
  mesh = obj->domain.cm3;
  ixv = obj->values.x;
  elmVec = mesh->res.elm.vec;
  maxElm = mesh->res.elm.maxEnt;
  if(fprintf(fP,
	     "# vtk DataFile Version 1.0\n"
	     "Output from Woolz WLZ_CMESH_3D file %s via %s\n"
	     "ASCII\n"
	     "DATASET POLYDATA\n"
	     "POINTS %d float\n",
	     inFileStr, prog,  maxElm) <= 0)
  {
    errNum = WLZ_ERR_WRITE_INCOMPLETE;
  }
  if(errNum == WLZ_ERR_NONE)
  {
    for(idE = 0; idE < maxElm; ++idE)
    {
      WlzDVertex3 c;
      WlzCMeshElm3D *elm;
      WlzCMeshNod3D *nod[4];
      
      elm = (WlzCMeshElm3D *)AlcVectorItemGet(elmVec, idE);
      if(elm->idx >= 0)
      {
	nod[0] = WLZ_CMESH_ELM3D_GET_NODE_0(elm);
	nod[1] = WLZ_CMESH_ELM3D_GET_NODE_1(elm);
	nod[2] = WLZ_CMESH_ELM3D_GET_NODE_2(elm);
	nod[3] = WLZ_CMESH_ELM3D_GET_NODE_2(elm);
	c.vtX = 0.25 * (nod[0]->pos.vtX + nod[1]->pos.vtX + 
			nod[2]->pos.vtX + nod[3]->pos.vtX);
	c.vtY = 0.25 * (nod[0]->pos.vtY + nod[1]->pos.vtY + 
			nod[2]->pos.vtY + nod[3]->pos.vtY);
	c.vtZ = 0.25 * (nod[0]->pos.vtZ + nod[1]->pos.vtZ + 
			nod[2]->pos.vtZ + nod[3]->pos.vtZ);
      }
      else
      {
	WLZ_VTX_3_ZERO(c);
      }
      if(fprintf(fP,
		 "%f %f %f\n", c.vtX, c.vtY, c.vtZ) <= 0)
      {
	errNum = WLZ_ERR_WRITE_INCOMPLETE;
	break;
      }
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    if(fprintf(fP,
	       "POINT_DATA %d\n"
	       "TENSORS tensors float\n",
	       maxElm) <= 0)
    {
      errNum = WLZ_ERR_WRITE_INCOMPLETE;
    }
  }
  if(errNum == WLZ_ERR_NONE)
  {
    for(idE = 0; idE < maxElm; ++idE)
    {
      WlzCMeshElm3D *elm;

      elm = (WlzCMeshElm3D *)AlcVectorItemGet(elmVec, idE);
      if(elm->idx >= 0)
      {
	double *t;

	t = (double *)WlzIndexedValueGet(ixv, elm->idx);
	if(fprintf(fP,
		   "%f %f %f "
		   "%f %f %f "
		   "%f %f %f \n",
		   t[0], t[1], t[2],
		   t[3], t[4], t[5],
		   t[6], t[7], t[8]) <= 0)
	{
	  errNum = WLZ_ERR_WRITE_INCOMPLETE;
	  break;
	}
      }
      else
      {
	if(fprintf(fP,
		   "0 0 0\n"
		   "0 0 0\n"
		   "0 0 0\n\n") <= 0)
	errNum = WLZ_ERR_WRITE_INCOMPLETE;
	break;
      }
    }
  }
  return(errNum);
}