void jit_freenect_grab_set_format(t_jit_freenect_grab *x,  void *attr, long argc, t_atom *argv){
	if(argc){
		t_atom a;
		if(argv->a_type == A_SYM){
			if((argv->a_w.w_sym == s_rgb)||((argv->a_w.w_sym == s_RGB))){
				jit_atom_setsym(&a, s_rgb);
			}
			else if((argv->a_w.w_sym == s_ir)||((argv->a_w.w_sym == s_IR))){
				jit_atom_setsym(&a, s_ir);
			}
			else{
				error("Invalid output format: %s", argv->a_w.w_sym->s_name);
				return;
			}
		}
		else{
			long v = jit_atom_getlong(argv);
			if(v <= 0){
				jit_atom_setsym(&a, s_rgb);
			}
			else{
				jit_atom_setsym(&a, s_ir);
			}
		}
		if(argv->a_w.w_sym == x->format.a_w.w_sym)return;
		
		x->format = a;
		
		if(x->device){
			/*
			if(x->format.a_w.w_sym == s_ir){
				freenect_set_video_format(x->device, FREENECT_VIDEO_IR_8BIT);
			}
			else{
				freenect_set_video_format(x->device, FREENECT_VIDEO_RGB);
			}
			*/
			/*
			t_atom arg;
			jit_atom_setlong(&arg, x->index);
			jit_freenect_grab_close(x, NULL, 0, NULL);
			jit_freenect_grab_open(x, NULL, 1, &arg);
			 */
			//jit_freenect_grab_close(x, NULL, 0, NULL);
			error("jit.freenect.grab: Cannot change output format while running. Please close and re-open device to activate change.");
		}
		
		
	}
}
Beispiel #2
0
t_jit_err jit_print_planedelim_get(t_jit_print *x, void *attr, long *ac, t_atom **av)
{
	char temp[2] = "";
	char *tmp = temp;
	t_symbol *tempsym;

	if ((*ac)&&(*av)) {
		;
	} else {
		*ac = 1;
		if (!(*av=jit_getbytes(sizeof(t_atom) * (*ac)))) {
			*ac = 0;
			return JIT_ERR_OUT_OF_MEM;
		}
	}

	temp[0] = x->planedelim->s_name[0];

	if (temp[0] == '\t')
		tempsym = ps_tab;
	else if (temp[0] == '\r')
		tempsym = ps_cr;
	else if (temp[0] == 32)
		tempsym = ps_space;
	else
		tempsym = gensym(tmp);

	jit_atom_setsym(*av, tempsym);
	return JIT_ERR_NONE;
}
Beispiel #3
0
t_jit_err max_jit_gradient_outputmatrix(t_max_jit_gradient *x)
{
	void *mop,*o,*p;
	long err=JIT_ERR_NONE;
	t_atom a;
	
	if (!(mop=max_jit_obex_adornment_get(x,_jit_sym_jit_mop)))
		return JIT_ERR_GENERIC;
	if (jit_attr_getlong(mop,_jit_sym_outputmode)) {
		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 {

			if ((p=jit_object_method(mop,_jit_sym_getoutput,1)) &&
				(o=max_jit_mop_io_getoutlet(p))) 
			{
				jit_atom_setsym(&a,jit_attr_getsym(p,_jit_sym_matrixname)); 
				outlet_anything(o,_jit_sym_jit_matrix,1,&a);
			}
		}
	}
	return err;
}
Beispiel #4
0
void max_jit_print_jit_matrix(t_max_jit_print *x, t_symbol *s, long argc, t_atom *argv)
{
	void *matrix;
	t_atom a;
	long err;

	if (argc&&argv) {
		//find matrix
		matrix = jit_object_findregistered(jit_atom_getsym(argv));
		if (matrix&&jit_object_method(matrix, _jit_sym_class_jit_matrix)) {
			if (err = jit_print_matrix_calc(max_jit_obex_jitob_get(x), matrix)) {
				jit_object_post((t_object *)x,"err: %d", err);
				jit_error_code(x,err);
			}
			jit_atom_setsym(&a,jit_atom_getsym(argv));
		} 
		else {
			jit_error_code(x,JIT_ERR_MATRIX_UNKNOWN);
		}
		outlet_anything(x->matrixout,s,1,&a);
	}
	else return;
out:
	return;
}
t_jit_err xray_jit_crossproduct_init(void)
{
	long attrflags=0;
	t_jit_object *attr,*mop;
	t_symbol *atsym;
	void *o;
	t_atom a[2];

	atsym = gensym("jit_attr_offset");

	_xray_jit_crossproduct_class = jit_class_new("xray_jit_crossproduct",(method)xray_jit_crossproduct_new,(method)xray_jit_crossproduct_free,
		sizeof(t_xray_jit_crossproduct),0L);

	//add mop
	mop = jit_object_new(_jit_sym_jit_mop,2,1);
	jit_atom_setsym(a, _jit_sym_float32);
	jit_atom_setsym(a+1, _jit_sym_float64);

	o = jit_object_method(mop,_jit_sym_getinput,1);
	jit_object_method(o,_jit_sym_types,2,a);

	o = jit_object_method(mop,_jit_sym_getinput,2);
	jit_object_method(o,_jit_sym_types,2,a);

	o = jit_object_method(mop,_jit_sym_getoutput,1);
	jit_object_method(o,_jit_sym_types,2,a);

	jit_class_addadornment(_xray_jit_crossproduct_class,mop);

	//add methods
	jit_class_addmethod(_xray_jit_crossproduct_class, (method)xray_jit_crossproduct_matrix_calc, 		"matrix_calc", 		A_CANT, 0L);

	//add attributes
	attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_USURP_LOW;

	//normalize
	attr = jit_object_new(_jit_sym_jit_attr_offset_array,"normalize",_jit_sym_char,2,attrflags,
		(method)0L,(method)0L,calcoffset(t_xray_jit_crossproduct,normalizecount),calcoffset(t_xray_jit_crossproduct,normalize));
	jit_class_addattr(_xray_jit_crossproduct_class,attr);

	jit_class_register(_xray_jit_crossproduct_class);

	return JIT_ERR_NONE;
}
t_jit_freenect_grab *jit_freenect_grab_new(void)
{
	t_jit_freenect_grab *x;
	
	if ((x=(t_jit_freenect_grab *)jit_object_alloc(_jit_freenect_grab_class)))
	{
		x->device = NULL;
		x->timestamp = 0;
		x->unique = 0;
		x->aligndepth = 0;
		x->mode = 3;
		x->has_frames = 0;
		x->ndevices = 0;
		x->lut.f_ptr = NULL;
		x->lut_type = NULL;
		x->tilt = 0;
		x->state = NULL;
		x->clear_depth = 0;
		x->type = NULL;
		x->threshold = 2.f;
		x->rgb = NULL;
        
		//x->x_systhread = NULL;
		x->backbuffer_mutex = NULL;
		x->x_sleeptime = 10;
		systhread_mutex_new(&x->backbuffer_mutex, 0);
		x->got_rgb=0;
		x->got_depth=0;
		x->depth_mid=NULL;
		x->depth_front=NULL;
		x->rgb_front=NULL;
		x->rgb_back=NULL;
		x->rgb_mid=NULL;
		x->depth_back=NULL;
		
		
		x->depth_back = (uint16_t*)malloc(DEPTH_WIDTH*DEPTH_HEIGHT*DEPTH_BPP);
		x->depth_mid = (uint16_t*)malloc(DEPTH_WIDTH*DEPTH_HEIGHT*DEPTH_BPP);
		x->depth_front = (uint16_t*)malloc(DEPTH_WIDTH*DEPTH_HEIGHT*DEPTH_BPP);
		x->rgb_back = (uint8_t*)malloc(RGB_WIDTH*RGB_HEIGHT*RGB_BPP);
		x->rgb_mid = (uint8_t*)malloc(RGB_WIDTH*RGB_HEIGHT*RGB_BPP);
		x->rgb_front = (uint8_t*)malloc(RGB_WIDTH*RGB_HEIGHT*RGB_BPP);
		
		x->is_open=FALSE;
		x->id=++global_id;
		
		//jit_fnect_restart_thread(x);
        //pthread_mutex_init(&x->cb_mutex, NULL);
		jit_atom_setsym(&x->format, s_rgb);
		postNesa("new freenect instance added.");//TODO: remove	
	} else {
		x = NULL;
	}
	return x;
}
t_jit_err jit_alphablend_init(void)
{
	long attrflags=0;
	t_jit_object *attr,*mop,*o;
	t_symbol *atsym;
	t_atom a[3];

	atsym = gensym("jit_attr_offset");

	_jit_alphablend_class = jit_class_new("jit_alphablend",(method)jit_alphablend_new,(method)jit_alphablend_free,
										  sizeof(t_jit_alphablend),0L);

	//add mop
	mop = jit_object_new(_jit_sym_jit_mop,2,1);
//	jit_mop_single_planecount(mop,4);
	jit_atom_setsym(a,_jit_sym_char);
	jit_atom_setsym(a+1,_jit_sym_float32);
	jit_atom_setsym(a+2,_jit_sym_float64);
	o = jit_object_method(mop,_jit_sym_getinput,2);
	jit_object_method(o,_jit_sym_types,3,a);
	o = jit_object_method(mop,_jit_sym_getoutput,1);
	jit_object_method(o,_jit_sym_types,3,a);

	jit_class_addadornment(_jit_alphablend_class,mop);
	//add methods
	jit_class_addmethod(_jit_alphablend_class, (method)jit_alphablend_matrix_calc, 		"matrix_calc", 		A_CANT, 0L);

	//add attributes
	attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_USURP_LOW;
	attr = jit_object_new(atsym,"mode",_jit_sym_long,attrflags,
						  (method)0L,(method)0L,calcoffset(t_jit_alphablend,mode));
	jit_class_addattr(_jit_alphablend_class,attr);
	CLASS_ATTR_BASIC(_jit_alphablend_class,"mode",0);
	CLASS_ATTR_LABEL(_jit_alphablend_class,"mode",0,"Crossfade Mode");
	CLASS_ATTR_ENUMINDEX2(_jit_alphablend_class, "mode", 0, "Left-to-Right", "Right-to-Left");
	CLASS_ATTR_CATEGORY(_jit_alphablend_class, "mode", 0, "Mode");

	jit_class_register(_jit_alphablend_class);

	return JIT_ERR_NONE;
}
t_jit_err xray_jit_colormap_init(void) 
{
	long attrflags=0;
	t_jit_object *attr,*mop,*o;
	t_symbol *atsym;
	t_atom a[2];
	
	atsym = gensym("jit_attr_offset");
	
	_xray_jit_colormap_class = jit_class_new("xray_jit_colormap",(method)xray_jit_colormap_new,(method)xray_jit_colormap_free,
		sizeof(t_xray_jit_colormap),0L);

	//add mop
	mop = jit_object_new(_jit_sym_jit_mop,1,1);
	jit_mop_single_planecount(mop,1);	
	jit_atom_setsym(a,_jit_sym_char);
	jit_atom_setsym(a+1,_jit_sym_long);
	
	o = jit_object_method(mop,_jit_sym_getoutput,1);
	jit_object_method(o,_jit_sym_types,2,a);
	
	jit_class_addadornment(_xray_jit_colormap_class,mop);
	
	//add methods
	jit_class_addmethod(_xray_jit_colormap_class, (method)xray_jit_colormap_matrix_calc, 		"matrix_calc", 		A_CANT, 0L);
	
	//add attributes	
	attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_USURP_LOW;
	
	//mode
	attr = jit_object_new(atsym,"mode",_jit_sym_char,attrflags,
		(method)0L,(method)0L,calcoffset(t_xray_jit_colormap,mode));
	jit_class_addattr(_xray_jit_colormap_class,attr);
	
	jit_class_register(_xray_jit_colormap_class);

	return JIT_ERR_NONE;
}
Beispiel #9
0
t_jit_err xray_jit_fdm_init(void) 
{
	long attrflags=0;
	t_jit_object *attr,*mop,*o;
	t_symbol *atsym;
	t_atom a[1];
	
	atsym = gensym("jit_attr_offset");
	
	_xray_jit_fdm_class = jit_class_new("xray_jit_fdm",(method)xray_jit_fdm_new,(method)xray_jit_fdm_free,
		sizeof(t_xray_jit_fdm),0L);

	//add mop
	mop = jit_object_new(_jit_sym_jit_mop,1,1);
	jit_mop_single_planecount(mop,1);	
	jit_atom_setsym(a,_jit_sym_float32);
	
	o = jit_object_method(mop,_jit_sym_getoutput,1);
	jit_object_method(o,_jit_sym_types,1,a);
	
	jit_class_addadornment(_xray_jit_fdm_class,mop);
	
	//add methods
	jit_class_addmethod(_xray_jit_fdm_class, (method)xray_jit_fdm_matrix_calc, 		"matrix_calc", 		A_CANT, 0L);
	
	//add attributes	
	attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_USURP_LOW;
	
	//spacestep
	attr = jit_object_new(atsym,"spacestep",_jit_sym_float32,attrflags,
		(method)0L,(method)0L,calcoffset(t_xray_jit_fdm,spacestep));
	jit_class_addattr(_xray_jit_fdm_class,attr);
	
	//direction
	attr = jit_object_new(_jit_sym_jit_attr_offset,"direction",_jit_sym_symbol,attrflags,
		(method)0L,(method)0L,calcoffset(t_xray_jit_fdm, direction));	
	jit_class_addattr(_xray_jit_fdm_class,attr);
	
	//generate symbols
	ps_x 	= gensym("x");
	ps_y 	= gensym("y");
	ps_xx	= gensym("xx");
	ps_xy 	= gensym("xy");
	ps_yx 	= gensym("yx");
	ps_yy 	= gensym("yy");

	jit_class_register(_xray_jit_fdm_class);
	
	return JIT_ERR_NONE;
}
Beispiel #10
0
void *max_jit_peek_new(t_symbol *s, long argc, t_atom *argv)
{
	t_max_jit_peek *x;
	long attrstart,i;
	t_atom a;

	if (x = (t_max_jit_peek *)max_jit_obex_new(max_jit_peek_class,NULL)) { //only max object, no jit object
		for (i=0; i<=JIT_MATRIX_MAX_DIMCOUNT+1; i++)
			x->vectors[i] = NULL;

		x->matrix_name = _jit_sym_nothing;
		x->dimcount = 2;
		x->plane = 0;
		x->interp = 0;
		x->normalize = 0;

		x->inperform = 0;
		x->mvalid = 0;
		x->mdata = 0;

		attrstart = max_jit_attr_args_offset(argc,argv);
		if (attrstart&&argv) {
			t_atom_long al;
			jit_atom_arg_getsym(&x->matrix_name, 0, attrstart, argv);
			if (!jit_atom_arg_getlong(&al, 1, attrstart, argv)) {
				C74_ASSERT_FITS_LONG(al);
				x->dimcount = (long) al;
			}
			if (!jit_atom_arg_getlong(&al, 2, attrstart, argv)) {
				C74_ASSERT_FITS_LONG(al);
				x->plane = (long) al;
			}
			jit_atom_setsym(&a,x->matrix_name);
			max_jit_peek_matrix_name(x,NULL,1,&a);
		}

		CLIP_ASSIGN(x->dimcount,0,JIT_MATRIX_MAX_DIMCOUNT);
		CLIP_ASSIGN(x->dimcount,0,32); //maximum signal inputs

		max_jit_attr_args(x,argc,argv); //handle attribute args

		dsp_setup((t_pxobject *)x,x->dimcount);
		max_jit_obex_dumpout_set(x, outlet_new(x,0L)); //general purpose outlet(rightmost)
		outlet_new((t_object *)x, "signal"); //signal output
	}
	return (x);
}
Beispiel #11
0
t_jit_err jit_gl_hap_getattr_out_name(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_setsym(*av,jit_attr_getsym(x->texoutput,_jit_sym_name));
	
	return JIT_ERR_NONE;
}
Beispiel #12
0
void jit_gl_hap_notify_atomarray_prep(t_jit_gl_hap *x, t_symbol *s, long ac, t_atom *av)
{
	if (ac && av) {
		t_object *arr;
		t_atom *a;
		
		if (a = (t_atom *)sysmem_newptr(sizeof(t_atom) * (ac + 1))) {
			jit_atom_setsym(a, s);
			sysmem_copyptr(av, a + 1, sizeof(t_atom) * ac);
			arr = (t_object *)object_new(gensym("nobox"), gensym("atomarray"), ac + 1, a);
			jit_object_notify(x, gensym("typedmess"), arr);
			freeobject(arr);
			sysmem_freeptr(a);
		}
	}
	else jit_object_notify(x, s, NULL);
}
Beispiel #13
0
void max_jit_peek_dsp(t_max_jit_peek *x, t_signal **sp, short *count)
{
	long i;
	t_atom a;

	if (!x->mdata) // matrix may haven been initialized after jit.peek~ object. try again.
	{
		jit_atom_setsym(&a,x->matrix_name);
		max_jit_peek_matrix_name(x,NULL,1,&a);
	}

	x->vectors[0] = (t_float *)sp[x->dimcount]->s_vec;
	for (i=0; i<(x->dimcount); i++)
		x->vectors[i+1] = (t_float *)sp[i]->s_vec;

	dsp_add(max_jit_peek_perform, 2, x, sp[0]->s_n);
}
Beispiel #14
0
void max_jit_peek_dsp64(t_max_jit_peek *x, t_object *dsp64, short *count, double samplerate, long maxvectorsize, long flags)
{
//	long i;
	t_atom a;

	if (!x->mdata) // matrix may haven been initialized after jit.peek~ object. try again.
	{
		jit_atom_setsym(&a,x->matrix_name);
		max_jit_peek_matrix_name(x,NULL,1,&a);
	}

//	x->vectors[0] = (t_float*)sp[x->dimcount]->s_vec;
//	for (i=0;i<(x->dimcount);i++)
//		x->vectors[i+1] = (t_float*)sp[i]->s_vec;

	dsp_add64(dsp64, (t_object *)x, (t_perfroutine64)max_jit_peek_perform64, 0, NULL);
}
void max_jit_gl_spout_receiver_draw(t_max_jit_gl_spout_receiver *x, t_symbol *s, long argc, t_atom *argv)
{

	t_atom a;

	// get the jitter object
	t_jit_object *jitob = (t_jit_object*)max_jit_obex_jitob_get(x);
	
	// call the jitter object's draw method
	jit_object_method(jitob, s, s, argc, argv);
	
	// query the texture name and send out the texture output 
	jit_atom_setsym(&a,jit_attr_getsym(jitob, ps_out_name));

	outlet_anything(x->texout, ps_jit_gl_texture, 1, &a);


}
Beispiel #16
0
t_jit_err cv_jit_opticalflow_get_method(t_cv_jit_opticalflow *x, void *attr, long *ac, t_atom **av){
	
	if ((*ac)&&(*av)) {
		//memory passed in, use it
	} else {
		//otherwise allocate memory
		*ac = 1;
		if (!(*av = (t_atom*)jit_getbytes(sizeof(t_atom)*(*ac)))) {
			*ac = 0;
			return JIT_ERR_OUT_OF_MEM;
		}
	}
	
	char *str = new char[x->of->getMethodName().length()+1];
	strcpy(str, x->of->getMethodName().c_str());
	
	jit_atom_setsym(*av, gensym(str));
	delete[] str;
	
	return JIT_ERR_NONE;
}
Beispiel #17
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);	
}
Beispiel #18
0
t_jit_err xray_jit_cumsum_init(void)
{
	long attrflags=0;
	t_jit_object *attr,*mop,*o;
	t_symbol *atsym;
	t_atom a[1];

	atsym = gensym("jit_attr_offset");

	_xray_jit_cumsum_class = jit_class_new("xray_jit_cumsum",(method)xray_jit_cumsum_new,(method)xray_jit_cumsum_free,
		sizeof(t_xray_jit_cumsum),0L);

	//add mop
	mop = jit_object_new(_jit_sym_jit_mop, 1, 1);
	jit_atom_setsym(a, _jit_sym_float32);

	o = jit_object_method(mop,_jit_sym_getinput,1);
	jit_object_method(o,_jit_sym_types,1,a);

	o = jit_object_method(mop,_jit_sym_getoutput,1);
	jit_object_method(o,_jit_sym_types,1,a);

	jit_class_addadornment(_xray_jit_cumsum_class,mop);

	//add methods
	jit_class_addmethod(_xray_jit_cumsum_class, (method)xray_jit_cumsum_matrix_calc, 		"matrix_calc", 		A_CANT, 0L);

	//add attributes
	attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_USURP_LOW;

	//dimmode
	attr = jit_object_new(atsym,"dimmode",_jit_sym_char,attrflags,
		(method)0L,(method)0L,calcoffset(t_xray_jit_cumsum,dimmode));
	jit_class_addattr(_xray_jit_cumsum_class,attr);

	jit_class_register(_xray_jit_cumsum_class);

	return JIT_ERR_NONE;
}
void max_jit_gl_spout_receiver_draw(t_max_jit_gl_spout_receiver *x, t_symbol *s, long argc, t_atom *argv)
{
	UNREFERENCED_PARAMETER(s);
	UNREFERENCED_PARAMETER(argc);
	UNREFERENCED_PARAMETER(argv);

	t_atom a;

	// get the jitter object
	t_jit_object *jitob = (t_jit_object*)max_jit_obex_jitob_get(x);
	
	// Call the jitter object's draw method (from Syphon code)

	// LJ - This causes an error with corrupted texture received in draw
	// but does not affect the output. Seem to be not needed - needs tracing
	// t_symbol *attr = gensym("draw");
	// jit_object_method(jitob, attr, s, argc, argv);
	
	// query the texture name and send out the texture output 
	jit_atom_setsym(&a, jit_attr_getsym(jitob, ps_out_name));
	outlet_anything(x->texout, ps_out_texture, 1, &a);


}
t_jit_err jit_pcl_concavehull_init(void)
{
    long			attrflags = JIT_ATTR_GET_DEFER_LOW | JIT_ATTR_SET_USURP_LOW;
    t_jit_object	*attr;
    t_jit_object	*mop;
    t_atom a[1];
    
    s_jit_pcl_concavehull_class = jit_class_new("jit_pcl_concavehull", (method)jit_pcl_concavehull_new, (method)jit_pcl_concavehull_free, sizeof(t_jit_pcl_concavehull), 0);
    
    // add matrix operator (mop)
    // args are  num inputs and num outputs
    mop = (t_jit_object *)jit_object_new(_jit_sym_jit_mop, 1, 1);
    jit_mop_input_nolink(mop,1);
    
    
    attr = (t_jit_object *)jit_object_method(mop, _jit_sym_getinput, 1);
    jit_attr_setlong(attr,_jit_sym_dimlink,0);
    jit_attr_setlong(attr,_jit_sym_typelink,0);
    jit_attr_setlong(attr,_jit_sym_planelink,0);
    jit_object_method(attr,_jit_sym_ioproc,jit_mop_ioproc_copy_adapt);
    jit_atom_setsym(a, _jit_sym_float32);
    jit_object_method(attr, _jit_sym_types,1, a);
    
    attr = (t_jit_object *)jit_object_method(mop, _jit_sym_getoutput, 1);
    jit_attr_setlong(attr, _jit_sym_dimlink,0);
    
    jit_class_addadornment(s_jit_pcl_concavehull_class, mop);
    
    
    
    // add method(s)
    jit_class_addmethod(s_jit_pcl_concavehull_class, (method)jit_pcl_concavehull_matrix_calc, "matrix_calc", A_CANT, 0);
    
    // add attribute(s)
    attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,
                                          "leafsize",
                                          _jit_sym_float64,
                                          attrflags,
                                          (method)NULL, (method)NULL,
                                          calcoffset(t_jit_pcl_concavehull, leafsize));
    
    jit_class_addattr(s_jit_pcl_concavehull_class, attr);
    
    attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,
                                          "npoints",
                                          _jit_sym_long,
                                          attrflags,
                                          (method)NULL, (method)NULL,
                                          calcoffset(t_jit_pcl_concavehull, npoints));
    jit_attr_addfilterget_clip(attr, 1, 10000, true, false);
    jit_class_addattr(s_jit_pcl_concavehull_class, attr);

    attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,
                                          "stdthresh",
                                          _jit_sym_float64,
                                          attrflags,
                                          (method)NULL, (method)NULL,
                                          calcoffset(t_jit_pcl_concavehull, stdthresh));
    
    jit_class_addattr(s_jit_pcl_concavehull_class, attr);
    
    attr = (t_jit_object *)jit_object_new(_jit_sym_jit_attr_offset,
                                          "alpha",
                                          _jit_sym_float64,
                                          attrflags,
                                          (method)NULL, (method)NULL,
                                          calcoffset(t_jit_pcl_concavehull, alpha));
    
    jit_class_addattr(s_jit_pcl_concavehull_class, attr);
    
    // finalize class
    jit_class_register(s_jit_pcl_concavehull_class);
    return JIT_ERR_NONE;
}
Beispiel #21
0
int script_lua_atoms_from_args(lua_State *L, int index_start, t_atom **args)
{
	int i, n;
	int num_args = 0;
	
	n = lua_gettop(L);
	
	//count the number of arguments
	for(i=index_start; i <= n; i++) {
		int type = lua_type(L, i);
		
		switch(type)
		{
			case LUA_TTABLE:
					num_args += luaL_getn(L, i);
					break;
			
			case LUA_TSTRING:
			case LUA_TNUMBER:
			case LUA_TUSERDATA:
					num_args++;
					break;

			default:
					break;
		}
	}
	
	*args = (t_atom *)jit_getbytes(num_args*sizeof(t_atom));

	{
		int arg_index=0;	//index of current argument
		
		//iterate over the number of stack elements
		for(i=index_start; i <= n; i++) {
			int type = lua_type(L, i);
			
			switch(type)
			{
				case LUA_TSTRING:
						jit_atom_setsym(*args+arg_index, GENSYM(lua_tostring(L, i)));
						arg_index++;
						break;
					
				case LUA_TNUMBER:
						jit_atom_setfloat(*args+arg_index, lua_tonumber(L, i));
						arg_index++;
						break;
				
				case LUA_TUSERDATA:
						(*args+arg_index)->a_w.w_obj = toJitobj(L, i);
						(*args+arg_index)->a_type = A_OBJ;
						arg_index++;
						break;
				
				case LUA_TTABLE:
						{
							int j;
							int table_type;
							
							//doesn't account for tables of userdata yet
							for(j=1; j <= luaL_getn(L, i); j++) {
								lua_rawgeti(L, i, j);
								table_type = lua_type(L, -1);
								
								switch(table_type)
								{
									case LUA_TSTRING:
											jit_atom_setsym(*args+arg_index, GENSYM(lua_tostring(L, -1)));
											arg_index++;
											break;
											
									case LUA_TNUMBER:
											jit_atom_setfloat(*args+arg_index, lua_tonumber(L, -1));
											arg_index++;
											break;
									
									case LUA_TUSERDATA:
											(*args+arg_index)->a_w.w_obj = toJitobj(L, -1);
											(*args+arg_index)->a_type = A_OBJ;
											arg_index++;
											break;
											
									default:
											break;
								}
								
							}
						}
						
						break;
						
				default:
					break;
			}
		}
	}
	
	return num_args;
}
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;
}