示例#1
0
// Create an Archive from the specified Source Directory.
VFS_BOOL VFS_Archive_CreateFromDirectory( const VFS_String& strArchiveFileName, const VFS_String& strDirName, const VFS_FilterNameList& UsedFilters, VFS_BOOL bRecursive )
{
    // Not initialized yet?
    if( !IsInit() )
    {
        SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
        return VFS_FALSE;
    }

    // Get the Directory Contents.
    VFS_EntityInfoList EntityInfos;
    if( !VFS_Dir_GetContents( strDirName, EntityInfos, bRecursive ) )
        return VFS_FALSE;

    // Get the absolute Path of the Directory.
    VFS_EntityInfo Info;
    if( !VFS_Dir_GetInfo( strDirName, Info ) )
        return VFS_FALSE;

    // Get the Start Position for the In-Archive Name.
    VFS_INT nStart = ( VFS_INT )Info.strPath.size();
    if( !IsRootDir( Info.strPath ) )
        nStart++;

    // Make a File Name List out of the Entity Info List.
    VFS_FileNameMap Files;
    for( VFS_EntityInfoList::iterator iter = EntityInfos.begin(); iter != EntityInfos.end(); iter++ )
    {
        if( ( *iter ).eType == VFS_FILE )
            Files[ ( *iter ).strPath ] = ( *iter ).strPath.substr( nStart );
    }

    // Try to create an Archive from the File List.
    return VFS_Archive_CreateFromFileList( strArchiveFileName, Files, UsedFilters );
}
示例#2
0
VFS_BOOL VFS_Archive_GetInfo( const VFS_String& strArchiveFileName, VFS_EntityInfo& Info )
{
    // Not initialized yet?
    if( !IsInit() )
    {
        SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
        return VFS_FALSE;
    }

    // Get Info and change Type.
    if( !VFS_File_GetInfo( strArchiveFileName + VFS_TEXT( "." ) + VFS_ARCHIVE_FILE_EXTENSION, Info ) )
        return VFS_FALSE;

    // Check the Extension.
    VFS_String strExtension;
    if( !VFS_Util_GetExtension( Info.strName, strExtension ) )
        return VFS_FALSE;
    if( ToLower( strExtension ) != ToLower( VFS_ARCHIVE_FILE_EXTENSION ) )
    {
        SetLastError( VFS_ERROR_NOT_AN_ARCHIVE );
        return VFS_FALSE;
    }

    // Remove the Extension (THE ONLY TIME THE USER IS CONFRONTATED WITH THE ARCHIVE FILE EXTENSION IS WHEN HE USES EXPLICITELY THE VFS_ARCHIVE_FILE_EXTENSION CONSTANT).
    Info.strName = Info.strName.substr( 0, Info.strName.size() - strExtension.size() - 1 );
    Info.strPath = Info.strPath.substr( 0, Info.strPath.size() - strExtension.size() - 1 );

    // Change the Type in the Entity Information Record.
    Info.eType = VFS_ARCHIVE;

    return VFS_TRUE;
}
示例#3
0
// Creates a File in the First Root Path.
VFS_Handle VFS_File_Create( const VFS_String& strFileName, VFS_DWORD dwFlags )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_INVALID_HANDLE_VALUE;
	}

	// No Root Paths specified yet?
	if( GetRootPaths().size() == 0 && !VFS_Util_IsAbsoluteFileName( strFileName ) )
	{
		SetLastError( VFS_ERROR_NO_ROOT_PATHS_DEFINED );
		return VFS_INVALID_HANDLE_VALUE;
	}

	// Make it absolute...
	VFS_String strAbsoluteFileName = ToLower( strFileName );
	if( !VFS_Util_IsAbsoluteFileName( strAbsoluteFileName ) )
		strAbsoluteFileName = ToLower( WithoutTrailingSeparator( GetRootPaths()[ 0 ], VFS_TRUE ) + VFS_PATH_SEPARATOR + strFileName );

	// Is such a File already open? Then just resize it.
	if( GetOpenFiles().find( strAbsoluteFileName ) != GetOpenFiles().end() )
	{
		IFile* pFile = GetOpenFiles()[ strAbsoluteFileName ];
		if( !pFile->Resize( 0 ) )
			return VFS_INVALID_HANDLE_VALUE;
		pFile->Add();
		return ( VFS_Handle )( VFS_DWORD )pFile;
	}

    // Try to create and return a StdIO File.	
	return AddAndConvert( CStdIOFile::Create( strAbsoluteFileName, dwFlags ), strAbsoluteFileName );
}
示例#4
0
	String ShininessToRoughnessTex(const String & path)
	{
		auto roughnessTexPath = path.substr(0, path.rfind('.')) + "_roughness" + TextureAsset::GetExtension();
		if (Global::GetPlatform()->FileExists(roughnessTexPath))
			return roughnessTexPath;

		auto shininessTexAsset = Asset::Find<TextureAsset>(path);
		if (!shininessTexAsset->IsInit())
		{
			shininessTexAsset->Init();

			auto roughnessTexDesc = shininessTexAsset->GetTexture()->GetDesc();
			roughnessTexDesc.bindFlag = TEXTURE_BIND_SHADER_RESOURCE | TEXTURE_BIND_RENDER_TARGET | TEXTURE_BIND_GENERATE_MIPS;
			roughnessTexDesc.mipLevels = 0;
			auto roughnessTex = Global::GetRenderEngine()->GetRenderFactory()->CreateTexture(TEXTURE_2D);
			roughnessTex->SetDesc(roughnessTexDesc);
			roughnessTex->Init();

			auto ps = Shader::FindOrCreate<ShininessToRoughnessPS>();
			ps->SetSRV("shininessTex", shininessTexAsset->GetTexture()->GetShaderResourceView(0, 1, 0, 1));
			ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get());
			ps->Flush();

			DrawQuad({ roughnessTex->GetRenderTargetView(0, 0, 1) });

			auto roughnessTexAsset = std::make_shared<TextureAsset>();
			roughnessTexAsset->SetPath(roughnessTexPath);
			roughnessTexAsset->Register();
			roughnessTexAsset->Save();
		}

		return roughnessTexPath;
	}
