void LightDirection::mousePressEvent(QMouseEvent *event) { QPoint pos = event->pos(); int width = this->width(); int height = this->height(); float new_x = pos.x() * 2.0 / (float)width - 1; float new_y = pos.y() * 2.0 / (float)height - 1; Scene::getInstance()->lighting->dirLight.setDirectionX(new_x); Scene::getInstance()->lighting->dirLight.setDirectionZ(new_y); Mat sandbox_view = *Scene::getInstance()->getSandboxView(); cvtColor(sandbox_view, sandbox_view, CV_BGRA2RGB); Mat resized = Mat::zeros(sandbox_view.cols /3, sandbox_view.rows / 3, CV_8UC3); cv::resize(sandbox_view, resized, Size(resized.rows, resized.cols)); QImage q_image((uchar*)resized.data,resized.cols, resized.rows, resized.step, QImage::Format_RGB888); GlobalSettings::getInstance()->setLightDirectionX(new_x * 100); GlobalSettings::getInstance()->setLightDirectionZ(new_y * 100); lightPos = QPoint(event->pos()); toDraw = true; repaint(); }
void LightDirection::paintEvent(QPaintEvent *event) { QPainter painter(this); if (this->isEnabled()) { qDebug() << "We are here"; QPen pen; pen.setWidth(10); pen.setColor(Qt::red); painter.setPen(pen); Mat sandbox_view = *Scene::getInstance()->getSandboxView(); cvtColor(sandbox_view, sandbox_view, CV_BGRA2RGB); Mat resized = Mat::zeros(sandbox_view.cols /3, sandbox_view.rows / 3, CV_8UC3); cv::resize(sandbox_view, resized, Size(resized.rows, resized.cols)); flip(resized, resized, 0); QImage q_image((uchar*)resized.data,resized.cols, resized.rows, resized.step, QImage::Format_RGB888); painter.drawImage(0,0,q_image); painter.drawImage(lightPos.x() - light->width() / 2, lightPos.y() - light->height() / 2, *light); toDraw = false; painter.end(); } }
static void saveDepthImage(osg::Image* depth_image, const std::string& filename) { int width = depth_image->s(); int height = depth_image->t(); float z_min, z_max; z_min = std::numeric_limits<float>::max(); z_max = std::numeric_limits<float>::lowest(); float* z_buffer = (float*)(depth_image->data()); for (size_t x = 0; x < width; ++ x) { for (size_t y = 0; y < height; ++ y) { float z = z_buffer[y*width+x]; if (z == 1.0) continue; z_min = std::min(z_min, z); z_max = std::max(z_max, z); } } QImage q_image(width, height, QImage::Format_ARGB32); for (size_t x = 0; x < width; ++ x) { for (size_t y = 0; y < height; ++ y) { float z = z_buffer[y*width+x]; float value = (z==1.0)?(1.0):(z-z_min)*0.8/(z_max-z_min); value *= 255; QRgb rgba = QColor(value, value, value, (z==1.0)?(0):(255)).rgba(); q_image.setPixel(x, height-1-y, rgba); } } q_image.save(filename.c_str()); return; }
static void saveColorImage(osg::Image* color_image, osg::Image* depth_image, const std::string& filename) { int width = color_image->s(); int height = color_image->t(); float* z_buffer = (float*)(depth_image->data()); QImage q_image(width, height, QImage::Format_ARGB32); for (int x = 0; x < width; ++ x) { for (int y = 0; y < height; ++ y) { float z = z_buffer[y*width+x]; osg::Vec4 color = color_image->getColor(x, y); color = color*255; QRgb rgba = QColor(color.r(), color.g(), color.b(), (z==1.0)?(0):(255)).rgba(); q_image.setPixel(x, height-1-y, rgba); } } q_image.save(filename.c_str()); return; }
void Crop::setDepthMap(cv::Mat img) { QImage q_image((uchar*)img.data,img.cols, img.rows, img.step, QImage::Format_RGB888); depthmap = q_image; }