1.5.1
CCC
 
CalcMigrate.cpp File Reference
#include "geoslib_old_f.h"
#include "Enum/ELoc.hpp"
#include "Basic/NamingConvention.hpp"
#include "Basic/OptDbg.hpp"
#include "Calculators/CalcMigrate.hpp"
#include "Calculators/ACalcDbToDb.hpp"
#include "Geometry/GeometryHelper.hpp"
#include "Db/DbGrid.hpp"
#include "Db/Db.hpp"
#include "Morpho/Morpho.hpp"
#include "Tree/Ball.hpp"
#include "Basic/Memory.hpp"
#include "Core/Keypair.hpp"
#include <math.h>

Macros

#define RES(nval, idim)   (res[(idim) + (ndim+1) * (nval)])
 

Functions

static void st_shift (int rank, Db *dbgrid, const VectorInt &indg1, const VectorDouble &prop, VectorInt &indg2, double *weight)
 
static int st_multilinear_evaluate (DbGrid *db_grid, const VectorInt &indg, int iatt, double *value)
 
static double st_multilinear_interpolation (DbGrid *dbgrid, int iatt, int distType, const VectorDouble &dmax, const VectorDouble &coor)
 
static double st_distance_modify (DbGrid *dbgrid, int ig, Db *dbpoint, int ip, VectorDouble &dvect, int flag_aniso, int iatt_time, int iatt_angle, int iatt_scaleu, int iatt_scalev, int iatt_scalew)
 
void st_get_closest_sample (DbGrid *dbgrid, int ig, Db *dbpoint, int ip, int flag_aniso, int iatt_time, int iatt_angle, int iatt_scaleu, int iatt_scalev, int iatt_scalew, int *ipmin, double *ddmin, VectorDouble &dvect)
 
int st_next_sample (int ip0_init, const VectorInt &rank, const VectorDouble &xtab, double xtarget)
 
static int st_locate_point_on_grid (const Db *db_point, const DbGrid *db_grid, VectorDouble &coor, VectorDouble &tab)
 
static int st_locate_coor_on_grid (int np, const VectorVectorDouble &coords, const DbGrid *db_grid, VectorDouble &tab)
 
static int st_larger_than_dmax (int ndim, const VectorDouble &dvect, int distType, const VectorDouble &dmax)
 
static void st_expand (int flag_size, DbGrid *dbgrid, VectorDouble &tab1, VectorInt &indg0, VectorInt &indg, VectorDouble &tab2)
 
int migrate (Db *dbin, Db *dbout, const String &name, int dist_type, const VectorDouble &dmax, bool flag_fill, bool flag_inter, bool flag_ball, const NamingConvention &namconv)
 
int migrateMulti (Db *dbin, Db *dbout, const VectorString &names, int dist_type, const VectorDouble &dmax, bool flag_fill, bool flag_inter, bool flag_ball, const NamingConvention &namconv)
 
int migrateByAttribute (Db *dbin, Db *dbout, const VectorInt &atts, int dist_type, const VectorDouble &dmax, bool flag_fill, bool flag_inter, bool flag_ball, const NamingConvention &namconv)
 
int migrateByLocator (Db *dbin, Db *dbout, const ELoc &locatorType, int dist_type, const VectorDouble &dmax, bool flag_fill, bool flag_inter, bool flag_ball, const NamingConvention &namconv)
 
int manageExternalInformation (int mode, const ELoc &locatorType, Db *dbin, Db *dbout, bool *flag_created)
 
int interpolateVariableToPoint (DbGrid *db_grid, int iatt, int np, const double *xp, const double *yp, const double *zp, double *tab)
 
double * dbgridLineSampling (DbGrid *dbgrid, const double *x1, const double *x2, int ndisc, int ncut, const double *cuts, int *nval_ret)
 
int expandPointToGrid (Db *db_point, DbGrid *db_grid, int iatt, int iatt_time, int iatt_angle, int iatt_scaleu, int iatt_scalev, int iatt_scalew, int flag_index, int distType, const VectorDouble &dmax, VectorDouble &tab)
 
