Beispiel #1
0
double distanceToGeometry(GModel *gm, int distType, double tol, int meshDiscr,
                          int geomDiscr)
{
  const int dim = gm->getDim();
  double maxDist = 0.;

  if(dim == 2) {
    for(GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); ++it) {
      if((*it)->geomType() == GEntity::Line) continue;
      for(unsigned int i = 0; i < (*it)->lines.size(); i++) {
        double dist;
        switch(distType) {
        case CADDIST_TAYLOR:
          dist = taylorDistanceEdge((*it)->lines[i], *it);
          break;
        case CADDIST_FRECHET:
          dist = discreteFrechetDistanceEdge((*it)->lines[i], *it, tol,
                                             meshDiscr, geomDiscr);
          break;
        case CADDIST_HAUSFAST:
          dist = discreteHausdorffDistanceFastEdge((*it)->lines[i], *it, tol,
                                                   meshDiscr, geomDiscr);
          break;
        case CADDIST_HAUSBRUTE:
          dist = discreteHausdorffDistanceBruteEdge((*it)->lines[i], *it, tol,
                                                    meshDiscr, geomDiscr);
          break;
        default:
          Msg::Error("Wrong CAD distance type in distanceToGeometry");
          break;
        }
        maxDist = std::max(dist, maxDist);
      }
    }
  }
  else if(dim == 3) {
    if(distType == CADDIST_TAYLOR) {
      for(GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it) {
        if((*it)->geomType() == GEntity::Plane) continue;
        for(unsigned int i = 0; i < (*it)->triangles.size(); i++) {
          maxDist =
            std::max(taylorDistanceFace((*it)->triangles[i], *it), maxDist);
        }
      }
    }
    else {
      Msg::Error("CAD distance type %i not implemented for surfaces", distType);
      return -1.;
    }
  }
  else {
    Msg::Error("CAD distance cannot be computed for dimension %i", dim);
    return -1.;
  }

  return maxDist;
}
Beispiel #2
0
double distanceToGeometry(GModel *gm, int dim, int tag, int distType,
                          double tol, int meshDiscr, int geomDiscr)
{
  double maxDist = 0.;

  if (dim == 2) {
    GEdge *ge = gm->getEdgeByTag(tag);
    if (ge->geomType() == GEntity::Line) return 0.;
    for (unsigned int i = 0; i < ge->lines.size(); i++) {
      double dist;
      switch (distType) {
        case CADDIST_TAYLOR:
          dist = taylorDistanceEdge(ge->lines[i], ge);
          break;
        case CADDIST_FRECHET:
          dist = discreteFrechetDistanceEdge(ge->lines[i], ge,
                                             tol, meshDiscr, geomDiscr);
          break;
        case CADDIST_HAUSFAST:
          dist = discreteHausdorffDistanceFastEdge(ge->lines[i], ge,
                                                   tol, meshDiscr, geomDiscr);
          break;
        case CADDIST_HAUSBRUTE:
          dist = discreteHausdorffDistanceBruteEdge(ge->lines[i], ge,
                                                    tol, meshDiscr, geomDiscr);
          break;
        default:
          Msg::Error("Wrong CAD distance type in distanceToGeometry");
          return -1.;
          break;
      }
      maxDist = std::max(dist, maxDist);
    }
  }
  else if (dim == 3) {
    if (distType == CADDIST_TAYLOR) {
      GFace *gf = gm->getFaceByTag(tag);
      if (gf->geomType() == GEntity::Plane) return 0.;
      for (unsigned int i = 0; i < gf->triangles.size(); i++)
        maxDist = std::max(taylorDistanceFace(gf->triangles[i], gf), maxDist);
      for (unsigned int i = 0; i < gf->quadrangles.size(); i++)
        maxDist = std::max(taylorDistanceFace(gf->quadrangles[i], gf), maxDist);
    }
    else {
      Msg::Error("CAD distance type %i not implemented for surfaces", distType);
      return -1.;
    }
  }
  else {
    Msg::Error("CAD distance cannot be computed for dimension %i", dim);
    return -1.;
  }

  return maxDist;
}
Beispiel #3
0
double HOPatchDefParameters::bndElBadness(MElement *el, GEntity* gEnt) const
{
  if (optCAD) {
    if (el->getType() == TYPE_LIN) {                                              // 2D
      if (gEnt->geomType() != GEntity::Line)                                      // Straight geometric line -> no distance
        return optCADDistMax -
               taylorDistanceEdge(static_cast<MLine*>(el), gEnt->cast2Edge());
    }
    else {                                                                        // 3D
      if (gEnt->geomType() != GEntity::Plane)                                     // Straight geometric plance -> no distance
        return optCADDistMax -
               taylorDistanceFace(el, gEnt->cast2Face());
    }
  }
  return 1.;
}
Beispiel #4
0
void distanceFromElementsToGeometry(GModel *gm, int dim,
                                    std::map<MElement *, double> &distances)
{
  std::map<MEdge, double, Less_Edge> dist2Edge;
  for(GModel::eiter it = gm->firstEdge(); it != gm->lastEdge(); ++it) {
    if((*it)->geomType() == GEntity::Line) continue;
    for(unsigned int i = 0; i < (*it)->lines.size(); i++) {
      double d = taylorDistanceEdge((*it)->lines[i], *it);
      MEdge e = (*it)->lines[i]->getEdge(0);
      dist2Edge[e] = d;
    }
  }

  std::map<MFace, double, Less_Face> dist2Face;
  for(GModel::fiter it = gm->firstFace(); it != gm->lastFace(); ++it) {
    if((*it)->geomType() == GEntity::Plane) continue;
    for(unsigned int i = 0; i < (*it)->triangles.size(); i++) {
      double d = taylorDistanceFace((*it)->triangles[i], *it);
      MFace f = (*it)->triangles[i]->getFace(0);
      dist2Face[f] = d;
    }
  }

  std::vector<GEntity *> entities;
  gm->getEntities(entities);
  for(int iEnt = 0; iEnt < entities.size(); ++iEnt) {
    GEntity *&entity = entities[iEnt];
    if(entity->dim() != dim) continue;
    for(int iEl = 0; iEl < entity->getNumMeshElements();
        iEl++) { // Detect bad elements
      MElement *element = entity->getMeshElement(iEl);
      double d = 0.;
      for(int iEdge = 0; iEdge < element->getNumEdges(); ++iEdge) {
        MEdge e = element->getEdge(iEdge);
        std::map<MEdge, double, Less_Edge>::iterator it = dist2Edge.find(e);
        if(it != dist2Edge.end()) d += it->second;
      }
      for(int iFace = 0; iFace < element->getNumFaces(); ++iFace) {
        MFace f = element->getFace(iFace);
        std::map<MFace, double, Less_Face>::iterator it = dist2Face.find(f);
        if(it != dist2Face.end()) d += it->second;
      }
      distances[element] = d;
    }
  }
}