Esempio n. 1
0
void max_jit_str_op_mproc(t_max_jit_str_op *x, void *mop)
{
	long err;
	void *o;
	long ac = 1;
	t_atom a[2];
	t_symbol *s;
	
	o = max_jit_obex_jitob_get(x);
	
	jit_attr_setlong(o, gensym("adaptflag"), jit_attr_getlong(mop, _jit_sym_adapt));
	
	if (err=(t_jit_err) jit_object_method(
		max_jit_obex_jitob_get(x),
		_jit_sym_matrix_calc,
		jit_object_method(mop,_jit_sym_getinputlist),
		jit_object_method(mop,_jit_sym_getoutputlist))) 
	{
		jit_error_code(x,err); 
	} else {
		s = jit_attr_getsym(o, gensym("op"));
		switch(jit_attr_getlong(o, gensym("outmode"))) {
		case 0:
			max_jit_mop_outputmatrix(x);
			break;
		case 2:
			ac = 2;
			jit_atom_setlong(&a[1], jit_attr_getlong(o, gensym("outlong2")));
		case 1:
			jit_atom_setlong(&a[0], jit_attr_getlong(o, gensym("outlong")));
			max_jit_obex_dumpout(x, s, ac, a);
			break;
		}	
	}
}
Esempio n. 2
0
void jit_3m_postcalc(t_jit_3m *x, t_jit_3m_vecdata *vecdata, t_jit_matrix_info *in1_minfo) 
{
	long i;
	
	x->planecount = in1_minfo->planecount;

	if (in1_minfo->type==_jit_sym_char) { 
		for (i=0;i<x->planecount;i++) {
			jit_atom_setlong(&(x->min[i]),vecdata->v_char.min[i]);
			jit_atom_setfloat(&(x->mean[i]),vecdata->v_long.mean[i]); //(hack) use v_long's float mean
			jit_atom_setlong(&(x->max[i]),vecdata->v_char.max[i]);
		}
	} else if (in1_minfo->type==_jit_sym_long) { 
		for (i=0;i<x->planecount;i++) {
			jit_atom_setlong(&(x->min[i]),vecdata->v_long.min[i]);
			jit_atom_setfloat(&(x->mean[i]),vecdata->v_long.mean[i]);
			jit_atom_setlong(&(x->max[i]),vecdata->v_long.max[i]);
		}
	} else if (in1_minfo->type==_jit_sym_float32) { 
		for (i=0;i<x->planecount;i++) {
			jit_atom_setfloat(&(x->min[i]),vecdata->v_float32.min[i]);
			jit_atom_setfloat(&(x->mean[i]),vecdata->v_float32.mean[i]);
			jit_atom_setfloat(&(x->max[i]),vecdata->v_float32.max[i]);
		}
	} else if (in1_minfo->type==_jit_sym_float64) { 
		for (i=0;i<x->planecount;i++) {
			jit_atom_setfloat(&(x->min[i]),vecdata->v_float64.min[i]);
			jit_atom_setfloat(&(x->mean[i]),vecdata->v_float64.mean[i]);
			jit_atom_setfloat(&(x->max[i]),vecdata->v_float64.max[i]);
		}
	}
}
Esempio n. 3
0
void max_jit_op_int(t_max_jit_op *x, long c)
{
	t_atom a;

	jit_atom_setlong(&a,c);
	typedmess(x,_jit_sym_val,1,&a);
}
t_xray_jit_levelsetseg *xray_jit_levelsetseg_new(void)
{
	t_xray_jit_levelsetseg *x;
	void *m;
	t_jit_matrix_info info;
	t_atom a;

	if (x=(t_xray_jit_levelsetseg *)jit_object_alloc(_xray_jit_levelsetseg_class)) {
		x->evolve = 0;
		x->smooth = 0;
		x->point[0] = 160;
		x->point[1] = 120;
		x->pointcount = 2;
		x->radius = 4;
		x->cycles = 7;
		x->Na = 7;
		x->Ng = 3;
		x->Ns = 5;
		x->gaussKernel = NULL;

		jit_atom_setlong(&a, 5);

		xray_jit_levelsetseg_Ng(x, 0L, 1, &a);

		//allocate and initialize linked-list
		DLLcreateList( &(x->L_in) );
		DLLcreateList( &(x->L_out) );

		x->inside = (t_RegionStats *)jit_getbytes(sizeof(t_RegionStats));
		x->outside = (t_RegionStats *)jit_getbytes(sizeof(t_RegionStats));

		sqrtTwoPi = jit_math_sqrt(2*jit_math_acos(-1));

		//setup backgFloat matrix
		jit_matrix_info_default(&info);
		info.type = _jit_sym_char;
		info.planecount = 1;
		x->phiName = jit_symbol_unique();
		m = jit_object_new(_jit_sym_jit_matrix, &info);
		m = jit_object_method(m, _jit_sym_register, x->phiName);

		//Register matrix name
		if(!m) error("could not allocate internal matrix!");
		jit_object_attach(x->phiName, x);
		x->phi = m;
	} else {
		x = NULL;
	}
	return x;
}
Esempio n. 5
0
void max_jit_turtle_reset(t_max_jit_turtle *x)
{
	t_atom a[16];
	short i;
	
	x->curstack = 0;
	x->stacknew = 1;

	for(i=0;i<MAXSTACK;i++) {
		x->thisangle[i] = -PI2/4.; // start facing north (upwards, towards your menubar).
		x->stack_x[i] = x->origin[0];
		x->stack_y[i] = x->origin[1];	
		x->pensize[i]=1;
	}

	jit_atom_setlong(&a[0],x->pensize[x->curstack]);
	jit_atom_setlong(&a[1],x->pensize[x->curstack]);
	outlet_anything(x->turtleout, gensym("pensize"), 2, a);

	// if the 'clearmode' attribute is set have jit.turtle tell the QuickDraw object downstream to clear itself.
	if(x->clearmode) outlet_anything(x->turtleout, gensym("clear"),0,0L);

}
Esempio n. 6
0
t_jit_err jit_gl_hap_loadram(t_jit_gl_hap *x, t_symbol *s, long ac, t_atom *av)
{
	t_atom_long al;
	t_atom_long from = 0, to = 0;
	short unload = (s == gensym("unloadram"));
	t_atom a;
	jit_atom_setlong(&a, 0);
	
	// 1 args end
	// 2 args = start, end
	if (x->movieloaded) {
		switch(ac) {
		case 1:
			if (!jit_atom_arg_getlong(&al, 0, ac, av)) {
				to = (t_atom_long) al;
			}
		case 2:
			if (!jit_atom_arg_getlong(&al, 0, ac, av)) {
				from = (t_atom_long) al; 
			}
			if (!jit_atom_arg_getlong(&al, 1, ac, av)) {
				to = (t_atom_long) al; 
			}
			break;
		default:
			break;
		}
		
		if(!jit_gl_hap_do_loadram(x, from, to, unload)) {
			jit_atom_setlong(&a, 1);
		}
	}
	
	jit_gl_hap_notify_atomarray_prep(x,s,1,&a);
	
	return JIT_ERR_NONE;
}
Esempio n. 7
0
void jit_gl_hap_do_report(t_jit_gl_hap *x)
{
	if(x->movieloaded) {
		t_atom_long curtime = jit_gl_hap_do_get_time(x);
		
		if(x->framereport) {
			t_atom a;
			t_atom_long frame = jit_gl_hap_timetoframe(x, curtime);
			jit_atom_setlong(&a, frame);
			jit_gl_hap_notify_atomarray_prep(x, gensym("framereport"), 1, &a);
		}
		
		if(x->loopreport&&!x->suppress_loopnotify) {					
			if(x->loop == JIT_GL_HAP_LOOP_PALINDROME) {
				if(x->direction) {
					if(curtime<=x->prevtime) {
						jit_gl_hap_looper_notify(x);
					}
				}
				else {
					if(curtime>x->prevtime) {
						jit_gl_hap_looper_notify(x);
					}
				}
			}
			else if(x->loop == JIT_GL_HAP_LOOP_ON){
				if(curtime<x->prevtime && x->rate>0) {
					jit_gl_hap_looper_notify(x);
				}
			}
			else if(x->loop == JIT_GL_HAP_LOOP_OFF) {
				if ((curtime == x->duration) && (curtime>x->prevtime)) {
					jit_gl_hap_looper_notify(x);
				}
			}
		}
		
		if(x->loop == JIT_GL_HAP_LOOP_PALINDROME)
			x->direction = curtime > x->prevtime;
		else
			x->direction = 1;
		
		//jit_attr_user_touch(x, ps_time);
		x->suppress_loopnotify = 0;
		x->prevtime = curtime;
	}
}
Esempio n. 8
0
t_jit_err jit_pcl_freenect_poll_get(t_jit_pcl_freenect *x, void *attr, long *ac, t_atom **av)
{
    if ((*ac)&&(*av)) {
        //memory passed in, use it
    } else {
        //otherwise allocate memory
        *ac = 1;
        *av = (t_atom *)jit_getbytes( sizeof(t_atom) * (*ac) );
        if ( !(*av) )
        {
            *ac = 0;
            return JIT_ERR_OUT_OF_MEM;
        }
    }
    jit_atom_setlong(*av, x->enable);
    return JIT_ERR_NONE;
}
Esempio n. 9
0
t_jit_err jit_gl_lua_getmemsize(t_jit_gl_lua *x, void *attr, long *argc, t_atom **argv)
{
	if ((*argc)&&(*argv)) {
		//memory passed in, use it
	} else {
		//otherwise allocate memory
		*argc = 1;
		if (!(*argv = (t_atom *)jit_getbytes(sizeof(t_atom)*(*argc)))) {
			*argc = 0;
			return JIT_ERR_OUT_OF_MEM;
		}
	}
	
	x->memsize = lua_gc(x->lua, LUA_GCCOUNT, 0);
	jit_atom_setlong(*argv, x->memsize);

	return JIT_ERR_NONE;
}
Esempio n. 10
0
t_jit_err jit_gl_lua_getcontext(t_jit_gl_lua *x, void *attr, long *argc, t_atom **argv)
{
	if ((*argc)&&(*argv)) {
		//memory passed in, use it
	} else {
		//otherwise allocate memory
		*argc = 1;
		if (!(*argv = (t_atom *)jit_getbytes(sizeof(t_atom)*(*argc)))) {
			*argc = 0;
			return JIT_ERR_OUT_OF_MEM;
		}
	}
	
	x->context = (long)(x->drawinfo.ctx);
	jit_atom_setlong(*argv, x->context);

	return JIT_ERR_NONE;
}
Esempio n. 11
0
t_jit_err jit_gl_hap_time_get(t_jit_gl_hap *x, void *attr, long *ac, t_atom **av) 
{
	if ((*ac)&&(*av)) {
		//memory passed in, use it
	} else {
		//otherwise allocate memory
		*ac = 1;
		if (!(*av = jit_getbytes(sizeof(t_atom)*(*ac)))) {
			*ac = 0;
			return JIT_ERR_OUT_OF_MEM;
		}
	}
	jit_atom_setlong(*av,0);
	
	if (x->movieloaded) {
		(*av)->a_w.w_long = jit_gl_hap_do_get_time(x);
	}
	return JIT_ERR_NONE;
}
Esempio n. 12
0
void *max_jit_op_new(t_symbol *s, long argc, t_atom *argv)
{
	t_max_jit_op *x;
	void *o;
	long i;

	if (x=(t_max_jit_op *)max_jit_obex_new(max_jit_op_class,gensym("jit_op"))) {
		if (o=jit_object_new(gensym("jit_op"))) {
			max_jit_mop_setup_simple(x,o,argc,argv);			
			x->last = OP_LAST_MATRIX;
			x->valcount = 0;
			for (i=0;i<JIT_MATRIX_MAX_PLANECOUNT;i++) 
				jit_atom_setlong(&x->val[i],0);
			max_jit_attr_args(x,argc,argv);
		} else {
			jit_object_error((t_object *)x,"jit.op: could not allocate object");
			freeobject(x);
			x = NULL;
		}
	}
	return (x);
}
Esempio n. 13
0
void jit_gl_hap_read(t_jit_gl_hap *x, t_symbol *s, long ac, t_atom *av)
{
	t_atom a[2];
	char fname[MAX_FILENAME_CHARS] = "";
	short vol;
	t_fourcc type;
	short ret;
	
	x->newfile = 0;
	
	if (ac && av) {
		strcpy(fname, atom_getsym(av)->s_name);
		ret = locatefile_extended(fname, &vol, &type, NULL, 0);			
	} else {
		ret = open_dialog(fname, &vol, &type, NULL, 0); // limit to movie files?
	}

	if (!ret) {
		jit_gl_hap_read_native(x, fname, vol);
		
		if(x->newfile) {
			jit_attr_user_touch(x, gensym("fps"));
			jit_attr_user_touch(x, gensym("duration"));
			jit_attr_user_touch(x, gensym("timescale"));
			jit_attr_user_touch(x, gensym("framecount"));
				
			// if user didn't modify looppoints, reset them
			//if(!x->userloop) {
				x->looppoints[0] = x->looppoints[1] = -1;
			//}
			// set attributes here
			jit_gl_hap_do_loop(x);
			// rate must init after playback starts
		}
	}
	jit_atom_setsym(a, x->file);
	jit_atom_setlong(a+1, x->newfile ? 1 : 0);	
	defer_low(x, (method)jit_gl_hap_notify_atomarray_prep, s, 2, a);	
}
Esempio n. 14
0
t_jit_err jit_charmap_init(void) 
{	
	t_atom a;
	void *o,*mop;
	
	_jit_charmap_class = jit_class_new("jit_charmap",(method)jit_charmap_new,(method)jit_charmap_free,
		sizeof(t_jit_charmap),0L);
	
	//add mop
	mop = jit_object_new(_jit_sym_jit_mop,2,1);
	jit_mop_single_type(mop,_jit_sym_char);	
	o = jit_object_method(mop,_jit_sym_getinput,2);
	jit_attr_setlong(o,_jit_sym_dimlink,0);
	jit_atom_setlong(&a,256);
	jit_object_method(o,_jit_sym_mindim,1,&a);
	jit_object_method(o,_jit_sym_maxdim,1,&a);
	jit_class_addadornment(_jit_charmap_class,mop);
	//add methods
	jit_class_addmethod(_jit_charmap_class, (method)jit_charmap_matrix_calc, 		"matrix_calc", 		A_CANT, 0L);

	jit_class_register(_jit_charmap_class);

	return JIT_ERR_NONE;
}
Esempio n. 15
0
t_jit_err jit_freenect_grab_get_ndevices(t_jit_freenect_grab *x, void *attr, long *ac, t_atom **av){
	
	if ((*ac)&&(*av)) {
		
	} else {
		*ac = 1;
		if (!(*av = jit_getbytes(sizeof(t_atom)*(*ac)))) {
			*ac = 0;
			return JIT_ERR_OUT_OF_MEM;
		}
	}
	
	if(f_ctx){
		x->ndevices = freenect_num_devices(f_ctx);
	}
	else{
		x->ndevices = 0;
	}
	
	
	jit_atom_setlong(*av,x->ndevices);
	
	return JIT_ERR_NONE;
}
Esempio n. 16
0
t_cv_jit_shift *cv_jit_shift_new(void)
{
	t_cv_jit_shift *x;

	if (x=(t_cv_jit_shift *)jit_object_alloc(_cv_jit_shift_class)) 
	{
		x->epsilon = 2;
		x->maxiters = 10;
		x->rect[0] = x->rect[1] = x->rect[2] = x->rect[3] = 0;
		x->boxcount = 4;
		x->rectcount = 4;
		x->mode = 0;
		jit_atom_setlong(&x->box[0],0);
		jit_atom_setlong(&x->box[1],0);
		jit_atom_setlong(&x->box[2],0);
		jit_atom_setlong(&x->box[3],0);
		x->framecount = 8;
		jit_atom_setlong(&x->frame[0],0);
		jit_atom_setlong(&x->frame[1],0);
		jit_atom_setlong(&x->frame[2],0);
		jit_atom_setlong(&x->frame[3],0);
		jit_atom_setlong(&x->frame[4],0);
		jit_atom_setlong(&x->frame[5],0);
		jit_atom_setlong(&x->frame[6],0);
		jit_atom_setlong(&x->frame[7],0);
		x->mass = 0;
		
	} else {
		x = NULL;
	}	
	return x;
}
Esempio n. 17
0
t_jit_err cv_jit_shift_matrix_calc(t_cv_jit_shift *x, void *inputs, void *outputs)
{
	t_jit_err			err=JIT_ERR_NONE;
	long				in_savelock = 0;
	t_jit_matrix_info	in_minfo;
	void				*in_matrix;
	CvMat				source;
	CvRect				rectangle;
	CvBox2D				box;
	CvConnectedComp		component;
	CvPoint2D32f		vertices[4];
	float				w,h,c,s;
	
	//Get pointer to matrix
	in_matrix 	= jit_object_method(inputs,_jit_sym_getindex,0);

	if (x&&in_matrix) 
	{
		//Lock the matrix
		in_savelock = (long) jit_object_method(in_matrix,_jit_sym_lock,1);
		
		//Make sure input is of proper format
		jit_object_method(in_matrix,_jit_sym_getinfo,&in_minfo);

		if(in_minfo.dimcount != 2)
		{
			err = JIT_ERR_MISMATCH_DIM;
			goto out;
		}
		if(in_minfo.planecount != 1)
		{
			err = JIT_ERR_MISMATCH_PLANE;
			goto out;
		}
		if(in_minfo.type != _jit_sym_char)
		{
			err = JIT_ERR_MISMATCH_TYPE;
			goto out;
		}

		//Don't process if image is too small
		if((in_minfo.dim[0] < 2)||(in_minfo.dim[1] < 2))
			goto out;
			
		//Calculate start rectangle:
		rectangle = cvRect(x->rect[0],x->rect[1],x->rect[2]-x->rect[0],x->rect[3]-x->rect[1]);
		CLIP_ASSIGN(rectangle.x,0,in_minfo.dim[0]-1);
		CLIP_ASSIGN(rectangle.y,0,in_minfo.dim[1]-1);
		CLIP_ASSIGN(rectangle.width,1,in_minfo.dim[0]-rectangle.x);
		CLIP_ASSIGN(rectangle.height,1,in_minfo.dim[1]-rectangle.y);

		//Convert Jitter matrix to OpenCV matrix
		cvJitter2CvMat(in_matrix, &source);
		
		//Calculate camshift
		if(x->mode == 1) //Use camshift
			cvCamShift(&source, rectangle, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,(int)x->maxiters,x->epsilon), &component, &box );
		else {
			cvMeanShift(&source, rectangle, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,(int)x->maxiters,x->epsilon), &component);
			box.angle = 90.f;
			box.size = cvSize2D32f(component.rect.width, component.rect.height);
			box.center = cvPoint2D32f((float)component.rect.x + (float)component.rect.width * 0.5f,(float)component.rect.y + (float)component.rect.height * 0.5f);
		}
		
		//Prepare output
		//
		jit_atom_setlong(&x->box[0],component.rect.x);
		jit_atom_setlong(&x->box[1],component.rect.y);
		jit_atom_setlong(&x->box[2],component.rect.x + component.rect.width);
		jit_atom_setlong(&x->box[3],component.rect.y + component.rect.height);
		
		x->rect[0]=component.rect.x;
		x->rect[1]=component.rect.y;
		x->rect[2]=component.rect.x + component.rect.width;
		x->rect[3]=component.rect.y + component.rect.height;
		
		//cvBoxPoints(box,vertices);
		w = box.size.width * 0.5;
		h = box.size.height * 0.5;
		c = cos((box.angle - 90.f) * -0.01745329252);
		s = sin((box.angle - 90.f) * -0.01745329252);
		
		vertices[0].x = box.center.x - s*h - c*w;
		vertices[0].y = box.center.y - c*h + s*w;
		vertices[1].x = box.center.x - s*h + c*w;
		vertices[1].y = box.center.y - c*h - s*w;
		vertices[2].x = box.center.x + s*h + c*w;
		vertices[2].y = box.center.y + c*h - s*w;
		vertices[3].x = box.center.x + s*h - c*w;
		vertices[3].y = box.center.y + c*h + s*w;
		
		jit_atom_setlong(&x->frame[0],(long)vertices[0].x);
		jit_atom_setlong(&x->frame[1],(long)vertices[0].y);
		jit_atom_setlong(&x->frame[2],(long)vertices[1].x);
		jit_atom_setlong(&x->frame[3],(long)vertices[1].y);
		jit_atom_setlong(&x->frame[4],(long)vertices[2].x);
		jit_atom_setlong(&x->frame[5],(long)vertices[2].y);
		jit_atom_setlong(&x->frame[6],(long)vertices[3].x);
		jit_atom_setlong(&x->frame[7],(long)vertices[3].y);
		
		x->mass = (float)(component.area / 256.);
		}
	
