コード例 #1
0
ファイル: HMMState.cpp プロジェクト: nlphacker/bavieca
// load the HMM from a file
void HMMState::load(FileInput &file, unsigned char iEstimationMethod) {

	// phonetic symbol
	char strPhone[MAX_PHONETIC_SYMBOL_LENGTH+1];	
	IOBase::readBytes(file.getStream(),reinterpret_cast<char*>(strPhone),MAX_PHONETIC_SYMBOL_LENGTH+1);
	m_iPhone = m_phoneSet->getPhoneIndex(strPhone);
	assert(m_iPhone != UCHAR_MAX);
	
	// state
	IOBase::read(file.getStream(),&m_iState);
	assert(m_iState < NUMBER_HMM_STATES);
	
	// within word position (DEPRECATED)
	IOBase::read(file.getStream(),&m_iPosition);
	
	// Gaussian components
	int iGaussianComponents = -1;
	IOBase::read(file.getStream(),&iGaussianComponents);
	for(int iGaussian = 0 ; iGaussian < iGaussianComponents ; ++iGaussian) {
	
		Gaussian *gaussian = new Gaussian(m_iDim,m_iCovarianceModeling);	
		
		IOBase::read(file.getStream(),&gaussian->weight());
		gaussian->mean().readData(file.getStream());		
		if (m_iCovarianceModeling == COVARIANCE_MODELLING_TYPE_DIAGONAL) {
			gaussian->covarianceDiag().readData(file.getStream());
		} else {
			gaussian->covarianceFull().readData(file.getStream());
		}	
		m_gaussianMixture->addGaussianComponent(gaussian);
	}
}
コード例 #2
0
bool ImageLoaderPng::load(ImagePtr image, const char *path)
{
	//Open the new file
	FileInput file;

	if(!file.open(path))
		return false;

	size_t filesize = file.size();

	if(filesize == 0)
	{
		Console::Print(Console::Error, "Could not load PNG %s. File empty.", path);
		return false;
	}

	std::vector<unsigned char> encoded_image;
	encoded_image.resize(filesize);

	size_t read_result = file.read(&encoded_image[0]);
	file.close();

	DEBUGPRINT("Read result is %i", read_result);
	DEBUGPRINT("Size of encoded image is %i", encoded_image.size());

	std::vector<unsigned char> decoded_image;
	
	unsigned int width = 0;
	unsigned int height = 0;

	unsigned int error = lodepng::decode(decoded_image, width, height, encoded_image);
	
	DEBUGPRINT("Lodepng returned %u", error);
	DEBUGPRINT("Lodepng decoded size: %ux%u", width, height);

	BufferPtr bitmapBuffer(new Buffer(decoded_image.size()));
	memcpy(bitmapBuffer->get(), &decoded_image[0], decoded_image.size());
    
	//Load the data into the image object
	image->setData(bitmapBuffer, width, height, Image::PixelFormat_RGBA);

	return true;
}
コード例 #3
0
ファイル: Main.cpp プロジェクト: sirarsalih/Algorithms
int main()
{
	std::string stringFilePath = "";					//FileInput Path
	std::vector<std::string> vectorStringNumbers;		//Literals
	int numberOfLiterals = 0;							//Assigned from the size of vectorNumbers
	std::string numberOfXLiterals = "";					//Number of X unique literals
	std::string numberOfClauses = "";					//Will be read from text file
	std::multimap<std::string, 
	std::vector<std::string>> multiMapLiteralClause;	//Multi map for data structure
	std::multimap<std::string, bool> mapClauseValues;	    //TRUE/FALSE SAT clauses map
	std::map<std::string, bool> mapLiteralValues;	    //TRUE/FALSE literals map
	std::vector<std::string> initialClusterCollection;  //Cluster collection that contains initial clusters (made randomly)
	std::vector<std::string> clusterCollection;			//Cluster collection that contains clusters
	int levelCounter = 0;							    //Level counter
	std::map<std::string, std::string> mapLevelClusters;//Map that contains level and the clusters within that level
	int bestSoFar = 0;
	double timeElapsedMultilevelClustering = 0;
	double timeElapsedTabuSearch = 0;
	double totalTimeElapsed = 0;
	std::string outputFile = "";
	std::string problemName = "";

	/**The objects that we need**/
	TimeElapsed te;
	OpenFileWindow ofw;
	FileInput fileInput;
	MultilevelClustering mc;
	TabuSearch ts;

	/**OpenFileDialog**/
	TCHAR * filePath = ofw.open();
	char charFilePath[260] = {0};
	
	if(filePath != NULL)
	{	
		for(int i = 0; i < wcslen((wchar_t*)filePath); i++)
			charFilePath[i] = filePath[i];
		for(int j = 0; j < sizeof(charFilePath)/sizeof(char); j++)
			stringFilePath += charFilePath[j];

		std::string fileFormat = "";
		int counter = 0;
		for(int i = stringFilePath.length() - 1; i > 0; i--)
		{
			if(counter == 3)
				break;

			if(stringFilePath[i] != 0)
			{
				fileFormat += stringFilePath[i];
				counter++;
			}
		}	

		if(fileFormat == "txt")
		{
			/**Read text file (Input)**/
			std::string collectionString = fileInput.readFile(stringFilePath);
			std::string noLettersCollectionString = fileInput.removeLetters(collectionString, numberOfXLiterals, numberOfClauses);

			/**Output file**/
			for(int i = stringFilePath.length() - 1; i > 0; i--)
			{
				if(stringFilePath[i] == '\\')
					break;
				
				if(stringFilePath[i] != 0)
					outputFile += stringFilePath[i];
			}

			std::reverse(outputFile.begin(), outputFile.end());

			while(outputFile[outputFile.length() - 1] != '.')
				outputFile.erase(outputFile.end() - 1);
			
			if(outputFile[outputFile.length() - 1] == '.')
				outputFile.erase(outputFile.end() - 1);

			problemName = outputFile;
			outputFile += "_output.txt";
			std::ofstream foutput(outputFile);
			foutput << "Problem: " << problemName << "\n";

			/**Initialize literals**/
			std::vector<int> vectorNumbers = mc.initializeNumbers(noLettersCollectionString, numberOfLiterals);

			/**Initialize data structure**/
			mc.initializeDataStructure(vectorStringNumbers, vectorNumbers, multiMapLiteralClause);

			/**Start timer**/
			clock_t begin = clock();

			/**Start clustering (Multilevel)**/
			mc.cluster(foutput, bestSoFar, numberOfXLiterals, levelCounter, mapLevelClusters, vectorStringNumbers, numberOfLiterals, numberOfClauses, initialClusterCollection, clusterCollection, mapLiteralValues, mapClauseValues, begin);

			/**Stop timer**/
			clock_t end = clock();

			timeElapsedMultilevelClustering = te.GetTimeElapsed(end, begin)/1000;

			/**Start timer**/
			begin = clock();

			/**Run Tabu Search, print out results**/
			ts.run(foutput, bestSoFar, noLettersCollectionString, numberOfLiterals, levelCounter, mapLevelClusters, vectorStringNumbers, initialClusterCollection, clusterCollection, mapLiteralValues, mapClauseValues, numberOfXLiterals, numberOfClauses, multiMapLiteralClause, begin);
			
			/**Stop timer**/
			end = clock();

			timeElapsedTabuSearch = te.GetTimeElapsed(end, begin)/1000;

			std::cout << "Time elapsed Multilevel: " << timeElapsedMultilevelClustering << " seconds" << std::endl;
			std::cout << "Time elapsed Tabu Search: " << timeElapsedTabuSearch << " seconds" << std::endl;
			std::cout << "Total time elapsed: " << timeElapsedMultilevelClustering + timeElapsedTabuSearch << " seconds" << std::endl << std::endl;
			foutput << "\nTotal time elapsed: " << timeElapsedMultilevelClustering + timeElapsedTabuSearch << " seconds";
			foutput.close();

			//Finished!
			Beep(800, 2000);
			system("pause");
		}
		
		else
		{			
			std::cout << "Incorrect file format. Input must be a text file. Exiting....." << std::endl << std::endl;
			system("pause");
		}
	}
	
	else
	{	
		std::cout << "No file input. Exiting....." << std::endl << std::endl;
		system("pause");
	}

	return 0;
}
コード例 #4
0
InputPlugin* InputThread::open_input(const FXString & uri) {
  FXString scheme = FXURL::scheme(uri);

  if (input) {
    delete input;
    input=NULL;
    }

  if (scheme=="file" || scheme.empty()) {
    FileInput * file = new FileInput(this);
    if (!file->open(uri)){
      delete file;
      return NULL;
      }
    url=uri;
    return file;
    }
  else if (scheme=="http") {
    HttpInput * http = new HttpInput(this);
    if (!http->open(uri)){
      delete http;
      return NULL;
      }
    url=uri;
    return http;
    }
#ifdef HAVE_MMS_PLUGIN
  else if (scheme=="mms") {
    MMSInput * mms = new MMSInput(this);
    if (!mms->open(uri)){
      delete mms;
      return NULL;
      }
    url=uri;
    return mms;
    }
#endif
#ifdef HAVE_CDDA_PLUGIN
  else if (scheme=="cdda") {
    CDDAInput * cdda = new CDDAInput(this);
    if (!cdda->open(uri)) {
      delete cdda;
      return NULL;
      }
    url=uri;
    return cdda;
    }
#endif
#ifdef HAVE_SMB_PLUGIN
  else if (scheme=="smb") {
    SMBInput * smb = new SMBInput(this);
    if (!smb->open(uri)) {
      delete smb;
      return NULL;
      }
    url=uri;
    return smb;
    }
#endif
  else {
    return NULL;
    }
  }
