Moved Object visualization

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
malinand
Posts: 31
Joined: Sun Aug 02, 2009 2:10 am

Re: Moved Object visualization

Post by malinand »

Hi Werner,
I would like to understand few things more clear, could you please help?
Here is the test code:

Code: Select all

>>> ob = Gui.getDocument("Unnamed").getObject("Face")
>>> ob.Object.Shape.Placement
Placement ((0,0,0,1),(0,0,0))
>>> ob.Object.Shape.Matrix
Matrix ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1))
>>> ob.Object.Placement
Matrix ((1,0,0,4),(0,1,0,0),(0,0,1,0),(0,0,0,1))
Some questions:
1. TopLoc_Location - is it Placement object or Matrix? More precisely, can I scale object without transformation?
2. ob.Object.Shape.transform(Matrix) will transform Vertexes and Poles coordinates, but will leave ob.Object.Shape.Matrix unchanged. Is it correct?
3. document Object could have different Placement then internal Shapes and To get world coordinates of the point Matrix for Object.Placement should be multiplied by Object.Shape.Matrix - is it cirrect? If Shape is Edge as part of the Wire - will correct calculations require 3 matrix multiplication and so on? Or ob.Object.Shape.Matrix, ob.Object.Shape.Edges[0].Matrix and ob.Object.Placement is the same matrix?
4. Gui.ActiveDocument.ActiveObject.Object and App.ActiveDocument.ActiveObject is the same Part object instance. Is it correct?
5. Is it possible to get assess to coin reflection of the Shape knowing its name from document? Yorik creating new object instance to make the ghost. Is it possible to avoid it and make copy of the visualization directly?

Andrey
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Moved Object visualization

Post by jriegel »

Hi,
maybe we come to a point where we have to clarify some things.

First of all we shut think what were doing here. It will be a CAD system.
A CAD system differs in one important thing from other 3D systems (like Blender).
Its the exactness! So normally we create exact 3D representations of things we whant
build some time. This Parts we do assemble to bigger "Products", consisting of one or
more parts. This assembly is done by "Placing" objects in a certain possition to each
other. There fore the data type is called Placement!

The 4x4 matrix is a mathematical construct which can transport all kind of transformation.
And is there for potential dangerous. It can destroy the important exactness of our design.
It even have to change the internal representation of the shape. Normally you dont want that
in a CAD system! There fore I would recommend only using Placement, which produce matrixes which
do not change the exactness of the design.

There are fore sure things you need the matrix, like special cases like mirroring..
But it shut be a exception! Scaling IMO is also not a part of Placement.

When we come to PartDesign and the Assembly workbench, we will working only with
Placements.
TopLoc_Location has the same idea.

Jürgen
Stop whining - start coding!
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Moved Object visualization

Post by wmayer »

Hi,
>>> ob = Gui.getDocument("Unnamed").getObject("Face")
>>> ob.Object.Shape.Placement
Placement ((0,0,0,1),(0,0,0))
>>> ob.Object.Shape.Matrix
Matrix ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1))
>>> ob.Object.Placement
Matrix ((1,0,0,4),(0,1,0,0),(0,0,1,0),(0,0,0,1))
Oops, how did this happen? The translation part of the object is (4,0,0) and of the shape it is (0,0,0). This seems to be wrong. BTW, the object placement returns a matrix here. I'll change that to return a placement. Please let me know how to reproduce this behaviour so that I can fix this.
1. TopLoc_Location - is it Placement object or Matrix? More precisely, can I scale object without transformation?
The implementation of this class is pretty complex. After having a look to its members it uses an array of gp_Trsf which consists of a 3x3 matrix, a translation vector and a scale factor. A gp_Trsf is comparable with our 4x4 matrix.

According to the OCC documentation scaling is possible but it doesn't seem to work very well. If you try to do a scaling over a matrix the value A44 must be <> 1 but it doesn't seem to have an effect when applying the matrix on the shape's TopLoc_Location. If you do it with transform(), i.e. a geometric modification it does something but not correctly either.
ob.Object.Shape.transform(Matrix) will transform Vertexes and Poles coordinates, but will leave ob.Object.Shape.Matrix unchanged. Is it correct?
Yes, this is correct. Note, you have two possibilities to change a shape: modify its placement (i.e. TopLoc_location) or modify directly its underlying geometry. The method transform() does the latter. I have fixed the documentation to make this clear. Maybe we should also rename the method to transformGeometry() to avoid any misunderstanings.
3. document Object could have different Placement then internal Shapes and To get world coordinates of the point Matrix for Object.Placement should be multiplied by Object.Shape.Matrix - is it cirrect? If Shape is Edge as part of the Wire - will correct calculations require 3 matrix multiplication and so on? Or ob.Object.Shape.Matrix, ob.Object.Shape.Edges[0].Matrix and ob.Object.Placement is the same matrix?
The object's placement and the shape placement must be identical. The above example demonstrates an error. And yes, to get the world coordinates of a vertex of a shape you must multiply it with Object.Shape.Matrix (or Object.Placement). And yes, if you have an edge that is part of a wire you must do further matrix multiplications. The matrix information of ob.Object.Shape.Edges[0].Matrix is not part of ob.Object.Placement. This matrix is completely out of control of the object.
4. Gui.ActiveDocument.ActiveObject.Object and App.ActiveDocument.ActiveObject is the same Part object instance. Is it correct?
Yes, this is correct.
5. Is it possible to get assess to coin reflection of the Shape knowing its name from document? Yorik creating new object instance to make the ghost. Is it possible to avoid it and make copy of the visualization directly?
Assuming you want to access the Inventor node of a document object with name "MyName" you get it by:
iv=Gui.ActiveDocument.getObject("MyName").RootNode
to get a copy you can use the method copy()
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Moved Object visualization

Post by wmayer »

There are two things fixed now:
* ob.Object.Placement returns a placement object, not a matrix
* transform() has been renamed to transformGeometry() to make it really clear this it modifies the underlying geometry
malinand
Posts: 31
Joined: Sun Aug 02, 2009 2:10 am

Re: Moved Object visualization

Post by malinand »

Hi Werner,
Code showing differnt matrixes is fake, you can do anything with text editor ;)
Lines were captured at different times
I tried to make the point that ob.Object.Placement should return Placement, not Matrix and didn't pay attention to the data inside.
Technically I shouldn' be able to change A14 it should always be 0, isn't it?

I still didn't get full understanding of this matrix staff, need to steer it for while...

Andrey
malinand
Posts: 31
Joined: Sun Aug 02, 2009 2:10 am

Re: Moved Object visualization

Post by malinand »

Werner,
Do you have access to OCC documentation more detailed then user manual?

Code: Select all

1. TopLoc_Location - is it Placement object or Matrix? More precisely, can I scale object without transformation?
The implementation of this class is pretty complex. After having a look to its members it uses an array of gp_Trsf which consists of a 3x3 matrix, a translation vector and a scale factor. A gp_Trsf is comparable with our 4x4 matrix.

According to the OCC documentation scaling is possible but it doesn't seem to work very well. If you try to do a scaling over a matrix the value A44 must be <> 1 but it doesn't seem to have an effect when applying the matrix on the shape's TopLoc_Location. If you do it with transform(), i.e. a geometric modification it does something but not correctly either.
I noticed the strange behavior of gp_Trsf when played with PythonOCC. It mast be logic behind it, just not easy to understand. And, at the end, if you are not transforming points using OCC transform(), it is up to you how to treat this matrix for view provider, isn't it?
From theory, A44 shouldn't do scaling. Diagonal components of 3x3 matrix should be responsible for scaling.
Affine transformations are fully described by 3x4 matrix. I think if you are using 4x4 matrix for affine transformations only access to fourth row should be disabled. Fourth row should be responsible for central projections.
A44 shuld do transformation something like this:
[x,y,z,1]->(matrix multiplication, projection to plaine w=A44) -> [x,y,z,A44]->(transformation back to plaine w=1) ->[x/A44,y/A44,z/A44,1]
This is true if [x,y,z,w] is treated as homogenious coordinates. I think in computer graphics it is common way to use w coordinate just to extend 3x4 transformation matrix without any use of w coordinate.

It would be really interesting to understand how this OCC feature works.
Andrey
malinand
Posts: 31
Joined: Sun Aug 02, 2009 2:10 am

Re: Moved Object visualization

Post by malinand »

jriegel wrote:Hi,
maybe we come to a point where we have to clarify some things.

First of all we shut think what were doing here. It will be a CAD system.
A CAD system differs in one important thing from other 3D systems (like Blender).
Its the exactness! So normally we create exact 3D representations of things we whant
build some time. This Parts we do assemble to bigger "Products", consisting of one or
more parts. This assembly is done by "Placing" objects in a certain possition to each
other. There fore the data type is called Placement!

The 4x4 matrix is a mathematical construct which can transport all kind of transformation.
And is there for potential dangerous. It can destroy the important exactness of our design.
It even have to change the internal representation of the shape. Normally you dont want that
in a CAD system! There fore I would recommend only using Placement, which produce matrixes which
do not change the exactness of the design.

There are fore sure things you need the matrix, like special cases like mirroring..
But it shut be a exception! Scaling IMO is also not a part of Placement.

When we come to PartDesign and the Assembly workbench, we will working only with
Placements.
TopLoc_Location has the same idea.

Jürgen
Hi Jürgen,

Using full featured 3x4 matrix transformation on the Part objects is not against "exactness" concept, I think. It keeps internal representation of the Part without change. It increase possibility to use Shape without transformation.
For example, parts like pipes, beams, bars, tension rods... It would be really nice to have all same profile but different lenghts components in the design as the derivative of one shape. I think Yorik will be happy to have an option to change all trims in the building design by one mouse click...

