コード例 #1
0
ファイル: glview.cpp プロジェクト: stenniswood/bk_code
void depth_cb( freenect_device *dev, void *v_depth, uint32_t timestamp )
{
	int line;
	int i=0;
	uint16_t *depth = (uint16_t*)v_depth;

	if (pause) {
		pthread_cond_signal(&gl_frame_cond);
		pthread_mutex_unlock(&gl_backbuf_mutex);
		return;
	}
		
/*	for (int column=0; column<640-1; column++)
	{
		calc_h_deltas( &(depth[(column*640)]), h_delta, false );
		find_peaks( h_delta );
	}*/
	
	// Find Wall edge:
	// histogram type anaylsis on the peaks.
	// When they're obviously underneath each other.  (ie. distance between < threshold)
	//		there could be a jump ie same peaks have different indexes on different lines. but don't handle this yet. simplicity.
	//average_peaks();
	
	pthread_mutex_lock(&gl_backbuf_mutex);
	for (i=0; i<640*480; i++) {
		int pval = t_gamma[depth[i]];
		int lb = pval & 0xff;
		lb = depth[i];
		depth_mid[3*i+0] = 255-lb;
		depth_mid[3*i+1] = 255-lb;
		depth_mid[3*i+2] = 255-lb;
	}
	colorize_seg_ends2( depth_mid, true );  
	// Now analyze corner ( )
	line = 150;
	calc_deltas( &(depth[(line*640)]), v_delta, false );	
	
	//plot_array( &(depth[line*640]), 255, depth_mid );
	//plot_array( (uint16_t *)v_delta, 100, depth_mid );	
	int index;
	for (i=0; i<640; i++) 
	{
		index = line*640*3 + 3*i;
		depth_mid[index+0] = 0;
		depth_mid[index+1] = 255;
		depth_mid[index+2] = 0;	
	}
	got_depth++;
	pthread_cond_signal(&gl_frame_cond);
	pthread_mutex_unlock(&gl_backbuf_mutex);
}
コード例 #2
0
ファイル: sampling_thread.c プロジェクト: acooks/jittertrap
static void
update_stats(struct sample *sample_c, char *iface, struct timespec deadline)
{
	struct sample sample_o;
	struct timespec whoosh_err; /* the sound of a missed deadline. */
	pthread_mutex_lock(&g_stats_mutex);
	/* FIXME: this smells funny */
	memcpy(&sample_o, &g_stats_o, sizeof(struct sample));

	if (0 == read_counters(iface, sample_c)) {
		clock_gettime(CLOCK_MONOTONIC, &(sample_c->timestamp));
		whoosh_err = ts_absdiff(sample_c->timestamp, deadline);
		sample_c->whoosh_error_ns = whoosh_err.tv_nsec;
		calc_deltas(&sample_o, sample_c);
	}
	memcpy(&g_stats_o, sample_c, sizeof(struct sample));
	pthread_mutex_unlock(&g_stats_mutex);
}
コード例 #3
0
static void correctivesmooth_modifier_do(
        ModifierData *md, Object *ob, DerivedMesh *dm,
        float (*vertexCos)[3], unsigned int numVerts,
        struct BMEditMesh *em)
{
	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;

