Exemplo n.º 1
0
ALERROR WriteHeader (CTDBCompiler &Ctx, int iGameFile, CDataFile &Out)
	{
	ALERROR error;
	CMemoryWriteStream Stream;

	if (error = Stream.Create())
		{
		Ctx.ReportError(CONSTLIT("Out of memory"));
		return error;
		}

	//	Write it

	CString sError;
	if (!Ctx.WriteHeader(Stream, iGameFile, &sError))
		{
		Ctx.ReportError(strPatternSubst(CONSTLIT("Unable to write header: %s"), sError));
		return ERR_FAIL;
		}

	//	Write out the header

	Stream.Close();
	CString sData(Stream.GetPointer(), Stream.GetLength(), TRUE);
	int iEntry;
	if (error = Out.AddEntry(sData, &iEntry))
		{
		Ctx.ReportError(CONSTLIT("Unable to write header"));
		return error;
		}

	Out.SetDefaultEntry(iEntry);

	return NOERROR;
	}
Exemplo n.º 2
0
ALERROR WriteHeader (int iGameFile, CSymbolTable &Resources, CDataFile &Out)
	{
	ALERROR error;
	CMemoryWriteStream Stream;
	DWORD dwSave;

	if (error = Stream.Create())
		{
		printf("Out of memory\n");
		return error;
		}

	//	Signature

	dwSave = TDB_SIGNATURE;
	Stream.Write((char *)&dwSave, sizeof(dwSave));

	//	Version

	dwSave = TDB_VERSION;
	Stream.Write((char *)&dwSave, sizeof(dwSave));

	//	Game file entry

	dwSave = iGameFile;
	Stream.Write((char *)&dwSave, sizeof(dwSave));

	//	Game title

	CString sGameTitle = CONSTLIT("Transcendence: The March of the Heretic");
	sGameTitle.WriteToStream(&Stream);

	//	Resource map

	CString sSave;
	if (error = CObject::Flatten(&Resources, &sSave))
		{
		printf("Unable to flatten resources map\n");
		return error;
		}

	sSave.WriteToStream(&Stream);

	//	Write out the header

	Stream.Close();
	CString sData(Stream.GetPointer(), Stream.GetLength(), TRUE);
	int iEntry;
	if (error = Out.AddEntry(sData, &iEntry))
		{
		printf("Unable to write out header\n");
		return error;
		}

	Out.SetDefaultEntry(iEntry);

	return NOERROR;
	}
