Commit b6a76877 authored by Vladimír Ulman's avatar Vladimír Ulman
Browse files

CHG: read all cells at one time point, than next timepoint... was abandoned.

parent 72d3d157
Loading
Loading
Loading
Loading
+63 −122
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ ActiveMesh mesh;
class timeVector: public std::vector<int>
{
  public:
	void Init(const size_t length=500)
	void Init(const size_t length=200)
	{ this->insert(this->end(),length,-1); }
};
//
@@ -45,7 +45,7 @@ std::map<int,timeVector> tipOffsets;
class timeVectorC: public std::vector<Vector3F>
{
  public:
	void Init(const size_t length=500)
	void Init(const size_t length=200)
	{ this->insert(this->end(),length,Vector3F(-1.f)); }
};
std::map<int,timeVectorC> tipCoords;
@@ -68,8 +68,8 @@ bool LoadNewMesh(const char* path,
int  RenderMesh(const char* path,
					 const int ID,
					 int fileNo,
					 i3d::Image3d<i3d::GRAY16> &mask,
					 i3d::Image3d<i3d::GRAY16> &texture);
					 i3d::Image3d<i3d::GRAY16> *mask,
					 i3d::Image3d<i3d::GRAY16> *texture);

template <class T> void CompleteSimulation(i3d::Image3d<T> &img);

@@ -79,7 +79,7 @@ int main(int argc,char **argv)
	{
		//I'm executed with no params, provide help
		std::cout << "ADD SOME HEADER INFORMATION HERE\n\n";
		std::cout << "params:  config_file  path_to_VTKs path_to_output  num  [time_point] [no_of_time_points]\n\n";
		std::cout << "params:  config_file  path_to_VTKs path_to_output  dataset_ID  [time_point] [no_of_time_points]\n\n";
		std::cout << "The program will try to load object files (cell body volumetric mesh and\n"
                   "filopodia skeleton definition) iteratively (starting from 0th time point)\n"
                   "until it fails loading cell body file. Filopodia files for the current time\n"
@@ -101,7 +101,7 @@ int main(int argc,char **argv)
	int framesToGoHome=999999999;
	if (argc == 7) framesToGoHome=atoi(argv[6]);

	//get number of cell to be processed (1,2,3,...)
	//get dataset ID
	int ID=atoi(argv[4]);

	//I'm called as generator/simulator, init the situation...
@@ -109,18 +109,17 @@ int main(int argc,char **argv)

	std::cout << "FIRST RUN: reading all meshes to figure out minimal bounding box.\n";
	//doubling iteration variables not to loose their values
	int ii(i);                           //starting index
	int fframesToGoHome(framesToGoHome); //how many indices to read
	Vector3F minBB(FLT_MAX, FLT_MAX, FLT_MAX),
				maxBB(-FLT_MAX, -FLT_MAX, -FLT_MAX); //bounding box corners
	bool readingSucceded = true;

   int ii;

	for (size_t ids=0; ids<ID; ids++)
	while ((fframesToGoHome > 0) && (readingSucceded))
	{
		ii = i;                           //starting index
		int fframesToGoHome(framesToGoHome); //how many indices to read


		while ((fframesToGoHome > 0) && (LoadNewMesh(argv[2],ids+1,ii)))
		 for (size_t ids=0; 
				(ids<ID) && (readingSucceded = LoadNewMesh(argv[2],ids+1,ii)); 
				ids++)
		{

		 /* jen vypisy
@@ -143,10 +142,11 @@ int main(int argc,char **argv)
		*/

			mesh.UpdateMeshBBox(minBB,maxBB);

		}
		++ii;
		--fframesToGoHome;
	}
	}

	//ii is the last timePoint -> allocate vector of cell centres large enough
	centreCoords.insert(centreCoords.end(),(unsigned)(ii)+1,Vector3F(-1.f));
