Exemple #1
0
//----------------------------------------------------------------------------------------------------------------------
void NGLScene::initializeGL()
{
#ifndef DARWIN
    glewExperimental = GL_TRUE;
    GLenum error = glewInit();
    if(error != GLEW_OK){
        std::cerr<<"GLEW IS NOT OK!!! "<<std::endl;
    }
#endif

  glClearColor(1.f, 1.f, 1.0f, 1.0f);			   // White Background
  //glClearColor(.7f, .7f, .7f, 1.0f);
  // enable depth testing for drawing
  glEnable(GL_DEPTH_TEST);
  // enable multisampling for smoother drawing
  glEnable(GL_MULTISAMPLE);

  // Now we will create a basic Camera from the graphics library
  // This is a static camera so it only needs to be set once
  // First create Values for the camera position
  glm::vec3 from(0,0,5);
  glm::vec3 to(0,0,0);
  glm::vec3 up(0,1,0);
  // now load to our new camera
  m_cam = Camera(from,to,up);
  // set the shape using FOV 45 Aspect Ratio based on Width and Height
  // The final two are near and far clipping planes of 0.5 and 10
  m_cam.setShape(45.0f,720.0f,576.0f,0.05f,350.0f);

  // Create our phong shader program
  m_phongShader = new ShaderProgram();
  // now we are going to create our shaders from source
  Shader vert("shaders/PhongVertex.glsl",GL_VERTEX_SHADER);
  Shader frag("shaders/PhongFragment.glsl",GL_FRAGMENT_SHADER);
  // attach the shaders to program
  m_phongShader->attachShader(&vert);
  m_phongShader->attachShader(&frag);
  m_phongShader->bindFragDataLocation(0, "fragColour");
  // now we have associated that data we can link the shader
  m_phongShader->link();
  // and make it active ready to
  m_phongShader->use();

  //Set some uniforms for our shader
  glUniform3f(m_phongShader->getUniformLoc("viewerPos"),from.x,from.y,from.z);
  glUniform3f(m_phongShader->getUniformLoc("material.ambient"),0.274725f,0.1995f,0.0745f);
  glUniform3f(m_phongShader->getUniformLoc("material.diffuse"),0.75164f,0.60648f,0.22648f);
  glUniform3f(m_phongShader->getUniformLoc("material.specular"),0.628281f,0.555802f,0.3666065f);
  glUniform1f(m_phongShader->getUniformLoc("material.shininess"),51.2f);

  glUniform4f(m_phongShader->getUniformLoc("light.position"),0.f,5.f,0.f,1.f);
  glUniform4f(m_phongShader->getUniformLoc("light.diffuse"),1.f,1.f,1.f,1.f);
  glUniform4f(m_phongShader->getUniformLoc("light.ambient"),1.f,1.f,1.f,1.f);
  glUniform4f(m_phongShader->getUniformLoc("light.specular"),1.f,1.f,1.f,1.f);
  glUniform1f(m_phongShader->getUniformLoc("light.constantAttenuation"),1.f);
  glUniform1f(m_phongShader->getUniformLoc("light.quadraticAttenuation"),0.f);
  glUniform1f(m_phongShader->getUniformLoc("light.linearAttenuation"),0.f);
  glUniform1f(m_phongShader->getUniformLoc("light.spotCosCutoff"),180.f);


  //Create our text drawer
  m_text = new Text(QFont("Ariel"));
  m_text->setScreenSize(width(),height());
  m_text->setColour(1.f,0.f,0.f);


  //Create our nice efficient particle drawer
  m_particleDrawer = new ParticleDrawer;
  m_particleDrawer->setParticleSize(0.025f);
  m_particleDrawer->setScreenWidth(width());

  //Create our SPH Solver
  m_SPHSolverCUDA = new SPHSolverCUDA;

  m_SPHSolverCUDA->genRandomSamples(160000);

  // Start our timer event. This will begin calling the TimerEvent function that updates our simulation.
  startTimer(0);
}
Exemple #2
0
std::vector<lp::Sequence>
LpReliability::onLpPacketLost(lp::Sequence txSeq)
{
  BOOST_ASSERT(m_unackedFrags.count(txSeq) > 0);
  auto txSeqIt = m_unackedFrags.find(txSeq);

  auto& txFrag = txSeqIt->second;
  txFrag.rtoTimer.cancel();
  auto netPkt = txFrag.netPkt;
  std::vector<lp::Sequence> removedThisTxSeq;

  // Check if maximum number of retransmissions exceeded
  if (txFrag.retxCount >= m_options.maxRetx) {
    // Delete all LpPackets of NetPkt from m_unackedFrags (except this one)
    for (size_t i = 0; i < netPkt->unackedFrags.size(); i++) {
      if (netPkt->unackedFrags[i] != txSeqIt) {
        removedThisTxSeq.push_back(netPkt->unackedFrags[i]->first);
        deleteUnackedFrag(netPkt->unackedFrags[i]);
      }
    }

    ++m_linkService->nRetxExhausted;

    // Notify strategy of dropped Interest (if any)
    if (netPkt->isInterest) {
      BOOST_ASSERT(netPkt->pkt.has<lp::FragmentField>());
      ndn::Buffer::const_iterator fragBegin, fragEnd;
      std::tie(fragBegin, fragEnd) = netPkt->pkt.get<lp::FragmentField>();
      Block frag(&*fragBegin, std::distance(fragBegin, fragEnd));
      onDroppedInterest(Interest(frag));
    }

    removedThisTxSeq.push_back(txSeqIt->first);
    deleteUnackedFrag(txSeqIt);
  }
  else {
    // Assign new TxSequence
    lp::Sequence newTxSeq = assignTxSequence(txFrag.pkt);
    netPkt->didRetx = true;

    // Move fragment to new TxSequence mapping
    auto newTxFragIt = m_unackedFrags.emplace_hint(
      m_firstUnackedFrag != m_unackedFrags.end() && m_firstUnackedFrag->first > newTxSeq
        ? m_firstUnackedFrag
        : m_unackedFrags.end(),
      std::piecewise_construct,
      std::forward_as_tuple(newTxSeq),
      std::forward_as_tuple(txFrag.pkt));
    auto& newTxFrag = newTxFragIt->second;
    newTxFrag.retxCount = txFrag.retxCount + 1;
    newTxFrag.netPkt = netPkt;

    // Update associated NetPkt
    auto fragInNetPkt = std::find(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(), txSeqIt);
    BOOST_ASSERT(fragInNetPkt != netPkt->unackedFrags.end());
    *fragInNetPkt = newTxFragIt;

    removedThisTxSeq.push_back(txSeqIt->first);
    deleteUnackedFrag(txSeqIt);

    // Retransmit fragment
    m_linkService->sendLpPacket(lp::Packet(newTxFrag.pkt));

    // Start RTO timer for this sequence
    newTxFrag.rtoTimer = scheduler::schedule(m_rto.computeRto(), [=] { onLpPacketLost(newTxSeq); });
  }

  return removedThisTxSeq;
}
Exemple #3
0
QT_BEGIN_NAMESPACE