示例#5
0
// Write the entire File at once.
VFS_BOOL VFS_File_WriteEntireFile( const VFS_String& strFileName, const VFS_BYTE* pBuffer, VFS_DWORD dwToWrite, VFS_DWORD* pWritten )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_FALSE;
	}

	// (Re)create the File.
	VFS_Handle hFile = VFS_File_Create( strFileName, VFS_WRITE );
	if( hFile == VFS_INVALID_HANDLE_VALUE )
		return VFS_FALSE;

    // Write the File.
	if( !VFS_File_Write( hFile, pBuffer, dwToWrite, pWritten ) )
	{
		// Close the File.
		VFS_File_Close( hFile );

		return VFS_FALSE;
	}

    // Close the File.
	return VFS_File_Close( hFile );
}
示例#6
0
// Returns Information about the File associated with the specified File Handle.
VFS_BOOL VFS_File_GetInfo( VFS_Handle hFile, VFS_EntityInfo& Info )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_FALSE;
	}

	// Invalid Handle Value?
	if( hFile == VFS_INVALID_HANDLE_VALUE )
	{
		SetLastError( VFS_ERROR_INVALID_PARAMETER );
		return VFS_FALSE;
	}

	// Get the File Pointer.
	IFile* pFile = ( IFile* )( VFS_DWORD )hFile;

	// Fill the Entity Information Structure.
	Info.bArchived = pFile->IsArchived();
	Info.eType = VFS_FILE;
	Info.lSize = pFile->GetSize();
	Info.strPath = pFile->GetFileName();
	return VFS_Util_GetName( Info.strPath, Info.strName );
}
示例#7
0
// Read in the entire File at once.
VFS_BOOL VFS_File_ReadEntireFile( const VFS_String& strFileName, VFS_BYTE* pBuffer, VFS_DWORD dwToRead, VFS_DWORD* pRead )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_FALSE;
	}

	// Open the File.
	VFS_Handle hFile = VFS_File_Open( strFileName, VFS_READ );
	if( hFile == VFS_INVALID_HANDLE_VALUE )
		return VFS_FALSE;

    // Read in the File.
	if( !VFS_File_Read( hFile, pBuffer, dwToRead, pRead ) )
	{
		// Close the File.
		VFS_File_Close( hFile );

		return VFS_FALSE;
	}

    // Close the File.
	return VFS_File_Close( hFile );
}
示例#8
0
// Flush the Archive System.
VFS_BOOL VFS_Archive_Flush()
{
    // Not initialized yet?
    if( !IsInit() )
    {
        SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
        return VFS_FALSE;
    }

    typedef vector< VFS_String > ArchiveList;
    ArchiveList ToClose;

    // For each open Archive.
    for( ArchiveMap::iterator iter = GetOpenArchives().begin(); iter != GetOpenArchives().end(); iter++ )
    {
        // If there are no more References to this Archive, then add it to the To Close List.
        if( ( *iter ).second->GetRefCount() == 0 )
        {
            ToClose.push_back( ( *iter ).first );
        }
    }

    // Close the Archives to Close.
    for( ArchiveList::iterator iter2 = ToClose.begin(); iter2 != ToClose.end(); iter2++ )
    {
        delete GetOpenArchives()[ ToLower( *iter2 ) ];
        GetOpenArchives().erase( ToLower( *iter2 ) );
    }

    return VFS_TRUE;
}
        T const& operator*() const
        {
            if (IsInit())
            {
                return *((T*)(&m_data));
            }

            throw std::exception("");
        }
