コード例 #1
0
ファイル: imcolres.c プロジェクト: svn2github/iup-iup
/*

%F Muda o cursor quando ele passa sobre uma juncao de titulos de coluna.
%i h : handle da matriz,
   x,y : coordenadas do mouse (coordenadas do canvas).

*/
void iupmatColresChangeCursor(Ihandle *h, int x, int y)
{
  Tmat *mat=(Tmat*)matrix_data(h);
  int ativo;
  char *attr = IupGetAttribute(h,IUP_RESIZEMATRIX);
  if (attr)
    ativo = !iupStrEqual(attr,IUP_NO);
  else
    ativo = 0;

  if(mat_ht(mat) && y<mat_ht(mat) && ativo)
  {
    /* Esta na area de tituos de coluna e o modo de resize esta ligado */
    int achou=0,width=mat_wt(mat),col;

    if(abs(width-x)<TOL)
      achou=1;            /*titulos de linha */
    else
    {
      for (col=mat_fc(mat);col<=mat_lc(mat)&&!achou;col++)
      {
        width+=mat_w(mat)[col];
        if (abs(width-x) < TOL)
          achou = 1;
      }
    }

    if (achou)
      iupCpiDefaultSetAttr(mat_self(mat),IUP_CURSOR,IUP_RESIZE_W);
    else
      setMatrixCursor(mat_self(mat)); /* Esta na area vazia apos a ultima coluna */
  }
  else
    setMatrixCursor(mat_self(mat));
}
コード例 #2
0
ファイル: imcolres.c プロジェクト: svn2github/iup-iup
/*

%F Muda a largura da coluna interativamente, so muda a linha na tela.
   Qando o usuario termina o drag, a funcao iupmatColresFinish e chamada
   para realmente mudar a largura da coluna.
%i h : handle da matriz,
   x : coordenada x do mouse (coordenadas do canvas).

*/
void iupmatColresMove(Ihandle *h, int x)
{
  Tmat *mat=(Tmat*)matrix_data(h);
  int y1,y2, charwidth,charheight;

  iupdrvGetCharSize(h,&charwidth,&charheight);

  /* Se tamanho da coluna ficou muito pequeno, nao muda tamanho da coluna */
  if (x < DragColStartPos+charwidth+DECOR_X)
    return;

  y1 = mat_ht(mat);
  y2 = YmaxCanvas(mat);

  cdCanvasWriteMode(mat->cdcanvas, CD_XOR);
  cdCanvasForeground(mat->cdcanvas, RESIZE_COLOR);

  /* Se nao e a primeira vez, retira linha antiga */
  if (Lastxpos != -1)
    cdCanvasLine(mat->cdcanvas,Lastxpos,INVY(y1),Lastxpos,INVY(y2));

  cdCanvasLine(mat->cdcanvas,x,INVY(y1),x,INVY(y2));

  Lastxpos = x;
  cdCanvasWriteMode(mat->cdcanvas, CD_REPLACE);
}
コード例 #3
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*
%F Muda o alihamento dos textos em uma determinada coluna. Redesenha a
   coluna se estiver visivel.
%i h : handle da matriz,
   col : coluna ater seu alinhamento mudado. col = 1 representa aprimeira
         coluna da matriz.
