private static void DrawTorusAndInliers(Document doc, FS_FEATURE_RESULT?result) { // fetch parameters of the torus found by FindSurface. XYZ center, axis; double mean_radius, tube_radius; FetchParametersOfTorus(result, out center, out axis, out mean_radius, out tube_radius); // create the inlier point cloud corresponding to the torus. string name = "Torus" + DirectShapeEngine.DirectTorusInstanceCount; ExtractInlierPointCloud(doc, name, S_TORUS_INLIER_COLOR); // find two edges of the torus part. XYZ tube_begin, tube_end; string last_pointcloud_name = InlierPointCloudEngine.GetPointCloudNames().Last(); XYZ[] inlier_points = InlierPointCloudEngine.GetCloudPoints(last_pointcloud_name).ToList().ConvertAll(x => (XYZ)x).ToArray(); CalculateTubeEdges(inlier_points, center, axis, out tube_begin, out tube_end); double positive_angle = FindSurfaceRevitPluginUtils.GetPositiveAngleBetween(tube_begin, tube_end, tube_begin.CrossProduct(tube_end)); // draw the torus on the Revit document. DirectShapeEngine.DrawTorus(doc, center, axis, mean_radius, tube_radius, tube_begin, positive_angle); }
/// <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 DrawPlaneAndInliers(Document doc, FS_FEATURE_RESULT?result) { // fetch parameters of the plane found by FindSurface. XYZ top_left, top_right, bottom_left, bottom_right; FetchParametersOfPlane(result, out bottom_left, out bottom_right, out top_left, out top_right); // create the inlier point cloud corresponding to the plane. string name = "Plane" + DirectShapeEngine.DirectPlaneInstanceCount; ExtractInlierPointCloud(doc, name, S_PLANE_INLIER_COLOR); // draw the plane on the Revit document. DirectShapeEngine.DrawPlane(doc, top_left, top_right, bottom_left, bottom_right); }
private static void DrawConeAndInliers(Document doc, FS_FEATURE_RESULT?result) { // fetch parameters of the cone found by FindSurface. XYZ top, bottom; double top_radius, bottom_radius; FetchParametersOfCone(result, out top, out bottom, out top_radius, out bottom_radius); // create the inlier point cloud corresponding to the cone. string name = "Cone" + DirectShapeEngine.DirectConeInstanceCount; ExtractInlierPointCloud(doc, name, S_CONE_INLIER_COLOR); // draw the cone on the Revit document. DirectShapeEngine.DrawCone(doc, top, bottom, top_radius, bottom_radius); }
private static void DrawCylinderAndInliers(Document doc, FS_FEATURE_RESULT?result) { // fetch parameters of the cylinder found by FindSurface. XYZ top, bottom; double radius; FetchParametersOfCylinder(result, out top, out bottom, out radius); // create the inlier point cloud corresponding to the cylinder. string name = "Cylinder" + DirectShapeEngine.DirectCylinderInstanceCount; ExtractInlierPointCloud(doc, name, S_CYLINDER_INLIER_COLOR); // draw the cylinder on the Revit document. DirectShapeEngine.DrawCylinder(doc, top, bottom, radius); }
private static void DrawSphereAndInliers(Document doc, FS_FEATURE_RESULT?result) { // fetch parameters of the sphere found by FindSurface. XYZ center; double radius; FetchParametersOfSphere(result, out center, out radius); // create the inlier point cloud corresponding to the sphere. string name = "Sphere" + DirectShapeEngine.DirectSphereInstanceCount; ExtractInlierPointCloud(doc, name, S_SPHERE_INLIER_COLOR); // draw the sphere on the Revit document. DirectShapeEngine.DrawSphere(doc, center, radius); }
/// <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> /// Initializes FindSurface, custom point cloud engines, DirectShapeManager instances when Revit loaded this plugin. /// </summary> public static bool OnPluginStartUp() { FS_CONTEXT_CREATION_ERROR error = FS_CONTEXT_CREATION_ERROR.FS_NO_ERROR; // initialize FindSurface s_find_surface = FindSurface.GetInstance(ref error); switch (error) { case FS_CONTEXT_CREATION_ERROR.FS_OUT_OF_MEMORY: TaskDialog.Show("FindSurface", "Context creation failed: FS_OUT_OF_MEMORY"); return(false); case FS_CONTEXT_CREATION_ERROR.FS_LICENSE_EXPIRED: TaskDialog.Show("FindSurface", "Context creation failed: FS_LICENSE_EXPIRED"); return(false); case FS_CONTEXT_CREATION_ERROR.FS_LICENSE_UNKNOWN: TaskDialog.Show("FindSurface", "Context creation failed: FS_LICENSE_UNKNOWN"); return(false); } // initialize parameters temporarily FindSurface.Accuracy = 0.003f; // Set Sensor Measurement Accuracy FindSurface.MeanDistance = 0.01f; // Set Mean Distance of Neighboring Points FindSurface.TouchRadius = 0.025f; // Touch Size of the Seed Region // initialize Custom Point Cloud Engines s_outlier_point_cloud_engine = new UniformGridPointCloudEngine(S_OUTLIER_PC_ENGINE_IDENTIFIER); PointCloudEngineRegistry.RegisterPointCloudEngine(S_OUTLIER_PC_ENGINE_IDENTIFIER, s_outlier_point_cloud_engine, false); s_inlier_point_cloud_engine = new OctreePointCloudEngine(S_INLIER_PC_ENGINE_IDENTIFIER); PointCloudEngineRegistry.RegisterPointCloudEngine(S_INLIER_PC_ENGINE_IDENTIFIER, s_inlier_point_cloud_engine, false); // initialize DirectShape Engines s_direct_shape_manager = new DirectShapeEngine(); return(true); }
/// <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(); }