コード例 #1
0
vtkIdType SimpleFoamWriter::getNeigh(int i_cells, int i_neigh) 
{ 
  l2g_t cells = getPartCells();
  l2l_t c2c   = getPartC2C();
  int n = c2c[i_cells][i_neigh]; 
  if (n >= 0) return cells[n]; 
  EG_ERR_RETURN("The grid is not suitable for OpenFOAM export (e.g. missing volume mesh).");
  return -1;
}
コード例 #2
0
ファイル: brlcadinterface.cpp プロジェクト: Nasrollah/engrid
BrlCadInterface::BrlCadInterface(QString file_name, QString object_name)
{
  m_Rtip = rt_dirbuild(qPrintable(file_name), m_IdBuf, sizeof(m_IdBuf));
  if (m_Rtip == RTI_NULL) {
    EG_ERR_RETURN("Unable to open BRL-CAD database!");
  }
  if (rt_gettree(m_Rtip, qPrintable(object_name)) < 0) {
    EG_ERR_RETURN("unable to access selected object");
  }
  rt_prep_parallel(m_Rtip, 1);
  application ap = {0};
  m_Ap = ap;
  m_Ap.a_rt_i   = m_Rtip;

  setName("BRL-CAD interface");
  m_ShootRayImplemented = true;

  //m_Ap.a_onehit = 1;
}
コード例 #3
0
ファイル: neutralwriter.cpp プロジェクト: danbarrynz/engrid
void NeutralWriter::operate()
{
  try {
    QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
    readOutputFileName(file_info.completeBaseName() + ".mesh");
    if (isValid()) {
      QFile file(getFileName());
      file.open(QIODevice::WriteOnly | QIODevice::Text);
      QTextStream f(&file);
      f << m_Grid->GetNumberOfPoints() << "\n";
      for (vtkIdType pointId = 0; pointId < m_Grid->GetNumberOfPoints(); ++pointId) {
        vec3_t x;
        m_Grid->GetPoints()->GetPoint(pointId, x.data());
        f << x[0] << " " << x[1] << " " << x[2] << "\n";
      };
      vtkIdType Nvol = 0;
      vtkIdType Nsurf = 0;
      for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
        vtkIdType cellType = m_Grid->GetCellType(cellId);
        if ((cellType != VTK_TRIANGLE) && (cellType != VTK_TETRA)) {
          EG_ERR_RETURN("only simplex elements are allowed for the NEUTRAL format");
        };
        if (isSurface(cellId, m_Grid)) {
          ++Nsurf;
        } else {
          ++Nvol;
        };
      };
      f << Nvol << "\n";
      for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
        if (!isSurface(cellId, m_Grid)) {
          vtkIdType Npts, *pts;
          m_Grid->GetCellPoints(cellId, Npts, pts);
          f << "1 " << pts[0]+1 << " " << pts[1]+1 << " " << pts[3]+1 << " " << pts[2]+1 << "\n";
        };
      };
      f << Nsurf << "\n";
      EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
      for (vtkIdType cellId = 0; cellId < m_Grid->GetNumberOfCells(); ++cellId) {
        if (isSurface(cellId, m_Grid)) {
          vtkIdType Npts, *pts;
          m_Grid->GetCellPoints(cellId, Npts, pts);
          f << 1;//cell_code->GetValue(cellId);
          f << " " << pts[2]+1 << " " << pts[1]+1 << " " << pts[0]+1 << "\n";
        };
      };
    };
  } catch (Error err) {
    err.display();
  };
};
コード例 #4
0
ファイル: foamobject.cpp プロジェクト: danbarrynz/engrid
void FoamObject::readFile(QString file_name)
{
  file_name = m_CaseDir + "/" + file_name;
  if(m_BufferedFileName != m_CaseDir + "/" + file_name) {
    m_BufferedFileName = file_name;
    QFile file(file_name);
    if (!file.open(QIODevice::ReadOnly)) {
      EG_ERR_RETURN(QString("error loading file:\n") + file_name);
    }
    QTextStream f(&file);
    m_Buffer = "";
    m_Buffer.reserve(file.size());
    while(!f.atEnd())
    {
      m_Buffer += f.readLine() + "\n";
    }
    stripBuffer();
  }
}
コード例 #5
0
ファイル: deletepickedpoint.cpp プロジェクト: huahbo/engrid
void DeletePickedPoint::operate()
{
    vtkIdType id_node = GuiMainWindow::pointer()->getPickedPoint();
    cout << "You picked " << id_node << endl;
    if( id_node<0  || GuiMainWindow::pointer()->getPickedObject()!=1 ) {
        QApplication::restoreOverrideCursor();
        EG_ERR_RETURN("Error: No node picked.");
    }

    char type;
    QVector <vtkIdType> PSP;

    //IMPORTANT: to make sure only unselected nodes become fixed (redundant with previous line, but more readable)
    this->m_BoundaryCodes = GuiMainWindow::pointer()->getAllBoundaryCodes();
    qWarning()<<"m_BoundaryCodes="<<m_BoundaryCodes;

    updateNodeInfo();

    QMessageBox msgBox;
    msgBox.setText("Delete point?");
    msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    switch (msgBox.exec()) {
    case QMessageBox::Yes:
        cout<<"yes was clicked"<<endl;
        DeletePoint(id_node);
        break;
    case QMessageBox::No:
        cout<<"no was clicked"<<endl;
        cout<<"=== Topological neighbours ==="<<endl;
        PSP = getPotentialSnapPoints(id_node);
        cout<<"id_node="<<id_node<<" PSP="<<PSP<<endl;

        cout<<"=== NODE TYPE ==="<<endl;
        type = getNodeType(id_node);
        cout<<"id_node="<<id_node<<" is of type="<<(int)type<<"="<<VertexType2Str(type)<<endl;

        break;
    default:
        // should never be reached
        break;
    }

}
コード例 #6
0
void GuiDeleteBadAspectTris::operate()
{
  double threshold = m_Ui.doubleSpinBox->value();
  QList<vtkIdType> new_cells;
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    if (isVolume(id_cell,m_Grid)) EG_ERR_RETURN("The grid contains volume cells");
    vtkIdType type_cell = m_Grid->GetCellType(id_cell);
    if (type_cell == VTK_TRIANGLE) {
      vtkIdType *pts, N_pts;
      m_Grid->GetCellPoints(id_cell, N_pts, pts);
      vec3_t x[3];
      for (int i = 0; i < 3; ++i) {
        m_Grid->GetPoint(pts[i], x[i].data());
      };
      double l1 = (x[1]-x[0]).abs();
      double l2 = (x[2]-x[1]).abs();
      double l3 = (x[0]-x[2]).abs();
      double l_min = min(l1,min(l2,l3));
      double l_max = max(l1,max(l2,l3));
      double ratio = l_max/l_min;
      if (ratio <= threshold) {
        new_cells.append(id_cell);
      };
    } else {
      new_cells.append(id_cell);
    };
  };
  EG_VTKSP(vtkUnstructuredGrid, new_grid);
  allocateGrid(new_grid, new_cells.size(), m_Grid->GetNumberOfPoints());
  for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
    vec3_t x;
    m_Grid->GetPoints()->GetPoint(id_node, x.data());
    new_grid->GetPoints()->SetPoint(id_node, x.data());
    copyNodeData(m_Grid, id_node, new_grid, id_node);
  };
  foreach (vtkIdType id_cell, new_cells) {
    vtkIdType *pts, N_pts;
    m_Grid->GetCellPoints(id_cell, N_pts, pts);
    vtkIdType type_cell = m_Grid->GetCellType(id_cell);
    vtkIdType id_new_cell = new_grid->InsertNextCell(type_cell, N_pts, pts);
    copyCellData(m_Grid, id_cell, new_grid, id_new_cell);
  };
コード例 #7
0
ファイル: guimergevolumes.cpp プロジェクト: ttjj/engrid
void GuiMergeVolumes::operate()
{
  QString vol_name1 = getSelectedVolume(m_Ui.listWidgetVC1);
  QString vol_name2 = getSelectedVolume(m_Ui.listWidgetVC2);
  VolumeDefinition V1 = GuiMainWindow::pointer()->getVol(vol_name1);
  VolumeDefinition V2 = GuiMainWindow::pointer()->getVol(vol_name2);
  QSet<int> all_bcs = GuiMainWindow::pointer()->getAllBoundaryCodes();

  // identify boundary patches to be deleted
  QSet<int> del_bcs;
  foreach (int bc, all_bcs) {
    int sign1 = V1.getSign(bc);
    int sign2 = V2.getSign(bc);
    if (sign1 != 0 && sign2 != 0) {
      if (sign1*sign2 > 0) {
        EG_ERR_RETURN("volume definition not consistent (green/yellow)");
      }
      del_bcs.insert(bc);
    }
  }
コード例 #8
0
void ReducedPolyDataReader::computeLevelSet(vtkUnstructuredGrid* m_Grid, vtkPolyData* poly)
{
  // create triangles
  poly->BuildCells();
  QVector<Triangle> triangles(poly->GetNumberOfPolys());
  for (vtkIdType id_poly = 0; id_poly < poly->GetNumberOfPolys(); ++id_poly) {
    vtkIdType Npts, *pts;
    poly->GetCellPoints(id_poly, Npts, pts);
    if (Npts == 3) {
      poly->GetPoint(pts[0], triangles[id_poly].a.data());
      poly->GetPoint(pts[1], triangles[id_poly].b.data());
      poly->GetPoint(pts[2], triangles[id_poly].c.data());
      triangles[id_poly].id_a = pts[0];
      triangles[id_poly].id_b = pts[1];
      triangles[id_poly].id_c = pts[2];
      triangles[id_poly].g1 = triangles[id_poly].b - triangles[id_poly].a;
      triangles[id_poly].g2 = triangles[id_poly].c - triangles[id_poly].a;
      triangles[id_poly].g3 = triangles[id_poly].g1.cross(triangles[id_poly].g2);
      triangles[id_poly].A  = 0.5*triangles[id_poly].g3.abs();
      triangles[id_poly].g3.normalise();
      triangles[id_poly].G.column(0, triangles[id_poly].g1);
      triangles[id_poly].G.column(1, triangles[id_poly].g2);
      triangles[id_poly].G.column(2, triangles[id_poly].g3);
      triangles[id_poly].GI = triangles[id_poly].G.inverse();
      triangles[id_poly].smallest_length = (triangles[id_poly].b - triangles[id_poly].a).abs();
      triangles[id_poly].smallest_length = min(triangles[id_poly].smallest_length, (triangles[id_poly].c - triangles[id_poly].b).abs());
      triangles[id_poly].smallest_length = min(triangles[id_poly].smallest_length, (triangles[id_poly].a - triangles[id_poly].c).abs());
    } else {
      EG_BUG;
    }
  }

  //vtkDoubleArray *scalars = vtkDoubleArray::New();
  EG_VTKSP(vtkDoubleArray, scalars);
  scalars->SetNumberOfComponents(1);
  scalars->SetName("g");
  scalars->Allocate(m_Grid->GetNumberOfPoints());

  QProgressDialog progress("Reducing triangulation", "Abort", 0, m_Grid->GetNumberOfPoints());
  progress.setWindowModality(Qt::ApplicationModal);
  for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
    progress.setValue(id_node);
    QApplication::processEvents();
    if (progress.wasCanceled()) {
      EG_ERR_RETURN("interrupted by user");
    }
    double g_levelset = 1e99;
    vec3_t xp;
    m_Grid->GetPoint(id_node, xp.data());
    foreach (Triangle T, triangles) {
      vec3_t xi(1e99,1e99,1e99);
      vec3_t ri;
      double scal = (xp - T.a)*T.g3;
      vec3_t x1, x2;
      if (scal > 0) {
        x1 = xp + T.g3;
        x2 = xp - scal*T.g3 - T.g3;
      } else {
        x1 = xp - T.g3;
        x2 = xp - scal*T.g3 + T.g3;
      }
      double d = 1e99;

      bool intersects_face = GeometryTools::intersectEdgeAndTriangle(T.a, T.b, T.c, x1, x2, xi, ri);
      if (intersects_face) {
        vec3_t dx = xp - xi;
        d = fabs(dx*T.g3);
      } else {
        double kab = GeometryTools::intersection(T.a, T.b - T.a, xp, T.b - T.a);
        double kac = GeometryTools::intersection(T.a, T.c - T.a, xp, T.c - T.a);
        double kbc = GeometryTools::intersection(T.b, T.c - T.b, xp, T.c - T.b);
        double dab = (T.a + kab*(T.b-T.a) - xp).abs();
        double dac = (T.a + kac*(T.c-T.a) - xp).abs();
        double dbc = (T.b + kbc*(T.c-T.b) - xp).abs();
        bool set = false;
        if ((kab >= 0) && (kab <= 1)) {
          if (dab < d) {
            xi = T.a + kab*(T.b-T.a);
            d = dab;
            set = true;
          }
        }
        if ((kac >= 0) && (kac <= 1)) {
          if (dac < d) {
            xi = T.a + kac*(T.c-T.a);
            d = dac;
            set = true;
          }
        }
        if ((kbc >= 0) && (kbc <= 1)) {
          if (dbc < d) {
            xi = T.b + kbc*(T.c-T.b);
            d = dbc;
            set = true;
          }
        }
        double da = (T.a - xp).abs();
        double db = (T.b - xp).abs();
        double dc = (T.c - xp).abs();
        if (da < d) {
          xi = T.a;
          d = da;
          set = true;
        }
        if (db < d) {
          xi = T.b;
          d = db;
        }
        if (dc < d) {
          xi = T.c;
          d = dc;
          set = true;
        }
        if (!set) {
          EG_BUG;
        }
      }
      if (xi[0] > 1e98) {
        EG_BUG;
      }
      vec3_t dx = xp - xi;
      if (d < fabs(g_levelset)) {
        if (dx*T.g3 > 0) {
          g_levelset = d;
        } else {
          g_levelset = -d;
        }
      }
    }
    scalars->InsertTuple1(id_node, g_levelset);
  }
コード例 #9
0
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;
    }
