real FEdge::z_discontinuity() const { if (!(getNature() & Nature::SILHOUETTE) && !(getNature() & Nature::BORDER)) { return 0; } BBox<Vec3r> box = ViewMap::getInstance()->getScene3dBBox(); Vec3r bbox_size_vec(box.getMax() - box.getMin()); real bboxsize = bbox_size_vec.norm(); if (occludee_empty()) { // return FLT_MAX; return 1.0; // return bboxsize; } #if 0 real result; z_discontinuity_functor<SVertex> _functor; Evaluate<SVertex, z_discontinuity_functor<SVertex>>(&_functor, iCombination, result); #endif Vec3r middle((_VertexB->point3d() - _VertexA->point3d())); middle /= 2; Vec3r disc_vec(middle - _occludeeIntersection); real res = disc_vec.norm() / bboxsize; return res; // return fabs((middle.z() - _occludeeIntersection.z())); }
FEdge* SVertex::getFEdge(Interface0D& inter) { FEdge * result = 0; SVertex* iVertexB = dynamic_cast<SVertex*>(&inter); if (!iVertexB) return result; vector<FEdge*>::const_iterator fe=_FEdges.begin(), feend=_FEdges.end(); for(; fe!=feend; ++fe) { if( (((*fe)->vertexA() == this) && ((*fe)->vertexB() == iVertexB)) || (((*fe)->vertexB() == this) && ((*fe)->vertexA() == iVertexB))) result = (*fe); } if((result == 0) && (getNature() & Nature::T_VERTEX)) { SVertex *brother; ViewVertex *vvertex = viewvertex(); TVertex * tvertex = dynamic_cast<TVertex*>(vvertex); if(tvertex) { brother = tvertex->frontSVertex(); if(this == brother) brother = tvertex->backSVertex(); const vector<FEdge*>& fedges = brother->fedges(); for(fe=fedges.begin(),feend=fedges.end(); fe!=feend; ++fe) { if( (((*fe)->vertexA() == brother) && ((*fe)->vertexB() == iVertexB)) || (((*fe)->vertexB() == brother) && ((*fe)->vertexA() == iVertexB))) result = (*fe); } } } if((result == 0) && (iVertexB->getNature() & Nature::T_VERTEX)) { SVertex *brother; ViewVertex *vvertex = iVertexB->viewvertex(); TVertex * tvertex = dynamic_cast<TVertex*>(vvertex); if(tvertex) { brother = tvertex->frontSVertex(); if(iVertexB == brother) brother = tvertex->backSVertex(); for(fe=_FEdges.begin(),feend=_FEdges.end(); fe!=feend; ++fe) { if( (((*fe)->vertexA() == this) && ((*fe)->vertexB() == brother)) || (((*fe)->vertexB() == this) && ((*fe)->vertexA() == brother))) result = (*fe); } } } return result; }
occluder_container::const_iterator SVertex::occluders_end() const { if (getNature() & Nature::T_VERTEX) Exception::raiseException(); return (_FEdges[0])->occluders_end(); }
const int SVertex::qi() const { if (getNature() & Nature::T_VERTEX) Exception::raiseException(); return (_FEdges[0])->qi(); }
FEdge *SVertex::fedge() { if (getNature() & Nature::T_VERTEX) return NULL; return _FEdges[0]; }
real SVertex::z_discontinuity() const { if (getNature() & Nature::T_VERTEX) Exception::raiseException(); return (_FEdges[0])->z_discontinuity(); }
const bool SVertex::occludee_empty() const { if (getNature() & Nature::T_VERTEX) Exception::raiseException(); return (_FEdges[0])->occludee_empty(); }
const SShape *SVertex::occluded_shape() const { if (getNature() & Nature::T_VERTEX) Exception::raiseException(); return (_FEdges[0])->occluded_shape(); }
const Polygon3r &SVertex::occludee() const { if (getNature() & Nature::T_VERTEX) Exception::raiseException(); return (_FEdges[0])->occludee(); }
int SVertex::occluders_size() const { if (getNature() & Nature::T_VERTEX) Exception::raiseException(); return (_FEdges[0])->occluders_size(); }
FEdge *CurvePoint::fedge() { if (getNature() & Nature::T_VERTEX) return 0; return __A->fedge(); }
real SVertex::GetIsophoteDistance(real isovalue, int maxDistance) const { if (_sourceVertex == NULL && _sourceEdge == NULL) return -1; // not handling the case of intersection SVertices yet if (!(getNature() & Nature::SILHOUETTE)) // only handle silhouette curves return -1; Vec3r startPoint = _Point3D; set<pair<WFace*,int> > possibleStartEdges; real currentNdotV; // if (!(getNature() & Nature::SURFACE_INTERSECTION)) // printf("Isophote search Nature: %d\n", getNature()); if (_sourceVertex != NULL) { currentNdotV = _sourceVertex->GetSurfaceNdotV(); // printf("Starting at vertex with n dot v = %f\n", currentNdotV); for(vector<WEdge*>::iterator it = _sourceVertex->GetEdges().begin(); it != _sourceVertex->GetEdges().end(); ++it) { WFace * aface = (*it)->GetaFace(); WFace * bface = (*it)->GetbFace(); if (aface != NULL) possibleStartEdges.insert( pair<WFace*,int>(aface, (aface->GetIndex(_sourceVertex)+1)%3)); if (bface != NULL) possibleStartEdges.insert(pair<WFace*,int>(bface, (bface->GetIndex(_sourceVertex)+1)%3)); } } else { currentNdotV = ComputeSurfaceNdotV(_sourceEdge, startPoint); WFace * faces[2] = { _sourceEdge->GetaFace(), _sourceEdge->GetbFace() }; for(int i=0;i<2;i++) if (faces[i] != NULL) { int v; for(v=0;v<3;v++) if (faces[i]->GetOEdge(v)->GetOwner() == _sourceEdge) break; assert(v<3); possibleStartEdges.insert(pair<WFace*,int>(faces[i], (v+1)%3)); possibleStartEdges.insert(pair<WFace*,int>(faces[i], (v+2)%3)); } } if (currentNdotV > isovalue) return 0; if (currentNdotV < -0.001) return 0; Vec3r currentPoint; WEdge * currentEdge = NULL; WFace * currentFace = NULL; Vec3r lastPoint = startPoint; real lastNdotV = currentNdotV; for(set<pair<WFace*,int> >::iterator it = possibleStartEdges.begin(); it != possibleStartEdges.end(); ++it) { WFace * face = (*it).first; int e = (*it).second; if (AdvanceToEdge( face, startPoint, e, currentPoint)) { currentNdotV = ComputeSurfaceNdotV(face->GetOEdge(e)->GetOwner(), currentPoint); // printf("\tlastNdotV = %f, currentNdotV = %f\n", lastNdotV, currentNdotV); if (currentNdotV < lastNdotV) continue; currentEdge = face->GetOEdge(e)->GetOwner(); currentFace = face->GetBordingFace(e); assert(GeomUtils::distPointSegment<Vec3r>( currentPoint, currentEdge->GetaVertex()->GetVertex(), currentEdge->GetbVertex()->GetVertex()) < 0.01); break; } } if (currentEdge == NULL) return -1; // march over the surface int numSteps = 0; while (currentNdotV < isovalue && currentNdotV > -0.001 && numSteps < 100 && currentFace != NULL && ImageSpaceDistance(startPoint, currentPoint) < maxDistance) { numSteps ++; lastPoint = currentPoint; lastNdotV = currentNdotV; // printf("advancing, current NdotV = %f\n", currentNdotV); bool result = false; int e; Vec3r nextPoint; for(e=0;e<3;e++) { if (currentFace->GetOEdge(e)->GetOwner() == currentEdge) continue; result = AdvanceToEdge(currentFace, currentPoint, e, nextPoint); // printf("\t advance result = %s\n", result ? "true" : "false"); if (result) break; } assert(result); currentPoint = nextPoint; currentEdge = currentFace->GetOEdge(e)->GetOwner(); currentNdotV = ComputeSurfaceNdotV(currentEdge, currentPoint); currentFace = currentFace->GetBordingFace(e); } Vec3r endpoint; if (currentNdotV > isovalue) { real t = (isovalue - lastNdotV)/(currentNdotV - lastNdotV); endpoint = (1-t) * lastPoint + t * currentPoint; } else if (currentNdotV < -0.001) { real t = -lastNdotV/(currentNdotV - lastNdotV); // endpoint is the zero-crossing endpoint = (1-t)*lastPoint + t * currentPoint; } else endpoint = currentPoint; ViewMap * vm = ViewMap::getInstance(); vm->addDebugPoint(DebugPoint::ISOPHOTE, endpoint, startPoint); real dist = ImageSpaceDistance(startPoint, endpoint); // printf("\t result: dist = %f, lastNdotV = %f, currentNdotV = %f, numSteps = %d, currentFace = %08X\n", dist, lastNdotV, currentNdotV, numSteps, currentFace); return dist; }