1 // File : FrontTrack_NodeGroups.cxx
2 // Created : Tue Apr 25 19:17:47 2017
3 // Author : Edward AGAPOV (eap)
5 #include "FrontTrack_NodeGroups.hxx"
6 #include "FrontTrack_Projector.hxx"
7 #include "FrontTrack_Utils.hxx"
9 #include <MEDCouplingMemArray.hxx>
10 #include <XAO_BrepGeometry.hxx>
11 #include <XAO_Xao.hxx>
13 #include <BRepBndLib.hxx>
14 #include <Bnd_Box.hxx>
16 #include <TopExp_Explorer.hxx>
17 #include <TopTools_IndexedMapOfShape.hxx>
18 #include <TopoDS_Shape.hxx>
22 //================================================================================
24 * \brief Initialize FT_Projector's with all sub-shapes of given type
25 * \param [in] theMainShape - the shape to explore
26 * \param [in] theSubType - the type of sub-shapes
27 * \param [out] theProjectors - the projectors
29 //================================================================================
31 void getProjectors( const TopoDS_Shape& theMainShape,
32 const TopAbs_ShapeEnum theSubType,
33 std::vector< FT_Projector > & theProjectors )
35 TopTools_IndexedMapOfShape subShapes;
36 TopExp::MapShapes( theMainShape, theSubType, subShapes );
38 theProjectors.resize( subShapes.Size() );
39 for ( int i = 1; i <= subShapes.Size(); ++i )
40 theProjectors[ i-1 ].setBoundaryShape( subShapes( i ));
44 //================================================================================
46 * \brief Load node groups from files
47 * \param [in] theNodeFiles - an array of names of files describing groups of nodes that
48 * will be moved onto geometry
49 * \param [in] theXaoGeom - the whole geometry to project on
50 * \param [inout] theNodeCoords - array of node coordinates
52 //================================================================================
54 void FT_NodeGroups::read( const std::vector< std::string >& theNodeFiles,
55 const XAO::Xao* theXao,
56 MEDCoupling::DataArrayDouble* theNodeCoords )
58 // get projectors for all boundary sub-shapes;
59 // index of a projector in the vector corresponds to a XAO index of a sub-shape
60 XAO::BrepGeometry* xaoGeom = dynamic_cast<XAO::BrepGeometry*>( theXao->getGeometry() );
61 getProjectors( xaoGeom->getTopoDS_Shape(), TopAbs_EDGE, _projectors[0] );
62 getProjectors( xaoGeom->getTopoDS_Shape(), TopAbs_FACE, _projectors[1] );
64 _nodesOnGeom.resize( theNodeFiles.size() );
66 // read node IDs and look for projectors to boundary sub-shapes by group name
67 FT_Utils::XaoGroups xaoGroups( theXao );
68 for ( size_t i = 0; i < theNodeFiles.size(); ++i )
70 _nodesOnGeom[i].read( theNodeFiles[i], xaoGroups, theNodeCoords, _projectors );
74 //================================================================================
76 * \brief Project and move nodes of a given group of nodes
78 //================================================================================
80 void FT_NodeGroups::projectAndMove( const int groupIndex )
82 _nodesOnGeom[ groupIndex ].projectAndMove();
85 //================================================================================
87 * \brief Return true if all nodes were successfully relocated
89 //================================================================================
91 bool FT_NodeGroups::isOK() const
93 for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
94 if ( ! _nodesOnGeom[ i ].isOK() )
100 //================================================================================
102 * \brief Print some statistics on node groups
104 //================================================================================
106 void FT_NodeGroups::dumpStat() const
108 for ( size_t i = 0; i < _nodesOnGeom.size(); ++i )
110 std::cout << _nodesOnGeom[i].getShapeDim() << "D "
111 << _nodesOnGeom[i].nbNodes() << " nodes" << std::endl;