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); }
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; } }
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; }
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); }
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; }
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); } }