MeshKit  1.0
example_graph.cpp
Go to the documentation of this file.
00001 
00009 /*
00010  *
00011  * Test the MeshOp graph code in MeshKit.  Do this by building a graph
00012  * which looks like:
00013  *
00014  *            R
00015  *          /   \
00016  *         A     B
00017  *        / \    |
00018  *       C   D  /
00019  *         \ | /
00020  *          \|/
00021  *           L
00022  *  and traversing it using BFS and RBFS (reverse BFS).  Do this by registering
00023  *  a MeshOp that does nothing but print its name during the setup/execute
00024  *  functions.
00025  *
00026  */
00027 
00028 #include "meshkit/MKCore.hpp"
00029 #include "meshkit/MeshOp.hpp"
00030 #include "meshkit/RegisterMeshOp.hpp"
00031 
00032 using namespace MeshKit;
00033 
00034 class MyScheme;
00035 
00036 class MyScheme : public MeshKit::MeshOp 
00037 {
00038 public:
00039   MyScheme(MKCore*, const MEntVector &);
00040   
00041   inline void setup_this() 
00042       {std::cout << "myScheme (setup), node " << get_name() << std::endl;
00043       }
00044   
00045   inline void execute_this() 
00046       {std::cout << "myScheme (execute), node " << get_name() << std::endl;
00047       }
00048 
00049   inline void mesh_types(std::vector<moab::EntityType> &tps) 
00050       {
00051       }
00052       
00053   static const char* name() { return "MyScheme"; }
00054   static bool can_mesh(iBase_EntityType dim) { return dim == iBase_REGION; }
00055   static bool can_mesh(ModelEnt* ent) { return canmesh_region(ent); }
00056   static const moab::EntityType* output_types() 
00057     { 
00058       static moab::EntityType end = moab::MBMAXTYPE;
00059       return &end;
00060     }
00061   const moab::EntityType* mesh_types_arr() const
00062     { return output_types(); }
00063   
00064 };
00065 
00066 inline MyScheme::MyScheme(MKCore *mk_core, const MEntVector & me_vec) 
00067         : MeshOp(mk_core, me_vec)
00068 {}
00069 
00070 //---------------------------------------------------------------------------//
00071 RegisterMeshOp<MyScheme> INIT;
00072 //---------------------------------------------------------------------------//
00073 
00074 int main(int argc, char **argv) 
00075 {
00076     // start up MK and register my scheme with it
00077   MKCore mk;
00078 
00079     // create the scheme objects
00080   MeshOp *A = mk.construct_meshop("MyScheme"),
00081       *B = mk.construct_meshop("MyScheme"),
00082       *C = mk.construct_meshop("MyScheme"),
00083       *D = mk.construct_meshop("MyScheme");
00084 
00085   A->set_name("A");
00086   B->set_name("B");
00087   C->set_name("C");
00088   D->set_name("D");
00089   
00090     // put them in the graph
00091   //mk.get_graph().addArc(A->get_node(), C->get_node());
00092   mk.insert_node(A, C);
00093   //mk.get_graph().addArc(A->get_node(), D->get_node());
00094   mk.insert_node(A, D);
00095   
00096     // now traverse
00097   mk.setup();
00098   
00099   mk.execute();
00100  
00101   mk.print_graph();
00102 }
00103 
00104   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines