コード例 #1
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();
  };
};
コード例 #2
0
ファイル: su2writer.cpp プロジェクト: danbarrynz/engrid
void Su2Writer::writeBoundaries()
{
  QTextStream f(m_File);
  f << "%\n";
  f << "% Boundary elements\n";
  f << "%\n";
  QSet<int> bcs = GuiMainWindow::pointer()->getAllBoundaryCodes();
  f << "NMARK= " << bcs.size() << "\n";
  EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
  foreach (int bc, bcs) {
    BoundaryCondition BC = GuiMainWindow::pointer()->getBC(bc);
    f << "MARKER_TAG= " << BC.getName() << "\n";
    QList<vtkIdType> faces;
    for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
      if (isSurface(id_cell, m_Grid)) {
        if (cell_code->GetValue(id_cell) == bc) {
          faces.append(id_cell);
        }
      }
    }
    f << "MARKER_ELEMS= " << faces.size() << "\n";
    foreach (vtkIdType id_cell, faces) {
      f << m_Grid->GetCellType(id_cell);
      vtkIdType N_pts, *pts;
      m_Grid->GetCellPoints(id_cell, N_pts, pts);
      for (int j = 0; j < N_pts; ++j) {
        f << " " << pts[j];
      }
      f << "\n";
    }
コード例 #3
0
ファイル: meshpartition.cpp プロジェクト: Haider-BA/engrid
void MeshPartition::setVolume(QString volume_name)
{
  m_Grid = GuiMainWindow::pointer()->getGrid();
  resetOrientation(m_Grid);
  VolumeDefinition V = GuiMainWindow::pointer()->getVol(volume_name);
  QList<vtkIdType> cls;
  EG_VTKDCC(vtkIntArray, cell_code,   m_Grid, "cell_code");
  EG_VTKDCC(vtkIntArray, cell_orgdir, m_Grid, "cell_orgdir");
  EG_VTKDCC(vtkIntArray, cell_curdir, m_Grid, "cell_curdir");
  EG_VTKDCC(vtkIntArray, cell_voldir, m_Grid, "cell_voldir");
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    if (isSurface(id_cell, m_Grid)) {
      int bc = cell_code->GetValue(id_cell);
      cell_voldir->SetValue(id_cell, 0);
      if (V.getSign(bc) != 0) {
        cls.append(id_cell);
        if (V.getSign(bc) == -1) {
          cell_voldir->SetValue(id_cell, 1);
        }
      }
    } else {
      if (cell_code->GetValue(id_cell) == V.getVC()) {
        cls.append(id_cell);
      }
    }
  }
  setCells(cls);
}
コード例 #4
0
void CreateHexCore::deleteOutside(vtkUnstructuredGrid *grid)
{
  MeshPartition part(grid, true);
  QVector<bool> is_inside(grid->GetNumberOfCells(), false);
  vtkIdType id_start = -1;
  double dmin = 1e99;
  for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
    if (isVolume(id_cell, grid)) {
      vec3_t x = cellCentre(grid, id_cell);
      double d = (x - m_Xi).abs();
      if (d < dmin) {
        dmin = d;
        id_start = id_cell;
      }
    }
  }
  if (id_start == -1) {
    EG_BUG;
  }
  is_inside[id_start] = true;
  bool added = true;
  while (added) {
    added = false;
    for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
      if (is_inside[id_cell]) {
        for (int j = 0; j < part.c2cGSize(id_cell); ++j) {
          vtkIdType id_neigh = part.c2cGG(id_cell, j);
          if (id_neigh >= 0) {
            if (!is_inside[id_neigh]) {
              is_inside[id_neigh] = true;
              added = true;
            }
          }
        }
      }
    }
  }
  int N = 0;
  for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
    if (isSurface(id_cell, grid)) {
      is_inside[id_cell] = true;
    }
    if (is_inside[id_cell]) {
      ++N;
    }
  }
  QVector<vtkIdType> cls(N);
  N = 0;
  for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
    if (is_inside[id_cell]) {
      cls[N] = id_cell;
      ++N;
    }
  }
  EG_VTKSP(vtkUnstructuredGrid, return_grid);
  makeCopy(grid, return_grid, cls);
  makeCopy(return_grid, grid);
}
コード例 #5
0
void BoundaryLayerOperation::readSettings()
{
  EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
  QString buffer = GuiMainWindow::pointer()->getXmlSection("engrid/blayer/settings");
  if(!buffer.isEmpty()) {
    QTextStream in(&buffer, QIODevice::ReadOnly);
    int num_bcs;
    in >> num_bcs;
    QVector<bool> use_bc(num_bcs);
    int N = 0;
    for (int i = 0; i < num_bcs; ++i) {
      int state;
      in >> state;
      use_bc[i] = bool(state);
      if (use_bc[i]) {
        ++N;
      }
    }
    m_BoundaryLayerCodes.resize(N);
    QVector<int> bcs;
    mainWindow()->getAllBoundaryCodes(bcs);
    int j = 0;
    for (int i = 0; i < bcs.size(); ++i) {
      if (use_bc[i]) {
        m_BoundaryLayerCodes[j++] = bcs[i];
      }
    }
    m_LayerAdjacentBoundaryCodes.clear();
    for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
      if (isSurface(id_cell, m_Grid)) {
        if (m_BoundaryLayerCodes.contains(cell_code->GetValue(id_cell))) {
          for (int i = 0; i < m_Part.c2cGSize(id_cell); ++i) {
            vtkIdType id_neigh = m_Part.c2cGG(id_cell, i);
            if (!m_BoundaryLayerCodes.contains(cell_code->GetValue(id_neigh))) {
              m_LayerAdjacentBoundaryCodes.insert(cell_code->GetValue(id_neigh));
            }
          }
        }
      }
    }
    in >> m_FeatureAngle;
    m_FeatureAngle = deg2rad(m_FeatureAngle);
    in >> m_StretchingRatio;
    in >> m_FarfieldRatio;
    in >> m_NumBoundaryLayerVectorRelaxations;
    in >> m_NumBoundaryLayerHeightRelaxations;
    in >> m_FaceSizeLowerLimit;
    in >> m_FaceSizeUpperLimit;
    in >> m_FaceAngleLimit;
    m_FaceAngleLimit = deg2rad(m_FaceAngleLimit);
    in >> m_MaxHeightInGaps;
    in >> m_RadarAngle;
    int use_grouping;
    in >> use_grouping;
    m_UseGrouping = use_grouping;
    in >> m_GroupingAngle;
    m_GroupingAngle = deg2rad(m_GroupingAngle);
  }
