#pragma once

#include "cardDef.h"

#define OF_ADDON_USING_OFXVECTORMATH
#define OF_ADDON_USING_OFXOPENCV
#define OF_ADDON_USING_OFXXMLSETTINGS

#include "ofMain.h"
#include "ofAddons.h"

// TODO remove HU completely, since HU seems to SUCk bigtime. 
// TODO opencv image to fuck with stuff. 

class cardManager {
	
	public:
	cardManager(){}
	
	//---------------------------
	void setup(string xmlFile);
	
	
	void saveCardAs(card &theCard, int whichCard);
	bool loadFromXML();
	void loadCardImages();
	bool saveToXML(card &theCard);
	//	void resetCards();
	
	//only pixels really works
	
	int		identifyCardSimple(card &theCard, float matchThresh = 10);
	int		identifyCardViaHu(card &theCard, float matchThresh = 10);
	int		identifyCardViaPixels(card &theCard, cardImageSet &theCardImageSet);
	

	float	differenceBetweenImages(ofxCvGrayscaleImage &mom, ofxCvGrayscaleImage &dad, int method); // 0 = sq diff, 1 = pixel diff, etc
	
	
	
	void draw(vector <card> &cards, float x, float y);
	void drawCardMatching(vector <card> &cards, float x, float y);

	ofxXmlSettings xml;
	string xmlCardBank;
	
	// TODO get rid of this: 
	card cardBank[52];
	
	// for "jiggling" pixel comparison to get good results
	
	ofxCvGrayscaleImage		inputToCheck;			// grayscale image that we will modify quite a bit for testing comparison against different pixel sets. 
	ofxCvGrayscaleImage		cardImage;				// TODO: I think it's better if this set before  (ie card bank has ofImages, not ofxCvGrayscale...)
	ofxCvGrayscaleImage		cardImageFlipped;
	ofxCvGrayscaleImage		resultImage;
	
	
	ofImage				cardImages[52];				// get em in
	card				newCardBank[52];			// cards
	cardImageSet		newCardBankImages[52];		// images...

	cardImageSet		currentlyTrackedImages[MAX_TRACKED_CARDS];	
};