I agree that 4x4 matrix is too much. Central projection is finicky. But access to all affine transformation options should not do enything but good.

Andrey
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Moved Object visualization

Post by jriegel »

Hi,
changing the length of a e.g. beam with a transformation is not a good idea. Think of a beam with two holes at the end.
A engineer want to change the length of the beam but he/she want not a ellipse instead the holes. The idea of working a lot
with transformation is the old CSG thinking. That works only with very simple and limited designs. No new CAD package since
the last 20 years work with that approach.

There is nowadays a very clear distinction between "PartDesign" which works with parametric and associative features and
the "Assembly" which assemble the Parts to a Product. Assembly is not allow to change the shape (as I said, mirroring is the
only exception). Or do you think a designer build a wheel design of a truck by scaling the wheel of a Honda civic? That only
works for games and movies.... ;-)

Jürgen
Stop whining - start coding!
malinand
Posts: 31
Joined: Sun Aug 02, 2009 2:10 am

Re: Moved Object visualization

Post by malinand »

Hi Jürgen
I'm probably getting old... :cry:
But what I don't like about all modern CAD packages is the "Lego" approach to design. SolidWorks, Ideas you name it are very good tools for assembling from off-the-shelf parts. Download library, and you are done...
20 years ago I didn't here from my CAD designers "my tool can not create model of what you need" or "we will have to redo all our libraries because you changed form factor and it will take couple mounts". Today in many cases it will take less time and money to make mockup then to do 3D model. Design this days takes more time and more expensive then 20 years ago. And significant part of it is "advances" of commercial packages.

I need a tool to make quick 3D model, use it for PDE solver, optimize on high level, refine details an so on... So I need tool for top down iterative design. At the end I need production quality 3D model for tolerance analysis and manufacturing. FreeCAD looks like very good framework for it - with advanced scripting possibilities I should be able to get everything, and it is free to try :) And you have meshing and FEM solver in your roadmap, isn't it?
I didn't learn parameterization options yet but based on what I've seen so far I don't think you will screw up there.

There is no big difference is it BRep or CSG for me as user. As long as geometry predictable I can make mesh and apply boundary conditions for ether one. But for anisotropic materials I have to know extrusion direction or lamination plain. There is no option to put this information to Brep or CSG geometry. I have to find work around.
So idea about using transformation coming from there. I would like to include some additional information on the Part level, but I don't want to do it as additional input step. May be that idea will not work.
May be I'll be able to use your parameterization options for the same purpose. And it could be more convenient. I need to try.

Andrey
Guest

Re: Moved Object visualization

Post by Guest »

Hi Andrey,
Technically I shouldn' be able to change A14 it should always be 0, isn't it?
No, of course, you must be able to change this data. For instance, you can do this via the GUI aka property editor or via scripting. Internally, all data structures like the shape, the view provider get updated automatically.
Do you have access to OCC documentation more detailed then user manual?
I have an old CHM file of version 5.2. The newer documentation generated by doxygen is IMO nearly unusable.

I'm not completely sure about gp_Trsf either. The gp_Trsf uses internally a 3x3 matrix, a vector and a separate scale factor. But it is also possible to do scaling by setting the values of the matrix. This is the way how we create an ellipse in FreeCAD starting from a sphere and then scale only in one direction not all three. Anyway, the logic of this class is still a miracle to me, too.
From theory, A44 shouldn't do scaling. Diagonal components of 3x3 matrix should be responsible for scaling.
Affine transformations are fully described by 3x4 matrix. I think if you are using 4x4 matrix for affine transformations only access to fourth row should be disabled. Fourth row should be responsible for central projections.
A44 shuld do transformation something like this:
[x,y,z,1]->(matrix multiplication, projection to plaine w=A44) -> [x,y,z,A44]->(transformation back to plaine w=1) ->[x/A44,y/A44,z/A44,1]
This is true if [x,y,z,w] is treated as homogenious coordinates. I think in computer graphics it is common way to use w coordinate just to extend 3x4 transformation matrix without any use of w coordinate.
Basically, this all is true. An affine transformation is a linear transformation which is fully described by a 3x3 matrix and a translation vector, the fourth dimension actually is not needed here. So, theoretically it would suffice to have a 3x4 matrix. But a 3x4 matrix isn't feasible. For example when you have two affine transformations and you want to compute the resulting affine transformation. You cannot do this by multiplying the matrices because it's not possible to multiply a 3x4 matrix with another 3x4 matrix. That's the reason for using a 4x4 matrix whose forth row is always (0,0,0,1). Using such 4x4 matrices allows to do two affine transformations just by multiplying the matrices. It's even possible to get the inverse affine transformtation by computing the inverse matrix, ...

Cheers,
Werner
Post Reply