1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "meshkit/VertexMesher.hpp"
#include "meshkit/MKCore.hpp"
#include "MBTagConventions.hpp"
#include "moab/EntityType.hpp"
#include "meshkit/iGeom.hpp"
#include "meshkit/RegisterMeshOp.hpp"

namespace MeshKit 
{
    
 
// static registration of this  mesh scheme
moab::EntityType types[] = { moab::MBVERTEX, moab::MBMAXTYPE};
const moab::EntityType* VertexMesher::output_types() 
  { return types; }
    
VertexMesher::VertexMesher(MKCore *mkcore, const MEntVector &me_vec) 
        : MeshScheme(mkcore, me_vec) 
{
  if (mk_core()->vertex_mesher()) 
    throw Error(MK_FAILURE, "Should only have a single VertexMesher; use mk_core()->vertex_mesher().");
  
  mk_core()->vertex_mesher(this);
}

VertexMesher::~VertexMesher() 
{
  assert (mk_core()->vertex_mesher() == this);
  mk_core()->vertex_mesher(NULL);
}
    
bool VertexMesher::add_modelent(ModelEnt *model_ent) 
{
    // make sure this represents a geometric vertex
  if (0 != model_ent->dimension()) 
    throw Error(MK_WRONG_DIMENSION, "Wrong dimension entity added to VertexMesher.");

  return MeshOp::add_modelent(model_ent);
}

    //! Setup is a no-op, but must be provided since it's pure virtual
void VertexMesher::setup_this() 
{}
    
void VertexMesher::execute_this() 
{
  if (mentSelection.empty()) return;
  
    // generate vertices for each vertex
  MEntSelection::iterator sit;
  for (sit = mentSelection.begin(); sit != mentSelection.end(); sit++) {<--- Prefer prefix ++/-- operators for non-primitive types.
    if  ((*sit).first->get_meshed_state() >= COMPLETE_MESH)
	continue;
    double pos[3] = {0, 0, 0};
      // get the position
    (*sit).first->evaluate(pos[0], pos[0], pos[0], pos);
    moab::EntityHandle new_vert;
      // create the vertex
    moab::ErrorCode rval = mk_core()->moab_instance()->create_vertex(pos, new_vert);
    MBERRCHK(rval, mk_core()->moab_instance());
      // category tagging
    iMesh::EntitySetHandle msh = IBSH((*sit).first->mesh_handle());
    char category_val[CATEGORY_TAG_SIZE] = "Vertex\0";
    iBase_TagHandle category_tag;
    mk_core()->imesh_instance()->createTag(CATEGORY_TAG_NAME,CATEGORY_TAG_SIZE,iBase_BYTES, category_tag);    
    mk_core()->imesh_instance()->setEntSetData(msh, category_tag, &category_val);
      // add to meselection
    (*sit).second.insert(new_vert);
      // commit to ModelEnt
    (*sit).first->commit_mesh((*sit).second, COMPLETE_MESH);
  }
}

  
} // namespace MeshKit