Beispiel #1
0
char *video_save (int row1, int col1, int row2, int col2)
{
    char    *s;
    int     r, ws, lw, lls;

    col1 = max1 (0, min1 (col1, COLS-1));
    col2 = max1 (0, min1 (col2, COLS-1));
    row1 = max1 (0, min1 (row1, ROWS-1));
    row2 = max1 (0, min1 (row2, ROWS-1));
    
    ws  = (row2-row1+1)*(col2-col1+1);
    lw  = col2-col1+1;
    lls = sizeof(int) * 4;
    s   = malloc (ws*2 + lls);

    ((int *)s)[0] = row1;
    ((int *)s)[1] = col1;
    ((int *)s)[2] = row2;
    ((int *)s)[3] = col2;

    for (r=row1; r<=row2; r++)
    {
        memcpy (s+(r-row1)*lw+lls, scrn_cache_chars+r*COLS+col1, lw);
        memcpy (s+(r-row1)*lw+ws+lls, scrn_cache_attrs+r*COLS+col1, lw);
    }
    return s;
}
Beispiel #2
0
void video_restore (char *s)
{
    int     r, ws, lw, lls;
    int     row1, col1, row2, col2;

    if (s == NULL) return;
    
    row1 = ((int *)s)[0];
    col1 = ((int *)s)[1];
    row2 = ((int *)s)[2];
    col2 = ((int *)s)[3];
    
    ws = (row2-row1+1)*(col2-col1+1);
    lw = col2 - col1 + 1;
    lls = sizeof(int) * 4;
    
    if (row1 > row2 || row1 >= ROWS ||
        col1 > col2 || col1 >= COLS)
    {
        free (s);
        return;
    }
                        
    for (r=row1; r<=min1(row2, ROWS-1); r++)
    {
        memcpy (scrn_cache_chars+r*COLS+col1, s+(r-row1)*lw+lls, min1(col2-col1+1, COLS-1-col1+1));
        memcpy (scrn_cache_attrs+r*COLS+col1, s+(r-row1)*lw+ws+lls, min1(col2-col1+1, COLS-1-col1+1));
    }
    
    free (s);
}
Beispiel #3
0
int Dijkstra1(int s,int e)
{
    int i,j;
    for(i=1;i<=C;i++)
    {
        hash[i]=true;
        path1[i]=-1;
    }
    path1[s]=INF;
    for(i=1;i<=C;i++)
    {
        int min=-1,w=-1;
        for(j=1;j<=C;j++)
        {
            if(hash[j]&&path1[j]>min)
            {min=path1[j];w=j;}
        }
        if(w==-1)
            break;
        hash[w]=false;
        for(j=1;j<=C;j++)
        {
            if(map1[w][j]!=-1&&path1[j]<min1(path1[w],map1[w][j]))
                path1[j]=min1(path1[w],map1[w][j]);
        }
    }
    return path1[e];
}
Beispiel #4
0
void select(HuffmanTree huffmanTree, int i, int *select1, int *select2) {
    int j;
    *select1 = min1(huffmanTree, i);
    *select2 = min1(huffmanTree, i);
    if (*select1 > *select2) {
        j = *select1;
        *select1 = *select2;
        *select2 = j;
    }
}
Beispiel #5
0
 void select(HuffmanTree t,int i,int *s1,int *s2)
 { /* s1为最小的两个值中序号小的那个 */
   int j;
   *s1=min1(t,i);
   *s2=min1(t,i);
   if(*s1>*s2)
   {
     j=*s1;
     *s1=*s2;
     *s2=j;
   }
 }
