예제 #1
0
void ActiveContourSeed::updatePhi() {
	if (isFinished()) {
		return;
	}
	for (int k = 0; k < narrowBand_count; k++) {
		int x = (*narrowBand_x)(k);
		int y = (*narrowBand_y)(k);
		int z = (*narrowBand_z)(k);
		int xAbs, yAbs, zAbs;
		relToAbs(xAbs, yAbs, zAbs, x, y, z);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfloat-equal"
		if ((*fullSeg)(xAbs, yAbs, zAbs) == -1.0f) {
			(*fullSeg)(xAbs, yAbs, zAbs) = -2.0f;
		}

		float dphidt = (*narrowBand_DphiDt)(k);
		float newPhi = (*phi_)(x, y, z) + (p_->dt) * dphidt;

		if ((*fullSeg)(xAbs, yAbs, zAbs) != -2.0f || newPhi > 0) {
#pragma clang diagnostic pop
			(*phi_)(x, y, z) = newPhi;
		}
	}

	// Reinitialize phi
	if (_tElapse % p_->sussmanInterval == 0) {
		sussmanReinitialization();
	}
}
예제 #2
0
void ActiveContourSeed::getSparseCoordinates(Array1D<int> *xS,
		Array1D<int> *yS, Array1D<int> *zS, Image3D<float> *bw) {

	// resize x,y,z to maximum size
	int dimx, dimy, dimz;
	bw->getDimensions(dimx, dimy, dimz);
	xS->resize(dimx * dimy * dimz);
	yS->resize(dimx * dimy * dimz);
	zS->resize(dimx * dimy * dimz);

	// iterate through bw and store absolute coordinates of voxels above threshold in x,y,z
	int pixelCount = 0;
	for (int x = 0; x < dimx; x++) {
		for (int y = 0; y < dimy; y++) {
			for (int z = 0; z < dimz; z++) {
				if ((*bw)(x, y, z) > float(BWTHRESH)) {
					int xAbs, yAbs, zAbs;
					relToAbs(xAbs, yAbs, zAbs, x, y, z);
					(*xS)(pixelCount) = xAbs;
					(*yS)(pixelCount) = yAbs;
					(*zS)(pixelCount) = zAbs;
					pixelCount++;
				}
			}
		}
	}

	// resize x,y,z to minimum size
	xS->resize(pixelCount);
	yS->resize(pixelCount);
	zS->resize(pixelCount);
}
예제 #3
0
void mousePress(sf::Mouse::Button button, int x, int y) {
    float absX = x, absY = y;
    relToAbs(absX, absY);

    switch(button) {
        case sf::Mouse::Left: {
            player->shoot(absX, absY);
            break;
        }
    }
}
예제 #4
0
/*
 * ReportSave
 */
void ReportSave( HWND parent, char *fname, char *appname, BOOL save_ok )
{
    char        ful_fname[_MAX_PATH];
    char        buf[_MAX_PATH + 20];

    if( save_ok ) {
        relToAbs( fname, ful_fname );
        RCsprintf( buf, SLB_DATA_SAVED_TO, ful_fname );
        MessageBox( parent, buf, appname, MB_OK | MB_TASKMODAL );
    } else {
        RCMessageBox( parent, SLB_CANT_SAVE_DATA, appname,
                      MB_OK | MB_TASKMODAL | MB_ICONEXCLAMATION );
    }

} /* ReportSave */
예제 #5
0
void ActiveContourSeed::updateFullSeg(Image3D<float> *phi) {
	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 ((*phi)(x, y, z) <= 0) {
					int xAbs, yAbs, zAbs;
					relToAbs(xAbs, yAbs, zAbs, x, y, z);
					float fsIdx = (*fullSeg)(xAbs, yAbs, zAbs);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfloat-equal"
					if (fsIdx > 0 && fsIdx != _seedIdx)
#pragma clang diagnostic pop
						(*fullSeg)(xAbs, yAbs, zAbs) = -2.0f;// Multiple contours collided at this position
					else if (fsIdx > 0) // Not already marked as collision area
						(*fullSeg)(xAbs, yAbs, zAbs) = _seedIdx;
				}
			}
		}
	}
}
예제 #6
0
/*!
 * Initialize g
 */
