Esempio n. 1
0
    void normalize()
    {
        T l = length();
        RAMEN_ASSERT( l > T(0));

        x /= l;
        y /= l;
        z /= l;
    }
Esempio n. 2
0
    vector3_t<T>& operator/=( T s)
    {
        RAMEN_ASSERT( s != T(0));

        x /= s;
        y /= s;
        z /= s;
        return *this;
    }
Esempio n. 3
0
void cu_ctx_destroy( CUcontext ctx)
{
	RAMEN_ASSERT( cuCtxDestroy_);

	// in this case, we don't check for errors, as
	// this is used in a destructor, and there's not much
	// we can do about it anyway.
	cuCtxDestroy_( ctx);
}
Esempio n. 4
0
void graph_t::add_node( node_t *v)
{
	RAMEN_ASSERT( !has_node( v));

	vertex_desc_type vd = boost::add_vertex( graph_);
	graph_[vd].node = v;
	node_to_desc_[v] = vd;
	valid_order_ = false;
}
Esempio n. 5
0
void clipboard_t::copy_keys( const std::string& name, const anim::any_curve_ptr_t& c)
{
	RAMEN_ASSERT( copying_);
	
	copy_curves_mode_ = false;
	contents_.push_back( named_curve_type( name, boost::shared_ptr<any_curve_t>()));
	copy_keys_visitor v( contents_.back().second);
	boost::apply_visitor( v, c);
}
Esempio n. 6
0
void graph_t::add_dependency( node_t *s, node_t *d)
{
	RAMEN_ASSERT( has_node( s) && has_node( d));
	RAMEN_ASSERT( s != d);

	boost::add_edge( node_to_desc_[s], node_to_desc_[d], graph_);

	cycle_detector v;
	boost::depth_first_search( graph_, boost::visitor( v));

	if( v.has_cycle)
	{
		remove_dependency( s, d);
		throw cycle_error();
	}

	valid_order_ = false;
}
Esempio n. 7
0
void yaml_oarchive_t::write_composition_header()
{
	RAMEN_ASSERT( !header_written_);

	out_ << YAML::Key << "magic"	<< YAML::Value << "Ramen composition";
	out_ << YAML::Key << "version"	<< YAML::Value << version;
	check_errors();
	header_written_ = true;
}
Esempio n. 8
0
	void add_level( const Sampler& sampler)
	{
		RAMEN_ASSERT( has_top_sampler_);

		samplers_.push_back( sampler);

		float scale = scales_.back() * 0.5f;
		scales_.push_back( scale);
		iscales_.push_back( 1.0f / scale);
	}
Esempio n. 9
0
	void set_top_level( const TopLevelSampler& sampler)
	{
		RAMEN_ASSERT( !has_top_sampler_);

		top_sampler_ = sampler;
		has_top_sampler_ = true;

		scales_.push_back( 1.0f);
		iscales_.push_back( 1.0f);
	}
Esempio n. 10
0
void graph_t::remove_node( node_t *v)
{
	RAMEN_ASSERT( has_node( v));

	vertex_desc_type vd = node_to_desc_[v];
	boost::clear_vertex( vd, graph_);
	boost::remove_vertex( vd, graph_);
	node_to_desc_.erase( v);
	valid_order_ = false;
}
Esempio n. 11
0
composition_t *param_t::composition()
{
    RAMEN_ASSERT( param_set());
    parameterised_t *p = parameterised();

    if( p)
        return p->composition();
    else
        return 0;
}
Esempio n. 12
0
    void deallocate( unsigned char *p, std::size_t s)
	{
		if( p == 0)
			return;

		RAMEN_ASSERT( s != 0);

	    boost::lock_guard<boost::recursive_mutex> lock( mutex_);
	    pool_.deallocate( p, s);
	}
