Contradicting number of faces

Need help, or want to share a macro? Post here!
orxshi
Posts: 21
Joined: Thu Dec 19, 2019 4:50 pm

Contradicting number of faces

Post by orxshi »

In the following code, I make a face and extrude it. Resultant number of faces is expected to be 20. In GUI, I hovered over and saw the names of each face (see blue semi-circle in image). Indeed there were 20 faces. But when I do geometry check on the solid (extrusion), it says there are 19 faces (see red circle in image). I am sure that there are actually 19 faces because using this geometry in my code causes problem due to missing face. My question is why I count 20 faces in GUI but actually there are 19 faces? Why there is a missing face?

Code: Select all

import sys
import math
import numpy

sys.path.append('/usr/lib/freecad/lib/')

import FreeCAD
import Part

doc = App.newDocument('newdoc')

#------

chord = 2.61
thick = 12 * chord / 100;
wing_z_start = 0
wing_z_end = 33.88
nx = 10;
x = numpy.linspace(0, chord, nx)

def y(x):
    C1 = 0.2969
    C2 = 0.1260
    C3 = 0.3516
    C4 = 0.2843
    C5 = 0.1036
    xc = x / chord
    y = thick * chord / 0.2 * (C1 * xc**(1/2) - C2 * xc**(1) - C3 * xc**(2) + C4 * xc**(3) - C5 * xc**(4))
    return y


# make points
points = []
for i in range(len(x)):
    points.append(App.Vector(x[i], y(x[i]), wing_z_start))
for i in reversed(range(1, len(x)-1)):
    points.append(App.Vector(x[i], -y(x[i]), wing_z_start))
points.append(points[0])

# polygon -> face -> extrude
polygon = Part.makePolygon(points)
face = Part.Face(polygon)
wing = face.extrude(App.Vector(0,0,wing_z_end))
Part.show(wing)

https://ibb.co/wyK63Ch
chrisb
Veteran
Posts: 40150
Joined: Tue Mar 17, 2015 9:14 am

Re: Contradicting number of faces

Post by chrisb »

Pasting your code in the Python console yields an error:

Code: Select all

>>> 
>>> # make points
>>> points = []
>>> for i in range(len(x)):
...     points.append(App.Vector(x[i], y(x[i]), wing_z_start))
... for i in reversed(range(1, len(x)-1)):
  File "<input>", line 3
    for i in reversed(range(1, len(x)-1)):
    ^
SyntaxError: invalid syntax
>>> 
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
orxshi
Posts: 21
Joined: Thu Dec 19, 2019 4:50 pm

Re: Contradicting number of faces

Post by orxshi »

I don't know how you paste in python console but I tried both freecadcmd and freecad itself and did not get any error.

EDIT: I also pasted into python console (didn't know I can do this) and also got the same error. I don't know why.
EDIT2: Adding newline before and after the problematic error line gets rid of the python error. But still does not show the solid. Why don't you do "freecad thefilename" directly?
openBrain
Veteran
Posts: 7038
Joined: Fri Nov 09, 2018 5:38 pm

Re: Contradicting number of faces

Post by openBrain »

Looks like the content given by geometry checker is totally wrong.
There are 20 faces :

Code: Select all

>>> len(App.ActiveDocument.Shape.Shape.Faces)
20
It's worth regarding vertices. Checker states shape has 18 vertices while it actually has :

Code: Select all

>>> len(App.ActiveDocument.Shape.Shape.Vertexes)
36
EDIT : shameful error. :)
orxshi
Posts: 21
Joined: Thu Dec 19, 2019 4:50 pm

Re: Contradicting number of faces

Post by orxshi »

Yeah looks like geometry checker gives false numbers. BTW, I take back one of the things I said:
I am sure that there are actually 19 faces because using this geometry in my code causes problem due to missing face
There are 20 faces for sure. The problem with my code was due to forgetting that numbering starts from 1 and I forgot to add last face. Such as

Code: Select all

temp = []
for i in range(4, len(cut_object.Shape.Faces) + 1): # +1 is important
    temp.append((cut_object, 'Face' + str(i)))
TheMarkster
Veteran
Posts: 3656
Joined: Thu Apr 05, 2018 1:53 am

Re: Contradicting number of faces

Post by TheMarkster »

