Line/object set intersection

Technical discussions
JM_
Posts: 6
Joined: Tue Aug 27, 2013 7:10 am

Line/object set intersection

Postby JM_ » Wed Jan 22, 2020 1:01 am

Hi
I have an old app which does line/model intersection at some point. I think the code was copied from Cannon sample. I do not see it in v6. What is the new way of doing it?
Looking forward for a hint
Thanks

Prashant Kande
Posts: 49
Joined: Mon Apr 04, 2016 4:55 am

Re: Line/object set intersection

Postby Prashant Kande » Thu Jan 23, 2020 3:33 am

Hi JM_
The old code from Cannon (we plan adding it back in the next version) should work. KC interface is still supported.

If you prefer doing it the new way it can be done per face:

Code: Select all

   public void GetRayIntersections()
        {
            // All entities independently of level
            IEntityArray_DG iEntArray = m_iModel.GetEntityArray(true);
            int n = iEntArray.GetCount();
            for (int i = 0; i < n; i++)
            {
                IEntity_DG iEntity = iEntArray.GetAt(i);
                GetEnityRayIntersections(iEntity);
            }
        }

        public void GetEnityRayIntersections(IEntity_DG iEntity)
        {
            string name = iEntity.GetName();
            if (iEntity.GetGeometryType() != "BRep")
                return;
            IBRepGeometry_DG iBrepGeom = iEntity.GetGeometry() as IBRepGeometry_DG;
            if (iBrepGeom == null)
                return;             // Empty geometry
            IBRepShape_DG iShape = iBrepGeom.GetShape();
            if (iShape == null)
                return;             // Empty geometry
            IShapeArray_DG iShapeArray = iShape.GetSubShapes(ShapeType_DG.eShTypeFaceDG);
            var n = iShapeArray.GetCount();
            for (var i = 0; i < n; i++)
            {
                IBRepFace_DG iFace = iShapeArray.GetAt(i) as IBRepFace_DG;
                GetFaceRayIntersections(iFace);
            }
        }

        public void GetFaceRayIntersections(IBRepFace_DG iFace)
        {
           //Somewhere on the start:
           // IObjectGenerator_DG m_gen = iModel as IObjectGenerator_DG;
           //Or little slower but does not need a model:
           // DIObjGeneratorClass generator = new DIObjGeneratorClass();   IObjectGenerator_DG m_gen = generator as IObjectGenerator_DG;
           
           ICurve_DG iCurve = m_gen.Create("Line_DG") as ICurve_DG;

            IUVSurface_DG iSurface = iFace.GetSurface();

            IPointArray_DG points;
            IPointArray_DG parameters;
            ICurveArray_DG segments;
            I2DPointArray_DG segmentParams;

            iSurface.GetCurveIntersection(iCurve, out points, out parameters, out segments, out segmentParams);

            int n = points.GetCount();
            for (var i = 0; i < n; i++)
            {
                Point_DG pt = points.GetPoint(i);
                double x = pt.x[0];
                //....
            }
        }


I have omitted here checking that the out parameters are within the face's range.

We do have plans of doing it on higher (model probably) level

Regards


Return to “General Issues”

Who is online

Users browsing this forum: No registered users and 6 guests