[Ptinpoly-commits] r11 - in pkg: . R data man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 19 04:15:05 CEST 2011


Author: jmaisog
Date: 2011-10-19 04:15:03 +0200 (Wed, 19 Oct 2011)
New Revision: 11

Added:
   pkg/R/pip2d.R
   pkg/data/comb.rda
   pkg/data/fractal.rda
   pkg/data/spiral.rda
   pkg/man/comb.Rd
   pkg/man/fractal.Rd
   pkg/man/pip2d.Rd
   pkg/man/spiral.Rd
Removed:
   pkg/data/triMesh.rda
   pkg/man/triMesh.Rd
Modified:
   pkg/DESCRIPTION
Log:
Added R script 'pip2d.R', which defines the R interface the user will interact with.
Added three 2D polygon example data sets: 'spiral.rda', 'comb.rda', and 'fractal.rda'.
Added documentation .Rd files for these new files.
Removed the complex polyhedron example data set.

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2011-10-18 00:54:42 UTC (rev 10)
+++ pkg/DESCRIPTION	2011-10-19 02:15:03 UTC (rev 11)
@@ -1,7 +1,7 @@
 Package: ptinpoly
 Title: Point-In-Polyhedron Test (2D and 3D)
 Version: 2.0
-Date: 2011-10-17
+Date: 2011-10-18
 Author: Jose M. Maisog, Yuan Wang, George Luta, Jianfei Liu
 Maintainer: Jose M. Maisog <bravas02 at gmail.com>
 Description: This library provides a function 'pip3d', which tests whether a point in 3D space is

Added: pkg/R/pip2d.R
===================================================================
--- pkg/R/pip2d.R	                        (rev 0)
+++ pkg/R/pip2d.R	2011-10-19 02:15:03 UTC (rev 11)
@@ -0,0 +1,32 @@
+pip2d = function(Vertices,Queries) {
+    # Output is a NUMERIC vector.
+
+    # Basic checks of Vertices input argument.
+    vertDims = dim(Vertices)
+    numColsV = vertDims[2]
+    if ( numColsV != 2 ) {
+        print("pip2d(): Number of columns in Vertices must be 2!")
+        return(as.vector(rep(-3,nrow(Queries))))
+    }
+
+    # Basic checks of Queries input argument.
+    querDims = dim(Queries)
+    numColsQ = querDims[2]
+    if ( numColsQ != 2 ) {
+        print("pip2d(): Number of columns in Queries must be 2!")
+        return(as.vector(rep(-6,nrow(Queries))))
+    }
+
+    # Invoke the ptinpoly C++ code (for convenience, it has
+    # the same name as this R function, but this wasn't necessary)
+    Output =.C("pip2d",
+        vts    = as.double(Vertices),
+        nVts   = as.integer(nrow(Vertices)),
+        qrs    = as.double(Queries),
+        nQrs   = as.integer(nrow(Queries)),
+        Result = as.vector(rep(0,nrow(Queries)),mode="integer")
+    )
+
+    # Return the Results data.
+    return(Output$Result)
+}

Added: pkg/data/comb.rda
===================================================================
(Binary files differ)


Property changes on: pkg/data/comb.rda
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: pkg/data/fractal.rda
===================================================================
(Binary files differ)


Property changes on: pkg/data/fractal.rda
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: pkg/data/spiral.rda
===================================================================
(Binary files differ)


Property changes on: pkg/data/spiral.rda
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Deleted: pkg/data/triMesh.rda
===================================================================
(Binary files differ)

Added: pkg/man/comb.Rd
===================================================================
--- pkg/man/comb.Rd	                        (rev 0)
+++ pkg/man/comb.Rd	2011-10-19 02:15:03 UTC (rev 11)
@@ -0,0 +1,29 @@
+\name{comb}
+\alias{comb}
+\docType{data}
+\title{
+Sample Data: Comb Polygon
+}
+\description{
+Sample data defining an enclosed comb 2D polygon.
+}
+\usage{data(comb)}
+\examples{
+# Load polygon.
+data(comb)
+
+# Plot the polygon.
+plot(rbind(comb,comb[1,]),type="l")
+
+# Generate 3333 random test points.
+set.seed(1902)
+n       <- 3333
+x1      <- rnorm(n) ; x2 <- rnorm(n)
+X       <- cbind(x1,x2)
+queries <- as.matrix(X)
+
+# Check whether test points are contained in the polygon.
+# Most of these points will lie outside the polygon.
+containment = pip2d(comb,queries);
+}
+\keyword{datasets}

Added: pkg/man/fractal.Rd
===================================================================
--- pkg/man/fractal.Rd	                        (rev 0)
+++ pkg/man/fractal.Rd	2011-10-19 02:15:03 UTC (rev 11)
@@ -0,0 +1,29 @@
+\name{fractal}
+\alias{fractal}
+\docType{data}
+\title{
+Sample Data: Fractal Polygon
+}
+\description{
+Sample data defining an enclosed fractal 2D polygon.
+}
+\usage{data(fractal)}
+\examples{
+# Load polygon.
+data(fractal)
+
+# Plot the polygon.
+plot(rbind(fractal,fractal[1,]),type="l")
+
+# Generate 3333 random test points.
+set.seed(1902)
+n       <- 3333
+x1      <- rnorm(n) ; x2 <- rnorm(n)
+X       <- cbind(x1,x2)
+queries <- as.matrix(X)
+
+# Check whether test points are contained in the polygon.
+# Most of these points will lie outside the polygon.
+containment = pip2d(fractal,queries);
+}
+\keyword{datasets}

Added: pkg/man/pip2d.Rd
===================================================================
--- pkg/man/pip2d.Rd	                        (rev 0)
+++ pkg/man/pip2d.Rd	2011-10-19 02:15:03 UTC (rev 11)
@@ -0,0 +1,76 @@
+\name{pip2d}
+\alias{pip2d}
+\title{
+Test for Point Containment in 2D Polygon
+}
+\description{
+Tests whether points are contained within a two-dimensional polygon.
+}
+\usage{pip2d(Vertices,Queries)}
+\arguments{
+    \item{Vertices}{N by 2 matrix containing the XY coordinates of N vertices of the polygon}
+    \item{Queries}{P by 2 matrix containing the XY coordinates of P points
+	to be tested for containment in the polygon defined by 'Vertices'}
+}
+\details{
+The XY coordinates of the vertices are stored \emph{in order} in the
+matrix \code{Vertices}. It is assumed that the last vertex listed in the matrix
+is connected to the first vertex, so that the polygon does not have a ''hole''.
+}
+\value{
+Returns a vector containing P values, one for each of the P points listed in
+the \code{Queries} matrix.
+
+'1' indicates that the point is contained in the polygon.
+
+'0' indicates that the point lies exactly on the surface of the polygon.
+
+'-1' indicates that the point lies outside the polygon.
+
+'-3' (error) indicates that the \code{Vertices} matrix didn't have two columns
+
+'-6' (error) indicates that the \code{Queries} matrix didn't have two columns
+
+'-8' (error) indicates computational error not otherwise specified
+}
+\note{
+The polygon defined by \code{Vertices} \emph{must} be "non-leaky";
+i.e., it must define an "inside" versus "outside" and must not contain any holes.
+}
+\references{
+W.P. Horn and D.L. Taylor, \emph{A theorem to determine the spatial containment of a point in a planar polygon}, Computer Vision, Graphics and Image Processing, vol. 45, pp. 106-116,1989.
+
+S. Nordbeck and B. Rysedt, \emph{Computer cartography point-in-polygon programs}, BIT, vol. 7, pp. 39-64, 1967.
+
+J.A. Baerentzen and H. Aanaes, \emph{Signed distance computation using the angle weighted pseudo-normal}, IEEE Trans. Visualization and Computer Graphics, vol. 11, no. 3, pp. 243-253, May/June 2005.
+
+J. Liu, Y.Q. Chen, J.M. Maisog, G. Luta, \emph{A new point containment test algorithm for polygon composed of huge number of triangles}, Computer-Aided Design, Volume 42, Issue 12, December 2010, Pages 1143-1150.
+
+\url{http://ptinpoly.pbworks.com/}
+}
+\examples{
+#-------------------------------------------
+# Load sample data defining a comb, spiral, and fractal. 
+data(comb)
+data(spiral)
+data(fractal)
+
+# Plot the comb, spiral, and fractal.
+plot(rbind(comb,comb[1,]),type="l")
+plot(rbind(spiral,spiral[1,]),type="l")
+plot(rbind(fractal,fractal[1,]),type="l")
+
+# Generate 3333 random test points.
+set.seed(1902)
+n       <- 3333
+x1      <- rnorm(n) ; x2 <- rnorm(n)
+X       <- cbind(x1,x2)
+queries <- as.matrix(X)
+
+# Check whether test points are contained in the comb, spiral, and factal.
+# Most of these points will lie outside the polygons.
+containment1 = pip2d(comb,queries);
+containment2 = pip2d(spiral,queries);
+containment3 = pip2d(fractal,queries);
+}
+\keyword{methods}

Added: pkg/man/spiral.Rd
===================================================================
--- pkg/man/spiral.Rd	                        (rev 0)
+++ pkg/man/spiral.Rd	2011-10-19 02:15:03 UTC (rev 11)
@@ -0,0 +1,29 @@
+\name{spiral}
+\alias{spiral}
+\docType{data}
+\title{
+Sample Data: Spiral Polygon
+}
+\description{
+Sample data defining an enclosed spiral 2D polygon.
+}
+\usage{data(spiral)}
+\examples{
+# Load polygon.
+data(spiral)
+
+# Plot the polygon.
+plot(rbind(spiral,spiral[1,]),type="l")
+
+# Generate 3333 random test points.
+set.seed(1902)
+n       <- 3333
+x1      <- rnorm(n) ; x2 <- rnorm(n)
+X       <- cbind(x1,x2)
+queries <- as.matrix(X)
+
+# Check whether test points are contained in the polygon.
+# Most of these points will lie outside the polygon.
+containment = pip2d(spiral,queries);
+}
+\keyword{datasets}

Deleted: pkg/man/triMesh.Rd
===================================================================
--- pkg/man/triMesh.Rd	2011-10-18 00:54:42 UTC (rev 10)
+++ pkg/man/triMesh.Rd	2011-10-19 02:15:03 UTC (rev 11)
@@ -1,54 +0,0 @@
-\name{triMesh}
-\alias{triMesh}
-\docType{data}
-\title{
-Sample Data: Complex Polyhedron
-}
-\description{
-Sample data defining a much more complex polyhedron than the simple cube example.
-}
-\usage{data(triMesh)}
-\format{
-\code{Triangles3D} object as defined by package \bold{misc3d}.
-}
-\note{
-In order to use the \code{pip3d} function on
-this data, it must first be converted to the \dfn{vertices-faces} format, as demonstrated
-in the \bold{Examples} section below.
-}
-\examples{
-# Load polyhedron.
-data(triMesh)
-
-# If desired, this complex polyhedron can be rendered for visualization, e.g.:
-# library(geometry)
-# library(rgl)
-# library(misc3d)
-drawScene.rgl(triMesh)
-
-# Extract three blocks from triMesh.
-block1 = triMesh$v1
-block2 = triMesh$v2
-block3 = triMesh$v3
-
-# Convert from 3-Block representation to vertices-faces representation.
-# Note double square brackets.
-vertsFaces = blocks2vf(block1,block2,block3)
-Vertices   = vertsFaces[[1]]
-Faces      = vertsFaces[[2]]
-
-# For a shorter way to convert this object to vertices-faces representation,
-# see the Examples section in the documentation for the 'pip3d' function.
-
-# Generate 3333 random test points.
-set.seed(1902)
-n       <- 3333
-x1      <- rnorm(n) ; x2 <- rnorm(n) ; x3 <- rnorm(n)
-X       <- cbind(x1,x2,x3)
-Queries <- as.matrix(X)
-
-# Check whether test points are contained in the polyhedron.
-# Most of these points will lie outside the polyhedron.
-containment = pip3d(Vertices,Faces,Queries);
-}
-\keyword{datasets}



More information about the Ptinpoly-commits mailing list