Esempio n. 13
0
void clipboard_t::paste( const std::string& name, anim::any_curve_ptr_t& c, float frame)
{
	RAMEN_ASSERT( !copying_);
	
	int i = find_compatible_curve( name, c);
	RAMEN_ASSERT( i != -1);
	
	float offset = 0;

	if( !copy_curves_mode_)
	{
		get_first_key_time_visitor v;
		boost::apply_visitor( v, *contents_[i].second.get());
		offset = frame - v.frame;
	}
	
	paste_keys_visitor v( *contents_[i].second.get(), offset);
	boost::apply_visitor( v, c);
}
Esempio n. 14
0
T *aligned_ptr( T *p, int alignment)
{
	RAMEN_ASSERT( (( alignment - 1) & alignment) == 0);

    uintptr_t ptr = reinterpret_cast<uintptr_t>( p);
    uintptr_t align = alignment - 1;
    uintptr_t aligned = ( ptr + align + 1) & ~align;

    return reinterpret_cast<unsigned char *>( aligned);
}
Esempio n. 15
0
quad_manipulator_t::quad_manipulator_t( float2_param_t *topleft, float2_param_t *topright,
										float2_param_t *botleft, float2_param_t *botright) : manipulator_t()
{
	RAMEN_ASSERT( topleft && topright && botleft && botright);
	topleft_ = topleft;
	topright_ = topright;
	botleft_ = botleft;
	botright_ = botright;
	picked_corner_ = -1;
}
Esempio n. 16
0
	virtual void do_mouse_release_event( const ui::mouse_release_event_t& event)
	{
		if( event.dragged)
		{
			RAMEN_ASSERT( drag_axes_ || drag_center_);
			param_->param_set()->end_edit( param_->track_mouse());
		}

		drag_center_ = drag_axes_ = false;
		dragx_ = dragy_ = true;
	}
Esempio n. 17
0
void vertex_t::perspective_divide()
{
	RAMEN_ASSERT( screen.w != 0);

	inv_w = 1.0f / screen.w;
	screen.x *= inv_w;
	screen.y *= inv_w;

	uv.x *= inv_w;
	uv.y *= inv_w;
}
Esempio n. 18
0
	pixel_t sample_level( int level, const vector2_t& p) const
	{
		RAMEN_ASSERT( level >= 0 && level < num_levels());

		if( level == 0)
			return top_sampler_( p);

		float s = scales_[level];
		vector2_t q( p.x * s, p.y * s);
		return samplers_[level - 1]( q);
	}
Esempio n. 19
0
	virtual bool do_mouse_press_event( const ui::mouse_press_event_t& event)
	{
		RAMEN_ASSERT( node()->composition());

		drag_center_ = drag_axes_ = false;
		dragx_ = dragy_ = true;

		move2d_node_t::matrix3_type m( param_->matrix_at_frame( node()->composition()->frame(), node()->aspect_ratio()));

	    // adjust for the aspect factor
	    Imath::V2f c = get_absolute_value<Imath::V2f>( param_->center_param());
	    c = c * m;
		c.x *= node()->aspect_ratio();

		switch( manipulators::pick_xy_axes( event.wpos, c, 70 / event.pixel_scale, 70 / event.pixel_scale,
											get_value<float>( param_->rotate_param()),
											event.aspect_ratio / node()->aspect_ratio(), event.pixel_scale))
		{
			case manipulators::axes_center_picked:
			{
				if( event.modifiers & ui::event_t::control_modifier)
					drag_center_ = true;
				else
					drag_axes_ = true;
			}
			return true;

			case manipulators::axes_x_picked:
			{
				dragy_ = false;

				if( event.modifiers & ui::event_t::control_modifier)
					drag_center_ = true;
				else
					drag_axes_ = true;
			}
			return true;

			case manipulators::axes_y_picked:
			{
				dragx_ = false;

				if( event.modifiers & ui::event_t::control_modifier)
					drag_center_ = true;
				else
					drag_axes_ = true;
			}
			return true;

			default:
				return false;
		}
	}
