Exemplo n.º 1
0
        /// <summary>
        /// Computes draft curve silhouettes of a shape.
        /// </summary>
        /// <param name="geometry">Geometry whose silhouettes need to be computed. Can be Brep, BrepFace, Mesh, or Extrusion.</param>
        /// <param name="draftAngle">The draft angle in radians. Draft angle can be a positive or negative value.</param>
        /// <param name="pullDirection">3d direction for the mold to be pulled in, directed away from the object.</param>
        /// <param name="tolerance">
        /// Tolerance to use for determining projecting relationships.
        /// Surfaces and curves that are closer than tolerance, may be treated as projecting.
        /// When in doubt use RhinoDoc.ModelAbsoluteTolerance.
        /// </param>
        /// <param name="angleToleranceRadians">
        /// Angular tolerance to use for determining projecting relationships.
        /// A surface normal N that satisfies N o cameraDirection &lt; Sin(angleToleranceRadians) may be considered projecting.
        /// When in doubt use RhinoDoc.ModelAngleToleranceRadians.
        /// </param>
        /// <param name="cancelToken">Computation cancellation token.</param>
        /// <returns>Array of silhouette curves.</returns>
        /// <since>7.0</since>
        public static Silhouette[] ComputeDraftCurve(
            GeometryBase geometry,
            double draftAngle,
            Vector3d pullDirection,
            double tolerance,
            double angleToleranceRadians,
            System.Threading.CancellationToken cancelToken
            )
        {
            IntPtr const_ptr_geometry = geometry.ConstPointer();

            ThreadTerminator terminator = null;

            if (cancelToken != System.Threading.CancellationToken.None)
            {
                terminator = new ThreadTerminator();
                cancelToken.Register(terminator.RequestCancel);
            }
            IntPtr ptr_terminator = terminator == null ? IntPtr.Zero : terminator.NonConstPointer();

            IntPtr ptr_silhouettes = UnsafeNativeMethods.TLC_Sillhouette3(const_ptr_geometry, draftAngle, pullDirection, tolerance, angleToleranceRadians, ptr_terminator);

            Silhouette[] rc = FromClassArray(ptr_silhouettes);
            UnsafeNativeMethods.TLC_SilhouetteArrayDelete(ptr_silhouettes);
            if (terminator != null)
            {
                terminator.Dispose();
            }
            GC.KeepAlive(geometry);
            return(rc);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Compute silhouettes of a shape for a perspective projection.
        /// </summary>
        /// <param name="geometry">Geometry whose silhouettes need to be computed. Can be Brep, BrepFace, Mesh, or Extrusion.</param>
        /// <param name="silhouetteType">Types of silhouette to compute.</param>
        /// <param name="perspectiveCameraLocation">Location of perspective camera.</param>
        /// <param name="tolerance">Tolerance to use for determining projecting relationships.
        /// Surfaces and curves that are closer than tolerance, may be treated as projecting.
        /// When in doubt use RhinoDoc.ModelAbsoluteTolerance.</param>
        /// <param name="angleToleranceRadians">Angular tolerance to use for determining projecting relationships.
        /// A surface normal N that satisfies N o cameraDirection &lt; Sin(angleToleranceRadians) may be considered projecting.
        /// When in doubt use RhinoDoc.ModelAngleToleranceRadians.</param>
        /// <param name="clippingPlanes">Optional collection of clipping planes.</param>
        /// <param name="cancelToken">Computation cancellation token.</param>
        /// <returns>Array of silhouette curves.</returns>
        public static Silhouette[] Compute(
            GeometryBase geometry,
            SilhouetteType silhouetteType,
            Point3d perspectiveCameraLocation,
            double tolerance,
            double angleToleranceRadians,
            IEnumerable <Plane> clippingPlanes,
            System.Threading.CancellationToken cancelToken)
        {
            IntPtr const_ptr_geometry = geometry.ConstPointer();

            Plane[] planes      = null;
            int     plane_count = 0;

            if (clippingPlanes != null)
            {
                List <Plane> p = new List <Plane>(clippingPlanes);
                plane_count = p.Count;
                planes      = p.ToArray();
            }

            ThreadTerminator terminator     = null;
            IntPtr           ptr_terminator = IntPtr.Zero;

            if (cancelToken != System.Threading.CancellationToken.None)
            {
                terminator     = new ThreadTerminator();
                ptr_terminator = terminator.NonConstPointer();
                cancelToken.Register(terminator.RequestCancel);
            }

            UnsafeNativeMethods.SilEventType s = (UnsafeNativeMethods.SilEventType)silhouetteType;
            IntPtr ptr_silhouettes             = UnsafeNativeMethods.TLC_Sillhouette2(const_ptr_geometry, s, perspectiveCameraLocation, tolerance, angleToleranceRadians, planes, plane_count, ptr_terminator);

            Silhouette[] rc = FromClassArray(ptr_silhouettes);
            UnsafeNativeMethods.TLC_SilhouetteArrayDelete(ptr_silhouettes);
            if (terminator != null)
            {
                terminator.Dispose();
            }
            GC.KeepAlive(geometry);
            return(rc);
        }
Exemplo n.º 3
0
        /// <summary>You must call Disable on the reporter output if it's not null when you are done with it. It will NOT clean itself.
        /// You should call Dispose on the terminator if it's not null, because that will keep it alive for the time of the computation.</summary>
        internal static void MarshalProgressAndCancelToken(System.Threading.CancellationToken cancel, IProgress <double> progress,
                                                           out IntPtr ptrTerminator, out int progressInt, out ProgressReporter reporter, out ThreadTerminator terminator)
        {
            reporter    = null;
            progressInt = 0;
            if (progress != null)
            {
                reporter    = new ProgressReporter(progress);
                progressInt = reporter.SerialNumber;
                reporter.Enable();
            }

            terminator = null;
            if (cancel != System.Threading.CancellationToken.None)
            {
                terminator = new ThreadTerminator();
                cancel.Register(terminator.RequestCancel);
            }
            ptrTerminator = terminator == null ? IntPtr.Zero : terminator.NonConstPointer();
        }