示例#10
0
void Player::CheckState()
{
    if( IsInit() )
    {
        FrameList& frm_lst = vl.GetFrames();
        ASSERT( frm_lst.IsPlayable() &&
                (frm_lst.Beg() <= curPos) && (curPos < frm_lst.End()) );
        UNUSED_VAR(frm_lst);
    }
}
示例#11
0
// Archive Management.
VFS_BOOL VFS_Archive_Delete( const VFS_String& strArchiveFileName )
{
    // Not initialized yet?
    if( !IsInit() )
    {
        SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
        return VFS_FALSE;
    }

    return VFS_File_Delete( strArchiveFileName + VFS_TEXT( "." ) + VFS_ARCHIVE_FILE_EXTENSION );
}
示例#12
0
// Determines if an Archive with the specified file name exists.
VFS_BOOL VFS_Archive_Exists( const VFS_String& strArchiveFileName )
{
    // Not initialized yet?
    if( !IsInit() )
    {
        SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
        return VFS_FALSE;
    }

    return CArchive::Exists( strArchiveFileName );
}
示例#13
0
// Close the File.
VFS_BOOL VFS_File_Close( VFS_Handle hFile )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_FALSE;
	}

	// Invalid Handle Value?
	if( hFile == VFS_INVALID_HANDLE_VALUE )
	{
		SetLastError( VFS_ERROR_INVALID_PARAMETER );
		return VFS_FALSE;
	}

	// Get the File Pointer.
	IFile* pFile = ( IFile* )( VFS_DWORD )hFile;

    // Invalid Handle Value?
	VFS_BOOL bFound = VFS_FALSE;
	for( FileMap::iterator iter = GetOpenFiles().begin(); iter != GetOpenFiles().end(); iter++ )
	{
		// Found?
		if( ( *iter ).second == pFile )
		{
			bFound = VFS_TRUE;
			break;
		}
	}
	if( !bFound )
	{
		SetLastError( VFS_ERROR_INVALID_PARAMETER );
		return VFS_FALSE;
	}

	// If the File will be deleted afterwards, remove the File from the
	// Open Files Map.
	if( pFile->GetRefCount() == 1 )
	{
		FileMap::iterator iter = GetOpenFiles().find( pFile->GetFileName() );
		if( iter == GetOpenFiles().end() )
		{
			SetLastError( VFS_ERROR_GENERIC );
			return VFS_FALSE;
		}
		GetOpenFiles().erase( iter );
	}

	// Release the File.
	pFile->Release();

	return VFS_TRUE;
}
示例#14
0
文件: anomaly.cpp 项目: blazs/qminer
int TNearestNeighbor::Predict(const TIntFltKdV& Vec) const {
    // if not initialized, do nothing
    if (!IsInit()) { return 0; }
    // get distance to nearest stored element
    const double Dist = DecisionFunction(Vec);
    // find in which rate bucket if falls (zero means none)
    int Rate = 0;
    while (Rate < RateV.Len() && Dist > ThresholdV[Rate]) { Rate++; }
    // we are done
    return Rate;
}
示例#15
0
PJsonVal TNearestNeighbor::Explain(const TIntFltKdV& Vec) const {
    // if not initialized, return null (JSON)
    if (!IsInit()) { return TJsonVal::NewNull(); }
    // find nearest neighbor
    double NearDist = TFlt::Mx; int NearColN = -1;
    for (int ColN = 0; ColN < Mat.Len(); ColN++) {
        const double Dist = TLinAlg::Norm2(Vec) - 2 * TLinAlg::DotProduct(Vec, Mat[ColN]) + TLinAlg::Norm2(Mat[ColN]);
        if (Dist < NearDist) { NearDist = Dist; NearColN = ColN; }
    }
    const TIntFltKdV& NearVec = Mat[NearColN];
    // generate JSon explanations
    PJsonVal ResVal = TJsonVal::NewObj();
    // id of the nearest element
    ResVal->AddToObj("nearestDat", DatV[NearColN]);
    ResVal->AddToObj("distance", NearDist);
    // element-wise difference
    PJsonVal DiffVal = TJsonVal::NewArr();
    int NearEltN = 0, EltN = 0;
    while (NearEltN < NearVec.Len() || EltN < Vec.Len()) {
        // get the feature ID
        const int VecFtrId = EltN < Vec.Len() ? Vec[EltN].Key.Val : TInt::Mx;
        const int NearFtrId = NearEltN < NearVec.Len() ? NearVec[NearEltN].Key.Val : TInt::Mx;
        const int FtrId = NearFtrId < VecFtrId ? NearFtrId : VecFtrId;
        // get values
        const double VecVal = FtrId < VecFtrId ? 0.0 : Vec[EltN].Dat.Val;
        const double NearVal = FtrId < NearFtrId ? 0.0 : NearVec[NearEltN].Dat.Val;
        // get diff
        const double Diff = TMath::Sqr(NearVal - VecVal) / NearDist;
        // add to json result
        PJsonVal FtrVal = TJsonVal::NewObj();
        //avoid unnecessary fields in the explanation
        if (Diff > 1e-8) {
            FtrVal->AddToObj("id", FtrId);
            FtrVal->AddToObj("val", VecVal);
            FtrVal->AddToObj("nearVal", NearVal);
            FtrVal->AddToObj("contribution", Diff);
            DiffVal->AddToArr(FtrVal);
        }
        // move to the next feature
        if (VecFtrId <= NearFtrId) {
            EltN++;
        }
        if (NearFtrId <= VecFtrId) {
            NearEltN++;
        }
    }
    ResVal->AddToObj("features", DiffVal);
    // first and last record in the buffer
    ResVal->AddToObj("oldestDat", DatV[NextCol]);
    int CurCol = NextCol > 0 ? NextCol - 1 : WindowSize - 1;
    ResVal->AddToObj("newestDat", DatV[CurCol]);
    return ResVal;
}
示例#16
0
//_____________________________________________________________________________
void THaDetector::SetApparatus( THaApparatus* apparatus )
{
  // Associate this detector with the given apparatus.
  // Only possible before initialization.

  if( IsInit() ) {
    Warning( Here("SetApparatus()"), "Cannot set apparatus. "
	     "Object already initialized.");
    return;
  }
  fApparatus = apparatus;
}
示例#17
0
void FwdPlayer::PlayCurFrame()
{
    ASSERT( IsInit() && lftBasePos <= curPos && curPos <= rgtBasePos );
    if( IsBoundFrame(curPos) )
        ; // уже готово
    else
    {
        FrameData& fram = *curPos;
        ASSERT( fram.typ == ptB_FRAME );

        prsCont.m2d.ReadFrame(fram, prsCont.dmx.ObjStrm());
    }
}
示例#18
0
Player::PlanesType FwdPlayer::Data() const
{
    ASSERT( IsInit() );
    FrameDecType fdt = fdtCURRENT;
    if( curPos == rgtBasePos )
        fdt = fdtRIGHT;
    else if( curPos == lftBasePos )
    {
        // см. PlayBaseFrames()
        ASSERT( lftBasePos != rgtBasePos );
        fdt = fdtLEFT;
    }

    return prsCont.m2d.FrameData(fdt);
}
示例#19
0
文件: cvgabor.cpp 项目: ToMadoRe/v4r
/**
 * @brief CvGabor::show(int Type)
 */
