Homography matrix

Hello,

I'm taking different views of a TopoDS_Shape created from the reading of a STEP file. To do that, I'm moving the camera around X, Y and Z world axis establishing the look-at point (center view) always at the center of mass of the shape. Now I need to calculate the homogeneous matrix (4x4) that transform points from the View Coordinate system into the camera coordinate system. How can I do that?

Another question, is it possible to change the location of the world coordinate system to the center of mass of the shape and then calculate the homogeneous matrix directly between the world coordinate system and the camera system?

Thanks!

 

 

Kirill Gavrilov's picture

The transformations in OCCT are defined by gp_Trsf class, which can be initialized in various ways, including translation and transformation from one coordinated system to another (defined by gp_Ax2/gp_Ax3 classes).
gp_Trsf::GetMat4() method can be used to define a 4x4 matrix (used in visualization), while gp_Trsf stores transformation in decomposed way.

Adriana Costas's picture

Hello,

Now I'm dealing with the opposite problem. How can I define a gp_Trsf from a given matrix 4x4?

Thanks!

Kirill Gavrilov's picture

Arbitrary 4x4 transformation matrix cannot be represented by gp_Trsf - see documentation of this class.
4x3 transformation matrix can be initialized using gp_Trsf::SetValues() method.

Adriana Costas's picture

And then, why does the method GetMat4 exist? If I use the three first columns of this matrix in the function SetValues, should I get the correct result?

Kirill Gavrilov's picture

You should read about transformation matrices (as well as documentation of related OCCT classes).

4x3 matrix is a convenient way for storing 4x4 matrix with one row being (0, 0, 0, 1), e.g. as in identity matrix - and this is what gp_Trsf::GetMat4() will return.
This is enough for a "normal" transformation, where 3x3 matrix within 4x3 stores rotation part (and scale) and the 4th column stores translation part.

Obviously, the arbitrary 4x4 matrix cannot fit into 4x3. For example, perspective projection matrix cannot be defined by gp_Trsf (and is not supposed to).

Selahattin BABADAĞ's picture

Dear Kirill I want to get help from you about converting the mouse coordinates to world coordinates if you help i will be very happy.

I Tried to convert by ConvertToClickToWorld as in forums , I want to make a snap function but it gives wrong coordinates .

is there any other safe way to convert mouse coordinates to world coordinates .(I use qt)

Thank you very much.

Selahattin BABADAG

Civil Eng.

Kirill Gavrilov's picture

Having only mouse position gives you an infinite number of 3D positions along the ray, hence it is not well-defined operation - you need defining some plane / grid in 3D.
In contrast, picking 3D point on a Shape under mouse cursor makes sense, and it can be directly SelectMgr_ViewerSelector after AIS_InteractiveContext::MoveTo() - see Draw Harness command vstate as example.

Selahattin BABADAĞ's picture

Dear Kirill ; my aim is to freely move the mouse cursor and get the real world coordinates on space near an object , it is successful if the view is a plane view like XY XZ... but in a 3d occ view all returned results are wrong..., so how do the user can move the mouse in 3d space and get the current real coordinate to start a new drawing  a line , a circle etc?

I coudnt succeed.