Z3i::DigitalSet linkTwoPointsWithTangents(const Z3i::Point& start, const Z3i::Point& end, const Z3i::RealPoint& tStart, const Z3i::RealPoint& tEnd, const Domain& domain) { Z3i::DigitalSet aSet(domain); Z3i::RealPoint vector = tStart; Z3i::RealPoint current = start; double initialDistance = Z3i::l2Metric(start, end)/2; while (Z3i::l2Metric(current, end) > sqrt(3) && Z3i::l2Metric(current, end) <= Z3i::l2Metric(start, end)) { current += vector; aSet.insert(current); double distanceToStart = std::abs(start.norm()- current.norm()) - initialDistance; if (distanceToStart < 0) distanceToStart = 1; double distanceToEnd = -std::abs(end.norm()- current.norm()) + initialDistance; double weightStart = 1/distanceToStart; double weightEnd; if (distanceToEnd < 0) weightEnd = 0; else weightEnd = 1/distanceToEnd; vector = ((weightStart * tStart + weightEnd * tEnd) / (weightStart + weightEnd)).getNormalized(); } return aSet; }
void computerBasicNormalsFromHeightField(const TImage &anHeightMap, TImageVector &vectorField) { for(typename TImage::Domain::ConstIterator it = anHeightMap.domain().begin(); it != anHeightMap.domain().end(); it++){ if(anHeightMap.domain().isInside(*it+Z2i::Point::diagonal(1))&& anHeightMap.domain().isInside(*it-Z2i::Point::diagonal(1))){ double dx = (anHeightMap(*it-Z2i::Point(1,0))-anHeightMap(*it+Z2i::Point(1,0)))/2.0; double dy = (anHeightMap(*it-Z2i::Point(0,1))-anHeightMap(*it+Z2i::Point(0,1)))/2.0; Z3i::RealPoint n (dx, dy, 1); n /= n.norm(); vectorField.setValue(*it,n); } } }