Example #1
0
//unused
int check_hor_line(event_t* evt,short length, unsigned short tolerance) {
	static state_t state = INIT; // initial state; keep state
	printf("state: %d\n", state);
	switch (state) {
	case INIT:
		if( evt->type == LDOWN )
			state = DRAW;
		break;
	case DRAW:
		if( evt->type == MOVE ) {// need to check if HOR_LINE event occurs
			if(abs(evt->delta.y) > tolerance)
				resetCoord(&(evt->delta));
			else if( length > 0)
				{if(evt->delta.x > length)
					return 1;}
			else if(length < 0)
				{if(evt->delta.x < length)
					return 1;}
		} else if( evt->type == LUP )
			state = INIT;
		break;
	default:
		break;
	}
	return 0;
}
Example #2
0
//initialize mouse state
void initMouseState(mouse_state_t* m)
{
	resetCoord(&(m->coords));
	m->lb =0;
	m->mb = 0;
	m->rb = 0;
}
Example #3
0
/* doDot:
 * Assume g has nodes.
 */
static void doDot (Agraph_t* g)
{
    Agraph_t **ccs;
    Agraph_t *sg;
    int ncc;
    int i;
    pack_info pinfo;
    int Pack = getPack(g, -1, CL_OFFSET);
    pack_mode mode = getPackModeInfo (g, l_undef, &pinfo);
    getPackInfo(g, l_node, CL_OFFSET, &pinfo);

    if ((mode == l_undef) && (Pack < 0)) {
	/* No pack information; use old dot with components
         * handled during layout
         */
	dotLayout(g);
    } else {
	/* fill in default values */
	if (mode == l_undef) 
	    pinfo.mode = l_node;
	else if (Pack < 0)
	    Pack = CL_OFFSET;
	pinfo.margin = Pack;
	pinfo.fixed = 0;

          /* components using clusters */
	ccs = cccomps(g, &ncc, 0);
	if (ncc == 1) {
	    dotLayout(g);
	} else if (GD_drawing(g)->ratio_kind == R_NONE) {
	    pinfo.doSplines = 1;

	    for (i = 0; i < ncc; i++) {
		sg = ccs[i];
		initSubg (sg, g);
		dotLayout (sg);
	    }
	    attachPos (g);
	    packSubgraphs(ncc, ccs, g, &pinfo);
	    resetCoord (g);
	} else {
	    /* Not sure what semantics should be for non-trivial ratio
             * attribute with multiple components.
             * One possibility is to layout nodes, pack, then apply the ratio
             * adjustment. We would then have to re-adjust all positions.
             */
	    dotLayout(g);
	}

	for (i = 0; i < ncc; i++) {
	    free (GD_drawing(ccs[i]));
	    agdelete(g, ccs[i]);
	}
	free(ccs);
    }
}
Example #4
0
//if x of coordinate 1 and 2 have different signs return is (0,0)
coord_t addCoordRes(coord_t c1, coord_t c2)
{
	coord_t out;
	if(c1.x * c2.x < 0)
	{
		resetCoord(&out);
		return out;
	}
	out.x = c1.x + c2.x;
	out.y = c1.y + c2.y;
	return out;
}
Example #5
0
//initialize event
void initEvent(event_t* e)
{
	resetCoord(&(e->delta));
	e->type = LUP;
}
Example #6
0
void ShortAxisFitting::optimize(const alglib::real_1d_array& x, double& func, void* ptr) {
	struct ShortAxisOptimizationInput* input = static_cast<struct ShortAxisOptimizationInput*>(ptr);
	Cmiss_field_module_id field_module = (input->field_module);
	std::vector<Cmiss_node_id>& cmiss_nodes(*(input->cmiss_nodes));
	std::vector<double>& targetDeltas(*(input->targetDeltas));
	Cmiss_field_id coordinate = (input->coordinates_rc);
	Cmiss_field_cache_id cache = (input->cache);
	double* initialSegmentLengths = input->initialSegmentLengths;
	int* saxNodes = input->saxNodes;
	int numberOfModelFrames = input->numberOfModelFrames;
	int NUMBER_OF_SEGMENTS = input->NUMBER_OF_SEGMENTS;
	int NUMBER_OF_SAX_NODES = input->NUMBER_OF_SAX_NODES;
	double** result = input->result; //This is expected to be preallocated for heap efficiency
	int* endoNodeIds = input->endoNodesIds;
	const int NUMBER_OF_ENDO_NODES = 48; //Ignore the apex
	int ctr = 0;
	double coord[3];
	int frame = input->frame;
	std::vector<Point3D>& resetCoord(input->initEndoCoordinates->at(frame));
	std::vector<Point3D>& initFrame(*input->initFrame);

	setThetaDelta(input, x);

	//Compute the theta error
	double thetaError = 0.0;
	//for (int frame = 0; frame < numberOfModelFrames; frame++)
	{
		double time = ((double) frame) / ((double) numberOfModelFrames);
		if (frame == (numberOfModelFrames - 1))
		{
			time = 1.0;
		}
		Cmiss_field_cache_set_time(cache, time);
		std::vector<Point3D> sax;
		Point3D sax_centroid(0, 0, 0);
		for (int seg = 0; seg < NUMBER_OF_SAX_NODES; seg++)
		{
			Cmiss_field_cache_set_node(cache, cmiss_nodes[saxNodes[seg]]);
			Cmiss_field_evaluate_real(coordinate, cache, 3, coord);
			Point3D start(coord);
			sax.push_back(start);
			sax_centroid += start;
		}
		sax_centroid = sax_centroid * (1.0 / NUMBER_OF_SAX_NODES);
		double avg = 0.0;
		for (int seg = 0; seg < NUMBER_OF_SAX_NODES; seg++)
		{
			Vector3D trans = sax[seg] - sax_centroid;
			double denom = trans.x- initFrame[seg].x;
			double nuem  = trans.z- initFrame[seg].z;
			double ltheta = atan2(nuem, denom);
			if(fabs(denom)<1.0e-6 && fabs(nuem)<1.0e-6){
					ltheta = 0.0;
			}
			avg += ltheta;
		}
		avg /=NUMBER_OF_SAX_NODES;
		thetaError +=fabs(avg-targetDeltas[frame]);
		input->thetaError = avg;
	}


	//Compute the segment error
	getSegmentLengths(input);
	double segmentMatchError = input->segmentMatchError;
	func = segmentMatchError + thetaError;
	if(segmentMatchError>2.0)
		func = 1.0e+30;
	input->totalError = func;
	//Reset coordinates to original
	{
		Cmiss_field_module_begin_change(field_module);

		{
			double time = ((double) frame) / ((double) numberOfModelFrames);
			if (frame == (numberOfModelFrames - 1))
			{
				time = 1.0;
			}
			Cmiss_field_cache_set_time(cache, time);
			for (int nc = 0; nc < NUMBER_OF_ENDO_NODES; nc++)
			{
				coord[0] = resetCoord[nc].x;
				coord[1] = resetCoord[nc].y;
				coord[2] = resetCoord[nc].z;
				Cmiss_field_cache_set_node(cache, cmiss_nodes[endoNodeIds[nc] - 1]);
				Cmiss_field_assign_real(coordinate, cache, 3, coord);
			}
		}
		Cmiss_field_module_end_change(field_module);
	}
}