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); }
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 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); }
void CreateHexCore::transferOctreeGrid() { QVector<bool> delete_node(m_Octree.getNumNodes(), false); QVector<bool> delete_cell(m_Octree.getNumCells(), false); for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) { vec3_t x; m_Grid->GetPoint(id_node, x.data()); int i_cell = m_Octree.findCell(x); if (m_Octree.hasChildren(i_cell)) { EG_BUG; } delete_cell[i_cell] = true; for (int i = 0; i < 8; ++i) { delete_node[m_Octree.getNode(i_cell, i)] = true; } } for (int layer = 0; layer < m_NumBreakOutLayers; ++layer) { for (int i = 0; i < m_Octree.getNumCells(); ++i) { if (delete_cell[i] && !m_Octree.hasChildren(i)) { for (int j = 0; j < 8; ++j) { delete_node[m_Octree.getNode(i,j)] = true; } } } for (int i = 0; i < m_Octree.getNumCells(); ++i) { if (!m_Octree.hasChildren(i)) { for (int j = 0; j < 8; ++j) { if (delete_node[m_Octree.getNode(i,j)]) { delete_cell[i] = true; break; } } } } } EG_VTKSP(vtkUnstructuredGrid, otgrid); m_Octree.toVtkGridPolyhedral(otgrid, true); //m_Octree.toVtkGridConforming(otgrid, true); MeshPartition add_part(otgrid); QList<vtkIdType> add_cells; for (vtkIdType id_cell = 0; id_cell < otgrid->GetNumberOfCells(); ++id_cell) { int i_cell = m_Octree.findCell(cellCentre(otgrid, id_cell)); if (!delete_cell[i_cell]) { add_cells.append(id_cell); } } add_part.setCells(add_cells); m_Part.addPartition(add_part); m_Part.setAllCells(); deleteOutside(m_Grid); }
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); }
void FaceFinder::setGrid(vtkUnstructuredGrid *grid) { m_Grid = grid; m_Triangles.resize(m_Grid->GetNumberOfCells()); m_Centres.resize(m_Grid->GetNumberOfCells()); for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { if (m_Grid->GetCellType(id_cell) != VTK_TRIANGLE) { EG_BUG; } m_Triangles[id_cell] = Triangle(m_Grid, id_cell); m_Centres[id_cell] = cellCentre(m_Grid, id_cell); } { double bounds[6]; m_Grid->GetBounds(bounds); vec3_t x1(bounds[0], bounds[2], bounds[4]); vec3_t x2(bounds[1], bounds[3], bounds[5]); vec3_t xc = 0.5*(x1 + x2); vec3_t Dx = x2 - xc; double dx_max = max(Dx[0], max(Dx[1], Dx[2])); Dx = vec3_t(dx_max, dx_max, dx_max); x1 = xc - 2*Dx; x2 = xc + 2*Dx; m_Octree.setBounds(x1, x2); if (m_UseImprovedFaceSearch) { m_MinSize = 0.005*Dx[0]; } else { m_MinSize = 0.0001*Dx[0]; } } m_Faces.resize(1); for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) { m_Faces[0].append(id_cell); } if (m_UseImprovedFaceSearch) { m_CritLengthOctreeCell.fill(EG_LARGE_REAL, 1); foreach (vtkIdType id_cell, m_Faces[0]) { m_CritLengthOctreeCell[0] = min(m_CritLengthOctreeCell[0], calcCritLength(id_cell)); } calcCritLengthForAllNodes(); } else {
void renderGame(GameState* game) { glClear(GL_COLOR_BUFFER_BIT); dge::Vector2 cellSize(grid_size, grid_size); dge::Vector4 white(1.0f, 1.0f, 1.0f, 1.0f); dge::Vector4 maroon = dge::Vector4 (0.5f,0.f,0.f,1.f); dge::Vector4 grey(0.4f, 0.4f, 0.4f, 1.0f); for(int y=0; y<game->currentLevel->height; ++y) { for(int x=0; x<game->currentLevel->width; ++x) { MapObject* mapObj = game->currentLevel->map[y][x]; if(!mapObj) continue; dge::Vector2 cellCentre(x*grid_size, y*grid_size); switch(mapObj->type) { case MapObjectType::CONVEYER: { Conveyer* conv = (Conveyer*)mapObj; dge::renderQuad(game->camera, cellCentre, cellSize, 0.0f, white); const char* dirChar = ""; switch(conv->dir) { case Direction::LEFT: dirChar = "<"; break; case Direction::RIGHT: dirChar = ">"; break; case Direction::UP: dirChar = "^"; break; case Direction::DOWN: dirChar = "v"; break; default: dirChar = "x"; } dge::renderString(game->camera, dirChar, 1, cellCentre, grid_size/2.0f, white); } break; case MapObjectType::BIN: { Bin* bin = (Bin*)mapObj; dge::renderQuad(game->camera, cellCentre, cellSize, 0.0f, white); dge::renderQuad(game->camera, cellCentre, cellSize*0.8f, 0.0f, categoryColours[bin->category]); } break; case MapObjectType::WALL: { Wall* wall = (Wall*)mapObj; dge::Vector2 quadLoc(cellCentre); dge::Vector2 quadSize; switch (wall->dir) { case Direction::UP: { quadLoc += dge::Vector2(0.0f,0.3f*grid_size); quadSize = dge::Vector2(0.6f, 0.2f); } break; case Direction::DOWN: { quadLoc += dge::Vector2(0.0f,-0.3f*grid_size); quadSize = dge::Vector2(0.6f, 0.2f); } break; case Direction::LEFT: { quadLoc += dge::Vector2(-0.3f*grid_size,0.0f); quadSize = dge::Vector2(0.2f, 0.6f); } break; case Direction::RIGHT: { quadLoc += dge::Vector2(0.3f*grid_size,0.0f); quadSize = dge::Vector2(0.2f, 0.6f); } break; default: { } break; } dge::renderQuad(game->camera, quadLoc, cellSize*quadSize, 0.0f, maroon); } break; case MapObjectType::BUMPER: { Bumper* bumper = (Bumper*)mapObj; dge::renderQuad(game->camera, cellCentre, cellSize*0.8f, 0.0f, grey); } break; } } } dge::Vector4 red(1.0f, 0.0f, 0.0f, 1.0f); for(int bagIndex=0; bagIndex<game->bagList.size(); ++bagIndex) { Bag bag = *game->bagList[bagIndex]; dge::Vector2 position = bag.position * grid_size; dge::Vector2 size = bag.size * grid_size; dge::renderQuad(game->camera, position, size, 0.0f, red); dge::renderQuad(game->camera, position, size, 0.0f, categoryColours[bag.category]); } std::string scoreString = "Score: "+std::to_string((int)game->score); dge::renderString(game->camera,scoreString.c_str(),scoreString.size(),dge::Vector2(370,400),20,dge::Vector4(0.8,0.8,0.8,0.8)); /* ImVec2 windowLoc(50.0f, 50.0f); ImVec2 windowSize(200.0f, 200.f); int UIFlags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings; ImGui::Begin("MainMenu", 0, UIFlags); ImGui::SetWindowPos(windowLoc); ImGui::SetWindowSize(windowSize); ImGui::Text("Lost Luggage Clone"); if(ImGui::Button("Start", ImVec2(100, 50))) { } ImGui::End(); */ }