2013-12-12 5 views
1

현재 직렬 포트에서 오는 데이터를 플롯하는 Win32 (.net) 프로그램을 만드는 중입니다. 필자는 직렬 포트에서 데이터를 가져올 수 있었고 ilnumerics plot cube 등을 설정할 수있었습니다.하지만 할 수없는 것은 (x, y, z)를 하나의 ILAray로 변환하여 점을 그립니다.ILNumerics 직렬 포트에서 주어진 데이터 플로팅

public void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) 
    { 
     if (serialPort1.IsOpen == true) 
     { 
      Varriables.numberOfSerialBytes = serialPort1.BytesToRead; 

      if (Varriables.numberOfSerialBytes >= Varriables.numberOfSerialBytesPerLine) //change 13 to number of bytes, changes for number of stars (stars x3 x BytesPerInt) 
      { 
       string serialText = serialPort1.ReadExisting(); 
       if (serialText != "") RecievedText(serialText); 
       else { } 
      } 
     } 
    } 

    public void RecievedText(string text) 
    { 
     if (richTextBox1.InvokeRequired) 
     { 
      SetTextCallBack x = new SetTextCallBack(RecievedText); 
      this.Invoke(x, new object[] { text }); 
     } 
     else 
     { 
      richTextBox1.Text = text; 
      try { CalculatePoints(text); } 
      catch { } 
     } 
    } 

    public void CalculatePoints(string positionsString) 
    { 
     string[] starpositionStringList = positionsString.Split(" ".ToCharArray()); 
     List<float> starPositionFloatListX = new List<float>(); 
     List<float> starPositionFloatListY = new List<float>(); 
     List<float> starPositionFloatListZ = new List<float>(); 
     System.Console.WriteLine(starpositionStringList.Count()); 

     for (int i = 0; i < starpositionStringList.Count()/3; i += 3) 
     { 
      int iy = i + 1; 
      int iz = i + 2; 

      float x = float.Parse(starpositionStringList[i]); 
      float y = float.Parse(starpositionStringList[iy]); 
      float z = float.Parse(starpositionStringList[iz]); 

      starPositionFloatListX.Add(x); 
      starPositionFloatListY.Add(y); 
      starPositionFloatListZ.Add(z); 
     } 

     float[] xArray = starPositionFloatListX.ToArray<float>(); 
     float[] yArray = starPositionFloatListY.ToArray<float>(); 
     float[] zArray = starPositionFloatListZ.ToArray<float>(); 

     PlotPoints(xArray, yArray, zArray); 
    } 

    public void PlotPoints(float[] x, float[] y, float[] z) 
    { 
     //could send data through PlotPoints(x,y,z); 
     //or make a long array using a for loop and send that 
     //either way i still need to make an array to plot and use ilPlanel2.Scene = Scene to continue upadating the scene 

     ILArray<float> starPositionsX = x; 
     ILArray<float> starPositionsY = y; 
     ILArray<float> starPositionsZ = z; 
     ILArray<float> starPositions = ???????????????; //need to convert (x,y,z) to ILArray<float> 

     ilPanel2.Scene.First<ILPlotCube>().Animations.AsParallel(); 

     if(Varriables.pointsPlotted == false) 
     { 
      //ilPanel2.Scene.First<ILPlotCube>(){ new ILPoints { Positions = starPositions, Colors } }; 
      //Cube.Add(new ILPoints { Positions = starPositions }); 
      ilPanel2.Scene.First<ILPlotCube>().Add<ILPoints>(new ILPoints{ Positions = starPositions }); 

      Varriables.pointsPlotted = true; 
     } 

     else 
     { 
      ilPanel2.Scene.First<ILPoints>().Positions.Update(starPositions); 
     } 
     ilPanel2.Refresh(); 
    } 

거기에 내가 할 수있는 IL.Math 함수가 있습니까?

답변

1

필요한 크기의 ILArray를 만들고 값을 입력하기 위해 직접 수신 플로트 [] System.Arrays를 사용

public void PlotPoints(float[] x, float[] y, float[] z) { 

    using (ILScope.Enter()) { 

     ILArray<float> starPositions = ILMath.zeros<float>(3, x.Length); 
     starPositions["0;:"] = x; 
     starPositions["1;:"] = y; 
     starPositions["2;:"] = z; 

     ilPanel1.Scene.First<ILPlotCube>().Add<ILPoints>(new ILPoints { Positions = starPositions }); 
     // (... or update accordingly, if the shape exists already) 

     // at the end of all modifications, call Configure() 

     ilPanel1.Scene.Configure(); 
     ilPanel1.Refresh(); 
    } 
} 

수정 된 모양 구성()를 호출하는 것을 잊지 마세요 (또는 루트에 대한 경로상의 모든 부모 노드)! 또한, 나는 일반적으로 모든 ILArray 관련 코드를 using (ILScope.Enter()) { .. 블록으로 감 쌉니다. 잦은 업데이트의 성능을 크게 향상시키는 데 도움이됩니다.

+0

부탁드립니다. – AstroPy