Пример #1
0
t_osc_err osc_bundle_u_intersection(t_osc_bndl_u *bndl1, t_osc_bndl_u *bndl2, t_osc_bndl_u **bndl_out)
{
	if(!(*bndl_out)){
		*bndl_out = osc_bundle_u_alloc();
	}
	int argc1 = osc_bundle_u_getMsgCount(bndl1);
	int argc2 = osc_bundle_u_getMsgCount(bndl2);
	if(argc1 == 0 || argc2 == 0){
		return OSC_ERR_NONE;
	}
	t_osc_bndl_it_u *it = osc_bndl_it_u_get(bndl1);
	while(osc_bndl_it_u_hasNext(it)){
		t_osc_msg_u *m = osc_bndl_it_u_next(it);
		char *address = osc_message_u_getAddress(m);
		int res = 0;
		osc_bundle_u_addressExists(bndl2, address, 1, &res);
		if(res != 0){
			int res = 0;
			osc_bundle_u_addressExists(*bndl_out, address, 1, &res);
			if(res == 0){
				t_osc_msg_u *mcopy = NULL;
				osc_message_u_deepCopy(&mcopy, m);
				osc_bundle_u_addMsg(*bndl_out, mcopy);
			}
		}
	}
	osc_bndl_it_u_destroy(it);
	return OSC_ERR_NONE;
}
Пример #2
0
void odisplay_anything(t_odisplay *x, t_symbol *msg, short argc, t_atom *argv)
{
	t_atom av[argc + 1];
	int ac = argc;

	if (msg) {
        ac = argc + 1;
        atom_setsym(av, msg);
        if (argc > 0) {
            memcpy(av + 1, argv, argc * sizeof(t_atom));
        }
	} else {
        memcpy(av, argv, argc * sizeof(t_atom));
	}

    t_osc_msg_u *m = NULL;
    t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&m, msg, argc, argv);
    if(e){
        return;
    }
    t_osc_bndl_u *b = osc_bundle_u_alloc();
    osc_bundle_u_addMsg(b, m);
    t_osc_bndl_s *bs = osc_bundle_u_serialize(b);
    odisplay_newBundle(x, b, bs);

#ifdef OMAX_PD_VERSION
    x->draw_new_data_indicator = 1;
    x->have_new_data = 1;
    jbox_redraw((t_jbox *)x);
#else
    x->draw_new_data_indicator = 1;
    x->have_new_data = 1;
    qelem_set(x->qelem);
