[Ptinpoly-commits] r13 - in pkg: . R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Apr 13 07:29:54 CEST 2014
Author: jmaisog
Date: 2014-04-13 07:29:34 +0200 (Sun, 13 Apr 2014)
New Revision: 13
Modified:
pkg/DESCRIPTION
pkg/R/pip3d.R
Log:
Fix bug in function PIP3D where R crashes if there are some vertices in the input VERTICES argument that are not actually used in the input FACES argument. The fix is to create an internal version of the input VERTICES argument that contains ONLY vertices that are actually used in the input FACES argument. The input FACES argument also needs to be updated to reflect the reduced number of rows in the input VERTICES argument. The updated VERTICES and FACES argument can then be forwarded to the underlying C++ method.
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2012-06-11 00:11:16 UTC (rev 12)
+++ pkg/DESCRIPTION 2014-04-13 05:29:34 UTC (rev 13)
@@ -1,15 +1,15 @@
-Package: ptinpoly
-Title: Point-In-Polyhedron Test (2D and 3D)
-Version: 2.01
-Date: 2012-06-10
-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
- within, exactly on, or outside an enclosed surface defined by a triangular mesh.
- Also provided is a 2D version, 'pip2d', which tests whether a point in 2D space is
- within, exactly on, or outside a polygon.
-License: GPL-2
-LazyLoad: yes
-Depends: misc3d
-Suggests: rgl, geometry
-URL: http://ptinpoly.pbworks.com
+Package: ptinpoly
+Title: Point-In-Polyhedron Test (2D and 3D)
+Version: 2.1
+Date: 2014-04-12
+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
+ within, exactly on, or outside an enclosed surface defined by a triangular mesh.
+ Also provided is a 2D version, 'pip2d', which tests whether a point in 2D space is
+ within, exactly on, or outside a polygon.
+License: GPL-2
+LazyLoad: yes
+Depends: misc3d
+Suggests: rgl, geometry
+URL: http://ptinpoly.pbworks.com
Modified: pkg/R/pip3d.R
===================================================================
--- pkg/R/pip3d.R 2012-06-11 00:11:16 UTC (rev 12)
+++ pkg/R/pip3d.R 2014-04-13 05:29:34 UTC (rev 13)
@@ -22,6 +22,36 @@
return(as.vector(rep(-5,nrow(Queries))))
}
+ # Check to ensure that ALL vertices in the matrix VERTICES
+ # are actually used in the matrix defining the faces, FACES.
+ # First, make a list of the vertices in VERTICES that
+ # are ACTUALLY USED in FACES.
+ numVertices <- nrow(Vertices)
+ listOfUsedVertices <- unique(as.numeric(Faces))
+ if ( ! all(1:numVertices %in% listOfUsedVertices) ) {
+ # If we got in this IF block, then not all vertices
+ # in the matrix VERTICES are actually used in FACES.
+ # Modify these two matrices to so that ALL vertices
+ # listed in the matrix VERTICES are actually used
+ # in the matrix FACES, and that the indices in FACES
+ # run from exactly 1 to exactly the number of vertices
+ # defined in the matrix VERTICES.
+
+ # Make an updated version of Vertices that contains
+ # ONLY the vertices that are mentioned in FACES.
+ Vertices <- Vertices[listOfUsedVertices,]
+
+ # Make an updated version of FACES that references
+ # the vertices in the updated Vertices.
+ numVerticesUsed <- length(listOfUsedVertices)
+ FacesTmp <- matrix(NA,nrow(Faces),ncol(Faces)); # Initialize to NA.
+ for ( i in 1:numVerticesUsed ) {
+ vertIndex <- listOfUsedVertices[i]
+ FacesTmp[ Faces == vertIndex ] <- i
+ }
+ Faces <- FacesTmp
+ }
+
# Basic checks of Queries input argument.
querDims = dim(Queries)
numColsQ = querDims[2]
More information about the Ptinpoly-commits
mailing list