\Header{panel.cloud}{Default Panel Function for cloud}
\alias{panel.3dscatter}{panel.cloud}
\alias{panel.3dwire}{panel.cloud}
\alias{panel.wireframe}{panel.cloud}
\keyword{dplot}{panel.cloud}
\begin{Description}\relax
These are default panel functions controlling \code{cloud} and
\code{wireframe} displays.
\end{Description}
\begin{Usage}
\begin{verbatim}
panel.cloud(
x, y, z, subscripts,
            groups = NULL,
            distance, xlim, ylim, zlim,
            panel.3d.cloud = "panel.3dscatter",
            panel.3d.wireframe = "panel.3dwire",
            rot.mat, aspect,
            par.box = NULL,
            xlab, ylab, zlab,
            xlab.default, 
            ylab.default,
            zlab.default,
            scales.3d,
            proportion = 0.6, wireframe = FALSE,
            scpos,
            ...,
            col.at,
            col.regions)
panel.wireframe(...)
panel.3dscatter(x, y, z, rot.mat, distance,
                groups, type = 'p',
                xlim.scaled, ylim.scaled, zlim.scaled,
                zero.scaled,
                col, col.point, col.line,
                lty, lwd, cex, pch,
                cross, ..., subscripts)
panel.3dwire(x, y, z, rot.mat, distance,
             col.at, col.regions,
             shade = FALSE,
             shade.colors = trellis.par.get("shade.colors")$palette,
             light.source = c(0, 0, 1000),
             xlim.scaled,
             ylim.scaled,
             zlim.scaled,
             col,
             col.groups = superpose.line$col,
             polynum = 100,
             ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, y, z}] numeric (or possibly factors) vectors representing the data to be
displayed. The interpretation depends on the context. For
\code{panel.cloud} these are essentially the same as the data passed
to the high level plot (except if \code{formula} was a matrix, the
appropriate \code{x, y} vectors are generated). By the time they are
passed to \code{panel.3dscatter} and \code{panel.3dwire}, they have
been scaled (to lie inside a bounding box, usually the [-0.5, 0.5]
cube).

Further, for \code{panel.3dwire}, \code{x} and \code{y} are shorter
than \code{z} and represent the sorted locations defining a
rectangular grid. Also in this case, \code{z} may be a matrix if the
display is grouped, with each column representing one surface.

In \code{panel.cloud} (called from \code{wireframe}) and
\code{panel.3dwire}, \code{x}, \code{y} and \code{z} could also be
matrices (of the same dimension) when they represent a 3-D surface
parametrized on a 2-D grid.

\item[\code{subscripts}] index specifying which points to draw. The same \code{x, y, z} values
(representing the whole data) are passed to \code{panel.cloud} for
each panel. \code{subscripts} specifies the subset of rows to be
used for the particular panel.

\item[\code{distance, par.box}] described in \code{\Link{cloud}} 
\item[\code{xlim, ylim, zlim}] limits for the respective axes. As with other lattice functions,
these could each be a numeric 2-vector or a character vector
indicating levels of a factor.

\item[\code{panel.3d.cloud, panel.3d.wireframe}] functions that draw the data-driven part of the plot (as opposed to
the bounding box and scales) in \code{cloud} and
\code{wireframe}. This function is called after the `back' of the
bounding box is drawn, but before the `front' is drawn.

Any user-defined custom display would probably want to change these
functions. The intention is to pass as much information to this
function as might be useful (not all of which are used by the
defaults). In particular, these functions can expect arguments
called \code{xlim}, \code{ylim}, \code{zlim} which give the bounding
box ranges in the original data scale and \code{xlim.scaled},
\code{ylim.scaled}, \code{zlim.scaled} which give the bounding box
ranges in the transformed scale. More arguments can be considered on
request.

\item[\code{aspect}] aspect as in \code{cloud} 
\item[\code{xlab, ylab, zlab}] Labels, have to be lists. Typically the user will not manipulate
these, but instead control this via arguments to \code{cloud}
directly.

\item[\code{xlab.default}] for internal use  
\item[\code{ylab.default}] for internal use  
\item[\code{zlab.default}] for internal use  
\item[\code{scales.3d}] list defining the scales 
\item[\code{proportion}] numeric scalar, gives the length of arrows as a proportion of the
sides

\item[\code{scpos}] A list with three components x, y and z (each a scalar integer),
describing which of the 12 sides of the cube the scales should be
drawn. The defaults should be OK. Valid values are x: 1, 3, 9, 11;
y: 8, 5, 7, 6 and z: 4, 2, 10, 12. (See comments in the source code
of \code{panel.cloud} to see the details of this enumeration.)

\item[\code{wireframe}] logical, indicating whether this is a wireframe plot
\item[\code{col.at, col.regions}] deals with specification of colors when \code{drape = TRUE} in
\code{\Link{wireframe}}

\item[\code{rot.mat}] 4x4 transformation matrix in homogeneous coordinates. This gives the
rotation matrix combining the \code{screen} and \code{R.mat}
arguments to \code{\Link{cloud}}

