Exemplo n.º 1
0
void cMC_Geom<_DataType, _ExtraDataType>::SearchingBoundary(cStack<int>& StackInitBLocs)
{
	int			i, j, k, l, m, n, loc[8], DataCoor_i[3], EI[2], NI[3];
	double		CurrLoc_d[3], GradVec_d[3], ZeroCrossingLoc_d[3], Length_d;
	double		FirstDAtTheLoc_d, DataPosFromZeroCrossingLoc_d;
	int			NeighborsLocs[28], Num_i, IsFound;
	cStack<int>		StackUntouchedLocs;
	double		SD_d[5], Pt_d[3], ZCPt_d[3], t_d;



//	StackInitBLocs.setDataPointer(10);


	StackUntouchedLocs.Clear();
	
	printf ("Computing the Real Boundary \n");
	fflush(stdout);

	// Computing and Finding Real Boundary using the boundary from the classification
	for (i=0; i<StackInitBLocs.Size(); i++) {
		StackInitBLocs.IthValue(i, loc[0]);
		DataCoor_i[2] = loc[0]/this->WtimesH_mi;
		DataCoor_i[1] = (loc[0] - DataCoor_i[2]*this->WtimesH_mi)/this->Width_mi;
		DataCoor_i[0] = loc[0] % this->Width_mi;
		for (k=0; k<3; k++) {
			CurrLoc_d[k] = (double)DataCoor_i[k];
			GradVec_d[k] = (double)this->GradientVec_mf[loc[0]*3 + k];
		}
		Length_d = sqrt(GradVec_d[0]*GradVec_d[0] + GradVec_d[1]*GradVec_d[1] + 
						GradVec_d[2]*GradVec_d[2]);
		for (k=0; k<3; k++) GradVec_d[k] /= Length_d;

		IsFound = this->PED_m.FindZeroCrossingLocation(CurrLoc_d, GradVec_d, ZeroCrossingLoc_d,
									FirstDAtTheLoc_d, DataPosFromZeroCrossingLoc_d);
		if (!IsFound) continue;
		for (k=0; k<3; k++) DataCoor_i[k] = (int)ZeroCrossingLoc_d[k];

		ZCPt_d[0]=ZeroCrossingLoc_d[0];
		ZCPt_d[1]=ZeroCrossingLoc_d[1];
		ZCPt_d[2]=ZeroCrossingLoc_d[2];
				
/*
int FaceIndexT [6][5] = {
	{1, 0, 4, 5, 1}, {0, 2, 6, 4, 0}, {7, 6, 2, 3, 7}, 
	{1, 5, 7, 3, 1}, {5, 4, 6, 7, 5}, {1, 3, 2, 0, 1}
};
*/
		if (DataCoor_i[2]>=24 && DataCoor_i[2]<=26 &&
			DataCoor_i[1]>=96 && DataCoor_i[1]<=104 &&
			DataCoor_i[0]>=111 && DataCoor_i[0]<=121) { }
		else continue;








		MarkingVoxelEdges(DataCoor_i, GradVec_d, ZCPt_d);
		StackUntouchedLocs.Push(loc[0]);
	}


	//------------------------------------------------------------------------------
	// Saving the Computed Real Boundary Volume
	unsigned char		*ComputedBoundaryVolume = new unsigned char[this->WHD_mi];
	for (j=0; j<this->WHD_mi; j++) ComputedBoundaryVolume[j] = (unsigned char)0;
	printf ("\n# Computed Boundary Voxels = %d\n", StackUntouchedLocs.Size());
	for (j=0; j<StackUntouchedLocs.Size(); j++) {
		if (!StackUntouchedLocs.IthValue(j, loc[0])) { printf ("Stack Error\n"); break; }

		DataCoor_i[2] = loc[0]/this->WtimesH_mi;
		DataCoor_i[1] = (loc[0] - DataCoor_i[2]*this->WtimesH_mi)/this->Width_mi;
		DataCoor_i[0] = loc[0] % this->Width_mi;
		
		loc[1] = DataCoor_i[2]*this->WtimesH_mi + DataCoor_i[1]*this->Width_mi + (DataCoor_i[0]+1);
		loc[2] = DataCoor_i[2]*this->WtimesH_mi + (DataCoor_i[1]+1)*this->Width_mi + DataCoor_i[0];
		loc[3] = DataCoor_i[2]*this->WtimesH_mi + (DataCoor_i[1]+1)*this->Width_mi + (DataCoor_i[0]+1);

		loc[4] = (DataCoor_i[2]+1)*this->WtimesH_mi + DataCoor_i[1]*this->Width_mi + DataCoor_i[0];
		loc[5] = (DataCoor_i[2]+1)*this->WtimesH_mi + DataCoor_i[1]*this->Width_mi + (DataCoor_i[0]+1);
		loc[6] = (DataCoor_i[2]+1)*this->WtimesH_mi + (DataCoor_i[1]+1)*this->Width_mi + DataCoor_i[0];
		loc[7] = (DataCoor_i[2]+1)*this->WtimesH_mi + (DataCoor_i[1]+1)*this->Width_mi + (DataCoor_i[0]+1);
		
		if (DataCoor_i[0]>=this->Width_mi)  loc[0] = loc[2] = loc[4] = loc[6] = 0;
		if (DataCoor_i[1]>=this->Height_mi) loc[0] = loc[1] = loc[4] = loc[5] = 0;
		if (DataCoor_i[2]>=this->Depth_mi)  loc[0] = loc[1] = loc[2] = loc[3] = 0;

		if (DataCoor_i[0]+1>=this->Width_mi)  loc[1] = loc[3] = loc[5] = loc[7] = 0;
		if (DataCoor_i[1]+1>=this->Height_mi) loc[2] = loc[3] = loc[6] = loc[7] = 0;
		if (DataCoor_i[2]+1>=this->Depth_mi) 	loc[4] = loc[5] = loc[6] = loc[7] = 0;

		for (k=0; k<8; k++) ComputedBoundaryVolume[loc[k]] = (unsigned char)255;
	}
	printf ("Saving the Computed Boundary Volume \n");
	char	Postfix[200];
	sprintf (Postfix, "Mat00_ComputedBoundary");
	SaveVolume(ComputedBoundaryVolume, 0, 255, Postfix); // Control.cpp
	printf ("The End of the Saving\n\n");
	fflush(stdout);
	delete [] ComputedBoundaryVolume;
	// The End of the Saving
	//------------------------------------------------------------------------------


	int		Count=0, NewVoxel;
	ZeroCrossingVolume_mf[0] = this->MinSecond_mf + 1.0;
	printf ("Searching the connected boundary from the computed boundary\n");
	// Searching the connected boundary from the computed boundary
	do {
	
		if (!StackUntouchedLocs.Pop(loc[0])) break;
		DataCoor_i[2] = loc[0]/this->WtimesH_mi;
		DataCoor_i[1] = (loc[0] - DataCoor_i[2]*this->WtimesH_mi)/this->Width_mi;
		DataCoor_i[0] = loc[0] % this->Width_mi;




			if (DataCoor_i[2]>=24 && DataCoor_i[2]<=26 &&
				DataCoor_i[1]>=96 && DataCoor_i[1]<=104 &&
				DataCoor_i[0]>=111 && DataCoor_i[0]<=121) { }
			else continue;





		for (n=0; n<27; n++) NeighborsLocs[n] = 0;
		Num_i = 0;
		for (n=DataCoor_i[2]-1; n<=DataCoor_i[2]+1; n++) {
			if (n<0 || n>=this->Depth_mi-2) continue;
			for (m=DataCoor_i[1]-1; m<=DataCoor_i[1]+1; m++) {
				if (m<0 || m>=this->Height_mi-2) continue;
				for (l=DataCoor_i[0]-1; l<=DataCoor_i[0]+1; l++) {
					if (l<0 || l>=this->Width_mi-2) continue;
					loc[1] = n*this->WtimesH_mi + m*this->Width_mi + l;
					NeighborsLocs[Num_i++] = loc[1];
				}
			}
		}

		loc[1] = DataCoor_i[2]*this->WtimesH_mi + DataCoor_i[1]*this->Width_mi + (DataCoor_i[0]+1);
		loc[2] = DataCoor_i[2]*this->WtimesH_mi + (DataCoor_i[1]+1)*this->Width_mi + DataCoor_i[0];
		loc[3] = DataCoor_i[2]*this->WtimesH_mi + (DataCoor_i[1]+1)*this->Width_mi + (DataCoor_i[0]+1);

		loc[4] = (DataCoor_i[2]+1)*this->WtimesH_mi + DataCoor_i[1]*this->Width_mi + DataCoor_i[0];
		loc[5] = (DataCoor_i[2]+1)*this->WtimesH_mi + DataCoor_i[1]*this->Width_mi + (DataCoor_i[0]+1);
		loc[6] = (DataCoor_i[2]+1)*this->WtimesH_mi + (DataCoor_i[1]+1)*this->Width_mi + DataCoor_i[0];
		loc[7] = (DataCoor_i[2]+1)*this->WtimesH_mi + (DataCoor_i[1]+1)*this->Width_mi + (DataCoor_i[0]+1);

		if (DataCoor_i[0]>=this->Width_mi)  loc[0] = loc[2] = loc[4] = loc[6] = 0;
		if (DataCoor_i[1]>=this->Height_mi) loc[0] = loc[1] = loc[4] = loc[5] = 0;
		if (DataCoor_i[2]>=this->Depth_mi)  loc[0] = loc[1] = loc[2] = loc[3] = 0;

		if (DataCoor_i[0]+1>=this->Width_mi)  loc[1] = loc[3] = loc[5] = loc[7] = 0;
		if (DataCoor_i[1]+1>=this->Height_mi) loc[2] = loc[3] = loc[6] = loc[7] = 0;
		if (DataCoor_i[2]+1>=this->Depth_mi) 	loc[4] = loc[5] = loc[6] = loc[7] = 0;



		// ZeroCrossingVolume_mf[] is initialized with (this->MinSecond_mf-1.0)
		for (i=0; i<12; i++) {
			EI[0] = EdgeListT[i][0];
			EI[1] = EdgeListT[i][1];
			SD_d[0] = ZeroCrossingVolume_mf[loc[EI[0]]];
			SD_d[1] = ZeroCrossingVolume_mf[loc[EI[1]]];
			
			if (SD_d[0]*SD_d[1]<=0.0) {
			
				for (k=0; k<3; k++) NI[k] = EdgeToNeighborT[EI[0]][EI[1]][k];
				for (m=0; m<3; m++) {
					if (NeighborsLocs[NI[m]]>0) {
					
						DataCoor_i[2] = NeighborsLocs[NI[m]]/this->WtimesH_mi;
						DataCoor_i[1] = (NeighborsLocs[NI[m]] - DataCoor_i[2]*this->WtimesH_mi)/this->Width_mi;
						DataCoor_i[0] = NeighborsLocs[NI[m]] % this->Width_mi;

						if (DataCoor_i[0]>=this->Width_mi-1) continue;
						if (DataCoor_i[1]>=this->Height_mi-1) continue;
						if (DataCoor_i[2]>=this->Depth_mi-1) continue;
						
//						printf ("DataCoor = %3d %3d %3d\n", DataCoor_i[0], DataCoor_i[1], DataCoor_i[2]);
						
						t_d = fabs(SD_d[0])/fabs(SD_d[0]-SD_d[1]);
						for (k=0; k<3; k++) {
							Pt_d[k] = (double)DataCoor_i[k];
							Pt_d[k] += (double)RelativeLocT[EI[0]][k];
							Pt_d[k] += (double)EdgeDirT[EI[0]][EI[1]][k]*t_d;
						}

//						printf ("Pt_d = %.2f %.2f %.2f\n", Pt_d[0], Pt_d[1], Pt_d[2]);
						this->GradVecInterpolation(Pt_d, GradVec_d);
						
						NewVoxel = MarkingVoxelEdges(DataCoor_i, GradVec_d, Pt_d);
						if (NewVoxel) StackUntouchedLocs.Push(NeighborsLocs[NI[m]]);

#ifdef	DEBUG_MC_GEOM
						if (NewVoxel) {
							printf ("DataCoor = %3d %3d %3d, ", DataCoor_i[0], DataCoor_i[1], DataCoor_i[2]);
							printf ("GradVec = %7.2f %7.2f %7.2f, ", GradVec_d[0], GradVec_d[1], GradVec_d[2]);
							printf ("This voxel is marked ");
							printf ("\n\n");
						}
#endif


					}
				}
			}
		}
	
		if (Count++%10000==0) {
			printf ("The Size of StackUntouchedLocs = %d\n", StackUntouchedLocs.Size());
			fflush(stdout);
		}
	
	} while (StackUntouchedLocs.Size()>0);
	printf ("The searching is done\n\n");
	fflush(stdout);

	StackUntouchedLocs.Destroy();
}
Exemplo n.º 2
0
inline  void Dump(cStack<int/*, string*/>& pl_stack)//Displays the whole stack on screen
	{ while(pl_stack.Size() != 0) cout<< pl_stack.Pull() <<endl; }