Diff of /wavelets/wfbtmanip/depthIndex2NodeNo.m [e1f90e] .. [191c94]  Maximize  Restore

Switch to side-by-side view

--- a/wavelets/wfbtmanip/depthIndex2NodeNo.m
+++ b/wavelets/wfbtmanip/depthIndex2NodeNo.m
@@ -1,4 +1,4 @@
-function [nodeNo,nodeChildIdx] = depthIndex2NodeNo(d,k,treeStruct)
+function [nodeNo,nodeChildIdx] = depthIndex2NodeNo(d,k,wt)
 
 if(d==0)
     nodeNo=0;
@@ -7,48 +7,93 @@
 end
 
 % find ordered nodes at depth d-1
-nodesNo = getNodesInDepth(d,treeStruct);
+nodesNo = getNodesInDepth(d,wt);
 if(isempty(nodesNo))
    error('%s: Depth of the tree is less than given d.',mfilename); 
 end
-ktemp = k;
+
 % k is index in children of ordered nodes at depth d
-for ii=1:length(nodesNo)
-    chNo = max([length(treeStruct.nodes{nodesNo(ii)}.g), length(treeStruct.nodes{nodesNo(ii)}.h)]);
-    %chNo = length(treeStruct.nodes{nodesNo(ii)});
-    if(ktemp<chNo)
-        nodeChildIdx = ktemp+1;
-        nodeNo = nodesNo(ii);
-        return;
-    else
-        ktemp = ktemp-chNo;
-    end
+
+nodeNo = zeros(numel(k),1);
+nodeChildIdx = zeros(numel(k),1);
+chNo = cumsum(cellfun( @(nEl) length(nEl.g),wt.nodes(nodesNo)));
+chNoZ = [0;chNo(:)];
+
+for kIdx=1:numel(k)
+    ktmp = k(kIdx);
+    idx = find(chNo>ktmp,1);
+    if isempty(idx)
+       error('%s: Index k=%i out of bounds.',mfilename,ktmp); 
+    end    
+    nodeNo(kIdx) = nodesNo(idx);
+    nodeChildIdx(kIdx) = ktmp-chNoZ(idx)+1;
 end
 
-error('%s: Index k out of bounds.',mfilename);
+% ktemp = k;
+% chNo = cellfun( @(nEl) numel(nEl.g),wt.nodes(nodesNo));
+% for ii=1:length(nodesNo)
+%     if(ktemp<chNo(ii))
+%         nodeChildIdx = ktemp+1;
+%         nodeNo = nodesNo(ii);
+%         if mynodeNo~=nodeNo || mynodeChildIdx ~= nodeChildIdx
+%             error('mas to tu spatne');
+%         end
+%         return;
+%     else
+%         ktemp = ktemp-chNo(ii);
+%     end
+% end
+% error('%s: Index k out of bounds.',mfilename);
 
 
-function nodd = getNodesInDepth(d,treeStruct)
-% find all nodes with d steps to the root ordered
-nodd = [];
-toGoTrough = {};
 
 
-   nodeNo = find(treeStruct.parents==0);
-   toGoTrough = cell(d+1,1);
-   toGoTrough{1} = nodeNo;
-   tempd = 1;
+function nodd = getNodesInDepth(d,wt)
+% find all nodes with d steps to the root ordered
+if d==1
+    % return root
+    nodd = find(wt.parents==0);
+    return;
+end    
 
-
-while(tempd<d)
-    for jj=1:length(toGoTrough{tempd})
-       actNod = toGoTrough{tempd}(jj);
-       childrenIdx = find(treeStruct.children{actNod}~=0);
-       ch = treeStruct.children{actNod}(childrenIdx);
-       toGoTrough{tempd+1} = [toGoTrough{tempd+1},ch];
-    end
-
+nbf = nodesBForder(wt);
+nbfTmp = nbf;
+tempd = 0;
+while tempd<d
+    nbf(nbfTmp==0) = [];
+    nbfTmp(nbfTmp==0) = [];
+    nbfTmp = wt.parents(nbfTmp);
     tempd = tempd+1;
 end
+nodd = nbf(nbfTmp==0);
 
-nodd=toGoTrough{d};
+% 
+% nbfPar = wt.parents(nbf);
+% 
+% for ii=1:numel(nbf)
+%    
+% end
+
+% nodd = [];
+% toGoTrough = {};
+% 
+% 
+%    nodeNo = find(wt.parents==0);
+%    toGoTrough = cell(d+1,1);
+%    toGoTrough{1} = nodeNo;
+%    tempd = 1;
+% 
+% 
+% while(tempd<d)
+%     
+%     for jj=1:length(toGoTrough{tempd})
+%        actNod = toGoTrough{tempd}(jj);
+%        childrenIdx = find(wt.children{actNod}~=0);
+%        ch = wt.children{actNod}(childrenIdx);
+%        toGoTrough{tempd+1} = [toGoTrough{tempd+1},ch];
+%     end
+% 
+%     tempd = tempd+1;
+% end
+% 
+% nodd=toGoTrough{d};