private static Result OnFindCommand(UIDocument ui_doc, FS_FEATURE_TYPE feature_type, string command_name, string shape_name, Action <Document, FS_FEATURE_RESULT?> post_action) { uint index; XYZ ray_origin = XYZ.Zero, ray_direction = XYZ.Zero; try { GenerateRay(ui_doc, out ray_origin, out ray_direction); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } // cast ray to point cloud and get an index of the point hit. if (OutlierPointCloudEngine.Cast(ray_origin, ray_direction, 0.01f, out index) == false) { TaskDialog.Show(command_name, "There is no points picked."); return(Result.Failed); } // run FindSurface to find shape FS_FEATURE_RESULT?result = FindSurface.RunFindSurface(feature_type, index); if (result == null) { TaskDialog.Show(command_name, $"FindSurface failed to find a {shape_name}."); return(Result.Failed); } post_action(ui_doc.Document, result); return(Result.Succeeded); }
public static Result OnFindThinRingTorusCommand(UIDocument ui_doc) { uint index0, index1, index2; XYZ ray0_origin = XYZ.Zero, ray0_direction = XYZ.Zero; XYZ ray1_origin = XYZ.Zero, ray1_direction = XYZ.Zero; XYZ ray2_origin = XYZ.Zero, ray2_direction = XYZ.Zero; try { GenerateRay(ui_doc, out ray0_origin, out ray0_direction); GenerateRay(ui_doc, out ray1_origin, out ray1_direction); GenerateRay(ui_doc, out ray2_origin, out ray2_direction); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } // cast ray to point cloud and get an index of the point hit. if (OutlierPointCloudEngine.Cast(ray0_origin, ray0_direction, 0.01f, out index0) == false) { TaskDialog.Show("FindThinRingTorus", "There is no points picked." + Environment.NewLine + "Command cancelled."); return(Result.Failed); } if (OutlierPointCloudEngine.Cast(ray1_origin, ray1_direction, 0.01f, out index1) == false) { TaskDialog.Show("FindThinRingTorus", "There is no points picked." + Environment.NewLine + "Command cancelled."); return(Result.Failed); } if (OutlierPointCloudEngine.Cast(ray2_origin, ray2_direction, 0.01f, out index2) == false) { TaskDialog.Show("FindThinRingTorus", "There is no points picked." + Environment.NewLine + "Command cancelled."); return(Result.Failed); } // run FindSurface to find shape FS_FEATURE_RESULT?result = FindSurface.RunFindThinRingTorus(index0, index1, index2); if (result == null) { TaskDialog.Show("FindThinRingTorus", $"FindSurface failed to find a thin ring torus."); return(Result.Failed); } switch (result.Value.type) { case FS_FEATURE_TYPE.FS_TYPE_CYLINDER: DrawCylinderAndInliers(ui_doc.Document, result); break; case FS_FEATURE_TYPE.FS_TYPE_SPHERE: DrawSphereAndInliers(ui_doc.Document, result); break; case FS_FEATURE_TYPE.FS_TYPE_TORUS: DrawTorusAndInliers(ui_doc.Document, result); break; } return(Result.Succeeded); }
/// <summary> /// Cleans up the stuff so that the plugin set to the initial state /// as if it is loaded at first. /// </summary> public static void OnCleanUpCommand() { // remove all point cloud instances s_temporary_outlier_deletion = true; OutlierPointCloudEngine.RemovePointCloud(); InlierPointCloudEngine.RemoveAllPointClouds(); DirectShapeEngine.RemoveAllDirectShapes(); OnPluginShutdown(); OnPluginStartUp(); }
/// <summary> /// Hides or unhides objects according to the check states of checked list boxes in View List tool window. /// </summary> public static void OnPluginIdling() { // check if there is a visibility change of point clouds in ViewListForm. foreach (KeyValuePair <string, ObjectVisibility> pair in ViewListForm.GetPointCloudsVisibilityChanged()) { string point_cloud_identifier = pair.Key; ObjectVisibility point_cloud_visibility = pair.Value; if (OutlierPointCloudEngine.ContainPointCloud(point_cloud_identifier)) { if (point_cloud_visibility.Visible) { OutlierPointCloudEngine.UnhidePointCloud(); } else { OutlierPointCloudEngine.HidePointCloud(); } } else if (InlierPointCloudEngine.ContainPointCloud(point_cloud_identifier)) { if (point_cloud_visibility.Visible) { InlierPointCloudEngine.UnhidePointCloud(point_cloud_identifier); } else { InlierPointCloudEngine.HidePointCloud(point_cloud_identifier); } } else { continue; } point_cloud_visibility.Expire(); } // check if there are visibility changes of DirectShape instances in ViewListForm. foreach (KeyValuePair <string, ObjectVisibility> shape in ViewListForm.GetShapesVisibilityChanged()) { if (shape.Value.Visible) { DirectShapeEngine.UnhideDirectShape(shape.Key); } else { DirectShapeEngine.HideDirectShape(shape.Key); } shape.Value.Expire(); } }
private static void FetchParametersOfSphere(FS_FEATURE_RESULT?result, out XYZ center, out double radius) { // get transform of the point clouds. Transform t = OutlierPointCloudEngine.GetPointCloudTransform(); // fetch parameters. FS_SPHERE_PARAMS p = result.Value.GetParamAsSphere(); System.Numerics.Vector3 c = p.Center; float r = p.Radius; // convert the parameters to the type Revit uses. center = t.OfPoint(new XYZ(c.X, c.Y, c.Z)); radius = r; }
/// <summary> /// Resets the plugin to the state of when users imported a point cloud file. /// </summary> /// <returns>false if any point cloud file has been opened or true otherwise</returns> public static bool OnResetCommand(Document document) { OnCleanUpCommand(); CloudPoint[] points; if (s_xyz == null || s_xyz.Length == 0) { return(false); } FindSurfaceRevitPluginUtils.Pack(s_xyz, s_color, out points); OutlierPointCloudEngine.CreatePointCloud(document, s_file_full_name, points, Transform.Identity, s_subdivision); FindSurface.CleanUp(); FindSurface.SetPointCloud(s_xyz); return(true); }
/// <summary> /// Creates a point cloud and send the data to FindSurface when users imported a point cloud file using Open button in FindSurface tab. /// </summary> /// <param name="doc">The active document that Revit uses</param> /// <param name="file_full_name">The name of imported file</param> /// <param name="xyz_array">Imported xyz data</param> /// <param name="color_array">Imported color data</param> /// <param name="subdivision">Subdivision number</param> /// <param name="unit">The base unit of when the inspector displays information</param> public static void OnOpenCommand(Document doc, string file_full_name, float[] xyz_array, int[] color_array, int subdivision, Units unit) { s_file_full_name = file_full_name; s_xyz = xyz_array; s_color = color_array; s_subdivision = subdivision; s_measurementUnit = unit; CloudPoint[] points; FindSurfaceRevitPluginUtils.Pack(xyz_array, color_array, out points); s_temporary_outlier_deletion = true; OutlierPointCloudEngine.CreatePointCloud(doc, file_full_name, points, Transform.Identity, subdivision); FindSurface.CleanUp(); FindSurface.SetPointCloud(xyz_array); }
public static Result OnFindDiskCylinderCommand(UIDocument ui_doc) { uint index0, index1, index2; XYZ ray0_origin = XYZ.Zero, ray0_direction = XYZ.Zero; XYZ ray1_origin = XYZ.Zero, ray1_direction = XYZ.Zero; XYZ ray2_origin = XYZ.Zero, ray2_direction = XYZ.Zero; try { GenerateRay(ui_doc, out ray0_origin, out ray0_direction); GenerateRay(ui_doc, out ray1_origin, out ray1_direction); GenerateRay(ui_doc, out ray2_origin, out ray2_direction); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } // cast ray to point cloud and get an index of the point hit. if (OutlierPointCloudEngine.Cast(ray0_origin, ray0_direction, 0.01f, out index0) == false) { TaskDialog.Show("FindDiskCylinder", "There is no points picked." + Environment.NewLine + "Command cancelled."); return(Result.Failed); } if (OutlierPointCloudEngine.Cast(ray1_origin, ray1_direction, 0.01f, out index1) == false) { TaskDialog.Show("FindDiskCylinder", "There is no points picked." + Environment.NewLine + "Command cancelled."); return(Result.Failed); } if (OutlierPointCloudEngine.Cast(ray2_origin, ray2_direction, 0.01f, out index2) == false) { TaskDialog.Show("FindDiskCylinder", "There is no points picked." + Environment.NewLine + "Command cancelled."); return(Result.Failed); } // run FindSurface to find shape FS_FEATURE_RESULT?result = FindSurface.RunFindDiskCylinder(index0, index1, index2); if (result == null) { TaskDialog.Show("FindDiskCylinder", $"FindSurface failed to find a disk cylinder."); return(Result.Failed); } DrawCylinderAndInliers(ui_doc.Document, result); return(Result.Succeeded); }
private static void FetchParametersOfCylinder(FS_FEATURE_RESULT?result, out XYZ top, out XYZ bottom, out double radius) { // get transform of the point clouds. Transform t = OutlierPointCloudEngine.GetPointCloudTransform(); // fetch parameters. FS_CYLINDER_PARAMS p = result.Value.GetParamAsCylinder(); System.Numerics.Vector3 tc = p.Top; System.Numerics.Vector3 bc = p.Bottom; float r = p.Radius; // convert the parameters to the type Revit uses. top = t.OfPoint(new XYZ(tc.X, tc.Y, tc.Z)); bottom = t.OfPoint(new XYZ(bc.X, bc.Y, bc.Z)); radius = r; }
private static void FetchParametersOfTorus(FS_FEATURE_RESULT?result, out XYZ center, out XYZ axis, out double mean_radius, out double tube_radius) { // get transform of the point clouds. Transform t = OutlierPointCloudEngine.GetPointCloudTransform(); // fetch parameters. FS_TORUS_PARAMS p = result.Value.GetParamAsTorus(); System.Numerics.Vector3 c = p.Center; System.Numerics.Vector3 a = p.Normal; float mr = p.MeanRadius; float tr = p.TubeRadius; // convert the parameters to the type Revit uses. center = t.OfPoint(new XYZ(c.X, c.Y, c.Z)); axis = t.OfVector(new XYZ(a.X, a.Y, a.Z)).Normalize(); mean_radius = mr; tube_radius = tr; }
private static void FetchParametersOfPlane(FS_FEATURE_RESULT?result, out XYZ bottom_left, out XYZ bottom_right, out XYZ top_left, out XYZ top_right) { // get transform of the point clouds. Transform t = OutlierPointCloudEngine.GetPointCloudTransform(); // fetch parameters. FS_PLANE_PARAMS p = result.Value.GetParamAsPlane(); System.Numerics.Vector3 lower_left = p.LowerLeft; System.Numerics.Vector3 lower_right = p.LowerRight; System.Numerics.Vector3 upper_left = p.UpperLeft; System.Numerics.Vector3 upper_right = p.UpperRight; // convert the parameters to the type Revit uses. bottom_left = t.OfPoint(new XYZ(lower_left.X, lower_left.Y, lower_left.Z)); bottom_right = t.OfPoint(new XYZ(lower_right.X, lower_right.Y, lower_right.Z)); top_left = t.OfPoint(new XYZ(upper_left.X, upper_left.Y, upper_left.Z)); top_right = t.OfPoint(new XYZ(upper_right.X, upper_right.Y, upper_right.Z)); }
private static void ExtractInlierPointCloud(Document doc, string inlier_identifier, int highlight_color) { CloudPoint[] original_points = OutlierPointCloudEngine.GetCloudPoint(); List <CloudPoint> inlier_point_list = new List <CloudPoint>(); List <CloudPoint> outlier_point_list = new List <CloudPoint>(); List <float> outlier_xyz = new List <float>(); // this is a flag array of which each element is set when the point of its corresponding location is in outlier. bool[] outlier_flags = FindSurface.GetInOutlierFlags(); for (int k = 0; k < outlier_flags.Length; k++) { float x = original_points[k].X; float y = original_points[k].Y; float z = original_points[k].Z; int color = original_points[k].Color; if (outlier_flags[k]) // outlier { outlier_point_list.Add(new CloudPoint(x, y, z, color)); outlier_xyz.AddRange(new float[] { x, y, z }); } else // inlier { color = FindSurfaceRevitPluginUtils.MixARGB(color, highlight_color); inlier_point_list.Add(new CloudPoint(x, y, z, color)); } } Transform outlier_transform = OutlierPointCloudEngine.GetPointCloudTransform(); // replace outlier (or original one) to new outlier points. s_temporary_outlier_deletion = true; OutlierPointCloudEngine.CreatePointCloud(doc, "Outlier", outlier_point_list.ToArray(), outlier_transform, s_subdivision); // give new outlier points to FindSurface. FindSurface.CleanUp(); FindSurface.SetPointCloud(outlier_xyz.ToArray()); // create inlier point cloud. InlierPointCloudEngine.CreatePointCloud(doc, inlier_identifier, inlier_point_list.ToArray(), outlier_transform); }
/// <summary> /// Deletes the instance wrapper of point clouds and direct shapes when they were deleted by users in Revit document. /// </summary> /// <param name="e">The arguments of the event</param> public static void OnContentChanged(Autodesk.Revit.DB.Events.DocumentChangedEventArgs e) { // when there are deleted objects foreach (ElementId eid in e.GetDeletedElementIds()) { // if the deleted object is PointCloud type if (OutlierPointCloudEngine.ContainPointCloud(eid)) { PromptOutlierDeletedWarning(); OutlierPointCloudEngine.RemovePointCloud(); } else if (InlierPointCloudEngine.ContainPointCloud(eid)) { InlierPointCloudEngine.RemovePointCloud(eid); } else if (DirectShapeEngine.ContainDirectShape(eid)) { DirectShapeEngine.RemoveDirectShape(eid); } } }
/// <summary> /// Removes all the stuffs this plugin made when Revit closed the document. /// </summary> /// <param name="e">The arguments of the event</param> public static void OnDocumentClosing(Autodesk.Revit.DB.Events.DocumentClosingEventArgs e) { OutlierPointCloudEngine.RemovePointCloud(); InlierPointCloudEngine.RemoveAllPointClouds(); DirectShapeEngine.RemoveAllDirectShapes(); }