string CCompiler::createCompilerCommand(const string& sourceFileName) { stringstream exeCmd; if(getFileNameNoExtension(mCompilerName) == "tcc" || getFileNameNoExtension(mCompilerName) == "gcc" || getFileNameNoExtension(mCompilerName) == "cc") { // standard unix compiler options exeCmd<<joinPath(mCompilerLocation, mCompilerName); //Add compiler flags for(int i = 0; i < mCompilerFlags.size(); i++) { exeCmd<<" "<<mCompilerFlags[i]; } exeCmd<<" \""<<sourceFileName<<"\" \""<<joinPath(mSupportCodeFolder, "rrSupport.c")<<"\""; exeCmd<<" -o \""<<mDLLFileName<<"\""; #if defined(WIN32) exeCmd<<" -DBUILD_MODEL_DLL "; #endif //Add include paths for(int i = 0; i < mIncludePaths.size(); i++) { exeCmd<<" -I\""<<mIncludePaths[i]<<"\" " ; } //Add library paths for(int i = 0; i < mLibraryPaths.size(); i++) { exeCmd<<" -L\""<<mLibraryPaths[i]<<"\" " ; } } return exeCmd.str(); }
bool CCompiler::compile(const string& cmdLine) { if( !cmdLine.size() ) { return false; } PROCESS_INFORMATION pi; ZeroMemory( &pi, sizeof(pi) ); STARTUPINFO si; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); //sec attributes for the output file SECURITY_ATTRIBUTES sao; sao.nLength=sizeof(SECURITY_ATTRIBUTES); sao.lpSecurityDescriptor=NULL; sao.bInheritHandle=1; string compilerTempFile(joinPath(mOutputPath, getFileNameNoExtension(mDLLFileName))); compilerTempFile.append("C.log"); Poco::File aFile(compilerTempFile); if(aFile.exists()) { aFile.remove(); } HANDLE outFile; //Todo: there is a problem creating the logfile after first time creation.. if((outFile=CreateFileA(compilerTempFile.c_str(), GENERIC_WRITE, FILE_SHARE_DELETE, &sao, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL))==INVALID_HANDLE_VALUE) { // Retrieve the system error message for the last-error code DWORD errorCode = GetLastError(); string anError = getWINAPIError(errorCode, TEXT("CreateFile")); Log(Logger::LOG_ERROR)<<"WIN API Error (after CreateFile): "<<anError; Log(Logger::LOG_ERROR)<<"Failed creating logFile for compiler output"; } SetFilePointer(outFile, 0, NULL, FILE_END); //set pointer position to end file //init the STARTUPINFO struct si.dwFlags=STARTF_USESTDHANDLES; si.hStdOutput = outFile; si.hStdError = outFile; //proc sec attributes SECURITY_ATTRIBUTES sap; sap.nLength=sizeof(SECURITY_ATTRIBUTES); sap.lpSecurityDescriptor=NULL; sap.bInheritHandle=1; //thread sec attributes SECURITY_ATTRIBUTES sat; sat.nLength=sizeof(SECURITY_ATTRIBUTES); sat.lpSecurityDescriptor=NULL; sat.bInheritHandle=1; // Start the child process. if( !CreateProcessA( NULL, // No module name (use command line) (char*) cmdLine.c_str(), // Command line &sap, // Process handle not inheritable &sat, // Thread handle not inheritable TRUE, // Set handle inheritance CREATE_NO_WINDOW, // Creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure ) { DWORD errorCode = GetLastError(); string anError = getWINAPIError(errorCode, TEXT("CreateProcess")); Log(Logger::LOG_ERROR)<<"WIN API Error: (after CreateProcess) "<<anError; // Close process and thread handles. CloseHandle(pi.hProcess); CloseHandle(pi.hThread); CloseHandle(outFile); return false; } // Wait until child process exits. WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(outFile); // Close process and thread handles. CloseHandle(pi.hProcess); DWORD errorCode = GetLastError(); if(errorCode != 0) { string anError = getWINAPIError(errorCode, TEXT("CloseHandle")); Log(lDebug)<<"WIN API error: (pi.hProcess)"<<anError; } CloseHandle(pi.hThread); errorCode = GetLastError(); if(errorCode != 0) { string anError = getWINAPIError(errorCode, TEXT("CloseHandle")); Log(lDebug)<<"WIN API error: (pi.hThread)"<<anError; } //Read the log file and log it if(fileExists(compilerTempFile)) { string log = getFileContent(compilerTempFile.c_str()); Log(lDebug)<<"Compiler output: "<<log<<endl; } return true; }
std::string ImageDirectoryReader::getFrameName() { return getFileNameNoExtension(mFilePaths.at(mFrameNameCounter)); }
bool CCompiler::setupCompilerEnvironment() { mIncludePaths.clear(); mLibraryPaths.clear(); mCompilerFlags.clear(); if(getFileNameNoExtension(mCompilerName) == "tcc" || getFileNameNoExtension(mCompilerName) == "gcc") { mCompilerFlags.push_back("-g"); //-g adds runtime debug information #if defined(__unix__) || defined(_WIN32) mCompilerFlags.push_back("-shared"); mCompilerFlags.push_back("-rdynamic"); //-rdynamic : Export global symbols to the dynamic linker #elif defined(__APPLE__) mCompilerFlags.push_back("-dynamiclib"); #endif //-b : Generate additional support code to check memory allocations and array/pointer bounds. `-g' is implied. mCompilerFlags.push_back("-fPIC"); // shared lib mCompilerFlags.push_back("-O0"); // turn off optimization //LogLevel //-v is for verbose if(getFileNameNoExtension(mCompilerName) == "tcc") { mIncludePaths.push_back("."); mIncludePaths.push_back("r:/rrl/source"); mIncludePaths.push_back(joinPath(mCompilerLocation, "include")); mLibraryPaths.push_back("."); mLibraryPaths.push_back(joinPath(mCompilerLocation, "lib")); if(gLog.getLevel() < lDebug) { mCompilerFlags.push_back("-v"); // suppress warnings } else if(gLog.getLevel() >= lDebug1) { mCompilerFlags.push_back("-vv"); } else if(gLog.getLevel() >= lDebug2) { mCompilerFlags.push_back("-vvv"); } } else if(getFileNameNoExtension(mCompilerName) == "gcc") { if(gLog.getLevel() < lDebug) { mCompilerFlags.push_back("-w"); // suppress warnings } else if(gLog.getLevel() >= lDebug1) { mCompilerFlags.push_back("-Wall"); } else if(gLog.getLevel() >= lDebug2) { mCompilerFlags.push_back("-Wall -pedantic"); } } } mIncludePaths.push_back(mSupportCodeFolder); return true; }
void CameraParameterReader::readParameters(const std::string& cameraParameterPath, const std::vector<std::string>& serialNumbers) { try { // Serial numbers if (serialNumbers.empty()) { mSerialNumbers = getFilesOnDirectory(cameraParameterPath, "xml"); for (auto& serialNumber : mSerialNumbers) serialNumber = getFileNameNoExtension(serialNumber); } else mSerialNumbers = serialNumbers; // Commong saving/loading const auto dataFormat = DataFormat::Xml; const std::vector<std::string> cvMatNames { "CameraMatrix", "Intrinsics", "Distortion" }; // Load parameters mCameraMatrices.clear(); mCameraExtrinsics.clear(); mCameraIntrinsics.clear(); mCameraDistortions.clear(); // log("Camera matrices:"); for (auto i = 0ull ; i < mSerialNumbers.size() ; i++) { const auto parameterPath = cameraParameterPath + mSerialNumbers.at(i); const auto cameraParameters = loadData(cvMatNames, parameterPath, dataFormat); // Error if empty element if (cameraParameters.empty() || cameraParameters.at(0).empty() || cameraParameters.at(1).empty() || cameraParameters.at(2).empty()) { const std::string errorMessage = " of the camera with serial number `" + mSerialNumbers[i] + "` (file: " + parameterPath + "." + dataFormatToString(dataFormat) + "). Is its format valid? You might want to check the example xml" + " file."; if (cameraParameters.empty()) error("Error at reading the camera parameters" + errorMessage, __LINE__, __FUNCTION__, __FILE__); if (cameraParameters.at(0).empty()) error("Error at reading the camera matrix parameters" + errorMessage, __LINE__, __FUNCTION__, __FILE__); if (cameraParameters.at(1).empty()) error("Error at reading the camera intrinsics parameters" + errorMessage, __LINE__, __FUNCTION__, __FILE__); if (cameraParameters.at(2).empty()) error("Error at reading the camera distortion parameters" + errorMessage, __LINE__, __FUNCTION__, __FILE__); } mCameraExtrinsics.emplace_back(cameraParameters.at(0)); mCameraIntrinsics.emplace_back(cameraParameters.at(1)); mCameraDistortions.emplace_back(cameraParameters.at(2)); mCameraMatrices.emplace_back(mCameraIntrinsics.back() * mCameraExtrinsics.back()); // log(cameraParameters.at(0)); } // // mCameraMatrices // log("\nFull camera matrices:"); // for (const auto& cvMat : mCameraMatrices) // log(cvMat); // // mCameraIntrinsics // log("\nCamera intrinsic parameters:"); // for (const auto& cvMat : mCameraIntrinsics) // log(cvMat); // // mCameraDistortions // log("\nCamera distortion parameters:"); // for (const auto& cvMat : mCameraDistortions) // log(cvMat); } catch (const std::exception& e) { error(e.what(), __LINE__, __FUNCTION__, __FILE__); } }