Exemplo n.º 1
0
t_osc_bndl_u *omax_pcl_fn_queue::FullPacketBroadcast(long len, char *ptr)
{
    
    //send out copy of internal state bundle which gets freed in max
    t_osc_bndl_u *bndl = NULL, *u_bndl = NULL;
    
    for( int i = 0; i < m_fullpackets.size(); i++ )
    {
        
        if( bndl )
            osc_bundle_u_free( bndl );
        
        bndl = NULL;
//        bndl = m_fullpackets[i]( len, ptr );
        
        t_osc_bndl_u * tmp = NULL;
        osc_bundle_u_union( bndl, tmp, &u_bndl );
        
        if(u_bndl)
            osc_bundle_u_free( u_bndl );
        
        u_bndl = NULL;
        osc_bundle_u_copy( &u_bndl, tmp );
        
        if( tmp )
            osc_bundle_u_free( tmp );
        
    }
    
    return bndl;
}
Exemplo n.º 2
0
t_osc_bndl_u *omax_pcl_fn_queue::getStates()
{
    //send out copy of internal state bundle which gets freed in max
    t_osc_bndl_u *bndl = NULL, *u_bndl = NULL;
    
    for( int i = 0; i < m_queries.size(); i++ )
    {
        
        if( bndl )
            osc_bundle_u_free( bndl );
        
        bndl = NULL;
        bndl = (this->*m_queries[i])();
        
        t_osc_bndl_u * tmp = NULL;
        osc_bundle_u_union( bndl, tmp, &u_bndl );

        if(u_bndl)
            osc_bundle_u_free( u_bndl );

        u_bndl = NULL;
        osc_bundle_u_copy( &u_bndl, tmp );
        
        if( tmp )
            osc_bundle_u_free( tmp );
        
    }

    return bndl;
}
Exemplo n.º 3
0
void otimetag_doFullPacket(t_otimetag *x,
			   long len,
			   char *ptr)
{
	t_osc_timetag t = osc_timetag_now();
	if(x->address){
		t_osc_bndl_u *copy = osc_bundle_s_deserialize(len, ptr);

		t_osc_msg_u *m = osc_message_u_allocWithTimetag(x->address->s_name, t);
		osc_bundle_u_addMsgWithoutDups(copy, m);

		t_osc_bndl_s *bs = osc_bundle_u_serialize(copy);
		if(bs){
			omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
			osc_bundle_s_deepFree(bs);
		}
		osc_bundle_u_free(copy);
	}else{
		char copy[len];
		memcpy(copy, ptr, len);
		osc_bundle_s_setTimetag(len, copy, t);
		omax_util_outletOSC(x->outlet, len, copy);
        OSC_MEM_INVALIDATE(copy);
	}
}
Exemplo n.º 4
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);
	*/
}
Exemplo n.º 5
0
void oedge_free(t_oedge *x)
{
	dsp_free((t_pxobject *)x);
	critical_free(x->lock);
	if(x->av){
		sysmem_freeptr(x->av);
	}
	osc_bundle_u_free(x->bundle);
}
Exemplo n.º 6
0
void ouniform_doFullPacket(t_ouniform *x,
                           long len,
                           char *ptr)
{
    int seed_is_bound = 0;
    osc_bundle_s_addressIsBound(len, ptr, "/uniform/set/seed", 1, &seed_is_bound);
    if (seed_is_bound) {
        long change_to = ouniform_getNumber(len, ptr, "/uniform/set/seed");
        
        if (change_to > 0) {
            if (x->seed != change_to) {
                x->seed = change_to;
                srand(x->seed);
                x->state = 0;
            }
        }
        osc_bundle_s_removeMessage("/uniform/set/seed", &len, ptr, 1);
    }
    int state_is_bound = 0;
    osc_bundle_s_addressIsBound(len, ptr, "/uniform/set/state", 1, &state_is_bound);
    if (state_is_bound) {
        long change_to = ouniform_getNumber(len, ptr, "/uniform/set/state");
        if (change_to >= 0) {
            x->state = 0;
            srand(x->seed);
            for (int i = 0; i < change_to; ++i) {
                rand();
                ++x->state;
            }
        }
        osc_bundle_s_removeMessage("/uniform/set/state", &len, ptr, 1);
    }
    
    t_osc_bndl_u *copy = osc_bundle_s_deserialize(len, ptr);
    t_osc_message_u *result = NULL;
    if(x->address) {
        result = osc_message_u_allocWithFloat(x->address->s_name, (1.0f * rand() / RAND_MAX));
    }else{
        result = osc_message_u_allocWithFloat("/uniform/random", (1.0f * rand() / RAND_MAX));
    }
    t_osc_message_u *seed = osc_message_u_allocWithAddress("/uniform/seed");
    osc_message_u_appendInt32(seed, x->seed);
    t_osc_message_u *state = osc_message_u_allocWithAddress("/uniform/state");
    osc_message_u_appendInt32(state, x->state);
    osc_bundle_u_addMsgWithoutDups(copy, result);
    osc_bundle_u_addMsgWithoutDups(copy, seed);
    osc_bundle_u_addMsgWithoutDups(copy, state);
    
    ++x->state;
    
    t_osc_bndl_s *bs = osc_bundle_u_serialize(copy);
    if(bs){
	    omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
	    osc_bundle_s_deepFree(bs);
    }
    osc_bundle_u_free(copy);
}
Exemplo n.º 7
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)
    
    
}
Exemplo n.º 8
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);
	}

}
Exemplo n.º 9
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);
}
Exemplo n.º 10
0
void odisplay_clearBundles(t_odisplay *x)
{
	critical_enter(x->lock);
	if(x->bndl_u){
		osc_bundle_u_free(x->bndl_u);
		x->bndl_u = NULL;
	}
	if(x->bndl_s){
		osc_bundle_s_deepFree(x->bndl_s);
		x->bndl_s = NULL;
	}
#ifndef OMAX_PD_VERSION
	if(x->text){
		x->textlen = 0;
		osc_mem_free(x->text);
		x->text = NULL;
	}
#endif
	critical_exit(x->lock);
}
Exemplo n.º 11
0
void ocontext_doFullPacket(t_ocontext *x, long len, char *ptr)
{
	t_canvas *patcher = NULL;
    
    patcher = x->canvas;
    
	t_osc_bndl_u *mypatcher_bndl = ocontext_processCanvas(patcher);
	t_osc_msg_u *context_msg = osc_message_u_allocWithAddress("/context");
	osc_message_u_appendBndl_u(context_msg, mypatcher_bndl);
	t_osc_bndl_u *bu = osc_bundle_s_deserialize(len, ptr);
	if(bu){
		osc_bundle_u_addMsgWithoutDups(bu, context_msg);
		t_osc_bndl_s *bs = osc_bundle_u_serialize(bu);
		if(bs){
			omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
			osc_bundle_s_deepFree(bs);
		}
	}
	osc_bundle_u_free(mypatcher_bndl);
}
Exemplo n.º 12
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;
    }
}
Exemplo n.º 13
0
void ocontext_doFullPacket(t_ocontext *x, long len, char *ptr)
{
	t_object *parent = NULL, *patcher = NULL;
        object_obex_lookup(x, gensym("#P"), &patcher);

	//t_jbox *box = NULL;
        //object_obex_lookup(x, gensym("#B"), &box);

	t_osc_bndl_u *mypatcher_bndl = ocontext_processPatcher(patcher);
	t_osc_msg_u *context_msg = osc_message_u_allocWithAddress("/context");
	osc_message_u_appendBndl_u(context_msg, mypatcher_bndl);
	t_osc_bndl_u *bu = osc_bundle_s_deserialize(len, ptr);
	if(bu){
		osc_bundle_u_addMsgWithoutDups(bu, context_msg);
		t_osc_bndl_s *bs = osc_bundle_u_serialize(bu);
		if(bs){
			omax_util_outletOSC(x->outlet, osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
			osc_bundle_s_deepFree(bs);
		}
		osc_bundle_u_free(bu);
	}
}
Exemplo n.º 14
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);
    }
}
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;
}
Exemplo n.º 16
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);
}
Exemplo n.º 17
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);
	}
}
Exemplo n.º 18
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);
	}
}
Exemplo n.º 19
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);
 	}
}
Exemplo n.º 20
0
//void odowncast_fullPacket(t_odowncast *x, long len, long ptr)
void odowncast_fullPacket(t_odowncast *x, t_symbol *msg, int argc, t_atom *argv)
{
	OMAX_UTIL_GET_LEN_AND_PTR;
	t_osc_bndl_u *b = osc_bundle_s_deserialize(len, ptr);
	if(!b){
		object_error((t_object *)x, "invalid OSC packet");
		return;
	}
	/*
	if(x->flatten_nested_bundles){
		t_osc_bndl_u *bf = NULL;
		e = osc_bundle_u_flatten(&bf, b
	}
	*/
	t_osc_bndl_u **nestedbundles = NULL;
	int nnestedbundles = 0, nestedbundles_buflen = 0;
	t_osc_bndl_it_u *bit = osc_bndl_it_u_get(b);
	t_osc_timetag timetag = OSC_TIMETAG_NULL;
	while(osc_bndl_it_u_hasNext(bit)){
		t_osc_msg_u *m = osc_bndl_it_u_next(bit);
		t_osc_msg_it_u *mit = osc_msg_it_u_get(m);
		while(osc_msg_it_u_hasNext(mit)){
			t_osc_atom_u *a = osc_msg_it_u_next(mit);
			int i = 0;
			switch(osc_atom_u_getTypetag(a)){
			case 'c':
			case 'C':
			case 'I':
			case 'h':
			case 'H':
			case 'u':
			case 'U':
			case 'N':
			case 'T':
			case 'F':
				if(x->ints){
					osc_atom_u_setInt32(a, osc_atom_u_getInt32(a));
				}
				break;
			case 'd':
				if(x->doubles){
					osc_atom_u_setFloat(a, osc_atom_u_getFloat(a));
				}
				break;
			case OSC_BUNDLE_TYPETAG:
				if(x->bundles){
					if(!nestedbundles || nnestedbundles == nestedbundles_buflen){
						nestedbundles = (t_osc_bndl_u **)osc_mem_resize(nestedbundles, (nestedbundles_buflen + 16) * sizeof(char *));
					}
					nestedbundles[nnestedbundles++] = osc_atom_u_getBndl(a);
					osc_message_u_removeAtom(m, a);
				}
				break;
			case OSC_TIMETAG_TYPETAG:
#if OSC_TIMETAG_FORMAT == OSC_TIMETAG_NTP
				if(x->timetags){
					t_osc_timetag tt = osc_atom_u_getTimetag(a);
					if(x->timetag_address){
						char *address = osc_message_u_getAddress(m);
						if(!strcmp(address, x->timetag_address->s_name)){
							timetag = tt;
						}
					}
					t_osc_atom_u *aa = osc_atom_u_alloc();
					int32_t tt1, tt2;
					//tt1 = (tt & 0xffffffff00000000) >> 32;
					//tt2 = tt & 0xffffffff;
					tt1 = osc_timetag_ntp_getSeconds(tt);
					tt2 = osc_timetag_ntp_getFraction(tt);
					osc_atom_u_setInt32(aa, ntoh32(tt1));
					osc_atom_u_setInt32(a, ntoh32(tt2));
					osc_message_u_insertAtom(m, aa, ++i);
				}
#else
				object_error((t_object *)x, "o.downcast only supports NTP timetags");
#endif
				break;
			}
			i++;
		}
		osc_msg_it_u_destroy(mit);
	}
	osc_bndl_it_u_destroy(bit);
	t_osc_bndl_s *bs1 = osc_bundle_u_serialize(b);
	if(bs1){
		long l = osc_bundle_s_getLen(bs1);
		char *p = osc_bundle_s_getPtr(bs1);
		memcpy(p + OSC_ID_SIZE, &timetag, sizeof(t_osc_timetag));
		for(int i = 0; i < nnestedbundles; i++){
			t_osc_bndl_s *bs2 = osc_bundle_u_serialize(nestedbundles[i]);
			if(bs2){
				long ll = osc_bundle_s_getLen(bs2);
				char *pp = osc_bundle_s_getPtr(bs2);
				p = osc_mem_resize(p, l + ll);
				memcpy(p + l, pp, ll);
				l += ll;
				osc_bundle_s_deepFree(bs2);
			}
		}
		//if(x->bundle){
		omax_util_outletOSC(x->outlet, l, p);
			/*
		}else{
			t_osc_bndl_it_s *bit = osc_bndl_it_s_get(l, p);
			while(osc_bndl_it_s_hasNext(bit)){
				t_osc_msg_s *m = osc_bndl_it_s_next(bit);
				long ml = osc_message_s_getSize(m);
				char *mp = osc_message_s_getAddress(m);
				omax_util_outletOSC(x->outlet, ml, mp);
			}
			osc_bndl_it_s_destroy(bit);
		}
			*/
		osc_bundle_s_deepFree(bs1);
	}
	osc_bundle_u_free(b);
}
Exemplo n.º 21
0
//input an expression and a bundle with data and have it evaluate the expression and compares the results to answer. 
int test_expression(char *expr, char *bundle_string, char *answer){
	t_osc_expr *f = NULL; //f = function = lambda
	int ret = osc_expr_parser_parseString(expr, &f); //parse expression string. returns valid or not
	if(ret){
		printf("parsing %s failed\n", expr);
		osc_expr_free(f);
		return 0;
	}	
	//text representation of the function tree
	char *functiongraph = NULL;
	long len = 0;
	osc_expr_formatFunctionGraph(f, &len, &functiongraph); //from osc_expr.c
	
	t_osc_bndl_u *bndl = NULL;
	t_osc_parser_subst *subs = NULL;
	long nsubs = 0;
	//printf("bundle: %s\n", bundle_string);
	osc_parser_parseString(strlen(bundle_string)+2, bundle_string, &bndl, &nsubs, &subs); //unserialized oscizer. throw valid bundles at this and see if it parses it.
	//^multiple bundles need to be /n delimited. 
	while(subs){ //subs is linked list of $n substitutions that need to take place
		t_osc_parser_subst *next = subs->next;
		osc_mem_free(subs);
		subs = next;
	}
	char *ser_bundle = NULL;
	long sbndl_len = 0;
	osc_bundle_u_serialize(bndl, &sbndl_len, &ser_bundle); //serialize the bundle
	
	//char * ser_bundle = bundalize_osc_string(bundle_string);
	
	t_osc_atom_ar_u *out = NULL;
	ret = osc_expr_funcall(f, &sbndl_len, &ser_bundle, &out);//calls the function on the bundle
	osc_atom_array_u_free(out);
	
	char *buf = NULL;
	long buflen = 0;
	osc_bundle_s_format(sbndl_len, ser_bundle, &buflen, &buf);
	char bufcopy[strlen(buf)];
	strcpy(bufcopy, buf);
	char * formated_answer = validate_osc_string(answer);
	char answer_copy[strlen(formated_answer)];
	strcpy(answer_copy, formated_answer);
	//make sure that the answer provided is the same as the answer computed
	ret = compare_answer(buf, formated_answer);
	if (ret==0){
		printf("expecting: '%s', but instead got: '%s'\n", answer_copy, bufcopy);
	}
	//free all the memory
	osc_bundle_u_free(bndl);
	if(ser_bundle){
		osc_mem_free(ser_bundle);
	}
	if(buf){
		osc_mem_free(buf);
	}
	osc_expr_free(f);
	if(functiongraph){
		osc_mem_free(functiongraph);
	}
	return ret;
}