MOAB: Mesh Oriented datABase  (version 5.4.1)
transform_test.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government retains certain
00007     rights in this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     [email protected], [email protected], [email protected],
00024     [email protected], [email protected], [email protected]
00025 
00026   ***************************************************************** */
00027 //
00028 //   SUMMARY:
00029 //     USAGE:
00030 //
00031 // ORIG-DATE: 19-Feb-02 at 10:57:52
00032 //  LAST-MOD: 18-Oct-04 by J.Kraftcheck
00033 //
00034 //
00035 // DESCRIPTION:
00036 // ============
00037 /*! \file main.cpp
00038 
00039 describe main.cpp here
00040 
00041  */
00042 // DESCRIP-END.
00043 //
00044 
00045 #include <iostream>
00046 using std::cerr;
00047 using std::cout;
00048 using std::endl;
00049 #include <cstdlib>
00050 
00051 #include "TestUtil.hpp"
00052 #include "Mesquite.hpp"
00053 #include "MeshImpl.hpp"
00054 #include "MsqError.hpp"
00055 #include "TerminationCriterion.hpp"
00056 
00057 // algorithms
00058 #include "MeshTransform.hpp"
00059 #include "Matrix3D.hpp"
00060 #include "Vector3D.hpp"
00061 #include "MsqVertex.hpp"
00062 
00063 using namespace MBMesquite;
00064 
00065 const double EPSILON = 1e-6;
00066 
00067 int main( int, char*[] )
00068 {
00069     MBMesquite::MsqPrintError err( cout );
00070     MBMesquite::MeshImpl mesh;
00071 
00072     std::string default_file_name = TestDir + "unittest/mesquite/2D/vtk/quads/untangled/tfi_horse10x4-12.vtk";
00073     // mesh->read_exodus("transformed_mesh.exo", err);
00074     mesh.read_vtk( default_file_name.c_str(), err );
00075     if( err ) return 1;
00076 
00077     // Get all vertex coordinates from mesh
00078     std::vector< MBMesquite::Mesh::VertexHandle > handles;
00079     mesh.get_all_vertices( handles, err );
00080     if( err ) return 1;
00081     if( handles.empty() )
00082     {
00083         std::cerr << "No verticies in mesh" << endl;
00084         return 1;
00085     }
00086     std::vector< MBMesquite::MsqVertex > coords( handles.size() );
00087     mesh.vertices_get_coordinates( arrptr( handles ), arrptr( coords ), handles.size(), err );
00088     if( err ) return 1;
00089 
00090     // create the matrix for affine transformation
00091     double array_entries[9];
00092     array_entries[0] = 0;
00093     array_entries[1] = 1;
00094     array_entries[2] = 0;
00095     array_entries[3] = 1;
00096     array_entries[4] = 0;
00097     array_entries[5] = 0;
00098     array_entries[6] = 0;
00099     array_entries[7] = 0;
00100     array_entries[8] = 1;
00101     // create the translation vector
00102     Matrix3D my_mat( array_entries );
00103     Vector3D my_vec( 0, 0, 10 );
00104     MeshTransform my_transform( my_mat, my_vec );
00105     // mesh->write_exodus("original_mesh.exo", err);
00106     MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, 0 );
00107     my_transform.loop_over_mesh( &mesh_and_domain, 0, err );
00108     if( err ) return 1;
00109     // mesh->write_exodus("transformed_mesh.exo", err);
00110     mesh.write_vtk( "transformed_mesh.vtk", err );
00111     if( err ) return 1;
00112 
00113     // Get transformed coordinates
00114     std::vector< MBMesquite::MsqVertex > coords2( handles.size() );
00115     mesh.vertices_get_coordinates( arrptr( handles ), arrptr( coords2 ), handles.size(), err );
00116     if( err ) return 1;
00117 
00118     // Compare vertex coordinates
00119     size_t invalid = 0;
00120     std::vector< MBMesquite::MsqVertex >::iterator iter, iter2;
00121     iter  = coords.begin();
00122     iter2 = coords2.begin();
00123     for( ; iter != coords.end(); ++iter, ++iter2 )
00124     {
00125         MBMesquite::Vector3D xform = my_mat * *iter + my_vec;
00126         double d                   = ( xform - *iter2 ).length();
00127         if( d > EPSILON ) ++invalid;
00128     }
00129 
00130     std::cerr << invalid << " vertices not within " << EPSILON << " of expected location" << std::endl;
00131 
00132     return ( invalid != 0 );
00133 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines