static gpointer
cal_model_calendar_value_at (ETableModel *etm,
                             gint col,
                             gint row)
{
	ECalModelComponent *comp_data;
	ECalModelCalendar *model = (ECalModelCalendar *) etm;

	g_return_val_if_fail (E_IS_CAL_MODEL_CALENDAR (model), NULL);

	g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_CALENDAR_FIELD_LAST, NULL);
	g_return_val_if_fail (row >= 0 && row < e_table_model_row_count (etm), NULL);

	if (col < E_CAL_MODEL_FIELD_LAST)
		return table_model_parent_interface->value_at (etm, col, row);

	comp_data = e_cal_model_get_component_at (E_CAL_MODEL (model), row);
	if (!comp_data)
		return (gpointer) "";

	switch (col) {
	case E_CAL_MODEL_CALENDAR_FIELD_DTEND :
		return get_dtend (model, comp_data);
	case E_CAL_MODEL_CALENDAR_FIELD_LOCATION :
		return get_location (comp_data);
	case E_CAL_MODEL_CALENDAR_FIELD_TRANSPARENCY :
		return get_transparency (comp_data);
	}

	return (gpointer) "";
}
Example #2
0
/** Get the shade determined by a given ray.
 *  
 *  @param ray the ray to trace.
 *  @param t0 the start of the interval for which to get a shade.
 *  @param t1 the end of the interval for which to get a shade.
 *  @param depth the maximum number of times a reflect ray will be
 *      cast for objects with non-NULL reflective color.
 *  @param in_trans whether the ray is inside a transparent surface or not.
 * 
 *
 *  @return the color corresponding to the closest object hit by
 *      <code>r</code> in the interval <code>[t0, t1]</code>.
 */
color_t ray_trace(ray3_t ray, float t0, float t1, int depth, bool in_trans) {
    assert(depth >= 0);

    color_t color = {0.0, 0.0, 0.0};

    if (depth == 0) return color;

    hit_record_t hit_rec, closest_hit_rec;

    // Get a hit record for the closest object that is hit.
    bool hit_something = false;
    list356_itr_t* s = lst_iterator(surfaces);
    while (lst_has_next(s)) {
        surface_t* sfc = lst_next(s);
        if (sfc_hit(sfc, &ray, t0, t1, &hit_rec)) {
            if (hit_rec.t < t1) {
                hit_something = true;
                memcpy(&closest_hit_rec, &hit_rec, 
                        sizeof(hit_record_t));
                t1 = hit_rec.t;
            }
            else assert("wrong");
        }
    }
    lst_iterator_free(s);

    // If we hit something, color the pixel.
    if (hit_something) {
        surface_t* sfc = closest_hit_rec.sfc;

        // Specular reflection.
        if (spec_reflection) {
          if (sfc->refl_color != NULL) {
              color_t refl_color = get_specular_refl(&ray,
                      &closest_hit_rec, depth, in_trans);
              add_scaled_color(&color, sfc->refl_color, &refl_color, 1.0f);
          }
        }

        // Tranparency
        if (transparency) {
          if (sfc->refr_index != -1) {
              color_t trans_color = get_transparency(&ray, &closest_hit_rec,
                      depth, !in_trans);
              // Only add returned color, don't multiply by a surface_color.
              color.red += (trans_color.red);
              color.green += (trans_color.green);
              color.blue += (trans_color.blue);
          }
        }

        // Ambient shading.
        if (ambient_shading) {
          add_scaled_color(&color, sfc->ambient_color, &ambient_light, 1.0f);
        }

        // Lighting.
        if (lighting) {
          list356_itr_t* light_itr = lst_iterator(lights);
          while (lst_has_next(light_itr)) {
              light_t* light = lst_next(light_itr);
              vector3_t light_dir;
              pv_subtract(light->position, &(closest_hit_rec.hit_pt),
                      &light_dir);
              normalize(&light_dir);

              // Check for global shadows.
              bool do_lighting = true;

              // Bool for if the shadow is caused by transparent surface.
              bool trans_shadow = false;

              ray3_t light_ray = {closest_hit_rec.hit_pt, light_dir};
              float light_dist = dist(&closest_hit_rec.hit_pt,
                      light->position);
              s = lst_iterator(surfaces);
              while (lst_has_next(s)) {
                  surface_t* sfc = lst_next(s);
                  if (sfc_hit(sfc, &light_ray, EPSILON, light_dist, &hit_rec)) {
                      do_lighting = false;
                      // If shadow is caused by transparent surface, we add
                      // Lambertian shading only so our shadows are not opaque.
                      if (hit_rec.sfc->refr_index != -1) trans_shadow = true;
                      break;
                  }
              }
              lst_iterator_free(s);
              if (!do_lighting) {
                  continue;
              }

              // Lambertian shading.
              if (lambertian_shading) {
                if (!trans_shadow) {
                    float scale = get_lambert_scale(&light_dir, &closest_hit_rec);
                    add_scaled_color(&color, sfc->diffuse_color, light->color,
                            scale);
                }
              }

            // Blin-Phong shading (if shadow is not caused by transparent
            // surface).
            if (blin_phong_shading) {
              if (!trans_shadow) {
                  float phong_scale = get_blinn_phong_scale(&ray, &light_dir,
                          &closest_hit_rec);
                  add_scaled_color(&color, sfc->spec_color, light->color, 
                          phong_scale);
              }
            }
        }

        lst_iterator_free(light_itr);
    }

    }   // if (hit_something)
    return color;
}
Example #3
0
/** Get the shade determined by a given ray.
 *  
 *  @param ray the ray to trace.
 *  @param t0 the start of the interval for which to get a shade.
 *  @param t1 the end of the interval for which to get a shade.
 *  @param depth the maximum number of times a reflect ray will be
 *      cast for objects with non-NULL reflective color.
 *
 *  @return the color corresponding to the closest object hit by
 *      <code>r</code> in the interval <code>[t0, t1]</code>.
 */
