#include "SimpleFramePipeline.h"

#include <glut.h>

 SimpleFramePipeline::SimpleFramePipeline( void )
 {
	 
 }

 SimpleFramePipeline::~SimpleFramePipeline( void )
 {
 
 }

 void SimpleFramePipeline::execute(shared_ptr<Capture> capture)
 {
	 if(timer.Time() > 1000 && elapsedFrames > 0) {
		frameProcessingTimeAvg = timer.Time()/elapsedFrames;
		fps = elapsedFrames;
		elapsedFrames = 0;
		timer.Start();
	 } else  {
		elapsedFrames++;
		timer.Resume();
	 }

	 model.onUpdate(updateTimer.Time());
	 updateTimer.Start();

 	shared_ptr<IplImage> preProcessedImagePtr = preProcessingPhase(capture);

 	vector<CvPoint2D32f> patternPoints(POINTS);
 	int numPointsFound;
 	int allFound = findPatternPhase(capture, preProcessedImagePtr.get(), patternPoints, numPointsFound);
 
 	drawBackgroundPhase(capture, preProcessedImagePtr.get());

 	cameraCalibrationPhase(capture, patternPoints, numPointsFound, allFound);

 	glClear(GL_DEPTH_BUFFER_BIT);
 
 	occlusionPhase();
 
 	drawScenePhase();

	timer.Pause();
 }

 void SimpleFramePipeline::init()
 {
	 mustDrawPreProcessedImage = false;
	 mustDrawPatternPoints = true;
	 mustDrawOcclusionWireframe = false;
	 mustDrawAxis = false;

	 timer.Start();
	 timer.Pause();

	 fps =0;
	 elapsedFrames = 0;
	 frameProcessingTimeAvg = 0;

	 initial = true;

	 float motionBlend[3] = {1.0f, 0.0f, 0.0f};
	 model.onInit("./data/skeleton.cfg");
	 //model.setState(model.STATE_MOTION,0.3f);
	 //model.setMotionBlend(motionBlend,0.1f);
	 model.setState(model.STATE_IDLE,0.3f);
 }

