Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt3d timer and texture binding
Forum Updated to NodeBB v4.3 + New Features

Qt3d timer and texture binding

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 513 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sunil.nair
    wrote on 12 Dec 2014, 09:17 last edited by
    #1

    I am trying to update the texture image which will be bound to the cube. Bu, when I do this I cannot see anything on the screen.

    a. Constructor has a timer which calls the update action slot every 10 ms
    b. this slot gets the cursor position and reads a Mat image
    c. Now this function calls Mat to QImage function which sets the grayscale value of the image and returns a QImage
    d. This QImage is taken and binded on the cube in the paintgl code
    e. but the code doesn't work

    @QImage Mat2QImage(cv::Mat const& src, int i, int j)
    {
    //temp.at<uchar>(i, j) = 255; //white
    cv::Mat temp, result; // make the same cv::Mat
    //cv::cvtColor(src, temp,CV_BGR2RGB); // cvtColor Makes a copt, that what i need
    cv::cvtColor(src,temp,CV_BGR2GRAY);
    for(int row=i-10; row<i+10; row++)
    {
    for(int col=j-10;col<j+10;col++)
    {
    temp.at<uchar>(i,j)=255;
    }
    }
    cv::cvtColor(temp,result,CV_GRAY2RGB);
    QImage dest((const uchar *) result.data, result.cols, result.rows, result.step, QImage::Format_RGB888);
    dest.bits(); // enforce deep copy, see documentation
    // of QImage::QImage ( const uchar * data, int width, int height, Format format )
    return dest;
    }
    //! [1] constructor, initialize the cube, cursor and camera
    CubeView::CubeView(QWidget *parent)
    {
    //! [1]
    QVector3D *cube1_pos= new QVector3D(0.0,0.0,-1.5);
    QGLBuilder builder1;
    builder1 << QGL::Faceted;
    builder1 << QGLCube(3.25);
    cube = builder1.finalizedSceneNode();
    cube->setPosition(*cube1_pos);

    QGLBuilder cursor_builder;
    cursor_builder <<QGL::Faceted;
    cursor_builder <<QGLCube(0.25);
    cursor=cursor_builder.finalizedSceneNode();
    
    //camera setup
    camera()->setFieldOfView(25);
    camera()->setNearPlane(1);
    camera()->setFarPlane(15);
    

    //! [2] set texture for cube and cursor
    //QImage image(QLatin1String(":/bluecircle.jpg"));

    cv::Mat mat=cv::imread("C:/Qt/qt-qt3d/tutorials/qt3d/cube4/bluecircle.jpg");
    
    handcursor.setImage(QImage(QLatin1String(":/hand.jpg")));
    
    
    //timer to call the update action slot
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update_action()));
    timer->start(50);
    std::cout<<i<<j<<"\n";
    

    }
    //! [2] update the cursor based on the haptic position
    void CubeView::update_action()
    {
    //QMatrix4x4 mat;
    double position[3];
    drawcursor(position);//updating the new cursor co-ordinates
    QVector3D *p2=new QVector3D(position[0],position[1],position[2]);
    cursor->setPosition(*p2);

    int i=((position[0]+(gCubeEdgeLength/2))/gCubeEdgeLength)*imageDim;
    int j=((position[1]+(gCubeEdgeLength/2))/gCubeEdgeLength)*imageDim;
    cv::imshow("image",source);
    
    //QImage image  = Mat2QImage(source, i, j);
    //image.scaled(256,256,Qt::IgnoreAspectRatio);
    //logo.setImage(image);
    update();
    

    }@

    1 Reply Last reply
    0

    1/1

    12 Dec 2014, 09:17

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved