\name{rcell}
\alias{rcell}
\title{Simulate Baddeley-Silverman Cell Process}
\description{
  Generates a random point pattern, a simulated realisation of the
  Baddeley-Silverman cell process model. 
}
\usage{
 rcell(win=square(1), nx=NULL, ny=nx, \dots, dx=NULL, dy=dx,
       N=10, nsim=1, drop=TRUE)
}
\arguments{
  \item{win}{
    A window. 
    An object of class \code{\link[spatstat.geom]{owin}},
    or data in any format acceptable to \code{\link[spatstat.geom]{as.owin}()}.
  }
  \item{nx}{
    Number of columns of cells in the window.
    Incompatible with \code{dx}.
  }
  \item{ny}{
    Number of rows of cells in the window.
    Incompatible with \code{dy}.
  }
  \item{\dots}{Ignored.}
  \item{dx}{
    Width of the cells. Incompatible with \code{nx}.
  }
  \item{dy}{
    Height of the cells.
    Incompatible with \code{ny}.
  }
  \item{N}{
    Integer. Distributional parameter:
    the maximum number of random points in each cell.
    Passed to \code{\link[spatstat.random]{rcellnumber}}.
  }
  \item{nsim}{Number of simulated realisations to be generated.}
  \item{drop}{
    Logical. If \code{nsim=1} and \code{drop=TRUE} (the default), the
    result will be a point pattern, rather than a list 
    containing a point pattern.
  }
}
\value{
  A point pattern (an object of class \code{"ppp"})
  if \code{nsim=1}, or a list of point patterns if \code{nsim > 1}.
}
\details{ 
  This function generates a simulated realisation of the \dQuote{cell process}
  (Baddeley and Silverman, 1984), a random point process
  with the same second-order properties as the uniform Poisson process.
  In particular, the \eqn{K} function of this process is identical to
  the \eqn{K} function of the uniform Poisson process (aka Complete
  Spatial Randomness). The same holds for the pair correlation function
  and all other second-order properties.
  The cell process is a counterexample to the claim that the
  \eqn{K} function completely characterises a point pattern.
  
  A cell process is generated by dividing space into equal rectangular
  tiles. In each tile, a random number of random points is placed.
  By default, there are either \eqn{0}, \eqn{1} or \eqn{10} points,
  with probabilities \eqn{1/10}, \eqn{8/9} and \eqn{1/90}
  respectively. 
  The points within a tile are independent and uniformly distributed in
  that tile, and the numbers of points in different tiles are
  independent random integers. 

  The tile width is determined
  either by the number of columns \code{nx} or by the
  horizontal spacing \code{dx}.
  The tile height is determined
  either by the number of rows \code{ny} or by the
  vertical spacing \code{dy}. 
  The cell process is then generated in these tiles.
  The random numbers of points are generated by \code{\link[spatstat.random]{rcellnumber}}.

  Some of the resulting random points may lie outside the window \code{win}:
  if they do, they are deleted.
  The result is a point pattern inside the window \code{win}.
}
\seealso{
  \code{\link{rcellnumber}},
  \code{\link{rstrat}},
  \code{\link[spatstat.geom]{rsyst}},
  \code{\link{runifpoint}},
  \code{\link[spatstat.explore]{Kest}}
}
\examples{
  X <- rcell(nx=15)
  plot(X)
  if(require(spatstat.explore)) {
     plot(Kest(X))
  }
}
\references{
  Baddeley, A.J. and Silverman, B.W. (1984)
  A cautionary example on the use of second-order methods for analyzing
  point patterns. \emph{Biometrics} \bold{40}, 1089-1094.
}

\author{\adrian
  and \rolf
}
\keyword{spatial}
\keyword{datagen}
