From: smh Date: Thu, 29 Jan 2004 12:36:42 +0000 (+0000) Subject: MPV: Merge V1_2d X-Git-Tag: V1_4_0~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ca3ee90d283850c294e6a8264107fb04d6bcb5db;p=modules%2Fvisu.git MPV: Merge V1_2d --- diff --git a/src/CONVERTOR/Makefile.in b/src/CONVERTOR/Makefile.in index d5b5d391..2473978c 100644 --- a/src/CONVERTOR/Makefile.in +++ b/src/CONVERTOR/Makefile.in @@ -32,12 +32,12 @@ VPATH=.:@srcdir@ @COMMENCE@ -EXPORT_HEADERS = VISU_Convertor.hxx VISU_Convertor_impl.hxx +EXPORT_HEADERS = VISU_Convertor.hxx VISU_Convertor_impl.hxx VISU_ConvertorUtils.hxx VISU_ExtractUnstructuredGrid.hxx # Libraries targets LIB = libVisuConvertor.la -LIB_SRC = VISU_Convertor.cxx VISU_Convertor_impl.cxx VISU_ConvertorUtils.cxx \ +LIB_SRC = VISU_Convertor.cxx VISU_Convertor_impl.cxx VISU_ConvertorUtils.cxx VISU_ExtractUnstructuredGrid.cxx \ VISU_MedConvertor.cxx VISU_DatConvertor.cxx # Executables targets @@ -47,6 +47,6 @@ BIN_SRC = CPPFLAGS+= -ftemplate-depth-32 $(VTK_INCLUDES) $(MED2_INCLUDES) $(QT_INCLUDES) \ -I${KERNEL_ROOT_DIR}/include/salome LDFLAGS+= $(VTK_LIBS) $(MED2_LIBS) $(HDF5_LIBS) $(QT_LIBS) \ - -L${KERNEL_ROOT_DIR}/lib/salome + -L${KERNEL_ROOT_DIR}/lib/salome @CONCLUDE@ diff --git a/src/CONVERTOR/VISUConvertor.cxx b/src/CONVERTOR/VISUConvertor.cxx index c8b2e55a..4afe4b27 100644 --- a/src/CONVERTOR/VISUConvertor.cxx +++ b/src/CONVERTOR/VISUConvertor.cxx @@ -25,6 +25,7 @@ // Module : VISU #include "VISU_Convertor.hxx" +#include "VISU_ConvertorUtils.hxx" #include #include @@ -44,10 +45,11 @@ static int MYDEBUG = 0; void parseFile(const char* theFileName) throw(std::runtime_error&){ try{ - cout<<"'"< aCon(CreateConvertor(theFileName)); - const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap(); + //aCon->GetSize(); //return; + const VISU::TMeshMap& aMeshMap = aCon->GetMeshMap(); VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ const string& aMeshName = aMeshMapIter->first; @@ -57,48 +59,51 @@ void parseFile(const char* theFileName) throw(std::runtime_error&){ //Import fields aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ - const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; - const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; - const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap; - VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); - for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ - const string& aFieldName = aFieldMapIter->first; - const VISU::TField& aField = aFieldMapIter->second; - const VISU::TField::TValField& aValField = aField.myValField; - VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin(); - for(; aValFieldIter != aValField.end(); aValFieldIter++){ - int aTimeStamp = aValFieldIter->first; - aCon->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); - } - } + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap; + VISU::TFieldMap::const_reverse_iterator aFieldMapIter = aFieldMap.rbegin(); + for(; aFieldMapIter != aFieldMap.rend(); aFieldMapIter++){ + const string& aFieldName = aFieldMapIter->first; + const VISU::TField& aField = aFieldMapIter->second; + const VISU::TField::TValField& aValField = aField.myValField; + VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin(); + for(; aValFieldIter != aValField.end(); aValFieldIter++){ + int aTimeStamp = aValFieldIter->first; + aCon->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); + //goto OK; + } + } } + //continue; //Importing groups const VISU::TGroupMap& aGroupMap = aMesh.myGroupMap; VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){ - const string& aGroupName = aGroupMapIter->first; - aCon->GetMeshOnGroup(aMeshName,aGroupName); + const string& aGroupName = aGroupMapIter->first; + aCon->GetMeshOnGroup(aMeshName,aGroupName); } //Import families aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ - const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; - const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; - //aCon->GetMeshOnEntity(aMeshName,anEntity); - const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap; - VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); - for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ - const string& aFamilyName = aFamilyMapIter->first; - aCon->GetMeshOnEntity(aMeshName,anEntity,aFamilyName); - } + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + //aCon->GetMeshOnEntity(aMeshName,anEntity); + const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap; + VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); + for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ + const string& aFamilyName = aFamilyMapIter->first; + aCon->GetMeshOnEntity(aMeshName,anEntity,aFamilyName); + } } //Import mesh on entity aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ - const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; - aCon->GetMeshOnEntity(aMeshName,anEntity); + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + aCon->GetMeshOnEntity(aMeshName,anEntity); } } + OK: cout<<"OK"< - using namespace std; #ifdef _DEBUG_ @@ -46,29 +44,20 @@ extern "C" { } } -void VISU::WriteToFile(vtkUnstructuredGrid* theDataSet, const string& theFileName){ -// vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); -// //aWriter->DebugOn(); -// //aWriter->SetFileType(VTK_BINARY); -// aWriter->SetFileName(theFileName.c_str()); -// aWriter->SetInput(theDataSet); -// //aWriter->Print(cout); -// aWriter->Write(); -// aWriter->Delete(); -} - namespace VISU{ - TVtkCellInfoMap aVtkCellInfoMap; - static int INIT = ( - aVtkCellInfoMap[VTK_VERTEX] = TVtkCellInfo("VTK_VERTEX",1), - aVtkCellInfoMap[VTK_LINE] = TVtkCellInfo("VTK_LINE",2), - aVtkCellInfoMap[VTK_TRIANGLE] = TVtkCellInfo("VTK_TRIANGLE",3), - aVtkCellInfoMap[VTK_QUAD] = TVtkCellInfo("VTK_QUAD",4), - aVtkCellInfoMap[VTK_TETRA] = TVtkCellInfo("VTK_TETRA",4), - aVtkCellInfoMap[VTK_HEXAHEDRON] = TVtkCellInfo("VTK_HEXAHEDRON",8), - aVtkCellInfoMap[VTK_WEDGE] = TVtkCellInfo("VTK_WEDGE",6), - aVtkCellInfoMap[VTK_PYRAMID] = TVtkCellInfo("VTK_PYRAMID",5), - 1); + inline int GetNbOfPoints(int theVTKCellType){ + switch(theVTKCellType){ + case VTK_VERTEX : return 1; + case VTK_LINE : return 2; + case VTK_TRIANGLE : return 3; + case VTK_QUAD : return 4; + case VTK_TETRA : return 4; + case VTK_HEXAHEDRON : return 8; + case VTK_WEDGE : return 6; + case VTK_PYRAMID : return 5; + default: return -1; + } + } pair TMeshOnEntity::GetCellsDims(const string& theFamilyName) const throw(std::runtime_error&) @@ -97,7 +86,7 @@ namespace VISU{ int tmp = aSubMeshOnCellType.size(); aNbCells += tmp; int aVtkType = aSubMeshIter->first; - int aVtkSize = aVtkCellInfoMap[aVtkType].mySize; + int aVtkSize = GetNbOfPoints(aVtkType); aCellsSize += tmp*(aVtkSize+1); } } @@ -125,7 +114,7 @@ namespace VISU{ if(aFamilyMapIter == aFamilyMap.end()) throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!"); const VISU::TFamily& aFamily = aFamilyMapIter->second; - return &aFamily; + return &aFamily; } TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName) diff --git a/src/CONVERTOR/VISU_Convertor.hxx b/src/CONVERTOR/VISU_Convertor.hxx index 490ae99f..65d2d6a3 100644 --- a/src/CONVERTOR/VISU_Convertor.hxx +++ b/src/CONVERTOR/VISU_Convertor.hxx @@ -1,4 +1,4 @@ -// VISU OBJECT : interactive object for VISU entities implementation +// VISU CONVERTOR : // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -41,63 +40,24 @@ #include #include -#ifndef MESSAGE -#define MESSAGE(msg) std::cout< -#include #include +#include +#include +#include +#include -namespace VISU{ - class TVtkCellInfo{ - public: - TVtkCellInfo() {} - TVtkCellInfo(const char* theName, vtkIdType theSize) : - myName(theName), mySize(theSize) {} - const char* myName; - vtkIdType mySize; - }; - typedef std::map TVtkCellInfoMap; - extern TVtkCellInfoMap aVtkCellInfoMap; +#include "VISU_ExtractUnstructuredGrid.hxx" + +#include +namespace VISU{ enum TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY}; - template class vtk_ptr { - private: - _Tp* _M_ptr; - public: - typedef _Tp element_type; - explicit vtk_ptr(_Tp* __p = 0) : _M_ptr(__p) {} - vtk_ptr(const vtk_ptr& __a) : _M_ptr(0) {} - vtk_ptr(vtk_ptr& __a) : _M_ptr(__a.release()) {} - vtk_ptr& operator=(const vtk_ptr& __a) { return *this;} - vtk_ptr& operator=(vtk_ptr& __a) { - if (&__a != this) { - if(_M_ptr) _M_ptr->Delete(); - _M_ptr = __a.release(); - } - return *this; - } - ~vtk_ptr() { - if(_M_ptr) _M_ptr->Delete(); - _M_ptr = 0; - } - _Tp& operator*() const { return *_M_ptr;} - _Tp* operator->() const { return _M_ptr;} - _Tp* get() const { return _M_ptr;} - _Tp* release() { - _Tp* __tmp = _M_ptr; - _M_ptr = 0; - return __tmp; - } - void reset(_Tp* __p = 0) { - if(_M_ptr) _M_ptr->Delete(); - _M_ptr = __p; - } - }; - typedef vtk_ptr TVTKSource; - typedef vtk_ptr TVTKPoints; + typedef vtkSmartPointer TVTKPoints; + typedef vtkSmartPointer TVTKSource; + typedef vtkSmartPointer TVTKMergetFilter; + typedef vtkSmartPointer TVTKExtractFilter; + typedef vtkSmartPointer TVTKAttribyteFilter; typedef std::set TBindGroups; struct TFamily{ @@ -115,17 +75,20 @@ namespace VISU{ typedef std::map TFamilyMap; struct TField{ + TVTKExtractFilter myExtractFilter; vtkIdType myId; std::string myName; TEntity myEntity; std::string myMeshName; - vtkIdType myNbComp, myNbValField, myDataSize; + vtkIdType myNbComp, myNbValField, myDataSize, myIsTrimmed; typedef std::vector TValForCellsWithType; typedef std::map TValForCells; typedef std::pair TTime; typedef std::vector TCompNames; typedef std::vector TUnitNames; struct TValForTime{ + TVTKAttribyteFilter myAttribyteFilter; + TVTKMergetFilter myMergeFilter; TVTKSource myStorage; vtkIdType myId; std::string myMeshName; @@ -135,16 +98,26 @@ namespace VISU{ TTime myTime; TValForCells myValForCells; TValForTime() : myNbComp(0) {} + ~TValForTime() { + if(myMergeFilter.GetPointer()) + myMergeFilter->UnRegisterAllOutputs(); + if(myAttribyteFilter.GetPointer()) + myAttribyteFilter->UnRegisterAllOutputs(); + } }; typedef std::map TValField; TValField myValField; TCompNames myCompNames; TUnitNames myUnitNames; - TField() : myNbComp(0), myNbValField(0), myDataSize(0) {} + TField() : myNbComp(0), myNbValField(0), myDataSize(0), myIsTrimmed(0) {} void ShallowCopy(const TField& aField); + ~TField() { + if(myExtractFilter.GetPointer()) + myExtractFilter->UnRegisterAllOutputs(); + } }; typedef std::map TFieldMap; - + struct TMeshOnEntity{ TVTKSource myStorage; std::string myMeshName; @@ -209,23 +182,23 @@ public: virtual VISU_Convertor* Build() throw (std::runtime_error&) = 0; virtual const VISU::TMeshMap& GetMeshMap() throw(std::runtime_error&); - + virtual float GetSize() throw (std::runtime_error&) = 0; virtual TOutput* GetMeshOnEntity(const std::string& theMeshName, const VISU::TEntity& theEntity, const std::string& theFamilyName = "") throw(std::runtime_error&) = 0; - virtual vtkIdType GetMeshOnEntitySize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName = "") + virtual float GetMeshOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName = "") throw (std::runtime_error&) = 0; virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, const std::string& theGroupName) throw(std::runtime_error&) = 0; - virtual vtkIdType GetMeshOnGroupSize(const std::string& theMeshName, - const std::string& theGroupName) + virtual float GetMeshOnGroupSize(const std::string& theMeshName, + const std::string& theGroupName) throw(std::runtime_error&) = 0; @@ -234,14 +207,14 @@ public: const std::string& theFieldName, int theStampsNum) throw(std::runtime_error&) = 0; - virtual vtkIdType GetTimeStampSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) + virtual float GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) throw(std::runtime_error&) = 0; - virtual vtkIdType GetFieldOnMeshSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName) + virtual float GetFieldOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName) throw(std::runtime_error&) = 0; virtual const VISU::TField& GetField(const std::string& theMeshName, VISU::TEntity theEntity, diff --git a/src/CONVERTOR/VISU_ConvertorUtils.cxx b/src/CONVERTOR/VISU_ConvertorUtils.cxx index 22cb5b2f..60c0a962 100644 --- a/src/CONVERTOR/VISU_ConvertorUtils.cxx +++ b/src/CONVERTOR/VISU_ConvertorUtils.cxx @@ -24,7 +24,8 @@ // Author : Alexey PETROV // Module : VISU -#include "VISU_Convertor_impl.hxx" +#include "VISU_Convertor.hxx" +#include "VISU_ConvertorUtils.hxx" #include diff --git a/src/CONVERTOR/VISU_ConvertorUtils.hxx b/src/CONVERTOR/VISU_ConvertorUtils.hxx index bc6dcad7..80ad171f 100644 --- a/src/CONVERTOR/VISU_ConvertorUtils.hxx +++ b/src/CONVERTOR/VISU_ConvertorUtils.hxx @@ -33,12 +33,24 @@ extern "C"{ #include #include +#include #include #include #include +#ifndef MESSAGE +#define MESSAGE(msg) std::cout<<__FILE__<<"["<<__LINE__<<"]::"< std::string dtos(const std::string& fmt, T val){ static QString aString; aString.sprintf(fmt.c_str(),val); diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index 8f6ed718..81a76c97 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -25,6 +25,7 @@ // Module : VISU #include "VISU_Convertor_impl.hxx" +#include "VISU_ConvertorUtils.hxx" #include #include @@ -34,6 +35,11 @@ #include #include #include +#include + +#include + +#include #include #include @@ -43,6 +49,10 @@ using namespace std; +static float ERR_SIZE_CALC = 1.00; + +static int MYVTKDEBUG = 0; + #ifdef _DEBUG_ static int MYDEBUG = 0; static int MYDEBUGWITHFILES = 0; @@ -51,6 +61,349 @@ static int MYDEBUG = 0; static int MYDEBUGWITHFILES = 0; #endif +void VISU::WriteToFile(vtkUnstructuredGrid* theDataSet, const string& theFileName){ + //vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New(); + //if(MYVTKDEBUG) aWriter->DebugOn(); + ////aWriter->SetFileType(VTK_BINARY); + //aWriter->SetFileName(theFileName.c_str()); + //aWriter->SetInput(theDataSet); + //aWriter->Write(); + //aWriter->Delete(); +} + +namespace{ + void GetPoints(VISU::TVTKSource& theStorage, VISU::TMesh& theMesh) + throw (std::runtime_error&) + { + vtkPoints* aPoints = theMesh.myPoints.GetPointer(); + if(!aPoints){ + aPoints = vtkPoints::New(); + if(MYVTKDEBUG) aPoints->DebugOn(); + const VISU::TMesh::TPointsCoord& anArray = theMesh.myPointsCoord; + vtkIdType iEnd = theMesh.myPointsCoord.size(); + vtkIdType aNbPoints = iEnd / theMesh.myDim; + aPoints->SetNumberOfPoints(aNbPoints); + if(MYDEBUG) + MESSAGE("GetPoints - aNbPoints = "<> There is no elements on the family !!!")); + VISU::TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); + if(aSubMeshIter == aSubMesh.end()) continue; + const VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; + if(MYDEBUG) + MESSAGE("GetCellsOnEntity - aSubMeshOnCellType.size() = "<SetValue(j++,(unsigned char)aVtkType); + } + } + } + vtkIdType *pts = 0, npts = 0; + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents(1); + aCellLocationsArray->SetNumberOfTuples(aNbCells); + aConnectivity->InitTraversal(); + for(int i=0; aConnectivity->GetNextCell(npts,pts); i++) + aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); + theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); + if(MYVTKDEBUG) aConnectivity->DebugOn(); + aCellLocationsArray->Delete(); + aCellTypesArray->Delete(); + aConnectivity->Delete(); + } + + + void GetCellsOnGroup(VISU::TVTKSource& theStorage, + const VISU::TMesh& theMesh, + const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) + throw (std::runtime_error&) + { + //Calculate dimentions of the group + int aNbCells = 0, aCellsSize = 0; + VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin(); + for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ + const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; + const string& aFamilyName = aFamilyAndEntity.first; + const VISU::TEntity& anEntity = aFamilyAndEntity.second; + const VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap.find(anEntity)->second; + pair aCellsDim = aMeshOnEntity.GetCellsDims(aFamilyName); + aNbCells += aCellsDim.first; + aCellsSize += aCellsDim.second; + } + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate(aCellsSize,0); + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents(1); + aCellTypesArray->SetNumberOfTuples(aNbCells); + aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin(); + for(int i = 0, j = 0; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ + const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; + const string& aFamilyName = aFamilyAndEntity.first; + const VISU::TEntity& anEntity = aFamilyAndEntity.second; + const VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap.find(anEntity)->second; + const VISU::TFamily& aFamily = *(VISU::GetFamily(aMeshOnEntity,aFamilyName)); + const VISU::TMeshOnEntity::TCellsConn &aCellsConn = aMeshOnEntity.myCellsConn; + VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin(); + for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){ + const VISU::TMeshOnEntity::TConnForCellType& anArray = aCellsConnIter->second; + int aVtkType = aCellsConnIter->first; + if(MYDEBUG) + MESSAGE("GetCellsOnGroup - aVtkType = "<> There is no elements on the family !!!")); + VISU::TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); + if(aSubMeshIter == aSubMesh.end()) continue; + const VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; + if(MYDEBUG) + MESSAGE("GetCellsOnGroup - aSubMeshOnCellType.size() = "<SetValue(j++,(unsigned char)aVtkType); + } + } + } + vtkIdType *pts = 0, npts = 0; + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents(1); + aCellLocationsArray->SetNumberOfTuples(aNbCells); + aConnectivity->InitTraversal(); + for(int i = 0; aConnectivity->GetNextCell(npts,pts); i++) + aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); + theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); + aCellLocationsArray->Delete(); + aCellTypesArray->Delete(); + aConnectivity->Delete(); + } + + + void InitProfile(VISU::TVTKExtractFilter& theFilter, + const VISU::TMeshOnEntity& theMeshOnEntity, + const VISU::TField::TValForTime& theValForTime) + throw (std::runtime_error&) + { + const VISU::TField::TValForCells& aValForCells = theValForTime.myValForCells; + const VISU::TMeshOnEntity::TCellsConn &aCellsConn = theMeshOnEntity.myCellsConn; + VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin(); + for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){ + const vtkIdType& aCellType = aCellsConnIter->first; + if(aValForCells.find(aCellType) == aValForCells.end()) + theFilter->RemoveCellsWithType(aCellType); + } + } + + + void GetValsOnTimeStamp(vtkFloatArray *theFloatArray, + const vtkIdType& theNumberOfTuples, + const std::string& theFieldName, + const VISU::TField& theField, + const VISU::TField::TValForTime& theValForTime) + throw (std::runtime_error&) + { + //theFloatArray->DebugOn(); + theFloatArray->SetNumberOfTuples(theNumberOfTuples); + theFloatArray->SetName(theFieldName.c_str()); + if(MYDEBUG) MESSAGE("GetValsOnTimeStamp - theNumberOfTuples = "<second; + int iEnd = anArray.size()/theField.myNbComp; + int aVtkType = aValForCellsIter->first; + if(MYDEBUG) MESSAGE("GetValsOnTimeStamp - iEnd = "<Delete(); + if(MYVTKDEBUG) aSource->DebugOn(); + LoadMeshOnEntity(aMeshOnEntity,theFamilyName); + GetPoints(aSource,aMesh); + GetCellsOnEntity(aSource,aMeshOnEntity,theFamilyName); + if(MYDEBUGWITHFILES){ + string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); + string aFamilyName = QString(theFamilyName.c_str()).simplifyWhiteSpace().latin1(); + string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; + aFileName += aMeshName + dtos("-%d-",int(theEntity)) + aFamilyName + "-Conv.vtk"; + VISU::WriteToFile(aSource.GetPointer(),aFileName); + } + } + if(MYVTKDEBUG){ + GetMeshOnEntitySize(theMeshName,theEntity,theFamilyName); + vtkUnstructuredGrid* aDataSet = aSource.GetPointer(); + aDataSet->Update(); + MESSAGE("GetMeshOnEntity - GetPoints() = "<GetPoints()->GetActualMemorySize()*1000)); + MESSAGE("GetMeshOnEntity - GetCells() = "<GetCells()->GetActualMemorySize()*1000)); + MESSAGE("GetMeshOnEntity - GetCellTypesArray() = "<GetCellTypesArray()->GetActualMemorySize()*1000)); + MESSAGE("GetMeshOnEntity - GetCellLocationsArray() = "<GetCellLocationsArray()->GetActualMemorySize()*1000)); + aDataSet->BuildLinks(); + MESSAGE("GetMeshOnEntity - GetCellLinks() = "<GetCellLinks()->GetActualMemorySize()*1000)); + MESSAGE("GetMeshOnEntity - GetActualMemorySize() = "<GetActualMemorySize()*1000)); } + }catch(...){ + aSource = vtkSmartPointerBase(); + throw; } - return aSource.get(); + return aSource.GetPointer(); } VISU_Convertor::TOutput* @@ -113,20 +485,26 @@ VISU_Convertor_impl::GetMeshOnGroup(const string& theMeshName, const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup.myFamilyAndEntitySet; VISU::TVTKSource& aSource = aGroup.myStorage; //Main part of code - if(aSource.get() == NULL){ - aSource.reset(TOutput::New()); - LoadMeshOnGroup(aMesh,aFamilyAndEntitySet); - GetPoints(aSource,aMesh); - GetCellsOnGroup(aSource,aMesh,aFamilyAndEntitySet); - if(MYDEBUGWITHFILES){ - string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); - string aGroupName = QString(theGroupName.c_str()).simplifyWhiteSpace().latin1(); - string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; - aFileName += aMeshName + "-" + aGroupName + "-Conv.vtk"; - VISU::WriteToFile(aSource.get(),aFileName); + try{ + if(aSource.GetPointer() == NULL){ + aSource = TOutput::New(); + aSource->Delete(); + LoadMeshOnGroup(aMesh,aFamilyAndEntitySet); + GetPoints(aSource,aMesh); + GetCellsOnGroup(aSource,aMesh,aFamilyAndEntitySet); + if(MYDEBUGWITHFILES){ + string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); + string aGroupName = QString(theGroupName.c_str()).simplifyWhiteSpace().latin1(); + string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; + aFileName += aMeshName + "-" + aGroupName + "-Conv.vtk"; + VISU::WriteToFile(aSource.GetPointer(),aFileName); + } } + }catch(...){ + aSource = vtkSmartPointerBase(); + throw; } - return aSource.get(); + return aSource.GetPointer(); } VISU_Convertor::TOutput* @@ -149,306 +527,175 @@ VISU_Convertor_impl::GetTimeStampOnMesh(const string& theMeshName, theFieldName,pField,theStampsNum,pValForTime); VISU::TMesh& aMesh = *pMesh; VISU::TMeshOnEntity& aMeshOnEntity = *pMeshOnEntity; - VISU::TMeshOnEntity& aVTKMeshOnEntity = *pVTKMeshOnEntity; VISU::TField& aField = *pField; VISU::TField::TValForTime& aValForTime = *pValForTime; + VISU::TVTKAttribyteFilter& anAttribyteFilter = aValForTime.myAttribyteFilter; VISU::TVTKSource& aSource = aValForTime.myStorage; + TOutput* anOutput = NULL; //Main part of code - if(aSource.get() == NULL){ - aSource.reset(TOutput::New()); - LoadFieldOnMesh(aMesh,aMeshOnEntity,aField,aValForTime); - try{ - LoadMeshOnEntity(aVTKMeshOnEntity); - }catch(std::runtime_error& exc){ - aVTKMeshOnEntity = aMeshOnEntity; - MESSAGE("Follow exception was accured :\n"<ShallowCopy(aVTKMeshOnEntity.myStorage.get()); - GetField(aSource,aMesh,aVTKMeshOnEntity,aField,aValForTime); - if(MYDEBUGWITHFILES){ - string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); - string aFieldName = QString(theFieldName.c_str()).simplifyWhiteSpace().latin1(); - string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; - aFileName += aMeshName + dtos("-%d-",int(theEntity)) + aFieldName + dtos("-%d",theStampsNum) + "-Conv.vtk"; - VISU::WriteToFile(aSource.get(),aFileName); - } - } - return aSource.get(); -} - -inline void PrintCells(int& theStartId, - vtkCellArray* theConnectivity, - const VISU::TMeshOnEntity::TConnect& theVector) -{ - vtkIdList *anIdList = vtkIdList::New(); - int kEnd = theVector.size(); - anIdList->SetNumberOfIds(kEnd); - for(int k = 0; k < kEnd; k++){ - anIdList->SetId(k,theVector[k]); - //anIdList->InsertNextId(theVector[k]); - } - theConnectivity->InsertNextCell(anIdList); - anIdList->Delete(); -} - -void VISU_Convertor_impl::GetCellsOnEntity(VISU::TVTKSource& theStorage, - const VISU::TMeshOnEntity& theMeshOnEntity, - const string& theFamilyName) - const throw (std::runtime_error&) -{ - //Check on existing family - const VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName); - bool isFamilyPresent = (pFamily != NULL); - const VISU::TFamily& aFamily = *pFamily; - //Main part of code - pair aCellsDim = theMeshOnEntity.GetCellsDims(theFamilyName); - int aNbCells = aCellsDim.first, aCellsSize = aCellsDim.second; - vtkCellArray* aConnectivity = vtkCellArray::New(); - //vtkIdType *anIdArray = aConnectivity->WritePointer(0,aCellsSize); - aConnectivity->Allocate(aCellsSize,0); - vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); - aCellTypesArray->SetNumberOfComponents(1); - aCellTypesArray->SetNumberOfTuples(aNbCells); - if(MYDEBUG) MESSAGE("GetCellsOnEntity - isFamilyPresent = "<second; - int aVtkType = aCellsConnIter->first; - if(MYDEBUG) MESSAGE("GetCellsOnEntity - aVtkType = "<> There is no elements on the family !!!"); - VISU::TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); - if(aSubMeshIter == aSubMesh.end()) continue; - const VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; - if(MYDEBUG) MESSAGE("GetCellsOnEntity - aSubMeshOnCellType.size() = "<SetValue(j++,(unsigned char)aVtkType); - //aCellTypesArray->InsertNextValue((unsigned char)aVtkType); + LoadFieldOnMesh(aMesh,aMeshOnEntity,aField,aValForTime); + + VISU::TVTKExtractFilter& anExtractFilter = aField.myExtractFilter; + if(anExtractFilter.GetPointer() == NULL){ + anExtractFilter = VISU_ExtractUnstructuredGrid::New(); + anExtractFilter->Delete(); + //anExtractFilter->DebugOn(); + try{ + LoadMeshOnEntity(*pVTKMeshOnEntity); + }catch(std::runtime_error& exc){ + pVTKMeshOnEntity = pMeshOnEntity; + MESSAGE("Follow exception was accured :\n"<myMeshName,pVTKMeshOnEntity->myEntity); + + anExtractFilter->SetInput(pVTKMeshOnEntity->myStorage.GetPointer()); + ::InitProfile(anExtractFilter,*pMeshOnEntity,aValForTime); + } + if(!anExtractFilter->IsRemoving()){ + aSource = TOutput::New(); + aSource->Delete(); + aSource->ShallowCopy(pVTKMeshOnEntity->myStorage.GetPointer()); + ::GetTimeStamp(aSource,aMesh,*pVTKMeshOnEntity,aField,aValForTime); + anOutput = aSource.GetPointer(); + }else{ + anAttribyteFilter = vtkFieldDataToAttributeDataFilter::New(); + anAttribyteFilter->Delete(); + //anAttribyteFilter->DebugOn(); + + VISU::TVTKMergetFilter& aMergeFilter = aValForTime.myMergeFilter; + aMergeFilter = vtkMergeDataObjectFilter::New(); + aMergeFilter->Delete(); + //aMergeFilter->DebugOn(); + + ::GetTimeStamp(anAttribyteFilter,aMergeFilter,anExtractFilter, + aMesh,*pVTKMeshOnEntity,aField,aValForTime); + anOutput = anAttribyteFilter->GetUnstructuredGridOutput(); } - } - } - vtkIdType *pts = 0, npts = 0; - vtkIntArray* aCellLocationsArray = vtkIntArray::New(); - aCellLocationsArray->SetNumberOfComponents(1); - aCellLocationsArray->SetNumberOfTuples(aNbCells); - aConnectivity->InitTraversal(); - for(int i=0; aConnectivity->GetNextCell(npts,pts); i++){ - aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); - //aCellLocationsArray->InsertNextValue(aConnectivity->GetTraversalLocation(npts)); - } - theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); -} - - -void VISU_Convertor_impl::GetCellsOnGroup(VISU::TVTKSource& theStorage, - const VISU::TMesh& theMesh, - const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) - const throw (std::runtime_error&) -{ - //Calculate dimentions of the group - int aNbCells = 0, aCellsSize = 0; - VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin(); - for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ - const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; - const string& aFamilyName = aFamilyAndEntity.first; - const VISU::TEntity& anEntity = aFamilyAndEntity.second; - const VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap.find(anEntity)->second; - pair aCellsDim = aMeshOnEntity.GetCellsDims(aFamilyName); - aNbCells += aCellsDim.first; - aCellsSize += aCellsDim.second; - } - vtkCellArray* aConnectivity = vtkCellArray::New(); - //vtkIdType *anIdArray = aConnectivity->WritePointer(0,aCellsSize); - aConnectivity->Allocate(aCellsSize,0); - vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); - aCellTypesArray->SetNumberOfComponents(1); - aCellTypesArray->SetNumberOfTuples(aNbCells); - aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin(); - for(int i = 0, j = 0; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){ - const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter; - const string& aFamilyName = aFamilyAndEntity.first; - const VISU::TEntity& anEntity = aFamilyAndEntity.second; - const VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap.find(anEntity)->second; - const VISU::TFamily& aFamily = *(VISU::GetFamily(aMeshOnEntity,aFamilyName)); - const VISU::TMeshOnEntity::TCellsConn &aCellsConn = aMeshOnEntity.myCellsConn; - VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin(); - for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){ - const VISU::TMeshOnEntity::TConnForCellType& anArray = aCellsConnIter->second; - int aVtkType = aCellsConnIter->first; - if(MYDEBUG) MESSAGE("GetCellsOnGroup - aVtkType = "<> There is no elements on the family !!!"); - VISU::TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); - if(aSubMeshIter == aSubMesh.end()) continue; - const VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; - if(MYDEBUG) MESSAGE("GetCellsOnGroup - aSubMeshOnCellType.size() = "<SetValue(j++,(unsigned char)aVtkType); - //aCellTypesArray->InsertNextValue((unsigned char)aVtkType); + if(MYDEBUGWITHFILES){ + string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); + string aFieldName = QString(theFieldName.c_str()).simplifyWhiteSpace().latin1(); + string aPrefix = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; + string aFileName = aPrefix + aMeshName + dtos("-%d-",int(theEntity)) + + aFieldName + dtos("-%d",theStampsNum) + "-Conv.vtk"; + VISU::WriteToFile(anOutput,aFileName); + } + if(MYVTKDEBUG){ + GetTimeStampSize(theMeshName,theEntity,theFieldName,theStampsNum); + vtkUnstructuredGrid *aDataSet = anAttribyteFilter->GetUnstructuredGridOutput(); + aDataSet->Update(); + if(theEntity == VISU::NODE_ENTITY) + MESSAGE("GetTimeStampOnMesh - GetData() = "<GetPointData()->GetActualMemorySize()*1000)); + else + MESSAGE("GetMeshOnEntity - GetData() = "<GetCellData()->GetActualMemorySize()*1000)); + MESSAGE("GetTimeStampOnMesh - GetActualMemorySize() = "<GetActualMemorySize()*1000)); } } + }catch(...){ + aSource = vtkSmartPointerBase(); + anAttribyteFilter = vtkSmartPointerBase(); + throw; } - vtkIdType *pts = 0, npts = 0; - vtkIntArray* aCellLocationsArray = vtkIntArray::New(); - aCellLocationsArray->SetNumberOfComponents(1); - aCellLocationsArray->SetNumberOfTuples(aNbCells); - aConnectivity->InitTraversal(); - for(int i = 0; aConnectivity->GetNextCell(npts,pts); i++){ - aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts)); - //aCellLocationsArray->InsertNextValue(aConnectivity->GetTraversalLocation(npts)); - } - theStorage->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity); -} - - -void VISU_Convertor_impl::GetPoints(VISU::TVTKSource& theStorage, const VISU::TMesh& theMesh) - const throw (std::runtime_error&) -{ - vtkPoints* aPoints = theMesh.myPoints.get(); - if(!aPoints){ - aPoints = vtkPoints::New(); - const VISU::TMesh::TPointsCoord& anArray = theMesh.myPointsCoord; - vtkIdType iEnd = theMesh.myPointsCoord.size(); - vtkIdType aNbPoints = iEnd / theMesh.myDim; - aPoints->SetNumberOfPoints(aNbPoints); - if(MYDEBUG) - MESSAGE("GetPoints - aNbPoints = "<SetName(aFieldName.c_str()); - if(MYDEBUG) MESSAGE("GetField - aNumberOfTuples = "<second; - int iEnd = anArray.size()/theField.myNbComp; - int aVtkType = aValForCellsIter->first; - if(MYDEBUG) MESSAGE("GetField - iEnd = "<> There is no mesh with the name!!!"); + throw std::runtime_error(EXCEPT("FindMesh >> There is no mesh with the name - '%1'!!!"). + arg(theMeshName.c_str()).latin1()); theMesh = &myMeshMap[theMeshName]; } -void VISU_Convertor_impl::FindMeshOnEntity(const string& theMeshName, VISU::TMesh*& theMesh, - const VISU::TEntity& theEntity, VISU::TMeshOnEntity*& theMeshOnEntity, - const string& theFamilyName, VISU::TFamily*& theFamily) +void VISU_Convertor_impl::FindMeshOnEntity(const string& theMeshName, + VISU::TMesh*& theMesh, + const VISU::TEntity& theEntity, + VISU::TMeshOnEntity*& theMeshOnEntity, + const string& theFamilyName, + VISU::TFamily*& theFamily) throw (std::runtime_error&) { FindMesh(theMeshName,theMesh); VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap; if(aMeshOnEntityMap.find(theEntity) == aMeshOnEntityMap.end()) - throw std::runtime_error("FindMeshOnEntity >> There is no mesh on the entity!!!"); + throw std::runtime_error(EXCEPT("FindMeshOnEntity >> There is no mesh on the entity - %1!!!"). + arg(int(theEntity)).latin1()); theMeshOnEntity = &aMeshOnEntityMap[theEntity]; theFamily = VISU::GetFamily(*theMeshOnEntity,theFamilyName); } -vtkIdType VISU_Convertor_impl::GetMeshOnEntitySize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName) +float VISU_Convertor_impl::GetSize() throw (std::runtime_error&){ + float aResult = 0.0; + const VISU::TMeshMap& aMeshMap = GetMeshMap(); + VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ + const string& aMeshName = aMeshMapIter->first; + const VISU::TMesh& aMesh = aMeshMapIter->second; + const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap; + VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter; + //Import fields + aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; + const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap; + VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); + for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ + const string& aFieldName = aFieldMapIter->first; + const VISU::TField& aField = aFieldMapIter->second; + const VISU::TField::TValField& aValField = aField.myValField; + VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin(); + for(; aValFieldIter != aValField.end(); aValFieldIter++){ + int aTimeStamp = aValFieldIter->first; + aResult += GetTimeStampSize(aMeshName,anEntity,aFieldName,aTimeStamp); + } + } + //Importing groups + const VISU::TGroupMap& aGroupMap = aMesh.myGroupMap; + VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); + for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){ + const string& aGroupName = aGroupMapIter->first; + aResult += GetMeshOnGroupSize(aMeshName,aGroupName); + } + //Import families + const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap; + VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); + for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ + const string& aFamilyName = aFamilyMapIter->first; + aResult += GetMeshOnEntitySize(aMeshName,anEntity,aFamilyName); + } + //Import mesh on entity + aResult += GetMeshOnEntitySize(aMeshName,anEntity); + } + } + if(MYDEBUG) + MESSAGE("GetSize - aResult = "<myNbPoints*sizeof(VISU::TMesh::TCoord); + vtkIdType aPointsSize = 3*pMesh->myNbPoints*sizeof(VISU::TMesh::TCoord); vtkIdType aNbCells, aCellsSize; if(!pFamily){ aNbCells = pMeshOnEntity->myNbCells; @@ -457,10 +704,26 @@ vtkIdType VISU_Convertor_impl::GetMeshOnEntitySize(const std::string& theMeshNam aNbCells = pFamily->myNbCells; aCellsSize = pFamily->myCellsSize; } - //that is Connectivity + (Types + Locations + Links) - aResult += aCellsSize*sizeof(vtkIdType) + - aNbCells*(sizeof(char) + sizeof(int) + (sizeof(short) + sizeof(vtkIdType))); - if(MYDEBUG) cout<<"VISU_Convertor_impl::GetMeshOnEntitySize = "<myNbPoints * + (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link)); + aLinksSize = 0; + vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize; + if(MYDEBUG){ + if(MYVTKDEBUG){ + MESSAGE("GetMeshOnEntitySize - aPointsSize = "<myGroupMap; VISU::TGroupMap::iterator aGroupMapIter = aGroupMap.find(theGroupName); if(aGroupMapIter == aGroupMap.end()) - throw std::runtime_error("FindMeshOnGroup >> There is no the group in the mesh!!!"); + throw std::runtime_error(EXCEPT("FindMesh >> There is no the group in the mesh!!! - '%1'").arg(theGroupName.c_str()).latin1()); theGroup = &aGroupMapIter->second; } -vtkIdType VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName, - const std::string& theGroupName) +float VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName, + const std::string& theGroupName) throw (std::runtime_error&) { VISU::TMesh* pMesh = NULL; VISU::TGroup* pGroup = NULL; FindMeshOnGroup(theMeshName,pMesh,theGroupName,pGroup); - vtkIdType aResult = 3*pMesh->myNbPoints*sizeof(VISU::TMesh::TCoord); - aResult += pGroup->myCellsSize*sizeof(vtkIdType); - if(MYDEBUG) cout<<"VISU_Convertor_impl::GetMeshOnGroupSize = "<myNbPoints*sizeof(VISU::TMesh::TCoord); + vtkIdType aNbCells = pGroup->myNbCells, aCellsSize = pGroup->myCellsSize; + vtkIdType aConnectivityAndTypesSize = aCellsSize*sizeof(vtkIdType); + vtkIdType aLocationsSize = aNbCells*sizeof(int); + float aNbCellsPerPoint = aCellsSize / aNbCells - 1; + vtkIdType aLinksSize = pMesh->myNbPoints * + (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(short)); + aLinksSize = 0; + vtkIdType aResult = aPointsSize + aConnectivityAndTypesSize + aLocationsSize + aLinksSize; + if(MYDEBUG){ + if(MYVTKDEBUG){ + MESSAGE("GetMeshOnGroupSize - aPointsSize = "<myMeshOnEntityMap; if(theEntity == VISU::NODE_ENTITY){ - if(aMeshOnEntityMap.find(VISU::CELL_ENTITY) == aMeshOnEntityMap.end()) - throw std::runtime_error("FindField >> There is no mesh on CELL_ENTITY!!!"); - pMeshOnEntity = &aMeshOnEntityMap[VISU::CELL_ENTITY]; + if(aMeshOnEntityMap.find(VISU::CELL_ENTITY) != aMeshOnEntityMap.end()) + pMeshOnEntity = &aMeshOnEntityMap[VISU::CELL_ENTITY]; + else if(aMeshOnEntityMap.find(VISU::FACE_ENTITY) != aMeshOnEntityMap.end()) + pMeshOnEntity = &aMeshOnEntityMap[VISU::FACE_ENTITY]; + else if(aMeshOnEntityMap.find(VISU::NODE_ENTITY) != aMeshOnEntityMap.end()) + pMeshOnEntity = &aMeshOnEntityMap[VISU::EDGE_ENTITY]; } theVTKMeshOnEntity = pMeshOnEntity; VISU::TFieldMap& aFieldMap = theMeshOnEntity->myFieldMap; if(aFieldMap.find(theFieldName) == aFieldMap.end()) - throw std::runtime_error("FindField >> There is no field on the mesh!!!"); + throw std::runtime_error(EXCEPTION("FindField >> There is no field on the mesh!!!")); theField = &aFieldMap[theFieldName]; } -vtkIdType VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName) +float VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName) throw(std::runtime_error&) { VISU::TMesh* pMesh = NULL; @@ -527,10 +810,15 @@ vtkIdType VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName VISU::TMeshOnEntity *pMeshOnEntity = NULL, *pVTKMeshOnEntity = NULL; FindField(theMeshName,pMesh,theEntity,pMeshOnEntity,pVTKMeshOnEntity, theFieldName,pField); - - vtkIdType aResult = GetMeshOnEntitySize(theMeshName,theEntity); - aResult += pField->myDataSize*sizeof(float)*pField->myNbValField; - if(MYDEBUG) cout<<"VISU_Convertor_impl::GetFieldOnMeshSize = "<myEntity); + float aFieldOnMeshSize = float(pField->myDataSize*sizeof(float)*pField->myNbValField * ERR_SIZE_CALC); + float aResult = aMeshSize + aFieldOnMeshSize; + if(MYDEBUG){ + if(MYVTKDEBUG) + MESSAGE("GetFieldOnMeshSize - aFieldOnMeshSize = "<myValField; if(aValField.find(theStampsNum) == aValField.end()) - throw std::runtime_error("FindTimeStamp >> There is no field with the timestamp!!!"); + throw std::runtime_error(EXCEPTION("FindTimeStamp >> There is no field with the timestamp!!!")); theValForTime = &aValField[theStampsNum]; } -vtkIdType VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) +float VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) throw (std::runtime_error&) { VISU::TMesh* pMesh = NULL; @@ -563,10 +851,15 @@ vtkIdType VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName, VISU::TField::TValForTime* pValForTime = NULL; FindTimeStamp(theMeshName,pMesh,theEntity,pMeshOnEntity,pVTKMeshOnEntity, theFieldName,pField,theStampsNum,pValForTime); - - vtkIdType aResult = GetMeshOnEntitySize(theMeshName,theEntity); - aResult += pField->myDataSize*sizeof(float); - if(MYDEBUG) cout<<"VISU_Convertor_impl::GetTimeStampSize = "<myEntity); + float aTimeStampSize = float(pField->myDataSize*sizeof(float) * ERR_SIZE_CALC); + float aResult = aMeshSize + aTimeStampSize; + if(MYDEBUG){ + if(MYVTKDEBUG) + MESSAGE("GetTimeStampSize - aTimeStampSize = "< class VISU_Convertor_impl: public VISU_Convertor{ -private: - void GetPoints(VISU::TVTKSource& theStorage, - const VISU::TMesh& theMesh) - const throw (std::runtime_error&); - void GetCellsOnEntity(VISU::TVTKSource& theStorage, - const VISU::TMeshOnEntity& theMeshOnEntity, - const std::string& theFamilyName) - const throw (std::runtime_error&); - void GetCellsOnGroup(VISU::TVTKSource& theStorage, - const VISU::TMesh& theMesh, - const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) - const throw (std::runtime_error&); - void GetField(VISU::TVTKSource& theStorage, - const VISU::TMesh& theMesh, - const VISU::TMeshOnEntity& theMeshOnEntity, - const VISU::TField& theField, - const VISU::TField::TValForTime& theValForTime) - const throw (std::runtime_error&); - +public: + virtual float GetSize() throw (std::runtime_error&); -protected: - void FindMesh(const std::string& theMeshName, VISU::TMesh*& theMesh) - throw(std::runtime_error&); - void FindMeshOnEntity(const std::string& theMeshName, VISU::TMesh*& theMesh, - const VISU::TEntity& theEntity, VISU::TMeshOnEntity*& theMeshOnEntity, - const std::string& theFamilyName, VISU::TFamily*& theFamily) + virtual float GetMeshOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName = "") throw (std::runtime_error&); - void FindMeshOnGroup(const std::string& theMeshName, VISU::TMesh*& theMesh, - const std::string& theGroupName, VISU::TGroup*& theGroup) - throw (std::runtime_error&); - - void FindField(const std::string& theMeshName, VISU::TMesh*& theMesh, - const VISU::TEntity& theEntity, - VISU::TMeshOnEntity*& theMeshOnEntity, - VISU::TMeshOnEntity*& theVTKMeshOnEntity, - const std::string& theFieldName, VISU::TField*& theField) - throw (std::runtime_error&); - void FindTimeStamp(const std::string& theMeshName, VISU::TMesh*& theMesh, - const VISU::TEntity& theEntity, - VISU::TMeshOnEntity*& theMeshOnEntity, - VISU::TMeshOnEntity*& theVTKMeshOnEntity, - const std::string& theFieldName, VISU::TField*& theField, - int theStampsNum, VISU::TField::TValForTime*& theValForTime) - throw (std::runtime_error&); - - -public: - virtual vtkIdType GetMeshOnEntitySize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName = "") - throw (std::runtime_error&); - virtual vtkIdType GetMeshOnGroupSize(const std::string& theMeshName, - const std::string& theGroupName) + virtual float GetMeshOnGroupSize(const std::string& theMeshName, + const std::string& theGroupName) throw(std::runtime_error&); - virtual vtkIdType GetTimeStampSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) + + virtual float GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) throw(std::runtime_error&); - virtual vtkIdType GetFieldOnMeshSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName) + + virtual float GetFieldOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName) throw(std::runtime_error&); + virtual const VISU::TField& GetField(const std::string& theMeshName, VISU::TEntity theEntity, const std::string& theFieldName) throw(std::runtime_error&); + virtual const VISU::TField::TValForTime& GetTimeStamp(const std::string& theMeshName, const VISU::TEntity& theEntity, const std::string& theFieldName, @@ -95,28 +55,63 @@ public: public: VISU_Convertor_impl(); + virtual ~VISU_Convertor_impl(); + virtual VISU_Convertor* Build() throw (std::runtime_error&) { return this;}; + virtual TOutput* GetMeshOnEntity(const std::string& theMeshName, const VISU::TEntity& theEntity, const std::string& theFamilyName = "") throw(std::runtime_error&); + virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, const std::string& theGroupName) throw(std::runtime_error&); + virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName, const VISU::TEntity& theEntity, const std::string& theFieldName, int theStampsNum) throw(std::runtime_error&); - protected: +protected: + void FindMesh(const std::string& theMeshName, VISU::TMesh*& theMesh) + throw(std::runtime_error&); + + void FindMeshOnEntity(const std::string& theMeshName, VISU::TMesh*& theMesh, + const VISU::TEntity& theEntity, VISU::TMeshOnEntity*& theMeshOnEntity, + const std::string& theFamilyName, VISU::TFamily*& theFamily) + throw (std::runtime_error&); + + void FindMeshOnGroup(const std::string& theMeshName, VISU::TMesh*& theMesh, + const std::string& theGroupName, VISU::TGroup*& theGroup) + throw (std::runtime_error&); + + void FindField(const std::string& theMeshName, VISU::TMesh*& theMesh, + const VISU::TEntity& theEntity, + VISU::TMeshOnEntity*& theMeshOnEntity, + VISU::TMeshOnEntity*& theVTKMeshOnEntity, + const std::string& theFieldName, VISU::TField*& theField) + throw (std::runtime_error&); + + void FindTimeStamp(const std::string& theMeshName, VISU::TMesh*& theMesh, + const VISU::TEntity& theEntity, + VISU::TMeshOnEntity*& theMeshOnEntity, + VISU::TMeshOnEntity*& theVTKMeshOnEntity, + const std::string& theFieldName, VISU::TField*& theField, + int theStampsNum, VISU::TField::TValForTime*& theValForTime) + throw (std::runtime_error&); + +protected: virtual int LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, const std::string& theFamilyName = "") throw (std::runtime_error&) = 0; + virtual int LoadMeshOnGroup(VISU::TMesh& theMesh, const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) throw (std::runtime_error&) = 0; + virtual int LoadFieldOnMesh(VISU::TMesh& theMesh, VISU::TMeshOnEntity& theMeshOnEntity, VISU::TField& theField, @@ -124,27 +119,4 @@ public: throw (std::runtime_error&) = 0; }; -template std::string dtos(const std::string& fmt, T val){ - static QString aString; - aString.sprintf(fmt.c_str(),val); - return aString.latin1(); -} - -extern "C"{ - int getNbMedConnect(int theMedType, int theMedEntity, int theMeshDim); - int getNbMedNodes(int theMedType); - int med2vtkCellType(int theMedType); - int vtk2medCellType(int theVtkType); - int getIdMedType(int medType); -} - -struct Med2vtk { - med_geometrie_element medType; - const char *medName; - int medNbNodes; - int vtkType; - const char *vtkName; - int vtkNbNodes; -}; -extern Med2vtk med2vtk[MED_NBR_GEOMETRIE_MAILLE]; #endif diff --git a/src/CONVERTOR/VISU_ExtractUnstructuredGrid.cxx b/src/CONVERTOR/VISU_ExtractUnstructuredGrid.cxx new file mode 100644 index 00000000..a8ba1e37 --- /dev/null +++ b/src/CONVERTOR/VISU_ExtractUnstructuredGrid.cxx @@ -0,0 +1,101 @@ +// VISU CONVERTOR : +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File: VISU_ExtractUnstructuredGrid.cxx +// Author: Alexey PETROV +// Module : VISU + + +#include "VISU_ExtractUnstructuredGrid.hxx" +#include "VISU_ConvertorUtils.hxx" + +#include +#include +#include +#include + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +vtkStandardNewMacro(VISU_ExtractUnstructuredGrid); + +VISU_ExtractUnstructuredGrid::VISU_ExtractUnstructuredGrid(){} + +VISU_ExtractUnstructuredGrid::~VISU_ExtractUnstructuredGrid(){} + +void VISU_ExtractUnstructuredGrid::RemoveCell(vtkIdType theCellId){ + myRemovedCellIds.insert(theCellId); + Modified(); +} + +void VISU_ExtractUnstructuredGrid::RemoveCellsWithType(vtkIdType theCellType){ + myRemovedCellTypes.insert(theCellType); + Modified(); +} + +namespace{ + inline void InsertCell(vtkUnstructuredGrid *theInput, + vtkUnstructuredGrid *theOutput, + vtkIdType theCellId, vtkIdList *theCellIds) + { + theCellIds->Reset(); + vtkCell *aCell = theInput->GetCell(theCellId); + vtkIdType aNbIds = aCell->PointIds->GetNumberOfIds(); + for(vtkIdType i = 0; i < aNbIds; i++) + theCellIds->InsertNextId(aCell->GetPointIds()->GetId(i)); + theOutput->InsertNextCell(theInput->GetCellType(theCellId), theCellIds); + } +} + +void VISU_ExtractUnstructuredGrid::Execute(){ + vtkUnstructuredGrid *anInput = this->GetInput(), *anOutput = this->GetOutput(); + vtkIdType aNbCells = anInput->GetNumberOfCells(); + anOutput->Allocate(aNbCells); + if(MYDEBUG) MESSAGE("Execute - anInput->GetNumberOfCells() = "<GetNumberOfCells()); + vtkIdList *aCellIds = vtkIdList::New(); + if(MYDEBUG) + MESSAGE("Execute - myRemovedCellIds.empty() = "<GetNumberOfCells() = "<GetNumberOfCells()); +} diff --git a/src/CONVERTOR/VISU_ExtractUnstructuredGrid.hxx b/src/CONVERTOR/VISU_ExtractUnstructuredGrid.hxx new file mode 100644 index 00000000..28396748 --- /dev/null +++ b/src/CONVERTOR/VISU_ExtractUnstructuredGrid.hxx @@ -0,0 +1,70 @@ +// VISU CONVERTOR : +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_ExtractUnstructuredGrid.hxx +// Author : Alexey PETROV +// Module : VISU + +#ifndef VISU_ExtractUnstructuredGrid_HeaderFile +#define VISU_ExtractUnstructuredGrid_HeaderFile + +#include + +#include + +class VISU_ExtractUnstructuredGrid : public vtkUnstructuredGridToUnstructuredGridFilter{ +public: + vtkTypeMacro(VISU_ExtractUnstructuredGrid,vtkUnstructuredGridToUnstructuredGridFilter); + + // Description: + // Construct with all types of clipping turned off. + static VISU_ExtractUnstructuredGrid *New(); + + // Description: + // Remove the cell from the output + void RemoveCell(vtkIdType theCellId); + int IsRemoveCells() { return !myRemovedCellIds.empty();} + + // Remove every cells with the type from the output + void RemoveCellsWithType(vtkIdType theCellType); + int IsRemoveCellsWithType() { return !myRemovedCellTypes.empty();} + + // Do the filter do some real work + int IsRemoving() { return IsRemoveCells() || IsRemoveCellsWithType();} + +protected: + VISU_ExtractUnstructuredGrid(); + ~VISU_ExtractUnstructuredGrid(); + + void Execute(); + + std::set myRemovedCellIds; + std::set myRemovedCellTypes; + +private: + VISU_ExtractUnstructuredGrid(const VISU_ExtractUnstructuredGrid&); // Not implemented. + void operator=(const VISU_ExtractUnstructuredGrid&); // Not implemented. +}; + +#endif + + diff --git a/src/CONVERTOR/VISU_MedConvertor.cxx b/src/CONVERTOR/VISU_MedConvertor.cxx index 9587f53f..ab1e1026 100644 --- a/src/CONVERTOR/VISU_MedConvertor.cxx +++ b/src/CONVERTOR/VISU_MedConvertor.cxx @@ -26,8 +26,11 @@ #include "VISU_MedConvertor.hxx" +#include "VISU_ConvertorUtils.hxx" + #include #include + #define USER_INTERLACE MED_FULL_INTERLACE using namespace std; @@ -38,6 +41,7 @@ static int MYDEBUG = 0; static int MYDEBUG = 0; #endif + static med_err ret = 0; typedef map TVisu2MedEntity; @@ -118,6 +122,7 @@ VISU_Convertor* VISU_MedConvertor::Build() throw (std::runtime_error&) { MedFile aMedFile(myFileInfo.absFilePath()); med_idt fid = aMedFile.GetFid(); med_int iMeshEnd = MEDnMaa(fid); //Get number of meshes + if (iMeshEnd < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDnMaa(...)")); if(MYDEBUG) MESSAGE("ImportInfo - MEDnMaa = "<> MEDnoeudsLire(...)"); + if(ret < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDnoeudsLire(...)")); for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) if(num_fam_elem[iNumElem] != 0){ aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity; @@ -199,7 +204,7 @@ VISU_Convertor* VISU_MedConvertor::Build() throw (std::runtime_error&) { ret = MEDelementsLire(fid,aMeshName,aMesh.myDim,&conn[0],MED_FULL_INTERLACE, &name_elem[0],&iname_elem,&num_elem[0],&inum_elem, &num_fam_elem[0],iNumElemEnd,aMedEntity,aMedType,MED_NOD); - if (ret < 0) throw std::runtime_error("ImportInfo >> MEDelementsLire(...)"); + if (ret < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDelementsLire(...)")); for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) if(num_fam_elem[iNumElem] != 0){ aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity; @@ -224,7 +229,7 @@ VISU_Convertor* VISU_MedConvertor::Build() throw (std::runtime_error&) { ret = MEDfamInfo(fid,aMeshName,aFamInd,aFamilyName,&aFamilyNum, &anAttId[0],&anAttVal[0],&anAttDesc[0],&aNbAttrib, &aGroupNames[0],&aNbGroup); - if(ret < 0) throw std::runtime_error("ImportInfo >> MEDfamInfo"); + if(ret < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDfamInfo")); if(0 && MYDEBUG) MESSAGE("ImportInfo - aFamilyNum = "<> MEDnChamp(fid,0)"); + if (iFieldEnd < 0) throw std::runtime_error(EXCEPTION("ImportChamps >> MEDnChamp(fid,0)")); if(MYDEBUG) MESSAGE("ImportInfo - iFieldEnd = "<> MEDnChamp(fid,i)"); + if(ncomp < 0) throw std::runtime_error(EXCEPTION("ImportChamps >> MEDnChamp(fid,i)")); valarray aCompNames('\0',ncomp*MED_TAILLE_PNOM + 1); valarray aUnitNames('\0',ncomp*MED_TAILLE_PNOM + 1); char name_field[MED_TAILLE_NOM + 1] = ""; med_type_champ type_field; if(MEDchampInfo(fid,iField,name_field,&type_field,&aCompNames[0],&aUnitNames[0],ncomp) < 0) - throw std::runtime_error(string("ImportInfo >> MEDchampInfo(...)")); + throw std::runtime_error(EXCEPTION("ImportInfo >> MEDchampInfo(...)")); //if(type_field != MED_REEL64) continue; //There is some problem in reading INTXX values TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin(); for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++) { @@ -323,7 +328,7 @@ VISU_Convertor* VISU_MedConvertor::Build() throw (std::runtime_error&) { for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) { med_geometrie_element& aGeom = aGeomElemVector[iGeomElem]; med_int iTimeStampEnd = MEDnPasdetemps(fid,name_field,aMedEntity,aGeom); - if(iTimeStampEnd < 0) throw std::runtime_error("ImportInfo >> MEDnPasdetemps(...)"); + if(iTimeStampEnd < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDnPasdetemps(...)")); if(iTimeStampEnd > 0) { for(med_int iTimeStamp = 1; iTimeStamp <= iTimeStampEnd; iTimeStamp++) { char aMeshName[MED_TAILLE_NOM+1] = ""; @@ -332,9 +337,9 @@ VISU_Convertor* VISU_MedConvertor::Build() throw (std::runtime_error&) { med_float dt = 0; ret = MEDpasdetempsInfo(fid,name_field,aMedEntity,aGeom,iTimeStamp, aMeshName,&ngauss,&numdt,dt_unit,&dt,&numo); - if(ret < 0) throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...) < 0"); + if(ret < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDpasdetempsInfo(...) < 0")); if(myMeshMap.find(aMeshName) == myMeshMap.end()) - throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...)"); + throw std::runtime_error(EXCEPTION("ImportInfo >> MEDpasdetempsInfo(...)")); VISU::TMesh &aMesh = myMeshMap[aMeshName]; VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity]; VISU::TFieldMap::iterator aFieldMapIter = aMeshOnEntity.myFieldMap.find(name_field); @@ -376,7 +381,7 @@ VISU_Convertor* VISU_MedConvertor::Build() throw (std::runtime_error&) { aValForTime.myMeshName = aField.myMeshName; aValForTime.myNbComp = aField.myNbComp; aValForTime.myTime = VISU::TField::TTime(dt,dt_unit); - if(MYDEBUG && iGeomElem == 0) + if(MYDEBUG) MESSAGE("ImportInfo -\t aValForTime.myTime = "<> MEDnEntMaa(...)"); + if (iNumElemEnd <= 0) throw std::runtime_error(EXCEPTION("LoadPoints >> MEDnEntMaa(...)")); if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<> MEDnoeudsLire(...)"); + if(ret < 0) throw std::runtime_error(EXCEPTION("LoadPoints >> MEDnoeudsLire(...)")); if(!isPointsLoaded){ VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord; aPointsCoord.resize(iNumElemEnd*theMesh.myDim); if(MYDEBUG) MESSAGE("LoadPoints - Filling coordinates of the mesh - inum_elem = "< num_node(aNbPoints); + med_booleen inum_node = + med_booleen(MEDnumLire(fid,aMeshName,&num_node[0],aNbPoints,MED_NOEUD,med_geometrie_element(0)) >= 0); + if(MYDEBUG) MESSAGE("LoadCellsOnEntity - inum_node = "< node_map; + if(inum_node) + for(int i = 0; i < aNbPoints; i++) + node_map[num_node[i]-1] = i; for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) { int medId = getIdMedType(aGeomElemVector[iGeomElem]); int nbMedNodes = med2vtk[medId].medNbNodes; @@ -574,7 +587,7 @@ int VISU_MedConvertor::LoadCellsOnEntity(const med_idt& fid, VISU::TMeshOnEntity ret = MEDelementsLire(fid,aMeshName,aMesh.myDim,&conn[0],MED_FULL_INTERLACE, &name_elem[0],&iname_elem,&num_elem[0],&inum_elem, &num_fam_elem[0],iNumElemEnd,aMedEntity,aMedType,MED_NOD); - if (ret < 0) throw std::runtime_error("LoadCellsOnEntity >> MEDelementsLire(...)"); + if (ret < 0) throw std::runtime_error(EXCEPTION("LoadCellsOnEntity >> MEDelementsLire(...)")); if(!isCellsLoaded){ VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = theMeshOnEntity.myCellsConn[aVtkType]; aConnForCellType.resize(iNumElemEnd); @@ -582,9 +595,12 @@ int VISU_MedConvertor::LoadCellsOnEntity(const med_idt& fid, VISU::TMeshOnEntity for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) { VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[iNumElem]; anArray.resize(nbVtkNodes); - for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) { - aConnect[k] = conn[kj+k] - 1; - } + if(inum_node) + for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) + aConnect[k] = node_map[conn[kj+k]-1]; + else + for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) + aConnect[k] = conn[kj+k] - 1; switch(aMedType){ case MED_TETRA4 : case MED_TETRA10 : @@ -606,11 +622,9 @@ int VISU_MedConvertor::LoadCellsOnEntity(const med_idt& fid, VISU::TMeshOnEntity anArray[k] = aConnect[k]; } for (int k = 0; k < nbVtkNodes; k++) - if(anArray[k] < 0 || aNbPoints <= anArray[k]){ - static QString aString; - aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d](%d) < 0",aNbPoints,iNumElem,k,anArray[k]); - throw std::runtime_error(aString.latin1()); - } + if(anArray[k] < 0 || aNbPoints <= anArray[k]) + throw std::runtime_error(EXCEPT("ImportCells >> aNbPoints(%1) <= anArray[%2][%3](%4) < 0"). + arg(aNbPoints).arg(iNumElem).arg(k).arg(anArray[k]).latin1()); } } //Filling aFamily SubMesh @@ -628,67 +642,93 @@ int VISU_MedConvertor::LoadCellsOnEntity(const med_idt& fid, VISU::TMeshOnEntity throw std::runtime_error(exc.what()); }catch(...){ theMeshOnEntity.myCellsConn.clear(); - throw std::runtime_error("Unknown exception !!!"); + throw std::runtime_error(EXCEPTION("Unknown exception !!!")); } return 0; } int VISU_MedConvertor::LoadField(const med_idt& fid, const VISU::TMeshOnEntity& theMeshOnEntity, - const VISU::TField& theField, VISU::TField::TValForTime& theValForTime) + VISU::TField& theField, VISU::TField::TValForTime& theValForTime) throw (std::runtime_error&) { //Check on loading already done if(!theValForTime.myValForCells.empty()) return 0; //Main part of code med_int ncomp = MEDnChamp(fid,theField.myId); - if(ncomp < 0) throw std::runtime_error("LoadField >> MEDnChamp(fid,i)"); + if(ncomp < 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDnChamp(fid,i)")); valarray comp('\0',ncomp*MED_TAILLE_PNOM + 1); valarray unit('\0',ncomp*MED_TAILLE_PNOM + 1); char aFieldName[MED_TAILLE_NOM + 1] = ""; + char aMeshName[MED_TAILLE_NOM+1] = ""; + strcpy(aMeshName,theValForTime.myMeshName.c_str()); med_type_champ type_field; if(MEDchampInfo(fid,theField.myId,aFieldName,&type_field,&comp[0],&unit[0],ncomp) < 0) - throw std::runtime_error(string("LoadField >> MEDchampInfo(...)")); + throw std::runtime_error(EXCEPTION("LoadField >> MEDchampInfo(...)")); int iGeomElemEnd; med_geometrie_element* aGeomElemVector; const VISU::TEntity& anEntity = theField.myEntity; GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd); med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity]; - if(MYDEBUG) { - MESSAGE("LoadField - aFieldName = '"< 0){ + if(!theField.myIsTrimmed){ + theField.myIsTrimmed = true; + theField.myDataSize -= iNumElemEnd*theField.myNbComp; + } + //throw std::runtime_error(EXCEPT("VISU_MedConvertor::LoadField - There is no the data " + // "for cells with type %1 of the mesh !!!"). + // arg(med2vtk[medId].medName).latin1()); + } + }else{ med_int ngauss = 0, numdt = 0, numo = 0; char dt_unit[MED_TAILLE_PNOM+1] = ""; med_float dt = 0; ret = MEDpasdetempsInfo(fid,aFieldName,aMedEntity,aGeom,theValForTime.myId, aMeshName,&ngauss,&numdt,dt_unit,&dt,&numo); - if(ret < 0) throw std::runtime_error("LoadField >> MEDpasdetempsInfo(...)"); + if(ret < 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDpasdetempsInfo(...)")); med_int nval = MEDnVal(fid,aFieldName,aMedEntity,aGeom,numdt,numo); - if (nval <= 0) throw std::runtime_error("LoadField >> MEDnVal(...) - nval <= 0"); + if(nval <= 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDnVal(...) - nval <= 0")); else{ - //Checking for accordance between the mesh and the field on number of geomterical elements - int aVtkType = med2vtkCellType(aGeom); - const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMeshOnEntity.myCellsConn; - VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType); - if(aCellsConnIter == aCellsConn.end()) throw std::runtime_error("LoadField - There is no the geom. elem. on the mesh !!!"); - const VISU::TMeshOnEntity::TConnForCellType aConnForCellType = aCellsConnIter->second; - if(aConnForCellType.size() != nval) throw std::runtime_error("LoadField - Size of values and size of mesh not equal !!!"); - if(MYDEBUG) MESSAGE("LoadField - aGeom = "< aMaxNbGaussPts) ngauss = 1; + if(iNumElemEnd*ngauss != nval) + throw std::runtime_error(EXCEPT("LoadField - Size of values (%1) and size of mesh (%2) not equal !!!"). + arg(nval).arg(iNumElemEnd*ngauss).latin1()); VISU::TField::TValForCellsWithType &anArray = theValForTime.myValForCells[aVtkType]; int jEnd = theField.myNbComp*nval; - anArray.resize(jEnd); + int kEnd = jEnd/ngauss; + anArray.resize(kEnd); char pflname[MED_TAILLE_NOM + 1] = ""; switch(type_field){ case MED_REEL64 : { valarray valr(jEnd); ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL, pflname,aMedEntity,aGeom,numdt,numo); - for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j]; + if(ret < 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDchampLire(...)")); + for (med_int k = 0, j = 0; k < kEnd; k++, j += ngauss){ + for (med_int iGauss = 0; iGauss < ngauss; iGauss++) + anArray[k] = valr[j+iGauss]; + anArray[k] /= ngauss; + } break; } //case MED_INT64 : //valarray valr(jEnd); @@ -697,13 +737,19 @@ int VISU_MedConvertor::LoadField(const med_idt& fid, const VISU::TMeshOnEntity& valarray valr(jEnd); ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL, pflname,aMedEntity,aGeom,numdt,numo); - for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j]; + if(ret < 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDchampLire(...)")); + for (med_int k = 0, j = 0; k < kEnd; k++, j += ngauss){ + for (med_int iGauss = 0; iGauss < ngauss; iGauss++) + anArray[k] = valr[j+iGauss]; + anArray[k] /= ngauss; + } break; } - default : - throw std::runtime_error("LoadField >> Value of med_type_champ for the field is wrong !!!"); + default : + throw std::runtime_error(EXCEPTION("LoadField >> Value of med_type_champ for the field is wrong !!!")); } - if(ret < 0) throw std::runtime_error("ChampLire >> MEDchampLire(...)"); + if(MYDEBUG) MESSAGE("LoadField - aGeom = "<