Page 1 of 1

Extract geometry from brep file

Posted: Fri Jul 03, 2020 2:27 am
by Fergus Wates
Hello everyone
I need to load simple brep files (turning parts) in C#. I managed to load my brep file and read the number of objects. Now I need to get the geometrical parameters (width, diameter, length, etc.). I am not sure know how it works, despite I read the documentations. I would be very happy to get any help, thanks!!

Re: Extract geometry from brep file

Posted: Mon Jul 06, 2020 4:48 am
by Prashant Kande
Hi Fergus

.brep format loads solids, etc. as bspline brep type.

The loaded structures are not aware of what the object represents. It is up to the application to interpret the input.

The easiest way would be to store some additional info with your app's document which would identify the objects by its indices or names.

Generally analyzing objects on the run is tricky. You need to have some additional information about what to expect. For example, if you know that an object is a cylinder, you could figure out its axis, diameter and length by using tightest bounding boxes demonstrated in Cloud sample. There are ways to do more detailed analysis, of course, but you would need to come up with some algorithm, which normally is not too difficult.

Often vertices and edges give good idea about the shape and its dimensions.

Regards

Re: Extract geometry from brep file

Posted: Tue Jul 07, 2020 6:36 am
by Fergus Wates
Thank you, Prashant
The bounding box technique would be handy. I could not see how it is supposed to work, though. I have looked at C# version. For knot.mdg it seems to have worked OK, but when I force to load (typing the *.step filer) the installed linkrods.step shows an error: "Could not load the points".
Would you have a suggestion?
Thank you

Re: Extract geometry from brep file

Posted: Wed Jul 08, 2020 6:17 am
by Prashant Kande
You are right. It should work. This is an ancient sample. We are looking into reworking it. For now please change the beginning of LoadPointCloud()
from

Code: Select all

	private void LoadPointCloud()
        {
            // Get extension of the model path to check that it is .csv or .xyz
            var strModelPath = m_kernCAD.ModelPath;
            strModelPath.ToLower(); // Extension can be in upper case
            bool dataIsMdgFile = strModelPath.LastIndexOf("mdg") >= 0;

            if (dataIsMdgFile)
                LoadPointCloudFromMDG(m_iModel as IModel);
            else
            {
                // The main case
                var countObjects = m_iModel.GetEntityCount();
                if (countObjects < 1)
                {
                    MessageBox.Show("The model is empty");
                    return;
                }

                // Leave commented until implement interface from Entity_DG to ISectionPointSet
                // Dim iEntity As IEntity_DG = m_iModel.GetEntityAt(0)
                // m_iSectPointSet = iEntity
                var iSection = m_iModel.GetEntityAt(0) as ISection;
                m_iSectPointSet = iSection as ISectionPointSet;
            }
            
             if (m_iSectPointSet == null)
                return;
            ....
To

Code: Select all

	private void LoadPointCloud()
        {
            IEntity_DG iEntity = m_iModel.GetEntityAt(0);
            if(iEntity.GetGeometryType() != "PointArray")
                LoadPointCloudFromMDG(m_iModel as IModel);
            else
                m_iSectPointSet = iEntity as ISectionPointSet;
            
            if (m_iSectPointSet == null)
                return;
            m_iSectPointSet.PointSize = 2;	// Make points visible better
            ...
Regards

Re: Extract geometry from brep file

Posted: Mon Jul 13, 2020 3:17 am
by Prashant Kande
This change was added to the Friday's update. We have also sorted out a couple of issues in conversion brep to point set. The sample was further simplified a little as well.
Regards