void OrganSegmentationController::postRender3D() { if( mOverlay ) { render3D(); } }
void CTextContextUser::render3D(const CMatrix &mat, const char *format, ...) { NL3D_HAUTO_RENDER_3D_TEXTCONTEXT; char *str; NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize); render3D(mat, ucstring(str)); _DriverUser->restoreMatrixContext(); }
void cCore::render(cApplication* application) { { PROFILE(_T("render 3D")); render3D(application); } { PROFILE(_T("render 2D")); render2D(application); } renderProfile(); present(); }
void Halo_Render() { if(HALOCUR[0] == 0 && HALOCUR[1] == 0) return; GRenderer->ResetTexture(0); RenderState baseState = render3D().depthWrite(false); if(HALOCUR[0] > 0) { UseRenderState state(baseState.blend(BlendZero, BlendInvSrcColor)); EERIEDRAWPRIM(Renderer::TriangleList, LATERDRAWHALO[0], HALOCUR[0] * 6); HALOCUR[0] = 0; } if(HALOCUR[1] > 0) { UseRenderState state(baseState.blend(BlendSrcColor, BlendOne)); EERIEDRAWPRIM(Renderer::TriangleList, LATERDRAWHALO[1], HALOCUR[1] * 6); HALOCUR[1] = 0; } }
void renderLightFlares() { ARX_PROFILE_FUNC(); if(g_debugToggles[6]) { RaycastDebugDraw(); } GRenderer->SetFogColor(Color::none); UseRenderState state(render3D().blend(BlendOne, BlendOne).depthWrite(false).depthTest(false)); for(size_t i = 0; i < g_culledDynamicLightsCount; i++) { const EERIE_LIGHT & el = *g_culledDynamicLights[i]; if(!el.m_exists || !el.m_isVisible || !(el.extras & EXTRAS_FLARE) || el.m_flareFader <= 0.f) { continue; } float v = el.m_flareFader; if(FADEDIR) { v *= 1.f - LAST_FADEVALUE; } float size = -el.ex_flaresize; if(el.extras & EXTRAS_FIXFLARESIZE) { // This is only used for one light in the whole game and makes it's flare gigantic when up close // TODO Is this part of some puzze or a bug / obsolete workaround? size = el.ex_flaresize; } EERIEDrawSprite(el.pos, size, tflare, Color(el.rgb * v), EE_RT(el.pos).z); } }
int main(int argc, char* argv[]) { try { nvxio::Application &app = nvxio::Application::get(); // // Parse command line arguments // // std::string sourceUri = app.findSampleFilePath("file:///dev/video0"); // "/home/ubuntu/VisionWorks-SFM-0.82-Samples/data/sfm/parking_sfm.mp4"; std::string sourceUri = "/home/px4/test.mp4"; std::string configFile = app.findSampleFilePath("sfm/sfm_config.ini"); bool fullPipeline = false; std::string maskFile; bool noLoop = false; app.setDescription("This sample demonstrates Structure from Motion (SfM) algorithm"); app.addOption(0, "mask", "Optional mask", nvxio::OptionHandler::string(&maskFile)); app.addBooleanOption('f', "fullPipeline", "Run full SfM pipeline without using IMU data", &fullPipeline); app.addBooleanOption('n', "noLoop", "Run sample without loop", &noLoop); app.init(argc, argv); nvx_module_version_t sfmVersion; nvxSfmGetVersion(&sfmVersion); std::cout << "VisionWorks SFM version: " << sfmVersion.major << "." << sfmVersion.minor << "." << sfmVersion.patch << sfmVersion.suffix << std::endl; std::string imuDataFile; std::string frameDataFile; if (!fullPipeline) { imuDataFile = app.findSampleFilePath("sfm/imu_data.txt"); frameDataFile = app.findSampleFilePath("sfm/images_timestamps.txt"); } if (app.getPreferredRenderName() != "default") { std::cerr << "The sample uses custom Render for GUI. --nvxio_render option is not supported!" << std::endl; return nvxio::Application::APP_EXIT_CODE_NO_RENDER; } // // Read SfMParams // nvx::SfM::SfMParams params; std::string msg; if (!read(configFile, params, msg)) { std::cout << msg << std::endl; return nvxio::Application::APP_EXIT_CODE_INVALID_VALUE; } // // Create OpenVX context // nvxio::ContextGuard context; // // Messages generated by the OpenVX framework will be processed by nvxio::stdoutLogCallback // vxRegisterLogCallback(context, &nvxio::stdoutLogCallback, vx_false_e); // // Add SfM kernels // NVXIO_SAFE_CALL(nvxSfmRegisterKernels(context)); // // Create a Frame Source // std::unique_ptr<nvxio::FrameSource> source( nvxio::createDefaultFrameSource(context, sourceUri)); if (!source || !source->open()) { std::cout << "Can't open source file: " << sourceUri << std::endl; // int haha=3; // fprintf(stderr, "errno = %d \n", haha); return nvxio::Application::APP_EXIT_CODE_NO_RESOURCE; } nvxio::FrameSource::Parameters sourceParams = source->getConfiguration(); // // Create OpenVX Image to hold frames from video source // vx_image frame = vxCreateImage(context, sourceParams.frameWidth, sourceParams.frameHeight, sourceParams.format); NVXIO_CHECK_REFERENCE(frame); // // Load mask image if needed // vx_image mask = NULL; if (!maskFile.empty()) { mask = nvxio::loadImageFromFile(context, maskFile, VX_DF_IMAGE_U8); vx_uint32 mask_width = 0, mask_height = 0; vxQueryImage(mask, VX_IMAGE_ATTRIBUTE_WIDTH, &mask_width, sizeof(mask_width)); vxQueryImage(mask, VX_IMAGE_ATTRIBUTE_HEIGHT, &mask_height, sizeof(mask_height)); if (mask_width != sourceParams.frameWidth || mask_height != sourceParams.frameHeight) { std::cerr << "The mask must have the same size as the input source." << std::endl; return nvxio::Application::APP_EXIT_CODE_INVALID_DIMENSIONS; } } // // Create 3D Render instance // std::unique_ptr<nvxio::Render3D> render3D(nvxio::createDefaultRender3D(context, 0, 0, "SfM Point Cloud", sourceParams.frameWidth, sourceParams.frameHeight)); nvxio::Render::TextBoxStyle style = {{255, 255, 255, 255}, {0, 0, 0, 255}, {10, 10}}; if (!render3D) { std::cerr << "Can't create a renderer" << std::endl; return nvxio::Application::APP_EXIT_CODE_NO_RENDER; } float fovYinRad = 2.f * atanf(sourceParams.frameHeight / 2.f / params.pFy); render3D->setDefaultFOV(180.f / nvxio::PI_F * fovYinRad); EventData eventData; render3D->setOnKeyboardEventCallback(eventCallback, &eventData); // // Create SfM class instance // std::unique_ptr<nvx::SfM> sfm(nvx::SfM::createSfM(context, params)); // // Create FenceDetectorWithKF class instance // FenceDetectorWithKF fenceDetector; nvxio::FrameSource::FrameStatus frameStatus; do { frameStatus = source->fetch(frame); } while (frameStatus == nvxio::FrameSource::TIMEOUT); if (frameStatus == nvxio::FrameSource::CLOSED) { std::cerr << "Source has no frames" << std::endl; return nvxio::Application::APP_EXIT_CODE_NO_FRAMESOURCE; } vx_status status = sfm->init(frame, mask, imuDataFile, frameDataFile); if (status != VX_SUCCESS) { std::cerr << "Failed to initialize the algorithm" << std::endl; return nvxio::Application::APP_EXIT_CODE_ERROR; } const vx_size maxNumOfPoints = 2000; const vx_size maxNumOfPlanesVertices = 2000; vx_array filteredPoints = vxCreateArray(context, NVX_TYPE_POINT3F, maxNumOfPoints); vx_array planesVertices = vxCreateArray(context, NVX_TYPE_POINT3F, maxNumOfPlanesVertices); // // Run processing loop // vx_matrix model = vxCreateMatrix(context, VX_TYPE_FLOAT32, 4, 4); float eye_data[4*4] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1}; vxWriteMatrix(model, eye_data); nvxio::Render3D::PointCloudStyle pcStyle = {0, 12}; nvxio::Render3D::PlaneStyle fStyle = {0, 10}; GroundPlaneSmoother groundPlaneSmoother(7); nvx::Timer totalTimer; totalTimer.tic(); double proc_ms = 0; float yGroundPlane = 0; while (!eventData.shouldStop) { if (!eventData.pause) { frameStatus = source->fetch(frame); if (frameStatus == nvxio::FrameSource::TIMEOUT) { continue; } if (frameStatus == nvxio::FrameSource::CLOSED) { if(noLoop) break; if (!source->open()) { std::cerr << "Failed to reopen the source" << std::endl; break; } do { frameStatus = source->fetch(frame); } while (frameStatus == nvxio::FrameSource::TIMEOUT); sfm->init(frame, mask, imuDataFile, frameDataFile); fenceDetector.reset(); continue; } // Process nvx::Timer procTimer; procTimer.tic(); sfm->track(frame, mask); proc_ms = procTimer.toc(); } // Print performance results sfm->printPerfs(); if (!eventData.showPointCloud) { render3D->disableDefaultKeyboardEventCallback(); render3D->putImage(frame); } else { render3D->enableDefaultKeyboardEventCallback(); } filterPoints(sfm->getPointCloud(), filteredPoints); render3D->putPointCloud(filteredPoints, model, pcStyle); if (eventData.showFences) { fenceDetector.getFencePlaneVertices(filteredPoints, planesVertices); render3D->putPlanes(planesVertices, model, fStyle); } if (fullPipeline && eventData.showGP) { const float x1(-1.5), x2(1.5), z1(1), z2(4); vx_matrix gp = sfm->getGroundPlane(); yGroundPlane = groundPlaneSmoother.getSmoothedY(gp, x1, z1); nvx_point3f_t pt[4] = {{x1, yGroundPlane, z1}, {x1, yGroundPlane, z2}, {x2, yGroundPlane, z2}, {x2, yGroundPlane, z1}}; vx_array gpPoints = vxCreateArray(context, NVX_TYPE_POINT3F, 4); vxAddArrayItems(gpPoints, 4, pt, sizeof(pt[0])); render3D->putPlanes(gpPoints, model, fStyle); vxReleaseArray(&gpPoints); } double total_ms = totalTimer.toc(); // Add a delay to limit frame rate app.sleepToLimitFPS(total_ms); total_ms = totalTimer.toc(); totalTimer.tic(); std::string state = createInfo(fullPipeline, proc_ms, total_ms, eventData); render3D->putText(state.c_str(), style); if (!render3D->flush()) { eventData.shouldStop = true; } } // // Release all objects // vxReleaseImage(&frame); vxReleaseImage(&mask); vxReleaseMatrix(&model); vxReleaseArray(&filteredPoints); vxReleaseArray(&planesVertices); } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; return nvxio::Application::APP_EXIT_CODE_ERROR; } return nvxio::Application::APP_EXIT_CODE_SUCCESS; }
void ARX_INTERFACE_ManageOpenedBook_Finish(const Vec2f & mousePos, Rectf rect, float scale) { RenderState baseState = render3D().depthTest(false).fog(false); Vec3f pos = Vec3f(0.f, 0.f, 2100.f); EERIE_LIGHT * light = lightHandleGet(torchLightHandle); EERIE_LIGHT tl = *light; light->pos = Vec3f(500.f, -1960.f, 1590.f); light->m_exists = true; light->rgb = Color3f(0.6f, 0.7f, 0.9f); light->intensity = 1.8f; light->fallstart = 4520.f; light->fallend = light->fallstart + 600.f; RecalcLight(light); Camera * oldcam = g_camera; g_culledDynamicLights[0] = light; g_culledDynamicLightsCount = 1; Vec2i tmpPos(0); GRenderer->SetAntialiasing(true); float wave = timeWaveSin(g_platformTime.frameStart(), PlatformDurationMsf(1256.6370614f)); float ptDelta = toMs(g_platformTime.lastFrameDuration()); Camera bookcam; bookcam.angle = Anglef(); bookcam.m_pos = Vec3f(0.f); bookcam.focal = 500.f; bookcam.cdepth = 2200.f; for(size_t i = 0; i < RUNE_COUNT; i++) { if(!gui::necklace.runes[i]) continue; EERIE_3DOBJ * rune = gui::necklace.runes[i]; Vec2i projectionCenter = Vec2i(rect.topLeft() + (Vec2f(285, 36) + Vec2f(tmpPos) * Vec2f(45, 64)) * scale); PrepareCamera(&bookcam, Rect(rect), projectionCenter); if(player.hasRune((Rune)i)) { Anglef angle; if(rune->angle.getYaw() != 0.f) { if(rune->angle.getYaw() > 300.f) { rune->angle.setYaw(300.f); } angle.setYaw(wave * rune->angle.getYaw() * (1.0f / 40)); } rune->angle.setYaw(rune->angle.getYaw() - ptDelta * 0.2f); if(rune->angle.getYaw() < 0.f) rune->angle.setYaw(0.f); // Now draw the rune TransformInfo t2(pos, glm::quat_cast(toRotationMatrix(angle))); DrawEERIEInter(rune, t2, NULL, false, 0.f); Rectf runeBox = UpdateBbox2d(*rune).toRect(); PopAllTriangleListOpaque(baseState); tmpPos.x++; if(tmpPos.x > 4) { tmpPos.x = 0; tmpPos.y++; } // TODO this is a workaround for vertexClipPositions being relative to viewport Vec2f mousePosInViewport = mousePos - rect.topLeft(); // Checks for Mouse floating over a rune... if(runeBox.contains(mousePosInViewport)) { bool r = false; for(size_t j = 0; j < rune->facelist.size(); j++) { float n = PtIn2DPolyProj(rune->vertexClipPositions, &rune->facelist[j], mousePosInViewport.x, mousePosInViewport.y); if(n != 0.f) { r = true; break; } } if(r) { TransformInfo t(pos, glm::quat_cast(toRotationMatrix(angle))); DrawEERIEInter(rune, t, NULL, false, 0.f); rune->angle.setYaw(rune->angle.getYaw() + ptDelta * 2.f); PopAllTriangleListOpaque(baseState.blendAdditive()); cursorSetInteraction(); if(eeMouseDown1()) { PlayerBookDrawRune((Rune)i); } } } TransformInfo t1(pos, quat_identity()); DrawEERIEInter(gui::necklace.lacet, t1, NULL, false, 0.f); PopAllTriangleListOpaque(baseState); } } *light = tl; PrepareCamera(oldcam, g_size); GRenderer->SetAntialiasing(false); }