RevitAPI: 如何获取点云PointCloud数据?

来源:互联网 发布:国考公务员 知乎 编辑:程序博客网 时间:2024/05/22 15:22

通过Revit菜单的“插入>点云"操作,可以把点云数据插入到Revit中,那么如何才能获得导入的这些点云数据呢?

通过使用RevitLookup查看到,点云数据在RevitAPI中表现为PointCloudInstance,再看PointCloudInstance有个方法叫GetPoints(),这个方法就是我们想要的。


GetPoints()有三个参数

public PointCollection GetPoints(PointCloudFilter filter, double averageDistance, int numPoints);

averageDistance表示最小点距离,这个值越小,在一定范围内返回的点越多。

numPoints表示返回点的最大数量

filter是一个过滤器,通过条件来过滤哪些点被返回。

问题就在于如何创建filter,经过查找发现PointCloudFilter这个类没有构造函数,也没有静态的Create函数,也无法通过Document.Create或者Application.Create来创建,不过我们找到了PointCloudFilterFactory类的CreateMultiPlaneFilter函数,

public static PointCloudFilter CreateMultiPlaneFilter(IList<Autodesk.Revit.DB.Plane> planes);public static PointCloudFilter CreateMultiPlaneFilter(IList<Autodesk.Revit.DB.Plane> planes, int exactPlaneCount);

planes:一系列的面,过滤出所有位于这些面正方向的点。可以理解为这些面形成一个包围区域,返回包围区域内的点。包围区域可以是非闭合的。

exactPlaneCount:精确匹配的面的个数。数字越大,匹配月精确,同时速度越慢。不指定该数值,则默认是planes的数量。

下面的代码展示如何使用过滤出一个方盒内的点。

if (pointCloudInstance != null){    int SIZE = 100;    List<Plane> planes = new List<Plane>();    var min = new XYZ(-SIZE,-SIZE, -SIZE);    var max = new XYZ(SIZE, SIZE, SIZE);    //x planes    planes.Add(new Plane(XYZ.BasisX, min));    planes.Add(new Plane(-XYZ.BasisX, max));    //y planes    planes.Add(new Plane(XYZ.BasisY, min));    planes.Add(new Plane(-XYZ.BasisY, max));    //z planes    planes.Add(new Plane(XYZ.BasisZ, min));    planes.Add(new Plane(-XYZ.BasisZ, max));    PointCloudFilter pcf = PointCloudFilterFactory.CreateMultiPlaneFilter(planes);    var points = pointCloudInstance.GetPoints(pcf, 1, 100000);}


0 0