예제 #1
0
 /// <summary>
 /// 更新fyGrid
 /// </summary>
 /// <param name="Grid"></param>
 public void UpdatefyGrid(ExGrid Grid, double ValueOfNull = -9999.9999)
 {
     if (Grid == null)
     {
         MessageBox.Show("来自fy3DModelCanvas的警告\nfyGrid是Null!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
     //对Grid的null值进行处理
     for (int i = 0; i < Grid.CellCount; i++)
     {
         //如果Cell是null,则赋予为ValueOfNull
         Grid.SetCell(i, Grid.GetCell(i) == null ? ValueOfNull : Grid.GetCell(i));
     }
     m_Grid = Grid;
     //发出数据更新消息
     UpdatefyGridEvent();
 }
        //把fyGrid转为vtkImageData
        private vtkImageData ConvertfyGrid2vtkImageData(ExGrid Grid)
        {
            vtkImageData ImageData = vtkImageData.New();

            ImageData.SetScalarTypeToUnsignedChar();

            ImageData.SetNumberOfScalarComponents(1);
            ImageData.SetDimensions(Grid.ICount, Grid.JCount, Grid.KCount);
            ImageData.SetSpacing(1, 1, 1);
            ImageData.AllocateScalars();
            byte[] data = new byte[Grid.CellCount];

            for (int i = 0; i < Grid.CellCount; i++)
            {
                data[i] = (byte)Grid.GetCell(i).Value;
            }
            System.Runtime.InteropServices.Marshal.Copy(data, 0, (IntPtr)ImageData.GetScalarPointer(), data.Length);
            return(ImageData);
        }