void CvGabor::show(int Type)
{
    if(!IsInit()) {
        perror("Error: the gabor kernel has not been created!\n");
    }
    else {
      //    IplImage *pImage;
      //pImage = get_image(Type);
      //cvNamedWindow("Testing",1);
      //cvShowImage("Testing",pImage);
      //cvWaitKey(0);
      //cvDestroyWindow("Testing");
      //cvReleaseImage(&pImage);
    }
}
示例#20
0
//---------------------------------------------------------------------
void BaseTween::Update(float _dt)
{
	if(!IsStarted() || IsPaused() || IsKilled())
    {
		return;
    }

	m_dt = _dt;

	if(!IsInit())
    {
		Initialize();
    }

	if(IsInit())
	{
		UpdateRelaunch();
		UpdateStep();
		UpdateCompletion();
	}

	m_currentTime += m_dt;
	m_dt = 0.0f;
}
示例#21
0
//*****************************************************************************
//	LOAD에서 부른 data들을 파괴시킨다.
//
//	Paremeters
//		void
//	Return Values
//		void
//	Remark
//*****************************************************************************
HRESULT	CNSlangTextFilter::Destroy()
{
	if (!IsInit())
		return false;

	m_xInit = false;
	for (int n = 0; n < m_nSlangNumber; n++)
	{
		SAFE_DELETE(m_szaSlangTarget[n]);
		SAFE_DELETE(m_szaSlangReplace[n]);
	}
	SAFE_DELETE_ARRAY(m_szaSlangTarget);
	SAFE_DELETE_ARRAY(m_szaSlangReplace);
	return true;
}
示例#22
0
// Rename the specified File.
VFS_BOOL VFS_File_Rename( const VFS_String& strFrom, const VFS_String& strTo )				// pszTo has to be a single File Name without a Path.
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_FALSE;
	}

	// Try to open the file to get the absolute file name and to see if the file is still open
	// and if it's not in an Archive (VFS_WRITE would fail otherwise).
	VFS_Handle hFile = VFS_File_Open( strFrom, VFS_READ | VFS_WRITE );
	if( hFile == VFS_INVALID_HANDLE_VALUE )
		return VFS_FALSE;

	// Get the File Pointer.
	IFile* pFile = ( IFile* )( VFS_DWORD )hFile;

	// Check if there are still references to the File (but count ourself).
	if( pFile->GetRefCount() > 1 )
	{
		// Close the File.
		VFS_File_Close( hFile );

        SetLastError( VFS_ERROR_IN_USE );
		return VFS_FALSE;
	}

	// Get the absolute File Name.
	VFS_String strAbsoluteFileName = pFile->GetFileName();

	// Close the File.
	VFS_File_Close( hFile );

	// Make the Target Name absolute.
	VFS_String strAbsoluteTo;
	VFS_Util_GetPath( strAbsoluteFileName, strAbsoluteTo );
	strAbsoluteTo = WithoutTrailingSeparator( strAbsoluteTo, VFS_TRUE ) + VFS_PATH_SEPARATOR + strTo;

	// Try to rename the File.
	if( !VFS_RENAME( strAbsoluteFileName, strAbsoluteTo ) )
	{
		SetLastError( VFS_ERROR_PERMISSION_DENIED );
		return VFS_FALSE;
	}

	return VFS_TRUE;
}
示例#23
0
// Move the specified File.
VFS_BOOL VFS_File_Move( const VFS_String& strFrom, const VFS_String& strTo )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_FALSE;
	}

	// Try to copy the file.
	if( !VFS_File_Copy( strFrom, strTo ) )
		return VFS_FALSE;

	// Try to delete the Source File.
	return VFS_File_Delete( strFrom );
}
示例#24
0
/*!
    \fn CvGabor::creat_kernel()
Create gabor kernel

Parameters:
        None

Returns:
        None

Create 2 gabor kernels - REAL and IMAG, with an orientation and a scale
 */
