For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

How can I display an Image (*.jpg, *.npg, etc ...) using an Occviewer.

Israel Machin Planas's picture

Hi, I am fresh new using Open Cascade Technologies, as the topic says, I am trying to display an Image in an Open Cascade viewer using Qt. I have tried using the AIS_TexturedShape and other functions, unsuccessfully.  My code is below, if anyone has any hint, comment, anything to help, it would be great.


   QString fileName = QFileDialog::getOpenFileName(this,tr("Open File"),"/home","Images (*.png *.jpg)");
   //QImage *anImage = new QImage(fileName);

   TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 60.0, 0.0), gp_Pnt(10.0, 60.0, 0.0));
   TopoDS_Shape aPrismEdge = BRepPrimAPI_MakePrism(anEdge, gp_Vec(0.0, 0.0, 5.0));
   Handle(AIS_Shape) anAisPrismEdge = new AIS_Shape(aPrismEdge);

   Handle (AIS_TexturedShape) anAisTexturePrismEdge = new AIS_TexturedShape(aPrismEdge);
   TCollection_AsciiString *asciiStringFile = new TCollection_AsciiString(fileName.toStdString().c_str());
   Handle(Image_AlienPixMap) myAlienPixMap = new Image_AlienPixMap();


  // myOccView->getContext()->SetDisplayMode(anAisTexturePrismEdge,3,Standard_True);




Kirill Gavrilov's picture

Do you see any errors in console, or have some crashes?
Have you built Open CASCADE Technology with FreeImage library enabled?
Have you checked if vtexture command works for you in Draw Harness?

Note that you don't have to use AIS_TexturedShape for displaying shape with a texture.
AIS_Shape is enough, but will need configuring presentation attributes in different way (see vtexture command implementation).

P.S.: don't use new for objects, which have not been declared as Handle() - these pointers will lead to memory leaks (like TCollection_AsciiString* in your sample).

Israel Machin Planas's picture

The application runs without any crash or error, not even warnings !! It displays a Surface in yellow color (color by default). If I may use an AIS_Shape, how can I modify its attributes ??, I see that the method "SetAttributes()" receives an AIS_Drawer, but an AIS_Drawer dont have any method that receives an AsciiString "FileName" for the surface mapping. As a I am very new using this libraries I am searching in the Documentation for functions and classes which can help me so I don't know how or where I can use "vtexture" commands, and also I do not use FreeImage library on Open Cascade Technology, I am currently using the version 7.1. Thanks for the warning about the pointer use without Handle, I'll take it in count.

Kirill Gavrilov's picture

"SetAttributes()" receives an AIS_Drawer

There is no class AIS_Drawer at least since OCCT 6.9.0 release.

also I do not use FreeImage library on Open Cascade Technology

You will not be able loading and storing images without FreeImage being enabled.

I don't know how or where I can use "vtexture" commands

Playing with Draw Harness is a good way to learn OCCT interactively (through it is implying entering commands into console or writing Tcl script).
Anyway - the source code of Draw Harness commands is a good way to know how to use particular functionality of OCCT.
Just grep "vtexture" through source code to find the command implementation.

I am currently using the version 7.1

OCCT 7.1 is an old release, it's AIS_Shape have no interface for setting textures - only AIS_TexturedShape does in old OCCT releases.
It is not recommended using old OCCT releases.