MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->actionGenerate_Polygons->setDisabled(true);
    ui->actionAddPolygons->setDisabled(true);
    ui->actionPolygons_List->setDisabled(true);
    ui->actionSave->setDisabled(true);

    this->setWindowTitle("2D Polygon Packing Problem");

    connect(ui->actionGenerate_Polygons, SIGNAL(triggered()), this, SLOT(generatePolygons()));
    connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(neo()));
    connect(ui->actionAddPolygons, SIGNAL(triggered()), this, SLOT(addPolygons()));
    connect(ui->actionPolygons_List, SIGNAL(triggered()), this, SLOT(polygonsList()));
    connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(save()));

    stripHeight = SCENE_HEIGHT;

    settings = new Settings(this);
    this->setCentralWidget(settings);
    this->resize(800, 600);
}
예제 #2
0
파일: layer.cpp 프로젝트: keesj/repsnapper
int Layer::addShape(const Matrix4d &T, const Shape &shape, double z,
		    double &max_gradient, double max_supportangle)
{
  double hackedZ = z;
  bool polys_ok = false;
  vector<Poly> polys;
  int num_polys=-1;
  // try to slice until polygons can be made, otherwise hack z
  while (!polys_ok && hackedZ < z+thickness) {
    polys.clear();
    polys_ok = shape.getPolygonsAtZ(T, hackedZ,  // slice shape at hackedZ
				    polys, max_gradient,
				    toSupportPolygons, max_supportangle,
				    thickness);
    hackedZ += thickness/10;
    if (polys_ok) {
      num_polys = polys.size();
      addPolygons(polys);
    } else {
      num_polys=-1;
      cerr << "hacked Z " << z << " -> " << hackedZ << endl;
    }
  }
  cleanupPolygons();
  return num_polys;
}
예제 #3
0
  void addRectangle(Geometry * geom, Vector2 const& pos, Vector2 const& size, Color const& color)
  {
    Vector2 vertices[] = {
      Vector2(pos.x, pos.y),
      Vector2(pos.x + size.x, pos.y),
      Vector2(pos.x + size.x, pos.y + size.y),
      Vector2(pos.x, pos.y + size.y)
    };

    addPolygons(geom, vertices, 4, 0.0f, color);
  }
