1 // Copyright (C) 2014-2022 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>
22 #include <BRep_Builder.hxx>
23 #include <BRepBuilderAPI_MakeFace.hxx>
24 #include <BRepBuilderAPI_MakePolygon.hxx>
25 #include <BRepBuilderAPI_MakeVertex.hxx>
26 #include <BRepBuilderAPI_Sewing.hxx>
28 #include <OSD_Path.hxx>
30 #include <TopoDS_Compound.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Shell.hxx>
35 #include <TopoDS_Vertex.hxx>
36 #include <TopoDS_Wire.hxx>
38 std::shared_ptr<GeomAPI_Shape> ImageImport(const int width,
40 std::string& theError)
42 TopoDS_Shape aResShape;
45 TopoDS_Vertex aTriVertexes[4];
46 gp_Pnt aPnt1( -0.5*width, -0.5*height, 0);
47 gp_Pnt aPnt2( 0.5*width, -0.5*height, 0);
48 gp_Pnt aPnt3( 0.5*width, 0.5*height, 0 );;
49 gp_Pnt aPnt4( -0.5*width, 0.5*height, 0 );
53 aTriVertexes[0] = BRepBuilderAPI_MakeVertex (aPnt1);
54 aTriVertexes[1] = BRepBuilderAPI_MakeVertex (aPnt2);
55 aTriVertexes[2] = BRepBuilderAPI_MakeVertex (aPnt3);
56 aTriVertexes[3] = BRepBuilderAPI_MakeVertex (aPnt4);
58 aWire = BRepBuilderAPI_MakePolygon (aTriVertexes[0], aTriVertexes[1], aTriVertexes[2],
59 aTriVertexes[3], Standard_True);
61 BRepBuilderAPI_Sewing aSewingTool;
62 aSewingTool.Init (1.0e-06, Standard_True);
64 TopoDS_Compound aComp;
65 BRep_Builder BuildTool;
66 BuildTool.MakeCompound(aComp);
70 aFace = BRepBuilderAPI_MakeFace (aWire);
73 BuildTool.Add (aComp, aFace);
77 aSewingTool.Load (aComp);
78 aSewingTool.Perform();
79 aResShape = aSewingTool.SewedShape();
80 if (aResShape.IsNull())
85 catch (Standard_Failure const& anException) {
86 theError = anException.GetMessageString();
90 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
91 aGeomShape->setImpl(new TopoDS_Shape(aResShape));