Exemplo n.º 1
0
void MeshEntry::LoadMesh(FbxMesh * mesh,


                         QVector<quint32> &master_indices,
                         QVector<float> &master_vertices,
                         QVector<float> &master_normals,
                         QVector<float> &master_uvs,
                         QVector<float> &master_tangents,


                         bool load_normals,
                         bool load_uvs,
                         bool load_tangents,



                         qint32 & current_control_point_offset,
                         qint32 & current_polygon_offset)
{




    /**
     *Load vertices and indices of the mesh entry
     */
    LoadIndices(mesh, master_indices, current_polygon_offset, current_control_point_offset);
    LoadVertices(mesh, master_vertices, current_control_point_offset);




    /**
    *Load the entry's layers
    */
    if (load_normals)
        LoadNormals(mesh, master_normals);


    if (load_uvs)
        LoadUVs(mesh, master_uvs);


    if (load_tangents)
        LoadTangents(mesh, master_tangents);



    /**
     *Compute the transform and bounding box and load them
     */
    LoadTransform(mesh);
    LoadBoundingBox(mesh);



}
bool SceneLoader::ProcessMesh(ID3D11Device *ind3dDevice, aiMesh &inMesh , DrawableObject &inObject, std::vector<Vertex> &inVertexList, std::vector<UINT> &inIndexList, unsigned int inMaterialIndex)
{

	int inPrevIndexListSize = inIndexList.size();
	int inPrevVertexListSize = inVertexList.size();

	LoadVertices(inMesh, inVertexList, mSceneBoundingSphere);
	LoadIndices(inMesh, inIndexList);

	inObject.AddPart(inPrevVertexListSize, inPrevIndexListSize, inIndexList.size() - inPrevIndexListSize, inMaterialIndex);

	return true;
}
Exemplo n.º 3
0
	void Model::CreateRectangle(Vector2 dimensions, const char* vertexPath, const char* fragmentPath)
	{
		width = dimensions.x;
		height = dimensions.y;

		int halfWidth = width / 2;
		int halfHeight = height / 2;

		Vector3 positions[] =
		{
			Vector3(halfWidth, -halfHeight, 0.0f),
			Vector3(halfWidth, halfHeight, 0.0f),
			Vector3(-halfWidth, halfHeight, 0.0f),
			Vector3(-halfWidth, -halfHeight, 0.0f)
		};

		Vector2 vTexCoords[] =
		{
			Vector2(1.0, 0.0),
			Vector2(1.0, 1.0),
			Vector2(0.0, 1.0),
			Vector2(0.0, 0.0)
		};

		GLubyte vIndices[] =
		{
			0, 1, 2,
			2, 3, 0
		};

		if (!LoadShader(vertexPath, fragmentPath))
		{
			// Log error here
			return;
		}

		glBindAttribLocation(shader.GetProgram(), 0, "vPosition");

		shader.Link();

		// Figure out how to deal with modelviewprojection matrices
		mvpMatrixHandle = glGetUniformLocation(shader.GetProgram(), "MVPMatrix");

		LoadVertices(positions, vTexCoords, arraysize(positions));
		LoadIndices(vIndices, arraysize(vIndices));
		Initialize();
	}
