[vtkusers] Read OBJ files from QResource file

Elvis Stansvik elvis.stansvik at orexplore.com
Fri Feb 26 08:43:42 EST 2016


Hi Rakesh,

2016-02-26 11:49 GMT+01:00 Rakesh Patil <rakesh.p at tataelxsi.co.in>:

> Dear users,
>
> I am trying to display a 3D object from OBJ file. I make use of
> vtkOBJReader to read the file. This works fine if I give the file name with
> absolute path. I am using QT as a GUI, and all my images/icons are stored
> in a resource (QResource(*.qrc)) file. I am able to read the images and
> icon from the resource file. But I am not able to read the OBJ file. Here
> is the code snippet to read image file from qrc file
> *QImage *image = new QImage(":/images/testImage.png");*
>
> On the similar lines, I want to get OBJ file, here is what I do:
> *QFile file(":/images/testObj.obj");*
>
> *vtkOBJReader *reader = vtkOBJReader::New();*
> *reader->SetFileName(file.fileName().toStdString().c_str());*
> *reader->Update();*
>
> While reader is calling Update function, it throws error message saying
> ":/images/testObj.obj" file not found. I would like to know, how to read an
> OBJ file from a resource file using vtkOBJReader.
>

The Qt resource system (.qrc files) is a Qt specific technology. I'm pretty
sure the VTK classes (such as vtkOBJReader) have no support for reading
from .qrc files. Your attempt with using QFile above won't help, the call
to fileName() will simply return ":/images/testObj.obj", which does not
exists in the file system (only in the .qrc namespace, which is Qt only).

You'll have to either save the file to a temporary location and open it
from there, or write your own reader which can read from Qt resources.

Hope that helps.

Elvis


>
> Thanks in advance
>
>
> Warm Regards
>
> Rakesh Patil
>
>
> Consultant
>
> Tata Elxsi
>
> Hoody, ITPB Road,
>
> Whitefield, Bangalore 560048
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160226/c2e489db/attachment-0001.html>


More information about the vtkusers mailing list