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