UT_sint32 GR_Graphics::ftlu(UT_sint32 fontUnits) const { UT_sint32 itmp = fontUnits * (UT_sint32)getResolution(); return (itmp/ (UT_sint32)getDeviceResolution()); }
//-------------------------------------------------------------- void ofConePrimitive::set( float _radius, float _height ) { radius = _radius; height = _height; setResolution( getResolution().x, getResolution().y, getResolution().z ); }
//-------------------------------------------------------------- void ofConePrimitive::setRadius( float _radius ) { radius = _radius; setResolution(getResolution().x, getResolution().y, getResolution().z); }
//---------------------------------------------------------- void ofIcoSpherePrimitive::setMode( ofPrimitiveMode mode ) { // ofIcoSpherePrimitive only works with OF_PRIMITIVE_TRIANGLES // setResolution( getResolution() ); }
//-------------------------------------------------------------- void ofCylinderPrimitive::set(float _radius, float _height, int radiusSegments, int heightSegments, int capSegments, bool _bCapped, ofPrimitiveMode mode) { radius = _radius; height = _height; bCapped = _bCapped; resolution.set( radiusSegments, heightSegments, capSegments ); int resX = getResolution().x; int resY = getResolution().y-1; int resZ = getResolution().z-1; int indexStep = 2; if(mode == OF_PRIMITIVE_TRIANGLES) { indexStep = 6; resX = resX-1; } // 0 -> top cap strides[0][0] = 0; strides[0][1] = resX * resZ * indexStep; vertices[0][0] = 0; vertices[0][1] = getResolution().x * getResolution().z; // 1 -> cylinder // if(bCapped) { strides[1][0] = strides[0][0] + strides[0][1]; vertices[1][0] = vertices[0][0] + vertices[0][1]; } else { strides[1][0] = 0; vertices[1][0] = 0; } strides[1][1] = resX * resY * indexStep; vertices[1][1] = getResolution().x * getResolution().y; // 2 -> bottom cap strides[2][0] = strides[1][0] + strides[1][1]; strides[2][1] = resX * resZ * indexStep; vertices[2][0] = vertices[1][0]+vertices[1][1]; vertices[2][1] = getResolution().x * getResolution().z; getMesh() = ofMesh::cylinder( getRadius(), getHeight(), getResolution().x, getResolution().y, getResolution().z, getCapped(), mode ); normalizeAndApplySavedTexCoords(); }
//-------------------------------------------------------------- void ofPlanePrimitive::setResolution( int columns, int rows ) { resolution.set( columns, rows ); ofPrimitiveMode mode = getMesh().getMode(); set( getWidth(), getHeight(), getResolution().x, getResolution().y, mode ); }
//---------------------------------------------------------- void ofSpherePrimitive::setResolution( int res ) { resolution = res; ofPrimitiveMode mode = getMesh().getMode(); set(getRadius(), getResolution(), mode ); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ChangeResolution::writeFilterParameters(AbstractFilterParametersWriter* writer) { writer->writeValue("Resolution", getResolution() ); }
int main() { DEBUGLOG->setAutoPrint(true); ////////////////////////////////////////////////////////////////////////////// /////////////////////// INIT ////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // create window and opengl context auto window = generateWindow(800,800); ////////////////////////////////////////////////////////////////////////////// /////////////////////////////// RENDERING /////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ///////////////////// Scene / View Settings ////////////////////////// glm::mat4 model = glm::mat4(1.0f); glm::vec4 eye(0.0f, 0.0f, 3.0f, 1.0f); glm::vec4 center(0.0f,0.0f,0.0f,1.0f); glm::mat4 view = glm::lookAt(glm::vec3(eye), glm::vec3(center), glm::vec3(0,1,0)); // glm::mat4 perspective = glm::ortho(-2.0f, 2.0f, -2.0f, 2.0f, -1.0f, 6.0f); /// perspective projection is experimental; yields weird warping effects due to vertex interpolation of uv-coordinates glm::mat4 perspective = glm::perspective(glm::radians(65.f), getRatio(window), 0.1f, 10.f); // create object // Sphere grid; Grid grid(10,10,0.1f,0.1f,true); // Volume grid; // load grass texture s_texHandle = TextureTools::loadTexture(RESOURCES_PATH + std::string( "/grass.png")); glBindTexture(GL_TEXTURE_2D, s_texHandle); /////////////////////// Renderpass /////////////////////////// DEBUGLOG->log("Shader Compilation: volume uvw coords"); DEBUGLOG->indent(); ShaderProgram shaderProgram("/modelSpace/GBuffer.vert", "/modelSpace/GBuffer.frag"); DEBUGLOG->outdent(); shaderProgram.update("model", model); shaderProgram.update("view", view); shaderProgram.update("projection", perspective); shaderProgram.update("color", glm::vec4(1.0f,0.0f,0.0f,1.0f)); DEBUGLOG->log("FrameBufferObject Creation: volume uvw coords"); DEBUGLOG->indent(); FrameBufferObject fbo(getResolution(window).x, getResolution(window).y); FrameBufferObject::s_internalFormat = GL_RGBA32F; // to allow arbitrary values in G-Buffer fbo.addColorAttachments(4); DEBUGLOG->outdent(); // G-Buffer FrameBufferObject::s_internalFormat = GL_RGBA; // restore default RenderPass renderPass(&shaderProgram, &fbo); renderPass.addEnable(GL_DEPTH_TEST); renderPass.addClearBit(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); renderPass.addRenderable(&grid); ShaderProgram compShader("/screenSpace/fullscreen.vert", "/screenSpace/finalCompositing.frag"); // ShaderProgram compShader("/screenSpace/fullscreen.vert", "/screenSpace/simpleAlphaTexture.frag"); Quad quad; RenderPass compositing(&compShader, 0); compositing.addClearBit(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); compositing.addRenderable(&quad); // Geometry test shader ShaderProgram geomShader("/modelSpace/geometry.vert", "/modelSpace/simpleLighting.frag", "/geometry/simpleGeom.geom"); RenderPass geom(&geomShader, 0); geom.addClearBit(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); geom.addRenderable(&grid); geom.addEnable(GL_DEPTH_TEST); geom.addEnable(GL_ALPHA_TEST); geom.addEnable(GL_BLEND); glAlphaFunc(GL_GREATER, 0); geomShader.update("projection", perspective); ////////////////////////////////////////////////////////////////////////////// /////////////////////// GUI / USER INPUT //////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // Setup ImGui binding ImGui_ImplGlfwGL3_Init(window, true); Turntable turntable; double old_x; double old_y; glfwGetCursorPos(window, &old_x, &old_y); auto cursorPosCB = [&](double x, double y) { ImGuiIO& io = ImGui::GetIO(); if ( io.WantCaptureMouse ) { return; } // ImGUI is handling this double d_x = x - old_x; double d_y = y - old_y; if ( turntable.getDragActive() ) { turntable.dragBy(d_x, d_y, view); } old_x = x; old_y = y; }; auto mouseButtonCB = [&](int b, int a, int m) { if (b == GLFW_MOUSE_BUTTON_LEFT && a == GLFW_PRESS) { turntable.setDragActive(true); } if (b == GLFW_MOUSE_BUTTON_LEFT && a == GLFW_RELEASE) { turntable.setDragActive(false); } ImGui_ImplGlfwGL3_MouseButtonCallback(window, b, a, m); }; auto keyboardCB = [&](int k, int s, int a, int m) { if (a == GLFW_RELEASE) {return;} switch (k) { case GLFW_KEY_W: eye += glm::inverse(view) * glm::vec4(0.0f,0.0f,-0.1f,0.0f); center += glm::inverse(view) * glm::vec4(0.0f,0.0f,-0.1f,0.0f); break; case GLFW_KEY_A: eye += glm::inverse(view) * glm::vec4(-0.1f,0.0f,0.0f,0.0f); center += glm::inverse(view) * glm::vec4(-0.1f,0.0f,0.0f,0.0f); break; case GLFW_KEY_S: eye += glm::inverse(view) * glm::vec4(0.0f,0.0f,0.1f,0.0f); center += glm::inverse(view) * glm::vec4(0.0f,0.0f,0.1f,0.0f); break; case GLFW_KEY_D: eye += glm::inverse(view) * glm::vec4(0.1f,0.0f,0.0f,0.0f); center += glm::inverse(view) * glm::vec4(0.1f,0.0f,0.0f,0.0f); break; default: break; } ImGui_ImplGlfwGL3_KeyCallback(window,k,s,a,m); }; setCursorPosCallback(window, cursorPosCB); setMouseButtonCallback(window, mouseButtonCB); setKeyCallback(window, keyboardCB); ////////////////////////////////////////////////////////////////////////////// //////////////////////////////// RENDER LOOP ///////////////////////////////// ////////////////////////////////////////////////////////////////////////////// double elapsedTime = 0.0; render(window, [&](double dt) { elapsedTime += dt; std::string window_header = "Volume Renderer - " + std::to_string( 1.0 / dt ) + " FPS"; glfwSetWindowTitle(window, window_header.c_str() ); //////////////////////////////// GUI //////////////////////////////// ImGuiIO& io = ImGui::GetIO(); ImGui_ImplGlfwGL3_NewFrame(); // tell ImGui a new frame is being rendered ImGui::PushItemWidth(-100); if (ImGui::CollapsingHeader("Geometry Shader Settings")) { ImGui::ColorEdit4( "color", glm::value_ptr( s_color)); // color mixed at max distance ImGui::SliderFloat("strength", &s_strength, 0.0f, 2.0f); // influence of color shift } ImGui::Checkbox("auto-rotate", &s_isRotating); // enable/disable rotating volume ImGui::PopItemWidth(); ////////////////////////////////////////////////////////////////////////////// ///////////////////////////// MATRIX UPDATING /////////////////////////////// if (s_isRotating) // update view matrix { model = glm::rotate(glm::mat4(1.0f), (float) dt, glm::vec3(0.0f, 1.0f, 0.0f) ) * model; } view = glm::lookAt(glm::vec3(eye), glm::vec3(center), glm::vec3(0.0f, 1.0f, 0.0f)); ////////////////////////////////////////////////////////////////////////////// //////////////////////// SHADER / UNIFORM UPDATING ////////////////////////// // update view related uniforms shaderProgram.update( "view", view); shaderProgram.update( "model", turntable.getRotationMatrix() * model); geomShader.update( "view", view); geomShader.update( "model", turntable.getRotationMatrix() * model); compShader.update( "vLightPos", view * turntable.getRotationMatrix() * s_lightPos); updateVectorTexture(elapsedTime); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, s_vectorTexture); // glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // this is altered by ImGui::Render(), so reset it every frame glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, s_texHandle); geomShader.update("tex", 1); geomShader.update("blendColor", 2.0); geomShader.update("color", s_color); geomShader.update("strength", s_strength); ////////////////////////////////////////////////////////////////////////////// //////////////////////////////// RENDERING //// ///////////////////////////// // glActiveTexture(GL_TEXTURE0); // glBindTexture(GL_TEXTURE_2D, fbo.getColorAttachmentTextureHandle(GL_COLOR_ATTACHMENT0)); // color // glActiveTexture(GL_TEXTURE1); // glBindTexture(GL_TEXTURE_2D, fbo.getColorAttachmeHntTextureHandle(GL_COLOR_ATTACHMENT1)); // normal // glActiveTexture(GL_TEXTURE2); // glBindTexture(GL_TEXTURE_2D, fbo.getColorAttachmentTextureHandle(GL_COLOR_ATTACHMENT2)); // position // glActiveTexture(GL_TEXTURE0); // compShader.update("colorMap", 0); // compShader.update("normalMap", 1); // compShader.update("positionMap", 2); // renderPass.render(); // compositing.render(); geom.render(); ImGui::Render(); glDisable(GL_BLEND); glBlendFunc(GL_ONE, GL_ZERO); // this is altered by ImGui::Render(), so reset it every frame ////////////////////////////////////////////////////////////////////////////// }); destroyWindow(window); return 0; }
NoRSX::NoRSX(int real_screen_type, int buffer_screen_type) : EventHandler(){ screen_type = real_screen_type; buffer_type = buffer_screen_type; currentBuffer = 0; host_addr = memalign(1024*1024, HOST_SIZE); switch(real_screen_type){ case RESOLUTION_1920x1080: { width=1920;height=1080; buffers[0].width=1920;buffers[0].height=1080; buffers[1].width=1920;buffers[1].height=1080; } break; case RESOLUTION_1280x720: { width=1280;height=720; buffers[0].width=1280;buffers[0].height=720; buffers[1].width=1280;buffers[1].height=720; } break; case RESOLUTION_720x576: { width=720;height=576; buffers[0].width=720;buffers[0].height=576; buffers[1].width=720;buffers[1].height=576; } break; case RESOLUTION_720x480: { width=720;height=480; buffers[0].width=720;buffers[0].height=480; buffers[1].width=720;buffers[1].height=480; } break; default: getResolution(&width,&height); switch(real_screen_type){ default: case RESOLUTION_AUTO_LOWER_1080p: { if(height>=1080){ real_screen_type = RESOLUTION_1280x720; width=1280;height=720; buffers[0].width=1280;buffers[0].height=720; buffers[1].width=1280;buffers[1].height=720; }else real_screen_type = RESOLUTION_AUTO; } break; case RESOLUTION_AUTO_LOWER_720p: { if(height>=720){ real_screen_type = RESOLUTION_720x576; width=720;height=576; buffers[0].width=720;buffers[0].height=576; buffers[1].width=720;buffers[1].height=576; }else real_screen_type = RESOLUTION_AUTO; } break; case RESOLUTION_AUTO_LOWER_576p: { if(height>=576){ real_screen_type = RESOLUTION_720x480; width=720;height=480; buffers[0].width=720;buffers[0].height=480; buffers[1].width=720;buffers[1].height=480; }else real_screen_type = RESOLUTION_AUTO; } break; real_screen_type = RESOLUTION_AUTO; break; } break; } context = initScreen(host_addr, HOST_SIZE, real_screen_type, width, height); for(int i=0;i<2;i++) makeBuffer(&buffers[i],width,height,i); switch(buffer_screen_type){ case RESOLUTION_1920x1080: width=1920; height=1080; break; case RESOLUTION_1280x720: width=1280; height=720; break; case RESOLUTION_720x576: width=720; height=576; break; case RESOLUTION_720x480: width=720; height=480; break; default: getResolution(&width,&height); break; } buffer = makeMemBuffer(width,height,&buffer_size); buffer_size = buffers[0].width * buffers[0].height * sizeof(u32); flip(context, 0); setRenderTarget(context, &buffers[0]); RegisterCallBack(EVENT_SLOT0); }
/* Reads the differential analog value of two pins (pinP - pinN) * It waits until the value is read and then returns the result * If a comparison has been set up and fails, it will return ADC_ERROR_DIFF_VALUE * Set the resolution, number of averages and voltage reference using the appropriate functions */ int ADC_Module::analogReadDifferential(uint8_t pinP, uint8_t pinN) { if(!checkDifferentialPins(pinP, pinN)) { fail_flag |= ADC_ERROR_WRONG_PIN; return ADC_ERROR_VALUE; // all others are invalid } // increase the counter of measurements num_measurements++; // check for calibration before setting channels, // because conversion will start as soon as we write to *ADC_SC1A if (calibrating) wait_for_cal(); uint8_t res = getResolution(); // vars to saved the current state of the ADC in case it's in use ADC_Config old_config = {0}; uint8_t wasADCInUse = isConverting(); // is the ADC running now? if(wasADCInUse) { // this means we're interrupting a conversion // save the current conversion config, we don't want any other interrupts messing up the configs __disable_irq(); saveConfig(&old_config); __enable_irq(); } // no continuous mode singleMode(); startDifferentialFast(pinP, pinN); // start conversion // wait for the ADC to finish while( isConverting() ) { yield(); //digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) ); } // it's done, check if the comparison (if any) was true int32_t result; __disable_irq(); // make sure nothing interrupts this part if (isComplete()) { // conversion succeded result = (int16_t)(int32_t)(*ADC_RA); // cast to 32 bits if(res==16) { // 16 bit differential is actually 15 bit + 1 bit sign result *= 2; // multiply by 2 as if it were really 16 bits, so that getMaxValue gives a correct value. } } else { // comparison was false result = ADC_ERROR_VALUE; fail_flag |= ADC_ERROR_COMPARISON; } __enable_irq(); // if we interrupted a conversion, set it again if (wasADCInUse) { __disable_irq(); loadConfig(&old_config); __enable_irq(); } num_measurements--; return result; } // analogReadDifferential
Complexity SmallestOfMaximum::complexity(const Term* term) const { return Complexity().comparison(1).arithmetic(1 + 2) + term->complexity().comparison(1).arithmetic(3).multiply(getResolution()); }
/** * @brief Parsing particular entry in exif directory * This is internal function and is not exposed to client * * Entries are divided into 12-bytes blocks each * Each block corresponds the following structure: * * +------+-------------+-------------------+------------------------+ * | Type | Data format | Num of components | Data or offset to data | * +======+=============+===================+========================+ * | TTTT | ffff | NNNNNNNN | DDDDDDDD | * +------+-------------+-------------------+------------------------+ * * Details can be found here: http://www.media.mit.edu/pia/Research/deepview/exif.html * * @param [in] offset Offset to entry in bytes inside raw exif data * @return ExifEntry_t structure which corresponds to particular entry * */ ExifEntry_t ExifReader::parseExifEntry(const size_t offset) { ExifEntry_t entry; uint16_t tagNum = getExifTag( offset ); entry.tag = tagNum; switch( tagNum ) { case IMAGE_DESCRIPTION: entry.field_str = getString( offset ); break; case MAKE: entry.field_str = getString( offset ); break; case MODEL: entry.field_str = getString( offset ); break; case ORIENTATION: entry.field_u16 = getOrientation( offset ); break; case XRESOLUTION: entry.field_u_rational = getResolution( offset ); break; case YRESOLUTION: entry.field_u_rational = getResolution( offset ); break; case RESOLUTION_UNIT: entry.field_u16 = getResolutionUnit( offset ); break; case SOFTWARE: entry.field_str = getString( offset ); break; case DATE_TIME: entry.field_str = getString( offset ); break; case WHITE_POINT: entry.field_u_rational = getWhitePoint( offset ); break; case PRIMARY_CHROMATICIES: entry.field_u_rational = getPrimaryChromaticies( offset ); break; case Y_CB_CR_COEFFICIENTS: entry.field_u_rational = getYCbCrCoeffs( offset ); break; case Y_CB_CR_POSITIONING: entry.field_u16 = getYCbCrPos( offset ); break; case REFERENCE_BLACK_WHITE: entry.field_u_rational = getRefBW( offset ); break; case COPYRIGHT: entry.field_str = getString( offset ); break; case EXIF_OFFSET: break; default: entry.tag = INVALID_TAG; break; } return entry; }
double GR_Graphics::ftluD(double fontUnits) const { return (fontUnits * static_cast<double>(getResolution()) / static_cast<double>(getDeviceResolution())); }
//---------------------------------------------------------- void ofBoxPrimitive::setMode( ofPrimitiveMode mode ) { // only supports triangles // setResolution( getResolution().x, getResolution().y, getResolution().z ); }
void StaticLayer::onInitialize() { ros::NodeHandle nh("~/" + name_), g_nh; current_ = true; global_frame_ = layered_costmap_->getGlobalFrameID(); std::string map_topic; nh.param("map_topic", map_topic, std::string("map")); nh.param("first_map_only", first_map_only_, false); nh.param("subscribe_to_updates", subscribe_to_updates_, false); nh.param("track_unknown_space", track_unknown_space_, true); nh.param("use_maximum", use_maximum_, false); int temp_lethal_threshold, temp_unknown_cost_value; nh.param("lethal_cost_threshold", temp_lethal_threshold, int(100)); nh.param("unknown_cost_value", temp_unknown_cost_value, int(-1)); nh.param("trinary_costmap", trinary_costmap_, true); lethal_threshold_ = std::max(std::min(temp_lethal_threshold, 100), 0); unknown_cost_value_ = temp_unknown_cost_value; // Only resubscribe if topic has changed if (map_sub_.getTopic() != ros::names::resolve(map_topic)) { // we'll subscribe to the latched topic that the map server uses ROS_INFO("Requesting the map..."); map_sub_ = g_nh.subscribe(map_topic, 1, &StaticLayer::incomingMap, this); map_received_ = false; has_updated_data_ = false; ros::Rate r(10); while (!map_received_ && g_nh.ok()) { ros::spinOnce(); r.sleep(); } ROS_INFO("Received a %d X %d map at %f m/pix", getSizeInCellsX(), getSizeInCellsY(), getResolution()); if (subscribe_to_updates_) { ROS_INFO("Subscribing to updates"); map_update_sub_ = g_nh.subscribe(map_topic + "_updates", 10, &StaticLayer::incomingUpdate, this); } } else { has_updated_data_ = true; } if (dsrv_) { delete dsrv_; } dsrv_ = new dynamic_reconfigure::Server<costmap_2d::GenericPluginConfig>(nh); dynamic_reconfigure::Server<costmap_2d::GenericPluginConfig>::CallbackType cb = boost::bind( &StaticLayer::reconfigureCB, this, _1, _2); dsrv_->setCallback(cb); }
//-------------------------------------------------------------- void ofPlanePrimitive::setWidth( float _width ) { width = _width; setResolution( getResolution().x, getResolution().y ); }
void qKinect::doStartGrabbing() { assert(m_app); if (!m_app) return; f_ctx=0; f_dev=0; s_grabIndex=0; if (m_kDlg) delete m_kDlg; m_kDlg=0; s_max_depth_count = 0; if (s_depth_data) delete[] s_depth_data; s_depth_count = 0; s_depth_data = 0; s_wDepth = s_hDepth = 0; if (s_last_rgb_data) delete[] s_last_rgb_data; s_last_rgb_data = 0; s_rgb_count = 0; s_wRgb = s_hRgb = 0; if (freenect_init(&f_ctx, NULL) < 0) { m_app->dispToConsole("[qKinect] Failed to initialize kinect driver!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG); int nr_devices = freenect_num_devices(f_ctx); m_app->dispToConsole(qPrintable(QString("[qKinect] Number of devices found: %1").arg(nr_devices))); if (nr_devices < 1) return; if (freenect_open_device(f_ctx, &f_dev, 0) < 0) { m_app->dispToConsole("[qKinect] Failed to initialize kinect device!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } //test: try to init high resolution mode //freenect_frame_mode upDepthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_HIGH, FREENECT_DEPTH_11BIT); //int success = freenect_set_depth_mode(f_dev,upDepthMode); /*** Depth information ***/ freenect_frame_mode depthMode = freenect_get_current_depth_mode(f_dev); if (!depthMode.depth_format == FREENECT_DEPTH_11BIT) { depthMode = freenect_find_depth_mode(depthMode.resolution, FREENECT_DEPTH_11BIT); if (freenect_set_depth_mode(f_dev,depthMode)<0) { m_app->dispToConsole("[qKinect] Failed to initialiaze depth mode!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } } if (!getResolution(depthMode.resolution,s_wDepth,s_hDepth)) { m_app->dispToConsole("[qKinect] Failed to read depth resolution!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } m_app->dispToConsole(qPrintable(QString("[qKinect] Depth resolution: %1 x %2").arg(s_wDepth).arg(s_hDepth))); s_depth_data = new uint16_t[s_wDepth*s_hDepth]; if (!s_depth_data) { m_app->dispToConsole("[qKinect] Not enough memory!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } s_max_depth_count = 1; /*** RGB information ***/ bool grabRGB = true; { freenect_frame_mode rgbMode = freenect_get_current_video_mode(f_dev); if (!rgbMode.video_format == FREENECT_VIDEO_RGB || depthMode.resolution != rgbMode.resolution) { rgbMode = freenect_find_video_mode(depthMode.resolution, FREENECT_VIDEO_RGB); if (freenect_set_video_mode(f_dev,rgbMode)<0) { m_app->dispToConsole("[qKinect] Can't find a video mode compatible with current depth mode?!"); grabRGB = false; } } //still want to/can grab RGB info? if (grabRGB) { getResolution(rgbMode.resolution,s_wRgb,s_hRgb); s_last_rgb_data = new uint8_t[s_wRgb*s_hRgb*3]; if (!s_last_rgb_data) //not enough memory for RGB { m_app->dispToConsole("[qKinect] Not enough memory to grab RGB info!"); grabRGB = false; } else { m_app->dispToConsole(qPrintable(QString("[qKinect] RGB resolution: %1 x %2").arg(s_wRgb).arg(s_hRgb))); } } } int freenect_angle = 0; freenect_set_tilt_degs(f_dev,freenect_angle); freenect_set_led(f_dev,LED_RED); freenect_set_depth_callback(f_dev, depth_cb); freenect_set_video_callback(f_dev, rgb_cb); if (grabRGB) freenect_set_video_buffer(f_dev, s_last_rgb_data); freenect_start_depth(f_dev); if (s_last_rgb_data) freenect_start_video(f_dev); m_kDlg = new ccKinectDlg(m_app->getMainWindow()); if (grabRGB) m_kDlg->addMode(QString("%1 x %2").arg(s_wDepth).arg(s_hDepth)); else m_kDlg->grabRGBCheckBox->setChecked(false); m_kDlg->grabRGBCheckBox->setEnabled(grabRGB); m_kDlg->grabPushButton->setEnabled(true); connect(m_kDlg->grabPushButton, SIGNAL(clicked()), this, SLOT(grabCloud())); connect(m_kDlg, SIGNAL(finished(int)), this, SLOT(dialogClosed(int))); //m_kDlg->setModal(false); //m_kDlg->setWindowModality(Qt::NonModal); m_kDlg->show(); if (!m_timer) { m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(updateRTView())); } m_timer->start(0); }
//-------------------------------------------------------------- void ofPlanePrimitive::setMode(ofPrimitiveMode mode) { ofPrimitiveMode currMode = getMesh().getMode(); if( mode != currMode ) set( getWidth(), getHeight(), getResolution().x, getResolution().y, mode ); }
Complexity Bisector::complexity(const Term* term) const { return Complexity().comparison(1).arithmetic(1 + 2 + 5) + term->complexity().comparison(1).arithmetic(1 + 5).multiply(getResolution()); }
//---------------------------------------------------------- void ofSpherePrimitive::setMode( ofPrimitiveMode mode ) { ofPrimitiveMode currMode = getMesh().getMode(); if(currMode != mode) set(getRadius(), getResolution(), mode ); }
//------------------------------------------------------------------------------ // process() -- //------------------------------------------------------------------------------ void Sar::process(const LCreal dt) { BaseClass::process(dt); // Imaging in progress? if (timer > 0) { // --- // Point the beam // --- Antenna* ant = getAntenna(); if (ant != nullptr) { const Simulation* s = getSimulation(); const double refLat = s->getRefLatitude(); const double refLon = s->getRefLongitude(); osg::Vec3 pos; Basic::Nav::convertLL2PosVec( refLat, refLon, // Ref point (at sea level) getStarePointLatitude(), getStarePointLongitude(), getStarePointElevation(), &pos); // x,y,z NED // Platform (ownship) coord and then body const osg::Vec3 posP = pos - getOwnship()->getPosition(); const osg::Vec3 posB = getOwnship()->getRotMat() * posP; // Convert to az/el LCreal tgt_az = 0.0; // Angle (degs) LCreal tgt_el = 0.0; // Angle (degs) xyz2AzEl(posB, &tgt_az, &tgt_el); // Command to that position const LCreal az = tgt_az * static_cast<LCreal>(Basic::Angle::D2RCC); const LCreal el = tgt_el * static_cast<LCreal>(Basic::Angle::D2RCC); ant->setRefAzimuth(az); ant->setRefElevation(el); ant->setScanMode(Antenna::CONICAL_SCAN); } // --- // Process timer // --- LCreal ttimer = timer - dt; if (ttimer <= 0) { // ### test -- Generate a test image ### Image* p = new Image(); p->testImage(width,height); p->setImageId(getNextId()); p->setLatitude(getStarePointLatitude()); p->setLongitude(getStarePointLongitude()); p->setElevation(getStarePointElevation()); p->setOrientation(0); if (isMessageEnabled(MSG_INFO)) { std::cout << "Sar:: Generating test image: resolution: " << getResolution() << std::endl; } if (getResolution() > 0) p->setResolution( getResolution() ); else p->setResolution( 3.0 * Basic::Distance::FT2M ); Basic::Pair* pp = new Basic::Pair("image", p); addImage(pp); // ### TEST // Just finished! ttimer = 0; setTransmitterEnableFlag(false); } timer = ttimer; } BaseClass::updateData(dt); }
//---------------------------------------------------------- void ofIcoSpherePrimitive::setRadius(float _radius) { radius = _radius; setResolution( getResolution() ); }
/// \brief Populate the Segment with surface normal data. /// /// Storage for the normals is allocated if necessary, and the average /// normal at each heightpoint is calculated. The middle normals are /// calculated first, followed by the boundaries which are done in /// 2 dimensions to ensure that there is no visible seam between segments. void Segment::populateNormals() { assert(m_points != nullptr); if (m_normals == nullptr) { m_normals = new float[m_size * m_size * 3]; } float * np = m_normals; // Fill in the damn normals float h1, h2, h3, h4; for (decltype(getResolution()) j = 1; j < m_res; ++j) { for (decltype(getResolution()) i = 1; i < m_res; ++i) { h1 = get(i - 1, j); h2 = get(i, j + 1); h3 = get(i + 1, j); h4 = get(i, j - 1); // Caclulate the normal vector. np[j * m_size * 3 + i * 3] = (h1 - h3) / 2.f; np[j * m_size * 3 + i * 3 + 1] = (h4 - h2) / 2.f; np[j * m_size * 3 + i * 3 + 2] = 1.0; } } //edges have one axis pegged to 0 //top and bottom boundary for (decltype(getResolution()) i = 1; i < m_res; ++i) { h1 = get(i - 1, 0); h2 = get(i + 1, 0); np[i * 3] = (h1 - h2) / 2.f; np[i * 3 + 1] = 0.0; np[i * 3 + 2] = 1.0; h1 = get(i - 1, m_res); h2 = get(i + 1, m_res); np[m_res * m_size * 3 + i * 3] = (h1 - h2) / 2.f; np[m_res * m_size * 3 + i * 3 + 1] = 0.0f; np[m_res * m_size * 3 + i * 3 + 2] = 1.0f; } //left and right boundary for (decltype(getResolution()) j = 1; j < m_res; ++j) { h1 = get(0, j - 1); h2 = get(0, j + 1); np[j * m_size * 3] = 0; np[j * m_size * 3 + 1] = (h1 - h2) / 2.f; np[j * m_size * 3 + 2] = 1.f; h1 = get(m_res, j - 1); h2 = get(m_res, j + 1); np[j * m_size * 3 + m_res * 3] = 0.f; np[j * m_size * 3 + m_res * 3 + 1] = (h1 - h2) / 2.f; np[j * m_size * 3 + m_res * 3 + 2] = 1.f; } //corners - these are all treated as flat //so the normal points straight up np[0] = 0.f; np[1] = 0.f; np[2] = 1.f; np[m_res * m_size * 3] = 0.f; np[m_res * m_size * 3 + 1] = 0.f; np[m_res * m_size * 3 + 2] = 1.f; np[m_res * 3] = 0.f; np[m_res * 3 + 1] = 0.f; np[m_res * 3 + 2] = 1.f; np[m_res * m_size * 3 + m_res * 3] = 0.f; np[m_res * m_size * 3 + m_res * 3 + 1] = 0.f; np[m_res * m_size * 3 + m_res * 3 + 2] = 1.f; }
//-------------------------------------------------------------- void ofCylinderPrimitive::setCapped(bool _bCapped) { bCapped = _bCapped; setResolution( getResolution().x, getResolution().y, getResolution().z ); }
/// \brief Two dimensional midpoint displacement fractal. /// /// For a tile where edges are to be filled by 1d fractals. /// Size must be a power of 2, array is (size + 1) * (size + 1) with the /// corners the control points. void Segment::fill2d(BasePoint const & p1, BasePoint const & p2, BasePoint const & p3, BasePoint const & p4) { assert(m_points != 0); // int line = m_res+1; // calculate the edges first. This is necessary so that segments tile // seamlessly note the order in which the edges are calculated and the // direction. opposite edges are calculated the same way (eg left->right) // so that the top of one tile matches the bottom of another, likewise // with sides. // temporary array used to hold each edge float * edge = new float[m_size]; // calc top edge and copy into m_points fill1d(p1, p2, edge); for (decltype(getResolution()) i = 0; i <= m_res; i++) { m_points[0 * m_size + i] = edge[i]; checkMaxMin(edge[i]); } // calc left edge and copy into m_points fill1d(p1, p4, edge); for (decltype(getResolution()) i = 0; i <= m_res; i++) { m_points[i * m_size + 0] = edge[i]; checkMaxMin(edge[i]); } // calc right edge and copy into m_points fill1d(p2, p3, edge); for (decltype(getResolution()) i = 0; i <= m_res; i++) { m_points[i * m_size + m_res] = edge[i]; checkMaxMin(edge[i]); } // calc bottom edge and copy into m_points fill1d(p4, p3, edge); for (decltype(getResolution()) i = 0; i <= m_res; i++) { m_points[m_res * m_size + i] = edge[i]; checkMaxMin(edge[i]); } // seed the RNG - this is the 5th and last seeding for the tile. // it was seeded once for each edge, now once for the tile. //srand(p1.seed()*20 + p2.seed()*15 + p3.seed()*10 + p4.seed()*5); WFMath::MTRand::uint32 seed[4] = { p1.seed(), p2.seed(), p3.seed(), p4.seed() }; WFMath::MTRand rng(seed, 4); QuadInterp qi(m_res, p1.roughness(), p2.roughness(), p3.roughness(), p4.roughness()); float f = BasePoint::FALLOFF; float depth = 0; // center of m_points is done separately decltype(getResolution()) stride = m_res / 2; //float roughness = (p1.roughness+p2.roughness+p3.roughness+p4.roughness)/(4.0f); auto roughness = qi.calc(stride, stride); m_points[stride * m_size + stride] = qRMD(rng, m_points[0 * m_size + stride], m_points[stride * m_size + 0], m_points[stride * m_size + m_res], m_points[m_res * m_size + stride], roughness, f, depth); checkMaxMin(m_points[stride * m_size + stride]); stride >>= 1; // skip across the m_points and fill in the points // alternate cross and plus shapes. // this is a diamond-square algorithm. while (stride) { //Cross shape - + contributes to value at X //+ . + //. X . //+ . + for (decltype(getResolution()) i = stride; i < m_res; i += stride * 2) { for (decltype(getResolution()) j = stride; j < m_res; j += stride * 2) { roughness = qi.calc(i, j); m_points[j * m_size + i] = qRMD(rng, m_points[(i - stride) + (j + stride) * (m_size)], m_points[(i + stride) + (j - stride) * (m_size)], m_points[(i + stride) + (j + stride) * (m_size)], m_points[(i - stride) + (j - stride) * (m_size)], roughness, f, depth); checkMaxMin(m_points[j * m_size + i]); } } depth++; //Plus shape - + contributes to value at X //. + . //+ X + //. + . for (decltype(getResolution()) i = stride * 2; i < m_res; i += stride * 2) { for (decltype(getResolution()) j = stride; j < m_res; j += stride * 2) { roughness = qi.calc(i, j); m_points[j * m_size + i] = qRMD(rng, m_points[(i - stride) + (j) * (m_size)], m_points[(i + stride) + (j) * (m_size)], m_points[(i) + (j + stride) * (m_size)], m_points[(i) + (j - stride) * (m_size)], roughness, f, depth); checkMaxMin(m_points[j * m_size + i]); } } for (decltype(getResolution()) i = stride; i < m_res; i += stride * 2) { for (decltype(getResolution()) j = stride * 2; j < m_res; j += stride * 2) { roughness = qi.calc(i, j); m_points[j * m_size + i] = qRMD(rng, m_points[(i - stride) + (j) * (m_size)], m_points[(i + stride) + (j) * (m_size)], m_points[(i) + (j + stride) * (m_size)], m_points[(i) + (j - stride) * (m_size)], roughness, f, depth); checkMaxMin(m_points[j * m_size + i]); } } stride >>= 1; depth++; } delete[] edge; }
//---------------------------------------------------------- void ofConePrimitive::setMode( ofPrimitiveMode mode ) { ofPrimitiveMode currMode = getMesh().getMode(); if(currMode != mode) set( getRadius(), getHeight(), getResolution().x, getResolution().y, getResolution().z, mode ); }
//-------------------------------------------------------------- void ofBoxPrimitive::set( float width, float height, float depth ) { set( width, height, depth, getResolution().x, getResolution().y, getResolution().z ); }
//-------------------------------------------------------------- void ofConePrimitive::setHeight(float _height) { height = _height; setResolution(getResolution().x, getResolution().y, getResolution().z); }
double GR_Graphics::tluD(double deviceUnits) const { return (deviceUnits * static_cast<double>(getResolution()) / static_cast<double>(getDeviceResolution())) * 100.0 / static_cast<double>(getZoomPercentage()); }