Esempio n. 1
0
int main() {
	fout = fopen("fixedpoint_out.txt", "w");

	fprintf(fout,"Kevin Boisseau\nCOT4500\nHomework 2\n\n");
	fprintf(fout,"Section 2.2, problem #4\n\n");

	fprintf(fout,"root of a) is: %lf\n", getFixedPoint(1,10000,1));
	fprintf(fout,"root of b) is: %lf\n", getFixedPoint(1,10000,2));
	fprintf(fout,"root of c) is: %lf\n", getFixedPoint(1,10000,3));
	fprintf(fout,"root of d) is: %lf\n", getFixedPoint(1,10000,4));
	
    fclose(fout);
    return 0;
}
int main(int argc, char** argv)
{
	char configFilename[256];
	
	if (argc > 1)
		strncpy(configFilename, argv[1], 255);
	else
		strcpy(configFilename, "conf.txt");

	SimulatorArgument simArgs;
	simArgs.load(configFilename);

	// real plane should be saved as plane.auto.conf, but for convenice, save plane.detected.conf
	// this will be rewrite after detecting plane process
	simArgs.planes.save("plane.detected.conf");
	simArgs.beacons.save("beacon.auto.conf");

	estArgs.load(configFilename);
	estArgs.estimatorMode = EST::TRADITIONAL;
	estArgs.optimization = 0;
	estimator.setEstimator(&estArgs);

	

	PlaneList realPlanes;

	PlaneList detectedPlanes;

	realPlanes.makeCube(simArgs.width, simArgs.length, simArgs.height);
	// there is 6 planes in realPlanes.
	// index 0~3 are side wall, 4 and 5 are ceiling and floor
	

	printf("Generating direct signal events...");
	fflush(stdout);
	// events for directly receiving signals
	EventGenerator directEventGenerator;
	directEventGenerator.generateEventForPlaneDetection(
			&simArgs, listenerInterval, minMargin, listenerZ, Vector(0, 0, 1));
	printf("done\n");

	Vector bestLocation[4];
	Vector bestLocationSimulated[4];
	double error[4];

	
	for (int i = 0; i < 4; i++)
	{
		EventGenerator reflectedEventGenerator;
		// normal vector of each plane faces outside of cube
		Vector vFacing = realPlanes.at(i)->vNormal;

		printf("\nGenerating events for Plane %d...", i);
		fflush(stdout);
		reflectedEventGenerator.generateEventForPlaneDetection(
				&simArgs, listenerInterval, minMargin, listenerZ, vFacing);
		printf("done\n");

		double gap = 100;

		Vector fixedPoint;
		int fixedPointIdx;
		EventLog *eventD;
		EventLog *eventR;
		
		for (gap = 100; gap > 0; gap -= 5)
		{

			fixedPoint = getFixedPoint(realPlanes.at(i), gap);
			fixedPointIdx = getFixedPointIndex(fixedPoint, &directEventGenerator.events);
			eventD = &directEventGenerator.events.events[fixedPointIdx];
			eventR = &reflectedEventGenerator.events.events[fixedPointIdx];

			if (!checkReflection(eventD)) continue;
			if (eventR->measurements.size() >= 5) break;
		};
		if (gap <= 0)
		{
			fprintf(stderr, "can not find valid point for plane %d\n", i);
			exit(1);
		}

		printf("fixed point for plane %d  (gap : %d) = ", i, (int)gap);
		fixedPoint.println();

		Plane detectedPlane = detectPlane(
				&simArgs, 
				realPlanes.at(i), 
				i/*pid*/, 				
				eventD,
				eventR,
				&bestLocation[i],
				&bestLocationSimulated[i],
				&error[i]);
		detectedPlane.setBoundary(true);
		detectedPlanes.addPlane(detectedPlane);
		printf("min error : %f\n", error[i]);
	}

	for (int i = 0; i < 5; i++)
	{
		// make test plane list. this list has mixed set of real plane and detected plane
		PlaneList testPlanes;
		for (int j = 0; j < 4; j++)
		{
			if (i > j)			
				testPlanes.addPlane(*detectedPlanes.at(j));
			else
				testPlanes.addPlane(*realPlanes.at(j));
		}

		testPlanes.addPlane(*realPlanes.at(4));
		testPlanes.addPlane(*realPlanes.at(5));

		char filename[255];
		sprintf(filename, "plane.detected.%d.conf", i);
		
		testPlanes.save(filename);	
	}

		

	printf("\nResults");

	for (int i = 0; i < 4; i++)
	{
		printf("\n");
		printf("detected plane            : ");
		detectedPlanes.at(i)->println();

		
		printf("best location             : ");
		bestLocation[i].println();

		printf("best location (simulated) : ");
		bestLocationSimulated[i].println();

		printf("error                     : %f\n", error[i]);
		
	}

	// add ceiling and floor
	detectedPlanes.addPlane(*realPlanes.at(4));
	detectedPlanes.addPlane(*realPlanes.at(5));

	// save detected planes
	detectedPlanes.save("plane.detected.conf");
}