public void PromptForPointCloudSelection(UIDocument uiDoc, PointCloudInstance pcInstance)
{
Application app = uiDoc.Application.Application;
Selection currentSel = uiDoc.Selection;
PickedBox pickedBox = currentSel.PickBox(PickBoxStyle.Enclosing, "Select region of cloud for highlighting");
XYZ min = pickedBox.Min;
XYZ max = pickedBox.Max;
View view = uiDoc.ActiveView;
XYZ right = view.RightDirection;
XYZ up = view.UpDirection;
List<Plane> planes = new List<Plane>();
bool directionCorrect = IsPointAbovePlane(right, min, max);
planes.Add(app.Create.NewPlane(right, directionCorrect ? min : max));
planes.Add(app.Create.NewPlane(-right, directionCorrect ? max : min));
directionCorrect = IsPointAbovePlane(up, min, max);
planes.Add(app.Create.NewPlane(up, directionCorrect ? min : max));
planes.Add(app.Create.NewPlane(-up, directionCorrect ? max : min));
PointCloudFilter filter = PointCloudFilterFactory.CreateMultiPlaneFilter(planes);
Transaction t = new Transaction(uiDoc.Document, "Highlight");
t.Start();
pcInstance.SetSelectionFilter(filter);
pcInstance.FilterAction = SelectionFilterAction.Highlight;
t.Commit();
uiDoc.RefreshActiveView();
}
private static bool IsPointAbovePlane(XYZ normal, XYZ planePoint, XYZ point)
{
XYZ difference = point - planePoint;
difference = difference.Normalize();
double dotProduct = difference.DotProduct(normal);
return dotProduct > 0;
}