Mesh creation algorithm

Technical discussions
Post Reply
Robert Ehrenwerth
Posts: 4
Joined: Mon Jun 22, 2020 7:34 am

Mesh creation algorithm

Post by Robert Ehrenwerth »

Hello all,

I try to do some basic research. Other cad software use some libraries which are doing the triangulation work. For example Gmsh, ICEM etc create the triangle mesh out of the CAD boundary representation.

Does someone know, which algorithm is used by dg kernel? It is internal use only? my quick look did not produce a clear way to get it.

Would appreciate for some more information!

nickz
Site Admin
Posts: 204
Joined: Fri Jul 26, 2013 3:58 am

Re: Mesh creation algorithm

Post by nickz »

Hi Robert
For parametric bspline objects we use the default OCCT BRepMesh_IncrementalMesh, which implements Delaunay's triangulation with the algorithm of Watson.
3DS and SOR types of objects use our own algorithms, which are a bit out of date, but we did not have enough reason to revisit it so far.
All are used a lot and work well.

To get mesh of an object use IEntity_DG.SetGeometryType("Mesh")

Code: Select all

IGeometry_DG iGeom = iEntity.SetGeometryType("Mesh");
IMesh mesh = iGeom as IMesh;
This will change the entity to mesh. Use

Code: Select all

IEntity_DG iEntity = iEntityOriginal.Clone();
prior the conversion, if you need to keep the original entity.
Regards

Robert Ehrenwerth
Posts: 4
Joined: Mon Jun 22, 2020 7:34 am

Re: Mesh creation algorithm

Post by Robert Ehrenwerth »

Thank you, Nick
Is there a way to control density of the mesh?

nickz
Site Admin
Posts: 204
Joined: Fri Jul 26, 2013 3:58 am

Re: Mesh creation algorithm

Post by nickz »

There is DeviationFactor of the component context. Its range is .001 to 1000. and the default is 1.0.
It can be modified via TheControl > GetView > IView > IKCContext > SetDoubleParam() :

Code: Select all

IView view = dgk.GetView() as IView;
IKCContext context = view as IKCContext;
context.SetDoubleParam(0, 0.5);			// 0-the parameter id
This code would make it twice as dense. Normally several experiments are needed to tune it in for performance vs quality.

Generally deviation is calculated automatically and optimized for rendering. To some extent it depends on the current zoom in the view, if it is a model in an active view. The actual deviation is multiplied by the DeviationFactor just before performing surface meshing.

Robert Ehrenwerth
Posts: 4
Joined: Mon Jun 22, 2020 7:34 am

Re: Mesh creation algorithm

Post by Robert Ehrenwerth »

Thank you, Nick.
Would this change density for all objects previously created?
Can I do it selectively for a particular object?
Thanks

nickz
Site Admin
Posts: 204
Joined: Fri Jul 26, 2013 3:58 am

Re: Mesh creation algorithm

Post by nickz »

No and Yes. DeviationFactor is used as part of presentation generation of an object, which happens during DGK.UpdateView() or otherwise rendering a frame and the view detects a modification of object's geometry or other rendering related property. So objects, which have already been rendered, will not change. All objects created or modified afterwards, will use the factor.

You can force updating presentation by calling IEntity_DG > GetGeometry() > IGeometry_DG > SetModified(), DGK.UpdateView() (the last call is same as IView_DG.Update())

In today's update we have added two tests TestDeviation*() to Samples\NET\C#\Tests\InterfaceTests.IEntityTest. Here is the code:

Code: Select all

	// Adding objects with different presentation mesh density
	void TestDeviation()
        {
            IEntity_DG iEnt = m_iStdShape.Sphere(1);

            m_iModel.AddEntity(iEnt);

            m_kernCAD.UpdateView();         // Force updating presentation of the first object before changing deviation factor

            IView view = m_kernCAD.GetView() as IView;
            IKCContext context = view as IKCContext;
            context.SetDoubleParam(0, 1000);            // The increased deviation factor (default 1.0) to make the rendered mesh more coarse

            IEntity_DG iEntNew = iEnt.Clone();
            IFrame_DG iFrame = iEntNew.GetLocation();
            iFrame.Translate1(2, 0, 0);

            m_iModel.AddEntity(iEntNew);
        }
        
        // Test late modification of deviation for an object
        void TestDeviation2()
        {
            IEntity_DG iEnt = m_iStdShape.Sphere(1);

            m_iModel.AddEntity(iEnt);

            IEntity_DG iEntNew = iEnt.Clone();
            IFrame_DG iFrame = iEntNew.GetLocation();
            iFrame.Translate1(2, 0, 0);

            m_iModel.AddEntity(iEntNew);

            // Update presentation for both
            m_kernCAD.UpdateView();

            // Modify the second only
            IView view = m_kernCAD.GetView() as IView;
            IKCContext context = view as IKCContext;
            context.SetDoubleParam(0, 1000);

            IGeometry_DG iGeom = iEntNew.GetGeometry();
            iGeom.SetModified();
            
            m_kernCAD.UpdateView();         // Update new entity's presentation before restoring the deviation factor

            // Restore the default. This test demoes selective, one off reduction of mesh density:
            context.SetDoubleParam(0, 1.0);
        }
Only order of magnitude (number of zeroes) in the deviation factor should matter.

Regards

Robert Ehrenwerth
Posts: 4
Joined: Mon Jun 22, 2020 7:34 am

Re: Mesh creation algorithm

Post by Robert Ehrenwerth »

Thank you, Nick

Post Reply