@@ -171,75 +171,49 @@ int main(int argc,char **argv)

	std::cout << "SECOND RUN: reading all meshes to conduct the texture simulation and rendering.\n";

	i3d::Image3d<i3d::GRAY16> mask,texture;
	i3d::Image3d<i3d::GRAY16> *mask = new i3d::Image3d<i3d::GRAY16> [ID];
	i3d::Image3d<i3d::GRAY16> *texture = new i3d::Image3d<i3d::GRAY16> [ID];
	i3d::Image3d<i3d::GRAY16> maskUnified, textureUnified;
   char fileName[1024];
	readingSucceded = true;

	for (size_t ids=0; ids<ID; ids++)
	while ((framesToGoHome > 0) && (readingSucceded))
	{
		ii = i;
		int fframesToGoHome(framesToGoHome); //how many indices to read

		/// empty the buffer with fluorescent dots (molecules)
		mesh.dots.clear();

		while ((fframesToGoHome > 0) && (LoadNewMesh(argv[2],ids+1,ii,true)))
		 for (size_t ids=0; 
				(ids<ID) && (readingSucceded = LoadNewMesh(argv[2],ids+1,i,true)); 
				ids++)
		 {
			 // here we render mesh into 'mask' and 'texture' image,
			 // i.e. the phantom should be ready
			 RenderMesh(argv[3], ids, ii, mask, texture);
		 	
			 std::cout << "exporting isotropic mask #" << ii << "\n";
			 sprintf(fileName,"%s/ISOmask_%02d_t%03d.ics",argv[3],ids,ii);
			 std::cout << "fname: " << fileName << std::endl;
			 mask.SaveImage(fileName);
		 
			 std::cout << "exporting phantom #" << ii << "\n";
			 sprintf(fileName,"%s/phantom_%02d_t%03d.ics",argv[3],ids,ii);
			 std::cout << "fname: " << fileName << std::endl;
			 texture.SaveImage(fileName);
		 
			 ++ii;
			 --fframesToGoHome;
		}
			 RenderMesh(argv[3], ids, i, mask, texture);
		 }

	std::cout << "THIRD RUN: merging the images + final rendering.\n";
	i3d::Image3d<i3d::GRAY16> maskUnified, textureUnified; 
	i3d::Image3d<i3d::GRAY16> *masks = new i3d::Image3d<i3d::GRAY16> [ID];
	i3d::Image3d<i3d::GRAY16> *textures = new i3d::Image3d<i3d::GRAY16> [ID];

	for (size_t timeidx=0; timeidx<ii; timeidx++)
	{
		 for (size_t ids=0; ids<ID; ids++)
		 {
			 sprintf(fileName,"%s/ISOmask_%02d_t%03d.ics",argv[3],ids,timeidx);
			 std::cout << "fname: " << fileName << std::endl;
			 masks[ids].ReadImage(fileName);
		 MergeImages(mask, ID, maskUnified);
				 
			 sprintf(fileName,"%s/phantom_%02d_t%03d.ics",argv[3],ids,timeidx);
			 std::cout << "fname: " << fileName << std::endl;
			 textures[ids].ReadImage(fileName);
		 }
		 std::cout << "exporting isotropic mask #" << i << "\n";
		 sprintf(fileName,"%s/ISOmask_t%03d.ics",argv[3],i);
		 maskUnified.SaveImage(fileName);

		 MergeImages(masks, ID, maskUnified);
		 MergeImages(textures, ID, textureUnified);
		 MergeImages(texture, ID, textureUnified);

		 std::cout << "exporting phantom #" << timeidx << "\n";
		 sprintf(fileName,"%s/finalPhantom_t%03d.ics",argv[3],timeidx);
		 std::cout << "exporting phantom #" << i << "\n";
		 sprintf(fileName,"%s/phantom_t%03d.ics",argv[3],i);
		 textureUnified.SaveImage(fileName);

#ifdef DO_PHASE_II_AND_III
		 CompleteSimulation(textureUnified);

		 std::cout << "exporting texture #" << timeidx << "\n";
		 sprintf(fileName,"%s/finalTexture_t%03d.ics",argv[3],timeidx);
		 std::cout << "exporting texture #" << i << "\n";
		 sprintf(fileName,"%s/texture_t%03d.ics",argv[3],i);
		 textureUnified.SaveImage(fileName);
#endif

		 ++i;
		 --framesToGoHome;
	}

	delete [] masks;
	delete [] textures;
	delete [] mask;
	delete [] texture;

	//report the tip trajectories
	sprintf(fileName,"%s/ID%d_afterTM/tip_trajectories_pxOffsets.txt",argv[3],ID);
