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