function createWindowDisplayWithCoords(myFigNum, fromRowIndex, toRowIndex,...
fromColIndex,toColIndex, dataSource, createSubWindow)
global theVars;
global menubarheight;
global scrollbarwidth;
global bottompadding;
% if(createSubWindow) then "dataSource" is the figNum of the spawning window
% else "dataSource" is the adjacency matrix.
% "fromIndex" and "toIndex" are the dataindex boundaries for
% displaying a *subset* of the data
figure(myFigNum); %create and focus the desired new figure
set(myFigNum, 'Units','pixels');
%position should be 0,0, but for some reason this is too low...
set(myFigNum,'Position',[5,5,theVars(myFigNum).desiredWindowWidth,...
theVars(myFigNum).desiredWindowHeight]);
set(myFigNum,'Toolbar','none');
set(myFigNum,'CloseRequestFcn','mainFigureCloseRequest');
if(createSubWindow)
figtitle = sprintf('(Data Subset from Figure %d)',dataSource);
set(myFigNum, 'Name',figtitle);
end;
if(theVars(myFigNum).desirednumpixelspersubcell < 4)
%the 'patches' are really vertical lines which cannot be resized
set(myFigNum,'Resize','off');
end;
thebigaxishandle = axes('Visible','off','Units','pixels',...
'Position',[0, theVars(myFigNum).desiredWindowHeight-...
(theVars(myFigNum).desiredheight+bottompadding),...
theVars(myFigNum).desiredwidth,theVars(myFigNum).desiredheight+bottompadding]);
if(theVars(myFigNum).needVertScrollbar)
%calculate the sliderstepsize
totalHeightinPixels = theVars(myFigNum).desiredheight+bottompadding;
numPixelsPastWindowBottom = totalHeightinPixels -...
theVars(myFigNum).desiredWindowHeight;
squareHeight = theVars(myFigNum).origNumrows*theVars(myFigNum).desirednumpixelspersubcell...
+theVars(myFigNum).desirednumpixelsperpadding;
desiredNumVertSliderSteps = numPixelsPastWindowBottom / squareHeight;
end;
if(theVars(myFigNum).needHorizScrollbar)
totalWidthinPixels = theVars(myFigNum).desiredwidth;
numPixelsPastRightofWindow = totalWidthinPixels -...
theVars(myFigNum).desiredWindowWidth;
squareWidth = theVars(myFigNum).origNumcols*theVars(myFigNum).desirednumpixelspersubcell...
+theVars(myFigNum).desirednumpixelsperpadding;
desiredNumHorizSliderSteps = numPixelsPastRightofWindow / squareWidth;
end;
%for now, don't keep a ref to the scrollbar handles
if(theVars(myFigNum).needVertScrollbar & theVars(myFigNum).needHorizScrollbar)
%need two scrollbars
%make vertical scroller
sl=uicontrol('Style','slider','Position',...
[theVars(myFigNum).desiredWindowWidth-scrollbarwidth,0,...
scrollbarwidth,theVars(myFigNum).desiredWindowHeight],...
'SliderStep',[0.01, 1/desiredNumVertSliderSteps],...
'Callback',{@sliderCallback,thebigaxishandle, ...
myFigNum, 0}, 'Value',1); %0 callback param--> is NOT horizontal
%make horiz scroller
sl=uicontrol('Style','slider','Position',...
[0,0,theVars(myFigNum).desiredWindowWidth-scrollbarwidth,...
scrollbarwidth], 'SliderStep',[0.01, 1/desiredNumHorizSliderSteps],...
'Callback',{@sliderCallback,thebigaxishandle, ...
myFigNum, 1}, 'Value',0); %1 callback param--> IS horizontal
else %need 0 or 1 scroll bars
if(theVars(myFigNum).needHorizScrollbar)
sl=uicontrol('Style','slider','Position',...
[0,0,theVars(myFigNum).desiredWindowWidth,...
scrollbarwidth],'SliderStep',[0.01, 1/desiredNumHorizSliderSteps],...
'Callback',{@sliderCallback,thebigaxishandle, ...
myFigNum, 1}, 'Value',0); %1 callback param--> IS horizontal
elseif(theVars(myFigNum).needVertScrollbar)
sl=uicontrol('Style','slider','Position',...
[theVars(myFigNum).desiredWindowWidth-scrollbarwidth,0,...
scrollbarwidth,theVars(myFigNum).desiredWindowHeight],...
'SliderStep',[0.01, 1/desiredNumVertSliderSteps],...
'Callback',{@sliderCallback,thebigaxishandle, ...
myFigNum, 0}, 'Value',1); %0 callback param--> is NOT horizontal
end;
end;
actualwidth = theVars(myFigNum).origNumcols* ...
theVars(myFigNum).desirednumpixelspersubcell+2;%!!
actualheight = theVars(myFigNum).origNumrows* ...
theVars(myFigNum).desirednumpixelspersubcell+2;%!!
paddedwidth= actualwidth + theVars(myFigNum).desirednumpixelsperpadding;
paddedheight= actualheight + theVars(myFigNum).desirednumpixelsperpadding;
pos = paddedwidth/2; %offset to center text
if(~ createSubWindow) %we have an adj matrix
%remove the 1's on the diagonal
nondiagdata = dataSource - diag(diag(dataSource));
thedata = dataSource; %for calculating similarities
lvi = theVars(myFigNum).lastValidDataIndex;
else
lvi = theVars(dataSource).lastValidDataIndex;
end;
textDarkener = 0.9;%set to 1 to leave text colors unchanged
nextNewIndex=1; %only used if createSubWindow=1
for(i=fromRowIndex:toRowIndex)
for(j=fromColIndex:toColIndex)
box off;
coordsString = sprintf('%d,%d', i- fromRowIndex +1, j- ...
fromColIndex+1);
if(createSubWindow)
originalIndex = (i-1)*theVars(dataSource).numcols + j;
index=nextNewIndex;
nextNewIndex=nextNewIndex+1;
else
originalIndex = (i-1)*theVars(myFigNum).numcols + j;
index=originalIndex;
end;
if(originalIndex > lvi)
if(createSubWindow & theVars(myFigNum).lastValidDataIndex ~= ...
index-1)
fprintf('SOMETHING IS WRONG! lvi is %d, should be %d', ...
theVars(myFigNum).lastValidDataIndex, index-1);
end;
break; %skip the squarifying placeholder zeros
end;
if(createSubWindow)
%NOTE: the function variable originalIndex is the index of
%this elem, **relative to the spawning window**. But the value
%stored in theVars (myorigindex) is the index relative to the
%this cluster of the complete data set (ie rel to the first
%window opened)
theVars(myFigNum).theAxesHandles(index).myorigindex = ...
theVars(dataSource).theAxesHandles(originalIndex).myorigindex;
else
theVars(myFigNum).theAxesHandles(index).myorigindex = index;
end;
set(myFigNum,'CurrentAxes',thebigaxishandle); %just in case
if(isempty(theVars(myFigNum).names))
myname=num2str(index);
else
myname = theVars(myFigNum).names{index};
end;
%add titles
%NOTE: text is positioned ***relative to thebigaxis***
theVars(myFigNum).nameHandles(index)=text((j-fromColIndex)* ...
(paddedwidth)+pos,(theVars(myFigNum).desiredheight)+bottompadding...
-((i-fromRowIndex)*(paddedheight)+theVars(myFigNum).mytitlefontsize),myname,...
'FontSize',theVars(myFigNum).mytitlefontsize,'Color', ...
textDarkener * theVars(myFigNum).borderColors(i-fromRowIndex+1,...
j-fromColIndex+1,:), 'HorizontalAlignment','center',...
'VerticalAlignment','baseline', 'Units','pixels');
set(theVars(myFigNum).nameHandles(index),'Units','normalized');
%NOTE: axes are positioned ***relative to the figure***
a=axes('Units','pixels','Position',...
[(j-fromColIndex)*(paddedwidth)+...
(theVars(myFigNum).desirednumpixelsperpadding/2)...
(theVars(myFigNum).desiredWindowHeight)-((i-fromRowIndex+1)*(paddedheight))...
actualwidth actualheight]);
if(~ createSubWindow)
%do NOT include myself in my associates (myassocI)
theVars(myFigNum).theAxesHandles(index).myassocI = ...
find(nondiagdata(index,:) > theVars(myFigNum).visThreshold);
adjacentPatchesToDraw = dataSource(index,:);
adjacentPatchesToDraw = adjacentPatchesToDraw > theVars(myFigNum).visThreshold;
else %reconstruct from parent's adjacency info
adjacentPatchesToDraw = zeros(1,theVars(myFigNum).origNumcols*...
theVars(myFigNum).origNumrows);%some of these zeros
%may be left as padding
switch(theVars(myFigNum).simMode)
case 1
adjacentPatchesToDraw(1:size(theVars(myFigNum).theFullAbsSimilarityMatrix,1)) = ...
theVars(myFigNum).theFullAbsSimilarityMatrix(...
theVars(myFigNum).theAxesHandles(index).myorigindex,:);
case 2
adjacentPatchesToDraw(1:size(theVars(myFigNum).theFullRelSimilarityMatrix,1)) = ...
theVars(myFigNum).theFullRelSimilarityMatrix(...
theVars(myFigNum).theAxesHandles(index).myorigindex,:);
case 3
adjacentPatchesToDraw(1:size(theVars(myFigNum).theFullRel2SimilarityMatrix,1)) = ...
theVars(myFigNum).theFullRel2SimilarityMatrix(...
theVars(myFigNum).theAxesHandles(index).myorigindex,:);
case 4
adjacentPatchesToDraw(1:size(theVars(myFigNum).theFullAbsSimSimMatrix,1)) = ...
theVars(myFigNum).theFullAbsSimSimMatrix(...
theVars(myFigNum).theAxesHandles(index).myorigindex,:);
case 5
adjacentPatchesToDraw(1:size(theVars(myFigNum).theFullRelSimSimMatrix,1)) = ...
theVars(myFigNum).theFullRelSimSimMatrix(...
theVars(myFigNum).theAxesHandles(index).myorigindex,:);
case 6
adjacentPatchesToDraw(1:size(theVars(myFigNum).theFullRel2SimSimMatrix,1)) = ...
theVars(myFigNum).theFullRel2SimSimMatrix(...
theVars(myFigNum).theAxesHandles(index).myorigindex,:);
end;
adjacentPatchesToDraw = adjacentPatchesToDraw > theVars(myFigNum).visThreshold;
%assocI is relative only to the parent of the spawnee, not
%the original ancestor (ie. in the case where the parent was also spawned)
origAssociates = adjacentPatchesToDraw(theVars(myFigNum).inboundsIndexes);
origAssociates(index)=0; %remove self-adjacency
theVars(myFigNum).theAxesHandles(index).myassocI = ...
find(origAssociates);%nonzero vals
end;
[grayboxhandle,greymaphandle,whitemaphandle] = makeConnectionMap(myFigNum, ...
reshape(adjacentPatchesToDraw,theVars(myFigNum).origNumcols, ...
theVars(myFigNum).origNumrows)', ...
theVars(myFigNum).borderColors(i-fromRowIndex+1,j-fromColIndex+1,:));
theVars(myFigNum).theAxesHandles(index).mybg = grayboxhandle;
theVars(myFigNum).theAxesHandles(index).mymap = greymaphandle;
theVars(myFigNum).theAxesHandles(index).myhilitemap = whitemaphandle;
theVars(myFigNum).theAxesHandles(index).myhandle = a;
theVars(myFigNum).theAxesHandles(index).numvisiblelevels = 1;
theVars(myFigNum).theAxesHandles(index).isdoneexpanding = 0;
theVars(myFigNum).theAxesHandles(index).latestlevelI={};
set(a,'Units','normalized');
theVars(myFigNum).theAxesHandles(index).coordsText = ...
text(0.5,0.5,coordsString,'HorizontalAlignment','center', ...
'VerticalAlignment','middle','FontSize',15,'Units','normalized',...
'HitTest','off','Visible','off', 'HandleVisibility','off');
end;
end;
set(thebigaxishandle,'HandleVisibility','off');
set(thebigaxishandle,'Units','normalized'); %to allow the text to scale
numinputs = theVars(myFigNum).lastValidDataIndex;
for(i=1:numinputs)
%this 'set ButtonDownFcn' has to be done AFTER the above loop
set(theVars(myFigNum).theAxesHandles(i).mybg,'ButtonDownFcn',{@clickCallback, ...
theVars(myFigNum).theAxesHandles(i).myassocI, i,myFigNum});
set(theVars(myFigNum).theAxesHandles(i).mymap,'ButtonDownFcn',{@clickMapCallback, ...
theVars(myFigNum).theAxesHandles(i).myassocI, i,...
theVars(myFigNum).theAxesHandles(i).mybg,myFigNum});
set(theVars(myFigNum).theAxesHandles(i).myhilitemap,'ButtonDownFcn',{@clickMapCallback, ...
theVars(myFigNum).theAxesHandles(i).myassocI, i,...
theVars(myFigNum).theAxesHandles(i).mybg,myFigNum});
end;
%set up the main figure to catch keypresses
set(myFigNum,'KeyPressFcn',{@keyPressCallback,myFigNum})