コード例 #10
0
ファイル: fillplane.cpp プロジェクト: Nasrollah/engrid
void FillPlane::closeLoops(vtkUnstructuredGrid *edge_grid)
{
  bool done = false;
  while (!done) {
    QList<vtkIdType> end_nodes;
    QVector<int> count(edge_grid->GetNumberOfPoints(), 0);
    for (vtkIdType id_edge = 0; id_edge < edge_grid->GetNumberOfCells(); ++id_edge) {
      vtkIdType num_pts, *pts;
      edge_grid->GetCellPoints(id_edge, num_pts, pts);
      for (int i = 0; i < num_pts; ++i) {
        ++count[pts[i]];
      }
    }
    for (vtkIdType id_node = 0; id_node < edge_grid->GetNumberOfPoints(); ++id_node) {
      if (count[id_node] == 0) {
        EG_ERR_RETURN("unable to fill plane(s)");
      }
      if (count[id_node] > 2) {
        EG_ERR_RETURN("unable to fill plane(s)");
      }
      if (count[id_node] == 1) {
        end_nodes.append(id_node);
      }
    }
    if (end_nodes.size() % 2 != 0) {
      EG_ERR_RETURN("unable to fill plane(s)");
    }
    if (end_nodes.size() > 0) {
      double dist_min = EG_LARGE_REAL;
      vtkIdType id_fill1 = -1;
      vtkIdType id_fill2 = -1;
      foreach (vtkIdType id_node1, end_nodes) {
        vec3_t n1 = m_Part.globalNormal(m_NodeMap[id_node1]);
        vec3_t x1;
        edge_grid->GetPoint(id_node1, x1.data());
        foreach (vtkIdType id_node2, end_nodes) {
          if (id_node1 != id_node2) {
            vec3_t n2 = m_Part.globalNormal(m_NodeMap[id_node2]);
            vec3_t x2;
            edge_grid->GetPoint(id_node2, x2.data());
            double angle = GeometryTools::angle(n1, -1*n2);
            if (angle < m_AngleTol) {
              vec3_t d = x2 - x1;
              double dist = d.abs();
              d.normalise();
              if (d*n2 > 0.5 && d*n1 < -0.5) {
                if (dist < dist_min) {
                  dist_min = dist;
                  id_fill1 = id_node1;
                  id_fill2 = id_node2;
                }
              }
            }
          }
        }
      }
      if (id_fill1 == -1 || id_fill2 == -1) {
        EG_ERR_RETURN("unable to fill plane(s)");
      }
      vtkIdType pts[2];
      pts[0] = id_fill1;
      pts[1] = id_fill2;
      edge_grid->InsertNextCell(VTK_LINE, 2, pts);
    } else {
コード例 #11
0
void GuiNormalExtrusion::operate()
{
  QSet<int> bcs;
  getSelectedItems(m_Ui.listWidget, bcs);
  EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
  QSet<int> volume_codes;
  EG_FORALL_CELLS(id_cell, m_Grid) {
    if (isSurface(id_cell, m_Grid)) {
      if (bcs.contains(cell_code->GetValue(id_cell))) {
        vtkIdType id_volume_cell = m_Part.getVolumeCell(id_cell);
        if (id_volume_cell != -1) {
          volume_codes.insert(cell_code->GetValue(id_volume_cell));
        }
      }
    }
  }

  EG_VTKSP(vtkEgNormalExtrusion, extr);
  QVector<double> y;
  
  if (m_Ui.radioButtonSimple->isChecked()) {
    y.resize(m_Ui.lineEditSimpleNumLayers->text().toInt() + 1);
    double h = m_Ui.lineEditSimpleHeight->text().toDouble();
    double f = m_Ui.lineEditSimpleIncrease->text().toDouble();
    y[0] = 0.0;
    for (int i = 1; i < y.size(); ++i) {
      y[i] = y[i-1] + h;
      h *= f;
    }
  } else if (m_Ui.radioButtonFixedHeights->isChecked()) {
    y.resize(m_Ui.lineEditFixedHeightsNumLayers->text().toInt() + 1);
    QVector<double> x(y.size());
    for (int i = 0; i < x.size(); ++i) {
      x[i] = i*1.0/(x.size() - 1);
    }
    mat3_t A;
    clinit(A[0]) = pow(x[1],5.0), pow(x[1],3.0), x[1];
    clinit(A[1]) = pow(x[x.size() - 2],5.0), pow(x[x.size() - 2],3.0), x[x.size() - 2];
    clinit(A[2]) = pow(x[x.size() - 1],5.0), pow(x[x.size() - 1],3.0), x[x.size() - 1];
    vec3_t h;
    h[0] = m_Ui.lineEditFixedHeightsHeightFirst->text().toDouble();
    h[2] = m_Ui.lineEditFixedHeightsTotalHeight->text().toDouble();
    h[1] = h[2] - m_Ui.lineEditFixedHeightsHeightLast->text().toDouble();
    mat3_t AI = A.inverse();
    vec3_t coeff = AI*h;
    for (int i = 0; i < y.size(); ++i) {
      y[i] = coeff[0]*pow(x[i],5.0) + coeff[1]*pow(x[i],3.0) + coeff[2]*x[i];
      if (i > 0) {
        if (y[i] < y[i-1]) {
          EG_ERR_RETURN("unable to compute layer heights");
        }
      }
    }
  }
  extr->SetLayers(y);
  
  if (m_Ui.radioButtonFixed->isChecked()) {
    extr->SetNormal(vec3_t(m_Ui.lineEditFixedNX->text().toDouble(),
                           m_Ui.lineEditFixedNY->text().toDouble(),
                           m_Ui.lineEditFixedNZ->text().toDouble()));
    double min_dist = m_Ui.lineEditFixedDist->text().toDouble();
    if (min_dist <= 0) {
      extr->SetFixed();
    } else {
      extr->SetPlanar();
      extr->SetMinDist(min_dist);
    }
  }
  if (m_Ui.radioButtonCylinder->isChecked()) {
    extr->SetCylindrical();
    extr->SetOrigin(vec3_t(m_Ui.lineEditCylinderX0->text().toDouble(),
                           m_Ui.lineEditCylinderY0->text().toDouble(),
                           m_Ui.lineEditCylinderZ0->text().toDouble()));
    extr->SetAxis(vec3_t(m_Ui.lineEditCylinderNX->text().toDouble(),
                         m_Ui.lineEditCylinderNY->text().toDouble(),
                         m_Ui.lineEditCylinderNZ->text().toDouble()));
  }
  if (m_Ui.radioButtonRotation->isChecked()) {
    extr->SetRotation();
    extr->SetOrigin(vec3_t(m_Ui.lineEditCylinderX0->text().toDouble(),
                           m_Ui.lineEditCylinderY0->text().toDouble(),
                           m_Ui.lineEditCylinderZ0->text().toDouble()));
    extr->SetAxis(vec3_t(m_Ui.lineEditCylinderNX->text().toDouble(),
                         m_Ui.lineEditCylinderNY->text().toDouble(),
                         m_Ui.lineEditCylinderNZ->text().toDouble()));
  }

  if (m_Ui.radioButtonNoRestrict->isChecked()) {
    extr->SetRestrictNone();
  }
  if (m_Ui.radioButtonXY->isChecked()) {
    extr->SetRestrictXY();
  }
  if (m_Ui.radioButtonXZ->isChecked()) {
    extr->SetRestrictXZ();
  }
  if (m_Ui.radioButtonYZ->isChecked()) {
    extr->SetRestrictYZ();
  }

  if (m_Ui.checkBoxNewVolume->isChecked()) {
    extr->SetRemoveInternalFacesOff();
  }

  QList<VolumeDefinition> vols = GuiMainWindow::pointer()->getAllVols();
  int vc = 1;
  foreach (VolumeDefinition vol, vols) {
    vc = max(vc, vol.getVC());
  }
コード例 #12
0
void GuiSetBoundaryCode::operate()
{
  m_ButtonGroup->checkedId();
  cout<<"buttongroup->checkedId()="<<m_ButtonGroup->checkedId()<<endl;

  //save settings
  QSettings local_qset("enGits","enGrid_GuisetBoundaryCode");
  local_qset.setValue("FeatureAngle", m_Ui.doubleSpinBoxFeatureAngle->value());
  local_qset.setValue("BoundaryCode", m_Ui.spinBoxBoundaryCode->value());
  local_qset.setValue("PickMethod", m_ButtonGroup->checkedId());
  
  SetBoundaryCode set_bc;
  set_bc.setGrid(m_Grid);
  set_bc.setAllSurfaceCells();
  if (m_RadioButtonAuto->isChecked()) {
    QSet <int> display_bcs;
    GuiMainWindow::pointer()->getDisplayBoundaryCodes(display_bcs);
    int bc = m_Ui.spinBoxBoundaryCode->value();
    EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
    for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
      bc = max(bc, cell_code->GetValue(id_cell));
      if (display_bcs.contains(cell_code->GetValue(id_cell))) {
        cell_code->SetValue(id_cell, 9999);
      }
    }
    bool done = false;
    do {
      vtkIdType id_start = -1;
      for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
        if (cell_code->GetValue(id_cell) == 9999) {
          id_start = id_cell;
          break;
        }
      }
      if (id_start == -1) {
        done = true;
      } else {
        set_bc.setFeatureAngle(m_Ui.doubleSpinBoxFeatureAngle->value());
        set_bc.setNewBC(bc);
        set_bc.setProcessAll(false);
        set_bc.setSelectAllVisible(false);
        set_bc.setOnlyPickedCell(false);
        set_bc.setOnlyPickedCellAndNeighbours(false);
        set_bc.setStart(id_start);
        QString bc_name = GuiMainWindow::pointer()->getBC(bc).getName();
        if (bc_name == "unknown") {
          bc_name.setNum(bc);
          bc_name = "wall_" + bc_name.rightJustified(3, '0');
          BoundaryCondition sym_bc(bc_name, "wall", bc);
          GuiMainWindow::pointer()->setBC(bc, sym_bc);
        }
        set_bc();
        ++bc;
      }
    } while (!done);
  } else {
    if (0 <= mainWindow()->getPickedCell() && mainWindow()->getPickedCell() < GuiMainWindow::pointer()->getGrid()->GetNumberOfCells() ) {
      set_bc.setFeatureAngle(m_Ui.doubleSpinBoxFeatureAngle->value());
      set_bc.setNewBC(m_Ui.spinBoxBoundaryCode->value());

      set_bc.setProcessAll(m_ButtonGroup->button(1)->isChecked());
      set_bc.setSelectAllVisible(m_ButtonGroup->button(2)->isChecked());
      set_bc.setOnlyPickedCell(m_ButtonGroup->button(3)->isChecked());
      set_bc.setOnlyPickedCellAndNeighbours(m_ButtonGroup->button(4)->isChecked());

      cout << "GuiMainWindow::getPickedCell()=" << mainWindow()->getPickedCell() << endl;
      set_bc.setStart(mainWindow()->getPickedCell());
      set_bc();
    } else {
      EG_ERR_RETURN("Please select a cell first.");
    }
  }
}
コード例 #13
0
ファイル: tauwriter.cpp プロジェクト: Nasrollah/engrid
void TauWriter::operate()
{
  try {
    QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
    readOutputFileName(file_info.completeBaseName() + ".grid");
    if (isValid()) {
      QString file_name = getFileName();
      NcFile *nc_file = new NcFile(file_name.toAscii(), NcFile::Replace);
      if (!nc_file->is_valid()) {
        EG_ERR_RETURN("unable to open NetCFD file for writing");
      }

      // point coordinates
      size_t Np = m_Grid->GetNumberOfPoints();
      vector<double> x(Np),y(Np),z(Np);
      for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
        vec3_t xv;
        m_Grid->GetPoint(id_node, xv.data());
        x[id_node] = xv[0];
        y[id_node] = xv[1];
        z[id_node] = xv[2];
      }
      NcDim *no_of_points = nc_file->add_dim("no_of_points", Np);
      NcVar *points_xc = nc_file->add_var("points_xc", ncDouble, no_of_points);
      NcVar *points_yc = nc_file->add_var("points_yc", ncDouble, no_of_points);
      NcVar *points_zc = nc_file->add_var("points_zc", ncDouble, no_of_points);
      points_xc->put(&x[0],Np);
      points_yc->put(&y[0],Np);
      points_zc->put(&z[0],Np);

      // boundary faces
      size_t Nbe   = 0;;
      size_t Nquad = 0;
      size_t Ntri  = 0;
      for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
        if (isSurface(id_cell, m_Grid)) {
          ++Nbe;
          if (m_Grid->GetCellType(id_cell) == VTK_TRIANGLE) {
            ++Ntri;
          } else if (m_Grid->GetCellType(id_cell) == VTK_QUAD) {
            ++Nquad;
          } else {
            EG_ERR_RETURN("unsupported boundary element type encountered");
          }
        }
      }
      NcDim *no_of_surfaceelements = nc_file->add_dim("no_of_surfaceelements", Nbe);
      NcVar *boundarymarker_of_surfaces = nc_file->add_var("boundarymarker_of_surfaces", ncInt, no_of_surfaceelements);
      vector<int> bm(Nbe,0), tri(3*Ntri), quad(4*Nquad);
      int i_bm = 0;
      QSet<int> bc_set = getAllBoundaryCodes(m_Grid);
      QVector<int> bcs(bc_set.size());
      qCopy(bc_set.begin(), bc_set.end(), bcs.begin());
      EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
      if (Ntri) {
        NcDim *no_of_surfacetriangles = nc_file->add_dim("no_of_surfacetriangles", Ntri);
        NcDim *points_per_surfacetriangle = nc_file->add_dim("points_per_surfacetriangle", 3);
        NcVar *points_of_surfacetriangles = nc_file->add_var("points_of_surfacetriangles", ncInt, no_of_surfacetriangles, points_per_surfacetriangle);
        int i_tri = 0;
        for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
          if (isSurface(id_cell, m_Grid)) {
            if (m_Grid->GetCellType(id_cell) == VTK_TRIANGLE) {
              for (int i_bc = 0; i_bc < bcs.size(); ++i_bc) {
                if (bcs[i_bc] == cell_code->GetValue(id_cell)) {
                  bm[i_bm] = i_bc+1;
                  break;
                }
              }
              vtkIdType N_pts, *pts;
              m_Grid->GetCellPoints(id_cell, N_pts, pts);
              tri[i_tri + 0] = pts[0];
              tri[i_tri + 1] = pts[1];
              tri[i_tri + 2] = pts[2];
              ++i_bm;
              i_tri += 3;
            }
          }
        }
        points_of_surfacetriangles->put(&tri[0],Ntri,3);
      }
      if (Nquad) {
        NcDim *no_of_surfacequadrilaterals     = nc_file->add_dim("no_of_surfacequadrilaterals",Nquad);
        NcDim *points_per_surfacequadrilateral = nc_file->add_dim("points_per_surfacequadrilateral",4);
        NcVar *points_of_surfacequadrilaterals = nc_file->add_var("points_of_surfacequadrilaterals",ncInt, no_of_surfacequadrilaterals, points_per_surfacequadrilateral);
        int i_quad = 0;
        for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
          if (isSurface(id_cell, m_Grid)) {
            if (m_Grid->GetCellType(id_cell) == VTK_QUAD) {
              for (int i_bc = 0; i_bc < bcs.size(); ++i_bc) {
                if (bcs[i_bc] == cell_code->GetValue(id_cell)) {
                  bm[i_bm] = i_bc+1;
                  break;
                }
              }
              vtkIdType N_pts, *pts;
              m_Grid->GetCellPoints(id_cell, N_pts, pts);
              quad[i_quad + 0] = pts[0];
              quad[i_quad + 1] = pts[1];
              quad[i_quad + 2] = pts[2];
              quad[i_quad + 3] = pts[3];
              ++i_bm;
              i_quad += 4;
            }
          }
        }
        points_of_surfacequadrilaterals->put(&quad[0],Nquad,4);
      }
      boundarymarker_of_surfaces->put(&bm[0],Nbe);
      NcDim *no_of_markers = nc_file->add_dim("no_of_markers", bcs.size());


      int Ntet = 0;
      int Npri = 0;
      int Nhex = 0;
      int Npyr = 0;
      for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
        if (m_Grid->GetCellType(id_cell) == VTK_TETRA)      ++Ntet;
        if (m_Grid->GetCellType(id_cell) == VTK_PYRAMID)    ++Npyr;
        if (m_Grid->GetCellType(id_cell) == VTK_WEDGE)      ++Npri;
        if (m_Grid->GetCellType(id_cell) == VTK_HEXAHEDRON) ++Nhex;
      }

      vector<int> tet(Ntet*4),pyr(Npyr*5),pri(Npri*6),hex(Nhex*8);
      int i_tet = 0;
      int i_pyr = 0;
      int i_pri = 0;
      int i_hex = 0;
      if (Ntet) {
        NcDim *no_of_tetraeders = nc_file->add_dim("no_of_tetraeders",Ntet);
        NcDim *points_per_tetraeder = nc_file->add_dim("points_per_tetraeder",4);
        NcVar *points_of_tetraeders = nc_file->add_var("points_of_tetraeders",ncInt, no_of_tetraeders, points_per_tetraeder);
        for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
          if (m_Grid->GetCellType(id_cell) == VTK_TETRA) {
            vtkIdType *pts, N_pts;
            m_Grid->GetCellPoints(id_cell, N_pts, pts);
            tet[i_tet + 0] = pts[0];
            tet[i_tet + 1] = pts[1];
            tet[i_tet + 2] = pts[2];
            tet[i_tet + 3] = pts[3];
            i_tet += 4;
          }
        }
        points_of_tetraeders->put(&tet[0],Ntet,4);
      }
      if (Npyr) {
        NcDim *no_of_pyramids = nc_file->add_dim("no_of_pyramids",Npyr);
        NcDim *points_per_pyramid = nc_file->add_dim("points_per_pyramid",5);
        NcVar *points_of_pyramids = nc_file->add_var("points_of_pyramids",ncInt, no_of_pyramids, points_per_pyramid);
        for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
          if (m_Grid->GetCellType(id_cell) == VTK_PYRAMID) {
            vtkIdType *pts, N_pts;
            m_Grid->GetCellPoints(id_cell, N_pts, pts);
            pyr[i_pyr + 0] = pts[0];
            pyr[i_pyr + 1] = pts[1];
            pyr[i_pyr + 2] = pts[2];
            pyr[i_pyr + 3] = pts[3];
            pyr[i_pyr + 4] = pts[4];
            i_pyr += 5;
          }
        }
        points_of_pyramids->put(&pyr[0],Npyr,5);
      }
      if (Npri) {
        NcDim *no_of_prisms = nc_file->add_dim("no_of_prisms",Npri);
        NcDim *points_per_prism = nc_file->add_dim("points_per_prism",6);
        NcVar *points_of_prisms = nc_file->add_var("points_of_prisms",ncInt, no_of_prisms,  points_per_prism);
        for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
          if (m_Grid->GetCellType(id_cell) == VTK_WEDGE) {
            vtkIdType *pts, N_pts;
            m_Grid->GetCellPoints(id_cell, N_pts, pts);
            pri[i_pri + 0] = pts[0];
            pri[i_pri + 1] = pts[2];
            pri[i_pri + 2] = pts[1];
            pri[i_pri + 3] = pts[3];
            pri[i_pri + 4] = pts[5];
            pri[i_pri + 5] = pts[4];
            i_pri += 6;
          }
        }
        points_of_prisms->put(&pri[0],Npri,6);
      }
      if (Nhex) {
        NcDim *no_of_hexaeders = nc_file->add_dim("no_of_hexaeders",Nhex);
        NcDim *points_per_hexaeder = nc_file->add_dim("points_per_hexaeder",8);
        NcVar *points_of_hexaeders = nc_file->add_var("points_of_hexaeders",ncInt, no_of_hexaeders, points_per_hexaeder);
        for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
          if (m_Grid->GetCellType(id_cell) == VTK_HEXAHEDRON) {
            vtkIdType *pts, N_pts;
            m_Grid->GetCellPoints(id_cell, N_pts, pts);
            hex[i_hex + 0] = pts[4];
            hex[i_hex + 1] = pts[7];
            hex[i_hex + 2] = pts[6];
            hex[i_hex + 3] = pts[5];
            hex[i_hex + 4] = pts[0];
            hex[i_hex + 5] = pts[3];
            hex[i_hex + 6] = pts[2];
            hex[i_hex + 7] = pts[1];
            i_hex += 8;
          }
        }
        points_of_hexaeders->put(&hex[0],Nhex,8);
      }

      delete nc_file;
    }
  } catch (Error err) {
    err.display();
  }
}