normal to mesh elements

Hello forum

using Tetgen I generated from a watertight surface mesh
a volume mesh.

Since I want a second order mesh I add, to each first
order tetrahedron, the midside nodes, simply by calculating
the midpoint of each mesh segment.

Since I would like to have "curved", isoparametric elements
I projected the miside nodes on the faces of the geometry,
using one of the OpenCascade tools.

The result is shown in Fig. 1, in which only the exterior
mesh of a volume mesh is shown. The normal to each surface
element is programmatically computed using the "first order"
nodes: when a 2nd order triangle {1,2,3,4,5,6} is encountered,
the normal is computed using {1,3,6}.
In building the mesh representation my redefined method
::getNormal() is called, for each element.

Problem:

if I show the volume mesh, instead of the surface mesh,
the result is shown in Fig. 2.
Several "curved" face elements are encountered: since {1,2,3,4,5,6}
is NOT flat, by definition, the normal is zero.

This is why I see several "dark", or "black" surface elements

1) in my opinion this has to do with the method

MeshVS_DataSource::computeNormalsByElement(...)

My attempt:
In my data source class, derived from the abstract one,
I redefined the mentioned method, but it is never called:
an exit(x) instruction at the begining of the redefined
function is never executed

2) I suspect that this behavior has something to share with
the static functions in MeshTools

//! Get one of normals to polygon described by these points.
//! If the polygon isn't planar, function returns false
Standard_EXPORT static Standard_Boolean GetNormal (const TColStd_Array1OfReal& Nodes, gp_Vec& Norm);

//! Get an average of normals to non-planar polygon described by these points or compute
//! normal of planar polygon. If the polygon isn't planar, function returns false
Standard_EXPORT static Standard_Boolean GetAverageNormal (const TColStd_Array1OfReal& Nodes, gp_Vec& Norm);

Questions:

1) since the view of the volume elements requires
the calculation of the normals for each face of each element,
for the correct light reflection, at what level the method

MeshVS_DataSource::computeNormalsByElement(...)

is called? Within the mesh builder?

Regards
Grazie mille
Giovanni

Attachments: 
gkv311 n's picture

I don't see any MeshVS_DataSource::computeNormalsByElement() in this class. Where did you find it? In which OCCT version?

Giovanni Bettega's picture

Thank you Kirill,
I admit having a problem: often my dubts overlap themselves.
I'm very sorry for that:

The volume element presentation is built by

void MeshVS_MeshPrsBuilder::AddVolumePrs

indeed I wrote another MeshVS_PrsBuilder and used it
instead of the original one.

In AddVolumePrs, at level

gp_Vec aNorm;

if (theIsShaded)
{
aPolyNodes.SetValue (0, aNbPolyNodes);

if (!MeshVS_Tool::GetAverageNormal (aPolyNodes, aNorm))
{
exit(1);
aNorm.SetCoord (0.0, 0.0, 1.0);
}
}

the exit instruction is executed, so that the problem of "black"
elements is exactly due to their non planarity.
I'll try to add an "else" statement for non planar elements.

So I disturbed you for a question I replied by myself.

A question survives: what is the role of computeNormalsByElements()? (OCC 7.3.0)
Thank you again
Buona giornata
Giovanni

Giovanni Bettega's picture

Hello
in changing the normal computation the results is correct: see Fig. 3,
showing the geometry, a slice of the volume mesh, a slice of the volume
mesh with the modified normal computation for non flat face elements.
Ciao

Attachments: