コード例 #1
0
 /// <summary>
 /// Determines if two objects are respectively shallow copies,
 /// new managed instantiations of the same geometry, or similar
 /// internal references to the exact same geometry, both in managed and in unmanaged code.
 /// </summary>
 /// <param name="one">The first object</param>
 /// <param name="other">The other object</param>
 /// <returns>True if indeed the objects are really the same. False otherwise.</returns>
 public static bool GeometryReferenceEquals(GeometryBase one, GeometryBase other)
 {
     if (object.ReferenceEquals(one, other))
     {
         return(true);
     }
     if (object.ReferenceEquals(one, null))
     {
         return(false);
     }
     if (object.ReferenceEquals(other, null))
     {
         return(false);
     }
     if (one.ConstPointer() != IntPtr.Zero && one.ConstPointer() == other.ConstPointer())
     {
         return(true);
     }
     if (one.m_shallow_parent != null && other.ConstPointer() != IntPtr.Zero && one.m_shallow_parent.ConstPointer() == other.ConstPointer())
     {
         return(true);
     }
     if (other.m_shallow_parent != null && one.ConstPointer() != IntPtr.Zero && other.m_shallow_parent.ConstPointer() == one.ConstPointer())
     {
         return(true);
     }
     if (one.m_shallow_parent != null && other.m_shallow_parent != null && other.m_shallow_parent.ConstPointer() != IntPtr.Zero &&
         one.m_shallow_parent.ConstPointer() == one.m_shallow_parent.ConstPointer())
     {
         return(true);
     }
     return(false);
 }
コード例 #2
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);
        }
コード例 #3
0
        internal override IntPtr _InternalGetConstPointer()
        {
            if (null != m_shallow_parent)
            {
                return(m_shallow_parent.ConstPointer());
            }

#if RHINO_SDK
            ObjRef obj_ref = m__parent as ObjRef;
            if (null != obj_ref)
            {
                return(obj_ref.GetGeometryConstPointer(this));
            }

            RhinoObject parent_object = ParentRhinoObject();
            if (parent_object == null)
            {
                FileIO.File3dmObject fileobject = m__parent as FileIO.File3dmObject;
                if (null != fileobject)
                {
                    return(fileobject.GetGeometryConstPointer());
                }
            }

            uint   serial_number          = 0;
            IntPtr ptr_parent_rhinoobject = IntPtr.Zero;
            if (null != parent_object)
            {
                serial_number          = parent_object.m_rhinoobject_serial_number;
                ptr_parent_rhinoobject = parent_object.m_pRhinoObject;
                if (IntPtr.Zero == ptr_parent_rhinoobject &&
                    parent_object.m__parent != null &&
                    parent_object.m__parent is ObjRef)
                {
                    ObjRef objref         = parent_object.m__parent as ObjRef;
                    IntPtr constPtrObjRef = objref.ConstPointer();
                    ptr_parent_rhinoobject = UnsafeNativeMethods.CRhinoObjRef_Object(constPtrObjRef);
                }
            }
            ComponentIndex ci = new ComponentIndex();
            // There are a few cases (like in ReplaceObject callback) where the parent
            // rhino object temporarily holds onto the CRhinoObject* because the object
            // is not officially in the document yet.
            if (ptr_parent_rhinoobject != IntPtr.Zero)
            {
                return(UnsafeNativeMethods.CRhinoObject_Geometry(ptr_parent_rhinoobject, ci));
            }
            return(UnsafeNativeMethods.CRhinoObject_Geometry2(serial_number, ci));
#else
            var fileobject = m__parent as Rhino.FileIO.File3dmObject;
            if (null != fileobject)
            {
                return(fileobject.GetGeometryConstPointer());
            }
            return(IntPtr.Zero);
#endif
        }
コード例 #4
0
        /// <summary>
        /// true if the geometry can be morphed by calling SpaceMorph.Morph(geometry)
        /// </summary>
        public static bool IsMorphable(GeometryBase geometry)
        {
            if (null == geometry)
            {
                return(false);
            }
            IntPtr pGeometry = geometry.ConstPointer();

            return(UnsafeNativeMethods.ON_Geometry_GetBool(pGeometry, GeometryBase.idxIsMorphable));
        }
コード例 #5
0
        /// <summary>
        /// Determines if two geometries equal one another, in pure geometrical shape.
        /// This version only compares the geometry itself and does not include any user
        /// data comparisons.
        /// This is a comparison by value: for two identical items it will be true, no matter
        /// where in memory they may be stored.
        /// </summary>
        /// <param name="first">The first geometry</param>
        /// <param name="second">The second geometry</param>
        /// <returns>The indication of equality</returns>
        public static bool GeometryEquals(GeometryBase first, GeometryBase second)
        {
            if (first == null && second == null)
            {
                return(true);
            }
            if (first == null || second == null)
            {
                return(false);
            }

            IntPtr first_ptr  = first.ConstPointer();
            IntPtr second_ptr = second.ConstPointer();

            bool rc = UnsafeNativeMethods.RH_RhinoCompareGeometry(first_ptr, second_ptr);

            Runtime.CommonObject.GcProtect(first, second);
            return(rc);
        }
コード例 #6
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);
        }
コード例 #7
0
 /// <summary>
 /// Checks geometry to see if it passes the basic GeometryAttributeFilter.
 /// </summary>
 /// <param name="rhObject">parent object being considered.</param>
 /// <param name="geometry">geometry being considered.</param>
 /// <param name="componentIndex">if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex.</param>
 /// <returns>
 /// true if the geometry passes the filter returned by GeometryAttributeFilter().
 /// </returns>
 public bool PassesGeometryAttributeFilter(DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex)
 {
   IntPtr pRhinoObject = IntPtr.Zero;
   if (rhObject != null)
     pRhinoObject = rhObject.ConstPointer();
   IntPtr pGeometry = IntPtr.Zero;
   if (geometry != null)
     pGeometry = geometry.ConstPointer();
   IntPtr ptr = NonConstPointer();
   return UnsafeNativeMethods.CRhinoGetObject_PassesGeometryAttributeFilter(ptr, pRhinoObject, pGeometry, componentIndex);
 }