Salome HOME
c9788e204acafce3ed71e35c1a2a7e997280dcb7
[modules/hydro.git] / src / HYDROData / HYDROData_LandCoverMap.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROData_LandCoverMap.h>
20 #include <HYDROData_Object.h>
21 #include <HYDROData_PolylineXY.h>
22 #include <HYDROData_Tool.h>
23 #include <HYDROData_ShapeFile.h>
24 #include <HYDROData_Document.h>
25 #include <HYDROData_StricklerTable.h>
26 #include <HYDROData_ShapesTool.h>
27
28 #include <BOPAlgo_BOP.hxx>
29 #include <BOPAlgo_Builder.hxx>
30 #include <BOPAlgo_PaveFiller.hxx>
31 #include <BOPCol_ListOfShape.hxx>
32 #include <BRep_Builder.hxx>
33 #include <BRepAdaptor_Curve.hxx>
34 #include <BRepAlgoAPI_Fuse.hxx>
35 #include <BRepBuilderAPI_MakeFace.hxx>
36 #include <GCPnts_QuasiUniformDeflection.hxx>
37 #include <TopoDS.hxx>
38 #include <TopoDS_Compound.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Iterator.hxx>
42 #include <TopoDS_Shell.hxx>
43 #include <TopExp_Explorer.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
46 #include <TopTools_SequenceOfShape.hxx>
47 #include <BOPAlgo_PaveFiller.hxx>
48 #include <BRepTools.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <ShapeUpgrade_UnifySameDomain.hxx>
51 #include <TopExp.hxx>
52 #include <TopTools_IndexedMapOfShape.hxx>
53 #include <ShapeBuild_ReShape.hxx>
54 #include <ShapeFix_Shape.hxx>
55 #include <BRepCheck_Shell.hxx>
56 #include <BRepCheck_ListOfStatus.hxx>
57 #include <TopTools_SequenceOfShape.hxx>
58 #include <Handle_Geom_Curve.hxx>
59 #include <Handle_Geom_Line.hxx>
60 #include <Handle_Geom_TrimmedCurve.hxx>
61 #include <Geom_TrimmedCurve.hxx>
62 #include <TopTools_DataMapOfShapeListOfShape.hxx>
63 #include <NCollection_DoubleMap.hxx>
64 #include <HYDROData_LCM_FaceClassifier.h>
65 #include <QDir>
66
67 #include <stdexcept>
68
69 #include <QFile>
70 #include <QString>
71 #include <QTextStream>
72 #include <QFileInfo>
73
74 #define _DEVDEBUG_
75 #include "HYDRO_trace.hxx"
76
77 const char TELEMAC_FORMAT = 'f';
78 const int TELEMAC_PRECISION = 3;
79
80
81 IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
82 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
83
84 /**
85   Constructor
86   @param theMap the land cover map to iterate through
87 */
88 HYDROData_LandCoverMap::Explorer::Explorer( const HYDROData_LandCoverMap& theMap )
89 {
90   Init( theMap );
91 }
92
93 HYDROData_LandCoverMap::Explorer::Explorer( const Handle( HYDROData_LandCoverMap )& theMap )
94 {
95   if( theMap.IsNull() )
96   {
97     myExplorer = 0;
98     myIndex = -1;
99   }
100   else
101     Init( *theMap );
102 }
103
104 /**
105   Initialize the iterator
106   @param theMap the land cover map to iterate through
107 */
108 void HYDROData_LandCoverMap::Explorer::Init( const HYDROData_LandCoverMap& theMap )
109 {
110   TopoDS_Shape aShape = theMap.GetShape();
111   if( aShape.IsNull() )
112     myExplorer = 0;
113   else
114   {
115     myExplorer = new TopExp_Explorer();
116     myExplorer->Init( aShape, TopAbs_FACE );
117   }
118   
119   theMap.myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), myArray );
120   if( myArray.IsNull() )
121     myIndex = -1;
122   else
123     myIndex = myArray->Lower();
124 }
125
126 /**
127   Destructor
128 */
129 HYDROData_LandCoverMap::Explorer::~Explorer()
130 {
131   delete myExplorer;
132 }
133
134 /**
135   Return the current 0-based index of the iterator
136   @return the current index
137 */
138 int HYDROData_LandCoverMap::Explorer::Index() const
139 {
140   if( myArray.IsNull() )
141     return -1;
142   else
143     return myIndex - myArray->Lower();
144 }
145
146 /**
147   Return if the iterator has more elements
148   @return if the iterator has more elements
149 */
150 bool HYDROData_LandCoverMap::Explorer::More() const
151 {
152   return !myArray.IsNull() && myExplorer && myExplorer->More();
153 }
154
155 /**
156   Move iterator to the next element
157 */
158 void HYDROData_LandCoverMap::Explorer::Next()
159 {
160   if( myExplorer )
161   {
162     myExplorer->Next();
163     myIndex++;
164   }
165 }
166
167 /**
168   Get the current land cover (face)
169   @return the land cover's face
170 */
171 TopoDS_Face HYDROData_LandCoverMap::Explorer::Face() const
172 {
173   if( myExplorer )
174     return TopoDS::Face( myExplorer->Current() );
175   else
176     return TopoDS_Face();
177 }
178
179 /**
180   Get the current land cover's Strickler type 
181   @return the land cover's Strickler type 
182 */
183 QString HYDROData_LandCoverMap::Explorer::StricklerType() const
184 {
185   if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
186     return "";
187   else
188     return HYDROData_Tool::toQString( myArray->Value( myIndex ) );
189 }
190
191 /**
192   Set the Strickler type for the current land cover
193   @param theType the Strickler type
194 */
195 void HYDROData_LandCoverMap::Explorer::SetStricklerType( const QString& theType )
196 {
197   if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
198     return;
199   else
200     myArray->SetValue( myIndex, HYDROData_Tool::toExtString( theType ) );
201 }
202
203 /**
204   Constructor
205 */
206 HYDROData_LandCoverMap::HYDROData_LandCoverMap()
207   : HYDROData_Entity( Geom_No )
208 {
209 }
210
211 /**
212   Destructor
213 */
214 HYDROData_LandCoverMap::~HYDROData_LandCoverMap()
215 {
216 }
217
218 /**
219   Get object's kind
220   @return object's kind
221 */
222 const ObjectKind HYDROData_LandCoverMap::GetKind() const
223 {
224   return KIND_LAND_COVER_MAP;
225 }
226
227 int HYDROData_LandCoverMap::GetLCCount() const
228 {
229   Explorer anIt( *this );
230   int i = 0;
231   for( ; anIt.More(); anIt.Next() )
232     i++;
233   return i;
234 }
235
236 bool HYDROData_LandCoverMap::IsEmpty() const
237 {
238   Explorer anIt( *this );
239   if ( !anIt.More() )
240     return true;
241   else
242     return false;
243 }
244
245 /**
246   Load attributes from DBF File
247 ///
248 */
249 HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QString& theDBFFileName, 
250                                                                      const QString& theFieldName, 
251                                                                      const QStringList& theDBFValues,
252                                                                      const QStringList& theStricklerTypes,
253                                                                      const QList<int>& theIndices )
254 {
255   if (theDBFValues.size() != theStricklerTypes.size())
256     return DBFStatus_DIFF_SIZE_ERROR;
257   HYDROData_ShapeFile aDBFImporter;
258   if (!aDBFImporter.DBF_OpenDBF(theDBFFileName))
259     return DBFStatus_OPEN_FILE_ERROR; //cant open file
260
261   QStringList FieldList = aDBFImporter.DBF_GetFieldList();
262   int FieldNameIndex = FieldList.indexOf(theFieldName);
263   if (FieldNameIndex == -1)
264     return DBFStatus_NO_SUCH_FIELD_ERROR; //no such field
265
266   std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
267   aDBFImporter.DBF_GetAttributeList(FieldNameIndex, theAttrV ); 
268
269   bool allOK = true;
270   Explorer anIt( *this );
271   for( ; anIt.More(); anIt.Next() )
272   {
273     int CurIndex = anIt.Index();
274     int anIndex = CurIndex;
275     if( !theIndices.isEmpty() )
276       anIndex = theIndices[CurIndex];
277
278     HYDROData_ShapeFile::DBF_AttrValue AValue = theAttrV[anIndex];
279     int StricklerTypesInd = theDBFValues.indexOf( QString( AValue.myStrVal ) );
280     if ( StricklerTypesInd != -1)
281       anIt.SetStricklerType( theStricklerTypes[StricklerTypesInd] );
282     else
283       allOK = false;
284   }
285   if (allOK)
286     return DBFStatus_OK;
287   else
288     return DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING;
289 }
290
291 /**
292   Export attributes to DBF File
293 ///
294 */
295 void HYDROData_LandCoverMap::ExportDBF( const QString& theDBFFileName, 
296                                         const QString& theFieldName, 
297                                         const QStringList& theDBFValues,
298                                         const QStringList& theStricklerTypes) const
299 {
300   if (theDBFValues.size() != theStricklerTypes.size())
301     return;
302   HYDROData_ShapeFile anExporter; 
303   std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
304   Explorer anIt( *this );
305   for( ; anIt.More(); anIt.Next() )
306   {
307     QString CurST = anIt.StricklerType();
308     HYDROData_ShapeFile::DBF_AttrValue aCurAttrV;
309     aCurAttrV.myIsNull = false;
310     int StricklerTypesInd = theStricklerTypes.indexOf(CurST);
311     if (StricklerTypesInd != -1)
312     {
313       aCurAttrV.myStrVal = theDBFValues[StricklerTypesInd];
314       aCurAttrV.myFieldType = HYDROData_ShapeFile::DBF_FieldType_String;
315       theAttrV.push_back(aCurAttrV);
316     }
317     else
318       aCurAttrV.myIsNull = true;
319   }
320   //use actual str value; not the raw value
321   anExporter.DBF_WriteFieldAndValues(theDBFFileName, theFieldName, HYDROData_ShapeFile::DBF_FieldType_String, theAttrV, false);
322
323 }
324
325 int HashCode( const gp_Pnt& thePoint, const Standard_Integer theUpper )
326 {
327   int aHashX = HashCode( thePoint.X(), theUpper );
328   int aHashY = HashCode( thePoint.Y(), theUpper );
329   return (aHashX^aHashY)%theUpper;
330 }
331
332 bool operator == ( const gp_Pnt& thePoint1, const gp_Pnt& thePoint2 )
333 {
334   return thePoint1.IsEqual( thePoint2, Precision::Confusion() );
335 }
336
337 bool EdgeDiscretization( const TopoDS_Edge& theEdge, 
338                          Standard_Real theDeflection,
339                          NCollection_IndexedMap<gp_Pnt>& theVerticesMap,
340                          QList<int>& theVerticesIds )
341 {
342   BRepAdaptor_Curve aCurve( theEdge );
343   GCPnts_QuasiUniformDeflection aDiscrete( aCurve, theDeflection );
344   if( !aDiscrete.IsDone() )
345     return false;
346
347   int n = aDiscrete.NbPoints();
348   for( int i=1; i<=n; i++ )
349   {
350     gp_Pnt aPnt = aDiscrete.Value( i );
351     int anId;
352     if( theVerticesMap.Contains( aPnt ) )
353       anId = theVerticesMap.FindIndex( aPnt );
354     else
355     {
356       anId = theVerticesMap.Size();
357       theVerticesMap.Add( aPnt );
358     }
359     theVerticesIds.append( anId );
360   }
361   return true;
362 }
363
364 /**
365   Export the land cover map for the solver (Telemac)
366   @param theFileName the name of file
367   @return if the export is successful
368 */
369 bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName,
370                                             double theDeflection,
371                                             const Handle(HYDROData_StricklerTable)& theTable,
372                                             QString& statMessage) const
373 {
374   TopoDS_Shape aLandCoverMapShape = GetShape();
375   TopTools_ListOfShape aListOfFaces;
376   Explorer anIt( *this );
377   QMap<Handle(TopoDS_TShape), QString> aTypesMap;
378   for( ; anIt.More(); anIt.Next() )
379   {
380     aListOfFaces.Append( anIt.Face() );
381     aTypesMap.insert( anIt.Face().TShape(), anIt.StricklerType() );
382   }
383
384   TopoDS_Shape aShape = MergeFaces( aListOfFaces, false, NULL );
385
386   NCollection_IndexedMap<gp_Pnt> aVerticesMap;
387   NCollection_IndexedDataMap< TopoDS_Edge, QList<int> > anEdgesMap;
388   typedef QPair< QString, QList<int> > FaceData;
389   NCollection_IndexedDataMap< TopoDS_Face, FaceData > aFacesMap;
390
391   // add into the map all edges existing in the shell
392   TopExp_Explorer anExp1( aShape, TopAbs_EDGE );
393   for( ; anExp1.More(); anExp1.Next() )
394   {
395     TopoDS_Edge anEdge = TopoDS::Edge( anExp1.Current() );
396     QList<int> aVerticesIdsList;
397     if( EdgeDiscretization( anEdge, theDeflection, aVerticesMap, aVerticesIdsList ) )
398       anEdgesMap.Add( anEdge, aVerticesIdsList );
399   }
400
401   // add into the map all faces existing in the shell and correspondence between face and edges ids
402   TopExp_Explorer anExp2( aShape, TopAbs_FACE );
403   for( ; anExp2.More(); anExp2.Next() )
404   {
405     TopoDS_Face aFace = TopoDS::Face( anExp2.Current() );
406     TopExp_Explorer anExp3( aFace, TopAbs_EDGE );
407     QList<int> anEdgesIdsList;
408     for( ; anExp3.More(); anExp3.Next() )
409     {
410       TopoDS_Edge anEdge = TopoDS::Edge( anExp3.Current() );
411       int anEdgeId = anEdgesMap.FindIndex( anEdge );
412       anEdgesIdsList.append( anEdgeId );
413     }
414
415     FaceData aData;
416     aData.first = aTypesMap[aFace.TShape()];
417     aData.second = anEdgesIdsList;
418     aFacesMap.Add( aFace, aData );
419   }
420
421   QFile aFile( theFileName );
422   if( !aFile.open( QFile::WriteOnly | QFile::Text ) )
423   {
424     QString homeDirPath = QDir::homePath();
425     aFile.setFileName(homeDirPath);
426     if (aFile.open( QFile::WriteOnly | QFile::Text ) )
427       statMessage = "Telemac file have been exported to the home directory:" + homeDirPath;
428     else
429       return false;
430   }
431   else
432     statMessage = "Telemac file have been exported to the current directory";
433
434   QTextStream aStream( &aFile );
435   aStream << "# nodes\n";
436   NCollection_IndexedMap<gp_Pnt>::Iterator anIt1( aVerticesMap );
437   for( ; anIt1.More(); anIt1.Next() )
438   {
439     gp_Pnt aPnt = anIt1.Value();
440     aStream << QString::number( aPnt.X(), TELEMAC_FORMAT, TELEMAC_PRECISION );
441     aStream << " ";
442     aStream << QString::number( aPnt.Y(), TELEMAC_FORMAT, TELEMAC_PRECISION );
443     aStream << " ";
444     aStream << QString::number( aPnt.Z(), TELEMAC_FORMAT, TELEMAC_PRECISION );
445     aStream << "\n";
446   }
447   aStream << "\n";
448
449   aStream << "# edges\n";
450   NCollection_IndexedDataMap< TopoDS_Edge, QList<int> >::Iterator anIt2( anEdgesMap );
451   for( ; anIt2.More(); anIt2.Next() )
452   {
453     QList<int> aVerticesIds = anIt2.Value();
454     foreach( int anId, aVerticesIds )
455       aStream << anId << " ";
456     aStream << "\n";
457   }
458   aStream << "\n";
459
460   aStream << "# faces\n";
461   NCollection_IndexedDataMap< TopoDS_Face, FaceData >::Iterator anIt3( aFacesMap );
462   for( ; anIt3.More(); anIt3.Next() )
463   {
464     QString aType = anIt3.Value().first;
465     double aCoeff = theTable->Get( aType, 0.0 );
466     QList<int> anEdgesIds = anIt3.Value().second;
467     //aStream << "\"" << aType << "\" ";
468     aStream << QString::number( aCoeff, TELEMAC_FORMAT, TELEMAC_PRECISION ) << " ";
469     foreach( int anId, anEdgesIds )
470       aStream << anId << " ";
471     aStream << "\n";
472   }
473   aStream << "\n";
474
475   aFile.close();
476   return true;
477 }
478
479 /**
480   Add a new object as land cover
481   @param theObject the object to add as land cover
482   @param theType the Strickler type for the new land cover
483   @return if the addition is successful
484 */
485 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Object )& theObject, const QString& theType )
486 {
487   if( theObject.IsNull() )
488     return false;
489
490   TopoDS_Shape aShape = theObject->GetTopShape();
491   TopoDS_Face aFace;
492
493   if( aShape.ShapeType() ==TopAbs_FACE )
494   {
495     aFace = TopoDS::Face(aShape);
496   }
497   else if ( aShape.ShapeType() ==TopAbs_COMPOUND )
498   {
499     TopoDS_Iterator It(aShape);
500     for (; It.More(); It.Next())
501       if (It.Value().ShapeType() == TopAbs_FACE)
502       {
503         aFace = TopoDS::Face(It.Value());
504         break;
505       }
506   }
507
508   if (aFace.IsNull())
509     return false;
510   return LocalPartition( aFace, theType );
511 }
512
513 bool HYDROData_LandCoverMap::Add( const TopoDS_Wire& theWire, const QString& theType )
514 {
515   if( !theWire.Closed() )
516     return false;
517
518   TopoDS_Face aFace = BRepBuilderAPI_MakeFace( theWire, Standard_True ).Face();
519   return LocalPartition( aFace, theType );
520 }
521
522 /**
523   Add a new polyline as land cover
524   @param thePolyline the polyline to add as land cover
525   @param theType the Strickler type for the new land cover
526   @return if the addition is successful
527 */
528 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_PolylineXY )& thePolyline, const QString& theType )
529 {
530   if( thePolyline.IsNull() )
531     return false;
532
533   TopoDS_Shape aShape = thePolyline->GetShape();
534   if( aShape.ShapeType()==TopAbs_WIRE )
535     return Add( TopoDS::Wire( aShape ), theType );
536
537   if( aShape.ShapeType()==TopAbs_COMPOUND )
538   {
539     TopExp_Explorer anExp( aShape, TopAbs_WIRE );
540     for( ; anExp.More(); anExp.Next() )
541     {
542       TopoDS_Wire aPart = TopoDS::Wire( anExp.Current() );
543       if( !Add( aPart, theType ) )
544         return false;
545     }
546     return true;
547   }
548
549   return false;
550 }
551
552 /**
553   Remove the given face from land cover map
554   @param theFace the face to be removed
555   @return if the removing is successful
556 */
557 bool HYDROData_LandCoverMap::Remove( const TopoDS_Face& theFace )
558 {
559   TopTools_ListOfShape aList;
560   aList.Append( theFace );
561   return Remove( aList );
562 }
563
564 /**
565   Remove the given faces from land cover map
566   @param theFacesToRemove the face list to be removed
567   @return if the removing is successful
568 */
569 bool HYDROData_LandCoverMap::Remove( const TopTools_ListOfShape& theFacesToRemove )
570 {
571   HYDROData_MapOfFaceToStricklerType aFacesToRemove, aNewFaces;
572   TopTools_ListIteratorOfListOfShape aFIt( theFacesToRemove );
573   for( ; aFIt.More(); aFIt.Next() )
574   {
575     TopoDS_Shape aShape = aFIt.Value();
576     if( aShape.ShapeType()==TopAbs_FACE )
577       aFacesToRemove.Add( TopoDS::Face( aShape ), "" );
578   }
579
580   Explorer anIt( *this );
581   for( ; anIt.More(); anIt.Next() )
582     if( !aFacesToRemove.Contains( anIt.Face() ) )
583       aNewFaces.Add( anIt.Face(), anIt.StricklerType() );
584
585   if ( aNewFaces.IsEmpty() )
586     return false;
587
588   StoreLandCovers( aNewFaces );
589   return true;
590 }
591
592 /**
593   Split the land cover map by the given polyline
594   @param thePolyline the tool polyline to split the land cover map
595   @return if the removing is successful
596 */
597 bool HYDROData_LandCoverMap::Split( const Handle( HYDROData_PolylineXY )& thePolyline )
598 {
599   if( thePolyline.IsNull() )
600     return false;
601
602   TopoDS_Shape aShape = thePolyline->GetShape();
603   return Split( aShape );
604 }
605
606
607 /**
608   Split the land cover map by the given polyline
609   @param theShape the tool polyline to split the land cover map
610   @return if the removing is successful
611 */
612 bool HYDROData_LandCoverMap::Split( const TopoDS_Shape& theShape )
613 {
614   int aNbCL = GetLCCount();
615   bool aResult = LocalPartition( theShape, "" );
616   return aResult && aNbCL != GetLCCount();
617 }
618
619
620 /**
621   Merge the given faces in the land cover
622   @param theFaces the faces to merge in the land cover map
623   @param theType the Strickler type for the merged land cover
624   @return if the merge is successful
625 */
626 bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const QString& theType )
627 {
628   // 1. to fuse the faces into the new face
629   TopoDS_Shape aMergedFace = MergeFaces( theFaces, true, NULL );  
630   bool aStat = true;
631   if( !aMergedFace.IsNull() )
632   { 
633     // 2. to remove the merged faces from the current map
634     Remove( theFaces );
635     TopExp_Explorer Exp(aMergedFace, TopAbs_FACE);
636     for( ; Exp.More(); Exp.Next() )
637     {
638       const TopoDS_Face& aCF = TopoDS::Face(Exp.Current());
639       // 3. to add the face into the map
640       aStat = aStat && LocalPartition( aCF, theType );
641     }
642   }
643   else
644     aStat = false;
645   return aStat;
646 }
647
648 /**
649   Merge the given faces into the shell/face
650   @param theFaces the faces to merge
651   @param IsToUnify if the common edges should be removed (fused)
652   @param theTolerance the operation's tolerance
653   @return result shape (face or shell)
654 */
655  
656 TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& theFaces,
657                                                  bool IsToUnify, 
658                                                  TopTools_IndexedDataMapOfShapeListOfShape* theShHistory, 
659                                                  double theTolerance)
660 {
661   //DEBTRACE("MergeFaces");
662   int anError;
663   TopTools_ListIteratorOfListOfShape anIt;
664   BOPCol_ListOfShape aLC;
665   anIt.Initialize(theFaces);
666   for( ; anIt.More(); anIt.Next() )
667   {
668     if (anIt.Value().ShapeType() != TopAbs_FACE)
669       return TopoDS_Shape();
670     aLC.Append( anIt.Value() );
671   }
672
673   BOPAlgo_PaveFiller aPF;
674   aPF.SetArguments( aLC );
675   aPF.SetRunParallel( Standard_False );
676   aPF.SetFuzzyValue( theTolerance );
677
678   aPF.Perform();
679   anError = aPF.ErrorStatus();
680   if( anError )
681     return TopoDS_Shape();
682
683   BOPAlgo_Builder anAlgo;
684   anIt.Initialize( theFaces );
685   for( ; anIt.More(); anIt.Next() )
686     anAlgo.AddArgument( anIt.Value() );
687
688   anAlgo.PerformWithFiller( aPF ); 
689   anError = anAlgo.ErrorStatus();
690   if( anError )
691     return TopoDS_Shape();
692
693   const TopoDS_Shape& aMergedShape = anAlgo.Shape();
694
695   // retrieve history of modifications
696   if (theShHistory)
697   {
698     theShHistory->Clear();
699     anIt.Initialize(theFaces);
700     for( ; anIt.More(); anIt.Next() )
701     {
702       const TopTools_ListOfShape aMLS = anAlgo.Modified( anIt.Value() );
703       theShHistory->Add(anIt.Value(), aMLS);
704     }
705   }
706   //
707
708   BRep_Builder aBuilder;
709   TopoDS_Shell aShell; 
710   aBuilder.MakeShell( aShell ); 
711   aShell.Closed( Standard_False );
712   TopExp_Explorer anExplorer( aMergedShape, TopAbs_FACE );
713   for( ; anExplorer.More(); anExplorer.Next() ) 
714   {
715     const TopoDS_Face& aFace = TopoDS::Face(anExplorer.Current());
716     if( aFace.IsNull() ) 
717       continue;
718     if( aFace.ShapeType() == TopAbs_FACE )
719     {
720       aBuilder.Add( aShell, aFace );
721       aShell.Closed( Standard_False );
722     }
723   }
724
725   TopoDS_Shape aResult;
726   if( IsToUnify )
727   {
728     ShapeUpgrade_UnifySameDomain aUSD;
729     aUSD.Initialize( aShell );
730     aUSD.Build();
731     aResult = aUSD.Shape();
732   }
733   else
734     aResult = aShell;
735
736   anExplorer.Init( aResult, TopAbs_FACE );
737   int n = 0;
738   TopoDS_Face anOneFace;
739   for( ; anExplorer.More(); anExplorer.Next(), n++ ) 
740     anOneFace = TopoDS::Face( anExplorer.Current() );
741
742   if (n == 1)
743     aResult = anOneFace;
744   else if (aResult.ShapeType() == TopAbs_SHELL)
745   {
746     BRepCheck_Shell aBCS(TopoDS::Shell(aResult));
747     if (aBCS.Status().First() != BRepCheck_NoError)
748     {
749       ShapeFix_Shell aFixer;
750       aFixer.FixFaceOrientation(TopoDS::Shell(aResult), 1);
751       aResult = aFixer.Shape();
752     }
753   }
754
755   return aResult;
756 }
757 /**
758   Change Strickler type for the list of faces to the given one
759   @param theFaces the faces to change type
760   @param theType the Strickler type for the given land cover(s)
761   @return if the change type operation is successful
762 */
763 bool HYDROData_LandCoverMap::ChangeType( const TopTools_ListOfShape& theFaces, const QString& theType )
764 {
765   HYDROData_MapOfFaceToStricklerType aFacesToChangeType;
766   TopTools_ListIteratorOfListOfShape aFIt( theFaces );
767   for( ; aFIt.More(); aFIt.Next() )
768   {
769     TopoDS_Shape aShape = aFIt.Value();
770     if( aShape.ShapeType()==TopAbs_FACE )
771       aFacesToChangeType.Add( TopoDS::Face( aShape ), "" );
772   }
773
774   int aNbChanges = 0;
775   Explorer anIt( *this );
776   for( ; anIt.More(); anIt.Next() )
777     if( aFacesToChangeType.Contains( anIt.Face() ) )
778     {
779       anIt.SetStricklerType( theType );
780       aNbChanges++;
781     }
782   if ( aNbChanges != theFaces.Extent() )
783     return false;
784
785   return true;
786 }
787
788 /**
789   Get the shape of the land cover map
790 */
791 TopoDS_Shape HYDROData_LandCoverMap::GetShape() const
792 {
793   return HYDROData_Entity::GetShape( DataTag_Shape );
794 }
795
796 /**
797   Get Strickler type of the given land cover
798   @param theLandCover the land cover to get Strickler type of
799   @return name of Strickler type
800 */
801 QString HYDROData_LandCoverMap::StricklerType( const TopoDS_Face& theLandCover ) const
802 {
803   QString aType = "";
804
805   Explorer anIt( *this );
806   for( ; anIt.More(); anIt.Next() )
807     if( anIt.Face().IsEqual( theLandCover) )
808     {
809       aType = anIt.StricklerType();
810       break;
811     }
812
813   return aType;
814 }
815
816 /**
817   Set the shape of the land cover map
818   @param theShape the new shape for the land cover map
819 */
820 void HYDROData_LandCoverMap::SetShape( const TopoDS_Shape& theShape )
821 {
822   HYDROData_Entity::SetShape( DataTag_Shape, theShape );
823 }
824
825 /**
826   Perform the local partition algorithm on the land cover
827   @param theNewShape the new shape to add into the land cover
828   @param theNewType the new Strickler type for the new land cover
829   @return if the local partition is successful
830 */
831 bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, const QString& theNewType )
832 {
833   if( theNewShape.IsNull() )
834     return false;
835
836   BOPCol_ListOfShape aShapesList;
837   BOPAlgo_PaveFiller aPaveFiller;
838   HYDROData_MapOfFaceToStricklerType aNewFaces;
839
840   // add faces to shapes list
841   Explorer anIt( *this );
842   for( ; anIt.More(); anIt.Next() )
843     aShapesList.Append( anIt.Face() );
844   aShapesList.Append( theNewShape );
845
846   //DEBTRACE("theNewType " << theNewType);
847   if( aShapesList.Size()==1 && theNewShape.ShapeType()==TopAbs_FACE )
848   {
849     aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
850     StoreLandCovers( aNewFaces );
851     return true;
852   }
853
854   // prepare pave filler
855   aPaveFiller.SetArguments( aShapesList );
856   aPaveFiller.Perform();
857   Standard_Integer anError = aPaveFiller.ErrorStatus();
858   if( anError )
859     return false;
860
861   // add faces to builder
862   BOPAlgo_Builder aBuilder;
863   anIt.Init( *this );
864   for( ; anIt.More(); anIt.Next() )
865     aBuilder.AddArgument( anIt.Face() );
866   aBuilder.AddArgument( theNewShape );
867
868   // perform the partition with the pave filler
869   aBuilder.PerformWithFiller( aPaveFiller );
870   anError = aBuilder.ErrorStatus();
871   if( anError )
872     return false;
873
874   //std::cout << "History:" << std::endl;
875   // analysis of the history
876   //     a. to fill map of shapes which come from the new face
877   NCollection_IndexedMap<int> aShapesFromNewFace;
878   //std::cout << "from NEW " << theNewShape << ":" << theNewType << std::endl;
879   TopTools_ListOfShape aModified = aBuilder.Modified( theNewShape );
880   TopTools_ListIteratorOfListOfShape aMIt( aModified );
881   for( ; aMIt.More(); aMIt.Next() )
882   {
883     //std::cout << "   " << aMIt.Value() << std::endl;
884     //DEBTRACE(aMIt.Value());
885     int aKey = (int)(uintptr_t)aMIt.Value().TShape().operator->();
886     aShapesFromNewFace.Add( aKey );
887   }
888
889   //     b. to fill map of parts except parts from new face
890   anIt.Init( *this );
891   for( ; anIt.More(); anIt.Next() )
892   {
893     QString aSType = anIt.StricklerType();
894     //DEBTRACE(anIt.StricklerType() << " " << anIt.Face());
895     //std::cout << "from " << anIt.Face() << ": " << anIt.StricklerType() << std::endl;
896     TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() );
897     //
898     if( aModified.Extent() == 0 )
899       aModified.Append( anIt.Face() );
900     //DEBTRACE(anIt.StricklerType() << " " << anIt.Face());
901
902     TopTools_ListIteratorOfListOfShape aMIt( aModified );
903     for( ; aMIt.More(); aMIt.Next() )
904     {
905       TopoDS_Shape aShape = aMIt.Value();
906       bool isFace = aShape.ShapeType()==TopAbs_FACE;
907       int aKey = (int)(uintptr_t)aShape.TShape().operator->();
908       bool isAlsoFromNew = aShapesFromNewFace.Contains( aKey );
909       //std::cout << "   " << aShape << " " << isAlsoFromNew << std::endl;
910       if( isFace && !isAlsoFromNew )
911         aNewFaces.Add( TopoDS::Face( aShape ), aSType );
912     }
913     //DEBTRACE(anIt.StricklerType() << " " << anIt.Face());
914   }
915   //     c. add the new shape if it is face with its type
916   if( theNewShape.ShapeType()==TopAbs_FACE )
917     aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
918   //DEBTRACE(theNewShape << " " << theNewType);
919   
920   // convert map of shape to type to compound and list of types
921   StoreLandCovers( aNewFaces );
922
923 //  anIt.Init( *this );
924 //  for( ; anIt.More(); anIt.Next() )
925 //  {
926 //     DEBTRACE(anIt.StricklerType() << " " << anIt.Face());
927 //  }
928   return true;
929 }
930
931 /**
932   Replace the set of land covers in the land cover map
933   @param theMap the map of shape (face) to Strickler type (string)
934 */
935 void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& theMap )
936 {
937   TopTools_ListOfShape aListOfFaces;
938
939   //DEBTRACE("theMap.Extent() " << theMap.Extent());
940   for( int i = 1; i <= theMap.Extent(); i++ )
941   {
942     TopoDS_Face aFace = theMap.FindKey(i);
943     if( aFace.IsNull() )
944       continue;
945     aListOfFaces.Append(aFace);
946   }
947
948   TopTools_IndexedDataMapOfShapeListOfShape ShHistory;
949   ShHistory.Clear();
950
951   TopoDS_Shape aResult;
952   if( aListOfFaces.Extent() == 1 )
953     aResult = aListOfFaces.First();
954   else if( aListOfFaces.Extent() > 1 )
955     aResult = MergeFaces( aListOfFaces, false, &ShHistory );
956
957   //remove internal edges
958   //if nothing changes => the result shape should be the same
959   //hence the map will be empty
960
961   NCollection_IndexedDataMap<TopoDS_Face, TopoDS_Face> ShF2FHistory;
962   RemoveInternal(aResult, &ShF2FHistory);
963
964   //one face => mark as unchanged
965   if( aListOfFaces.Extent() == 1 )
966     ShHistory.Add(aResult, TopTools_ListOfShape());
967
968   NCollection_IndexedDataMap<TopoDS_Face, QString> aChF2ST;
969   QStringList aSTypes;
970   //
971   for( int i = 1; i <= theMap.Extent(); i++ )
972   {
973     TopoDS_Face aFF = theMap.FindKey(i);
974     //DEBTRACE("  --- " << aFF);
975     if( aFF.IsNull() )
976       continue;
977     //DEBTRACE(ShHistory.IsEmpty());
978     //DEBTRACE(aFF.Checked());
979     TopTools_ListOfShape aLS;
980     try
981     {
982       aLS = ShHistory.FindFromKey(aFF); //TODO: bug to fix. Observed on an incomplete split of a face
983     }
984     catch (...)
985     {
986       DEBTRACE("TODO: bug to fix. Observed on an incomplete split of a face");
987       //continue; // No, keep aLS empty and propagate the type of the original face
988     }
989     if (aLS.IsEmpty())
990     {
991       //DEBTRACE("--- aLS.IsEmpty()");
992       QString aSType = theMap.FindFromKey(aFF);
993       //DEBTRACE("  --- " << aSType.toStdString());
994       if (ShF2FHistory.Contains(aFF))
995         {
996           //DEBTRACE("ShF2FHistory.FindFromKey(aFF) " << ShF2FHistory.FindFromKey(aFF));
997           aChF2ST.Add(ShF2FHistory.FindFromKey(aFF), aSType);
998         }
999       else
1000         {
1001           //DEBTRACE("aFF " << aFF);
1002           aChF2ST.Add(aFF, aSType);
1003         }
1004     }
1005     else
1006     {
1007       //DEBTRACE("--- !aLS.IsEmpty()");
1008       TopTools_ListIteratorOfListOfShape anIt(aLS);
1009       for (; anIt.More(); anIt.Next())
1010       {
1011         QString aSType = theMap.FindFromKey(aFF);
1012         //DEBTRACE("  --- " << aSType.toStdString());
1013         const TopoDS_Face& aMF = TopoDS::Face(anIt.Value()); 
1014         //if (ShF2FHistory.Contains(aFF))
1015         if (ShF2FHistory.Contains(aMF))
1016           {
1017             //DEBTRACE("ShF2FHistory.FindFromKey(aMF) " << ShF2FHistory.FindFromKey(aFF));
1018             aChF2ST.Add(ShF2FHistory.FindFromKey(aMF), aSType);
1019           }
1020         else
1021           {
1022             //DEBTRACE("aMF " << aMF);
1023             aChF2ST.Add(aMF, aSType);
1024           }
1025       }
1026     }
1027   }
1028   //
1029   SetShape( aResult );
1030   //
1031   //Explorer Exp(*this);
1032   TopExp_Explorer FExp(aResult, TopAbs_FACE);
1033   for( ; FExp.More(); FExp.Next() )
1034   {
1035     TopoDS_Face aFace = TopoDS::Face(FExp.Current());
1036     QString aST = ""; 
1037     if (aChF2ST.Contains(aFace))
1038       aST = aChF2ST.FindFromKey(aFace);
1039     //DEBTRACE("aFace "  << aFace << " aST " << aST.toStdString());
1040     aSTypes << aST;
1041   }
1042   
1043   Handle( TDataStd_ExtStringArray ) aTypes = TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, aSTypes.size() - 1, Standard_True );
1044   int k = 0;
1045   foreach (QString aST, aSTypes)
1046   {
1047     //DEBTRACE("aST " << aST.toStdString());
1048     aTypes->SetValue( k, HYDROData_Tool::toExtString( aST ) );
1049     k++;
1050   }
1051
1052 }
1053
1054 /**
1055    Checks that object has 2D presentation. Reimlemented to retun true.
1056 */
1057 bool HYDROData_LandCoverMap::IsHas2dPrs() const
1058 {
1059   return true;
1060 }
1061
1062 /**
1063   Find the land cover for the given point
1064   @param thePoint the point laying in some land cover
1065   @param theType the returned type
1066   @return the found land cover's face
1067 */
1068 TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QString& theType ) const
1069 {
1070   //TODO: some more optimal algorithm
1071   Explorer anIt( *this );
1072   for( ; anIt.More(); anIt.Next() )
1073     if( HYDROData_Tool::ComputePointState( thePoint.XY(), anIt.Face() ) == TopAbs_IN )
1074     {
1075       theType = anIt.StricklerType();
1076       return anIt.Face();
1077     }
1078
1079   theType = "";
1080   return TopoDS_Face();
1081 }
1082
1083 void Dump( const QString& theName, const QStringList& theList, QStringList& theLines )
1084 {
1085   theLines.append( QString( "%1 = QStringList()" ).arg( theName ) );
1086   foreach( QString anItem, theList )
1087     theLines.append( QString( "%1.append( u\"%2\" )" ).arg( theName ).arg( anItem ) );
1088 }
1089
1090 /**
1091   Dump to Python
1092   @param theTreatedObjects the map of treated objects
1093 */
1094 QStringList HYDROData_LandCoverMap::DumpToPython( const QString&       thePyScriptPath,
1095                                                   MapOfTreatedObjects& theTreatedObjects ) const
1096 {
1097   QStringList aResList = dumpObjectCreation( theTreatedObjects );
1098   QString aName = GetObjPyName();
1099
1100   QString aShpFileName = thePyScriptPath;
1101   aShpFileName.replace( ".py", ".shp" );
1102   QString aDbfFileName = thePyScriptPath;
1103   aDbfFileName.replace( ".py", ".dbf" );
1104
1105   ExportSHP( aShpFileName, true, 0.1 );
1106
1107   QString anAttr = "CODE_06"; //TODO: some custom choice
1108   QStringList anAttrValues, aTypes;
1109   HYDROData_Document::Document( myLab )->CollectQGISValues( anAttr, anAttrValues, aTypes );
1110   ExportDBF( aDbfFileName, anAttr, anAttrValues, aTypes );
1111
1112   aResList << QString( "%1.ImportSHP( '%2' )" ).
1113     arg( aName ).arg( QFileInfo( aShpFileName ).fileName() );
1114
1115   Dump( "attr_values", anAttrValues, aResList );
1116   Dump( "types", aTypes, aResList );
1117   aResList << QString( "%1.ImportDBF( '%2', '%3', attr_values, types )" ).
1118     arg( aName ).arg( QFileInfo( aDbfFileName ).fileName() ).arg( anAttr );
1119
1120   return aResList;
1121 }
1122
1123 void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollection_IndexedDataMap<TopoDS_Face, TopoDS_Face>* aF2FReplace)
1124 {
1125   //DEBTRACE("RemoveInternal");
1126   //Shape must be topologically correct
1127   TopExp_Explorer anExpF(ShToRebuild, TopAbs_FACE);
1128   //
1129   for(; anExpF.More(); anExpF.Next() )
1130   {
1131     TopoDS_Face CurFace = TopoDS::Face(anExpF.Current());
1132     //
1133     TopExp_Explorer anExp(CurFace, TopAbs_EDGE);
1134     TopTools_ListOfShape anEdgesToRemove;
1135     //
1136     for(; anExp.More(); anExp.Next() )
1137     {
1138       TopoDS_Edge CurEdge = TopoDS::Edge(anExp.Current());
1139       if (CurEdge.Orientation() == TopAbs_INTERNAL)
1140         anEdgesToRemove.Append(CurEdge);
1141     }
1142     //
1143     if (!anEdgesToRemove.IsEmpty())
1144     {
1145       Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape();
1146       TopoDS_Shape OutF = aReshape->Apply(CurFace);
1147       TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove);
1148       for (; aIt.More(); aIt.Next()) 
1149         aReshape->Remove(aIt.Value());
1150       OutF = aReshape->Apply(CurFace);
1151
1152       Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1153       sfs->Init(OutF);
1154       sfs->Perform();
1155       OutF = sfs->Shape();
1156       aF2FReplace->Add(CurFace, TopoDS::Face(OutF));
1157     }
1158   }
1159   //
1160   Handle_ShapeBuild_ReShape anExtReshape = new ShapeBuild_ReShape();
1161   for (int i = 1; i <= aF2FReplace->Extent(); i++)
1162   {
1163     TopoDS_Face aFK = aF2FReplace->FindKey(i);
1164     TopoDS_Face aFV = aF2FReplace->FindFromIndex(i);
1165     anExtReshape->Replace(aFK, aFV);
1166     ShToRebuild = anExtReshape->Apply(ShToRebuild);
1167   }
1168 //  for (int i = 1; i <= aF2FReplace->Extent(); i++)
1169 //    {
1170 //      DEBTRACE("aF2FReplace key,value " << aF2FReplace->FindKey(i) << " " << aF2FReplace->FindFromIndex(i));
1171 //    }
1172
1173 }
1174
1175 void HYDROData_LandCoverMap::SetTransparency( double theTransparency )
1176 {
1177   SetDouble( DataTag_Transparency, theTransparency );
1178 }
1179
1180 double HYDROData_LandCoverMap::GetTransparency() const
1181 {
1182   return GetDouble( DataTag_Transparency, 0.5 );
1183 }
1184
1185 bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName,
1186                                         const QList<int>& theIndices )
1187 {
1188   HYDROData_ShapeFile anImporter;
1189   QStringList aPolyList; 
1190   TopTools_SequenceOfShape aFaces;
1191   int aSHapeType = -1;
1192   int Stat = anImporter.ImportPolygons(HYDROData_Document::Document(1), theSHPFileName, aPolyList, aFaces, aSHapeType);
1193   //
1194   if (Stat != 1)
1195     return false;
1196   //
1197   HYDROData_MapOfFaceToStricklerType aMapFace2ST;
1198   int maxInd = *std::max_element(theIndices.begin(), theIndices.end());
1199   if (maxInd > aPolyList.length())
1200     return false;
1201   //
1202   if (theIndices.empty())
1203   {
1204     //import all shapes
1205     for ( int i = 1; i <=aFaces.Length(); i++ )
1206     {
1207       TopoDS_Shape aShape = aFaces(i);
1208       if ( aShape.IsNull() ) 
1209         continue;
1210       aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
1211     }
1212   }
1213   else
1214   {
1215     //import given indices
1216     foreach ( int Ind, theIndices )
1217     {
1218       TopoDS_Shape aShape = aFaces(Ind + 1);
1219       if ( aShape.IsNull() ) 
1220         continue;
1221       aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
1222     }
1223   }
1224   //
1225   StoreLandCovers(aMapFace2ST);
1226   return true;
1227 }
1228
1229 bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUseDiscr, double theDefl) const
1230 {
1231   HYDROData_ShapeFile anExporter;
1232   QStringList aList;
1233   anExporter.Export(HYDROData_Document::Document(1), theSHPFileName, this, aList, bUseDiscr, theDefl );
1234   if (aList.empty())
1235     return true;
1236   else 
1237     return false;
1238 }
1239
1240 bool HYDROData_LandCoverMap::CheckLinear()
1241 {
1242   TopoDS_Shape InpShape = GetShape();
1243   TopExp_Explorer anEdgeEx(InpShape, TopAbs_EDGE);
1244   for (; anEdgeEx.More(); anEdgeEx.Next()) 
1245   {
1246     TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
1247     double aFP, aLP;
1248     Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
1249     Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
1250     if (aLine.IsNull())
1251     {
1252       Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur);
1253       if (!aTC.IsNull())
1254       {
1255         Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve());
1256         if (aLine.IsNull())
1257           return false;
1258       }
1259       else
1260         return false;
1261     }
1262   }
1263   return true;
1264 }
1265
1266 void HYDROData_LandCoverMap::UpdateLocalCS( double theDx, double theDy )
1267 {
1268   TopoDS_Shape aShape = GetShape();
1269   TopoDS_Shape aLocatedShape = HYDROData_ShapesTool::Translated( aShape, theDx, theDy, 0 );
1270   SetShape( aLocatedShape );
1271 }
1272
1273 void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints, std::vector<std::set <QString> >& theTypes ) const
1274 {
1275   HYDROData_LCM_FaceClassifier FC(this);
1276   FC.Classify(thePoints, theTypes, NULL);
1277 }
1278
1279 void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints,  
1280   Handle(HYDROData_StricklerTable) theTable, 
1281   std::vector<double>& theCoeffs, double DefValue, bool UseMax ) const
1282 {
1283   std::vector<std::set <QString> > Types;
1284   HYDROData_LCM_FaceClassifier FC(this);
1285   FC.Classify(thePoints, Types, NULL);
1286   theCoeffs.resize(thePoints.size());
1287   for (size_t i = 0; i < Types.size(); i++)
1288   {
1289     const std::set<QString>& SStr = Types[i];
1290     if (SStr.empty())
1291       theCoeffs[i] = DefValue;
1292     else
1293     {
1294       std::set<QString>::const_iterator it;
1295       std::vector<double> C1(SStr.size());
1296       for (it = SStr.begin(); it != SStr.end(); ++it)
1297         C1.push_back(theTable->Get( *it, DefValue ));
1298       double Val;
1299       if (UseMax)
1300         Val = *(std::max_element( C1.begin(), C1.end() ) );
1301       else
1302         Val = *(std::min_element( C1.begin(), C1.end() ) );
1303       theCoeffs[i] = Val;
1304     }
1305   }
1306 }