0031478: Visualization, TKOpenGl - allow uploading Cubemap in compressed DDS format...
[occt.git] / samples / mfc / standard / Common / Primitive / Sample2D_Image.cpp
1 #include "stdafx.h"
2
3 #include "Sample2D_Image.h"
4
5 #include <Graphic3d_Texture2Dmanual.hxx>
6 #include <Image_AlienPixMap.hxx>
7
8 IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Image,AIS_Shape)
9
10 Sample2D_Image::Sample2D_Image(TCollection_AsciiString& aFileName,
11                                const Standard_Real X,
12                                const Standard_Real Y,
13                                const Standard_Real aScale)
14     :AIS_Shape(TopoDS_Shape())
15 {
16   myFilename = aFileName;
17   myX = X;
18   myY = Y;  
19   myScale = aScale;
20 }
21 void Sample2D_Image::MakeShape()
22 {
23   Standard_Real coeff = 1.0;
24   Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
25   if (anImage->Load (myFilename))
26   {
27     coeff = Standard_Real(anImage->Height()) / Standard_Real(anImage->Width()) * myScale;
28   }
29
30   TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(myX,myY,0.), gp_Pnt(100*myScale+myX,myY,0.));
31   TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(100*myScale+myX,myY,0.), gp_Pnt(100*myScale+myX,100*coeff+myY,0.));
32   TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(100*myScale+myX,100*coeff+myY,0.), gp_Pnt(myX,100*coeff+myY,0.));
33   TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt(myX,100*coeff+myY,0.), gp_Pnt(myX,myY,0.));
34   TopoDS_Wire anImageBounds = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);
35   myFace = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1)),anImageBounds);
36 }
37
38 void Sample2D_Image::SetContext(const Handle(AIS_InteractiveContext)& theContext) 
39 {
40   if(theContext.IsNull() || theContext->CurrentViewer().IsNull()) return;
41   AIS_InteractiveObject::SetContext(theContext);
42   MakeShape();
43   this->Set(TopoDS_Shape(myFace));
44   myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
45   Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual (myFilename);
46   aTexture->DisableModulate();
47   myDrawer->ShadingAspect()->Aspect()->SetTextureMap (aTexture);
48   myDrawer->ShadingAspect()->Aspect()->SetTextureMapOn();
49 }