int main(int argc, char **argv) { /* Correct call? */ if(argc!=2) fatal(); /* Split arguments and terminate application if wrong format. */ char *ip, *bitmask; ip = strtok(argv[1], "/"); if(!ip) fatal(); bitmask = strtok(NULL, "\0"); if(!bitmask) fatal(); /* Convert the ASCII strings to workable integers. * The inet_addr() function cannot be used because * the resulting integer is in NBO. */ unsigned int ipAsUInt = ip2ui(ip); unsigned int bitmaskAsUInt = createBitmask(bitmask); char *networkAddress = ui2ip(ipAsUInt & bitmaskAsUInt), *broadcastAddress = ui2ip(ipAsUInt | ~bitmaskAsUInt); printf("IP range spans from %s to %s (Network and broadcast addresses inclusive)\n", networkAddress, broadcastAddress); free(networkAddress); free(broadcastAddress); return 0; }
void VolumeMask::erode(int mind, int maxd, int minw, int maxw, int minh, int maxh, QBitArray vbitmask) { createBitmask(); //int thickness = Global::spread(); int thickness = 1; while (thickness > 0) { erodeBitmask(mind, maxd, minw, maxw, minh, maxh); thickness --; } // m_bitmask now contains region eroded by thickness // QProgressDialog progress("Updating Mask", // "Cancel", // 0, 100, // 0); int nbytes = m_width*m_height; unsigned char *mask = new unsigned char[nbytes]; for(int d=mind; d<=maxd; d++) { emit progressChanged((int)(100.0*(float)d/(float)m_depth)); qApp->processEvents(); uchar *mslice = m_maskFileManager.getSlice(d); memcpy(mask, mslice, nbytes); for(int w=minw; w<=maxw; w++) for(int h=minh; h<=maxh; h++) { qint64 bidx = (d*m_width*m_height + w*m_height + h); if ( vbitmask.testBit(bidx) && !m_bitmask.testBit(bidx)) { // reset mask to 0 if the // mask value is same as supplied tag value qint64 idx = (w*m_height + h); if ( mask[idx] == Global::tag()) mask[idx] = 0; } } m_maskFileManager.setSlice(d, mask); } delete [] mask; emit progressReset(); }
void VolumeMask::dilate(QBitArray vbitmask) { createBitmask(); //int thickness = Global::spread(); int thickness = 1; while (thickness > 0) { dilateBitmask(); thickness --; } // m_bitmask now contains region dilated by thickness // QProgressDialog progress("Updating Mask", // "Cancel", // 0, 100, // 0); int nbytes = m_width*m_height; unsigned char *mask = new unsigned char[nbytes]; qint64 bidx = 0; for(int d=0; d<m_depth; d++) { emit progressChanged((int)(100.0*(float)d/(float)m_depth)); qApp->processEvents(); uchar *mslice = m_maskFileManager.getSlice(d); memcpy(mask, mslice, nbytes); for(int w=0; w<m_width; w++) for(int h=0; h<m_height; h++) { if ( vbitmask.testBit(bidx) && m_bitmask.testBit(bidx)) { qint64 idx = (w*m_height + h); mask[idx] = Global::tag(); } bidx++; } m_maskFileManager.setSlice(d, mask); } delete [] mask; emit progressReset(); }