2014-01-16 3 views
4

배열 데이터 변경을 지속적으로 플로팅 할 수 있습니까? 단추 이벤트에 대한 데이터 변경을 그래프로 표시하는 ILLinePlot이 있지만 연속으로 만들고 싶습니다.ILNumeric 연속 렌더링 플롯

while (true) 
{ 
    float[] RefArray = A.GetArrayForWrite(); 
    //RefArray[0] = 100; 
    Shuffle<float>(ref RefArray); 
    Console.Write(A.ToString()); 
    scene = new ILScene(); 
    pc = scene.Add(new ILPlotCube()); 
    linePlot = pc.Add(new ILLinePlot(A.T, lineColor: Color.Green)); 
    ilPanel1.Scene = scene; 
    ilPanel1.Invalidate(); 

} 

내가 실행 해요 문제는 루프가 실행되는지, 그리고 내가 배열의 업데이트 된 내용을 확인할 수 있지만 ILPanel는 업데이트되지 않습니다. 이 무한 루프로 인해 메인 루프에 액세스 할 수 없기 때문에 아마 생각할 수 있습니다. 그래서 자체 스레드에도 넣었지만 기대했던대로 렌더링되지 않았습니다 ...

답변

4

바울이 지적한 바와 같이,이 작업을 수행 할 수있는보다 효율적인 시도가 알려 : 여기

private void ilPanel1_Load(object sender, EventArgs e) { 
    using (ILScope.Enter()) { 
     // create some test data 
     ILArray<float> A = ILMath.tosingle(ILMath.rand(1, 50)); 
     // add a plot cube and a line plot (with markers) 
     ilPanel1.Scene.Add(new ILPlotCube(){ 
      new ILLinePlot(A, markerStyle: MarkerStyle.Rectangle) 
     }); 
     // register update event 
     ilPanel1.BeginRenderFrame += (o, args) => 
     { 
      // use a scope for automatic memory cleanup 
      using (ILScope.Enter()) { 
       // fetch the existint line plot object 
       var linePlot = ilPanel1.Scene.First<ILLinePlot>(); 
       // fetch the current positions 
       var posBuffer = linePlot.Line.Positions; 
       ILArray<float> data = posBuffer.Storage; 
       // add a random offset 
       data = data + ILMath.tosingle(ILMath.randn(1, posBuffer.DataCount) * 0.005f); 
       // update the positions of the line plot 
       linePlot.Line.Positions.Update(data); 
       // fit the line plot inside the plot cube limits 
       ilPanel1.Scene.First<ILPlotCube>().Reset(); 
       // inform the scene to take the update 
       linePlot.Configure(); 
      } 
     }; 
     // start the infinite rendering loop 
     ilPanel1.Clock.Running = true; 
    } 
} 

, 전체 업데이트 실행 익명 함수 내에서 BeginRenderFrame에 등록되었습니다.

장면 개체는 모든 렌더링 프레임에서 재생성되는 대신 재사용됩니다. 업데이트가 끝나면 장면에서 영향을받는 노드 또는 해당 부모 노드 중 일부 노드에서 Configure을 호출하여 작업을 완료해야합니다. 이렇게하면 장면이 부분 업데이트를 렌더링하지 못하게됩니다.

모든 업데이트 후에 정리하기 위해 ILNumerics 인공 관절을 사용하십시오. 일단 더 큰 배열이 관련되면 이것은 특히 수익성이 높습니다. 플롯 큐브의 한계를 새 데이터 컨텐츠로 재조정하기 위해 ilPanel1.Scene.First<ILPlotCube>().Reset()에 대한 호출을 추가했습니다.

마지막으로 ILPanel의 Clock을 시작하여 렌더링 루프를 시작하십시오.

결과는 동적 인 플롯이며, 모든 렌더링 프레임에서 자동으로 업데이트됩니다.

enter image description here

2

나는 생각합니다. 셰이프 나 버퍼를 수정 한 후에 Configure()를 호출해야합니다. BeginRenderFrame 이벤트를 사용하여 수정 작업을 수행하면 무한히 많은 모양/새 장면을 추가해서는 안됩니다. 다시 사용하는 것이 좋습니다!

는 예를 필요로하는 경우 ...

관련 문제