From 31ddcb8b94bee85b2e2a627b504c5679848d44d5 Mon Sep 17 00:00:00 2001 From: apo Date: Tue, 30 Aug 2005 08:12:55 +0000 Subject: [PATCH] 1. To introduce forward and backward ID's mapping 2. To separate MeshOnEntity and Family handling (first step) --- src/CONVERTOR/VISU_Convertor_impl.cxx | 355 +++++++++++++++++++------- src/CONVERTOR/VISU_Convertor_impl.hxx | 57 ++++- src/CONVERTOR/VISU_MedConvertor.cxx | 15 +- src/CONVERTOR/VISU_MedConvertor.hxx | 6 - 4 files changed, 317 insertions(+), 116 deletions(-) diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index def332d0..25e8ac3f 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -58,7 +58,7 @@ static float ERR_SIZE_CALC = 1.00; static int MYVTKDEBUG = 0; #ifdef _DEBUG_ -static int MYDEBUG = 0; +static int MYDEBUG = 1; static int MYDEBUGWITHFILES = 0; #else static int MYDEBUG = 0; @@ -160,6 +160,9 @@ namespace VISU TPointCoords::Init(theNbPoints,theDim); myPointsDim.resize(theDim); myVectorID = theVectorID; + + for(vtkIdType anID = 0, anEnd = theVectorID.size(); anID < anEnd; anID++) + myObj2VTKID[theVectorID[anID]] = anID; } std::string& @@ -187,6 +190,20 @@ namespace VISU } + vtkIdType + TNamedPointCoords + ::GetVTKID(vtkIdType theID) const + { + if(myObj2VTKID.empty()) + return theID; + else{ + TObj2VTKID::const_iterator anIter = myObj2VTKID.find(theID); + if(anIter != myObj2VTKID.end()) + return anIter->second; + } + return -1; + } + //--------------------------------------------------------------- TMeshImpl::TMeshImpl(): myNamedPointCoords(new TNamedPointCoords()), @@ -205,13 +222,6 @@ namespace VISU } - vtkIdType - TSubProfileImpl - ::GetNodeObjID(vtkIdType theID) const - { - return theID; - } - vtkIdType TSubProfileImpl ::GetElemObjID(vtkIdType theID) const @@ -242,11 +252,7 @@ namespace VISU TProfileImpl ::GetNodeObjID(vtkIdType theID) const { - vtkIdType anInputID; - const TVTKAppendFilter& anAppendFilter = GetFilter(); - vtkIdType aID = anAppendFilter->GetNodeObjId(theID,anInputID); - const TSubProfileImpl& aSubProfileImpl = mySubProfileArr[anInputID]; - return aSubProfileImpl.GetNodeObjID(aID); + return myNamedPointCoords->GetObjID(theID); } vtkIdType @@ -259,30 +265,44 @@ namespace VISU const TSubProfileImpl& aSubProfileImpl = mySubProfileArr[anInputID]; return aSubProfileImpl.GetElemObjID(aID); } - //modified by NIZNHY-PKV Tue Aug 30 11:18:46 2005f - //--------------------------------------------------------------- - vtkCell* TProfileImpl::GetElemCell(int theObjID) + + vtkIdType + TProfileImpl + ::GetElemVTKID(vtkIdType theID) const { - int aVtkID; - vtkIdType aObjID; - // - aObjID=GetElemObjID(theObjID); - const TVTKAppendFilter& anAppendFilter = GetFilter(); - aVtkID=anAppendFilter->GetElemVtkID(aObjID); - return anAppendFilter->GetOutput()->GetCell(aVtkID); + if(myElemObj2VTKID.empty()) + return theID; + else{ + TElemObj2VTKID::const_iterator anIter = myElemObj2VTKID.find(theID); + if(anIter != myElemObj2VTKID.end()) + return anIter->second; + } + return -1; } - //--------------------------------------------------------------- - float* TProfileImpl::GetNodeCoord(int theObjID) + + vtkIdType + TProfileImpl + ::GetNodeVTKID(vtkIdType theID) const { - int aVtkID; - vtkIdType aObjID; - // - aObjID=GetNodeObjID(theObjID); - const TVTKAppendFilter& anAppendFilter = GetFilter(); - aVtkID=anAppendFilter->GetElemVtkID(theObjID); - return anAppendFilter->GetOutput()->GetPoint(aVtkID); + return myNamedPointCoords->GetVTKID(theID); } - //modified by NIZNHY-PKV Tue Aug 30 11:18:49 2005t + + vtkCell* + TProfileImpl + ::GetElemCell(int theObjID) + { + vtkIdType aVtkID = GetElemVTKID(theObjID); + return GetFilter()->GetOutput()->GetCell(aVtkID); + } + + float* + TProfileImpl + ::GetNodeCoord(int theObjID) + { + vtkIdType aVtkID = GetNodeVTKID(theObjID); + return GetFilter()->GetOutput()->GetPoint(aVtkID); + } + //--------------------------------------------------------------- TGaussSubMeshImpl::TGaussSubMeshImpl(): @@ -672,7 +692,7 @@ namespace void GetCellsOnEntity(const TVTKSource& theSource, const PMeshOnEntityImpl& theMeshOnEntity, - const std::string& theFamilyName) + const std::string& theFamilyName = "") { //Check on existing family PFamilyImpl aFamily = GetFamily(theMeshOnEntity,theFamilyName); @@ -921,6 +941,7 @@ namespace void GetCells(const TVTKSource& theSource, const PSubProfileImpl& theSubProfile, + const PProfileImpl& theProfile, const PMeshOnEntityImpl& theMeshOnEntity) { vtkIdType aNbCells = theSubProfile->myNbCells; @@ -942,12 +963,16 @@ namespace aCellTypesArray->SetNumberOfComponents(1); aCellTypesArray->SetNumberOfTuples(aNbCells); + VISU::TElemObj2VTKID& anElemObj2VTKID = theProfile->myElemObj2VTKID; if(theSubProfile->myStatus == eAddAll){ VISU::TCell2Connect::const_iterator anIter = aCell2Connect.begin(); for(vtkIdType anId = 0, aConnId = 0; anIter != aCell2Connect.end(); anIter++){ const TConnect& anArray = aCell2Connect[anId]; PrintCells(aConnId,aConnectivity,anArray); aCellTypesArray->SetValue(anId,(unsigned char)aGeom); + + anElemObj2VTKID[theSubProfile->GetElemObjID(anId)] = anId; + aConnId += aNbNodes; anId++; } @@ -958,6 +983,9 @@ namespace const TConnect& anArray = aCell2Connect[aSubId]; PrintCells(aConnId,aConnectivity,anArray); aCellTypesArray->SetValue(anId,(unsigned char)aGeom); + + anElemObj2VTKID[theSubProfile->GetElemObjID(anId)] = anId; + aConnId += aNbNodes; anId++; } @@ -994,7 +1022,7 @@ namespace GetPoints(aSource,theMesh); INITMSGA(MYDEBUG,0,"GetNumberOfPoints - "<GetNumberOfPoints()<GetNumberOfCells()<myIsVTKDone = true; @@ -1266,6 +1294,21 @@ namespace } + //--------------------------------------------------------------- + void + PrintMemorySize(vtkUnstructuredGrid* theDataSet) + { + theDataSet->Update(); + BEGMSG(1,"GetPoints() = "<GetPoints()->GetActualMemorySize()*1000)<(aFindMeshOnEntity);; - PFamilyImpl aFamily = boost::get<2>(aFindMeshOnEntity); PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity); - TVTKSource aSource; - bool *anIsInitialized; - if(aFamily){ - aSource = aFamily->GetSource(); - anIsInitialized = &(aFamily->myIsVTKDone); - }else{ - aSource = aMeshOnEntity->GetSource(); - anIsInitialized = &(aMeshOnEntity->myIsVTKDone); + //Main part of code + const TVTKSource& aSource = aMeshOnEntity->GetSource(); +#ifndef _DEXCEPT_ + try{ +#endif + if(!aMeshOnEntity->myIsVTKDone){ + if(MYVTKDEBUG) aSource->DebugOn(); + + LoadMeshOnEntity(aMeshOnEntity); + GetPoints(aSource,aMesh); + GetCellsOnEntity(aSource,aMeshOnEntity); + + aMeshOnEntity->myIsVTKDone = true; + + if(MYDEBUGWITHFILES){ + std::string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); + std::string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; + aFileName += aMeshName + dtos("-%d-",int(theEntity)) + "-Conv.vtk"; + VISU::WriteToFile(aSource.GetPointer(),aFileName); + } + } + + if(MYVTKDEBUG){ + GetMeshOnEntitySize(theMeshName,theEntity); + PrintMemorySize(aSource.GetPointer()); + } + +#ifndef _DEXCEPT_ + }catch(...){ + throw; } +#endif + + return aSource.GetPointer(); +} + + +//--------------------------------------------------------------- +VISU_Convertor::TOutput* +VISU_Convertor_impl +::GetFamilyOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName) +{ + INITMSG(MYDEBUG,"GetFamilyOnEntity"<< + "; theMeshName = '"<(aFindFamilyOnEntity);; + PFamilyImpl aFamily = boost::get<2>(aFindFamilyOnEntity); + PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindFamilyOnEntity); //Main part of code + const TVTKSource& aSource = aFamily->GetSource(); #ifndef _DEXCEPT_ try{ #endif - if(!(*anIsInitialized)){ + if(!aFamily->myIsVTKDone){ if(MYVTKDEBUG) aSource->DebugOn(); LoadMeshOnEntity(aMeshOnEntity,theFamilyName); GetPoints(aSource,aMesh); GetCellsOnEntity(aSource,aMeshOnEntity,theFamilyName); - (*anIsInitialized) = true; + aFamily->myIsVTKDone = true; 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")+"-"; + std::string aMeshName = QString(theMeshName.c_str()).simplifyWhiteSpace().latin1(); + std::string aFamilyName = QString(theFamilyName.c_str()).simplifyWhiteSpace().latin1(); + std::string aFileName = string("/users/")+getenv("USER")+"/"+getenv("USER")+"-"; aFileName += aMeshName + dtos("-%d-",int(theEntity)) + aFamilyName + "-Conv.vtk"; VISU::WriteToFile(aSource.GetPointer(),aFileName); } @@ -1338,15 +1441,9 @@ VISU_Convertor_impl if(MYVTKDEBUG){ GetMeshOnEntitySize(theMeshName,theEntity,theFamilyName); - aSource->Update(); - BEGMSG(MYVTKDEBUG,"GetPoints() = "<GetPoints()->GetActualMemorySize()*1000)<> There is no mesh on the entity - "<second; - + return TFindMeshOnEntity(aMesh, - aMeshOnEntityMap[theEntity], - GetFamily(aMeshOnEntity,theFamilyName)); + aMeshOnEntity); +} + + +//--------------------------------------------------------------- +VISU_Convertor_impl::TFindFamilyOnEntity +VISU_Convertor_impl +::FindFamilyOnEntity(const string& theMeshName, + const VISU::TEntity& theEntity, + const string& theFamilyName) +{ + PMeshImpl aMesh = FindMesh(theMeshName); + VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.find(theEntity); + if(aMeshOnEntityMapIter == aMeshOnEntityMap.end()) + EXCEPTION(runtime_error,"FindFamilyOnEntity >> There is no mesh on the entity - "<second; + + return TFindFamilyOnEntity(aMesh, + aMeshOnEntity, + VISU::GetFamily(aMeshOnEntity,theFamilyName)); } @@ -1695,29 +1814,79 @@ VISU_Convertor_impl } +//--------------------------------------------------------------- float VISU_Convertor_impl ::GetMeshOnEntitySize(const std::string& theMeshName, const VISU::TEntity& theEntity, const std::string& theFamilyName) +{ + if(theFamilyName == "") + return GetMeshOnEntitySize2(theMeshName,theEntity); + else + return GetFamilyOnEntitySize(theMeshName,theEntity,theFamilyName); +} + + +//--------------------------------------------------------------- +float +VISU_Convertor_impl +::GetMeshOnEntitySize2(const std::string& theMeshName, + const VISU::TEntity& theEntity) { TFindMeshOnEntity aFindMeshOnEntity = - FindMeshOnEntity(theMeshName,theEntity,theFamilyName); + FindMeshOnEntity(theMeshName,theEntity); + PMeshImpl aMesh = boost::get<0>(aFindMeshOnEntity); - PFamilyImpl aFamily = boost::get<2>(aFindMeshOnEntity); PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity); vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord); - vtkIdType aNbCells, aCellsSize; - - if(!aFamily){ - aNbCells = aMeshOnEntity->myNbCells; - aCellsSize = aMeshOnEntity->myCellsSize; - }else{ - aNbCells = aFamily->myNbCells; - aCellsSize = aFamily->myCellsSize; + vtkIdType aNbCells = aMeshOnEntity->myNbCells; + vtkIdType aCellsSize = aMeshOnEntity->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; + + MSG(MYDEBUG,"GetMeshOnEntitySize2 "<< + "- aResult = "<(aFindFamilyOnEntity); + PFamilyImpl aFamily = boost::get<2>(aFindFamilyOnEntity); + PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindFamilyOnEntity); + + vtkIdType aPointsSize = 3*aMesh->myNbPoints*sizeof(VISU::TCoord); + vtkIdType aNbCells = aFamily->myNbCells; + vtkIdType aCellsSize = aFamily->myCellsSize; + vtkIdType aConnectivitySize = aCellsSize*sizeof(vtkIdType); vtkIdType aTypesSize = aNbCells*sizeof(char); vtkIdType aLocationsSize = aNbCells*sizeof(int); @@ -1726,21 +1895,26 @@ VISU_Convertor_impl (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link)); aLinksSize = 0; vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize; + + MSG(MYDEBUG,"GetFamilyOnEntitySize "<< + "- aResult = "<(aFindMeshOnEntity);; - PFamilyImpl aFamily = boost::get<2>(aFindMeshOnEntity); PMeshOnEntityImpl aMeshOnEntity = boost::get<1>(aFindMeshOnEntity); VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; diff --git a/src/CONVERTOR/VISU_Convertor_impl.hxx b/src/CONVERTOR/VISU_Convertor_impl.hxx index 571a1f63..b9bb7bcf 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.hxx +++ b/src/CONVERTOR/VISU_Convertor_impl.hxx @@ -120,11 +120,14 @@ namespace VISU //--------------------------------------------------------------- typedef TVector TVectorID; + typedef std::map TObj2VTKID; + class TNamedPointCoords: public virtual TPointCoords { typedef TVector TPointsDim; TPointsDim myPointsDim; TVectorID myVectorID; + TObj2VTKID myObj2VTKID; public: @@ -142,6 +145,10 @@ namespace VISU virtual vtkIdType GetObjID(vtkIdType theID) const; + + virtual + vtkIdType + GetVTKID(vtkIdType theID) const; }; typedef SharedPtr PNamedPointCoords; @@ -171,10 +178,6 @@ namespace VISU vtkIdType myGeom; std::string myName; - virtual - vtkIdType - GetNodeObjID(int theVtkI) const; - virtual vtkIdType GetElemObjID(int theVtkI) const; @@ -186,6 +189,7 @@ namespace VISU //--------------------------------------------------------------- + typedef std::map TElemObj2VTKID; typedef std::vector TSubProfileArr; typedef std::map TGeom2SubProfile; @@ -202,15 +206,23 @@ namespace VISU vtkIdType GetElemObjID(int theVtkI) const; - //pkv f + virtual + vtkIdType + GetElemVTKID(int theID) const; + + virtual + vtkIdType + GetNodeVTKID(int theID) const; + virtual vtkCell* GetElemCell(int theObjID); + virtual float* GetNodeCoord(int theObjID); - //pkv t + TElemObj2VTKID myElemObj2VTKID; PNamedPointCoords myNamedPointCoords; TSubProfileArr mySubProfileArr; @@ -384,6 +396,17 @@ public: const VISU::TEntity& theEntity, const std::string& theFamilyName = ""); + virtual + float + GetMeshOnEntitySize2(const std::string& theMeshName, + const VISU::TEntity& theEntity); + + virtual + float + GetFamilyOnEntitySize(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName); + virtual float GetMeshOnGroupSize(const std::string& theMeshName, @@ -430,6 +453,17 @@ public: const VISU::TEntity& theEntity, const std::string& theFamilyName = ""); + virtual + TOutput* + GetMeshOnEntity2(const std::string& theMeshName, + const VISU::TEntity& theEntity); + + virtual + TOutput* + GetFamilyOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName); + virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, @@ -466,11 +500,16 @@ protected: VISU::PMeshImpl FindMesh(const std::string& theMeshName); - typedef boost::tuple TFindMeshOnEntity; + typedef boost::tuple TFindMeshOnEntity; TFindMeshOnEntity FindMeshOnEntity(const std::string& theMeshName, - const VISU::TEntity& theEntity, - const std::string& theFamilyName); + const VISU::TEntity& theEntity); + + typedef boost::tuple TFindFamilyOnEntity; + TFindFamilyOnEntity + FindFamilyOnEntity(const std::string& theMeshName, + const VISU::TEntity& theEntity, + const std::string& theFamilyName); typedef boost::tuple TFindMeshOnGroup; TFindMeshOnGroup diff --git a/src/CONVERTOR/VISU_MedConvertor.cxx b/src/CONVERTOR/VISU_MedConvertor.cxx index d66a8df2..49138225 100644 --- a/src/CONVERTOR/VISU_MedConvertor.cxx +++ b/src/CONVERTOR/VISU_MedConvertor.cxx @@ -736,13 +736,6 @@ namespace //--------------------------------------------------------------- - vtkIdType - TMEDSubProfile - ::GetNodeObjID(vtkIdType theID) const - { - return myNamedPointCoords->GetObjID(theID); - } - vtkIdType TMEDSubProfile ::GetElemObjID(vtkIdType theID) const @@ -976,7 +969,7 @@ VISU_MedConvertor PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY]; aMeshOnEntity->myEntity = NODE_ENTITY; aMeshOnEntity->myMeshName = theMesh->myName; - PMEDFamily aFamily = GetFamily(aMeshOnEntity,theFamilyName); + PMEDFamily aFamily = VISU::GetFamily(aMeshOnEntity,theFamilyName); //Check on loading already done if(theMesh->myIsDone) @@ -1055,7 +1048,7 @@ VISU_MedConvertor #endif //Check on existing family - PFamilyImpl aFamily = GetFamily(theMeshOnEntity,theFamilyName); + PFamilyImpl aFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName); //Check on loading already done bool isCellsLoaded = !theMeshOnEntity->myGeom2Cell2Connect.empty(); @@ -1306,10 +1299,10 @@ LoadProfile(const MED::PWrapper& theMed, aSubProfile->myIsElemNum = anElemInfo->IsElemNum(); if(aSubProfile->myIsElemNum) aSubProfile->myElemNum = anElemInfo->myElemNum; - - aSubProfile->myNamedPointCoords = theMesh->myNamedPointCoords; } } + aProfile->myNamedPointCoords = theMesh->myNamedPointCoords; + aProfile->myIsDone = true; } diff --git a/src/CONVERTOR/VISU_MedConvertor.hxx b/src/CONVERTOR/VISU_MedConvertor.hxx index fd51f28f..3394876e 100644 --- a/src/CONVERTOR/VISU_MedConvertor.hxx +++ b/src/CONVERTOR/VISU_MedConvertor.hxx @@ -34,16 +34,10 @@ namespace VISU MED::EBooleen myIsElemNum; MED::TElemNum myElemNum; - PNamedPointCoords myNamedPointCoords; - - virtual - vtkIdType - GetNodeObjID(vtkIdType theID) const; virtual vtkIdType GetElemObjID(vtkIdType theID) const; - }; typedef SharedPtr PMEDSubProfile; -- 2.39.2