*/
void iupmatSetColAlign (Ihandle *h, int col)
{
  Tmat *mat=(Tmat*)matrix_data(h);
  Ihandle *d   = IupGetDialog(h);
  int visible = (iupCheck(h,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);
  int err;

  IsCanvasSet(mat,err);

  if(col > mat_nc(mat) || col < 0)
    return;

  if(!visible || err!=CD_OK)
    return;

  if(col == 0) /* Alinhamento da coluna de titulos */
  {
    iupmatDrawLineTitle(h, mat_fl(mat), mat_ll(mat));
  }
  else
  {
    col--;  /* a celula super. esq. e 1:1 para o usuario, internamente e 0:0 */
    /* Se a coluna esta na parte visivel, redesenha a matriz */
    if((col >= mat_fc(mat))&&(col <= mat_lc(mat)))
    {
      iupmatDrawCells(h,mat_fl(mat),col,mat_ll(mat),col);
      iupmatShowFocus(h);
    }
  }
}
コード例 #4
0
  LargeGPUMatrixFixtureComplex()
  {
std::cout << "LargeGPUMatrixFixtureComplex" << std::endl;
    agile::GPUEnvironment::allocateGPU(0);

    x_host.resize(NUM_COLUMNS);
    y_host.resize(NUM_ROWS);
    std::vector<std::complex<float> > matrix_data(NUM_ROWS * NUM_COLUMNS);
    for (unsigned counter = 0; counter < NUM_COLUMNS; ++counter)
      x_host[counter] = std::complex<float>(float(rand()) / RAND_MAX * 10 - 5,
                                            float(rand()) / RAND_MAX * 10 - 5);
    for (unsigned counter = 0; counter < NUM_ROWS; ++counter)
      y_host[counter] = std::complex<float>(float(rand()) / RAND_MAX * 10 - 5,
                                            float(rand()) / RAND_MAX * 10 - 5);
    for (unsigned row = 0; row < NUM_ROWS; ++row)
      for (unsigned column = 0; column < NUM_COLUMNS; ++column)
        matrix_data[row * NUM_COLUMNS + column]
          = std::complex<float>(float(rand()) / RAND_MAX * 10 - 5,
                                float(rand()) / RAND_MAX * 10 - 5);

    x.assignFromHost(x_host.begin(), x_host.end());
    y.assignFromHost(y_host.begin(), y_host.end());
    A_host = new agile::CPUMatrix<std::complex<float> >(NUM_ROWS, NUM_COLUMNS,
                                                          &matrix_data[0]);
    A = new agile::GPUMatrixPitched<std::complex<float> >(NUM_ROWS, NUM_COLUMNS,
                                                     &matrix_data[0]);
std::cout << "LargeGPUMatrixFixtureComplex done" << std::endl;
  }
コード例 #5
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*
%F Funcao chamada para ativar ou desativar uma linha ou coluna da matriz.

%i h      - Handle da matriz
   mode   - Flag que indica se estou operando em linhas ou colunas
            [MAT_LIN|MAT_COL]
   lincol - Numero da linha ou coluna em questao (formato IUP)
   val    - Valor do atributo.
*/
void iupmatSetActive(Ihandle *h, int mode, int lincol, char *val)
{
  Tmat *mat = (Tmat*)matrix_data(h);
  int on = iupStrEqualNoCase(val,"ON") || iupStrEqualNoCase(val,"YES");
  Ihandle *d   = IupGetDialog(h);
  int visible = (iupCheck(h,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);
  int err;

  lincol--;

  if (mode == MAT_LIN)
    mat_lininactive(mat)[lincol] = !on;
  else
    mat_colinactive(mat)[lincol] = !on;

  IsCanvasSet(mat,err);
  if (visible && (err == CD_OK))
  {
    if(mode == MAT_LIN)
    {
      iupmatDrawLineTitle(h,lincol,lincol);
      iupmatDrawCells(h,lincol,mat_fc(mat),lincol,mat_lc(mat));
    }
    else
    {
      iupmatDrawColumnTitle(h,lincol,lincol);
      iupmatDrawCells(h,mat_fl(mat),lincol,mat_ll(mat),lincol);
    }
  }
}
コード例 #6
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*
%F Chamada quando da mudanca do titulo de uma linha, redesenha o titulo
   se ele for visivel
%i h : handle da matriz,
   linha : Linha que teve seu titulo alterado. linha = 1 indica que o
           titulo da primeira linha foi alterado. Ja linha = 0 indica que
           o titulo da celula que fica no canto entre os titulos de linha
           e coluna foi modificado.

*/
void iupmatSetTitleLine(Ihandle *h, int linha)
{
 Tmat *mat=(Tmat*)matrix_data(h);
 Ihandle *d   = IupGetDialog(h);
 int visible = (iupCheck(h,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);
 int err;

 if (linha > mat_nl(mat) || linha < 0)
   return;

 IsCanvasSet(mat,err);
 if (visible && err == CD_OK)
 {
   /* Se e' o titulo do canto, e o canto existe */
   if (linha == 0)
   {
     /* Redesenha o canto entre titulos de linha e coluna
        se ele existir
     */
     iupmatDrawTitleCorner(h);
   }
   else
   {
     linha--;
     /* Redesenha o titulo da linha, se ela estiver visivel */
     iupmatDrawLineTitle(h,linha,linha);
   }
 }
}
コード例 #7
0
ファイル: imcolres.c プロジェクト: svn2github/iup-iup
/*

%F Termina o resize interativo de colunas. Chama a funcao ChangeMatrixWidth para
   mudar realmente o tamanho da coluna.
%i h : handle da matriz,
   x : coordenada x do mouse (coordenadas do canvas).

*/
void iupmatColresFinish(Ihandle *h, int x)
{
  int  charwidth,charheight, width;
  int  y1, y2;
  Tmat *mat=(Tmat*)matrix_data(h);

  iupdrvGetCharSize(h,&charwidth,&charheight);
  width = x - DragColStartPos-DECOR_X;

  if (width < charwidth)
    width = charwidth ;  /* Tamanho minimo para a celula */

  /* Apaga feedback */
  if (Lastxpos != -1)
  {

    y1 = mat_ht(mat);
    y2 = YmaxCanvas(mat);

    cdCanvasWriteMode(mat->cdcanvas,CD_XOR);
    cdCanvasForeground(mat->cdcanvas,RESIZE_COLOR);
    cdCanvasLine(mat->cdcanvas,Lastxpos,INVY(y1),Lastxpos,INVY(y2));
    cdCanvasWriteMode(mat->cdcanvas,CD_REPLACE);

  }

  ChangeMatrixWH(h,DragCol,width+DECOR_X,MAT_COL);
  Dragging = 0;
}
コード例 #8
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*

%F Funcao que retorna a coordenada da celula superior esquerda da parte
  atualmente visivel da matrix.

%i h - Handle da matriz.
%o Retorna uma string com a coordenada da celula, no formato lin:col

*/
char *iupmatGetOrigin(Ihandle *h)
{
  Tmat *mat = (Tmat*)matrix_data(h);
  static char val[100];

  sprintf(val,"%d:%d",mat_fl(mat)+1,mat_fc(mat)+1);
  return val;
}
コード例 #9
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*

%F Consulta a celula que contem o focus.
%i h : handle da matriz,
%r string contendo a celula esta com o foco, na forma "%d:%d",
       onde o primeiro numero indica a linha e o segundo a coluna. "1:1"
       corresponde a celula do canto superior esquerdo.

*/
char *iupmatGetFocusPosition(Ihandle *h)
{
  static char cell[100];
  Tmat *mat=(Tmat*)matrix_data(h);
  if (mat)
   sprintf(cell,"%d:%d",mat_lin(mat)+1,mat_col(mat)+1);
  else
   return NULL;
  return cell;
}
コード例 #10
0
ファイル: imcolres.c プロジェクト: svn2github/iup-iup
/*

%F Verifica se o mouse esta na intersecao entre dois titulos de coluna. Se
   estiver inicia o resize.
%i h : handle da matriz,
   x,y : coordenadas do mouse (coordenadas do canvas).

%o Retorna 1 se iniciou um resize, 0 caso contrario.
*/
int iupmatColresTry(Ihandle *h, int x, int y)
{
  Tmat *mat=(Tmat*)matrix_data(h);
  int achou,ativo,width,col;
  char *attr;

  attr = IupGetAttribute(h,IUP_RESIZEMATRIX);
  if (attr)
    ativo = !iupStrEqual(attr,IUP_NO);
  else
    ativo = 0;

  if(mat_ht(mat) && y<mat_ht(mat) && ativo)
  {
    /* Esta na area de titulos de coluna*/
    achou = 0;
    width = mat_wt(mat);

    if (abs(width-x) < TOL)
    {
      /* Estou na interface entre a coluna de titulos e a primeira coluna */
      col = 0;
      achou = 1;
      DragColStartPos = 0;
    }
    else
    {
      /* Procura para ver se estou em outra interface */
      DragColStartPos= width;
      for (col=mat_fc(mat);col<=mat_lc(mat)&&!achou;col++)
      {
        width+=mat_w(mat)[col];
        if (abs(width-x) < TOL)
          achou = 1;
        if (!achou)
          DragColStartPos= width;
      }
    }

    if (achou)
    {
      Dragging = 1;
      Lastxpos = -1;
      DragCol = col-1;

      return 1;
    }
  }
  return 0;
}
コード例 #11
0
ファイル: imcolres.c プロジェクト: svn2github/iup-iup
/*

%F Pega a largura/altura de uma coluna/linha. Os atributos WIDTH e HEIGHT nao
   podem ser consultados pois quando a largura/altura da coluna/linha sao
   mudados dinamicamente, o valor do atributo fica desatualizado. Alem disso,
   nem todas as colunas/linhas tem seu atributo WIDTH/HEIGHT definidos.
   (Largura e altura default)
%i h   : handle da matriz,
   col : coluna/linha que tera seua largura/altura consultada. col = 1 indica
         a primeira coluna/linha, col = 0 indica a coluna/linha de titulos.
   m   : Indica se estou operando sobre linhas(MAT_LIN) ou colunas(MAT_COL).

%o retorna uma string com a largura, ja retorna em valores tipo IUP.

*/
char *iupmatColresGet(Ihandle *h, int col, int m, int pixels)
{
  static char width[100];
  Tmat *mat = (Tmat*)matrix_data(h);
  int w;
  Tlincol *p;

  if (m == MAT_LIN)
    p = &(mat->lin);
  else
    p = &(mat->col);

  if (col > p->num || col < 0)
    return NULL;

  if (col == 0)
    w = p->titlewh;
  else
  {
    col--;  /* a celula super. esq. e 1:1 para o usuario, internamente e 0:0 */
    w = p->wh[col];
  }


  if (w)
  {
    if (pixels)
    {
      if (m == MAT_COL)
        sprintf(width,"%d",(int)(w-DECOR_X));
      else
        sprintf(width,"%d",(int)(w-DECOR_Y));
    }
    else
    {
      int charwidth,charheight;
      iupdrvGetCharSize(h,&charwidth,&charheight);
      if (m == MAT_COL)
        sprintf(width,"%d",(int)((w-DECOR_X)*4/charwidth));
      else
        sprintf(width,"%d",(int)((w-DECOR_Y)*8/charheight));
    }
  }
  else
    strcpy(width,"0");

  return width;
}
コード例 #12
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*
%F Retorna o valor de uma celula da matriz
%i n : handle da matriz,
   lin,col : coordenadas da celula a ser consultada, (1,1) corresponde a
             celula do canto superior esquerdo.
%o retorna o valor da celula.
   Used only by getattribute method.
*/
char *iupmatGetCell (Ihandle *n, int lin, int col)
{
  Tmat *mat = (Tmat*)matrix_data(n);

  /* Se a celula nao existe, retorna NULL */
  if ((lin < 0) || (col < 0) || (lin > mat_nl(mat)) || (col > mat_nc(mat)))
    return NULL;

  lin--;  /* a celula superior esquerda e´ 1:1 para o usuario, */
  col--;  /* internamente ela e´ 0:0                           */

  if (lin==mat_lin(mat) && col==mat_col(mat) && iupCheck(mat_edtdatah(mat), "VISIBLE")==YES)
    return iupmatEditGetValue(mat);
  else
    return iupmatGetCellValue(n,lin,col);
}
コード例 #13
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
void iupmatSetRedrawCell(Ihandle* n, int lin, int col)
{
  Tmat *mat    = (Tmat*)matrix_data(n);
  Ihandle *d   = IupGetDialog(n);
  int visible  = (iupCheck(n,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);
  int err;

  IsCanvasSet(mat,err);
  if(!visible || err != CD_OK)
    return;

  if(lin == -1) /* Redesenha uma coluna */
  {
    iupmatHideFocus(n);
    iupmatDrawCells(n,mat_fl(mat),col-1,mat_ll(mat),col-1);
    iupmatShowFocus(n);
  }
  else if(col == -1) /* Redesenha uma linha */
  {
    iupmatHideFocus(n);
    iupmatDrawCells(n,lin-1,mat_fc(mat),lin-1,mat_lc(mat));
    iupmatShowFocus(n);
  }
  else /* Redesenha apenas a celula */
  {
    /* Se a celula nao existe, retorna NULL */
    if((lin < 0) || (col < 0) || (lin > mat_nl(mat)) || (col > mat_nc(mat)))
      return;

    lin--;  /* A celula superior esquerda e 1:1 para o usuario, */
    col--;  /* Internamente ela e 0:0                           */

    if(col == -1 && lin == -1) /* Canto de titulo */
     iupmatDrawTitleCorner(n);
    else if(col == -1) /* Titulo de uma linha */
     iupmatDrawLineTitle(n,lin,lin);
    else if(lin == -1) /* Titulo de uma coluna */
      iupmatDrawColumnTitle(n,col,col);
    else if(iupmatIsCellVisible(n,lin,col))
    {
      iupmatDrawCells(n, lin, col, lin, col);
      iupmatShowFocus(n);
    }
  }
}
コード例 #14
0
ファイル: imcolres.c プロジェクト: svn2github/iup-iup
/*

%F Muda a largura de uma coluna ou a altura de uma linha, redesenhando se
   estiver visivel
%i col : coluna/linha a ter sua largura modificada, Esta funcao trbalha com a
         representacao interna para o numero de coluna, ou seja col = 0 e
         a primeira coluna, col = -1 e a coluna de titulos. O mesma
         representacao e' usada para linhas
   largura : largura em pixels da coluna/linha col.
   m  : Indica se estou atuando sobre uma coluna (MAT_COL) ou linha (MAT_LIN).

*/
static void ChangeMatrixWH(Ihandle *h,int col,int largura, int m)
{
 Tmat *mat=(Tmat*)matrix_data(h);
 Ihandle *d   = IupGetDialog(h);
 int visible = (iupCheck(h,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);
 int err,drawmode = m;
 Tlincol *p;

 if (m == MAT_LIN)
   p = &(mat->lin);
 else
   p = &(mat->col);

 IsCanvasSet(mat,err);

 if (col != -1)  /* col -1 indica largura do titulo */
 {
   if (largura > p->size)   /* largura nao pode ser maior que area util */
     largura = p->size;

   /* Recalcula espaco total ocupado pelas colunas/linhas */
   p->totalwh=p->totalwh - p->wh[col] + largura;
   p->wh[col]=largura;
 }
 else if (p->titlewh > 0)      /* so muda tamanho, se ja' existir titulo */
 {
   if(largura > XmaxCanvas(mat))
     largura = XmaxCanvas(mat);
   /* Recalcula espaco que sobra para as outras celulas */
   p->size=p->size+p->titlewh-largura;
   p->titlewh = largura;

   drawmode = DRAW_ALL; /* Tenho que redesenhar os titulos de linha/coluna tambem */
 }
 iupmatGetLastWidth(h,m);

 /* Se a coluna/linha esta na parte visivel, redesenha a matriz */
 if (((col >= p->first)&&(col <= p->last)) || col==-1)
  if (visible && err == CD_OK)
  {
    SetSb(m);
    iupmatDrawMatrix(h,drawmode);
    iupmatShowFocus(h);
  }
}
コード例 #15
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*

%F  Chamada quando da mudanca do titulo de uma coluna, redesenha o titulo
    se ele for visivel
%i  h : handle da matriz,
    col : Coluna que teve seu titulo alterado. col = 1 indica que o
          titulo da primeira coluna foi alterado
*/
void iupmatSetTitleColumn(Ihandle *h, int col)
{
 Tmat *mat =(Tmat*)matrix_data(h);
 Ihandle *d   = IupGetDialog(h);
 int visible = (iupCheck(h,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);
 int err;

 if (col > mat_nc(mat) || col < 1)
   return;
 col--;

 IsCanvasSet(mat,err);
 if (visible && err==CD_OK)
 {
   /* Redesenha o titulo da coluna, se estiver visivel */
   iupmatDrawColumnTitle(h,col,col);
 }
}
コード例 #16
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*

%F Seta o valor de uma celula da matriz, redesenha a celula se
   estiver visivel.
%i n : handle da matriz,
   lin,col : coordenadas da celula a ser modificada, (1,1) corresponde a
             celula do canto superior esquerdo.
   v : string com o novo valor da celula.
%o retorna v.

*/
void *iupmatSetCell (Ihandle *n, int lin ,int col, char *v)
{
 Tmat *mat    = (Tmat*)matrix_data(n);
 Ihandle *d   = IupGetDialog(n);
 int cellvisible;
 int visible = (iupCheck(n,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);

 int err;

 if (v==NULL)
   v="";

 IsCanvasSet(mat,err);

 /* Se a celula nao existe, retorna NULL */
 if ((lin < 1) || (col < 1) || (lin > mat_nl(mat)) || (col > mat_nc(mat)))
   return NULL;

 lin--;  /* a celula superior esquerda e 1:1 para o usuario, */
 col--;  /* internamente ela e 0:0                           */

  cellvisible = iupmatIsCellVisible(n,lin,col);

  if (mat->valeditcb)
  {
    mat->valeditcb(n,lin+1,col+1,v);
  }
  else if (!mat->valcb)
  {
    iupmatMemAlocCell(mat,lin,col,strlen(v));
    strcpy(mat_v(mat)[lin][col].value,v);
  }

  if (visible && cellvisible && err == CD_OK)
  {
    iupmatDrawCells(n, lin, col, lin, col);
    iupmatShowFocus(n);
  }

  return v;
}
コード例 #17
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
void iupmatSetRedraw(Ihandle *h, char *value)
{
 Tmat *mat = (Tmat*)matrix_data(h);
 Ihandle *d   = IupGetDialog(h);
 int visible = (iupCheck(h,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);
 int err;
 int type=DRAW_ALL;

 if (value == NULL)
   return;

 IsCanvasSet(mat,err);

 if (visible && (err == CD_OK))
 {
   if (value[0] == 'L' || value[0] == 'l')
     type = DRAW_LIN;
   else if (value[0] == 'C' || value[0] == 'c')
     type = DRAW_COL;

   if(type != DRAW_ALL)
   {
     int min=0,max=0;
     value++;
     if (iupStrToIntInt(value,&min,&max, ':')!=2)
       max = min;

     if(type==DRAW_LIN)
       iupmatDrawCells(h,min-1,mat_fc(mat),max-1,mat_lc(mat));
     else
       iupmatDrawCells(h,mat_fl(mat),min-1,mat_ll(mat),max-1);
   }
   else
   {
     iupmatDrawMatrix(h,DRAW_ALL);
   }

   iupmatShowFocus(h);
 }
}
コード例 #18
0
void colorengine::threadFunc()
{
    std::unique_ptr<float> regdata(new float[width_*height_]);

    std::vector<float> scalar_constant(3);
    scalar_constant.push_back(0);
    scalar_constant.push_back(0);
    scalar_constant.push_back(0);

    _XTIFFInitialize();
    rawdata_tiff = TIFFOpen(raw_tiff_path.c_str(), "w");
    TIFFSetField(rawdata_tiff, TIFFTAG_NFILTERS, filter_->nfilters());
    TIFFSetField(rawdata_tiff, TIFFTAG_NLIGHTS, nlights_);

    for (auto filter_index = 0; filter_index < filter_->nfilters(); ++filter_index) {
        std::vector<float> cmf = filter_->cmfValues(filter_->wavelengthAtPos(filter_index));
        float illuminant = filter_->illuminantValue(filter_->wavelengthAtPos(filter_index));
        for (auto xyz_index = 0; xyz_index < 3; ++xyz_index) {
            scalar_constant[xyz_index] += cmf[xyz_index] * illuminant;
        }
    }
    int page_index = 0;
    for (int filter_index = 0; filter_index < filter_->nfilters(); ++filter_index) {  
        for (int light_index = 0; light_index < nlights_; ++light_index) {
            std::shared_ptr<unsigned short> data = data_queue_.pop();
            if (cancel_) {
                return;
            }
            std::unique_ptr<float> floatdata(new float[width_*height_]);

            for (auto y = 0; y < height_; ++y) {
                for (auto x = 0; x < width_; ++x) {
                    if (data.get()[y*width_+x] - bias_data.get()[y*width_+x] < 0) {
                        data.get()[y*width_+x] = 0;
                    } else {
                        data.get()[y*width_+x] -= bias_data.get()[y*width_+x];
                    }
                }
            }
            for (auto y = 0; y < height_; ++y) {
                for (auto x = 0; x <width_; ++x) {
                    if (flat_data[light_index]->filterData(filter_index)[y*width_+x] == 0) {
                        floatdata.get()[y*width_+x] = 0;
                    } else {
                        floatdata.get()[y*width_+x] = (float)data.get()[y*width_+x] / (float)flat_data[light_index]->filterData(filter_index)[y*width_+x];
                    }
                }
            }
            // subtract bias, divide flat field
            cv::Mat floatdatamat(height_, width_, CV_32F, floatdata.get());
            // Normalize data to a white reference

            std::vector<float> values;

            for (auto y = wtpt_rect_.y(); y < wtpt_rect_.y() + wtpt_rect_.size().height(); ++y) {
                for (auto x = wtpt_rect_.x(); x < wtpt_rect_.x() + wtpt_rect_.size().width(); ++x) {
                    values.push_back(floatdata.get()[y*width_+x]);
                }
            }
            std::nth_element(values.begin(), values.begin()+(values.size()/2), values.end()); // median sort in constant time
            float measured_wtpt = values[values.size()/2];

            for (auto y = 0; y < height_; ++y) {
                for (auto x = 0; x < width_; ++x) {
                    floatdata.get()[y*width_+x] /= (measured_wtpt / absolute_wtpt_values_[filter_index]);
                }
            }

            if (filter_index == 0) { // use first filter as registration target
                for (auto y = 0; y < height_; ++y) {
                    for (auto x = 0; x < width_; ++x) {
                        regdata.get()[y*width_+x] = floatdata.get()[y*width_+x];
                    }
                }
                cv::Mat regdatamat(height_, width_, CV_32F, regdata.get());

            } else {                // Register image to regtarget_data
                // Phase-correlate based registration algorithm to align image planes based on two concentric circle targets
                // Concentric targets are used because of their non-repeating nature; phase correlate gets tripped up by repeating patterns as the peaks can be matched at errant points

                //cv::mat construction is efficient and does not copy data.  Initialize registration target from our regdata


                cv::Mat registerTo(height_, width_, CV_32F, regdata.get());
                cv::Mat reg0_source, reg0_target, reg1_source, reg1_target;
                cv::Mat reg0_sourcef, reg0_targetf, reg1_sourcef, reg1_targetf;

                // These cv::Mats' are our registration targets; selected by the user in the main application.

                //reg0_source = registration target 0 on the image that is going to be registered
                //reg0_target = registration target 1 on the image that is going to be registered to
                reg0_sourcef = floatdatamat(cv::Range(regtargets[0].y(), regtargets[0].y() + regtargets[0].size().height()), cv::Range(regtargets[0].x(), regtargets[0].x() + regtargets[0].size().width()));
                reg0_targetf = registerTo(cv::Range(regtargets[0].y(), regtargets[0].y() + regtargets[0].size().height()), cv::Range(regtargets[0].x(), regtargets[0].x() + regtargets[0].size().width()));// - (reg_size/2), regtargets[0].y + (reg_size/2)), cv::Range(regtargets[0].x - (reg_size/2), regtargets[0].x + (reg_size/2)));
                reg1_sourcef = floatdatamat(cv::Range(regtargets[1].y(), regtargets[1].y() + regtargets[1].size().height()), cv::Range(regtargets[1].x(), regtargets[1].x() + regtargets[1].size().width()));// - (reg_size/2), regtargets[1].y + (reg_size/2)), cv::Range(regtargets[1].x - (reg_size/2), regtargets[1].x + (reg_size/2)));
                reg1_targetf = registerTo(cv::Range(regtargets[1].y(), regtargets[1].y() + regtargets[1].size().height()), cv::Range(regtargets[1].x(), regtargets[1].x() + regtargets[1].size().width()));// - (reg_size/2), regtargets[1].y + (reg_size/2)), cv::Range(regtargets[1].x - (reg_size/2), regtargets[1].x + (reg_size/2)));

                double min, max;
                cv::Point minLoc, maxLoc;

                cv::minMaxLoc(reg0_sourcef, &min, &max, &minLoc, &maxLoc);
                reg0_sourcef *= 255/max;
                cv::minMaxLoc(reg1_sourcef, &min, &max, &minLoc, &maxLoc);
                reg1_sourcef *= 255/max;
                cv::minMaxLoc(reg0_targetf, &min, &max, &minLoc, &maxLoc);
                reg0_targetf *= 255/max;
                cv::minMaxLoc(reg1_targetf, &min, &max, &minLoc, &maxLoc);
                reg1_targetf *= 255/max;

                reg0_sourcef.convertTo(reg0_source, CV_8U);
                reg0_targetf.convertTo(reg0_target, CV_8U);
                reg1_sourcef.convertTo(reg1_source, CV_8U);
                reg1_targetf.convertTo(reg1_target, CV_8U);

                cv::adaptiveThreshold(reg0_source, reg0_source, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY, 11, 2);
                cv::adaptiveThreshold(reg0_target, reg0_target, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY, 11, 2);
                cv::adaptiveThreshold(reg1_source, reg1_source, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY, 11, 2);
                cv::adaptiveThreshold(reg1_target, reg1_target, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY, 11, 2);

                reg0_source.convertTo(reg0_source, CV_32F);
                reg1_source.convertTo(reg1_source, CV_32F);
                reg0_target.convertTo(reg0_target, CV_32F);
                reg1_target.convertTo(reg1_target, CV_32F);

                reg0_sourcef /= 255;
                reg0_targetf /= 255;
                reg1_sourcef /= 255;
                reg1_targetf /= 255;

                cv::Point2d offset_center = cv::phaseCorrelate(reg0_source, reg0_target);
                cv::Point2d offset_corner = cv::phaseCorrelate(reg1_source, reg1_target);

                float r, r_prime, deltaX, deltaY;

                deltaX = offset_corner.x - offset_center.x;
                deltaY = offset_corner.y - offset_center.y;

                r = pow((regtargets[1].center().x() - regtargets[0].center().x()), 2) + pow((regtargets[1].center().y() - regtargets[0].center().y()), 2);
                r = sqrt(r);

                r_prime = pow((regtargets[1].center().x() - regtargets[0].center().x() + deltaX), 2) + pow((regtargets[1].center().y() - regtargets[0].center().y() + deltaY), 2);
                r_prime = sqrt(r_prime);


                float scale = r_prime / r;
                float trans_x = (floatdatamat.size().width  / 2) * (1-scale);
                float trans_y = (floatdatamat.size().height / 2) * (1-scale);

                std::vector<float> matrix_data(6);
                matrix_data[0] = scale;
                matrix_data[1] = 0;
                matrix_data[2] = trans_x;
                matrix_data[3] = 0;
                matrix_data[4] = scale;
                matrix_data[5] = trans_y;

                cv::Mat affine(2, 3, CV_32F, matrix_data.data());
                cv::Mat scaled;
                cv::warpAffine(floatdatamat, scaled, affine, floatdatamat.size());

                cv::Mat scaled_target = scaled(cv::Range(regtargets[0].y(), regtargets[0].y() + regtargets[0].size().height()), cv::Range(regtargets[0].x(), regtargets[0].x() + regtargets[0].size().width()));
                cv::Point2d translation_offset = cv::phaseCorrelate(scaled_target, reg0_target);


                matrix_data[2] += translation_offset.x;
                matrix_data[5] += translation_offset.y;

                cv::warpAffine(floatdatamat, floatdatamat, affine, floatdatamat.size());
            }
            if (raw_tiff_path.size() > 0) {
                TIFFSetField(rawdata_tiff, TIFFTAG_IMAGEWIDTH, width_);
                TIFFSetField(rawdata_tiff, TIFFTAG_IMAGELENGTH, height_);
                TIFFSetField(rawdata_tiff, TIFFTAG_BITSPERSAMPLE, sizeof(float) * 8);
                TIFFSetField(rawdata_tiff, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
                TIFFSetField(rawdata_tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
                TIFFSetField(rawdata_tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
                TIFFSetField(rawdata_tiff, TIFFTAG_SAMPLESPERPIXEL, 1);
                TIFFSetField(rawdata_tiff, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
                TIFFSetField(rawdata_tiff, TIFFTAG_WTPTVAL, absolute_wtpt_values_[filter_index]);
                TIFFSetField(rawdata_tiff, TIFFTAG_WTPTMEASURED, measured_wtpt);
                TIFFSetField(rawdata_tiff, TIFFTAG_PAGENUMBER, page_index);

                for (auto row = 0; row < height_; ++row) {
                    TIFFWriteScanline(rawdata_tiff, &floatdata.get()[row*width_], row);
                }
                TIFFWriteDirectory(rawdata_tiff);
                ++page_index;
            }

            int wavelength = filter_->wavelengthAtPos(filter_index);
            std::vector<float> cmf = filter_->cmfValues(wavelength);
            float illuminant = filter_->illuminantValue(wavelength);
            for (auto y = 0; y < height_; ++y) {
                for (auto x = 0; x < width_; ++x) {
                    for (auto xyz_index = 0; xyz_index < 3; ++xyz_index) {
                        xyz_data[light_index].get()->filterData(xyz_index)[y*width_+x] += floatdata.get()[y*width_+x] * cmf[xyz_index] * illuminant;
                    }
                }
            }
        }
    }
    if (raw_tiff_path.size() > 0) {
        TIFFClose(rawdata_tiff);
    }
    // Scale xyz data by scalar constant
    for (auto light = 0; light < nlights_; ++light) {
        for (auto y = 0; y < height_; ++y) {
            for (auto x = 0; x < width_; ++x) {
                for (auto xyz_index = 0; xyz_index < 3; ++xyz_index) {
                     xyz_data[light].get()->filterData(xyz_index)[y*width_+x] /= scalar_constant[xyz_index];
                }
            }
        }
    }


    std::vector<XYZImage*> xyz_ptr;
    for (auto i = 0; i < xyz_data.size(); ++i) {
        xyz_ptr.push_back(xyz_data[i].get());
    }
    std::vector<float> weights(nlights_);
    for (auto weight = 0; weight < weights.size(); ++weight) {
       weights[weight] = 1.0 / float(nlights_);
    }

    master_xyz = std::shared_ptr<XYZImage>(new XYZImage(xyz_ptr, nlights_, weights));
}
コード例 #19
0
	CubeExample(void)
	 : cube_instr(make_cube.Instructions())
	 , cube_indices(make_cube.Indices())
	 , projection_matrix(prog)
	 , camera_matrix(prog)
	{
		// Set the vertex shader source and compile it
		VertexShader vs;
		vs.Source(
			"#version 150\n"
			"uniform mat4 ProjectionMatrix, CameraMatrix;"
			"layout (std140) uniform ModelBlock {"
			"	mat4 ModelMatrices[36];"
			"};"
			"in vec4 Position;"
			"out vec3 vertColor;"
			"void main(void)"
			"{"
			"	mat4 ModelMatrix = ModelMatrices[gl_InstanceID];"
			"	gl_Position = "
			"		ProjectionMatrix *"
			"		CameraMatrix *"
			"		ModelMatrix *"
			"		Position;"
			"	vertColor = abs(normalize((ModelMatrix*Position).yxz));"
			"}"
		).Compile();

		// set the fragment shader source and compile it
		FragmentShader fs;
		fs.Source(
			"#version 150\n"
			"in vec3 vertColor;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	fragColor = vec4(vertColor, 1.0);"
			"}"
		).Compile();

		// attach the shaders to the program
		prog.AttachShader(vs);
		prog.AttachShader(fs);
		// link and use it
		prog.Link().Use();

		projection_matrix.BindTo("ProjectionMatrix");
		camera_matrix.BindTo("CameraMatrix");

		// bind the VAO for the cube
		cube.Bind();

		// bind the VBO for the cube vertices
		verts.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.Positions(data);
			// upload the data
			Buffer::Data(Buffer::Target::Array, data);
			// setup the vertex attribs array for the vertices
			(prog|"Position").Setup<GLfloat>(n_per_vertex).Enable();
		}

		// make the matrices
		{
			// 36 x 4x4 matrices
			std::vector<GLfloat> matrix_data(36*16);
			auto p = matrix_data.begin(), e = matrix_data.end();

			Angle<GLfloat> angle, astep = Angle<GLfloat>::Degrees(10);
			while(p != e)
			{
				GLfloat cx = Cos(angle);
				GLfloat sx = Sin(angle);
				auto matrix = Transposed(Mat4f(
					Vec4f( cx, 0.0, -sx, 0.0),
					Vec4f(0.0, 1.0, 0.0, 0.0),
					Vec4f( sx, 0.0,  cx, 0.0),
					Vec4f(0.0, 0.0, 0.0, 1.0)
				) * Mat4f(
					Vec4f(1.0, 0.0, 0.0,12.0),
					Vec4f(0.0, 1.0, 0.0, 0.0),
					Vec4f(0.0, 0.0, 1.0, 0.0),
					Vec4f(0.0, 0.0, 0.0, 1.0)
				));
				p = std::copy(
					Data(matrix),
					Data(matrix)+Size(matrix),
					p
				);
				angle += astep;
			}

			UniformBlock model_block(prog, "ModelBlock");
			model_block.Binding(0);

			block_buf.Bind(Buffer::Target::Uniform);
			Buffer::Data(
				Buffer::Target::Uniform,
				matrix_data,
				BufferUsage::DynamicDraw
			);
			block_buf.BindBaseUniform(0);
		}

		//
		gl.ClearColor(0.9f, 0.9f, 0.9f, 0.0f);
		gl.ClearDepth(1.0f);
		gl.Enable(Capability::DepthTest);
	}
コード例 #20
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*

%F Seta a celula que contem o focus. Se a celula nao estiver visivel,
   muda a parte visivel da matriz para conter a celula como o foco.
%i h : handle da matriz,
   v : string contendo a celula que vai conter o foco. E da forma "%d:%d",
       onde o primeiro numero indica a linha e o segundo a coluna. "1:1"
       corresponde a celula do canto superior esquerdo.

*/
void iupmatSetFocusPosition(Ihandle *h, char *v, int call_cb)
{
  Tmat *mat=(Tmat*)matrix_data(h);
  int lin,col;
  int redraw = 0;
  Ihandle *d   = IupGetDialog(h);
  int visible = (iupCheck(h,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);
  int err;

  IsCanvasSet(mat,err);

  if (!v) return;

  if (iupStrToIntInt(v,&lin,&col,':')!=2)
    return;

  /* Se a celula nao existe, retorna */
  if ((lin < 1) || (col < 1) || (lin > mat_nl(mat)) || (col > mat_nc(mat)))
    return;

  lin--;  /* a celula superior esquerda e 1:1 para o usuario, */
  col--;  /* internamente ela e 0:0                           */

  if (mat_w(mat)[col] == 0)
    return;

  /* se a matriz esta' com focus, pede permissao a aplicacao */
  /* para sair da celula. Quando a matriz nao esta' com o    */
  /* focus, a aplicacao ja' foi avisada na perda do focus    */
  if (mat_hasiupfocus(mat) && call_cb)
  {
    if (iupmatCallLeavecellCb(h) == IUP_IGNORE)
      return;
  }

  /* Se a linha estiver invisivel */
  if (lin<mat_fl(mat) || lin>mat_ll(mat))
  {
    /* faz a primeira linha ser aquela que vai conter o focus */
    mat_fl(mat) = lin;
    iupmatGetLastWidth(h,MAT_LIN);
    redraw = 1;
  }

  /* Se a coluna estiver invisivel */
  if (col<mat_fc(mat) || col>mat_lc(mat))
  {
    /* Faz a primeira coluna ser aquela que vai conter o focus */
    mat_fc(mat) = col;
    iupmatGetLastWidth(h,MAT_COL);
    redraw = 1;
  }

  if(visible && err == CD_OK)
  {
    iupmatHideFocus(h);
    iupmatSetFocusPos(h,lin,col);

    if (redraw)
      iupmatDrawMatrix(h,DRAW_ALL);
    iupmatShowFocus(h);
  }

  /* Se a matriz esta' com focus, avisa a aplicacao da nova
     celula que tem o foco. Caso contrario, quando a matriz
     ganhar o foco entao a aplicacao sera avisada.
  */
  if (mat_hasiupfocus(mat) && call_cb)
   iupmatCallEntercellCb(h);
}
コード例 #21
0
ファイル: imgetset.c プロジェクト: svn2github/iup-iup
/*

%F Funcao para setar qual a area visivel da matriz.  Faz isto a partir
da informacao de qual celula deve ser colocada no canto superior
esquerdo da matriz.

%i h     - Handle da matriz
   value - Informacao de qual a celula que deve ficar no canto superio
           esquerdo da matriz, codificada no formato lin:col.

*/
void  iupmatSetOrigin(Ihandle *h, char *value)
{
 Tmat *mat = (Tmat*)matrix_data(h);
 Ihandle *d   = IupGetDialog(h);
 int visible = (iupCheck(h,IUP_VISIBLE)==YES) && (iupCheck(d,IUP_VISIBLE)==YES);
 int err;
 int lin=-1,col=-1,oldlin,oldcol,num=0;

 if (value == NULL)
   return;

 /* Pega os parametros. Um '*' indica que quero manter a tabela na mesma
   linha ou coluna.
 */
 if (iupStrToIntInt(value,&lin,&col,':') != 2)
 {
   if (lin != -1)
     col = mat_fc(mat) + 1;
   else if(col != -1)
     lin = mat_fl(mat) + 1;
   else
     return;
 }

 /* Se a celula nao existe, retorna NULL */
 if ((lin < 1) || (col < 1) || (lin > mat_nl(mat)) || (col > mat_nc(mat)))
   return;

 /* TODO: allow position based on the title cells also */

 lin--;  /* a celula superior esquerda e 1:1 para o usuario, */
 col--;  /* internamente ela e 0:0                           */

 IsCanvasSet(mat,err);

 oldcol = mat_fc(mat);
 oldlin = mat_fl(mat);

 mat_fc(mat) = col;
 iupmatGetLastWidth(h,MAT_COL);
 iupmatGetPos(h,MAT_COL);

 mat_fl(mat) = lin;
 iupmatGetLastWidth(h,MAT_LIN);
 iupmatGetPos(h,MAT_LIN);

 num = abs(oldcol - mat_fc(mat)) + abs(oldlin - mat_fl(mat));

 /* Se a matriz esta visivel, e houve mudanca na parte visivel da mesma,
   entao redesenha...
 */
 if (visible && (err == CD_OK) && num)
 {
  iupmatHideFocus(h);

  if(num == 1)
  {
    if(oldlin != mat_fl(mat))
      iupmatScroll(h,oldlin < mat_fl(mat)?SCROLL_DOWN:SCROLL_UP,oldlin,1);
    else
      iupmatScroll(h,oldcol < mat_fc(mat)?SCROLL_RIGHT:SCROLL_LEFT,oldcol,1);

    SetSbV;
    SetSbH;
  }
  else
  {
    SetSbV;
    SetSbH;

    iupmatDrawMatrix(h,DRAW_ALL);
  }

  iupmatShowFocus(h);
  mat->redraw = 1;
 }
}