void AxisInfo::displayAxis(spGframe_t gf) { initAxis(gf); spViewInfo_t view = gf->getFirstView(); if(view == nullView) return; if(magnetFrame && view->isOblique()) return; // draw center lines drawCenterLines(gf); // draw axes if(!showAxis) return; if(!canShowAxis(gf)) return; if(isDisplayed == 0) return; // set offset and size horizSize = getReal("aipAxisGeom",INDEX_WIDTH,0.6); vertSize = getReal("aipAxisGeom",INDEX_HEIGHT,0.6); westX = getReal("aipAxisGeom",INDEX_WX,0.0); westY = getReal("aipAxisGeom",INDEX_WY,0.0); eastX = getReal("aipAxisGeom",INDEX_EX,0.0); eastY = getReal("aipAxisGeom",INDEX_EY,0.0); southX = getReal("aipAxisGeom",INDEX_SX,0.0); southY = getReal("aipAxisGeom",INDEX_SY,0.0); northX = getReal("aipAxisGeom",INDEX_NX,0.0); northY = getReal("aipAxisGeom",INDEX_NY,0.0); if(isDisplayed & AX_WEST) displayAxis_west(gf, inflg); if(isDisplayed & AX_EAST) displayAxis_east(gf, inflg); if(isDisplayed & AX_SOUTH) displayAxis_south(gf, inflg); if(isDisplayed & AX_NORTH) displayAxis_north(gf, inflg); }
int AxisInfo::getPositionString(spGframe_t gf, int x, int y, char *str) { if(getReal("aipShowPosition",1) < 1 && getReal("aipShowROIPos",0) < 1) return 0; if(!canShowLabel(gf, x, y)) return 0; spViewInfo_t view = gf->getFirstView(); if(view == nullView) return 0; units = getString("aipUnits","cm"); if(units == "pixel") { sprintf(str,"(%d,%d)",x,y); } else if(units == "pix") { double dx,dy; //pixToData(view, (double)x, (double)y, dx,dy); view->pixToData((double)x, (double)y, dx,dy); sprintf(str,"(%d,%d)",(int)dx,(int)dy); } else { double u[3]; /* pixToLogical(view,(double)x, (double)y, 0.0,u[0],u[1],u[2]); if(units == "mm") sprintf(str,"(%.1f,%.1f)",u[0]*10,u[1]*10); else sprintf(str,"(%.2f,%.2f)",u[0],u[1]); */ if(magnetFrame) { view->pixToMagnet((double)x, (double)y, 0.0,u[0],u[1],u[2]); if(units == "mm") sprintf(str,"(%.1f,%.1f,%.1f)",u[0]*10,u[1]*10,u[2]*10); else sprintf(str,"(%.2f,%.2f,%.2f)",u[0],u[1],u[2]); } else { view->pixToUser((double)x, (double)y, 0.0,u[0],u[1],u[2]); if(units == "mm") sprintf(str,"(%.1f,%.1f)",u[0]*10,u[1]*10); else sprintf(str,"(%.2f,%.2f)",u[0],u[1]); } } return 1; }
/* * Constructor from data location. * Assume gf is valid. */ Line::Line(spGframe_t gf, spCoordVector_t dpts, bool pixflag) : Roi() { created_type = ROI_LINE; init(gf, 2); if(pixflag) { pntData = dpts; setMagnetCoordsFromPixels(); // TODO: Should be set from data } else { magnetCoords = dpts; setDataPntsFromMagnet(); } setPixPntsFromData(); // Sets pntPix, npnts, min/max gf->addRoi(this); pntData->name = "Line"; magnetCoords->name="Line"; }
/* * Constructor from data location. * Assume gf is valid. */ Polyline::Polyline(spGframe_t gf, spCoordVector_t dpts, bool pixflag) : Polygon() { init(gf, dpts->coords.size()); created_type = ROI_POLYGON_OPEN; closed = false; initEdgelist(); if(pixflag) { pntData = dpts; setMagnetCoordsFromPixels(); // TODO: Should be set from data } else { magnetCoords = dpts; setDataPntsFromMagnet(); } setPixPntsFromData(); // Sets pntPix, npnts, min/max gf->addRoi(this); pntData->name = "Polyline"; magnetCoords->name="Polyline"; }
/* * Constructor from data location. * Assume gf is valid. */ Point::Point(spGframe_t gf, spCoordVector_t dpts, bool pixflag) : Roi() { init(gf, 1); created_type = ROI_POINT; myID = ++id; // Unique ID for this Point ROI // note: dpts is in magnet frame if(pixflag) { pntData = dpts; setMagnetCoordsFromPixels(); // TODO: Should be set from data } else { magnetCoords = dpts; setDataPntsFromMagnet(); } setPixPntsFromData(); // Sets pntPix, npnts, min/max gf->addRoi(this); pntData->name = "Point"; magnetCoords->name="Point"; }
void AxisInfo::displayAxis_south(spGframe_t gf, bool inflg) { spViewInfo_t view = gf->getFirstView(); if(view == nullView) return; int xoff = (int)(pixstx + 0.5*pixwd + pixwd * southX); int yoff; if(inflg) yoff = (int)(pixsty + pixht + pixht * southY - 3); else yoff = (int)(pixsty + pixht + pixht * southY - axisSize); int minpixx = (int)(xoff - pixwd * horizSize/2); int maxpixx = (int)(xoff + pixwd * horizSize/2 - 3); if(!inflg && horizSize == 1.0 && (isDisplayed & AX_WEST)) minpixx += axisSize; if(!inflg && horizSize == 1.0 && (isDisplayed & AX_EAST)) maxpixx -= axisSize; int tickpix; if(inflg) tickpix = -10; else tickpix = 10; drawHorizAxis(gf, xoff, yoff, minpixx, maxpixx, tickpix); }
void AxisInfo::displayAxis_east(spGframe_t gf, bool inflg) { spViewInfo_t view = gf->getFirstView(); if(view == nullView) return; int xoff; if(inflg) xoff = (int)(pixstx + pixwd + pixwd * eastX - 3); else xoff = (int)(pixstx + pixwd + pixwd * eastX - axisSize); int yoff = (int)(pixsty + 0.5*pixht + pixht * eastY); int minpixy = (int)(yoff - pixht * vertSize/2); int maxpixy = (int)(yoff + pixht * vertSize/2 - 3); if(!inflg && vertSize == 1.0 && (isDisplayed & AX_NORTH)) minpixy += axisSize; if(!inflg && vertSize == 1.0 && (isDisplayed & AX_SOUTH)) maxpixy -= axisSize; int tickpix; if(inflg) tickpix = -10; else tickpix = 10; drawVertAxis(gf, xoff, yoff, minpixy, maxpixy, tickpix); }
// called first void AxisInfo::initAxis(spGframe_t gf) { showAxis = false; if(getReal("aipAxis",INDEX_SHOW,0) > 0) showAxis = true; isDisplayed = 0; if(getReal("aipAxis",INDEX_WEST,0) > 0) isDisplayed |= AX_WEST; if(getReal("aipAxis",INDEX_EAST,0) > 0) isDisplayed |= AX_EAST; if(getReal("aipAxis",INDEX_SOUTH,0) > 0) isDisplayed |= AX_SOUTH; if(getReal("aipAxis",INDEX_NORTH,0) > 0) isDisplayed |= AX_NORTH; if(getString("aipAxisRef","logical") == "magnet") magnetFrame=true; else magnetFrame= false; // may set inflg here by a parameter if(getReal("aipAxis",INDEX_TICK,0) > 0) inflg = false; else inflg = true; int fov = false; // use image size or frame size if(getReal("aipAxis",INDEX_FOV,1) > 0) fov = true; if(getReal("aipAxis",INDEX_CROSS,1) > 0 && getReal("aipAxis",INDEX_SHOW,0) > 0 && isDisplayed == (AX_WEST | AX_EAST | AX_SOUTH | AX_NORTH) ) crosshair=true; else crosshair=false; spViewInfo_t view = gf->getFirstView(); if(fov && view != nullView) { pixstx = view->pixstx; pixsty = view->pixsty; pixwd = view->pixwd; pixht = view->pixht; } else { pixstx = gf->pixstx+2; pixsty = gf->pixsty+2; pixwd = gf->pixwd-2; pixht = gf->pixht-2; } }
int AxisInfo::getDistanceString(spGframe_t gf, int x1, int y1, int x2, int y2, char *str, double dis) { if(getReal("aipShowPosition",1) < 1 && getReal("aipShowROIPos",0) < 1) return 0; if(!canShowLabel(gf, x1, y1)) return 0; if(!canShowLabel(gf, x2, y2)) return 0; spViewInfo_t view = gf->getFirstView(); if(view == nullView) return 0; units = getString("aipUnits","cm"); if(units == "pixel") { dis = sqrt((double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))); sprintf(str,"%d",(int)dis); } else if(units == "pix") { double dx1,dy1,dx2,dy2; if(dis<=0.0) { pixToData(view, (double)x1, (double)y1, dx1,dy1); pixToData(view, (double)x2, (double)y2, dx2,dy2); dis = sqrt((double)((dx1-dx2)*(dx1-dx2)+(dy1-dy2)*(dy1-dy2))); } sprintf(str,"%d",(int)dis); } else { double ux1,uy1,uz1,ux2,uy2,uz2; if(dis<=0.0) { pixToUser(view,(double)x1, (double)y1, 0.0,ux1,uy1,uz1); pixToUser(view,(double)x2, (double)y2, 0.0,ux2,uy2,uz2); dis = sqrt((ux1-ux2)*(ux1-ux2)+(uy1-uy2)*(uy1-uy2)); } if(units == "mm") { sprintf(str,"%.1f",dis*10); } else { sprintf(str,"%.2f",dis); } } return 1; }
void AxisInfo::drawString(spGframe_t gf, char *str, int x, int y, int color, int direction) { spViewInfo_t view = gf->getFirstView(); if(view == nullView) return; int ascent; int descent; int cwd; int cht; // Get width and height of a character (cwd, cht) GraphicsWin::getTextExtents(str, 12, &ascent, &descent, &cwd); cht = ascent + descent; cwd = (int)(cwd*12.0/14.0); int xmin = pixstx; int xmax = pixstx + pixwd; int ymin = pixsty; int ymax = pixsty + pixht; if(direction & AX_WEST) { x -= (cwd+2); y += (int)(0.5*cht); } else if(direction & AX_SOUTH) { x -= (int)(0.5*cwd); y += (int)(0.5*cht); } else if(direction & AX_NORTH) { x -= (int)(0.5*cwd); y -= (int)(0.5*cht); } else { // east x += 2; y += (int)(0.5*cht); } if(x <= xmin || x+cwd+1 >= xmax) return; if(y >=ymax || y-cht <= ymin) return; GraphicsWin::drawString(str, x, y, color, 0,0,0); }
void AxisInfo::drawCenterLines(spGframe_t gf) { int flag = getReal("aipShowCenter",0); if(flag <= 0) return; spViewInfo_t view = gf->getFirstView(); if(view == nullView) return; int color = axisColor; double px,py,pz; double ux=0.0,uy=0.0,uz=0.0; if(flag > 1) { spImgInfo_t img = view->imgInfo; if(img != nullImg) { ux -= img->getDataInfo()->getLocation(0); uy += img->getDataInfo()->getLocation(1); uz += img->getDataInfo()->getLocation(2); } color = YELLOW; } view->userToPix(ux,uy,uz,px,py,pz); GraphicsWin::drawLine((int)px, pixsty,(int)px, pixsty + pixht - 3, color); GraphicsWin::drawLine(pixstx,(int)py, pixstx + pixwd - 3, (int)py, color); }
void AxisInfo::displayAxis_north(spGframe_t gf, bool inflg) { spViewInfo_t view = gf->getFirstView(); if(view == nullView) return; int xoff = (int)(pixstx + 0.5*pixwd + pixwd * northX); int yoff; if(inflg) yoff = (int)(pixsty + pixht * northY); else yoff = (int)(pixsty + axisSize + pixht * northY); int minpixx = (int)(xoff - pixwd * horizSize/2); int maxpixx = (int)(xoff + pixwd * horizSize/2 - 3); if(!inflg && horizSize == 1.0 && (isDisplayed & AX_WEST)) minpixx += axisSize; if(!inflg && horizSize == 1.0 && (isDisplayed & AX_EAST)) maxpixx -= axisSize; int tickpix; if(inflg) tickpix = 10; else tickpix = -10; drawHorizAxis(gf, xoff, yoff, minpixx, maxpixx, tickpix); /* GraphicsWin::drawLine(minpixx,yoff,maxpixx, yoff, labelColor); units = getString("aipUnits","cm"); */ }
string ImgOverlay::getCoPlane(spGframe_t gf, spDataInfo_t overlayData) { spViewInfo_t view = gf->getFirstView(); if(view == nullView) return ""; spImgInfo_t img = view->imgInfo; if(img == nullImg) return ""; spDataInfo_t baseData = img->getDataInfo(); if(baseData == (spDataInfo_t)NULL || overlayData == (spDataInfo_t)NULL) return string(""); // overlayData may have rank 2 or 3. if(overlayData->getRank() == 2 && isCoPlane(baseData, overlayData)) { return overlayData->getKey(); } else if(overlayData->getRank() == 2) { return string(""); } if(overlayData->getRank() != 3) return string(""); // if gets here, overlayData has rank 3. return extractPlane(gf, overlayData); }
string ImgOverlay::extractPlane(spGframe_t gf, spDataInfo_t overlayData) { if(overlayData == (spDataInfo_t)NULL) return ""; spViewInfo_t view = gf->getFirstView(); if(view == nullView) return ""; // get baseData spImgInfo_t img = view->imgInfo; if(img == nullImg) return ""; spDataInfo_t baseData = img->getDataInfo(); // determin size for overlay plane int bfast = baseData->getFast(); int bmedium = baseData->getMedium(); int ofast = overlayData->getFast(); int omedium = overlayData->getMedium(); double blpe,olpe,blro,olro; DDLSymbolTable *bst = baseData->st; DDLSymbolTable *ost = overlayData->st; if(!bst || !ost) return ""; bst->GetValue("roi",blpe, 0); bst->GetValue("roi",blro, 1); ost->GetValue("roi",olpe, 0); ost->GetValue("roi",olro, 1); int nfast = (int)(blpe*ofast/olpe); int nmedium = (int)(blro*omedium/olro); double scalex = (blpe*ofast)/(olpe*bfast); double scaley = (blro*omedium)/(olro*bmedium); // new data struct for extracted plane // The only difference from baseData is ds2d->data, and data size nfast, nmedium. dataStruct_t *ds2d = new dataStruct_t; if(!ds2d) { return ""; } memcpy(ds2d, baseData->dataStruct, sizeof(*ds2d)); ds2d->data = NULL; ds2d->auxparms = NULL; float *buf = new float[nfast*nmedium]; if(buf == NULL) { delete ds2d; Winfoprintf("VolData: allocate memory returned NULL pointer."); return ""; } int np = rebinOverlayData(gf, overlayData, nfast,nmedium, scalex, scaley, buf,false); if(np<1) { delete[] buf; delete ds2d; return ""; } DDLSymbolTable *st = (DDLSymbolTable *)baseData->st->CloneList(false); DDLSymbolTable *st2 = new DDLSymbolTable(); // New 2D datainfo spDataInfo_t datainfo = spDataInfo_t(new DataInfo(ds2d, st, st2)); if(datainfo == (spDataInfo_t)NULL) { delete ds2d; delete st2; Winfoprintf("VolData: allocate memory returned NULL pointer."); return ""; } datainfo->st->SetData((float *)buf, sizeof(float) * nfast * nmedium); delete[] buf; // update header char floatStr[16]; strcpy(floatStr, "float"); datainfo->st->SetValue("rank", 2); datainfo->st->SetValue("bits", 32); datainfo->st->SetValue("storage", floatStr); datainfo->st->SetValue("matrix", nfast, 0); datainfo->st->SetValue("matrix", nmedium, 1); string newpath = overlayData->getFilepath()+string("_")+baseData->getShortName(); datainfo->st->SetValue("filename", newpath.c_str()); DataManager *dm = DataManager::get(); string key = dm->loadFile(newpath.c_str(), datainfo->st, datainfo->st2); //Winfoprintf("-----key %s",key.c_str()); //ReviewQueue::get()->addImagePlane(dataInfo, key); datainfo->st = NULL; return key; }
// calc centers for intersecting voxels // center is in pixel, use baseImage's pixToData to convert to data pix. // scale data pix to resolution of overlay image. int ImgOverlay::rebinOverlayData(spGframe_t gf, spDataInfo_t overlayData, int nfast, int nmedium, double scalex, double scaley, float *buf, bool drawIntersect) { if(overlayData == (spDataInfo_t)NULL) return 0; spViewInfo_t fview = gf->getFirstView(); if(fview == nullView) return 0; float *data = (float *)overlayData->getData(); if(!data) return 0; iplan_view *view = (iplan_view *)malloc(sizeof(iplan_view)); iplan_stack *stack = (iplan_stack *)malloc(sizeof(iplan_stack)); getIBview(view, gf->id); string dpath = overlayData->getFilepath(); dpath = dpath.substr(0,dpath.find_last_of("/"))+"/procpar"; string tpath = getCurexpdir()+"/curpar"; P_save(CURRENT,(char *)tpath.c_str()); P_read(CURRENT,(char *)dpath.c_str()); getStack(stack, VOLUME); P_read(CURRENT,(char *)tpath.c_str()); float orig[3],voxsize[3],p1[3]; int ny = overlayData->getFast(); int nx = overlayData->getMedium(); int nz = overlayData->getSlow(); voxsize[0] = (stack->lpe)/nx; voxsize[1] = (stack->lro)/ny; voxsize[2] = (stack->lpe2)/nz; orig[0] = - 0.5*(stack->lpe+voxsize[0]); orig[1] = - 0.5*(stack->lro+voxsize[1]); orig[2] = - 0.5*(stack->lpe2+voxsize[2]); //float viewThk = 0.5*(view->slice.thk)*(view->pixelsPerCm); float viewThk = getReal("aipOverlayThk",2, 1.5)*0.5*voxsize[2]*(view->pixelsPerCm); int ix,iy; double dx,dy; int i,j,k, count=0; for(i=0; i<nfast*nmedium; i++) buf[i] = (float)0.0; int maxx=0, maxy=0, minx=nfast, miny=nmedium; for(k=0;k<nz;k++) for(j=0;j<ny;j++) for(i=0;i<nx;i++) { // p1 is the upper left corner of a 3d voxel // p2 is the diagnal corner of p1 // Note, p1[0] and p2[0] are swapped p1[0] = orig[0] + i*voxsize[0]; p1[1] = orig[1] + j*voxsize[1]; p1[2] = orig[2] + k*(voxsize[2]); // transform p1, p2 to pixel space (base image space) transform(stack->u2m, p1); transform(view->m2p, p1); if(!(p1[2]>viewThk) && !(p1[2]< -viewThk)) { // vox intersects with base image fview->pixToData(p1[0],aip_mnumypnts - p1[1] - 1,dx,dy); ix = (int)(dx*scalex); iy = (int)(dy*scaley); if(ix >=0 && ix < nfast && iy >= 0 && iy < nmedium) { int ind = csi_getInd(ny-1-j,i,k,ny,nx,nz); if((data+ind)) buf[ix+iy*nfast] = data[ind]; // buf[ix+iy*nfast] = *(data+ind); if(drawIntersect) { Dpoint_t polygon[2]; polygon[0].x = polygon[1].x = p1[0]; polygon[0].y = polygon[1].y = aip_mnumypnts - p1[1] - 1; GraphicsWin::drawPolyline(polygon, 2, 4); } if(ix<minx) minx=ix; if(iy<miny) miny=iy; if(ix>maxx) maxx=ix; if(iy>maxy) maxy=iy; count++; } } } //Winfoprintf("###%d",count); free(view); free(stack); // smooth data // if a data point is missing, use average of its neighboring points int ind,ind2,n; float f; for(j=1; j<maxy-1; j++) { for(i=1; i<maxx-1; i++) { ind=i+j*nfast; if(buf[ind] == 0.0) { n=0; f=0.0; for(iy=j-1; iy<j+1; iy++) { for(ix=i-1; ix<i+1; ix++) { ind2=ix+iy*nfast; if(buf[ind2] != 0.0) { f+=buf[ind2]; n++; } } } if(n>1) buf[ind]=f/n; } } } return count; }
void AxisInfo::drawVertAxis(spGframe_t gf, int xoff, int yoff, int minpixy, int maxpixy, int tickpix) { spViewInfo_t view = gf->getFirstView(); if(view == nullView) return; int unitPos = maxpixy + 16; int miny = minpixy; int maxy = maxpixy; int pmin = minpixy+abs(tickpix)+10; int pmax = maxpixy-abs(tickpix)-10; int horizAxis = (isDisplayed & AX_SOUTH) || (isDisplayed & AX_NORTH); int tickpix2 = tickpix/2; // small tick int direction; if(tickpix > 0) direction = AX_EAST; else direction = AX_WEST; units = getString("aipUnits","cm"); char str[MAXSTR]; if(units == "pixel") { int smallTickSpan = 10; // 10 pixels int bigTickSpan = 50; minpixy = minpixy - pixsty; maxpixy = maxpixy - pixsty; // adjust minpixy (first point) to start from a tick. minpixy = ((int)(minpixy/smallTickSpan + 0.5))*smallTickSpan; // draw ticks, start from minpixy int y = minpixy; while(y <= maxpixy) { if((y % bigTickSpan) == 0) { //big tick GraphicsWin::drawLine(xoff+tickpix,y+pixsty,xoff,y+pixsty, axisColor); if(!horizAxis || !inflg || (y>pmin && y<pmax)) { sprintf(str,"%d", y); drawString(gf, str, xoff+tickpix, y+pixsty, axisColor, direction); } } else { // small tick GraphicsWin::drawLine(xoff+tickpix2,y+pixsty,xoff,y+pixsty, axisColor); } y += smallTickSpan; } maxpixy = y - smallTickSpan; minpixy += pixsty; maxpixy += pixsty; // draw units if(inflg) unitPos = maxpixy + 16; drawString(gf, "[pixel]", xoff+2, unitPos, axisColor, direction); } else if(units == "pix") { double dx,dy,px,py,dymin,dymax; px = (double)xoff; // px does not change pixToData(view, px, (double)minpixy, dx,dymin); pixToData(view, px, (double)maxpixy, dx,dymax); bool invertY=false; if(dymin > dymax) { invertY=true; double d=dymin; dymin=dymax; dymax=d; } double first, inc, mag; int nticks; if(!calcAxis(dymin, dymax, minpixy, maxpixy, first, inc, mag, nticks)) return; // draw ticks, start from first point if(!inflg) dy = first + inc; else dy = first; dataToPix(view,dx,dy,px,py); if(invertY) { maxpixy = (int)py; } else { minpixy = (int)py; } while(dy <= dymax) { if((int)(10.0*fabs(dy)/mag + 0.5) % nticks == 0) { // big tick GraphicsWin::drawLine(xoff+tickpix,(int)py,xoff,(int)py, axisColor); if(!horizAxis || !inflg || (py>pmin && py<pmax)) { if(mag < 1) sprintf(str,"%.1f",dy); else sprintf(str,"%d",(int)dy); drawString(gf, str, xoff+tickpix, (int)py, axisColor, direction); } } else if(inc>=1) { GraphicsWin::drawLine(xoff+tickpix2,(int)py,xoff,(int)py, axisColor); } dy += inc; dataToPix(view,dx,dy,px,py); } dy = dy - inc; dataToPix(view,dx,dy,px,py); if(invertY) { minpixy = (int)py; } else { maxpixy = (int)py; } // draw units if(inflg) unitPos = maxpixy + 16; drawString(gf, "[pix]", xoff+2, unitPos, axisColor, direction); } else if(units == "cm" || units == "mm") { int ind = 1; double d[3],px,py,pz,dymin,dymax; px = (double)xoff; // px does not change pixToLogical(view,px, (double)minpixy, 0.0, d[0],d[1],d[2]); dymin = d[ind]; pixToLogical(view,px, (double)maxpixy, 0.0, d[0],d[1],d[2]); dymax = d[ind]; bool invertY=false; if(dymin > dymax) { invertY=true; double tmp=dymin; dymin=dymax; dymax=tmp; } double first, inc, mag; int nticks; if(!calcAxis(dymin, dymax, minpixy, maxpixy, first, inc, mag, nticks)) return; // draw ticks, start from first point d[ind] = first; logicalToPix(view,d[0],d[1],d[2],px,py,pz); if(invertY) { maxpixy = (int)py; } else { minpixy = (int)py; } while(d[ind] <= dymax) { // note, use fabs for modulus operation if(fabs(d[ind]) < 1.0e-4) d[ind] = 0.0; if((int)(fabs(d[ind]*10.0)/mag+0.5) % nticks == 0) { // big tick GraphicsWin::drawLine(xoff+tickpix,(int)py,xoff,(int)py, axisColor); if(!horizAxis || !inflg || (py>pmin && py<pmax)) { if(units=="cm") { if(mag <= 0.01) sprintf(str,"%.2f",d[ind]); else if(inc <= 0.1) sprintf(str,"%.1f",d[ind]); else sprintf(str,"%.0f",d[ind]); } else if(units=="mm") { if(mag <= 0.01) sprintf(str,"%.1f",d[ind]*10.0); else sprintf(str,"%.0f",(d[ind]*10.0)); } drawString(gf, str, xoff+tickpix, (int)py, axisColor, direction); } } else { GraphicsWin::drawLine(xoff+tickpix2,(int)py,xoff,(int)py, axisColor); } d[ind] += inc; logicalToPix(view,d[0],d[1],d[2],px,py,pz); } d[ind] = d[ind] - inc; logicalToPix(view,d[0],d[1],d[2],px,py,pz); if(invertY) { minpixy = (int)py; } else { maxpixy = (int)py; } // draw units if(inflg) unitPos = maxpixy + 16; sprintf(str,"[%s]",units.c_str()); drawString(gf, str, xoff+2, unitPos, axisColor, direction); } // draw axis if(vertSize == 1.0 && inflg) GraphicsWin::drawLine(xoff,pixsty,xoff,pixsty+pixht - 3, axisColor); else if(vertSize == 1.0) GraphicsWin::drawLine(xoff,miny+1,xoff,maxy+3, axisColor); else GraphicsWin::drawLine(xoff,minpixy,xoff,maxpixy, axisColor); }
void AxisInfo::drawHorizAxis(spGframe_t gf, int xoff, int yoff, int minpixx, int maxpixx, int tickpix) { spViewInfo_t view = gf->getFirstView(); if(view == nullView) return; int tickpix2 = tickpix/2; // small tick int direction; if(tickpix > 0) direction = AX_SOUTH; else direction = AX_NORTH; int minx = minpixx; int maxx = maxpixx; int pmin = minpixx+abs(tickpix)+10; int pmax = maxpixx-abs(tickpix)-10; int vertAxis = (isDisplayed & AX_EAST) || (isDisplayed & AX_WEST); units = getString("aipUnits","cm"); char str[MAXSTR]; if(units == "pixel") { int smallTickSpan = 10; // 10 pixels int bigTickSpan = 50; minpixx = minpixx - pixstx; maxpixx = maxpixx - pixstx; // adjust minpixx (first point) to start from a tick. minpixx = ((int)(minpixx/smallTickSpan + 0.5))*smallTickSpan; // draw ticks, start from minpixx int x = minpixx; while(x <= maxpixx) { if((x % bigTickSpan) == 0) { //big tick GraphicsWin::drawLine(x+pixstx, yoff+tickpix, x+pixstx, yoff, axisColor); if(!vertAxis || !inflg || (x>pmin && x<pmax)) { sprintf(str,"%d", x); drawString(gf, str, x+pixstx, yoff+tickpix+10, axisColor, direction); } } else { // small tick GraphicsWin::drawLine(x+pixstx, yoff, x+pixstx, yoff+tickpix2, axisColor); } x += smallTickSpan; } maxpixx = x - smallTickSpan; minpixx += pixstx; maxpixx += pixstx; // draw units //drawString(gf, "[pixel]", maxpixx+20, yoff+8, axisColor, direction); } else if(units == "pix") { double dx,dy,px,py,dxmin,dxmax; py = (double)yoff; // py does not change pixToData(view, (double)minpixx, py, dxmin,dy); pixToData(view, (double)maxpixx, py, dxmax,dy); bool invertX = false; if(dxmin > dxmax) { invertX=true; double d=dxmin; dxmin=dxmax; dxmax=d; } double first, inc, mag; int nticks; if(!calcAxis(dxmin, dxmax, minpixx, maxpixx, first, inc, mag, nticks)) return; // draw ticks, start from first point if(!inflg) dx = first + inc; else dx = first; dataToPix(view,dx,dy,px,py); if(invertX) { maxpixx = (int)px; } else { minpixx = (int)px; } while(dx <= dxmax) { if((int)(10.0*fabs(dx)/mag + 0.5) % nticks == 0) { // big tick GraphicsWin::drawLine((int)px,yoff+tickpix,(int)px,yoff, axisColor); if(!vertAxis || !inflg || (px>pmin && px<pmax)) { if(mag < 1) sprintf(str,"%.1f",dx); else sprintf(str,"%d",(int)dx); drawString(gf, str, (int)px, yoff+tickpix+10, axisColor, direction); } } else if(inc>=1) { GraphicsWin::drawLine((int)px,yoff+tickpix2,(int)px,yoff, axisColor); } dx += inc; dataToPix(view,dx,dy,px,py); } dx = dx - inc; dataToPix(view,dx,dy,px,py); if(invertX) { minpixx = (int)px; } else { maxpixx = (int)px; } // draw units //drawString(gf, "[pix]", maxpixx+20, yoff+8, axisColor, direction); } else if(units == "cm" || units == "mm") { int ind = 0; double d[3],px,py,pz,dxmin,dxmax; py = (double)yoff; // py does not change pixToLogical(view,(double)minpixx, py, 0.0, d[0],d[1],d[2]); dxmin=d[ind]; pixToLogical(view,(double)maxpixx, py, 0.0, d[0],d[1],d[2]); dxmax=d[ind]; bool invertX=false; if(dxmin > dxmax) { invertX=true; double tmp=dxmin; dxmin=dxmax; dxmax=tmp; } double first, inc, mag; int nticks; if(!calcAxis(dxmin, dxmax, minpixx, maxpixx, first, inc, mag, nticks)) return; // draw ticks, start from first point d[ind] = first; logicalToPix(view,d[0],d[1],d[2],px,py,pz); if(invertX) { maxpixx = (int)px; // first point is maxpixx } else { minpixx = (int)px; // first point is minpixx } while(d[ind] <= dxmax) { // note, use fabs for modulus operation if(fabs(d[ind]) < 1.0e-4) d[ind] = 0.0; if((int)(fabs(d[ind]*10.0)/mag+0.5) % nticks == 0) { // big tick GraphicsWin::drawLine((int)px, yoff+tickpix,(int)px,yoff, axisColor); if(!vertAxis || !inflg || (px>pmin && px<pmax)) { if(units=="cm") { if(mag <= 0.01) sprintf(str,"%.2f",d[ind]); else if(inc <= 0.1) sprintf(str,"%.1f",d[ind]); else sprintf(str,"%.0f",d[ind]); } else if(units=="mm") { if(mag <= 0.01) sprintf(str,"%.1f",d[ind]*10.0); else sprintf(str,"%.0f",(d[ind]*10.0)); } drawString(gf, str, (int)px, yoff+tickpix+10, axisColor, direction); } } else { GraphicsWin::drawLine((int)px, yoff+tickpix2,(int)px, yoff, axisColor); } d[ind] += inc; logicalToPix(view,d[0],d[1],d[2],px,py,pz); } d[ind] = d[ind] - inc; logicalToPix(view,d[0],d[1],d[2],px,py,pz); if(invertX) { minpixx = (int)px; } else { maxpixx = (int)px; } // draw units /* sprintf(str,"[%s]",units.c_str()); drawString(gf, str, maxpixx+20, yoff+8, axisColor, direction); */ } // draw axis if(horizSize == 1.0 && inflg) GraphicsWin::drawLine(pixstx, yoff,pixstx+pixwd - 3, yoff, axisColor); else if(vertSize == 1.0) GraphicsWin::drawLine(minx+1,yoff,maxx+3, yoff, axisColor); else GraphicsWin::drawLine(minpixx,yoff,maxpixx, yoff, axisColor); }
void AxisInfo::showPosition(spGframe_t gf, int x, int y, bool showLabel, bool updateSlaves) { initAxis(gf); char str[MAXSTR]; if(!getPositionString(gf, x, y, str) ) return; spViewInfo_t view = gf->getFirstView(); if(view == nullView) return; int xmin = gf->pixstx; int xmax = gf->pixstx + gf->pixwd - 3; int ymin = gf->pixsty; int ymax = gf->pixsty + gf->pixht - 3; if(x < xmin || x > xmax || y < ymin || y > ymax) return; if(crosshair && getReal("aipMode",1) == 3 && updateSlaves) { GraphicsWin::drawLine(x,ymin,x,ymax, labelColor); GraphicsWin::drawLine(xmin,y,xmax,y, labelColor); } else { GraphicsWin::drawLine(x-3,y-3,x+3,y+3, labelColor); GraphicsWin::drawLine(x+3,y-3,x-3,y+3, labelColor); } // Get width and height of a character (cwd, cht) int ascent; int descent; int cwd; // string width int cht; // string height GraphicsWin::getTextExtents(str, 12, &ascent, &descent, &cwd); cht = ascent + descent; cwd = (int)(cwd*12.0/14.0); // getTextExtents calls a function that assume font size 14 int px = x+8; if(px <= xmin) showLabel=false; if(px+cwd+1 >= xmax) px -= cwd; if(px <= xmin) showLabel=false; int py = y; if(py <= ymin+cht) py = y+cht; if(py >=ymax) showLabel=false; if(showLabel) GraphicsWin::drawString(str, px, py, labelColor, 0,0,0); // show position only if mouse in createLine or createPoint state. //if((Mouse::creatingLine() || Mouse::creatingPoint()) && updateSlaves && getReal("aipRoiBind",0) > 0) { if(updateSlaves && getReal("aipRoiBind",0) > 0) { double ux,uy,uz; pixToMagnet(view,(double)x, (double)y, 0.0,ux,uy,uz); spGframe_t frame; GframeManager *gfm = GframeManager::get(); GframeList::iterator gfi; for (frame=gfm->getFirstFrame(gfi); frame != nullFrame; frame =gfm->getNextFrame(gfi)) { if(frame == gf || !gfm->isFrameDisplayed(frame)) continue; view = frame->getFirstView(); if(view == nullView) return; double dx,dy,dz; magnetToPix(view,ux,uy,uz,dx,dy,dz); showPosition(frame,(int)dx, (int)dy, false, false); } } }