/*!
    \class QTextTableCell
    \reentrant

    \brief The QTextTableCell class represents the properties of a
    cell in a QTextTable.

    \ingroup richtext-processing

    Table cells are pieces of document structure that belong to a table.
    The table orders cells into particular rows and columns; cells can
    also span multiple columns and rows.

    Cells are usually created when a table is inserted into a document with
    QTextCursor::insertTable(), but they are also created and destroyed when
    a table is resized.

    Cells contain information about their location in a table; you can
    obtain the row() and column() numbers of a cell, and its rowSpan()
    and columnSpan().

    The format() of a cell describes the default character format of its
    contents. The firstCursorPosition() and lastCursorPosition() functions
    are used to obtain the extent of the cell in the document.

    \sa QTextTable QTextTableFormat
*/

/*!
    \fn QTextTableCell::QTextTableCell()

    Constructs an invalid table cell.

    \sa isValid()
*/

/*!
    \fn QTextTableCell::QTextTableCell(const QTextTableCell &other)

    Copy constructor. Creates a new QTextTableCell object based on the
    \a other cell.
*/

/*!
    \fn QTextTableCell& QTextTableCell::operator=(const QTextTableCell &other)

    Assigns the \a other table cell to this table cell.
*/

/*!
    \since 4.2

    Sets the cell's character format to \a format. This can for example be used to change
    the background color of the entire cell:

    QTextTableCell cell = table->cellAt(2, 3);
    QTextCharFormat format = cell.format();
    format.setBackground(Qt::blue);
    cell.setFormat(format);

    Note that the cell's row or column span cannot be changed through this function. You have
    to use QTextTable::mergeCells and QTextTable::splitCell instead.

    \sa format()
*/
void QTextTableCell::setFormat(const QTextCharFormat &format)
{
    QTextCharFormat fmt = format;
    fmt.clearProperty(QTextFormat::ObjectIndex);
    fmt.setObjectType(QTextFormat::TableCellObject);
    QTextDocumentPrivate *p = table->docHandle();
    QTextDocumentPrivate::FragmentIterator frag(&p->fragmentMap(), fragment);

    QTextFormatCollection *c = p->formatCollection();
    QTextCharFormat oldFormat = c->charFormat(frag->format);
    fmt.setTableCellRowSpan(oldFormat.tableCellRowSpan());
    fmt.setTableCellColumnSpan(oldFormat.tableCellColumnSpan());

    p->setCharFormat(frag.position(), 1, fmt, QTextDocumentPrivate::SetFormatAndPreserveObjectIndices);
}