int expandPointToCoor (const Db *db1, int iatt, const VectorVectorDouble &coords, VectorDouble &tab)
 
int pointToBlock (Db *dbpoint, DbGrid *dbgrid, int option, int flag_size, int iatt_time, int iatt_size, int iatt_angle, int iatt_scaleu, int iatt_scalev, int iatt_scalew)
 
int migrateGridToCoor (const DbGrid *db_grid, int iatt, const VectorVectorDouble &coords, VectorDouble &tab)
 
int expand_point_to_coor (const Db *db1, int iatt, const VectorVectorDouble &coords, VectorDouble &tab)
 

Macro Definition Documentation

◆ RES

#define RES (   nval,
  idim 
)    (res[(idim) + (ndim+1) * (nval)])

Function Documentation

◆ dbgridLineSampling()

double* dbgridLineSampling ( DbGrid dbgrid,
const double *  x1,
const double *  x2,
int  ndisc,
int  ncut,
const double *  cuts,
int *  nval_ret 
)

Sampling vertices within a Grid between two points

Returns
Array of sampled vertices
Parameters
[in]dbgridreference Grid
[in]x1Array giving the coordinates of the first point
[in]x2Array giving the coordinates of the second point
[in]ndiscNumber of discretized points in the segment
[in]ncutNumber of cutoffs
[in]cutsArray of cutoffs
[out]nval_retNumber of samples in the output array
Remarks
This function considers the segment [x1,x2] and subdivises it
into 'ndisc' intervals. The endpoints of each interval correspond
to two points in the space
At each endpoint, the target variable is interpolated from the grid
If the target variable values cross a cutoff, the coordinates of
the intersection are calculated.
The program returns the list of all these intersection coordinates

TODO FUTURE_REFACTOR

◆ expand_point_to_coor()

int expand_point_to_coor ( const Db db1,
int  iatt,
const VectorVectorDouble coords,
VectorDouble tab 
)

Expands a variable from one point Db into a variable at points defined by coordinate vectors (maximum 3D)

Returns
Error return code
Parameters
[in]db1descriptor of the input parameters
[in]iattrank of the input attribute
[in]coordsArray of coordinates
[out]tabOutput array (Dimension: number of discretized points)

◆ expandPointToCoor()

int expandPointToCoor ( const Db db1,
int  iatt,
const VectorVectorDouble coords,
VectorDouble tab 
)

Expands a variable from one point Db into a variable at points defined by coordinate vectors (maximum 3D)

Returns
Error return code
Parameters
[in]db1descriptor of the input parameters
[in]iattrank of the input attribute
[in]coordsArray of coordinates
[out]tabOutput array (Dimension: number of discretized points)

◆ expandPointToGrid()

int expandPointToGrid ( Db db_point,
DbGrid db_grid,
int  iatt,
int  iatt_time,
int  iatt_angle,
int  iatt_scaleu,
int  iatt_scalev,
int  iatt_scalew,
int  flag_index,
int  distType,
const VectorDouble dmax,
VectorDouble tab 
)

Expands a variable from the point structure into a variable in the grid structure

Returns
Error return code
Parameters
[in]db_pointDescriptor of the point parameters
[in]db_gridDescriptor of the grid parameters
[in]iattRank of the point attribute
[in]iatt_timeOptional variable for Time shift
[in]iatt_angleOptional variable for anisotropy angle (around Z)
[in]iatt_scaleuOptional variable for anisotropy scale factor (U)
[in]iatt_scalevOptional variable for anisotropy scale factor (V)
[in]iatt_scalewOptional variable for anisotropy scale factor (W)
[in]flag_index1 if the Index must be assigned to grid node 0 the 'iatt' attribute is assigned instead
[in]distTypeType of distance for calculating maximum distance 1 for L1 and 2 for L2 distance
[in]dmaxArray of maximum distances (optional)
[out]tabOutput array
Remarks
When a Time Shift is present, this corresponds to Johnson-Mehl
The Time Shift is an optional variable which increases the
distance (the time-to-distance conversion is assumed to be 1)
Only positive Time Shifts are considered

