Application: PointCloudEngine
Revit Platform: All
Revit Version: 2012.0
First Released For: 2012.0
Programming Language: C#
Skill Level: Advanced
Category: Geometry
Type: ExternalCommand

Subject: Point cloud engine examples.
Summary: 
Offers a variety of examples for custom point cloud engines. 

Classes: 
Autodesk.Revit.DB.PointClouds.IPointCloudAccess
Autodesk.Revit.DB.PointClouds.IPointCloudEngine
Autodesk.Revit.DB.PointClouds.IPointSetIterator
Autodesk.Revit.DB.PointClouds.CloudPoint
Autodesk.Revit.DB.PointClouds.PointCloudFilter
Autodesk.Revit.DB.PointCloudType
Autodesk.Revit.DB.PointCloudInstance

Project Files:
FileBasedPointCloud.cs
PointCloudAccessBase.cs
PointCloudCellStorage.cs
PointCloudEngineSample.cs
PredefinedPointCloud.cs
PredefinedPointCloudEngine.cs
XmlUtils.cs

Description: 
1.	Several variations on point cloud engines are provided by this sample.  In all cases, the point clouds themselves are represented by cells:
a.	A cell is a bounded rectangular 3D space defined by two points (in the point clouds coordinate system)
b.	Points are calculated in boundary lines running along the major axes of the cell.
c.	Points can be regular or have some randomization factors applied.
d.	All points in a given cell is assigned the same color.
e.	Multiple cells are permitted for a given point cloud.
2.	Predefined point cloud implementations are provided as examples of non-file-based point clouds. In non-file-based point clouds, Revit’s user interface cannot create and manage these point clouds.  The application must provide the ability to create the needed instance(s).  

A predefined point cloud

3.	A file-based point cloud implementation is provided.  The file format is a particular format of XML, where the boundary points, colors, and randomization option for each cell is specified.  The overall scale of the point cloud can also be specified.  The XML file should look similar to this:
<PointCloud>
    ///      <Scale value="2.5"/>
    ///      <Cell>
    ///        <LowerLeft X="-30" Y="-30" Z="0" />
    ///        <UpperRight X="30" Y="30" Z="200" />
    ///        <Color value="#000000" />
    ///        <Randomize value="True" />
    ///      </Cell>
    ///      <Cell>
    ///         <LowerLeft X="-30" Y="-10" Z="10" />
    ///         <UpperRight X="-29" Y="10" Z="150" />
    ///         <Color value="#CC3300" />
    ///         <Randomize value="False" />
    ///       </Cell>
    ///    </PointCloud>

A file-based point cloud

4.	The most complex part of the implementation is contained in the PointCloudAccessBase.ReadSomePoints() method.  This provides the implementation for both IPointCloudAccess.ReadPoints() and IPointSetIterator.ReadPoints(), wherein Revit requests a buffer of points which pass a given filter.  This is the method that provides points to Revit for display, selection, snapping, and other operations allowed by Revit.

Instructions: 
1.	You can instantiate a predefined point cloud instance with the Add-in command “Add predefined instance”
2.	You can instantiate a randomized version with the Add-in command “Add randomized instance”
3.	You can instantiate an instance with a non-default transform with the Add-in command “Add randomized instance at transform”
4.	You can instantiate a file-based point cloud by:
a.	From the Insert tab, select “Point Clouds”
b.	In the File selection dialog, change the file type to “Point Clouds (*.xml)
c.	Navigate to tower.xml in the sample directory (or another properly constructed XML file) and select it 
5.	You can write a default XML file with the Add-in command “Serialize point cloud (utility)”.  The file is written to the c:\ folder.