#ifdef GTP_INTERNAL //#define USE_QT 0 #endif #define USE_BOOST 1 #ifdef UNICODE #undef UNICODE #endif #include #include #include #include "SamplingPreprocessor.h" #include "VssPreprocessor.h" #include "RssPreprocessor.h" #include "ExactPreprocessor.h" #include "Parser.h" #include "UnigraphicsParser.h" #include "X3dParser.h" #include "Environment.h" #include "Camera.h" #include "MeshKdTree.h" #include "Exporter.h" #include "ViewCell.h" #include "SceneGraph.h" #if USE_BOOST #include "BoostPreprocessorThread.h" #endif #include "RenderSampler.h" #include "ResourceManager.h" #include "GlRenderer.h" #if USE_QT #include "QtRenderer/QtGlRenderer.h" #endif #define USE_EXE_PATH false using namespace GtpVisibilityPreprocessor; Preprocessor *preprocessor = NULL; GlRendererWidget *rendererWidget = NULL; // DLL function signature typedef GlRendererWidget *(*importFunction)(Preprocessor *); int LoadMyDll() { importFunction LoadRenderWidget; // Load DLL file HINSTANCE hinstLib = LoadLibrary("../QtGlRenderer/Release/QtGlRenderer.dll"); if (hinstLib == NULL) { cout << "ERROR: unable to load DLL\n"; return 1; } // Get function pointer LoadRenderWidget = (importFunction)GetProcAddress(hinstLib, "LoadRenderWidget"); if (LoadRenderWidget == NULL) { cout << "ERROR: unable to find DLL function\n"; return 1; } cout << "loading widget ... "; // load the render window rendererWidget = LoadRenderWidget(preprocessor); cout << "finished" << endl; // Unload DLL file //FreeLibrary(hinstLib); return 0; } void Cleanup() { DEL_PTR(rendererWidget); DEL_PTR(preprocessor); Environment::DelSingleton(); MeshManager::DelSingleton(); MaterialManager::DelSingleton(); } void DisplayWidget() { if (!rendererWidget) { LoadMyDll(); } //rendererWidget->Show(); } string ReplaceSuffix(string filename, string a, string b) { string result = filename; int pos = filename.rfind(a, filename.size()-1); if (pos == filename.size() - a.size()) { result.replace(pos, a.size(), b); } return result; } int main(int argc, char **argv) { //Now just call this function at the start of your program and if you're //compiling in debug mode (F5), any leaks will be displayed in the Output //window when the program shuts down. If you're not in debug mode this will //be ignored. Use it as you will! //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { #if 0 _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); #endif int returnCode = 0; InitTiming(); Debug.open("debug.log"); Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH); MeshKdTree::ParseEnvironment(); char buff[128]; Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff); string preprocessorType(buff); if (preprocessorType == "vss") { preprocessor = new VssPreprocessor(); } else { if (preprocessorType == "rss") { preprocessor = new RssPreprocessor(); } else { if (preprocessorType == "exact") { preprocessor = new ExactPreprocessor(); } else { if (preprocessorType == "sampling") { preprocessor = new SamplingPreprocessor(); } else { if (preprocessorType == "render") { preprocessor = new RenderSampler(); } else { Environment::DelSingleton(); cerr<<"Unknown preprocessor type"<GetStringValue("Scene.filename", buff); string filename(buff); preprocessor->LoadScene(filename); string rayCastFile = ReplaceSuffix(filename, ".obj", ".kdf"); //-- initialize external ray casters if (preprocessor->InitRayCast(rayCastFile)) { cout << "ray casting initialized!" << endl; } else { cout << "ray casting initialization failed" << endl; exit(1); } //-- build kd tree from scene geometry preprocessor->BuildKdTree(); preprocessor->KdTreeStatistics(cout); /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz"); MeshManager::GetSingleton()->ExportEntries("meshes.bin"); KdTree *kdTree2 = new KdTree; cout << "loading kd tree ... "; long startTime = GetTime(); kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects); cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; Exporter *exporter = Exporter::GetExporter("testkd.x3d"); MeshManager::GetSingleton()->ExportEntries("meshes.bin"); if (exporter) { exporter->SetWireframe(); exporter->ExportKdTree(*kdTree2, true); delete exporter; } DEL_PTR(kdTree2); */ // parse view cells related options preprocessor->PrepareViewCells(); if (0) { preprocessor->Export(filename + "-out.x3d", true, false, false); preprocessor->Export(filename + "-kdtree.x3d", false, true, false); } // create a preprocessor thread (note: capsulates calls to boost fuctions!) //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor); #if USE_BOOST BoostPreprocessorThread pt(preprocessor); #endif bool guiSupported = false; if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger) { cout << "using gl widget" << endl; // create and run the preprocessor application in a parallel thread #if USE_BOOST pt.InitThread(); #endif //pt.RunThread(); // display the render widget if (!rendererWidget) { #if !USE_QT guiSupported = LoadMyDll(); #else rendererWidget = new QtGlRendererWidget(preprocessor->mSceneGraph, preprocessor->mViewCellsManager, preprocessor->mKdTree); #endif } } if (!guiSupported) { preprocessor->mUseGlRenderer = false; preprocessor->mUseGlDebugger = false; } if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) { // just call the mail method -> will be executed in the main thread #if USE_BOOST pt.Main(); #endif } Cleanup(); return returnCode; }