◆ interpolateVariableToPoint()

int interpolateVariableToPoint ( DbGrid db_grid,
int  iatt,
int  np,
const double *  xp,
const double *  yp,
const double *  zp,
double *  tab 
)

Interpolate a variable from a grid Db on discretization points

Parameters
[in]db_gridDescriptor of the grid parameters
[in]iattRank of the attribute in db_grid
[in]npNumber of discretized points
[in]xpArray of first coordinates
[in]ypArray of second coordinates
[in]zpArray of third coordinates
[out]tabOutput array
Remarks
The arguments 'xp', 'yp' and 'zp' must be defined in accordance
with the space dimension in argument 'db_grid'
A point which does not lie between two valuated grid nodes
(in all space dimensions) is always set to FFFF

◆ manageExternalInformation()

int manageExternalInformation ( int  mode,
const ELoc &  locatorType,
Db dbin,
Db dbout,
bool *  flag_created 
)

Derive the external information(s) from the Output db (if Grid) to the Input Db

Returns
Error return code
Parameters
[in]mode1 for allocation; -1 for deallocation
[in]locatorTypeType of the pointer (ELoc)
[in]dbinDescriptor of the input Db
[in]dboutDescriptor of the output Db
[out]flag_createdTrue if variables have been created
Remarks
This function only functions when the Output Db is a grid
However, in case of a Point output Db, this function should not
be used: the external drift functions should already be present
in the output Db.
If this is not the case, an error is issued.

◆ migrate()

int migrate ( Db dbin,
Db dbout,
const String name,
int  dist_type,
const VectorDouble dmax,
bool  flag_fill,
bool  flag_inter,
bool  flag_ball,
const NamingConvention namconv 
)

Migrates a variable from one Db to another one

Returns
Error return code
Parameters
[in]dbinDescriptor of the input Db
[in]dboutDescriptor of the output Db
[in]nameName of the attribute to be migrated
[in]dist_typeType of distance for calculating maximum distance 1 for L1 and 2 for L2 distance
[in]dmaxArray of maximum distances (optional)
[in]flag_fillFilling option
[in]flag_interInterpolation
[in]flag_ballUse BallTree sorting algorithm when available
[in]namconvNaming convention

◆ migrateByAttribute()

int migrateByAttribute ( Db dbin,
Db dbout,
const VectorInt atts,
int  dist_type,
const VectorDouble dmax,
bool  flag_fill,
bool  flag_inter,
bool  flag_ball,
const NamingConvention namconv 
)

Migrates a variable from one Db to another one

Returns
Error return code
Parameters
[in]dbinDescriptor of the input Db
[in]dboutDescriptor of the output Db
[in]attsArray of attributes to be migrated
[in]dist_typeType of distance for calculating maximum distance 1 for L1 and 2 for L2 distance
[in]dmaxArray of maximum distances (optional)
[in]flag_fillFilling option
[in]flag_interInterpolation
[in]flag_ballUse BallTree sorting algorithm when available
[in]namconvNaming Convention

◆ migrateByLocator()

int migrateByLocator ( Db dbin,
Db dbout,
const ELoc &  locatorType,
int  dist_type,
const VectorDouble dmax,
bool  flag_fill,
bool  flag_inter,
bool  flag_ball,
const NamingConvention namconv 
)

Migrates all z-locator variables from one Db to another one

Returns
Error return code
Parameters
[in]dbinDescriptor of the input Db
[in]dboutDescriptor of the output Db
[in]locatorTypeLocator Type
[in]dist_typeType of distance for calculating maximum distance 1 for L1 and 2 for L2 distance
[in]dmaxArray of maximum distances (optional)
[in]flag_fillFilling option
[in]flag_interInterpolation
[in]flag_ballUse BallTree sorting algorithm when available
[in]namconvNaming convention
Remarks
The output variable receive the same locator as the input variables

◆ migrateGridToCoor()

int migrateGridToCoor ( const DbGrid db_grid,
int  iatt,
const VectorVectorDouble coords,
VectorDouble tab 
)

