From 410d864cab96ed14915b68500041cecbda972dcc Mon Sep 17 00:00:00 2001 From: apo Date: Tue, 20 Sep 2005 13:06:42 +0000 Subject: [PATCH] To introduce mapping of mesh elements --- src/CONVERTOR/VISU_Convertor.hxx | 14 +---- src/CONVERTOR/VISU_Convertor_impl.cxx | 71 ++++++++++++++++++---- src/CONVERTOR/VISU_Convertor_impl.hxx | 69 ++++++++++++--------- src/CONVERTOR/VISU_IDMapper.hxx | 34 +++++++++++ src/CONVERTOR/VISU_MedConvertor.cxx | 79 +++++++++++++++++++----- src/CONVERTOR/VISU_MedConvertor.hxx | 27 +++++++++ src/OBJECT/VISU_GaussPtsAct.cxx | 86 +++++++++++---------------- 7 files changed, 264 insertions(+), 116 deletions(-) diff --git a/src/CONVERTOR/VISU_Convertor.hxx b/src/CONVERTOR/VISU_Convertor.hxx index 2cb3673c..7fa63b58 100644 --- a/src/CONVERTOR/VISU_Convertor.hxx +++ b/src/CONVERTOR/VISU_Convertor.hxx @@ -105,16 +105,8 @@ namespace VISU //--------------------------------------------------------------- - typedef vtkIdType TCellID; - typedef vtkIdType TLocalPntID; - typedef std::pair TGaussPointID; - - struct TGaussMesh: virtual TIDMapper - { - virtual - TGaussPointID - GetObjID(int theVtkI) const = 0; - }; + struct TGaussMesh: virtual TGaussPtsIDMapper + {}; //--------------------------------------------------------------- @@ -130,7 +122,7 @@ namespace VISU typedef std::map TFamilyMap; typedef std::map TFieldMap; - struct TMeshOnEntity: virtual TIDMapper + struct TMeshOnEntity: virtual TNamedIDMapper { TGaussMeshMap myGaussMeshMap; TProfileMap myProfileMap; diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index ee2075a5..b960be24 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -58,7 +58,7 @@ static int MYVTKDEBUG = 0; #ifdef _DEBUG_ static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; +static int MYDEBUGWITHFILES = 1; //#define _DEXCEPT_ #else static int MYDEBUG = 0; @@ -124,6 +124,7 @@ namespace VISU TAppendFilter ::GetVTKOutput() { + GetFilter()->Update(); return GetFilter()->GetOutput(); } @@ -216,9 +217,15 @@ namespace VISU return -1; } + std::string + TNamedPointCoords + ::GetNodeName(vtkIdType theObjID) const + { + return ""; + } + //--------------------------------------------------------------- TMeshImpl::TMeshImpl(): - myNamedPointCoords(new TNamedPointCoords()), myPoints(vtkPoints::New()), myNbPoints(0) { @@ -328,6 +335,12 @@ namespace VISU return GetFilter()->GetOutput()->GetCell(aVtkID); } + TVTKOutput* + TProfileImpl + ::GetVTKOutput() + { + return mySource.GetVTKOutput(); + } //--------------------------------------------------------------- TGaussSubMeshImpl::TGaussSubMeshImpl(): @@ -364,10 +377,9 @@ namespace VISU //--------------------------------------------------------------- TGaussMeshImpl - ::TGaussMeshImpl() - { - myParentMesh=0; - } + ::TGaussMeshImpl(): + myParent(NULL) + {} TGaussPointID TGaussMeshImpl @@ -380,13 +392,18 @@ namespace VISU return aSubMeshImpl.GetObjID(anInputID); } - void TGaussMeshImpl::SetParentMesh(VISU::TMeshOnEntityImpl* theMesh) + TVTKOutput* + TGaussMeshImpl + ::GetVTKOutput() { - myParentMesh=theMesh; + return mySource.GetVTKOutput(); } - VISU::TMeshOnEntityImpl* TGaussMeshImpl::GetParentMesh() + + TNamedIDMapper* + TGaussMeshImpl:: + GetParent() { - return myParentMesh; + return myParent; } //--------------------------------------------------------------- @@ -397,6 +414,12 @@ namespace VISU return myStartID + theID; } + std::string + TSubMeshImpl + ::GetElemName(vtkIdType theObjID) const + { + return ""; + } //--------------------------------------------------------------- vtkIdType @@ -438,6 +461,23 @@ namespace VISU return aSubMesh->GetElemObjID(aID); } + std::string + TMeshOnEntityImpl + ::GetNodeName(vtkIdType theObjID) const + { + return myNamedPointCoords->GetNodeName(theObjID); + } + + std::string + TMeshOnEntityImpl + ::GetElemName(vtkIdType theObjID) const + { + vtkIdType anInputID; + const TVTKAppendFilter& anAppendFilter = GetFilter(); + vtkIdType aID = anAppendFilter->GetCellInputID(theObjID,anInputID); + const PSubMeshImpl& aSubMesh = mySubMeshArr[anInputID]; + return aSubMesh->GetElemName(aID); + } //--------------------------------------------------------------- vtkIdType @@ -475,6 +515,13 @@ namespace VISU return myNamedPointCoords->GetVTKID(theID); } + TVTKOutput* + TFamilyImpl + ::GetVTKOutput() + { + return TSource::GetVTKOutput(); + } + //--------------------------------------------------------------- TNbASizeCells @@ -1458,7 +1505,9 @@ namespace anAppendFilter->AddInput(aSource.GetPointer()); } anAppendFilter->Update(); // Fix on VTK - theGaussMesh->SetParentMesh(theMeshOnEntity.get()); + + theGaussMesh->myParent = theMeshOnEntity.get(); + vtkDataSet* aSource = anAppendFilter->GetOutput(); INITMSGA(MYDEBUG,0,"aNbPoints - "<GetNumberOfPoints()<GetNumberOfCells()< PNamedPointCoords; //--------------------------------------------------------------- - struct TMeshImpl: virtual TMesh, virtual TIsVTKDone + struct TMeshImpl: virtual TMesh, + virtual TIsVTKDone { PNamedPointCoords myNamedPointCoords; @@ -178,7 +183,8 @@ namespace VISU typedef TVector TSubMeshID; typedef enum {eRemoveAll, eAddAll, eAddPart, eNone} ESubMeshStatus; - struct TSubProfileImpl: virtual TSubProfile, virtual TSource + struct TSubProfileImpl: virtual TSubProfile, + virtual TSource { TSubProfileImpl(); @@ -202,7 +208,8 @@ namespace VISU typedef TVector TSubProfileArr; typedef std::map TGeom2SubProfile; - struct TProfileImpl: virtual TProfile, virtual TAppendFilter + struct TProfileImpl: virtual TProfile, + virtual TAppendFilter { TProfileImpl(); bool myIsAll; @@ -233,10 +240,7 @@ namespace VISU virtual TVTKOutput* - GetVTKOutput() - { - return mySource.GetVTKOutput(); - } + GetVTKOutput(); TID2ID myElemObj2VTKID; TSubProfileArr mySubProfileArr; @@ -260,7 +264,8 @@ namespace VISU //--------------------------------------------------------------- - struct TGaussSubMeshImpl: virtual TGaussSubMesh, virtual TSource + struct TGaussSubMeshImpl: virtual TGaussSubMesh, + virtual TSource { TGaussSubMeshImpl(); @@ -279,30 +284,27 @@ namespace VISU typedef TVector TGaussSubMeshArr; typedef std::map TGeom2GaussSubMesh; - struct TGaussMeshImpl: virtual TGaussMesh, virtual TAppendFilter + struct TGaussMeshImpl: virtual TGaussMesh, + virtual TAppendFilter { TGaussMeshImpl(); virtual TGaussPointID - GetObjID(int theVtkI) const; + GetObjID(vtkIdType theID) const; virtual TVTKOutput* - GetVTKOutput() - { - return mySource.GetVTKOutput(); - } - - void SetParentMesh(VISU::TMeshOnEntityImpl* theMesh); - - VISU::TMeshOnEntityImpl* GetParentMesh(); + GetVTKOutput(); - TGaussSubMeshArr myGaussSubMeshArr; + virtual + TNamedIDMapper* + GetParent(); TSource mySource; + TNamedIDMapper* myParent; + TGaussSubMeshArr myGaussSubMeshArr; TGeom2GaussSubMesh myGeom2GaussSubMesh; - TMeshOnEntityImpl* myParentMesh; }; typedef SharedPtr PGaussMeshImpl; @@ -317,6 +319,10 @@ namespace VISU vtkIdType GetElemObjID(vtkIdType theID) const; + virtual + std::string + GetElemName(vtkIdType theObjID) const; + vtkIdType myStartID; TCell2Connect myCell2Connect; }; @@ -327,7 +333,9 @@ namespace VISU typedef std::map TGeom2SubMesh; typedef TVector TSubMeshArr; - struct TMeshOnEntityImpl: virtual TMeshOnEntity, virtual TAppendFilter, virtual TSizeCounter + struct TMeshOnEntityImpl: virtual TMeshOnEntity, + virtual TAppendFilter, + virtual TSizeCounter { virtual vtkIdType @@ -345,6 +353,14 @@ namespace VISU vtkIdType GetElemObjID(vtkIdType theID) const; + virtual + std::string + GetNodeName(vtkIdType theObjID) const; + + virtual + std::string + GetElemName(vtkIdType theObjID) const; + TID2ID myElemObj2VTKID; TSubMeshArr mySubMeshArr; PNamedPointCoords myNamedPointCoords; @@ -357,7 +373,8 @@ namespace VISU //--------------------------------------------------------------- typedef std::map TGeom2SubMeshID; - struct TFamilyImpl: virtual TFamily, virtual TSource + struct TFamilyImpl: virtual TFamily, + virtual TSource { vtkIdType GetNodeObjID(vtkIdType theID) const ; @@ -376,10 +393,7 @@ namespace VISU virtual TVTKOutput* - GetVTKOutput() - { - return TSource::GetVTKOutput(); - } + GetVTKOutput(); PNamedPointCoords myNamedPointCoords; TID2ID myElemObj2VTKID; @@ -394,7 +408,8 @@ namespace VISU typedef std::pair TNbASizeCells; typedef TVector TFamilyArr; - struct TGroupImpl: virtual TGroup, virtual TAppendFilter + struct TGroupImpl: virtual TGroup, + virtual TAppendFilter { TNbASizeCells GetNbASizeCells() const; diff --git a/src/CONVERTOR/VISU_IDMapper.hxx b/src/CONVERTOR/VISU_IDMapper.hxx index 6b1e5a50..8bfdd23f 100644 --- a/src/CONVERTOR/VISU_IDMapper.hxx +++ b/src/CONVERTOR/VISU_IDMapper.hxx @@ -30,6 +30,7 @@ #include "MED_SharedPtr.hxx" #include +#include class vtkUnstructuredGrid; class vtkCell; @@ -81,6 +82,39 @@ namespace VISU }; typedef SharedPtr PIDMapper; + + //--------------------------------------------------------------- + struct TNamedIDMapper: virtual TIDMapper + { + virtual + std::string + GetNodeName(vtkIdType theObjID) const = 0; + + virtual + std::string + GetElemName(vtkIdType theObjID) const = 0; + }; + typedef SharedPtr PNamedIDMapper; + + + //--------------------------------------------------------------- + typedef vtkIdType TCellID; + typedef vtkIdType TLocalPntID; + typedef std::pair TGaussPointID; + + struct TGaussPtsIDMapper: virtual TIDMapper + { + virtual + TGaussPointID + GetObjID(vtkIdType theID) const = 0; + + virtual + TNamedIDMapper* + GetParent() = 0; + }; + typedef SharedPtr PGaussPtsIDMapper; + + //--------------------------------------------------------------- } #endif diff --git a/src/CONVERTOR/VISU_MedConvertor.cxx b/src/CONVERTOR/VISU_MedConvertor.cxx index 133e200b..92d07362 100644 --- a/src/CONVERTOR/VISU_MedConvertor.cxx +++ b/src/CONVERTOR/VISU_MedConvertor.cxx @@ -919,6 +919,35 @@ namespace } + //--------------------------------------------------------------- + void + TMEDNamedPointCoords + ::Init(vtkIdType theNbPoints, + vtkIdType theDim, + const MED::PNodeInfo& theNodeInfo) + { + if(theNodeInfo->IsElemNum()) + TNamedPointCoords::Init(theNbPoints,theDim,theNodeInfo->myElemNum); + else + TNamedPointCoords::Init(theNbPoints,theDim); + + if(theNodeInfo->IsElemNames() && theNbPoints > 0){ + myPointNames.resize(theNbPoints); + for(vtkIdType anID = 0; anID < theNbPoints; anID++) + myPointNames[anID] = theNodeInfo->GetElemName(anID); + } + } + + std::string + TMEDNamedPointCoords + ::GetNodeName(vtkIdType theObjID) const + { + if(myPointNames.empty()) + return TNamedPointCoords::GetNodeName(theObjID); + return myPointNames[theObjID]; + } + + //--------------------------------------------------------------- vtkIdType TMEDSubProfile @@ -948,6 +977,21 @@ namespace //--------------------------------------------------------------- + void + TMEDSubMesh + ::Init(const MED::PElemInfo& theElemInfo) + { + myIsElemNum = theElemInfo->IsElemNum(); + myElemNum = theElemInfo->myElemNum; + if(theElemInfo->IsElemNames()){ + TInt aNbElem = theElemInfo->GetNbElem(); + myElemNames.resize(aNbElem); + for(TInt anID = 0; anID < aNbElem; anID++){ + myElemNames[anID] = theElemInfo->GetElemName(anID); + } + } + } + vtkIdType TMEDSubMesh ::GetElemObjID(vtkIdType theID) const @@ -957,6 +1001,16 @@ namespace else return TSubMeshImpl::GetElemObjID(theID); } + + std::string + TMEDSubMesh + ::GetElemName(vtkIdType theObjID) const + { + if(myElemNames.empty()) + return TSubMeshImpl::GetElemName(theObjID); + else + return myElemNames[theObjID]; + } } @@ -1015,7 +1069,8 @@ VISU_MedConvertor aMesh->myNbPoints = aNodeInfo->GetNbElem(); aMesh->myMeshInfo = aMeshInfo; aMesh->myEntityInfo = aEntityInfo; - + aMesh->myNamedPointCoords(new TMEDNamedPointCoords()); + INITMSG(MYDEBUG,"aMeshName = '"<GetNbElem(); TInt aDim = theMesh->myDim; - TNamedPointCoords& aCoords = theMesh->myNamedPointCoords; - if(EBooleen anIsNodeNum = aNodeInfo->IsElemNum()) - aCoords.Init(aNbElem,aDim,aNodeInfo->myElemNum); - else - aCoords.Init(aNbElem,aDim); + PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords; + TMEDNamedPointCoords& aCoords = aNamedPointCoords; + aCoords.Init(aNbElem,aDim,aNodeInfo); for(int iDim = 0; iDim < aDim; iDim++) aCoords.GetName(iDim) = aNodeInfo->GetCoordName(iDim); @@ -1220,9 +1273,8 @@ VISU_MedConvertor TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh; PMEDSubMesh aSubMesh = aGeom2SubMesh[VTK_VERTEX](new TMEDSubMesh()); - - aSubMesh->myIsElemNum = aNodeInfo->IsElemNum(); - aSubMesh->myElemNum = aNodeInfo->myElemNum; + + aSubMesh->Init(aNodeInfo); aSubMesh->myNbCells = theMesh->myNbPoints; aSubMesh->myCellsSize = 2*theMesh->myNbPoints; @@ -1341,8 +1393,7 @@ VISU_MedConvertor if(aNbElem > 0){ PMEDSubMesh aSubMesh = aGeom2SubMesh[aVGeom](new TMEDSubMesh()); - aSubMesh->myIsElemNum = aPolygoneInfo->IsElemNum(); - aSubMesh->myElemNum = aPolygoneInfo->myElemNum; + aSubMesh->Init(aPolygoneInfo); aSubMesh->myNbCells = aNbElem; TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect; @@ -1367,8 +1418,7 @@ VISU_MedConvertor if(aNbElem > 0){ PMEDSubMesh aSubMesh = aGeom2SubMesh[aVGeom](new TMEDSubMesh()); - aSubMesh->myIsElemNum = aPolyedreInfo->IsElemNum(); - aSubMesh->myElemNum = aPolyedreInfo->myElemNum; + aSubMesh->Init(aPolyedreInfo); aSubMesh->myNbCells = aNbElem; TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect; @@ -1410,8 +1460,7 @@ VISU_MedConvertor if(aNbElem > 0){ PMEDSubMesh aSubMesh = aGeom2SubMesh[aVGeom](new TMEDSubMesh()); - aSubMesh->myIsElemNum = aCellInfo->IsElemNum(); - aSubMesh->myElemNum = aCellInfo->myElemNum; + aSubMesh->Init(aCellInfo); aSubMesh->myNbCells = aNbElem; aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1); diff --git a/src/CONVERTOR/VISU_MedConvertor.hxx b/src/CONVERTOR/VISU_MedConvertor.hxx index 0307427d..ee063780 100644 --- a/src/CONVERTOR/VISU_MedConvertor.hxx +++ b/src/CONVERTOR/VISU_MedConvertor.hxx @@ -19,6 +19,25 @@ namespace VISU { + typedef TVector TNames; + + //--------------------------------------------------------------- + class TMEDNamedPointCoords: public virtual TNamedPointCoords + { + TNames myPointNames; + public: + void + Init(vtkIdType theNbPoints, + vtkIdType theDim, + const MED::PNodeInfo& theNodeInfo); + + virtual + std::string + GetNodeName(vtkIdType theObjID) const; + }; + typedef SharedPtr PMEDNamedPointCoords; + + //--------------------------------------------------------------- struct TMEDMesh: virtual TMeshImpl { @@ -93,10 +112,18 @@ namespace VISU MED::EBooleen myIsElemNum; MED::TElemNum myElemNum; + TNames myElemNames; + + void + Init(const MED::PElemInfo& theElemInfo); virtual vtkIdType GetElemObjID(vtkIdType theID) const; + + virtual + std::string + GetElemName(vtkIdType theObjID) const; }; typedef SharedPtr PMEDSubMesh; diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index be0d5a90..8489cc3b 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -62,7 +62,6 @@ #include #include -#include "VISU_Convertor_impl.hxx" // /////////////////////////////////////////////////////////////////////////// // @@ -286,24 +285,24 @@ VISU_GaussPtsAct mySphereActorSelected->GetProperty()->SetColor(aColorSelected); // // Cell - myCellSource=vtkUnstructuredGrid::New(); + myCellSource = vtkUnstructuredGrid::New(); myCellSource->Allocate(); - myCellMapper=vtkDataSetMapper::New(); - myCellActor=vtkActor::New(); - // myCellSource->Delete(); + // + myCellMapper = vtkDataSetMapper::New(); myCellMapper->Delete(); + // + myCellActor = vtkActor::New(); myCellActor->Delete(); // myCellMapper->SetInput(myCellSource.GetPointer()); myCellActor->SetMapper(myCellMapper.GetPointer()); myCellActor->SetVisibility(0); myCellActor->SetPickable(0); - - float aColorCell[3]={.9,.9,.9}; - vtkProperty* pPropertyCell=myCellActor->GetProperty(); - pPropertyCell->SetColor(aColorCell); - pPropertyCell->SetRepresentationToWireframe(); + // + myCellActor->GetProperty()->SetAmbient(1.0); + myCellActor->GetProperty()->SetDiffuse(0.0); + myCellActor->GetProperty()->SetRepresentationToWireframe(); } VISU_GaussPtsAct @@ -374,7 +373,8 @@ VISU_GaussPtsAct { myTextActor->SetVisibility(false); mySphereActor->SetVisibility(false); - myCursorPyramid->SetVisibility(0); + myCursorPyramid->SetVisibility(false); + myCellActor->SetVisibility(false); if(theSelectionEvent->mySelectionMode == ActorSelection || !theIsHighlight) return Superclass::PreHighlight(theSelector,theInteractorStyle,theSelectionEvent,theIsHighlight); @@ -414,10 +414,14 @@ VISU_GaussPtsAct std::ostringstream aStr; aStr<<"Global ID: "<GetGaussMesh(); + VISU::TNamedIDMapper* aParent = aGaussMesh->GetParent(); + VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId); VISU::TCellID aCellID = aGaussPointID.first; VISU::TLocalPntID aLocalPntID = aGaussPointID.second; aStr<<"\nParentCellID: "<GetElemName(aCellID)<<"'"; aStr<<"\nLocalPntID: "<GetVisibility(); int aSphereVisibility = mySphereActor->GetVisibility(); @@ -569,45 +575,21 @@ bool VISU_GaussPtsAct::Highlight(SVTK_Selector* theSelector, // if(aSelectionMode == CellSelection){ // Hilighting an element from the parent Mesh - int k, aNbPoints, aIDs[20]; - float *pX; - vtkIdType aCellID; - vtkCell* pCell; - vtkPoints *pPoints; - VISU::TMeshOnEntityImpl* pMeshOnEntityImpl; - // - const VISU::PGaussMesh& aGaussMesh=myGaussPointsPL->GetGaussMesh(); - VISU::TGaussMeshImpl* pGaussMeshImpl= - dynamic_cast(aGaussMesh.get()); - // - VISU::TGaussPointID anGPID= aGaussMesh->GetObjID(anObjId); - aCellID=anGPID.first; - - pMeshOnEntityImpl=pGaussMeshImpl->GetParentMesh(); - pCell=pMeshOnEntityImpl->GetElemCell(aCellID); - // - pPoints=pCell->GetPoints(); - // - aNbPoints=pCell->GetNumberOfPoints(); - for (k=0; kGetPoint(k); - aIDs[k]=k; - } - myCellSource->Initialize(); - myCellSource->Allocate(); - myCellSource->SetPoints(pCell->GetPoints()); - myCellSource->InsertNextCell(pCell->GetCellType(), aNbPoints, aIDs); - // - vtkProperty* pPropertyCell=myCellActor->GetProperty(); - pPropertyCell->SetAmbient(1.0); - pPropertyCell->SetDiffuse(0.0); - pPropertyCell->SetRepresentationToWireframe(); - if (theSelector->HasIndex(myIO)) { + if(theSelector->HasIndex(myIO)){ + const VISU::PGaussMesh& aGaussMesh = myGaussPointsPL->GetGaussMesh(); + VISU::TNamedIDMapper* aParent = aGaussMesh->GetParent(); + + myCellSource->Reset(); + myCellSource->Modified(); // a VTK bug + myCellSource->SetPoints(aParent->GetVTKOutput()->GetPoints()); + + VISU::TGaussPointID aGaussPointID = aGaussMesh->GetObjID(anObjId); + vtkIdType aCellID = aGaussPointID.first; + vtkCell* aCell = aParent->GetElemCell(aCellID); + myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); + myCellActor->SetVisibility(1); } - else { - myCellActor->SetVisibility(0); - } } return bRet; -- 2.39.2