Skip to content

Commit

Permalink
Added methods for serialisation of triangle nodes in NodeOfTriangles …
Browse files Browse the repository at this point in the history
…class and included serialising of nodes along with saving results in different folders in all 3 commands. Other linear gradient interpolators can now be used extra to bilinear interpolator. SimulDispl can now generate post-deformation images from user defined displacement maps.
  • Loading branch information
StaronC authored and erupnik committed Jul 24, 2024
1 parent e637da9 commit 736c51f
Show file tree
Hide file tree
Showing 17 changed files with 1,414 additions and 696 deletions.
18 changes: 12 additions & 6 deletions MMVII/include/MMVII_PhgrDist.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,18 @@ NS_SymbolicDerivative::cCalculator<double> * EqTopoDZ(bool WithDerive,int aSzBuf
NS_SymbolicDerivative::cCalculator<double> * EqDeformImHomotethy(bool WithDerive,int aSzBuf);
/// Variant of "EqDeformImHomotethy", case where we use linear approximation
NS_SymbolicDerivative::cCalculator<double> * EqDeformImLinearGradHomotethy(bool WithDerive,int aSzBuf);
/// Equation used to optimize translation and radiometry transformation between two images.
NS_SymbolicDerivative::cCalculator<double> *EqDeformTri(bool WithDerive, int aSzBuf);
/// Equation used to optimize translation transformation between two images.
NS_SymbolicDerivative::cCalculator<double> *EqDeformTriTranslation(bool WithDerive, int aSzBuf);
/// Equation used to optimize radiometric transformation between two images.
NS_SymbolicDerivative::cCalculator<double> *EqDeformTriRadiometry(bool WithDerive, int aSzBuf);
/// Equation used to optimize translation and radiometry transformation between two images with bilinear interpolator.
NS_SymbolicDerivative::cCalculator<double> *EqDeformTriBilin(bool WithDerive, int aSzBuf);
/// Equation used to optimize translation transformation between two images with bilinear interpolator.
NS_SymbolicDerivative::cCalculator<double> *EqDeformTriTranslationBilin(bool WithDerive, int aSzBuf);
/// Equation used to optimize radiometric transformation between two images with bilinear interpolator.
NS_SymbolicDerivative::cCalculator<double> *EqDeformTriRadiometryBilin(bool WithDerive, int aSzBuf);
/// Equation used to optimize translation and radiometry transformation between two images with linear interpolator.
NS_SymbolicDerivative::cCalculator<double> *EqDeformTriLinearGrad(bool WithDerive, int aSzBuf);
/// Equation used to optimize translation transformation between two images with linear interpolator.
NS_SymbolicDerivative::cCalculator<double> *EqDeformTriTranslationLinearGrad(bool WithDerive, int aSzBuf);
/// Equation used to optimize radiometric transformation between two images with linear interpolator.
NS_SymbolicDerivative::cCalculator<double> *EqDeformTriRadiometryLinearGrad(bool WithDerive, int aSzBuf);

// ............. Covariance propagation .............

Expand Down
66 changes: 62 additions & 4 deletions MMVII/include/MMVII_TplSymbTriangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ using namespace NS_SymbolicDerivative;

namespace MMVII
{

/**
Compute the formula for composition of a function and an image.
Expand Down Expand Up @@ -68,7 +67,8 @@ namespace MMVII
}

// standard name for observation
std::vector<std::string> FormalBilinIm2D_NameObs(const std::string &aPrefix);
std::vector<std::string> FormalBilinTri_NameObs(const std::string &aPrefix);
constexpr int TriangleDisplacement_NbObs_ImPre = 6;

template <class Type>
void FormalInterpBarycenter_SetObs(
Expand All @@ -89,7 +89,7 @@ namespace MMVII
This is the "companion" function of FormalBilinIm2D_Formula, it fills
the vector aVObs with X0,Y0,I00, that will be used in FormalBilinIm2D_Formula.
*/

constexpr int TriangleDisplacement_Bilin_NbObs = 6;
template <class Type, class TypeIm>
void FormalBilinTri_SetObs(
std::vector<Type> &aVObs, // vector of observation to fill
Expand All @@ -112,7 +112,65 @@ namespace MMVII
SetOrPush(aVObs, aK0 + 5, (Type)aDIm.GetV(aP0 + cPt2di(1, 1)));
}

constexpr int TriangleDisplacement_NbObs = 6;
/* ********************************************************* */
/* */
/* UTIILITY FOR GRADIENT/INTERPOLATED FORMULA */
/* */
/* ********************************************************* */

/**
* Similar to "FormalBilinIm2D_Formula", but using linear approx (by gradient generally) rather than bi-linear
*
* Given the linear approximation of function I (typically an image), by its gradient and value in (X0,Y0),
* and a mappinf FX,FY, return the "I*(Fx,Fy)"
*
*/

template <class TypeFunc, class TypeObs>
TypeFunc FormalGradInterpolTri_Formula(
const std::vector<TypeObs> &aVObs,
const int aKObs0,
const TypeFunc &FX,
const TypeFunc &FY)
{
TypeFunc aX0(aVObs.at(aKObs0));
TypeFunc aY0(aVObs.at(aKObs0 + 1));
TypeFunc aValI(aVObs.at(aKObs0 + 2));
TypeFunc aGIx(aVObs.at(aKObs0 + 3));
TypeFunc aGIy(aVObs.at(aKObs0 + 4));

return aValI + aGIx * (FX - aX0) + aGIy * (FY - aY0);
}

/*
* "Companion" function of FormalGradInterpolIm2D_Formula. Push in correct order the values
* in aVObs of point, function and gradient.
*
*/

/** standard name for observation */
std::vector<std::string> FormalGradInterpol_NameObs(const std::string &aPrefix);
constexpr int TriangleDisplacement_GradInterpol_NbObs = 5;

template <class Type, class TypeIm>
void FormalGradInterpol_SetObs(
std::vector<Type> &aVObs, // vector of observation to fill with [X0,Y0,I00...]
const int aK0, // first index where fill the vector
const cPt2dr &aPtIm, // point in image
const cDataIm2D<TypeIm> &aDIm, // image
const cDiffInterpolator1D &anInterpol // differentiable interpolator
)
{
// compute coordinates of left-high corner of including pixel
SetOrPush(aVObs, aK0, Type(aPtIm.x()));
SetOrPush(aVObs, aK0 + 1, Type(aPtIm.y()));

auto [aValue, aGrad] = aDIm.GetValueAndGradInterpol(anInterpol, aPtIm);

SetOrPush(aVObs, aK0 + 2, (Type)aValue);
SetOrPush(aVObs, aK0 + 3, (Type)aGrad.x());
SetOrPush(aVObs, aK0 + 4, (Type)aGrad.y());
}
};

#endif // _MMVII_TplSymbTriangle_
20 changes: 10 additions & 10 deletions MMVII/src/MeshDisplacement/ApplyDelaunayOnRandomGeneratedPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace MMVII
void ConstructUniformRandomVector(); // Build vector with node coordinates drawn from uniform law
void GeneratePointsForRectangularGrid(); // Build vector with node coordinates that form a rectangular grid
// Shift triangles by a certain quantity defined in method
void ComputeShiftedTrianglesAndPoints(const cTriangle<tREAL8, 2> &aTri, std::vector<cPt2dr> &ShiftedTriangleCoordinates,
void ComputeShiftedTrianglesAndPoints(const cTriangle<tREAL8, 2> &aTri, std::vector<tPt2dr> &ShiftedTriangleCoordinates,
const tREAL8 aUniformRandomRedChannel, const tREAL8 aUniformRandomGreenChannel,
const tREAL8 aUniformRandomBlueChannel);

Expand All @@ -62,7 +62,7 @@ namespace MMVII
cPt2di mSzImIn; // Size of images
tIm mImIn; // memory representation of the image
tDIm *mDImIn; // memory representation of the image
std::vector<cPt2dr> mVectorPts; // A vector containing a set of points
std::vector<tPt2dr> mVectorPts; // A vector containing a set of points
cTriangulation2D<tREAL8> mDelTri; // A delaunay triangle
};

Expand Down Expand Up @@ -108,7 +108,7 @@ namespace MMVII
{
mDelTri.MakeDelaunay();

std::vector<cPt2dr> ShiftedTriangleCoordinates;
std::vector<tPt2dr> ShiftedTriangleCoordinates;

const int aMaxValueUniformLaw = 256;

Expand Down Expand Up @@ -149,7 +149,7 @@ namespace MMVII
{
const double aUniformRandomXAxis = RandUnif_N(mNumberOfCols);
const double aUniformRandomYAxis = RandUnif_N(mNumberOfLines);
const cPt2dr aUniformRandomPt(aUniformRandomXAxis, aUniformRandomYAxis); // cPt2dr format
const tPt2dr aUniformRandomPt(aUniformRandomXAxis, aUniformRandomYAxis); // tPt2dr format
mVectorPts.push_back(aUniformRandomPt);
}

Expand Down Expand Up @@ -204,17 +204,17 @@ namespace MMVII
}

void cAppli_RandomGeneratedDelaunay::ComputeShiftedTrianglesAndPoints(const cTriangle<tREAL8, 2> &aTri,
std::vector<cPt2dr> &ShiftedTriangleCoordinates,
std::vector<tPt2dr> &ShiftedTriangleCoordinates,
const tREAL8 aUniformRandomRedChannel,
const tREAL8 aUniformRandomGreenChannel,
const tREAL8 aUniformRandomBlueChannel)
{
const cTriangle2DCompiled aCompTri(aTri);

// Compute shifts depending on point of triangle
const cPt2dr PercentDiffA = 0.01 * (aTri.Pt(0) - aTri.Pt(2));
const cPt2dr PercentDiffB = 0.015 * (aTri.Pt(1) - aTri.Pt(0)); // arbitrary values are chosen for displacement
const cPt2dr PercentDiffC = 0.02 * (aTri.Pt(2) - aTri.Pt(1));
const tPt2dr PercentDiffA = 0.01 * (aTri.Pt(0) - aTri.Pt(2));
const tPt2dr PercentDiffB = 0.015 * (aTri.Pt(1) - aTri.Pt(0)); // arbitrary values are chosen for displacement
const tPt2dr PercentDiffC = 0.02 * (aTri.Pt(2) - aTri.Pt(1));

ShiftedTriangleCoordinates.push_back(aTri.Pt(0) + PercentDiffA);
ShiftedTriangleCoordinates.push_back(aTri.Pt(1) + PercentDiffB);
Expand All @@ -227,9 +227,9 @@ namespace MMVII
{
if (aFilledPixel % 40 == 0)
{
const cPt2dr aFilledPoint(aVectorToFillwithInsidePixels[aFilledPixel].x(), aVectorToFillwithInsidePixels[aFilledPixel].y());
const tPt2dr aFilledPoint(aVectorToFillwithInsidePixels[aFilledPixel].x(), aVectorToFillwithInsidePixels[aFilledPixel].y());
const cPt3dr barycenter_coordinates = aCompTri.CoordBarry(aFilledPoint);
const cPt2dr ShiftedInsidePixels = cPt2dr(aFilledPoint.x() + barycenter_coordinates.x() * PercentDiffA.x() +
const tPt2dr ShiftedInsidePixels = tPt2dr(aFilledPoint.x() + barycenter_coordinates.x() * PercentDiffA.x() +
barycenter_coordinates.y() * PercentDiffB.x() + barycenter_coordinates.z() * PercentDiffC.x(),
aFilledPoint.y() + barycenter_coordinates.x() * PercentDiffA.y() +
barycenter_coordinates.y() * PercentDiffB.y() + barycenter_coordinates.z() * PercentDiffC.y());
Expand Down
115 changes: 0 additions & 115 deletions MMVII/src/MeshDisplacement/SerialiseTriangleDeformation.cpp

This file was deleted.

56 changes: 0 additions & 56 deletions MMVII/src/MeshDisplacement/SerialiseTriangleDeformation.h

This file was deleted.

Loading

0 comments on commit 736c51f

Please sign in to comment.