void CvGabor::creat_kernel()
{
   
    if (IsInit() == false) {perror("Error: The Object has not been initilised in creat_kernel()!\n");}
    else {
      CvMat *mReal, *mImag;
      mReal = cvCreateMat( Width, Width, CV_32FC1);
      mImag = cvCreateMat( Width, Width, CV_32FC1);
     
      /**************************** Gabor Function ****************************/
      int x, y;
      double dReal;
      double dImag;
      double dTemp1, dTemp2, dTemp3;

      for (int i = 0; i < Width; i++)
      {
          for (int j = 0; j < Width; j++)
          {
              x = i-(Width-1)/2;          // (width-1)/2 = anchor
              y = j-(Width-1)/2;
              dTemp1 = (pow(K,2)/pow(Sigma,2))*exp(-(pow((double)x,2)+pow((double)y,2))*pow(K,2)/(2*pow(Sigma,2)));

              dTemp2 = cos(K*cos(Phi)*x + K*sin(Phi)*y) - exp(-(pow(Sigma,2)/2));
              dTemp3 = sin(K*cos(Phi)*x + K*sin(Phi)*y);
              dReal = dTemp1*dTemp2;
              dImag = dTemp1*dTemp3;
              //gan_mat_set_el(pmReal, i, j, dReal);
              //cvmSet( (CvMat*)mReal, i, j, dReal );
                cvSetReal2D((CvMat*)mReal, i, j, dReal );
              //gan_mat_set_el(pmImag, i, j, dImag);
              //cvmSet( (CvMat*)mImag, i, j, dImag );
                cvSetReal2D((CvMat*)mImag, i, j, dImag );

          }
       }
       /**************************** Gabor Function ****************************/
       bKernel = true;
       cvCopy(mReal, Real, NULL);
       cvCopy(mImag, Imag, NULL);
      //printf("A %d x %d Gabor kernel with %f PI in arc is created.\n", Width, Width, Phi/PI);
       cvReleaseMat( &mReal );
       cvReleaseMat( &mImag );
     }
}
示例#25
0
文件: anomaly.cpp 项目: blazs/qminer
PJsonVal TNearestNeighbor::Explain(const TIntFltKdV& Vec) const {
	// if not initialized, return null (JSON)
	if (!IsInit()) { return TJsonVal::NewNull(); }
	// find nearest neighbor
	double NearDist = TFlt::Mx;
	int NearColN = -1;
	TIntFltKdV DiffV;
	for (int ColN = 0; ColN < Mat.Len(); ColN++) {		
		const double Dist = TLinAlg::Norm2(Vec) - 2 * TLinAlg::DotProduct(Vec, Mat[ColN]) + TLinAlg::Norm2(Mat[ColN]);
		if (Dist < NearDist) { NearDist = Dist; NearColN = ColN; }
	}
    const TIntFltKdV& NearVec = Mat[NearColN];
	// generate JSon explanations
	PJsonVal ResVal = TJsonVal::NewObj();
    // id of the nearest element
	ResVal->AddToObj("nearestID", IDVec[NearColN]);
	ResVal->AddToObj("distance", NearDist);
    // element-wise difference
    PJsonVal DiffVal = TJsonVal::NewArr();
    int NearEltN = 0, EltN = 0;
    while (NearEltN < NearVec.Len() && EltN < Vec.Len()) {
        // get values
        const int FtrId =      (NearVec[NearEltN].Key < Vec[EltN].Key) ? NearVec[NearEltN].Key     : Vec[EltN].Key;
        const double Val =     (NearVec[NearEltN].Key >= Vec[EltN].Key) ? Vec[EltN].Dat.Val : 0.0;
        const double NearVal = (NearVec[NearEltN].Key <= Vec[EltN].Key) ? NearVec[NearEltN].Dat.Val : 0.0;
        const double Diff    = TMath::Sqr(NearVal - Val) / NearDist;
        // add to json result
        PJsonVal FtrVal = TJsonVal::NewObj();
        FtrVal->AddToObj("id", FtrId);
        FtrVal->AddToObj("val", Val);
        FtrVal->AddToObj("nearVal", NearVal);
        FtrVal->AddToObj("contribution", Diff);
        DiffVal->AddToArr(FtrVal);
        // move to the next feature
        if (NearVec[NearEltN].Key > Vec[EltN].Key) {
            EltN++;
        } else if (NearVec[NearEltN].Key < Vec[EltN].Key) {
            NearEltN++;
        } else {
            NearEltN++; EltN++;
        }
    }
    ResVal->AddToObj("features", DiffVal);
	return ResVal;
}
示例#26
0
文件: cvgabor.cpp 项目: ToMadoRe/v4r
/**
 * @brief Return the width of mask (should be NxN) by the value of Sigma and iNu.
 * @return The long type show the width.
 */
