|
Add invisible contour layer to get indices |
Posted by Raoul on May-30-2013 00:36 |
|
Hi,
I think I am very close to having this working, but I am just a bit confused on the final step. I am a bit of a newbie and am still confused on the philosophy behind adding these various layers. I am still looking for a high-level concept explanation about how to best use ChartDirector, but I have been able to put most of it together from the excellent examples provided.
Essentially, what I am trying to do is to interact with a heatmap by drawing a rubberband box with the mouse and find the local min and max within that box. To start with, I made a simple 2D gaussian where z is an array of size [500,500] calculated by X and Y being simple index arrays of size [500] each.
Using the examples provided, it was easy to locate the X,Y coordinates when the mouse button was clicked and its current location, and then just draw a box using hline and vline between those coordinates. I was able to take the X,Y coordinates and get the data values for X and Y using xData = c.getXValue(XCoor) and then search between these index values for the min and max. Everything works great!
However, I now want to move towards a real-world situation where X and Y are now real values and not simple indices for Z. So now when I use the getXValue, it is going to give me the real Xaxis value where I am still just wanting the index position of the array. I think this can be done for the X index by using Layer.getXIndexOf(xvalue), but I don't see an equivalent for the Y index.
So I believe what I need to do is after I create my original contour layer, I need to add another contour layer over the top that is essentially invisible. This second layer would use the size of the X and Y arrays (in this case 500) and essentially create an index-lookup set of axes. So when I am interacting with the mouse as described above, I am now working on this new "invisible" layer and just getting the corresponding indices and not the real "data" layer....
Am I thinking about this correctly? I would think this is fairly easy, but again I am still confused about the philosophy behind these layers and how to go about this. I can try to clean up my test code well enough to post here if needed...
Raoul |
Re: Add invisible contour layer to get indices |
Posted by Raoul on May-31-2013 23:13 |
|
Nevermind, I guess. I will just take the value and search through the X and Y arrays to
find the proper index. That will work just fine, although it seems a bit clunky. I am still
interested in how to drop another transparent contour layer over my main image and get
the indices directly. Mostly because I think it would help me to better understand how all
of this works. However, it is not a necessity at this point. |
Re: Add invisible contour layer to get indices |
Posted by Peter Kwan on Jun-01-2013 00:14 |
|
Hi Raoul,
If I were you, I will probably use your latest method - obtain the x and y data value under the mouse, and search the x and y data arrays for the index.
From your description, since you mentioned above independently obtaining the x array index and y array index, I think you are using "gridded data points" (as opposed to "scatter data points".) For this type of data, the x and y data arrays are usually very short (less than a few thousand values), and they can be searched very quickly with very simple code. It is certainly must faster nad use less code than creating a layer with many thousands of dummy points.
Regards
Peter Kwan |
Re: Add invisible contour layer to get indices |
Posted by Raoul on Jun-01-2013 01:09 |
|
Thanks Peter. I think you are definitely correct and that is what I am doing. The data is
gridded, and since it is axis data, it is nice and sorted too. So, it is a quick binary search
lookup...
I was just using it as a way to better understand ChartDirector really....
-R |
|