void ActiveContourSeed::initializeG(Image3D<float> *g_full) {
	// set resolution
	g->setResolution(p_->res_x, p_->res_y, p_->res_z);
	g_x->setResolution(p_->res_x, p_->res_y, p_->res_z);
	g_y->setResolution(p_->res_x, p_->res_y, p_->res_z);
	g_z->setResolution(p_->res_x, p_->res_y, p_->res_z);

	// initialize image
	g->resize(_dimx_Rel, _dimy_Rel, _dimz_Rel);
	g_x->resize(_dimx_Rel, _dimy_Rel, _dimz_Rel);
	g_y->resize(_dimx_Rel, _dimy_Rel, _dimz_Rel);
	g_z->resize(_dimx_Rel, _dimy_Rel, _dimz_Rel);

	// get g subwindow
	for (int x = 0; x < _dimx_Rel; x++) {
		for (int y = 0; y < _dimy_Rel; y++) {
			for (int z = 0; z < _dimz_Rel; z++) {
				int xAbs, yAbs, zAbs;
				relToAbs(xAbs, yAbs, zAbs, x, y, z);
				(*g)(x, y, z) = (*g_full)(xAbs, yAbs, zAbs);
			}
		}
	}

	// pre-calculate partial derivatives of g
	for (int x = 0; x < _dimx_Rel; x++) {
		for (int y = 0; y < _dimy_Rel; y++) {
			for (int z = 0; z < _dimz_Rel; z++) {
				(*g_x)(x, y, z) = g->getDdxVal(x, y, z);
				(*g_y)(x, y, z) = g->getDdyVal(x, y, z);
				(*g_z)(x, y, z) = g->getDdzVal(x, y, z);
			}
		}
	}

}
예제 #7
0
파일: GameMap.cpp 프로젝트: Epictetus/Joyau
void GameMap::centerOn(int x, int y)
{
   Point p = relToAbs(x, y);
   move(240 - p.x, 136 - p.y);
}
예제 #8
0
void ActiveContourSeed::preUpdatePhi() {
	narrowBand_count = 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++) {

				// check if voxel falls in narrow band range
				if ((*phi_)(x, y, z) > p_->narrowBandThreshold || (*phi_)(x, y,
						z) < -(p_->narrowBandThreshold)) {
					continue;
				}

				int xAbs, yAbs, zAbs;
				relToAbs(xAbs, yAbs, zAbs, x, y, z);
				float fsIdx = (*fullSeg)(xAbs, yAbs, zAbs);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfloat-equal"
				if (fsIdx == -2.0f) {
#pragma clang diagnostic pop
					// Old collision; do not update Phi here
					continue;
				}

				/*
				 // Check for collisions if active contours are running forward
				 if (p->c>=0) {
				 int xAbs,yAbs,zAbs;
				 relToAbs(xAbs,yAbs,zAbs,x,y,z);
				 if ((*fullSeg)(xAbs,yAbs,zAbs)!=0 && (*fullSeg)(xAbs,yAbs,zAbs)!=_seedIdx) {
				 continue;
				 }
				 }*/

				// calculate derivatives of phi
				float phix, phiy, phiz, phixx, phiyy, phizz, phixz, phixy,
						phiyz;
				if (isCloseTo(p_->res_x, 1.0f) && isCloseTo(p_->res_y, 1.0f)) {
					phi_->getFastDerivatives(x, y, z, phix, phiy, phiz, phixx,
							phiyy, phizz, phixy, phixz, phiyz);
				} else {
					phix = phi_->getDdxVal(x, y, z);
					phiy = phi_->getDdyVal(x, y, z);
					phiz = phi_->getDdzVal(x, y, z);
					phixx = phi_->getD2dx2Val(x, y, z);
					phiyy = phi_->getD2dy2Val(x, y, z);
					phizz = phi_->getD2dz2Val(x, y, z);
					phixz = phi_->getD2dxzVal(x, y, z);
					phixy = phi_->getD2dxyVal(x, y, z);
					phiyz = phi_->getD2dyzVal(x, y, z);
				}

				// calculate curvature
				float H = (phizz * phiy * phiy - 2.0f * phiz * phiy * phiyz
						+ phiyy * phiz * phiz + phizz * phix * phix + phiyy
						* phix * phix - 2.0f * phiz * phix * phixz - 2.0f
						* phiy * phix * phixy + phixx * phiz * phiz + phixx
						* phiy * phiy) / (powf(
						phix * phix + phiy * phiy + phiz * phiz, 1.5f) + EPS);
				H = H * sgn(p_->c);

				// calculate derivatives of g
				float G = 1 - (*g)(x, y, z);
				float Gx = (*g_x)(x, y, z);
				float Gy = (*g_y)(x, y, z);
				float Gz = (*g_z)(x, y, z);

				// calculate update
				float c = p_->c;
				float d = p_->d;
				float epsilon = p_->epsilon;
				float dphidt = -G * c * (1.0f - epsilon * H) * sqrtf(
						phix * phix + phiy * phiy + phiz * phiz) - d * (Gx
						* phix + Gy * phiy + Gz * phiz);

				(*narrowBand_DphiDt)(narrowBand_count) = dphidt;
				(*narrowBand_x)(narrowBand_count) = x;
				(*narrowBand_y)(narrowBand_count) = y;
				(*narrowBand_z)(narrowBand_count) = z;
				narrowBand_count++;
			}
		}
	}

	for (int k = 0; k < narrowBand_count; k++) {
		// Update fullSeg, which allows detection of collisions
		int x = (*narrowBand_x)(k);
		int y = (*narrowBand_y)(k);
		int z = (*narrowBand_z)(k);
		float dphidt = (*narrowBand_DphiDt)(k);
		float newPhi = (*phi_)(x, y, z) + (p_->dt) * dphidt;
		//(*phi)(x,y,z) = newPhi;

		if (newPhi <= 0) {
			int xAbs, yAbs, zAbs;
			relToAbs(xAbs, yAbs, zAbs, x, y, z);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfloat-equal"
			//Old collision; do not update fullseg
			if ((*fullSeg)(xAbs, yAbs, zAbs) == -2.0f) {
				continue;
			}

			if ((*fullSeg)(xAbs, yAbs, zAbs) != 0.0f &&
					(*fullSeg)(xAbs, yAbs, zAbs) != _seedIdx) {
				//New collision
				(*fullSeg)(xAbs, yAbs, zAbs) = -1.0f;
			} else {
				(*fullSeg)(xAbs, yAbs, zAbs) = _seedIdx;
				if ((*fullSeg)(xAbs, yAbs, zAbs) != _seedIdx) {
					//This might not be sufficient to take care of race conditions, but it's cheap
					(*fullSeg)(xAbs, yAbs, zAbs) = -1.0f;
				}
			}
#pragma clang diagnostic pop
		}
	}
}