int main(int argc, char *argv[]) {
  QApplication a(argc, argv);
  glutInit(&argc, argv);
  google::InitGoogleLogging(argv[0]);

  namespace fs = boost::filesystem;
  namespace po = boost::program_options;

  const string home_directory = QDir::homePath().toStdString();
  cout << "Home dir: " << home_directory << endl;

  po::options_description desc("Options");
  desc.add_options()
  ("settings_file", po::value<string>()->required(), "Input settings file")
  ("model_file", po::value<string>()->default_value(home_directory + "/Data/Multilinear/blendshape_core.tensor"), "Multilinear model file")
  ("id_prior_file", po::value<string>()->default_value(home_directory + "/Data/Multilinear/blendshape_u_0_aug.tensor"), "Identity prior file")
  ("exp_prior_file", po::value<string>()->default_value(home_directory + "/Data/Multilinear/blendshape_u_1_aug.tensor"), "Expression prior file")
  ("template_mesh_file", po::value<string>()->default_value(home_directory + "/Data/Multilinear/template.obj"), "Template mesh file")
  ("contour_points_file", po::value<string>()->default_value(home_directory + "/Data/Multilinear/contourpoints.txt"), "Contour points file")
  ("landmarks_file", po::value<string>()->default_value(home_directory + "/Data/Multilinear/landmarks_73.txt"), "Landmarks file")
  ("direct_multi_recon", "Use direct multi-recon")
  ("no_selection", "Disable selection")
  ("no_failure_detection", "Disable feature points failure detection")
  ("no_progressive", "Diable progressive reconstruction");

  po::variables_map vm;

  try {
    po::store(po::parse_command_line(argc, argv, desc), vm);
    po::notify(vm);
    if(vm.count("help")) {
      cout << desc << endl;
      return 1;
    }

    // nothing to do after successful parsing command line arguments

  } catch(po::error& e) {
    cerr << "Error: " << e.what() << endl;
    cerr << desc << endl;
    return 1;
  }

  const string model_filename(vm["model_file"].as<string>());
  const string id_prior_filename(vm["id_prior_file"].as<string>());
  const string exp_prior_filename(vm["exp_prior_file"].as<string>());
  const string template_mesh_filename(vm["template_mesh_file"].as<string>());
  const string contour_points_filename(vm["contour_points_file"].as<string>());
  const string landmarks_filename(vm["landmarks_file"].as<string>());
  const string settings_filename(vm["settings_file"].as<string>());

  BasicMesh mesh(template_mesh_filename);
  auto landmarks = LoadIndices(landmarks_filename);
  auto contour_indices = LoadContourIndices(contour_points_filename);

  // Create reconstructor and load the common resources
  MultiImageReconstructor<Constraint2D> recon;
  recon.LoadModel(model_filename);
  recon.LoadPriors(id_prior_filename, exp_prior_filename);
  recon.SetMesh(mesh);
  recon.SetContourIndices(contour_indices);
  recon.SetIndices(landmarks);

  recon.SetSelectionState(!vm.count("no_selection"));
  recon.SetFailureDetectionState(!vm.count("no_failure_detection"));
  recon.SetProgressiveReconState(!vm.count("no_progressive"));
  recon.SetDirectMultiRecon(vm.count("direct_multi_recon"));

  // Parse the setting file and load image related resources
  fs::path settings_filepath(settings_filename);

  vector<pair<string, string>> image_points_filenames = ParseSettingsFile(settings_filename);
  for(auto& p : image_points_filenames) {
    fs::path image_filename = settings_filepath.parent_path() / fs::path(p.first);
    fs::path pts_filename = settings_filepath.parent_path() / fs::path(p.second);
    cout << "[" << image_filename << ", " << pts_filename << "]" << endl;

    auto image_points_pair = LoadImageAndPoints(image_filename.string(), pts_filename.string(), false);
    recon.AddImagePointsPair(image_filename.string(), image_points_pair);
  }

  {
    boost::timer::auto_cpu_timer t("Reconstruction finished in %w seconds.\n");
    recon.Reconstruct();
  }

  //return a.exec();
  return 0;
}
Exemplo n.º 5
0
int main()
{
	const int triangleCount = 111;
	const int trianglePoints = 68;
	const Vec2i resolution(169, 167);

	std::string meanShape = "Data/Mean_Shape.txt";
	std::string currentShape = "Data/Current_Shape.txt";
	std::string triangles = "Data/Triangles.txt";
	std::string textureBase = "Data/Texture_Base.txt";
	std::string imageName = "Data/inputImage.png";

	cv::Mat inputImage = cv::imread(imageName, CV_LOAD_IMAGE_GRAYSCALE);
	if(!inputImage.data)
	{
		std::cerr << "Could not open or find the image"  << std::endl;		
		std::exit(EXIT_FAILURE);
	}	

	std::vector<Vec2i> trianglePointsList[triangleCount];
	LoadTextureBase(textureBase, resolution, trianglePointsList);


	// load points rounded to nearest int
	Vec2i* meanPoints = new Vec2i[trianglePoints];	
	LoadShape(meanShape, meanPoints);
	Vec2i* currentPoints = new Vec2i[trianglePoints];	
	LoadShape(currentShape, currentPoints);

	// load points as floats
	Vec2f* meanPointsf = new Vec2f[trianglePoints];	
	LoadShapef(meanShape, meanPointsf);
	Vec2f* currentPointsf = new Vec2f[trianglePoints];	
	LoadShapef(currentShape, currentPointsf);



	Index* indices = new Index[triangleCount];
	LoadIndices(triangles, indices);


	cv::Mat outImage = cv::Mat::zeros(resolution.y, resolution.x, inputImage.type());

	clock_t timeC;
	int loops = 10000;
	timeC = clock();	
	for(int y = 0; y < loops; ++y)
	{
		WarpImage(meanPoints, currentPoints, indices, triangleCount, trianglePointsList, inputImage, outImage);
	}	
	timeC = clock() - timeC;
	std::cout << "WarpImage time to do " << loops << " loops: " << timeC * 1000 / CLOCKS_PER_SEC << " milliseconds." << std::endl;

	cv::Mat outImagef = cv::Mat::zeros(resolution.y, resolution.x, inputImage.type());
	timeC = clock();	
	for(int y = 0; y < loops; ++y)
	{
		WarpImagef(meanPointsf, currentPointsf, indices, triangleCount, trianglePointsList, inputImage, outImagef);
	}	
	timeC = clock() - timeC;
	std::cout << "WarpImagef time to do " << loops << " loops: " << timeC * 1000 / CLOCKS_PER_SEC << " milliseconds." << std::endl;
	

	cv::namedWindow("WarpImage image", CV_WINDOW_AUTOSIZE );
	cv::imshow("WarpImage image", outImage);

	cv::namedWindow("WarpImage imagef", CV_WINDOW_AUTOSIZE );
	cv::imshow("WarpImage imagef", outImagef);	

	cv::waitKey(0);

	delete[] indices;	
	delete[] currentPointsf;
	delete[] meanPointsf;
	delete[] currentPoints;
	delete[] meanPoints;

	return 0;
}