It is interesting if you do draft downgrade (to faces) then draft upgrade (to shell) and draft upgrade again (to solid) checkgeometry gives correct face count.
chrisb
Veteran
Posts: 40150
Joined: Tue Mar 17, 2015 9:14 am

Re: Contradicting number of faces

Post by chrisb »

Is CheckGeometry within reach of FreeCAD or is it completely hidded in OCC?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
vocx
Veteran
Posts: 5205
Joined: Thu Oct 18, 2018 9:18 pm

Re: Contradicting number of faces

Post by vocx »

chrisb wrote: Tue Jul 21, 2020 12:00 am Is CheckGeometry within reach of FreeCAD or is it completely hidded in OCC?
The Part_CheckGeometry tool is defined inside Part/Gui/Command.cpp
https://github.com/FreeCAD/FreeCAD/blob ... 2118-L2139

The only thing it does is create the task panel, inside Part/Gui/TaskCheckGeometry.cpp
https://github.com/FreeCAD/FreeCAD/blob ... ometry.cpp

However, the code that is actually called does use a bunch of OCCT functions and methods. For example, it seems to use some sort of BRepCheck_Analyzer to check the internal Shape of the selected objects. The display of the information is controlled by FreeCAD though.

Code: Select all

void TaskCheckGeometryResults::recursiveCheck(const BRepCheck_Analyzer &shapeCheck, const TopoDS_Shape &shape,
                                              ResultEntry *parent)
{
    ResultEntry *branchNode = parent;
    BRepCheck_ListIteratorOfListOfStatus listIt;
    if (!shapeCheck.Result(shape).IsNull() && !checkedMap.Contains(shape))
    {
        listIt.Initialize(shapeCheck.Result(shape)->Status());
        if (listIt.Value() != BRepCheck_NoError)
        {
            ResultEntry *entry = new ResultEntry();
            entry->parent = parent;
            entry->shape = shape;
            entry->buildEntryName();
            entry->type = shapeEnumToString(shape.ShapeType());
            entry->error = checkStatusToString(listIt.Value());
            entry->viewProviderRoot = currentSeparator;
            entry->viewProviderRoot->ref();
            dispatchError(entry, listIt.Value());
            parent->children.push_back(entry);
            branchNode = entry;
        }
    }
    checkedMap.Add(shape);

    if (shape.ShapeType() == TopAbs_SOLID)
        checkSub(shapeCheck, shape, TopAbs_SHELL, branchNode);
    if (shape.ShapeType() == TopAbs_EDGE)
        checkSub(shapeCheck, shape, TopAbs_VERTEX, branchNode);
    if (shape.ShapeType() == TopAbs_FACE)
    {
        checkSub(shapeCheck, shape, TopAbs_WIRE, branchNode);
        checkSub(shapeCheck, shape, TopAbs_EDGE, branchNode);
        checkSub(shapeCheck, shape, TopAbs_VERTEX, branchNode);
    }

    for (TopoDS_Iterator it(shape); it.More(); it.Next())
        recursiveCheck(shapeCheck, it.Value(), branchNode);
}

Code: Select all

void TaskCheckGeometryResults::checkSub(const BRepCheck_Analyzer &shapeCheck, const TopoDS_Shape &shape,
                                        const TopAbs_ShapeEnum subType, ResultEntry *parent)
{
    BRepCheck_ListIteratorOfListOfStatus itl;
    TopExp_Explorer exp;
    for (exp.Init(shape,subType); exp.More(); exp.Next())
    {
        const Handle(BRepCheck_Result)& res = shapeCheck.Result(exp.Current());

        ...
    }
...
}
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
chrisb
Veteran
Posts: 40150
Joined: Tue Mar 17, 2015 9:14 am

Re: Contradicting number of faces

Post by chrisb »

Thanks for the information. If I understand it right FreeCAD only calls and collects the information from OCC.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
TheMarkster
Veteran
Posts: 3656
Joined: Thu Apr 05, 2018 1:53 am

Re: Contradicting number of faces

Post by TheMarkster »

chrisb wrote: Tue Jul 21, 2020 7:09 am Thanks for the information. If I understand it right FreeCAD only calls and collects the information from OCC.
It does, but we can count the faces, edges, etc. ourselves and display that in the results instead of relying on OCCT. I'm working on a PR for this. The advantage of this is not only can we ensure to get accurate counts, but we can also add additional information, for example volume, area, etc.

Edit: https://github.com/FreeCAD/FreeCAD/pull/3747
Post Reply