#endif
}
Пример #3
0
void otimetag_anything(t_otimetag *x, t_symbol *selector, short argc, t_atom *argv)
{
	t_osc_msg_u *msg = NULL;
	t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg, selector, argc, argv);
	if(e){
		object_error((t_object *)x, "%s", osc_error_string(e));
		return;
	}
	t_osc_bndl_u *bndl = osc_bundle_u_alloc();
	osc_bundle_u_addMsg(bndl, msg);
	t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl);
	if(bs){
		otimetag_doFullPacket(x, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
		osc_bundle_s_deepFree(bs);
	}
	osc_bundle_u_free(bndl);
	/*
	t_osc_msg_u *msg = NULL;
	t_symbol *address_sym = NULL;
	long osc_argc = argc;
	t_atom *osc_argv = argv;
	if(selector){
		if(selector->s_name[0] == '/'){
			address_sym = selector;
		}
	}
	if(!address_sym){
		if(argc != 0){
			if(atom_gettype(argv) != A_SYM){
				object_error((t_object *)x, "first argument must be an OSC address");
				return;
			}
			address_sym = atom_getsym(argv);
			if(address_sym->s_name[0] != '/'){
				object_error((t_object *)x, "first argument must be an OSC address");
				return;
			}
			osc_argc = argc - 1;
			osc_argv = argv + 1;
		}else{
			object_error((t_object *)x, "first argument must be an OSC address");
			return;
		}
	}
	omax_util_maxAtomsToOSCMsg_u(&msg, address_sym, osc_argc, osc_argv);
	t_osc_bndl_u *bndl = osc_bundle_u_alloc();
	osc_bundle_u_addMsg(bndl, msg);
	long len = 0;
	char *buf = NULL;
	osc_bundle_u_serialize(bndl, &len, &buf);
	otimetag_doFullPacket(x, len, buf);
	if(buf){
		osc_mem_free(buf);
	}
	osc_bundle_u_free(bndl);
	*/
}
Пример #4
0
void simplemax_anything(t_simplemax *x,t_symbol* s,int argc,t_atom* argv){
    
    // msg is a dispatch name (/foo), argc is # of elements, argv is element vector
    
    if (!s){object_error((t_object*)x, "NOOOOOO!!!!");}
    
    //object_post((t_object*)x, "%s",msg->s_name);
    t_osc_bundle_u *bundle = osc_bundle_u_alloc();//alloc creates memory for and initializes the bundle
    
    
    t_osc_message_u *msg = osc_message_u_alloc();
    osc_message_u_setAddress(msg, s->s_name);
    
    
    for(int i=0;i < argc;i++){ //going through all the arguments (arg vector) whos length is argc
        
        t_osc_atom_u* a = osc_atom_u_alloc();
        
        switch(atom_gettype(argv+i)){
            
            case A_LONG:
            osc_atom_u_setInt32(a, atom_getlong(argv+i));
            break;
            
            case A_FLOAT:
            osc_atom_u_setFloat(a, atom_getfloat(argv+i));
            break;
            
            case A_SYM:
            osc_atom_u_setString(a, atom_getsym(argv+i)->s_name);
            break;
        
        }
        
        osc_message_u_appendAtom(msg, a);
        //osc_message_u_appendFloat(msg, 15.0);
    }
    osc_bundle_u_addMsg(bundle, msg);
    long bytes = 0;//length of byte array
    char* pointer = NULL;
    
    osc_bundle_u_serialize(bundle, &bytes, &pointer);//& is adress of the variable
    //post("%ld %p", bytes,pointer);
    
    t_atom out[2];
    atom_setlong(out, bytes);
    atom_setlong(out+1, (long)pointer);
    outlet_anything(x->outlet, gensym("FullPacket"), 2, out);
    
    osc_bundle_u_free(bundle);//get rid of stuff in osc message
    osc_mem_free(pointer);//marks pointer address as being free (clear if you want to keep using same pointer)
    
    
}
Пример #5
0
t_osc_bndl_u *ocontext_processPatcher(t_object *patcher)
{
	t_osc_bndl_u *patcher_bndl = osc_bundle_u_alloc();
	if(patcher == NULL){
		// return empty bundle---this is intentional
		return patcher_bndl;
	}
	long nattrs = 0;
	t_symbol **attrs = NULL;
	object_attr_getnames(patcher, &nattrs, &attrs);
	for(int i = 0; i < nattrs; i++){
		t_atom *av = NULL;
		long ac = 0;
		object_attr_getvalueof(patcher, attrs[i], &ac, &av);
		if(av && ac){
			long addresslen = strlen(attrs[i]->s_name) + 2;
			char address[addresslen];
			snprintf(address, addresslen, "/%s", attrs[i]->s_name);
			t_osc_msg_u *msg = NULL;
			if(ac == 1 && atom_gettype(av) == A_OBJ){
				//printf("%s has object: %p %p\n", address, patcher, atom_getobj(av));
				continue;
				t_osc_bndl_u *b = ocontext_processPatcher(atom_getobj(av));
				if(b){
					msg = osc_message_u_allocWithAddress(address);
					osc_message_u_appendBndl_u(msg, b);
					osc_bundle_u_addMsg(patcher_bndl, msg);
				}
			}else{
				omax_util_maxAtomsToOSCMsg_u(&msg, gensym(address), ac, av);
				if(msg){
					osc_bundle_u_addMsg(patcher_bndl, msg);
				}
			}
		}
	}
	sysmem_freeptr(attrs);

	t_symbol *maxclass = object_attr_getsym(patcher, gensym("maxclass"));
	if(maxclass && maxclass == gensym("jpatcher")){
		patcher = jpatcher_get_parentpatcher(patcher);
		t_osc_bndl_u *parent_bndl = ocontext_processPatcher(patcher);

		t_osc_msg_u *msg = osc_message_u_allocWithAddress("/parent");
		osc_message_u_appendBndl_u(msg, parent_bndl);
		osc_bundle_u_addMsg(patcher_bndl, msg);
	}

	return patcher_bndl;
}
Пример #6
0
void olistenumerate_anything(t_olistenumerate *x, t_symbol *selector, short argc, t_atom *argv)
{
	t_osc_msg_u *msg = NULL;
	t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg, selector, argc, argv);
	if(e){
		object_error((t_object *)x, "%s", osc_error_string(e));
		return;
	}
	t_osc_bndl_u *bndl = osc_bundle_u_alloc();
	osc_bundle_u_addMsg(bndl, msg);
	t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl);
	if(bs){
		olistenumerate_doFullPacket(x, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
		osc_bundle_s_deepFree(bs);
	}
	osc_bundle_u_free(bndl);
}
Пример #7
0
void olistenumerate_noMatchesOrData(t_olistenumerate *x)
{
    // left outlet:
    t_osc_message_u* address = osc_message_u_allocWithString("/address", x->address->s_name);
    t_osc_message_u* length = osc_message_u_allocWithAddress("/length");
    osc_message_u_appendInt32(length, 0);
    t_osc_bundle_u* unserialized_result = osc_bundle_u_alloc();
    osc_bundle_u_addMsg(unserialized_result, address);
    osc_bundle_u_addMsg(unserialized_result, length);
    
    t_osc_bndl_s *bs = osc_bundle_u_serialize(unserialized_result);
    osc_bundle_u_free(unserialized_result);
    unserialized_result = NULL;
    
    if (bs) {
	    omax_util_outletOSC(x->outlets[1], osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
	    osc_bundle_s_deepFree(bs);
        bs = NULL;
    }
}
Пример #8
0
void *oedge_new(t_symbol *msg, short argc, t_atom *argv)
{
	t_oedge *x = NULL;
	if((x = (t_oedge *)object_alloc(oedge_class))){
  		dsp_setup((t_pxobject *)x, 1); 
		x->outlet = outlet_new((t_object *)x, "FullPacket");
		critical_new(&(x->lock));
		x->ac = 0;
		x->av = NULL;
		x->lastx = 0;
		x->gettime = 0;

		x->time_onset = osc_message_u_alloc();
		osc_message_u_setAddress(x->time_onset, "/zerotononzero/time");
		x->block_sample_onset = osc_message_u_alloc();
		osc_message_u_setAddress(x->block_sample_onset, "/zerotononzero/sample/withinblock");
		x->global_sample_onset = osc_message_u_alloc();
		osc_message_u_setAddress(x->global_sample_onset, "/zerotononzero/sample/sincedspstart");
		x->value_onset = osc_message_u_alloc();
		osc_message_u_setAddress(x->value_onset, "/zerotononzero/value");

		x->time_zero = osc_message_u_alloc();
		osc_message_u_setAddress(x->time_zero, "/nonzerotozero/time");
		x->block_sample_zero = osc_message_u_alloc();
		osc_message_u_setAddress(x->block_sample_zero, "/nonzerotozero/sample/withinblock");
		x->global_sample_zero = osc_message_u_alloc();
		osc_message_u_setAddress(x->global_sample_zero, "/nonzerotozero/sample/sincedspstart");

		x->bundle = osc_bundle_u_alloc();

		osc_bundle_u_addMsg(x->bundle, x->time_onset);
		osc_bundle_u_addMsg(x->bundle, x->block_sample_onset);
		osc_bundle_u_addMsg(x->bundle, x->global_sample_onset);
		osc_bundle_u_addMsg(x->bundle, x->value_onset);
		osc_bundle_u_addMsg(x->bundle, x->time_zero);
		osc_bundle_u_addMsg(x->bundle, x->block_sample_zero);
		osc_bundle_u_addMsg(x->bundle, x->global_sample_zero);
	}
	return x;
}
Пример #9
0
t_osc_err osc_bundle_u_explode(t_osc_bndl_u **dest,
			       t_osc_bndl_u *src,
			       int maxlevel,
			       char *sep)
{
	if(!src){
		return OSC_ERR_NOBUNDLE;
	}
	if(!(*dest)){
		*dest = osc_bundle_u_alloc();
	}
	t_osc_bndl_it_u *it = osc_bndl_it_u_get(src);
	while(osc_bndl_it_u_hasNext(it)){
		t_osc_msg_u *m = osc_bndl_it_u_next(it);
		t_osc_err ret = osc_message_u_explode(*dest, m, maxlevel, sep);
		if(ret){
			return ret;
		}
	}
	osc_bndl_it_u_destroy(it);
	return OSC_ERR_NONE;
}
Пример #10
0
void ocoll_anything(t_ocoll *x, t_symbol *msg, int argc, t_atom *argv)
{
	t_osc_bndl_u *bndl_u = osc_bundle_u_alloc();
	t_osc_msg_u *msg_u = NULL;
	t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg_u, msg, argc, argv);
	if(e){
		object_error((t_object *)x, "%s", osc_error_string(e));
		if(bndl_u){
			osc_bundle_u_free(bndl_u);
		}
		return;
	}
	osc_bundle_u_addMsg(bndl_u, msg_u);
	t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl_u);
	if(bndl_u){
		osc_bundle_u_free(bndl_u);
	}
    
	ocoll_fullPacket_impl(x, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
	if(bs){
		osc_bundle_s_deepFree(bs);
	}

}
Пример #11
0
void omax_object_createIOReport(t_object *x, t_symbol *msg, int argc, t_atom *argv, long *buflen, char **buf)
{
	t_symbol *classname = object_classname(x);
	if(!classname){
		return;
	}
	t_hashtab *ht = omax_class_getHashtab(classname->s_name);
	if(!ht){
		return;
	}
	long nkeys = 0;
	t_symbol **keys = NULL;
	hashtab_getkeys(ht, &nkeys, &keys);

	t_osc_bndl_u *bndl_u = osc_bundle_u_alloc();
	int i;
	for(i = 0; i < nkeys; i++){
		if(!osc_error_validateAddress(keys[i]->s_name)){
			int j;

			for(j = 0; j < argc; j++){
				t_atom *a = argv + j;
				if(atom_gettype(a) == A_SYM){
					int ret = 0;
					int ao, po;
					if(atom_getsym(a) == gensym("/*")){
						ret = OSC_MATCH_ADDRESS_COMPLETE;
					}else{
						ret = osc_match(atom_getsym(a)->s_name, keys[i]->s_name, &po, &ao);
					}
					if(ret && OSC_MATCH_ADDRESS_COMPLETE){
						t_omax_method *m = NULL;
						hashtab_lookup(ht, keys[i], (t_object **)(&m));
						if(!m){
							continue;
						}
						if(m->type == OMAX_PARAMETER){
							t_object *attr = object_attr_get(x, m->sym);
							long argc = 0;
							t_atom *argv = NULL;
							//m->m.m_fun(ob, attr, &argc, &argv);
							char getter[128];
							sprintf(getter, "get%s", m->sym->s_name);
							long get;
							method f = object_attr_method(x, gensym(getter), (void **)(&attr), &get);
							if(f){
								f(x, attr, &argc, &argv);
								if(argv){
									char address[128];
									sprintf(address, "/%s", m->sym->s_name);
									t_atom a[argc + 1];
									atom_setsym(a, gensym(address));
									memcpy(a + 1, argv, argc * sizeof(t_atom));

									t_osc_msg_u *msg_u = NULL;
									t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg_u, ps_oscioreport, argc + 1, a);
									if(e){
										object_error((t_object *)x, "%s", osc_error_string(e));
										if(bndl_u){
											osc_bundle_u_free(bndl_u);
										}
										return;
									}
									osc_bundle_u_addMsg(bndl_u, msg_u);
									sysmem_freeptr(argv);
								}
							}
						}
					}
				}
			}
		}
	}
	//*buflen = pos;
	t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl_u);
	if(bs){
		*buflen = osc_bundle_s_getLen(bs);
		*buf = osc_bundle_s_getPtr(bs);
		osc_bundle_s_free(bs);
	}
	if(bndl_u){
		osc_bundle_u_free(bndl_u);
	}
}
Пример #12
0
void ovalidate_fullPacket(t_ovalidate *x, t_symbol *msg, int argc, t_atom *argv)
{
	OMAX_UTIL_GET_LEN_AND_PTR;
	/*
	t_osc_err e = osc_error_bundleSanityCheck(len, ptr);
	if(e){
		t_osc_bndl_u *b = osc_bundle_u_alloc();

		t_osc_msg_u *merr = osc_message_u_alloc();
		osc_message_u_setAddress(merr, "/error/str");
		osc_message_u_appendString(merr, osc_error_string(e));
		osc_bundle_u_addMsg(b, merr);

		long l = 0;
		char *buf = NULL;
		osc_bundle_u_serialize(b, &l, &buf);
		if(buf){
			omax_util_outletOSC(x->outletErr, l, buf);
			omax_util_outletOSC(x->outletInval, len, ptr);
			osc_mem_free(buf);
		}
		return;
	}
	*/
	if(*ptr != '#' && *ptr != '/'){
		char errstr[128];
		snprintf(errstr, 128, "invalid packet: packet does not begin with a # or a /");
		t_osc_bndl_u *b = osc_bundle_u_alloc();

		t_osc_msg_u *merr = osc_message_u_alloc();
		osc_message_u_setAddress(merr, "/error/str");
		osc_message_u_appendString(merr, errstr);
		osc_bundle_u_addMsg(b, merr);

		t_osc_bndl_s *bs = osc_bundle_u_serialize(b);
		if(bs){
			omax_util_outletOSC(x->outletErr, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
			omax_util_outletOSC(x->outletInval, len, ptr);
			osc_bundle_s_deepFree(bs);
		}
		return;
	}
	if(len % 4){
		char errstr[128];
		snprintf(errstr, 128, "%ld is not a multiple of 4 bytes", len);
		t_osc_bndl_u *b = osc_bundle_u_alloc();

		t_osc_msg_u *merr = osc_message_u_alloc();
		osc_message_u_setAddress(merr, "/error/str");
		osc_message_u_appendString(merr, errstr);
		osc_bundle_u_addMsg(b, merr);

		t_osc_bndl_s *bs = osc_bundle_u_serialize(b);
		if(bs){
			omax_util_outletOSC(x->outletErr, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
			omax_util_outletOSC(x->outletInval, len, ptr);
			osc_bundle_s_deepFree(bs);
		}
		return;
	}
	if(*ptr == '#'){
		char *p = ptr;
		p += OSC_HEADER_SIZE;
		while((p - ptr) < (len - 4)){
			int i = ntoh32(*((int32_t *)p));
			if(i < 0){
				break;
			}
			p += i + 4;
		}
		if((p - ptr) != len){
			char errstr[128];
			snprintf(errstr, 128, "expected %ld bytes, but found %d", len, p - ptr);
			t_osc_bndl_u *b = osc_bundle_u_alloc();

			t_osc_msg_u *merr = osc_message_u_alloc();
			osc_message_u_setAddress(merr, "/error/str");
			osc_message_u_appendString(merr, errstr);
			osc_bundle_u_addMsg(b, merr);

			t_osc_bndl_s *bs = osc_bundle_u_serialize(b);
			if(bs){
				omax_util_outletOSC(x->outletErr, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
				omax_util_outletOSC(x->outletInval, len, ptr);
				osc_bundle_s_deepFree(bs);
			}
			return;
		}
	}
	uint64_t state = OSC_SERIAL_INIT;
	for(int i = 0; i < len; i++){
		state = osc_serial_processByte(ptr[i], state);
		if(osc_serial_errorp(state)){
			char *errstr = osc_serial_errstr(state);
			t_osc_bndl_u *b = osc_bundle_u_alloc();

			t_osc_msg_u *merr = osc_message_u_alloc();
			osc_message_u_setAddress(merr, "/error/str");
			osc_message_u_appendString(merr, errstr);
			osc_bundle_u_addMsg(b, merr);

			t_osc_msg_u *mbytenum = osc_message_u_alloc();
			osc_message_u_setAddress(mbytenum, "/error/byte/num");
			osc_message_u_appendInt32(mbytenum, i);
			osc_bundle_u_addMsg(b, mbytenum);

			if(mbytenum < len){
				t_osc_msg_u *mbyteval = osc_message_u_alloc();
				osc_message_u_setAddress(mbyteval, "/error/byte/val");
				osc_message_u_appendInt32(mbyteval, ptr[i]);
				osc_bundle_u_addMsg(b, mbyteval);
			}

			t_osc_bndl_s *bs = osc_bundle_u_serialize(b);
			if(bs){
				omax_util_outletOSC(x->outletErr, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
				omax_util_outletOSC(x->outletInval, len, ptr);
				osc_bundle_s_deepFree(bs);
			}
			return;
		}
	}
	omax_util_outletOSC(x->outletVal, len, ptr);
}
Пример #13
0
void omax_outputState(t_object *x)
{
	t_symbol *classname = object_classname(x);
	if(!classname){
		return;
	}
	t_hashtab *ht = omax_class_getHashtab(classname->s_name);
	if(!ht){
		return;
	}
	long nkeys = 0;
	t_symbol **keys = NULL;
	hashtab_getkeys(ht, &nkeys, &keys);

	t_osc_bndl_u *bndl_u = osc_bundle_u_alloc();
	int i;
	for(i = 0; i < nkeys; i++){
		if(osc_error_validateAddress(keys[i]->s_name)){
			continue;
		}

		t_omax_method *m = NULL;
		hashtab_lookup(ht, keys[i], (t_object **)(&m));
		if(!m){
			continue;
		}
		if(m->type == OMAX_PARAMETER){
			t_object *attr = object_attr_get(x, m->sym);
			long argc = 0;
			t_atom *argv = NULL;
			//m->m.m_fun(ob, attr, &argc, &argv);
			char getter[128];
			sprintf(getter, "get%s", m->sym->s_name);
			long get;
			method f = object_attr_method(x, gensym(getter), (void **)(&attr), &get);
			if(f){
				f(x, attr, &argc, &argv);
				if(argv){
					char address[128];
					sprintf(address, "/%s", m->sym->s_name);
					t_symbol *addresssym = gensym(address);

					t_osc_msg_u *msg_u = NULL;
					t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg_u, addresssym, argc, argv);
					if(e){
						object_error((t_object *)x, "%s", osc_error_string(e));
						if(bndl_u){
							osc_bundle_u_free(bndl_u);
						}
						return;
					}
					osc_bundle_u_addMsg(bndl_u, msg_u);

					if(argv){
						sysmem_freeptr(argv);
					}
				}
			}
		}
	}
	//long len = 0;
	//char *buf = NULL;
	t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl_u);
	void *outlet = omax_object_getInfoOutlet(x);
	if(outlet && bs){
		omax_util_outletOSC(outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
		osc_bundle_s_deepFree(bs);
	}
	if(bndl_u){
		osc_bundle_u_free(bndl_u);
 	}
}
Пример #14
0
static t_osc_err osc_bundle_u_flatten_impl(t_osc_bndl_u **dest,
					   t_osc_bndl_u *src,
					   int maxlevel,
					   int level,
					   char *prefix,
					   char *sep,
					   int remove_enclosing_address_if_empty)
{
	if(!sep){
		sep = "";
	}
	if(!(*dest)){
		*dest = osc_bundle_u_alloc();
	}
	t_osc_bndl_it_u *bit = osc_bndl_it_u_get(src);
	while(osc_bndl_it_u_hasNext(bit)){
		t_osc_msg_u *m = osc_bndl_it_u_next(bit);
		t_osc_msg_u *mcopy = NULL;
		osc_message_u_deepCopy(&mcopy, m);
		if((level < maxlevel) || (maxlevel <= 0)){
			t_osc_msg_it_u *mit = osc_msg_it_u_get(mcopy);
			while(osc_msg_it_u_hasNext(mit)){
				t_osc_atom_u *a = osc_msg_it_u_next(mit);
				if(osc_atom_u_getTypetag(a) == OSC_BUNDLE_TYPETAG){
					osc_message_u_removeAtom(mcopy, a);
					t_osc_bndl_u *bu = osc_atom_u_getBndl(a);
					/*
					t_osc_bndl_u *bu = NULL;
					osc_bundle_s_deserialize(osc_bundle_s_getLen(b),
								 osc_bundle_s_getPtr(b),
								 &bu);
					*/
					t_osc_err e;
					if(prefix){
						int prefixlen = strlen(prefix) + strlen(osc_message_u_getAddress(mcopy)) + strlen(sep);
						char pfx[prefixlen + 1];
						sprintf(pfx, "%s%s%s", prefix, sep, osc_message_u_getAddress(mcopy));
						e = osc_bundle_u_flatten_impl(dest,
									      bu,
									      maxlevel,
									      level + 1,
									      pfx,
									      sep,
									      remove_enclosing_address_if_empty);
					}else{
						e = osc_bundle_u_flatten_impl(dest,
									      bu,
									      maxlevel,
									      level + 1,
									      osc_message_u_getAddress(mcopy),
									      sep,
									      remove_enclosing_address_if_empty);
					}
					if(e){
						return e;
					}
					osc_atom_u_free(a);
				}
			}
			osc_msg_it_u_destroy(mit);
		}
		if(!remove_enclosing_address_if_empty || osc_message_u_getArgCount(mcopy) > 0){
			if(prefix){
				int newaddresslen = strlen(prefix) + strlen(osc_message_u_getAddress(mcopy)) + strlen(sep);
				char newaddress[newaddresslen + 1];
				sprintf(newaddress, "%s%s%s", prefix, sep, osc_message_u_getAddress(mcopy));
				osc_message_u_setAddress(mcopy, newaddress);
			}
			osc_bundle_u_addMsgWithoutDups(*dest, mcopy);
		}else{
			osc_message_u_free(mcopy);
		}
	}
	osc_bndl_it_u_destroy(bit);
	return OSC_ERR_NONE;
}
Пример #15
0
void _omax_doc_outletDoc(void *outlet,
			 char *name,
			 char *short_desc,
			 char *long_desc,
			 int ninlets,
			 char **inlets_desc,
			 int noutlets,
			 char **outlets_desc,
			 int num_see_also_refs,
			 char **see_also)
{
	t_osc_bndl_u *bndl = osc_bundle_u_alloc();
	t_osc_msg_u *msg_name = osc_message_u_alloc();
	osc_message_u_setAddress(msg_name, "/doc/name");
	osc_message_u_appendString(msg_name, name);
	osc_bundle_u_addMsg(bndl, msg_name);

	t_osc_msg_u *msg_short_desc = osc_message_u_alloc();
	osc_message_u_setAddress(msg_short_desc, "/doc/desc/short");
	osc_message_u_appendString(msg_short_desc, short_desc);
	osc_bundle_u_addMsg(bndl, msg_short_desc);

	t_osc_msg_u *msg_long_desc = osc_message_u_alloc();
	osc_message_u_setAddress(msg_long_desc, "/doc/desc/long");
	osc_message_u_appendString(msg_long_desc, long_desc);
	osc_bundle_u_addMsg(bndl, msg_long_desc);

	t_osc_msg_u *msg_ninlets = osc_message_u_alloc();
	osc_message_u_setAddress(msg_ninlets, "/doc/ninlets");
	osc_message_u_appendInt32(msg_ninlets, ninlets);
	osc_bundle_u_addMsg(bndl, msg_ninlets);

	t_osc_msg_u *msg_noutlets = osc_message_u_alloc();
	osc_message_u_setAddress(msg_noutlets, "/doc/noutlets");
	osc_message_u_appendInt32(msg_noutlets, noutlets);
	osc_bundle_u_addMsg(bndl, msg_noutlets);

	int i;
	for(i = 0; i < ninlets; i++){
		if(inlets_desc[i]){
			t_osc_msg_u *m = osc_message_u_alloc();
			char buf[64];
			sprintf(buf, "/doc/desc/inlet/%d", i + 1);
			osc_message_u_setAddress(m, buf);
			osc_message_u_appendString(m, inlets_desc[i]);
			osc_bundle_u_addMsg(bndl, m);
		}
	}
	for(i = 0; i < noutlets; i++){
		if(outlets_desc[i]){
			t_osc_msg_u *m = osc_message_u_alloc();
			char buf[64];
			sprintf(buf, "/doc/desc/outlet/%d", i + 1);
			osc_message_u_setAddress(m, buf);
			osc_message_u_appendString(m, outlets_desc[i]);
			osc_bundle_u_addMsg(bndl, m);
		}
	}

	t_osc_msg_u *msg_seealso = osc_message_u_alloc();
	osc_message_u_setAddress(msg_seealso, "/doc/seealso");
	for(i = 0; i < num_see_also_refs; i++){
		osc_message_u_appendString(msg_seealso, see_also[i]);
	}
	osc_bundle_u_addMsg(bndl, msg_seealso);
	//long len = 0;
	//char *bndl_s = NULL;
	t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl);
	if(bs){
		omax_util_outletOSC(outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
		osc_bundle_s_deepFree(bs);
	}
	if(bndl){
		osc_bundle_u_free(bndl);
	}
}
t_jit_err   o_jit_pcl_supervoxel_matrix_calc(t_o_jit_pcl_supervoxel *x, t_symbol *s, long argc, t_atom *argv)
{
    void                *matrix = NULL;
    t_jit_err			err = JIT_ERR_NONE;
    long				in_savelock;
    t_jit_matrix_info	in_minfo;
    char				*in_bp;
    long				i, j;
    long				dimcount;
    long				planecount;
    long				dim[JIT_MATRIX_MAX_DIMCOUNT];
    char                *fip;
    
    if( argc && argv )
    {
        matrix = jit_object_findregistered(jit_atom_getsym(argv));
    }
    else
        return JIT_ERR_INVALID_INPUT;
    
    if( matrix == NULL || !jit_object_method(matrix, _jit_sym_class_jit_matrix))
        return JIT_ERR_INVALID_PTR;

    in_savelock = (long)jit_object_method(matrix, _jit_sym_lock, 1);
    jit_object_method(matrix, _jit_sym_getinfo, &in_minfo);
    jit_object_method(matrix, _jit_sym_getdata, &in_bp);
    
    if (!in_bp)
        return JIT_ERR_INVALID_INPUT;
    
    //get dimensions/planecount
    dimcount   = in_minfo.dimcount;
    planecount = in_minfo.planecount;
    
    if( planecount < 6 )
    {
        object_error((t_object *)x, "requires a 6 plane matrix (xyzrgb)");
        err = JIT_ERR_INVALID_INPUT;
        goto out;
    }
    if( in_minfo.type != _jit_sym_float32)
    {
        object_error((t_object *)x, "received: %s jit.pcl uses only float32 matrixes", in_minfo.type->s_name );
        err = JIT_ERR_INVALID_INPUT;
        goto out;
    }
    
    //if dimsize is 1, treat as infinite domain across that dimension.
    //otherwise truncate if less than the output dimsize
    for (i=0; i<dimcount; i++) {
        dim[i] = in_minfo.dim[i];
        if ( in_minfo.dim[i]<dim[i] && in_minfo.dim[i]>1) {
            dim[i] = in_minfo.dim[i];
        }
    }
    
    
    {
        //convert to point cloud
        pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
        cloud->width    = (uint32_t)dim[0];
        cloud->height   = (uint32_t)dim[1];
        cloud->points.resize (cloud->width * cloud->height);
        
        size_t count = 0;
        float _x, _y, _z;
        uint8_t _r, _g, _b;
        const float bad_point = std::numeric_limits<float>::quiet_NaN();
        for (j = 0; j < dim[0]; ++j)
        {
            fip = in_bp + j * in_minfo.dimstride[0];
            
            for( i = 0; i < dim[1]; ++i)
            {
                if(count < cloud->points.size())
                {
                    _x = ((float *)fip)[0];
                    _y = ((float *)fip)[1];
                    _z = ((float *)fip)[2];
                    _r = (uint8_t)(((float *)fip)[3] * 255.0);
                    _g = (uint8_t)(((float *)fip)[4] * 255.0);
                    _b = (uint8_t)(((float *)fip)[5] * 255.0);
                    if( !_x && !_y && !_z && !_r && !_g && !_b )
                    {
                        cloud->points[count].x = bad_point;
                        cloud->points[count].y = bad_point;
                        cloud->points[count].z = bad_point;
                        cloud->points[count].r = bad_point;
                        cloud->points[count].g = bad_point;
                        cloud->points[count].b = bad_point;
                        cloud->points[count].a = bad_point;
                    }
                    else
                    {
                        cloud->points[count].x = _x;
                        cloud->points[count].y = _y;
                        cloud->points[count].z = _z;
                        cloud->points[count].r = _r;
                        cloud->points[count].g = _g;
                        cloud->points[count].b = _b;
                        cloud->points[count].a = 255;
                    }
                }
                count++;
                fip += in_minfo.dimstride[1];
            }
        }
        
        {
            typedef pcl::PointXYZRGBA PointT;
            
            pcl::SupervoxelClustering<PointT> super (x->voxel_resolution, x->seed_resolution);
            
            float concavity_tolerance_threshold = 10;
            float smoothness_threshold = 0.1;
            uint32_t min_segment_size = 0;
            bool use_extended_convexity = false;
            bool use_sanity_criterion = false;
            
            if (x->disable_transform)
                super.setUseSingleCameraTransform (false);
            
            super.setInputCloud ( cloud );
            super.setColorImportance (x->color_importance);
            super.setSpatialImportance (x->spatial_importance);
            super.setNormalImportance (x->normal_importance);
            if( cloud->height > 1)
            {
                    super.setUseSingleCameraTransform (false);
            }
            
            std::map <uint32_t, pcl::Supervoxel<PointT>::Ptr > supervoxel_clusters;
            super.extract (supervoxel_clusters);
            
            
            pcl::PointCloud<PointT>::Ptr voxel_centroid_cloud = super.getVoxelCentroidCloud ();
            pcl::PointCloud<pcl::PointXYZL>::Ptr labeled_voxel_cloud = super.getLabeledVoxelCloud ();
            pcl::PointCloud<pcl::PointNormal>::Ptr sv_normal_cloud = super.makeSupervoxelNormalCloud (supervoxel_clusters);
            
            std::multimap<uint32_t, uint32_t> supervoxel_adjacency;
            super.getSupervoxelAdjacency (supervoxel_adjacency);
            
            
            // LCCP
            pcl::LCCPSegmentation<PointT> lccp;
            lccp.setConcavityToleranceThreshold (concavity_tolerance_threshold);
            lccp.setSanityCheck (use_sanity_criterion);
            lccp.setSmoothnessCheck (true, x->voxel_resolution, x->seed_resolution, smoothness_threshold);
            
            uint k_factor = 0;
            if (use_extended_convexity)
                k_factor = 1;
            
            lccp.setKFactor (k_factor);
            lccp.segment (supervoxel_clusters, supervoxel_adjacency);
            
            if (min_segment_size > 0)
            {
                post ("Merging small segments\n");
                lccp.mergeSmallSegments (min_segment_size);
            }
            
            pcl::PointCloud<pcl::PointXYZL>::Ptr sv_labeled_cloud = super.getLabeledCloud ();
            pcl::PointCloud<pcl::PointXYZL>::Ptr lccp_labeled_cloud = sv_labeled_cloud->makeShared ();
            lccp.relabelCloud (*lccp_labeled_cloud);
            
/*
            typedef pcl::LCCPSegmentation<PointT>::SupervoxelAdjacencyList SuperVoxelAdjacencyList;
            typedef pcl::LCCPSegmentation<PointT>::VertexIterator VertexIterator;
            typedef pcl::LCCPSegmentation<PointT>::AdjacencyIterator AdjacencyIterator;
            typedef pcl::LCCPSegmentation<PointT>::EdgeID EdgeID;
            
            SuperVoxelAdjacencyList sv_adjacency_list;
            lccp.getSVAdjacencyList (sv_adjacency_list);
*/

            std::map<uint32_t, std::set<uint32_t> > segment_supervoxel_map;
            lccp.getSegmentSupervoxelMap( segment_supervoxel_map );
            
            std::map<uint32_t, std::set<uint32_t> >::iterator map_iter;
            
            t_osc_bndl_u *bndl = osc_bundle_u_alloc();
            char buf[2048];
            ssize_t count = 0;
            for( map_iter = segment_supervoxel_map.begin(); map_iter != segment_supervoxel_map.end(); ++map_iter)
            {
                uint32_t group_label = map_iter->first;
//                ssize_t ngroup_voxel_pts = map_iter->second.size();
                
                std::set<uint32_t>::iterator pt_id_iter;
                for( pt_id_iter = map_iter->second.begin(); pt_id_iter != map_iter->second.end(); ++pt_id_iter)
                {
                    sprintf(buf, "/supervoxel/pt/%ld", ++count);
                    
                    t_osc_msg_u *supervoxel_group = osc_message_u_allocWithAddress(buf);
                    t_osc_bndl_u *subbndl = osc_bundle_u_alloc();
                    
                    t_osc_msg_u *pt_num = osc_message_u_allocWithAddress((char *)"/pt_id");
                    osc_message_u_appendInt64(pt_num, count);
                    osc_bundle_u_addMsg(subbndl, pt_num);
                    
                    t_osc_msg_u *segment_num = osc_message_u_allocWithAddress((char *)"/group_id");
                    osc_message_u_appendInt32(segment_num, group_label);
                    osc_bundle_u_addMsg(subbndl, segment_num);
                    
                    pcl::Supervoxel<pcl::PointXYZRGBA>::Ptr supervoxel = supervoxel_clusters.at( *pt_id_iter );
                    
                    t_osc_msg_u *centroid = osc_message_u_allocWithAddress((char *)"/centroid/xyz");
                    osc_message_u_appendFloat(centroid, supervoxel->centroid_.x);
                    osc_message_u_appendFloat(centroid, supervoxel->centroid_.y);
                    osc_message_u_appendFloat(centroid, supervoxel->centroid_.z);
                    osc_bundle_u_addMsg(subbndl, centroid);
                    
                    t_osc_msg_u *centroid_color = osc_message_u_allocWithAddress((char *)"/centroid/rgb");
                    osc_message_u_appendFloat(centroid_color, supervoxel->centroid_.r);
                    osc_message_u_appendFloat(centroid_color, supervoxel->centroid_.g);
                    osc_message_u_appendFloat(centroid_color, supervoxel->centroid_.b);
                    osc_bundle_u_addMsg(subbndl, centroid_color);
                    
                    pcl::PointCloud<pcl::PointXYZRGBA> adjacent_supervoxel_centers;
                    
                    t_osc_msg_u *adjx = osc_message_u_allocWithAddress((char *)"/adjacent/x");
                    t_osc_msg_u *adjy = osc_message_u_allocWithAddress((char *)"/adjacent/y");
                    t_osc_msg_u *adjz = osc_message_u_allocWithAddress((char *)"/adjacent/z");
                    
                    std::multimap<uint32_t,uint32_t>::iterator adjacent_itr = supervoxel_adjacency.equal_range(*pt_id_iter).first;
                    for ( ; adjacent_itr!=supervoxel_adjacency.equal_range(*pt_id_iter).second; ++adjacent_itr)
                    {
                        pcl::Supervoxel<pcl::PointXYZRGBA>::Ptr neighbor_supervoxel = supervoxel_clusters.at(adjacent_itr->second);
                        osc_message_u_appendFloat(adjx, neighbor_supervoxel->centroid_.x);
                        osc_message_u_appendFloat(adjy, neighbor_supervoxel->centroid_.y);
                        osc_message_u_appendFloat(adjz, neighbor_supervoxel->centroid_.z);
                        
                        // line from supervoxel->centroid_ to each adjacent_supervoxel_centers
                        
                    }
                    
                    osc_bundle_u_addMsg(subbndl, adjx);
                    osc_bundle_u_addMsg(subbndl, adjy);
                    osc_bundle_u_addMsg(subbndl, adjz);
                    
                    osc_message_u_appendBndl_u(supervoxel_group, subbndl);
                    osc_bundle_u_addMsg(bndl, supervoxel_group);

                }
                
                

//                post("%d %d", group_label, ngroup_voxel_pts);
            }

            
//            for( int i = 0; i < lccp_labeled_cloud->points.size(); i++ )
//                post("%d %d", lccp_labeled_cloud->points.size(), lccp_labeled_cloud->points[i].label);
            
 /*

            
            std::set<EdgeID> edge_drawn;
            
                     //The vertices in the supervoxel adjacency list are the supervoxel centroids
            //This iterates through them, finding the edges
            std::pair<VertexIterator, VertexIterator> vertex_iterator_range;
            vertex_iterator_range = boost::vertices (sv_adjacency_list);
            

            t_osc_bndl_u *bndl = osc_bundle_u_alloc();
            char buf[2048];
            
            
            for (VertexIterator itr = vertex_iterator_range.first; itr != vertex_iterator_range.second; ++itr)
            {
                const uint32_t sv_label = sv_adjacency_list[*itr];
                pcl::Supervoxel<PointT>::Ptr supervoxel = supervoxel_clusters.at (sv_label);
                pcl::PointXYZRGBA vert_curr = supervoxel->centroid_;
//                pcl::PointXYZL lccp_pt = lccp_labeled_cloud->at ( sv_label );
                const uint32_t group_label = lccp_labeled_cloud->at ( sv_label ).label;

                //                const uint32_t group_label = lccp_labeled_cloud->points[ sv_label ].label;

                
                sprintf(buf, "/supervoxel/%d/%d", group_label, sv_label);
                post("%s", buf);
                t_osc_msg_u *supervoxel_group = osc_message_u_allocWithAddress(buf);
                t_osc_bndl_u *subbndl = osc_bundle_u_alloc();

                t_osc_msg_u *centroid = osc_message_u_allocWithAddress((char *)"/centroid/xyz");
                osc_message_u_appendFloat(centroid, vert_curr.x);
                osc_message_u_appendFloat(centroid, vert_curr.y);
                osc_message_u_appendFloat(centroid, vert_curr.z);
                osc_bundle_u_addMsg(subbndl, centroid);
                
                t_osc_msg_u *centroid_color = osc_message_u_allocWithAddress((char *)"/centroid/rgb");
                osc_message_u_appendFloat(centroid_color, vert_curr.r);
                osc_message_u_appendFloat(centroid_color, vert_curr.g);
                osc_message_u_appendFloat(centroid_color, vert_curr.b);
                osc_bundle_u_addMsg(subbndl, centroid_color);
                
                t_osc_msg_u *adjx = osc_message_u_allocWithAddress((char *)"/adjacent/x");
                t_osc_msg_u *adjy = osc_message_u_allocWithAddress((char *)"/adjacent/y");
                t_osc_msg_u *adjz = osc_message_u_allocWithAddress((char *)"/adjacent/z");
                
                t_osc_msg_u *is_conv = osc_message_u_allocWithAddress((char *)"/vertex/convex");
                
                std::pair<AdjacencyIterator, AdjacencyIterator> neighbors = boost::adjacent_vertices (*itr, sv_adjacency_list);
                
                for (AdjacencyIterator itr_neighbor = neighbors.first; itr_neighbor != neighbors.second; ++itr_neighbor)
                {
                    EdgeID connecting_edge = boost::edge (*itr, *itr_neighbor, sv_adjacency_list).first;  //Get the edge
                    osc_message_u_appendBool(is_conv, sv_adjacency_list[connecting_edge].is_convex);

                    const uint32_t sv_neighbor_label = sv_adjacency_list[*itr_neighbor];
                    pcl::Supervoxel<PointT>::Ptr supervoxel_neigh = supervoxel_clusters.at (sv_neighbor_label);
                    pcl::PointXYZRGBA vert_neigh = supervoxel_neigh->centroid_;
                    
                    osc_message_u_appendFloat(adjx, vert_neigh.x);
                    osc_message_u_appendFloat(adjy, vert_neigh.y);
                    osc_message_u_appendFloat(adjz, vert_neigh.z);

                    
                }
                
                osc_bundle_u_addMsg(subbndl, adjx);
                osc_bundle_u_addMsg(subbndl, adjy);
                osc_bundle_u_addMsg(subbndl, adjz);
                osc_bundle_u_addMsg(subbndl, is_conv);

                
                osc_message_u_appendBndl_u(supervoxel_group, subbndl);
                osc_bundle_u_addMsg(bndl, supervoxel_group);
            }
            post("--------------");
*/
            
/*
            //To make a graph of the supervoxel adjacency, we need to iterate through the supervoxel adjacency multimap
            std::multimap<uint32_t,uint32_t>::iterator label_itr = supervoxel_adjacency.begin ();
            for ( ; label_itr != supervoxel_adjacency.end (); )
            {
                //First get the label
                uint32_t supervoxel_label = label_itr->first;
                pcl::Supervoxel<pcl::PointXYZRGBA>::Ptr supervoxel = supervoxel_clusters.at( supervoxel_label );

                sprintf(buf, "/supervoxel/%d", supervoxel_label);
                t_osc_msg_u *supervoxel_group = osc_message_u_allocWithAddress(buf);
                
                t_osc_bndl_u *subbndl = osc_bundle_u_alloc();

                t_osc_msg_u *centroid = osc_message_u_allocWithAddress((char *)"/centroid/xyz");
                osc_message_u_appendFloat(centroid, supervoxel->centroid_.x);
                osc_message_u_appendFloat(centroid, supervoxel->centroid_.y);
                osc_message_u_appendFloat(centroid, supervoxel->centroid_.z);
                osc_bundle_u_addMsg(subbndl, centroid);
                
                t_osc_msg_u *centroid_color = osc_message_u_allocWithAddress((char *)"/centroid/rgb");
                osc_message_u_appendFloat(centroid_color, supervoxel->centroid_.r);
                osc_message_u_appendFloat(centroid_color, supervoxel->centroid_.g);
                osc_message_u_appendFloat(centroid_color, supervoxel->centroid_.b);
                osc_bundle_u_addMsg(subbndl, centroid_color);
                
                
                pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_hull_ (new pcl::PointCloud<pcl::PointXYZRGBA>);
                std::vector<pcl::Vertices> vertices_;

                //get convex hull of supervoxel region:

                pcl::ConvexHull<pcl::PointXYZRGBA> hr;
                hr.setDimension(3);
                hr.setInputCloud(supervoxel->voxels_);
                //            cloud_hull_.reset (new Cloud); << save on reallocating memory later?
                hr.reconstruct (*cloud_hull_, vertices_);

                t_osc_msg_u *cvx_x = osc_message_u_allocWithAddress((char *)"/convexhull/pts/x");
                t_osc_msg_u *cvx_y = osc_message_u_allocWithAddress((char *)"/convexhull/pts/y");
                t_osc_msg_u *cvx_z = osc_message_u_allocWithAddress((char *)"/convexhull/pts/z");
                for( long j = 0; j < cloud_hull_->points.size(); ++j)
                {
                    osc_message_u_appendFloat(cvx_x, cloud_hull_->points[j].x);
                    osc_message_u_appendFloat(cvx_y, cloud_hull_->points[j].y);
                    osc_message_u_appendFloat(cvx_z, cloud_hull_->points[j].z);
                }
                osc_bundle_u_addMsg(subbndl, cvx_x);
                osc_bundle_u_addMsg(subbndl, cvx_y);
                osc_bundle_u_addMsg(subbndl, cvx_z);
                
                t_osc_msg_u *vert0 = osc_message_u_allocWithAddress((char *)"/convexhull/vertex/idx/0");
                t_osc_msg_u *vert1 = osc_message_u_allocWithAddress((char *)"/convexhull/vertex/idx/1");
                t_osc_msg_u *vert2 = osc_message_u_allocWithAddress((char *)"/convexhull/vertex/idx/2");

                std::vector<pcl::Vertices>::iterator iter_vertices;
                for( iter_vertices = vertices_.begin(); iter_vertices != vertices_.end(); ++iter_vertices)
                {
                    osc_message_u_appendInt32(vert0, (*iter_vertices).vertices[0]);
                    osc_message_u_appendInt32(vert1, (*iter_vertices).vertices[1]);
                    osc_message_u_appendInt32(vert2, (*iter_vertices).vertices[3]);
                    
                }
                osc_bundle_u_addMsg(subbndl, vert0);
                osc_bundle_u_addMsg(subbndl, vert1);
                osc_bundle_u_addMsg(subbndl, vert2);
                
                //Now we need to iterate through the adjacent supervoxels and make a point cloud of them
//                pcl::PointCloud<pcl::PointXYZRGBA> adjacent_supervoxel_centers;
  
                t_osc_msg_u *adjx = osc_message_u_allocWithAddress((char *)"/adjacent/x");
                t_osc_msg_u *adjy = osc_message_u_allocWithAddress((char *)"/adjacent/y");
                t_osc_msg_u *adjz = osc_message_u_allocWithAddress((char *)"/adjacent/z");
                
                std::multimap<uint32_t,uint32_t>::iterator adjacent_itr = supervoxel_adjacency.equal_range(supervoxel_label).first;
                for ( ; adjacent_itr!=supervoxel_adjacency.equal_range(supervoxel_label).second; ++adjacent_itr)
                {
                    pcl::Supervoxel<pcl::PointXYZRGBA>::Ptr neighbor_supervoxel = supervoxel_clusters.at(adjacent_itr->second);
                    osc_message_u_appendFloat(adjx, neighbor_supervoxel->centroid_.x);
                    osc_message_u_appendFloat(adjy, neighbor_supervoxel->centroid_.y);
                    osc_message_u_appendFloat(adjz, neighbor_supervoxel->centroid_.z);
                    
                    // line from supervoxel->centroid_ to each adjacent_supervoxel_centers
                    
                }
                
                osc_bundle_u_addMsg(subbndl, adjx);
                osc_bundle_u_addMsg(subbndl, adjy);
                osc_bundle_u_addMsg(subbndl, adjz);
                
                osc_message_u_appendBndl_u(supervoxel_group, subbndl);
                osc_bundle_u_addMsg(bndl, supervoxel_group);
                
                //Move iterator forward to next label
                label_itr = supervoxel_adjacency.upper_bound (supervoxel_label);
            }
*/
            omax_util_outletOSC_u(x->outlet, bndl);
            
            if(bndl)
                osc_bundle_u_free(bndl);

        }

    }
out:
    jit_object_method(matrix, _jit_sym_lock, in_savelock);
    return err;
}
Пример #17
0
int main(int argc, char **argv)
{
	// create a bundle and add messages to it
	t_osc_bndl_u *bndl_u = osc_bundle_u_alloc();
	t_osc_msg_u *m1 = osc_message_u_alloc();
	osc_message_u_setAddress(m1, "/foo");
	osc_message_u_appendFloat(m1, 3.14);
	osc_bundle_u_addMsg(bndl_u, m1);

	t_osc_msg_u *m2 = osc_message_u_allocWithString("/bar", "whatevs");
	osc_bundle_u_addMsg(bndl_u, m2);

	t_osc_msg_u *m3 = osc_message_u_allocWithAddress("/bloo");
	t_osc_atom_u *a = osc_atom_u_allocWithInt32(12);
	osc_message_u_appendAtom(m3, a);
	osc_bundle_u_addMsg(bndl_u, m3);

	// serialize the bundle
	long len = osc_bundle_u_nserialize(NULL, 0, bndl_u);
	char bndl_s[len];
	osc_bundle_u_nserialize(bndl_s, len, bndl_u);

	// free the original unserialized bundle
	osc_bundle_u_free(bndl_u);
	bndl_u = NULL;

	// deserialize the serialized bundle
	osc_bundle_s_deserialize(len, bndl_s, &bndl_u);
	
	// iterate over messages in a serialized bundle
	t_osc_bndl_it_s *b_it_s = osc_bndl_it_s_get(len, bndl_s);
	while(osc_bndl_it_s_hasNext(b_it_s)){
		t_osc_msg_s *m = osc_bndl_it_s_next(b_it_s);
		printf("%s\n", osc_message_s_getAddress(m));
	}
	osc_bndl_it_s_destroy(b_it_s);

	// turn a serialized bundle into printable text
	long tlen = osc_bundle_s_nformat(NULL, 0, len, bndl_s, 0);
	char text[tlen + 1];
	osc_bundle_s_nformat(text, tlen, len, bndl_s, 0);
	printf("\nBUNDLE:\n");
	printf("%s\n", text);
	printf("\n");

	// turn text into an unserialized bundle
	t_osc_bndl_u *bndl_u_2 = NULL;
	char *text2 = "/jean : [1, 2, 3], /john : 6.66, /jeremy : \"is cool\"";
	osc_parser_parseString(strlen(text2), text2, &bndl_u_2);

	// iterate over messages in an unserialized bundle
	t_osc_bndl_it_u *b_it_u = osc_bndl_it_u_get(bndl_u_2);
	while(osc_bndl_it_u_hasNext(b_it_u)){
		t_osc_msg_u *m = osc_bndl_it_u_next(b_it_u);
		printf("%s has typetags ", osc_message_u_getAddress(m));
		// iterate over atoms in list
		t_osc_msg_it_u *m_it_u = osc_msg_it_u_get(m);
		while(osc_msg_it_u_hasNext(m_it_u)){
			t_osc_atom_u *a = osc_msg_it_u_next(m_it_u);
			printf("%c", osc_atom_u_getTypetag(a));
		}
		osc_msg_it_u_destroy(m_it_u);
		printf("\n");
	}
	osc_bndl_it_u_destroy(b_it_u);
}
Пример #18
0
t_osc_bndl_u *ocontext_processCanvas(t_canvas *canvas)
{
	t_osc_bndl_u *canvas_bndl = osc_bundle_u_alloc();
	if(canvas == NULL){
		// return empty bundle---this is intentional
		return canvas_bndl;
	}

    t_osc_msg_u *msg = NULL;

    msg = osc_message_u_allocWithAddress("/name");
    osc_message_u_appendString(msg, canvas->gl_name->s_name);
    osc_bundle_u_addMsg(canvas_bndl, msg);

    t_canvasenvironment *c_env = canvas_getenv(canvas);
    
    msg = osc_message_u_allocWithAddress("/path");
    osc_message_u_appendString(msg, c_env->ce_dir->s_name);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/$0");
    osc_message_u_appendInt32(msg, c_env->ce_dollarzero);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/isabstraction");
    osc_message_u_appendBool(msg, !canvas_isabstraction(canvas));
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/editmode");
    osc_message_u_appendBool(msg, canvas->gl_edit);
    osc_bundle_u_addMsg(canvas_bndl, msg);

    msg = osc_message_u_allocWithAddress("/font");
    osc_message_u_appendString(msg, sys_font);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/fontsize");
    osc_message_u_appendInt32(msg, canvas->gl_font);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/dirty");
    osc_message_u_appendBool(msg, canvas->gl_dirty);
    osc_bundle_u_addMsg(canvas_bndl, msg);

    if(!canvas_isabstraction(canvas))
    {
        msg = osc_message_u_allocWithAddress("/abstraction/position/x1");
        osc_message_u_appendInt32(msg, canvas->gl_obj.te_xpix);
        osc_bundle_u_addMsg(canvas_bndl, msg);
        
        msg = osc_message_u_allocWithAddress("/abstraction/position/y1");
        osc_message_u_appendInt32(msg, canvas->gl_obj.te_ypix);
        osc_bundle_u_addMsg(canvas_bndl, msg);
    }
    
    msg = osc_message_u_allocWithAddress("/pixwidth");
    osc_message_u_appendInt32(msg, canvas->gl_pixwidth);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/pixheight");
    osc_message_u_appendInt32(msg, canvas->gl_pixheight);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/screen/x1");
    osc_message_u_appendInt32(msg, canvas->gl_screenx1);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/screen/y1");
    osc_message_u_appendInt32(msg, canvas->gl_screeny1);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/screen/x2");
    osc_message_u_appendInt32(msg, canvas->gl_screenx2);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    msg = osc_message_u_allocWithAddress("/screen/y2");
    osc_message_u_appendInt32(msg, canvas->gl_screeny2);
    osc_bundle_u_addMsg(canvas_bndl, msg);

    msg = osc_message_u_allocWithAddress("/xmargin");
    osc_message_u_appendInt32(msg, canvas->gl_xmargin);
    osc_bundle_u_addMsg(canvas_bndl, msg);

    msg = osc_message_u_allocWithAddress("/ymargin");
    osc_message_u_appendInt32(msg, canvas->gl_ymargin);
    osc_bundle_u_addMsg(canvas_bndl, msg);
    
    if(canvas->gl_goprect && canvas->gl_owner)
    {
        int x1,y1,x2,y2;
        gobj_getrect(&canvas->gl_obj.te_g, canvas->gl_owner, &x1, &y1, &x2, &y2);

        msg = osc_message_u_allocWithAddress("/graphrect");
        osc_message_u_appendInt32(msg, x1);
        osc_message_u_appendInt32(msg, y1);
        osc_message_u_appendInt32(msg, x2);
        osc_message_u_appendInt32(msg, y2);
        osc_bundle_u_addMsg(canvas_bndl, msg);
    }
    
    t_binbuf *b = NULL;
    b = canvas->gl_obj.te_binbuf;
    
    if(b)
    {
        int argc = binbuf_getnatom(b);
        t_atom *argv = binbuf_getvec(b);

        if(argc)
        {
            t_osc_msg_u *msg_u = NULL;
            int abstr = !canvas_isabstraction(canvas);
            t_osc_err e = omax_util_maxAtomsToOSCMsg_u(&msg_u, gensym("/arguments"), argc-1-abstr, argv+1+abstr);
            if(e)
            {
                if(e){
                    object_error((t_object *)x, "%s", osc_error_string(e));
                    goto exit;
                }
            }
            osc_bundle_u_addMsg(canvas_bndl, msg_u);
        }
        else
        {
            msg = osc_message_u_allocWithAddress("/arguments");
            osc_message_u_appendString(msg, "");
            osc_bundle_u_addMsg(canvas_bndl, msg);
        }
    }
    else
    {
        msg = osc_message_u_allocWithAddress("/arguments");
        osc_message_u_appendString(msg, "");
        osc_bundle_u_addMsg(canvas_bndl, msg);
    }
    
exit:
    if(canvas->gl_owner)
    {
        t_osc_bndl_u *parent_bndl = ocontext_processCanvas(canvas->gl_owner);
		t_osc_msg_u *pmsg = osc_message_u_allocWithAddress("/parent");
		osc_message_u_appendBndl_u(pmsg, parent_bndl);
		osc_bundle_u_addMsg(canvas_bndl, pmsg);
    }
    
	return canvas_bndl;
}
Пример #19
0
void olistenumerate_doFullPacket(t_olistenumerate *x,
                           long len,
                           char *ptr)
{
    if (!x->address) {
        return;
    }
    
    critical_enter(x->lock);
    char* address_name = x->address->s_name;
    critical_exit(x->lock);
    
    t_osc_msg_ar_s *matches = osc_bundle_s_lookupAddress(len, ptr, address_name, 1);
    
    char delegate[len];
    long dlen = len;
    memcpy(delegate, ptr, len);
    
    if (matches) {
        // right outlet:
        osc_bundle_s_removeMessage(address_name, &dlen, delegate, 1);
        int message_count = 0;
        osc_bundle_s_getMsgCount(dlen, delegate, &message_count);
        if (message_count > 0) {
            omax_util_outletOSC(x->outlets[0], dlen, delegate);
            OSC_MEM_INVALIDATE(delegate);
        }
        
        // left outlet:
        for (int i = 0; i < osc_array_getLen(matches); ++i)
        {
            t_osc_message_s* message_match = (t_osc_message_s*)osc_array_get(matches, i);
            t_osc_message_u* unserialized_msg = osc_message_s_deserialize(message_match);
            
            int array_length = osc_message_u_getArgCount(unserialized_msg);
            if (array_length > 0)
            {
                for (int j = 0; j < array_length; ++j)
                {
			t_osc_atom_u* iter_atom = osc_message_u_getArg(unserialized_msg, j);
                    t_osc_atom_u* atom_copy = osc_atom_u_copy(iter_atom);
                    if (atom_copy)
                    {
                        t_osc_bundle_u* unserialized_result = NULL;
                        //char type = osc_atom_u_getTypetag(atom_copy);
                        unserialized_result = osc_bundle_u_alloc();
                        t_osc_message_u* value = osc_message_u_allocWithAddress("/value");
                        osc_message_u_appendAtom(value, atom_copy);
                        osc_bundle_u_addMsg(unserialized_result, value);
                        
                        t_osc_message_u* address = osc_message_u_allocWithString("/address", address_name);
                        t_osc_message_u* index = osc_message_u_allocWithAddress("/index");
                        osc_message_u_appendInt32(index, j);
                        t_osc_message_u* length = osc_message_u_allocWithAddress("/length");
                        osc_message_u_appendInt32(length, array_length);
                        osc_bundle_u_addMsg(unserialized_result, address);
                        osc_bundle_u_addMsg(unserialized_result, index);
                        osc_bundle_u_addMsg(unserialized_result, length);
                        t_osc_bndl_s *bs = osc_bundle_u_serialize(unserialized_result);
                        osc_bundle_u_free(unserialized_result); // frees value, count, length and atom_copy
                        unserialized_result = NULL;
                        atom_copy = NULL;
                        
                        if (bs)
                        {
				omax_util_outletOSC(x->outlets[1], osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
				osc_bundle_s_deepFree(bs);
                            bs = NULL;
                        }
                    }
                }
                
                if (unserialized_msg) {
                    osc_message_u_free(unserialized_msg);
                    unserialized_msg = NULL;
                }
                
            } else {
                olistenumerate_noMatchesOrData(x);
            }
        }
    } else { // no matches
        // right outlet:
        omax_util_outletOSC(x->outlets[0], dlen, delegate);
    }
    
    if (matches) {
        osc_array_free(matches);
    }
}