Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

guma_transform.cpp

Go to the documentation of this file.
00001 /* LIBGUL - Geometry Utility Library
00002  * Copyright (C) 1998-1999 Norbert Irmer
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #include "stdafx.h"
00021 
00022 #include <iostream>
00023 
00024 #include "gul_types.h"
00025 #include "gul_vector.h"
00026 #include "gul_matrix.h"
00027 #include "guma_lineq.h"
00028 
00029 namespace guma {
00030 
00031 using gul::Ptr;
00032 using gul::rtr;
00033 using gul::point;
00034 using gul::normalize;
00035 using gul::MMProduct;
00036 using gul::cross_product;
00037 
00038 /*-------------------------------------------------------------------
00039   Calculates a matrix wich transforms points given in a local coordinate
00040   system at a point 'B' into the world coordinate system.
00041   An additional point is required (both in world coordinates
00042   (=P) and local coordinates (=Pb)). 'Ab' must contain the coordinates
00043   of the origin in the local coordinate system at 'B'.
00044   Both coordinate systems must be orthonormal, and memory for 'T' (a 4x4
00045   matrix) must be reserved by the caller.
00046 -------------------------------------------------------------------*/
00047 
00048 template< class U >
00049 void CommonCoordinateSystem(
00050        const point<U>& B, const point<U>& P, const point<U>& Ab, 
00051        const point<U>& Pb, Ptr< Ptr<U> >& T )
00052 {
00053   point<U> a1,a2,a3,b1,b2,b3;
00054   Ptr< Ptr<U> > Ta,Tb;
00055   int i;
00056 
00057   Ta.reserve_pool(3);
00058   Tb.reserve_pool(3);
00059   for( i = 0; i < 3; i++ )
00060   {
00061     Ta[i].reserve_pool(3);
00062     Tb[i].reserve_pool(3);
00063   }
00064 
00065   normalize( &a1, B );
00066   normalize( &a2, P-((P*a1)*a1) );
00067   normalize( &a3, cross_product(a1,a2) );
00068 
00069   normalize( &b1, -Ab );
00070   normalize( &b2, P-((P*b1)*b1) );
00071   normalize( &b3, cross_product(b1,b2) );
00072 
00073   Tb[0][0] = b1[0];   Tb[0][1] = b1[1];  Tb[0][2] = b1[2];
00074   Tb[1][0] = b2[0];   Tb[1][1] = b2[1];  Tb[1][2] = b2[2];
00075   Tb[2][0] = b3[0];   Tb[2][1] = b3[1];  Tb[2][2] = b3[2];
00076 
00077   GaussJordan( 3, 0, Tb, Tb ); 
00078 
00079   Ta[0][0] = a1[0];   Ta[0][1] = a1[1];  Ta[0][2] = a1[2];
00080   Ta[1][0] = a2[0];   Ta[1][1] = a2[1];  Ta[1][2] = a2[2];
00081   Ta[2][0] = a3[0];   Ta[2][1] = a3[1];  Ta[2][2] = a3[2];
00082 
00083   MMProduct( 3, 3, 3, Tb, Ta, T );  
00084 
00085   T[3][0] = B[0];  T[3][1] = B[1]; T[3][2] = B[2]; T[3][3] = (U)1; 
00086   T[0][3] = T[1][3] = T[2][3] = (U)0; 
00087 }
00088 // template instantiation
00089 template void CommonCoordinateSystem(
00090        const point<float>& B, const point<float>& P, const point<float>& Ab,  
00091        const point<float>& Pb, Ptr< Ptr<float> >& T );
00092 template void CommonCoordinateSystem(
00093        const point<double>& B, const point<double>& P, const point<double>& Ab,  
00094        const point<double>& Pb, Ptr< Ptr<double> >& T );
00095 }
00096 

Generated on Mon Jan 21 04:17:35 2002 for GUL 0.6 - Geometry Utility Library by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001