<class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

<class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2

Post by keithsloan52 »

I have some code that is getting the error

Code: Select all

<class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2
when trying to apply a transform matrix operation to a complicated mesh ( Imported STL file )

The Transform matrix is

Code: Select all

 Matrix ((4,0,0,0),(0,4,0,0),(0,0,4,0),(0,0,0,1))
and the failing python request is

Code: Select all

new_part.Shape = part.Shape.transformGeometry(transform_matrix)
The stl file that is imported to create the Mesh
test.stl
(391.2 KiB) Downloaded 28 times
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: <class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2

Post by vocx »

keithsloan52 wrote: Sat Sep 19, 2020 7:54 pm I have some code that is getting the error

Code: Select all

<class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2
...
I have also noticed this error while importing SVGs.

I've been modifying the SVG code of Draft and testing by exporting and importing. At some point I started getting this error on import, so I was unsure if it was something I did. But the error seems to come from Part.

This example creates a cube that is rotated, and exported to SVG (it is projected on the XY plane).

Code: Select all

import FreeCAD as App
import importSVG

doc = App.newDocument()

feat = doc.addObject("Part::Box", "Box")
feat.Length = 14
feat.Width = 8
feat.Height = 6
feat.Placement.Base = App.Vector(10, 80, 0)
feat.Placement.Rotation = App.Rotation (0.0, -0.2756, 0.0, 0.9612)
doc.recompute()

importSVG.export([feat], "/home/vocx/result.svg")
Then we import the resulting SVG.

Code: Select all

importSVG.open("/home/vocx/result.svg")
Error message

Code: Select all

File "<string>", line 1, in <module>
  File "/opt/freecad-build-main/Mod/Draft/importSVG.py", line 1744, in open
    parser.parse(f)
  File "/usr/lib/python3.6/xml/sax/expatreader.py", line 111, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python3.6/xml/sax/xmlreader.py", line 125, in parse
    self.feed(buffer)
  File "/usr/lib/python3.6/xml/sax/expatreader.py", line 217, in feed
    self._parser.Parse(data, isFinal)
  File "../Modules/pyexpat.c", line 419, in StartElement
  File "/usr/lib/python3.6/xml/sax/expatreader.py", line 333, in start_element
    self._cont_handler.startElement(name, AttributesImpl(attrs))
  File "/opt/freecad-build-main/Mod/Draft/importSVG.py", line 1194, in startElement
    sh = self.applyTrans(sh)
  File "/opt/freecad-build-main/Mod/Draft/importSVG.py", line 1537, in applyTrans
    sh = sh.transformGeometry(transform)
<class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2
The error occurs inside the importSVG module when using Part.Shape.transformGeometry.

https://github.com/FreeCAD/FreeCAD/blob ... 1527-L1538

Code: Select all

            for transform in self.grouptransform[::-1]:
                _msg("applying group transform: {}".format(transform))
                # sh = transformCopyShape(sh, transform)
                # see issue #2062
                sh = sh.transformGeometry(transform)
Here transform contains a transformation matrix.

If the cube is just displaced the message is

Code: Select all

Part.OCCError: Geom_RectangularTrimmedSurface::U1==U2
If the cube is just rotated the message is

Code: Select all

Part.OCCError: Geom_RectangularTrimmedSurface::V1==V2
https://github.com/FreeCAD/FreeCAD/blob ... 1381-L1397
https://github.com/FreeCAD/FreeCAD/blob ... 3012-L3034

Code: Select all

OS: Ubuntu 18.04.5 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22474 (Git)
Build type: Release
Branch: master
Hash: a44f8ffd427fa9b23b1f00dbf62d66cd152cd774
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
Last edited by vocx on Sun Sep 20, 2020 4:58 pm, edited 1 time in total.
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.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: <class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2

Post by vocx »

This is very strange, I get the same error with v0.18.4, and I never noticed.

Code: Select all

OS: Ubuntu 18.04.5 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4.
Build type: Release
Python version: 3.6.8
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
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.
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: <class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2

