#include "VISU_Convertor.hxx"
#include "VISU_ConvertorUtils.hxx"
-#include <vtkUnstructuredGridWriter.h>
+#include <qstring.h>
using namespace std;
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
+namespace VISU{
-extern "C" {
- VISU_Convertor* CreateConvertor(const string& theFileName) throw(std::runtime_error&){
- if(QFileInfo(theFileName.c_str()).extension(false) == "med")
- return CreateMedConvertor(theFileName);
- else
- return CreateDatConvertor(theFileName);
+ 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;
+ }
}
-}
-
-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);
pair<int,int> TMeshOnEntity::GetCellsDims(const string& theFamilyName) const
- throw(std::runtime_error&)
{
- bool isFamilyPresent = (theFamilyName != "");
- int aNbCells = 0, aCellsSize = 0;
- if(!isFamilyPresent){
- TCellsConn::const_iterator aCellsConnIter = myCellsConn.begin();
- for(; aCellsConnIter != myCellsConn.end(); aCellsConnIter++){
- const TConnForCellType& aConnForCellType = aCellsConnIter->second;
- if(!aConnForCellType.empty()){
- aNbCells += aConnForCellType.size();
- aCellsSize += aConnForCellType.size()*(aConnForCellType[0].size()+1);
- }
- }
- }else{
- TFamilyMap::const_iterator aFamilyMapIter = myFamilyMap.find(theFamilyName);
- if(aFamilyMapIter == myFamilyMap.end())
- throw std::runtime_error("GetCellsDims >> There is no family on the mesh with entity !!!");
- const TFamily& aFamily = aFamilyMapIter->second;
- const TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
- TFamily::TSubMesh::const_iterator aSubMeshIter = aSubMesh.begin();
- for(; aSubMeshIter != aSubMesh.end(); aSubMeshIter++){
- const TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aSubMeshIter->second;
- if(!aSubMeshOnCellType.empty()){
- int tmp = aSubMeshOnCellType.size();
- aNbCells += tmp;
- int aVtkType = aSubMeshIter->first;
- int aVtkSize = aVtkCellInfoMap[aVtkType].mySize;
- aCellsSize += tmp*(aVtkSize+1);
- }
- }
- }
- return make_pair(aNbCells,aCellsSize);
+ if(theFamilyName == "")
+ return make_pair(myNbCells,myCellsSize);
+ TFamilyMap::const_iterator aFamilyMapIter = myFamilyMap.find(theFamilyName);
+ if(aFamilyMapIter == myFamilyMap.end())
+ throw std::runtime_error("GetCellsDims >> There is no family on the mesh with entity !!!");
+ const PFamily& aFamily = aFamilyMapIter->second;
+ return make_pair(aFamily->myNbCells,aFamily->myCellsSize);
}
- const TField* TMesh::GetField(const string& theFieldName) const {
+ const PField TMesh::GetField(const string& theFieldName) const {
TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = myMeshOnEntityMap.begin();
for(; aMeshOnEntityMapIter != myMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const TFieldMap& aFieldMap = (aMeshOnEntityMapIter->second).myFieldMap;
+ const TFieldMap& aFieldMap = aMeshOnEntityMapIter->second->myFieldMap;
TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++)
- if(theFieldName == aFieldMapIter->first) return &(aFieldMapIter->second);
+ if(theFieldName == aFieldMapIter->first)
+ return aFieldMapIter->second;
}
- return NULL;
+ return PField();
}
- const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
- throw(std::runtime_error&)
+
+ PFamily FindFamily(VISU::PMesh theMesh, const string& theFamilyName)
{
- if(theFamilyName == "") return NULL;
- const VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
- VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
- 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;
+ PFamily aFamily;
+ const TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
+ TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
+ for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
+ const PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
+ aFamily = GetFamily(aMeshOnEntity,theFamilyName);
+ if(aFamily)
+ break;
+ }
+ return aFamily;
}
- TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
- throw(std::runtime_error&)
+
+ PFamily GetFamily(VISU::PMeshOnEntity theMeshOnEntity, const string& theFamilyName)
{
- if(theFamilyName == "") return NULL;
- VISU::TFamilyMap& aFamilyMap = theMeshOnEntity.myFamilyMap;
- VISU::TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
- if(aFamilyMapIter == aFamilyMap.end())
- throw std::runtime_error("GetFamily >> There is no family on the mesh with entity !!!");
- VISU::TFamily& aFamily = aFamilyMapIter->second;
- return &aFamily;
- }
-
- void TField::ShallowCopy(const TField& aField){
- myEntity = aField.myEntity;
- myMeshName = aField.myMeshName;
- myNbComp = aField.myNbComp;
- VISU::TField::TValField::const_iterator iter = aField.myValField.begin();
- for(; iter != aField.myValField.end(); iter++)
- myValField[iter->first];
+ PFamily aFamily;
+ if(theFamilyName != ""){
+ TFamilyMap& aFamilyMap = theMeshOnEntity->myFamilyMap;
+ TFamilyMap::iterator aFamilyMapIter = aFamilyMap.find(theFamilyName);
+ if(aFamilyMapIter != aFamilyMap.end())
+ aFamily = aFamilyMapIter->second;
+ }
+ return aFamily;
}
}
-const VISU::TMeshMap& VISU_Convertor::GetMeshMap() throw(std::runtime_error&){
+const VISU::TMeshMap& VISU_Convertor::GetMeshMap() {
if(!myIsDone) { myIsDone = true; Build();}
return myMeshMap;
}
-string VISU_Convertor::GenerateName(const VISU::TField::TTime& aTime){
+string VISU_Convertor::GenerateName(const VISU::TTime& aTime){
static QString aName;
const string aUnits = aTime.second, tmp(aUnits.size(),' ');
if(aUnits == "" || aUnits == tmp)