+//--------------------------------------------------------------------
+/**
+ Start from the pixel "index" in the image "skeleton" and track the
+ path from neighbor pixels. Put the tracked path in the tree at the
+ currentNode position. Label is used to mark the FG pixel as already
+ visited. Progress recursively when several neighbors are found.
+ **/
+template <class ImageType>
+void
+clitk::ExtractAirwaysTreeInfoFilter<ImageType>::
+TrackFromThisIndex2(ImageIndexType index, ImagePointer skeleton,
+ ImagePixelType label,
+ typename FullTreeType::iterator currentNode,
+ typename StructuralTreeType::iterator currentSNode)
+{
+ // Create NeighborhoodIterator
+ typedef itk::NeighborhoodIterator<ImageType> NeighborhoodIteratorType;
+ typename NeighborhoodIteratorType::SizeType radius;
+ radius.Fill(1);
+ NeighborhoodIteratorType nit(radius, skeleton, skeleton->GetLargestPossibleRegion());
+
+ // Track
+ std::vector<typename NeighborhoodIteratorType::IndexType> listOfTrackedPoint;
+ bool stop = false;
+ while (!stop) {
+ nit.SetLocation(index);
+ nit.SetCenterPixel(label);
+ listOfTrackedPoint.clear();
+ for(unsigned int i=0; i<nit.Size(); i++) {
+ if (i != nit.GetCenterNeighborhoodIndex ()) { // Do not observe the current point
+ if (nit.GetPixel(i) == GetForegroundValue()) {
+ // if pixel value is FG, we keep this point
+ listOfTrackedPoint.push_back(nit.GetIndex(i));
+ }
+ }
+ }
+ // If only neighbor is found, we keep the point and continue
+ if (listOfTrackedPoint.size() == 1) {
+ FullTreeNodeType n;
+ index = n.index = listOfTrackedPoint[0];
+ skeleton->TransformIndexToPhysicalPoint(n.index, n.point);
+ currentNode = mFullSkeletonTree.append_child(currentNode, n);
+ skeleton->SetPixel(n.index, label); // change label in skeleton image
+ }
+ else {
+ if (listOfTrackedPoint.size() >= 2) {
+ for(uint i=0; i<listOfTrackedPoint.size(); i++) {
+ FullTreeNodeType n;
+ n.index = listOfTrackedPoint[i];
+ skeleton->TransformIndexToPhysicalPoint(n.index, n.point);
+ typename FullTreeType::iterator node = mFullSkeletonTree.append_child(currentNode, n);
+ StructuralTreeNodeType sn;
+ sn.index = listOfTrackedPoint[i];
+ skeleton->TransformIndexToPhysicalPoint(sn.index, sn.point);
+ typename StructuralTreeType::iterator snode = mStructuralSkeletonTree.append_child(currentSNode, sn);
+ TrackFromThisIndex2(listOfTrackedPoint[i], skeleton, label, node, snode);
+ }
+ }
+ stop = true; // this it the end of the tracking
+ } // end else
+ } // end while stop
+}
+//--------------------------------------------------------------------
+