public static SynthData Load(string collectionID) { SynthData synthData = new SynthData(); synthData.CollectionID = collectionID; string jsonUrl; try { using (PhotosynthServiceSoapClient soapClient = new PhotosynthServiceSoapClient("PhotosynthServiceSoap")) { CollectionResult collectionResult = soapClient.GetCollectionData(new Guid(collectionID), false); if (collectionResult.Result != Result.OK) throw new SynthDataLoadException(string.Format("The Photosynth web service returned an error (Error code: {0}). Make sure the URL you entered is correct and the synth exists.", collectionResult.Result)); if (collectionResult.CollectionType != CollectionType.Synth) throw new SynthDataLoadException("The URL you have entered belongs to a panorama hosted on photosynth.net. SynthExport is compatible with photosynths only."); synthData.CollectionRoot = collectionResult.CollectionRoot; jsonUrl = collectionResult.JsonUrl; } } catch (CommunicationException e) { throw new SynthDataLoadException("An error occurred while trying to contact the Photosynth web service.", e); } string jsonString; try { using (WebClient webClient = new WebClient()) jsonString = webClient.DownloadString(jsonUrl); } catch (WebException e) { throw new SynthDataLoadException("An error occured while downloading synth data.", e); } synthData.LoadJsonData(new StringReader(jsonString)); return synthData; }
public void DownloadPointClouds(SynthData synthData) { var coordSystemsWithPointCloud = synthData.CoordinateSystems.Where(cs => cs.PointCloud != null); int filesDownloaded = 0; int totalFileCount = coordSystemsWithPointCloud.Sum(cs => cs.PointCloud.BinFileCount); using (WebClient webClient = new WebClient()) foreach (CoordinateSystem coordSystem in coordSystemsWithPointCloud) for (int i = 0; i < coordSystem.PointCloud.BinFileCount; i++) { string downloadUrl = string.Format("{0}points_{1}_{2}.bin", synthData.CollectionRoot, coordSystem.ID, i); byte[] binFile; try { binFile = webClient.DownloadData(downloadUrl); } catch (WebException e) { throw new PointCloudDownloadException("An error occurred during download of point cloud data files.", e); } using (MemoryStream memoryStream = new MemoryStream(binFile)) coordSystem.PointCloud.LoadBinFile(memoryStream); filesDownloaded++; if (CallbackEvent != null) CallbackEvent(this, new CallbackEventArgs(filesDownloaded, totalFileCount)); } }
public static SynthData LoadFromZipFile(string path) { SynthData synthData = new SynthData(); try { using (ZipFile zipFile = new ZipFile(path)) { using (MemoryStream stream = new MemoryStream()) { zipFile["0.json"].Extract(stream); stream.Seek(0, SeekOrigin.Begin); synthData.LoadJsonData(new StreamReader(stream)); } foreach (ZipEntry zipEntry in zipFile) { string name = zipEntry.FileName.ToLower(); if (!name.StartsWith("points_") || !name.EndsWith(".bin")) continue; int i = name.IndexOf('_', 7); if (i < 0) continue; int coordSystem; if (!int.TryParse(name.Substring(7, i - 7), out coordSystem)) continue; int index; if (!int.TryParse(name.Substring(i + 1, name.Length - i - 5), out index)) continue; using (MemoryStream stream = new MemoryStream()) { zipEntry.Extract(stream); stream.Seek(0, SeekOrigin.Begin); synthData.CoordinateSystems[coordSystem].PointCloud.LoadBinFile(stream); } } } } catch (ZipException e) { throw new SynthDataLoadException("Could not extract synth data and point clouds from zip archive. The file seems to be corrupted.", e); } return synthData; }