コード例 #6
0
ファイル: Region.cpp プロジェクト: phonexhsu/VizBench
void
Region::initSound() {
	if ( isSurface() ) {
		std::string snd = SoundBank[0][0][0];
		NosuchAssert(snd!="");
		params.sound = snd;
		UpdateSound();
	}
}
コード例 #7
0
ファイル: Region.cpp プロジェクト: phonexhsu/VizBench
void
Region::init_loop()
{
	if ( isSurface() ) {
		int loopid = LOOPID_BASE + id;
		_loop = new NosuchLoop(palette->paletteHost(),loopid,params.looplength,params.loopfade);
		palette->paletteHost()->AddLoop(_loop);
	} else {
		_loop = NULL;
	}
}
コード例 #8
0
ファイル: meshpartition.cpp プロジェクト: Haider-BA/engrid
void MeshPartition::setOriginalOrientation()
{
  EG_VTKDCC(vtkIntArray, cell_curdir, m_Grid, "cell_curdir");
  EG_VTKDCC(vtkIntArray, cell_orgdir, m_Grid, "cell_orgdir");
  foreach (vtkIdType id_cell, m_Cells) {
    if (isSurface(id_cell, m_Grid)) {
      if (cell_curdir->GetValue(id_cell) != cell_orgdir->GetValue(id_cell)) {
        reorientateFace(m_Grid, id_cell);
      }
    }
  }
}
コード例 #9
0
void GuiCreateHexIbMesh::before()
{
  vec3_t x_centre(0,0,0);
  double A = 0;
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    if (isSurface(id_cell, m_Grid)) {
      double A_cell = GeometryTools::cellVA(m_Grid, id_cell);
      x_centre += A_cell*cellCentre(m_Grid, id_cell);
      A += A_cell;
    }
  }
  x_centre *= 1.0/A;
  setVector(x_centre, m_Ui.m_LineEditCentre);
}
コード例 #10
0
ファイル: createhexcore.cpp プロジェクト: ttjj/engrid
void CreateHexCore::refineOctree()
{
  m_Octree.resetRefineMarks();

  // begin DEBUG
  /*
  m_Octree.markToRefine(0);
  m_Octree.refineAll();
  m_Octree.markToRefine(3);
  m_Octree.markToRefine(8);
  m_Octree.refineAll();
  return;
  */
  // end DEBUG

  EG_VTKDCN(vtkDoubleArray, cl, m_Grid, "node_meshdensity_desired");
  do {
    for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
      vtkIdType id_surf = -1;
      for (int i = 0; i < m_Part.n2cGSize(id_node); ++i) {
        vtkIdType id_cell = m_Part.n2cGG(id_node, i);
        if (isSurface(id_cell, m_Grid)) {
          id_surf = id_node;
          break;
        } else {
          vtkIdType cell_type = m_Grid->GetCellType(id_cell);
          if (cell_type == VTK_WEDGE) {
            vtkIdType N_pts, *pts;
            m_Grid->GetCellPoints(id_cell, N_pts, pts);
            if      (pts[3] == id_node) id_surf = pts[0];
            else if (pts[4] == id_node) id_surf = pts[1];
            else if (pts[5] == id_node) id_surf = pts[2];
          }
        }
      }
      if (id_surf != -1) {
        vec3_t x;
        m_Grid->GetPoint(id_node, x.data());
        int i_otcell = m_Octree.findCell(x);
        double h = m_Octree.getDx(i_otcell);
        h = max(h, m_Octree.getDy(i_otcell));
        h = max(h, m_Octree.getDz(i_otcell));
        if (h > cl->GetValue(id_surf)) {
          m_Octree.markToRefine(i_otcell);
        }
      }
    }
  } while (m_Octree.refineAll());
}
コード例 #11
0
ファイル: drnumwriter.cpp プロジェクト: danbarrynz/engrid
QString DrNumWriter::boundaryCode(vtkIdType id_cell, int i)
{
  EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
  QString bcode = "0";
  vtkIdType id_neigh = m_Part.c2cGG(id_cell, i);
  if (id_neigh != -1) {
    if (m_CellToCartPatch[id_neigh] == -1) {
      if (isSurface(id_neigh, m_Grid)) {
        BoundaryCondition bc = GuiMainWindow::pointer()->getBC(cell_code->GetValue(id_neigh));
        if (bc.getName() != "unknown") {
          bcode = bc.getType();
        }
      }
    }
  }
  return bcode;
}
コード例 #12
0
void UpdateDesiredMeshDensity::computeExistingLengths()
{
  QSet<int> all_bcs = GuiMainWindow::pointer()->getAllBoundaryCodes();
  QSet<int> fixed_bcs = all_bcs - m_BoundaryCodes;
  QVector<double> edge_length(m_Grid->GetNumberOfPoints(), 1e99);
  QVector<int> edge_count(m_Grid->GetNumberOfPoints(), 0);
  m_Fixed.fill(false, m_Grid->GetNumberOfPoints());
  EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
  for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
    if (isSurface(id_cell, m_Grid)) {
      if (fixed_bcs.contains(cell_code->GetValue(id_cell))) {
        vtkIdType N_pts, *pts;
        m_Grid->GetCellPoints(id_cell, N_pts, pts);
        QVector<vec3_t> x(N_pts);
        for (int i = 0; i < N_pts; ++i) {
          m_Grid->GetPoint(pts[i], x[i].data());
          m_Fixed[pts[i]] = true;
        }
        for (int i = 0; i < N_pts; ++i) {
          int j = i + 1;
          if (j >= N_pts) {
            j = 0;
          }
          double L = (x[i] - x[j]).abs();
          edge_length[pts[i]] = min(edge_length[pts[i]], L);
          edge_length[pts[j]] = min(edge_length[pts[j]], L);
          ++edge_count[pts[i]];
          ++edge_count[pts[j]];
        }
      }
    }
  }
  EG_VTKDCN(vtkDoubleArray, characteristic_length_desired,   m_Grid, "node_meshdensity_desired");
  for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
    if (edge_count[id_node] > 0) {
      if (edge_length[id_node] > 1e98) {
        EG_BUG;
      }
      characteristic_length_desired->SetValue(id_node, edge_length[id_node]);
    }
  }
}
コード例 #13
0
ファイル: Region.cpp プロジェクト: phonexhsu/VizBench
void Region::advanceTo(int tm) {
	
	spritelist->advanceTo(tm);
#if 0
	spritelist_lock_write();

	for ( std::list<Sprite*>::iterator i = sprites.begin(); i!=sprites.end(); ) {
		Sprite* s = *i;
		NosuchAssert(s);
		s->advanceTo(tm);
		if ( s->state.killme ) {
			i = sprites.erase(i);
			// NosuchDebug("Should be deleting Sprite s=%d",(int)s);
			delete s;
		} else {
			i++;
		}
	}

	spritelist_unlock();
#endif
	
	if ( last_tm > 0 && isSurface() ) {
		int dt = leftover_tm + tm - last_tm;
		if ( dt > fire_period ) {
			// NosuchDebug("Region %d calling behave->periodicFire now=%d",this->id,Palette::now);
			if ( Palette::selector_check && (_graphicBehaviour->isSelectorDown() || _musicBehaviour->isSelectorDown()) ) {
				NosuchDebug(2,"NOT calling behaviour->advanceTo because Selector is down");
			} else {
				_graphicBehaviour->advanceTo(tm);
				_musicBehaviour->advanceTo(tm);
			}
			dt -= fire_period;
		}
		leftover_tm = dt % fire_period;
	}
	last_tm = tm;
}
コード例 #14
0
ファイル: stitchholes.cpp プロジェクト: Haider-BA/engrid
QList<vtkIdType> StitchHoles::getNextHole()
{
  QList<vtkIdType> loop_nodes;
  EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");

  // find the first two nodes of the hole
  //
  vtkIdType id_node1 = -1;
  vtkIdType id_node2 = -1;
  EG_FORALL_CELLS (id_cell, m_Grid) {
    if (isSurface(id_cell, m_Grid) && cell_code->GetValue(id_cell) == m_Bc) {
      for (int i = 0; i < m_Part.c2cGSize(id_cell); ++i) {
        if (m_Part.c2cGG(id_cell, i) == -1) {
          QList<vtkIdType> pts;
          getPointsOfCell(m_Grid, id_cell, pts);
          pts << pts.first();
          id_node1 = pts[i+1];
          id_node2 = pts[i];
          break;
        }
      }
      if (id_node1 != -1) {
        break;
      }
    }
  }
  if (id_node1 == -1) {
    return loop_nodes;
  }

  // create node loop around hole
  //
  vtkIdType id_start = id_node1;
  loop_nodes << id_node1;
  vec3_t x0;
  m_Grid->GetPoint(id_node1, x0.data());
  while (id_node2 != id_start && loop_nodes.size() < m_Grid->GetNumberOfPoints()) {
    loop_nodes << id_node2;
    vec3_t x;
    m_Grid->GetPoint(id_node2, x.data());
    x0 += x;
    bool found = false;
    for (int i = 0; i < m_Part.n2nGSize(id_node2); ++i) {
      vtkIdType id_node3 = m_Part.n2nGG(id_node2, i);
      if (id_node3 != id_node1) {
        QList<vtkIdType> edge_faces;
        m_Part.getEdgeFaces(id_node2, id_node3, edge_faces);
        if (edge_faces.size() == 1) {
          found = true;
          id_node1 = id_node2;
          id_node2 = id_node3;
          break;
        }
      }
    }
    if (!found) {
      loop_nodes.clear();
      return loop_nodes;
    }
  }
  x0 *= 1.0/loop_nodes.size();
  m_Cad->snap(x0);
  vec3_t n = m_Cad->getLastNormal();
  setOrigin(x0);
  setNormal(n);
  setupTransformation();
  return loop_nodes;
}
コード例 #15
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();
  }
}
コード例 #16
0
ファイル: fillplane.cpp プロジェクト: Nasrollah/engrid
void FillPlane::createEdgesOnPlane(vtkUnstructuredGrid *edge_grid)
{
  vtkIdType num_edges = 0;
  vtkIdType num_nodes = 0;

  QVector<bool> is_edge_node(m_Grid->GetNumberOfPoints(), false);
  for (vtkIdType id_face = 0; id_face < m_Grid->GetNumberOfCells(); ++id_face) {
    vtkIdType num_pts, *pts;
    if (isSurface(id_face, m_Grid)) {
      m_Grid->GetCellPoints(id_face, num_pts, pts);
      for (int i = 0; i < num_pts; ++i) {
        if (m_Part.c2cGG(id_face, i) == -1) {
          vtkIdType id_node1 = pts[i];
          vtkIdType id_node2 = pts[0];
          if (i < num_pts - 1) {
            id_node2 = pts[i + 1];
          }
          vec3_t x1, x2;
          m_Grid->GetPoint(id_node1, x1.data());
          m_Grid->GetPoint(id_node2, x2.data());
          if (isWithinTolerance(x1) && isWithinTolerance(x2)) {
            is_edge_node[id_node1] = true;
            is_edge_node[id_node2] = true;
            ++num_edges;
          }
        }
      }
    }
  }


  QVector<vtkIdType> node_map(m_Grid->GetNumberOfPoints(), -1);
  for (vtkIdType id_node1 = 0; id_node1 < m_Grid->GetNumberOfPoints(); ++id_node1) {
    if (is_edge_node[id_node1]) {
      node_map[id_node1] = num_nodes;
      ++num_nodes;
    }
  }
  m_NodeMap.resize(num_nodes);
  allocateGrid(edge_grid, 2*num_edges, num_nodes, false);
  for (vtkIdType id_node1 = 0; id_node1 < m_Grid->GetNumberOfPoints(); ++id_node1) {
    if (node_map[id_node1] != -1) {
      m_NodeMap[node_map[id_node1]] = id_node1;
      vec3_t x;
      m_Grid->GetPoint(id_node1, x.data());
      edge_grid->GetPoints()->SetPoint(node_map[id_node1], x.data());
    }
  }


  for (vtkIdType id_face = 0; id_face < m_Grid->GetNumberOfCells(); ++id_face) {
    vtkIdType num_pts, *pts;
    if (isSurface(id_face, m_Grid)) {
      m_Grid->GetCellPoints(id_face, num_pts, pts);
      for (int i = 0; i < num_pts; ++i) {
        if (m_Part.c2cGG(id_face, i) == -1) {
          vtkIdType id_node1 = pts[i];
          vtkIdType id_node2 = pts[0];
          if (i < num_pts - 1) {
            id_node2 = pts[i + 1];
          }
          if (is_edge_node[id_node1] && is_edge_node[id_node2]) {
            vtkIdType pts[2];
            pts[0] = node_map[id_node1];
            pts[1] = node_map[id_node2];
            edge_grid->InsertNextCell(VTK_LINE, 2, pts);
          }
        }
      }
    }
  }
}
コード例 #17
0
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);
  }
コード例 #18
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());
  }