I want to use a colorbar with custom objects. The objects are colored according to a specific colormap. I want to show this colormap in a colorbar at runtime.
I already tried adding it to scene by:
ILColorbar cb = new ILColorbar();
scene.Add(cb);
or to the cube:
plotCube.Add(cb);
or even plotCube.Children.Add(cb);
but it still doesn't work. What is the correct way to display a colorbar for custom objects?
Here is my code:
private void OKInputBodyListButton_Click(object sender, EventArgs e)
{
try
{
var sceneBody = new ILScene();
var plotCubeBody = sceneBody.Add(new ILPlotCube(twoDMode: false));
foreach (BlockBody item in ObjectList)
{
createBlockBody(item, sceneBody, plotCubeBody);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void createBlockBody(BlockBody BlockBody, ILScene scene, ILPlotCube plotCube)
{
var box = new ILTriangles("tri")
{
...
...
}
plotCube.Add(box);
var colormap = new ILColormap(Colormaps.Jet);
Vector4 key1 = colormap.Map((float)BlockBody.Rho, new Tuple<float, float>(-1, 1));
var test = key1.ToColor();
box.Color = test;
SliceilPanel.Scene = scene;
SliceilPanel.Refresh();
}
And this are my figures:
The colorbar needs some data: the colormap used and the upper/lower limits for the colorbar axis. Normally, it takes those information from the corresponding plot object (contour plot, surface plot) in the scene at runtime. 'At runtime' because it must be able to react to changes to these plot objects due to interactivity.
If you want to use colorbars for your custom objects you must provide those data yourself. ILColorbar provides the ColormapProvider property. Assign an object to it which provides the information at runtime. You can take the predefined
ILNumerics.Drawing.Plotting.ILStaticColormapProvider
or provide your own implementation of the 'IILColormapProvider' interface.This is not working with the Community Edition from nuget!