Beispiel #1
0
t_double3			color_diffused(t_scene *scene, t_surface *surface, t_vector ray)
{
	t_double3		color_hit;
	t_light			*light;
	int				light_nb;
	double			dot_light;
	t_surface		*light_intersect;
	t_double3		reflected;

	color_hit = (t_double3){0, 0, 0};
	light = scene->light;
	light_nb = 0;
	while (light)
	{
		light_intersect = is_in_light(surface, scene, light, &dot_light);
		if (light_intersect->object == NULL || light_intersect->distance > 0)
		{
			color_hit = v_plus_v(color_hit, color_mix(scale_v(light->color,
				dot_light), surface->object->gloss,
				// scale_v(surface->object->color, dot_light)));
				scale_v(surface->color, dot_light)));
			reflected = reflect(scale_v(normalize(v_minus_v(light->pos, surface->point)), -1), surface->normal);
			color_hit = v_plus_v(color_hit, scale_v(light->color, pow(max_double(0, -dot_product(reflected, ray.dir) * surface->object->gloss), 2)));
		}
		free(light_intersect);
		light_nb++;
		light = light->next;
	}
	if (light_nb > 1)
		color_hit = scale_v(color_hit, (1.0 / (double)light_nb));
	return (color_hit);
}
Beispiel #2
0
t_surface			*is_in_light(t_surface *surface, t_scene *scene,
	t_light *light, double *dot_light)
{
	t_vector		light_ray;
	t_double3		light_distance;
	t_surface		*light_intersect;
	double			dot_light_dir;

	light_ray.pos = surface->point;
	light_distance = v_minus_v(light->pos, surface->point);
	light_ray.dir = normalize(light_distance);
	*dot_light = dot_product(light_ray.dir, surface->normal);
	*dot_light = max_double(0, *dot_light);
	if (length_v(light->dir) > 0.01)
	{
		dot_light_dir = abs_double(dot_product(light_ray.dir, normalize(light->dir)));
		dot_light_dir = max_double(0, dot_light_dir);
		*dot_light *= dot_light_dir;
	}
	light_intersect = intersect(light_ray, scene, surface->object);
	if (light_intersect->object != NULL)
		light_intersect->distance -= length_v(light_distance);
	return (light_intersect);
}
Beispiel #3
0
t_double3			direct_light(t_vector ray, t_scene *scene,
	t_double3 color_hit)
{
	t_light			*light;
	t_double3		light_vector;
	t_surface		*light_intersect;
	double			dot_light;

	light = scene->light;
	while (light)
	{
		light_vector = v_minus_v(light->pos, ray.pos);
		dot_light = dot_product(normalize(light_vector), ray.dir);
		dot_light = max_double(0, exp(dot_light +  7.51745) -5000);
		light_intersect = intersect((t_vector){scene->camera.pos,
			normalize(light_vector)}, scene, NULL);
		if (light_intersect->object == NULL || (light_intersect->distance >
			length_v(light_vector)))
			color_hit = color_mix(light->color, dot_light, color_hit);
		free(light_intersect);
		light = light->next;
	}
	return (color_hit);
}
/*--------------------------------------------------------------------------------
 * Function:	wban_source_init
 *
 * Description:	- initialize the process
 *				- read the values of source attributes
 *              - schedule a self interrupt that will indicate start time	
 *					for MSDU generation
 *
 * No parameters
 *--------------------------------------------------------------------------------*/