@@ -413,12 +387,12 @@ bool LoadNewMesh(const char* path,
					tipCoords[idx].Init();
				}

/*				std::cout << "before check " << std::endl;
				std::cout << "before check " << std::endl;
				std::cout << "idx: " << idx << std::endl;
				std::cout << "fileNo: " << fileNo << std::endl;
				std::cout << "tippOffsets.size: " << tipOffsets[idx].size() << "\n";*/
				std::cout << "tippOffsets.size: " << tipOffsets[idx].size() << "\n";
				tipOffsets[idx].at((unsigned)fileNo)=(signed)iterTips->second;
//				std::cout << "after check" << std::endl;
				std::cout << "after check" << std::endl;

				++iterTips;
			}
@@ -448,24 +422,24 @@ bool LoadNewMesh(const char* path,
int RenderMesh(const char* path,
					const int ID,
					int fileNo,
					i3d::Image3d<i3d::GRAY16> &mask,
					i3d::Image3d<i3d::GRAY16> &texture)
					i3d::Image3d<i3d::GRAY16> *mask,
					i3d::Image3d<i3d::GRAY16> *texture)
{
   char fileName[1024];

	//setup isotropic(!) image for mask-output of the simulated cell
	mask.SetOffset(i3d::Offset(mesh.meshShift.x,mesh.meshShift.y,mesh.meshShift.z));
	mask[ID].SetOffset(i3d::Offset(mesh.meshShift.x,mesh.meshShift.y,mesh.meshShift.z));
	const float isoRes = mesh.configFile.texture_Resolution.x;
	mask.SetResolution(i3d::Resolution(isoRes,isoRes,isoRes));
	mask[ID].SetResolution(i3d::Resolution(isoRes,isoRes,isoRes));
	//use "optimal" calculated size
	mask.MakeRoom((size_t)(mesh.meshPlaygroundSize.x*isoRes),
	mask[ID].MakeRoom((size_t)(mesh.meshPlaygroundSize.x*isoRes),
                 (size_t)(mesh.meshPlaygroundSize.y*isoRes),
                 (size_t)(mesh.meshPlaygroundSize.z*isoRes));
	mask.GetVoxelData()=0;
	mask[ID].GetVoxelData()=0;

	//renders the isotropic mask into the image
	std::cout << "rendering mask #" << fileNo << "\n";
	mesh.RenderMask_bodyVol(mask); //full volume
	mesh.RenderMask_bodyVol(mask[ID]); //full volume
	std::map<int,timeVector>::iterator tipIter=tipOffsets.begin();
	while (tipIter != tipOffsets.end())
	{
@@ -478,7 +452,7 @@ int RenderMesh(const char* path,
		//else std::cout << "RENDERING ID " << tipIter->first << " with no detection\n";

		if (tipIter->second.at((unsigned)fileNo) > -1)
			mesh.RenderMask_filo(mask,(unsigned)tipIter->second.at((unsigned)fileNo),(unsigned short)tipIter->first,false,checkCollisionOfTip);
			mesh.RenderMask_filo(mask[ID],(unsigned)tipIter->second.at((unsigned)fileNo),(unsigned short)tipIter->first,false,checkCollisionOfTip);
		++tipIter;
	}

@@ -486,7 +460,7 @@ int RenderMesh(const char* path,
	std::cout << "exporting isotropic mask #" << fileNo << "\n";
	sprintf(fileName,"%s/tmp_%d_ISOmask_t%03d.ics",path,ID,fileNo);

	mask.SaveImage(fileName);
	mask[ID].SaveImage(fileName);
	*/ 

	//updates the texture fl. points
@@ -497,16 +471,16 @@ int RenderMesh(const char* path,
		//
		//first, prepare the cell body texture
		std::cout << "rendering texture first run\n";
		mesh.InitDots_body(mask);
		mesh.InitDots_body(mask[ID]);
		//slightly displace the fl. points to "hide" the FF shift-effects
		//NB: the filopodia texture dots are now empty
		mesh.BrownDots(mask);
		mesh.BrownDots(mask[ID]);

		//second, create texture for filopodia
		mesh.dots_filo.clear();
		mesh.dots_filo.reserve(300000);
		for (unsigned int i=0; i < mesh.GetFilopodiaNumber(); ++i)
			mesh.InitDots_filo(mask,i); //filopodium one by one
			mesh.InitDots_filo(mask[ID],i); //filopodium one by one
		std::cout << "filo dots size=" << mesh.dots_filo.size() << "\n";
	}
	else
@@ -530,9 +504,9 @@ int RenderMesh(const char* path,
		FF.x=new i3d::Image3d<float>;
		FF.y=new i3d::Image3d<float>;
		FF.z=new i3d::Image3d<float>;
		FF.x->CopyMetaData(mask);
		FF.y->CopyMetaData(mask);
		FF.z->CopyMetaData(mask);
		FF.x->CopyMetaData(mask[ID]);
		FF.y->CopyMetaData(mask[ID]);
		FF.z->CopyMetaData(mask[ID]);

		//create a FF (FlowField) by "rendering displacement triangles"
		mesh.ConstructFF_T(FF);
@@ -548,7 +522,7 @@ int RenderMesh(const char* path,
*/

		//apply the FF on the fl. dots
		mesh.FFDots(mask,FF);
		mesh.FFDots(mask[ID],FF);

		//FF destructor will delete dyn. allocated images in the FF...

@@ -556,7 +530,7 @@ int RenderMesh(const char* path,
		mesh.dots_filo.clear();
		mesh.dots_filo.reserve(300000);
		for (unsigned int i=0; i < mesh.GetFilopodiaNumber(); ++i)
			mesh.InitDots_filo(mask,i); //filopodium one by one
			mesh.InitDots_filo(mask[ID],i); //filopodium one by one
		std::cout << "filo dots size=" << mesh.dots_filo.size() << "\n";
	}

@@ -566,7 +540,7 @@ int RenderMesh(const char* path,
	//renders the isotropic texture
	std::cout << "rendering texture I   #" << fileNo << "\n";
	// i3d::Image3d<i3d::GRAY16> texture;
	mesh.RenderDots(mask,texture);
	mesh.RenderDots(mask[ID],texture[ID]);
	//
	//or always one shot (for debugging, always a new texture, incoherent):
	//i3d::Image3d<i3d::GRAY16> texture;
@@ -574,40 +548,7 @@ int RenderMesh(const char* path,
 
	/*
	sprintf(fileName,"%s/tmp_%d_phantom_t%03d.ics",path,ID,fileNo);
	texture.SaveImage(fileName);
   */

	/*
#ifdef DO_PHASE_II_AND_III
	//do phase II on the isotropic image
	std::cout << "rendering texture II  #" << fileNo << "\n";
	i3d::Image3d<float> intermediate;
	mesh.PhaseII(textureUnified,intermediate);

	//UNCOMMENT THESE IF YOU WANT TO SEE PHANTOM AFTER STAGE II PROCESSING
	//sprintf(fileName,"%s/ID%d_afterTM/phantomII_t%03d.tif",path,ID,fileNo);
	//intermediate.SaveImage(fileName);

 #ifdef DO_ANISOTROPIC_OUTPUT
	//downsample now:
	const float factor[3]={1.f, //NB: isotropic phantom has resolution of the x-axis
	  mesh.configFile.texture_Resolution.y/mesh.configFile.texture_Resolution.x,
	  mesh.configFile.texture_Resolution.z/mesh.configFile.texture_Resolution.x};
	i3d::Image3d<float>* tmp=NULL;
	i3d::lanczos_resample(&intermediate,tmp,factor,2);
	intermediate=*tmp;
	delete tmp;
 #endif

	//do phase III on the final image (can be iso or aniso now)
	std::cout << "rendering texture III #" << fileNo << "\n";
	mesh.PhaseIII(intermediate,textureUnified);

	//save the texture and that's it for texture image
	std::cout << "exporting texture #" << fileNo << "\n";
	sprintf(fileName,"%s/ID%d_afterTM/texture_t%03d.ics",path,ID,fileNo);
	textureUnified.SaveImage(fileName);
#endif
	texture[ID].SaveImage(fileName);
   */

/*