Q: [v8i C++] PointCloud IPointCloudChannelDisplayHandler by Maury
Any there any examples of using this for making your own display style?
A: Re: [v8i C++] PointCloud IPointCloudChannelDisplayHandler by Simon Normand
Hi,
First, you cannot create custom display styles and have them listed in the View Attributes dialog.
The IPointCloudChannelDisplayHandler interface allows you to change the display of points for your custom point channel. If you are not familiar with the IPointCloudChannel interface, it allows you to store arbitrary per point data.
Here's an example of use of both interfaces:
I want to color the points that are within a certain distance of another MS element and display them in a different color.
The first I would create a point channel that stores a single integer value per point
int defaultValue = -1;Bentley::WString infoStr (L"Storing distances to element");PointCloudChannelPtr pMyChannel = PointCloudChannelManager::GetManager().CreateChannel (Bentley::WString(L"DistanceChannel"), &infoStr, sizeof(int), 1, &defaultValue, false);
Then I would run a query on points and calculate the distance for each point
PointCloudDataQueryPtr query = IPointCloudDataQuery::CreateBoundingBoxQuery(elHandle, origin, corner); int maxPoints = 50000; DPoint3d* pointsBuffer = new DPoint3d[maxPoints]; int pointsRead = 0; // alloc buffer for our channel int* channelBuffer = new int[maxPoints]; PointChannelQueryBufferVector channelQueries; channelQueries.push_back (PointChannelQueryBuffer (pMyChannel, channelBuffer)); // Perform the query for points do { pointsRead = query->GetDetailedPoints (maxPoints, pointsBuffer, NULL, NULL, NULL, NULL, NULL, &channelQueries); if (pointsRead) { // loop on each point, set its distance in channelBuffer[]
...
query->SubmitUpdate (pMyChannel); } } while (pointsRead > 0); delete [] pointsBuffer; delete [] channelBuffer;Now that I have setup my own point channel. I can create its display handler.
class DistanceChannelDisplayHandler : public IPointCloudChannelDisplayHandler, public PointCloudChannelHandler { protected: virtual bool _CanHandle (ElemHandleCR eh) const override {return true}; virtual UInt _OnDisplay (IViewContextP viewContext, ElemHandleCR eh, UInt bufferSize, DPoint3dP geomBuffer, RGBColorDef* rgbBuffer, UChar* selectionBuffer, UChar* classificationBuffer, void* channelBuffer) { // loop on each point, retrieve value from channel buffer, change the color in rgbBuffer ... return bufferSize; } };
Create an instance of DistanceDisplayChannelHandler and set it as the handler for my custom point channel.
pMyChannel->SetHandler (&myDistanceDisplayHandler);