static void wban_source_init() {
	Objid own_id;	/* Object ID of the surrounding processor or queue */
	Objid traffic_source_comp_id; 
	Objid traffic_source_id;
	char device_mode[20];	/* mode of the device: Hub or Node */
	double temp;
	
	/* Stack tracing enrty point */
	FIN(wban_source_init);

	/* obtain self object ID of the surrounding processor or queue */
	own_id = op_id_self ();
	/* obtain object ID of the parent object (node) */
	parent_id = op_topo_parent (own_id);
	/* set the initial number of sequence number to 0 */
	dataSN = 0;
	/* get the value to check if this node is PAN coordinator or not */
	op_ima_obj_attr_get (parent_id, "Device Mode", device_mode);
	/* get destination ID */
	op_ima_obj_attr_get (own_id, "Destination ID", &destination_id);
	/* get the name of the node */
	op_ima_obj_attr_get (parent_id, "name", node_name);

	printf("%s User Priority Traffic initialization.\n", node_name);
	op_ima_obj_attr_get (own_id, "User Priority 7 Traffic Parameters", &traffic_source_id); 
	traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_GENERIC, 0);
	/* Read the values of the up7-MSDU generation parameters, i.e. the attribute values of the surrounding module. */
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Interval Time", up7_msdu_interarrival_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Size",              up7_msdu_size_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "Start Time",             &up7_start_time);
	op_ima_obj_attr_get (traffic_source_comp_id, "Stop Time",              &up7_stop_time);	

	op_ima_obj_attr_get (own_id, "User Priority 6 Traffic Parameters", &traffic_source_id); 
	traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_GENERIC, 0);
	/* Read the values of the up6-MSDU generation parameters, i.e. the attribute values of the surrounding module. */
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Interval Time", up6_msdu_interarrival_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Size",              up6_msdu_size_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "Start Time",             &up6_start_time);
	op_ima_obj_attr_get (traffic_source_comp_id, "Stop Time",              &up6_stop_time);	

	op_ima_obj_attr_get (own_id, "User Priority 5 Traffic Parameters", &traffic_source_id); 
	traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_GENERIC, 0);
	/* Read the values of the up5-MSDU generation parameters, i.e. the attribute values of the surrounding module. */
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Interval Time", up5_msdu_interarrival_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Size",              up5_msdu_size_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "Start Time",             &up5_start_time);
	op_ima_obj_attr_get (traffic_source_comp_id, "Stop Time",              &up5_stop_time);	

	op_ima_obj_attr_get (own_id, "User Priority 4 Traffic Parameters", &traffic_source_id); 
	traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_GENERIC, 0);
	/* Read the values of the up4-MSDU generation parameters, i.e. the attribute values of the surrounding module. */
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Interval Time", up4_msdu_interarrival_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Size",              up4_msdu_size_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "Start Time",             &up4_start_time);
	op_ima_obj_attr_get (traffic_source_comp_id, "Stop Time",              &up4_stop_time);	

	op_ima_obj_attr_get (own_id, "User Priority 3 Traffic Parameters", &traffic_source_id); 
	traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_GENERIC, 0);
	/* Read the values of the up3-MSDU generation parameters, i.e. the attribute values of the surrounding module. */
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Interval Time", up3_msdu_interarrival_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Size",              up3_msdu_size_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "Start Time",             &up3_start_time);
	op_ima_obj_attr_get (traffic_source_comp_id, "Stop Time",              &up3_stop_time);	

	op_ima_obj_attr_get (own_id, "User Priority 2 Traffic Parameters", &traffic_source_id); 
	traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_GENERIC, 0);
	/* Read the values of the up2-MSDU generation parameters, i.e. the attribute values of the surrounding module. */
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Interval Time", up2_msdu_interarrival_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Size",              up2_msdu_size_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "Start Time",             &up2_start_time);
	op_ima_obj_attr_get (traffic_source_comp_id, "Stop Time",              &up2_stop_time);	

	op_ima_obj_attr_get (own_id, "User Priority 1 Traffic Parameters", &traffic_source_id); 
	traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_GENERIC, 0);
	/* Read the values of the up1-MSDU generation parameters, i.e. the attribute values of the surrounding module. */
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Interval Time", up1_msdu_interarrival_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Size",              up1_msdu_size_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "Start Time",             &up1_start_time);
	op_ima_obj_attr_get (traffic_source_comp_id, "Stop Time",              &up1_stop_time);	

	op_ima_obj_attr_get (own_id, "User Priority 0 Traffic Parameters", &traffic_source_id); 
	traffic_source_comp_id = op_topo_child (traffic_source_id, OPC_OBJTYPE_GENERIC, 0);
	/* Read the values of the up0-MSDU generation parameters, i.e. the attribute values of the surrounding module. */
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Interval Time", up0_msdu_interarrival_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "MSDU Size",              up0_msdu_size_dist_str);
	op_ima_obj_attr_get (traffic_source_comp_id, "Start Time",             &up0_start_time);
	op_ima_obj_attr_get (traffic_source_comp_id, "Stop Time",              &up0_stop_time);	

	/* if you are Hub do not send packets itself */
	if ((strcmp(device_mode, "Hub") == 0) && (destination_id == HUB_ID)) {
		up7_start_time = SC_INFINITE_TIME;
		up6_start_time = SC_INFINITE_TIME;
		up5_start_time = SC_INFINITE_TIME;
		up4_start_time = SC_INFINITE_TIME;
		up3_start_time = SC_INFINITE_TIME;
		up2_start_time = SC_INFINITE_TIME;
		up1_start_time = SC_INFINITE_TIME;
		up0_start_time = SC_INFINITE_TIME;
	}

	/* Load the PDFs that will be used in computing the MSDU Interval Times and MSDU Sizes. */
	up7_msdu_interarrival_dist_ptr = oms_dist_load_from_string (up7_msdu_interarrival_dist_str);
	up7_msdu_size_dist_ptr       = oms_dist_load_from_string (up7_msdu_size_dist_str);

	/* Load the PDFs that will be used in computing the MSDU Interval Times and MSDU Sizes. */
	up6_msdu_interarrival_dist_ptr = oms_dist_load_from_string (up6_msdu_interarrival_dist_str);
	up6_msdu_size_dist_ptr       = oms_dist_load_from_string (up6_msdu_size_dist_str);

	/* Load the PDFs that will be used in computing the MSDU Interval Times and MSDU Sizes. */
	up5_msdu_interarrival_dist_ptr = oms_dist_load_from_string (up5_msdu_interarrival_dist_str);
	up5_msdu_size_dist_ptr       = oms_dist_load_from_string (up5_msdu_size_dist_str);

	/* Load the PDFs that will be used in computing the MSDU Interval Times and MSDU Sizes. */
	up4_msdu_interarrival_dist_ptr = oms_dist_load_from_string (up4_msdu_interarrival_dist_str);
	up4_msdu_size_dist_ptr       = oms_dist_load_from_string (up4_msdu_size_dist_str);

	/* Load the PDFs that will be used in computing the MSDU Interval Times and MSDU Sizes. */
	up3_msdu_interarrival_dist_ptr = oms_dist_load_from_string (up3_msdu_interarrival_dist_str);
	up3_msdu_size_dist_ptr       = oms_dist_load_from_string (up3_msdu_size_dist_str);

	/* Load the PDFs that will be used in computing the MSDU Interval Times and MSDU Sizes. */
	up2_msdu_interarrival_dist_ptr = oms_dist_load_from_string (up2_msdu_interarrival_dist_str);
	up2_msdu_size_dist_ptr       = oms_dist_load_from_string (up2_msdu_size_dist_str);

	/* Load the PDFs that will be used in computing the MSDU Interval Times and MSDU Sizes. */
	up1_msdu_interarrival_dist_ptr = oms_dist_load_from_string (up1_msdu_interarrival_dist_str);
	up1_msdu_size_dist_ptr       = oms_dist_load_from_string (up1_msdu_size_dist_str);

	/* Load the PDFs that will be used in computing the MSDU Interval Times and MSDU Sizes. */
	up0_msdu_interarrival_dist_ptr = oms_dist_load_from_string (up0_msdu_interarrival_dist_str);
	up0_msdu_size_dist_ptr       = oms_dist_load_from_string (up0_msdu_size_dist_str);

	/* Make sure we have valid start and stop times, i.e. stop time is not earlier than start time.	*/
	if ((up7_stop_time <= up7_start_time) && (up7_stop_time != SC_INFINITE_TIME)) {
		/* Stop time is earlier than start time. Disable the source.	*/
		up7_start_time = SC_INFINITE_TIME;

		/* Display an appropriate warning.								*/
		op_prg_odb_print_major ("Warning from a Traffic source model:", 
								"Although the user priority 7 generator is not disabled (start time is set to a finite value) a stop time that is not later than the start time is specified.",
								"Disabling the user priority 7 generator.", OPC_NIL);
	}

	/* Make sure we have valid start and stop times, i.e. stop time is not earlier than start time.	*/
	if ((up6_stop_time <= up6_start_time) && (up6_stop_time != SC_INFINITE_TIME)) {
		/* Stop time is earlier than start time. Disable the source.	*/
		up6_start_time = SC_INFINITE_TIME;

		/* Display an appropriate warning.								*/
		op_prg_odb_print_major ("Warning from a Traffic source model:", 
								"Although the user priority 6 generator is not disabled (start time is set to a finite value) a stop time that is not later than the start time is specified.",
								"Disabling the user priority 6 generator.", OPC_NIL);
	}

	/* Make sure we have valid start and stop times, i.e. stop time is not earlier than start time.	*/
	if ((up5_stop_time <= up5_start_time) && (up5_stop_time != SC_INFINITE_TIME)) {
		/* Stop time is earlier than start time. Disable the source.	*/
		up5_start_time = SC_INFINITE_TIME;

		/* Display an appropriate warning.								*/
		op_prg_odb_print_major ("Warning from a Traffic source model:", 
								"Although the user priority 5 generator is not disabled (start time is set to a finite value) a stop time that is not later than the start time is specified.",
								"Disabling the user priority 5 generator.", OPC_NIL);
	}

	/* Make sure we have valid start and stop times, i.e. stop time is not earlier than start time.	*/
	if ((up4_stop_time <= up4_start_time) && (up4_stop_time != SC_INFINITE_TIME)) {
		/* Stop time is earlier than start time. Disable the source.	*/
		up4_start_time = SC_INFINITE_TIME;

		/* Display an appropriate warning.								*/
		op_prg_odb_print_major ("Warning from a Traffic source model:", 
								"Although the user priority 4 generator is not disabled (start time is set to a finite value) a stop time that is not later than the start time is specified.",
								"Disabling the user priority 4 generator.", OPC_NIL);
	}

	/* Make sure we have valid start and stop times, i.e. stop time is not earlier than start time.	*/
	if ((up3_stop_time <= up3_start_time) && (up3_stop_time != SC_INFINITE_TIME)) {
		/* Stop time is earlier than start time. Disable the source.	*/
		up3_start_time = SC_INFINITE_TIME;

		/* Display an appropriate warning.								*/
		op_prg_odb_print_major ("Warning from a Traffic source model:", 
								"Although the user priority 3 generator is not disabled (start time is set to a finite value) a stop time that is not later than the start time is specified.",
								"Disabling the user priority 3 generator.", OPC_NIL);
	}

	/* Make sure we have valid start and stop times, i.e. stop time is not earlier than start time.	*/
	if ((up2_stop_time <= up2_start_time) && (up2_stop_time != SC_INFINITE_TIME)) {
		/* Stop time is earlier than start time. Disable the source.	*/
		up2_start_time = SC_INFINITE_TIME;

		/* Display an appropriate warning.								*/
		op_prg_odb_print_major ("Warning from a Traffic source model:", 
								"Although the user priority 2 generator is not disabled (start time is set to a finite value) a stop time that is not later than the start time is specified.",
								"Disabling the user priority 2 generator.", OPC_NIL);
	}

	/* Make sure we have valid start and stop times, i.e. stop time is not earlier than start time.	*/
	if ((up1_stop_time <= up1_start_time) && (up1_stop_time != SC_INFINITE_TIME)) {
		/* Stop time is earlier than start time. Disable the source.	*/
		up1_start_time = SC_INFINITE_TIME;

		/* Display an appropriate warning.								*/
		op_prg_odb_print_major ("Warning from a Traffic source model:", 
								"Although the user priority 1 generator is not disabled (start time is set to a finite value) a stop time that is not later than the start time is specified.",
								"Disabling the user priority 1 generator.", OPC_NIL);
	}

	/* Make sure we have valid start and stop times, i.e. stop time is not earlier than start time.	*/
	if ((up0_stop_time <= up0_start_time) && (up0_stop_time != SC_INFINITE_TIME)) {
		/* Stop time is earlier than start time. Disable the source.	*/
		up0_start_time = SC_INFINITE_TIME;

		/* Display an appropriate warning.								*/
		op_prg_odb_print_major ("Warning from a Traffic source model:", 
								"Although the user priority 0 generator is not disabled (start time is set to a finite value) a stop time that is not later than the start time is specified.",
								"Disabling the user priority 0 generator.", OPC_NIL);
	}

	/* Schedule a self interrupt that will indicate transition to next state.	*/
	if ((up7_start_time == SC_INFINITE_TIME) && (up6_start_time == SC_INFINITE_TIME) 
		&& (up5_start_time == SC_INFINITE_TIME) && (up4_start_time == SC_INFINITE_TIME) 
		&& (up3_start_time == SC_INFINITE_TIME) && (up2_start_time == SC_INFINITE_TIME) 
		&& (up1_start_time == SC_INFINITE_TIME) && (up0_start_time == SC_INFINITE_TIME) 
		) {
		op_intrpt_schedule_self (op_sim_time (), SC_STOP);	//DISABLED
	} else {
		op_intrpt_schedule_self (op_sim_time (), SC_START); //START
		
		/* In this case, also schedule the interrupt for starting of the MSDU generation */		
		if (up7_start_time != SC_INFINITE_TIME)
			op_intrpt_schedule_self (up7_start_time, SC_GENERATE_UP7);	//UP7_MSDU_GENERATE
		if (up6_start_time != SC_INFINITE_TIME)
			op_intrpt_schedule_self (up6_start_time, SC_GENERATE_UP6);	//UP6_MSDU_GENERATE
		if (up5_start_time != SC_INFINITE_TIME)
			op_intrpt_schedule_self (up5_start_time, SC_GENERATE_UP5);	//UP5_MSDU_GENERATE	
		if (up4_start_time != SC_INFINITE_TIME)
			op_intrpt_schedule_self (up4_start_time, SC_GENERATE_UP4);	//UP4_MSDU_GENERATE	
		if (up3_start_time != SC_INFINITE_TIME)
			op_intrpt_schedule_self (up3_start_time, SC_GENERATE_UP3);	//UP3_MSDU_GENERATE
		if (up2_start_time != SC_INFINITE_TIME)
			op_intrpt_schedule_self (up2_start_time, SC_GENERATE_UP2);	//UP2_MSDU_GENERATE
		if (up1_start_time != SC_INFINITE_TIME)
			op_intrpt_schedule_self (up1_start_time, SC_GENERATE_UP1);	//UP1_MSDU_GENERATE	
		if (up0_start_time != SC_INFINITE_TIME)
			op_intrpt_schedule_self (up0_start_time, SC_GENERATE_UP0);	//UP0_MSDU_GENERATE	

		/* In this case, also schedule the interrupt when we will stop	generating */
		/* MSDUs, unless we are configured to run until the end of the simulation. */
		if ((up7_stop_time != SC_INFINITE_TIME) && (up6_stop_time != SC_INFINITE_TIME)
			&& (up5_stop_time != SC_INFINITE_TIME) && (up4_stop_time != SC_INFINITE_TIME) 
			&& (up3_stop_time != SC_INFINITE_TIME) && (up2_stop_time != SC_INFINITE_TIME) 
			&& (up1_stop_time != SC_INFINITE_TIME) && (up0_stop_time != SC_INFINITE_TIME) 
			){
			temp = max_double(max_double(up7_stop_time, up6_stop_time), max_double(up5_stop_time, up4_stop_time));
			temp = max_double(temp, max_double(max_double(up3_stop_time, up2_stop_time), max_double(up1_stop_time, up0_stop_time)));
			op_intrpt_schedule_self (temp, SC_STOP);
		}
	}

	wban_print_parameters ();

	/* Stack tracing exit point */
	FOUT;
}
Beispiel #5
0
int main(int argc, char **argv){
  ImMat image, Im, LowPass, HighPass, HighResult, LowResult, result_high, result_low;
  uchar *abs_result;
  int i; double ABS[HT*WD];
  im = image_from_bin("resized_sample.bin", WD*HT);
  
  for(i=0; i<WD*HT; i++){
    int x=i%WD, y=i/WD;
    image.real[i] = (double)im[i];
    LowPass.real[i] = ((x>THR && x<WD-THR && y>THR && y<HT-THR) ? 0 : 1);
    HighPass.real[i] = ((x>THR && x<WD-THR && y>THR && y<HT-THR) ? 1 : 0);
    image.im[i] = 0;
    LowPass.im[i] = 0;
    HighPass.im[i] = 0;

    image.width=WD;image.height=HT;
    Im.width=WD;Im.height=HT;
    LowPass.width=WD;LowPass.height=HT;
    HighPass.width=WD;HighPass.height=HT;
  }

  dft(&image, &Im);
  dft_rev(&Im, &image);

  dot(&Im, &LowPass, &LowResult);
  dft_rev(&LowResult, &result_low);

  dot(&Im, &HighPass, &HighResult);
  dft_rev(&HighResult, &result_high);

  result = (uchar*)malloc(sizeof(uchar)*WD*HT);
  low_result = (uchar*)malloc(sizeof(uchar)*WD*HT);
  high_result = (uchar*)malloc(sizeof(uchar)*WD*HT);
  abs_result = (uchar*)malloc(sizeof(uchar)*WD*HT);


  for(i=0; i<WD*HT; i++){
    ABS[i] = sqrt(pow(Im.real[i], 2) + pow(Im.im[i], 2));
  }

  for(i=0; i<WD*HT; i++){
    low_result[i] = (uchar)result_low.real[i];
    high_result[i] = (uchar)result_low.real[i];
    
    double max_ = max_double(ABS, WD*HT);
    double min_ = min_double(ABS, WD*HT);
    abs_result[i] = (uchar)((511*(ABS[i]-min_))/(max_-min_));
  }

  image_to_bin(abs_result, "65abs.bin", WD*HT);
  
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowSize(WD, HT);
  glutInitWindowPosition(100, 100);
  glutCreateWindow(argv[0]);
  
  glClearColor(0, 0, 0, 0);

  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutKeyboardFunc(keyboard);
  glutMainLoop();

  return 0;
}