///////////////////////////////////////////////////////////////////////////////
/// Checks if a key that is supposed in a specific section exists in ini file. 
/// If the key does not exists an error message is generated and the programm 
/// is quit.
/// @param [in] CfgFile Reference to the loaded ini file. 
/// @param [in] key the key that is to be checked.
/// @param [in] section the section in which the key is supposed to be. 
///////////////////////////////////////////////////////////////////////////////
bool CheckCfgParameterKeyExist(CDataFile CfgFile, string key, string section)
{   
    if (CfgFile.GetString(key,section).length() == 0)
		return false;
	else
		return true;
}
Exemplo n.º 4
0
ALERROR WriteResource (const CString &sFilename, const CString &sFolder, CSymbolTable &Resources, CDataFile &Out)
	{
	ALERROR error;
	CString sFilespec = pathAddComponent(sFolder, sFilename);

	CFileReadBlock theFile(sFilespec);
	if (error = theFile.Open())
		{
		printf("Unable to open '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	CString sData(theFile.GetPointer(0, -1), theFile.GetLength(), TRUE);
	int iEntry;
	if (error = Out.AddEntry(sData, &iEntry))
		{
		printf("Unable to store '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	Resources.AddEntry(sFilespec, (CObject *)iEntry);
	printf("   %s\n", sFilespec.GetASCIIZPointer());

	return NOERROR;
	}
Exemplo n.º 5
0
void getCamPose(const char* pose_cal_file, TomGine::tgPose& camPose){
    CDataFile cdfParams;
    if(!cdfParams.Load(pose_cal_file)){
        char errmsg[128];
        sprintf(errmsg, "[utilities::getCamPose] Can not open pose_cal file '%s'", pose_cal_file);
        throw std::runtime_error(errmsg);
    }

    vec3 t, r;
    mat3 R;

    std::string pose = cdfParams.GetString("pose");
    sscanf( pose.c_str(), "[%f %f %f] [%f %f %f]",
            &(t.x), &(t.y), &(t.z), &(r.x), &(r.y), &(r.z) );

    R.fromRotVector(r);

    camPose.SetPose(R,t);
}
Exemplo n.º 6
0
void setCameraPose(TomGine::tgCamera::Parameter& camPar, const char* pose_cal_file)
{
    CDataFile poseCDF;
    if(!poseCDF.Load(pose_cal_file)){
        char errmsg[128];
        sprintf(errmsg, "[utilities::GetTrackingParameter] Can not open pose_cal file '%s'", pose_cal_file);
        throw std::runtime_error(errmsg);
    }

    // Pose
    vec3 p, r;
    std::string pose = poseCDF.GetString("pose");
    sscanf( pose.c_str(), "[%f %f %f] [%f %f %f]", &(p.x), &(p.y), &(p.z), &(r.x), &(r.y), &(r.z) );
    //printf("%s\n", pose.c_str());
    //printf("%f %f %f, %f %f %f\n", p.x, p.y, p.z, r.x, r.y, r.z);
    camPar.pos.x = p.x;
    camPar.pos.y = p.y;
    camPar.pos.z = p.z;
    camPar.rot.fromRotVector(r);
}
Exemplo n.º 7
0
ALERROR WriteResource (CTDBCompiler &Ctx, const CString &sFilename, const CString &sFolder, bool bCompress, CDataFile &Out)
	{
	ALERROR error;
	CString sFilespec = pathAddComponent(sFolder, sFilename);

	CFileReadBlock theFile(pathAddComponent(Ctx.GetRootPath(), sFilespec));
	if (error = theFile.Open())
		{
		Ctx.ReportError(strPatternSubst(CONSTLIT("Unable to open '%s'."), sFilespec));
		return error;
		}

	CString sData(theFile.GetPointer(0, -1), theFile.GetLength(), TRUE);

	if (bCompress)
		{
		CBufferReadBlock Input(sData);

		CMemoryWriteStream Output;
		if (error = Output.Create())
			return ERR_FAIL;

		CString sError;
		if (!zipCompress(Input, compressionZlib, Output, &sError))
			{
			Ctx.ReportError(sError);
			return ERR_FAIL;
			}

		sData = CString(Output.GetPointer(), Output.GetLength());
		}

	int iEntry;
	if (error = Out.AddEntry(sData, &iEntry))
		{
		Ctx.ReportError(strPatternSubst(CONSTLIT("Unable to store '%s'."), sFilespec));
		return error;
		}

	Ctx.AddResource(sFilespec, iEntry, bCompress);

	printf("   %s\n", sFilespec.GetASCIIZPointer());

	return NOERROR;
	}
Exemplo n.º 8
0
BOOL CDataFile::Init( const char *pFilename, int iRifVer, BOOL bErr )
{

	m_iRifVer = iRifVer;

	CString strFileName;
	if ( ( ! bErr ) && ( ptheApp->m_lpCmdLine[0] ) )
		{
		TRAP ();
		strFileName = ptheApp->m_lpCmdLine;
		}
	else
		strFileName = ptheApp->GetProfileString ("Game", "DataFile", CString (".\\") + pFilename);
	CString sPatch = ptheApp->GetProfileString ("Game", "Patch", "data");
	if (! sPatch.IsEmpty ())
		if (sPatch[sPatch.GetLength()-1] == '\\')
			sPatch.ReleaseBuffer (sPatch.GetLength()-1);

	// if it's an error we force looking for a new file
	if (bErr)
		if ( ! GetFileName ( strFileName ) )
			return (FALSE);
			
	// open the data file
	for (; TRUE; )
		{
		try
			{
			theDataFile._Init (strFileName, sPatch, iRifVer);
			ptheApp->WriteProfileString ("Game", "DataFile", strFileName);
			return (TRUE);
			}

		catch (...)
			{
			if ( ! GetFileName ( strFileName ) )
				return (FALSE);
			}
		}

	ASSERT (FALSE);
	return (FALSE);
}
Exemplo n.º 9
0
void GetPlySiftFilenames(const char* ini_file, std::string &ply_file, std::string &sift_file, std::string &model_name)
{
    CDataFile iniCDF;

    if(!iniCDF.Load(ini_file)){
        char errmsg[128];
        sprintf(errmsg, "[utilities::GetTrackingParameter] Can not open tracking_ini file '%s'", ini_file);
        throw std::runtime_error(errmsg);
    }

    ply_file = iniCDF.GetString("ModelPath", "ResourcePath");
    ply_file.append(iniCDF.GetString("Model", "Files"));
    sift_file = iniCDF.GetString("SiftPath", "ResourcePath");
    sift_file.append(iniCDF.GetString("SiftModel", "Files"));

    model_name = iniCDF.GetString("Model", "Files");
    model_name = model_name.substr(0, model_name.find("."));

}
Exemplo n.º 10
0
ALERROR WriteGameFile (const CString &sFilespec, CDataFile &Out, int *retiGameFile)
	{
	ALERROR error;

	CFileReadBlock theFile(sFilespec);
	if (error = theFile.Open())
		{
		printf("Unable to open '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	CString sData(theFile.GetPointer(0, -1), theFile.GetLength(), TRUE);
	if (error = Out.AddEntry(sData, retiGameFile))
		{
		printf("Unable to store '%s'\n", sFilespec.GetASCIIZPointer());
		return error;
		}

	printf("%s\n", sFilespec.GetASCIIZPointer());

	return NOERROR;
	}
Exemplo n.º 11
0
void spliterrorsetVL(CMyAln * pALN) // routine
{
	// assign the square errors on the validation set to the leaf nodes of the ALN
	double * adblX = (double *) malloc((nDim) * sizeof(double));
	double desired = 0;
	double predict = 0;
  double      se = 0; // square error added to LFN DBLSQERRORVAL
	ALNNODE* pActiveLFN;
	for(int j=0; j<nRowsALNinputValFile; j++)   // this is expensive using the whole validation set, but more accurate
  {
    for(int i=0; i<nDim; i++)
		{
			adblX[i] = ALNinputValFile.GetAt(j,i,0); // the value at nDim - 1 is used only for desired
		}
		desired = adblX[nDim - 1];
		adblX[nDim - 1] = 0; // not used by QuickEval WWA 2009.10.06
		predict = pALN->QuickEval(adblX, &pActiveLFN);
    se = (predict - desired) * (predict - desired);
		(pActiveLFN->DATA.LFN.pSplit)->nCount++;
		(pActiveLFN->DATA.LFN.pSplit)->DBLSQERRORVAL += se;
  } // end loop over VLfile
	free(adblX);
} // END of spliterrorsetVL
Exemplo n.º 12
0
void spliterrorsetTR(CMyAln * pALN) // routine
{
	// assign the square errors on the validation set to the leaf nodes of the ALN
	double * adblX = (double *) malloc((nDim) * sizeof(double));
	double desired = 0;
	double predict = 0;
  double      se = 0; // square error accumulator
	ALNNODE* pActiveLFN;
	for(int j=0; j<nRowsTR; j++)
	{
		for(int i=0; i<nDim; i++)
		{
			adblX[i] = TRfile.GetAt(j,i,0);
		}
		desired = adblX[nDim - 1]; // get the desired result
		adblX[nDim-1] = 0; // not used in evaluation by QuickEval
		predict = pALN->QuickEval(adblX, &pActiveLFN);
    se = (predict - desired) * (predict - desired);
		(pActiveLFN->DATA.LFN.pSplit)->nCount++;
		(pActiveLFN->DATA.LFN.pSplit)->dblSqError += se;
  } // end loop over TRset
	free(adblX);
} // END of spliterrorsetTR
Exemplo n.º 13
0
int main(int argc, char** argv) {
    CDataFile data;
    data.ReadFile("iris3.csv");
    std::vector<double> col;
    int n = data.GetData("PetalLength",col);
    int samples = data.GetNumberOfSamples(1);
    int vars = data.GetNumberOfVariables();
    std::cout<<"Samples: "<<samples<<" Vars: "<<vars<<"\n";
    std::vector<double> row;
    for(int i=0; i<samples; i++) {
        data.GetSample(i,row);
        for(int j=0; j<vars; j++) {
            std::cout << row[j]<<"\t";
        }
        std::cout<<"\n";
    }
    return 0;
}
bool ReadIniParameters(string szFile, InitialParameter &IniParam)
{
///////////////////////////////////////////////////////////////////////////////
// Section: Define variables
CDataFile	CfgFile;
vector<int> chset;
vector<float> windlen;
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// Section: Testing input parameters and initialize parameters
if (CfgFile.Load(szFile.c_str()))
{
	if (CheckCfgParameterKeyExist(CfgFile,"dir","Initialization"))
		IniParam.dir = CfgFile.GetString("dir","Initialization");
	else
		IniParam.dir = "C:";	

	if (CheckCfgParameterKeyExist(CfgFile,"decimation_frequency_Hz","Initialization"))
		IniParam.Decimation_Frequency = CfgFile.GetInt("decimation_frequency_Hz","Initialization");
	else
		IniParam.Decimation_Frequency = 20;

	if (CheckCfgParameterKeyExist(CfgFile,"spatial_filter","Initialization"))
		IniParam.SF = CfgFile.GetInt("spatial_filter","Initialization");
	else
		IniParam.SF = 1;

	if (CheckCfgParameterKeyExist(CfgFile,"penter","Initialization"))
		IniParam.penter = CfgFile.GetFloat("penter","Initialization");
	else
		IniParam.penter = 0.1000f;

	if (CheckCfgParameterKeyExist(CfgFile,"premove","Initialization"))
		IniParam.premove = CfgFile.GetFloat("premove","Initialization");
	else
		IniParam.premove = 0.1500f;

	if (CheckCfgParameterKeyExist(CfgFile,"maxiter","Initialization"))
		IniParam.maxiter = CfgFile.GetInt("maxiter","Initialization");
	else
		IniParam.maxiter = 60;

	if (CheckCfgParameterKeyExist(CfgFile,"channel_set","Initialization"))
	{
		string channelset = CfgFile.GetValue("channel_set","Initialization");
		read_vector(channelset, IniParam.channel_set);
	}
	else
		IniParam.channel_set.push_back(1); 

	if (CheckCfgParameterKeyExist(CfgFile,"Resp_window_ms","Initialization"))
	{
		string Resp_window = CfgFile.GetValue("Resp_window_ms","Initialization");
		read_vector(Resp_window, IniParam.windlen);
	}
	else
	{
		IniParam.windlen.push_back(0);
		IniParam.windlen.push_back(800);
	}
	return true;
}
else
// file does not exist
return false;
}
Exemplo n.º 15
0
void GetTrackingParameter( Tracking::Tracker::Parameter& params, const char* ini_file, std::string config_root = ".")
{
    CDataFile iniCDF;

    if(!iniCDF.Load(ini_file)){
        char errmsg[128];
        sprintf(errmsg, "[utilities::GetTrackingParameter] Can not open tracking_ini file '%s'", ini_file);
        throw std::runtime_error(errmsg);
    }

    // Tracking
    // Constraints
    params.variation.r.x = iniCDF.GetFloat("r.x", "Constraints") * Tracking::pi/180.0f;
    params.variation.r.y = iniCDF.GetFloat("r.y", "Constraints") * Tracking::pi/180.0f;
    params.variation.r.z = iniCDF.GetFloat("r.z", "Constraints") * Tracking::pi/180.0f;
    params.variation.t.x 	= iniCDF.GetFloat("t.x", "Constraints");
    params.variation.t.y 	= iniCDF.GetFloat("t.y", "Constraints");
    params.variation.t.z 	= iniCDF.GetFloat("t.z", "Constraints");
    params.variation.z 		= iniCDF.GetFloat("z", "Constraints");

    // Performance
    params.num_recursions = iniCDF.GetInt("recursions", "Performance");
    params.num_particles = iniCDF.GetInt("particles", "Performance");
    params.hypotheses_trials = iniCDF.GetInt("hypotheses", "Performance");
    params.convergence = iniCDF.GetInt("convergence", "Performance");

    // Resource Path
    params.modelPath = pal_blort::addRoot(iniCDF.GetString("ModelPath", "ResourcePath"), config_root);
    params.texturePath = pal_blort::addRoot(iniCDF.GetString("TexturePath", "ResourcePath"), config_root);
    params.shaderPath = pal_blort::addRoot(iniCDF.GetString("ShaderPath", "ResourcePath"), config_root);

    // Other
    params.edge_tolerance = iniCDF.GetFloat("EdgeMatchingTolerance", "Other") * Tracking::pi/180.0f;
    params.minTexGrabAngle = iniCDF.GetFloat("MinTextureGrabAngle", "Other") * Tracking::pi/180.0f;
    params.num_spreadings =  iniCDF.GetInt("NumberOfSpreadings", "Other");
    params.max_kernel_size = iniCDF.GetInt("MaxKernelSize", "Other");

    params.model_sobel_th = iniCDF.GetFloat("ModelSobelThreshold", "Other");
    params.image_sobel_th = iniCDF.GetFloat("ImageSobelThreshold", "Other");
    params.pred_no_convergence = iniCDF.GetFloat("PredictorNoConvergence", "Other");

    params.c_th_base = iniCDF.GetFloat("BaseThreshold", "Qualitative");
    params.c_th_min = iniCDF.GetFloat("MinThreshold", "Qualitative");
    params.c_th_fair = iniCDF.GetFloat("FairThreshold", "Qualitative");
    params.c_th_lost = iniCDF.GetFloat("LostThreshold", "Qualitative");

    params.c_mv_not = iniCDF.GetFloat("NoMovementThreshold", "Movement");
    params.c_mv_slow = iniCDF.GetFloat("SlowMovementThreshold", "Movement");
}
Exemplo n.º 16
0
int main( int /*argc*/, char * /*argv*/[] )
{
	//  Create a CDataFile object.
	CString	str;
	CMmio *pFile;

	dataFile.Init( "test.dat", "." );

	pFile = dataFile.OpenAsMMIO( "t1" );
	pFile->DescendRiff( 'T','S','T','1' );
	pFile->DescendList( 'T','S','T','L' );
	pFile->DescendChunk( 'D','A','T','A' );
	pFile->ReadString( str );
	pFile->AscendChunk();
	pFile->DescendChunk( 'D','A','T','A' );
	pFile->ReadString( str );
	delete pFile;

	pFile = dataFile.OpenAsMMIO( "t2" );
	pFile->DescendRiff( 'T','S','T','2' );
	pFile->DescendChunk( 'D','A','T','A' );
	pFile->ReadString( str );
	delete pFile;

	pFile = dataFile.OpenAsMMIO( "units" );
	pFile->DescendRiff( 'U','N','I','T' );
	pFile->DescendList( 'T','E','R','N' );
	pFile->DescendChunk( 'N','M','B','R' );
	short x = ( short )pFile->ReadInt();
	delete pFile;

	CFile *pNormFile;
	pNormFile = dataFile.OpenAsFile( "bk.bat" );
	char	array[ 64 ];
	pNormFile->Read( array, 64 );
	delete pNormFile;

	CArchive *pArchive;
	pArchive = dataFile.OpenAsCArchive( "bk.bat" );
	dataFile.CloseCArchive( pArchive );

	dataFile.SetCountryCode( 1 );
	pFile = dataFile.OpenAsMMIO( NULL );
	delete pFile;

	dataFile.SetCountryCode( 2 );
	pFile = dataFile.OpenAsMMIO( NULL );
	delete pFile;

	dataFile.SetCountryCode( 12 );
	pFile = dataFile.OpenAsMMIO( NULL );
	delete pFile;

	dataFile.Close();

	dataFile.Init( NULL, "." );

	pFile = dataFile.OpenAsMMIO( "t1" );
	pFile->DescendRiff( 'T','S','T','1' );
	pFile->DescendList( 'T','S','T','L' );
	pFile->DescendChunk( 'D','A','T','A' );
	pFile->ReadString( str );
	pFile->AscendChunk();
	pFile->DescendChunk( 'D','A','T','A' );
	pFile->ReadString( str );
	delete pFile;
	
	pNormFile = dataFile.OpenAsFile( "bk2.bat" );
	pNormFile->Read( array, 64 );
	delete pNormFile;

	pArchive = dataFile.OpenAsCArchive( "bk2.bat" );
	dataFile.CloseCArchive( pArchive );

	dataFile.Close();

	return 0;
}