0029659: Samples - Image is not displayed in Viewer2d MFC sample
[occt.git] / samples / mfc / standard / Common / Primitive / Sample2D_Image.cpp
CommitLineData
7fd59977 1#include "stdafx.h"
2
3#include "Sample2D_Image.h"
7fd59977 4
a6dee93d 5#include <Graphic3d_Texture2Dmanual.hxx>
6
7IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Image,AIS_Shape)
7fd59977 8
5c1f974e 9Sample2D_Image::Sample2D_Image(TCollection_AsciiString& aFileName,
ee2be2a8 10 const Standard_Real X,
11 const Standard_Real Y,
12 const Standard_Real aScale)
a6dee93d 13 :AIS_Shape(TopoDS_Shape())
7fd59977 14{
5c1f974e 15 myFilename = aFileName;
16 myX = X;
17 myY = Y;
18 myScale = aScale;
7fd59977 19}
5c1f974e 20void Sample2D_Image::MakeShape()
7fd59977 21{
5c1f974e 22 Handle(Graphic3d_Texture1D) anImageTexture =
23 new Graphic3d_Texture1Dsegment(myFilename);
24 Standard_Real coeff = (Standard_Real)(anImageTexture->GetImage()->Height())/
25 (anImageTexture->GetImage()->Width())*myScale;
26 TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(myX,myY,0.), gp_Pnt(100*myScale+myX,myY,0.));
27 TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(100*myScale+myX,myY,0.), gp_Pnt(100*myScale+myX,100*coeff+myY,0.));
28 TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(100*myScale+myX,100*coeff+myY,0.), gp_Pnt(myX,100*coeff+myY,0.));
29 TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt(myX,100*coeff+myY,0.), gp_Pnt(myX,myY,0.));
30 TopoDS_Wire anImageBounds = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);
31 myFace = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1)),anImageBounds);
7fd59977 32}
33
5c1f974e 34void Sample2D_Image::SetContext(const Handle(AIS_InteractiveContext)& theContext)
7fd59977 35{
7fd59977 36 if(theContext.IsNull() || theContext->CurrentViewer().IsNull()) return;
5c1f974e 37 AIS_InteractiveObject::SetContext(theContext);
38 MakeShape();
39 this->Set(TopoDS_Shape(myFace));
a6dee93d 40 myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
759e2a15 41 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual (myFilename);
42 aTexture->DisableModulate();
43 myDrawer->ShadingAspect()->Aspect()->SetTextureMap (aTexture);
a6dee93d 44 myDrawer->ShadingAspect()->Aspect()->SetTextureMapOn();
7fd59977 45}