AcPointCloud.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Name: AcPointCloud.h
  13. //
  14. // Description: Api for AcDbPointCloud
  15. // NOTE:
  16. // AcDbPointCloudObj.dbx must be loaded before any of these
  17. // functions and classes are used.
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20. #pragma once
  21. #include "rxobject.h"
  22. #include "AcString.h"
  23. class AcPointCloudViewFrustum;
  24. class IPointCloudFilter;
  25. //////////////////////////////////////////////////////////////////////////////
  26. /// <summary>
  27. /// View frustum for defining area of interest for point extraction.
  28. /// </summary>
  29. class ACDB_PORT AcViewFrustum
  30. {
  31. public:
  32. AcViewFrustum();
  33. ~AcViewFrustum();
  34. void setNearUpperRight(double x, double y, double z);
  35. void setNearUpperLeft(double x, double y, double z);
  36. void setNearLowerLeft(double x, double y, double z);
  37. void setNearLowerRight(double x, double y, double z);
  38. void setFarUpperRight(double x, double y, double z);
  39. void setFarUpperLeft(double x, double y, double z);
  40. void setFarLowerLeft(double x, double y, double z);
  41. void setFarLowerRight(double x, double y, double z);
  42. void nearUpperRight(double& x, double& y, double& z) const;
  43. void nearUpperLeft(double& x, double& y, double& z) const;
  44. void nearLowerLeft(double& x, double& y, double& z) const;
  45. void nearLowerRight(double& x, double& y, double& z) const;
  46. void farUpperRight(double& x, double& y, double& z) const;
  47. void farUpperLeft(double& x, double& y, double& z) const;
  48. void farLowerLeft(double& x, double& y, double& z) const;
  49. void farLowerRight(double& x, double& y, double& z) const;
  50. void setNearClip(bool clip);
  51. bool nearClip() const;
  52. void setFarClip(bool clip);
  53. bool farClip() const;
  54. AcPointCloudViewFrustum* asPointCloudFrustum() const;
  55. private:
  56. void* m_pData;
  57. };
  58. //////////////////////////////////////////////////////////////////////////////
  59. /// <summary>
  60. /// Point definition for single precision points
  61. /// </summary>
  62. class ACDB_PORT AcPcPointFloat {
  63. public:
  64. /// <summary>Position</summary>
  65. float m_x, m_y, m_z;
  66. /// <summary>
  67. /// Color format: 0xAARRGGBB
  68. /// Alpha needs to be >0 for the points to be visible
  69. /// Example colors:
  70. /// 0xffff0000 - Red
  71. /// 0xff000000 - Black
  72. /// 0xffffffff - White
  73. /// </summary>
  74. DWORD m_argb;
  75. };
  76. //////////////////////////////////////////////////////////////////////////////
  77. /// <summary>
  78. /// Point definition for double precision points
  79. /// </summary>
  80. class ACDB_PORT AcPcPointDouble {
  81. public:
  82. /// <summary>Position</summary>
  83. double m_x, m_y, m_z;
  84. /// <summary>
  85. /// Color format: 0xAARRGGBB
  86. /// Alpha needs to be >0 for the points to be visible
  87. /// Example colors:
  88. /// 0xffff0000 - Red
  89. /// 0xff000000 - Black
  90. /// 0xffffffff - White
  91. /// </summary>
  92. DWORD m_argb;
  93. };
  94. //////////////////////////////////////////////////////////////////////////////
  95. /// <summary>
  96. /// Point attributes definition
  97. /// </summary>
  98. class ACDB_PORT AcPcPointAttributes
  99. {
  100. public:
  101. /// <summary>Intensity, range 0 - 1</summary>
  102. float m_intensity;
  103. /// <summary>Normal value</summary>
  104. float m_nx, m_ny, m_nz;
  105. /// <summary>Classification value</summary>
  106. BYTE m_classification;
  107. };
  108. //////////////////////////////////////////////////////////////////////////////
  109. /// <summary>
  110. /// Data buffer for points returned from the point cloud engine.
  111. /// Points returned in the data buffer will be in local point cloud space.
  112. /// To convert the points to world space you need to first add the XYZ offset
  113. /// to the point and then transform the point using the entityTransform.
  114. /// Example:
  115. ///
  116. /// AcPcPointFloat p;
  117. /// pBuffer->floatPoint(pointIndex, p);
  118. /// double offsetX, offsetY, offsetZ;
  119. /// pBuffer->offset(offsetX, offsetY, offsetZ);
  120. /// AcGeMatrix3d xform;
  121. /// pBuffer->entityTransform(xform);
  122. /// AcGePoint3d pt(p->m_x+offsetX, p->m_y+offsetY, p->m_z+offsetZ);
  123. /// pt = xform*pt; // Point is now in world space
  124. ///
  125. /// </summary>
  126. class ACDB_PORT IAcPcDataBuffer {
  127. public:
  128. virtual ~IAcPcDataBuffer() = 0 {};
  129. ///<summary>Indicate if the points are in single or double precision.</summary>
  130. virtual bool nativeDbl() = 0;
  131. ///<summary>Resize the buffer. This may be a destructive operation.</summary>
  132. virtual bool resize(DWORD size) = 0;
  133. ///<summary>Shrink the buffer without destroying its contents.</summary>
  134. virtual bool shrink(DWORD size) = 0;
  135. /// <summary>Return the number of points in the buffer.</summary>
  136. virtual DWORD size() const = 0;
  137. /// <summary>Return a array of single precision points.
  138. /// This may return NULL if the buffer is not single precision.</summary>
  139. virtual AcPcPointFloat* floatPoints () = 0;
  140. /// <summary>Return a array of double precision points.
  141. /// This may return NULL if the buffer is not double precision.</summary>
  142. virtual AcPcPointDouble* doublePoints() = 0;
  143. /// <summary>Return a array of point attributes.
  144. /// This may return NULL if the point cloud don't have such attributes.</summary>
  145. virtual AcPcPointAttributes* pointAttributes() = 0;
  146. /// <summary>Return a point in single precision.
  147. /// This will work regardless of the native precision of the buffer.</summary>
  148. virtual bool floatPoint (DWORD ptIx, AcPcPointFloat& pt) const = 0;
  149. /// <summary>Return a point in double precision.
  150. /// This will work regardless of the native precision of the buffer.</summary>
  151. virtual bool doublePoint (DWORD ptIx, AcPcPointDouble& pt) const = 0;
  152. /// <summary>Set a point in single precision.
  153. /// This will work regardless of the native precision of the buffer.</summary>
  154. virtual bool setFloatPoint (DWORD ptIx, AcPcPointFloat& pt) = 0;
  155. /// <summary>Set a point in double precision.
  156. /// This will work regardless of the native precision of the buffer.</summary>
  157. virtual bool setDoublePoint (DWORD ptIx, AcPcPointDouble& pt) = 0;
  158. /// <summary>Get the translation offset of the points.
  159. /// This offset needs to be added to each point in order to get the
  160. /// original location of the point in the point cloud</summary>
  161. virtual bool offset (double& x, double& y, double& z) const = 0;
  162. /// <summary>This transform needs to be applied to the points to
  163. /// get the points in world space.</summary>
  164. virtual bool entityTransform(AcGeMatrix3d& matrix) const = 0;
  165. /// <summary>Copy the contents of the given buffer.</summary>
  166. virtual void copyFrom(IAcPcDataBuffer const & from) = 0;
  167. };
  168. //////////////////////////////////////////////////////////////////////////////
  169. /// <summary>
  170. /// Callback class to filter point display.
  171. /// The original points are provided in the inBuffer.
  172. /// The resulting points are placed into the outBuffer.
  173. /// Points can be added, removed, or modified. Any resulting point in the
  174. /// outBuffer will be displayed.
  175. /// </summary>
  176. class ACDB_PORT IAcPcPointFilter {
  177. public:
  178. /// <summary>
  179. /// Filter points to display
  180. /// </summary>
  181. ///
  182. /// <param name="inBuffer">The input buffer includes the original points</param>
  183. /// <param name="outBuffer">The output buffer includes the points after filtering</param>
  184. virtual void doFilter(
  185. const IAcPcDataBuffer& inBuffer,
  186. IAcPcDataBuffer& outBuffer) = 0;
  187. };
  188. //////////////////////////////////////////////////////////////////////////////
  189. /// <summary>
  190. /// Point processor. This class let you extract points from the drawing for
  191. /// export or interrogation purposes. These operations do not affect the
  192. /// current point display.
  193. /// </summary>
  194. class ACDB_PORT IAcPcPointProcessor {
  195. public:
  196. /// <summary>Return true to cancel processing.</summary>
  197. virtual bool cancel() = 0;
  198. /// <summary>Called to abort the process</summary>
  199. virtual void abort() = 0;
  200. /// <summary>Called after the last call to ProcessPoints</summary>
  201. virtual void finished() = 0;
  202. /// <summary>Process point in buffer. This will be called repeatedly with
  203. /// new buffer contents until all points have been processed.</summary>
  204. virtual bool processPoints() = 0;
  205. /// <summary>Filter, if available, to filter points.
  206. /// Called before processPoints() on the next batch of points.</summary>
  207. virtual IAcPcPointFilter* filter() = 0;
  208. /// <summary>The buffer used to store points</summary>
  209. IAcPcDataBuffer* buffer();
  210. /// <summary>For internal use</summary>
  211. void setBuffer(IAcPcDataBuffer* buffer);
  212. private:
  213. IAcPcDataBuffer* mpBuffer;
  214. };
  215. //////////////////////////////////////////////////////////////////////////////
  216. /// <summary>
  217. /// Create an AcDbPointCloud entity.
  218. /// AcDbPointCloudObj.dbx must be loaded before this function is used.
  219. /// </summary>
  220. /// <param name="newPointCloud">Created AcDbPointCloud entity, the caller responsible to destroy it</param>
  221. /// <param name="indexFile">Point cloud index file</param>
  222. /// <param name="sourceFile">Point cloud source file. This represent the original file
  223. /// use to cerate the index. This entry can be blank.</param>
  224. /// <param name="location">Location of point cloud entity. If entity is inserted at
  225. /// 0,0,0 the points will appear where they are located in the point cloud</param>
  226. /// <param name="scale">Scale factor. 1.0 is default scale, and cannot less than 0.0</param>
  227. /// <param name="rotation">Rotation Angle in degrees. 0 is default rotation</param>
  228. ///
  229. /// <returns>
  230. /// Returns Acad::eOk if successful
  231. ///</returns>
  232. ACDB_PORT Acad::ErrorStatus acdbCreatePointCloudEntity(
  233. AcDbEntity*& newPointCloud,
  234. const AcString& indexFile,
  235. const AcString& sourceFile,
  236. AcGePoint3d& location,
  237. double scale = 1.0,
  238. double rotation = 0.0);
  239. //////////////////////////////////////////////////////////////////////////////
  240. /// <summary>
  241. /// Create an AcDbPointCloudEx entity.
  242. /// AcDbPointCloudObj.dbx must be loaded before this function is used.
  243. /// </summary>
  244. /// <param name="newPointCloud">Created AcDbPointCloudEx entity, the caller responsible to destroy it</param>
  245. /// <param name="indexFile">Point cloud index file</param>
  246. /// <param name="sourceFile">Point cloud source file. This represent the original file
  247. /// use to cerate the index. This entry can be blank.</param>
  248. /// <param name="location">Location of point cloud entity. If entity is inserted at
  249. /// 0,0,0 the points will appear where they are located in the point cloud</param>
  250. /// <param name="scale">Scale factor. 1.0 is default scale, and cannot less than 0.0</param>
  251. /// <param name="rotation">Rotation Angle in degrees. 0 is default rotation</param>
  252. ///
  253. /// <returns>
  254. /// Returns Acad::eOk if successful
  255. ///</returns>
  256. ACDB_PORT Acad::ErrorStatus acdbAttachPointCloudExEntity(
  257. AcDbObjectId& newPointCloudExId,
  258. const AcString& pointCloudFile,
  259. AcGePoint3d& location,
  260. double scale = 1.0,
  261. double rotation = 0.0,
  262. AcDbDatabase* pDb = NULL);
  263. //////////////////////////////////////////////////////////////////////////////
  264. /// <summary>
  265. /// Attach a point cloud file into drawing as external reference item.
  266. /// AcDbPointCloudObj.dbx must be loaded before this function is used.
  267. /// </summary>
  268. /// <param name="newPointCloud">Return the object id of created AcDbPointCloud entity
  269. /// into destination database</param>
  270. /// <param name="indexFile">Point cloud index file</param>
  271. /// <param name="sourceFile">Point cloud source file. This represent the original file
  272. /// use to cerate the index. This entry can be blank.</param>
  273. /// <param name="location">Location of point cloud entity. If entity is inserted at
  274. /// 0,0,0 the points will appear where they are located in the point cloud</param>
  275. /// <param name="scale">Scale factor. 1.0 is default scale, and cannot less than 0.0</param>
  276. /// <param name="rotation">Rotation Angle in degrees. 0 is default rotation</param>
  277. /// <param name="pDb">The destination database, use current working database if NULL</param>
  278. ///
  279. /// <returns>
  280. /// Returns Acad::eOk if successful
  281. ///</returns>
  282. ACDB_PORT Acad::ErrorStatus acdbAttachPointCloudEntity(
  283. AcDbObjectId& newPointCloudId,
  284. const AcString& indexFile,
  285. const AcString& sourceFile,
  286. AcGePoint3d& location,
  287. double scale = 1.0,
  288. double rotation = 0.0,
  289. AcDbDatabase* pDb = NULL);
  290. //////////////////////////////////////////////////////////////////////////////
  291. /// <summary>
  292. /// Modify point cloud data view.
  293. /// This function allows a filter to be inserted into the display pipeline
  294. /// of point cloud objects. This filter can inspect and modify the point set
  295. /// before they are displayed.
  296. /// If the entity is already in a database, this will cause a redisplay with
  297. /// the modified point set.
  298. /// It is the applications responsibility to remove any filter added
  299. /// by using acdbResetPointCloudDataView()
  300. /// AcDbPointCloudObj.dbx must be loaded before this function is used.
  301. /// </summary>
  302. /// <param name="pEnt">The destination point cloud entity.</param>
  303. /// <param name="pFilter">The callback to filter point display</param>
  304. ///
  305. /// <returns>
  306. /// Returns Acad::eOk if successful
  307. ///</returns>
  308. ACDB_PORT Acad::ErrorStatus acdbModifyPointCloudDataView(
  309. AcDbEntity* pEnt,
  310. IAcPcPointFilter* pFilter
  311. );
  312. //////////////////////////////////////////////////////////////////////////////
  313. /// <summary>
  314. /// Clear the filter from the given entity.
  315. /// Any filter added to a point cloud entity needs to be removed using this
  316. /// function.
  317. /// AcDbPointCloudObj.dbx must be loaded before this function is used.
  318. /// </summary>
  319. /// <param name="">The destination point cloud entity.</param>
  320. ///
  321. /// <returns>
  322. /// Returns Acad::eOk if successful
  323. ///</returns>
  324. ACDB_PORT Acad::ErrorStatus acdbResetPointCloudDataView(
  325. AcDbEntity* pEnt
  326. );
  327. //////////////////////////////////////////////////////////////////////////////
  328. /// <summary>
  329. /// Select a set of points within the point cloud entity.
  330. /// This function does not modify the points or affect the display of the given
  331. /// entity.
  332. /// The points within the given extents will be passed to the callback for
  333. /// processing. Points will be extracted from the point cloud engine with the
  334. /// selected level of detail (the POINTCLOUDDENSITY sysvar is not honored),
  335. /// and the processPoints() function in the callback will be called repeatedly
  336. /// as the buffer is filled up until all points have been processed.
  337. /// The buffer will be sized so that no unreasonable memory pressure is put on
  338. /// the system.
  339. /// Note that there is no clipping performed after extracting the points so
  340. /// it is likely that a number of points outside the given extents will be
  341. /// returned. The actual extents of the points returned depend on the
  342. /// point cloud engine being used.
  343. /// AcDbPointCloudObj.dbx must be loaded before this function is used.
  344. /// </summary>
  345. /// <param name="pEnt">The destination point cloud entity.</param>
  346. /// <param name="ext">The extent area of interest for point extraction</param>
  347. /// <param name="levelOfDetail">The percentage of the visible points to be processed,
  348. /// range from 0 to 100 </param>
  349. /// <param name="pCallback">The callback of point processer</param>
  350. ///
  351. /// <returns>
  352. /// Returns Acad::eOk if successful
  353. ///</returns>
  354. ACDB_PORT Acad::ErrorStatus acdbProcessPointCloudData(
  355. AcDbEntity* pEnt,
  356. const AcDbExtents& ext,
  357. int levelOfDetail,
  358. IAcPcPointProcessor* pCallback);
  359. //////////////////////////////////////////////////////////////////////////////
  360. /// <summary>
  361. /// Select a set of points within the point cloud entity.
  362. /// This function does not modify the points or affect the display of the given
  363. /// entity.
  364. /// The points within the given extents will be passed to the callback for
  365. /// processing. Points will be extracted from the point cloud engine with the
  366. /// selected level of detail (the POINTCLOUDDENSITY sysvar is not honored),
  367. /// and the processPoints() function in the callback will be called repeatedly
  368. /// as the buffer is filled up until all points have been processed.
  369. /// The buffer will be sized so that no unreasonable memory pressure is put on
  370. /// the system.
  371. /// Note that there is no clipping performed after extracting the points so
  372. /// it is likely that a number of points outside the given view frustum will be
  373. /// returned. The actual extents of the points returned depend on the
  374. /// point cloud engine being used.
  375. /// AcDbPointCloudObj.dbx must be loaded before this function is used.
  376. /// </summary>
  377. /// <param name="pEnt">The destination point cloud entity.</param>
  378. /// <param name="frustum">The view frustum for defining area of interest for point extraction</param>
  379. /// <param name="levelOfDetail">The percentage of the visible points to be processed,
  380. /// range from 0 to 100 </param>
  381. /// <param name="pCallback">The callback of point processer</param>
  382. ///
  383. /// <returns>
  384. /// Returns Acad::eOk if successful
  385. ///</returns>
  386. ACDB_PORT Acad::ErrorStatus acdbProcessPointCloudData(
  387. AcDbEntity* pEnt,
  388. const AcViewFrustum& frustum,
  389. int levelOfDetail,
  390. IAcPcPointProcessor* pCallback);
  391. //////////////////////////////////////////////////////////////////////////////
  392. /// <summary>
  393. /// Set a filter into point cloud engine of the given entity.
  394. /// The filter works during engine reading points from data file.
  395. /// </summary>
  396. /// <param name="pEnt">The destination point cloud entity.</param>
  397. /// <param name="pFilter">the customized filter which will be passed into engine,
  398. /// remove custom filter in current engine if pass pFilter as NULL
  399. /// It is the applications' responsibility to release the filter resource</param>
  400. ///
  401. /// <returns>
  402. /// Returns Acad::eOk if successful
  403. ///</returns>
  404. ///
  405. /// <remarks>
  406. /// NOTES:
  407. /// If the point cloud entity has internal clipping filter already, the pFilter
  408. /// will be treated as one element of PointCloudIntersectionFilter
  409. /// </remarks>
  410. ACDB_PORT Acad::ErrorStatus acdbSetPointCloudFilter(
  411. AcDbEntity* pEnt,
  412. IPointCloudFilter* pFilter);