Exemple #1
0
double ActivityStats::pearsonCorrelation(ActivityStats *s) {
  u_int8_t x[CONST_MAX_ACTIVITY_DURATION] = { 0 };
  u_int8_t y[CONST_MAX_ACTIVITY_DURATION] = { 0 };

  extractPoints(x);
  s->extractPoints(y);

  return(Utils::pearsonValueCorrelation(x, y));
}
Exemple #2
0
void BccLattice::extractTetrahedronMeshData(Vector3F * points, unsigned * indices)
{
    extractPoints(points);
    extractIndices(indices);
}
Exemple #3
0
gMuteChannel::gMuteChannel(int x, int y, gdActionEditor *pParent)
 : gActionWidget(x, y, 200, 80, pParent), draggedPoint(-1), selectedPoint(-1)
{
	size(pParent->totalWidth, h());
	extractPoints();
}
Exemple #4
0
int gMuteChannel::handle(int e) {

	int ret = 0;
	int mouseX = Fl::event_x()-x();

	switch (e) {

		case FL_ENTER: {
			ret = 1;
			break;
		}

		case FL_MOVE: {
			selectedPoint = getSelectedPoint();
			redraw();
			ret = 1;
			break;
		}

		case FL_LEAVE: {
			draggedPoint  = -1;
			selectedPoint = -1;
			redraw();
			ret = 1;
			break;
		}

		case FL_PUSH: {

			/* left click on point: drag
			 * right click on point: delete
			 * left click on void: add */

			if (Fl::event_button1())  {

				if (selectedPoint != -1) {
					draggedPoint   = selectedPoint;
					previousXPoint = points.at(selectedPoint).x;
				}
				else {

					/* click on the grey area leads to nowhere */

					if (mouseX > pParent->coverX) {
						ret = 1;
						break;
					}

					/* click in the middle of a long mute_on (between two points): new actions
					 * must be added in reverse: first mute_off then mute_on. Let's find the
					 * next point from here. */

					unsigned nextPoint = points.size;
					for (unsigned i=0; i<points.size; i++) {
						if (mouseX < points.at(i).x) {
							nextPoint = i;
							break;
						}
					}

					/* next point odd = mute_on [click here] mute_off
					 * next point even = mute_off [click here] mute_on */

					int frame_a = mouseX * pParent->zoom;
					int frame_b = frame_a+2048;

					if (pParent->gridTool->isOn()) {
						frame_a = pParent->gridTool->getSnapFrame(mouseX);
						frame_b = pParent->gridTool->getSnapFrame(mouseX + pParent->gridTool->getCellSize());

						/* with snap=on a point can fall onto another */

						if (pointCollides(frame_a) || pointCollides(frame_b)) {
							ret = 1;
							break;
						}
					}

					/* ensure frame parity */

					if (frame_a % 2 != 0) frame_a++;
					if (frame_b % 2 != 0) frame_b++;

					/* avoid overflow: frame_b must be within the sequencer range. In that
					 * case shift the ON-OFF block */

					if (frame_b >= G_Mixer.totalFrames) {
						frame_b = G_Mixer.totalFrames;
						frame_a = frame_b-2048;
					}

					if (nextPoint % 2 != 0) {
						recorder::rec(pParent->chan->index, ACTION_MUTEOFF, frame_a);
						recorder::rec(pParent->chan->index, ACTION_MUTEON,  frame_b);
					}
					else {
						recorder::rec(pParent->chan->index, ACTION_MUTEON,  frame_a);
						recorder::rec(pParent->chan->index, ACTION_MUTEOFF, frame_b);
					}
					recorder::sortActions();

					mainWin->keyboard->setChannelWithActions((gSampleChannel*)pParent->chan->guiChannel); // update mainWindow
					extractPoints();
					redraw();
				}
			}
			else {

				/* delete points pair */

				if (selectedPoint != -1) {

					unsigned a;
					unsigned b;

					if (points.at(selectedPoint).type == ACTION_MUTEOFF) {
						a = selectedPoint-1;
						b = selectedPoint;
					}
					else {
						a = selectedPoint;
						b = selectedPoint+1;
					}

					//gLog("selected: a=%d, b=%d >>> frame_a=%d, frame_b=%d\n",
					//		a, b, points.at(a).frame, points.at(b).frame);

					recorder::deleteAction(pParent->chan->index, points.at(a).frame,	points.at(a).type, false); // false = don't check vals
					recorder::deleteAction(pParent->chan->index,	points.at(b).frame,	points.at(b).type, false); // false = don't check vals
					recorder::sortActions();

					mainWin->keyboard->setChannelWithActions((gSampleChannel*)pParent->chan->guiChannel); // update mainWindow
					extractPoints();
					redraw();
				}
			}
			ret = 1;
			break;
		}

		case FL_RELEASE: {

			if (draggedPoint != -1) {

				if (points.at(draggedPoint).x == previousXPoint) {
					//gLog("nothing to do\n");
				}
				else {

					int newFrame = points.at(draggedPoint).x * pParent->zoom;

					recorder::deleteAction(
							pParent->chan->index,
							points.at(draggedPoint).frame,
							points.at(draggedPoint).type,
							false);  // don't check values

					recorder::rec(
							pParent->chan->index,
							points.at(draggedPoint).type,
							newFrame);

					recorder::sortActions();

					points.at(draggedPoint).frame = newFrame;
				}
			}
			draggedPoint  = -1;
			selectedPoint = -1;

			ret = 1;
			break;
		}

		case FL_DRAG: {

			if (draggedPoint != -1) {

				/* constrain the point between two ends (leftBorder-point,
				 * point-point, point-rightBorder) */

				int prevPoint;
				int nextPoint;

				if (draggedPoint == 0) {
					prevPoint = 0;
					nextPoint = points.at(draggedPoint+1).x - 1;
					if (pParent->gridTool->isOn())
						nextPoint -= pParent->gridTool->getCellSize();
				}
				else
				if ((unsigned) draggedPoint == points.size-1) {
					prevPoint = points.at(draggedPoint-1).x + 1;
					nextPoint = pParent->coverX-x();
					if (pParent->gridTool->isOn())
						prevPoint += pParent->gridTool->getCellSize();
				}
				else {
					prevPoint = points.at(draggedPoint-1).x + 1;
					nextPoint = points.at(draggedPoint+1).x - 1;
					if (pParent->gridTool->isOn()) {
						prevPoint += pParent->gridTool->getCellSize();
						nextPoint -= pParent->gridTool->getCellSize();
					}
				}

				if (mouseX <= prevPoint)
					points.at(draggedPoint).x = prevPoint;
				else
				if (mouseX >= nextPoint)
					points.at(draggedPoint).x = nextPoint;
				else
				if (pParent->gridTool->isOn())
					points.at(draggedPoint).x = pParent->gridTool->getSnapPoint(mouseX)-1;
				else
					points.at(draggedPoint).x = mouseX;

				redraw();
			}
			ret = 1;
			break;
		}
	}


	return ret;
}
Exemple #5
0
/**
 * Main control logic.
 * - processes a single CHM
 * - sets tciFlag indicating which tree crowns intersect the current CHM
 * - calls extractPoints
 */
static PyObject* Py_execute(PyObject* self, PyObject* args)
{
	int xBlockPos, yBlockPos, bioFlag;
	char *inFile, *outFile, *outTiff;
	
	if(!PyArg_ParseTuple(args, "ssiiis", &inFile, &outFile, &xBlockPos, &yBlockPos, &bioFlag, &outTiff))
	{
		PyErr_SetString(PyExc_IOError, "Py_execute could not parse parameters.");
		return NULL;
	}
	
	FILE * fpIn, * fpOut;
	
	if(!(fpIn = fopen(inFile, "r"))){
		PyErr_SetString(PyExc_IOError, "Could not open input file.");
		return NULL;
	}
	if(!(fpOut = fopen(outFile, "w"))){
		PyErr_SetString(PyExc_IOError, "Could not open output file.");
		return NULL;
	}
	
	int i, process, **numAll;
	double xBlockMin, xBlockMax, yBlockMin, yBlockMax;
	SHPObject * pShpObj;
	
	xBlockMin = MIN_E + (xBlockPos * BLOCK_SIZE);
	xBlockMax = xBlockMin + BLOCK_SIZE;
	yBlockMin = MIN_N + (yBlockPos * BLOCK_SIZE);
	yBlockMax = yBlockMin + BLOCK_SIZE;
	
	process = 0;
	
	//index all tree crowns that intersect the current file
	for(i = 0; i < N_RECORDS; i++)
	{
		if((pShpObj = SHPReadObject(H_SHP, i)) == NULL)
		{
			PyErr_SetString(PyExc_IOError, "Error opening shape file.");
			return NULL;
		}
		
		if(pShpObj->dfXMin >= xBlockMax || pShpObj->dfXMax <= xBlockMin
			|| pShpObj->dfYMin >= yBlockMax || pShpObj->dfYMax <= yBlockMin)
		{
			tciFlag.data[i] = 0;
		}
		else{
			process = 1;
			tciFlag.data[i] = 1;
		}
		
		SHPDestroyObject(pShpObj);
	}
	
	if(!process){
		printf("Nothing to process\n");
		return Py_None;
	}
	
	if(!readChm(fpIn))
		return NULL;
	
	if(bioFlag)
	{
		numAll = countPoints(CHM, N_POINTS, MIN_E, MIN_N, BLOCK_SIZE, OUT_RES, xBlockPos, yBlockPos);
		if(!numAll)
			return NULL;
		int dim = BLOCK_SIZE/OUT_RES;
		int i,j;
		for(i = 0;i<dim;i++)
			for(j=0;j<dim;j++)
				printf("%d\n", numAll[i][j]);
		
	}
	
	//process each file
	for(i = 0; i < tciFlag.size; i++)
	{
		if(tciFlag.data[i] == 0)continue;
		
		printf("Calling:\textractPoints(%d, fpOut)\n", i);
		extractPoints(i, fpOut);
	}
	
	
	if(bioFlag)
	{
		printf("Run ccf calcs\n");
		computeCCF(CHM, N_POINTS, numAll, MIN_E, MIN_N, BLOCK_SIZE, OUT_RES, Z_THRESH, xBlockPos, yBlockPos, outTiff);
	}
	
	printf("Calling:\twriteFile(fpOut, CHM, %d)\n", N_POINTS);
	if(!writeFile(fpOut, CHM, N_POINTS))
	{
		return NULL;
	}
	
	freed2d(CHM, 3);
	free(POINT_CLASSIFICATION);
	fclose(fpIn);
	fclose(fpOut);
	
	return Py_None;
}