Ejemplo n.º 1
0
void CreateHexCore::createBoundaryFaces()
{
  EG_VTKSP(vtkUnstructuredGrid, new_grid);

  // find all polygons which need to be triangulated and collect the new triangles
  m_Part.setAllCells();
  QList<QVector<vtkIdType> > new_triangles;
  QVector<bool> adapt_cell(m_Grid->GetNumberOfCells(), false);
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    vec3_t xc = cellCentre(m_Grid, id_cell);
    if (isVolume(id_cell, m_Grid)) {
      for (int i = 0; i < m_Part.c2cGSize(id_cell); ++i) {
        if (m_Part.c2cGG(id_cell, i) == -1) {
          QVector<vtkIdType> face;
          getFaceOfCell(m_Grid, id_cell, i, face);
          QVector<QVector<vtkIdType> > triangles;
          triangulatePolygon(m_Grid, face, triangles);
          foreach (QVector<vtkIdType> triangle, triangles) {
            vec3_t x1, x2, x3;
            m_Grid->GetPoint(triangle[0], x1.data());
            m_Grid->GetPoint(triangle[1], x2.data());
            m_Grid->GetPoint(triangle[2], x3.data());
            vec3_t xt = (1.0/3.0)*(x1 + x2 + x3);
            vec3_t nt = GeometryTools::triNormal(x1, x2, x3);
            if (nt*(xt - xc) < 0) {
              swap(triangle[0], triangle[1]);
            }
            new_triangles.append(triangle);
          }
          if (face.size() > 3) {
            adapt_cell[id_cell] = true;
          }
        }
      }
    }
void RestrictToAvailableVolumeCells::operate()
{
  QList<vtkIdType> vol_cells, surf_cells;
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    if (isVolume(id_cell, m_Grid)) {
      vol_cells.append(id_cell);
    }
  }
  foreach (vtkIdType id_cell, vol_cells) {
    for (int i = 0; i < m_Part.c2cGSize(id_cell); ++i) {
      vtkIdType id_neigh = m_Part.c2cGG(id_cell, i);
      if (id_neigh >= 0) {
        if (isSurface(id_neigh, m_Grid)) {
          surf_cells.append(id_neigh);
        }
      }
    }
  }
  MeshPartition vol_part(m_Grid);
  vol_part.setCells(vol_cells + surf_cells);
  EG_VTKSP(vtkUnstructuredGrid, new_grid1);
  vol_part.extractToVtkGrid(new_grid1);
  MeshPartition new_part1(new_grid1, true);
  QList<QVector<vtkIdType> > new_faces;
  for (vtkIdType id_cell = 0; id_cell < new_grid1->GetNumberOfCells(); ++id_cell) {
    if (isVolume(id_cell, new_grid1)) {
      for (int i = 0; i < new_part1.c2cGSize(id_cell); ++i) {
        vtkIdType id_neigh = new_part1.c2cGG(id_cell, i);
        if (id_neigh == -1) {
          QVector<vtkIdType> pts;
          getFaceOfCell(new_grid1, id_cell, i, pts);
          new_faces.append(pts);
        }
      }
    }
  }
  EG_VTKSP(vtkUnstructuredGrid, new_grid2);
  allocateGrid(new_grid2, new_grid1->GetNumberOfCells() + new_faces.size(), new_grid1->GetNumberOfPoints());
  EG_VTKDCC(vtkIntArray, cell_code1, new_grid1, "cell_code");
  EG_VTKDCC(vtkIntArray, cell_code2, new_grid2, "cell_code");
  for (vtkIdType id_node = 0; id_node < new_grid1->GetNumberOfPoints(); ++id_node) {
    vec3_t x;
    new_grid1->GetPoint(id_node, x.data());
    new_grid2->GetPoints()->SetPoint(id_node, x.data());
    copyNodeData(new_grid1, id_node, new_grid2, id_node);
  }
  int bc_new = 0;
  for (vtkIdType id_cell = 0; id_cell < new_grid1->GetNumberOfCells(); ++id_cell) {
    copyCell(new_grid1, id_cell, new_grid2);
    copyCellData(new_grid1, id_cell, new_grid2, id_cell);
    if (isSurface(id_cell, new_grid1)) {
      bc_new = max(bc_new, cell_code1->GetValue(id_cell) + 1);
    } else {
      cell_code2->SetValue(id_cell, 0);
    }
  }
  foreach (QVector<vtkIdType> face, new_faces) {
    vtkIdType type = VTK_POLYGON;
    if (face.size() == 3) {
      type = VTK_TRIANGLE;
    } else if (face.size() == 4) {
      type = VTK_QUAD;
    }
    vtkIdType id_cell = new_grid2->InsertNextCell(type, face.size(), face.data());
    cell_code2->SetValue(id_cell, bc_new);
  }