https://brlcad.org/w/index.php?title=User:NyahCh3ck20/GSOC13/Design_Document&feed=atom&action=historyUser:NyahCh3ck20/GSOC13/Design Document - Revision history2020-08-14T17:18:35ZRevision history for this page on the wikiMediaWiki 1.32.2https://brlcad.org/w/index.php?title=User:NyahCh3ck20/GSOC13/Design_Document&diff=5399&oldid=prevNyahCh3ck20: Design Document2013-06-13T09:16:13Z<p>Design Document</p>
<p><b>New page</b></p><div>===Implementation of Pull routine Design Document===<br />
<br />
<br />
==Introduction:==<br />
<br />
The Pull command/routine restores the original state of a CSG tree by reversing all the geometric transformations from the leaf(primitive) nodes applied during the Push operation on the CSG tree. The pull routine reverses the matrix operation on the primitives and recursively restores all matrix transformations on the parent nodes up the CSG tree during an inorder tree walk, from the leaf to the designated head of the tree.<br />
<br />
==Intended Implementation Approach:==<br />
<br />
The pull routine works down a tree from a specific node(head) pushing the directory pointers to a linked list till when it reaches the leaves(primitives); It then copies the geometric transformation on the primitive and restores the primitives to its initial state and moves back up the tree restoring the original matrix transformations on the parent nodes by performing an Inverse of the current matrix transformation stored on the linked list; hence it restores the local coordinates of the parent nodes.<br />
<br />
On a CSG tree, the transformation matrices are always a 4x4 matrix<br />
<br />
Code:<br />
[ Xx Xy Xz Tx ]<br />
M = [ Yx Yy Yz Ty ]<br />
[ Zx Zy Zz Tz ]<br />
[ 0 0 0 1 ]<br />
The unit X vector in new coordinates [ 1 0 0 ] matches [ Xx Xy Xz ] in old coordinates.<br />
The unit Y vector in new coordinates [ 0 1 0 ] matches [ Yx Yy Yz ] in old coordinates.<br />
The unit Z vector in new coordinates [ 0 0 1 ] matches [ Zx Zy Zz ] in old coordinates.<br />
The origin [ 0 0 0 ] in new coordinates is moved to [ Tx Ty Tz ] in old coordinates.<br />
<br />
With the matrix transformation matrix M defined as above, inverse matrix R = M-1(Inverse of M) defines the rotation back to the original coordinate system. R is simple to calculate:<br />
Code:<br />
d = Det(M) = Zz Xx Yy - Zz Yx Xy - Zx Xz Yy - Zy Xx Yz + Zy Yx Xz + Zx Xy Yz<br />
<br />
So I'll require a routine(Inverse_transf() and det_trans() routines)<br />
<br />
[ (Zz Yy - Zy Yz)/d (Zy Xz - Zz Xy)/d (Xy Yz - Xz Yy)/d (Xy Ty Zz - Xy Yz Tz + Xz Tz Yy - Xz Zy Ty - Tx Zz Yy + Tx Zy Yz)/d ]<br />
R = [ (Zx Yz - Zz Yx)/d (Zz Xx - Zx Xz)/d (Yx Xz - Yz Xx)/d (Xx Yz Tz - Xx Ty Zz + Ty Zx Xz - Yz Zx Tx - Yx Xz Tz + Yx Tx Zz)/d ]<br />
[ (Zy Yx - Zx Yy)/d (Zx Xy - Zy Xx)/d (Yy Xx - Xx Xy)/d (Tz Yx Xy - Tz Xx Yy + Zx Tx Yy + Zy Xx Ty - Zy Yx Tx - Zx Xy Ty)/d ]<br />
[ 0 0 0 1 ]<br />
<br />
R(Inverse_transf()) algorithm will be used in determining the inverse of the transformation taking into consideration othogonal matrices(transpose of matrix is the same as the inverse of the matrix.)<br />
<br />
In a case where d=0, the matrix is degenerate (also called singular), and does not describe a true transformation. Such a matrix flattens the space into a flat plane or a single point. In practice, d is always near one. <br />
<br />
In a case of more than one transformation matrices, the matrices are multiplied in the order below:M = MN MN-1 ... M2 M1<br />
<br />
<br />
Assuming the transformation matrix Mself transforms parent coordinates to current object coordinates, and Mchild transforms current object coordinates to child object coordinates. To transform current object coordinates to world coordinates we use<br />
<br />
M = Mself Mparent ... Mancestor<br />
and to transform child object coordinates to world coordinates you use<br />
M = Mchild Mself Mparent ... Mancestor<br />
<br />
To transform world coordinates to current object coordinates, you use<br />
R = Mancestor-1 ... Mparent-1 Mself-1 = (Mself Mparent ... Mancestor)-1<br />
<br />
Considering the small tree below:<br />
Code:<br />
World<br />
|<br />
Ancestor<br />
|<br />
Grandparent<br />
/ \<br />
Parent Uncle<br />
/ \ \<br />
Self Sibling Cousin<br />
<br />
Starting with an identity matrix,<br />
M = I = [ [ 1 0 0 0 ] [ 0 1 0 0 ] [ 0 0 1 0 ] [ 0 0 0 1 ] ]<br />
If you move down, multiply the transformation by the target transform on the left:<br />
M â† Mtarget M<br />
If you move up, multiply the transform by the inverse of the source transform on the left:<br />
M â† Msource-1 M<br />
<br />
In both cases the source/target transform corresponds to the lower node in the tree.<br />
Example:<br />
<br />
We need to transform current coordinates to coordinates in uncle's coordinate system. The path is Selfâ†‘Parentâ†‘Grandparentâ†“Uncle:<br />
[INDENT]M = I<br />
M â† Mself-1 M<br />
M â† Mparent-1 M<br />
M â† Muncle M<br />
[/IDENT]<br />
or, in other words,<br />
M = Muncle Mparent-1 Mself-1<br />
and describes the transformation from current coordinates to Uncle's coordinate system.<br />
<br />
Generally, in implementing the pull routine, i'll need the matrix transformation of the leaf(primtive) nodes and recursively compute its inverse while moving up the tree and restoring the various matrix transformations.<br />
So, (Muncle Mparent-1 Mself-1)-1 = Mself Mparent Muncle-1<br />
which also matches the inverse path, Uncleâ†‘Grandparentâ†“Parentâ†“Self!<br />
<br />
However, in implementing the pull routine I would need the following:<br />
<br />
<br />
*. pull_obj -create a structure to hold the original matrix and corresponding local coordinate systems while calling inverse_tranf() routine.<br />
<br />
*. inverse_tranf(): this performs the inverse of a 4x4 matrix using the procedure shown above.<br />
*. <br />
*. det_trans(): This determines the determinant of a 4x4 matrix as shown above.<br />
*. create a loop to move down the tree to the leaf and then recursively move up restoring the original matrix transformations.<br />
*. pull leaf() routine : which runs in parallel restoring the original primitive state and copies the matrix transformation which then calls the det_transf() routine to seperate the different matrix tranformations.<br />
<br />
*. mat_restore() routine: which restores the original matrix transformation and coordinate system at each node, which will consist in calling the rt_matrix_tranform() as defined in (/src/librt/transform.c)<br />
<br />
<br />
1.) The det_trans() routine:<br />
This determines the determinant of a 4x4 matrix which is to be called in inverse_tranf() routine. <br />
<br />
2.) The inverse_transf() routine:<br />
This routine takes any of matrix transformations determined by the det_trans() routine and determines the inverse of the transformation which will then be applied to all the nodes up the CSG tree from the primitive by pull leaf() in restoring the original state of the matrix transformations up the CSG tree. This routine will consider orthogonal matrices in order to increase runtime for some matrix transformations.<br />
<br />
3.) The mat_restore() routine:<br />
This routine called by pull_leaf() uses rt_matrix_transform() routine to restore the original transformation matrix at the parent nodes up the tree.<br />
<br />
<br />
4.) The pull_leaf() routine:<br />
This routine starts reversing all the geometric transformations the leafs then calls mat_restore(), inverse_tranf() routines to determine and restore the original matrix transformations up the CSG tree.<br />
<br />
<br />
Tests and Verification:<br />
<br />
I believe test driven development would be key in finding and fixing problems with the pull routine and then with more tests to ensure the code functions correctly and its bulletproof to all forms of object inputs. This will be enhanced with the creation of a special regression tests for the pull command to avoid modification of unwanted nodes/objects.Also, this command will be included among the MGED commands and a well written manual will be made so support the usage of the command.<br />
<br />
<br />
<br />
==Milestones and Deliverables:==<br />
Implementation of the inverse_tranf(), mat_restore(), det_transf() routines and other pull subroutines.<br />
<br />
Implementation of the complete pull routine with further testing.:(pull_leaf())<br />
<br />
Integration of the Pull routine into MGED command interface together with Documentation containing(summary together with usage capabilities)<br />
<br />
== Original Development Schedule:==<br />
<br />
Since my semester ends by late june or early july, i will start coding on July 1st.<br />
<br />
July 1st (~ 3 weeks)<br />
Study of BRLCAD Manuals and other Documentation on the Push Command<br />
Discuss with other developers concerning implementation details.<br />
Study the (src/libged , /include ) libraries and the implementation of push/xpush commands.<br />
Discuss more coding specifications and implementations details with mentor.<br />
<br />
July 21 - July 28 (1 week)<br />
Implementation of the det_trans() and InverseTransf() routines with<br />
determination of original matrix tranformations.<br />
Tests on sample primitive matrices<br />
<br />
July 29 - Aug 17(3 weeks)<br />
Implementation of do_restore() routine(1 week)<br />
which traverses nodes restoring the original matrix and tests<br />
Implementation of pull routine(pull_leaf() and others)(2 weeks)<br />
Testing and functionality verification of function.<br />
<br />
Mid-term evaluation in July 29 - Aug. 2 <br />
<br />
Aug. 18 - Aug. 31 (2 weeks)<br />
Finalization of complete pull routine <br />
Tests<br />
Tests of the final pull routine on primitives <br />
<br />
Sept 01 - Sept 14( 2 weeks) <br />
Integration of Pull into MGED command interface.<br />
Testing of functionality of command <br />
and debugging<br />
<br />
Sept 15 - Sept 21(1 week)<br />
Tests<br />
Fix bugs and improve performance of routine<br />
Documentation and code clean up<br />
<br />
Sept 23 - Sept 27(1 week)<br />
Final Evaluation<br />
Submission of Final code to Google.<br />
<br />
==References and Resources:==<br />
<br />
Graphics Gems: Matrix identities, transformation axes, Fast matrix multiplication, Matrix orthogonalization, www.graphicsgems.org<br />
Wikipedia: Composing and inverting transformations, Quaternion-derived rotation matrix, Invertible matrix(www.wikipedia.org/transformation_matrix, www.wikipedia.org/Rotation_matrix)</div>NyahCh3ck20