Migrates a variable from the grid structure into a variable at points defined by coordinate vectors

Returns
Error return code
Parameters
[in]db_griddescriptor of the grid parameters
[in]iattrank of the grid attribute
[in]coordsArray of coordinates (dimension: ndim, np)
[out]tabOutput array (Dimension: number of discretized points)

◆ migrateMulti()

int migrateMulti ( Db dbin,
Db dbout,
const VectorString names,
int  dist_type,
const VectorDouble dmax,
bool  flag_fill,
bool  flag_inter,
bool  flag_ball,
const NamingConvention namconv 
)

Migrates a set of variables from one Db to another one

Returns
Error return code
Parameters
[in]dbinDescriptor of the input Db
[in]dboutDescriptor of the output Db
[in]namesName of the attribute to be migrated
[in]dist_typeType of distance for calculating maximum distance 1 for L1 and 2 for L2 distance
[in]dmaxArray of maximum distances (optional)
[in]flag_fillFilling option
[in]flag_interInterpolation
[in]flag_ballUse BallTree sorting algorithm when available
[in]namconvNaming convention

◆ pointToBlock()

int pointToBlock ( Db dbpoint,
DbGrid dbgrid,
int  option,
int  flag_size,
int  iatt_time,
int  iatt_size,
int  iatt_angle,
int  iatt_scaleu,
int  iatt_scalev,
int  iatt_scalew 
)

Plunge a set of isolated points within a discretization grid in order to compute the voronoi of the points and derive:

  • the statistics on the volume and perimeter of the cells
  • the edge between cells
Returns
Error return code
Parameters
[in]dbpointDescriptor of the point parameters
[in]dbgridDescriptor of the grid parameters
[in]optionConnectivity option (0 for cross and 1 for block)
[in]flag_sizeWhen 1, the border pixels report the border thickness When 0, the border pixels are painted in 1
[in]iatt_timeAttribute of 'dbpoint'for Time shift (optional)
[in]iatt_sizeAttribute of 'dbpoint' giving size (optional)
[in]iatt_angleOptional variable for anisotropy angle (around Z)
[in]iatt_scaleuOptional variable for anisotropy scale factor (U)
[in]iatt_scalevOptional variable for anisotropy scale factor (V)
[in]iatt_scalewOptional variable for anisotropy scale factor (W)
Remarks
The value of 'flag_index' can be turned on for assigning
the sample index to the grid cell (instead of the 'iatt' value)
using: set_keypair("PTB_flag_index")

◆ st_distance_modify()

static double st_distance_modify ( DbGrid dbgrid,
int  ig,
Db dbpoint,
int  ip,
VectorDouble dvect,
int  flag_aniso,
int  iatt_time,
int  iatt_angle,
int  iatt_scaleu,
int  iatt_scalev,
int  iatt_scalew 
)
static

◆ st_expand()

static void st_expand ( int  flag_size,
DbGrid dbgrid,
VectorDouble tab1,
VectorInt indg0,
VectorInt indg,
VectorDouble tab2 
)
static

Expand the joins at each cell in its vicinity, the radius is given per pixel in the array 'tab1'

Parameters
[in]flag_sizewhen 0, the norder pixels are painted with 1 when 1, the border pixels report the border thckness
[in]dbgridDescriptor of the grid parameters
[in]tab1Array containing expansion radius
[in]indg0Array used for encoding/decoding
[in]indgArray used for encoding/decoding
[in]tab2Returned array

◆ st_get_closest_sample()

void st_get_closest_sample ( DbGrid dbgrid,
int  ig,
Db dbpoint,
int  ip,
int  flag_aniso,
int  iatt_time,
int  iatt_angle,
int  iatt_scaleu,
int  iatt_scalev,
int  iatt_scalew,
int *  ipmin,
double *  ddmin,
VectorDouble dvect 
)

Update minimum distance and rank of the corresponding sample

