/*void Graffiti::thicken() {
	ofFill();
	for (int i = 0; i < strokes.size(); i++) {
		Stroke* currentStroke = strokes.at(i);
		printf("new stroke:\n");
		for (int j = 0; j < currentStroke->gmlPoints.size() - 2; j++) {
			GMLPoint* pt1 = currentStroke->gmlPoints.at(j);//first point
			GMLPoint* pt2 = currentStroke->gmlPoints.at(j+1);//second point
			GMLPoint* pt3 = currentStroke->gmlPoints.at(j+2);//third point
			//printf("	new points:(%f,%f) and (%f,%f).\n",pt1->x * scaleFactor,pt1->y * scaleFactor,pt2->x * scaleFactor,pt2->y * scaleFactor);

			float threshold = 15.0;
			float dist12 = ofDist(pt1->x,pt1->y,pt2->x,pt2->y);//the distance between pt1 && pt2
			float dist23 = ofDist(pt2->x,pt2->y,pt3->x,pt3->y);//the distance between pt2 && pt3
			float time12 = pt2->time - pt1->time;//the time from pt1 to pt2
			float time23 = pt3->time - pt2->time;//the time from pt 2 to pt3
			float radius1 = 1 - pow((dist12/time12/threshold),5);//the radius of pt1
			float radius2 = 1 - pow((dist23/time23/threshold),5);;//the radius of pt2
			
			float increment = 20.0;//20 is an arbitrary number.
			float xDist12 = (pt2->x - pt1->x) * scaleFactor / increment;//xDist b/t pt1 and pt2
			float yDist12 = (pt2->y - pt1->y) * scaleFactor / increment;//yDist b/t pt1 and pt2
			float radDist12 = (radius2 - radius1) / increment;//the difference in radii size.
			printf("radii = %f,%f, dif = %f\n",radius1,radius2,radDist12);

			drawCircle(pt1,radius1);
			for(float k = 0; k < increment;k++) {
				drawCircle(pt1->x * scaleFactor + xDist12*k,pt1->y * scaleFactor + yDist12*k,radius1 + radDist12 * k);
			}
			//printf("	The end point was: (%f,%f)\n",pt1->x * scaleFactor + xDist12, pt1->y * scaleFactor + yDist12);
		}
	}
}

//Method for thickening with ofCircles, but with relative radii.
/*void Graffiti::thicken() {
	for (int i = 0; i < strokes.size(); i++) {
		Stroke* currentStroke = strokes.at(i);
		for (int j = 0; j < currentStroke->gmlPoints.size() - 2; j++) {
			printf("new point set:\n");
			GMLPoint* pt1 = currentStroke->gmlPoints.at(j);//first point
			GMLPoint* pt2 = currentStroke->gmlPoints.at(j+1);//second point
			GMLPoint* pt3 = currentStroke->gmlPoints.at(j+2);//third point
			float dist12 = sqrt((pt2->x - pt1->x) * (pt2->x - pt1->x) + (pt2->y - pt1->y) * (pt2->y - pt1->y));//the distance between pt1 && pt2
			float dist23 = sqrt((pt3->x - pt2->x) * (pt3->x - pt2->x) + (pt3->y - pt2->y) * (pt3->y - pt2->y));//the distance between pt2 && pt3
			float time12 = pt2->time - pt1->time;//the time from pt1 to pt2
			float time23 = pt3->time - pt2->time;//the time from pt 2 to pt3
			float radius1 = dist12/time12;//the radius of pt1
			float radius2 = dist23/time23;//the radius of pt2
			//draw intermediary circles
			drawCircle(currentStroke->gmlPoints.at(j),radius1);
			float radiusIncrement = radius2 - radius1;//amount the radius must increase or decrease
			float xIncrement = pt2->x * scaleFactor - pt1->x * scaleFactor;//amount x must increase or decrease
			float yIncrement = pt2->y * scaleFactor - pt1->y * scaleFactor;//amount y must increase or decrease
			printf("%f,%f,%f\n",pt1->x * scaleFactor,pt1->y * scaleFactor,radius1);
			for (float i = dist12 * scaleFactor; i > 0; i--) {
				drawCircle(pt1->x * scaleFactor + xIncrement/i,pt1->y * scaleFactor + yIncrement/i,radius1 + radiusIncrement/i);
				printf("%f,%f,%f\n",pt1->x * scaleFactor + xIncrement/i,pt1->y * scaleFactor + yIncrement/i,radius1 + radiusIncrement/i);
			}
		}
	}
}*/

//---------------------------------------------------
//The old hunk of code for determining if one blob is in another
/*thicken();//in case it hasn't been thickened- only finding contours on a thickened image
	
	//need to load into an ofImage, then ofxCvGrayscaleImage, so as to solve problems w/ openCv images.
	ofImage graffitiRegular;
	int w = myFBO.getWidth();
	int h = myFBO.getHeight();
	graffitiRegular.setFromPixels((unsigned char*) myFBO.getPixels(),w,h,OF_IMAGE_COLOR_ALPHA);
	graffitiRegular.update();
	graffitiRegular.setImageType(OF_IMAGE_GRAYSCALE);
	//graffitiRegular.draw(0,0,w,h);

	ofxCvGrayscaleImage graffitiGrayscale;
	graffitiGrayscale.allocate(w,h);
	graffitiGrayscale.setFromPixels(graffitiRegular.getPixels(),w,h);
	
	//get the number of points for use in nConsidered
	int numPoints = 0;
	for(int i = 0; i < strokes.size(); i++) {
		numPoints += strokes.at(i)->gmlPoints.size();		
	}
	
	graffitiGrayscale.draw(0,0);
	int contours = contourFinder.findContours(graffitiGrayscale,minHoleSize,ofGetWidth() * ofGetHeight(),numPoints,true);

	//print out the blobs
	for (int i = 0; i < contourFinder.blobs.size(); i++) {
		ofNoFill();
		if (contourFinder.blobs.at(i).hole) { ofSetColor(0x000FFF); 
		} else { ofSetColor(0xFF0099); }
		ofBeginShape();
		for (int j = 0; j < contourFinder.blobs.at(i).pts.size(); j++) {
			ofVertex(contourFinder.blobs.at(i).pts.at(j).x,contourFinder.blobs.at(i).pts.at(j).y);
		}
		ofEndShape(false);
		
		ofRect(contourFinder.blobs.at(i).boundingRect.x, contourFinder.blobs.at(i).boundingRect.y, contourFinder.blobs.at(i).boundingRect.width,contourFinder.blobs.at(i).boundingRect.height);

		char numStr[1024];
		sprintf(numStr,"contour #%d",i + 1);
		ofDrawBitmapString(numStr, contourFinder.blobs.at(i).boundingRect.x, contourFinder.blobs.at(i).boundingRect.y);
	}
	
	ofSetColor(0xFFFFFF);
	ofFill();
	myFBO.clear();
	myFBO.begin();
	graffitiGrayscale.draw(0,0);
	
	for (int i = 0; i < contourFinder.blobs.size(); i++) {//for each blob in the contourFinder's model
		ofxCvBlob blob = contourFinder.blobs.at(i);
		if (!blob.hole) {//apparently, hole means it's not a hole?
			ofxCvBlob surroundingBlob;
			
			//Now we determine the blob that surrounds 
			for (int j = 0; j < contourFinder.blobs.size(); j++) {
				if (j != i && contourFinder.blobs.at(j).hole) {
					ofxCvBlob nextBlob = contourFinder.blobs.at(j);
					float lowestX = INT_MAX;
					float lowestY = INT_MAX;
					float highestX = INT_MIN;
					float highestY = INT_MIN;
					//is nextBlob blob's surrounding blob?
					//test to see if centroid is within four outermost points
					for (int k = 0; k < nextBlob.pts.size(); k++) {
						ofPoint nextPoint = nextBlob.pts.at(k);
						if (nextPoint.x < lowestX) lowestX = nextPoint.x;
						if (nextPoint.y < lowestY) lowestY = nextPoint.y;
						if (nextPoint.x > highestX) highestX = nextPoint.x;
						if (nextPoint.y > highestY) highestY = nextPoint.y;
					}
					if (blob.centroid.x > lowestX && blob.centroid.x < highestX &&
						blob.centroid.y > lowestY && blob.centroid.y < highestY) {
							surroundingBlob = contourFinder.blobs.at(j);
					}
				}
			}
			
			//now we know surroundingBlob surrounds blob.
			//let's find the two closest points in the two.
			float lowestDifference =  INT_MAX;
			ofPoint blobsClosestPoint;
			ofPoint SurroundingBlobsClosestPoint;

			for (int j = 0; j < blob.pts.size(); j++) {
				ofPoint pt1 = blob.pts.at(j);
				for (int k = 0; k < surroundingBlob.pts.size(); k++) {
					ofPoint pt2 = surroundingBlob.pts.at(k);
					if (ofDist(pt1.x,pt1.y,pt2.x,pt2.y) < lowestDifference) {
						lowestDifference = ofDist(pt1.x,pt1.y,pt2.x,pt2.y);
						blobsClosestPoint = pt1;
						SurroundingBlobsClosestPoint = pt2;
					}
				}
			}

			//draw a line between the two points in black
			ofSetColor(0x000000);
 			drawLine(blobsClosestPoint,SurroundingBlobsClosestPoint);
		}
	}
	ofSetColor(0xFFFFFF);
	myFBO.end();
	myFBO.draw(0,0,ofGetWidth(),ofGetHeight());
}*/

//---------------------------------------------------------------

