Exemple #1
0
void levelSet3Dfast(MATRIXD im, MATRIX init_mask, int max_its, double E, double T, double alpha, 
					MATRIX *seg0, MATRIX *tmap, MATRIXD *phi, long **ls_vols, int offset){
	long dx = im.dx, dy = im.dy, dz = im.dz;
	int *px, *py, *pz, *qx, *qy, *qz, k, tmap_it = 1;
	MATRIX intTmp;
	MATRIX intTmp2 = allocateMatrix(dx,dy,dz);	// add a new temporary matrix
	MATRIXD dblTmp = allocateMatrixD(dx,dy,dz);	
	MATRIXD gradPhi = allocateMatrixD(dx,dy,dz);
	int minx, maxx, miny, maxy, minz, maxz;
	
	*phi = allocateMatrixD(dx,dy,dz);
	*seg0 = allocateMatrix(dx,dy,dz);
	*tmap = allocateMatrix(dx,dy,dz);
	*ls_vols = (long *)calloc(max_its,sizeof(long)); // initialized with 0
	
	initializeMatrix(tmap,0);
	initializeMatrix(seg0,0);		// initialized with 0
	initializeMatrix(&intTmp2,0);	// initialized with 0
	initializeGlobals4bwdist(dx,dy,dz,&px,&py,&pz,&qx,&qy,&qz,&intTmp);
	
	createSignedDistanceMap(init_mask,phi,px,py,pz,qx,qy,qz,intTmp,dblTmp); // temps: intTmp, dblTmp

	findLimits(init_mask,offset,&minx,&maxx,&miny,&maxy,&minz,&maxz);
	
	for (k = 1; k <= max_its; k++){
		calculateCurvature(*phi,&dblTmp,minx,maxx,miny,maxy,minz,maxz); // dblTmp keeps the curvatures
		calculateF(im,dblTmp,&dblTmp,E,T,alpha,minx,maxx,miny,maxy,minz,maxz); // first dblTmp (input): curvatures, second dblTmp (output): F values
		calculateGradPhi(*phi,dblTmp,&gradPhi,minx,maxx,miny,maxy,minz,maxz);
		evolveCurve(phi,dblTmp,gradPhi,minx,maxx,miny,maxy,minz,maxz);
		
		if (k % 50 == 0)
			reinitializeDistanceFunction(phi,init_mask,px,py,pz,qx,qy,qz,intTmp,dblTmp); // temps: init_mask, intTmp, dblTmp
		
		(*ls_vols)[k-1] = selectNonpositive(*phi,&intTmp2,minx,maxx,miny,maxy,minz,maxz); // use the second temporarymatrix
		
		if (k == 1){
			selectNonpositive(*phi,seg0,minx,maxx,miny,maxy,minz,maxz);
			copyMatrixWithLimits(tmap,*seg0,minx,maxx,miny,maxy,minz,maxz);
			findLimits(*tmap,offset,&minx,&maxx,&miny,&maxy,&minz,&maxz);
		}
		else if (k % 10 == 0){
			selectNonpositive(*phi,&intTmp2,minx,maxx,miny,maxy,minz,maxz);			// use the second temporarymatrix
			updateMaps(tmap,intTmp2,*seg0,tmap_it,minx,maxx,miny,maxy,minz,maxz);	// use the second temporarymatrix
			copyMatrixWithLimits(seg0,intTmp2,minx,maxx,miny,maxy,minz,maxz);		// use the second temporarymatrix
			tmap_it++;
			
			findLimits(*tmap,offset,&minx,&maxx,&miny,&maxy,&minz,&maxz);
		}
	}
	selectNonpositive(*phi,seg0,0,dx-1,0,dy-1,0,dz-1);
	//selectNonpositive(*phi,seg0,minx,maxx,miny,maxy,minz,maxz); ???? (consider this modification if there are more problems)
	
	freeMatrixD(gradPhi);
	freeMatrixD(dblTmp);
	freeMatrix(intTmp2);
	freeGlobals4bwdist(px,py,pz,qx,qy,qz,intTmp);
}
bool BinaryConnection::update()
{
	if (mIsConnected == false)
	{
		return false;
	}

	return deleteMaps() && updateMaps();
}
Exemple #3
0
void levelSet3D(MATRIXD im, MATRIX init_mask, int max_its, double E, double T, double alpha, 
				MATRIX *seg0, MATRIX *tmap, MATRIXD *phi, long **ls_vols){
	// some of these variables will be used as the local variables for other functions
	// they are defined outside (like global variables) because we want to decrease the overhead
	// corresponding to allocation and deallocation (since we have multiple calls for the same function
	long dx = im.dx, dy = im.dy, dz = im.dz;
	int *px, *py, *pz, *qx, *qy, *qz, k, tmap_it = 1;
	MATRIX intTmp;
	MATRIXD dblTmp = allocateMatrixD(dx,dy,dz);	
	MATRIXD gradPhi = allocateMatrixD(dx,dy,dz);
	
	*phi = allocateMatrixD(dx,dy,dz);
	*seg0 = allocateMatrix(dx,dy,dz);
	*tmap = allocateMatrix(dx,dy,dz);
	*ls_vols = (long *)calloc(max_its,sizeof(long)); // initialized with 0
	
	initializeMatrix(tmap,0);
	initializeGlobals4bwdist(dx,dy,dz,&px,&py,&pz,&qx,&qy,&qz,&intTmp);

	createSignedDistanceMap(init_mask,phi,px,py,pz,qx,qy,qz,intTmp,dblTmp); // temps: intTmp, dblTmp

	for (k = 1; k <= max_its; k++){
		calculateCurvature(*phi,&dblTmp,0,dx-1,0,dy-1,0,dz-1); // dblTmp keeps the curvatures
		calculateF(im,dblTmp,&dblTmp,E,T,alpha,0,dx-1,0,dy-1,0,dz-1); // first dblTmp (input): curvatures, second dblTmp (output): F values
		calculateGradPhi(*phi,dblTmp,&gradPhi,0,dx-1,0,dy-1,0,dz-1);
		evolveCurve(phi,dblTmp,gradPhi,0,dx-1,0,dy-1,0,dz-1);
		
		if (k % 50 == 0)
			reinitializeDistanceFunction(phi,init_mask,px,py,pz,qx,qy,qz,intTmp,dblTmp); // temps: init_mask, intTmp, dblTmp
		
		(*ls_vols)[k-1] = selectNonpositive(*phi,&intTmp,0,dx-1,0,dy-1,0,dz-1);
		
		if (k == 1){
			selectNonpositive(*phi,seg0,0,dx-1,0,dy-1,0,dz-1);
			copyMatrix(tmap,*seg0);
		}
		else if (k % 10 == 0){
			selectNonpositive(*phi,&intTmp,0,dx-1,0,dy-1,0,dz-1);
			updateMaps(tmap,intTmp,*seg0,tmap_it,0,dx-1,0,dy-1,0,dz-1);
			copyMatrix(seg0,intTmp);
			tmap_it++;
		}
	}
	selectNonpositive(*phi,seg0,0,dx-1,0,dy-1,0,dz-1);

	freeMatrixD(gradPhi);
	freeMatrixD(dblTmp);
	freeGlobals4bwdist(px,py,pz,qx,qy,qz,intTmp);
}