예제 #4
0
int Layer::addShape(Matrix4d T, const Shape shape, double z, 
		     double &max_gradient)
{
  double hackedZ = z;
  bool polys_ok = false;
  vector<Poly> polys;
  int num_polys=-1;
  // try to slice all objects until polygons can be made, otherwise hack z
  while (!polys_ok && hackedZ < z+thickness) {
    polys.clear();
    polys_ok=shape.getPolygonsAtZ(T, hackedZ,  // slice shape at hackedZ
				  polys, max_gradient);
    if (polys_ok) {
      num_polys = polys.size();
      addPolygons(polys);
    } else {
      num_polys=-1;
      cerr << "hacked Z=" << hackedZ << endl;
    }
    hackedZ += thickness/10;
  }
  return num_polys;
}
예제 #5
0
//-----------------------------------------------------------------------------
// create vertex and index buffers
void Planet::createBuffers()
{
  int vertexSize = m_samples+1;
  m_outsideShader = mgVertex::loadShader("litTexture");
  m_outsideVertexes = mgVertex::newBuffer(6*vertexSize*vertexSize);
  m_outsideIndexes = mgDisplay->newIndexBuffer(6*6*m_samples*m_samples);

  m_insideShader = mgVertex::loadShader("cave");
  m_insideVertexes = mgVertex::newBuffer(6*vertexSize*vertexSize);
  m_insideIndexes = mgDisplay->newIndexBuffer(6*6*m_samples*m_samples);

  m_lavaShader = mgVertex::loadShader("unlitTexture");
  m_lavaVertexes = mgVertex::newBuffer(6*vertexSize*vertexSize);
  m_lavaIndexes = mgDisplay->newIndexBuffer(6*6*m_samples*m_samples);

  // generate the depth map.  extend into neighbors so we can compute normals
  int depthSize = m_samples+3;  // -1 to size+1
  double* outsideHts = new double[depthSize*depthSize];
  double* insideHts = new double[depthSize*depthSize];
  mgPoint3* points = new mgPoint3[depthSize*depthSize];
  BOOL* flags = new BOOL[depthSize*depthSize];
  double px, py, pz;

  // ymin outside
  py = 0.0;
  for (int x = -1; x <= m_samples+1; x++)
  {
    px = x/(double) m_samples;
    for (int z = -1; z <= m_samples+1; z++)
    {
      pz = z/(double) m_samples;

      mgPoint3 pt(px-0.5, py-0.5, pz-0.5);
      pt.normalize();

      double inside = insideHt(pt);
      double outside = outsideHt(pt);

      // find heights of inside and outside edges
      int posn = (m_samples+1-x)*depthSize + (z+1);
      points[posn] = pt;
      insideHts[posn] = inside; // max(m_lavaRadius, min(outside, inside));
      outsideHts[posn] = outside;
    }
  }

  addPolygons(insideHts, outsideHts, points, flags);

  // ymax side
  py = 1.0;
  for (int x = -1; x <= m_samples+1; x++)
  {
    px = x/(double) m_samples;
    for (int z = -1; z <= m_samples+1; z++)
    {
      pz = z/(double) m_samples;

      mgPoint3 pt(px-0.5, py-0.5, pz-0.5);
      pt.normalize();

      // find heights of inside and outside edges
      double inside = insideHt(pt);
      double outside = outsideHt(pt);

      int posn = (x+1)*depthSize + (z+1);
      points[posn] = pt;
      insideHts[posn] = inside; // max(m_lavaRadius, min(outside, inside));
      outsideHts[posn] = outside;
    }
  }

  addPolygons(insideHts, outsideHts, points, flags);

  // xmin side
  px = 0.0;
  for (int z = -1; z <= m_samples+1; z++)
  {
    pz = z/(double) m_samples;
    for (int y = -1; y <= m_samples+1; y++)
    {
      py = y/(double) m_samples;

      mgPoint3 pt(px-0.5, py-0.5, pz-0.5);
      pt.normalize();

      // find heights of inside and outside edges
      double inside = insideHt(pt);
      double outside = outsideHt(pt);

      int posn = (m_samples+1-z)*depthSize + (y+1);
      points[posn] = pt;
      insideHts[posn] = inside;
      outsideHts[posn] = outside;
    }
  }

  addPolygons(insideHts, outsideHts, points, flags);

  // xmax side
  px = 1.0;
  for (int z = -1; z <= m_samples+1; z++)
  {
    pz = z/(double) m_samples;
    for (int y = -1; y <= m_samples+1; y++)
    {
      py = y/(double) m_samples;

      mgPoint3 pt(px-0.5, py-0.5, pz-0.5);
      pt.normalize();

      // find heights of inside and outside edges
      double inside = insideHt(pt);
      double outside = outsideHt(pt);

      int posn = (z+1)*depthSize + (y+1);
      points[posn] = pt;
      insideHts[posn] = inside;
      outsideHts[posn] = outside;
    }
  }
 
  addPolygons(insideHts, outsideHts, points, flags);

  // zmin side
  pz = 0.0;
  for (int y = -1; y <= m_samples+1; y++)
  {
    py = y/(double) m_samples;
    for (int x = -1; x <= m_samples+1; x++)
    {
      px = x/(double) m_samples;

      mgPoint3 pt(px-0.5, py-0.5, pz-0.5);
      pt.normalize();

      // find heights of inside and outside edges
      double inside = insideHt(pt);
      double outside = outsideHt(pt);

      int posn = (m_samples+1-y)*depthSize + (x+1);
      points[posn] = pt;
      insideHts[posn] = inside;
      outsideHts[posn] = outside;
    }
  }

  addPolygons(insideHts, outsideHts, points, flags);

  // zmax side
  pz = 1.0;
  for (int y = -1; y <= m_samples+1; y++)
  {
    py = y/(double) m_samples;
    for (int x = -1; x <= m_samples+1; x++)
    {
      px = x/(double) m_samples;

      mgPoint3 pt(px-0.5, py-0.5, pz-0.5);
      pt.normalize();

      // find heights of inside and outside edges
      double inside = insideHt(pt);
      double outside = outsideHt(pt);

      int posn = (y+1)*depthSize + (x+1);
      points[posn] = pt;
      insideHts[posn] = inside;
      outsideHts[posn] = outside;
    }
  }

  addPolygons(insideHts, outsideHts, points, flags);

  delete insideHts;
  delete outsideHts;
  delete points;
  delete flags;
}
예제 #6
0
  void addRoundedRectangle(Geometry * geom, Vector2 const& pos, Vector2 const& size, float radius, Color const& color)
  {
    const Vector2 p0(pos.x + size.x - radius, pos.y + radius); // top-right
    const Vector2 p1(pos.x + size.x - radius, pos.y + size.y - radius); // bottom-right
    const Vector2 p2(pos.x + radius, pos.y + size.y - radius); // bottom-left
    const Vector2 p3(pos.x + radius, pos.y + radius); // top-left
    const float step = M_PI / 16.0f;

    Vector2 vertices[] = {
      // top
      Vector2(pos.x + radius, pos.y),
      Vector2(pos.x + size.x - radius, pos.y),

      // top-right
      Vector2(p0.x + std::cos(step * 7) * radius, p0.y - std::sin(step * 7) * radius),
      Vector2(p0.x + std::cos(step * 6) * radius, p0.y - std::sin(step * 6) * radius),
      Vector2(p0.x + std::cos(step * 5) * radius, p0.y - std::sin(step * 5) * radius),
      Vector2(p0.x + std::cos(step * 4) * radius, p0.y - std::sin(step * 4) * radius),
      Vector2(p0.x + std::cos(step * 3) * radius, p0.y - std::sin(step * 3) * radius),
      Vector2(p0.x + std::cos(step * 2) * radius, p0.y - std::sin(step * 2) * radius),
      Vector2(p0.x + std::cos(step * 1) * radius, p0.y - std::sin(step * 1) * radius),

      // right
      Vector2(pos.x + size.x, pos.y + radius),
      Vector2(pos.x + size.x, pos.y + size.y - radius),

      // bottom-right
      Vector2(p1.x + std::cos(step * 31) * radius, p1.y - std::sin(step * 31) * radius),
      Vector2(p1.x + std::cos(step * 30) * radius, p1.y - std::sin(step * 30) * radius),
      Vector2(p1.x + std::cos(step * 29) * radius, p1.y - std::sin(step * 29) * radius),
      Vector2(p1.x + std::cos(step * 28) * radius, p1.y - std::sin(step * 28) * radius),
      Vector2(p1.x + std::cos(step * 27) * radius, p1.y - std::sin(step * 27) * radius),
      Vector2(p1.x + std::cos(step * 26) * radius, p1.y - std::sin(step * 26) * radius),
      Vector2(p1.x + std::cos(step * 25) * radius, p1.y - std::sin(step * 25) * radius),

      // bottom
      Vector2(pos.x + size.x - radius, pos.y + size.y),
      Vector2(pos.x + radius, pos.y + size.y),

      // bottom-left
      Vector2(p2.x + std::cos(step * 23) * radius, p2.y - std::sin(step * 23) * radius),
      Vector2(p2.x + std::cos(step * 22) * radius, p2.y - std::sin(step * 22) * radius),
      Vector2(p2.x + std::cos(step * 21) * radius, p2.y - std::sin(step * 21) * radius),
      Vector2(p2.x + std::cos(step * 20) * radius, p2.y - std::sin(step * 20) * radius),
      Vector2(p2.x + std::cos(step * 19) * radius, p2.y - std::sin(step * 19) * radius),
      Vector2(p2.x + std::cos(step * 18) * radius, p2.y - std::sin(step * 18) * radius),
      Vector2(p2.x + std::cos(step * 17) * radius, p2.y - std::sin(step * 17) * radius),

      // left
      Vector2(pos.x, pos.y + size.y - radius),
      Vector2(pos.x, pos.y + radius),

      // top-left
      Vector2(p3.x + std::cos(step * 15) * radius, p3.y - std::sin(step * 15) * radius),
      Vector2(p3.x + std::cos(step * 14) * radius, p3.y - std::sin(step * 14) * radius),
      Vector2(p3.x + std::cos(step * 13) * radius, p3.y - std::sin(step * 13) * radius),
      Vector2(p3.x + std::cos(step * 12) * radius, p3.y - std::sin(step * 12) * radius),
      Vector2(p3.x + std::cos(step * 11) * radius, p3.y - std::sin(step * 11) * radius),
      Vector2(p3.x + std::cos(step * 10) * radius, p3.y - std::sin(step * 10) * radius),
      Vector2(p3.x + std::cos(step *  9) * radius, p3.y - std::sin(step *  9) * radius)
    };

    addPolygons(geom, vertices, 36, 1.0f, color);
  }