Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

test_mesh.C

Go to the documentation of this file.
00001 /**********************************************************************
00002  * test_mesh.C:
00003  *
00004  *  used to test whatever mesh functionality is lately being developed.
00005  *  change the code as needed...
00006  *
00007  *  currently testing indexing in SimplexArrays
00008  *     ... and they do seem to work
00009  *
00010  **********************************************************************/
00011 #include "std/config.H"
00012 #include "mi.H"
00013 
00014 inline uint
00015 num_data(CBsimplex* s)
00016 {
00017    if (!(s && s->data_list()))
00018       return 0;
00019    return (uint)s->data_list()->num();
00020 }
00021 
00022 /*****************************************************************
00023  * NumSimplexDataFilter:
00024  *
00025  *   Accept a simplex if it contains a specific number
00026  *   of SimplexData pointers.
00027  *
00028  *****************************************************************/
00029 class NumSimplexDataFilter : public SimplexFilter {
00030  public:
00031    NumSimplexDataFilter(uint num) : _num(num) {}
00032 
00033    virtual bool accept(CBsimplex* s) const {
00034       return (s && num_data(s) == _num);
00035    }
00036 
00037  protected:
00038    uint _num;
00039 };
00040 typedef const NumSimplexDataFilter CNumSimplexDataFilter;
00041 
00042 inline void
00043 print_data_counts(CBvert_list& verts)
00044 {
00045    cerr << "data counts for " << verts.num() << " vertices" << endl;
00046    for (uint total=0, i=0, t=0; total < (uint)verts.num(); total += t, i++) {
00047       t = verts.filter(NumSimplexDataFilter(i)).num();
00048       cerr << "  " << i << ": " << t << endl;
00049    }
00050 }
00051 
00052 inline void
00053 check_indices(CBvert_list& verts)
00054 {
00055    for (int i=0; i<verts.num(); i++) {
00056       if (verts.get_index(verts[i]) != i) {
00057          cerr << "  index error: " << i << "/" << verts.num()
00058               << " recorded as " << verts.get_index(verts[i]) << endl;
00059          return;
00060       }
00061    }
00062    cerr << verts.num() << " indices okay" << endl;
00063 }
00064 
00065 /*****************************************************************
00066  * main
00067  *****************************************************************/
00068 int 
00069 main(int argc, char *argv[])
00070 {
00071    if (argc != 1) {
00072       err_msg("Usage: %s < mesh.sm", argv[0]);
00073       return 1;
00074    }
00075 
00076    BMESH* bmesh = new BMESH;
00077    BMESH* lmesh = new LMESH;
00078 
00079    cerr << "dynamic cast from BMESH* to BMESH* does ";
00080    if (dynamic_cast<BMESH*>(bmesh) == NULL)
00081       cerr << "NOT ";
00082    cerr << "work" << endl;
00083 
00084    cerr << "dynamic cast from LMESH* to LMESH* does ";
00085    if (dynamic_cast<LMESH*>(lmesh) == NULL)
00086       cerr << "NOT ";
00087    cerr << "work" << endl;
00088    return 0;
00089 
00090    BMESHptr mesh = BMESH::read_jot_stream(cin);
00091    if (!mesh || mesh->empty())
00092       return 1; // didn't work
00093 
00094 
00095    Bvert_list verts = mesh->vert_list();
00096    Bvert_list bak   = verts;
00097 
00098    cerr << "loaded mesh" << endl;
00099    mesh->print();
00100 
00101    print_data_counts(verts);
00102 
00103    cerr << "begin index" << endl;
00104    verts.begin_index();
00105 
00106    print_data_counts(verts);
00107 
00108    cerr << "verts reverse" << endl;
00109    verts.reverse();
00110 
00111    cerr << "check indices" << endl;
00112    check_indices(verts);
00113 
00114    int n = verts.num();
00115    cerr << "removing " << n/2 << " verts" << endl;
00116    for (int i=0; i<n/2; i++) {
00117       Bvert* v = verts[i];
00118       uint b = num_data(v);     // before
00119       verts -= v;
00120       uint a = num_data(v);     // after
00121       if (!(b == 1) && (a == 0)) {
00122          err_msg("before: %d, after: %d", b, a);
00123          break;
00124       }
00125    }
00126 
00127    print_data_counts(verts);
00128 
00129    cerr << "bak:" << endl;
00130    print_data_counts(bak);
00131 
00132    cerr << "bak with indexing:" << endl;
00133    bak.begin_index();
00134    print_data_counts(bak);
00135 
00136    cerr << "turning off indexing" << endl;
00137    verts.end_index();
00138 
00139    cerr << "verts: " << endl;
00140    print_data_counts(verts);
00141 
00142    cerr << "verts = bak" << endl;
00143    verts = bak; 
00144    print_data_counts(verts);
00145 
00146    cerr << "bak.clear()" << endl;
00147    bak.clear();
00148    print_data_counts(verts);
00149    
00150    return 0;
00151 }
00152 
00153 // end of file test_mesh.C

Generated on Mon Sep 18 11:39:33 2006 for jot by  doxygen 1.4.4