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

Merge branch 'sim-cosmetics'

parents 4d53acb8 c253586d
......@@ -59,7 +59,7 @@ set(SOURCES
src/util/texture/myround.cpp
src/util/texture/texture.cpp
src/util/synthoscopy/finalpreview.cpp
src/util/synthoscopy/Filogen_VM.cpp
src/util/synthoscopy/FiloGen_VM.cpp
src/util/synthoscopy/SNR.cpp
src/DisplayUnits/SceneryDisplayUnit.cpp
src/DisplayUnits/SceneryBufferedDisplayUnit.cpp
......
......@@ -93,7 +93,9 @@ private:
lastUpdatedTime = currTime;
}
else
{
DEBUG_REPORT(IDSIGN << "skipping update now");
}
}
// ------------- rendering -------------
......
......@@ -9,19 +9,19 @@
decreasing photon budget, or just always returns 1.0 iff photobleaching
shall be ignored (photobleaching feature is disabled */
#ifdef ENABLED_PHOTOBLEACHING
inline float GetBleachFactor(const short cntOfExcitations)
inline float getBleachFactor(const short cntOfExcitations)
{
return std::exp((float)-cntOfExcitations);
}
#else
inline float GetBleachFactor(const short)
inline float getBleachFactor(const short)
{
return 1.0f;
}
#endif
void Texture::RenderIntoPhantom(i3d::Image3d<float> &phantoms, const float quantization)
void Texture::renderIntoPhantom(i3d::Image3d<float> &phantoms, const float quantization)
{
DEBUG_REPORT("going to render " << dots.size() << " dots");
......@@ -58,7 +58,7 @@ void Texture::RenderIntoPhantom(i3d::Image3d<float> &phantoms, const float quant
//plus upper bound (tests also underflows... "negative" coordinates)
if (imgPos.elemIsLessThan(imgSize))
{
const float fval = quantization * GetBleachFactor(dot.cntOfExcitations);
const float fval = quantization * getBleachFactor(dot.cntOfExcitations);
#ifdef DEBUG
meanIntContribution += fval;
++meanIntContCounter;
......@@ -80,7 +80,7 @@ void Texture::RenderIntoPhantom(i3d::Image3d<float> &phantoms, const float quant
}
void TextureQuantized::RenderIntoPhantom(i3d::Image3d<float> &phantoms)
void TextureQuantized::renderIntoPhantom(i3d::Image3d<float> &phantoms)
{
DEBUG_REPORT("going to render " << dots.size() << " quantum dots");
......@@ -107,7 +107,7 @@ void TextureQuantized::RenderIntoPhantom(i3d::Image3d<float> &phantoms)
// a variable for debugging the photobleaching
double meanIntContribution = 0.0f;
const float quantumElems = qCounts.x * qCounts.y * qCounts.z;
const float quantumElems = (float)qCounts.x * (float)qCounts.y * (float)qCounts.z;
long meanIntContCounter = 0;
#endif
......@@ -128,7 +128,7 @@ void TextureQuantized::RenderIntoPhantom(i3d::Image3d<float> &phantoms)
if (imgPos.elemIsGreaterOrEqualThan(halfBoxSize)
&& imgPos.elemIsLessThan(imgSize))
{
const float fval = GetBleachFactor(dot.cntOfExcitations);
const float fval = getBleachFactor(dot.cntOfExcitations);
#ifdef DEBUG
meanIntContribution += quantumElems * fval;
++meanIntContCounter;
......
......@@ -64,7 +64,7 @@ public:
/** setup the output image to wrap around the given geometry, respecting
the given outer frame (in pixels) and the wanted resolution of the image */
template <typename VT>
void SetupImageForRasterizingTexture( i3d::Image3d<VT>& img,
void setupImageForRasterizingTexture( i3d::Image3d<VT>& img,
const Vector3d<float>& imgRes,
const Geometry& geom,
const Vector3d<short>& pxFrameWidth = Vector3d<short>(2) )
......@@ -77,7 +77,7 @@ public:
texture (stored in 'img') respecting the actual shape of the agent ('geom'),
and considering given 'quantization' */
template <typename VT>
void SampleDotsFromImage(const i3d::Image3d<VT>& img,
void sampleDotsFromImage(const i3d::Image3d<VT>& img,
const Spheres& geom,
const VT quantization = 1)
{
......@@ -126,7 +126,7 @@ public:
}
#ifdef DEBUG
REPORT("there are " << missedDots << " (" << 100.f*missedDots/dots.size()
REPORT("there are " << missedDots << " (" << (float)(100*missedDots)/(float)dots.size()
<< " %) dots placed outside its original voxel");
REPORT("there are currently " << dots.size() << " registered dots");
#endif
......@@ -149,7 +149,7 @@ public:
is only shifting the range into [textureAverageIntensity-0.5,textureAverageIntensity+0.5].
Hence, with the higher value of the 'textureAverageIntensity', the contrast (ratio of
the highest over smallest intensity value) of the texture is essentially worsened. */
void CreatePerlinTexture(const Spheres& geom,
void createPerlinTexture(const Spheres& geom,
const Vector3d<FLOAT> textureResolution,
const double var,
const double alpha = 8,
......@@ -161,7 +161,7 @@ public:
{
//setup the aux texture image
i3d::Image3d<float> img;
SetupImageForRasterizingTexture(img,textureResolution, geom);
setupImageForRasterizingTexture(img,textureResolution, geom);
//sanity check... if the 'geom' is "empty", no texture image is "wrapped" around it,
//we do no creation of the texture then...
......@@ -187,15 +187,19 @@ public:
*i += textureIntShift;
//*i = std::max( *i, 0.f );
}
SampleDotsFromImage(img,geom, quantization);
sampleDotsFromImage(img,geom, quantization);
//NB: the function ignores any negative-valued texture image voxels,
// no dots are created for such voxels
if (shouldCollectOutlyingDots)
{
const int dotOutliers = CollectOutlyingDots(geom);
DEBUG_REPORT(dotOutliers << " (" << 100.f*dotOutliers/dots.size()
#ifndef DEBUG
collectOutlyingDots(geom);
#else
const int dotOutliers = collectOutlyingDots(geom);
DEBUG_REPORT(dotOutliers << " (" << (float)(100*dotOutliers)/(float)dots.size()
<< " %) dots had to be moved inside the initial geometry");
#endif
}
}
......@@ -205,7 +209,7 @@ public:
/** find dots that are outside the given geometry and "put them back",
which is randomly close to the centre of the closest sphere,
returns the number of such processed dots (for statistics purposes) */
int CollectOutlyingDots(const Spheres& geom)
int collectOutlyingDots(const Spheres& geom)
{
int count = 0;
#ifdef DEBUG
......@@ -275,7 +279,7 @@ public:
REPORT("average outside-to-surface distance " << outDist/(double)count << " um (in " << toc(stopWatch) << ")");
REPORT("average new-pos-to-centre distance " << inDist/(double)count << " um");
REPORT("secondary corrections of " << postCorrectionsCnt << "/" << count
<< " (" << 100.f*postCorrectionsCnt/count << " %) dots");
<< " (" << (float)(100*postCorrectionsCnt)/(float)count << " %) dots");
}
else
{
......@@ -292,7 +296,7 @@ public:
// rendering
/** renders the current content of the this->dots list into the given phantom image */
void RenderIntoPhantom(i3d::Image3d<float> &phantoms, const float quantization = 1);
void renderIntoPhantom(i3d::Image3d<float> &phantoms, const float quantization = 1);
};
/**
......@@ -368,8 +372,8 @@ public:
/** renders (quantum-wise) the current content of the this->dots list into the given phantom image,
the contributed intensity to the image should be 'quantum'-times greater than what would provide
the upstream, non-quantum Texture::RenderIntoPhantom(phantoms,1.0) */
void RenderIntoPhantom(i3d::Image3d<float> &phantoms);
the upstream, non-quantum Texture::renderIntoPhantom(phantoms,1.0) */
void renderIntoPhantom(i3d::Image3d<float> &phantoms);
};
......
#ifndef FILEDISPLAYUNIT_H
#define FILEDISPLAYUNIT_H
#include <fstream>
#include "DisplayUnit.h"
/**
* This class implements drawing by reporting what is being drawed
* into a file, in a (human-readable) textual form.
*
* Author: Vladimir Ulman, 2019
*/
class FileDisplayUnit : public DisplayUnit
{
public:
FileDisplayUnit(const char* filename)
{
logger.open(filename);
}
~FileDisplayUnit()
{
logger.close();
}
void DrawPoint(const int ID,
const Vector3d<float>& pos,
const float radius = 1.0f,
const int color = 0) override
{
logger << "Point ID " << ID << ": "
<< pos << ", radius=" << radius << ", color=" << color << "\n";
}
void DrawLine(const int ID,
const Vector3d<float>& posA,
const Vector3d<float>& posB,
const int color = 0) override
{
logger << "Line ID " << ID << ": "
<< posA << " <-> " << posB << ", color=" << color << "\n";
}
void DrawVector(const int ID,
const Vector3d<float>& pos,
const Vector3d<float>& vector,
const int color = 0) override
{
logger << "Vector ID " << ID << ": "
<< "(" << vector.x << "," << vector.y << "," << vector.z << ")"
<< " @ " << pos << ", color=" << color << "\n";
}
void DrawTriangle(const int ID,
const Vector3d<float>& posA,
const Vector3d<float>& posB,
const Vector3d<float>& posC,
const int color = 0) override
{
logger << "Triangle ID " << ID << ": "
<< posA << ", " << posB << ", " << posC << ", color=" << color << "\n";
}
void Tick(const char* msg) override
{
logger << "Tick " << (msg != NULL ? msg : "(no message given)") << "\n";
}
void Flush(void) override
{
logger.flush();
}
protected:
std::ofstream logger;
};
#endif
#ifndef FLIGHTRECORDERDISPLAYUNIT_H
#define FLIGHTRECORDERDISPLAYUNIT_H
#include <fstream>
#include "DisplayUnit.h"
/**
* This class implements drawing by reporting what is being drawed
* into a file, in a form of messages agreed with the SimViewer.
* SimViewer can later replay the messages.
*
* Author: Vladimir Ulman, 2019
*/
class FlightRecorderDisplayUnit : public DisplayUnit
{
public:
FlightRecorderDisplayUnit(const char* filename)
{
logger.open(filename);
}
~FlightRecorderDisplayUnit()
{
logger.close();
}
void DrawPoint(const int ID,
const Vector3d<float>& pos,
const float radius = 1.0f,
const int color = 0) override
{
//message syntax := v1 points N dim D Point1 ... PointN
// Point syntax := ID x1 ... xD radius color
//
//where N is the number of points in this message,
//where D is the dimension of one point,
//where x1,...,xD,radius are real scalars, ID,color are integer scalars
logger << "v1 points 1 dim 3 " << ID << " "
<< pos.x << " " << pos.y << " " << pos.z << " "
<< radius << " " << color << "\n";
}
void DrawLine(const int ID,
const Vector3d<float>& posA,
const Vector3d<float>& posB,
const int color = 0) override
{
// message syntax := v1 lines N dim D PointPair1 ... PointPairN
//PointPair syntax := ID o1 ... oD p1 ... pD color
//
//where N is the number of lines in this message,
//where D is the dimension of one line end point,
//where o1,...,oD,p1,...,pD are real scalars, ID,color are integer scalars
//
// o,p are two end points of a line
logger << "v1 lines 1 dim 3 " << ID << " "
<< posA.x << " " << posA.y << " " << posA.z << " "
<< posB.x << " " << posB.y << " " << posB.z << " "
<< color << "\n";
}
void DrawVector(const int ID,
const Vector3d<float>& pos,
const Vector3d<float>& vector,
const int color = 0) override
{
// message syntax := v1 vectors N dim D PointPair1 ... PointPairN
//PointPair syntax := ID o1 ... oD p1 ... pD color
//
//where N is the number of vectors in this message,
//where D is the dimension of the base coordinate and vector itself
//where o1,...,oD,p1,...,pD are real scalars, ID,color are integer scalars
//
// o is the base coordinate/anchor point of the vector, p is the vector itself
//
//vector ID essentially determines to which cell it belongs
//vector color essentially determines what type this vector is
logger << "v1 vectors 1 dim 3 " << ID << " "
<< pos.x << " " << pos.y << " " << pos.z << " "
<< vector.x << " " << vector.y << " " << vector.z << " "
<< color << "\n";
}
void DrawTriangle(const int ID,
const Vector3d<float>& posA,
const Vector3d<float>& posB,
const Vector3d<float>& posC,
const int color = 0) override
{
// message syntax := v1 triangles N dim D PointTripple1 ... PointTrippleN
//PointTripple syntax := ID o1 ... oD p1 ... pD q1 ... qD color
//
//where N is the number of triangles in this message,
//where D is the dimension of one triangle vertex,
//where o1,...,oD,p1,...,pD,q1,...,qD are real scalars,
//where ID,color are integer scalars
//
// o,p,q are three vertices of a triangle
logger << "v1 triangles 1 dim 3 " << ID << " "
<< posA.x << " " << posA.y << " " << posA.z << " "
<< posB.x << " " << posB.y << " " << posB.z << " "
<< posC.x << " " << posC.y << " " << posC.z << " "
<< color << "\n";
}
void Tick(const char* msg) override
{
logger << "v1 tick " << (msg != NULL ? msg : "") << "\n";
}
void Flush(void) override
{
logger.flush();
}
protected:
std::ofstream logger;
};
#endif
......@@ -102,7 +102,7 @@ void SceneryBufferedDisplayUnit::Flush(void)
msgString += " dim 3";
msgString += BufferedPointMsgs.str();
socket->send(msgString.c_str(),msgString.size());
socket->send( zmq::const_buffer(msgString.c_str(),msgString.size()) );
}
if (BufferedLineMsgs_count > 0)
......@@ -112,7 +112,7 @@ void SceneryBufferedDisplayUnit::Flush(void)
msgString += " dim 3";
msgString += BufferedLineMsgs.str();
socket->send(msgString.c_str(),msgString.size());
socket->send( zmq::const_buffer(msgString.c_str(),msgString.size()) );
}
if (BufferedVectorMsgs_count > 0)
......@@ -122,7 +122,7 @@ void SceneryBufferedDisplayUnit::Flush(void)
msgString += " dim 3";
msgString += BufferedVectorMsgs.str();
socket->send(msgString.c_str(),msgString.size());
socket->send( zmq::const_buffer(msgString.c_str(),msgString.size()) );
}
if (BufferedTriangleMsgs_count > 0)
......@@ -132,7 +132,7 @@ void SceneryBufferedDisplayUnit::Flush(void)
msgString += " dim 3 ";
msgString += BufferedTriangleMsgs.str();
socket->send(msgString.c_str(),msgString.size());
socket->send( zmq::const_buffer(msgString.c_str(),msgString.size()) );
}
InitBuffers();
......
......@@ -21,8 +21,7 @@ void SceneryDisplayUnit::DrawPoint(const int ID,
<< radius << " " << color;
std::string msgString(msg.str());
socket->send(msgString.c_str(),msgString.size());
//socket->send(msgString.c_str(),msgString.size(),ZMQ_SNDMORE);
socket->send( zmq::const_buffer(msgString.c_str(),msgString.size()) );
}
......@@ -48,7 +47,7 @@ void SceneryDisplayUnit::DrawLine(const int ID,
<< color;
std::string msgString(msg.str());
socket->send(msgString.c_str(),msgString.size());
socket->send( zmq::const_buffer(msgString.c_str(),msgString.size()) );
}
......@@ -77,7 +76,7 @@ void SceneryDisplayUnit::DrawVector(const int ID,
<< color;
std::string msgString(msg.str());
socket->send(msgString.c_str(),msgString.size());
socket->send( zmq::const_buffer(msgString.c_str(),msgString.size()) );
}
......@@ -106,14 +105,14 @@ void SceneryDisplayUnit::DrawTriangle(const int ID,
<< color;
std::string msgString(msg.str());
socket->send(msgString.c_str(),msgString.size());
socket->send( zmq::const_buffer(msgString.c_str(),msgString.size()) );
}
void SceneryDisplayUnit::Tick(const char* msg)
{
std::string msgString = std::string("v1 tick ") + (msg != NULL ? msg : "");
socket->send(msgString.c_str(),msgString.size());
socket->send( zmq::const_buffer(msgString.c_str(),msgString.size()) );
}
......
......@@ -10,7 +10,7 @@
#define FLOAT float
/** a coordinate value that is way far outside of any scene... [micrometers] */
#define TOOFAR 999999999
#define TOOFAR 999999999.f
/** An x,y,z-axes aligned 3D bounding box for approximate representation of agent's geometry */
class AxisAlignedBoundingBox
......
......@@ -261,7 +261,7 @@ public:
grad.x -= distImg.GetVoxel(hints[i].x-1,hints[i].y,hints[i].z);
else
grad.x -= defValue, span--;
grad.x *= 3-span; //missing /2.0
grad.x *= (float)(3-span); //missing /2.0
//NB: this stretches the value difference as if central difference is calculated,
// and leaves it at zero when GetSizeX() == 1 because grad.x == defValue - defValue
......@@ -274,7 +274,7 @@ public:
grad.y -= distImg.GetVoxel(hints[i].x,hints[i].y-1,hints[i].z);
else
grad.y -= defValue, span--;
grad.y *= 3-span; //missing /2.0
grad.y *= (float)(3-span); //missing /2.0
span = 2;
if (hints[i].z+1 < distImg.GetSizeZ())
......@@ -285,7 +285,7 @@ public:
grad.z -= distImg.GetVoxel(hints[i].x,hints[i].y,hints[i].z-1);
else
grad.z -= defValue, span--;
grad.z *= 3-span; //missing /2.0
grad.z *= (float)(3-span); //missing /2.0
grad.elemMult(distImgRes); //account for anisotropy [1/px -> 1/um]
//DEBUG_REPORT("grad: " << grad << " @ voxel: " << hints[i] << ", distance: " << distances[i]);
......
......@@ -132,7 +132,7 @@ public:
//NB: should not become zero as the input orientations do differ
//quaternion params
rotAng /= 2.0;
rotAng /= (FT)2.0;
const FT q0 = std::cos(rotAng);
const FT q1 = std::sin(rotAng) * rotAxis.x;
const FT q2 = std::sin(rotAng) * rotAxis.y;
......
......@@ -62,10 +62,13 @@ void Scenario_AFewAgents::initializeScenario(void)
Img.SetResolution( i3d::Resolution(xRes,yRes,zRes) );
DEBUG_REPORT("Shape hinter image offset [um]: " << size);
//fill the actual shape
for (size_t z=(size_t)(0.1*Img.GetSizeZ()); z <= (size_t)(0.9*Img.GetSizeZ()); ++z)
for (size_t y=(size_t)(0.2*Img.GetSizeY()); y <= (size_t)(0.8*Img.GetSizeY()); ++y)
for (size_t x=(size_t)(0.1*Img.GetSizeX()); x <= (size_t)(0.9*Img.GetSizeX()); ++x)
//fill the actual shape (except for a dX x dY x dZ frame at the border)
const size_t dZ = (size_t)(0.1*(double)Img.GetSizeZ());
const size_t dY = (size_t)(0.2*(double)Img.GetSizeY());
const size_t dX = (size_t)(0.1*(double)Img.GetSizeX());
for (size_t z=dZ; z <= Img.GetSizeZ()-dZ; ++z)
for (size_t y=dY; y <= Img.GetSizeY()-dY; ++y)
for (size_t x=dX; x <= Img.GetSizeX()-dX; ++x)
Img.SetVoxel(x,y,z,20);
//Img.SaveImage("GradIN_ZeroOUT__original.tif");
......
......@@ -17,7 +17,7 @@ public:
//TextureQuantized(60000, Vector3d<float>(2.0f,2.0f,2.0f), 8)
{
//texture img: resolution -- makes sense to match it with the phantom img resolution
CreatePerlinTexture(futureGeometry, Vector3d<float>(2.0f),
createPerlinTexture(futureGeometry, Vector3d<float>(2.0f),
5.0,8,4,6, //Perlin
1.0f, //texture intensity range centre
0.1f, true); //quantization and shouldCollectOutlyingDots
......@@ -25,7 +25,7 @@ public:
void drawTexture(i3d::Image3d<float>& phantom, i3d::Image3d<float>&) override
{
if (Officer->isProducingOutput(phantom)) RenderIntoPhantom(phantom);
if (Officer->isProducingOutput(phantom)) renderIntoPhantom(phantom);
}
};
......
......@@ -4,7 +4,6 @@
#include "../Simulation.h"
#include "../Agents/Nucleus4SAgent.h"
#include "../Agents/util/Texture.h"
#include "../util/texture/texture.h"
#include "Scenarios.h"
class myDragAndTextureNucleus: public Nucleus4SAgent, TextureQuantized, TextureUpdater4S
......@@ -21,7 +20,7 @@ public:
cytoplasmWidth = 0.0f;
//texture img: resolution -- makes sense to match it with the phantom img resolution
CreatePerlinTexture(futureGeometry, Vector3d<float>(2.0f),
createPerlinTexture(futureGeometry, Vector3d<float>(2.0f),
5.0,8,4,6, //Perlin
1.0f, //texture intensity range centre
0.1f, true); //quantization and shouldCollectOutlyingDots
......@@ -61,16 +60,20 @@ public:
updateTextureCoords(dots, futureGeometry);
//correct for outlying texture particles
const int dotOutliers = CollectOutlyingDots(futureGeometry);
DEBUG_REPORT(dotOutliers << " (" << 100.f*dotOutliers/dots.size()
#ifndef DEBUG
collectOutlyingDots(futureGeometry);
#else
const int dotOutliers = collectOutlyingDots(futureGeometry);
DEBUG_REPORT(dotOutliers << " (" << (float)(100*dotOutliers)/(float)dots.size()
<< " %) dots had to be moved inside the initial geometry");
#endif
}
}
void drawTexture(i3d::Image3d<float>& phantom, i3d::Image3d<float>&) override
{
if (Officer->isProducingOutput(phantom)) RenderIntoPhantom(phantom);
if (Officer->isProducingOutput(phantom)) renderIntoPhantom(phantom);
}
void drawMask(DisplayUnit& du) override
......