Ejemplo n.º 1
0
void Planet::generatePlanetSprite() {
	m_planet_image.create(m_radius * 2, m_radius * 2, sf::Color(0, 0, 0, 0));

	for (int i = 0; i < m_radius * 2; ++i) {
		for (int j = 0; j < m_radius * 2; ++j) {
			float x = (i - m_radius);
			float y = (j - m_radius);
			if (distance(sf::Vector2f(x, y), sf::Vector2f(0, 0)) <= m_radius) {
				sf::Vector2f planePos = toPlane(sf::Vector2f(x, y), m_radius);

				float height = heightMap.GetValue(planePos.x / 1, planePos.y / 1);
				m_test_image.setPixel(planePos.x, planePos.y, sf::Color(255, 255, 255, 255));
				m_planet_image.setPixel(i, j, colorByHeight(height));
			}
		}
	}

	m_planet_texture.loadFromImage(m_planet_image, sf::IntRect(0, 0, (int)(m_radius * 2), (int)(m_radius * 2)));
	m_planet_sprite.setTexture(m_planet_texture);
}
Ejemplo n.º 2
0
void StitchHoles::stitchHole(QList<vtkIdType> loop_nodes)
{
  EG_VTKSP(vtkPolyData, edge_pdata);
  EG_VTKSP(vtkPoints, points);
  EG_VTKSP(vtkCellArray, polys);
  for (int i = 0; i < loop_nodes.size(); ++i) {
    vec3_t x;
    m_Grid->GetPoint(loop_nodes[i], x.data());
    x = toPlane(x);
    points->InsertNextPoint(x.data());
  }
  EG_VTKSP(vtkIdList, pts);
  pts->SetNumberOfIds(loop_nodes.size());
  for (vtkIdType i = 0; i < pts->GetNumberOfIds(); ++i) {
    pts->SetId(i, i);
  }
  polys->InsertNextCell(pts);
  edge_pdata->SetPoints(points);
  edge_pdata->SetPolys(polys);
  EG_VTKSP(vtkUnstructuredGrid, tri_grid);
  /*
  {
    QString name = GuiMainWindow::pointer()->getCwd() + "/input.vtk";
    EG_VTKSP(vtkPolyDataWriter, vtk);
    vtk->SetFileName(qPrintable(name));
    vtk->SetInputData(edge_pdata);
    vtk->Write();
  }
  */
  triangulate(edge_pdata, tri_grid, m_Bc);
  //writeGrid(tri_grid, "tri");
  gridFromPlane(tri_grid);

  EG_FORALL_CELLS(id_cell, tri_grid) {
    if (cellNormal(tri_grid, id_cell)*m_N < 0) {
      vtkIdType num_pts, *pts;
      tri_grid->GetCellPoints(id_cell, num_pts, pts);
      QVector<vtkIdType> nodes(num_pts);
      for (vtkIdType j = 0; j < num_pts; ++j) {
        nodes[j] = pts[j];
      }
      for (vtkIdType j = 0; j < num_pts; ++j) {
        pts[num_pts - j - 1] = nodes[j];
      }
    }
  }

  MeshPartition tri_part(tri_grid, true);
  /*
  int n1 = tri_grid->GetNumberOfPoints();
  int n2 = tri_grid->GetNumberOfCells();
  writeGrid(m_Grid, "before");
  */
  m_Part.addPartition(tri_part);
  /*
  int N1 = m_Grid->GetNumberOfPoints();
  int N2 = m_Grid->GetNumberOfCells();
  writeGrid(m_Grid, "after");
  */

  DeleteStrayNodes del_stray;
  del_stray.setGrid(m_Grid);
  del_stray.setAllCells();
  del_stray();
}