Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Point Clouds > Inserting a Point Cloud into a Drawing
Inserting a Point Cloud into a Drawing

Here is an example of inserting a point cloud file inside the drawing. The code fragment creates a point cloud object, linking it with an external point cloud file named pointCloud.pcg, inserts it into model space of the drawing, and adds two clipping boundaries for the created point cloud entity. Note that the point cloud module must be loaded before working with point cloud objects.


  /**********************************************************************/
  /* Load the point cloud module                                        */
  /**********************************************************************/
  ::odrxDynamicLinker()->loadModule(DbPointCloudObjModuleName);
  
  /**********************************************************************/
  /* Open the Block Table                                               */
  /**********************************************************************/
  OdDbBlockTablePtr pTable  = pDb->getBlockTableId().safeOpenObject(OdDb::kForWrite);
  OdDbObjectId blockTableID = pDb->getBlockTableId();
 
  /**********************************************************************/
  /* Open the Model Space block                                         */
  /**********************************************************************/
  OdDbBlockTableRecordPtr pModelSpace = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite); 

  /*********************************************************************************************************/
  /* Get the point cloud dictionary, create the point cloud definition object and add it to the dictionary */
  /*********************************************************************************************************/
  OdDbObjectId pointCloudDictId = OdDbPointCloudDef::createPointCloudDictionary(*(pDb.get()));
  OdDbPointCloudDefPtr pPointCloudDef = OdDbPointCloudDef::createObject();
  OdDbDictionaryPtr pPointCloudDict = pointCloudDictId.safeOpenObject(OdDb::kForWrite);
  OdDbObjectId pointCloudDefId = pPointCloudDict->setAt(pPointCloudDict->suggestName("pointCloud.pcg", 15), pPointCloudDef);
  pPointCloudDef->setSourceFileName("pointCloud.pcg");
  pPointCloudDict.release();

  /*********************************************************************************************************/
  /* Create the point cloud entity, link it to the point cloud definition object and add it to model space */
  /*********************************************************************************************************/
  OdDbPointCloudPtr pPointCloud = OdDbPointCloud::createObject();
  pPointCloud->setPointCloudDefId(pointCloudDefId);
  OdDbObjectId pointCloudId = pModelSpace->appendOdDbEntity(pPointCloud);
  
  /*****************************************************************************************************************************************************/
  /* Create the OdDbPointCloudDefReactor object, link it to the point cloud definition object and point cloud entity.                                  */
  /* The OdDbPointCloudDefReactor object is used to notify point cloud entities of relevant modifications to their associated OdbPointCloudDef object. */
  /* Erasing the OdbPointCloudDef object erases all dependent OdDbPointCloud objects.                                                                  */
  /*****************************************************************************************************************************************************/
  OdDbPointCloudDefReactorPtr pPointCloudDefReactor = OdDbPointCloudDefReactor::createObject();
  OdDbObjectId defReactorId = pDb->addOdDbObject(pPointCloudDefReactor, pPointCloud->objectId());
  pPointCloudDef->addPersistentReactor(defReactorId);
  pPointCloud->setReactorId(defReactorId);

  /*************************************************************************/
  /* Create two clipping boundaries and add them to the point cloud entity */
  /*************************************************************************/ 
  OdDbPointCloudClipping clip1 = OdDbPointCloudClipping();
  clip1.setRectangle(OdGePoint2d(-16,-7), OdGePoint2d(-1,6));
  OdDbPointCloudClipping clip2 = OdDbPointCloudClipping();
  clip2.setRectangle(OdGePoint2d(-8,-7), OdGePoint2d(-1,-1.5));
  
  pPointCloud->addClippingBoundary(clip1);
  pPointCloud->addClippingBoundary(clip2);
  
  /******************************************************/
  /* Set the point cloud entity to be displayed clipped */
  /******************************************************/
  pPointCloud->setShowClipping(true);

  /******************************************************/
  /* Release smart pointers                             */
  /******************************************************/
  pPointCloudDef = 0;
  pPointCloud = 0;
  pPointCloudDefReactor = 0;

A more efficient way for creating point cloud entities uses the DBPOINTCLOUDOBJ_EXPORT::oddbCreatePointCloudEntity() method. It does all the work except applying clipping boundaries: creates the OdDbPointCloud object, appends it to the database, applies specified attributes, restores or creates new links to the OdDbPointCloudDef object, and adds reactors. The previous code will be changed to the following:


  /**********************************************************************/
  /* Load the point cloud module                                        */
  /**********************************************************************/
  ::odrxDynamicLinker()->loadModule(DbPointCloudObjModuleName);
  
  /**********************************************************************/
  /* Open the Block Table                                               */
  /**********************************************************************/
  OdDbBlockTablePtr pTable  = pDb->getBlockTableId().safeOpenObject(OdDb::kForWrite);
  OdDbObjectId blockTableID = pDb->getBlockTableId();
 
  /**********************************************************************/
  /* Open the Model Space block                                         */
  /**********************************************************************/
  OdDbBlockTableRecordPtr pModelSpace = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
  
  /**********************************************************************/
  /* Create the point cloud entity                                      */
  /**********************************************************************/
  OdDbPointCloudPtr pPointCloud;
  ::oddbCreatePointCloudEntity(pModelSpace, pPointCloud, "", "pointCloud.pcg");

  /*************************************************************************/
  /* Create two clipping boundaries and add them to the point cloud entity */
  /*************************************************************************/ 
  OdDbPointCloudClipping clip1 = OdDbPointCloudClipping();
  clip1.setRectangle(OdGePoint2d(-16,-7), OdGePoint2d(-1,6));
  OdDbPointCloudClipping clip2 = OdDbPointCloudClipping();
  clip2.setRectangle(OdGePoint2d(-8,-7), OdGePoint2d(-1,-1.5));
  
  pPointCloud->addClippingBoundary(clip1);
  pPointCloud->addClippingBoundary(clip2);
  
  /**************************************/
  /* Enable showing clipping boundaries */
  /**************************************/
  pPointCloud->setShowClipping(true);
      
  pPointCloud = 0;

See Also

Working with Point Clouds

Working with Point Cloud Definitions

Working with Point Cloud Entities

Rendering Point Clouds

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.