Beispiel #6
0
void addlims_(float* STARPAR, short int* JRECT)
{

     /* both passed vars are 1d arrays and do not need to be dereferenced 
        as a seperate step */

     /* renaming tuneable variables */
     float NPHSUB = (float)tune6_.nphsub; 
     float IHTAB  = (float)tune22_.ihtab; 
     
     /* substance of subroutine begins here */
     float TEMP, FUDGEX, FUDGEY;
     float BETA6;
     if (strncmp(tune16_.flags[0], "EXTPGAUSS", 5) == 0){
          BETA6 = STARPAR[8];
     }
     else{
          BETA6 = tune17_.beta6;
     }


     if (STARPAR[1] > 0.0f){
          TEMP = powf( ((STARPAR[1]/NPHSUB)*(6.0f/BETA6)), 0.33333333f );

          if (STARPAR[4] > 0.0f){
               FUDGEX = sqrtf(TEMP*STARPAR[4]*2.0f);
          }
          else{
               FUDGEX = 10.0f;
          }

          if (STARPAR[6] > 0.0f){
               FUDGEY = sqrtf(TEMP*STARPAR[6]*2.0f);
          }
          else{
               FUDGEY = 10.0f;
          }
     }
     else{
          FUDGEX = 10.0f;          
          FUDGEY = 10.0f;
     }

     FUDGEX = 2.0f * min1(FUDGEX, IHTAB-2.0f);
     FUDGEY = 2.0f * min1(FUDGEY, IHTAB-2.0f);

     JRECT[0] = STARPAR[2] - FUDGEX;
     JRECT[1] = STARPAR[2] + FUDGEX;
     JRECT[2] = STARPAR[3] - FUDGEY;
     JRECT[3] = STARPAR[3] + FUDGEY;

}
Beispiel #7
0
void Clock::displayColor(bool onOff)
{
     Digit hour1(x, y), hour2(x, y+10), min1(x, y+25), min2(x, y+35), sec1(x, y+50), sec2(x, y+60);
     hour1.changeColor(true); 
     hour2.changeColor(true); 
     min1.changeColor(true); 
     min2.changeColor(true); 
     sec1.changeColor(true); 
     sec2.changeColor(true); 
     if(onOff)
     {
          clearDisplay();
          hour1.display(hr/10, true); 
          hour2.display(hr%10, true);
          min1.display(min/10, true);
          min2.display(min%10, true); 
          sec1.display(sec/10, isSec);
          sec2.display(sec%10, isSec);

          if(isPM)
          {
             attron(COLOR_PAIR(BLACKONYELLOW));
             mvprintw(x+6, y-5, "PM");
             attroff(COLOR_PAIR(BLACKONYELLOW));
          }
          else
          {
             attron(COLOR_PAIR(WHITEONBLACK));
             mvprintw(x+6, y-5, "  ");
          }
          refresh();
     }
     else
         clearDisplay();   
}
Beispiel #8
0
int main()
{
    char a=min1('z','b');
    std::cout<<a<<"\n";
    int b=min2(1,8);
    std::cout<<b;
}
Beispiel #9
0
void video_put_n_char (char c, int n, int row, int col)
{
    if (n <= 0 || row < 0 || col < 0) return;
    if (row >= ROWS || col >= COLS) return;
    n = min1 (n, COLS-col);
    memset (scrn_cache_chars+row*COLS+col, c == '\0' ? ' ' : c, n);
}
Beispiel #10
0
void video_put_n_attr (char a, int n, int row, int col)
{
    if (n <= 0 || row < 0 || col < 0) return;
    if (row >= ROWS || col >= COLS) return;
    n = min1 (n, COLS-col);
    memset (scrn_cache_attrs+row*COLS+col, a, n);
}
// minimize a single link (see "PatchMatch" - page 4)
void minimizeLinkNNF(NNF_P nnf, int x, int y, int dir)
{
	int xp,yp,dp,wi, xpi, ypi;
	//Propagation Up/Down
	if (x-dir>0 && x-dir<nnf->input->image->height) {
		xp = nnf->field[x-dir][y][0]+dir;
		yp = nnf->field[x-dir][y][1];
		dp = distanceNNF(nnf,x,y, xp,yp);
		if (dp<nnf->field[x][y][2]) {
			nnf->field[x][y][0] = xp;
			nnf->field[x][y][1] = yp;
			nnf->field[x][y][2] = dp;
		}
	}
	//Propagation Left/Right
	if (y-dir>0 && y-dir<nnf->input->image->width) {
		xp = nnf->field[x][y-dir][0];
		yp = nnf->field[x][y-dir][1]+dir;
		dp = distanceNNF(nnf,x,y, xp,yp);
		if (dp<nnf->field[x][y][2]) {
			nnf->field[x][y][0] = xp;
			nnf->field[x][y][1] = yp;
			nnf->field[x][y][2] = dp;
		}
	}
	//Random search
	wi=nnf->output->image->width;
	xpi=nnf->field[x][y][0];
	ypi=nnf->field[x][y][1];
	int r=0;
    while (wi>0) {
		r=(rand() % (2*wi)) -wi;
		xp = xpi + r;
		r=(rand() % (2*wi)) -wi;
		yp = ypi + r;
		xp = (int)(max1(0, min1(nnf->output->image->height-1, xp )));
		yp = (int)(max1(0, min1(nnf->output->image->width-1, yp )));

		dp = distanceNNF(nnf,x,y, xp,yp);
		if (dp<nnf->field[x][y][2]) {
			nnf->field[x][y][0] = xp;
			nnf->field[x][y][1] = yp;
			nnf->field[x][y][2] = dp;
		}
		wi/=2;
	}
}
Beispiel #12
0
void video_put_str (char *s, int n, int row, int col)
{
    if (n <= 0 || row < 0 || col < 0) return;
    if (row >= ROWS || col >= COLS) return;
    n = min1 (n, COLS-col);
    memcpy (scrn_cache_chars+row*COLS+col, s, n);
    fix_string (scrn_cache_chars+row*COLS+col, n);
}
Beispiel #13
0
int main()
{
//   min1(foo{}, foo{}); // error - invalid operands to <
   min1(10, 20);
   
//   min2(foo{}, foo{}); // no matching function min2
   min2(10, 20);
}
// initialize field from an existing (possibily smaller) NNF
void initializeNNFFromOtherNNF(NNF_P nnf, NNF_P otherNnf)
{
	int fx, fy, x, y, xlow, ylow;
	// field
	allocNNFField(nnf);
	fy = nnf->fieldW/otherNnf->fieldW;
	fx = nnf->fieldH/otherNnf->fieldH;
    for (x=0;x<nnf->fieldH;++x) {
        for (y=0;y<nnf->fieldW;++y) {
			xlow = (int)(min1(x/fx, otherNnf->input->image->height-1));
			ylow = (int)(min1(y/fy, otherNnf->input->image->width-1));
			nnf->field[x][y][0] = otherNnf->field[xlow][ylow][0]*fx;  
			nnf->field[x][y][1] = otherNnf->field[xlow][ylow][1]*fy;
			nnf->field[x][y][2] = DSCALE;
		}
	}
	initializeNNF(nnf);
}
Beispiel #15
0
void video_init (int rows, int cols)
{
    int   row;
    char  *scrn_cache_chars1, *scrn_cache_attrs1;

    // free old store, create new one
    if (scrn_store_chars != NULL)  free (scrn_store_chars);
    if (scrn_store_attrs != NULL)  free (scrn_store_attrs);
    scrn_store_chars = malloc (rows*cols);
    scrn_store_attrs = malloc (rows*cols);

    // allocate new backing store buffers
    scrn_cache_chars1 = malloc (rows*cols);
    scrn_cache_attrs1 = malloc (rows*cols);
    memset (scrn_cache_chars1, ' ', rows*cols);
    memset (scrn_cache_attrs1, fl_clr.background, rows*cols);
    if (scrn_cache_chars != NULL && scrn_cache_attrs != NULL)
    {
        for (row=0; row < min1(ROWS,rows); row++)
        {
            memcpy (scrn_cache_chars1+row*cols, scrn_cache_chars+row*COLS, min1(cols, COLS));
            memcpy (scrn_cache_attrs1+row*cols, scrn_cache_attrs+row*COLS, min1(cols, COLS));
        }
        free (scrn_cache_chars);
        free (scrn_cache_attrs);
        CURSOR_ROW = min1 (rows-1, CURSOR_ROW);
        CURSOR_COL = min1 (cols-1, CURSOR_COL);
    }
    else
    {
        CURSOR_ROW = 0;
        CURSOR_COL = 0;
    }
    scrn_cache_chars = scrn_cache_chars1;
    scrn_cache_attrs = scrn_cache_attrs1;
    
    // bring the screen to the initial state
    ROWS = rows;
    COLS = cols;
    set_cursor (cursor_store);
    
    video_update (1);
}
Beispiel #16
0
static double higgspotent_(void)
{ int i,j;
  double ee,sw,cw,lmax;
  double MZ,alfEMZ,tb,At,Ab;
  char name[10]; 

  MZ=findValW("MZ");
  alfEMZ=findValW("alfEMZ");
  At=findValW("At");
  Ab=findValW("Ab");
  tb=findValW("tb");
  
  for(i=1;i<=2;i++) for(j=1;j<=2;j++) 
  { sprintf(name,"Pa%d%d",i,j); Pa_[i-1][j-1]=findValW(name);}

  for(i=1;i<=3;i++) for(j=1;j<=3;j++) 
  { sprintf(name,"Zh%d%d",i,j); Zh_[i-1][j-1]=findValW(name);}
  
  for(i=1;i<=5;i++) for(j=1;j<=5;j++) 
  { sprintf(name,"Zn%d%d",i,j); Zn_[i-1][j-1]=findValW(name);}

  extpar.tb      = findValW("tb");
  extpar.Lambda  = findValW("Lambda");
  extpar.Kappa   = findValW("Kappa");
  extpar.aLambda = findValW("aLmbd0");
  
  extpar.vev=findValW("vev");

  ee=sqrt(4*M_PI*alfEMZ);
  sw=sin(asin(extpar.vev*sqrt(2.0)*ee/MZ)/2);
  cw=sqrt(1.0-sw*sw);
  extpar.mw=MZ*cw; 
  extpar.g2=ee*ee/(sw*cw)/(sw*cw)/2; 

  extpar.aLambda=min1(extpar.aLambda-1, extpar.aLambda+1, varAlam);
  varAlam(extpar.aLambda);
  assignValW("mu",extpar.mu);
  assignValW("aLmbda",extpar.aLambda);
  assignValW("aKappa",extpar.aKappa);

  fillNeutralinoMassMatrix();

  for(i=1;i<=5;i++) {sprintf(name,"la%d",i);  assignValW(name, La[i]);}
  for(i=1;i<=2;i++) {sprintf(name,"la%ds",i); assignValW(name,Las[i]);}
  assignValW("lass", Lass);
  lmax=0;
  for(i=0;i<10;i++)
  {  if(lmax<fabs(La[i]))lmax=fabs(La[i]);
     if(lmax<fabs(Las[i]))lmax=fabs(Las[i]);
  }
  if(lmax<fabs(Lass))lmax=fabs(Lass);
  if(nCall>2000) return -1;
  else return lmax;
}
Beispiel #17
0
void Clock::clearDisplay()
{
     Digit hour1(x, y), hour2(x, y+10), min1(x, y+25), min2(x, y+35), sec1(x, y+50), sec2(x, y+60);
     hour1.display(8, false); 
     hour2.display(8, false);
     min1.display(8, false);
     min2.display(8, false); 
     sec1.display(8, false);
     sec2.display(8, false);
     attron(COLOR_PAIR(WHITEONBLACK));
     mvprintw(x+6, y-5, "  ");            //erase PM indicator   
     refresh();
}
Beispiel #18
0
glm::uvec2 Indigo::UIGroup::min_size() const
{
	glm::uvec2 min(0);
	for (OOBase::Vector<OOBase::SharedPtr<UIWidget>,OOBase::ThreadLocalAllocator>::const_iterator i=m_children.begin();i;++i)
	{
		if ((*i)->visible())
		{
			glm::uvec2 min1((*i)->min_size());
			min1 += (*i)->position();
			min = glm::max(min1,min);
		}
	}

	return min;
}
Beispiel #19
0
///
//Checks for collision between two axis aligned bounding box by seeing 
//if they overlap on each axis.
//
//Parameters:
//	aabb1: The first axis aligned bounding box to test
//	aabb2: The second axis aligned bounding box to test
//
//Returns:
//	true if colliding, else false.
bool CheckCollision(const AABB &aabb1, const AABB &aabb2)
{
	//Find the max and min points for each box
	glm::vec3 min1(aabb1.center - (aabb1.dimensions*0.5f));
	glm::vec3 max1(aabb1.center + (aabb1.dimensions*0.5f));
	glm::vec3 min2(aabb2.center - (aabb2.dimensions*0.5f));
	glm::vec3 max2(aabb2.center + (aabb2.dimensions*0.5f));

	//If there is overlap on each axis, we have a collision
	if (max1.x > min2.x && min1.x < max2.x)
		if (max1.y > min2.y && min1.y < max2.y)
			if (max1.z > min2.z && min1.z < max2.z)
				return true;

	return false;
}
int main(int argc, char* argv[])
{
	Mat<float> hwd((float)4,3,1);
	
	BoxShape box( NULL, hwd);
	
	
	Mat<float> pointsB1[8];
	for(int i=8;i--;)	pointsB1[i] = Mat<float>(0.0f,3,1);
	
	//register the position of the 8 points composing b1:
	Mat<float> min1((float)0,3,1);
	Mat<float> max1((float)0,3,1);
	
	min1.set( -box.getHeight()/2.0f, 1,1);
	min1.set( -box.getWidth()/2.0f, 2,1);
	min1.set( -box.getDepth()/2.0f, 3,1);
	max1.set( -min1.get(1,1), 1,1);
	max1.set( -min1.get(2,1), 2,1);
	max1.set( -min1.get(3,1), 3,1);
	
	int col = 0;
	
	for(int pm1=2;pm1--;)
	{
		for(int pm2=2;pm2--;)
		{
			for(int pm3=2;pm3--;)
			{
				pointsB1[col].set( pm1*( min1.get(1,1) ) + (1-pm1)*( max1.get(1,1) ), 1,1);
				pointsB1[col].set( pm2*( min1.get(2,1) ) + (1-pm2)*( max1.get(2,1) ), 2,1);
				pointsB1[col].set( pm3*( min1.get(3,1) ) + (1-pm3)*( max1.get(3,1) ), 3,1);
				
				col++;
			}
		}
	}
	
	
	for(int i=8;i--;)	pointsB1[i].afficher();
	
	
	return 0;
}
Beispiel #21
0
Vec2 CollisionDetector::AABBToAABB(const Rect& rect1, const Rect& rect2) {
	// Prevents false collision if either rects has no width and height
	if ((rect1.GetW() == 0 && rect1.GetH() == 0) ||
		(rect2.GetW() == 0 && rect2.GetH() == 0)) {
		return Vec2(0.0, 0.0); 
	}

	Vec2 min1(rect1.GetX(), rect1.GetY());
	Vec2 max1(rect1.GetX() + rect1.GetW(), rect1.GetY() + rect1.GetH());
	Vec2 min2(rect2.GetX(), rect2.GetY());
	Vec2 max2(rect2.GetX() + rect2.GetW(), rect2.GetY() + rect2.GetH());

	if ((max1.GetX() < min2.GetX()) || (max1.GetY() < min2.GetY())) {
		return Vec2(0.0, 0.0);
	}

	if ((max2.GetX() < min1.GetX()) || (max2.GetY() < min1.GetY())) {
		return Vec2(0.0, 0.0);
	}

	// Potential resolution offsets
	double negX = max1.GetX() - min2.GetX();
	double posX = max2.GetX() - min1.GetX();
	double negY = max1.GetY() - min2.GetY();
	double posY = max2.GetY() - min1.GetY();

	// Returns the component vector that needs the least offset to resolve the collision
	if (negX <= posX && negX <= negY && negX <= posY) {
		return Vec2(-negX, 0.0);
	}
	else if (posX <= negY && posX <= posY) {
		return Vec2(posX, 0.0);
	}
	else if (negY <= posY) {
		return Vec2(0.0, -negY);
	}
	else {
		return Vec2(0.0, posY);
	}

	return Vec2(0.0, 0.0);
}
Beispiel #22
0
int main()
{
    int c,d,i,j;
    scanf("%d%d",&c,&d);
    int max=b[1][1];
    for(i=1;i<=c;i++)
    {
        for(j=1;j<=d;j++)
        {
            b[0][1]=0;
            scanf("%d",&a[i][j]);
            if(a[i][j-1]==a[i-1][j-1]&&a[i-1][j-1]==a[i-1][j])
                b[i][j]=min1(b[i][j-1],b[i-1][j-1],b[i-1][j])+1;
            else
            {
                if(a[i][j-1]!=a[i-1][j-1]||a[i-1][j-1]!=a[i-1][j])
                b[i][j]=1;
            }
            if(b[i][j]>max)
            max=b[i][j];
        }
    }
    printf("%d",max);
}
Beispiel #23
0
/*	Returns a matrix made up with the coordinates of intersecting points in the World frame of b1 that are within b2. If there are none, it returns a zero 3x8 matrix.
*/
Mat<float> testOBBOBB( RigidBody& b1, RigidBody& b2, bool& intersect)
{
	float precision = 1e-3f;
	Mat<float> ret((float)0,3,1);
	bool initialized = false;
	BoxShape& box1 = (BoxShape&)(b1.getShapeReference());
	BoxShape& box2 = (BoxShape&)(b2.getShapeReference());
	
	Mat<float> pointsB1((float)0,3,8);
	//register the position of the 8 points composing b1:
	Mat<float> min1((float)0,3,1);
	Mat<float> max1((float)0,3,1);
	
	min1.set( -box1.getHeight()/2.0f, 1,1);
	min1.set( -box1.getWidth()/2.0f, 2,1);
	min1.set( -box1.getDepth()/2.0f, 3,1);
	max1.set( -min1.get(1,1), 1,1);
	max1.set( -min1.get(2,1), 2,1);
	max1.set( -min1.get(3,1), 3,1);
	
	int col = 1;
	Mat<float> temp(3,1);
	Mat<float> voronoiTemp(3,1);
	
	for(int pm1=2;pm1--;)
	{
		for(int pm2=2;pm2--;)
		{
			for(int pm3=2;pm3--;)
			{
				Mat<float> tempL(3,1);
				tempL.set( pm1*( min1.get(1,1) ) + (1-pm1)*( max1.get(1,1) ), 1,1);
				tempL.set( pm2*( min1.get(2,1) ) + (1-pm2)*( max1.get(2,1) ), 2,1);
				tempL.set( pm3*( min1.get(3,1) ) + (1-pm3)*( max1.get(3,1) ), 3,1);
				
				
				//--------------------
				//let us compute its coordinate in the world frame :
				temp = b1.getPointInWorld( tempL);
#ifdef debug				
				b1.getPose().exp().afficher();
				b2.getPose().exp().afficher();
				tempL.afficher();
				temp.afficher();
#endif
				//----------------------
				//let us find its associated projected point :
				voronoiTemp = closestPointWOfBOXGivenPointW( b2, temp);
				
				//----------------------
				//let us find out if there was an intersection
				// <==> voronoiTemp = temp, because it would means that the projected point is already the closest to b2 for it is within it.
				if( equals(voronoiTemp,temp,precision) )
				{
					//let us refill pointsB1 with it :
					pointsB1.set( temp.get(1,1), 1,col);
					pointsB1.set( temp.get(2,1), 2,col);
					pointsB1.set( temp.get(3,1), 3,col);
					
					if(initialized)
					{
						ret = operatorL( ret, temp);
					}
					else
					{
						initialized = true;
						ret = temp;
					}
					intersect = true;
					
#ifdef debug
std::cout << "COLLISION DETECTOR : midnarrowphase : testOBBOBB : voronoi and temp : " << std::endl;
std::cout << " ids : b1 = " << b1.getID() << " ; b2 = " << b2.getID() << std::endl;
operatorL(voronoiTemp,temp).afficher();
//std::cout << "COLLISION POINTS :" << std::endl;
//ret.afficher();
//tempL.afficher();
#endif				
				}
				else
				{
#ifdef debug
std::cout << "COLLISION DETECTOR : ELSE : midnarrowphase : testOBBOBB : voronoi and temp : " << std::endl;
std::cout << " ids : b1 = " << b1.getID() << " ; b2 = " << b2.getID() << std::endl;
operatorL(voronoiTemp,temp).afficher();
//std::cout << "COLLISION POINTS :" << std::endl;
//ret.afficher();
//tempL.afficher();
#endif
				}
				
				
				col++;
			}
		}
	}
	
	return ret;
}
Beispiel #24
0
/* prepare list for fast lookups */
fastlist_t *prepare_fastlist (char **list)
{
    int i, j, current_category, negation, escaped, first_special;
    fastlist_t *fl;
    char   *p, *p1;

    fl = xmalloc (sizeof(fastlist_t));
    /* count total number of rules. we add fictitios rule at the start
     to avoid having rule #0 which is bad for routines which use
     signed integers to indicate positive/negative matches */
    for (i=0; list[i] != NULL; i++)
        ;
    fl->n = i+1;
    fl->ncats = 0;
    fl->rules = xmalloc (sizeof(catrule_t) * fl->n);

    fl->rules[0].type     = RULETYPE_SEPARATOR;
    fl->rules[0].category = 0;
    fl->rules[0].rule = NULL;
    fl->rules[0].len = 0;

    /* process every rule: assign type, possibly convert */
    current_category = 0;
    for (i=1; i<fl->n; i++)
    {
        /* shifted because we inserted one rule! */
        p = list[i-1];

        /* check for separator */
        if (p[0] == '+')
        {
            p++;
            p1 = strchr (p, ' ');
            if (p1 != NULL) *p1 = '\0';
            current_category = atoi (p);
            if (current_category != 0) fl->ncats++;
            if (p1 != NULL) *p1 = ' ';
            fl->rules[i].type = RULETYPE_SEPARATOR;
            fl->rules[i].category = 0;
            fl->rules[i].rule = NULL;
            fl->rules[i].len = 0;
            continue;
        }

        /* check for subcategories list */
        if (p[0] == ':')
        {
            fl->rules[i].type = RULETYPE_SUBCATS;
            fl->rules[i].rule = strdup (p+1);
            fl->rules[i].category = current_category;
            continue;
        }

        /* check for negation */
        if (p[0] == '^')
        {
            p++;
            negation = TRUE;
        }
        else
            negation = FALSE;

        /* if rule does not contain slashes at all, append one at the
         end */
        if (strchr (p, '/') == NULL)
        {
            p = str_join (p, "/*");
        }

        /* see if this rule is simple, exact or complex: lookup
         special chars *, ?, [ */
        escaped = FALSE;
        first_special = -1;
        for (j=0; p[j] != '\0'; j++)
        {
            switch (p[j])
            {
            case '\\':
                if (!escaped) escaped = TRUE;
                break;

            case '?':
            case '*':
            case '[':
                if (!escaped) first_special = j;
                else          escaped = FALSE;
                break;

            default:
                if (escaped) escaped = FALSE;
            }
            if (first_special != -1) break;
        }

        /* no special chars at all? */
        if (first_special == -1)
        {
            if (negation)
                fl->rules[i].type = RULETYPE_MATCH_NEG;
            else
                fl->rules[i].type = RULETYPE_MATCH;
            fl->rules[i].rule = strdup (p);
            kill_escapes (fl->rules[i].rule);
        }
        /* simple rule? (just asterisk at the end) */
        else if (p[first_special] == '*' && p[first_special+1] == '\0')
        {
            if (negation)
                fl->rules[i].type = RULETYPE_SIMPLE_NEG;
            else
                fl->rules[i].type = RULETYPE_SIMPLE;
            fl->rules[i].rule = strdup (p);
            fl->rules[i].rule[first_special] = '\0';
            kill_escapes (fl->rules[i].rule);
        }
        /* everything else is complex */
        else
        {
            if (negation)
                fl->rules[i].type = RULETYPE_COMPLEX_NEG;
            else
                fl->rules[i].type = RULETYPE_COMPLEX;
            fl->rules[i].rule = strdup (p);
        }
        fl->rules[i].category = current_category;
        fl->rules[i].len = strlen (fl->rules[i].rule);
    }

    /* build a sorted list of simple and exact rules. find out
     the shortest rule among them */
    fl->n_simple = 0;
    fl->n_complex = 0;
    for (i=0; i<fl->n; i++)
    {
        if (fl->rules[i].type == RULETYPE_MATCH ||
            fl->rules[i].type == RULETYPE_SIMPLE ||
            fl->rules[i].type == RULETYPE_MATCH_NEG ||
            fl->rules[i].type == RULETYPE_SIMPLE_NEG)
            fl->n_simple++;
        else if (fl->rules[i].type == RULETYPE_COMPLEX ||
            fl->rules[i].type == RULETYPE_COMPLEX_NEG)
            fl->n_complex++;
    }

    if (fl->n_simple > 0)
        fl->simple = xmalloc (sizeof(int) * fl->n_simple);
    if (fl->n_complex > 0)
        fl->complex = xmalloc (sizeof(int) * fl->n_complex);
    fl->n_simple = 0;
    fl->n_complex = 0;
    fl->shortest = 10000000;
    /* j = 0; */
    for (i=0; i<fl->n; i++)
    {
        if (fl->rules[i].type == RULETYPE_MATCH ||
            fl->rules[i].type == RULETYPE_SIMPLE ||
            fl->rules[i].type == RULETYPE_MATCH_NEG ||
            fl->rules[i].type == RULETYPE_SIMPLE_NEG)
        {
            fl->shortest = min1 (fl->shortest, strlen(fl->rules[i].rule));
            fl->simple[fl->n_simple++] = i;
        }
        else if (fl->rules[i].type == RULETYPE_COMPLEX ||
                 fl->rules[i].type == RULETYPE_COMPLEX_NEG)
        {
            fl->complex[fl->n_complex++] = i;
        }
        /* if (fl->rules[i].type == RULETYPE_SEPARATOR) j = i+1; */
    }
    fl1 = fl;
    qsort (fl->simple, fl->n_simple, sizeof(int), cmp_simple);

    return fl;
}
Beispiel #25
0
///
//Performs a dynamic collision check between a moving AABB and a static AABB.
//
//Overview:
//	This algorithm detects potentially missed collisions by performing a moving version of the 
//	separating axis test. First we must determine the distances along each axis signifying
//	the distance to begin collision (dFirst) & the distance to separate from that collision (dLast). Then
//	we can easily determine the time at which these distances will be reached by dividing them by the magnitude of the
//	velocity along the axis (tFirst / tLast). If we keep the largest tFirst and the smallest tLast from all axes,
//	we will determine the time interval which the boxes will be intersecting! If tLast < tFirst, the boxes will not overlap.
//	Alternatively, if tFirst > 1.0f,  the boxes will not overlap!
//
//Parameters:
//	aabb1: The moving aabb
//	aabb2: The static aabb
//	mvmt: The relative movement vector of box 1 from an observer on box 2
//
//Returns:
//	a t value between 0 and 1 indicating the "relative time" since the start of this frame that the collision occurred.
//	a t value of 0.0f would indicate the very start of this frame, a t value of 1.0f would indicate the very end of this frame.
float CheckDynamicCollision(const AABB &aabb1, const AABB &aabb2, const glm::vec3 &mvmt)
{
	//If we start out colliding, we do not need to perform the test.
	if (CheckCollision(aabb1, aabb2))
	{
		return 0.0f;
	}

	float tFirst = 0.0f;
	float tLast = 1.0f;
	float tCurrent = 0.0f;

	//Get the minimum and maximum dimensions in world space for each box
	glm::vec2 min1(aabb1.center - (aabb1.dimensions*0.5f));
	glm::vec2 max1(aabb1.center + (aabb1.dimensions*0.5f));
	glm::vec2 min2(aabb2.center - (aabb2.dimensions*0.5f));
	glm::vec2 max2(aabb2.center + (aabb2.dimensions*0.5f));

	//For every axis (X, and Y axes in this case)
	for (int i = 0; i < 3; i++)
	{
		//Check the direction of the projection of the movement vector on this axis
		if (mvmt[i] < 0.0f)
		{
			//In this case object 1 is moving in the negative direction along axis from an observer on object 2.
			//So if object 1 is more negative in direction than object 2, they will not collide on this axis.
			if (max1[i] < min2[i]) return -1.0f;
			//Is the "low part" object 1 higher than the "high part" object 2 along this axis?
			if (min1[i] > max2[i])
			{
				//If so, the shapes are not yet colliding on this axis, so determine when they first will collide on this axis
				tCurrent = (max2[i] - min1[i]) / mvmt[i];		//We solve for a negative distance here, because we are dividing by a negative velocity to get a positive time
				//This strange ordering prevents us from needing to make a call to fabs (absolute value function)
				//If it is larger than the current tFirst, change tFirst
				if (tCurrent > tFirst) tFirst = tCurrent;
			}
			//Is the "High Part" of object 1 higher than the low part of object 2 along this axis?
			if (max1[i] > min2[i])
			{
				//If so, the shapes have not yet separated on this axis, so determine when they will finish colliding
				tCurrent = (min2[i] - max1[i]) / mvmt[i];		//Note the wierd ordering again, for the same reason as above
				//If it is smaller than current tLast, update tLast
				if (tCurrent < tLast) tLast = tCurrent;
			}
		}
		else if (mvmt[i] > 0.0f)
		{
			//If object 1 is more positive along the axis than object 2, they will not collide
			if (min1[i] > max2[i]) return -1.0f;
			//Is the "High part" of object 1 lower than the "low part" of object 2 along this axis?
			if (max1[i] < min2[i])
			{
				//If so, the shapes are not yet colliding on this axis so determine when they will first collide on this axis
				tCurrent = (min2[i] - max1[i]) / mvmt[i];
				//If it is larger than the current tFirst, update tFirst
				if (tCurrent > tFirst) tFirst = tCurrent;
			}
			//Is the "Low part" of object 1 lower than the "high part" of object 2 along this axis?
			if (min1[i] < max2[i])
			{
				//If so, the shapes have not yet separated on this axis, so determine when they will finish collidiing
				tCurrent = (max2[i] - min1[i]) / mvmt[i];
				//If it is smaller than the current tLast, update tLast
				if (tCurrent < tLast) tLast = tCurrent;
			}
		}
	}

	//If there was no overlap
	if (tLast < tFirst) return -1.0f;

	return tFirst;

}
Beispiel #26
0
std::array<unsigned long,vcp<4,1,1>::element_count()> const vcp<4,1,1>::generate_vector( const_vertex_iterator v1, const_vertex_iterator v2 ) {
	std::array<unsigned long,element_count()> counts = {{0}};
	
	std::size_t v1v2( V1V2 * OUT * g.out_edge_exists( v1, v2 ) + V1V2 * IN * g.in_edge_exists( v1, v2 ) );
	
	unsigned long connections( 0 );
	unsigned long amutuals( 0 );
	unsigned long gaps( 0 );
	
	// compose ordered list of v3 candidates
	const_edge_iterator v1_out_neighbors_it( g.out_neighbors_begin( v1 ) );
	const_edge_iterator v1_out_neighbors_end( g.out_neighbors_end( v1 ) );
	const_edge_iterator v1_in_neighbors_it( g.in_neighbors_begin( v1 ) );
	const_edge_iterator v1_in_neighbors_end( g.in_neighbors_end( v1 ) );
	const_edge_iterator v2_out_neighbors_it( g.out_neighbors_begin( v2 ) );
	const_edge_iterator v2_out_neighbors_end( g.out_neighbors_end( v2 ) );
	const_edge_iterator v2_in_neighbors_it( g.in_neighbors_begin( v2 ) );
	const_edge_iterator v2_in_neighbors_end( g.in_neighbors_end( v2 ) );
	assert( MAX_NEIGHBORS > (v1_out_neighbors_end-v1_out_neighbors_it)+(v1_in_neighbors_end-v1_in_neighbors_it)+(v2_out_neighbors_end-v2_out_neighbors_it)+(v2_in_neighbors_end-v2_in_neighbors_it) );
	std::pair<const_vertex_iterator,unsigned short>* v3Vertices_begin( &v3Vertices[0] );
	std::pair<const_vertex_iterator,unsigned short>* v3Vertices_end( &v3Vertices[0] );
	std::pair<const_edge_iterator,directedness_value> min1( next_union_element( v1_out_neighbors_it, v1_out_neighbors_end, v1_in_neighbors_it, v1_in_neighbors_end ) );
	std::pair<const_edge_iterator,directedness_value> min2( next_union_element( v2_out_neighbors_it, v2_out_neighbors_end, v2_in_neighbors_it, v2_in_neighbors_end ) );
	while( min1.first != v1_in_neighbors_end && min2.first != v2_in_neighbors_end ) {
		if( g.target_of( min1.first ) < g.target_of( min2.first ) ) {
			if( g.target_of( min1.first ) != v2 ) {
				++connections;
				++gaps;
				if( min1.second < 3 ) {
					++amutuals;
				}
				v3Vertices_end->first = g.target_of( min1.first );
				v3Vertices_end->second = v1v2 + V1V3 * min1.second;
				++v3Vertices_end;
			}
			min1 = next_union_element( v1_out_neighbors_it, v1_out_neighbors_end, v1_in_neighbors_it, v1_in_neighbors_end );
		} else if( g.target_of( min1.first ) > g.target_of( min2.first ) ) {
			if( g.target_of( min2.first ) != v1 ) {
				++connections;
				++gaps;
				if( min2.second < 3 ) {
					++amutuals;
				}
				v3Vertices_end->first = g.target_of( min2.first );
				v3Vertices_end->second = v1v2 + V2V3 * min2.second;
				++v3Vertices_end;
			}
			min2 = next_union_element( v2_out_neighbors_it, v2_out_neighbors_end, v2_in_neighbors_it, v2_in_neighbors_end );
		} else { // the next neighbor is shared by both v1 and v2, so it cannot be either and we do not need to check to exclude it
			connections += 2;
			if( min1.second < 3 ) {
				++amutuals;
			}
			if( min2.second < 3 ) {
				++amutuals;
			}
		 	v3Vertices_end->first = g.target_of( min1.first );
		 	v3Vertices_end->second = v1v2 + V1V3 * min1.second + V2V3 * min2.second;
			++v3Vertices_end;
			min1 = next_union_element( v1_out_neighbors_it, v1_out_neighbors_end, v1_in_neighbors_it, v1_in_neighbors_end );
			min2 = next_union_element( v2_out_neighbors_it, v2_out_neighbors_end, v2_in_neighbors_it, v2_in_neighbors_end );
		}
	}
	while( min1.first != v1_in_neighbors_end ) {
		if( g.target_of( min1.first ) != v2 ) {
			++connections;
			++gaps;
			if( min1.second < 3 ) {
				++amutuals;
			}
			v3Vertices_end->first = g.target_of( min1.first );
			v3Vertices_end->second = v1v2 + V1V3 * min1.second;
			++v3Vertices_end;
		}
		min1 = next_union_element( v1_out_neighbors_it, v1_out_neighbors_end, v1_in_neighbors_it, v1_in_neighbors_end );
	}
	while( min2.first != v2_in_neighbors_end ) {
		if( g.target_of( min2.first ) != v1 ) {
			++connections;
			++gaps;
			if( min2.second < 3 ) {
				++amutuals;
			}
			v3Vertices_end->first = g.target_of( min2.first );
			v3Vertices_end->second = v1v2 + V2V3 * min2.second;
			++v3Vertices_end;
		}
		min2 = next_union_element( v2_out_neighbors_it, v2_out_neighbors_end, v2_in_neighbors_it, v2_in_neighbors_end );
	}

	unsigned long v3_count( v3Vertices_end-v3Vertices_begin );
	unsigned long v4_count( 0 );
	for( std::pair<const_vertex_iterator,unsigned short>* it1( v3Vertices_begin ); it1 != v3Vertices_end; ++it1 ) { // for each v3 vertex computed above
		const_edge_iterator v3_out_neighbors_it( g.out_neighbors_begin( it1->first ) );
		const_edge_iterator v3_out_neighbors_end( g.out_neighbors_end( it1->first ) );
		const_edge_iterator v3_in_neighbors_it( g.in_neighbors_begin( it1->first ) );
		const_edge_iterator v3_in_neighbors_end( g.in_neighbors_end( it1->first ) );
		unsigned long v4_local_count( 0 ); // keep track of how many v4 vertices are only the result of the neighbors of this v3
		std::pair<const_edge_iterator,directedness_value> min( next_union_element( v3_out_neighbors_it, v3_out_neighbors_end, v3_in_neighbors_it, v3_in_neighbors_end ) );
		for( std::pair<const_vertex_iterator,unsigned short>* it2( v3Vertices_begin ); it2 != v3Vertices_end; ++it2 ) {	
			while( min.first != v3_in_neighbors_end && g.target_of( min.first ) < it2->first ) {
				if( g.target_of( min.first ) != v1 && g.target_of( min.first ) != v2 ) {
					++v4_local_count;
					if( min.second < 3 ) {
						++amutuals;
					}
					++counts[ element_address( it1->second + V3V4 * min.second ) ];
				}
				min = next_union_element( v3_out_neighbors_it, v3_out_neighbors_end, v3_in_neighbors_it, v3_in_neighbors_end );
			}
			if( min.first == v3_in_neighbors_end || g.target_of( min.first ) > it2->first ) {
				if( it1->first < it2->first ) {
					unsigned short temp( it2->second - v1v2 );
					std::size_t contrib( 0 );
					contrib += V1V4 * (temp % V2V3);
					contrib += V2V4 * (temp / V2V3);
					++gaps;
					++counts[ element_address( it1->second + contrib ) ];
				}
			} else {
				if( it1->first < it2->first ) {
					unsigned short temp( it2->second - v1v2 );
					std::size_t contrib( 0 );
					contrib += V1V4 * (temp % V2V3);
					contrib += V2V4 * (temp / V2V3);
					++connections;
					if( min.second < 3 ) {
						++amutuals;
					}
					++counts[ element_address( it1->second + contrib + V3V4 * min.second  ) ];
				}
				min = next_union_element( v3_out_neighbors_it, v3_out_neighbors_end, v3_in_neighbors_it, v3_in_neighbors_end );
			}
		}
		while( min.first != v3_in_neighbors_end ) {
			if( g.target_of( min.first ) != v1 && g.target_of( min.first ) != v2 ) {
				++v4_local_count;
				if( min.second < 3 ) {
					++amutuals;
				}
				++counts[ element_address( it1->second + V3V4 * min.second ) ];
			}
			min = next_union_element( v3_out_neighbors_it, v3_out_neighbors_end, v3_in_neighbors_it, v3_in_neighbors_end );
		}
		v4_count += v4_local_count;
		connections += v4_local_count;
		gaps += 2*v4_local_count;
		counts[ element_address( it1->second ) ] += g.vertex_count() - 2 - v3_count - v4_local_count;
	}
		
	// account for the least connected substructures
	counts[ element_address( v1v2+OUT*V3V4) ] = this->amutualPairs - (amutuals + static_cast<bool>(v1v2)); // out and in versions are isomorphically equivalent and do not need to be counted separately
	counts[ element_address( v1v2+BOTH*V3V4 ) ] = this->mutualPairs - (connections - amutuals);
	counts[ element_address( v1v2 ) ] = unconnected_pairs - (gaps + !static_cast<bool>(v1v2)) - (2 + v3_count) * (g.vertex_count() - 2 - v3_count) + 3 * v4_count;
	
	return counts;
}
Beispiel #27
0
int IL_resample_interp_segments_2d(struct interp_params *params, struct BM *bitmask,	/* bitmask */
				   double zmin, double zmax,	/* min and max input z-values */
				   double *zminac, double *zmaxac,	/* min and max interp. z-values */
				   double *gmin, double *gmax,	/* min and max inperp. slope val. */
				   double *c1min, double *c1max, double *c2min, double *c2max,	/* min and max interp. curv. val. */
				   double *ertot,	/* total interplating func. error */
				   off_t offset1,	/* offset for temp file writing */
				   double *dnorm,
				   int overlap,
				   int inp_rows,
				   int inp_cols,
				   int fdsmooth,
				   int fdinp,
				   double ns_res,
				   double ew_res,
				   double inp_ns_res,
				   double inp_ew_res, int dtens)
{

    int i, j, k, l, m, m1, i1;	/* loop coounters */
    int cursegm = 0;
    int new_comp = 0;
    int n_rows, n_cols, inp_r, inp_c;
    double x_or, y_or, xm, ym;
    static int first = 1, new_first = 1;
    double **matrix = NULL, **new_matrix = NULL, *b = NULL;
    int *indx = NULL, *new_indx = NULL;
    static struct fcell_triple *in_points = NULL;	/* input points */
    int inp_check_rows, inp_check_cols,	/* total input rows/cols */
      out_check_rows, out_check_cols;	/* total output rows/cols */
    int first_row, last_row;	/* first and last input row of segment */
    int first_col, last_col;	/* first and last input col of segment */
    int num, prev;
    int div;			/* number of divides */
    int rem_out_row, rem_out_col;	/* output rows/cols remainders */
    int inp_seg_r, inp_seg_c,	/* # of input rows/cols in segment */
      out_seg_r, out_seg_c;	/* # of output rows/cols in segment */
    int ngstc, nszc		/* first and last output col of the
				 * segment */
     , ngstr, nszr;		/* first and last output row of the
				 * segment */
    int index;			/* index for input data */
    int c, r;
    int overlap1;
    int p_size;
    struct quaddata *data;
    double xmax, xmin, ymax, ymin;
    int totsegm;		/* total number of segments */
    int total_points = 0;
    struct triple triple;	/* contains garbage */


    xmin = params->x_orig;
    ymin = params->y_orig;
    xmax = xmin + ew_res * params->nsizc;
    ymax = ymin + ns_res * params->nsizr;
    prev = inp_rows * inp_cols;
    if (prev <= params->kmax)
	div = 1;		/* no segmentation */

    else {			/* find the number of divides */
	for (i = 2;; i++) {
	    c = inp_cols / i;
	    r = inp_rows / i;
	    num = c * r;
	    if (num < params->kmin) {
		if (((params->kmin - num) > (prev + 1 - params->kmax)) &&
		    (prev + 1 < params->KMAX2)) {
		    div = i - 1;
		    break;
		}
		else {
		    div = i;
		    break;
		}
	    }
	    if ((num > params->kmin) && (num + 1 < params->kmax)) {
		div = i;
		break;
	    }
	    prev = num;
	}
    }
    out_seg_r = params->nsizr / div;	/* output rows per segment */
    out_seg_c = params->nsizc / div;	/* output cols per segment */
    inp_seg_r = inp_rows / div;	/* input rows per segment */
    inp_seg_c = inp_cols / div;	/* input rows per segment */
    rem_out_col = params->nsizc % div;
    rem_out_row = params->nsizr % div;
    overlap1 = min1(overlap, inp_seg_c - 1);
    overlap1 = min1(overlap1, inp_seg_r - 1);
    out_check_rows = 0;
    out_check_cols = 0;
    inp_check_rows = 0;
    inp_check_cols = 0;

    if (div == 1) {
	p_size = inp_seg_c * inp_seg_r;
    }
    else {
	p_size = (overlap1 * 2 + inp_seg_c) * (overlap1 * 2 + inp_seg_r);
    }
    if (!in_points) {
	if (!
	    (in_points =
	     (struct fcell_triple *)G_malloc(sizeof(struct fcell_triple) *
					     p_size * div))) {
	    fprintf(stderr, "Cannot allocate memory for in_points\n");
	    return -1;
	}
    }

    *dnorm =
	sqrt(((xmax - xmin) * (ymax -
			       ymin) * p_size) / (inp_rows * inp_cols));

    if (dtens) {
	params->fi = params->fi * (*dnorm) / 1000.;
	fprintf(stderr, "dnorm = %f, rescaled tension = %f\n", *dnorm,
		params->fi);
    }

    if (div == 1) {		/* no segmentation */
	totsegm = 1;
	cursegm = 1;

	input_data(params, 1, inp_rows, in_points, fdsmooth, fdinp, inp_rows,
		   inp_cols, zmin, inp_ns_res, inp_ew_res);

	x_or = 0.;
	y_or = 0.;
	xm = params->nsizc * ew_res;
	ym = params->nsizr * ns_res;

	data = (struct quaddata *)quad_data_new(x_or, y_or, xm, ym,
						params->nsizr, params->nsizc,
						0, params->KMAX2);
	m1 = 0;
	for (k = 1; k <= p_size; k++) {
	    if (!Rast_is_f_null_value(&(in_points[k - 1].z))) {
		data->points[m1].x = in_points[k - 1].x / (*dnorm);
		data->points[m1].y = in_points[k - 1].y / (*dnorm);
		/*        data->points[m1].z = (double) (in_points[k - 1].z) / (*dnorm); */
		data->points[m1].z = (double)(in_points[k - 1].z);
		data->points[m1].sm = in_points[k - 1].smooth;
		m1++;
	    }
	}
	data->n_points = m1;
	total_points = m1;
	if (!(indx = G_alloc_ivector(params->KMAX2 + 1))) {
	    fprintf(stderr, "Cannot allocate memory for indx\n");
	    return -1;
	}
	if (!(matrix = G_alloc_matrix(params->KMAX2 + 1, params->KMAX2 + 1))) {
	    fprintf(stderr, "Cannot allocate memory for matrix\n");
	    return -1;
	}
	if (!(b = G_alloc_vector(params->KMAX2 + 2))) {
	    fprintf(stderr, "Cannot allocate memory for b\n");
	    return -1;
	}

	if (params->matrix_create(params, data->points, m1, matrix, indx) < 0)
	    return -1;
	for (i = 0; i < m1; i++) {
	    b[i + 1] = data->points[i].z;
	}
	b[0] = 0.;
	G_lubksb(matrix, m1 + 1, indx, b);

	params->check_points(params, data, b, ertot, zmin, *dnorm, triple);

	if (params->grid_calc(params, data, bitmask,
			      zmin, zmax, zminac, zmaxac, gmin, gmax,
			      c1min, c1max, c2min, c2max, ertot, b, offset1,
			      *dnorm) < 0) {
	    fprintf(stderr, "interpolation failed\n");
	    return -1;
	}
	else {
	    if (totsegm != 0) {
		G_percent(cursegm, totsegm, 1);
	    }
	    /*
	     * if (b) G_free_vector(b); if (matrix) G_free_matrix(matrix); if
	     * (indx) G_free_ivector(indx);
	     */
	    fprintf(stderr, "dnorm in ressegm after grid before out= %f \n",
		    *dnorm);
	    return total_points;
	}
    }

    out_seg_r = params->nsizr / div;	/* output rows per segment */
    out_seg_c = params->nsizc / div;	/* output cols per segment */
    inp_seg_r = inp_rows / div;	/* input rows per segment */
    inp_seg_c = inp_cols / div;	/* input rows per segment */
    rem_out_col = params->nsizc % div;
    rem_out_row = params->nsizr % div;
    overlap1 = min1(overlap, inp_seg_c - 1);
    overlap1 = min1(overlap1, inp_seg_r - 1);
    out_check_rows = 0;
    out_check_cols = 0;
    inp_check_rows = 0;
    inp_check_cols = 0;

    totsegm = div * div;

    /* set up a segment */
    for (i = 1; i <= div; i++) {	/* input and output rows */
	if (i <= div - rem_out_row)
	    n_rows = out_seg_r;
	else
	    n_rows = out_seg_r + 1;
	inp_r = inp_seg_r;
	out_check_cols = 0;
	inp_check_cols = 0;
	ngstr = out_check_rows + 1;	/* first output row of the segment */
	nszr = ngstr + n_rows - 1;	/* last output row of the segment */
	y_or = (ngstr - 1) * ns_res;	/* y origin of the segment */
	/*
	 * Calculating input starting and ending rows and columns of this
	 * segment
	 */
	first_row = (int)(y_or / inp_ns_res) + 1;
	if (first_row > overlap1) {
	    first_row -= overlap1;	/* middle */
	    last_row = first_row + inp_seg_r + overlap1 * 2 - 1;
	    if (last_row > inp_rows) {
		first_row -= (last_row - inp_rows);	/* bottom */
		last_row = inp_rows;
	    }
	}
	else {
	    first_row = 1;	/* top */
	    last_row = first_row + inp_seg_r + overlap1 * 2 - 1;
	}
	if ((last_row > inp_rows) || (first_row < 1)) {
	    fprintf(stderr, "Row overlap too large!\n");
	    return -1;
	}
	input_data(params, first_row, last_row, in_points, fdsmooth, fdinp,
		   inp_rows, inp_cols, zmin, inp_ns_res, inp_ew_res);

	for (j = 1; j <= div; j++) {	/* input and output cols */
	    if (j <= div - rem_out_col)
		n_cols = out_seg_c;
	    else
		n_cols = out_seg_c + 1;
	    inp_c = inp_seg_c;

	    ngstc = out_check_cols + 1;	/* first output col of the segment */
	    nszc = ngstc + n_cols - 1;	/* last output col of the segment */
	    x_or = (ngstc - 1) * ew_res;	/* x origin of the segment */

	    first_col = (int)(x_or / inp_ew_res) + 1;
	    if (first_col > overlap1) {
		first_col -= overlap1;	/* middle */
		last_col = first_col + inp_seg_c + overlap1 * 2 - 1;
		if (last_col > inp_cols) {
		    first_col -= (last_col - inp_cols);	/* right */
		    last_col = inp_cols;
		}
	    }
	    else {
		first_col = 1;	/* left */
		last_col = first_col + inp_seg_c + overlap1 * 2 - 1;
	    }
	    if ((last_col > inp_cols) || (first_col < 1)) {
		fprintf(stderr, "Column overlap too large!\n");
		return -1;
	    }
	    m = 0;
	    /* Getting points for interpolation (translated) */

	    xm = nszc * ew_res;
	    ym = nszr * ns_res;
	    data = (struct quaddata *)quad_data_new(x_or, y_or, xm, ym,
						    nszr - ngstr + 1,
						    nszc - ngstc + 1, 0,
						    params->KMAX2);
	    new_comp = 0;

	    for (k = 0; k <= last_row - first_row; k++) {
		for (l = first_col - 1; l < last_col; l++) {
		    index = k * inp_cols + l;
		    if (!Rast_is_f_null_value(&(in_points[index].z))) {
			/* if the point is inside the segment (not overlapping) */
			if ((in_points[index].x - x_or >= 0) &&
			    (in_points[index].y - y_or >= 0) &&
			    ((nszc - 1) * ew_res - in_points[index].x >= 0) &&
			    ((nszr - 1) * ns_res - in_points[index].y >= 0))
			    total_points += 1;
			data->points[m].x =
			    (in_points[index].x - x_or) / (*dnorm);
			data->points[m].y =
			    (in_points[index].y - y_or) / (*dnorm);
			/*            data->points[m].z = (double) (in_points[index].z) / (*dnorm); */
			data->points[m].z = (double)(in_points[index].z);
			data->points[m].sm = in_points[index].smooth;
			m++;
		    }
		    else
			new_comp = 1;

		    /*          fprintf(stderr,"%f,%f,%f
		       zmin=%f\n",in_points[index].x,in_points[index].y,in_points[index].z,zmin);
		     */
		}
	    }
	    /*      fprintf (stdout,"m,index:%di,%d\n",m,index); */
	    if (m <= params->KMAX2)
		data->n_points = m;
	    else
		data->n_points = params->KMAX2;
	    out_check_cols += n_cols;
	    inp_check_cols += inp_c;
	    cursegm = (i - 1) * div + j - 1;

	    /* show before to catch 0% */
	    if (totsegm != 0) {
		G_percent(cursegm, totsegm, 1);
	    }
	    if (m == 0) {
		/*
		 * fprintf(stderr,"Warning: segment with zero points encountered,
		 * insrease overlap\n");
		 */
		write_zeros(params, data, offset1);
	    }
	    else {
		if (new_comp) {
		    if (new_first) {
			new_first = 0;
			if (!b) {
			    if (!(b = G_alloc_vector(params->KMAX2 + 2))) {
				fprintf(stderr,
					"Cannot allocate memory for b\n");
				return -1;
			    }
			}
			if (!(new_indx = G_alloc_ivector(params->KMAX2 + 1))) {
			    fprintf(stderr,
				    "Cannot allocate memory for new_indx\n");
			    return -1;
			}
			if (!
			    (new_matrix =
			     G_alloc_matrix(params->KMAX2 + 1,
					    params->KMAX2 + 1))) {
			    fprintf(stderr,
				    "Cannot allocate memory for new_matrix\n");
			    return -1;
			}
		    }		/*new_first */
		    if (params->
			matrix_create(params, data->points, data->n_points,
				      new_matrix, new_indx) < 0)
			return -1;

		    for (i1 = 0; i1 < m; i1++) {
			b[i1 + 1] = data->points[i1].z;
		    }
		    b[0] = 0.;
		    G_lubksb(new_matrix, data->n_points + 1, new_indx, b);

		    params->check_points(params, data, b, ertot, zmin,
					 *dnorm, triple);

		    if (params->grid_calc(params, data, bitmask,
					  zmin, zmax, zminac, zmaxac, gmin,
					  gmax, c1min, c1max, c2min, c2max,
					  ertot, b, offset1, *dnorm) < 0) {

			fprintf(stderr, "interpolate() failed\n");
			return -1;
		    }
		}		/*new_comp */
		else {
		    if (first) {
			first = 0;
			if (!b) {
			    if (!(b = G_alloc_vector(params->KMAX2 + 2))) {
				fprintf(stderr,
					"Cannot allocate memory for b\n");
				return -1;
			    }
			}
			if (!(indx = G_alloc_ivector(params->KMAX2 + 1))) {
			    fprintf(stderr,
				    "Cannot allocate memory for indx\n");
			    return -1;
			}
			if (!
			    (matrix =
			     G_alloc_matrix(params->KMAX2 + 1,
					    params->KMAX2 + 1))) {
			    fprintf(stderr,
				    "Cannot allocate memory for matrix\n");
			    return -1;
			}
		    }		/* first */
		    if (params->
			matrix_create(params, data->points, data->n_points,
				      matrix, indx) < 0)
			return -1;
		    /*        } here it was bug */
		    for (i1 = 0; i1 < m; i1++)
			b[i1 + 1] = data->points[i1].z;
		    b[0] = 0.;
		    G_lubksb(matrix, data->n_points + 1, indx, b);

		    params->check_points(params, data, b, ertot, zmin,
					 *dnorm, triple);

		    if (params->grid_calc(params, data, bitmask,
					  zmin, zmax, zminac, zmaxac, gmin,
					  gmax, c1min, c1max, c2min, c2max,
					  ertot, b, offset1, *dnorm) < 0) {

			fprintf(stderr, "interpolate() failed\n");
			return -1;
		    }
		}
	    }
	    if (data) {
		G_free(data->points);
		G_free(data);
	    }
	    /*
	     * cursegm++;
	     */
	}

	inp_check_rows += inp_r;
	out_check_rows += n_rows;
    }

    /* run one last time after the loop is done to catch 100% */
    if (totsegm != 0)
	G_percent(1, 1, 1);	/* cursegm doesn't get to totsegm so we force 100% */

    /*
     * if (b) G_free_vector(b); if (indx) G_free_ivector(indx); if (matrix)
     * G_free_matrix(matrix);
     */
    fprintf(stderr, "dnorm in ressegm after grid before out2= %f \n", *dnorm);
    return total_points;
}
int main(int argc, char **argv) {
  MPI_Init(&argc, &argv);

  QUESO::EnvOptionsValues options;
  options.m_numSubEnvironments = 1;
  options.m_subDisplayFileName = "outputData/testIntersectionSubsetContains";
  options.m_subDisplayAllowAll = 0;
  options.m_subDisplayAllowedSet.insert(0);
  options.m_seed = 1.0;
  options.m_checkingLevel = 1;
  options.m_displayVerbosity = 55;

  QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "",
            "", &options);

  std::vector<std::string> names(1);
  names[0] = "my_name";

  // Create a vector space
  QUESO::VectorSpace<QUESO::GslVector, QUESO::GslMatrix> vec_space(*env,
      "vec_prefix", 1, &names);

  // Create two vector sets
  QUESO::GslVector min1(vec_space.zeroVector());
  min1[0] = 0.0;
  QUESO::GslVector max1(vec_space.zeroVector());
  max1[0] = 1.0;
  QUESO::BoxSubset<QUESO::GslVector, QUESO::GslMatrix> set1("set1", vec_space,
      min1, max1);

  // Now for the second one
  QUESO::GslVector min2(vec_space.zeroVector());
  min2[0] = 0.5;
  QUESO::GslVector max2(vec_space.zeroVector());
  max2[0] = 1.5;
  QUESO::BoxSubset<QUESO::GslVector, QUESO::GslMatrix> set2("set1", vec_space,
      min2, max2);

  // Create their intersection
  QUESO::IntersectionSubset<QUESO::GslVector, QUESO::GslMatrix> intersection(
      "intersection", vec_space, 1.0, set1, set2);

  // Test the containment
  bool does_contain;
  QUESO::GslVector test_vec(vec_space.zeroVector());

  // Should be true
  test_vec[0] = 0.75;
  does_contain = intersection.contains(test_vec);
  if (!does_contain) {
    std::cerr << "First IntersectionSubset contains test failed" << std::endl;
    return 1;
  }

  // Should be false
  test_vec[0] = 2.0;
  does_contain = intersection.contains(test_vec);
  if (does_contain) {
    std::cerr << "Second contains test failed" << std::endl;
    return 1;
  }

  // Print out some info
  intersection.print(std::cout);

  MPI_Finalize();

  return 0;
}
Beispiel #29
0
void editor (char *filename, int startpos)
{
    int stop    = FALSE; // exit main loop?
    int fline   = 0;     // no. of first displayed line
    int cline   = 0;     // no. of line with cursor
    int shift   = 0;     // shift to the right
    int ccol    = 0;     // column of the cursor position in the file window

    int        k, i, ndisp, rc, reply;
    char       *p, buf[1024];

    if (editor_open_file (filename) < 0) return;
    cline = min1 (startpos, nl-1);
    fline = max1 (0, cline - video_vsize()/2);

    // enter the loop
    while (1)
    {
        if (stop)
        {
            rc = 0;
            if (changed)
            {
                rc = -1;
                reply = fly_ask (0, "   Save file `%s'?   ", " Yes \n No \n Cancel ", filename);
                if (reply == 1) rc = editor_save_file (filename);
                if (reply == 2) rc = 0;
                if (reply == 3) stop = FALSE;
            }
            if (rc == 0) break;
        }
        
        ndisp = video_vsize()-1;
        // draw the screen
        for (i=0; i<ndisp; i++)
        {
            video_put_n_cell (' ', _BackWhite+_Black, video_hsize(), i, 0);
            if (i+fline < nl)
                editor_display_line (i, fline+i, shift);
        }
        video_put_n_cell (' ', _BackBlue+_White, video_hsize(), video_vsize()-1, 0);
        snprintf1 (buf, sizeof(buf), "L%d:C%d:S%d %c %s%s", cline, ccol, shift, fl_sym.v,
                 changed ? "*" : "", filename);
        video_put (buf, video_vsize()-1, 0);
        video_set_cursor (cline-fline, ccol-shift);
        video_update (0);

        // get a keyboard/mouse event and process it
        k = getmessage (-1);
        if (IS_KEY(k))
        {
            switch (k)
            {
                // Navigation keys
                
            case _Up:
            case _Down:
            case _PgUp:
            case _PgDn:
                fly_scroll_it (k, &fline, &cline, nl, video_vsize()-1);
                break;

            case _Right:
                ccol++;
                if (ccol-shift > video_hsize()-1) shift = ccol-video_hsize()+1;
                break;

            case _Left:
                ccol = max1 (ccol-1, 0);
                if (ccol < shift) shift = ccol;
                break;

            case _Home:
                ccol = 0; shift = 0;
                break;

            case _End:
                ccol = strlen(lines[cline]);
                if (ccol-shift > video_hsize()-1) shift = ccol-video_hsize()+1;
                break;

            case _CtrlHome:
                fline = 0; cline = 0; ccol = 0; shift = 0; break;

            case _CtrlEnd:
                fline = max1 (0, nl-video_vsize()+1);
                cline = min1 (fline+video_vsize()-1, nl-1);
                shift = 0;
                ccol = 0;
                break;

                // Action keys

            case _CtrlY:
                put_clipboard (lines[cline]);
                free (lines[cline]);
                for (i=cline; i<nl-1; i++)
                    lines[i] = lines[i+1];
                nl--;
                changed = TRUE;
                break;

            case _ShiftInsert:
            case _CtrlV:
                p = get_clipboard ();
                if (p == NULL || *p == '\0') break;
                if (nl == na)
                {
                    na *= 2;
                    lines = realloc (lines, sizeof(char *) * na);
                }
                for (i=nl-1; i>cline; i--)
                    lines[i+1] = lines[i];
                lines[cline+1] = p;
                ccol = 0;
                shift = 0;
                cline++;
                if (cline-fline == video_vsize()-1) fline++;
                nl++;
                changed = TRUE;
                break;

            case _BackSpace:
                if (ccol == 0)
                {
                    // ccol == 0: glue this line to the previous
                    if (cline == 0) break;
                    p = malloc (strlen (lines[cline])+strlen(lines[cline-1])+1);
                    strcpy (p, lines[cline-1]);
                    strcat (p, lines[cline]);
                    ccol = strlen (lines[cline-1]);
                    if (ccol-shift > video_hsize()-1) shift = ccol-video_hsize()+1;
                    free (lines[cline-1]);
                    free (lines[cline]);
                    lines[cline-1] = p;
                    for (i=cline; i<nl-1; i++)
                        lines[i] = lines[i+1];
                    cline--;
                    nl--;
                }
                else
                {
                    // ccol != 0: delete char at ccol-1, move cursor left
                    str_delete (lines[cline], lines[cline]+ccol-1);
                    ccol--;
                    if (ccol < shift) shift = ccol;
                }
                changed = TRUE;
                break;

            case _Enter:
                if (nl == na)
                {
                    na *= 2;
                    lines = realloc (lines, sizeof(char *) * na);
                }
                for (i=nl-1; i>cline; i--)
                    lines[i+1] = lines[i];
                if (ccol < strlen (lines[cline]))
                {
                    lines[cline+1] = strdup (lines[cline]+ccol);
                    lines[cline][ccol] = '\0';
                }
                else
                {
                    lines[cline+1] = strdup ("");
                }
                ccol = 0;
                shift = 0;
                cline++;
                if (cline-fline == video_vsize()-1) fline++;
                nl++;
                changed = TRUE;
                break;

            case _Delete:
                if (ccol >= strlen (lines[cline]))
                {
                    // glue previous line to this one
                    if (cline == nl-1) break;
                    p = malloc (ccol+strlen(lines[cline+1])+1);
                    strcpy (p, lines[cline]);
                    memset (p+strlen(lines[cline]), ' ', ccol-strlen(lines[cline]));
                    strcpy (p+ccol, lines[cline+1]);
                    free (lines[cline]);
                    free (lines[cline+1]);
                    lines[cline] = p;
                    for (i=cline+1; i<nl-1; i++)
                        lines[i] = lines[i+1];
                    nl--;
                }
                else
                {
                    // ccol != 0: delete char at ccol-1, move cursor left
                    str_delete (lines[cline], lines[cline]+ccol);
                }
                changed = TRUE;
                break;

            case _F2:
                rc = editor_save_file (filename);
                if (rc == 0) changed = FALSE;
                break;
                
            case _Esc:
            case _F10:
                stop = TRUE; break;

                // character keys
                
            default:
                if (k >= ' ' && k <= 255)
                {
                    str_insert_at (cline, k, ccol);
                    ccol++;
                    changed = TRUE;
                }
            }
        }
        else if (IS_MOUSE(k))
        {
        }
        else if (IS_SYSTEM(k))
        {
            switch (SYS_TYPE(k))
            {
            case SYSTEM_QUIT:
                stop = TRUE; break;
            }
        }
    }

    if (nl != 0 && lines != NULL)
        for (i=0; i<nl; i++)
            free (lines[i]);
    if (na != 0 && lines != NULL) free (lines);
    na = 0;
    lines = NULL;
}
Beispiel #30
0
long CHSDownloadData::GetChangedBeginDate( CodeInfo *pCode,long lBeginDate,int nSpillDays,int nPeriod )
{
	if (nSpillDays <= 0)
	{
		return lBeginDate;
	}

	short nOneDayNums  = 240;
	short nGZIndex = MakeGZIndex(pCode->m_cCodeType);
	short nMainType  = MakeMarket(pCode->m_cCodeType);

	if (nGZIndex)
		nOneDayNums = 270;
	else
		nOneDayNums = 240;

	int nCount = 0,nGapDays =0, nYushu =0;
	CTimeSpan oneDay(1,0,0,0);
	CTime tmbg = GetTimeFromIntTime(lBeginDate,nPeriod);
	long lBeginMinite = lBeginDate%10000;
	switch(nPeriod)
	{
	case PERIOD_TYPE_DAY:
		while(nCount < nSpillDays)
		{
			tmbg += oneDay;
			int nWeekEnd = tmbg.GetDayOfWeek();
			if (nWeekEnd != 1 && nWeekEnd != 7)
			{
				nCount++;
			}
		}
		return GetIntTimeFromTime(tmbg,nPeriod);
	case PERIOD_TYPE_MINUTE1:
	case PERIOD_TYPE_MINUTE5:
		{
			int nIndex = 1,nQiHuoMorningBegin = 900,nQZQihuoMorningBegin = 915,nStockMorningBegin = 930;
			if (nPeriod == PERIOD_TYPE_MINUTE5)
			{
				nIndex = 5;
				nQiHuoMorningBegin = 905;
				nQZQihuoMorningBegin = 920;
				nStockMorningBegin = 935;
			}
			nGapDays = nSpillDays/(nOneDayNums/nIndex);
			nYushu = nSpillDays%(nOneDayNums/nIndex);
			while(nCount < nGapDays)
			{
				tmbg += oneDay;
				int nWeekEnd = tmbg.GetDayOfWeek();
				if (nWeekEnd != 1 && nWeekEnd != 7)
				{
					nCount++;
				}
			}

			CTime tmMoriningEnd;
			CTime tmNewTime;
			long lTmp = 0;
			CTimeSpan  tmTempSpan;
			CTimeSpan min1(0,(nYushu*nIndex)/60,(nYushu*nIndex)%60,0);
			CTime tmTemp = tmbg;
			tmTemp += min1;
			long lNewMini = GetIntTimeFromTime(tmTemp,nPeriod);
			tmNewTime = tmTemp;
			if (lBeginMinite < 1130)
			{	
				long ltailMini = lNewMini%10000;
				if (ltailMini <1130 )
				{
					return  lNewMini;
				}
				else
				{
					if (nMainType == STOCK_MARKET)
					{
						lTmp = (lNewMini/10000) * 10000 + 1300;
					}
					else
					{
						if (!nGZIndex)
							lTmp = (lNewMini/10000) * 10000 + 1330;
						else
							lTmp = (lNewMini/10000) * 10000 + 1300;
					}
					tmNewTime = GetTimeFromIntTime(lTmp,nPeriod);
					tmMoriningEnd = GetTimeFromIntTime((lNewMini/10000) * 10000 + 1130,nPeriod);
					tmTempSpan = tmTemp - tmMoriningEnd;
					tmNewTime += tmTempSpan;
					lNewMini = GetIntTimeFromTime(tmNewTime,nPeriod);
					goto minite1_5;
				}
			}
			else
			{
				goto minite1_5;
			}

minite1_5:
			if (nGZIndex)
			{
				if (lNewMini%10000 <= 1515)
				{
					return lNewMini;
				}
				else
				{
					lTmp = (lNewMini/10000) * 10000 + 1515;
					tmTemp = GetTimeFromIntTime(lTmp,nPeriod);
					tmTempSpan = tmNewTime - tmTemp;

					lNewMini = (lNewMini/10000) * 10000 + nQZQihuoMorningBegin;
					tmTemp =  GetTimeFromIntTime(lNewMini,nPeriod);
					tmTemp += oneDay;
					tmTemp += tmTempSpan;
					lNewMini = GetIntTimeFromTime(tmTemp,nPeriod);
					if (lNewMini%10000 <= 1130)
					{
						return lNewMini;
					}
					tmMoriningEnd = GetTimeFromIntTime((lNewMini/10000) * 10000 + 1130,nPeriod);
					tmTempSpan = tmTemp - tmMoriningEnd;
					lTmp = (lNewMini/10000) * 10000 + 1300;
					tmTemp = GetTimeFromIntTime(lTmp,nPeriod);
					tmTemp += tmTempSpan;
					return  GetIntTimeFromTime(tmTemp,nPeriod);
				}
			}
			else
			{
				if (lNewMini%10000 <= 1500)
				{
					return lNewMini;
				}
				else
				{
					lTmp = (lNewMini/10000) * 10000 + 1500;
					tmTemp = GetTimeFromIntTime(lTmp,nPeriod);
					tmTempSpan = tmNewTime - tmTemp;

					if (nMainType == STOCK_MARKET)						
						lNewMini = (lNewMini/10000) * 10000 + nStockMorningBegin;			
					else
						lNewMini = (lNewMini/10000) * 10000 + nQiHuoMorningBegin;

					tmTemp =  GetTimeFromIntTime(lNewMini,nPeriod);
					tmTemp += oneDay;
					tmTemp += tmTempSpan;
					lNewMini = GetIntTimeFromTime(tmTemp,nPeriod);
					if (lNewMini%10000 <= 1130)
					{
						return lNewMini;
					}
					tmMoriningEnd = GetTimeFromIntTime((lNewMini/10000) * 10000 + 1130,nPeriod);
					tmTempSpan = tmTemp - tmMoriningEnd;
					if (nMainType == STOCK_MARKET)	
						lTmp = (lNewMini/10000) * 10000 + 1300;
					else
						lTmp = (lNewMini/10000) * 10000 + 1330;

					tmTemp = GetTimeFromIntTime(lTmp,nPeriod);
					tmTemp += tmTempSpan;
					return  GetIntTimeFromTime(tmTemp,nPeriod);
				}
			}
		}
		break;
	default:
		return lBeginDate;
	}
}