3 #include "Sample2D_Image.h"
5 IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Image,AIS_TexturedShape)
7 Sample2D_Image::Sample2D_Image(TCollection_AsciiString& aFileName,
10 const Standard_Real aScale)
11 :AIS_TexturedShape(TopoDS_Shape())
13 myFilename = aFileName;
18 void Sample2D_Image::MakeShape()
20 Handle(Graphic3d_Texture1D) anImageTexture =
21 new Graphic3d_Texture1Dsegment(myFilename);
22 Standard_Real coeff = (Standard_Real)(anImageTexture->GetImage()->Height())/
23 (anImageTexture->GetImage()->Width())*myScale;
24 TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(myX,myY,0.), gp_Pnt(100*myScale+myX,myY,0.));
25 TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(100*myScale+myX,myY,0.), gp_Pnt(100*myScale+myX,100*coeff+myY,0.));
26 TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(100*myScale+myX,100*coeff+myY,0.), gp_Pnt(myX,100*coeff+myY,0.));
27 TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt(myX,100*coeff+myY,0.), gp_Pnt(myX,myY,0.));
28 TopoDS_Wire anImageBounds = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);
29 myFace = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1)),anImageBounds);
32 void Sample2D_Image::SetContext(const Handle(AIS_InteractiveContext)& theContext)
34 if(theContext.IsNull() || theContext->CurrentViewer().IsNull()) return;
35 AIS_InteractiveObject::SetContext(theContext);
37 this->Set(TopoDS_Shape(myFace));
38 this->SetTextureFileName(myFilename);