fileMotionFilter.cpp
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
/*
*  MotionFilter.cpp
*
*  Created by Daisuke Nogami on Sep, 05.
*  opyright 2005 Daisuke Nogami [null-null.net]. Some rights reserved.
*/
 
#include "stdafx.h"
#include "MotionFilter.h"
 
#define HIT_RANGE 15
 
MotionFilter::MotionFilter( DirectShow* ds ){
  this->ds = ds;
}
 
// x[0-1], y[0-1]
void MotionFilter::getRgbAt( float x, float y, unsigned char* rgb ){
  // normalize
  x = x < 0 ? 0 : x;
  x = x > 1 ? 1 : x;
  y = y < 0 ? 0 : y;
  y = y > 1 ? 1 : y;
  int ix = (int)(((float)ds->_cWidth-1)*x);
  int iy = (int)(((float)ds->_cHeight-1)*y);
  int  rowSize = ds->_cWidth * 3;
  rgb[0] = ds->btmp[(ix*3)+iy*rowSize];
  rgb[1] = ds->btmp[(ix*3)+iy*rowSize+1];
  rgb[2] = ds->btmp[(ix*3)+iy*rowSize+2];
}
 
// attach raindrop
void MotionFilter::attach( CellSet* cellset, RainFilter* rfilter ){
  int x, y, i;
  float lenx, leny, len_a, len_b;
  float flow;
  unsigned char rgb[3];
 
  for( i = 0; i < rfilter->raindrop_num; i++ ){
 
    getRgbAt( rfilter->xpos[i]/1024, 1-rfilter->ypos[i]/768, rgb );
    flow = 1-(float)rgb[2]/255;
 
    // flow raindrop
    if( flow > 0.04 ){
 
      for( y = 0; y < cellset->hdiv; y++ ){
        for( x = 0; x < cellset->wdiv; x++ ){
 
          // cell A
          lenx = cellset->cells_a[x+y*cellset->wdiv].xpos+cellset->xpos-rfilter->xpos[i];
          leny = cellset->cells_a[x+y*cellset->wdiv].ypos+cellset->ypos-rfilter->ypos[i];
          len_a = sqrt( lenx*lenx+leny*leny );
 
          // cell B
          lenx = cellset->cells_b[x+y*cellset->wdiv].xpos+cellset->xpos-rfilter->xpos[i];
          leny = cellset->cells_b[x+y*cellset->wdiv].ypos+cellset->ypos-rfilter->ypos[i];
          len_b = sqrt( lenx*lenx+leny*leny );
 
          // hit test [ between raindrop and cell ]
          if( len_a < HIT_RANGE || len_b < HIT_RANGE ){
            cellset->cells_a[x+y*cellset->wdiv].flow = flow;
            cellset->cells_b[x+y*cellset->wdiv].flow = flow;
          }
        }
      }
 
      // clear raindrop
      rfilter->initRaindrop( i );
    }
  }
}
 
// attach airstream
void MotionFilter::attach( CellSet* cellset, AirstreamFilter* asfilter ){
  int x, y, i;
  unsigned char rgb_a[3], rgb_b[3];
  float m_a, m_b;
 
  for( y = 0; y < cellset->hdiv; y++ ){
    for( x = 0; x < cellset->wdiv; x++ ){
      i = x+y*cellset->wdiv;
 
      getRgbAt( (cellset->cells_a[i].xpos+cellset->xpos)/1024, 1-(cellset->cells_a[i].ypos+cellset->ypos)/768, rgb_a );
      getRgbAt( (cellset->cells_b[i].xpos+cellset->xpos)/1024, 1-(cellset->cells_b[i].ypos+cellset->ypos)/768, rgb_b );
      m_a = 1-(float)rgb_a[2]/255;
      m_b = 1-(float)rgb_b[2]/255;
 
      if( m_a > 0.1 ){
        cellset->cells_a[i].nextpow = m_a*2+2;
      }
      else{
        cellset->cells_a[i].nextpow = 1;
      }
      if( m_b > 0.1 ){
        cellset->cells_b[i].nextpow = m_b*2+2;
      }
      else{
        cellset->cells_b[i].nextpow = 1;
      }
    }
  }
}
[トップ] [一覧] [最終更新] [検索] [バックアップ]