Ejemplo n.º 1
0
/*!
 * Initialize phi
 */
void ActiveContourSeed::initializePhi(int protobuf_idx, Protobuf *proto) {

	// set resolution
	phi_->setResolution(p_->res_x, p_->res_y, p_->res_z);

	// initialize image
	phi_->resize(_dimx_Rel, _dimy_Rel, _dimz_Rel);

	// get cell centers, previous sparse segmentation from protobuf file
	Array1D<int> xAbs(cb), yAbs(cb), zAbs(cb);
	proto->getSparseSegmentationCoordinates("full", protobuf_idx, &xAbs, &yAbs,
			&zAbs);

	// if previous sparse segmentation is empty, then initialize phi from single point
	if (xAbs.size() == 0) {
		for (int x = 0; x < _dimx_Rel; x++) {
			for (int y = 0; y < _dimy_Rel; y++) {
				for (int z = 0; z < _dimz_Rel; z++) {
					float xRadial = (float) (x - _hszX);
					float yRadial = (float) (y - _hszY);
					float zRadial = (float) (z - _hszZ);
					(*phi_)(x, y, z) = sqrtf(
							xRadial * xRadial + yRadial * yRadial + zRadial
									* zRadial) - p_->r;
				}
			}
		}
		// otherwise, initialize phi using distance transform on previous segmentation
	} else {
		// get previous binary segmentation, store in phi
		for (int p = 0; p < xAbs.size(); p++) {
			int xRel, yRel, zRel;
			absToRel(xRel, yRel, zRel, xAbs(p), yAbs(p), zAbs(p));
			(*phi_)(xRel, yRel, zRel) = 1;
		}

		// get perimeter segmentation and store in phi.  Store original segmentation in temp
		Image3D<float> temp(*phi_);
		perim(phi_, 1);

		// calculate distance transform
		bwdist(phi_);

		// Make distances negative inside the segmentation
		for (int x = 0; x < _dimx_Rel; x++) {
			for (int y = 0; y < _dimy_Rel; y++) {
				for (int z = 0; z < _dimz_Rel; z++) {
					if (temp(x, y, z) > float(BWTHRESH)) {
						(*phi_)(x, y, z) = -(*phi_)(x, y, z);
					}
				}
			}
		}
	}

	updateFullSeg(phi_);
}
Ejemplo n.º 2
0
// gives the intersection-point between two lines, returns true, if any
// computes the crossing point between the (infinite) lines
// defined by the endpoints of the DLines, then checks if it
// lies within the two rectangles defined by the DLines endpoints
bool DLine::intersection(
	const DLine &line,
	DPoint &inter,
	bool endpoints) const
{
	double ix, iy;

	//do not return true if parallel edges are encountered
	if (slope() == line.slope()) return false;

	//two possible checks:
	// only check for overlap on endpoints if option parameter set,
	// compute crossing otherwise
	// or skip computation if endpoints overlap (can't have "real" crossing)
	// (currently implemented)
	//if (endpoints) {

	if (m_start == line.m_start || m_start == line.m_end) {
		inter = m_start;
		if (endpoints) return true;
		else return false;
	}

	if (m_end == line.m_start || m_end == line.m_end) {
		inter = m_end;
		if (endpoints) return true;
		else return false;
	}

	//}//if endpoints

	//if the edge is vertical, we cannot compute the slope
	if (isVertical())
		ix = m_start.m_x;
	else
		if (line.isVertical())
			ix = line.m_start.m_x;
		else
			ix = (line.yAbs() - yAbs())/(slope() - line.slope());

	//set iy to the value of the infinite line at xvalue ix
	//use a non-vertical line (can't be both, otherwise they're parallel)
	if (isVertical())
		iy = line.slope() * ix + line.yAbs();
	else
		iy = slope() * ix + yAbs();

	inter = DPoint(ix, iy); //the (infinite) lines cross point

	DRect tRect(line);
	DRect mRect(*this);

	return (tRect.contains(inter) && mRect.contains(inter));
}
Ejemplo n.º 3
0
Archivo: afr.cpp Proyecto: BOPOHOB/NPO
CChartDataList AFR::toChartData(unsigned interalParts) const {
    CChartDataList result;
    if (interalParts & Real) {
        CDimensionArray* xRe(new CDimensionArray(static_cast<int>(this->size())));
        CDimensionArray* yRe(new CDimensionArray(static_cast<int>(this->size())));
        double* xReIt(xRe->data());
        double* yReIt(yRe->data());
        for (AFR::const_iterator it(this->begin()); it != this->end(); ++it, ++xReIt, ++yReIt) {
            *xReIt = it->frequency;
            *yReIt = it->amplitude.real();
        }
        xRe->updateRange();
        yRe->updateRange();
        CChartData re;
        re.push_back(xRe);
        re.push_back(yRe);
        result << re;
    }
    if (interalParts & Imaginary) {
        CDimensionArray* xIm(new CDimensionArray(static_cast<int>(this->size())));
        CDimensionArray* yIm(new CDimensionArray(static_cast<int>(this->size())));
        double* xImIt(xIm->data());
        double* yImIt(yIm->data());
        for (AFR::const_iterator it(this->begin()); it != this->end(); ++it, ++xImIt, ++yImIt) {
            *xImIt= it->frequency;
            *yImIt = it->amplitude.imag();
        }
        xIm->updateRange();
        yIm->updateRange();
        CChartData im;
        im.push_back(xIm);
        im.push_back(yIm);
        result << im;
    }
    if (interalParts & Amplitude) {
        CDimensionArray* xAbs(new CDimensionArray(static_cast<int>(this->size())));
        CDimensionArray* yAbs(new CDimensionArray(static_cast<int>(this->size())));
        double* xAbsIt(xAbs->data());
        double* yAbsIt(yAbs->data());
        for (AFR::const_iterator it(this->begin()); it != this->end(); ++it, ++xAbsIt, ++yAbsIt) {
            *xAbsIt = it->frequency;
            *yAbsIt = abs(it->amplitude);
        }
        xAbs->updateRange();
        yAbs->updateRange();
        CChartData abs;
        abs.push_back(xAbs);
        abs.push_back(yAbs);
        result << abs;
    }
    return result;
}