PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/WpfCSharp/AutodeskReCapClient/AdskReCapPhotoscene.cs

https://github.com/PandazZ/Autodesk-ReCap-Samples
C# | 260 lines | 218 code | 16 blank | 26 comment | 17 complexity | 99b237411b19eaf309c734661e75d2bb MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. // (C) Copyright 2014 by Autodesk, Inc.
  2. //
  3. // Permission to use, copy, modify, and distribute this software in
  4. // object code form for any purpose and without fee is hereby granted,
  5. // provided that the above copyright notice appears in all copies and
  6. // that both that copyright notice and the limited warranty and
  7. // restricted rights notice below appear in all supporting
  8. // documentation.
  9. //
  10. // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  11. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  12. // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
  13. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  14. // UNINTERRUPTED OR ERROR FREE.
  15. //- Written by Cyrille Fauvel, Autodesk Developer Network (ADN)
  16. //- http://www.autodesk.com/joinadn
  17. //- April 20th, 2014
  18. //
  19. using System;
  20. using System.Collections.Generic;
  21. using System.ComponentModel;
  22. using System.Linq;
  23. using System.Text;
  24. using System.Threading.Tasks;
  25. using System.Xml;
  26. using System.Xml.Linq;
  27. using Newtonsoft.Json;
  28. using Newtonsoft.Json.Linq;
  29. namespace Autodesk.ADN.Toolkit.ReCap {
  30. public class AdskReCapPhotoscene {
  31. #region Properties
  32. [Category("Photoscene")]
  33. [DisplayName("Photoscene ID")]
  34. [Description("Internal database ID for the Photoscene")]
  35. public string PhotoSceneID { get; private set; }
  36. [Category("Photoscene")]
  37. [DisplayName("Scene Name")]
  38. [Description("Name of the scene as it appears in the final filename")]
  39. public string Name { get; private set; }
  40. [Category("Photoscene")]
  41. [DisplayName("Creation Date")]
  42. [Description("Date/Time when the scene was first created")]
  43. public DateTime CreationDate { get; private set; }
  44. [Category("Mesh Data")]
  45. [DisplayName("Mesh Quality")]
  46. [Description("Requested quality for the generated mesh")]
  47. [DefaultValueAttribute(AdskReCap.MeshQuality.DRAFT)]
  48. public AdskReCap.MeshQuality MeshQuality { get; private set; }
  49. [Category("Misc")]
  50. [DisplayName("Status")]
  51. public string Status { get; private set; }
  52. [Category("Photoscene")]
  53. [DisplayName("Convert Format")]
  54. [DefaultValueAttribute (AdskReCap.Format._3DP)]
  55. public AdskReCap.Format ConvertFormat { get; private set; }
  56. [Category("Misc")]
  57. [DisplayName("Convert Status")]
  58. public AdskReCap.WorkerStatus ConvertStatus { get; private set; }
  59. [Category("Mesh Data")]
  60. [DisplayName ("Faces")]
  61. [Description("Number of faces in the generated mesh")]
  62. public int NbFaces { get; private set; }
  63. [Category("Mesh Data")]
  64. [DisplayName("Vertices")]
  65. [Description("Number of vertices in the generated mesh")]
  66. public int NbVertices { get; private set; }
  67. [Category("Mesh Data")]
  68. [DisplayName("3d Points")]
  69. [Description("Number of 3D points in the generated mesh")]
  70. public int Nb3dPoints { get; private set; }
  71. [Category("Photogrammetry")]
  72. [DisplayName("Shots")]
  73. [Description("Number of images loaded in the Photoscene")]
  74. public int NbShots { get; private set; }
  75. [Category("Photogrammetry")]
  76. [DisplayName("Stitched Shots")]
  77. [Description("Number of images used to extract the generated mesh")]
  78. public int NbStitchedShots { get; private set; }
  79. [Category("Photoscene")]
  80. [DisplayName("Deleted")]
  81. [Description("If true, the Photoscene and its resources were deleted from the server")]
  82. [DefaultValueAttribute(false)]
  83. public bool Deleted { get; private set; }
  84. [Category("Photoscene")]
  85. [DisplayName("File Size")]
  86. [Description("Size on disc for all documents used to or created by the Photoscene")]
  87. public int FileSize { get; private set; }
  88. [Category("Photogrammetry")]
  89. [DisplayName("Files")]
  90. public List<string> Files { get; private set; }
  91. [Category("Misc")]
  92. [DisplayName("Processing Time")]
  93. public double ProcessingTime { get; private set; }
  94. [Category("Misc")]
  95. [DisplayName("Progress")]
  96. [Description("Current progress of a Photoscene (in %)")]
  97. public double Progress { get; private set; }
  98. [Category("Misc")]
  99. [DisplayName("Progress Message")]
  100. public string ProgressMessage { get; private set; }
  101. [Category("Mesh Data")]
  102. [DisplayName("Scene Link")]
  103. [Description("Link to download the processed Photoscene")]
  104. public Uri SceneLink { get; private set; }
  105. [Category("Misc")]
  106. [DisplayName("User ID")]
  107. [Description("Internal database User ID of the person who created the Photoscene")]
  108. public string UserID { get; private set; }
  109. #endregion
  110. #region Constructors
  111. // XML Serializer - http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx
  112. public AdskReCapPhotoscene (XmlDocument doc)
  113. : this (doc.SelectSingleNode ("/Response/Photoscenes/Photoscene")) {
  114. }
  115. public AdskReCapPhotoscene (XmlNode el) {
  116. try {
  117. XmlNode node =el.SelectSingleNode ("./photosceneid") ;
  118. PhotoSceneID =node.InnerText ;
  119. node =el.SelectSingleNode ("./name") ;
  120. Name =node.InnerText ;
  121. node =el.SelectSingleNode ("./creationDate") ;
  122. CreationDate =DateTime.Parse (Uri.UnescapeDataString (node.InnerText)) ;
  123. node =el.SelectSingleNode ("./meshQuality") ;
  124. MeshQuality =(AdskReCap.MeshQuality)Enum.Parse (typeof (AdskReCap.MeshQuality), node.InnerText, true) ;
  125. node =el.SelectSingleNode ("./status") ;
  126. Status =node.InnerText ;
  127. node =el.SelectSingleNode ("./convertFormat") ;
  128. ConvertFormat =(AdskReCap.Format)node.InnerText.ToReCapFormatEnum () ;
  129. node =el.SelectSingleNode ("./convertStatus") ;
  130. ConvertStatus =(AdskReCap.WorkerStatus)Enum.Parse (typeof (AdskReCap.WorkerStatus), node.InnerText, true) ;
  131. try {
  132. node =el.SelectSingleNode ("./nbfaces") ;
  133. NbFaces =int.Parse (node.InnerText) ;
  134. } catch { }
  135. try {
  136. node =el.SelectSingleNode ("./nbvertices") ;
  137. NbVertices =int.Parse (node.InnerText) ;
  138. } catch { }
  139. try {
  140. node =el.SelectSingleNode ("./nb3Dpoints") ;
  141. Nb3dPoints =int.Parse (node.InnerText) ;
  142. } catch { }
  143. try {
  144. node =el.SelectSingleNode ("./nbStitchedShots") ;
  145. NbStitchedShots =int.Parse (node.InnerText) ;
  146. } catch { }
  147. try {
  148. node =el.SelectSingleNode ("./nbShots") ;
  149. NbShots =int.Parse (node.InnerText) ;
  150. } catch { }
  151. try {
  152. node =el.SelectSingleNode ("./fileSize") ;
  153. FileSize =(node != null ? int.Parse (node.InnerText) : -1) ;
  154. } catch { }
  155. //node =el.SelectSingleNode ("./nbShots") ;
  156. //public List<string> Files { get; private set; }
  157. try {
  158. node =el.SelectSingleNode ("./processingTime") ;
  159. ProcessingTime =double.Parse (node.InnerText) ;
  160. } catch { }
  161. try {
  162. node =el.SelectSingleNode ("./progress") ;
  163. Progress =(node != null ? double.Parse (node.InnerText) : 0) ;
  164. } catch { }
  165. try {
  166. node =el.SelectSingleNode ("./progressMessage") ;
  167. ProgressMessage =(node != null ? node.InnerText : "") ;
  168. } catch { }
  169. try {
  170. node =el.SelectSingleNode ("./scenelink") ;
  171. SceneLink =(node != null ? new Uri ((string)node.InnerText) : null) ;
  172. } catch { }
  173. try {
  174. node =el.SelectSingleNode ("./deleted") ;
  175. Deleted =(node != null ? bool.Parse (node.InnerText) : false) ;
  176. } catch { }
  177. node =el.SelectSingleNode ("./userID") ;
  178. UserID =Uri.UnescapeDataString (node.InnerText) ;
  179. } catch {
  180. }
  181. }
  182. // LINQ to XML - http://msdn.microsoft.com/en-us/library/bb308960.aspx
  183. // http://www.codeproject.com/Tips/366993/Convert-XML-to-Object-using-LINQ
  184. public AdskReCapPhotoscene (XDocument doc)
  185. : this (doc.Element ("Response").Element ("Photoscenes").Elements ("Photoscene").First ()) {
  186. }
  187. public AdskReCapPhotoscene (XElement el) {
  188. try {
  189. PhotoSceneID =(string)el.Element ("photosceneid") ;
  190. Name =(string)el.Element ("name") ;
  191. CreationDate =DateTime.Parse (Uri.UnescapeDataString (el.Element ("creationDate").Value)) ;
  192. MeshQuality =(AdskReCap.MeshQuality)Enum.Parse (typeof (AdskReCap.MeshQuality), el.Element ("meshQuality").Value, true) ;
  193. Status =(string)el.Element ("status") ;
  194. ConvertFormat =(AdskReCap.Format)(el.Element ("convertFormat").Value.ToReCapFormatEnum ()) ;
  195. ConvertStatus =(AdskReCap.WorkerStatus)Enum.Parse (typeof (AdskReCap.WorkerStatus), el.Element ("convertStatus").Value, true) ;
  196. try { NbFaces =(int)el.Element("nbfaces") ; } catch { }
  197. try { NbVertices =(int)el.Element ("nbvertices") ; } catch { }
  198. try { Nb3dPoints =(int)el.Element ("nb3Dpoints") ; } catch { }
  199. try { NbStitchedShots =(int)el.Element ("nbStitchedShots") ; } catch { }
  200. try { NbShots =(int)el.Element ("nbShots") ; } catch { }
  201. try { Deleted =(el.Element ("deleted") != null ? (bool)el.Element ("deleted") : false) ; } catch { }
  202. try { FileSize =(el.Element ("fileSize") != null ? (int)el.Element ("fileSize") : -1) ; } catch { }
  203. //public List<string> Files { get; private set; }
  204. try { ProcessingTime =(double)el.Element ("processingTime") ; } catch { }
  205. try { Progress =(el.Element ("progress") != null ? (double)el.Element ("progress") : 0) ; } catch { }
  206. try { ProgressMessage =(el.Element ("progressMessage") != null ? (string)el.Element ("progressMessage") : "") ; } catch { }
  207. try { SceneLink =(el.Element ("scenelink") != null ? new Uri ((string)el.Element ("scenelink")) : null) ; } catch { }
  208. UserID =Uri.UnescapeDataString ((string)el.Element ("userID")) ;
  209. } catch {
  210. }
  211. }
  212. // http://james.newtonking.com/json/help/index.html#
  213. public AdskReCapPhotoscene (JObject el) {
  214. try {
  215. if ( el ["Photoscenes"] != null )
  216. el =(JObject)el ["Photoscenes"] ["Photoscene"] ;
  217. PhotoSceneID =(string)el ["photosceneid"] ;
  218. Name =(string)el ["name"] ;
  219. CreationDate =DateTime.Parse (Uri.UnescapeDataString ((string)el ["creationDate"])) ;
  220. MeshQuality =(AdskReCap.MeshQuality)Enum.Parse (typeof (AdskReCap.MeshQuality), (string)el ["meshQuality"], true) ;
  221. Status =(string)el ["status"] ;
  222. ConvertFormat =(AdskReCap.Format)((string)el ["convertFormat"]).ToReCapFormatEnum () ;
  223. ConvertStatus =(AdskReCap.WorkerStatus)Enum.Parse (typeof (AdskReCap.WorkerStatus), (string)el ["convertStatus"], true) ;
  224. NbFaces =(int)el ["nbfaces"] ;
  225. NbVertices =(int)el ["nbvertices"] ;
  226. Nb3dPoints =(int)el ["nb3Dpoints"] ;
  227. NbStitchedShots =(int)el ["nbStitchedShots"] ;
  228. NbShots =(int)el ["nbShots"] ;
  229. Deleted =(el ["deleted"] != null ? (bool)el ["deleted"] : false) ;
  230. FileSize =(el ["fileSize"] != null ? (int)el ["fileSize"] : -1) ;
  231. //public List<string> Files { get; private set; }
  232. ProcessingTime =(double)el ["processingTime"] ;
  233. Progress =(el ["progress"] != null ? (double)el ["progress"] : 0) ;
  234. ProgressMessage =(el ["progressMessage"] != null ? (string)el ["progressMessage"] : "") ;
  235. SceneLink =(el ["scenelink"] != null ? new Uri ((string)el ["scenelink"]) : null) ;
  236. UserID =Uri.UnescapeDataString ((string)el ["userID"]) ;
  237. } catch {
  238. }
  239. }
  240. protected AdskReCapPhotoscene () {
  241. }
  242. #endregion
  243. }
  244. }