out:
	jit_object_method(in_matrix,gensym("lock"),in_savelock);
	return err;
}
Esempio n. 18
0
t_jit_err xray_jit_levelsetseg_matrix_calc(t_xray_jit_levelsetseg *x, void *inputs, void *outputs)
{
	t_jit_err err=JIT_ERR_NONE;
	long in1_savelock, out1_savelock, out2_savelock;
	t_jit_matrix_info in1_minfo, out1_minfo, out2_minfo;
	char *in1_bp, *out1_bp, *out2_bp;
	long i,dimcount,planecount,dim[JIT_MATRIX_MAX_DIMCOUNT];
	void *in1_matrix, *out1_matrix, *out2_matrix;

	long phi_savelock;
	t_jit_matrix_info phi_minfo;
	char *phi_bp;

	t_atom a;

	in1_matrix 	= jit_object_method(inputs,_jit_sym_getindex,0);
	out1_matrix = jit_object_method(outputs,_jit_sym_getindex,0);
	out2_matrix = jit_object_method(outputs,_jit_sym_getindex,1);

	if (x&&in1_matrix&&out1_matrix&&out2_matrix) {
		in1_savelock = (long) jit_object_method(in1_matrix,_jit_sym_lock,1);
		out1_savelock = (long) jit_object_method(out1_matrix,_jit_sym_lock,1);
		out2_savelock = (long) jit_object_method(out2_matrix,_jit_sym_lock,1);

		jit_object_method(in1_matrix,_jit_sym_getinfo,&in1_minfo);
		jit_object_method(out1_matrix,_jit_sym_getinfo,&out1_minfo);
		jit_object_method(out2_matrix,_jit_sym_getinfo,&out2_minfo);


		out1_minfo.dim[0] = in1_minfo.dim[0];
		out1_minfo.dim[1] = in1_minfo.dim[1];
		out1_minfo.planecount = 1;
		out1_minfo.type = _jit_sym_float32;

		jit_object_method(out1_matrix,_jit_sym_setinfo,&out1_minfo);
		jit_object_method(out1_matrix,_jit_sym_getinfo,&out1_minfo);
		jit_object_method(out1_matrix,_jit_sym_getdata,&out1_bp);


		jit_object_method(in1_matrix,_jit_sym_getdata,&in1_bp);
		jit_object_method(out2_matrix,_jit_sym_getdata,&out2_bp);

		phi_savelock = (long) jit_object_method(x->phi,_jit_sym_lock,1);
		jit_object_method(x->phi,_jit_sym_getinfo,&phi_minfo);

		if( !(x->evolve) ) {
			phi_minfo.dim[0] = in1_minfo.dim[0];
			phi_minfo.dim[1] = in1_minfo.dim[1];
			phi_minfo.planecount = 1;
			phi_minfo.type = _jit_sym_char;

			jit_object_method(x->phi,_jit_sym_setinfo,&phi_minfo);
			jit_object_method(x->phi,_jit_sym_getinfo,&phi_minfo);

			//init phi to have all pixels as exterior pixels
			jit_atom_setlong(&a, EXTERIOR);
			jit_object_method(x->phi, _jit_sym_setall, _jit_sym_setall, 1, &a);
		}

		jit_object_method(x->phi,_jit_sym_getdata,&phi_bp);

		if (!in1_bp)		{ err=JIT_ERR_INVALID_INPUT; goto out;}
		if (!out2_bp)		{ err=JIT_ERR_INVALID_OUTPUT; goto out;}

		//get dimensions/planecount
		dimcount   = out1_minfo.dimcount;
		planecount = out1_minfo.planecount;

		for (i=0;i<dimcount;i++) {
			dim[i] = out1_minfo.dim[i];
		}

		xray_jit_levelsetseg_calculate_ndim(x, dimcount, dim, planecount, &in1_minfo, in1_bp,
			&phi_minfo, phi_bp, &out1_minfo, out1_bp, &out2_minfo, out2_bp);



		//makeLines(x, out1_minfo, out1_bp);

	} else {
		return JIT_ERR_INVALID_PTR;
	}

out:
	jit_object_method(x->phi,gensym("lock"),phi_savelock);
	jit_object_method(out2_matrix,gensym("lock"),out2_savelock);
	jit_object_method(out1_matrix,gensym("lock"),out1_savelock);
	jit_object_method(in1_matrix,gensym("lock"),in1_savelock);
	return err;
}
Esempio n. 19
0
void max_jit_turtle_int(t_max_jit_turtle *x, long n)
{
	t_atom a[16];
	double tempangle;
	double temp_x, temp_y;
	long dest_x, dest_y;
	long curstack = x->curstack;

	x->command = n; // why do we do this?  i can't remember...

	// check to see if the integer received matches the ASCII code for one of these commands.
	// if so, compute the appropriate QuickDraw response and pass it out the outlet as a Max message.
	switch(n) {
		case (35): // '#' - increase pen size	
			x->pensize[curstack] = x->pensize[curstack]+1;
			jit_atom_setlong(&a[0],x->pensize[curstack]);
			jit_atom_setlong(&a[1],x->pensize[curstack]);
			outlet_anything(x->turtleout, gensym("pensize"), 2, a);
			break;
		case (33): // '!' - decrease pen size
			if(x->pensize[curstack]>1) x->pensize[curstack] = x->pensize[curstack]-1;
			jit_atom_setlong(&a[0],x->pensize[curstack]);
			jit_atom_setlong(&a[1],x->pensize[curstack]);
			outlet_anything(x->turtleout, gensym("pensize"), 2, a);
			break;
		case (70): // 'F' - move forward and draw
			if(x->stacknew) {
				x->stack_x[curstack] = x->origin[0];
				x->stack_y[curstack] = x->origin[1];
				x->stacknew=0;
			}
			temp_x = (double)x->scale*jit_math_cos(x->thisangle[curstack]);
			temp_y = (double)x->scale*jit_math_sin(x->thisangle[curstack]);
			dest_x = x->stack_x[curstack]+temp_x+0.5;
			dest_y = x->stack_y[curstack]+temp_y+0.5;
			jit_atom_setlong(&a[0],x->stack_x[curstack]);
			jit_atom_setlong(&a[1],x->stack_y[curstack]);
			jit_atom_setlong(&a[2],dest_x);
			jit_atom_setlong(&a[3],dest_y);
			outlet_anything(x->turtleout, gensym("linesegment"), 4, a);
			x->stack_x[curstack] = dest_x;
			x->stack_y[curstack] = dest_y;			
			break;
		case (102): // 'f' - move forward and don't draw	
			if(x->stacknew) {
				x->stack_x[curstack] = x->origin[0];
				x->stack_y[curstack] = x->origin[1];
				x->stacknew=0;
			}
			temp_x = (double)x->scale*jit_math_cos(x->thisangle[curstack]);
			temp_y = (double)x->scale*jit_math_sin(x->thisangle[curstack]);
			dest_x = x->stack_x[curstack]+temp_x+0.5;
			dest_y = x->stack_y[curstack]+temp_y+0.5;
			x->stack_x[curstack] = dest_x;
			x->stack_y[curstack] = dest_y;			
			break;
		case (91): // '[' - start a branch
			if(x->curstack>(MAXSTACK-2)) { // you can uncomment this jit_object_post((t_object *)x,) if you prefer... it's kind of annoying, IMHO.
				// jit_object_post((t_object *)x,"out of stack range -- not branching");
			}
			else {
				// copy current coords and angle to next branch and increment the stack
				x->stack_x[curstack+1] = x->stack_x[curstack];
				x->stack_y[curstack+1] = x->stack_y[curstack];
				x->thisangle[curstack+1] = x->thisangle[curstack];
				x->curstack++;			
			}
			break;
		case (93): // ']' - end a branch and decrement the stack
			if(curstack>0) x->curstack--;
			break;
		case (43): // '+' - turn right
			x->thisangle[curstack]+=((x->angle/360.)*PI2);
			break;
		case (45): // '-' - turn left
			x->thisangle[curstack]-=((x->angle/360.)*PI2);
			break;
		case (124): // '|' - turn around
			x->thisangle[curstack]+=(0.5*PI2);
			break;
		default: // no match, don't do anything
		break;
	}
}
Esempio n. 20
0
t_jit_err jit_glue_matrix_calc(t_jit_glue *x, void *inputs, void *outputs)
{
	t_jit_err err=JIT_ERR_NONE;
	long in_savelock,out_savelock, dimmode;
	t_jit_matrix_info in_minfo,out_minfo;
	char *in_bp,*out_bp;
	long i,dimcount,planecount,dim[JIT_MATRIX_MAX_DIMCOUNT];
	t_atom a[2];
	t_matrix_conv_info conv;
	long rows=x->rows,cols=x->cols,n=x->input;
	void *in_matrix,*out_matrix;
	
	in_matrix 	= jit_object_method(inputs,_jit_sym_getindex,0);
	out_matrix 	= jit_object_method(outputs,_jit_sym_getindex,0);

	if (x&&in_matrix&&out_matrix) {
		
		in_savelock = (long) jit_object_method(in_matrix,_jit_sym_lock,1);
		out_savelock = (long) jit_object_method(out_matrix,_jit_sym_lock,1);
		
		jit_object_method(in_matrix,_jit_sym_getinfo,&in_minfo);
		jit_object_method(out_matrix,_jit_sym_getinfo,&out_minfo);
		
		jit_object_method(in_matrix,_jit_sym_getdata,&in_bp);
		jit_object_method(out_matrix,_jit_sym_getdata,&out_bp);
		
		if (!in_bp) { err=JIT_ERR_INVALID_INPUT; goto out;}
		if (!out_bp) { err=JIT_ERR_INVALID_OUTPUT; goto out;}
				
		//compatible types?
		if (in_minfo.type!=out_minfo.type) { 
			err=JIT_ERR_MISMATCH_TYPE; 
			goto out;
		}		

		//compatible planes?
		if ((in_minfo.planecount!=out_minfo.planecount)) { 
			err=JIT_ERR_MISMATCH_PLANE; 
			goto out;
		}		

		//compatible dims?
		if ((in_minfo.dimcount!=2)||(out_minfo.dimcount!=2)) { 
			err=JIT_ERR_MISMATCH_DIM; 
			goto out;
		}		

		//get dimensions/planecount

		if (rows<1) rows=1;
		if (rows>16) rows=16;
		if (cols<1) cols=1;
		if (cols>16) cols=16;

		if (n>=(rows*cols)) goto out;
		
		dimcount   = out_minfo.dimcount;
		planecount = out_minfo.planecount;			
		dim[0] = in_minfo.dim[0]*cols;
		dim[1] = in_minfo.dim[1]*rows;

		if((out_minfo.dim[0]!=dim[0]) || (out_minfo.dim[1]!=dim[1])) {
			jit_atom_setlong(&a[0], dim[0]);
			jit_atom_setlong(&a[1], dim[1]);	
			jit_object_method(out_matrix, _jit_sym_dim, 2, a);
		
		}
		
		setmem(&conv,sizeof(t_matrix_conv_info),0);
		for(i=0;i<JIT_MATRIX_MAX_PLANECOUNT;i++) {
			conv.planemap[i] = i;
		}
		
		conv.flags = JIT_MATRIX_CONVERT_SRCDIM | JIT_MATRIX_CONVERT_DSTDIM;
				
		conv.srcdimstart[0] = 0;
		conv.srcdimstart[1] = 0;
		conv.srcdimend[0] = in_minfo.dim[0]-1;
		conv.srcdimend[1] = in_minfo.dim[1]-1;
		
		conv.dstdimstart[0] = in_minfo.dim[0]*(n%cols);
		conv.dstdimstart[1] = (in_minfo.dim[1]*(n/cols));
		conv.dstdimend[0] = conv.dstdimstart[0]+in_minfo.dim[0]-1;
		conv.dstdimend[1] = conv.dstdimstart[1]+in_minfo.dim[1]-1;
		
//		jit_object_post((t_object *)x,"compositing %i from %i %i %i %i to %i %i %i %i", n, conv.srcdimstart[0], conv.srcdimstart[1], conv.srcdimend[0], conv.srcdimend[1], conv.dstdimstart[0], conv.dstdimstart[1], conv.dstdimend[0], conv.dstdimend[1]);
				
		jit_object_method(out_matrix, _jit_sym_frommatrix, in_matrix, &conv);

	} else {
		return JIT_ERR_INVALID_PTR;
	}
	
out:
	jit_object_method(out_matrix,_jit_sym_lock,out_savelock);
	jit_object_method(in_matrix,_jit_sym_lock,in_savelock);
	return err;
}
Esempio n. 21
0
t_jit_err jit_freenect_grab_init(void)
{
	long attrflags=0;
	t_jit_object *attr;
	t_jit_object *mop,*output;
	t_atom a[4];
	
	global_id=0;
	x_systhread = NULL;
	x_systhread_cancel=FALSE;
	freenect_active=FALSE;
	open_device_count=0;
	
	s_rgb = gensym("rgb");
	s_RGB = gensym("RGB");
	s_ir = gensym("ir");
	s_IR = gensym("IR");
	
	_jit_freenect_grab_class = jit_class_new("jit_freenect_grab",(method)jit_freenect_grab_new,
											 (method)jit_freenect_grab_free, sizeof(t_jit_freenect_grab),0L);
  	
	//add mop
	mop = (t_jit_object *)jit_object_new(_jit_sym_jit_mop,0,2); //0 inputs, 2 outputs
	
	//Prepare depth image, all values are hard-coded, may need to be queried for safety?
	output = jit_object_method(mop,_jit_sym_getoutput,1);
		
	jit_atom_setsym(a,_jit_sym_float32); //default
	jit_atom_setsym(a+1,_jit_sym_long);
	jit_atom_setsym(a+2,_jit_sym_float64);
	jit_object_method(output,_jit_sym_types,3,a);
	
	jit_atom_setlong(&a[0], DEPTH_WIDTH);
	jit_atom_setlong(&a[1], DEPTH_HEIGHT);
	
	jit_object_method(output, _jit_sym_mindim, 2, a);  //Two dimensions, sizes in atom array
	jit_object_method(output, _jit_sym_maxdim, 2, a);
	
	//Prepare RGB image
	output = jit_object_method(mop,_jit_sym_getoutput,2);
	
	jit_atom_setsym(a,_jit_sym_char); //default
	jit_object_method(output,_jit_sym_types,1,a);
	
	jit_attr_setlong(output,_jit_sym_minplanecount,4);
	jit_attr_setlong(output,_jit_sym_maxplanecount,4);
	
	jit_atom_setlong(&a[0], RGB_WIDTH);
	jit_atom_setlong(&a[1], RGB_HEIGHT);
	
	jit_object_method(output, _jit_sym_mindim, 2, a);
	jit_object_method(output, _jit_sym_maxdim, 2, a);
	
	jit_class_addadornment(_jit_freenect_grab_class,mop);
	
	//add methods
	jit_class_addmethod(_jit_freenect_grab_class, (method)jit_freenect_grab_open, "open", A_GIMME, 0L);
	jit_class_addmethod(_jit_freenect_grab_class, (method)jit_freenect_grab_close, "close", A_GIMME, 0L);
	
	jit_class_addmethod(_jit_freenect_grab_class, (method)jit_freenect_grab_matrix_calc, "matrix_calc", A_CANT, 0L);
	
	//add attributes	
	attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_USURP_LOW;
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"unique",_jit_sym_char,
										  attrflags,(method)NULL,(method)NULL,calcoffset(t_jit_freenect_grab,unique));
	jit_attr_addfilterset_clip(attr,0,1,TRUE,TRUE);
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"threshold",_jit_sym_float32,
										  attrflags,(method)NULL,(method)NULL,calcoffset(t_jit_freenect_grab,threshold));
	jit_attr_addfilterset_clip(attr,0,0,TRUE,FALSE);
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	//attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_USURP_LOW;
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"cleardepth",_jit_sym_char,
										  attrflags,(method)NULL,(method)NULL,calcoffset(t_jit_freenect_grab,clear_depth));
	jit_attr_addfilterset_clip(attr,0,1,TRUE,TRUE);
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"mode",_jit_sym_char,
										  attrflags,(method)NULL,(method)jit_freenect_grab_set_mode,calcoffset(t_jit_freenect_grab,mode));
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"format",_jit_sym_atom,
										  attrflags,(method)NULL,(method)jit_freenect_grab_set_format,calcoffset(t_jit_freenect_grab,format));
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"tilt",_jit_sym_long,
										  attrflags,(method)jit_freenect_grab_get_tilt,(method)jit_freenect_grab_set_tilt,
										  calcoffset(t_jit_freenect_grab,tilt));
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"aligndepth",_jit_sym_char,
										  attrflags,(method)NULL,(method)NULL,calcoffset(t_jit_freenect_grab,aligndepth));
	jit_attr_addfilterset_clip(attr,0,1,TRUE,TRUE);
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_OPAQUE;
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"index",_jit_sym_long,
										  attrflags,(method)NULL,(method)NULL,calcoffset(t_jit_freenect_grab,index));
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"ndevices",_jit_sym_long,
										  attrflags,(method)jit_freenect_grab_get_ndevices,(method)NULL,calcoffset(t_jit_freenect_grab,ndevices));
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset_array, "accel", _jit_sym_float64, 3, 
										  attrflags, (method)jit_freenect_grab_get_accel,(method)NULL, 
										  calcoffset(t_jit_freenect_grab, accelcount),calcoffset(t_jit_freenect_grab,mks_accel));
	jit_class_addattr(_jit_freenect_grab_class,attr);

	
	attrflags = JIT_ATTR_GET_OPAQUE_USER | JIT_ATTR_SET_OPAQUE_USER;
	attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,"has_frames",_jit_sym_char,
										  attrflags,(method)NULL,(method)NULL,calcoffset(t_jit_freenect_grab,has_frames));
	jit_class_addattr(_jit_freenect_grab_class,attr);
	
	jit_class_register(_jit_freenect_grab_class);
	
	post("jit.freenect.grab: Copyright 2010, Jean-Marc Pelletier, Nenad Popov and Andrew Roth. Built on %s",DEBUG_TIMESTAMP);
	return JIT_ERR_NONE;
}