How to configure the scale label position in ILNumerics?

若如初见. 提交于 2019-12-11 03:38:41

问题


I draw some lines with ILLinePlot.

Then I rotate the cube (with the intention to change the position of the Y scale label that starts from the top):

Rotation = Matrix4.Rotation(new Vector3(1, 0, 0), ILMath.pif),

It produces results like this.

In this graph, I am losing the scale label in Y axis. How to configure it? So the label can be shown?

Update: This question is related to : How to reverse the axis in ILNumerics

At first, I have make a graph that consists some lines like this figure:

That figure is produced by this code:
scene.Add(new ILPlotCube
{
   Children = {
      new ILLinePlot(ILMath.tosingle(responses["1,0;:"]),lineWidth:1, markerStyle: MarkerStyle.None),
      new ILLinePlot(line1, lineColor: Color.Black ,lineWidth: 2)
   },

   Axes =
   {
      YAxis =
      {
          LabelAnchor = new PointF(1, 0)
      },
      ZAxis = 
      {
         Visible = false,  
      }
   }
});

BoreholeRespondilPanel.Scene = scene;
BoreholeRespondilPanel.Refresh();

Then I want to reverse the Y axis scale become like this:

From this thread : How to reverse the axis in ILNumerics, he suggest me to turn the plot cube around the X axis by 180°. Then This is my final code:

scene.Add(new ILPlotCube
{
   Children = {
      new ILLinePlot(ILMath.tosingle(responses["1,0;:"]),lineWidth:1, markerStyle: MarkerStyle.None),
      new ILLinePlot(line1, lineColor: Color.Black ,lineWidth: 2)
   },
   Rotation = Matrix4.Rotation(new Vector3(1, 0, 0), ILMath.pif), //<<==== added this line

   Axes =
   {
      YAxis =
      {
          LabelAnchor = new PointF(1, 0)
      },
      ZAxis = 
      {
         Visible = false,  
      }
   }
});

BoreholeRespondilPanel.Scene = scene;
BoreholeRespondilPanel.Refresh();

But, the result is missing the scale label at the Y axis. How to configure it, so the scale label can be shown?


回答1:


Edit and New Answer with Solution

After some investigation your issue could be reproduced. We have two issues, actually:

1) Rotating the plot cube in order to flip axes is fine. But it should be done correctly. This involves a rotation and a translation. Both can be combined and applied together to the ILPlotCube.Rotation property:

Rotation = Matrix4.Translation(0, 0, -2).Rotate(Vector3.UnitX, ILMath.pif)

The translation is needed, because the rotation is always done around the origin. The origin for a plotcube lays in (0,0,0) and rotating around the X Axis brings the plot cube closer to the camera. Without the translation, it could come too close so that the clipping on ZNear kicks in and prevents some parts of the scene from showing.

2) BUT there is a bug in ILNumerics ILOGLLabel OpenGL label class prior version 4.1 of ILNumerics which will prevent the labels to show in such a rotated plotcube. This bug will be fixed in 4.1. In order to workaround this bug,

a. Use ILPlotCube.Transform instead of ILPlotCube.Rotation, and
b. reconfigure the settings of ILPlotCube.ZNear and ILPlotCube.ZFar:

plotCube.Transform = Matrix4.Translation(0, 0, -2).Rotate(Vector3.UnitX, ILMath.pif); 
plotCube.ZNear = -1; plotCube.ZFar = 1;

Recap

In order to reverse the Y axis with ILNumerics version > 4.0 just apply 1). For older versions (4.0 and below) just use 2).


Old Answer

@Edit: The old answer didn't really answer the question. See the first part above in order to find a solution to the original question. This old answer is left here for sake of completeness and since it is usefull anyway: it shows how to ensure a stable configuration even by allowing user interaction.


I was not able to fully reproduce your issue, but here comes a potential solution.

By reversing the plot cube in order to get a Y axis in top-> down direction, you will have to make sure, that the user is not able to reset the plotcube by double clicking on the scene. We can handle the double click event and put the rotation in there.

Anyway, for this example below, all ticks are showing properly. If the problem persists for you, please post a screenshot and a runnable example.

private void ilPanel1_Load(object sender, EventArgs e) {
    // generate some test data
    ILArray<float> A = ILMath.tosingle(ILMath.randn(1, 20));
    ILArray<float> B = A + ILMath.vec<float>(1, 20);
    // add two lines
    ilPanel1.Scene.Add(new ILPlotCube {
        Children = {
            new ILLinePlot(A, lineWidth:1, markerStyle: MarkerStyle.None),
            new ILLinePlot(B, lineColor: Color.Black, lineWidth: 2)
        },
        // rotate the plotcube so the Y axis appears in top down direction
        Rotation = Matrix4.Rotation(new Vector3(1, 0, 0), ILMath.pif), //<<==== added this line

        // configure some axis label properties
        Axes = {
            YAxis = {
                LabelAnchor = new PointF(1, 0)
            },
            ZAxis = {
                Visible = false,
            }
        }
    });

    // override the double click event: resetting the plotcube will restore the reversed axis
    ilPanel1.Scene.First<ILPlotCube>().MouseDoubleClick += (_s, _a) => {
        var plotCube = _s as ILPlotCube;
        if (plotCube != null) {
            plotCube.Reset(); 
            plotCube.Rotation = Matrix4.Rotation(new Vector3(1, 0, 0), ILMath.pif);
            _a.Refresh = true;
            _a.Cancel = true; 
        }
    }; 
}



来源:https://stackoverflow.com/questions/24623700/how-to-configure-the-scale-label-position-in-ilnumerics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!