Salome HOME
32b4ffce1f3c61120eb47d833c228f869e4a6f78
[modules/homard.git] / src / FrontTrack / FrontTrack_NodesOnGeom.hxx
1 // Copyright (C) 2017-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : FrontTrack_NodesOnGeom.hxx
20 // Created   : Tue Apr 25 19:12:25 2017
21 // Author    : Edward AGAPOV (eap)
22
23
24 #ifndef __FrontTrack_NodesOnGeom_HXX__
25 #define __FrontTrack_NodesOnGeom_HXX__
26
27 #include "FrontTrack_Projector.hxx"
28
29 #include <Bnd_Box.hxx>
30 #include <NCollection_DataMap.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TColStd_DataMapOfIntegerInteger.hxx>
33
34 #include <string>
35 #include <vector>
36
37 namespace FT_Utils {
38   struct XaoGroups;
39 }
40 namespace MEDCoupling {
41   class DataArrayDouble;
42 }
43 namespace XAO {
44   class BrepGeometry;
45 }
46
47   //--------------------------------------------------------------------------------------------
48 /*!
49  * \brief Node group and geometry to project onto
50  */
51 class FT_NodesOnGeom
52 {
53 public:
54
55   // read node IDs form a file and try to find a boundary sub-shape by name
56   void read( const std::string&            nodesFile,
57              const FT_Utils::XaoGroups&    xaoGroups,
58              MEDCoupling::DataArrayDouble* nodeCoords,
59              std::vector< FT_Projector > * allProjectorsByDim);
60
61   // chose boundary shapes by evaluating distance between nodes and shapes
62   //void choseShape( const std::vector< FT_Utils::ShapeAndBndBox >& shapeAndBoxList );
63
64   // project nodes to the shapes and move them to new positions
65   void projectAndMove();
66
67   // return true if all nodes were successfully relocated
68   bool isOK() const { return _OK; }
69
70   // return dimension of boundary shapes
71   int getShapeDim() const { return _shapeDim; }
72
73   // return nb of nodes to move
74   int nbNodes() const { return _nodes.size(); }
75
76
77 private:
78
79   // put nodes in the order for optimal projection
80   void putNodesInOrder();
81
82   // get node coordinates
83   gp_Pnt getPoint( const int nodeID );
84
85   // change node coordinates
86   void moveNode( const int nodeID, const gp_Pnt& xyz );
87
88
89   // Ids of a node to move and its 2 or 4 neighbors
90   struct FT_NodeToMove
91   {
92     int                _nodeToMove;
93     std::vector< int > _neighborNodes;
94
95     double             _params[2];   // parameters on shape (U or UV) found by projection
96     double            *_nearParams; // _params of a neighbor already projected node
97
98     FT_NodeToMove(): _nearParams(0) {}
99   };
100
101   std::vector< std::string >    _groupNames;
102   int                           _shapeDim;   // dimension of boundary shapes
103   std::vector< FT_NodeToMove >  _nodes;      // ids of nodes to move and their neighbors
104   std::vector< FT_Projector >   _projectors; // FT_Projector's initialized with boundary shapes
105   std::vector< FT_Projector > * _allProjectors; // FT_Projector's for all shapes of _shapeDim
106   MEDCoupling::DataArrayDouble* _nodeCoords;
107   bool                          _OK;          // projecting is successful 
108
109   // map of { FT_NodeToMove::_neighborNodes[i] } to { FT_NodeToMove* }
110   // this map is used to find neighbor nodes
111   typedef NCollection_DataMap< int, std::vector< FT_NodeToMove* > > TNodeIDToLinksMap;
112   TNodeIDToLinksMap             _neigborsMap;
113   std::vector<int>              _nodesOrder;
114
115 };
116
117 #endif