Go to Overview over all GrAL packages.
Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Gral/Grids/Triang2D/construct.C

Go to the documentation of this file.
00001 #ifndef GRAL_GB_GRIDS_TRIANG2D_CONSTRUCT_C
00002 #define GRAL_GB_GRIDS_TRIANG2D_CONSTRUCT_C
00003 
00004 // $LICENSE
00005 
00006 
00007 #include "Gral/Grids/Triang2D/copy.h"
00008 
00009 #include "Container/partial-mapping.h"
00010 #include "Container/dummy-mapping.h"
00011 
00012 //----------------------------------------------------------------
00013 //
00014 //  Copy-construct a Triang2D grid from a right-hand side (Connect)
00015 //  that allows
00016 //  - iteration over vertices ( VertexIterator | FirstVertex() )
00017 //  - iteration over cells    ( CellIterator   | FirstCell() )
00018 //  - iteration over cell-vertices (VertexOnCellIterator | Cell::FirstVertex() )
00019 //  and a geometry (geom) that gives coordinates for each vertex.
00020 //  The additional connectivity information is then calculated
00021 //  (that is, neighbors of cells and adjacent cells of vertices)
00022 //
00023 //  This algorithm is essentially the same for reading a file from
00024 //  disk (storing vertex coordinates and indices of vertices for each cell)
00025 //  or, more general, for constructing the grid from a serialized representation
00026 //  (e.g. in message passing).
00027 //  Perhaps the best way to exploit this would be to write a grid mask
00028 //  for these serial versions, using one single template method for
00029 //  the copy-construction. This could then also be used for Enlarge(...)
00030 //  and future similar functions.
00031 //----------------------------------------------------------------
00032 
00033 
00034 template<class Geom, class G2, class Geom2>
00035 void ConstructGrid(Triang2D        & G, 
00036                    Geom            & destGeom,
00037                    G2         const& srcG,
00038                    Geom2      const& srcGeom )
00039 { 
00040   typedef grid_types<G2>                                source_gt;
00041   typedef typename source_gt::vertex_handle             src_vertex_handle;
00042   typedef typename grid_types<Triang2D>::vertex_handle  vertex_handle;
00043 
00044   // this should be replaced by an array if possible.
00045   // map also lacks an operator() const  |  operator[] const 
00046   partial_mapping<src_vertex_handle,vertex_handle> VertexCorr;
00047   ConstructGridV(G,destGeom,srcG,srcGeom,VertexCorr);
00048 }
00049 
00050 template<class G2> 
00051 void ConstructGrid0(Triang2D        & G, 
00052                     G2         const& srcG)
00053 { 
00054   typedef grid_types<G2>                                source_gt;
00055   typedef typename source_gt::vertex_handle             src_vertex_handle;
00056   typedef typename source_gt::cell_handle               src_cell_handle;
00057   typedef typename grid_types<Triang2D>::vertex_handle  vertex_handle;
00058   typedef typename grid_types<Triang2D>::cell_handle    cell_handle;
00059 
00060   // this should be replaced by an array if possible.
00061   // map also lacks an operator() const  |  operator[] const 
00062   partial_mapping<src_vertex_handle,vertex_handle> VertexCorr;
00063   // here we are not interested in a cell correspondance
00064   dummy_mapping<src_cell_handle,cell_handle> CellCorr;
00065   ConstructGrid0(G,srcG,VertexCorr,CellCorr);
00066 }
00067 
00068 
00069 template<class Geom, class G2,  class Geom2, class VertexMap>
00070 void ConstructGridV(Triang2D       & G, 
00071                     Geom           & destGeom,
00072                     G2        const& srcG,
00073                     Geom2     const& srcGeom,
00074                     // maps src::handles to grid2d_fvg::handles
00075                     VertexMap      &  VertexCorr) 
00076 {
00077 
00078   typedef grid_types<G2>                               source_gt;
00079   typedef typename source_gt::cell_handle              src_cell_handle;
00080   typedef typename grid_types<Triang2D>::cell_handle   cell_handle;
00081 
00082   // here we are not interested in a cell correspondance
00083   dummy_mapping<src_cell_handle,cell_handle> CellCorr;
00084 
00085   ConstructGridVC(G,destGeom, srcG,srcGeom,VertexCorr,CellCorr);
00086 }
00087 
00088 
00089 template<class Geom, class G2, class Geom2, class VertexMap, class CellMap>
00090 void ConstructGridVC(Triang2D       & G,
00091                      Geom           & destGeom,
00092                      G2        const&  srcG,
00093                      Geom2     const&  srcGeom,
00094                      VertexMap      &  VertexCorr, // maps src::handles to
00095                      CellMap        &  CellCorr)   // complex2d::handles
00096 {
00097   // construct combinatorial grid
00098  ConstructGrid0(G,srcG,VertexCorr,CellCorr);
00099 
00100 
00101  // copy geometry
00102  destGeom.set_grid(G);
00103  typedef typename grid_types<G2>::VertexIterator   src_vertex_it;
00104  typedef typename grid_types<Triang2D>::Vertex     Vertex;
00105  for(src_vertex_it src_v = srcG.FirstVertex(); ! src_v.IsDone(); ++src_v) {
00106    Vertex V(G,VertexCorr(src_v.handle()));
00107    assign_point(destGeom.coord(V) , srcGeom.coord(*src_v));
00108  }
00109 }
00110 
00111 template<class G2, class VertexMap, class CellMap>
00112 void ConstructGrid0(Triang2D       &  G, 
00113                     G2        const&  srcG,
00114                     VertexMap      &  VertexCorr, // maps src::handles to
00115                     CellMap        &  CellCorr)   // complex2d::handles
00116 
00117 {
00118   typedef grid_types<G2> source_gt;
00119 
00120   //  typedef typename source_gt::vertex_handle   src_v_index;
00121   typedef typename source_gt::cell_handle          src_cell_handle;
00122   typedef typename source_gt::CellIterator         src_cell_it;
00123   typedef typename source_gt::VertexIterator       src_vertex_it;
00124   typedef typename source_gt::VertexOnCellIterator src_vertex_on_cell_it;
00125 
00126   typedef grid_types<Triang2D>       gt;
00127   typedef typename gt::Cell          Cell;
00128   typedef typename gt::cell_handle   cell_handle;
00129   typedef typename gt::vertex_handle vertex_handle;
00130 
00131   //---  construct vertices ---------------------------
00132   
00133   int v = 0;
00134   for(src_vertex_it src_v = srcG.FirstVertex(); ! src_v.IsDone(); ++src_v, ++v) {
00135     VertexCorr[src_v.handle()] = v;
00136   }
00137   
00138 
00139   //---- construct cells ------------------------------
00140 
00141   copy_cells(G,srcG,VertexCorr,CellCorr);
00142  
00143 
00144 }
00145 
00146 #endif
00147 

Copyright (c) Guntram Berti 1997-2002. See the GrAL Homepage for up-to-date information.

Generated at Tue Feb 26 16:09:11 2002 for GrAL Triang2D by doxygen 1.2.11-20011104 written by Dimitri van Heesch, © 1997-2000