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

PnGetMeNonrigidHints() made available. However, there is still some bug in...

PnGetMeNonrigidHints() made available. However, there is still some bug in preserving the generated power noise array.
Or it is perhaps in the global pointers on Mac compiler?
parent 1156fa33
Loading
Loading
Loading
Loading
+40 −49
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include "params.h"
#include "graphics.h"
#include "TriangleMesh.h"
#include "rnd_generators.h"

//pressures:
#include <gsl/gsl_rng.h>
@@ -35,9 +36,10 @@ ActiveMesh mesh;
Vector3F sceneRes(8.f); //make isotropic resolution at 8 px/um

bool LoadNewMesh(const char* path,const int ID,const int fileNo);
int PnInitArray(const char *fileName,const char *outputName);
int PnInitArray(const char *fileName);
int PnInitArray(i3d::Vector3d<size_t> const &size, const size_t frames,
                const char *fileName,const char *outputName);
                const char *fileName);
int PnGetMeNonrigidHints(const float stretch,i3d::Image3d<float> &Hints);

int main(int argc,char **argv)
{
@@ -87,21 +89,25 @@ int main(int argc,char **argv)
	{ 
		// file exists, use it
		FLE.close();
		PnInitArray(fileName,argv[4]);
		PnInitArray(fileName);
	} 
	else 
	{
		// file is probably not existing, create it
		// according to the given setting
		size_t frames=(unsigned)atol(argv[2]);
		float bumpiness=(float)atof(argv[3]);

		PnInitArray(i3d::Vector3d<size_t>(
		   (size_t)(mesh.meshPlaygroundSize.x*sceneRes.x),
		   (size_t)(mesh.meshPlaygroundSize.y*sceneRes.y),
		   (size_t)(mesh.meshPlaygroundSize.z*sceneRes.z)),
		   frames,fileName,argv[4]);
		   frames,fileName);
	} 

	const float bumpiness=(float)atof(argv[3]);
	i3d::Image3d<float> hints;
	PnGetMeNonrigidHints(bumpiness,hints);
	hints.SaveImage(argv[4]);
}


@@ -192,8 +198,7 @@ size_t pnRealWidth;

