Exemplo n.º 1
0
int ChainSilhouetteIterator::traverse(const AdjacencyIterator& ait)
{
	AdjacencyIterator it(ait);
	ViewVertex *nextVertex = getVertex();
	// we can't get a NULL nextVertex here, it was intercepted before
	if (nextVertex->getNature() & Nature::T_VERTEX) {
		TVertex *tvertex = (TVertex *)nextVertex;
		ViewEdge *mate = (tvertex)->mate(getCurrentEdge());
		while (!it.isEnd()) {
			ViewEdge *ve = *it;
			if (ve == mate) {
				result = ve;
				return 0;
			}
			++it;
		}
		result = 0;
		return 0;
	}
	if (nextVertex->getNature() & Nature::NON_T_VERTEX) {
		//soc NonTVertex *nontvertex = (NonTVertex*)nextVertex;
		ViewEdge *newEdge(0);
		// we'll try to chain the edges by keeping the same nature...
		// the preseance order is : SILHOUETTE, BORDER, CREASE, SUGGESTIVE, VALLEY, RIDGE
		Nature::EdgeNature natures[6] = {
			Nature::SILHOUETTE,
			Nature::BORDER,
			Nature::CREASE,
			Nature::SUGGESTIVE_CONTOUR,
			Nature::VALLEY,
			Nature::RIDGE
		};
		for (unsigned int i = 0; i < 6; ++i) {
			if (getCurrentEdge()->getNature() & natures[i]) {
				int n = 0;
				while (!it.isEnd()) {
					ViewEdge *ve = *it;
					if (ve->getNature() & natures[i]) {
						++n;
						newEdge = ve;
					}
					++it;
				}
				if (n == 1) {
					result = newEdge;
				}
				else {
					result = 0;
				}
				return 0;
			}
		}
	}
	result = 0;
	return 0;
}
Exemplo n.º 2
0
 Nature::EdgeNature CurveNatureF1D::operator()(Interface1D& inter) {
   ViewEdge* ve = dynamic_cast<ViewEdge*>(&inter);
   if (ve)
     return ve->getNature();
   else{
     // we return a nature that contains every 
     // natures of the viewedges spanned by the chain.
     Nature::EdgeNature nat = Nature::NO_FEATURE;
     Interface0DIterator it = inter.verticesBegin();
     while(!it.isEnd()){
       nat |= _func(it);
       ++it;
     }
     return nat;
   }
 }
Exemplo n.º 3
0
ViewVertex *ViewMap::InsertViewVertex(SVertex *iVertex, vector<ViewEdge*>& newViewEdges)
{
	NonTVertex *vva = dynamic_cast<NonTVertex*>(iVertex->viewvertex());
	if (vva)
		return vva;
	// because it is not already a ViewVertex, this SVertex must have only 2 FEdges. The incoming one still belongs
	// to ioEdge, the outgoing one now belongs to newVEdge
	const vector<FEdge *>& fedges = iVertex->fedges();
	if (fedges.size() != 2) {
		cerr << "ViewMap warning: Can't split the ViewEdge" << endl;
		return NULL;
	}
	FEdge *fend(NULL), *fbegin(NULL);
	for (vector<FEdge *>::const_iterator fe = fedges.begin(), feend = fedges.end(); fe != feend; ++fe) {
		if ((*fe)->vertexB() == iVertex) {
			fend = (*fe);
		}
		if ((*fe)->vertexA() == iVertex) {
			fbegin = (*fe);
		}
		if ((fbegin != NULL) && (fend != NULL))
			break;
	}
	ViewEdge *ioEdge = fbegin->viewedge();
	ViewShape *vshape = ioEdge->viewShape();
	vva = new NonTVertex(iVertex);
	// if the ViewEdge is a closed loop, we don't create a new VEdge
	if (ioEdge->A() == 0) {
		// closed loop
		ioEdge->setA(vva);
		ioEdge->setB(vva);
		// update sshape
		vshape->sshape()->RemoveEdgeFromChain(ioEdge->fedgeA());
		vshape->sshape()->RemoveEdgeFromChain(ioEdge->fedgeB());

		ioEdge->setFEdgeA(fbegin);
		ioEdge->setFEdgeB(fend);

		// Update FEdges
		fend->setNextEdge(NULL);
		fbegin->setPreviousEdge(NULL);

		// update new View Vertex:
		vva->AddOutgoingViewEdge(ioEdge);
		vva->AddIncomingViewEdge(ioEdge);

		vshape->sshape()->AddChain(ioEdge->fedgeA());
		vshape->sshape()->AddChain(ioEdge->fedgeB());
	}
	else {
		// Create new ViewEdge
		ViewEdge *newVEdge = new ViewEdge(vva, ioEdge->B(), fbegin, ioEdge->fedgeB(), vshape);
		newVEdge->setId(Id(ioEdge->getId().getFirst(), ioEdge->getId().getSecond() + 1));
		newVEdge->setNature(ioEdge->getNature());
		//newVEdge->UpdateFEdges(); // done in the ViewEdge constructor
		// Update old ViewEdge
		ioEdge->setB(vva);
		ioEdge->setFEdgeB(fend);

		// Update FEdges
		fend->setNextEdge(NULL);
		fbegin->setPreviousEdge(NULL);

		// update new View Vertex:
		vva->AddOutgoingViewEdge(newVEdge);
		vva->AddIncomingViewEdge(ioEdge);

		NonTVertex *vvb = dynamic_cast<NonTVertex*>(newVEdge->B());
		if (vvb)
			vvb->Replace(ioEdge, newVEdge);

		// update ViewShape
		//vshape->AddEdge(newVEdge);
		// update SShape
		vshape->sshape()->AddChain(fbegin);
		// update ViewMap
		//_VEdges.push_back(newVEdge);
		newViewEdges.push_back(newVEdge);
	}

	// update ViewShape
	vshape->AddVertex(vva);

	// update ViewMap
	_VVertices.push_back(vva);

	return vva;
}