Commit 36951eec authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

fix(zooming): Fix issue #6 - Zoom is aligned with cblks now, and start to cleaup the loops

parent f36d965e
......@@ -46,6 +46,8 @@ void Zooming::clean_move( double *xbeg, double *xend,
void Zooming::move(double xStart, double xEnd, double yStart, double yEnd)
{
symbol_cblk_t* cblk;
symbol_blok_t* blok;
int i, j, m, n;
clean_move( &xStart, &xEnd, &yStart, &yEnd );
......@@ -55,26 +57,36 @@ void Zooming::move(double xStart, double xEnd, double yStart, double yEnd)
int startRow = yStart * m_matrix->m_rowsnbr;
int endRow = yEnd * m_matrix->m_rowsnbr;
int diffCols = endCol - startCol;
int diffRow = endRow - startRow;
// Find first cblk
int startCblk = 0;
int endCblk = 0;
for (i = 0; i < m_matrix->m_cblknbr; ++i)
int endCblk = 0;
cblk = m_matrix->m_cblktab;
for (i = 0; i < m_matrix->m_cblknbr; ++i, cblk++)
{
symbol_cblk_t* cblk = &(m_matrix->m_cblktab[i]);
if (cblk->m_fcolumn <= startCol && cblk->m_lcolnum >= startCol)
if ( (cblk->m_fcolnum <= startCol) && (cblk->m_lcolnum >= startCol) )
{
startCblk = i;
if (cblk->m_fcolumn <= endCol && cblk->m_lcolnum >= endCol)
startCol = cblk->m_fcolnum;
}
if ( (cblk->m_fcolnum <= startRow) && (cblk->m_lcolnum >= startRow) )
{
startRow = cblk->m_fcolnum;
}
if ( (cblk->m_fcolnum <= endCol) && (cblk->m_lcolnum >= endCol) )
{
endCblk = i;
endCol = cblk->m_lcolnum;
}
if ( (cblk->m_fcolnum <= endRow) && (cblk->m_lcolnum >= endRow) )
{
endRow = cblk->m_lcolnum;
}
}
int diffCblk = endCblk - startCblk;
int nb_cols = endCol - startCol + 1;
int nb_rows = endRow - startRow + 1;
symbol_cblk_t* cblks = m_matrix->m_cblktab;
symbol_blok_t* bloks = m_matrix->m_bloktab;
int diffCblk = endCblk - startCblk;
for (i = 0; i < DEFAULT_LEVEL_POWER_2; ++i)
{
......@@ -84,34 +96,33 @@ void Zooming::move(double xStart, double xEnd, double yStart, double yEnd)
}
}
float xCoeff = (float)DEFAULT_LEVEL_POWER_2 / ((float)diffCols + 1);
float yCoeff = (float)DEFAULT_LEVEL_POWER_2 / ((float)diffRow + 1);
float xCoeff = (float)DEFAULT_LEVEL_POWER_2 / ((float)nb_cols);
float yCoeff = (float)DEFAULT_LEVEL_POWER_2 / ((float)nb_rows);
for (i = startCblk; i <= endCblk; ++i)
cblk = m_matrix->m_cblktab + startCblk;
for (i = startCblk; i <= endCblk; ++i, cblk++)
{
int firstBlokNum = cblks[i].m_bloknum;
int nextBlokNum = (i + 1 != m_matrix->m_cblknbr ? cblks[i + 1].m_bloknum : m_matrix->m_bloknbr);
int fbloknum = cblk->m_bloknum;
int lbloknum = (i + 1 != m_matrix->m_cblknbr ? cblk[1].m_bloknum : m_matrix->m_bloknbr);
// Get first block size in col from x to xEnd
symbol_cblk_t* cblk = &(cblks[i]);
int startingCol = (cblk->m_fcolumn < startCol ? startCol : cblk->m_fcolumn);
int endingCol = (cblk->m_lcolnum > endCol ? endCol + 1 : cblk->m_lcolnum);
int startingCol = cblk->m_fcolnum;
int endingCol = cblk->m_lcolnum;
int x = (startingCol - startCol) * xCoeff;
int xEnd = (endingCol - startCol) * xCoeff;
int x = (startingCol - startCol) * xCoeff;
int xEnd = (endingCol - startCol) * xCoeff;
for (j = firstBlokNum; j < nextBlokNum; ++j)
blok = m_matrix->m_bloktab + fbloknum;
for (j = fbloknum; j < lbloknum; ++j)
{
symbol_blok_t* blok = &(bloks[j]);
if (blok->m_frownum >= startRow && blok->m_frownum <= endRow)
{
// Get first block size in row from y to yEnd
int startingRow = (blok->m_frownum < startRow ? startRow : blok->m_frownum);
int endingRow = (blok->m_lrownum > endRow ? endRow + 1 : blok->m_lrownum);
int startingRow = blok->m_frownum;
int endingRow = blok->m_lrownum;
int y = (startingRow - startRow) * yCoeff;
int yEnd = (endingRow - startRow) * yCoeff;
int y = (startingRow - startRow) * yCoeff;
int yEnd = (endingRow - startRow) * yCoeff;
m = x;
do
......
......@@ -8,21 +8,22 @@
class Zooming
{
public:
static const int DEFAULT_LEVEL = 10;
static const int DEFAULT_LEVEL_POWER_2 = 1024;
static const int DEFAULT_LEVEL = 10;
static const int DEFAULT_LEVEL_POWER_2 = 1024;
public:
Zooming(symbol_matrix_t* matrix);
~Zooming();
~Zooming();
GLfloat getColor(int x, int y);
void move(double xStart, double xEnd, double yStart, double yEnd);
void move(double xStart, double xEnd, double yStart, double yEnd);
private:
symbol_matrix_t* m_matrix;
void clean_move( double *xs, double *xe, double *ys, double *ye );
GLfloat m_colors[DEFAULT_LEVEL_POWER_2][DEFAULT_LEVEL_POWER_2];
symbol_matrix_t *m_matrix;
GLfloat m_colors[DEFAULT_LEVEL_POWER_2][DEFAULT_LEVEL_POWER_2];
};
#endif
......@@ -77,7 +77,7 @@ void symbol_matrix_print_stats(symbol_matrix_t* matrix)
int32_t iterblok = cblk[0].m_bloknum + 1;
int32_t lbloknum = cblk[1].m_bloknum;
int32_t colnbr = cblk->m_lcolnum - cblk->m_fcolumn + 1;
int32_t colnbr = cblk->m_lcolnum - cblk->m_fcolnum + 1;
cblkmin = imin(cblkmin, colnbr);
cblkmax = imax(cblkmax, colnbr);
......
......@@ -5,7 +5,7 @@
typedef struct symbol_cblk_s
{
int32_t m_fcolumn; // First column index
int32_t m_fcolnum; // First column index
int32_t m_lcolnum; // Last column index (exclusive)
int32_t m_bloknum; // First blok in column
int32_t m_flags; // Flags
......
......@@ -45,12 +45,12 @@ int pastix_read_symbol(FILE* stream, symbol_matrix_t* matrix)
int32_t maxcol = 0;
for (cblknum = 0; cblknum < cblknbr; ++cblknum)
{
result = pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_fcolumn));
result = pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_fcolnum));
result += pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_lcolnum));
result += pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_bloknum));
if ((result != 3) ||
(matrix->m_cblktab[cblknum].m_fcolumn > matrix->m_cblktab[cblknum].m_lcolnum))
(matrix->m_cblktab[cblknum].m_fcolnum > matrix->m_cblktab[cblknum].m_lcolnum))
{
Helper::log(LogStatus::FATAL, "Bad input while reading cblk !");
......@@ -63,7 +63,7 @@ int pastix_read_symbol(FILE* stream, symbol_matrix_t* matrix)
matrix->m_cblktab[cblknum].m_flags = 0;
matrix->m_cblktab[cblknum].m_lcolnum++;
}
matrix->m_cblktab[cblknbr].m_fcolumn = matrix->m_cblktab[cblknbr].m_lcolnum = nodenbr + matrix->m_baseval;
matrix->m_cblktab[cblknbr].m_fcolnum = matrix->m_cblktab[cblknbr].m_lcolnum = nodenbr + matrix->m_baseval;
matrix->m_cblktab[cblknbr].m_bloknum = matrix->m_bloknbr + matrix->m_baseval;
matrix->m_colsnbr = maxcol + 1;
......
Markdown is supported
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