Beispiel #1
0
void
etrace_if_mode_change(scope_state_t *scope, periph_t *pperiph, unsigned long mode,
                      unsigned long long time_stamp)
{

    int new_mode  = mode & 0x1F;
    int new_fvset = ((mode >> 5) & 0x07);

    // check the new mode and new fvset (do they exist)
    if(new_mode >= pperiph->pclass->nmodes){
        cerr << "Wrong mode (" << new_mode << " for peripheral : "
             << pperiph->name << ")" << endl;
        return;
    }

    if(new_fvset >= pperiph->pclass->nfvsets){
        cerr << "Wrong FV set (" << new_fvset << " for peripheral index : "
             << pperiph->name << ")" << endl;
        return;
    }

    // check if the time_stamp is not before last_evt time stamp
    if(time_stamp < pperiph->last_change_stamp){
        cerr << "Time event not correct : new event time : "
             << time_stamp << " whereas previous event was at "
             << pperiph->last_change_stamp << endl;
        return;
    }

    // update samples if needed
    if (time_stamp > pperiph->last_change_stamp)
        update_samples(scope, pperiph, mode, time_stamp);

    // update periph status
    pperiph->curr_mode         = new_mode;
    pperiph->curr_fvset        = new_fvset;
    pperiph->last_change_stamp = time_stamp;
}
void ImplicitSampler::sample(Vector3* points, int* tris)  {
	UniformGrid* uniform_grid = new UniformGrid(grid_res_x, grid_res_y, grid_res_z, ll_bound, ur_bound);

	int iteration = 0;
	bool sampling_satisfied = iteration == num_iterations;

	double start_radius = global_radius, end_radius = 2.0*global_radius;

	double prior_energy = 0;
	while(!sampling_satisfied)  {
		// populate grid with new points
		for(int s = 0; s < num_points; s++)  {
			if(iteration > 0)
				break;
			uniform_grid->add_point(sampled_pts[s]);
		}

		int periodicity = num_points/10;

		vector<GridPoint> new_samples;
		ComputationTimer timer("relaxation");
		timer.start();
		double total_energy = 0;
		// and perform repulsion
		for(int s = 0; s < num_points; s++)  {
			if((s % periodicity) == 0)
				cout << "point["<<s<<"]" << endl;
			GridPoint sampler_pt = sampled_pts[s];
			Vector3 pt = sampler_pt.pt;

			// gather neighborhood
			vector<GridPoint> neighborhood;
			this->gather_neighborhood(sampler_pt, uniform_grid, &neighborhood);
			if(neighborhood.size() == 1)
				continue;

			// compute energy & repulsed point
			total_energy += compute_energy(sampler_pt, &neighborhood);
			Vector3 force_vector = construct_force(sampler_pt, &neighborhood);
			Vector3 repulsed_pt = pt + force_vector;

			// project point onto nearest triangle
			GridPoint new_pt = this->projection(repulsed_pt, sampler_pt);

			// assign new point, and update grid
			new_samples.push_back(new_pt);
		}

		for(unsigned s = 0; s < new_samples.size(); s++)
			update_samples(new_samples[s], uniform_grid);

		timer.end();
		cout << timer.getComputation() << " : " << timer.getElapsedTime() << "s energy: " << total_energy << endl;

		bool energy_achieved = false;
		if(iteration > 0)  {
			double energy_fraction = (prior_energy-total_energy)/total_energy;
			energy_achieved = iteration >= (min_iterations-1) && energy_fraction < 0.1;
		}

		iteration++;
		sampling_satisfied = energy_achieved || (iteration == num_iterations);
		prior_energy = total_energy;
	}

	delete uniform_grid;

	for(int s = 0; s < num_points; s++)
		points[s] = sampled_pts[s].pt;
}