[Ptinpoly-commits] r8 - in pkg: . R data man src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Oct 31 17:56:55 CET 2010
Author: jmaisog
Date: 2010-10-31 17:56:54 +0100 (Sun, 31 Oct 2010)
New Revision: 8
Modified:
pkg/DESCRIPTION
pkg/R/pip3d.R
pkg/data/faces.rda
pkg/data/verts.rda
pkg/man/pip3d.Rd
pkg/src/kodtree.cc
pkg/src/pinpolyhedronA.cc
Log:
Modified two C++ source code files, kodtree.cc and pinpolyhedronA.cc to remove debugging print statements, to fix memory leak, and to prevent crashing if the polyhedron has a hole.
Modified pip3d.R to handle the new behavior of the underlying C++ code. Updated the documentation file (pip3d.Rd) to reflect this.
Fixed defective data files faces.rda and verts.rda; they seemed to be the faces and verts of the triMesh data.
Finally, updated the DESCRIPTION file to indicate that we're now at revision 1.9.
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2010-04-25 20:37:22 UTC (rev 7)
+++ pkg/DESCRIPTION 2010-10-31 16:56:54 UTC (rev 8)
@@ -1,7 +1,7 @@
Package: ptinpoly
Title: Point-In-Polyhedron Test (3D)
-Version: 1.4
-Date: 2010-04-22
+Version: 1.9
+Date: 2010-08-07
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
Modified: pkg/R/pip3d.R
===================================================================
--- pkg/R/pip3d.R 2010-04-25 20:37:22 UTC (rev 7)
+++ pkg/R/pip3d.R 2010-10-31 16:56:54 UTC (rev 8)
@@ -4,32 +4,32 @@
# Basic checks of Vertices input argument.
vertDims = dim(Vertices)
numColsV = vertDims[2] ;
- if ( numColsV != 3 ) {
- print("pip3d(): Number of columns in Vertices must be 3!")
- return(0);
- }
+ if ( numColsV != 3 ) {
+ print("pip3d(): Number of columns in Vertices must be 3!")
+ return(-3);
+ }
# Basic checks of Faces input argument.
faceDims = dim(Faces)
numColsF = faceDims[2] ;
- if ( numColsF != 3 ) {
- print("pip3d(): Number of columns in Faces must be 3!")
- return(0);
- }
+ if ( numColsF != 3 ) {
+ print("pip3d(): Number of columns in Faces must be 3!")
+ return(-4);
+ }
- if ( min(Faces) < 1 ) {
- print("pip3d(): Values in Faces must be greater than 0!")
- return(0);
- }
+ if ( min(Faces) < 1 ) {
+ print("pip3d(): Values in Faces must be greater than 0!")
+ return(-5);
+ }
# Basic checks of Queries input argument.
querDims = dim(Queries)
numColsQ = querDims[2] ;
- if ( numColsQ != 3 ) {
- print("pip3d(): Number of columns in Queries must be 3!")
- return(0);
- }
-
+ if ( numColsQ != 3 ) {
+ print("pip3d(): Number of columns in Queries must be 3!")
+ return(-6);
+ }
+
# Invoke theptinpoly C++ code (for convenience, it has
# the same name as this R function, but this wasn't necessary)
Output =.C("pip3d",
Modified: pkg/data/faces.rda
===================================================================
(Binary files differ)
Modified: pkg/data/verts.rda
===================================================================
(Binary files differ)
Modified: pkg/man/pip3d.Rd
===================================================================
--- pkg/man/pip3d.Rd 2010-04-25 20:37:22 UTC (rev 7)
+++ pkg/man/pip3d.Rd 2010-10-31 16:56:54 UTC (rev 8)
@@ -28,14 +28,31 @@
'0' indicates that the point lies exactly on the surface of the polyhedron.
'-1' indicates that the point lies outside the polyhedron.
+
+'-2' (error) indicates that the polyhedron was topologically defective (e.g., had a hole)
+
+'-3' (error) indicates that the \code{Vertices} matrix didn't have three columns
+
+'-4' (error) indicates that the \code{Faces} matrix didn't have three columns
+
+'-5' (error) indicates that the \code{Faces} matrix was 0- rather than 1-offset
+
+'-6' (error) indicates that the \code{Queries} matrix didn't have three columns
}
\note{
The polyhedron defined by \code{Vertices} and \code{Faces} \emph{must} be "non-leaky";
i.e., it must define an "inside" versus "outside" and must not contain any holes.
-Running this function on a defective polyhedron \emph{will} cause R to crash.
For an example of external software that could potentially be used to fix defective polyhedra,
see, e.g., PolyMender (\url{http://www1.cse.wustl.edu/~taoju/code/polymender.htm}).
+
+Previous versions of this function would hang when there were more than two vertices very close
+to one another; this problem was discovered with a polyhedron in which there were multip;le
+duplicate vertices and one triplicate vertex. The triplicate vertex fulfilled the case of
+"more than two vertices very close to one another", and caused the code to hang.
+The threshold for vertices that are very close to one another has been increased to three.
+It is advisable to make sure that a polyhedron does not have more then three vertices
+that are "very close to one another", and to make sure that there are no duplicate vertices.
}
\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.
@@ -124,14 +141,11 @@
containment = pip3d(Vertices,Faces,Queries);
#-------------------------------------------
-# A warning.
-#
-# If you remove one of the faces of the cube, the resulting cube is no
-# longer "non-leaky". Running 'pip3d' on the resulting defective
-# polyhedron will cause R to crash.
-#
-# badcube = faces[1:11,]
-# containment = pip3d(verts,badcube,queries); # crash
-#
+# If you remove one of the faces of the cube, the resulting cube
+# becomes "leaky". Running 'pip3d' on the resulting defective
+# polyhedron will return -2.
+
+badcube = faces[1:11,]
+containment = pip3d(verts,badcube,queries);
}
\keyword{methods}
Modified: pkg/src/kodtree.cc
===================================================================
--- pkg/src/kodtree.cc 2010-04-25 20:37:22 UTC (rev 7)
+++ pkg/src/kodtree.cc 2010-10-31 16:56:54 UTC (rev 8)
@@ -820,8 +820,8 @@
quet.push(tnb);
}
tneighb[ctri][i]=tnb;
-printf("sort1ShellFromaTri(): about to call indexOfVertAtTri()...\n");fflush(NULL);
-printf(" i = %d, trips[%d][%d] = %d, tnb = %d\n",i,ctri,(i+1)%3,trips[ctri][(i+1)%3],tnb);fflush(NULL);
+//printf("sort1ShellFromaTri(): about to call indexOfVertAtTri()...\n");fflush(NULL);
+//printf(" i = %d, trips[%d][%d] = %d, tnb = %d\n",i,ctri,(i+1)%3,trips[ctri][(i+1)%3],tnb);fflush(NULL);
int ind=indexOfVertAtTri(trips[ctri][(i+1)%3],trips[tnb]);
tneighb[tnb][(ind+1)%3]=ctri;
}
@@ -871,7 +871,8 @@
if(t3n[0]==v) return 0;
else if(t3n[1]==v) return 1;
else if(t3n[2]==v) return 2;
- else jf_error("indexoftri #1\n");
+ else throw((int)3);
+// else jf_error("indexoftri #1\n");
}
/********************************************************/
Modified: pkg/src/pinpolyhedronA.cc
===================================================================
--- pkg/src/pinpolyhedronA.cc 2010-04-25 20:37:22 UTC (rev 7)
+++ pkg/src/pinpolyhedronA.cc 2010-10-31 16:56:54 UTC (rev 8)
@@ -372,7 +372,7 @@
sortTrianglesOuterNormAndRecNeighb(vertcoord,numvert,trips,numtri,tneighb,triofnode);
void **wvti;
wrapPointsUpasVerts(wvti);
- polytree=new Kodtree(wvti,numvert,pofvforcoordnodes3,2,epsoverlap);
+ polytree=new Kodtree(wvti,numvert,pofvforcoordnodes3,3,epsoverlap);
delete wvti;
polytree->setFuncExinfoShouldbeInCell(ifexinfoshouldbeincell);
polytree->setFuncExinfoOverlapBox(ifexinfooverlapbox);
@@ -559,7 +559,6 @@
else jf_error("indexofneighb");
}
int PointInPolyhedron::nextTriOfVert(int v, int ctri){
-printf("PointInPolyhedron::nextTriOfVert(): about to call indexOfVertAtTri()...\n");fflush(NULL);
int ind=indexOfVertAtTri(v,ctri);
return tneighb[ctri][(1+ind)%3];
}
@@ -749,11 +748,29 @@
tris[i][1] = faces[i+1*(*numF)] - 1;
tris[i][2] = faces[i+2*(*numF)] - 1;
}
- //construct a object of PointInPolyhedron
+
+ // Attempt to construct a object of PointInPolyhedron
PointInPolyhedron *ptpoly = 0;
- ptpoly = new PointInPolyhedron(vert,(*numV),tris,(*numF));
-
+ try {
+ ptpoly = new PointInPolyhedron(vert,(*numV),tris,(*numF));
+ }
+ catch ( int ptpolyError ) {
+ // Fill result vector with the code "-2" to indicate
+ // a failed initialization.
+ for( i=0; i<(*numQ); i++) {
+ result[i] = -2;
+ }
+
+ // Revert XYZ coordinates back to original values.
+ for ( i = 0; i < (*numV); i++ ) {
+ vert[i][0] += minX;
+ vert[i][1] += minY;
+ vert[i][2] += minZ;
+ }
+ return;
+ }
+
// Loop over queries, feed them to the Jianfei method.
// Don't forget about the minX, minY, and minZ shifts.
double q[3]={0,0,0};
@@ -764,10 +781,8 @@
result[i] = ptpoly->isPinPolyhedron(q);
}
- // Revert XYZ coordinates back to original values.
- for ( i = 0; i < (*numV); i++ ) {
- vert[i][0] += minX;
- vert[i][1] += minY;
- vert[i][2] += minZ;
- }
+ // RELEASE MEMORY!!
+ delete [] tris;
+ delete [] vert;
+ delete ptpoly;
}
More information about the Ptinpoly-commits
mailing list