//-----------------------------------------------------------------------------
int PnInitArray(i3d::Vector3d<size_t> const &size, const size_t frames,
                const char *fileName,
                const char *outputName)
                const char *fileName)
{
	// if required, init multi-threaded computing
	const size_t CPUs = i3d::GetNumberOfProcessors();
@@ -234,8 +239,6 @@ int PnInitArray(i3d::Vector3d<size_t> const &size, const size_t frames,
		PN_ERROR_REPORT(err.str());
	}

	PN_DEBUG_REPORT("Starting to init the Fourier image of size "
			<< image_sz*sizeof(float) << " Bytes");
	PN_DEBUG_REPORT("Starting to init the Fourier image of size "
			<< image_sz*sizeof(float)/(1<<20) << " MBytes");

@@ -364,7 +367,7 @@ int PnInitArray(i3d::Vector3d<size_t> const &size, const size_t frames,


//-----------------------------------------------------------------------------
int PnInitArray(const char *fileName,const char *outputName)
int PnInitArray(const char *fileName)
{
	if (!fileName)
		PN_ERROR_REPORT("NULL pointer for fileName");
@@ -432,36 +435,31 @@ int PnInitArray(const char *fileName,const char *outputName)
}

//-----------------------------------------------------------------------------
#if 0
void PnGetMeNonrigidHints(std::vector< i3d::Vector3d<float> /**/> const &BPList,
						const size_t BPLength,
						i3d::Image3d<float> &Hints)
int PnGetMeNonrigidHints(const float stretch,i3d::Image3d<float> &Hints)
{
	//consistency checks...
	if (!pnArray)
	if (pnArray == NULL)
		PN_ERROR_REPORT("'power noise' image (pnArray) is not ready");
	if (BPList.size() == 0)
		PN_ERROR_REPORT("Empty list given");
	if (BPList.size() < BPLength)
		PN_ERROR_REPORT("Empty list too short!?");
	if (mesh.Pos.size() == 0)
		PN_ERROR_REPORT("List of vertices is given empty");
	if (pnSizes[3] == 0)
		PN_ERROR_REPORT("'power noise' image (pnArray) is crippled, it is ready for zero frames");

	//find the (rectangular coordinate-system axis-aligned) bounding box
	//in microns...
	float xFrom=100000000000000.f;
	float yFrom=100000000000000.f;
	float zFrom=100000000000000.f;
	float xTo= -100000000000000.f;
	float yTo= -100000000000000.f;
	float zTo= -100000000000000.f;
	float xFrom=mesh.Pos[0].x;
	float yFrom=mesh.Pos[0].y;
	float zFrom=mesh.Pos[0].z;
	float xTo=  mesh.Pos[0].x;
	float yTo=  mesh.Pos[0].y;
	float zTo=  mesh.Pos[0].z;

	//sweep over the list and seek extremal coordinates
	for (size_t i=0; i < BPLength; ++i) {
	for (size_t i=1; i < mesh.Pos.size(); ++i) {
		//tested position
		const float x=BPList[i].x;
		const float y=BPList[i].y;
		const float z=BPList[i].z;
		const float x=mesh.Pos[i].x;
		const float y=mesh.Pos[i].y;
		const float z=mesh.Pos[i].z;

		if (x < xFrom) xFrom=x;
		if (y < yFrom) yFrom=y;
@@ -472,7 +470,8 @@ void PnGetMeNonrigidHints(std::vector< i3d::Vector3d<float> /**/> const &BPList,
	}

	PN_DEBUG_REPORT("points span x=" << xFrom << " to " << xTo << "; y="
	       << yFrom << " to " << yTo << "; z=" << zFrom << " to " << zTo);
	       << yFrom << " to " << yTo << "; z=" << zFrom << " to " << zTo
	       << " in microns\n");

	//minimum required size of the pnArray in pixels
	const size_t xSize=(size_t)ceilf( (xTo-xFrom) * sceneRes.x );
@@ -492,7 +491,7 @@ void PnGetMeNonrigidHints(std::vector< i3d::Vector3d<float> /**/> const &BPList,
	     	     << yOffs << "," << zOffs);

	//init output image
	Hints.MakeRoom(BPLength,pnSizes[3]-1,1);
	Hints.MakeRoom(mesh.Pos.size(),pnSizes[3]-1,1);
	Hints.SetOffset(i3d::Offset(0.f,0.f,0.f));
	Hints.SetResolution(i3d::Resolution(1.0f,1.0f,1.0f));

@@ -504,15 +503,6 @@ void PnGetMeNonrigidHints(std::vector< i3d::Vector3d<float> /**/> const &BPList,
	const size_t slice_sz = pnSizes[1] * buffer_line_length;
	const size_t frame_sz = pnSizes[2] * slice_sz;

	/*
	//for computing mean and variance values of used 'power noise' values
	double sum=0;
	double sum2=0;

	int histo[1001]; //TEST
	for (size_t i=0; i < 1001; ++i) histo[i]=0;
	*/

	//to access pixel at [x,y,z,t], one needs to look at
	// *(pnArray + t*frame_sz + z*slice_sz + y*buffer_line_length + x)
	// it has a type 'float'
@@ -522,11 +512,11 @@ void PnGetMeNonrigidHints(std::vector< i3d::Vector3d<float> /**/> const &BPList,
	for (size_t t=1; t < pnSizes[3]; ++t) {
	  float *pA=pnArray + t*frame_sz;

	  for (size_t i=0; i < BPLength; ++i, ++pH) {
	  for (size_t i=0; i < mesh.Pos.size(); ++i, ++pH) {
		//convert absolute micron size to pixels within the pnArray
		const size_t x=(size_t)roundf((BPList[i].x-xFrom)*sceneRes.x) + xOffs;
		const size_t y=(size_t)roundf((BPList[i].y-yFrom)*sceneRes.y) + yOffs;
		const size_t z=(size_t)roundf((BPList[i].z-zFrom)*sceneRes.z) + zOffs;
		const size_t x=(size_t)roundf((mesh.Pos[i].x-xFrom)*sceneRes.x) + xOffs;
		const size_t y=(size_t)roundf((mesh.Pos[i].y-yFrom)*sceneRes.y) + yOffs;
		const size_t z=(size_t)roundf((mesh.Pos[i].z-zFrom)*sceneRes.z) + zOffs;
		*pH= *(pA + z*slice_sz + y*buffer_line_length + x);
		*pH-=*(pA + z*slice_sz + y*buffer_line_length + x -frame_sz);
	  }
@@ -539,7 +529,7 @@ void PnGetMeNonrigidHints(std::vector< i3d::Vector3d<float> /**/> const &BPList,
		double mean=0.;
		float minPN=10000.f;
		float maxPN=-10000.f;
		for (size_t i=0; i < BPLength; ++i) {
		for (size_t i=0; i < mesh.Pos.size(); ++i) {
			mean+=*(pH+i);
			if (*(pH+i) < minPN) minPN=*(pH+i);
			if (*(pH+i) > maxPN) maxPN=*(pH+i);
@@ -547,7 +537,7 @@ void PnGetMeNonrigidHints(std::vector< i3d::Vector3d<float> /**/> const &BPList,

		//plan changes:
		//mean to subtract
		const float fmean=static_cast<float>(mean/(double)BPLength);
		const float fmean=static_cast<float>(mean/(double)mesh.Pos.size());

		//stretch factor so that maximum detected shift of any boundary
		//point is cellNonRigidDeformation microns, new extremas:
@@ -555,14 +545,15 @@ void PnGetMeNonrigidHints(std::vector< i3d::Vector3d<float> /**/> const &BPList,
		maxPN=fabsf(maxPN-fmean);
		if (minPN > maxPN) maxPN=minPN;
		//note: maxPN now holds max(minPN,maxPN)
		const float stretch=(float)configIni["cell"]["cell nonrigid deformation"]/maxPN;
		//const float stretch=(float)configIni["cell"]["cell nonrigid deformation"]/maxPN;
		//PN_DEBUG_REPORT("row " << t-1 << "\t mean is " << fmean << ", stretch is " << stretch);

		//commit changes
		for (size_t i=0; i < BPLength; ++i, ++pH) *pH=(*pH-fmean)*stretch;
		for (size_t i=0; i < mesh.Pos.size(); ++i, ++pH) *pH=(*pH-fmean)*stretch/maxPN;
	}

	return(0);
}
#endif


bool LoadNewMesh(const char* path,const int ID,const int fileNo)