\item[\code{type}] character vector, specifying type of cloud plot. Can include one or
more of ``p'', ``l'', ``h'' or ``b''. ``p'' and ``l'' mean `points'
and `lines' respectively, and ``b'' means `both'. ``h'' stands for
`histogram', and causes a line to be drawn from each point to
the X-Y plane (i.e., the plane representing \code{z = 0}), or the
lower (or upper) bounding box face, whichever is closer.

\item[\code{xlim.scaled, ylim.scaled, zlim.scaled}] axis limits (after being scaled to the bounding box) 

\item[\code{zero.scaled}] z-axis location (after being scaled to the bounding box) of the X-Y
plane in the original data scale, to which lines will be dropped (if
within range) from each point when \code{type = 'h'}

\item[\code{cross}] logical, defaults to \code{TRUE} if \code{pch='+'}.
\code{panel.3dscatter} can represent each point by a 3d `cross' of
sorts (it's much easier to understand looking at an example than
from a description). This is different from the usual \code{pch}
argument, and reflects the depth of the points and the orientation
of the axes. This argument indicates whether this feature will be
used.

This is useful for two reasons. It can be set to \code{FALSE} to use
`+' as the plotting character in the regular sense. It can also be
used to force this feature in grouped displays.

\item[\code{groups}] specification of a grouping variable, passed down from the high
level functions.

\item[\code{shade}] logical, indicating whether the surface is to be colored using an
illumination model with a single light source

\item[\code{shade.colors}] a function (or the name of one) that is supposed to calculate the
color of a facet when shading is being used. Three pieces of
information is available to the function: first, the cosine of the
angle between the incident light ray and the normal to the surface
(representing foreshortening); second, the cosine of half the angle
between the reflected ray and the viewing direction (useful for
non-lambertian surfaces); and third, the scaled (average) height of
that particular facet with respect to the total plot z-axis limits.

All three numbers should be between 0 and 1. The \code{shade.colors}
function should return a valid color. The default function is
obtained from the Lattice settings.

\item[\code{light.source}] a 3-vector representing (in cartesian coordinates) the light
source. This is relative to the viewing point being (0, 0,
1/distance) (along the positive z-axis), keeping in mind that all
observations are bounded within the [-0.5, 0.5] cube

\item[\code{polynum}] quadrilateral faces are drawn in batches of \code{polynum} at a
time. Drawing too few at a time increases the total number of calls
to the underlying \code{grid.polygon} function, which affects
speed. Trying to draw too many at once may be unnecessarily memory
intensive. This argument controls the trade-off.

\item[\code{col.groups}] colors for different groups
\item[\code{col, col.point, col.line, lty, lwd, cex, pch}] graphical parameters
\item[\code{...}] other parameters, passed down when appropriate
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
These functions together are responsible for the content drawn inside
each panel in \code{cloud} and
\code{wireframe}. \code{panel.wireframe} is a wrapper to
\code{panel.cloud}, which does the actual work.

\code{panel.cloud} is responsible for drawing the content that does
not depend on the data, namely, the bounding box, the arrows/scales,
etc. At some point, depending on whether \code{wireframe} is TRUE, it
calls either \code{panel.3d.wireframe} or \code{panel.3d.cloud}, which
draws the data-driven part of the plot.

The arguments accepted by these two functions are different, since
they have essentially different purposes. For cloud, the data is
unstructured, and \code{x, y, z} are all passed to the
\code{panel.3d.cloud} function. For wireframe, on the other hand,
\code{x} and \code{y} are increasing vectors with unique values,
defining a rectangular grid. \code{z} must be a matrix with
\code{length(x) * length(y)} rows, and as many columns as the number
of groups.

\code{panel.3dscatter} is the default \code{panel.3d.cloud} function.
It has a \code{type} argument similar to \code{\Link{panel.xyplot}},
and supports grouped displays. It tries to honour depth ordering,
i.e., points and lines closer to the camera are drawn later,
overplotting more distant ones. (Of course there is no absolute
ordering for line segments, so an ad hoc ordering is used. There is no
hidden point removal.)

\code{panel.3dwire} is the default \code{panel.3d.wireframe}
function. It calculates polygons corresponding to the facets one by
one, but waits till it has collected information about \code{polynum}
facets, and draws them all at once. This avoids the overhead of
drawing \code{grid.polygon} repeatedly, speeding up the rendering
considerably. If \code{shade = TRUE}, these attempt to color the
surface as being illuminated from a light source at
\code{light.source}. \code{palette.shade} is a simple function that
provides the deafult shading colors

Multiple surfaces are drawn if \code{groups} is non-null in the call
to \code{wireframe}, however, the algorithm is not sophisticated
enough to render intersecting surfaces correctly.
\end{Details}
\begin{Author}\relax
Deepayan Sarkar \email{deepayan@stat.wisc.edu}
\end{Author}
\begin{SeeAlso}\relax
\code{\Link{cloud}}
\end{SeeAlso}

