/// <summary> /// Loads clusters from the specified level. /// </summary> /// <param name="level">Number of the level from where to load the data.</param> /// <returns>Returns an array of vertices.</returns> public Centre[] LoadClusters(int level) { // open input file string fileName = GetNumberedFileName(level); FileStream streamIn = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader fileIn = new BinaryReader(streamIn); // read the number of coordinates each vertex has ushort coordCount = fileIn.ReadUInt16(); int vertexSize = sizeof(double) * coordCount; int clusterCentreSize = vertexSize + sizeof(long) + sizeof(int); // determine the number of points in the file long fileLengthExclHeader = streamIn.Length - sizeof(UInt16); int vertexCount; if (level == 0) { // zero level vertices without pointers to cluster members vertexCount = (int)fileLengthExclHeader / vertexSize; } else { vertexCount = (int)fileLengthExclHeader / clusterCentreSize; } // prepare memory Centre[] vertices = new Centre[vertexCount]; // load the data if (level > 0) { for (int i = 0; i < vertexCount; i++) { vertices[i] = Centre.ReadBinary(fileIn, coordCount); } } else { for (int i = 0; i < vertexCount; i++) { vertices[i] = Centre.ReadBinaryJustCoords(fileIn, coordCount); } } // close input file fileIn.Close(); streamIn.Close(); return(vertices); }
/// <summary> /// Loads all members of the given cluster. /// </summary> /// <param name="level">The level from where to load the members (one level lower than the cluster centre).</param> /// <param name="startIndex">Index of the first cluster member.</param> /// <param name="count">Number of the cluster members.</param> /// <returns>Returns an array of cluster vertices.</returns> public Centre[] ExpandCluster(int level, long startIndex, int count) { // open input file string fileName = GetNumberedFileName(level); FileStream streamIn = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader fileIn = new BinaryReader(streamIn); // read the number of coordinates each vertex has ushort coordCount = fileIn.ReadUInt16(); // seek to the appropriate cluster streamIn.Seek(startIndex, SeekOrigin.Begin); // prepare memory Centre[] clusterMembers = new Centre[count]; // load the cluster members if (level > 0) { for (int i = 0; i < count; i++) { clusterMembers[i] = Centre.ReadBinary(fileIn, coordCount); } } else { for (int i = 0; i < count; i++) { clusterMembers[i] = Centre.ReadBinaryJustCoords(fileIn, coordCount); } } // close input file fileIn.Close(); streamIn.Close(); return(clusterMembers); }