
Timing (??) error in ModifyContour triangulation=1

I created a wave tripletWave[n][3] that holds x-y-z triplets for creating a (2D) Delaunay triangulation, then created the the triangulation using "ModifyContour triangulation=1". I then plotted it in a graph. The triangulation occurs automatically; if I delete a row from tripletWave, the triangulation in my graph immediately updates, which is very convenient.
Also, I can extract a list of triangle vertices used in the current triangulation, as well as two waves containing the x-y points that represent the vertices of the triangles. These latter waves should match the x-y columns of triangleWave, which they do but not exactly—they're off in the 3rd or 4th decimal place for some reason (this is not an issue for me).
My program appears to have some kind of timing error which is hard to pin down. To illustrate this, I have created a MNWE (minimal non-working example):
function test() Variable Nt, Nxy Wave tripletWave // (n x 3) wave of x-y-z triplets DeletePoints 35,1, tripletWave // Delete one row WMDuplicateTraceWave("Graph0","tripletWave=xymarkers") // Extracts triangulation waves Wave px = 'tripletWave=xymarkers.x' // This is one of the waves extracted. Should have same # of points as tripletWave Nt = DimSize(tripletWave,0) Nxy = numpnts(px) print "tripletWave size = ", Nt print "xymarkers size = ", Nxy end
This function does the following. First, it deletes a row from the original tripletWave. Then, it uses the function "WMDuplicateTraceWave" from "Extract Contours As Waves.ipf," to extract the wave hidden in tripletWave that contains the same (almost) values as in tripletWave. Then it finds the number of points in tripletWave and the extracted copy, "tripletWave=xymarkers.x". These two sizes are not the same. tripletWave is always one smaller than tripletWave=xymarkers.x. In other words, the function correctly deletes the row from tripletWave, but does not delete it from "tripletWave=xymarkers.x".
The reason that this seems to be some sort of timing or overrun error is that if I type in each of the commands into the command line and execute them one at a time, the two sizes match and an inspection of "tripletWave=xymarkers.x" shows that the correct row has been deleted. Further, if I run the function in the debugger, stepping line-by-line, it works as well.
My interpretation is that when a point is deleted from tripletWave, a rather lengthy (in time) background task needs to run to update the Delaunay triangulation. But before this can finish (I presume) I start the WMDuplicateTraceWave extraction, which returns the original internal version from which the row has not yet been deleted. If I run line-by-line there is plenty of time for the triangulation to complete.
Is my interpretation correct? But more importantly, how should I handle this case? I would like to delete a row from tripletWave and then extract the correctly updated wave using WMDuplicateTraceWave, and have the two waves match in length and content.
Sorry for the very long post!
Without knowing anything about the problem, your description of the issue reminds me of the many times I seemingly got different results when executing everything manually / in the debugger with code involving graphs. Before investigating further, I would recommend simply dropping in a DoUpdate or something and see if that helps. More often than not, graphs do not update during code execution, which can throw off code relying on the current state of the graph.
March 28, 2025 at 06:19 pm - Permalink
I am pretty sure that chozo is right: a DoUpdate command will help. The contour waves/traces are recalculated as part of graph updates.
March 28, 2025 at 08:31 pm - Permalink
I tried placing DoUpdate's in many places. It helped with my test code but not with my real code. I guess my concern is something along these lines: I delete a point, which presumably starts the internal code to calculate the Delaunay triangulation and compute the various waves associated with this. I could imagine that this takes some time to do, and that it's running in the background.
Then I immediately extract/copy one of the waves that is in the process of regeneration. Maybe, because it's being generated in a background process, it is not complete or hasn't even been started on yet. So my call to extract it turns the old version.
If this is what's happening, then adding a DoUpdate won't help, because DoUpdate would be starting a process that has already begun.
What I need is a way to know when the recalculation of the Delaunay waves is done so that I can safely proceed. But I imagine that there is no way to do this.
Or is there a way to wait some for some time in a way that allows background processes to continue?
March 29, 2025 at 03:47 pm - Permalink
You could try to wrap the second part into an Execute/P call, which should shift this calculation to the end of whatever Igor is still doing after you deleted the row.
March 29, 2025 at 06:40 pm - Permalink
If you fill out your example with the rest of the necessary details (sample data triplet wave data, and the AppendXYZContour command) we might be better able to help you.
That said, why are you using the xymarkers trace instead of the triangulation trace?
And you need to say which version of Igor you are using.
March 31, 2025 at 02:59 pm - Permalink