コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnstructuredModel"/> class.
 /// </summary>
 public UnstructuredModel()
 {
     _Data    = new List <PointData>();
     _Desc    = new DimensionDescription();
     Time     = 0d;
     FileName = String.Empty;
 }
コード例 #2
0
        public void Resolve()
        {
            if (IsResolved)
            {
                return;
            }

            if (File.Exists(FileName))
            {
                if (FileName.ToLowerInvariant().EndsWith(".pvtu"))
                {
                    var reader = vtkXMLPUnstructuredGridReader.New();
                    reader.SetFileName(FileName);
                    reader.Update();
                    var model = FromReader(reader);
                    _Data = model._Data;
                    _Desc = model._Desc;
                }
                else if (FileName.ToLowerInvariant().EndsWith(".vtu"))
                {
                    var reader = vtkXMLUnstructuredGridReader.New();
                    reader.SetFileName(FileName);
                    reader.Update();

                    var output = reader.GetOutput();
                    var model  = FromGrid(output, reader.GetNumberOfPointArrays());
                    _Data = model._Data;
                    _Desc = model._Desc;
                }
            }

            IsResolved = true;
        }
コード例 #3
0
        public static DimensionDescription FromPoints(vtkPoints points)
        {
            if (points == null)
            {
                return(null);
            }

            var bounds    = points.GetBounds();
            var numPoints = points.GetNumberOfPoints();
            var result    = new DimensionDescription
            {
                MinX        = bounds[0],
                MaxX        = bounds[1],
                MinY        = bounds[2],
                MaxY        = bounds[3],
                Coordinates = new double[numPoints, 4]
            };

            var xIndices = new List <double>();
            var yIndices = new List <double>();

            for (var i = 0; i < numPoints; i++)
            {
                var current = points.GetPoint(i);
                if (!xIndices.Contains(current[0]))
                {
                    xIndices.Add(current[0]);
                }
                if (!yIndices.Contains(current[1]))
                {
                    yIndices.Add(current[1]);
                }
            }

            xIndices.Sort();
            yIndices.Sort();

            if (xIndices.Count > 0)
            {
                result.DistanceX = xIndices[1] - xIndices[0];
            }
            if (yIndices.Count > 0)
            {
                result.DistanceY = yIndices[1] - yIndices[0];
            }

            for (var i = 0; i < numPoints; i++)
            {
                var current = points.GetPoint(i);

                result.Coordinates[i, 0] = current[0];
                result.Coordinates[i, 1] = current[1];
                result.Coordinates[i, 2] = xIndices.IndexOf(current[0]);
                result.Coordinates[i, 3] = yIndices.IndexOf(current[1]);
            }

            return(result);
        }
コード例 #4
0
        public static UnstructuredModel FromGrid(vtkUnstructuredGrid output, int numArrays)
        {
            var result = new UnstructuredModel
            {
                _Desc = DimensionDescription.FromPoints(output.GetPoints()),
                _Data = new List <PointData>()
            };

            for (var i = 0; i < numArrays; ++i)
            {
                var pdata = PointData.FromArray((vtkFloatArray)output.GetPointData().GetArray(i));
                pdata.DimensionDescription = result._Desc;
                result._Data.Add(pdata);
            }

            return(result);
        }