MeshKit  1.0
Singlet.cpp
Go to the documentation of this file.
00001 #include "meshkit/QuadCleanUp.hpp"
00002 
00003 using namespace Jaal;
00004 
00006 
00007 void
00008 Jaal::set_singlet_tag(Mesh *mesh, const string &aname )
00009 {
00010      size_t numnodes = mesh->getSize(0);
00011 
00012      int relexist = mesh->build_relations(0, 2);
00013 
00014      if (!mesh->isBoundaryKnown())
00015         mesh->search_boundary();
00016 
00017      size_t ncount = 0;
00018      for (size_t i = 0; i < numnodes; i++) {
00019           Vertex *vertex = mesh->getNodeAt(i);
00020           if( vertex->isActive() ) {
00021                if (QuadCleanUp::isSinglet(vertex)) {
00022                     vertex->setAttribute(aname, 1);
00023                     ncount++;
00024                } else
00025                     vertex->setAttribute(aname, 0);
00026           }
00027      }
00028      cout << "#of Singlets detected: " << ncount << endl;
00029 
00030      if (!relexist)
00031           mesh->clear_relations(0, 2);
00032 }
00033 
00035 
00036 vector<Singlet>
00037 QuadCleanUp::search_boundary_singlets()
00038 {
00039      vSinglets.clear();
00040      //
00041      // A boundary singlet is a vertex which is shared by only one face.
00042      // They are undesirables in the quad mesh as that would mean large
00043      // angle on some of the edges..
00044      //
00045      // For the flat singlet ( angle closer to 180 degree ). it is easy
00046      // to remove the neighbouring quad from the mesh.
00047      //
00048 
00049      int relexist = mesh->build_relations(0, 2);
00050 
00051      mesh->search_boundary();
00052 
00053      assert(mesh->getAdjTable(0, 2));
00054 
00055      size_t numfaces = mesh->getSize(2);
00056      for (size_t i = 0; i < numfaces; i++) {
00057           Face *face = mesh->getFaceAt(i);
00058           face->setVisitMark(0);
00059      }
00060 
00061      size_t numnodes = mesh->getSize(0);
00062      for (size_t i = 0; i < numnodes; i++) {
00063           Vertex *v = mesh->getNodeAt(i);
00064           if( v->isActive() )  {
00065                if (isSinglet(v)) {
00066                     Singlet newsinglet(mesh, v);
00067                     vSinglets.push_back(newsinglet);
00068                }
00069           }
00070 
00071      }
00072 
00073      if (!relexist)
00074           mesh->clear_relations(0, 2);
00075 
00076      if (vSinglets.size())
00077           cout << "Info: Number of Singlets detected " << vSinglets.size() << endl;
00078 
00079      return vSinglets;
00080 }
00081 
00083 
00084 int
00085 QuadCleanUp::remove_boundary_singlets_once()
00086 {
00087 
00088      if (vSinglets.empty())
00089           search_boundary_singlets();
00090 
00091      int ncount = 0;
00092      size_t nSize = vSinglets.size();
00093      for (size_t i = 0; i <  nSize; i++) {
00094           int err = vSinglets[i].remove();
00095           if (!err) {
00096                ncount++;
00097           }
00098      }
00099 
00100      vSinglets.clear();
00101 
00102      return ncount;
00103 }
00105 int Singlet::remove()
00106 {
00107      FaceSequence vfaces;
00108      vertex->getRelations( vfaces );
00109      if (vfaces.size() > 1) return 1;
00110 
00111      return mesh->refine_quad15(vfaces[0]);
00112 }
00113 
00115 
00116 int
00117 QuadCleanUp::remove_boundary_singlets()
00118 {
00119      int relexist = mesh->build_relations(0, 2);
00120 
00121      int ncount = 0;
00122      while (1) {
00123           size_t nremoved = remove_boundary_singlets_once();
00124           if (nremoved == 0) break;
00125           ncount += nremoved;
00126      }
00127 
00128      if (!relexist) mesh->clear_relations(0, 2);
00129 
00130      return ncount;
00131 }
00132 
00134 
00135 void
00136 Singlet::clear()
00137 {
00138      size_t nSize = newNodes.size();
00139      for (size_t j = 0; j < nSize; j++)
00140           delete newNodes[j];
00141      newNodes.clear();
00142 
00143      nSize = newFaces.size();
00144      for (size_t j = 0; j < nSize; j++)
00145           delete newFaces[j];
00146 
00147      newFaces.clear();
00148 
00149 }
00150 
00152 
00153 int
00154 Singlet::commit()
00155 {
00156 
00157      for (size_t i = 0; i < oldFaces.size(); i++) {
00158           if (oldFaces[i]->isRemoved()) {
00159                clear();
00160                return 1;
00161           }
00162      }
00163 
00164      if (!active) return 2;
00165 
00166      for (size_t i = 0; i < oldNodes.size(); i++)
00167           mesh->remove( oldNodes[i] );
00168      oldNodes.clear();
00169 
00170      for (size_t i = 0; i < oldFaces.size(); i++)
00171           mesh->remove(oldFaces[i] );
00172      oldFaces.clear();
00173 
00174      for (size_t i = 0; i < newNodes.size(); i++)
00175           mesh->addNode(newNodes[i]);
00176      newNodes.clear();
00177 
00178      for (size_t i = 0; i < newFaces.size(); i++)
00179           mesh->addFace(newFaces[i]);
00180      newFaces.clear();
00181 
00182      return 0;
00183 
00184 }
00185 
00187 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines