Volume::Volume() { m_valid = false; m_depth = m_height = m_width = 0; m_slice = 0; m_fileName.clear(); m_mask.reset(); m_1dHistogram = 0; m_2dHistogram = 0; m_histImageData1D = 0; m_histImageData2D = 0; m_histogramImage1D = QImage(256, 256, QImage::Format_RGB32); m_histogramImage2D = QImage(256, 256, QImage::Format_RGB32); m_nonZeroVoxels = 0; m_bitmask.clear(); m_connectedbitmask.clear(); connect(&m_mask, SIGNAL(progressChanged(int)), this, SIGNAL(progressChanged(int))); connect(&m_mask, SIGNAL(progressReset()), this, SIGNAL(progressReset())); }
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 ZProgressManager::connectSignalSlot() { connect(this, SIGNAL(progressStarted()), this, SLOT(startProgress())); connect(this, SIGNAL(progressEnded()), this, SLOT(endProgress())); connect(this, SIGNAL(progressReset()), this, SLOT(resetProgress())); connect(this, SIGNAL(progressStarted(double)), this, SLOT(startProgress(double))); connect(this, SIGNAL(progressEnded(double)), this, SLOT(endProgress(double))); connect(this, SIGNAL(progressAdvanced(double)), this, SLOT(advanceProgress(double))); }
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(); }
void VolumeMask::erodeBitmask(int mind, int maxd, int minw, int maxw, int minh, int maxh) { // QProgressDialog progress("Eroding Tag Mask", // "Cancel", // 0, 100, // 0); QBitArray bitcopy = m_bitmask; for(int d=mind; d<=maxd; d++) { emit progressChanged((int)(100.0*(float)d/(float)m_depth)); qApp->processEvents(); 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 (bitcopy.testBit(bidx)) { int d0 = qMax(d-1, mind); int d1 = qMin(d+1, maxd); int w0 = qMax(w-1, minw); int w1 = qMin(w+1, maxw); int h0 = qMax(h-1, minh); int h1 = qMin(h+1, maxh); bool ok = true; for(int d2=d0; d2<=d1; d2++) for(int w2=w0; w2<=w1; w2++) for(int h2=h0; h2<=h1; h2++) { qint64 idx = d2*m_width*m_height + w2*m_height + h2; ok &= bitcopy.testBit(idx); } if (!ok) // surface voxel m_bitmask.setBit(bidx, false); // set bit to 0 } } } emit progressReset(); }
void VolumeMask::tagUsingBitmask(QList<int> pos, QBitArray bitmask) { checkMaskFile(); if (pos.count()) findConnectedRegion(pos); // QProgressDialog progress("Updating Mask", // "Cancel", // 0, 100, // 0); int nbytes = m_width*m_height; uchar *mask = new uchar[nbytes]; int tag = Global::tag(); 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 (bitmask.testBit(bidx)) { qint64 idx = (w*m_height + h); //if (tag == 0 || mask[idx] == 0) mask[idx] = tag; } bidx++; } m_maskFileManager.setSlice(d, mask); } delete [] mask; emit progressReset(); }
void VolumeMask::dilateBitmask() { // QProgressDialog progress("Dilating Tag Mask", // "Cancel", // 0, 100, // 0); QBitArray bitcopy = m_bitmask; m_bitmask.fill(false); qint64 bidx = 0; for(int d=0; d<m_depth; d++) { emit progressChanged((int)(100.0*(float)d/(float)m_depth)); qApp->processEvents(); for(int w=0; w<m_width; w++) for(int h=0; h<m_height; h++) { if (bitcopy.testBit(bidx)) { int d0 = qMax(d-1, 0); int d1 = qMin(d+1, m_depth-1); int w0 = qMax(w-1, 0); int w1 = qMin(w+1, m_width-1); int h0 = qMax(h-1, 0); int h1 = qMin(h+1, m_height-1); for(int d2=d0; d2<=d1; d2++) for(int w2=w0; w2<=w1; w2++) for(int h2=h0; h2<=h1; h2++) { qint64 idx = d2*m_width*m_height + w2*m_height + h2; m_bitmask.setBit(idx); } } bidx ++; } } emit progressReset(); }
void VolumeMask::createBitmask() { checkMaskFile(); m_bitmask.fill(false); // QProgressDialog progress("Identifying Tagged Region", // "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++) { qint64 idx = (w*m_height + h); if (mask[idx] == Global::tag()) m_bitmask.setBit(bidx); bidx++; } } delete [] mask; emit progressReset(); }
void ZProgressManager::notifyProgressReset() { emit progressReset(); }
void Volume::findConnectedRegion(int mind, int maxd, int minw, int maxw, int minh, int maxh, QList<int> pos, bool sliceOnly) { m_connectedbitmask.fill(false); uchar *lut = Global::lut(); QStack<int> stack; uchar *vslice; uchar v0, g0; int d = pos[0]; int w = pos[1]; int h = pos[2]; vslice = m_pvlFileManager.rawValue(d, w, h); v0 = vslice[0]; // vslice = m_gradFileManager.rawValue(d, w, h); // g0 = vslice[0]; g0 = 0; // put the seeds in for(int pi=0; pi<pos.size()/3; pi++) { int d = pos[3*pi]; int w = pos[3*pi+1]; int h = pos[3*pi+2]; if (d >= mind && d <= maxd && w >= minw && w <= maxw && h >= minh && h <= maxh) { qint64 idx = d*m_width*m_height + w*m_height + h; if (m_bitmask.testBit(idx)) { m_connectedbitmask.setBit(idx); stack.push(d); stack.push(w); stack.push(h); } } } if (sliceOnly) stack.clear(); int pv = 0; int progv = 0; while(!stack.isEmpty()) { progv++; if (progv == 1000) { progv = 0; pv = (++pv % 100); emit progressChanged(pv); } int h = stack.pop(); int w = stack.pop(); int d = stack.pop(); qint64 idx = d*m_width*m_height + w*m_height + h; if (m_bitmask.testBit(idx)) { int d0 = qMax(d-1, 0); int d1 = qMin(d+1, m_depth-1); int w0 = qMax(w-1, 0); int w1 = qMin(w+1, m_width-1); int h0 = qMax(h-1, 0); int h1 = qMin(h+1, m_height-1); for(int d2=d0; d2<=d1; d2++) for(int w2=w0; w2<=w1; w2++) for(int h2=h0; h2<=h1; h2++) { if (d2 >= mind && d2 <= maxd && w2 >= minw && w2 <= maxw && h2 >= minh && h2 <= maxh) { qint64 idx = d2*m_width*m_height + w2*m_height + h2; if ( m_bitmask.testBit(idx) && !m_connectedbitmask.testBit(idx) ) { // uchar v, g; // vslice = m_pvlFileManager.rawValue(d2, w2, h2); // v = vslice[0]; // vslice = m_gradFileManager.rawValue(d2, w2, h2); // g = vslice[0]; // // if (qAbs(v-v0) < Global::deltaV() && // g < Global::deltaG()) { m_connectedbitmask.setBit(idx); stack.push(d2); stack.push(w2); stack.push(h2); } } } } } } // end find connected //------------------------------------------------------ emit progressReset(); }