#include "Picture.h"


void Picture::setCameraParameters(Points* cp,double r, double t_X, double t_Z)
{
	cameraPoint = cp;
	rotation = r;
	translation_X = t_X;
	translation_Z = t_Z;

}

void Picture::transform()
{
        cameraPoint->transform(rotation,translation_X,translation_Z);
		int size = lines.size();
		for(int i = 0; i < size; i++)
			lines[i]->transform(rotation,translation_X,translation_Z);

}

void Picture::getPlaneCord()
{
		// following code finds the plans associated with a line
		double one = 0.0,two = 0.0,three = 0.0,four = 0.0, five = 0.0, six = 0.0;
		int size = lines.size();
		for(int i = 0; i < size; i++)
		{
			one = ( (lines[i]->pluckerCord[1]*cameraPoint->getZ()) - (lines[i]->pluckerCord[2]*cameraPoint->getY()) ) - lines[i]->pluckerCord[3];
			two = ( (lines[i]->pluckerCord[2]*cameraPoint->getX()) - (lines[i]->pluckerCord[0]*cameraPoint->getZ()) ) - lines[i]->pluckerCord[4];
			three =( (lines[i]->pluckerCord[0]*cameraPoint->getY()) - (lines[i]->pluckerCord[1]*cameraPoint->getX()) )  - lines[i]->pluckerCord[5];
			four = lines[i]->pluckerCord[3]*cameraPoint->getX() +  lines[i]->pluckerCord[4]*cameraPoint->getY() + lines[i]->pluckerCord[5]*cameraPoint->getZ();			
			lines[i]->setPlaneCord(one,two,three,four);
			//cout << "PLANE CORD" << "\n";
			//cout << one << "\n";
			//cout << two << "\n";
			//cout << three << "\n";
			//cout << four << "\n";

		}	
      
        // following code finds the line La and Lb
		for(int i = 0; i < size; i++)
		{
			one = 0.0;two = 0.0;three = 0.0;four = 0.0; five = 0.0; six = 0.0;

			one = (lines[i]->source->getX() - cameraPoint->getX());
			two = (lines[i]->source->getY() - cameraPoint->getY());
			three = (lines[i]->source->getZ() - cameraPoint->getZ());
			four = ( (lines[i]->source->getY() * cameraPoint->getZ() ) - (lines[i]->source->getZ() * cameraPoint->getY()));
			five = ( (lines[i]->source->getZ() * cameraPoint->getX() ) - (lines[i]->source->getX() * cameraPoint->getZ()));
			six = ( (lines[i]->source->getX() * cameraPoint->getY() ) - (lines[i]->source->getY() * cameraPoint->getX()));

			lines[i]->setLA(one, two, three, four, five, six);
			
			one = 0.0;two = 0.0;three = 0.0;four = 0.0; five = 0.0; six = 0.0;

			one = (lines[i]->destination->getX() - cameraPoint->getX());
			two = (lines[i]->destination->getY() - cameraPoint->getY());
			three = (lines[i]->destination->getZ() - cameraPoint->getZ());
			four = ( (lines[i]->destination->getY() * cameraPoint->getZ() ) - (lines[i]->destination->getZ() * cameraPoint->getY()));
			five = ( (lines[i]->destination->getZ() * cameraPoint->getX() ) - (lines[i]->destination->getX() * cameraPoint->getZ()));
			six = ( (lines[i]->destination->getX() * cameraPoint->getY() ) - (lines[i]->destination->getY() * cameraPoint->getX()));

			lines[i]->setLB(one, two, three, four, five, six);
		}
}

void Picture::convertLinesToPlucker()
{
	//cout << "New Picture" << endl;
	int size = lines.size();
		for(int i = 0; i < size; i++)
		{
			lines[i]->convertToPlucker();
		}	
}	