Exemple #1
0
//init all Edges
void GraphHandler::initEdges(){
    for(unsigned int i = 0; i < attributes.size(); i++){
        w.push_back(1.0);
    }
    
    updateEdges();
};
Exemple #2
0
// Shift road ends to connect to each other.
void PatchMap::smoothSeams(){

	
	for(size_t x = 0; x < xTiles; ++x){
		for(size_t y = 0; y < yTiles; ++y){

			if(x < xTiles - 1){ // Smooth the seam to the right.
				std::vector<RoadEnd>& rightEnds = patches[x][y].getRightRoads();
				std::vector<RoadEnd>& leftEnds = patches[x + 1][y].getLeftRoads();

				// Shouldn't happen. Theoretically.
				if(rightEnds.size() != leftEnds.size())
					continue;

				// Use pointers within RoadEnd objects to directly shift the path end points.
				for(size_t i = 0; i < rightEnds.size(); ++i){
					float xDistance = *(rightEnds[i].coordPos) - *(leftEnds[i].coordPos);
					float yDistance = rightEnds[i].location - leftEnds[i].location;
					*(rightEnds[i].coordPos) -= xDistance / 2;
					*(leftEnds[i].coordPos) += xDistance / 2;
					*(rightEnds[i].coordPos + 1) -= yDistance / 2;
					*(leftEnds[i].coordPos + 1) += yDistance / 2;

					// Keep track of the distance each patch has been modified by.
					float modification = fabs(xDistance) + fabs(yDistance);
					patches[x][y].addModification(modification);
					patches[x + 1][y].addModification(modification);
				}
			}

			if(y == 0) // No top seam to smooth out, so stop here.
				continue;


			std::vector<RoadEnd>& topEnds = patches[x][y].getTopRoads();
			std::vector<RoadEnd>& bottomEnds = patches[x][y - 1].getBottomRoads();

			if(topEnds.size() != bottomEnds.size())
				continue;

			// Same as with right seam smoothing.
			for(size_t i = 0; i < topEnds.size(); ++i){
				float xDistance = topEnds[i].location - bottomEnds[i].location;
				float yDistance = *(topEnds[i].coordPos + 1) - *(bottomEnds[i].coordPos + 1);
				*(topEnds[i].coordPos) -= xDistance / 2;
				*(bottomEnds[i].coordPos) += xDistance / 2;
				*(topEnds[i].coordPos + 1) -= yDistance / 2;
				*(bottomEnds[i].coordPos + 1) += yDistance / 2;

				float modification = fabs(xDistance) + fabs(yDistance);
				patches[x][y].addModification(modification);
				patches[x][y - 1].addModification(modification);
			}
		}
	}

	updateEdges();
};
Exemple #3
0
void PatchMap::fill(){
	if(lut.isEmpty())
		std::cout << "Warning: no fragments available. Ensure maps are in the correct input location.\n";

	for(unsigned int i = 0; i < xTiles * yTiles; ++i)
		step();
	
	updatePositions();
	updateEdges();
};
//*******************************************************************************
void Node::translate(const double x, const double y, const double z)
{
	if (m_pBusinessObject != NULL)
	{
		// Business-Objekt fragen, ob und wie schwer sich der Knoten bewegen lassen
		// soll.
		float xUnits = m_rUnitInfo.xValueToUnit(x);
		float yUnits = m_rUnitInfo.yValueToUnit(y);
		force f = incredible;
		f = m_pBusinessObject->getForce(xUnits, yUnits);
		switch(f)
		{
			case none:
			{
				// der Node darf sich frei bewegen, keine Aktion nötig.
				// Eventuell aktive Effekte müssen gestoppt werden.
				m_pHardToMoveEffect->stopEffect();
				m_pImpossibleToMoveEffect->stopEffect();
				break;
			}
			case medium:
			{
				// ForceEffect für schweres Bewegen aktivieren und den anderen Effekt
				// falls nötig stoppen.
				m_pImpossibleToMoveEffect->stopEffect();
				m_pHardToMoveEffect->startEffect();
				break;
			}
			case incredible:
			{
				// ForceEffect, der jede Bewegung blockieren soll, aktivieren und 
				// den anderen Effekt falls nötig stoppen.
				m_pHardToMoveEffect->stopEffect();
				double prox[3];
//				hlGetDoublev(HL_PROXY_POSITION, prox);
//				((SpringForceEffect *)m_pImpossibleToMoveEffect)->setAnchorPosition(prox[0], prox[1], prox[2]);
				m_pImpossibleToMoveEffect->startEffect();
				break;
			}
			default:
			{
				// Eventuell aktive Effekte müssen gestoppt werden.
				m_pHardToMoveEffect->stopEffect();
				m_pImpossibleToMoveEffect->stopEffect();
				break;
			}
		}
	}

	HapticObject::translate(x, y, z);
	updateEdges();
}
//*******************************************************************************
void Node::Update( Observable * pObservable )
{
	float pad = m_rUnitInfo.getHorizontalPadding();

	// Breite vom BusinessObjekt erfragen
	m_Width = m_rUnitInfo.unitToXValue((float)m_pBusinessObject->getWidth()) - pad;

	// Position erfragen
	double x = m_rUnitInfo.unitToXValue(m_pBusinessObject->getBegin());
	double y = m_rUnitInfo.unitToYValue(m_pBusinessObject->getLine());
	HapticObject::setPosition(x, y, 0.0);

	updateEdges();
}
void GraphDrawingScene::updateEdgesOfNode(Node* node)
{
    // nodepointer can't be NULL, this would give problems
    assert(node);
    /* this makes it a whole lot efficienter when reading big graphs without edges,
        the nodeedges don't have to be retrieved because it's empty anyways*/
    if (!_graph->getNumberOfEdges())
        return ;
    /* if the last cached node is diferrent from the node that we are updating
        the edges from, we change the cached node to the node that and cache those edges that need updating*/
    cacheEdgesForNode(node);
    // now update the cached edges
    updateEdges(_cachedEdges);
}
//*******************************************************************************
void Node::setPosition(const double x, const double y, const double z)
{
	if (m_pBusinessObject != NULL)
	{
		float xUnits = m_rUnitInfo.xValueToUnit(x);
		m_pBusinessObject->setBegin(xUnits);
		Update(m_pBusinessObject);

		m_pHardToMoveEffect->stopEffect();
		m_pImpossibleToMoveEffect->stopEffect();
	}
	else
	{
		HapticObject::setPosition(x, y, z);
		updateEdges();
	}
}
Exemple #8
0
// Fill patch map from a city, rather than synthesising a new one.
void PatchMap::fill(const City& city){
	
	// Modify patch width/height to fit the user specified number of tiles.
	patchWidth = (float)city.getWidth() / xTiles;
	patchHeight = (float)city.getHeight() / yTiles;

	for(size_t x = 0; x < xTiles; ++x){
		for(size_t y = 0; y < yTiles; ++y){
			MapFragment frag;
			city.fillFragment(frag, x * patchWidth, y * patchHeight, patchWidth, patchHeight);
			patches[x][y] = Patch(frag);
		}
	}

	updatePositions();
	updateEdges();

	graph.clear();
};
void m_Polygon::updateAll() {
    updateNormals();
    updateClockwise();
    updateEdges();
}
Exemple #10
0
//updateAll
void GraphHandler::updateAll(vector<vector<unsigned int>> &clustering, vector<unsigned int> &medians){
    updateWeights(clustering, medians);
    updateEdges();
};
Exemple #11
0
//--------------------------------------------------------------
// update animation 
BOOL ChunkWorld::animate(
  double now,                       // current time (ms)
  double since)                     // milliseconds since last pass
{
  BOOL viewChanged = false;

  m_chunkLock->lock();

  // keep memory use under limits
  checkMemory();

  resetRequestList();

  // figure which chunk we are in
  int viewX = (int) floor(m_eyePt.x / CHUNK_SIZE);
  int viewZ = (int) floor(m_eyePt.z / CHUNK_SIZE);

  // for all coordinates in view list
  for (int i = m_viewListCount-1; i >= 0; i--)
  {
    ChunkOrigin* origin = &m_viewList[i];
    int chunkX = CHUNK_SIZE*(viewX + origin->x);
    int chunkZ = CHUNK_SIZE*(viewZ + origin->z);

    // find/create chunk
    ChunkObj* chunk = createChunk(chunkX, chunkZ);

    // if chunk within view
    if (chunk->withinFrustum())
    {
      switch (chunk->m_status)
      {
        case CHUNK_UNLOADED:
          // request the chunk (loads in memory)
          requestChunk(chunk);

          // request the neighbors
          loadNeighbors(chunk);
          break;

        case CHUNK_INMEMORY:
          // if all neighbors loaded, update chunk edges
          if (loadNeighbors(chunk))
          {
            updateEdges(chunk);

            // request the chunk (loads in display)
            requestChunk(chunk);
          }
          break;

        case CHUNK_INDISPLAY:
          // if we have an update, use it
          if (!chunk->m_active && chunk->m_hasUpdate)
          {
//            mgDebug("use update on (%d, %d)", chunk->m_originX, chunk->m_originZ);
            int oldSize = chunk->getDisplayMemUsed();
            chunk->useUpdate();
            int size = chunk->getDisplayMemUsed();
            m_displayMemUsed += size-oldSize;
            chunk->m_hasUpdate = false;
          }

          // if it needs an update, flag it
          if (!chunk->m_active && chunk->needsUpdate(m_eyePt))
          {
//            mgDebug("wants update on (%d, %d)", chunk->m_originX, chunk->m_originZ);
            chunk->m_status = CHUNK_NEEDSUPDATE;
            chunk->m_eyePt = m_eyePt;
            m_requestList.addToTail(chunk);
          }

          // if still in display, animate it, since we will draw it
          if (chunk->m_status == CHUNK_INDISPLAY ||
              chunk->m_status == CHUNK_NEEDSUPDATE)
            chunk->animate(now, since);
          break;

        case CHUNK_NEEDSUPDATE:
          // if needed update last pass, and not being processed, still needs update
          if (!chunk->m_active)
          {
//            mgDebug("still needs update on (%d, %d)", chunk->m_originX, chunk->m_originZ);
            m_requestList.addToTail(chunk);
            chunk->animate(now, since);
          }
          break;
      }

      // push to bottom of LRU list
      ChunkListNode* node = m_LRUList.find(chunk);
      if (node != NULL)
        m_LRUList.removeNode(node);
      m_LRUList.addToTail(chunk);
    }
  }

  if (m_chunksChanged)
  {
    viewChanged = true;
    m_chunksChanged = false;
  }

  m_chunkLock->unlock();

  // if we requested chunks, activate worker threads
  if (!m_requestList.isEmpty())
  {
    if (m_chunkThreads != NULL)
    {
      // signal the threads to look at requestList
      m_chunkEvent->signal();
    }
    else
    {
      // process one request in this thread (no worker threads)
      ChunkObj* found = dequeueRequest();
      if (found != NULL)
        processRequest(found);
    }
  }

  return viewChanged;
}
Exemple #12
0
void Polygon2D::addPoint(Vector2D point)
{
	m_vertices.push_back(point); 
	updateEdges();
}
Exemple #13
0
void Polygon2D::clearPoints()
{
	m_vertices.clear();
	updateEdges();
}