color_t ray_trace(ray3_t ray, float t0, float t1, int depth) {
    assert(depth >= 0) ;

    color_t color = {0.0, 0.0, 0.0} ;

    if (depth ==0) return color ;

    hit_record_t hit_rec, closest_hit_rec ;

    // Get a hit record for the closest object that is hit.
    bool hit_something = false ;
    list356_itr_t* s = lst_iterator(surfaces) ;
    while (lst_has_next(s)) {
        surface_t* sfc = lst_next(s) ;
        if (sfc_hit(sfc, &ray, t0, t1, &hit_rec)) {
            if (hit_rec.t < t1) {
                hit_something = true ;
                memcpy(&closest_hit_rec, &hit_rec, 
                        sizeof(hit_record_t)) ;
                t1 = hit_rec.t ;
            }
        }
    }
    lst_iterator_free(s) ;

    // If we hit something, color the pixel.
    if (hit_something) {
        surface_t* sfc = closest_hit_rec.sfc ;

        // Specular reflection.
        if (sfc->refl_color != NULL) {
            color_t refl_color = get_specular_refl(&ray,
                    &closest_hit_rec, depth) ;
            add_scaled_color(&color, sfc->refl_color, &refl_color, 1.0f) ;
        }

        // Tranparency

        if (sfc->refr_index != -1) {
            toggle_trans_bool();
            color_t trans_color = get_transparency(&ray, &closest_hit_rec,
                    depth);
            // Only add returned color, don't multiply by a surface_color.
            //TODO: 
            //add_scaled_color(&color, sfc->refl_color, &trans_color, 1.0f);
            if (sfc->ambient_color == NULL) assert(0);
            color_t* s_color_ = sfc->ambient_color;
            color_t s_color = (color_t) *s_color_;
            //debug("ending trans_color { %f, %f, %f }", trans_color.red, trans_color.green, trans_color.blue);
            color.red += (trans_color.red);
            color.green += (trans_color.green);
            color.blue += (trans_color.blue);
            //add_scaled_color(&color, sfc->refl_color, &trans_color, 1.0f);
        }
        // Ambient shading.
        add_scaled_color(&color, sfc->ambient_color, &ambient_light, 1.0f) ;

        // Lighting.
        list356_itr_t* light_itr = lst_iterator(lights) ;
        while (lst_has_next(light_itr)) {
            light_t* light = lst_next(light_itr) ;
            vector3_t light_dir ;
            pv_subtract(light->position, &(closest_hit_rec.hit_pt), 
                    &light_dir) ;
            normalize(&light_dir) ;

            // Check for global shadows.
            bool do_lighting = true ;
            ray3_t light_ray = {closest_hit_rec.hit_pt, light_dir} ;
            float light_dist = dist(&closest_hit_rec.hit_pt,
                    light->position) ;
            s = lst_iterator(surfaces) ;
            while (lst_has_next(s)) {
                surface_t* sfc = lst_next(s) ;
                if (sfc_hit(sfc, &light_ray, EPSILON, light_dist, &hit_rec)) {
                    do_lighting = false ;
                    break ;
                }
            }
            lst_iterator_free(s) ;
            if (!do_lighting) {
                continue ;
            }

            // Lambertian shading.
            float scale = get_lambert_scale(&light_dir, &closest_hit_rec) ;
            add_scaled_color(&color, sfc->diffuse_color, light->color, scale) ;

            // Blin-Phong shading.
            float phong_scale = get_blinn_phong_scale(&ray, &light_dir,
                    &closest_hit_rec) ;
            add_scaled_color(&color, sfc->spec_color, light->color, 
                    phong_scale) ;
        }   // while(lst_has_next(light_itr))

        lst_iterator_free(light_itr) ;

    }   // if (hit_something)

    return color ;
}