MeshKit  1.0
VertexMesher.cpp
Go to the documentation of this file.
00001 #include "meshkit/VertexMesher.hpp"
00002 #include "meshkit/MKCore.hpp"
00003 #include "moab/EntityType.hpp"
00004 #include "meshkit/iGeom.hpp"
00005 #include "meshkit/RegisterMeshOp.hpp"
00006 
00007 namespace MeshKit 
00008 {
00009     
00010  
00011 // static registration of this  mesh scheme
00012 moab::EntityType types[] = { moab::MBVERTEX, moab::MBMAXTYPE};
00013 const moab::EntityType* VertexMesher::output_types() 
00014   { return types; }
00015     
00016 VertexMesher::VertexMesher(MKCore *mkcore, const MEntVector &me_vec) 
00017         : MeshScheme(mkcore, me_vec) 
00018 {
00019   if (mk_core()->vertex_mesher()) 
00020     throw Error(MK_FAILURE, "Should only have a single VertexMesher; use mk_core()->vertex_mesher().");
00021   
00022   mk_core()->vertex_mesher(this);
00023 }
00024 
00025 VertexMesher::~VertexMesher() 
00026 {
00027   assert (mk_core()->vertex_mesher() == this);
00028   mk_core()->vertex_mesher(NULL);
00029 }
00030     
00031 bool VertexMesher::add_modelent(ModelEnt *model_ent) 
00032 {
00033     // make sure this represents a geometric vertex
00034   if (0 != model_ent->dimension()) 
00035     throw Error(MK_WRONG_DIMENSION, "Wrong dimension entity added to VertexMesher.");
00036 
00037   return MeshOp::add_modelent(model_ent);
00038 }
00039 
00041 void VertexMesher::setup_this() 
00042 {}
00043     
00044 void VertexMesher::execute_this() 
00045 {
00046   if (mentSelection.empty()) return;
00047   
00048     // generate vertices for each vertex
00049   MEntSelection::iterator sit;
00050   for (sit = mentSelection.begin(); sit != mentSelection.end(); sit++) {
00051     if  ((*sit).first->get_meshed_state() >= COMPLETE_MESH)
00052         continue;
00053     double pos[3];
00054       // get the position
00055     (*sit).first->evaluate(pos[0], pos[0], pos[0], pos);
00056     moab::EntityHandle new_vert;
00057       // create the vertex
00058     moab::ErrorCode rval = mk_core()->moab_instance()->create_vertex(pos, new_vert);
00059     MBERRCHK(rval, mk_core()->moab_instance());
00060       // add to meselection
00061     (*sit).second.insert(new_vert);
00062       // commit to ModelEnt
00063     (*sit).first->commit_mesh((*sit).second, COMPLETE_MESH);
00064   }
00065 }
00066 
00067   
00068 } // namespace MeshKit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines