Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / CONVERTOR / VISU_Convertor_impl.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File   : VISU_Convertor_impl.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_Convertor_impl.hxx"
28 #include "VISU_ConvertorUtils.hxx"
29 #include "VTKViewer_AppendFilter.h"
30 #include "VISU_MergeFilter.hxx"
31
32 #include <vtkPoints.h>
33 #include <vtkUnstructuredGrid.h>
34
35 #include <vtkIdList.h>
36 #include <vtkCellType.h>
37 #include <vtkIntArray.h>
38 #include <vtkCellArray.h>
39 #include <vtkFloatArray.h>
40 #include <vtkUnsignedCharArray.h>
41 #include <vtkPointData.h>
42 #include <vtkCellData.h>
43 #include <vtkCellLinks.h>
44
45
46 #include <qstring.h>
47 #include <qfileinfo.h>
48
49 #include <valarray>     
50 #include <memory>
51
52 using namespace std;
53 using namespace VISU;
54
55 static float ERR_SIZE_CALC = 1.00;
56
57 static int MYVTKDEBUG = 0;
58
59 #ifdef _DEBUG_
60 static int MYDEBUG = 0;
61 static int MYDEBUGWITHFILES = 0;
62 //#define _DEXCEPT_
63 #else
64 static int MYDEBUG = 0;
65 static int MYDEBUGWITHFILES = 0;
66 #endif
67
68 namespace VISU
69 {
70   //---------------------------------------------------------------
71   TIsVTKDone::TIsVTKDone(): 
72     myIsVTKDone(false),
73     myIsDone(false)
74   {}
75
76
77   //---------------------------------------------------------------
78   TSizeCounter::TSizeCounter():
79     myNbCells(0),
80     myCellsSize(0)
81   {}
82
83
84   //---------------------------------------------------------------
85   TSource::TSource()
86   {}
87
88   const TVTKSource& 
89   TSource
90   ::GetSource() const
91   {
92     if(!mySource.GetPointer()){
93       mySource = vtkUnstructuredGrid::New();
94       mySource->Delete();
95     }
96     return mySource;
97   }
98
99   TVTKOutput* 
100   TSource
101   ::GetVTKOutput()
102   {
103     return GetSource().GetPointer();
104   }
105
106
107   //---------------------------------------------------------------
108   TAppendFilter::TAppendFilter()
109   {}
110
111   const TVTKAppendFilter& 
112   TAppendFilter
113   ::GetFilter() const
114   {
115     if(!myFilter.GetPointer()){
116       myFilter = VTKViewer_AppendFilter::New();
117       myFilter->Delete();
118       myFilter->SetDoMappingFlag(true);
119     }
120     return myFilter;
121   }
122
123   TVTKOutput* 
124   TAppendFilter
125   ::GetVTKOutput()
126   {
127     GetFilter()->Update();
128     return GetFilter()->GetOutput();
129   }
130
131
132   //---------------------------------------------------------------
133   TMergeFilter::TMergeFilter()
134   {}
135
136   const TVTKMergeFilter& 
137   TMergeFilter
138   ::GetFilter() const
139   {
140     if(!myFilter.GetPointer()){
141       myFilter = VISU_MergeFilter::New();
142       myFilter->Delete();
143     }
144     return myFilter;
145   }
146
147   TVTKOutput* 
148   TMergeFilter
149   ::GetVTKOutput()
150   {
151     GetFilter()->Update();
152     return GetFilter()->GetUnstructuredGridOutput();
153   }
154
155
156   //---------------------------------------------------------------
157   TPointCoords
158   ::TPointCoords():
159     myPoints(vtkPoints::New())
160   {
161     myPoints->Delete();
162   }
163
164   void
165   TPointCoords
166   ::Init(vtkIdType theNbPoints,
167          vtkIdType theDim)
168   {
169     myDim = theDim;
170     myNbPoints = theNbPoints;
171     myCoord.resize(theNbPoints*theDim);
172     myPoints->SetNumberOfPoints(theNbPoints);
173   }
174
175   TCCoordSlice 
176   TPointCoords
177   ::GetCoordSlice(vtkIdType theNodeId) const
178   {
179     return TCCoordSlice(myCoord,std::slice(theNodeId*myDim,myDim,1));
180   }
181   
182   TCoordSlice 
183   TPointCoords
184   ::GetCoordSlice(vtkIdType theNodeId)
185   {
186     return TCoordSlice(myCoord,std::slice(theNodeId*myDim,myDim,1));
187   }
188
189
190   //---------------------------------------------------------------
191   void
192   TNamedPointCoords
193   ::Init(vtkIdType theNbPoints,
194          vtkIdType theDim,
195          const TVectorID& theVectorID)
196   {
197     TPointCoords::Init(theNbPoints,theDim);
198     myPointsDim.resize(theDim);
199     myVectorID = theVectorID;
200
201     for(vtkIdType anID = 0, anEnd = theVectorID.size(); anID < anEnd; anID++)
202       myObj2VTKID[theVectorID[anID]] = anID;
203   }
204
205   std::string&
206   TNamedPointCoords
207   ::GetName(vtkIdType theDim)
208   {
209     return myPointsDim[theDim];
210   }
211
212   const std::string&
213   TNamedPointCoords
214   ::GetName(vtkIdType theDim) const
215   {
216     return myPointsDim[theDim];
217   }
218
219   vtkIdType
220   TNamedPointCoords
221   ::GetObjID(vtkIdType theID) const
222   {
223     if(myVectorID.empty())
224       return theID;
225     else
226       return myVectorID[theID];
227   }
228
229
230   vtkIdType
231   TNamedPointCoords
232   ::GetVTKID(vtkIdType theID) const
233   {
234     if(myObj2VTKID.empty())
235       return theID;
236     else{
237       TObj2VTKID::const_iterator anIter = myObj2VTKID.find(theID);
238       if(anIter != myObj2VTKID.end())
239         return anIter->second;
240     }
241     return -1;
242   }
243
244   std::string 
245   TNamedPointCoords
246   ::GetNodeName(vtkIdType theObjID) const
247   {
248     return "";
249   }
250
251   //---------------------------------------------------------------
252   TMeshImpl::TMeshImpl():
253     myPoints(vtkPoints::New()),
254     myNbPoints(0) 
255   {
256     myPoints->Delete();
257   }
258
259
260   //---------------------------------------------------------------
261   TSubProfileImpl::TSubProfileImpl():
262     myStatus(eNone),
263     myGeom(eNONE)
264   {}
265
266
267   vtkIdType
268   TSubProfileImpl
269   ::GetElemObjID(vtkIdType theID) const
270   {
271     return theID;
272   }
273
274
275   //---------------------------------------------------------------
276   bool
277   operator<(const PSubProfile& theLeft, const PSubProfile& theRight)
278   {
279     PSubProfileImpl aLeft(theLeft), aRight(theRight);
280
281     if(aLeft->myGeom != aRight->myGeom)
282       return aLeft->myGeom < aRight->myGeom;
283
284     if(aLeft->myStatus != aRight->myStatus)
285       return aLeft->myStatus < aRight->myStatus;
286
287     return aLeft->myName < aRight->myName;
288   }
289
290
291   //---------------------------------------------------------------
292   TProfileImpl::TProfileImpl():
293     myIsAll(true),
294     myMeshOnEntity(NULL)
295   {}
296
297   vtkIdType
298   TProfileImpl
299   ::GetNodeObjID(vtkIdType theID) const
300   {
301     return myNamedPointCoords->GetObjID(theID);
302   }
303   
304   vtkIdType
305   TProfileImpl
306   ::GetNodeVTKID(vtkIdType theID) const
307   {
308     return myNamedPointCoords->GetVTKID(theID);
309   }
310
311   float*  
312   TProfileImpl
313   ::GetNodeCoord(vtkIdType theObjID)
314   {
315     if(myIsAll)
316       return myMeshOnEntity->GetNodeCoord(theObjID);
317
318     vtkIdType aVtkID = GetNodeVTKID(theObjID);
319     return GetFilter()->GetOutput()->GetPoint(aVtkID);
320   }
321
322   vtkIdType
323   TProfileImpl
324   ::GetElemObjID(vtkIdType theID) const
325   {
326     if(myIsAll)
327       return myMeshOnEntity->GetElemObjID(theID);
328
329     vtkIdType anInputID, aStartID, anInputDataSetID;
330     const TVTKAppendFilter& anAppendFilter = GetFilter();
331     anAppendFilter->GetCellInputID(theID,anInputID,aStartID,anInputDataSetID);
332     PSubProfileImpl aSubProfileImpl = mySubProfileArr[anInputDataSetID];
333     return aSubProfileImpl->GetElemObjID(anInputID);
334   }
335
336   vtkIdType
337   TProfileImpl
338   ::GetElemVTKID(vtkIdType theID) const
339   {
340     if(myIsAll)
341       return myMeshOnEntity->GetElemVTKID(theID);
342
343     if(myElemObj2VTKID.empty())
344       return theID;
345     else{
346       TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID);
347       if(anIter != myElemObj2VTKID.end())
348         return anIter->second;
349     }
350     return -1;
351   }
352
353   vtkCell* 
354   TProfileImpl
355   ::GetElemCell(vtkIdType theObjID)
356   {
357     if(myIsAll)
358       return myMeshOnEntity->GetElemCell(theObjID);
359
360     vtkIdType aVtkID = GetElemVTKID(theObjID);
361     return GetFilter()->GetOutput()->GetCell(aVtkID);
362   }
363   
364   TVTKOutput* 
365   TProfileImpl
366   ::GetVTKOutput()
367   {
368     const TVTKAppendFilter& anAppendFilter = GetFilter();
369     return anAppendFilter->GetOutput();
370   }
371
372   std::string 
373   TProfileImpl
374   ::GetNodeName(vtkIdType theObjID) const
375   {
376     return myNamedPointCoords->GetNodeName(theObjID);
377   }
378
379   std::string 
380   TProfileImpl
381   ::GetElemName(vtkIdType theObjID) const
382   {
383     if(myIsAll)
384       return myMeshOnEntity->GetElemName(theObjID);
385
386     vtkIdType aVTKId = GetElemVTKID(theObjID);
387     vtkIdType anInputID, aStartID, anInputDataSetID;
388     const TVTKAppendFilter& anAppendFilter = GetFilter();
389     anAppendFilter->GetCellInputID(aVTKId,anInputID,aStartID,anInputDataSetID);
390     PSubProfileImpl aSubProfileImpl = mySubProfileArr[anInputDataSetID];
391     vtkIdType anEntityObjId = aSubProfileImpl->GetElemObjID(anInputID);
392     return myMeshOnEntity->GetElemName(anEntityObjId);
393   }
394
395
396   //---------------------------------------------------------------
397   TVTKOutput* 
398   TIDMapperFilter
399   ::GetVTKOutput()
400   {
401     if(!myFilter.GetPointer()){
402       const TVTKAppendFilter& anAppendFilter = myIDMapper.GetFilter();
403       TVTKOutput* aGeometry = anAppendFilter->GetOutput();
404       
405       const TVTKSource& aSource = mySource.GetSource();
406       TDataSet* aDataSet = aSource.GetPointer();
407       aDataSet->ShallowCopy(aGeometry);
408       
409       const TVTKMergeFilter& aFilter = GetFilter();
410       aFilter->SetGeometry(aGeometry);
411       aFilter->SetScalars(aDataSet);
412       aFilter->SetVectors(aDataSet);
413       aFilter->AddField("VISU_FIELD",aDataSet);
414     }
415     return myFilter->GetUnstructuredGridOutput();
416   }
417
418   vtkIdType
419   TIDMapperFilter
420   ::GetNodeObjID(vtkIdType theID) const
421   {
422     return myIDMapper.GetNodeObjID(theID);
423   }
424   
425   vtkIdType
426   TIDMapperFilter
427   ::GetNodeVTKID(vtkIdType theID) const
428   {
429     return myIDMapper.GetNodeVTKID(theID);
430   }
431
432   float*  
433   TIDMapperFilter
434   ::GetNodeCoord(vtkIdType theObjID)
435   {
436     return myIDMapper.GetNodeCoord(theObjID);
437   }
438
439   vtkIdType
440   TIDMapperFilter
441   ::GetElemObjID(vtkIdType theID) const
442   {
443     return myIDMapper.GetElemObjID(theID);
444   }
445
446   vtkIdType
447   TIDMapperFilter
448   ::GetElemVTKID(vtkIdType theID) const
449   {
450     return myIDMapper.GetElemVTKID(theID);
451   }
452
453   vtkCell* 
454   TIDMapperFilter
455   ::GetElemCell(vtkIdType theObjID)
456   {
457     return myIDMapper.GetElemCell(theObjID);
458   }
459   
460
461   //---------------------------------------------------------------
462   void
463   TGaussImpl
464   ::LessThan(const PGaussImpl& theGauss,
465              bool& theResult) const
466   {
467     theResult = false;
468   }
469
470
471   //---------------------------------------------------------------
472   TGaussSubMeshImpl::TGaussSubMeshImpl():
473     myStatus(eNone)
474   {}
475   
476   TGaussPointID
477   TGaussSubMeshImpl
478   ::GetObjID(vtkIdType theID,
479              vtkIdType theStartID) const
480   {
481     TCellID aCellID = theStartID + theID / myGauss->myNbPoints;
482     TLocalPntID aLocalPntID = theID % myGauss->myNbPoints;
483     
484     return TGaussPointID(aCellID,aLocalPntID);
485   }
486
487   //---------------------------------------------------------------
488   bool
489   operator<(const PGaussSubMesh& theLeft, const PGaussSubMesh& theRight)
490   {
491     PGaussSubMeshImpl aLeft(theLeft), aRight(theRight);
492     const PGaussImpl& aGaussLeft = aLeft->myGauss;
493     const PGaussImpl& aGaussRight = aRight->myGauss;
494     
495     if(aGaussLeft->myGeom != aGaussRight->myGeom)
496       return aGaussLeft->myGeom < aGaussRight->myGeom;
497
498     if(aLeft->mySubProfile != aRight->mySubProfile)
499       return aLeft->mySubProfile < aRight->mySubProfile;
500
501     bool aResult;
502     aGaussLeft->LessThan(aGaussRight,aResult);
503
504     return aResult;
505   }
506
507
508   //---------------------------------------------------------------
509   TGaussMeshImpl
510   ::TGaussMeshImpl():
511     myParent(NULL)
512   {}
513
514   TGaussPointID 
515   TGaussMeshImpl
516   ::GetObjID(vtkIdType theID) const
517   {
518     vtkIdType anInputID, aStartId, anInputDataSetID;
519     const TVTKAppendFilter& anAppendFilter = GetFilter();
520     anAppendFilter->GetCellInputID(theID,anInputID,aStartId,anInputDataSetID);
521     const TGaussSubMeshImpl& aSubMeshImpl = myGaussSubMeshArr[anInputDataSetID];
522
523     return aSubMeshImpl.GetObjID(anInputID,aStartId);
524   }
525   
526   TVTKOutput* 
527   TGaussMeshImpl
528   ::GetVTKOutput()
529   {
530     return mySource.GetVTKOutput();
531   }
532
533   TNamedIDMapper* 
534   TGaussMeshImpl::
535   GetParent()
536   {
537     return myParent;
538   }
539
540
541   //---------------------------------------------------------------
542   TGaussPointID 
543   TGaussPtsIDFilter
544   ::GetObjID(vtkIdType theID) const
545   {
546     return myGaussPtsIDMapper->GetObjID(theID);
547   }
548   
549   TNamedIDMapper* 
550   TGaussPtsIDFilter::
551   GetParent()
552   {
553     return myGaussPtsIDMapper->GetParent();
554   }
555
556
557   //---------------------------------------------------------------
558   vtkIdType
559   TSubMeshImpl
560   ::GetElemObjID(vtkIdType theID) const
561   {
562     return myStartID + theID;
563   }
564
565   std::string 
566   TSubMeshImpl
567   ::GetElemName(vtkIdType theObjID) const
568   {
569     return "";
570   }
571
572   //---------------------------------------------------------------
573   vtkIdType
574   TMeshOnEntityImpl
575   ::GetNodeVTKID(vtkIdType theID) const
576   {
577     return myNamedPointCoords->GetVTKID(theID);
578   }
579
580   vtkIdType
581   TMeshOnEntityImpl
582   ::GetNodeObjID(vtkIdType theID) const
583   {
584     return myNamedPointCoords->GetObjID(theID);
585   }
586
587   vtkIdType
588   TMeshOnEntityImpl
589   ::GetElemVTKID(vtkIdType theID) const
590   {
591     if(myElemObj2VTKID.empty())
592       return theID;
593     else{
594       TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID);
595       if(anIter != myElemObj2VTKID.end())
596         return anIter->second;
597     }
598     return -1;
599   }
600
601   vtkIdType
602   TMeshOnEntityImpl
603   ::GetElemObjID(vtkIdType theID) const
604   {
605     vtkIdType anInputID, aStartId, anInputDataSetID;
606     const TVTKAppendFilter& anAppendFilter = GetFilter();
607     anAppendFilter->GetCellInputID(theID,anInputID,aStartId,anInputDataSetID);
608     const PSubMeshImpl& aSubMesh = mySubMeshArr[anInputDataSetID];
609     return aSubMesh->GetElemObjID(anInputID);
610   }
611
612   std::string 
613   TMeshOnEntityImpl
614   ::GetNodeName(vtkIdType theObjID) const
615   {
616     return myNamedPointCoords->GetNodeName(theObjID);
617   }
618
619   std::string 
620   TMeshOnEntityImpl
621   ::GetElemName(vtkIdType theObjID) const
622   {
623     vtkIdType aVTKId = GetElemVTKID(theObjID);
624     vtkIdType anInputID, aStartId, anInputDataSetID;
625     const TVTKAppendFilter& anAppendFilter = GetFilter();
626     anAppendFilter->GetCellInputID(aVTKId,anInputID,aStartId,anInputDataSetID);
627     const PSubMeshImpl& aSubMesh = mySubMeshArr[anInputDataSetID];
628     return aSubMesh->GetElemName(anInputID);
629   }
630
631   //---------------------------------------------------------------
632   vtkIdType
633   TFamilyImpl
634   ::GetElemVTKID(vtkIdType theID) const
635   {
636     if(myElemObj2VTKID.empty())
637       return theID;
638     else{
639       TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID);
640       if(anIter != myElemObj2VTKID.end())
641         return anIter->second;
642     }
643     return -1;
644   }
645
646   vtkIdType
647   TFamilyImpl
648   ::GetElemObjID(vtkIdType theID) const
649   {
650     return myMeshID[theID];
651   }
652
653   vtkIdType 
654   TFamilyImpl
655   ::GetNodeObjID(vtkIdType theID) const 
656   {
657     return myNamedPointCoords->GetObjID(theID);
658   }
659
660   vtkIdType
661   TFamilyImpl
662   ::GetNodeVTKID(vtkIdType theID) const 
663   {
664     return myNamedPointCoords->GetVTKID(theID);
665   }
666
667   TVTKOutput* 
668   TFamilyImpl
669   ::GetVTKOutput()
670   {
671     return TSource::GetVTKOutput();
672   }
673
674
675   //---------------------------------------------------------------
676   TNbASizeCells 
677   TGroupImpl
678   ::GetNbASizeCells() const
679   {
680     vtkIdType aNbCells = 0, aCellsSize = 0;
681     TFamilySet::const_iterator anIter = myFamilySet.begin();
682     for(; anIter != myFamilySet.end(); anIter++){
683       PFamilyImpl aFamily = *anIter; 
684       aNbCells += aFamily->myNbCells;
685       aCellsSize += aFamily->myCellsSize;
686     }
687     return make_pair(aNbCells,aCellsSize);
688   }
689
690   vtkIdType
691   TGroupImpl
692   ::GetElemVTKID(vtkIdType theID) const
693   {
694     if(myElemObj2VTKID.empty())
695       return theID;
696     else{
697       TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID);
698       if(anIter != myElemObj2VTKID.end())
699         return anIter->second;
700     }
701     return -1;
702   }
703
704   vtkIdType
705   TGroupImpl
706   ::GetElemObjID(vtkIdType theID) const
707   {
708     vtkIdType anInputID, aStartId, anInputDataSetID;
709     const TVTKAppendFilter& anAppendFilter = GetFilter();
710     anAppendFilter->GetCellInputID(theID,anInputID,aStartId,anInputDataSetID);
711     const PFamilyImpl& aFamily = myFamilyArr[anInputDataSetID];
712     return aFamily->GetElemObjID(anInputID);
713   }
714
715   vtkIdType 
716   TGroupImpl
717   ::GetNodeObjID(vtkIdType theID) const 
718   {
719     return myNamedPointCoords->GetObjID(theID);
720   }
721
722   vtkIdType
723   TGroupImpl
724   ::GetNodeVTKID(vtkIdType theID) const 
725   {
726     return myNamedPointCoords->GetVTKID(theID);
727   }
728
729   
730   //---------------------------------------------------------------
731   TFieldImpl
732   ::TFieldImpl(): 
733     myDataSize(0)
734   {}
735
736   void 
737   TFieldImpl
738   ::InitArrays(vtkIdType theNbComp)
739   {
740     myNbComp = theNbComp;
741     myCompNames.resize(theNbComp);
742     myUnitNames.resize(theNbComp);
743     myMinMaxArr.resize(theNbComp + 1);
744     for(vtkIdType iComp = 0; iComp <= theNbComp; iComp++){
745       TMinMax& aMinMax = myMinMaxArr[iComp];
746       aMinMax.first = VTK_LARGE_FLOAT;
747       aMinMax.second = -VTK_LARGE_FLOAT;
748     }
749   }
750
751   TMinMax 
752   TFieldImpl
753   ::GetMinMax(vtkIdType theCompID)
754   {
755     return myMinMaxArr[theCompID];
756   }
757
758
759   //---------------------------------------------------------------
760   void
761   TMeshValue
762   ::Init(vtkIdType theNbElem,
763          vtkIdType theNbGauss,
764          vtkIdType theNbComp)
765   {
766     myNbElem = theNbElem;
767     myNbGauss = theNbGauss;
768     myNbComp = theNbComp;
769     
770     myStep = theNbComp*theNbGauss;
771     
772     myValue.resize(theNbElem*myStep);
773   }
774
775   TCValueSliceArr 
776   TMeshValue
777   ::GetGaussValueSliceArr(vtkIdType theElemId) const
778   {
779     TCValueSliceArr aValueSliceArr(myNbGauss);
780     vtkIdType anId = theElemId*myStep;
781     for(vtkIdType aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
782       aValueSliceArr[aGaussId] =
783         TCValueSlice(myValue,std::slice(anId,myNbComp,1));
784       anId += myNbComp;
785     }
786     return aValueSliceArr;
787   }
788
789   TValueSliceArr 
790   TMeshValue
791   ::GetGaussValueSliceArr(vtkIdType theElemId)
792   {
793     TValueSliceArr aValueSliceArr(myNbGauss);
794     vtkIdType anId = theElemId*myStep;
795     for(vtkIdType aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
796       aValueSliceArr[aGaussId] =
797         TValueSlice(myValue,std::slice(anId,myNbComp,1));
798       anId += myNbComp;
799     }
800     return aValueSliceArr;
801   }
802
803   TCValueSliceArr 
804   TMeshValue
805   ::GetCompValueSliceArr(vtkIdType theElemId) const
806   {
807     TCValueSliceArr aValueSliceArr(myNbComp);
808     vtkIdType anId = theElemId*myStep;
809     for(vtkIdType aCompId = 0; aCompId < myNbComp; aCompId++){
810       aValueSliceArr[aCompId] =
811         TCValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp));
812       anId += 1;
813     }
814     return aValueSliceArr;
815   }
816
817   TValueSliceArr 
818   TMeshValue
819   ::GetCompValueSliceArr(vtkIdType theElemId)
820   {
821     TValueSliceArr aValueSliceArr(myNbComp);
822     vtkIdType anId = theElemId*myStep;
823     for(vtkIdType aCompId = 0; aCompId < myNbComp; aCompId++){
824       aValueSliceArr[aCompId] =
825         TValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp));
826       anId += 1;
827     }
828     return aValueSliceArr;
829   }
830
831
832   //---------------------------------------------------------------
833   TValForTimeImpl
834   ::TValForTimeImpl():
835     myGaussPtsIDFilter(new TGaussPtsIDFilter()),
836     myIDMapperFilter(new TIDMapperFilter())
837   {}
838
839   const TMeshValue& 
840   TValForTimeImpl
841   ::GetMeshValue(EGeometry theGeom) const
842   {
843     TGeom2Value::const_iterator anIter = myGeom2Value.find(theGeom);
844     if(anIter == myGeom2Value.end())
845       EXCEPTION(runtime_error,"TValForTimeImpl::GetMeshValue - myGeom2Value.find(theGeom) fails");
846     return anIter->second;
847   }
848   
849   TMeshValue& 
850   TValForTimeImpl
851   ::GetMeshValue(EGeometry theGeom)
852   {
853     return myGeom2Value[theGeom];
854   }
855
856   int
857   TValForTimeImpl
858   ::GetNbGauss(EGeometry theGeom) const
859   {
860     TGeom2NbGauss::const_iterator anIter = myGeom2NbGauss.find(theGeom);
861     if(anIter == myGeom2NbGauss.end()){
862       //EXCEPTION(runtime_error,"TValForTimeImpl::GetNbGauss - myGeom2NbGauss.find(theGeom) fails");
863       return 1;
864     }
865     return anIter->second;
866   }
867   
868
869   //---------------------------------------------------------------
870   vtkIdType
871   VISUGeom2NbNodes(EGeometry theGeom)
872   { 
873     switch(theGeom){
874 #ifndef VISU_ENABLE_QUADRATIC
875     case VISU::eSEG3: 
876       return 2;
877     case VISU::eTRIA6: 
878       return 3;
879     case VISU::eQUAD8: 
880       return 4;
881     case VISU::eTETRA10: 
882       return 4;
883     case VISU::eHEXA20: 
884       return 8;
885     case VISU::ePENTA15: 
886       return 6;
887     case VISU::ePYRA13: 
888       return 5;
889 #endif
890     case VISU::ePOLYGONE: 
891     case VISU::ePOLYEDRE: 
892       return -1;
893     default:
894       return theGeom % 100;
895     }
896   }
897
898   vtkIdType
899   VISUGeom2VTK(EGeometry theGeom)
900   { 
901     switch(theGeom){
902     case VISU::ePOINT1: 
903       return VTK_VERTEX;
904     case VISU::eSEG2: 
905       return VTK_LINE;
906     case VISU::eTRIA3: 
907       return VTK_TRIANGLE;
908     case VISU::eQUAD4: 
909       return VTK_QUAD;
910     case VISU::eTETRA4: 
911       return VTK_TETRA;
912     case VISU::eHEXA8: 
913       return VTK_HEXAHEDRON;
914     case VISU::ePENTA6: 
915       return VTK_WEDGE;
916     case VISU::ePYRA5: 
917       return VTK_PYRAMID;
918
919     case VISU::ePOLYGONE: 
920       return VTK_POLYGON;
921     case VISU::ePOLYEDRE: 
922       return VTK_CONVEX_POINT_SET;
923
924 #ifndef VISU_ENABLE_QUADRATIC
925     case VISU::eSEG3: 
926       return VTK_LINE;
927     case VISU::eTRIA6: 
928       return VTK_TRIANGLE;
929     case VISU::eQUAD8: 
930       return VTK_QUAD;
931     case VISU::eTETRA10: 
932       return VTK_TETRA;
933     case VISU::eHEXA20: 
934       return VTK_HEXAHEDRON;
935     case VISU::ePENTA15: 
936       return VTK_WEDGE;
937     case VISU::ePYRA13: 
938       return VTK_PYRAMID;
939
940 #else
941
942     case VISU::eSEG3: 
943 #if defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC)
944       return VTK_QUADRATIC_EDGE;
945 #else
946       return VTK_POLY_LINE;
947 #endif
948
949     case VISU::eTRIA6: 
950 #if defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC)
951       return VTK_QUADRATIC_TRIANGLE;
952 #else
953       return VTK_POLYGON;
954 #endif
955
956     case VISU::eQUAD8: 
957 #if defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC)
958       return VTK_QUADRATIC_QUAD;
959 #else
960       return VTK_POLYGON;
961 #endif
962
963     case VISU::eTETRA10: 
964 #if defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC)
965       return VTK_QUADRATIC_TETRA;
966 #else
967       return VTK_CONVEX_POINT_SET;
968 #endif
969
970     case VISU::eHEXA20: 
971 #if defined(VTK_QUADRATIC_HEXAHEDRON) && defined(VISU_USE_VTK_QUADRATIC)
972       return VTK_QUADRATIC_HEXAHEDRON;
973 #else
974       return VTK_CONVEX_POINT_SET;
975 #endif
976
977     case VISU::ePENTA15: 
978 #if defined(VTK_QUADRATIC_WEDGE) && defined(VISU_USE_VTK_QUADRATIC)
979       return VTK_QUADRATIC_WEDGE;
980 #else
981       return VTK_CONVEX_POINT_SET;
982 #endif
983
984     case VISU::ePYRA13: 
985 #if defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC)
986       return VTK_QUADRATIC_PYRAMID;
987 #else
988       return VTK_CONVEX_POINT_SET;
989 #endif
990
991 #endif //VISU_ENABLE_QUADRATIC
992
993     default:
994       return -1;
995     }
996   }
997 }
998
999
1000 namespace
1001 {
1002   //---------------------------------------------------------------
1003   template<class T> 
1004   std::string 
1005   dtos(const std::string& fmt, T val)
1006   {
1007     static QString aString;
1008     aString.sprintf(fmt.c_str(),val);
1009     return aString.latin1();
1010   }
1011
1012
1013   //---------------------------------------------------------------
1014   enum ECoordName{eX, eY, eZ, eNone};
1015   typedef VISU::TCoord (*TGetCoord)(const VISU::TCCoordSlice& theCoordSlice);
1016   
1017   template<ECoordName TCoordId>
1018   VISU::TCoord 
1019   GetCoord(const VISU::TCCoordSlice& theCoordSlice)
1020   {
1021     return theCoordSlice[TCoordId];
1022   }
1023   
1024   template<>
1025   VISU::TCoord 
1026   GetCoord<eNone>(const VISU::TCCoordSlice& theCoordSlice)
1027   {
1028     return 0.0;
1029   }
1030   
1031   
1032   TGetCoord aXYZGetCoord[3] = {
1033     &GetCoord<eX>, 
1034     &GetCoord<eY>, 
1035     &GetCoord<eZ>
1036   };
1037   
1038   
1039   TGetCoord aXYGetCoord[3] = {
1040     &GetCoord<eX>, 
1041     &GetCoord<eY>, 
1042     &GetCoord<eNone>
1043   };
1044   
1045   TGetCoord aYZGetCoord[3] = {
1046     &GetCoord<eNone>,
1047     &GetCoord<eX>, 
1048     &GetCoord<eY>
1049   };
1050   
1051   TGetCoord aXZGetCoord[3] = {
1052     &GetCoord<eX>, 
1053     &GetCoord<eNone>,
1054     &GetCoord<eY>
1055   };
1056   
1057   
1058   TGetCoord aXGetCoord[3] = {
1059     &GetCoord<eX>, 
1060     &GetCoord<eNone>,
1061     &GetCoord<eNone>
1062   };
1063   
1064   TGetCoord aYGetCoord[3] = {
1065     &GetCoord<eNone>,
1066     &GetCoord<eX>, 
1067     &GetCoord<eNone>
1068   };
1069
1070   TGetCoord aZGetCoord[3] = {
1071     &GetCoord<eNone>,
1072     &GetCoord<eNone>,
1073     &GetCoord<eX>
1074   };
1075
1076   
1077   class TCoordHelper{
1078     TGetCoord* myGetCoord;
1079   public:
1080     TCoordHelper(TGetCoord* theGetCoord):
1081       myGetCoord(theGetCoord)
1082     {}
1083
1084     virtual
1085     ~TCoordHelper()
1086     {}
1087
1088     VISU::TCoord 
1089     GetCoord(VISU::TCCoordSlice& theCoordSlice, 
1090              int theCoordId)
1091     {
1092       return (*myGetCoord[theCoordId])(theCoordSlice);
1093     }
1094   };
1095   typedef std::auto_ptr<TCoordHelper> TCoordHelperPtr;
1096   
1097
1098   //---------------------------------------------------------------
1099   vtkPoints*
1100   GetPoints(const PMeshImpl& theMesh) 
1101   {
1102     TVTKPoints& aPoints = theMesh->myPoints;
1103     const TNamedPointCoords& aCoords = theMesh->myNamedPointCoords;
1104
1105     if(!theMesh->myIsVTKDone){
1106       TCoordHelperPtr aCoordHelperPtr;
1107       {
1108         int aMeshDimension = theMesh->myDim;
1109         bool anIsDimPresent[3] = {false, false, false};
1110         for(int iDim = 0; iDim < aMeshDimension; iDim++){
1111           const std::string& aName = aCoords.GetName(iDim);
1112           if(aName == "x" || aName == "X")
1113             anIsDimPresent[eX] = true;
1114           else if(aName == "y" || aName == "Y")
1115             anIsDimPresent[eY] = true;
1116           else if(aName == "z" || aName == "Z")
1117             anIsDimPresent[eZ] = true;
1118         }
1119
1120         switch(aMeshDimension){
1121         case 3:
1122           aCoordHelperPtr.reset(new TCoordHelper(aXYZGetCoord));
1123           break;
1124         case 2:
1125           if(anIsDimPresent[eY] && anIsDimPresent[eZ])
1126             aCoordHelperPtr.reset(new TCoordHelper(aYZGetCoord));
1127           else if(anIsDimPresent[eX] && anIsDimPresent[eZ])
1128             aCoordHelperPtr.reset(new TCoordHelper(aXZGetCoord));
1129           else
1130             aCoordHelperPtr.reset(new TCoordHelper(aXYGetCoord));
1131           break;
1132         case 1:
1133           if(anIsDimPresent[eY])
1134             aCoordHelperPtr.reset(new TCoordHelper(aYGetCoord));
1135           else if(anIsDimPresent[eZ])
1136             aCoordHelperPtr.reset(new TCoordHelper(aZGetCoord));
1137           else
1138             aCoordHelperPtr.reset(new TCoordHelper(aXGetCoord));
1139           break;
1140         }
1141       }
1142
1143       vtkIdType aNbPoints = aCoords.GetNbPoints();
1144       aPoints->SetNumberOfPoints(aNbPoints);
1145       
1146       INITMSG(MYDEBUG,"GetPoints - aNbPoints = "<<aNbPoints<<
1147               "; aDim = "<<theMesh->myDim<<
1148               endl);
1149
1150       for(vtkIdType aNodeId = 0; aNodeId < aNbPoints; aNodeId++){ 
1151         TCCoordSlice aCoordSlice = aCoords.GetCoordSlice(aNodeId);
1152         aPoints->SetPoint(aNodeId,
1153                           aCoordHelperPtr->GetCoord(aCoordSlice,eX),
1154                           aCoordHelperPtr->GetCoord(aCoordSlice,eY),
1155                           aCoordHelperPtr->GetCoord(aCoordSlice,eZ));
1156       }
1157       
1158       theMesh->myIsVTKDone = true;
1159
1160       if(MYVTKDEBUG) aPoints->DebugOn();
1161     }
1162
1163     return aPoints.GetPointer();
1164   }
1165   
1166   
1167   //---------------------------------------------------------------
1168   void
1169   PrintCells(int& theStartId,
1170              vtkCellArray* theConnectivity, 
1171              const VISU::TConnect& theVector)
1172   {
1173     vtkIdList *anIdList = vtkIdList::New();
1174     int kEnd = theVector.size();
1175     anIdList->SetNumberOfIds(kEnd);
1176     for(int k = 0; k < kEnd; k++)
1177       anIdList->SetId(k,theVector[k]);
1178     theConnectivity->InsertNextCell(anIdList);
1179     anIdList->Delete();
1180   }
1181
1182
1183   //---------------------------------------------------------------
1184   void
1185   GetCellsOnSubMesh(const TVTKSource& theSource,
1186                     const PMeshOnEntityImpl& theMeshOnEntity, 
1187                     const PSubMeshImpl& theSubMesh,
1188                     const vtkIdType theGeom) 
1189   {
1190     const VISU::TCell2Connect& anArray = theSubMesh->myCell2Connect;
1191     vtkIdType aCellsSize = theSubMesh->myCellsSize;
1192     vtkIdType aNbCells = theSubMesh->myNbCells;
1193     INITMSG(MYDEBUG,"GetCellsOnSubMesh "<<
1194             "- theGeom = "<<theGeom<<
1195             "; aNbCells = "<<aNbCells<<
1196             endl);
1197
1198
1199     vtkCellArray* aConnectivity = vtkCellArray::New();
1200     aConnectivity->Allocate(aCellsSize,0);
1201     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
1202     aCellTypesArray->SetNumberOfComponents(1);
1203     aCellTypesArray->SetNumberOfTuples(aNbCells);
1204
1205     for(vtkIdType anID = 0; anID < aNbCells; anID++){
1206       PrintCells(anID,aConnectivity,anArray[anID]);
1207       aCellTypesArray->SetValue(anID,(unsigned char)theGeom);
1208     }
1209
1210     vtkIdType *pts = 0, npts = 0;
1211     vtkIntArray* aCellLocationsArray = vtkIntArray::New();
1212     aCellLocationsArray->SetNumberOfComponents(1);
1213     aCellLocationsArray->SetNumberOfTuples(aNbCells);
1214     aConnectivity->InitTraversal();
1215     for(int i=0; aConnectivity->GetNextCell(npts,pts); i++)
1216       aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
1217     theSource->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
1218
1219     if(MYVTKDEBUG) aConnectivity->DebugOn();
1220
1221     aCellLocationsArray->Delete();
1222     aCellTypesArray->Delete();
1223     aConnectivity->Delete();
1224   } 
1225   
1226   
1227   //---------------------------------------------------------------
1228   void
1229   GetCellsOnFamily(const TVTKSource& theSource,
1230                    const PMeshOnEntityImpl& theMeshOnEntity, 
1231                    const PFamilyImpl& theFamily) 
1232   {
1233     INITMSG(MYDEBUG,"GetCellsOnFamily"<<endl);
1234
1235     vtkIdType aNbCells = theFamily->myNbCells;
1236     vtkIdType aCellsSize = theFamily->myCellsSize;
1237
1238     vtkCellArray* aConnectivity = vtkCellArray::New();
1239     aConnectivity->Allocate(aCellsSize,0);
1240     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
1241     aCellTypesArray->SetNumberOfComponents(1);
1242     aCellTypesArray->SetNumberOfTuples(aNbCells);
1243
1244     TSubMeshID& aMeshID = theFamily->myMeshID;
1245     aMeshID.resize(aNbCells);
1246
1247     VISU::TID2ID& anElemObj2VTKID = theFamily->myElemObj2VTKID;
1248
1249     const VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
1250     VISU::TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin();
1251     for(vtkIdType i = 0, j = 0; anIter != aGeom2SubMesh.end(); anIter++){
1252       VISU::EGeometry aEGeom = anIter->first;
1253       vtkIdType aVGeom = VISUGeom2VTK(aEGeom);
1254
1255       const VISU::TSubMeshImpl& aSubMesh = anIter->second;
1256       const VISU::TCell2Connect& anArray = aSubMesh.myCell2Connect;
1257
1258       const VISU::TGeom2SubMeshID& aGeom2SubMeshID = theFamily->myGeom2SubMeshID;
1259       if(aGeom2SubMeshID.empty()) 
1260         EXCEPTION(runtime_error,"GetCells >> There is no elements on the family !!!");
1261
1262       VISU::TGeom2SubMeshID::const_iterator aGeom2SubMeshIDIter = aGeom2SubMeshID.find(aEGeom);
1263       if(aGeom2SubMeshIDIter == aGeom2SubMeshID.end()) 
1264         continue;
1265
1266       const VISU::TSubMeshID& aSubMeshID = aGeom2SubMeshIDIter->second;
1267
1268       INITMSG(MYDEBUG,
1269               " - aEGeom = "<<aEGeom<<
1270               "; aVGeom = "<<aVGeom<<
1271               "; aSubMeshID.size() = "<<aSubMeshID.size()<<
1272               endl);
1273
1274       VISU::TSubMeshID::const_iterator aSubMeshIDIter = aSubMeshID.begin();
1275       for(; aSubMeshIDIter != aSubMeshID.end(); aSubMeshIDIter++, i++){
1276         vtkIdType anID = *aSubMeshIDIter;
1277         PrintCells(i,aConnectivity,anArray[anID]);
1278         aCellTypesArray->SetValue(j++,(unsigned char)aVGeom);
1279
1280         anElemObj2VTKID[anID] = i;
1281         aMeshID[i] = anID;
1282       }
1283     }
1284     vtkIdType *pts = 0, npts = 0;
1285     vtkIntArray* aCellLocationsArray = vtkIntArray::New();
1286     aCellLocationsArray->SetNumberOfComponents(1);
1287     aCellLocationsArray->SetNumberOfTuples(aNbCells);
1288     aConnectivity->InitTraversal();
1289     for(int i=0; aConnectivity->GetNextCell(npts,pts); i++)
1290       aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
1291     theSource->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
1292
1293     if(MYVTKDEBUG) aConnectivity->DebugOn();
1294
1295     aCellLocationsArray->Delete();
1296     aCellTypesArray->Delete();
1297     aConnectivity->Delete();
1298   }
1299   
1300   
1301   //---------------------------------------------------------------
1302   std::string
1303   GenerateFieldName(const PFieldImpl& theField,
1304                     const PValForTimeImpl& theValForTime)
1305   {
1306     const VISU::TTime& aTime = theValForTime->myTime;
1307     string aFieldName = theField->myMeshName + ", " + theField->myName + ": " + 
1308       VISU_Convertor::GenerateName(aTime);
1309     return aFieldName;
1310   }
1311
1312
1313   //---------------------------------------------------------------
1314   void 
1315   GetTimeStampOnProfile(const TVTKSource& theSource,
1316                         const PFieldImpl& theField, 
1317                         const PValForTimeImpl& theValForTime,
1318                         const VISU::TEntity& theEntity)
1319   {
1320     int aNbTuples = theField->myDataSize/theField->myNbComp;
1321     std::string aFieldName = GenerateFieldName(theField,theValForTime);
1322     
1323     vtkDataSetAttributes* aDataSetAttributes;
1324     switch(theEntity){
1325     case VISU::NODE_ENTITY : 
1326       aDataSetAttributes = theSource->GetPointData();
1327       break;
1328     default: 
1329       aDataSetAttributes = theSource->GetCellData();
1330     }
1331
1332     int aNbComp = theField->myNbComp;
1333     vtkFloatArray *aFloatArray = vtkFloatArray::New();
1334
1335     switch(aNbComp) {
1336     case 1:
1337       aFloatArray->SetNumberOfComponents(1);
1338       aDataSetAttributes->SetScalars(aFloatArray);
1339       break;
1340     default:
1341       aFloatArray->SetNumberOfComponents(3);
1342       aDataSetAttributes->SetVectors(aFloatArray);
1343     }
1344     aFloatArray->SetNumberOfTuples(aNbTuples);
1345     aFloatArray->SetName(aFieldName.c_str());
1346
1347     vtkFloatArray *aDataArray = vtkFloatArray::New();
1348     aDataArray->SetNumberOfComponents(aNbComp);
1349     aDataArray->SetNumberOfTuples(aNbTuples);
1350     aDataArray->SetName("VISU_FIELD");
1351     aDataSetAttributes->AddArray(aDataArray);
1352
1353     INITMSG(MYDEBUG,"GetTimeStampOnProfile "<<
1354             "- theEntity = "<<theEntity<<
1355             "; aNbTuples = "<<aNbTuples<<
1356             "; aNbComp = "<<aNbComp<<
1357             endl);
1358     
1359     int aSize = max(3,aNbComp);
1360     TVector<float> aDataValues(aSize,0.0);
1361
1362     TGeom2Value& aGeom2Value = theValForTime->myGeom2Value;
1363     TGeom2Value::const_iterator anIter = aGeom2Value.begin();
1364     for(int aTupleId = 0; anIter != aGeom2Value.end(); anIter++){
1365       EGeometry aEGeom = anIter->first;
1366       const TMeshValue& aMeshValue = anIter->second;
1367       
1368       int aNbElem = aMeshValue.myNbElem;
1369       int aNbGauss = aMeshValue.myNbGauss;
1370       INITMSG(MYDEBUG,
1371               "- aEGeom = "<<aEGeom<<
1372               "; aNbElem = "<<aNbElem<<
1373               "; aNbGauss = "<<aNbGauss<<
1374               endl);
1375
1376       for(int iElem = 0; iElem < aNbElem; iElem++, aTupleId++){
1377         TCValueSliceArr aValueSliceArr = aMeshValue.GetCompValueSliceArr(iElem);
1378         for(int iComp = 0; iComp < aNbComp; iComp++){
1379           const TCValueSlice& aValueSlice = aValueSliceArr[iComp];
1380           aDataValues[iComp] = 0.0;
1381           for(int iGauss = 0; iGauss < aNbGauss; iGauss++){
1382             aDataValues[iComp] += aValueSlice[iGauss];
1383           }
1384           aDataValues[iComp] /= aNbGauss;
1385         }
1386         aFloatArray->SetTuple(aTupleId,&aDataValues[0]);
1387         aDataArray->SetTuple(aTupleId,&aDataValues[0]);
1388       }
1389     }
1390     aFloatArray->Delete();
1391     aDataArray->Delete();
1392   }
1393
1394
1395   //---------------------------------------------------------------
1396   void
1397   GetCells(const TVTKSource& theSource,
1398            const PSubProfileImpl& theSubProfile,
1399            const PProfileImpl& theProfile,
1400            const PMeshOnEntityImpl& theMeshOnEntity)
1401   {
1402     vtkIdType aNbCells = theSubProfile->myNbCells;
1403     vtkIdType aCellsSize = theSubProfile->myCellsSize;
1404     VISU::EGeometry aEGeom = theSubProfile->myGeom;
1405     vtkIdType aNbNodes = VISUGeom2NbNodes(aEGeom);
1406     vtkIdType aVGeom = VISUGeom2VTK(aEGeom);
1407
1408     INITMSG(MYDEBUG,"GetCells - aVGeom = "<<aVGeom<<endl);
1409
1410     const TSubMeshID& aSubMeshID = theSubProfile->mySubMeshID;
1411
1412     const VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
1413     VISU::TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.find(aEGeom);
1414     if(anIter == aGeom2SubMesh.end())
1415       EXCEPTION(runtime_error,"GetCells >> There is no elements for the GEOM("<<aEGeom<<")");
1416     
1417     const VISU::TSubMeshImpl& aSubMesh = anIter->second;
1418     const TCell2Connect& aCell2Connect = aSubMesh.myCell2Connect;
1419     
1420     vtkCellArray* aConnectivity = vtkCellArray::New();
1421     aConnectivity->Allocate(aCellsSize,0);
1422     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
1423     aCellTypesArray->SetNumberOfComponents(1);
1424     aCellTypesArray->SetNumberOfTuples(aNbCells);
1425     
1426     if(theSubProfile->myStatus == eAddAll){
1427       VISU::TCell2Connect::const_iterator anIter = aCell2Connect.begin();
1428       for(vtkIdType anId = 0, aConnId = 0; anIter != aCell2Connect.end(); anIter++){
1429         const TConnect& anArray = aCell2Connect[anId];
1430         PrintCells(aConnId,aConnectivity,anArray);
1431         aCellTypesArray->SetValue(anId,(unsigned char)aVGeom);
1432         aConnId += aNbNodes;
1433         anId++;
1434       }
1435     }else{
1436       VISU::TSubMeshID::const_iterator anIter = aSubMeshID.begin();
1437       for(vtkIdType anId = 0, aConnId = 0; anIter != aSubMeshID.end(); anIter++){
1438         vtkIdType aSubId = *anIter;
1439         const TConnect& anArray = aCell2Connect[aSubId];
1440         PrintCells(aConnId,aConnectivity,anArray);
1441         aCellTypesArray->SetValue(anId,(unsigned char)aVGeom);
1442         aConnId += aNbNodes;
1443         anId++;
1444       }
1445     }
1446     
1447     vtkIdType *pts = 0, npts = 0;
1448     vtkIntArray* aCellLocationsArray = vtkIntArray::New();
1449     
1450     aCellLocationsArray->SetNumberOfComponents(1);
1451     aCellLocationsArray->SetNumberOfTuples(aNbCells);
1452     aConnectivity->InitTraversal();
1453     for(int i=0; aConnectivity->GetNextCell(npts,pts); i++)
1454       aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
1455     theSource->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
1456     
1457     aCellLocationsArray->Delete();
1458     aCellTypesArray->Delete();
1459     aConnectivity->Delete();
1460   }
1461   
1462   
1463   //---------------------------------------------------------------
1464   void
1465   GetMeshOnSubProfile(const PMeshImpl& theMesh,
1466                       const PMeshOnEntityImpl& theMeshOnEntity,
1467                       const PProfileImpl& theProfile,
1468                       const PSubProfileImpl& theSubProfile)
1469   {
1470     INITMSG(MYDEBUG,"GetMeshOnSubProfile - aEGeom = "<<theSubProfile->myGeom<<endl);
1471     
1472     const TVTKSource& aSource = theSubProfile->GetSource();
1473     if(theSubProfile->myIsVTKDone)
1474       return;
1475     
1476     aSource->SetPoints(GetPoints(theMesh));
1477     INITMSGA(MYDEBUG,0,"GetNumberOfPoints - "<<aSource->GetNumberOfPoints()<<endl);
1478     GetCells(aSource,theSubProfile,theProfile,theMeshOnEntity);
1479     BEGMSG(MYDEBUG,"GetNumberOfCells - "<<aSource->GetNumberOfCells()<<endl);
1480     
1481     theSubProfile->myIsVTKDone = true;
1482   }
1483   
1484   
1485   //---------------------------------------------------------------
1486   void
1487   GetMeshOnProfile(const PMeshImpl& theMesh,
1488                    const PMeshOnEntityImpl& theMeshOnEntity,
1489                    const PProfileImpl& theProfile)
1490   {
1491     INITMSG(MYDEBUG,"GetMeshOnProfile - anEntity = "<<theMeshOnEntity->myEntity<<endl);
1492
1493     if(theProfile->myIsVTKDone)
1494       return;
1495     
1496     theProfile->myMeshOnEntity = theMeshOnEntity.get();
1497     const TVTKAppendFilter& anAppendFilter = theProfile->GetFilter();
1498     anAppendFilter->SetPoints(GetPoints(theMesh));
1499
1500     if(theProfile->myIsAll){
1501       TVTKOutput* aDataSet = theMeshOnEntity->GetVTKOutput();
1502       anAppendFilter->AddInput(aDataSet);
1503     }else{
1504       const TGeom2SubProfile& aGeom2SubProfile = theProfile->myGeom2SubProfile;
1505
1506       TID2ID& anElemObj2VTKID = theProfile->myElemObj2VTKID;
1507
1508       TSubProfileArr& aSubProfileArr = theProfile->mySubProfileArr;
1509       aSubProfileArr.resize(aGeom2SubProfile.size());
1510
1511       TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin();
1512       for(vtkIdType anInputID = 0, aCellID = 0; anIter != aGeom2SubProfile.end(); anIter++){
1513         PSubProfileImpl aSubProfile = anIter->second;
1514         if(aSubProfile->myStatus == eRemoveAll)
1515           continue;
1516         
1517         GetMeshOnSubProfile(theMesh,
1518                             theMeshOnEntity,
1519                             theProfile,
1520                             aSubProfile);
1521         
1522         const TVTKSource& aSource = aSubProfile->GetSource();
1523         anAppendFilter->AddInput(aSource.GetPointer());
1524
1525         vtkIdType aNbCells = aSource->GetNumberOfCells();
1526         for(vtkIdType aCell = 0; aCell < aNbCells; aCell++, aCellID++){
1527           anElemObj2VTKID[aSubProfile->GetElemObjID(aCell)] = aCellID;
1528         }
1529
1530         aSubProfileArr[anInputID++] = aSubProfile;
1531       }
1532     }
1533     anAppendFilter->Update(); // Fix on VTK
1534     theProfile->myNamedPointCoords = theMesh->myNamedPointCoords;
1535     
1536     theProfile->myIsVTKDone = true;
1537   }
1538   
1539   
1540   //---------------------------------------------------------------
1541   void 
1542   GetTimeStampOnGaussMesh(const TVTKSource& theSource,
1543                           const PFieldImpl& theField, 
1544                           const PValForTimeImpl& theValForTime)
1545   {
1546     int aNbTuples = theSource->GetNumberOfPoints();
1547     std::string aFieldName = GenerateFieldName(theField,theValForTime);
1548
1549     vtkDataSetAttributes* aDataSetAttributes;
1550     switch(theField->myEntity){
1551     case VISU::NODE_ENTITY : 
1552       aDataSetAttributes = theSource->GetPointData();
1553       break;
1554     default: 
1555       aDataSetAttributes = theSource->GetCellData();
1556     }
1557
1558     int aNbComp = theField->myNbComp;
1559     vtkFloatArray *aFloatArray = vtkFloatArray::New();
1560     switch(aNbComp){
1561     case 1:
1562       aFloatArray->SetNumberOfComponents(1);
1563       aDataSetAttributes->SetScalars(aFloatArray);
1564       break;
1565     default:
1566       aFloatArray->SetNumberOfComponents(3);
1567       aDataSetAttributes->SetVectors(aFloatArray);
1568     }
1569     aFloatArray->SetNumberOfTuples(aNbTuples);
1570     aFloatArray->SetName(aFieldName.c_str());
1571
1572     vtkFloatArray *aDataArray = vtkFloatArray::New();
1573     aDataArray->SetNumberOfComponents(aNbComp);
1574     aDataArray->SetNumberOfTuples(aNbTuples);
1575     aDataArray->SetName("VISU_FIELD");
1576     aDataSetAttributes->AddArray(aDataArray);
1577
1578     INITMSG(MYDEBUG,"GetTimeStampOnGaussMesh "<<
1579             "- aNbTuples = "<<aNbTuples<<
1580             "; aNbComp = "<<aNbComp<<
1581             endl);
1582     
1583     int aSize = max(3,aNbComp);
1584     TVector<float> aDataValues(aSize,0.0);
1585
1586     const TGeom2Value& aGeom2Value = theValForTime->myGeom2Value;
1587
1588     PGaussMeshImpl aGaussMesh = theValForTime->myGaussMesh;
1589     const TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
1590     TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin();
1591     for(int aTupleId = 0; anIter != aGeom2GaussSubMesh.end(); anIter++){
1592       EGeometry aEGeom = anIter->first;
1593
1594       PGaussSubMeshImpl aGaussSubMesh = anIter->second;
1595       if(!aGaussSubMesh->myIsDone)
1596         continue;
1597       
1598       TGeom2Value::const_iterator anIter2 = aGeom2Value.find(aEGeom);
1599       if(anIter2 == aGeom2Value.end()){
1600         EXCEPTION(runtime_error,
1601                   "GetTimeStampOnGaussMesh >> Can't find values for corresponding Gauss Points SubMesh");
1602       }
1603       const TMeshValue& aMeshValue = anIter2->second;
1604       int aNbGauss = aMeshValue.myNbGauss;
1605       int aNbElem = aMeshValue.myNbElem;
1606       
1607       if(aNbGauss < 1)
1608         continue;
1609
1610       const TPointCoords& aCoords = aGaussSubMesh->myPointCoords;
1611
1612       INITMSG(MYDEBUG,
1613               "- aEGeom = "<<aEGeom<<
1614               "; aNbElem = "<<aNbElem<<
1615               "; aNbGauss = "<<aNbGauss<<
1616               "; aCoords.GetNbPoints() = "<<aCoords.GetNbPoints()<<
1617               endl);
1618
1619       if(aCoords.GetNbPoints() == aNbElem*aNbGauss){
1620         for(int iElem = 0; iElem < aNbElem; iElem++){
1621           TCValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem);
1622           for(int iGauss = 0; iGauss < aNbGauss; iGauss++, aTupleId++){
1623             const TCValueSlice& aValueSlice = aValueSliceArr[iGauss];
1624             for(int iComp = 0; iComp < aNbComp; iComp++){
1625               aDataValues[iComp] = aValueSlice[iComp];
1626             }
1627             aFloatArray->SetTuple(aTupleId,&aDataValues[0]);
1628             aDataArray->SetTuple(aTupleId,&aDataValues[0]);
1629           }
1630         }
1631       }else{
1632         for(int iElem = 0; iElem < aNbElem; iElem++, aTupleId++){
1633           TCValueSliceArr aValueSliceArr = aMeshValue.GetCompValueSliceArr(iElem);
1634           for(int iComp = 0; iComp < aNbComp; iComp++){
1635             const TCValueSlice& aValueSlice = aValueSliceArr[iComp];
1636             aDataValues[iComp] = 0.0;
1637             for(int iGauss = 0; iGauss < aNbGauss; iGauss++){
1638               aDataValues[iComp] += aValueSlice[iGauss];
1639             }
1640             aDataValues[iComp] /= aNbGauss;
1641           }
1642           aFloatArray->SetTuple(aTupleId,&aDataValues[0]);
1643           aDataArray->SetTuple(aTupleId,&aDataValues[0]);
1644         }
1645       }
1646     }
1647     aFloatArray->Delete();
1648     aDataArray->Delete();
1649   }
1650
1651
1652   //---------------------------------------------------------------
1653   void
1654   GetSource(const TVTKSource& theSource,
1655             const PGaussSubMeshImpl& theGaussSubMesh,
1656             const PMeshOnEntityImpl& theMeshOnEntity)
1657   {
1658     const TPointCoords& aCoords = theGaussSubMesh->myPointCoords;
1659     vtkIdType aNbPoints = aCoords.GetNbPoints();
1660     vtkIdType aDim = aCoords.GetDim();
1661     
1662     vtkIdType aNbCells = theGaussSubMesh->myNbCells;
1663     vtkIdType aCellsSize = theGaussSubMesh->myCellsSize;
1664     
1665     vtkCellArray* aConnectivity = vtkCellArray::New();
1666     aConnectivity->Allocate(aCellsSize,0);
1667     vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
1668     aCellTypesArray->SetNumberOfComponents(1);
1669     aCellTypesArray->SetNumberOfTuples(aNbCells);
1670     
1671     const TVTKPoints& aPoints = aCoords.GetPoints();
1672     vtkIdList *anIdList = vtkIdList::New();
1673     anIdList->SetNumberOfIds(1);
1674     for(vtkIdType aPointId = 0; aPointId < aNbPoints; aPointId++){
1675       TCCoordSlice aSlice = aCoords.GetCoordSlice(aPointId);
1676       
1677       float aCoords[3] = {0.0, 0.0, 0.0};
1678       for(vtkIdType aDimId = 0; aDimId < aDim; aDimId++)
1679         aCoords[aDimId] = aSlice[aDimId];
1680       
1681       aPoints->SetPoint(aPointId,aCoords);
1682       
1683       anIdList->SetId(0,aPointId);
1684       aConnectivity->InsertNextCell(anIdList);
1685       aCellTypesArray->SetValue(aPointId,(unsigned char)VTK_VERTEX);
1686     }
1687     anIdList->Delete();
1688     
1689     vtkIntArray* aCellLocationsArray = vtkIntArray::New();
1690     aCellLocationsArray->SetNumberOfComponents(1);
1691     aCellLocationsArray->SetNumberOfTuples(aNbCells);
1692     
1693     vtkIdType *pts = 0, npts = 0;
1694     aConnectivity->InitTraversal();
1695     for(int i = 0; aConnectivity->GetNextCell(npts,pts); i++)
1696       aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
1697     
1698     const TVTKSource& aSource = theGaussSubMesh->GetSource();
1699     aSource->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
1700     aSource->SetPoints(aPoints.GetPointer());
1701     
1702     aCellLocationsArray->Delete();
1703     aCellTypesArray->Delete();
1704     aConnectivity->Delete();
1705   }
1706   
1707   
1708   //---------------------------------------------------------------
1709   void
1710   GetGaussSubMesh(const PMeshImpl& theMesh,
1711                   const PMeshOnEntityImpl& theMeshOnEntity,
1712                   const PGaussMeshImpl& theGaussMesh,
1713                   const PGaussSubMeshImpl& theGaussSubMesh)
1714   {
1715     PGaussImpl aGauss = theGaussSubMesh->myGauss;
1716     INITMSG(MYDEBUG,"GetGaussSubMesh - aVGeom = "<<aGauss->myGeom<<endl);
1717     
1718     if(!theGaussSubMesh->myIsDone)
1719       return;
1720     
1721     if(theGaussSubMesh->myIsVTKDone)
1722       return;
1723     
1724     const TVTKSource& aSource = theGaussSubMesh->GetSource();
1725     GetSource(aSource,theGaussSubMesh,theMeshOnEntity);
1726     INITMSGA(MYDEBUG,0,"GetNumberOfPoints - "<<aSource->GetNumberOfPoints()<<endl);
1727     BEGMSG(MYDEBUG,"GetNumberOfCells - "<<aSource->GetNumberOfCells()<<endl);
1728     
1729     theGaussSubMesh->myIsVTKDone = true;
1730   }
1731   
1732
1733   //---------------------------------------------------------------
1734   void
1735   BuildGaussMesh(const PMeshImpl& theMesh,
1736                  const PMeshOnEntityImpl& theMeshOnEntity,
1737                  const PGaussMeshImpl& theGaussMesh)
1738   {
1739     if(theGaussMesh->myIsVTKDone)
1740       return;
1741
1742     INITMSG(MYDEBUG,"BuildGaussMesh"<<endl);
1743     const TVTKAppendFilter& anAppendFilter = theGaussMesh->GetFilter();
1744     const TGeom2GaussSubMesh& aGeom2GaussSubMesh = theGaussMesh->myGeom2GaussSubMesh;
1745     TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin();
1746     for(; anIter != aGeom2GaussSubMesh.end(); anIter++){
1747       PGaussSubMeshImpl aGaussSubMesh = anIter->second;
1748       if(aGaussSubMesh->myStatus == eRemoveAll)
1749         continue;
1750       
1751       GetGaussSubMesh(theMesh,
1752                       theMeshOnEntity,
1753                       theGaussMesh,
1754                       aGaussSubMesh);
1755       
1756       const TVTKSource& aSource = aGaussSubMesh->GetSource();
1757       
1758       anAppendFilter->AddInput(aSource.GetPointer());
1759     }
1760     anAppendFilter->Update(); // Fix on VTK
1761
1762     theMeshOnEntity->GetVTKOutput()->Update();
1763
1764     vtkDataSet* aSource = anAppendFilter->GetOutput();
1765     INITMSGA(MYDEBUG,0,"aNbPoints - "<<aSource->GetNumberOfPoints()<<endl);
1766     BEGMSG(MYDEBUG,"aNbCells - "<<aSource->GetNumberOfCells()<<endl);
1767     
1768     theGaussMesh->myIsVTKDone = true;
1769   }
1770
1771
1772   //---------------------------------------------------------------
1773   void
1774   PrintMemorySize(vtkUnstructuredGrid* theDataSet)
1775   {
1776     theDataSet->Update();
1777     BEGMSG(1,"GetPoints() = "<<float(theDataSet->GetPoints()->GetActualMemorySize()*1000)<<endl);
1778     BEGMSG(1,"GetCells() = "<<float(theDataSet->GetCells()->GetActualMemorySize()*1000)<<endl);
1779     BEGMSG(1,"GetCellTypesArray() = "<<float(theDataSet->GetCellTypesArray()->GetActualMemorySize()*1000)<<endl);
1780     BEGMSG(1,"GetCellLocationsArray() = "<<float(theDataSet->GetCellLocationsArray()->GetActualMemorySize()*1000)<<endl);
1781     theDataSet->BuildLinks();
1782     BEGMSG(1,"GetCellLinks() = "<<float(theDataSet->GetCellLinks()->GetActualMemorySize()*1000)<<endl);
1783     BEGMSG(1,"GetPointData() = "<<float(theDataSet->GetPointData()->GetActualMemorySize()*1000)<<endl);
1784     BEGMSG(1,"GetCellData() = "<<float(theDataSet->GetCellData()->GetActualMemorySize()*1000)<<endl);
1785     BEGMSG(1,"GetActualMemorySize() = "<<float(theDataSet->GetActualMemorySize()*1000)<<endl);
1786   }
1787 }
1788
1789
1790 //---------------------------------------------------------------
1791 VISU_Convertor_impl
1792 ::VISU_Convertor_impl() 
1793 {
1794   myIsDone = false;
1795 }
1796
1797
1798 //---------------------------------------------------------------
1799 VISU_Convertor_impl
1800 ::~VISU_Convertor_impl() 
1801 {}
1802
1803
1804 //---------------------------------------------------------------
1805 VISU_Convertor* 
1806 VISU_Convertor_impl
1807 ::Build() 
1808
1809   if(!myIsDone){ 
1810     myIsDone = true;  
1811     BuildEntities();
1812     BuildFields();
1813     BuildMinMax();
1814     BuildGroups();
1815   }
1816   return this;
1817 }
1818
1819 VISU_Convertor* 
1820 VISU_Convertor_impl
1821 ::BuildEntities() 
1822
1823   return this;
1824 }
1825
1826 VISU_Convertor* 
1827 VISU_Convertor_impl
1828 ::BuildFields() 
1829
1830   return this;
1831 }
1832
1833 VISU_Convertor* 
1834 VISU_Convertor_impl
1835 ::BuildMinMax() 
1836
1837   return this;
1838 }
1839
1840 VISU_Convertor* 
1841 VISU_Convertor_impl
1842 ::BuildGroups() 
1843
1844   return this;
1845 }
1846
1847
1848 //---------------------------------------------------------------
1849 VISU::PNamedIDMapper 
1850 VISU_Convertor_impl
1851 ::GetMeshOnEntity(const string& theMeshName, 
1852                   const VISU::TEntity& theEntity)
1853 {
1854   INITMSG(MYDEBUG,"GetMeshOnEntity"<<
1855           "; theMeshName = '"<<theMeshName<<"'"<<
1856           "; theEntity = "<<theEntity<<
1857           endl);
1858
1859   //Cheching possibility do the query
1860   TFindMeshOnEntity aFindMeshOnEntity = 
1861     FindMeshOnEntity(theMeshName,theEntity);
1862   
1863   PMeshImpl aMesh = boost::get<0>(aFindMeshOnEntity);;
1864   PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity);
1865   
1866   //Main part of code
1867 #ifndef _DEXCEPT_
1868   try{
1869 #endif
1870     if(!aMeshOnEntity->myIsVTKDone){
1871       const TVTKAppendFilter& anAppendFilter = aMeshOnEntity->GetFilter();
1872       if(MYVTKDEBUG) anAppendFilter->DebugOn();
1873
1874       LoadMeshOnEntity(aMesh,aMeshOnEntity);
1875       anAppendFilter->SetPoints(GetPoints(aMesh));
1876       
1877       const TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
1878       TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin();
1879
1880       TID2ID& anElemObj2VTKID = aMeshOnEntity->myElemObj2VTKID;
1881       TSubMeshArr& aSubMeshArr = aMeshOnEntity->mySubMeshArr;
1882       aSubMeshArr.resize(aGeom2SubMesh.size());
1883
1884       for(vtkIdType anID = 0, aCellID = 0; anIter != aGeom2SubMesh.end(); anIter++, anID++){
1885         EGeometry aEGeom = anIter->first;
1886         vtkIdType aVGeom = VISUGeom2VTK(aEGeom);
1887         PSubMeshImpl aSubMesh = anIter->second;
1888         const TVTKSource& aSource = aSubMesh->GetSource();
1889         aSource->SetPoints(GetPoints(aMesh));
1890         GetCellsOnSubMesh(aSource,aMeshOnEntity,aSubMesh,aVGeom);
1891         anAppendFilter->AddInput(aSource.GetPointer());
1892
1893         aSubMesh->myStartID = aCellID;
1894         vtkIdType aNbCells = aSource->GetNumberOfCells();
1895         for(vtkIdType aCell = 0; aCell < aNbCells; aCell++, aCellID++){
1896           vtkIdType anObjID = aSubMesh->GetElemObjID(aCell);
1897           anElemObj2VTKID[anObjID] = aCellID;
1898         }
1899         aSubMeshArr[anID] = aSubMesh;
1900       }
1901       aMeshOnEntity->myNamedPointCoords = aMesh->myNamedPointCoords;
1902
1903       aMeshOnEntity->myIsVTKDone = true;
1904
1905       if(MYDEBUGWITHFILES){
1906         std::string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
1907         std::string aFileName = string(getenv("HOME"))+"/"+getenv("USER")+"-";
1908         aFileName += aMeshName + dtos("-%d-",int(theEntity)) + "-Conv.vtk";
1909         VISU::WriteToFile(anAppendFilter->GetOutput(),aFileName);
1910       }
1911
1912       if(MYVTKDEBUG){
1913         GetMeshOnEntitySize(theMeshName,theEntity);
1914         PrintMemorySize(anAppendFilter->GetOutput());
1915       }
1916     }
1917
1918 #ifndef _DEXCEPT_
1919   }catch(...){
1920     throw;
1921   }
1922 #endif
1923
1924   return aMeshOnEntity;
1925 }
1926
1927
1928 //---------------------------------------------------------------
1929 VISU::PIDMapper 
1930 VISU_Convertor_impl
1931 ::GetFamilyOnEntity(const std::string& theMeshName, 
1932                     const VISU::TEntity& theEntity,
1933                     const std::string& theFamilyName)
1934 {
1935   INITMSG(MYDEBUG,"GetFamilyOnEntity"<<
1936           "; theMeshName = '"<<theMeshName<<"'"<<
1937           "; theEntity = "<<theEntity<<
1938           "; theFamilyName = '"<<theFamilyName<<"'"<<
1939           endl);
1940
1941   //Cheching possibility do the query
1942   TFindFamilyOnEntity aFindFamilyOnEntity = 
1943     FindFamilyOnEntity(theMeshName,theEntity,theFamilyName);
1944
1945   PMeshImpl aMesh = boost::get<0>(aFindFamilyOnEntity);;
1946   PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindFamilyOnEntity);
1947   PFamilyImpl aFamily = boost::get<2>(aFindFamilyOnEntity);
1948
1949   //Main part of code
1950 #ifndef _DEXCEPT_
1951   try{
1952 #endif
1953     if(!aFamily->myIsVTKDone){
1954       const TVTKSource& aSource = aFamily->GetSource();
1955       if(MYVTKDEBUG) aSource->DebugOn();
1956
1957       GetMeshOnEntity(theMeshName,theEntity);
1958
1959       LoadFamilyOnEntity(aMesh,aMeshOnEntity,aFamily);
1960       aSource->SetPoints(GetPoints(aMesh));
1961       GetCellsOnFamily(aSource,aMeshOnEntity,aFamily);
1962
1963       aFamily->myNamedPointCoords = aMesh->myNamedPointCoords;
1964
1965       aFamily->myIsVTKDone = true;
1966
1967       if(MYDEBUGWITHFILES){
1968         std::string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
1969         std::string aFamilyName = QString(theFamilyName.c_str()).simplifyWhiteSpace().latin1();
1970         std::string aFileName = string(getenv("HOME"))+"/"+getenv("USER")+"-";
1971         aFileName += aMeshName + dtos("-%d-",int(theEntity)) + aFamilyName + "-Conv.vtk";
1972         VISU::WriteToFile(aSource.GetPointer(),aFileName);
1973       }
1974
1975       if(MYVTKDEBUG){
1976         GetFamilyOnEntitySize(theMeshName,theEntity,theFamilyName);
1977         PrintMemorySize(aSource.GetPointer());
1978       }
1979     }
1980
1981 #ifndef _DEXCEPT_
1982   }catch(...){
1983     throw;
1984   }
1985 #endif
1986
1987   return aFamily;
1988 }
1989
1990
1991 //---------------------------------------------------------------
1992 VISU::PIDMapper 
1993 VISU_Convertor_impl
1994 ::GetMeshOnGroup(const string& theMeshName, 
1995                  const string& theGroupName)
1996 {
1997   INITMSG(MYDEBUG,"GetMeshOnGroup\n");
1998   INITMSGA(MYDEBUG,0,
1999            "- theMeshName = '"<<theMeshName<<
2000            "'; theGroupName = '"<<theGroupName<<"'"<<
2001            endl);
2002
2003   //Cheching possibility do the query
2004   TFindMeshOnGroup aFindMeshOnGroup = FindMeshOnGroup(theMeshName,theGroupName);
2005   PMeshImpl aMesh = boost::get<0>(aFindMeshOnGroup);
2006   PGroupImpl aGroup = boost::get<1>(aFindMeshOnGroup);
2007
2008   //Main part of code
2009 #ifndef _DEXCEPT_
2010   try{
2011 #endif
2012     if(!aGroup->myIsVTKDone){
2013       const TVTKAppendFilter& anAppendFilter = aGroup->GetFilter();
2014       const VISU::TFamilySet& aFamilySet = aGroup->myFamilySet;
2015
2016       LoadMeshOnGroup(aMesh,aFamilySet);
2017       anAppendFilter->SetPoints(GetPoints(aMesh));
2018
2019       TFamilySet::const_iterator anIter = aFamilySet.begin();
2020
2021       TID2ID& anElemObj2VTKID = aGroup->myElemObj2VTKID;
2022       TFamilyArr& aFamilyArr = aGroup->myFamilyArr;
2023       aFamilyArr.resize(aFamilySet.size());
2024
2025       for(vtkIdType anID = 0; anIter != aFamilySet.end(); anIter++){
2026         PFamilyImpl aFamily = *anIter;
2027         const std::string& aFamilyName = aFamily->myName;
2028         const VISU::TEntity& anEntity = aFamily->myEntity;
2029
2030         VISU::PIDMapper anIDMapper = GetFamilyOnEntity(theMeshName,anEntity,aFamilyName);
2031         VISU::TVTKOutput* anOutput = anIDMapper->GetVTKOutput();
2032         anAppendFilter->AddInput(anOutput);
2033
2034         vtkIdType aNbCells = anOutput->GetNumberOfCells();
2035         for(vtkIdType aCellID = 0; aCellID < aNbCells; aCellID++){
2036           anElemObj2VTKID[aFamily->GetElemObjID(aCellID)] = aCellID;
2037         }
2038         aFamilyArr[anID] = aFamily;
2039       }
2040       aGroup->myNamedPointCoords = aMesh->myNamedPointCoords;
2041
2042       aGroup->myIsVTKDone = true;
2043
2044       if(MYDEBUGWITHFILES){
2045         std::string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
2046         std::string aGroupName = QString(theGroupName.c_str()).simplifyWhiteSpace().latin1();
2047         std::string aFileName = string(getenv("HOME"))+"/"+getenv("USER")+"-";
2048         aFileName += aMeshName + "-" + aGroupName + "-Conv.vtk";
2049         VISU::WriteToFile(anAppendFilter->GetOutput(),aFileName);
2050       }
2051     }
2052 #ifndef _DEXCEPT_
2053   }catch(...){
2054     throw;
2055   }
2056 #endif
2057
2058   return aGroup;
2059 }
2060
2061
2062 //---------------------------------------------------------------
2063 VISU::TVTKOutput*
2064 VISU_Convertor_impl
2065 ::GetTimeStampOnProfile(const VISU::PMeshImpl& theMesh,
2066                         const VISU::PMeshOnEntityImpl& theMeshOnEntity,
2067                         const VISU::PFieldImpl& theField,
2068                         const VISU::PValForTimeImpl& theValForTime,
2069                         const VISU::PIDMapperFilter& theIDMapperFilter,
2070                         const VISU::PProfileImpl& theProfile,
2071                         const VISU::TEntity& theEntity)
2072 {
2073   LoadMeshOnEntity(theMesh,theMeshOnEntity);
2074   GetMeshOnEntity(theMeshOnEntity->myMeshName,theMeshOnEntity->myEntity);
2075   GetMeshOnProfile(theMesh,theMeshOnEntity,theProfile);
2076
2077   theIDMapperFilter->myIDMapper = theProfile;
2078   TVTKOutput* anOutput = theIDMapperFilter->GetVTKOutput();
2079   const TVTKSource& aSource = theIDMapperFilter->mySource.GetSource();
2080   ::GetTimeStampOnProfile(aSource,theField,theValForTime,theEntity);
2081
2082   return anOutput;
2083 }
2084
2085
2086 //---------------------------------------------------------------
2087 VISU::PIDMapper 
2088 VISU_Convertor_impl
2089 ::GetTimeStampOnMesh(const string& theMeshName, 
2090                      const VISU::TEntity& theEntity,
2091                      const string& theFieldName,
2092                      int theStampsNum)
2093 {
2094   INITMSG(MYDEBUG,"GetTimeStampOnMesh"<<
2095           "; theMeshName = '"<<theMeshName<<"'"<<
2096           "; theEntity = "<<theEntity<<
2097           "; theFieldName = '"<<theFieldName<<"'"<<
2098           "; theStampsNum = "<<theStampsNum<<
2099           endl);
2100
2101   //Cheching possibility do the query
2102   TFindTimeStamp aFindTimeStamp = FindTimeStamp(theMeshName,
2103                                                 theEntity,
2104                                                 theFieldName,
2105                                                 theStampsNum);
2106
2107   PMeshImpl aMesh = boost::get<0>(aFindTimeStamp);
2108   PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindTimeStamp);
2109   PMeshOnEntityImpl aVTKMeshOnEntity = boost::get<2>(aFindTimeStamp);
2110   PValForTimeImpl aValForTime = boost::get<4>(aFindTimeStamp);
2111   PFieldImpl aField = boost::get<3>(aFindTimeStamp);
2112
2113   //Main part of code
2114   PIDMapperFilter anIDMapperFilter = aValForTime->myIDMapperFilter;
2115 #ifndef _DEXCEPT_
2116   try{
2117 #endif
2118     if(!anIDMapperFilter->myIsVTKDone){
2119       LoadValForTimeOnMesh(aMesh,aMeshOnEntity,aField,aValForTime);
2120
2121       TVTKOutput* anOutput;
2122       try{
2123         anOutput = GetTimeStampOnProfile(aMesh,
2124                                          aVTKMeshOnEntity,
2125                                          aField,
2126                                          aValForTime,
2127                                          anIDMapperFilter,
2128                                          aValForTime->myProfile,
2129                                          aMeshOnEntity->myEntity);
2130       }catch(std::exception& exc){
2131         MSG(MYDEBUG,"Follow exception was occured :\n"<<exc.what());
2132         anOutput = GetTimeStampOnProfile(aMesh,
2133                                          aMeshOnEntity,
2134                                          aField,
2135                                          aValForTime,
2136                                          anIDMapperFilter,
2137                                          aValForTime->myProfile,
2138                                          aVTKMeshOnEntity->myEntity);
2139       }
2140
2141       anIDMapperFilter->myIsVTKDone = true;
2142
2143       if(MYDEBUGWITHFILES){
2144         string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
2145         string aFieldName = QString(theFieldName.c_str()).simplifyWhiteSpace().latin1();
2146         string aPrefix = string(getenv("HOME"))+"/"+getenv("USER")+"-";
2147         string aFileName = aPrefix + aMeshName + dtos("-%d-",int(theEntity)) + 
2148           aFieldName + dtos("-%d",theStampsNum) + "-Conv.vtk";
2149         VISU::WriteToFile(anOutput,aFileName);
2150       }
2151       if(MYVTKDEBUG){
2152         GetTimeStampSize(theMeshName,theEntity,theFieldName,theStampsNum);
2153         anOutput->Update();
2154         if(theEntity == VISU::NODE_ENTITY)
2155           BEGMSG(MYVTKDEBUG,"GetPointData() = "<<float(anOutput->GetPointData()->GetActualMemorySize()*1000)<<endl);
2156         else
2157           BEGMSG(MYVTKDEBUG,"GetCellData() = "<<float(anOutput->GetCellData()->GetActualMemorySize()*1000)<<endl);
2158         BEGMSG(MYVTKDEBUG,"GetActualMemorySize() = "<<float(anOutput->GetActualMemorySize()*1000)<<endl);
2159       }
2160     }
2161 #ifndef _DEXCEPT_
2162   }catch(std::exception& exc){
2163     throw;
2164   }catch(...){
2165     throw;
2166   }
2167 #endif
2168
2169   return anIDMapperFilter;
2170 }
2171
2172
2173 //---------------------------------------------------------------
2174 VISU::PGaussPtsIDMapper 
2175 VISU_Convertor_impl
2176 ::GetTimeStampOnGaussPts(const string& theMeshName, 
2177                          const VISU::TEntity& theEntity,
2178                          const string& theFieldName,
2179                          int theStampsNum)
2180 {
2181   INITMSG(MYDEBUG,"GetTimeStampOnGaussPts"<<
2182           "; theMeshName = '"<<theMeshName<<"'"<<
2183           "; theEntity = "<<theEntity<<
2184           "; theFieldName = '"<<theFieldName<<"'"<<
2185           "; theStampsNum = "<<theStampsNum<<
2186           endl);
2187
2188   //Cheching possibility do the query
2189   TFindTimeStamp aFindTimeStamp = FindTimeStamp(theMeshName,
2190                                                 theEntity,
2191                                                 theFieldName,
2192                                                 theStampsNum);
2193   
2194   PMeshImpl aMesh = boost::get<0>(aFindTimeStamp);
2195   PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindTimeStamp);
2196   PMeshOnEntityImpl aVTKMeshOnEntity = aMeshOnEntity;
2197   PValForTimeImpl aValForTime = boost::get<4>(aFindTimeStamp);
2198   PFieldImpl aField = boost::get<3>(aFindTimeStamp);
2199
2200   //Main part of code
2201   PGaussPtsIDFilter aGaussPtsIDFilter = aValForTime->myGaussPtsIDFilter;
2202 #ifndef _DEXCEPT_
2203   try{
2204 #endif
2205     if(!aGaussPtsIDFilter->myIsVTKDone){
2206       LoadValForTimeOnGaussPts(aMesh,aMeshOnEntity,aField,aValForTime);
2207       
2208       GetMeshOnEntity(aVTKMeshOnEntity->myMeshName,aVTKMeshOnEntity->myEntity);
2209       
2210       PProfileImpl aProfile = aValForTime->myProfile;
2211       GetMeshOnProfile(aMesh,aVTKMeshOnEntity,aProfile);
2212
2213       PGaussMeshImpl aGaussMesh = aValForTime->myGaussMesh;
2214       TSource& aGaussPtsSource = aGaussMesh->mySource;
2215       if(!aGaussPtsSource.myIsVTKDone){
2216         BuildGaussMesh(aMesh,aVTKMeshOnEntity,aGaussMesh);
2217         aGaussMesh->myParent = aProfile.get();
2218         aGaussPtsSource.myIsVTKDone = true;
2219       }
2220
2221       aGaussPtsIDFilter->myIDMapper = aGaussMesh;
2222       aGaussPtsIDFilter->myGaussPtsIDMapper = aGaussMesh;
2223       TVTKOutput* anOutput = aGaussPtsIDFilter->GetVTKOutput();
2224       const TVTKSource& aSource = aGaussPtsIDFilter->mySource.GetSource();
2225       GetTimeStampOnGaussMesh(aSource,aField,aValForTime);
2226
2227       aGaussPtsIDFilter->myIsVTKDone = true;
2228
2229       if(MYDEBUGWITHFILES){
2230         string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1();
2231         string aFieldName = QString(theFieldName.c_str()).simplifyWhiteSpace().latin1();
2232         string aPrefix = string(getenv("HOME"))+"/"+getenv("USER")+"-";
2233         string aFileName = aPrefix + aMeshName + dtos("-%d-",int(theEntity)) + 
2234           aFieldName + dtos("-%d",theStampsNum) + "-Conv.vtk";
2235         VISU::WriteToFile(anOutput,aFileName);
2236       }
2237       if(MYVTKDEBUG){
2238         GetTimeStampSize(theMeshName,theEntity,theFieldName,theStampsNum);
2239         anOutput->Update();
2240         if(theEntity == VISU::NODE_ENTITY)
2241           BEGMSG(MYVTKDEBUG,"GetPointData() = "<<float(anOutput->GetPointData()->GetActualMemorySize()*1000)<<endl);
2242         else
2243           BEGMSG(MYVTKDEBUG,"GetCellData() = "<<float(anOutput->GetCellData()->GetActualMemorySize()*1000)<<endl);
2244         BEGMSG(MYVTKDEBUG,"GetActualMemorySize() = "<<float(anOutput->GetActualMemorySize()*1000)<<endl);
2245       }
2246     }
2247 #ifndef _DEXCEPT_
2248   }catch(std::exception& exc){
2249     throw;
2250   }catch(...){
2251     throw;
2252   }
2253 #endif
2254
2255   return aGaussPtsIDFilter;
2256 }
2257
2258 //---------------------------------------------------------------
2259 VISU::PMeshImpl 
2260 VISU_Convertor_impl
2261 ::FindMesh(const string& theMeshName)
2262 {
2263   GetMeshMap();
2264   TMeshMap::iterator aMeshMapIter = myMeshMap.find(theMeshName);
2265   if(aMeshMapIter == myMeshMap.end())
2266     EXCEPTION(runtime_error,"FindMesh >> There is no mesh with the name - '"<<theMeshName<<"'!!!");
2267
2268   PMeshImpl aMesh = aMeshMapIter->second;
2269   return aMesh;
2270 }
2271
2272
2273 //---------------------------------------------------------------
2274 VISU_Convertor_impl::TFindMeshOnEntity
2275 VISU_Convertor_impl
2276 ::FindMeshOnEntity(const string& theMeshName,
2277                    const VISU::TEntity& theEntity)
2278 {
2279   PMeshImpl aMesh = FindMesh(theMeshName);
2280   VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
2281   VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(theEntity);
2282   if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
2283     EXCEPTION(runtime_error,"FindMeshOnEntity >> There is no mesh on the entity - "<<theEntity<<"!!!");
2284
2285   PMeshOnEntityImpl aMeshOnEntity = aMeshOnEntityMapIter->second;
2286   
2287   return TFindMeshOnEntity(aMesh,
2288                            aMeshOnEntity);
2289 }
2290
2291
2292 //---------------------------------------------------------------
2293 VISU_Convertor_impl::TFindFamilyOnEntity
2294 VISU_Convertor_impl
2295 ::FindFamilyOnEntity(const string& theMeshName,
2296                      const VISU::TEntity& theEntity,
2297                      const string& theFamilyName)
2298 {
2299   if(theFamilyName != ""){
2300     PMeshImpl aMesh = FindMesh(theMeshName);
2301     VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
2302     VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(theEntity);
2303     if(aMeshOnEntityMapIter == aMeshOnEntityMap.end())
2304       EXCEPTION(runtime_error,"FindFamilyOnEntity >> There is no mesh on the entity - "<<theEntity<<"!!!");
2305
2306     PMeshOnEntityImpl aMeshOnEntity = aMeshOnEntityMapIter->second;
2307
2308     TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
2309     TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
2310     if(aFamilyMapIter != aFamilyMap.end()){
2311       const PFamily& aFamily = aFamilyMapIter->second;
2312       return TFindFamilyOnEntity(aMesh,
2313                                  aMeshOnEntity,
2314                                  aFamily);
2315     }
2316   }
2317   return TFindFamilyOnEntity();
2318 }
2319
2320
2321 //---------------------------------------------------------------
2322 float
2323 VISU_Convertor_impl
2324 ::GetSize() 
2325 {
2326   float aResult = 0.0;
2327   const VISU::TMeshMap& aMeshMap = GetMeshMap();
2328   VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
2329   for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
2330     const string& aMeshName = aMeshMapIter->first;
2331     const VISU::PMesh aMesh = aMeshMapIter->second;
2332     const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
2333     VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
2334     //Import fields
2335     aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
2336     for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
2337       const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
2338       const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
2339       const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
2340       VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
2341       for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
2342         const string& aFieldName = aFieldMapIter->first;
2343         const VISU::PField aField = aFieldMapIter->second;
2344         const VISU::TValField& aValField = aField->myValField;
2345         VISU::TValField::const_iterator aValFieldIter = aValField.begin();
2346         for(; aValFieldIter != aValField.end(); aValFieldIter++){
2347           int aTimeStamp = aValFieldIter->first;
2348           aResult += GetTimeStampSize(aMeshName,anEntity,aFieldName,aTimeStamp);
2349         }
2350       }
2351       //Importing groups
2352       const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
2353       VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
2354       for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
2355         const string& aGroupName = aGroupMapIter->first;
2356         aResult += GetMeshOnGroupSize(aMeshName,aGroupName);
2357       }
2358       //Import families
2359       const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
2360       VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
2361       for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
2362         const string& aFamilyName = aFamilyMapIter->first;
2363         aResult += GetFamilyOnEntitySize(aMeshName,anEntity,aFamilyName);
2364       }
2365       //Import mesh on entity
2366       aResult += GetMeshOnEntitySize(aMeshName,anEntity);
2367     }
2368   }
2369   MSG(MYDEBUG,"GetSize - aResult = "<<float(aResult));
2370   return aResult;
2371 }
2372
2373
2374 //---------------------------------------------------------------
2375 float
2376 VISU_Convertor_impl
2377 ::GetMeshOnEntitySize(const std::string& theMeshName, 
2378                       const VISU::TEntity& theEntity)
2379 {
2380   TFindMeshOnEntity aFindMeshOnEntity = 
2381     FindMeshOnEntity(theMeshName,theEntity);
2382
2383   PMeshImpl aMesh = boost::get<0>(aFindMeshOnEntity);
2384   PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity);
2385
2386   vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord);
2387   vtkIdType aNbCells = aMeshOnEntity->myNbCells;
2388   vtkIdType aCellsSize = aMeshOnEntity->myCellsSize;
2389
2390   vtkIdType aConnectivitySize = aCellsSize*sizeof(vtkIdType);
2391   vtkIdType aTypesSize = aNbCells*sizeof(char);
2392   vtkIdType aLocationsSize = aNbCells*sizeof(int);
2393   float aNbCellsPerPoint = aCellsSize / aNbCells - 1;
2394   vtkIdType aLinksSize = aMesh->myNbPoints * 
2395     (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link));
2396   aLinksSize = 0;
2397   vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize;
2398
2399   MSG(MYDEBUG,"GetMeshOnEntitySize "<<
2400       "- aResult = "<<float(aResult)<<
2401       "; theMeshName = '"<<theMeshName<<"'"<<
2402       "; theEntity = "<<theEntity);
2403   if(MYDEBUG){
2404     INITMSG(MYVTKDEBUG,"- aPointsSize = "<<float(aPointsSize)<<"\n");
2405     BEGMSG(MYVTKDEBUG,"- aConnectivitySize = "<<float(aConnectivitySize)<<"\n");
2406     BEGMSG(MYVTKDEBUG,"- aTypesSize = "<<float(aTypesSize)<<"\n");
2407     BEGMSG(MYVTKDEBUG,"- aLocationsSize = "<<float(aLocationsSize)<<"\n");
2408     BEGMSG(MYVTKDEBUG,"- aLinksSize = "<<float(aLinksSize)<<"\n");
2409   }
2410
2411   aResult = vtkIdType(aResult*ERR_SIZE_CALC);
2412   return aResult;
2413 }
2414
2415
2416 //---------------------------------------------------------------
2417 float
2418 VISU_Convertor_impl
2419 ::GetFamilyOnEntitySize(const std::string& theMeshName, 
2420                         const VISU::TEntity& theEntity,
2421                         const std::string& theFamilyName)
2422 {
2423   TFindFamilyOnEntity aFindFamilyOnEntity = 
2424     FindFamilyOnEntity(theMeshName,theEntity,theFamilyName);
2425   PMeshImpl aMesh = boost::get<0>(aFindFamilyOnEntity);
2426   PFamilyImpl aFamily = boost::get<2>(aFindFamilyOnEntity);
2427   PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindFamilyOnEntity);
2428
2429   vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord);
2430   vtkIdType aNbCells = aFamily->myNbCells;
2431   vtkIdType aCellsSize = aFamily->myCellsSize;
2432
2433   vtkIdType aConnectivitySize = aCellsSize*sizeof(vtkIdType);
2434   vtkIdType aTypesSize = aNbCells*sizeof(char);
2435   vtkIdType aLocationsSize = aNbCells*sizeof(int);
2436   float aNbCellsPerPoint = aCellsSize / aNbCells - 1;
2437   vtkIdType aLinksSize = aMesh->myNbPoints * 
2438     (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link));
2439   aLinksSize = 0;
2440   vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize;
2441
2442   MSG(MYDEBUG,"GetFamilyOnEntitySize "<<
2443       "- aResult = "<<float(aResult)<<
2444       "; theMeshName = '"<<theMeshName<<"'"<<
2445       "; theEntity = "<<theEntity<<
2446       "; theFamilyName = '"<<theFamilyName<<"'");
2447   if(MYDEBUG){
2448     INITMSG(MYVTKDEBUG,"- aPointsSize = "<<float(aPointsSize)<<"\n");
2449     BEGMSG(MYVTKDEBUG,"- aConnectivitySize = "<<float(aConnectivitySize)<<"\n");
2450     BEGMSG(MYVTKDEBUG,"- aTypesSize = "<<float(aTypesSize)<<"\n");
2451     BEGMSG(MYVTKDEBUG,"- aLocationsSize = "<<float(aLocationsSize)<<"\n");
2452     BEGMSG(MYVTKDEBUG,"- aLinksSize = "<<float(aLinksSize)<<"\n");
2453   }
2454
2455   aResult = vtkIdType(aResult*ERR_SIZE_CALC);
2456   return aResult;
2457 }
2458
2459
2460 //---------------------------------------------------------------
2461 VISU_Convertor_impl::TFindMeshOnGroup
2462 VISU_Convertor_impl
2463 ::FindMeshOnGroup(const std::string& theMeshName, 
2464                   const std::string& theGroupName)
2465 {
2466   PMeshImpl aMesh = FindMesh(theMeshName);
2467   VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
2468   VISU::TGroupMap::iterator aGroupMapIter = aGroupMap.find(theGroupName);
2469   if(aGroupMapIter == aGroupMap.end())
2470     EXCEPTION(runtime_error,"FindMesh >> There is no the group in the mesh!!! - '"<<theGroupName<<"'");
2471
2472   VISU::PGroupImpl aGroup = aGroupMapIter->second;
2473   return TFindMeshOnGroup(aMesh,aGroup);
2474 }
2475
2476
2477 float
2478 VISU_Convertor_impl
2479 ::GetMeshOnGroupSize(const std::string& theMeshName, 
2480                      const std::string& theGroupName)
2481 {
2482   TFindMeshOnGroup aFindMeshOnGroup = FindMeshOnGroup(theMeshName,theGroupName);
2483   PMeshImpl aMesh = boost::get<0>(aFindMeshOnGroup);
2484   PGroupImpl aGroup = boost::get<1>(aFindMeshOnGroup);
2485
2486   vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord);
2487   TNbASizeCells aNbASizeCells = aGroup->GetNbASizeCells();
2488   vtkIdType aNbCells = aNbASizeCells.first;
2489   vtkIdType aCellsSize = aNbASizeCells.second;
2490   vtkIdType aConnectivityAndTypesSize = aCellsSize*sizeof(vtkIdType);
2491   vtkIdType aLocationsSize = aNbCells*sizeof(int);
2492   float aNbCellsPerPoint = aCellsSize / aNbCells - 1;
2493   vtkIdType aLinksSize = aMesh->myNbPoints * 
2494     (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(short));
2495   aLinksSize = 0;
2496   vtkIdType aResult = aPointsSize + aConnectivityAndTypesSize + aLocationsSize + aLinksSize;
2497   if(MYDEBUG){
2498     MSG(MYVTKDEBUG,"GetMeshOnGroupSize - aPointsSize = "<<float(aPointsSize));
2499     MSG(MYVTKDEBUG,"GetMeshOnGroupSize - aConnectivityAndTypesSize = "<<float(aConnectivityAndTypesSize));
2500     MSG(MYVTKDEBUG,"GetMeshOnGroupSize - aLocationsSize = "<<float(aLocationsSize));
2501     MSG(MYVTKDEBUG,"GetMeshOnGroupSize - aLinksSize = "<<float(aLinksSize));
2502   }
2503   MSG(MYDEBUG,"GetMeshOnGroupSize - aResult = "<<float(aResult)<<"; theMeshName = '"
2504       <<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
2505
2506   aResult = vtkIdType(aResult*ERR_SIZE_CALC);
2507   return aResult;
2508 }
2509
2510
2511 VISU_Convertor_impl::TFindField
2512 VISU_Convertor_impl
2513 ::FindField(const string& theMeshName, 
2514             const VISU::TEntity& theEntity, 
2515             const string& theFieldName)
2516 {
2517   TFindMeshOnEntity aFindMeshOnEntity = 
2518     FindMeshOnEntity(theMeshName,theEntity);
2519
2520   PMeshImpl aMesh = boost::get<0>(aFindMeshOnEntity);;
2521   PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity);
2522
2523   VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
2524   PMeshOnEntityImpl aVTKMeshOnEntity;
2525   if(theEntity == VISU::NODE_ENTITY){
2526     if(aMeshOnEntityMap.find(VISU::CELL_ENTITY) != aMeshOnEntityMap.end())
2527       aVTKMeshOnEntity = aMeshOnEntityMap[VISU::CELL_ENTITY];
2528     else if(aMeshOnEntityMap.find(VISU::FACE_ENTITY) != aMeshOnEntityMap.end())
2529       aVTKMeshOnEntity = aMeshOnEntityMap[VISU::FACE_ENTITY];
2530     else if(aMeshOnEntityMap.find(VISU::NODE_ENTITY) != aMeshOnEntityMap.end())
2531       aVTKMeshOnEntity = aMeshOnEntityMap[VISU::EDGE_ENTITY];
2532   }else
2533     aVTKMeshOnEntity = aMeshOnEntity;
2534   
2535   VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
2536   VISU::TFieldMap::const_iterator aFieldIter= aFieldMap.find(theFieldName);
2537   if(aFieldIter == aFieldMap.end())
2538     EXCEPTION(runtime_error,"FindField >> There is no field on the mesh!!!");
2539   
2540   PFieldImpl aField = aFieldIter->second;
2541
2542   return TFindField(aMesh,
2543                     aMeshOnEntity,
2544                     aVTKMeshOnEntity,
2545                     aField);
2546 }
2547
2548
2549 float
2550 VISU_Convertor_impl
2551 ::GetFieldOnMeshSize(const std::string& theMeshName, 
2552                      const VISU::TEntity& theEntity,
2553                      const std::string& theFieldName)
2554 {
2555   TFindField aFindField = FindField(theMeshName,theEntity,theFieldName);
2556   PMeshOnEntityImpl aVTKMeshOnEntity = boost::get<2>(aFindField);
2557   PFieldImpl aField = boost::get<3>(aFindField);
2558
2559   float aMeshSize = GetMeshOnEntitySize(theMeshName,aVTKMeshOnEntity->myEntity);
2560   float aFieldOnMeshSize = float(aField->myDataSize*sizeof(float)*aField->myValField.size()*ERR_SIZE_CALC);
2561   float aResult = aMeshSize + aFieldOnMeshSize;
2562   if(MYDEBUG)
2563     MSG(MYVTKDEBUG,"GetFieldOnMeshSize - aFieldOnMeshSize = "<<float(aFieldOnMeshSize));
2564   MSG(MYDEBUG,"GetFieldOnMeshSize - aResult = "<<float(aResult)<<"; theMeshName = '"<<theMeshName<<
2565       "'; theEntity = "<<theEntity<<"; theFieldName = '"<<theFieldName<<"'");
2566
2567   return aResult;
2568 }
2569
2570
2571 VISU_Convertor_impl::TFindTimeStamp
2572 VISU_Convertor_impl
2573 ::FindTimeStamp(const std::string& theMeshName, 
2574                 const VISU::TEntity& theEntity, 
2575                 const std::string& theFieldName, 
2576                 int theStampsNum)
2577 {
2578   TFindField aFindField = FindField(theMeshName,theEntity,theFieldName);
2579   PField aField = boost::get<3>(aFindField);
2580
2581   VISU::TValField& aValField = aField->myValField;
2582   VISU::TValField::const_iterator aValFieldIter= aValField.find(theStampsNum);
2583   if(aValFieldIter == aValField.end())
2584     EXCEPTION(runtime_error,"FindTimeStamp >> There is no field with the timestamp!!!");
2585   
2586   PMeshImpl aMesh = boost::get<0>(aFindField);
2587   PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindField);
2588   PMeshOnEntityImpl aVTKMeshOnEntity = boost::get<2>(aFindField);
2589   PValForTimeImpl aValForTime = aValFieldIter->second;
2590
2591   return TFindTimeStamp(aMesh,
2592                         aMeshOnEntity,
2593                         aVTKMeshOnEntity,
2594                         aField,
2595                         aValForTime);
2596 }
2597
2598
2599 float
2600 VISU_Convertor_impl
2601 ::GetTimeStampSize(const std::string& theMeshName, 
2602                    const VISU::TEntity& theEntity,
2603                    const std::string& theFieldName,
2604                    int theStampsNum)
2605 {
2606   TFindTimeStamp aFindTimeStamp = 
2607     FindTimeStamp(theMeshName,theEntity,theFieldName,theStampsNum);
2608   PMeshOnEntityImpl aVTKMeshOnEntity = boost::get<2>(aFindTimeStamp);
2609   PFieldImpl aField = boost::get<3>(aFindTimeStamp);
2610   
2611   float aMeshSize = GetMeshOnEntitySize(theMeshName,aVTKMeshOnEntity->myEntity);
2612   float aTimeStampSize = float(aField->myDataSize*sizeof(float) * ERR_SIZE_CALC);
2613   float aResult = aMeshSize + aTimeStampSize;
2614
2615   MSG(MYDEBUG && MYVTKDEBUG,"GetTimeStampSize - aTimeStampSize = "<<float(aTimeStampSize));
2616   MSG(MYDEBUG,"GetTimeStampSize - aResult = "<<float(aResult)<<
2617       "; theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<
2618       "; theFieldName = '"<<theFieldName<<"'; theStampsNum = "<<theStampsNum);
2619
2620   return aResult;
2621 }
2622
2623
2624 const VISU::PField
2625 VISU_Convertor_impl
2626 ::GetField(const string& theMeshName, 
2627            VISU::TEntity theEntity, 
2628            const string& theFieldName) 
2629 {
2630   TFindField aFindField = FindField(theMeshName,theEntity,theFieldName);
2631   PField aField = boost::get<3>(aFindField);
2632   return aField;
2633 }
2634
2635
2636 const VISU::PValForTime 
2637 VISU_Convertor_impl
2638 ::GetTimeStamp(const std::string& theMeshName, 
2639                const VISU::TEntity& theEntity,
2640                const std::string& theFieldName,
2641                int theStampsNum)
2642 {
2643   TFindTimeStamp aFindTimeStamp = 
2644     FindTimeStamp(theMeshName,theEntity,theFieldName,theStampsNum);
2645   PValForTime aValForTime = boost::get<4>(aFindTimeStamp);
2646   return aValForTime;
2647 }