The Results window is a specialized Table (a non-image window) working only with numbers and extensively used in many plugins like the Analyze > Analyze Particles... . Moreover, this window has specific menus to explore the data (distribution, statistics computation: min, max, average, standard deviation,etc.).
There are two utility functions to manipulate the data in a Results Window:
- setResult(...): Creation and set Data
- getResult(...): Get data
1-Create and fill the Results window
There is no specific function for the creation of the Results window, each time a new value is added in this table via the function setResult(..), the window, a new row or a new column are automatically created if required.The function setResult(...) has three arguments:
- the column name (a String)
- the row index (Notice that the first index is 0 (zero) !! )
- the value
+++ IJ snippet: array_results_creation.ijm +++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array using Results Window in IJ script | |
// Jean-Christophe Taveau | |
// Fill the data column by column, | |
// the first time a new heading is found, | |
// the corresponding column is created. | |
// Column #1: faces | |
setResult("faces",0,4); // tetrahedron | |
setResult("faces",1,5); // pyramid | |
setResult("faces",2,5); // pentahedron (prism) | |
setResult("faces",3,6); // cube | |
setResult("faces",4,7); // heptahedron(prism) | |
setResult("faces",5,8); // octahedron | |
setResult("faces",6,9); // nonahedron(augmented cube) | |
setResult("faces",7,10); // decahedron (augm. pentag. prism) | |
// Column #2: edges | |
setResult("edges",0,6); | |
setResult("edges",1,10); | |
setResult("edges",2,9); | |
setResult("edges",3,12); | |
setResult("edges",4,15); | |
setResult("edges",5,12); | |
setResult("edges",6,16); | |
setResult("edges",7,19); | |
setResult("edges",8,10); | |
exit(); |
There are some constraints when defining rows:
- Keep in mind that the first row has the index 0.
- You have to define the rows indexes by ascending order (an increment of 1) - we can't create rows #3, then #2 and #4, you must follow the ascending order (#2, #3, and #4).
2-Read the data
The function getResult(...) allows to read a value, you need two arguments:- The column name ( a String)
- The row index .
+++ IJ snippet +++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array using Results Window in IJ script | |
// Jean-Christophe Taveau | |
// Clear the Log window | |
print("\\Clear"); | |
// Read and display the data in the Log window | |
for (i=0;i<nResults;i++) | |
{ | |
nfaces=getResult("faces",i); | |
nedges=getResult("edges",i); | |
print("The polyhedron #" + i + " has " + nfaces + " faces and " + nedges + " edges."); | |
} | |
exit(); |
Don't be confused between the indexes displayed in the Results window and the index of the getResult(...) function.
As shown in Fig. 1, the Results begins with the row # 1 ...
![]() |
Fig. 1: Results window. The first row has the index 1. |
...but in a macro/script to get the values of the first row, you need to type:
getResult("faces",0); // 4
getResult("edges",0); // 63- Utilily functions
nResults(): To get the rows number. That's very useful to scan all the values in a loop.run("Clear Results"): To reset (and clear) the Results window.
4- Conclusion
Pros: easy access, good for large arrays (columns)Cons: Only one unique Results table, strings not supported, no row access.
The Results window is a specialized version of the Table window ... and this is the subject of my next post.
No comments:
Post a Comment