Beispiel #1
0
int Quality::getHoleCount(std::vector<Edge*>& edges)
{
    int cmp = 0;

    std::vector<Edge*> e;
    Edge* nextEdge;

    for (unsigned int i = 1; i < edges.size(); ++i)
    {
        if(std::find(e.begin(), e.end(), edges[i]) == e.end()) // If edge is not in the visited list
        {
            nextEdge = getNextEdge(edges, edges[i], e);

            while (nextEdge != NULL)
            {
                e.push_back(nextEdge);
                nextEdge = getNextEdge(edges, nextEdge, e);
            }

            cmp++;
        }
    }

    return cmp;
}
Beispiel #2
0
bool Contour::findNextTriangle( double z, int t1, int e1, int& t2, int& e2, DT_Point& p )
{
    // 已达到边界
    if( t1 == -1 ) return false;

    // 对第i个三角形的另外2条边进行检查并插值
    e2 = getNextEdge( t1, e1 );
    if( isNextTriangleUsed( t1, e2 ) || !hasContourPoint( z, e2 ) )
    {
        e2 = getNextEdge( t1, e2 );
        if( isNextTriangleUsed( t1, e2 ) || !hasContourPoint( z, e2 ) )
        {
            return false;
        }
    }

    // 将当前的三角形的标记为已使用
    getTriangleObject( t1 )->used = true;

    // 将三角形的编号进行转换
    t2 = getNextTriangle( e2, t1 );

    // 对边e2线性插值
    linearInterpolate( z, e2, p );

    return true;
}
// runs cmpAndSwapResvBy on each track, provided they are contineous
static int swapTrackResvBy(int oldValue, int newValue, track_node **track, int n, int *dist) {
    ASSERT(track && n > 0, "Expected non-empty array, instead got %s, %d", (track ? track[0]->name : "NULL"), n);

    track_node *currentNode = *track++;
    track_node *nextNode;
    track_edge *nextEdge;
    bool validRes;
    int nextEdgeDist;
    int numSuccess = 0;

    while (currentNode && (validRes = cmpAndSwapResvBy(currentNode, oldValue, newValue))) {
        // debug("%d res %s, %d node %d dist left", newValue, d(currentNode).name, n, (dist ? *dist : -1));
        numSuccess++;

        if (--n <= 0) {
            if (dist) {
                // no more nodes left but still has dist, just use track state
                if ((nextEdge = getNextEdge(currentNode))) {
                    nextNode = nextEdge->dest;
                } else {
                    // next node is null! nothing to see here
                    return numSuccess;
                }
                //debug("using next node from track state %s", d(nextNode).name);
            } else {
                //debug("no nodes left, no dist left, break");
                break;
            }
        } else {
            // still has node left
            nextNode = *track++;
        }

        nextEdgeDist = validNextNode(currentNode, nextNode);
        // path is not contiguous (not DIR_AHEAD/DIR_STRAIGHT or DIR_CURVED)
        ASSERT(nextEdgeDist >= 0, "Incorrect path at %s to %s",
                (currentNode ? currentNode->name : "NULL"), (nextNode ? nextNode->name : "NULL"));

        if (dist) {
            if (*dist <= 0) {
                //debug("out of distance with dist = %d", *dist);
                break;
            } else {
                //debug("has dist, subtracting nextEdgeDist: %d - %d", *dist, nextEdgeDist);
                *dist -= nextEdgeDist;
            }
        }
        currentNode = nextNode;
    }

    return numSuccess;
}
Beispiel #4
0
// Begin following cycles and joining them to compute the final tour
void Graph::mergeCycles(int curEdgeIndex, int prevNode)
{
	edges[curEdgeIndex].used = true;   // Mark the edge as used
	finalTour.push_back(curEdgeIndex);

	if (finalTour.size() == edgeCt) return;

	auto toNode = edges[curEdgeIndex].toNode;
	if (toNode == prevNode) toNode = edges[curEdgeIndex].fromNode;  // Swap the nodes if they're in the wrong order

	auto nextEdgeIndex = getNextEdge(curEdgeIndex, toNode);

	mergeCycles(nextEdgeIndex, toNode);
}
void parcoursMST(Matrix m, Edge* e){
  int alpha=getMatrixLength(m);
  int currentSize = 0;

  // On crée un tableau contenant toutes les arêtes triées
  readMatrixAndCreateEdges(m);

  // Pour chaque arrêt de la route tant que l'on a pas attein la fin du tableau
  for (int j=0;j<(alpha-1) && caseActuelleEnsemble < tailleEnsemble;j++){

    // On récupère une arête correcte
    e[j]=getNextEdge(e, currentSize, j);
    
    //Affiche les arêtes rajoutés (sert de test)
    //printf("L'arete de trajet : [%d,%d] a été rajouté\n", e[j]->start, e[j]->end);

    currentSize++;
  }
}
Beispiel #6
0
bool
Person::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
    switch (variable) {
        case TRACI_ID_LIST:
            return wrapper->wrapStringList(objID, variable, getIDList());
        case ID_COUNT:
            return wrapper->wrapInt(objID, variable, getIDCount());
        case VAR_POSITION:
            return wrapper->wrapPosition(objID, variable, getPosition(objID));
        case VAR_POSITION3D:
            return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
        case VAR_ANGLE:
            return wrapper->wrapDouble(objID, variable, getAngle(objID));
        case VAR_SLOPE:
            return wrapper->wrapDouble(objID, variable, getSlope(objID));
        case VAR_SPEED:
            return wrapper->wrapDouble(objID, variable, getSpeed(objID));
        case VAR_ROAD_ID:
            return wrapper->wrapString(objID, variable, getRoadID(objID));
        case VAR_LANEPOSITION:
            return wrapper->wrapDouble(objID, variable, getLanePosition(objID));
        case VAR_COLOR:
            return wrapper->wrapColor(objID, variable, getColor(objID));
        case VAR_WAITING_TIME:
            return wrapper->wrapDouble(objID, variable, getWaitingTime(objID));
        case VAR_TYPE:
            return wrapper->wrapString(objID, variable, getTypeID(objID));
        case VAR_NEXT_EDGE:
            return wrapper->wrapString(objID, variable, getNextEdge(objID));
        case VAR_STAGES_REMAINING:
            return wrapper->wrapInt(objID, variable, getRemainingStages(objID));
        case VAR_VEHICLE:
            return wrapper->wrapString(objID, variable, getVehicle(objID));
        default:
            return false;
    }
}
void Mesh::LoopSubdivisionNewPositions() {
// Calculate new positions of vertices based on current cage
  Vertex *vertA;
  Vertex *vertB;
  Vertex *vertC;
  Vertex *vertD;
  Vertex *newVert;
  Edge *e = NULL;
  std::vector<Vertex *> newTriVerts;
  std::vector<Vertex *> middleTriVerts;

  int numNewVerts = 0;

  // Store old vertex locations
  for (int i=0; i<vertices.size(); i++) {
    vertices[i]->setOldPos(vertices[i]->getPos());
  }

  // Calculate new positions for these verts
  for (triangleshashtype::iterator iter = triangles.begin(); iter != triangles.end(); iter++) {

    Triangle *t = iter->second;
    std::vector<Vertex *> surroundingVerts;
    int numSurroundingVerts;
    glm::vec3 newPos;
    for (int i=0; i<3; i++) {
      surroundingVerts.clear();
      numSurroundingVerts = 0;

      Vertex *v = (*t)[i];

      Edge *startingEdge = t->getEdge();
      while (startingEdge->getStartVertex()->getIndex() != v->getIndex()) {
          startingEdge = startingEdge->getNext();
      }


      bool goOtherWay = false;
      Edge *loop = startingEdge;
      // Check for cases of boundary edges in open meshes
      do {
        // If boundary edge...
            if (loop->getOpposite() == NULL) {

                glm::vec3 factorA = v->getOldPos();
                factorA *= 0.75;
          
                glm::vec3 factorB = loop->getNext()->getStartVertex()->getOldPos();
                factorB *= 0.125;

          // Find other boundary edge
          Edge* otherBoundaryEdge = loop->getNext()->getNext();
          while (!(otherBoundaryEdge->getOpposite() == NULL)) {
            otherBoundaryEdge = otherBoundaryEdge->getOpposite()->getNext()->getNext();
          }
          Vertex *c = otherBoundaryEdge->getStartVertex();
                glm::vec3 factorC = c->getOldPos();
          factorC *= 0.125;

                newPos = factorA + factorB + factorC;
          break;

            }
            else {

                numSurroundingVerts++;
                Vertex *connectedV = loop->getOpposite()->getStartVertex();
                surroundingVerts.push_back(connectedV);

            }
            Edge *checkingEdge = getNextEdge(loop, goOtherWay);
            if (checkingEdge == NULL) {
                loop = startingEdge;
            }
            loop = checkingEdge;

      }
      while (loop != startingEdge);

      // If it's not a boundary edge...
      if (!(loop->getOpposite() == NULL)) {

        float beta;
        if (numSurroundingVerts == 3) {
          beta = 3/16.0;
        }
        else {
          // Weight the new position based on num of surrounding verts
          beta = 3/(8.0 * numSurroundingVerts);
        }
        newPos = v->getOldPos() * (1-numSurroundingVerts*beta);
        for (int j=0; j<numSurroundingVerts; j++) {
          newPos += surroundingVerts[j]->getOldPos() * beta;
        }
      }

      v->setPos(newPos);
    }
  }
}