#include "../Header/myTarget.h"

MyTarget::MyTarget() {
	std::cout << "Target obj created" << std::endl;
}

MyTarget::~MyTarget() {
	std::cout << "Target obj detroyed" << std::endl;
}

void MyTarget::initTarget8Dots(float half_l) {
	/*keyPnts.clear();
	keyPnts_img.clear();*/

	// Target info
	pnt_num = 8;
	keyPnts.reserve(pnt_num);
	keyPnts_img.reserve(pnt_num);
	myKeyPnt dummy_keypnt;
	cv::Point2f dummy_pnt2f;
	for (int i = 0; i < pnt_num; i++) {
		keyPnts.push_back(dummy_keypnt);
		keyPnts_img.push_back(dummy_pnt2f);
	}
	// prior knowledge of features
	target_obj.reserve(pnt_num);
	target_obj.push_back(cv::Point3f(-half_l, half_l, 0.));
	target_obj.push_back(cv::Point3f(0., half_l, 0.));
	target_obj.push_back(cv::Point3f(half_l, half_l, 0.));
	target_obj.push_back(cv::Point3f(half_l, 0., 0.));
	target_obj.push_back(cv::Point3f(half_l, -half_l, 0.));
	target_obj.push_back(cv::Point3f(0., -half_l, 0.));
	target_obj.push_back(cv::Point3f(-half_l, -half_l, 0.));
	target_obj.push_back(cv::Point3f(-half_l, 0., 0.));
	num_active_kpt = pnt_num;
}

void MyTarget::initTarget_readfile(std::string file_name) {
	int target_pnt_counter = 0;
	float x, y, z;
	std::ifstream infile(file_name);
	while (infile >> x >> y >> z) {
		target_pnt_counter++;
		target_obj.push_back(cv::Point3f(x, y, z));
	}
	infile.close();
	pnt_num = target_pnt_counter;
	num_active_kpt = pnt_num;

	// Target info
	keyPnts.reserve(pnt_num);
	keyPnts_img.reserve(pnt_num);
	myKeyPnt dummy_keypnt;
	cv::Point2f dummy_pnt2f;
	for (int i = 0; i < pnt_num; i++) {
		keyPnts.push_back(dummy_keypnt);
		keyPnts_img.push_back(dummy_pnt2f);
	}
}
