Commit dd6c4f22 authored by Andrew Cohen's avatar Andrew Cohen

cellFeatures : render feature as color, leverjs,serverHelper -- cellFeatures...

cellFeatures : render feature as color, leverjs,serverHelper -- cellFeatures force array even for 1 element,
parent 36262e17
......@@ -498,12 +498,21 @@ function LoadHulls_3D(time,channelList,fnCallback)
});
} // LoadHulls_3d
function dbLoadHulls(lDB,time,fnCallback)
function dbLoadHulls(lDB,time,CONSTANTS,fnCallback)
{
var tNewCells=[];
var sqlCmd = "SELECT cellID, centroid, surface, channel, area,tblTracks.trackID, tblColors.jsColor as jsColor FROM tblCells " +
"INNER JOIN tblTracks ON tblCells.trackID=tblTracks.trackID "+
"INNER JOIN tblColors ON tblTracks.idxColor=tblColors.rowID WHERE time=?";
var sqlCmd;
if (1)
sqlCmd= "SELECT tblCells.cellID, centroid, surface, channel, area,tblTracks.trackID, tblColors.jsColor as jsColor,tblCellFeatures.* FROM "+
" tblCellFeatures INNER JOIN tblCells on tblCells.cellID=tblCellFeatures.cellID "+
" INNER JOIN tblTracks ON tblCells.trackID=tblTracks.trackID "+
"INNER JOIN tblColors ON tblTracks.idxColor=tblColors.rowID WHERE time=?";
else
sqlCmd= "SELECT cellID, centroid, surface, channel, area,tblTracks.trackID, tblColors.jsColor as jsColor FROM tblCells " +
"INNER JOIN tblTracks ON tblCells.trackID=tblTracks.trackID "+
"INNER JOIN tblColors ON tblTracks.idxColor=tblColors.rowID WHERE time=?";
lDB.all(sqlCmd, time, function(err, rows) {
if (err !== null) {
console.error(err.message);
......@@ -523,7 +532,6 @@ function dbLoadHulls(lDB,time,fnCallback)
// if (-1===newCell.surface[b][0] && -1===newCell.surface[b][1])
// newCell.surface[b]=[NaN,NaN];
// }
}
else newCell.surface=JSON.parse(row.surface);
newCell.jsColor = JSON.parse(row.jsColor);
......@@ -534,6 +542,14 @@ function dbLoadHulls(lDB,time,fnCallback)
else
newCell.channel=row.channel;
// copy over cellFeatures
if (CONSTANTS!==undefined && CONSTANTS.cellFeatures!=undefined) {
for (var i=0;i<CONSTANTS.cellFeatures.length;i++) {
newCell[CONSTANTS.cellFeatures[i].name]=row[CONSTANTS.cellFeatures[i].name];
}
}
tNewCells.push(newCell);
})
}
......@@ -549,7 +565,7 @@ function LoadHulls(time,fnCallback)
tCells[time]=[];
gbLoadTextureInProgress=true;
if (Is3D()) {
if (Is3D()) {``
LoadHulls_3D(time,undefined,fnCallback);
return;
}
......@@ -568,7 +584,7 @@ function LoadHulls(time,fnCallback)
hullsReq.send();
}
else {
dbLoadHulls(gDB,time,function(tNewCells){
dbLoadHulls(gDB,time,CONSTANTS,function(tNewCells){
tCells[time]=tNewCells;
updateTimeButton();
LoadTextureImages(fnCallback);
......
......@@ -872,6 +872,11 @@ class LeverDB {
if (undefined===CONSTANTS.segmentationData) {
CONSTANTS.segmentationData={};
}
if (CONSTANTS.cellFeatures!=undefined && CONSTANTS.cellFeatures.length===undefined) {
var cf=CONSTANTS.cellFeatures;
CONSTANTS.cellFeatures=[];
CONSTANTS.cellFeatures.push(cf);
}
CONSTANTS.segmentationData.nSegmentations=rows[0].nSegmentations;
CONSTANTS.segmentationData.maxSegmentationTime=rows[0].maxSegmentationTime;
if (null===CONSTANTS.segmentationData.maxSegmentationTime)
......
......@@ -51,7 +51,7 @@ function setPopupTID(tid,bScroll=false)
}
}
lineagePopup.style.top=Math.round(y)+"px";
lineagePopup.style.left=x+"px";
lineagePopup.style.left=x+lineageDiv.scrollLeft+"px";
var context = lineagePopup.getContext("2d");
context.clearRect(0, 0, lineagePopup.width,lineagePopup.height);
......@@ -1009,21 +1009,29 @@ function toggleShowLineage()
function toggleShowFeature(nFeature)
{
console.log('show feature')
var bChecked=document.getElementById('featureShow_'+nFeature).checked;
if (undefined===CONSTANTS.cellFeatures.length) {
if (nFeature!=0) {
console.error('bad feature id');
return
}
CONSTANTS.cellFeatures.bShow=bChecked;
}
else {
CONSTANTS.cellFeatures[nFeature].bShow=bChecked;
}
CONSTANTS.cellFeatures[nFeature].bShow=bChecked;
toggleShowLineage();
} // toggleShowFeatures
function toggleRenderFeature(nFeature)
{
var bChecked=document.getElementById('featureRender_'+nFeature).checked;
// only one checked at a time
if (true==bChecked) {
for (var i=0;i<CONSTANTS.cellFeatures.length;i++) {
CONSTANTS.cellFeatures[nFeature].bRender=false;
}
}
CONSTANTS.cellFeatures[nFeature].bRender=bChecked;
// redraw
reDraw(false);
} // toggleRenderFeature
function standardize_color(str)
{
var ctx = document.createElement('canvas').getContext('2d');
......@@ -1065,6 +1073,25 @@ function changeFeatureColor(i)
writeViewConstantsToDB(); // see view.js
} // changeFeatureColor
var gFeatureMinMax;
function setFeatureMinMaX(cxFeatures,i)
{
if (undefined===gDB)
return; // don't have one handy -- need the global db for this
var sqlCmd='select min('+cxFeatures[i].name+') as fmin, max('+cxFeatures[i].name+') as fmax from tblCellFeatures';
lDB.all(sqlCmd,function(err,featureMinMax) {
if (err) {
console.error(err.message);
return;
}
else {
gFeatureMinMax[i,0]=featureMinMax.fmin;
gFeatureMinMax[i,0]=featureMinMax.fmax;
}
});
} // setFeatureMinMaX
function lineageShowFeatures(cx)
{
if (undefined==cx)
......@@ -1079,17 +1106,20 @@ function lineageShowFeatures(cx)
var cxFeatures=cxGetCellFeatures(cx);
gFeatureMinMax=[];
for (var i=0;i<cxFeatures.length;i++) {
if (undefined==cxFeatures[i].bShow)
cxFeatures[i].bShow=true;
gFeatureMinMax.push([0,2]); // default value
setFeatureMinMaX(cxFeatures,i);
var newFeature=document.createElement('div');
newFeature.id='cellFeatures_'+i;
var color=standardize_color(cxFeatures[i].color);
// feature is index,color,show,delete
newFeature.innerHTML=cxFeatures[i].name+' <input type="color" value="'+color+
'" id="featureColor_'+i+'" onChange="changeFeatureColor('+i+')" /> show <input type="checkbox" '+
' onclick="toggleShowFeature('+i+')" id=featureShow_'+i+' />';
'" id="featureColor_'+i+'" onChange="changeFeatureColor('+i+')" /> on_lineage <input type="checkbox" '+
' onclick="toggleShowFeature('+i+')" id=featureShow_'+i+'> on_image <input type="checkbox" '+
' onclick="toggleRenderFeature('+i+')" id=featureRender_'+i+'>';
divFeatures.appendChild(newFeature);
document.getElementById('featureShow_'+i).checked=cxFeatures[i].bShow;
}
......
......@@ -681,6 +681,16 @@ function drawHulls(tHulls)
var screenPt;
context.lineWidth=2;
var nFeature=-1;
if (undefined!==CONSTANTS.cellFeatures) {
for (var i=0;i<CONSTANTS.cellFeatures.length;i++) {
if (CONSTANTS.cellFeatures[i].bRender) {
nFeature=i;
break;
}
}
}
for (var i = 0; i < tHulls.length; i++) {
if (isNaN(tHulls[i].channel)){
......@@ -723,7 +733,7 @@ function drawHulls(tHulls)
}
// color by feature?
if (0 && CONSTANTS.cellFeatures!==undefined) {
if (nFeature>=0) {
var fval=tHulls[i][CONSTANTS.cellFeatures[0].name]/2;
color = getHTMLcolor([fval,fval,fval]);
}
......
......@@ -67,6 +67,11 @@ function getCells(req,res)
CONSTANTS=JSON.parse(rows[0].jsConstants);
if ('number'!==typeof(CONSTANTS.imageData.Dimensions[0]))
CONSTANTS.imageData.Dimensions=CONSTANTS.imageData.Dimensions[0];
if (CONSTANTS.cellFeatures!=undefined && CONSTANTS.cellFeatures.length===undefined) {
cf=CONSTANTS.cellFeatures;
CONSTANTS.cellFeatures=[];
CONSTANTS.cellFeatures.push(cf);
}
if (CONSTANTS.imageData.Dimensions[2]>1) {
// 3d
const loadHulls=require('./LoadHulls.js');
......@@ -81,7 +86,7 @@ function getCells(req,res)
}
else {
// 2d
loadHulls.dbLoadHulls(lDB,time,function(tCells){
loadHulls.dbLoadHulls(lDB,time,CONSTANTS,function(tCells){
res.send(JSON.stringify(tCells));
lDB.close();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment