1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <GeomAlgoAPI_ImageImport.h>
23 #include <BRep_Builder.hxx>
24 #include <BRepBuilderAPI_MakeFace.hxx>
25 #include <BRepBuilderAPI_MakePolygon.hxx>
26 #include <BRepBuilderAPI_MakeVertex.hxx>
27 #include <BRepBuilderAPI_Sewing.hxx>
29 #include <OSD_Path.hxx>
31 #include <TopoDS_Compound.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Shell.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <TopoDS_Wire.hxx>
39 std::shared_ptr<GeomAPI_Shape> ImageImport(const std::string& theFileName,
40 std::string& theError)
42 TopoDS_Shape aResShape;
45 QPixmap* pixmap = new QPixmap(theFileName.c_str());
46 int height = pixmap->height();
47 int width = pixmap->width();
51 TopoDS_Vertex aTriVertexes[4];
52 gp_Pnt aPnt1( -0.5*width, -0.5*height, 0);
53 gp_Pnt aPnt2( 0.5*width, -0.5*height, 0);
54 gp_Pnt aPnt3( 0.5*width, 0.5*height, 0 );;
55 gp_Pnt aPnt4( -0.5*width, 0.5*height, 0 );
59 aTriVertexes[0] = BRepBuilderAPI_MakeVertex (aPnt1);
60 aTriVertexes[1] = BRepBuilderAPI_MakeVertex (aPnt2);
61 aTriVertexes[2] = BRepBuilderAPI_MakeVertex (aPnt3);
62 aTriVertexes[3] = BRepBuilderAPI_MakeVertex (aPnt4);
64 aWire = BRepBuilderAPI_MakePolygon (aTriVertexes[0], aTriVertexes[1], aTriVertexes[2],
65 aTriVertexes[3], Standard_True);
67 BRepBuilderAPI_Sewing aSewingTool;
68 aSewingTool.Init (1.0e-06, Standard_True);
70 TopoDS_Compound aComp;
71 BRep_Builder BuildTool;
72 BuildTool.MakeCompound(aComp);
76 aFace = BRepBuilderAPI_MakeFace (aWire);
79 BuildTool.Add (aComp, aFace);
83 aSewingTool.Load (aComp);
84 aSewingTool.Perform();
85 aResShape = aSewingTool.SewedShape();
86 if (aResShape.IsNull())
91 catch (Standard_Failure const& anException) {
92 theError = anException.GetMessageString();
96 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
97 aGeomShape->setImpl(new TopoDS_Shape(aResShape));