contourWalker {contoureR}R Documentation

Contour Walker Function, Rcpp Interface to C++ Routine


This function is the R interface to the C++ core contour-walker function, totally essential for this package.



the n x 3 matrix representing the indexes of the vertices of the triangles in the delaunay mesh. No values should be greater than the number of rows in xyz.


the m x 3 matrix of xyz coordinates for all the points in the data.


a numeric vector of levels to contour.


the maximum pertubation amount (positive or negative) as a percentage.


The underlying C++ routine establishes a pointer-driven adjacency-network within each of the triangles (Dels) in the supplied Delaunay mesh, that is to say that Two Del's are deemed to be 'networked' with each other if they share adjacent edges (Edges), which are drawn between two points (Nodes). Dels are deemed as 'fully-networked' if they hold reciprocating pointers with exactly three (3) other Dels. Dels can be partially networked if one or two of the available pointers remain unassigned, which may be the case if the particular Del is a participating member of the convex hull.

Because C++ uses zero-based indexing, whilst R uses 1-based indexing, should the Delaunay Mesh (dm) be provided where the minimum value is 1, then it will be deemed to be a 1-based set and reduced accordingly.

Prior to traversing the mesh, in order to prevent degeneracies, should any Dels in the mesh have vertices which are of the same z value, and/or equal to one of the intended contouring levels, then these nodes will be pertubated (along the z direction) by an infitesimally small amount. The consequences of this approach is that when interpolating along the edges of the Del, the path will always leave at some point (if even trivially small) inbetween two (2) nodes – the path will NEVER leave directly through a node, which would otherwise lead to potential confusion as to the appropriate recipient of the path under such circumstance.

This function is not particularly convenient, and a more convenient wrapper has been produced, with all the usual checks and balances, for further information, see the getContourLines function.


matrix with 6 columns: LevelID, GroupID, PathID, x, y and z

See Also



n = 100
x = runif(n)
y = runif(n)
df = expand.grid(x,y);
colnames(df) = c("x","y")
df$z = df$x^2 + df$y^2
dm  = getDelaunayMesh(df$x,df$y)
res = contourWalker(dm,as.matrix(df),levels=pretty(df$z,n=20))
res = data.frame(res); colnames(res) = c('LID','GID','PID','x','y','z')
res$Group = interaction(res$LID,res$GID)
ggplot(res,aes(x,y,group=Group,colour=z)) + geom_path()

[Package contoureR version 1.0.5 Index]