Post by keithsloan52 »

vocx wrote: Sun Sep 20, 2020 4:03 pm This is very strange, I get the same error with v0.18.4, and I never noticed.

Code: Select all

OS: Ubuntu 18.04.5 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4.
Build type: Release
Python version: 3.6.8
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
Think it may depend on the Shape so maybe that is why you did not see it before.

We could really do with a section in the wiki that documents dealing with potential OCC errors and reporting.

From memory the suggested procedure was

Save the Shape as a BRep file ( TopShape.exportBrep('File Path')
and try and reproduce with DrawExe.

Sebastian @shoogen was the expert at this and he did develop the Sandbox workbench for such things, perhaps it needs reviving.

My STL imported to create the mesh is quite complex so it would be great if you could track down with a simpler Shape.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: <class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2

Post by vocx »

keithsloan52 wrote: Mon Sep 21, 2020 2:09 pm ...so it would be great if you could track down with a simpler Shape.
Dude, I literally wrote a way to reproduce the error above. Create a box, rotate it, export it as SVG, re-import it. Error.
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.
wmayer
Founder
Posts: 20321
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: <class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2

Post by wmayer »

<class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::U1==U2
<class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2
This exception is raised by OCC and it means you created a trimmed surface with zero width/length which is not allowed.

The class Geom_RectangularTrimmedSurface is used to limit an underlying surface with the parameter range [U1, U2] x [V1, V2] and in order to be a valid surface you must make sure that: U2 > U1 and V2 > V1, otherwise the geometry would degenerate to a line or even a point only.
This example creates a cube that is rotated, and exported to SVG (it is projected on the XY plane).
The problematic part of the created SVG is this:

Code: Select all

<path id="Box_f0002"  d="M 6.820676798210311 80.0 L 10.0 80.0 L 21.872953835173856 80.0 L 18.693630633384164 80.0 L 6.820676798210311 80.0 Z " />
<path id="Box_f0003"  d="M 21.872953835173853 88.0 L 10.0 88.0 L 6.82067679821031 88.0 L 18.693630633384167 88.0 L 21.872953835173853 88.0 Z " />
This is supposed to describe a rectangle but you will see the Y coordinates are equal for both rectangles and thus degenerate to a line segment.
From the exported model this are the faces 3 & 4 which are parallel to the Z axis and their projections into the XY plane will be these two line segments.

It's up to the SVG importer of the Draft module to check that from this input no surface can be created.

If you remove the two lines from the file the SVG file can be loaded without problems.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: <class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2

Post by vocx »

wmayer wrote: Mon Sep 21, 2020 4:09 pm ...
It's up to the SVG importer of the Draft module to check that from this input no surface can be created.

If you remove the two lines from the file the SVG file can be loaded without problems.
Thanks a lot for your help, it would have taken me days to find the cause of the issue.

So, you recommend me to do some checks inside the SVG importer; or should I try to prevent the SVG exporter (Draft.get_svg) from creating these paths in the first place?

The importSVG.py module is pretty large, so I don't think I will investigate this thoroughly right now. Maybe I'll try discarding the object in the loop, and add a comment to check this another time.
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.
wmayer
Founder
Posts: 20321
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: <class 'Part.OCCError'>: Geom_RectangularTrimmedSurface::V1==V2

Post by wmayer »

So, you recommend me to do some checks inside the SVG importer; or should I try to prevent the SVG exporter (Draft.get_svg) from creating these paths in the first place?
I guess the SVG importer is supposed to also edges and not only faces. So, you need an additional check to handle this properly.

The issue is in line 1189ff in importSVG.py. As input for makewire() the path variable is a list of four edges on top of each other. The function makewire is able to build a (collapsed) wire and the check whether it's closed returns true. It even succeeds to build a face. Now when trying to transform the underlying geometry OCC accesses the surface of the face and realizes that it's invalid and raises an exception.

So, before trying to transform the geometry you must also check if the face is valid:

Code: Select all

...
face = Part.Face(sh)
if face.isValid():
    sh = face
...
Post Reply