For a PointCloud entity created using a PCG file, a simple way to get the coordinates of the points would be insert a spatial filter using the "acdbModifyPointCloudDataView" method. For the PointCloud entity created using RCP file, the way to insert a spatial filter is to use the "AcDbPointCloudEx::addSpatialFilter" method. While creating a spatial filter would still provide access to the point coordinates, the other method is to use the "AcDbPointCloudEx::traverseAllPointData" method.
Here is a sample code to identify the coordinates of the point using the "traverseAllPointData" method :
#include "AcPointCloud.h"
#include "AcDbPointCloudEx.h"
#include "AcDbPointCloudApi.h"
class MyPointCloudProcessor
: public IAcDbPointCloudPointProcessor
{
public:
MyPointCloudProcessor(){}
virtual ~MyPointCloudProcessor(){}
virtual ProcessSate process(
const IAcDbPointCloudDataBuffer* buffer)
{
const AcGePoint3d *pts = buffer->points();
for(int cnt = 0; cnt < buffer->numPoints(); cnt++)
{
AcGePoint3d pt = pts[cnt];
// Get the pt coordinates
}
return ProcessSate::Continue;
}
};
static void AdskMyTestCommand()
{
ads_point pt;
ads_name name;
if (acedEntSel
( L"Select a point cloud",
name, pt) != RTNORM)
return;
AcDbObjectId id;
if (acdbGetObjectId(id, name) != Acad::eOk)
return;
AcDbEntityPointer pEntity(id, AcDb::kForWrite);
if (pEntity.openStatus() != Acad::eOk)
return;
AcDbPointCloudEx *pPtCloud
= AcDbPointCloudEx::cast(pEntity);
if(pPtCloud == NULL)
return;
MyPointCloudProcessor *pPCProcessor
= new MyPointCloudProcessor();
// The last parameter is the Level of Detail.
// There is currently no way to get the maximum LOD value
// from a pointcloud entity.
// You can pass a value between 1 and 100 depending
// on the Level of detail required.
pPtCloud->traverseAllPointData(pPCProcessor, NULL,
IAcDbPointCloudDataBuffer::DataType::kColor, 2);
if(pPCProcessor != NULL)
{
delete pPCProcessor;
pPCProcessor = NULL;
}
}