Commit 2cfffd64 authored by Yaroslav Gevorkov's avatar Yaroslav Gevorkov
Browse files

refactoring + finer multi seed refinement

parent 826feb4f
...@@ -53,6 +53,7 @@ class PinkIndexer ...@@ -53,6 +53,7 @@ class PinkIndexer
private: private:
void reducePeakCount(Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms, Eigen::RowVectorXf& intensities, void reducePeakCount(Eigen::Matrix3Xf& ucsDirections, Eigen::Array2Xf& ucsBorderNorms, Eigen::RowVectorXf& intensities,
const Eigen::Matrix2Xf& detectorPeaks_m); const Eigen::Matrix2Xf& detectorPeaks_m);
void refine(Lattice& indexedLattice, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Array2Xf& ucsBorderNorms);
float getAngleResolution(); float getAngleResolution();
int getConsideredPeaksCount(); int getConsideredPeaksCount();
......
...@@ -16,6 +16,8 @@ class Refinement ...@@ -16,6 +16,8 @@ class Refinement
int getFittedPeaksCount(Lattice& lattice, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Matrix2Xf& ucsBorderNorms); int getFittedPeaksCount(Lattice& lattice, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Matrix2Xf& ucsBorderNorms);
int getFittedPeaks(Lattice& lattice, Eigen::Array<bool, Eigen::Dynamic, 1>& fittedPeaks, const Eigen::Matrix3Xf& ucsDirections, int getFittedPeaks(Lattice& lattice, Eigen::Array<bool, Eigen::Dynamic, 1>& fittedPeaks, const Eigen::Matrix3Xf& ucsDirections,
const Eigen::Matrix2Xf& ucsBorderNorms); const Eigen::Matrix2Xf& ucsBorderNorms);
double getMeanDefect(const Eigen::Matrix3f& basis, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Matrix2Xf& ucsBorderNorms,
bool significantChangesToPreviousCall = true);
void setTolerance(float tolerance) void setTolerance(float tolerance)
{ {
...@@ -29,8 +31,6 @@ class Refinement ...@@ -29,8 +31,6 @@ class Refinement
private: private:
void getDefects(Eigen::ArrayXf& defects, const Eigen::Matrix3f& basis, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Matrix2Xf& ucsBorderNorms, void getDefects(Eigen::ArrayXf& defects, const Eigen::Matrix3f& basis, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Matrix2Xf& ucsBorderNorms,
bool significantChangesToPreviousCall = true); bool significantChangesToPreviousCall = true);
double getMeanDefect(const Eigen::Matrix3f& basis, const Eigen::Matrix3Xf& ucsDirections, const Eigen::Matrix2Xf& ucsBorderNorms,
bool significantChangesToPreviousCall = true);
float tolerance; float tolerance;
......
...@@ -64,6 +64,17 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen: ...@@ -64,6 +64,17 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen:
Matrix3f bestBasis = bestRotation * sampleLattice.getBasis(); Matrix3f bestBasis = bestRotation * sampleLattice.getBasis();
indexedLattice = Lattice(bestBasis); indexedLattice = Lattice(bestBasis);
refine(indexedLattice, ucsDirections, ucsBorderNorms);
indexedLattice.minimize();
return refinement.getFittedPeaks(indexedLattice, fittedPeaks, ucsDirections, ucsBorderNorms);
// sinogram.saveToFile("C:\\DesyFiles\\workspaces\\VisualStudio_workspace\\pinkIndexer\\workfolder\\sinogram");
}
void PinkIndexer::refine(Lattice& indexedLattice, const Matrix3Xf& ucsDirections, const Array2Xf& ucsBorderNorms)
{
switch (refinementType) switch (refinementType)
{ {
case RefinementType::none: case RefinementType::none:
...@@ -92,6 +103,7 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen: ...@@ -92,6 +103,7 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen:
{ {
#define REFINEMENT_TRIES 250 #define REFINEMENT_TRIES 250
int fittedNodesCount[REFINEMENT_TRIES]; int fittedNodesCount[REFINEMENT_TRIES];
double fittedNodesMeanDefects[REFINEMENT_TRIES];
Lattice fittedLattices[REFINEMENT_TRIES]; Lattice fittedLattices[REFINEMENT_TRIES];
float maxRelativeDeviation = 0.012; float maxRelativeDeviation = 0.012;
...@@ -111,16 +123,18 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen: ...@@ -111,16 +123,18 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen:
refinement.setTolerance(finalRefinementTolerance); refinement.setTolerance(finalRefinementTolerance);
refinement.refineVariableLattice(fittedLattices[i], ucsDirections, ucsBorderNorms); refinement.refineVariableLattice(fittedLattices[i], ucsDirections, ucsBorderNorms);
fittedNodesCount[i] = refinement.getFittedPeaks(fittedLattices[i], fittedPeaks, ucsDirections, ucsBorderNorms); fittedNodesCount[i] = refinement.getFittedPeaksCount(fittedLattices[i], ucsDirections, ucsBorderNorms);
fittedNodesMeanDefects[i] = refinement.getMeanDefect(fittedLattices[i].getBasis(), ucsDirections, ucsBorderNorms);
} }
Lattice bestLattice = indexedLattice; int maxFittedNodesCount = refinement.getFittedPeaksCount(indexedLattice, ucsDirections, ucsBorderNorms);
int maxFittedNodesCount = refinement.getFittedPeaks(indexedLattice, fittedPeaks, ucsDirections, ucsBorderNorms); double minFittedNodesMeanDefect = refinement.getMeanDefect(indexedLattice.getBasis(), ucsDirections, ucsBorderNorms);
for (int i = 0; i < REFINEMENT_TRIES; ++i) for (int i = 0; i < REFINEMENT_TRIES; ++i)
{ {
if (fittedNodesCount[i] > maxFittedNodesCount) if (fittedNodesCount[i] > maxFittedNodesCount || (fittedNodesCount[i] == maxFittedNodesCount && fittedNodesMeanDefects[i] < minFittedNodesMeanDefect))
{ {
maxFittedNodesCount = fittedNodesCount[i]; maxFittedNodesCount = fittedNodesCount[i];
minFittedNodesMeanDefect = fittedNodesMeanDefects[i];
indexedLattice = fittedLattices[i]; indexedLattice = fittedLattices[i];
} }
} }
...@@ -129,22 +143,6 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen: ...@@ -129,22 +143,6 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen:
default: default:
break; break;
} }
indexedLattice.minimize();
return refinement.getFittedPeaks(indexedLattice, fittedPeaks, ucsDirections, ucsBorderNorms);
// int fittedPeaksCount = refinement.getFittedPeaksCount(indexedLattice, ucsDirections, ucsBorderNorms);
// if ((fittedPeaksCount >= 20 && fittedPeaksCount >= detectorPeaks_m.cols() * 0.3) || fittedPeaksCount >= detectorPeaks_m.cols() * 0.5)
//{
// return true;
//}
// else
//{
// return false;
//}
// sinogram.saveToFile("C:\\DesyFiles\\workspaces\\VisualStudio_workspace\\pinkIndexer\\workfolder\\sinogram");
} }
void PinkIndexer::reducePeakCount(Matrix3Xf& ucsDirections, Array2Xf& ucsBorderNorms, RowVectorXf& intensities, const Eigen::Matrix2Xf& detectorPeaks_m) void PinkIndexer::reducePeakCount(Matrix3Xf& ucsDirections, Array2Xf& ucsBorderNorms, RowVectorXf& intensities, const Eigen::Matrix2Xf& detectorPeaks_m)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment