/*******************************************************************************
*
* McXtrace, x-ray tracing package
*         Copyright, All rights reserved
*         DTU Physics, Kgs. Lyngby, Denmark
*         Synchrotron SOLEIL, Saint-Aubin, France
*
* Component: Shape
*
* %I
* Written by: E. Farhi
* Date: June 23rd 2009
* Origin: ILL
* Modified by: E. Farhi, based on Incoherent
*
* A geometric shape without effect on X-rays, for instrument display purpose.
*
* %D
* An inactive geometrical shape, for drawing purposes only.
* It does not propagate x-ray, nor interact.
* <b>Shape:</b>
* Geometric shape may be a cylinder, a sphere, a box or any other shape
*   box/plate:       xwidth x yheight x zdepth (thickness=0)
*   hollow box/plate:xwidth x yheight x zdepth and thickness>0
*   cylinder:        radius x yheight (thickness=0)
*   hollow cylinder: radius x yheight and thickness>0
*   sphere:          radius (yheight=0 thickness=0)
*   any shape:       geometry=OFF file
*
*   The complex geometry option handles any closed non-convex polyhedra.
*   It computes the intersection points of the X-ray with the object
*   transparently, so that it can be used like a regular sample object.
*   It supports the OFF and NOFF file format but not COFF (colored faces).
*   Such files may be generated from XYZ data using qhull/powercrust, and
*   viewed with geomview
*   The default size of the object depends of the OFF file data, but its
*   bounding box may be resized using xwidth,yheight and zdepth.
*
* Example: Shape(radius=0.05, yheight=0.1)
*          Shape(geometry="socket.off")
*
* %P
* INPUT PARAMETERS:
* radius:     [m]  Outer radius of sample in (x,z) plane 
* xwidth:     [m]  Horiz. dimension of sample (bounding box if off file), as a width 
* yheight:    [m]  Vert.  dimension of sample (bounding box if off file), as a height. A sphere shape is used when 0 and radius is set 
* zdepth:     [m]  Depth of sample (bounding box if off file) 
* thickness:  [m]  Thickness of hollow box or cylinder (spheres are drawn solid)
* geometry: [str]  Name of an Object File Format (OFF) file for complex geometry. The OFF file may be generated from XYZ coordinates using qhull/powercrust 
* center:     [1]  Flag to determine if OFF object is centered on its centre of mass.
* nx:         [1]  x-comp of orientation vector
* ny:         [1]  y-comp of orientation vector
* nz:         [1]  z-comp of orientation vector
*
* %L
* Geomview and Object File Format (OFF) <http|://www.geomview.org>
* %L
* Powercrust/qhull <http://www.cs.utexas.edu/users/amenta/powercrust>
*
* %E
*******************************************************************************/

DEFINE COMPONENT Shape

SETTING PARAMETERS (string geometry=0, radius=0, xwidth=0, yheight=0, zdepth=0, thickness=0, nx=0, ny=1, nz=0, int center=1)

SHARE
%{
%include "read_table-lib"
%include "interoff-lib"
%}

DECLARE
%{
  off_struct offdata;
%}

INITIALIZE
%{
  if (geometry && strlen (geometry) && strcmp (geometry, "NULL") && strcmp (geometry, "0")) {
    if (off_init (geometry, xwidth, yheight, zdepth, !center, &offdata)) {
      thickness = 0;
    }
  }
%}


TRACE %{
  /* component Shape does nothing */
%}

MCDISPLAY
%{
  if (geometry && strlen (geometry) && strcmp (geometry, "NULL") && strcmp (geometry, "0")) { /* OFF file */
    off_display (offdata);
  } else if (radius > 0 && yheight) { /* cylinder along y*/
    cylinder (0, 0, 0, radius, yheight, thickness, nx, ny, nz);
  } else if (xwidth && yheight) { /* box/rectangle */
    box (0, 0, 0, xwidth, yheight, zdepth, thickness, nx, ny, nz);
  } else if (radius > 0 && !yheight) { /* sphere */
    sphere (0, 0, 0, radius);
  }
%}
END
