Beispiel #1
0
void BrlcadReader::findBoundaryCodes()
{
  int num_grids = m_Grids.size();
  QVector<vtkUnstructuredGrid*> grids(num_grids);
  qCopy(m_Grids.begin(), m_Grids.end(), grids.begin());
  QVector<FaceFinder> finders(num_grids);
  for (int i_grid = 0; i_grid < num_grids; ++i_grid) {
    finders[i_grid].setGrid(grids[i_grid]);
  }
  EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
  bool has_errors = false;
  QVector<bool> bc_exists(num_grids, false);
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    int best_grid = -1;
    double L_min = 1e99;
    vec3_t x1 = cellCentre(m_Grid, id_cell);
    for (int i_grid = 0; i_grid < num_grids; ++i_grid) {
      double L = 1e99;
      vtkIdType id_closest = finders[i_grid].getClosestFace(x1, L);
      vec3_t x2(-999,-999,-999);
      if (id_closest != -1) x2 = cellCentre(m_Grids[i_grid], id_closest);
      if (id_closest != -1) {
        if (L < L_min) {
          best_grid = i_grid;
          L_min = L;
        }
      }
    }
    if (best_grid == -1) {
      has_errors = true;
      cell_code->SetValue(id_cell, 9999);
    } else {
      bc_exists[best_grid] = true;
      cell_code->SetValue(id_cell, best_grid + 1);
    }
  }
  GuiMainWindow::pointer()->clearBCs();
  int bc_max = 1;
  QVector<int> bc_map(num_grids+1,9999);
  m_BC2GridIndex.clear();
  for (int i_grid = 0; i_grid < num_grids; ++i_grid) {
    if (bc_exists[i_grid]) {
      bc_map[i_grid+1] = bc_max;
      GuiMainWindow::pointer()->addBC(bc_max, BoundaryCondition(m_BCNames[grids[i_grid]], "patch"));
      m_BC2GridIndex[bc_max] = i_grid;
      ++bc_max;
    }
  }
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    if (cell_code->GetValue(id_cell) != 9999) {
      cell_code->SetValue(id_cell, bc_map[cell_code->GetValue(id_cell)]);
    }
  }
  if (has_errors) {
    GuiMainWindow::pointer()->addBC(9999, BoundaryCondition("error-faces", "patch"));
  }
  GuiMainWindow::pointer()->updateBoundaryCodes(true);
}
    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);
  }
  makeCopy(new_grid2, m_Grid);
  GuiMainWindow::pointer()->addBC(bc_new, BoundaryCondition("ami_blayer", "cyclic_AMI"));
  UpdateCellIndex(m_Grid);
  GuiMainWindow::pointer()->updateBoundaryCodes(true);
}
void MultiSolidAsciiStlReader::operate()
{
  QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
  readInputFileName(file_info.completeBaseName() + ".stl");
  if (isValid()) {
    double tol = QInputDialog::getText(NULL, "enter STL tolerance", "tolerance", QLineEdit::Normal, "1e-10").toDouble();
    QList<QString> buffer;
    QList<QString> bc_name;
    {
      QFile file(getFileName());
      if (!file.open(QFile::ReadOnly)) {
        EG_ERR_RETURN("unable to open file");
      }
      QTextStream f(&file);
      QString buf = "";
      QString name = "unknown";
      while (!f.atEnd()) {
        QString line = f.readLine();
        buf += line + "\n"; // endline??
        if (line.left(8) == "endsolid") {
          buffer.append(buf);
          buf = "";
          bc_name.append(name);
        } else if (line.left(5) == "solid") {
          name = line.right(line.size() - 6);
        }
      }
    }
    bool first = true;
    int last_bc = 1;
    foreach (QString buf, buffer) {
      QString file_name = getFileName() + ".tmp";
      {
        QFile file(file_name);
        if (!file.open(QFile::WriteOnly)) {
          EG_ERR_RETURN("unable to open file\"" + file_name + "\" for writing");
        }
        QTextStream f(&file);
        f << buf << endl;
      }
      StlReader stl;
      stl.setTolerance(tol);
      stl.setFileName(file_name);
      EG_VTKSP(vtkUnstructuredGrid, grid);
      stl.setGrid(grid);
      stl.setMaximalCleaningIterations(3);
      stl();

      // @todo set boundary names
      EG_VTKDCC(vtkIntArray, bc, grid, "cell_code");
      for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
        bc->SetValue(id_cell, last_bc);
      }
      ++last_bc;

      if (first) {
        first = false;
        makeCopy(grid, m_Grid);
      } else {
        MeshPartition part1(m_Grid, true);
        MeshPartition part2(grid, true);
        part1.addPartition(part2);
      }
    }

    last_bc = 1;
    GuiMainWindow::pointer()->resetXmlDoc();
    GuiMainWindow::pointer()->clearBCs();
    foreach (QString name, bc_name) {
      GuiMainWindow::pointer()->addBC(last_bc, BoundaryCondition(name, "patch"));
      ++last_bc;
    }
Beispiel #4
0
void CreateCadTesselation::operate()
{
  double preview_memory = min(1024*1024*100.0, m_ScanMemory);
  int N = int(pow(preview_memory/sizeof(float), 1.0/3.0));
  m_Ni = N;
  m_Nj = N;
  m_Nk = N;
  m_X1 = vec3_t(-1e6,-1e6,-1e6);
  m_X2 = vec3_t( 1e6, 1e6, 1e6);
  m_Dx = (m_X2[0] - m_X1[0])/(m_Ni-1);
  m_Dy = (m_X2[1] - m_X1[1])/(m_Nj-1);
  m_Dz = (m_X2[2] - m_X1[2])/(m_Nk-1);
  double new_vol, old_vol;
  int count = 0;
  do {
    old_vol = (m_X2[0]-m_X1[0])*(m_X2[1]-m_X1[1])*(m_X2[2]-m_X1[2]);
    QString num;
    QString text = "scanning (V=";
    num.setNum(old_vol);
    text += num + ")";

    GuiMainWindow::pointer()->resetProgress(text, 3*N*N);
    scan(false);
    if (m_GeometryFound) {
      m_X1 = m_XScan1 - 2*vec3_t(m_Dx, m_Dy, m_Dz);
      m_X2 = m_XScan2 + 2*vec3_t(m_Dx, m_Dy, m_Dz);
    } else {
      m_X1 *= 0.1;
      m_X2 *= 0.1;
    }
    new_vol = (m_X2[0]-m_X1[0])*(m_X2[1]-m_X1[1])*(m_X2[2]-m_X1[2]);
  } while (count < 20 && (old_vol - new_vol)/old_vol > 0.05);

  // bounding box should now be established
  // last scan run with the full resoluion (if required)
  double Lx = m_X2[0] - m_X1[0];
  double Ly = m_X2[1] - m_X1[1];
  double Lz = m_X2[2] - m_X1[2];
  double max_size = m_ScanMemory/sizeof(float);
  double delta = max(m_SmallestResolution, pow(Lx*Ly*Lz/max_size, 1.0/3.0));
  int interlaces = 0;
  if (preserveFluid() || preserveSolid()) {
    interlaces = int(2*delta/m_SmallestFeatureSize);
  }
  m_Ni = int(Lx/delta) + 1;
  m_Nj = int(Ly/delta) + 1;
  m_Nk = int(Lz/delta) + 1;
  QString num;
  QString text = "scanning (h=";
  num.setNum(delta/(interlaces+1));
  text += num + ")";
  GuiMainWindow::pointer()->resetProgress(text, m_Ni*m_Nj + m_Ni*m_Nk + m_Nj*m_Nk);
  scan(true, interlaces);

  updateNodeIndex(m_Grid);
  updateCellIndex(m_Grid);
  GuiMainWindow::pointer()->resetXmlDoc();
  GuiMainWindow::pointer()->clearBCs();
  GuiMainWindow::pointer()->setBC(1, BoundaryCondition("imported", "patch", 1));

  GuiMainWindow::pointer()->resetProgress(" ", 100);
}