1## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com> 2## 3## This program is free software; you can redistribute it and/or modify it under 4## the terms of the GNU General Public License as published by the Free Software 5## Foundation; either version 3 of the License, or (at your option) any later 6## version. 7## 8## This program is distributed in the hope that it will be useful, but WITHOUT 9## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 11## details. 12## 13## You should have received a copy of the GNU General Public License along with 14## this program; if not, see <http://www.gnu.org/licenses/>. 15 16## -*- texinfo -*- 17## @deftypefn {Function File} {@var{J} =} qtsetblk (@var{I}, @var{S}, @var{dim}, @var{vals}) 18## Set block values in a quadtree decomposition. 19## 20## J=qtsetblk(I,S,dim,vals) sets all the @var{dim}-by-@var{dim} blocks 21## in the quadtree decomposition (@var{S} returned by qtdecomp) of 22## @var{I} to @var{dim}-by-@var{dim} blocks in @var{vals}, which is 23## itself a @var{dim}-by-@var{dim}-by-k array. k is the number of 24## @var{dim}-by-@var{dim} blocks in the quadtree decomposition. 25## @seealso{qtdecomp, qtgetblk} 26## @end deftypefn 27 28function J = qtsetblk (I, S, dim, vals) 29 if (nargin != 4) 30 print_usage; 31 endif 32 33 ## get blocks 34 [ii,ji,v]=find(S); 35 36 ## filter the ones which match dim 37 idx=find(v==dim); 38 if(size(vals,3)<length(idx)) ## we won't complain if k>num blocks 39 error("qtsetblk: k (vals 3rd dimension) is not equal to number of blocks."); 40 endif 41 ii=ii(idx); 42 ji=ji(idx); 43 44 ## calc end vertex 45 ie=ii+dim-1; 46 je=ji+dim-1; 47 48 J=I; 49 for b=1:length(idx) 50 J(ii(b):ie(b),ji(b):je(b))=vals(:,:,b); 51 endfor 52endfunction 53 54%!demo 55%! J=qtsetblk(eye(4),qtdecomp(eye(4)),2,ones(2,2,2)) 56%! % Sets upper-right and lower-left blocks of 2*2 zeros to ones 57 58%!shared A, S 59%! A=[ 1, 4, 2, 5,54,55,61,62; 60%! 3, 6, 3, 1,58,53,67,65; 61%! 3, 6, 3, 1,58,53,67,65; 62%! 3, 6, 3, 1,58,53,67,65; 63%! 23,42,42,42,99,99,99,99; 64%! 27,42,42,42,99,99,99,99; 65%! 23,22,26,25,99,99,99,99; 66%! 22,22,24,22,99,99,99,99]; 67%! S = qtdecomp (A, 10); 68 69%!test 70%! R=A; 71%! vals=zeros(4,4,2); 72%! vals(:,:,1)=reshape([1:16],4,4); 73%! vals(:,:,2)=reshape([21:36],4,4); 74%! R(1:4,1:4)=reshape([1:16],4,4); 75%! R(5:8,5:8)=reshape([21:36],4,4); 76%! assert(qtsetblk(A,S,4,vals),R); 77 78%!test 79%! R=A; 80%! R(1:4,5:8)=1; 81%! R(7:8,1:4)=1; 82%! R(5:6,3:4)=1; 83%! assert(qtsetblk(A,S,2,ones(2,2,7)),R); 84 85%!test 86%! R=A; 87%! R(5:6,1:2)=10; 88%! assert(qtsetblk(A,S,1,ones(1,1,4)*10),R); 89