-
Manuel Günther authoredManuel Günther authored
Graph.cpp 5.56 KiB
/**
* @author Manuel Guenther <manuel.guenther@idiap.ch>
* @date Wed Jun 11 17:20:43 CEST 2014
*
* @brief The C++ implementations of a Graph of Gabor jets
*
* Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland
*/
#include <bob.ip.gabor/Graph.h>
/**
* Generates grid graphs which will be placed according to the given eye positions
* @param lefteye Position of the left eye
* @param righteye Position of the right eye
* @param between Number of nodes to place between the eyes (excluding the eye nodes themselves)
* @param along Number of nodes to place left and right of the eye nodes (excluding the eye nodes themselves)
* @param above Number of nodes to place above the eyes (excluding the eye nodes themselves)
* @param below Number of nodes to place below the eyes (excluding the eye nodes themselves)
*/
bob::ip::gabor::Graph::Graph(
blitz::TinyVector<int,2> righteye,
blitz::TinyVector<int,2> lefteye,
int between,
int along,
int above,
int below
)
{
// shortcuts for eye positions
int rex = righteye[1], rey = righteye[0];
int lex = lefteye[1], ley = lefteye[0];
// compute grid parameters
double stepx = double(lex - rex) / double(between+1);
double stepy = double(ley - rey) / double(between+1);
double xstart = rex - along*stepx + above*stepy;
double ystart = rey - along*stepy - above*stepx;
int xcount = between + 2 * (along+1);
int ycount = above + below + 1;
// create grid positions
m_nodes.resize(xcount*ycount);
for (int y = 0, i = 0; y < ycount; ++y){
for (int x = 0; x < xcount; ++x, ++i){
// y position
m_nodes[i][0] = round(ystart + y * stepx + x * stepy);
// x position
m_nodes[i][1] = round(xstart + x * stepx - y * stepy);
}
}
}
/**
* Generates a grid graph starting at the given first index, ending at (or before) the given last index, and advancing the given step size.
* @param first First node to be placed (top-left)
* @param last Last node to be placed (bottom-right). Depending on the step size, this node might not be reached.
* @param step The step size (in pixel) between two nodes
*/
bob::ip::gabor::Graph::Graph(
blitz::TinyVector<int,2> first,
blitz::TinyVector<int,2> last,
blitz::TinyVector<int,2> step
)
{
int ycount = (last[0] - first[0]) / step[0] + 1;
int xcount = (last[1] - first[1]) / step[1] + 1;
// create grid positions
m_nodes.resize(xcount*ycount);
for (int y = 0, i = 0; y < ycount; ++y){