From 6b1208abbb58edf35d94dda58714b221b600e4d3 Mon Sep 17 00:00:00 2001 From: apo Date: Wed, 27 Dec 2006 09:07:48 +0000 Subject: [PATCH] To generalize implementation of direct passing MED node coordinates to VTK --- src/CONVERTOR/VISU_Convertor_impl.cxx | 98 ++++++++++++------- src/CONVERTOR/VISU_Convertor_impl.hxx | 136 +++++++++++++++++++++----- src/CONVERTOR/VISU_MedConvertor.cxx | 51 +++++----- src/CONVERTOR/VISU_MedConvertor.hxx | 76 ++++++++++++-- src/VISU_I/VISU_CorbaMedConvertor.cxx | 34 ++----- src/VISU_I/VISU_CorbaMedConvertor.hxx | 25 ++++- 6 files changed, 302 insertions(+), 118 deletions(-) diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index 10ea9e20..fe77253d 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -211,6 +211,46 @@ namespace VISU return GetFilter()->GetUnstructuredGridOutput(); } + + //--------------------------------------------------------------- + void + TCoordHolderBase + ::Init(vtkIdType theNbPoints, + vtkIdType theDim) + { + myDim = theDim; + myNbPoints = theNbPoints; + } + + vtkIdType + TCoordHolderBase + ::GetNbPoints() const + { + return myNbPoints; + } + + vtkIdType + TCoordHolderBase + ::GetDim() const + { + return myDim; + } + + size_t + TCoordHolderBase + ::size() const + { + return GetNbPoints() * GetDim(); + } + + unsigned long int + TCoordHolderBase + ::GetMemorySize() + { + return sizeof(TCoord) * size(); + } + + //--------------------------------------------------------------- TPointCoords ::TPointCoords(): @@ -222,37 +262,38 @@ namespace VISU void TPointCoords - ::Init(vtkIdType theNbPoints, - vtkIdType theDim, - const MED::PNodeCoord& theCoord) + ::Init(const PCoordHolder& theCoord) { - myDim = theDim; - myNbPoints = theNbPoints; - myPoints->SetNumberOfPoints(theNbPoints); + myPoints->SetNumberOfPoints(theCoord->GetNbPoints()); myCoord = theCoord; } - void + vtkIdType TPointCoords - ::Init(vtkIdType theNbPoints, - vtkIdType theDim) + ::GetNbPoints() const { - MED::PNodeCoord aCoord(new MED::TNodeCoord(theNbPoints * theDim)); - Init(theNbPoints, theDim, aCoord); + return myCoord->GetNbPoints(); + } + + vtkIdType + TPointCoords + ::GetDim() const + { + return myCoord->GetDim(); } TCCoordSlice TPointCoords ::GetCoordSlice(vtkIdType theNodeId) const { - return TCCoordSlice(*myCoord, std::slice(theNodeId * myDim, myDim, 1)); + return myCoord->GetCoordSlice(theNodeId); } TCoordSlice TPointCoords ::GetCoordSlice(vtkIdType theNodeId) { - return TCoordSlice(*myCoord, std::slice(theNodeId * myDim, myDim, 1)); + return myCoord->GetCoordSlice(theNodeId); } void @@ -260,7 +301,7 @@ namespace VISU ::SetVoidArray() const { vtkDataArray* aDataArray = myPoints->GetData(); - aDataArray->SetVoidArray(&(*myCoord)[0], myCoord->size(), false); + aDataArray->SetVoidArray(myCoord->GetValuePtr(), myCoord->size(), false); } vtkPoints* @@ -274,7 +315,7 @@ namespace VISU TPointCoords ::GetMemorySize() { - size_t aSize = sizeof(TCoord) * myCoord->size(); + size_t aSize = myCoord->GetMemorySize(); aSize += myPoints->GetActualMemorySize() * 1024; return aSize; } @@ -283,21 +324,10 @@ namespace VISU //--------------------------------------------------------------- void TNamedPointCoords - ::Init(vtkIdType theNbPoints, - vtkIdType theDim, - const MED::PNodeCoord& theCoord) - { - TPointCoords::Init(theNbPoints, theDim, theCoord); - myPointsDim.resize(theDim); - } - - void - TNamedPointCoords - ::Init(vtkIdType theNbPoints, - vtkIdType theDim) + ::Init(const PCoordHolder& theCoord) { - TPointCoords::Init(theNbPoints, theDim); - myPointsDim.resize(theDim); + TPointCoords::Init(theCoord); + myPointsDim.resize(theCoord->GetDim()); } std::string& @@ -321,7 +351,6 @@ namespace VISU return theID; } - vtkIdType TNamedPointCoords ::GetVTKID(vtkIdType theID) const @@ -336,6 +365,7 @@ namespace VISU return ""; } + //--------------------------------------------------------------- enum ECoordName{eX, eY, eZ, eNoneCoord}; typedef VISU::TCoord (*TGetCoord)(const VISU::TCCoordSlice& theCoordSlice); @@ -1161,7 +1191,7 @@ namespace VISU vtkIdType anId = theElemId*myStep; for(vtkIdType aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ aValueSliceArr[aGaussId] = - TCValueSlice(myValue,std::slice(anId,myNbComp,1)); + TCValueSlice(myValue,std::slice(anId, myNbComp, 1)); anId += myNbComp; } return aValueSliceArr; @@ -1175,7 +1205,7 @@ namespace VISU vtkIdType anId = theElemId*myStep; for(vtkIdType aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ aValueSliceArr[aGaussId] = - TValueSlice(myValue,std::slice(anId,myNbComp,1)); + TValueSlice(myValue, std::slice(anId, myNbComp, 1)); anId += myNbComp; } return aValueSliceArr; @@ -1189,7 +1219,7 @@ namespace VISU vtkIdType anId = theElemId*myStep; for(vtkIdType aCompId = 0; aCompId < myNbComp; aCompId++){ aValueSliceArr[aCompId] = - TCValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp)); + TCValueSlice(myValue,std::slice(anId, myNbGauss, myNbComp)); anId += 1; } return aValueSliceArr; @@ -1203,7 +1233,7 @@ namespace VISU vtkIdType anId = theElemId*myStep; for(vtkIdType aCompId = 0; aCompId < myNbComp; aCompId++){ aValueSliceArr[aCompId] = - TValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp)); + TValueSlice(myValue,std::slice(anId, myNbGauss, myNbComp)); anId += 1; } return aValueSliceArr; diff --git a/src/CONVERTOR/VISU_Convertor_impl.hxx b/src/CONVERTOR/VISU_Convertor_impl.hxx index 4e316b7e..53b1b504 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.hxx +++ b/src/CONVERTOR/VISU_Convertor_impl.hxx @@ -186,19 +186,115 @@ namespace VISU using MED::TCoordSlice; using MED::TCCoordSlice; - //! This class is responsible for representation of mesh nodes - class TPointCoords: public virtual TBaseStructure + //! This class is responsible for keeping the mesh node coordinates + class TCoordHolderBase: public virtual TBaseStructure { - protected: vtkIdType myDim; //!< Dimension of the nodal coordinates vtkIdType myNbPoints; //!< Number of nodes in corresponding mesh + public: + //! To initilize the instance + void + Init(vtkIdType theNbPoints, + vtkIdType theDim); + + vtkIdType + GetNbPoints() const; + + vtkIdType + GetDim() const; + + size_t + size() const; + + //! Gets memory size used by the instance (bytes). + virtual + unsigned long int + GetMemorySize(); + + //! Get slice of coordinates for defined node (const version) + virtual + TCCoordSlice + GetCoordSlice(vtkIdType theNodeId) const = 0; + + //! Get slice of coordinates for defined node + virtual + TCoordSlice + GetCoordSlice(vtkIdType theNodeId) = 0; + + virtual + unsigned char* + GetValuePtr() = 0; + }; + typedef SharedPtr PCoordHolder; + + + //--------------------------------------------------------------- + template + class TCoordHolder: public virtual TCoordHolderBase + { + protected: + mutable TContainerType myCoord; //!< Keeps the node coordinates container itself + + public: + //! To initilize the class + void + Init(vtkIdType theNbPoints, + vtkIdType theDim, + const TContainerType& theCoord) + { + TCoordHolderBase::Init(theNbPoints, theDim); + myCoord = theCoord; + } + + virtual + const TCoord* + GetPointer() const = 0; + + //! Get slice of coordinates for defined node (const version) + virtual + TCCoordSlice + GetCoordSlice(vtkIdType theNodeId) const + { + return TCCoordSlice(this->GetPointer(), + this->size(), + std::slice(theNodeId * this->GetDim(), this->GetDim(), 1)); + } + + virtual + TCoord* + GetPointer() = 0; + + //! Get slice of coordinates for defined node + virtual + TCoordSlice + GetCoordSlice(vtkIdType theNodeId) + { + return TCoordSlice(this->GetPointer(), + this->size(), + std::slice(theNodeId * this->GetDim(), this->GetDim(), 1)); + } + + virtual + unsigned char* + GetValuePtr() + { + return (unsigned char*)this->GetPointer(); + } + }; + + + //--------------------------------------------------------------- + //! This class is responsible for representation of mesh nodes + class TPointCoords: public virtual TBaseStructure + { + protected: //! An container for coordinates of the nodes /*! Usage of slices allow to minimize amount of memory to store the nodal coordinates and provide unifirm way of conversation with this coordinates (independant from mesh dimension) */ - MED::PNodeCoord myCoord; + PCoordHolder myCoord; //!< A pointer to the coordinates container holder TVTKPoints myPoints; //!< VTK representation for the mesh nodes void @@ -209,14 +305,13 @@ namespace VISU //! To initilize the class void - Init(vtkIdType theNbPoints, - vtkIdType theDim, - const MED::PNodeCoord& theCoord); + Init(const PCoordHolder& theCoord); - //! To initilize the class - void - Init(vtkIdType theNbPoints, - vtkIdType theDim); + vtkIdType + GetNbPoints() const; + + vtkIdType + GetDim() const; //! Get slice of coordinates for defined node (const version) TCCoordSlice @@ -226,12 +321,6 @@ namespace VISU TCoordSlice GetCoordSlice(vtkIdType theNodeId); - vtkIdType - GetNbPoints() const { return myNbPoints; } - - vtkIdType - GetDim() const { return myDim; } - virtual vtkPoints* GetPoints() const; //!< Gets corresponding VTK structure @@ -261,14 +350,7 @@ namespace VISU //! To initilize the class (numeration of the nodes can be missed) void - Init(vtkIdType theNbPoints, - vtkIdType theDim, - const MED::PNodeCoord& theCoord); - - //! To initilize the class (numeration of the nodes can be missed) - void - Init(vtkIdType theNbPoints, - vtkIdType theDim); + Init(const PCoordHolder& theCoord); //! Get name for defined dimension std::string& @@ -792,8 +874,8 @@ namespace VISU //--------------------------------------------------------------- typedef TVector TValue; - typedef TSlice TValueSlice; - typedef TCSlice TCValueSlice; + typedef TSlice TValueSlice; + typedef TCSlice TCValueSlice; typedef TVector TCValueSliceArr; typedef TVector TValueSliceArr; diff --git a/src/CONVERTOR/VISU_MedConvertor.cxx b/src/CONVERTOR/VISU_MedConvertor.cxx index 0055bdf9..d7a16ff1 100644 --- a/src/CONVERTOR/VISU_MedConvertor.cxx +++ b/src/CONVERTOR/VISU_MedConvertor.cxx @@ -999,12 +999,14 @@ namespace //--------------------------------------------------------------- void TMEDNamedPointCoords - ::Init(vtkIdType theNbPoints, - vtkIdType theDim, - const MED::PNodeInfo& theNodeInfo, + ::Init(const MED::PNodeInfo& theNodeInfo, MED::EVersion theVersion) { - TNamedPointCoords::Init(theNbPoints, theDim, theNodeInfo->myCoord); + TMEDCoordHolder* aCoordHolder = new TMEDCoordHolder(); + TInt aNbElem = theNodeInfo->GetNbElem(); + TInt aDim = theNodeInfo->GetMeshInfo()->GetDim(); + aCoordHolder->Init(aNbElem, aDim, theNodeInfo->myCoord); + TNamedPointCoords::Init(PCoordHolder(aCoordHolder)); myVersion = theVersion; myIsElemNum = theNodeInfo->IsElemNum(); @@ -1021,11 +1023,14 @@ namespace void TMEDNamedPointCoords - ::Init(vtkIdType theNbPoints, - vtkIdType theDim, - const MED::PGrilleInfo& theInfo) + ::Init(const MED::PGrilleInfo& theGrilleInfo) { - TNamedPointCoords::Init(theNbPoints, theDim); + TMEDCoordHolder* aCoordHolder = new TMEDCoordHolder(); + TInt aNbElem = theGrilleInfo->GetNbNodes(); + TInt aDim = theGrilleInfo->GetMeshInfo()->GetDim(); + MED::PNodeCoord aCoord(new MED::TNodeCoord(aNbElem * aDim)); + aCoordHolder->Init(aNbElem, aDim, aCoord); + TNamedPointCoords::Init(PCoordHolder(aCoordHolder)); } vtkIdType @@ -1880,7 +1885,7 @@ VISU_MedConvertor PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords; TMEDNamedPointCoords& aCoords = aNamedPointCoords; - aCoords.Init(aNbElem,aDim,aNodeInfo,theMed->GetVersion()); + aCoords.Init(aNodeInfo, theMed->GetVersion()); for(int iDim = 0; iDim < aDim; iDim++) aCoords.GetName(iDim) = aNodeInfo->GetCoordName(iDim); @@ -1912,7 +1917,7 @@ VISU_MedConvertor PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords; TMEDNamedPointCoords& aCoords = aNamedPointCoords; - aCoords.Init(aNbElem,aDim,aGrilleInfo); + aCoords.Init(aGrilleInfo); for(int iDim = 0; iDim < aDim; iDim++) aCoords.GetName(iDim) = aGrilleInfo->GetCoordName(iDim); @@ -2585,8 +2590,9 @@ LoadGaussMesh(const MED::PWrapper& theMed, aGaussSubMesh->myElemNum = anElemInfo->myElemNum; std::string aName; - MED::TGaussCoord aGaussCoord; bool anIsGaussCoord3D = false; + MED::PGaussCoord aGaussCoordPtr(new MED::TGaussCoord()); + MED::TGaussCoord& aGaussCoord = *aGaussCoordPtr; MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom); if(aGaussIter != aGeom2Gauss.end()){ @@ -2660,23 +2666,16 @@ LoadGaussMesh(const MED::PWrapper& theMed, if(anIsGaussCoord3D){ TPointCoords& aCoords = aGaussSubMesh->myPointCoords; - TInt aNbGauss = aGaussCoord.GetNbGauss(); - TInt aNbElem = aGaussCoord.GetNbElem(); - TInt aDim = aGaussCoord.GetDim(); - vtkIdType aNbCells = aNbElem*aNbGauss; - aCoords.Init(aNbCells,aDim); - for(TInt anElemId = 0, aNodeId = 0; anElemId < aNbElem; anElemId++){ - MED::TCoordSliceArr aCoordSliceArr = aGaussCoord.GetCoordSliceArr(anElemId); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++, aNodeId++){ - MED::TCoordSlice aCoordSlice = aCoordSliceArr[aGaussId]; - TCoordSlice aSlice = aCoords.GetCoordSlice(aNodeId); - for(TInt aDimId = 0; aDimId < aDim; aDimId++) - aSlice[aDimId] = aCoordSlice[aDimId]; - } - } + TMEDGaussCoordHolder* aCoordHolder = new TMEDGaussCoordHolder(); + aCoordHolder->Init(aGaussCoordPtr); + aCoords.Init(PCoordHolder(aCoordHolder)); - aGaussSubMesh->myIsDone = true;; + aGaussSubMesh->myIsDone = true; + TInt aNbGauss = aGaussCoord.GetNbGauss(); + TInt aNbElem = aGaussCoord.GetNbElem(); + TInt aNbCells = aNbElem*aNbGauss; + INITMSG(MYDEBUG, "- aEGeom = "< #include namespace VISU { + //--------------------------------------------------------------- + struct TMEDCoordHolder: TCoordHolder + { + virtual + const TCoord* + GetPointer() const + { + return &(*myCoord)[0]; + } + + virtual + TCoord* + GetPointer() + { + return &(*myCoord)[0]; + } + }; + + + //--------------------------------------------------------------- + struct TMEDGaussCoordHolder: TCoordHolderBase + { + MED::PGaussCoord myGaussCoord; + + //! To initilize the instance + void + Init(const MED::PGaussCoord& theGaussCoord) + { + MED::TInt aNbGauss = theGaussCoord->GetNbGauss(); + MED::TInt aNbElem = theGaussCoord->GetNbElem(); + MED::TInt aDim = theGaussCoord->GetDim(); + MED::TInt aNbCells = aNbElem * aNbGauss; + TCoordHolderBase::Init(aNbCells, aDim); + myGaussCoord = theGaussCoord; + } + + //! Get slice of coordinates for defined node (const version) + virtual + TCCoordSlice + GetCoordSlice(vtkIdType theNodeId) const + { + MED::TInt anElemId = theNodeId / myGaussCoord->GetNbGauss(); + MED::TCCoordSliceArr aCoordSliceArr = myGaussCoord->GetCoordSliceArr(anElemId); + MED::TInt aGaussId = theNodeId % myGaussCoord->GetNbGauss(); + return aCoordSliceArr[aGaussId]; + } + + //! Get slice of coordinates for defined node + virtual + TCoordSlice + GetCoordSlice(vtkIdType theNodeId) + { + MED::TInt anElemId = theNodeId / myGaussCoord->GetNbGauss(); + MED::TCoordSliceArr aCoordSliceArr = myGaussCoord->GetCoordSliceArr(anElemId); + MED::TInt aGaussId = theNodeId % myGaussCoord->GetNbGauss(); + return aCoordSliceArr[aGaussId]; + } + + virtual + unsigned char* + GetValuePtr() + { + return myGaussCoord->GetValuePtr(); + } + }; + + //--------------------------------------------------------------- typedef std::map TObj2VTKID; @@ -49,15 +117,11 @@ namespace VISU {} void - Init(vtkIdType theNbPoints, - vtkIdType theDim, - const MED::PNodeInfo& theNodeInfo, + Init(const MED::PNodeInfo& theNodeInfo, MED::EVersion theVersion); void - Init(vtkIdType theNbPoints, - vtkIdType theDim, - const MED::PGrilleInfo& theGrilleInfo); + Init(const MED::PGrilleInfo& theGrilleInfo); //! Get object number for node by its VTK one virtual diff --git a/src/VISU_I/VISU_CorbaMedConvertor.cxx b/src/VISU_I/VISU_CorbaMedConvertor.cxx index 26b5074b..d8af01b4 100644 --- a/src/VISU_I/VISU_CorbaMedConvertor.cxx +++ b/src/VISU_I/VISU_CorbaMedConvertor.cxx @@ -348,9 +348,6 @@ VISU_MEDFieldConvertor::Build() aMesh->myName = aMeshName.in(); aMesh->myMesh = aMEDMesh; - TNamedPointCoords& aCoords = aMesh->myNamedPointCoords; - aCoords.Init(aMesh->myNbPoints,aMesh->myDim); - if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<> There is no points in the mesh !!!"); SALOME_MED::double_array_var aCCoord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE); - for(int iElem = 0, anId = 0; iElem < aNbElem; iElem++){ - VISU::TCoordSlice aCoordSlice = aCoords.GetCoordSlice(iElem); - for(int iDim = 0; iDim < aDim; iDim++) - aCoordSlice[iDim] = aCCoord[anId++]; - } + TCMEDCoordHolder* aCoordHolder = new TCMEDCoordHolder(); + aCoordHolder->Init(aNbElem, aDim, aCCoord); + + TNamedPointCoords& aCoords = theMesh->myNamedPointCoords; + aCoords.Init(PCoordHolder(aCoordHolder)); if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY"); @@ -1034,9 +1024,7 @@ VISU_MEDConvertor if(theFamily->myIsDone) return 0; - TNamedPointCoords& aCoords = theMesh->myNamedPointCoords; - int aNbElem = aCoords.GetNbPoints(); - + vtkIdType aNbElem = theMesh->GetNbPoints(); SALOME_MED::FAMILY_var aMedFamily = theFamily->myFamily; CORBA::Boolean anIsOnAllElements = aMedFamily->isOnAllElements(); TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1]; @@ -1084,9 +1072,8 @@ VISU_MEDConvertor const TEntity& aVEntity = theMeshOnEntity->myEntity; int iGeomEnd = GetEntity2Geom(aVEntity,aGeomElems); const SALOME_MED::medEntityMesh& aMEntity = VTKEntityToMED(aVEntity); - const TNamedPointCoords& aCoords = theMesh->myNamedPointCoords; TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh; - int aNbPoints = aCoords.GetNbPoints(); + vtkIdType aNbPoints = theMesh->GetNbPoints(); for(int iGeom = 0, aCounter = 0; iGeom < iGeomEnd; iGeom++){ SALOME_MED::medGeometryElement aMGeom = aGeomElems[iGeom]; @@ -1271,8 +1258,7 @@ ImportField(TArray& theArray, if(theField->myEntity == NODE_ENTITY){ VISU::EGeometry aEGeom = VISU::ePOINT1; int aNbGauss = theValForTime->GetNbGauss(aEGeom); - const TNamedPointCoords& aCoords = theMesh->myNamedPointCoords; - int aNbElem = aCoords.GetNbPoints(); + vtkIdType aNbElem = theMesh->GetNbPoints(); if(MYDEBUG) MESSAGE("ImportField - aNbElem = "< + { + virtual + const TCoord* + GetPointer() const + { + return &myCoord[0]; + } + + virtual + TCoord* + GetPointer() + { + return &myCoord[0]; + } + }; + + //--------------------------------------------------------------- struct TCMesh: virtual TMeshImpl { @@ -100,7 +119,9 @@ namespace VISU } -class VISU_MEDConvertor: public VISU_Convertor_impl{ +//--------------------------------------------------------------- +class VISU_MEDConvertor: public VISU_Convertor_impl +{ protected: SALOMEDS::SObject_var mySObject; VISU_MEDConvertor() {}; @@ -179,6 +200,8 @@ class VISU_MEDConvertor: public VISU_Convertor_impl{ }; + +//--------------------------------------------------------------- class VISU_MEDFieldConvertor: public VISU_MEDConvertor { protected: -- 2.39.2