Exemple #1
0
        /// <summary>
        /// Creates a new geometric graph.
        /// </summary>
        public GeometricGraph(MemoryMap map, GeometricGraphProfile profile, int edgeDataSize, int size)
        {
            if (profile == null)
            {
                _graph       = new Graph(map, edgeDataSize, size);
                _coordinates = new Array <float>(map, size * 2);
                for (var i = 0; i < _coordinates.Length; i++)
                {
                    _coordinates[i] = NO_COORDINATE;
                }
                _shapes = new ShapesArray(map, size);
            }
            else
            {
                _graph       = new Graph(map, profile.GraphProfile, edgeDataSize, size);
                _coordinates = new Array <float>(map, size * 2, profile.CoordinatesProfile);
                for (var i = 0; i < _coordinates.Length; i++)
                {
                    _coordinates[i] = NO_COORDINATE;
                }
                _shapes = new ShapesArray(map, size);
            }

            _createElevation = (s) =>
            {
                return(new Array <short>(map, size));
            };
        }
Exemple #2
0
        /// <summary>
        /// Deserializes a graph from the stream.
        /// </summary>
        public static GeometricGraph Deserialize(System.IO.Stream stream, GeometricGraphProfile profile)
        {
            var version = stream.ReadByte();

            if (version != 1)
            {
                throw new Exception(string.Format("Cannot deserialize geometric graph: Invalid version #: {0}.", version));
            }
            var graph           = Graph.Deserialize(stream, profile == null ? null : profile.GraphProfile);
            var initialPosition = stream.Position;
            var size            = 0L;

            ArrayBase <float> coordinates;
            ShapesArray       shapes;

            if (profile == null)
            { // don't use the stream, the read from it.
                coordinates = Context.ArrayFactory.CreateMemoryBackedArray <float>(graph.VertexCount * 2);
                coordinates.CopyFrom(stream);
                size += graph.VertexCount * 2 * 4;
                long shapeSize;
                shapes = ShapesArray.CreateFrom(stream, true, out shapeSize);
                size  += shapeSize;
            }
            else
            { // use the stream as a map.
                var position = stream.Position;
                var map      = new MemoryMapStream(new CappedStream(stream, position, graph.VertexCount * 4 * 2));
                coordinates = new Array <float>(map.CreateSingle(graph.VertexCount * 2), profile.CoordinatesProfile);
                size       += graph.VertexCount * 2 * 4;
                stream.Seek(position + graph.VertexCount * 4 * 2, System.IO.SeekOrigin.Begin);
                long shapeSize;
                shapes = ShapesArray.CreateFrom(stream, false, out shapeSize);
                size  += shapeSize;
            }

            // make stream is positioned correctly.
            stream.Seek(initialPosition + size, System.IO.SeekOrigin.Begin);

            return(new GeometricGraph(graph, coordinates, shapes));
        }
Exemple #3
0
 /// <summary>
 /// Creates a new geometric graph.
 /// </summary>
 public GeometricGraph(MemoryMap map, GeometricGraphProfile profile, int edgeDataSize)
     : this(map, profile, edgeDataSize, BLOCKSIZE)
 {
 }