Parameters
[in]dbgridDescriptor of the grid parameters
[in]igRank of the sample in the Grid file
[in]dbpointDescriptor of the point parameters
[in]ipRank of the sample in the Point file
[in]flag_aniso1 if anisotropic distance must be calculated
[in]iatt_timeOptional variable for Time shift
[in]iatt_angleOptional variable for anisotropy angle (around Z)
[in]iatt_scaleuOptional variable for anisotropy scale factor (U)
[in]iatt_scalevOptional variable for anisotropy scale factor (V)
[in]iatt_scalewOptional variable for anisotropy scale factor (W)
[in,out]ipminRank of the Point sample
[in,out]ddminMinimum distance
[out]dvectWorking vector
Remarks
The Time Shift is an optional variable which increases the
distance (the time-to-distance conversion is assumed to be 1)
Only positive Time Shifts are considered

◆ st_larger_than_dmax()

static int st_larger_than_dmax ( int  ndim,
const VectorDouble dvect,
int  distType,
const VectorDouble dmax 
)
static

Check if vector is out of range by comparing each component to the maximum value defined per direction

Returns
Error return code
Parameters
[in]ndimSpace dimension
[in]dvectVector
[in]distTypeType of distance for calculating maximum distance 1 for L1 and 2 for L2 distance
[in]dmaxArray of maximum distances (optional)
Remarks
If 'dmax' is not defined, the function always returns 0
The function returns 1 as soon as one vector component is
larger than the maximum value for this direction

◆ st_locate_coor_on_grid()

static int st_locate_coor_on_grid ( int  np,
const VectorVectorDouble coords,
const DbGrid db_grid,
VectorDouble tab 
)
static

Locate a set of points on a grid

Returns
Number of samples located on the grid
Parameters
[in]npNumber of samples
[in]coordsArray of coordinates (dimension: ndim, np)
[in]db_griddescriptor of the grid parameters
[out]tabOutput array (Dimension: Number of discretized points)
Remarks
The array tab contains the index of the closest grid node
even if the sample does not lie within the grid
This function is limited to 3D space maximum. The consistency
of space dimension must have been performed beforehand

◆ st_locate_point_on_grid()

static int st_locate_point_on_grid ( const Db db_point,
const DbGrid db_grid,
VectorDouble coor,
VectorDouble tab 
)
static

Locate a set of points on a grid

Returns
Number of samples located on the grid
Parameters
[in]db_pointdescriptor of the point parameters
[in]db_griddescriptor of the grid parameters
[out]coorWorking array
[out]tabOutput array (Dimension: Number of point samples)
Remarks
The array tab contains the index of the closest grid node
even if the sample does not lie within the grid

◆ st_multilinear_evaluate()

static int st_multilinear_evaluate ( DbGrid db_grid,
const VectorInt indg,
int  iatt,
double *  value 
)
static

◆ st_multilinear_interpolation()

static double st_multilinear_interpolation ( DbGrid dbgrid,
int  iatt,
int  distType,
const VectorDouble dmax,
const VectorDouble coor 
)
static

Perform the multi-linear interpolation from a regular grid Db

Returns
Interpolated value
Parameters
[in]dbgriddescriptor of the grid parameters
[in]iattrank of the target variable in dbgrid
[in]distTypeType of distance for calculating maximum distance 1 for L1 and 2 for L2 distance
[in]dmaxArray of maximum distances (optional)
[in]coorCoordinates of the target point

◆ st_next_sample()

int st_next_sample ( int  ip0_init,
const VectorInt rank,
const VectorDouble xtab,
double  xtarget 
)

Get the rank of the next sample just above the target To speed up the process, this operation is performed starting from the rank assigned to the previous sample (this assumes that samples are treated by increasing coordinate)

Parameters
ip0_initRank of the previous sample
rankArray of sample ordering
xtabArray of sample coordinates
xtargetTarget coordinate
Returns
Rank of the sample just above the target (or equal)
Note
: The use of 'ip0_init' which could be different from 0 has been abandoned temporarily

◆ st_shift()

static void st_shift ( int  rank,
Db dbgrid,
const VectorInt indg1,
const VectorDouble prop,
VectorInt indg2,
double *  weight 
)
static