Esempio n. 20
0
void graph_t::remove_dependency( node_t *s, node_t *d)
{
	RAMEN_ASSERT( s != d);

	if( has_node( s) && has_node( d))
	{
		vertex_desc_type vs = node_to_desc_[s];
		vertex_desc_type vd = node_to_desc_[d];
		boost::remove_edge( vs, vd, graph_);
		valid_order_ = false;
	}
}
Esempio n. 21
0
void buffer_t::check_area_inside_image( const Imath::Box2i& area) const
{
	#ifndef NDEBUG
        if( !ImathExt::isInside( bounds_, area))
		{
		    // Not OK, print some debug info and exit
		    std::cout << "Trying to access pixels outside buffer\n";
            //std::cout << "Area = " << area << " Bounds = " << bounds_ << "\n";
			RAMEN_ASSERT( 0);
		}
	#endif
}
Esempio n. 22
0
void keyer3d_node_t::create_cluster_params( int i)
{
	#ifndef NDEBUG
		RAMEN_ASSERT( i < max_clusters);
		
		std::string kcenter( "k0_center");
		std::string ktol( "k0_tol");
		std::string ksoft( "k0_soft");
	
		kcenter[1] = i + '0';
		std::auto_ptr<color_param_t> c( new color_param_t( kcenter));
		c->set_id( kcenter);
		c->set_default_value( Imath::Color4f( 0, 0, 0, 0));
		c->set_is_rgba( false);
		c->set_static( true);
		//c->set_secret( true);
		c->set_enabled( false);
		c->set_can_undo( false);
		c->set_persist( false);
		c->set_include_in_hash( false);		
		kcenter_[i] = c.get();
		add_param( c);
			
		ktol[1] = i + '0';
		std::auto_ptr<float_param_t> f( new float_param_t( ktol));
		f->set_id( ktol);
		f->set_default_value( 0);
		f->set_min( 0);
		f->set_static( true);
		//f->set_secret( true);
		f->set_enabled( false);
		f->set_can_undo( false);
		f->set_persist( false);
		f->set_include_in_hash( false);		
		ktol_[i] = f.get();
		add_param( f);		
	
		ksoft[1] = i + '0';
		f.reset( new float_param_t( ksoft));
		f->set_id( ksoft);
		f->set_default_value( 0);
		f->set_min( 0);
		f->set_static( true);
		//f->set_secret( true);
		f->set_enabled( false);
		f->set_can_undo( false);
		f->set_persist( false);
		f->set_include_in_hash( false);
		ksoft_[i] = f.get();
		add_param( f);
	#endif
}
Esempio n. 23
0
buffer_t::buffer_t( int width, int height, int channels)
{
    RAMEN_ASSERT( ( channels == 1 || channels == 3 || channels == 4) && "buffer_t: only 1, 3 and 4 channels images supported");

	init();
	channels_ = channels;
    bounds_ = Imath::Box2i( Imath::V2i( 0, 0), Imath::V2i( width-1, height-1));

    if( bounds_.isEmpty())
		return;

    alloc_pixels();
}
Esempio n. 24
0
void image_node_renderer_t::set_context( const context_t& context)
{
	has_context_ = true;
    new_context_ = context;
    n_ = dynamic_cast<image_node_t*>( new_context_.result_node);
    RAMEN_ASSERT( n_);
	n_->release_image();
	
    n_->composition()->set_frame( new_context_.frame);
    depth_first_inputs_search( *n_, boost::bind( &image_node_t::calc_format_fun, _1, new_context_));
    depth_first_inputs_search( *n_, boost::bind( &image_node_t::calc_bounds_fun, _1, new_context_));
    depth_first_inputs_search( *n_, boost::bind( &image_node_t::clear_interest_fun, _1));
}
Esempio n. 25
0
buffer_t::buffer_t( const Imath::Box2i& bounds, int channels)
{
    RAMEN_ASSERT( ( channels == 1 || channels == 3 || channels == 4) && "buffer_t: only 1, 3 and 4 channels images supported");

	init();
	bounds_ = bounds;
	channels_ = channels;

    if( bounds_.isEmpty())
		return;

    alloc_pixels();
}
Esempio n. 26
0
bool yaml_iarchive_t::read_composition_header()
{
	RAMEN_ASSERT( version_ == 0);
	RAMEN_ASSERT( !header_read_);

	std::string magic;

	if( !get_optional_value( "magic", magic))
		return false;

	if( magic != "Ramen composition")
		return false;

	if( !get_optional_value( "version", version_))
		return false;

	if( version() < 1)
		return false;

	root().set_version( version());
	header_read_ = true;
	return true;
}
Esempio n. 27
0
void memory_pool_t::init( std::size_t size)
{
    RAMEN_ASSERT( !pimpl_.get() && "cuda mem_pool_t::init already called");

	if( initialized())
	{
		try
		{
		    pimpl_.reset( new implementation_t( size));
		}
		catch( cuda::error& e)
		{
		}
	}
}
Esempio n. 28
0
void corner_pin_node_t::param_changed( param_t *p, param_t::change_reason reason)
{
	RAMEN_ASSERT( composition());
	
	if( reason == param_t::user_edited && p == &param( "apply_track"))
	{		
		const tracker_node_t *tracker = ui::apply_corner_track_dialog_t::instance().exec();
		
		if( tracker)
		{
			float2_param_t *topleft		= dynamic_cast<float2_param_t*>( &param( "topleft"));
			float2_param_t *topright	= dynamic_cast<float2_param_t*>( &param( "topright"));
			float2_param_t *botleft		= dynamic_cast<float2_param_t*>( &param( "botleft"));
			float2_param_t *botright	= dynamic_cast<float2_param_t*>( &param( "botright"));
			
			float start_frame = composition()->start_frame();
			float end_frame = composition()->end_frame();
			
			param_set().begin_edit();
			
			for( float frame = start_frame; frame <= end_frame; frame += 1.0f)
			{
				boost::optional<Imath::V2f> p = tracker->tracker_pos( 0, frame);
				
				if( p)
					topleft->set_absolute_value_at_frame( p.get(), frame);

				p = tracker->tracker_pos( 1, frame);
				
				if( p)
					topright->set_absolute_value_at_frame( p.get(), frame);
				
				p = tracker->tracker_pos( 2, frame);

				if( p)
					botright->set_absolute_value_at_frame( p.get(), frame);
				
				p = tracker->tracker_pos( 3, frame);
				
				if( p)
					botleft->set_absolute_value_at_frame( p.get(), frame);
			}
			
			param_set().end_edit();
			update_widgets();
		}
	}
}
Esempio n. 29
0
	virtual void do_draw_overlay( const ui::paint_event_t& event) const
	{
		RAMEN_ASSERT( node()->composition());

		move2d_node_t::matrix3_type lm( param_->matrix_at_frame( node()->composition()->frame(), node()->aspect_ratio()));

		Imath::V2f p = get_absolute_value<Imath::V2f>( param_->center_param());
	    p = p * lm;
		p.x *= node()->aspect_ratio();

		gl_line_width( default_line_width());
	    manipulators::draw_xy_axes( p, 70 / event.pixel_scale, 70 / event.pixel_scale,
									get_value<float>( param_->rotate_param()),
									event.aspect_ratio / node()->aspect_ratio(),
									  ui::palette_t::instance().color("x_axis"),
									  ui::palette_t::instance().color("y_axis"), event.pixel_scale);

	    manipulators::draw_cross( p, 3 / event.pixel_scale, 3 / event.pixel_scale, default_color(), event.pixel_scale);
		manipulators::draw_ellipse( p, 7 / event.pixel_scale, 7 / event.pixel_scale, Imath::Color3c( 255, 255, 255), 20);

		// draw the boundary
		move2d_node_t::matrix3_type gm( node()->global_matrix());
		gm *= move2d_node_t::matrix3_type().setScale( move2d_node_t::vector2_type( node()->aspect_ratio(), 1));

	    Imath::Box2i bbox( node()->format());
		++bbox.max.x;
		++bbox.max.y;

		float offset = manipulators::shadow_offset( event.pixel_scale);
		gl_line_width( manipulator_t::default_line_width());
		gl_point_size( manipulator_t::default_control_point_size());

		// shadow
		gl_color3ub( 0, 0, 0);
	    gl_begin( GL_LINE_LOOP);
			manipulators::gl_transformed_box( bbox, gm, offset);
	    gl_end();

		// color
		gl_color( manipulator_t::default_color());
	    gl_begin( GL_LINE_LOOP);
			manipulators::gl_transformed_box( bbox, gm);
	    gl_end();
	}
Esempio n. 30
0
	float do_kmeans( const std::vector<sample_type>& samples)
	{
		for( int iters = 0; iters < max_iters_; ++iters)
		{
			int num_swaps = assign_nearest_cluster( samples);
			
			if( num_swaps == 0)
				break;

			for( typename std::list<cluster_t>::iterator it( clusters_.begin()); it != clusters_.end(); ++it)
			{
				it->num_samples = 0;
				it->radius = traits_type::zero();
				
				for( int i = 0; i < samples.size(); ++i)
				{
					if( labels_[i] == &(*it))
						it->add_sample( samples[i]);
				}
				
				if( !it->empty())
					it->mean /= it->num_samples;

				for( int i = 0; i < samples.size(); ++i)
				{
					if( labels_[i] == &(*it))
						it->update_radius( samples[i]);
				}					
			}
			
			clusters_.erase( std::remove_if( clusters_.begin(), clusters_.end(),
											boost::bind( &kmeans_t::cluster_t::empty, _1)), clusters_.end());
			
			RAMEN_ASSERT( !clusters_.empty());
		}

		float max_radius = traits_type::zero();
		
		for( const_iterator it( begin()); it != end(); ++it)
			max_radius = std::max( max_radius, it->radius);
		
		return max_radius;
	}