long CvGabor::mask_width()  
{
    long lWidth;
    if (IsInit() == false)  {
       perror ("Error: The Object has not been initilised in mask_width()!\n");
       return 0;
    }
    else {
       //determine the width of Mask
      double dModSigma = Sigma/K;
      double dWidth = (int)(dModSigma*6 + 1);
      //test whether dWidth is an odd.
      if (fmod(dWidth, 2.0)==0.0) dWidth++;
      lWidth = (long)dWidth;
      //printf("[CvGabor::mask_width] Gabor mask with: %lu\n", lWidth);
      return lWidth;
    }
}
示例#27
0
// Try to open a File with the specified Path (this function is way to big, hmm).
VFS_Handle VFS_File_Open( const VFS_String& strFileName, VFS_DWORD dwFlags )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_INVALID_HANDLE_VALUE;
	}

	// No Root Paths specified yet?
	if( GetRootPaths().size() == 0 && !VFS_Util_IsAbsoluteFileName( strFileName ) )
	{
		SetLastError( VFS_ERROR_NO_ROOT_PATHS_DEFINED );
		return VFS_INVALID_HANDLE_VALUE;
	}

	// Try to open the File.
	return TryToOpen( strFileName, dwFlags );
}
示例#28
0
// Delete the File with the specified File Name.
VFS_BOOL VFS_File_Delete( const VFS_String& strFileName )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_FALSE;
	}

	// Try to open the file to get the absolute file name and to see if the file is still open
	// and if it's not in an Archive (VFS_WRITE would fail otherwise).
	VFS_Handle hFile = VFS_File_Open( strFileName, VFS_READ | VFS_WRITE );
	if( hFile == VFS_INVALID_HANDLE_VALUE )
		return VFS_FALSE;

	// Get the File Pointer.
	IFile* pFile = ( IFile* )( VFS_DWORD )hFile;

	// Check if there are still references to the File (but count ourself).
	if( pFile->GetRefCount() > 1 )
	{
		// Close the File.
		VFS_File_Close( hFile );

        SetLastError( VFS_ERROR_IN_USE );
		return VFS_FALSE;
	}

	// Get the absolute File Name.
	VFS_String strAbsoluteFileName = pFile->GetFileName();

	// Close the File.
	VFS_File_Close( hFile );

	// Try to delete the File.
	if( !VFS_UNLINK( strAbsoluteFileName ) )
	{
		SetLastError( VFS_ERROR_PERMISSION_DENIED );
		return VFS_FALSE;
	}

	return VFS_TRUE;
}
示例#29
0
//*****************************************************************************
//	소스에서 치환할 대상을 찾아낸다.
//
//	Paremeters
//		int *nLength		: 치환 대상의 길이를 받을 포인터
//		const char *szSrc	: 치환 대상을 찾을 문자열
//	Return Values
//		char*				: 치환 대상의 위치
//	Remark
//		치환 대상이 없으면 nLength에는 0이 들어가고 NULL이 반환된다.
//*****************************************************************************
char*	CNSlangTextFilter::GetReplaceTarget(int *nLength, char *szSrc)
{
	if (!IsInit())
		return NULL;

	char *l_szStr = (char*) malloc(strlen(szSrc) + 1);
	Trim(l_szStr, szSrc);
	for (int n = 0; n < m_nSlangNumber; n++)
	{
		if (FindString(l_szStr, m_szaSlangTarget[n]))
		{
			int l_nTargetPos = FindString(l_szStr, m_szaSlangTarget[n]) - l_szStr;
			int l_nOffsetSpaceNumber = 0, l_nTargetSpaceNumber = 0;
			int i;int l_nOffset;
			for (int i = 0, l_nOffset = 0; ; i++)
			{
				if (szSrc[i] == ' ' || szSrc[i] == '\t' || szSrc[i] == '\n')
					l_nOffsetSpaceNumber++;
				else
				{
					if (l_nOffset >= l_nTargetPos)
						break;
					l_nOffset++;
				}
			}

			for (l_nOffset = 0; l_nOffset < strlen(m_szaSlangTarget[n]); i++)
			{
				if (szSrc[i] == ' ' || szSrc[i] == '\t' || szSrc[i] == '\n')
					l_nTargetSpaceNumber++;
				else
					l_nOffset++;
			}
			free(l_szStr);
			if (nLength != NULL)
				*nLength = strlen(m_szaSlangTarget[n]) + l_nTargetSpaceNumber;
			return (szSrc + l_nTargetPos + l_nOffsetSpaceNumber);
		}
	}
	free(l_szStr);
	return NULL;
}
示例#30
0
//*****************************************************************************
//	특정 문자열을 무엇으로 치환해야 하는지 찾아낸다.
//
//	Paremeters
//		char *szDest		: 치환한 뒤의 문자열을 저장할 포인터
//		const char *szSrc	: 치환할 문자열
//		int nMaxLength		: szDest 버퍼의 최대 크기
//	Return Values
//		void				:
//	Remark
//		치환한 문자열이 없으면 ""이 들어간다.
//*****************************************************************************
void	CNSlangTextFilter::ReplaceWord(char *szDest, const char *szSrc, int nMaxLength)
{
	if (!IsInit())
		return;

	char *l_szStr = (char*) malloc(strlen(szSrc) + 1);
	Trim(l_szStr, szSrc);

	for (int n = 0; n < m_nSlangNumber; n++)
	{
		if (strcmp(l_szStr, m_szaSlangTarget[n]) == 0)
		{
			GetStringPart(szDest, m_szaSlangReplace[n], nMaxLength);
			free(l_szStr);
			return;
		}
	}
	strcpy(szDest, "");
	free(l_szStr);
}