int SaveArrayCSV(const char* chrFilePath, float* lpArray, U32 count) { DAnsiStr strLine; for(U32 i=0; i<count; i++) { if(i < count - 1) strLine += printToAStr("%f, ", lpArray[i]); else strLine += printToAStr("%f", lpArray[i]); } WriteTextFile(DAnsiStr(chrFilePath), strLine); return count; }
void IAvatar::mousePress(int button, int state, int x, int y) { if (button == ArcBallCamera::mbRight) { LogInfo("Right clicked cleared cut context!"); clearCutContext(); return; } if (button != ArcBallCamera::mbLeft) return; //Down = Start if (state == 0) { if (m_lpTissue) { m_isToolActive = true; TheSceneGraph::Instance().headers()->updateHeaderLine("scalpel", "scalpel: start cutting"); } } else { //Up = Stop if (m_lpTissue) { m_isToolActive = false; //count disjoint parts vector<vector<U32> > parts; U32 ctParts = m_lpTissue->get_disjoint_parts(parts); AnsiStr strMsg = printToAStr("scalpel: finished cut %u. disjoint parts#%u", (U32)m_lpTissue->countCompletedCuts(), ctParts); TheSceneGraph::Instance().headers()->updateHeaderLine("scalpel", strMsg); } } }
int SaveArrayCSV(const char* lpArrayName, float* lpArray, U32 count) { DAnsiStr strPath = ExtractFilePath(GetExePath()); DAnsiStr strFP = printToAStr("%s/%s", strPath.ptr(), lpArrayName); DAnsiStr strLine; for(int i=0; i<count; i++) { if(i < count - 1) strLine += printToAStr("%f, ", lpArray[i]); else strLine += printToAStr("%f", lpArray[i]); } WriteTextFile(strFP, strLine); return count; }
void EventLogger::add(const char* lpStrDesc, EVENTTYPE t, const char* lpStrSource, int value) { if(lpStrDesc == NULL) return; DAnsiStr strEvent; //Write Event Type if(m_bWriteEventTypes) { if(t == etInfo) strEvent += printToAStr("INFO: "); else if(t == etWarning) strEvent += printToAStr("WARNING: "); else if(t == etError) strEvent += printToAStr("ERROR: "); } //Write Event Time if(m_bWriteTimeStamps) { time_t rawtime; time (&rawtime); #ifdef PS_SECURE_API char buffer[64]; struct tm timeinfo; localtime_s(&timeinfo, &rawtime); asctime_s(timeinfo, buffer, 64) strEvent += printToAStr("TIME: [%s], ", buffer); #else struct tm * timeinfo = localtime ( &rawtime ); DAnsiStr strTime = DAnsiStr(asctime(timeinfo)); strTime.trim(); strEvent += printToAStr("TIME: [%s], ", strTime.cptr()); #endif } //Write Source + Value if(m_bWriteSourceInfo && lpStrSource) { strEvent += printToAStr("SOURCE: [%s, LINE:%d], ", lpStrSource, value); } //Write Event itself strEvent += DAnsiStr(lpStrDesc); m_lstLog.push_back(strEvent); //Write Message to screen if(m_bWriteToScreen) display(strEvent.cptr()); //Update Buffer size and Flush if ready m_szBufferSize += strEvent.length(); if(m_szBufferSize > PS_LOG_BUFFER_SIZE) flush(); }
void IAvatar::onStop() { if (m_lpTissue) { m_isToolActive = false; //count disjoint parts vector<vector<U32> > parts; U32 ctParts = m_lpTissue->get_disjoint_parts(parts); AnsiStr strMsg = printToAStr("scalpel: finished cut %u. disjoint parts#%u", (U32)m_lpTissue->countCompletedCuts(), ctParts); vloginfo("Finished cutting"); TheEngine::Instance().headers()->updateHeaderLine("scalpel", strMsg); } }
//================================================================== void GetExePathPlatform(char *exePath, int szBuffer) { #ifdef PS_OS_MAC uint32_t szExePath = szBuffer; if(_NSGetExecutablePath(exePath, &szExePath) == 0) exePath[szBuffer] = 0; else { exePath[0] = 0; printf("Not enough memory to get exepath. Needs %d\n", szBuffer); } /* AnsiStr strInput(exePath, ) int index = result.lastIndexOf(QString(".app")); if(index < 0) index = result.length(); else result = result.left(index); index = result.lastIndexOf(QString("/")); if(index < 0) { index = result.lastIndexOf(QString("\\")); if(index < 0) index = result.length(); } result = result.left(index + 1); */ #elif defined(PS_OS_WINDOWS) WCHAR wszExeName[MAX_PATH + 1]; wszExeName[MAX_PATH] = 0; GetModuleFileNameW(NULL, wszExeName, sizeof(wszExeName) - 1); WideCharToMultiByte(CP_ACP, 0, wszExeName, -1, (LPSTR)exePath, szBuffer, NULL, NULL); #elif defined(PS_OS_LINUX) //getcwd only retrieves the current working directory //getcwd(exePath, (int)szBuffer); pid_t pid = getpid(); AnsiStr strProcessPath = printToAStr("/proc/%d/exe", pid); int nCharsWritten = readlink(strProcessPath.ptr(), exePath, szBuffer); if(nCharsWritten != -1) { exePath[nCharsWritten] = 0; } #endif }
//================================================================== int ListFilesInDir(std::vector<AnsiStr>& lstFiles, const char* pDir, const char* pExtensions, bool storeWithPath) { AnsiStr strDir; AnsiStr strResolvedDir; lstFiles.resize(0); if(pDir == NULL) strResolvedDir = ps::dir::ExtractFilePath(ps::dir::GetExePath()); else strResolvedDir = AnsiStr(pDir); if(pExtensions != NULL) strDir = printToAStr("%s/*.%s", strResolvedDir.ptr(), pExtensions); else strDir = printToAStr("%s/*.*", strResolvedDir.ptr()); #ifdef PS_OS_WINDOWS WIN32_FIND_DATA ffd; HANDLE hFind = INVALID_HANDLE_VALUE; DWideStr wstrDir = toWideString(strDir); hFind = FindFirstFile(wstrDir.ptr(), &ffd); if(hFind == INVALID_HANDLE_VALUE) return 0; AnsiStr temp; do { if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (storeWithPath) { temp = strResolvedDir + "\\"; temp += AnsiStr(ffd.cFileName); lstFiles.push_back(temp); } else { temp = AnsiStr(ffd.cFileName); lstFiles.push_back(temp); } } }while (FindNextFile(hFind, &ffd) != 0); FindClose(hFind); #else DIR* dirFile = opendir( strResolvedDir.cptr() ); if ( dirFile ) { struct dirent* hFile; string strExt = "." + string(pExtensions); while (( hFile = readdir( dirFile )) != NULL ) { if ( !strcmp( hFile->d_name, "." )) continue; if ( !strcmp( hFile->d_name, ".." )) continue; // in linux hidden files all start with '.' if (hFile->d_name[0] == '.' ) continue; // dirFile.name is the name of the file. Do whatever string comparison // you want here. Something like: if ( strstr( hFile->d_name, strExt.c_str())) { if(storeWithPath) lstFiles.push_back(strResolvedDir + "//" + AnsiStr(hFile->d_name)); else lstFiles.push_back(AnsiStr(hFile->d_name)); printf("Found file %s", hFile->d_name); } } closedir( dirFile ); } #endif return (int)lstFiles.size(); }