コード例 #1
0
void LevelSetOperator::IntegrateEuler(float dt)
{
  // Create grid used to store next time step
  LevelSetGrid grid = GetGrid();



  // Iterate over grid and compute the grid values for the next timestep
  LevelSetGrid::Iterator iter = GetGrid().BeginNarrowBand();
  LevelSetGrid::Iterator iend = GetGrid().EndNarrowBand();
  while (iter != iend) {
    unsigned int i = iter.GetI();
    unsigned int j = iter.GetJ();
    unsigned int k = iter.GetK();

    // Compute rate of change
    float ddt = Evaluate(i,j,k);

    // Compute the next time step and store it in the grid
    grid.SetValue(i,j,k, GetGrid().GetValue(i,j,k) + ddt*dt);

    iter++;
  }


  // Update the grid with the next time step
  GetGrid() = grid;
}
コード例 #2
0
void LevelSetOperator::GridLerp(const LevelSetGrid & grid1,const LevelSetGrid & grid2,float factor,LevelSetGrid & gridOut)
{
// Iterate over grid and compute the grid values for the next timestep
	gridOut = grid1;
  LevelSetGrid::Iterator iter = grid1.BeginNarrowBand();
  LevelSetGrid::Iterator iend = grid1.EndNarrowBand();
  while (iter != iend) {
    unsigned int i = iter.GetI();
    unsigned int j = iter.GetJ();
    unsigned int k = iter.GetK();
	
    // Compute the next time step and store it in the grid
    gridOut.SetValue(i,j,k, grid1.GetValue(i,j,k)*factor + grid2.GetValue(i,j,k)*(1.0f-factor));

    iter++;
  }

}
コード例 #3
0
void LevelSetOperator::EulerStep(LevelSetGrid & gridOut,float dt)
{
// Iterate over grid and compute the grid values for the next timestep
	gridOut = GetGrid();
  LevelSetGrid::Iterator iter = GetGrid().BeginNarrowBand();
  LevelSetGrid::Iterator iend = GetGrid().EndNarrowBand();
  while (iter != iend) {
    unsigned int i = iter.GetI();
    unsigned int j = iter.GetJ();
    unsigned int k = iter.GetK();

    // Compute rate of change
    float ddt = Evaluate(i,j,k);

    // Compute the next time step and store it in the grid
    gridOut.SetValue(i,j,k, GetGrid().GetValue(i,j,k) + ddt*dt);

    iter++;
  }

}
コード例 #4
0
void LevelSetOperator::IntegrateRungeKutta(float dt)
{
	/*
		TVD RK
	*/
	/*
	//Spara värdet för n samt beräkna n+1
  LevelSetGrid grid = GetGrid();
  LevelSetGrid gridOldPhi(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
  LevelSetGrid::Iterator iter = GetGrid().BeginNarrowBand();
  LevelSetGrid::Iterator iend = GetGrid().EndNarrowBand();
  while (iter != iend) {
    unsigned int i = iter.GetI();
    unsigned int j = iter.GetJ();
    unsigned int k = iter.GetK();

    // Compute rate of change
    float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
	gridOldPhi.SetValue(i,j,k,GetGrid().GetValue(i,j,k));
	float phi_new = GetGrid().GetValue(i,j,k)  + ddt*dt;
    // Compute the next time step and store it in the grid
    grid.SetValue(i,j,k,phi_new);
    iter++;
  }
  GetGrid() = grid;

  //Beräkna nytt n+1 via n och n+2
  iter = GetGrid().BeginNarrowBand();
  iend = GetGrid().EndNarrowBand();
  while (iter != iend) {
    unsigned int i = iter.GetI();
    unsigned int j = iter.GetJ();
    unsigned int k = iter.GetK();

    // Compute rate of change
    float ddt = Evaluate(i,j,k); //Beräkna derivatan i n+1

	float old_phi = gridOldPhi.GetValue(i,j,k);
	float phi_new = 0.5*(old_phi +  (GetGrid().GetValue(i,j,k) + ddt*dt));//0.5(n + (n+2)) = n+1
    // Compute the next time step and store it in the grid
    grid.SetValue(i,j,k,phi_new);
    iter++;
  }
  GetGrid() = grid;*/
	/*
	//K1
	LevelSetGrid grid = GetGrid();
	LevelSetGrid y(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	LevelSetGrid k1(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	LevelSetGrid::Iterator iter = GetGrid().BeginNarrowBand();
	LevelSetGrid::Iterator iend = GetGrid().EndNarrowBand();
	while (iter != iend) 
	{
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i k1
		y.SetValue(i,j,k,GetGrid().GetValue(i,j,k));
		k1.SetValue(i,j,k,ddt*dt);
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k, y.GetValue(i,j,k) + (1.0/2.0)*k1.GetValue(i,j,k));
		iter++;
	}
	GetGrid() = grid;

	//K2
	LevelSetGrid k2(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	 iter = GetGrid().BeginNarrowBand();
	 iend = GetGrid().EndNarrowBand();
	while (iter != iend) 
	{
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i k2
		k2.SetValue(i,j,k,ddt*dt);
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k, y.GetValue(i,j,k) + (1.0/2.0)*k2.GetValue(i,j,k));
		iter++;
	}
	GetGrid() = grid;

	//K3
	LevelSetGrid k3(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	 iter = GetGrid().BeginNarrowBand();
	 iend = GetGrid().EndNarrowBand();
	while (iter != iend) 
	{
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i k3
		k3.SetValue(i,j,k,ddt*dt);
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k, y.GetValue(i,j,k) + k3.GetValue(i,j,k));
		iter++;
	}
	GetGrid() = grid;

	//K4
	LevelSetGrid k4(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	 iter = GetGrid().BeginNarrowBand();
	 iend = GetGrid().EndNarrowBand();
	while (iter != iend) 
	{
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i k3
		k4.SetValue(i,j,k,ddt*dt);
		iter++;
	}
	GetGrid() = grid;

  //Beräkna nytt n+1 via n och n+2
  iter = GetGrid().BeginNarrowBand();
  iend = GetGrid().EndNarrowBand();
  while (iter != iend) {
    unsigned int i = iter.GetI();
    unsigned int j = iter.GetJ();
    unsigned int k = iter.GetK();
	
	float yn =   y.GetValue(i,j,k);
	float k1n =  k1.GetValue(i,j,k);
	float k2n =  k2.GetValue(i,j,k);
	float k3n =  k3.GetValue(i,j,k);
	float k4n =  k4.GetValue(i,j,k);

	float new_y = yn + (1.0/6.0)*(k1n+k4n) + (1.0/3.0)*(k2n + k3n);

    grid.SetValue(i,j,k,new_y);
    iter++;
  }
  GetGrid() = grid;*/

	LevelSetGrid grid = GetGrid();
	LevelSetGrid n(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	LevelSetGrid::Iterator iter = GetGrid().BeginNarrowBand();
	LevelSetGrid::Iterator iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
		n.SetValue(i,j,k,GetGrid().GetValue(i,j,k));
		float n1 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k,n1);
		iter++;
	}
	GetGrid() = grid;

	iter = GetGrid().BeginNarrowBand();
	iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n

		float n2 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		float n0 = n.GetValue(i,j,k);
		float n1 = (n0+n2)/2.0;
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k,n1);
		iter++;
	}
	GetGrid() = grid;

	iter = GetGrid().BeginNarrowBand();
	iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
		float n2 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k,n2);
		iter++;
	}
	GetGrid() = grid;

	iter = GetGrid().BeginNarrowBand();
	iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
		float n0 = n.GetValue(i,j,k);
		float n2 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		// Compute the next time step and store it in the grid
		float n12 = 3.0/4.0*n0 + 1.0/4.0*n2;
		grid.SetValue(i,j,k,n12);
		iter++;
	}
	GetGrid() = grid;

	iter = GetGrid().BeginNarrowBand();
	iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
		float n0 = n.GetValue(i,j,k);
		float n32 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		// Compute the next time step and store it in the grid
		float n1 = 1.0/3.0*n0 + 2.0/3.0*n32;
		grid.SetValue(i,j,k,n1);
		iter++;
	}
	GetGrid() = grid;
}