	const bool force_delta_cache_update =
	        /* XXX, take care! if mesh data its self changes we need to forcefully recalculate deltas */
	        ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_ORCO) &&
	         (((ID *)ob->data)->tag & LIB_TAG_ID_RECALC));

	bool use_only_smooth = (csmd->flag & MOD_CORRECTIVESMOOTH_ONLY_SMOOTH) != 0;
	MDeformVert *dvert = NULL;
	int defgrp_index;

	modifier_get_vgroup(ob, dm, csmd->defgrp_name, &dvert, &defgrp_index);

	/* if rest bind_coords not are defined, set them (only run during bind) */
	if ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) &&
	    /* signal to recalculate, whoever sets MUST also free bind coords */
	    (csmd->bind_coords_num == (unsigned int)-1))
	{
		BLI_assert(csmd->bind_coords == NULL);
		csmd->bind_coords = MEM_dupallocN(vertexCos);
		csmd->bind_coords_num = numVerts;
		BLI_assert(csmd->bind_coords != NULL);
	}

	if (UNLIKELY(use_only_smooth)) {
		smooth_verts(csmd, dm, dvert, defgrp_index, vertexCos, numVerts);
		return;
	}

	if ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) && (csmd->bind_coords == NULL)) {
		modifier_setError(md, "Bind data required");
		goto error;
	}

	/* If the number of verts has changed, the bind is invalid, so we do nothing */
	if (csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) {
		if (csmd->bind_coords_num != numVerts) {
			modifier_setError(md, "Bind vertex count mismatch: %u to %u", csmd->bind_coords_num, numVerts);
			goto error;
		}
	}
	else {
		/* MOD_CORRECTIVESMOOTH_RESTSOURCE_ORCO */
		if (ob->type != OB_MESH) {
			modifier_setError(md, "Object is not a mesh");
			goto error;
		}
		else {
			unsigned int me_numVerts = (unsigned int)((em) ? em->bm->totvert : ((Mesh *)ob->data)->totvert);

			if (me_numVerts != numVerts) {
				modifier_setError(md, "Original vertex count mismatch: %u to %u", me_numVerts, numVerts);
				goto error;
			}
		}
	}

	/* check to see if our deltas are still valid */
	if (!csmd->delta_cache || (csmd->delta_cache_num != numVerts) || force_delta_cache_update) {
		const float (*rest_coords)[3];
		bool is_rest_coords_alloc = false;

		if (csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) {
			/* caller needs to do sanity check here */
			csmd->bind_coords_num = numVerts;
			rest_coords = (const float (*)[3])csmd->bind_coords;
		}
		else {
			int me_numVerts;
			rest_coords = (const float (*)[3]) ((em) ?
			        BKE_editmesh_vertexCos_get_orco(em, &me_numVerts) :
			        BKE_mesh_vertexCos_get(ob->data, &me_numVerts));

			BLI_assert((unsigned int)me_numVerts == numVerts);
			is_rest_coords_alloc = true;
		}

#ifdef DEBUG_TIME
	TIMEIT_START(corrective_smooth_deltas);
#endif

		calc_deltas(csmd, dm, dvert, defgrp_index, rest_coords, numVerts);

#ifdef DEBUG_TIME
	TIMEIT_END(corrective_smooth_deltas);
#endif
		if (is_rest_coords_alloc) {
			MEM_freeN((void *)rest_coords);
		}
	}

	if (csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) {
		/* this could be a check, but at this point it _must_ be valid */
		BLI_assert(csmd->bind_coords_num == numVerts && csmd->delta_cache);
	}


#ifdef DEBUG_TIME
	TIMEIT_START(corrective_smooth);
#endif

	/* do the actual delta mush */
	smooth_verts(csmd, dm, dvert, defgrp_index, vertexCos, numVerts);

	{
		unsigned int i;

		float (*tangent_spaces)[3][3];

		/* calloc, since values are accumulated */
		tangent_spaces = MEM_callocN((size_t)numVerts * sizeof(float[3][3]), __func__);

		calc_tangent_spaces(dm, vertexCos, tangent_spaces);

		for (i = 0; i < numVerts; i++) {
			float delta[3];

#ifdef USE_TANGENT_CALC_INLINE
			calc_tangent_ortho(tangent_spaces[i]);
#endif

			mul_v3_m3v3(delta, tangent_spaces[i], csmd->delta_cache[i]);
			add_v3_v3(vertexCos[i], delta);
		}

		MEM_freeN(tangent_spaces);
	}

#ifdef DEBUG_TIME
	TIMEIT_END(corrective_smooth);
#endif

	return;

	/* when the modifier fails to execute */
error:
	MEM_SAFE_FREE(csmd->delta_cache);
	csmd->delta_cache_num = 0;

}