コード例 #5
0
void Shader::load(const char *path)
{
	std::string pathStr = path;

	FileInput vertexShaderFile;
	FileInput fragmentShaderFile;

	if(
		!vertexShaderFile.open(pathStr + ".vert") ||
		!fragmentShaderFile.open(pathStr + ".frag")
	)
	{
		Console::Print(Console::Error, "Could not load vertex shader %s.", path);
		return;
	}

	DEBUGPRINT("Reading shader sources",0);

	//Read the shader sources from file
	vertexShaderFile.read(mVertexShaderSrc);
	fragmentShaderFile.read(mFragmentShaderSrc);

	//DEBUGPRINT("Vertex shader %s", mVertexShaderSrc.c_str());

	//Compile the shaders
	DEBUGPRINT("Compiling Vertex Shader %s.vert", path);
	GLuint vertexshader = loadShader(mVertexShaderSrc, GL_VERTEX_SHADER);

	if(vertexshader == 0)
	{
		Console::Print(Console::Error, "Could not compile vertex shader.");
		return;
	}

	DEBUGPRINT("Compiling Fragment Shader %s.frag", path);
	GLuint fragmentshader = loadShader(mFragmentShaderSrc, GL_FRAGMENT_SHADER);

	if(vertexshader == 0)
	{
		Console::Print(Console::Error, "Could not compile fragment shader.");
		return;
	}

	//Link the shaders together into a program.
	DEBUGPRINT("Linking program %s", path);
	mProgram = linkProgram(vertexshader, fragmentshader);

	if (mProgram == 0)
	{
		Console::Print(Console::Error, "Error linking program.");
		glDeleteShader(vertexshader);
		glDeleteShader(fragmentshader);
		return;
	}

	DEBUGPRINT("Program linked: %i", mProgram);

	//Decrease the reference count on our shader objects so they get
	//deleted when the program is deleted.
	glDeleteShader(vertexshader);
	glDeleteShader(fragmentshader);

	//Set up the uniform locations for the matrices in this shader
	mProjectionMatrixHandle = glGetUniformLocation(mProgram, SHADER_PROJECTION_MATRIX_NAME);
	mModelMatrixHandle = glGetUniformLocation(mProgram, SHADER_MODEL_MATRIX_NAME);
	mViewMatrixHandle = glGetUniformLocation(mProgram, SHADER_VIEW_MATRIX_NAME);

	mTexture0Handle = glGetUniformLocation(mProgram, SHADER_TEXTURE0_NAME);
	mColor = glGetUniformLocation(mProgram, SHADER_COLOR_NAME);

	DEBUGPRINT("Found %s at: %i", SHADER_PROJECTION_MATRIX_NAME, mProjectionMatrixHandle);
	DEBUGPRINT("Found %s at: %i", SHADER_MODEL_MATRIX_NAME, mModelMatrixHandle);
	DEBUGPRINT("Found %s at: %i", SHADER_VIEW_MATRIX_NAME, mViewMatrixHandle);
	DEBUGPRINT("Found Texture0 at: %i", mTexture0Handle);
	DEBUGPRINT("Found Color at: %i", mColor);

	//Bind our shader
	use();
	//Set the default color
	glm::vec4 defaultcolor = glm::vec4(COLOR_DEFAULT);
	setColor(defaultcolor);

	//TODO: We should probably check if any of these are -1. If so, the shader is unusable.

	//Mark this shader as loaded so binding this shader works.
	setLoaded();
}