void Optimizer::GenerateRandomPoints(ModelPtr model, int num)
{

	model->GenerateRandomNumbers(num,random_points_);

	//ofstream random;
 //   random.open("random_points", ios::app);
	//for (auto e:random_points_)
	//{
	//	//cout << e << endl;
	//	random << e << "\n";
	//}
	//random.close();
}
double Optimizer::ComputeCost(InputPtr input_image, ModelPtr model, Alpha& alpha) const
{
	double function_value = 0;
	
	int random_num = 1000;
	vector<int> triangle_ids;
	model->GenerateRandomNumbers(random_num, triangle_ids);	
	//int random_num = random_points_.size();

	for (int i = 0; i < random_num; ++i)
	{
		int id = triangle_ids[i];
    	//int id = random_points_[i];

		ivec2 pos = alpha.ComputePosition(id);
		vec3 model_color = alpha.ComputeColor(id);  // in RGB order 
		vec3 input_color = input_image->GetColor(Point(pos[0], pos[1])); // in RGB order
		vec3 diff = (model_color - input_color);
		function_value += dot(diff, diff);
	}
	return 40.0/1000*function_value;
}