X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FCONVERTOR%2FVISU_Convertor_impl.cxx;h=5fcb2f9e5983cc7236200e4369ca021d2115d0c3;hb=48d5ec677f0df3ad0bd8dfc1c1c092b9efaf952d;hp=8f6ed718c8b525d776c91fd5b71ac67a4aa1d0d5;hpb=1470190682148c950f0c1a941034e9e2b6c10318;p=modules%2Fvisu.git diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index 8f6ed718..5fcb2f9e 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,9 @@ #include #include #include +#include + +#include #include #include @@ -42,6 +46,11 @@ #include using namespace std; +using namespace VISU; + +static float ERR_SIZE_CALC = 1.00; + +static int MYVTKDEBUG = 0; #ifdef _DEBUG_ static int MYDEBUG = 0; @@ -52,6 +61,439 @@ static int MYDEBUGWITHFILES = 0; #endif +namespace{ + + template + std::string dtos(const std::string& fmt, T val){ + static QString aString; + aString.sprintf(fmt.c_str(),val); + return aString.latin1(); + } + + enum ECoordName{eX, eY, eZ, eNone}; + typedef VISU::TCoord (*TGetCoord)(const VISU::TMeshImpl::TPointsCoord&, int); + + template + VISU::TCoord + GetCoord(const VISU::TMeshImpl::TPointsCoord& thePointsCoord, + int theStartPos) + { + return thePointsCoord[theStartPos+TheCoordId]; + } + + template<> + VISU::TCoord + GetCoord(const VISU::TMeshImpl::TPointsCoord& thePointsCoord, + int theStartPos) + { + return 0.0; + } + + + TGetCoord aXYZGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord + }; + + + TGetCoord aXYGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord + }; + + TGetCoord aYZGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord + }; + + TGetCoord aXZGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord + }; + + + TGetCoord aXGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord + }; + + TGetCoord aYGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord + }; + + TGetCoord aZGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord + }; + + + class TCoordHelper{ + const VISU::TMeshImpl::TPointsCoord& myPointsCoord; + TGetCoord* myGetCoord; + public: + TCoordHelper(const VISU::TMeshImpl::TPointsCoord& thePointsCoord, + TGetCoord* theGetCoord): + myPointsCoord(thePointsCoord), + myGetCoord(theGetCoord) + {} + virtual ~TCoordHelper(){} + VISU::TCoord + GetCoord(int theStartPos, int theCoodId) + { + return (*myGetCoord[theCoodId])(myPointsCoord,theStartPos); + } + }; + typedef std::auto_ptr TCoordHelperPtr; + + void GetPoints(VISU::TVTKSource& theStorage, VISU::PMeshImpl theMesh) + { + vtkPoints* aPoints = theMesh->myPoints.GetPointer(); + if(!aPoints){ + aPoints = vtkPoints::New(); + TCoordHelperPtr aCoordHelperPtr; + const VISU::TMeshImpl::TPointsCoord& anArray = theMesh->myPointsCoord; + { + int aMeshDimension = theMesh->myDim; + bool anIsDimPresent[3] = {false, false, false}; + for(int iDim = 0; iDim < aMeshDimension; iDim++){ + string aDimName = theMesh->myPointsDim[iDim]; + if(aDimName == "x" || aDimName == "X") + anIsDimPresent[eX] = true; + else if(aDimName == "y" || aDimName == "Y") + anIsDimPresent[eY] = true; + else if(aDimName == "z" || aDimName == "Z") + anIsDimPresent[eZ] = true; + } + + switch(aMeshDimension){ + case 3: + aCoordHelperPtr.reset(new TCoordHelper(anArray,aXYZGetCoord)); + break; + case 2: + if(anIsDimPresent[eY] && anIsDimPresent[eZ]) + aCoordHelperPtr.reset(new TCoordHelper(anArray,aYZGetCoord)); + else if(anIsDimPresent[eX] && anIsDimPresent[eZ]) + aCoordHelperPtr.reset(new TCoordHelper(anArray,aXZGetCoord)); + else + aCoordHelperPtr.reset(new TCoordHelper(anArray,aXYGetCoord)); + break; + case 1: + if(anIsDimPresent[eY]) + aCoordHelperPtr.reset(new TCoordHelper(anArray,aYGetCoord)); + else if(anIsDimPresent[eZ]) + aCoordHelperPtr.reset(new TCoordHelper(anArray,aZGetCoord)); + else + aCoordHelperPtr.reset(new TCoordHelper(anArray,aXGetCoord)); + break; + } + } + + if(MYVTKDEBUG) aPoints->DebugOn(); + vtkIdType iEnd = theMesh->myPointsCoord.size(); + vtkIdType aNbPoints = iEnd / theMesh->myDim; + aPoints->SetNumberOfPoints(aNbPoints); + MSG(MYDEBUG,"GetPoints - aNbPoints = "<> There is no elements on the family !!!"); + VISU::TFamilyImpl::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); + if(aSubMeshIter == aSubMesh.end()) continue; + const VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; + MSG(MYDEBUG,"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, + VISU::PMeshImpl theMesh, + const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) + { + //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::PMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity]; + 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; + PMeshOnEntityImpl aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity]; + PFamilyImpl aFamily = GetFamily(aMeshOnEntity,aFamilyName); + const VISU::TMeshOnEntityImpl::TCellsConn &aCellsConn = aMeshOnEntity->myCellsConn; + VISU::TMeshOnEntityImpl::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin(); + for(; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){ + const VISU::TMeshOnEntityImpl::TConnForCellType& anArray = aCellsConnIter->second; + int aVtkType = aCellsConnIter->first; + MSG(MYDEBUG,"GetCellsOnGroup - aVtkType = "<> There is no elements on the family !!!"); + VISU::TFamilyImpl::TSubMesh::const_iterator aSubMeshIter = aSubMesh.find(aVtkType); + if(aSubMeshIter == aSubMesh.end()) continue; + const VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second; + MSG(MYDEBUG,"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, + PMeshOnEntityImpl theMeshOnEntity, + PValForTimeImpl theValForTime) + { + const VISU::TValForTimeImpl::TValForCells& aValForCells = theValForTime->myValForCells; + const VISU::TMeshOnEntityImpl::TCellsConn &aCellsConn = theMeshOnEntity->myCellsConn; + VISU::TMeshOnEntityImpl::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, + VISU::PFieldImpl theField, + VISU::PValForTimeImpl theValForTime) + { + //theFloatArray->DebugOn(); + theFloatArray->SetNumberOfTuples(theNumberOfTuples); + theFloatArray->SetName(theFieldName.c_str()); + MSG(MYDEBUG,"GetValsOnTimeStamp - theNumberOfTuples = "<myValForCells; + VISU::TValForTimeImpl::TValForCells::const_iterator aValForCellsIter = aValForCells.begin(); + for(int k = 0; aValForCellsIter != aValForCells.end(); aValForCellsIter++) { + const VISU::TValForTimeImpl::TValForCellsWithType& anArray = aValForCellsIter->second; + int iEnd = anArray.size()/theField->myNbComp; + int aVtkType = aValForCellsIter->first; + MSG(MYDEBUG,"GetValsOnTimeStamp - iEnd = "<myTime; + string aFieldName = theField->myMeshName + ", " + theField->myName + ": " + + VISU_Convertor::GenerateName(aTime); + return aFieldName; + } + + void GetTimeStamp(VISU::TVTKSource& theStorage, + const VISU::PFieldImpl theField, + const VISU::PValForTimeImpl theValForTime) + { + int aNumberOfTuples = theField->myDataSize/theField->myNbComp; + string aFieldName = GenerateFieldName(theField,theValForTime); + MSG(MYDEBUG,"GetTimeStamp(TVTKSource) - aFieldName = "<myStorage); + PMeshImpl aMesh = boost::get<0>(aFindMeshOnEntity);; + PFamilyImpl aFamily = boost::get<2>(aFindMeshOnEntity); + PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity); + if(aFamily) + pSource = &(aFamily->myStorage); else - pSource = &(aMeshOnEntity.myStorage); + pSource = &(aMeshOnEntity->myStorage); VISU::TVTKSource& aSource = *pSource; //Main part of code - if(aSource.get() == NULL){ - aSource.reset(TOutput::New()); - 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.get(),aFileName); + try{ + if(aSource.GetPointer() == NULL){ + aSource = TOutput::New(); + aSource->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(); + MSG(MYVTKDEBUG,"GetMeshOnEntity - GetPoints() = "<GetPoints()->GetActualMemorySize()*1000)); + MSG(MYVTKDEBUG,"GetMeshOnEntity - GetCells() = "<GetCells()->GetActualMemorySize()*1000)); + MSG(MYVTKDEBUG,"GetMeshOnEntity - GetCellTypesArray() = "<GetCellTypesArray()->GetActualMemorySize()*1000)); + MSG(MYVTKDEBUG,"GetMeshOnEntity - GetCellLocationsArray() = "<GetCellLocationsArray()->GetActualMemorySize()*1000)); + aDataSet->BuildLinks(); + MSG(MYVTKDEBUG,"GetMeshOnEntity - GetCellLinks() = "<GetCellLinks()->GetActualMemorySize()*1000)); + MSG(MYVTKDEBUG,"GetMeshOnEntity - GetActualMemorySize() = "<GetActualMemorySize()*1000)); + } + }catch(...){ + aSource = vtkSmartPointerBase(); + throw; } - return aSource.get(); + return aSource.GetPointer(); } VISU_Convertor::TOutput* VISU_Convertor_impl::GetMeshOnGroup(const string& theMeshName, const string& theGroupName) - throw(std::runtime_error&) { - if(MYDEBUG) MESSAGE("GetMeshOnGroup - theMeshName = '"<(aFindMeshOnGroup); + PGroupImpl aGroup = boost::get<1>(aFindMeshOnGroup); + 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* @@ -134,473 +595,391 @@ VISU_Convertor_impl::GetTimeStampOnMesh(const string& theMeshName, const VISU::TEntity& theEntity, const string& theFieldName, int theStampsNum) - throw(std::runtime_error&) { - if(MYDEBUG){ - MESSAGE("GetTimeStampOnMesh - theMeshName = '"<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); + try{ + if(aSource.GetPointer()) + return aSource.GetPointer(); + else if(anAttribyteFilter.GetPointer()) + return anAttribyteFilter->GetUnstructuredGridOutput(); + else{ + LoadFieldOnMesh(aMesh,aMeshOnEntity,aField,aValForTime); + + VISU::TVTKExtractFilter& anExtractFilter = aField->myExtractFilter; + if(anExtractFilter.GetPointer() == NULL){ + anExtractFilter = VISU_ExtractUnstructuredGrid::New(); + anExtractFilter->Delete(); + //anExtractFilter->DebugOn(); + try{ + LoadMeshOnEntity(aVTKMeshOnEntity); + }catch(std::exception& exc){ + aVTKMeshOnEntity = aMeshOnEntity; + MSG(MYDEBUG,"Follow exception was occured :\n"<myMeshName,aVTKMeshOnEntity->myEntity); + + anExtractFilter->SetInput(aVTKMeshOnEntity->myStorage.GetPointer()); + ::InitProfile(anExtractFilter,aMeshOnEntity,aValForTime); + } + if(!anExtractFilter->IsRemoving()){ + aSource = TOutput::New(); + aSource->Delete(); + aSource->ShallowCopy(aVTKMeshOnEntity->myStorage.GetPointer()); + ::GetTimeStamp(aSource,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, + aField,aValForTime); + anOutput = anAttribyteFilter->GetUnstructuredGridOutput(); + } + 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) + MSG(MYVTKDEBUG,"GetTimeStampOnMesh - GetData() = "<GetPointData()->GetActualMemorySize()*1000)); + else + MSG(MYVTKDEBUG,"GetMeshOnEntity - GetData() = "<GetCellData()->GetActualMemorySize()*1000)); + MSG(MYVTKDEBUG,"GetTimeStampOnMesh - GetActualMemorySize() = "<GetActualMemorySize()*1000)); + } } + }catch(...){ + aSource = vtkSmartPointerBase(); + anAttribyteFilter = vtkSmartPointerBase(); + throw; } - return aSource.get(); + return anOutput; } -inline void PrintCells(int& theStartId, - vtkCellArray* theConnectivity, - const VISU::TMeshOnEntity::TConnect& theVector) +VISU::PMeshImpl +VISU_Convertor_impl::FindMesh(const string& theMeshName) { - 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(); -} + GetMeshMap(); + TMeshMap::iterator aMeshMapIter = myMeshMap.find(theMeshName); + if(aMeshMapIter == myMeshMap.end()) + EXCEPTION(runtime_error,"FindMesh >> There is no mesh with the name - '"< 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); - } - } - } - 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); -} + PMeshImpl aMesh = aMeshMapIter->second; + return aMesh; +} -void VISU_Convertor_impl::GetCellsOnGroup(VISU::TVTKSource& theStorage, - const VISU::TMesh& theMesh, - const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet) - const throw (std::runtime_error&) +VISU_Convertor_impl::TFindMeshOnEntity +VISU_Convertor_impl::FindMeshOnEntity(const string& theMeshName, + const VISU::TEntity& theEntity, + const string& theFamilyName) { - //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); - } - } - } - 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); -} + PMeshImpl aMesh = FindMesh(theMeshName); + VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(theEntity); + if(aMeshOnEntityMapIter == aMeshOnEntityMap.end()) + EXCEPTION(runtime_error,"FindMeshOnEntity >> There is no mesh on the entity - "<second; -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 = "<first; + const VISU::PMesh 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::PMeshOnEntity 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::PField aField = aFieldMapIter->second; + const VISU::TValField& aValField = aField->myValField; + VISU::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); } } + MSG(MYDEBUG,"GetSize - aResult = "<> There is no mesh with the name!!!"); - 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) - throw (std::runtime_error&) +float VISU_Convertor_impl::GetMeshOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName) { - 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!!!"); - theMeshOnEntity = &aMeshOnEntityMap[theEntity]; - theFamily = VISU::GetFamily(*theMeshOnEntity,theFamilyName); -} - + TFindMeshOnEntity aFindMeshOnEntity = + FindMeshOnEntity(theMeshName,theEntity,theFamilyName); + PMeshImpl aMesh = boost::get<0>(aFindMeshOnEntity); + PFamilyImpl aFamily = boost::get<2>(aFindMeshOnEntity); + PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity); -vtkIdType VISU_Convertor_impl::GetMeshOnEntitySize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName) - throw (std::runtime_error&) -{ - VISU::TMesh* pMesh = NULL; - VISU::TFamily* pFamily = NULL; - VISU::TMeshOnEntity* pMeshOnEntity = NULL; - FindMeshOnEntity(theMeshName,pMesh,theEntity,pMeshOnEntity,theFamilyName,pFamily); - vtkIdType aResult = 3*pMesh->myNbPoints*sizeof(VISU::TMesh::TCoord); + vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord); vtkIdType aNbCells, aCellsSize; - if(!pFamily){ - aNbCells = pMeshOnEntity->myNbCells; - aCellsSize = pMeshOnEntity->myCellsSize; + + if(!aFamily){ + aNbCells = aMeshOnEntity->myNbCells; + aCellsSize = aMeshOnEntity->myCellsSize; }else{ - aNbCells = pFamily->myNbCells; - aCellsSize = pFamily->myCellsSize; + aNbCells = aFamily->myNbCells; + aCellsSize = aFamily->myCellsSize; + } + + vtkIdType aConnectivitySize = aCellsSize*sizeof(vtkIdType); + vtkIdType aTypesSize = aNbCells*sizeof(char); + vtkIdType aLocationsSize = aNbCells*sizeof(int); + float aNbCellsPerPoint = aCellsSize / aNbCells - 1; + vtkIdType aLinksSize = aMesh->myNbPoints * + (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link)); + aLinksSize = 0; + vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize; + if(MYDEBUG){ + MSG(MYVTKDEBUG,"GetMeshOnEntitySize - aPointsSize = "<myGroupMap; + PMeshImpl aMesh = FindMesh(theMeshName); + VISU::TGroupMap& aGroupMap = aMesh->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!!!"); - theGroup = &aGroupMapIter->second; + EXCEPTION(runtime_error,"FindMesh >> There is no the group in the mesh!!! - '"<second; + return TFindMeshOnGroup(aMesh,aGroup); } -vtkIdType VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName, - const std::string& theGroupName) - throw (std::runtime_error&) +float VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName, + const std::string& theGroupName) { - 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 = "<(aFindMeshOnGroup); + PGroupImpl aGroup = boost::get<1>(aFindMeshOnGroup); + + vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord); + vtkIdType aNbCells = aGroup->myNbCells, aCellsSize = aGroup->myCellsSize; + vtkIdType aConnectivityAndTypesSize = aCellsSize*sizeof(vtkIdType); + vtkIdType aLocationsSize = aNbCells*sizeof(int); + float aNbCellsPerPoint = aCellsSize / aNbCells - 1; + vtkIdType aLinksSize = aMesh->myNbPoints * + (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(short)); + aLinksSize = 0; + vtkIdType aResult = aPointsSize + aConnectivityAndTypesSize + aLocationsSize + aLinksSize; + if(MYDEBUG){ + MSG(MYVTKDEBUG,"GetMeshOnGroupSize - aPointsSize = "<myMeshOnEntityMap; + TFindMeshOnEntity aFindMeshOnEntity = FindMeshOnEntity(theMeshName,theEntity,""); + PMeshImpl aMesh = boost::get<0>(aFindMeshOnEntity);; + PFamilyImpl aFamily = boost::get<2>(aFindMeshOnEntity); + PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity); + + VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + PMeshOnEntityImpl aVTKMeshOnEntity; 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]; - } - 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!!!"); - theField = &aFieldMap[theFieldName]; + if(aMeshOnEntityMap.find(VISU::CELL_ENTITY) != aMeshOnEntityMap.end()) + aVTKMeshOnEntity = aMeshOnEntityMap[VISU::CELL_ENTITY]; + else if(aMeshOnEntityMap.find(VISU::FACE_ENTITY) != aMeshOnEntityMap.end()) + aVTKMeshOnEntity = aMeshOnEntityMap[VISU::FACE_ENTITY]; + else if(aMeshOnEntityMap.find(VISU::NODE_ENTITY) != aMeshOnEntityMap.end()) + aVTKMeshOnEntity = aMeshOnEntityMap[VISU::EDGE_ENTITY]; + }else + aVTKMeshOnEntity = aMeshOnEntity; + + VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; + VISU::TFieldMap::const_iterator aFieldIter= aFieldMap.find(theFieldName); + if(aFieldIter == aFieldMap.end()) + EXCEPTION(runtime_error,"FindField >> There is no field on the mesh!!!"); + + PFieldImpl aField = aFieldIter->second; + + return TFindField(aMesh, + aMeshOnEntity, + aVTKMeshOnEntity, + aField); } -vtkIdType VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName) - throw(std::runtime_error&) +float VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName) { - VISU::TMesh* pMesh = NULL; - VISU::TField* pField = NULL; - 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 = "<(aFindField); + PField aField = boost::get<3>(aFindField); + + float aMeshSize = GetMeshOnEntitySize(theMeshName,aVTKMeshOnEntity->myEntity); + float aFieldOnMeshSize = float(aField->myDataSize*sizeof(float)*aField->myValField.size()*ERR_SIZE_CALC); + float aResult = aMeshSize + aFieldOnMeshSize; + if(MYDEBUG) + MSG(MYVTKDEBUG,"GetFieldOnMeshSize - aFieldOnMeshSize = "<myValField; - if(aValField.find(theStampsNum) == aValField.end()) - throw std::runtime_error("FindTimeStamp >> There is no field with the timestamp!!!"); - theValForTime = &aValField[theStampsNum]; + TFindField aFindField = FindField(theMeshName,theEntity,theFieldName); + PField aField = boost::get<3>(aFindField); + + VISU::TValField& aValField = aField->myValField; + VISU::TValField::const_iterator aValFieldIter= aValField.find(theStampsNum); + if(aValFieldIter == aValField.end()) + EXCEPTION(runtime_error,"FindTimeStamp >> There is no field with the timestamp!!!"); + + PMeshImpl aMesh = boost::get<0>(aFindField); + PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindField); + PMeshOnEntityImpl aVTKMeshOnEntity = boost::get<2>(aFindField); + PValForTimeImpl aValForTime = aValFieldIter->second; + + return TFindTimeStamp(aMesh, + aMeshOnEntity, + aVTKMeshOnEntity, + aField, + aValForTime); } -vtkIdType VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFieldName, - int theStampsNum) - throw (std::runtime_error&) +float VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFieldName, + int theStampsNum) { - VISU::TMesh* pMesh = NULL; - VISU::TField* pField = NULL; - VISU::TMeshOnEntity *pMeshOnEntity = NULL, *pVTKMeshOnEntity = NULL; - 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 = "<(aFindTimeStamp); + PField aField = boost::get<3>(aFindTimeStamp); + + float aMeshSize = GetMeshOnEntitySize(theMeshName,aVTKMeshOnEntity->myEntity); + float aTimeStampSize = float(aField->myDataSize*sizeof(float) * ERR_SIZE_CALC); + float aResult = aMeshSize + aTimeStampSize; + + MSG(MYDEBUG && MYVTKDEBUG,"GetTimeStampSize - aTimeStampSize = "<