int main(void){ double radius; double height; double material_cost; int quantity; double surface_area; double total_cost; instruct(); printf("Radius in cm: "); scanf("%lf", &radius); printf("Height in cm: "); scanf("%lf", &height); printf("Material cost in $/cm^2: "); scanf("%lf", &material_cost); quantity = get_quantity(); surface_area = comp_area(height, radius); total_cost = material_cost * surface_area * quantity; print_area_cost(surface_area, total_cost); return 0; }
void key_mix_layer_node_t::do_process( const render::context_t& context) { image_node_t *bg = input_as<image_node_t>( 0); image_node_t *fg = input_as<image_node_t>( 1); image_node_t *mt = input_as<image_node_t>( 2); Imath::Box2i bg_area = Imath::intersect( bg->defined(), defined()); if( !bg_area.isEmpty()) { render_input( 0, context); boost::gil::copy_pixels( bg->const_subimage_view( bg_area), subimage_view( bg_area)); release_input_image( 0); } Imath::Box2i comp_area( Imath::intersect( Imath::intersect( fg->defined(), mt->defined()), defined())); if( !comp_area.isEmpty()) { render_input( 1, context); // image buffer contains a shared ptr to // the actual pixels. Saving it to a local variable, // is equivalent to locking the pixels. // This could be improved, as I think it's not really clear. // There is also a lock method in buffer_t that it's // currently unused... image::buffer_t fg_img = fg->image(); render_input( 2, context); image::buffer_t alpha_img = mt->image(); boost::gil::tbb_transform3_pixels( const_subimage_view( comp_area), fg->const_subimage_view( comp_area), mt->const_subimage_view( comp_area), subimage_view( comp_area), key_mix_layer_mode_fun( get_value<float>( param( "opacity")))); release_input_image( 1); release_input_image( 2); } }
void layer_node_t::do_process( const render::context_t& context) { int mode = get_value<int>( param( "layer_mode")); if( mode == comp_mult || mode == comp_min || mode == comp_overlay || mode == comp_mix) // min, mult and overlay are special { do_process_mult_min_overlay_mix( context); return; } image_node_t *bg = input_as<image_node_t>( 0); image_node_t *fg = input_as<image_node_t>( 1); Imath::Box2i bg_area = ImathExt::intersect( bg->defined(), defined()); float opacity = get_value<float>( param( "opacity")); if( !bg_area.isEmpty()) { render_input( 0, context); boost::gil::copy_pixels( bg->const_subimage_view( bg_area), subimage_view( bg_area)); release_input_image( 0); } Imath::Box2i comp_area( ImathExt::intersect( fg->defined(), defined())); if( !comp_area.isEmpty()) { if( opacity == 0.0f) return; render_input( 1, context); switch( mode) { case comp_over: image::composite_over( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; case comp_add: image::composite_add( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; case comp_sub: image::composite_sub( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; case comp_screen: image::composite_screen( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; case comp_overlay: image::composite_overlay( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; case comp_diff: image::composite_diff( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; case comp_max: image::composite_max( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; } release_input_image( 1); } }
void layer_node_t::do_process_mult_min_overlay_mix( const render::context_t& context) { image_node_t *bg = input_as<image_node_t>( 0); image_node_t *fg = input_as<image_node_t>( 1); int mode = get_value<int>( param( "layer_mode")); float opacity = get_value<float>( param( "opacity")); Imath::Box2i bg_area( ImathExt::intersect( bg->defined(), defined())); Imath::Box2i comp_area( ImathExt::intersect( fg->defined(), defined())); if( !bg_area.isEmpty()) { render_input( 0, context); if( opacity == 0.0f) // just copy the background and return { boost::gil::copy_pixels( bg->const_subimage_view( bg_area), subimage_view( bg_area)); return; } if( mode == comp_overlay) { image::composite_zero_overlay( bg->const_subimage_view( bg_area), subimage_view( bg_area), opacity); Imath::Box2i common_area( ImathExt::intersect( fg->defined(), bg->defined())); if( !common_area.isEmpty()) boost::gil::copy_pixels( bg->const_subimage_view( common_area), subimage_view( common_area)); } else { if( opacity == 1.0f) // the normal case, nothing special to do boost::gil::copy_pixels( bg->const_subimage_view( bg_area), subimage_view( bg_area)); else // we need to handle the areas of the bg that don't intersect the fg { image::mul_image_scalar( bg->const_subimage_view( bg_area), 1.0f - opacity, subimage_view( bg_area)); Imath::Box2i common_area( ImathExt::intersect( fg->defined(), bg->defined())); if( !common_area.isEmpty()) boost::gil::copy_pixels( bg->const_subimage_view( common_area), subimage_view( common_area)); } } // we don't need the bg anymore release_input_image( 0); } if( !comp_area.isEmpty()) { render_input( 1, context); switch( mode) { case comp_min: image::composite_min( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; case comp_mult: image::composite_mul( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; case comp_mix: image::composite_mix( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; case comp_overlay: image::composite_overlay( const_subimage_view( comp_area), input_as<image_node_t>( 1)->const_subimage_view( comp_area), subimage_view( comp_area), opacity); break; } release_input_image( 1); } }