/*	//thicken();//in case it hasn't been thickened- only finding contours on a thickened image
	ofFill();
	ofSetColor(0xFFFFFF);

	//need to load into an ofImage, then ofxCvGrayscaleImage, so as to solve problems w/ openCv images.
	ofImage graffitiRegular;
	graffitiRegular.loadImage("contour_test.jpg");//.setFromPixels((unsigned char*) myFBO.getPixels(),w,h,OF_IMAGE_COLOR_ALPHA);
	int w = graffitiRegular.getWidth();
	int h = graffitiRegular.getHeight();
	graffitiRegular.update();
	graffitiRegular.setImageType(OF_IMAGE_GRAYSCALE);

	ofxCvGrayscaleImage graffitiGrayscale;
	graffitiGrayscale.allocate(w,h);
	graffitiGrayscale.setFromPixels(graffitiRegular.getPixels(),w,h);
	graffitiGrayscale.draw(0,0);*/

//----------------------------------------------------------------------------------------------
	//print out the blobs
	/*for (int i = 0; i < contourFinder.blobs.size(); i++) {
		ofNoFill();
		if (contourFinder.blobs.at(i).hole) { ofSetColor(0x000FFF); 
		} else { ofSetColor(0xFF0099); }
		ofBeginShape();
		for (int j = 0; j < contourFinder.blobs.at(i).pts.size(); j++) {
			ofVertex(contourFinder.blobs.at(i).pts.at(j).x,contourFinder.blobs.at(i).pts.at(j).y);
		}
		ofEndShape(false);
		
		ofRect(contourFinder.blobs.at(i).boundingRect.x, contourFinder.blobs.at(i).boundingRect.y, contourFinder.blobs.at(i).boundingRect.width,contourFinder.blobs.at(i).boundingRect.height);

		char numStr[1024];
		sprintf(numStr,"contour #%d",i + 1);
		ofDrawBitmapString(numStr, contourFinder.blobs.at(i).boundingRect.x, contourFinder.blobs.at(i).boundingRect.y);
	}*/

/*
//smoothStroke code courtesy of dustTag 2.0
void Graffiti::smoothStroke(int resolution, Stroke* src) {
	if( src->gmlPoints.size() < 8 ) {
		return;
	}
	for( int j = 4;j < src->gmlPoints.size(); j++) {
        int startPos = j - 3;
		
		float x0 = src->gmlPoints[startPos + 0]->x;
		float y0 = src->gmlPoints[startPos + 0]->y;
		float z0 = src->gmlPoints[startPos + 0]->time;
		float a0 = src->gmlPoints[startPos + 0]->dist;
		
		float x1 = src->gmlPoints[startPos + 1]->x;
		float y1 = src->gmlPoints[startPos + 1]->y;
		float z1 = src->gmlPoints[startPos + 1]->time;
		float a1 = src->gmlPoints[startPos + 1]->dist;
		
		float x2 = src->gmlPoints[startPos + 2]->x;
		float y2 = src->gmlPoints[startPos + 2]->y;
		float z2 = src->gmlPoints[startPos + 2]->time;
		float a2 = src->gmlPoints[startPos + 2]->dist;
		
		float x3 = src->gmlPoints[startPos + 3]->x;
		float y3 = src->gmlPoints[startPos + 3]->y;
		float z3 = src->gmlPoints[startPos + 3]->time;
		float a3 = src->gmlPoints[startPos + 3]->dist;
		
		float t,t2,t3;
		float x,y,z,a;
		
		for (int i = 1; i < resolution; i++) {
			t = (float) i / (float) (resolution-1);// i / resolution - 1
			t2 = t * t; // t^2
			t3 = t2 * t; // t^3
			
			x = 0.5f * ( ( 2.0f * x1 ) + 
						( -x0 + x2 ) * t +
						( 2.0f * x0 - 5.0f * x1 + 4 * x2 - x3 ) * t2 +
						( -x0 + 3.0f * x1 - 3.0f * x2 + x3 ) * t3 );
			
			y = 0.5f * ( ( 2.0f * y1 ) +
						( -y0 + y2 ) * t +
						( 2.0f * y0 - 5.0f * y1 + 4 * y2 - y3 ) * t2 +
						( -y0 + 3.0f * y1 - 3.0f * y2 + y3 ) * t3 );
			
			z = 0.5f * ( ( 2.0f * z1 ) +
						( -z0 + z2 ) * t +
						( 2.0f * z0 - 5.0f * z1 + 4 * z2 - z3 ) * t2 +
						( -z0 + 3.0f * z1 - 3.0f * z2 + z3 ) * t3 );
			
			a = 0.5f * ( ( 2.0f * a1 ) +
						( -a0 + a2 ) * t +
						( 2.0f * a0 - 5.0f * a1 + 4 * a2 - a3 ) * t2 +
						( -a0 + 3.0f * a1 - 3.0f * a2 + a3 ) * t3 );
		
			src->gmlPoints.at(j) = new GMLPoint(x,y,z,a,src->gmlPoints.at(j)->dist);
		}
    }
}*/