Displaying images from files

Hi everybody,

I need to introduce an image from a file in the Interactive Context and display it, I did this:

...

Handle(AIS_InteractiveContext) aContext;
aContext=Context;
OSD_Path aPath(((Imagen*)this)->Get_Path());
OSD_File aFile(aPath);
Handle(Graphic2d_GraphicObject) gr_obj=new Graphic2d_GraphicObject();
Quantity_Length X=0.0;
Quantity_Length Y= 0.0;
Quantity_Length adX= 0.0;
Quantity_Length adY= 0.0;
Quantity_Length aScale=1.0;
Handle(Graphic2d_ImageFile) image = new Graphic2d_ImageFile(gr_obj,aFile,X,Y,adX,adY,Aspect_CP_Center,aScale);
image->SetZoomable(Standard_True);
...

Probably, I have something wrong whit the Graphic2d_GraphicObject...I know that the displaying part is missing but I don't know if I have to use Prs3d_Presentation.

Thank you for your help.

Francois Lauzon's picture

Hi,
one way to do what you want in an 3D interactive context is to build a plane shape the size you want, and put a texture on it (your image file) using AIS_TexturedShape. I can post some code if that's something you might want.

Good Luck,
Francois.

Andrea's picture

Yes Francois, I would appreciate that!!!

Francois Lauzon's picture

Here is a quick sample, using an image that come with an OCC installation:

Standard_Integer aWidth,aHeight;
Handle_Image_Image anImage;
if (AlienImage::LoadImageFile("C:\\CAS5.2.3\\data\\images\\HCBKBCH.BMP",anImage,aWidth,aHeight)) {
BRepBuilderAPI_MakeFace aFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1)),0,Standard_Real(aWidth),0,Standard_Real(aHeight));
Handle_AIS_TexturedShape aTextShape=new AIS_TexturedShape(aFace.Shape());
aTextShape->SetTextureFileName("C:\\CAS5.2.3\\data\\images\\HCBKBCH.BMP");
aTextShape->SetTextureMapOn();
aTextShape->SetDisplayMode(3);
myContext->Display(aTextShape,Standard_False);
myContext->UpdateCurrentViewer();
}

Good Luck,
Francois.

Andrea's picture

Hi,

I had problems with the code you wrote. I changed a couple of lines and it compiled o.k. But when I execute the program an exception appears:

Standard_Integer aWidth,aHeight;
Handle(Image_Image) anImage;
if (AlienImage::LoadImageFile("/home/andrea/Logo.bmp",anImage,aWidth,aHeight))
{
//BRepBuilderAPI_MakeFace aFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1)),0,Standard_Real(aWidth),0,Standard_Real(aHeight));
TopoDS_Shape aFace= BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1)),0,Standard_Real(aWidth),0,Standard_Real(aHeight));
//Handle(AIS_TexturedShape) aTextShape=new AIS_TexturedShape(aFace.Shape());
Handle(AIS_TexturedShape) aTextShape=new AIS_TexturedShape(aFace);
aTextShape->SetTextureFileName("/home/andrea/Logo.bmp");
aTextShape->SetTextureMapOn();
aTextShape->SetDisplayMode(3);
aContext->Display(aTextShape,Standard_False);
aContext->UpdateCurrentViewer();

EXCEPTION:
The exception is:0x2a95a60ffa : Standard_NullObject: TCollection_AsciiString : parameter 'astring'

I really don't know what to do. Do you have any suggestions???

Thank you very much!!!

Francois Lauzon's picture

I don't know what might be causing this exception, but you could try to put a breakpoint on the constructors of the class Standard_Failure, and see where the exception is raise (you will have to use the debug libraries).

Good Luck,
Francois.

Andrea's picture

Hi Francois,

I've got this trouble:

Handle(Image_Image) anImage;
if (AlienImage::LoadImageFile("./Modulos.bak/Logo.bmp",anImage,aWidth,aHeight))
{
//BRepBuilderAPI_MakeFace aFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1)),0,Standard_Real(aWidth),0,Standard_Real(aHeight));
TopoDS_Shape aFace= BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1)),0,Standard_Real(aWidth),0,Standard_Real(aHeight));
Handle(AIS_TexturedShape) aTextShape=new AIS_TexturedShape(aFace);
aTextShape->SetTextureFileName("./Modulos.bak/Logo.bmp");
aTextShape->SetTextureMapOn();
aTextShape->SetDisplayMode(3);
aContext->Display(aTextShape,Standard_False);
aContext->UpdateCurrentViewer();
}
When I display the textured Shape, only appears the plane in the default color and material, but no Logo.bmp image. I read in other posts that theres a problem with the AIS_TexturedShape and materials but I don't know how to solve it.

Thanks for your answer