// Module : VISU
#include "VISU_Convertor_impl.hxx"
+#include "VISU_ConvertorUtils.hxx"
#include <vtkIdList.h>
#include <vtkCellType.h>
#include <vtkUnsignedCharArray.h>
#include <vtkPointData.h>
#include <vtkCellData.h>
+#include <vtkCellLinks.h>
+
+#include <vtkMergeDataObjectFilter.h>
+
+#include <vtkUnstructuredGridWriter.h>
#include <qstring.h>
#include <qfileinfo.h>
using namespace std;
+static float ERR_SIZE_CALC = 1.00;
+
+static int MYVTKDEBUG = 0;
+
#ifdef _DEBUG_
static int MYDEBUG = 0;
static int MYDEBUGWITHFILES = 0;
static int MYDEBUGWITHFILES = 0;
#endif
+void VISU::WriteToFile(vtkUnstructuredGrid* theDataSet, const string& theFileName){
+ //vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
+ //if(MYVTKDEBUG) aWriter->DebugOn();
+ ////aWriter->SetFileType(VTK_BINARY);
+ //aWriter->SetFileName(theFileName.c_str());
+ //aWriter->SetInput(theDataSet);
+ //aWriter->Write();
+ //aWriter->Delete();
+}
+
+namespace{
+ void GetPoints(VISU::TVTKSource& theStorage, VISU::TMesh& theMesh)
+ throw (std::runtime_error&)
+ {
+ vtkPoints* aPoints = theMesh.myPoints.GetPointer();
+ if(!aPoints){
+ aPoints = vtkPoints::New();
+ if(MYVTKDEBUG) aPoints->DebugOn();
+ 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 = "<<aNbPoints<<"; myDim = "<<theMesh.myDim);
+ switch(theMesh.myDim) {
+ case 1:
+ for (vtkIdType i = 0, j = 0; i < iEnd; i += theMesh.myDim, j++)
+ aPoints->SetPoint(j,anArray[i],0.0,0.0);
+ break;
+ case 2:
+ for (vtkIdType i = 0, j = 0; i < iEnd; i += theMesh.myDim, j++)
+ aPoints->SetPoint(j,anArray[i],anArray[i+1],0.0);
+ break;
+ case 3:
+ for (vtkIdType i = 0, j = 0; i < iEnd; i += theMesh.myDim, j++)
+ aPoints->SetPoint(j,anArray[i],anArray[i+1],anArray[i+2]);
+ break;
+ }
+ theMesh.myPoints = aPoints;
+ }
+ theStorage->SetPoints(aPoints);
+ }
+
+
+ inline void PrintCells(int& theStartId,
+ vtkCellArray* theConnectivity,
+ const VISU::TMeshOnEntity::TConnect& theVector)
+ {
+ vtkIdList *anIdList = vtkIdList::New();
+ int kEnd = theVector.size();
+ anIdList->SetNumberOfIds(kEnd);
+ for(int k = 0; k < kEnd; k++)
+ anIdList->SetId(k,theVector[k]);
+ theConnectivity->InsertNextCell(anIdList);
+ anIdList->Delete();
+ }
+
+ void GetCellsOnEntity(VISU::TVTKSource& theStorage,
+ const VISU::TMeshOnEntity& theMeshOnEntity,
+ const string& theFamilyName)
+ throw (std::runtime_error&)
+ {
+ //Check on existing family
+ const VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName);
+ bool isFamilyPresent = (pFamily != NULL);
+ const VISU::TFamily& aFamily = *pFamily;
+ //Main part of code
+ pair<int,int> aCellsDim = theMeshOnEntity.GetCellsDims(theFamilyName);
+ int aNbCells = aCellsDim.first, aCellsSize = aCellsDim.second;
+ vtkCellArray* aConnectivity = vtkCellArray::New();
+ aConnectivity->Allocate(aCellsSize,0);
+ vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+ aCellTypesArray->SetNumberOfComponents(1);
+ aCellTypesArray->SetNumberOfTuples(aNbCells);
+ if(MYDEBUG) MESSAGE("GetCellsOnEntity - isFamilyPresent = "<<isFamilyPresent);
+ const VISU::TMeshOnEntity::TCellsConn &aCellsConn = theMeshOnEntity.myCellsConn;
+ VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin();
+ for(int i = 0, j = 0; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){
+ const VISU::TMeshOnEntity::TConnForCellType& anArray = aCellsConnIter->second;
+ int aVtkType = aCellsConnIter->first;
+ if(MYDEBUG)
+ MESSAGE("GetCellsOnEntity - aVtkType = "<<aVtkType<<"; anArray.size() = "<<anArray.size());
+ if(!isFamilyPresent)
+ for(int k = 0, kEnd = anArray.size(); k < kEnd; k++, i++){
+ PrintCells(i,aConnectivity,anArray[k]);
+ aCellTypesArray->SetValue(j++,(unsigned char)aVtkType);
+ }
+ else{
+ const VISU::TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
+ if(aSubMesh.empty())
+ throw std::runtime_error(EXCEPTION("GetCells >> 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() = "<<aSubMeshOnCellType.size());
+ VISU::TFamily::TSubMeshOnCellType::const_iterator aSubMeshOnCellTypeIter = aSubMeshOnCellType.begin();
+ for(; aSubMeshOnCellTypeIter != aSubMeshOnCellType.end(); aSubMeshOnCellTypeIter++, i++){
+ PrintCells(i,aConnectivity,anArray[*aSubMeshOnCellTypeIter]);
+ aCellTypesArray->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,
+ const VISU::TMesh& theMesh,
+ const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
+ throw (std::runtime_error&)
+ {
+ //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<int,int> 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;
+ 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 = "<<aVtkType<<"; anArray.size() = "<<anArray.size());
+ const VISU::TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
+ if(aSubMesh.empty())
+ throw std::runtime_error(EXCEPTION("GetCells >> 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() = "<<aSubMeshOnCellType.size());
+ VISU::TFamily::TSubMeshOnCellType::const_iterator aSubMeshOnCellTypeIter = aSubMeshOnCellType.begin();
+ for(; aSubMeshOnCellTypeIter != aSubMeshOnCellType.end(); aSubMeshOnCellTypeIter++, i++){
+ PrintCells(i,aConnectivity,anArray[*aSubMeshOnCellTypeIter]);
+ aCellTypesArray->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,
+ const VISU::TMeshOnEntity& theMeshOnEntity,
+ const VISU::TField::TValForTime& theValForTime)
+ throw (std::runtime_error&)
+ {
+ const VISU::TField::TValForCells& aValForCells = theValForTime.myValForCells;
+ const VISU::TMeshOnEntity::TCellsConn &aCellsConn = theMeshOnEntity.myCellsConn;
+ VISU::TMeshOnEntity::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,
+ const VISU::TField& theField,
+ const VISU::TField::TValForTime& theValForTime)
+ throw (std::runtime_error&)
+ {
+ //theFloatArray->DebugOn();
+ theFloatArray->SetNumberOfTuples(theNumberOfTuples);
+ theFloatArray->SetName(theFieldName.c_str());
+ if(MYDEBUG) MESSAGE("GetValsOnTimeStamp - theNumberOfTuples = "<<theNumberOfTuples);
+ const VISU::TField::TValForCells& aValForCells = theValForTime.myValForCells;
+ VISU::TField::TValForCells::const_iterator aValForCellsIter = aValForCells.begin();
+ for(int k = 0; aValForCellsIter != aValForCells.end(); aValForCellsIter++) {
+ const VISU::TField::TValForCellsWithType& anArray = aValForCellsIter->second;
+ int iEnd = anArray.size()/theField.myNbComp;
+ int aVtkType = aValForCellsIter->first;
+ if(MYDEBUG) MESSAGE("GetValsOnTimeStamp - iEnd = "<<iEnd<<"; aVtkType = "<<aVtkType);
+ switch(theField.myNbComp) {
+ case 1:
+ for (int i = 0; i < iEnd; i++)
+ theFloatArray->SetTuple1(k++,anArray[i]);
+ break;
+ case 2:
+ for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*2)
+ theFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+1],0.0);
+ break;
+ case 3:
+ for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*3)
+ theFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+1],anArray[ji+2]);
+ break;
+ case 4:
+ for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*4)
+ theFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+2],0.0);
+ break;
+ case 6:
+ for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*4)
+ theFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+2],anArray[ji+5]);
+ break;
+ default:
+ throw std::runtime_error(EXCEPTION("GetValsOnTimeStamp - There is no an algorithm for representation of the field !!!"));
+ }
+ }
+ }
+
+ string GenerateFieldName(const VISU::TField& theField,
+ const VISU::TField::TValForTime& theValForTime)
+ {
+ const VISU::TField::TTime& aTime = theValForTime.myTime;
+ string aFieldName = theField.myMeshName + ", " + theField.myName + ": " +
+ VISU_Convertor::GenerateName(aTime);
+ return aFieldName;
+ }
+
+ void GetTimeStamp(VISU::TVTKSource& theStorage,
+ const VISU::TMesh& theMesh,
+ const VISU::TMeshOnEntity& theMeshOnEntity,
+ const VISU::TField& theField,
+ const VISU::TField::TValForTime& theValForTime)
+ throw (std::runtime_error&)
+ {
+ int aNumberOfTuples = theField.myDataSize/theField.myNbComp;
+ string aFieldName = GenerateFieldName(theField,theValForTime);
+ if(MYDEBUG)
+ MESSAGE("GetTimeStamp(TVTKSource) - aFieldName = "<<aFieldName<<
+ "; aNumberOfTuples = "<<aNumberOfTuples);
+
+ vtkDataSetAttributes* aDataSetAttributes;
+ switch(theField.myEntity){
+ case VISU::NODE_ENTITY :
+ aDataSetAttributes = theStorage->GetPointData();
+ break;
+ default:
+ aDataSetAttributes = theStorage->GetCellData();
+ }
+
+ vtkFloatArray *aFloatArray = vtkFloatArray::New();
+ switch(theField.myNbComp) {
+ case 1:
+ aFloatArray->SetNumberOfComponents(1);
+ aDataSetAttributes->SetScalars(aFloatArray);
+ break;
+ default:
+ aFloatArray->SetNumberOfComponents(3);
+ aDataSetAttributes->SetVectors(aFloatArray);
+ }
+
+ GetValsOnTimeStamp(aFloatArray,aNumberOfTuples,aFieldName,theField,theValForTime);
+ }
+
+ void GetTimeStamp(VISU::TVTKAttribyteFilter& theAttribyteFilter,
+ VISU::TVTKMergetFilter& theMergeFilter,
+ VISU::TVTKExtractFilter& theExtractFilter,
+ const VISU::TMesh& theMesh,
+ const VISU::TMeshOnEntity& theMeshOnEntity,
+ const VISU::TField& theField,
+ const VISU::TField::TValForTime& theValForTime)
+ throw (std::runtime_error&)
+ {
+ int aNumberOfTuples = theField.myDataSize/theField.myNbComp;
+ string aFieldName = GenerateFieldName(theField,theValForTime);
+ if(MYDEBUG)
+ MESSAGE("GetTimeStamp(TVTKAttribyteFilter) - aFieldName = "<<aFieldName<<
+ "; aNumberOfTuples = "<<aNumberOfTuples);
+
+ vtkDataObject* aDataObject = vtkDataObject::New();
+ theMergeFilter->SetDataObject(aDataObject);
+ aDataObject->Delete();
+
+ theMergeFilter->SetInput(theExtractFilter->GetOutput());
+ theAttribyteFilter->SetInput(theMergeFilter->GetOutput());
+
+ switch(theField.myEntity){
+ case VISU::NODE_ENTITY :
+ theMergeFilter->SetOutputFieldToPointDataField();
+ theAttribyteFilter->SetInputFieldToPointDataField();
+ theAttribyteFilter->SetOutputAttributeDataToPointData();
+ break;
+ default:
+ theMergeFilter->SetOutputFieldToCellDataField();
+ theAttribyteFilter->SetInputFieldToCellDataField();
+ theAttribyteFilter->SetOutputAttributeDataToCellData();
+ }
+
+ vtkFloatArray *aFloatArray = vtkFloatArray::New();
+ switch(theField.myNbComp) {
+ case 1:
+ aFloatArray->SetNumberOfComponents(1);
+ theAttribyteFilter->SetScalarComponent(0,aFieldName.c_str(),0);
+ break;
+ default:
+ aFloatArray->SetNumberOfComponents(3);
+ theAttribyteFilter->SetVectorComponent(0,aFieldName.c_str(),0);
+ theAttribyteFilter->SetVectorComponent(1,aFieldName.c_str(),1);
+ theAttribyteFilter->SetVectorComponent(2,aFieldName.c_str(),2);
+ }
+
+ vtkFieldData* aFieldData = aDataObject->GetFieldData();
+ aFieldData->AddArray(aFloatArray);
+ aFloatArray->Delete();
+
+ GetValsOnTimeStamp(aFloatArray,aNumberOfTuples,aFieldName,theField,theValForTime);
+ }
+}
VISU_Convertor_impl::VISU_Convertor_impl() {
myIsDone = false;
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();
+ MESSAGE("GetMeshOnEntity - GetPoints() = "<<float(aDataSet->GetPoints()->GetActualMemorySize()*1000));
+ MESSAGE("GetMeshOnEntity - GetCells() = "<<float(aDataSet->GetCells()->GetActualMemorySize()*1000));
+ MESSAGE("GetMeshOnEntity - GetCellTypesArray() = "<<float(aDataSet->GetCellTypesArray()->GetActualMemorySize()*1000));
+ MESSAGE("GetMeshOnEntity - GetCellLocationsArray() = "<<float(aDataSet->GetCellLocationsArray()->GetActualMemorySize()*1000));
+ aDataSet->BuildLinks();
+ MESSAGE("GetMeshOnEntity - GetCellLinks() = "<<float(aDataSet->GetCellLinks()->GetActualMemorySize()*1000));
+ MESSAGE("GetMeshOnEntity - GetActualMemorySize() = "<<float(aDataSet->GetActualMemorySize()*1000));
}
+ }catch(...){
+ aSource = vtkSmartPointerBase();
+ throw;
}
- return aSource.get();
+ return aSource.GetPointer();
}
VISU_Convertor::TOutput*
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*
theFieldName,pField,theStampsNum,pValForTime);
VISU::TMesh& aMesh = *pMesh;
VISU::TMeshOnEntity& aMeshOnEntity = *pMeshOnEntity;
- VISU::TMeshOnEntity& aVTKMeshOnEntity = *pVTKMeshOnEntity;
VISU::TField& aField = *pField;
VISU::TField::TValForTime& aValForTime = *pValForTime;
+ VISU::TVTKAttribyteFilter& anAttribyteFilter = aValForTime.myAttribyteFilter;
VISU::TVTKSource& aSource = aValForTime.myStorage;
+ TOutput* anOutput = NULL;
//Main part of code
- if(aSource.get() == NULL){
- aSource.reset(TOutput::New());
- LoadFieldOnMesh(aMesh,aMeshOnEntity,aField,aValForTime);
- try{
- LoadMeshOnEntity(aVTKMeshOnEntity);
- }catch(std::runtime_error& exc){
- aVTKMeshOnEntity = aMeshOnEntity;
- MESSAGE("Follow exception was accured :\n"<<exc.what());
- }catch(...){
- aVTKMeshOnEntity = aMeshOnEntity;
- MESSAGE("Unknown exception was accured!");
- }
- GetMeshOnEntity(aVTKMeshOnEntity.myMeshName,aVTKMeshOnEntity.myEntity);
- aSource->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);
- }
- }
- return aSource.get();
-}
-
-inline void PrintCells(int& theStartId,
- vtkCellArray* theConnectivity,
- const VISU::TMeshOnEntity::TConnect& theVector)
-{
- 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();
-}
-
-void VISU_Convertor_impl::GetCellsOnEntity(VISU::TVTKSource& theStorage,
- const VISU::TMeshOnEntity& theMeshOnEntity,
- const string& theFamilyName)
- const throw (std::runtime_error&)
-{
- //Check on existing family
- const VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName);
- bool isFamilyPresent = (pFamily != NULL);
- const VISU::TFamily& aFamily = *pFamily;
- //Main part of code
- pair<int,int> 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 = "<<isFamilyPresent);
- const VISU::TMeshOnEntity::TCellsConn &aCellsConn = theMeshOnEntity.myCellsConn;
- VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.begin();
- for(int i = 0, j = 0; aCellsConnIter != aCellsConn.end(); aCellsConnIter++){
- const VISU::TMeshOnEntity::TConnForCellType& anArray = aCellsConnIter->second;
- int aVtkType = aCellsConnIter->first;
- if(MYDEBUG) MESSAGE("GetCellsOnEntity - aVtkType = "<<aVtkType<<"; anArray.size() = "<<anArray.size());
- if(!isFamilyPresent)
- for(int k = 0, kEnd = anArray.size(); k < kEnd; k++, i++){
- PrintCells(i,aConnectivity,anArray[k]);
- aCellTypesArray->SetValue(j++,(unsigned char)aVtkType);
- //aCellTypesArray->InsertNextValue((unsigned char)aVtkType);
- }
+ try{
+ if(aSource.GetPointer())
+ return aSource.GetPointer();
+ else if(anAttribyteFilter.GetPointer())
+ return anAttribyteFilter->GetUnstructuredGridOutput();
else{
- const VISU::TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
- if(aSubMesh.empty()) throw std::runtime_error("GetCells >> 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() = "<<aSubMeshOnCellType.size());
- VISU::TFamily::TSubMeshOnCellType::const_iterator aSubMeshOnCellTypeIter = aSubMeshOnCellType.begin();
- for(; aSubMeshOnCellTypeIter != aSubMeshOnCellType.end(); aSubMeshOnCellTypeIter++, i++){
- PrintCells(i,aConnectivity,anArray[*aSubMeshOnCellTypeIter]);
- aCellTypesArray->SetValue(j++,(unsigned char)aVtkType);
- //aCellTypesArray->InsertNextValue((unsigned char)aVtkType);
+ LoadFieldOnMesh(aMesh,aMeshOnEntity,aField,aValForTime);
+
+ VISU::TVTKExtractFilter& anExtractFilter = aField.myExtractFilter;
+ if(anExtractFilter.GetPointer() == NULL){
+ anExtractFilter = VISU_ExtractUnstructuredGrid::New();
+ anExtractFilter->Delete();
+ //anExtractFilter->DebugOn();
+ try{
+ LoadMeshOnEntity(*pVTKMeshOnEntity);
+ }catch(std::runtime_error& exc){
+ pVTKMeshOnEntity = pMeshOnEntity;
+ MESSAGE("Follow exception was accured :\n"<<exc.what());
+ }catch(...){
+ pVTKMeshOnEntity = pMeshOnEntity;
+ MESSAGE("Unknown exception was accured!");
+ }
+ GetMeshOnEntity(pVTKMeshOnEntity->myMeshName,pVTKMeshOnEntity->myEntity);
+
+ anExtractFilter->SetInput(pVTKMeshOnEntity->myStorage.GetPointer());
+ ::InitProfile(anExtractFilter,*pMeshOnEntity,aValForTime);
+ }
+ if(!anExtractFilter->IsRemoving()){
+ aSource = TOutput::New();
+ aSource->Delete();
+ aSource->ShallowCopy(pVTKMeshOnEntity->myStorage.GetPointer());
+ ::GetTimeStamp(aSource,aMesh,*pVTKMeshOnEntity,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,
+ aMesh,*pVTKMeshOnEntity,aField,aValForTime);
+ anOutput = anAttribyteFilter->GetUnstructuredGridOutput();
}
- }
- }
- 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);
-}
-
-
-void VISU_Convertor_impl::GetCellsOnGroup(VISU::TVTKSource& theStorage,
- const VISU::TMesh& theMesh,
- const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
- const throw (std::runtime_error&)
-{
- //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<int,int> 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 = "<<aVtkType<<"; anArray.size() = "<<anArray.size());
- const VISU::TFamily::TSubMesh& aSubMesh = aFamily.mySubMesh;
- if(aSubMesh.empty()) throw std::runtime_error("GetCells >> 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() = "<<aSubMeshOnCellType.size());
- VISU::TFamily::TSubMeshOnCellType::const_iterator aSubMeshOnCellTypeIter = aSubMeshOnCellType.begin();
- for(; aSubMeshOnCellTypeIter != aSubMeshOnCellType.end(); aSubMeshOnCellTypeIter++, i++){
- PrintCells(i,aConnectivity,anArray[*aSubMeshOnCellTypeIter]);
- aCellTypesArray->SetValue(j++,(unsigned char)aVtkType);
- //aCellTypesArray->InsertNextValue((unsigned char)aVtkType);
+ 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)
+ MESSAGE("GetTimeStampOnMesh - GetData() = "<<float(aDataSet->GetPointData()->GetActualMemorySize()*1000));
+ else
+ MESSAGE("GetMeshOnEntity - GetData() = "<<float(aDataSet->GetCellData()->GetActualMemorySize()*1000));
+ MESSAGE("GetTimeStampOnMesh - GetActualMemorySize() = "<<float(aDataSet->GetActualMemorySize()*1000));
}
}
+ }catch(...){
+ aSource = vtkSmartPointerBase();
+ anAttribyteFilter = vtkSmartPointerBase();
+ throw;
}
- 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);
-}
-
-
-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 = "<<aNbPoints<<"; myDim = "<<theMesh.myDim);
- switch(theMesh.myDim) {
- case 1:
- for (vtkIdType i = 0, j = 0; i < iEnd; i += theMesh.myDim, j++)
- aPoints->SetPoint(j,anArray[i],0.0,0.0);
- break;
- case 2:
- for (vtkIdType i = 0, j = 0; i < iEnd; i += theMesh.myDim, j++)
- aPoints->SetPoint(j,anArray[i],anArray[i+1],0.0);
- break;
- case 3:
- for (vtkIdType i = 0, j = 0; i < iEnd; i += theMesh.myDim, j++)
- aPoints->SetPoint(j,anArray[i],anArray[i+1],anArray[i+2]);
- break;
- }
- }
- theStorage->SetPoints(aPoints);
-}
-
-void VISU_Convertor_impl::GetField(VISU::TVTKSource& theStorage,
- const VISU::TMesh& theMesh,
- const VISU::TMeshOnEntity& theMeshOnEntity,
- const VISU::TField& theField,
- const VISU::TField::TValForTime& theValForTime)
- const throw (std::runtime_error&)
-{
- if(MYDEBUG) MESSAGE("GetField - aTime = "<<theValForTime.myId<<"; theField.myName = "<<theField.myName);
- int aNumberOfTuples;
- vtkDataSetAttributes* aDataSetAttributes;
- switch(theField.myEntity) {
- case VISU::NODE_ENTITY :
- {
- int aNbPoints = theMesh.myPointsCoord.size()/theMesh.myDim;
- aNumberOfTuples = aNbPoints;
- aDataSetAttributes = theStorage->GetPointData();
- break;
- }
- default:
- {
- pair<int,int> aCellsDim = theMeshOnEntity.GetCellsDims();
- int aNbCells = aCellsDim.first, aCellsSize = aCellsDim.second;
- aNumberOfTuples = aNbCells;
- aDataSetAttributes = theStorage->GetCellData();
- }
- }
- vtkFloatArray *aFloatArray = vtkFloatArray::New();
- switch(theField.myNbComp) {
- case 1:
- aFloatArray->SetNumberOfComponents(1);
- aDataSetAttributes->SetScalars(aFloatArray);
- break;
- default:
- aFloatArray->SetNumberOfComponents(3);
- aDataSetAttributes->SetVectors(aFloatArray);
- }
- aFloatArray->SetNumberOfTuples(aNumberOfTuples);
- //const VISU::TField::TTime& aTime = theValForTime.myTime;
- //string aFieldName = theField.myMeshName + ", " + theField.myName + ": " + GenerateName(aTime);
- //aFloatArray->SetName(aFieldName.c_str());
- if(MYDEBUG) MESSAGE("GetField - aNumberOfTuples = "<<aNumberOfTuples);
- const VISU::TField::TValForCells& aValForCells = theValForTime.myValForCells;
- VISU::TField::TValForCells::const_iterator aValForCellsIter = aValForCells.begin();
- for(int k = 0; aValForCellsIter != aValForCells.end(); aValForCellsIter++) {
- const VISU::TField::TValForCellsWithType& anArray = aValForCellsIter->second;
- int iEnd = anArray.size()/theField.myNbComp;
- int aVtkType = aValForCellsIter->first;
- if(MYDEBUG) MESSAGE("GetField - iEnd = "<<iEnd<<"; aVtkType = "<<aVtkType);
- switch(theField.myNbComp) {
- case 1:
- for (int i = 0; i < iEnd; i++)
- aFloatArray->SetTuple1(k++,anArray[i]);
- break;
- case 2:
- for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*2)
- aFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+1],0.0);
- break;
- case 3:
- for (int i = 0, ji = 0; i < iEnd; ++i, ji = i*3)
- aFloatArray->SetTuple3(k++,anArray[ji],anArray[ji+1],anArray[ji+2]);
- break;
- default:
- throw std::runtime_error("GetField - There is algorithm for representation the field !!!");
- }
- }
+ return anOutput;
}
-
void VISU_Convertor_impl::FindMesh(const string& theMeshName, VISU::TMesh*& theMesh)
throw (std::runtime_error&)
{
GetMeshMap();
if(myMeshMap.find(theMeshName) == myMeshMap.end())
- throw std::runtime_error("FindMesh >> There is no mesh with the name!!!");
+ throw std::runtime_error(EXCEPT("FindMesh >> There is no mesh with the name - '%1'!!!").
+ arg(theMeshName.c_str()).latin1());
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)
+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&)
{
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!!!");
+ throw std::runtime_error(EXCEPT("FindMeshOnEntity >> There is no mesh on the entity - %1!!!").
+ arg(int(theEntity)).latin1());
theMeshOnEntity = &aMeshOnEntityMap[theEntity];
theFamily = VISU::GetFamily(*theMeshOnEntity,theFamilyName);
}
-vtkIdType VISU_Convertor_impl::GetMeshOnEntitySize(const std::string& theMeshName,
- const VISU::TEntity& theEntity,
- const std::string& theFamilyName)
+float VISU_Convertor_impl::GetSize() throw (std::runtime_error&){
+ float aResult = 0.0;
+ const VISU::TMeshMap& aMeshMap = GetMeshMap();
+ VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
+ for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
+ const string& aMeshName = aMeshMapIter->first;
+ const VISU::TMesh& 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::TMeshOnEntity& 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::TField& aField = aFieldMapIter->second;
+ const VISU::TField::TValField& aValField = aField.myValField;
+ VISU::TField::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);
+ }
+ }
+ if(MYDEBUG)
+ MESSAGE("GetSize - aResult = "<<float(aResult));
+ return aResult;
+}
+
+
+float 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*pMesh->myNbPoints*sizeof(VISU::TMesh::TCoord);
vtkIdType aNbCells, aCellsSize;
if(!pFamily){
aNbCells = pMeshOnEntity->myNbCells;
aNbCells = pFamily->myNbCells;
aCellsSize = pFamily->myCellsSize;
}
- //that is Connectivity + (Types + Locations + Links)
- aResult += aCellsSize*sizeof(vtkIdType) +
- aNbCells*(sizeof(char) + sizeof(int) + (sizeof(short) + sizeof(vtkIdType)));
- if(MYDEBUG) cout<<"VISU_Convertor_impl::GetMeshOnEntitySize = "<<aResult<<endl;
+ vtkIdType aConnectivitySize = aCellsSize*sizeof(vtkIdType);
+ vtkIdType aTypesSize = aNbCells*sizeof(char);
+ vtkIdType aLocationsSize = aNbCells*sizeof(int);
+ float aNbCellsPerPoint = aCellsSize / aNbCells - 1;
+ vtkIdType aLinksSize = pMesh->myNbPoints *
+ (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(vtkCellLinks::Link));
+ aLinksSize = 0;
+ vtkIdType aResult = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize + aLinksSize;
+ if(MYDEBUG){
+ if(MYVTKDEBUG){
+ MESSAGE("GetMeshOnEntitySize - aPointsSize = "<<float(aPointsSize));
+ MESSAGE("GetMeshOnEntitySize - aConnectivitySize = "<<float(aConnectivitySize));
+ MESSAGE("GetMeshOnEntitySize - aTypesSize = "<<float(aTypesSize));
+ MESSAGE("GetMeshOnEntitySize - aLocationsSize = "<<float(aLocationsSize));
+ MESSAGE("GetMeshOnEntitySize - aLinksSize = "<<float(aLinksSize));
+ }
+ MESSAGE("GetMeshOnEntitySize - aResult = "<<float(aResult)<<"; theMeshName = '"<<theMeshName<<
+ "'; theEntity = "<<theEntity<<"; theFamilyName = '"<<theFamilyName<<"'");
+ }
+ aResult = vtkIdType(aResult*ERR_SIZE_CALC);
return aResult;
}
VISU::TGroupMap& aGroupMap = theMesh->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!!!");
+ throw std::runtime_error(EXCEPT("FindMesh >> There is no the group in the mesh!!! - '%1'").arg(theGroupName.c_str()).latin1());
theGroup = &aGroupMapIter->second;
}
-vtkIdType VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName,
- const std::string& theGroupName)
+float VISU_Convertor_impl::GetMeshOnGroupSize(const std::string& theMeshName,
+ const std::string& theGroupName)
throw (std::runtime_error&)
{
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 = "<<aResult<<endl;
+ vtkIdType aPointsSize = 3*pMesh->myNbPoints*sizeof(VISU::TMesh::TCoord);
+ vtkIdType aNbCells = pGroup->myNbCells, aCellsSize = pGroup->myCellsSize;
+ vtkIdType aConnectivityAndTypesSize = aCellsSize*sizeof(vtkIdType);
+ vtkIdType aLocationsSize = aNbCells*sizeof(int);
+ float aNbCellsPerPoint = aCellsSize / aNbCells - 1;
+ vtkIdType aLinksSize = pMesh->myNbPoints *
+ (vtkIdType(sizeof(vtkIdType)*aNbCellsPerPoint) + sizeof(short));
+ aLinksSize = 0;
+ vtkIdType aResult = aPointsSize + aConnectivityAndTypesSize + aLocationsSize + aLinksSize;
+ if(MYDEBUG){
+ if(MYVTKDEBUG){
+ MESSAGE("GetMeshOnGroupSize - aPointsSize = "<<float(aPointsSize));
+ MESSAGE("GetMeshOnGroupSize - aConnectivityAndTypesSize = "<<float(aConnectivityAndTypesSize));
+ MESSAGE("GetMeshOnGroupSize - aLocationsSize = "<<float(aLocationsSize));
+ MESSAGE("GetMeshOnGroupSize - aLinksSize = "<<float(aLinksSize));
+ }
+ MESSAGE("GetMeshOnGroupSize - aResult = "<<float(aResult)<<"; theMeshName = '"
+ <<theMeshName<<"'; theGroupName = '"<<theGroupName<<"'");
+ }
+ aResult = vtkIdType(aResult*ERR_SIZE_CALC);
return aResult;
}
theMeshOnEntity = pMeshOnEntity;
VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
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];
+ if(aMeshOnEntityMap.find(VISU::CELL_ENTITY) != aMeshOnEntityMap.end())
+ pMeshOnEntity = &aMeshOnEntityMap[VISU::CELL_ENTITY];
+ else if(aMeshOnEntityMap.find(VISU::FACE_ENTITY) != aMeshOnEntityMap.end())
+ pMeshOnEntity = &aMeshOnEntityMap[VISU::FACE_ENTITY];
+ else if(aMeshOnEntityMap.find(VISU::NODE_ENTITY) != aMeshOnEntityMap.end())
+ pMeshOnEntity = &aMeshOnEntityMap[VISU::EDGE_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!!!");
+ throw std::runtime_error(EXCEPTION("FindField >> There is no field on the mesh!!!"));
theField = &aFieldMap[theFieldName];
}
-vtkIdType VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName,
- const VISU::TEntity& theEntity,
- const std::string& theFieldName)
+float VISU_Convertor_impl::GetFieldOnMeshSize(const std::string& theMeshName,
+ const VISU::TEntity& theEntity,
+ const std::string& theFieldName)
throw(std::runtime_error&)
{
VISU::TMesh* pMesh = 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 = "<<aResult<<endl;
+ float aMeshSize = GetMeshOnEntitySize(theMeshName,pVTKMeshOnEntity->myEntity);
+ float aFieldOnMeshSize = float(pField->myDataSize*sizeof(float)*pField->myNbValField * ERR_SIZE_CALC);
+ float aResult = aMeshSize + aFieldOnMeshSize;
+ if(MYDEBUG){
+ if(MYVTKDEBUG)
+ MESSAGE("GetFieldOnMeshSize - aFieldOnMeshSize = "<<float(aFieldOnMeshSize));
+ MESSAGE("GetFieldOnMeshSize - aResult = "<<float(aResult)<<"; theMeshName = '"<<theMeshName<<
+ "'; theEntity = "<<theEntity<<"; theFieldName = '"<<theFieldName<<"'");
+ }
return aResult;
}
FindField(theMeshName,theMesh,theEntity,theMeshOnEntity,theVTKMeshOnEntity,theFieldName,theField);
VISU::TField::TValField& aValField = theField->myValField;
if(aValField.find(theStampsNum) == aValField.end())
- throw std::runtime_error("FindTimeStamp >> There is no field with the timestamp!!!");
+ throw std::runtime_error(EXCEPTION("FindTimeStamp >> There is no field with the timestamp!!!"));
theValForTime = &aValField[theStampsNum];
}
-vtkIdType VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName,
- const VISU::TEntity& theEntity,
- const std::string& theFieldName,
- int theStampsNum)
+float VISU_Convertor_impl::GetTimeStampSize(const std::string& theMeshName,
+ const VISU::TEntity& theEntity,
+ const std::string& theFieldName,
+ int theStampsNum)
throw (std::runtime_error&)
{
VISU::TMesh* pMesh = 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 = "<<aResult<<endl;
+ float aMeshSize = GetMeshOnEntitySize(theMeshName,pVTKMeshOnEntity->myEntity);
+ float aTimeStampSize = float(pField->myDataSize*sizeof(float) * ERR_SIZE_CALC);
+ float aResult = aMeshSize + aTimeStampSize;
+ if(MYDEBUG){
+ if(MYVTKDEBUG)
+ MESSAGE("GetTimeStampSize - aTimeStampSize = "<<float(aTimeStampSize));
+ MESSAGE("GetTimeStampSize - aResult = "<<float(aResult)<<"; theMeshName = '"<<theMeshName<<"'; theEntity = "<<theEntity<<
+ "; theFieldName = '"<<theFieldName<<"'; theStampsNum = "<<theStampsNum);
+ }
return aResult;
}
const VISU::TField&
VISU_Convertor_impl::GetField(const string& theMeshName,
VISU::TEntity theEntity,
- const string& theFieldName)
+ const string& theFieldName)
throw (std::runtime_error&)
{
VISU::TMesh* pMesh = NULL;
#include "VISU_MedConvertor.hxx"
+#include "VISU_ConvertorUtils.hxx"
+
#include <valarray>
#include <vtkCellType.h>
+
#define USER_INTERLACE MED_FULL_INTERLACE
using namespace std;
static int MYDEBUG = 0;
#endif
+
static med_err ret = 0;
typedef map<VISU::TEntity,med_entite_maillage> TVisu2MedEntity;
MedFile aMedFile(myFileInfo.absFilePath());
med_idt fid = aMedFile.GetFid();
med_int iMeshEnd = MEDnMaa(fid); //Get number of meshes
+ if (iMeshEnd < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDnMaa(...)"));
if(MYDEBUG) MESSAGE("ImportInfo - MEDnMaa = "<<iMeshEnd<<"; myFileInfo = "<<myFileInfo.filePath());
for(int iMesh = 1; iMesh <= iMeshEnd; iMesh++){
med_int aMeshDim;
ret = MEDnoeudsLire(fid,aMeshName,aMesh.myDim,&coord[0],MED_FULL_INTERLACE,&rep,
&name_coord[0],&unit_coord[0],&name_elem[0],&iname_elem,
&num_elem[0],&inum_elem,&num_fam_elem[0],iNumElemEnd);
- if(ret < 0) throw std::runtime_error("ImportInfo >> MEDnoeudsLire(...)");
+ if(ret < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDnoeudsLire(...)"));
for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
if(num_fam_elem[iNumElem] != 0){
aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity;
ret = MEDelementsLire(fid,aMeshName,aMesh.myDim,&conn[0],MED_FULL_INTERLACE,
&name_elem[0],&iname_elem,&num_elem[0],&inum_elem,
&num_fam_elem[0],iNumElemEnd,aMedEntity,aMedType,MED_NOD);
- if (ret < 0) throw std::runtime_error("ImportInfo >> MEDelementsLire(...)");
+ if (ret < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDelementsLire(...)"));
for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
if(num_fam_elem[iNumElem] != 0){
aFamily2EntityMap[num_fam_elem[iNumElem]] = anEntity;
ret = MEDfamInfo(fid,aMeshName,aFamInd,aFamilyName,&aFamilyNum,
&anAttId[0],&anAttVal[0],&anAttDesc[0],&aNbAttrib,
&aGroupNames[0],&aNbGroup);
- if(ret < 0) throw std::runtime_error("ImportInfo >> MEDfamInfo");
+ if(ret < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDfamInfo"));
if(0 && MYDEBUG)
MESSAGE("ImportInfo - aFamilyNum = "<<aFamilyNum<<"; aNbGroup = "<<aNbGroup);
if(aFamily2EntityMap.find(aFamilyNum) == aFamily2EntityMap.end()) {
}
//Reading information about fields
med_int iFieldEnd = MEDnChamp(fid,0);
- if (iFieldEnd < 0) throw std::runtime_error("ImportChamps >> MEDnChamp(fid,0)");
+ if (iFieldEnd < 0) throw std::runtime_error(EXCEPTION("ImportChamps >> MEDnChamp(fid,0)"));
if(MYDEBUG) MESSAGE("ImportInfo - iFieldEnd = "<<iFieldEnd);
for(med_int iField = 1; iField <= iFieldEnd; iField++){
med_int ncomp = MEDnChamp(fid,iField);
- if(ncomp < 0) throw std::runtime_error("ImportChamps >> MEDnChamp(fid,i)");
+ if(ncomp < 0) throw std::runtime_error(EXCEPTION("ImportChamps >> MEDnChamp(fid,i)"));
valarray<char> aCompNames('\0',ncomp*MED_TAILLE_PNOM + 1);
valarray<char> aUnitNames('\0',ncomp*MED_TAILLE_PNOM + 1);
char name_field[MED_TAILLE_NOM + 1] = "";
med_type_champ type_field;
if(MEDchampInfo(fid,iField,name_field,&type_field,&aCompNames[0],&aUnitNames[0],ncomp) < 0)
- throw std::runtime_error(string("ImportInfo >> MEDchampInfo(...)"));
+ throw std::runtime_error(EXCEPTION("ImportInfo >> MEDchampInfo(...)"));
//if(type_field != MED_REEL64) continue; //There is some problem in reading INTXX values
TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin();
for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++) {
for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
med_geometrie_element& aGeom = aGeomElemVector[iGeomElem];
med_int iTimeStampEnd = MEDnPasdetemps(fid,name_field,aMedEntity,aGeom);
- if(iTimeStampEnd < 0) throw std::runtime_error("ImportInfo >> MEDnPasdetemps(...)");
+ if(iTimeStampEnd < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDnPasdetemps(...)"));
if(iTimeStampEnd > 0) {
for(med_int iTimeStamp = 1; iTimeStamp <= iTimeStampEnd; iTimeStamp++) {
char aMeshName[MED_TAILLE_NOM+1] = "";
med_float dt = 0;
ret = MEDpasdetempsInfo(fid,name_field,aMedEntity,aGeom,iTimeStamp,
aMeshName,&ngauss,&numdt,dt_unit,&dt,&numo);
- if(ret < 0) throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...) < 0");
+ if(ret < 0) throw std::runtime_error(EXCEPTION("ImportInfo >> MEDpasdetempsInfo(...) < 0"));
if(myMeshMap.find(aMeshName) == myMeshMap.end())
- throw std::runtime_error("ImportInfo >> MEDpasdetempsInfo(...)");
+ throw std::runtime_error(EXCEPTION("ImportInfo >> MEDpasdetempsInfo(...)"));
VISU::TMesh &aMesh = myMeshMap[aMeshName];
VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
VISU::TFieldMap::iterator aFieldMapIter = aMeshOnEntity.myFieldMap.find(name_field);
aValForTime.myMeshName = aField.myMeshName;
aValForTime.myNbComp = aField.myNbComp;
aValForTime.myTime = VISU::TField::TTime(dt,dt_unit);
- if(MYDEBUG && iGeomElem == 0)
+ if(MYDEBUG)
MESSAGE("ImportInfo -\t aValForTime.myTime = "<<dt<<", "<<dt_unit);
}
}
med_geometrie_element typgeo = (med_geometrie_element)0; //MED_POINT1
med_connectivite typco = (med_connectivite)0; //MED_NOD
med_int iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_COOR,MED_NOEUD,typgeo,typco);
- if (iNumElemEnd <= 0) throw std::runtime_error("LoadPoints >> MEDnEntMaa(...)");
+ if (iNumElemEnd <= 0) throw std::runtime_error(EXCEPTION("LoadPoints >> MEDnEntMaa(...)"));
if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<<iNumElemEnd);
med_repere rep;
med_booleen iname_elem, inum_elem;
ret = MEDnoeudsLire(fid,aMeshName,theMesh.myDim,&coord[0],MED_FULL_INTERLACE,&rep,
&name_coord[0],&unit_coord[0],&name_elem[0],&iname_elem,
&num_elem[0],&inum_elem,&num_fam_elem[0],iNumElemEnd);
- if(ret < 0) throw std::runtime_error("LoadPoints >> MEDnoeudsLire(...)");
+ if(ret < 0) throw std::runtime_error(EXCEPTION("LoadPoints >> MEDnoeudsLire(...)"));
if(!isPointsLoaded){
VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord;
aPointsCoord.resize(iNumElemEnd*theMesh.myDim);
if(MYDEBUG) MESSAGE("LoadPoints - Filling coordinates of the mesh - inum_elem = "<<inum_elem);
- inum_elem = MED_FAUX; // It is workaround
+ inum_elem = MED_FAUX; // It is workaround
if(inum_elem == MED_FAUX)
for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++)
aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim];
else
- for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
+ for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++)
aPointsCoord[num_elem[iNumElem2Dim]] = coord[iNumElem2Dim];
if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
throw std::runtime_error(exc.what());
}catch(...){
theMesh.myPointsCoord.clear();
- throw std::runtime_error("Unknown exception !!!");
+ throw std::runtime_error(EXCEPTION("Unknown exception !!!"));
}
return 0;
}
"; iGeomElemEnd = "<<iGeomElemEnd<<"; theFamilyName = '"<<theFamilyName<<"'");
VISU::TMesh &aMesh = myMeshMap[theMeshOnEntity.myMeshName];
int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
+ valarray<med_int> num_node(aNbPoints);
+ med_booleen inum_node =
+ med_booleen(MEDnumLire(fid,aMeshName,&num_node[0],aNbPoints,MED_NOEUD,med_geometrie_element(0)) >= 0);
+ if(MYDEBUG) MESSAGE("LoadCellsOnEntity - inum_node = "<<inum_node);
+ map<med_int,med_int> node_map;
+ if(inum_node)
+ for(int i = 0; i < aNbPoints; i++)
+ node_map[num_node[i]-1] = i;
for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
int medId = getIdMedType(aGeomElemVector[iGeomElem]);
int nbMedNodes = med2vtk[medId].medNbNodes;
ret = MEDelementsLire(fid,aMeshName,aMesh.myDim,&conn[0],MED_FULL_INTERLACE,
&name_elem[0],&iname_elem,&num_elem[0],&inum_elem,
&num_fam_elem[0],iNumElemEnd,aMedEntity,aMedType,MED_NOD);
- if (ret < 0) throw std::runtime_error("LoadCellsOnEntity >> MEDelementsLire(...)");
+ if (ret < 0) throw std::runtime_error(EXCEPTION("LoadCellsOnEntity >> MEDelementsLire(...)"));
if(!isCellsLoaded){
VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = theMeshOnEntity.myCellsConn[aVtkType];
aConnForCellType.resize(iNumElemEnd);
for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[iNumElem];
anArray.resize(nbVtkNodes);
- for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) {
- aConnect[k] = conn[kj+k] - 1;
- }
+ if(inum_node)
+ for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++)
+ aConnect[k] = node_map[conn[kj+k]-1];
+ else
+ for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++)
+ aConnect[k] = conn[kj+k] - 1;
switch(aMedType){
case MED_TETRA4 :
case MED_TETRA10 :
anArray[k] = aConnect[k];
}
for (int k = 0; k < nbVtkNodes; k++)
- if(anArray[k] < 0 || aNbPoints <= anArray[k]){
- static QString aString;
- aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d](%d) < 0",aNbPoints,iNumElem,k,anArray[k]);
- throw std::runtime_error(aString.latin1());
- }
+ if(anArray[k] < 0 || aNbPoints <= anArray[k])
+ throw std::runtime_error(EXCEPT("ImportCells >> aNbPoints(%1) <= anArray[%2][%3](%4) < 0").
+ arg(aNbPoints).arg(iNumElem).arg(k).arg(anArray[k]).latin1());
}
}
//Filling aFamily SubMesh
throw std::runtime_error(exc.what());
}catch(...){
theMeshOnEntity.myCellsConn.clear();
- throw std::runtime_error("Unknown exception !!!");
+ throw std::runtime_error(EXCEPTION("Unknown exception !!!"));
}
return 0;
}
int VISU_MedConvertor::LoadField(const med_idt& fid, const VISU::TMeshOnEntity& theMeshOnEntity,
- const VISU::TField& theField, VISU::TField::TValForTime& theValForTime)
+ VISU::TField& theField, VISU::TField::TValForTime& theValForTime)
throw (std::runtime_error&)
{
//Check on loading already done
if(!theValForTime.myValForCells.empty()) return 0;
//Main part of code
med_int ncomp = MEDnChamp(fid,theField.myId);
- if(ncomp < 0) throw std::runtime_error("LoadField >> MEDnChamp(fid,i)");
+ if(ncomp < 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDnChamp(fid,i)"));
valarray<char> comp('\0',ncomp*MED_TAILLE_PNOM + 1);
valarray<char> unit('\0',ncomp*MED_TAILLE_PNOM + 1);
char aFieldName[MED_TAILLE_NOM + 1] = "";
+ char aMeshName[MED_TAILLE_NOM+1] = "";
+ strcpy(aMeshName,theValForTime.myMeshName.c_str());
med_type_champ type_field;
if(MEDchampInfo(fid,theField.myId,aFieldName,&type_field,&comp[0],&unit[0],ncomp) < 0)
- throw std::runtime_error(string("LoadField >> MEDchampInfo(...)"));
+ throw std::runtime_error(EXCEPTION("LoadField >> MEDchampInfo(...)"));
int iGeomElemEnd;
med_geometrie_element* aGeomElemVector;
const VISU::TEntity& anEntity = theField.myEntity;
GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
med_entite_maillage& aMedEntity = aVisu2MedEntity[anEntity];
- if(MYDEBUG) {
- MESSAGE("LoadField - aFieldName = '"<<aFieldName<<"'; anEntity = "<<anEntity<<"; iGeomElemEnd = "<<iGeomElemEnd);
- MESSAGE("LoadField - ncomp = "<<ncomp<<"; type_field = "<<type_field<<"; myId = "<<theValForTime.myId);
+ const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMeshOnEntity.myCellsConn;
+ if(MYDEBUG){
+ MESSAGE("LoadField - aMeshName = '"<<aMeshName<<"' aFieldName = '"<<aFieldName<<"'; anEntity = "<<anEntity);
+ MESSAGE("LoadField - iGeomElemEnd = "<<iGeomElemEnd<<"; ncomp = "<<ncomp<<"; type_field = "<<type_field);
}
for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
- med_geometrie_element& aGeom = aGeomElemVector[iGeomElem];
+ const med_geometrie_element& aGeom = aGeomElemVector[iGeomElem];
med_int iTimeStampEnd = MEDnPasdetemps(fid,aFieldName,aMedEntity,aGeom);
- if(iTimeStampEnd > 0) {
- char aMeshName[MED_TAILLE_NOM+1] = "";
+ //Checking for accordance between the mesh and the field data
+ med_int iNumElemEnd = 0;
+ if(aMedEntity == MED_NOEUD)
+ iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_COOR,MED_NOEUD,med_geometrie_element(0),med_connectivite(0));
+ else
+ iNumElemEnd = MEDnEntMaa(fid,aMeshName,MED_CONN,aMedEntity,aGeom,MED_NOD);
+ int medId = getIdMedType(aGeomElemVector[iGeomElem]);
+ int aVtkType = med2vtk[medId].vtkType;
+ if(iTimeStampEnd <= 0){
+ if(iNumElemEnd > 0){
+ if(!theField.myIsTrimmed){
+ theField.myIsTrimmed = true;
+ theField.myDataSize -= iNumElemEnd*theField.myNbComp;
+ }
+ //throw std::runtime_error(EXCEPT("VISU_MedConvertor::LoadField - There is no the data "
+ // "for cells with type %1 of the mesh !!!").
+ // arg(med2vtk[medId].medName).latin1());
+ }
+ }else{
med_int ngauss = 0, numdt = 0, numo = 0;
char dt_unit[MED_TAILLE_PNOM+1] = "";
med_float dt = 0;
ret = MEDpasdetempsInfo(fid,aFieldName,aMedEntity,aGeom,theValForTime.myId,
aMeshName,&ngauss,&numdt,dt_unit,&dt,&numo);
- if(ret < 0) throw std::runtime_error("LoadField >> MEDpasdetempsInfo(...)");
+ if(ret < 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDpasdetempsInfo(...)"));
med_int nval = MEDnVal(fid,aFieldName,aMedEntity,aGeom,numdt,numo);
- if (nval <= 0) throw std::runtime_error("LoadField >> MEDnVal(...) - nval <= 0");
+ if(nval <= 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDnVal(...) - nval <= 0"));
else{
- //Checking for accordance between the mesh and the field on number of geomterical elements
- int aVtkType = med2vtkCellType(aGeom);
- const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMeshOnEntity.myCellsConn;
- VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType);
- if(aCellsConnIter == aCellsConn.end()) throw std::runtime_error("LoadField - There is no the geom. elem. on the mesh !!!");
- const VISU::TMeshOnEntity::TConnForCellType aConnForCellType = aCellsConnIter->second;
- if(aConnForCellType.size() != nval) throw std::runtime_error("LoadField - Size of values and size of mesh not equal !!!");
- if(MYDEBUG) MESSAGE("LoadField - aGeom = "<<aGeom<<"; nval = "<<nval<<"; iTimeStampEnd = "<<iTimeStampEnd);
+ //Checking for accordance between the mesh and the field data
+ if(iNumElemEnd <= 0)
+ throw std::runtime_error(EXCEPTION("LoadField - There is no the geom. elem. on the mesh !!!"));
+ static int aMaxNbGaussPts = 52; // the workaround for broken files
+ if(ngauss > aMaxNbGaussPts) ngauss = 1;
+ if(iNumElemEnd*ngauss != nval)
+ throw std::runtime_error(EXCEPT("LoadField - Size of values (%1) and size of mesh (%2) not equal !!!").
+ arg(nval).arg(iNumElemEnd*ngauss).latin1());
VISU::TField::TValForCellsWithType &anArray = theValForTime.myValForCells[aVtkType];
int jEnd = theField.myNbComp*nval;
- anArray.resize(jEnd);
+ int kEnd = jEnd/ngauss;
+ anArray.resize(kEnd);
char pflname[MED_TAILLE_NOM + 1] = "";
switch(type_field){
case MED_REEL64 : {
valarray<med_float> valr(jEnd);
ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL,
pflname,aMedEntity,aGeom,numdt,numo);
- for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j];
+ if(ret < 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDchampLire(...)"));
+ for (med_int k = 0, j = 0; k < kEnd; k++, j += ngauss){
+ for (med_int iGauss = 0; iGauss < ngauss; iGauss++)
+ anArray[k] = valr[j+iGauss];
+ anArray[k] /= ngauss;
+ }
break;
}
//case MED_INT64 : //valarray<long long> valr(jEnd);
valarray<med_int> valr(jEnd);
ret = MEDchampLire(fid,aMeshName,aFieldName,(unsigned char*)&valr[0],MED_FULL_INTERLACE,MED_ALL,
pflname,aMedEntity,aGeom,numdt,numo);
- for (med_int j = 0; j < jEnd; j++) anArray[j] = valr[j];
+ if(ret < 0) throw std::runtime_error(EXCEPTION("LoadField >> MEDchampLire(...)"));
+ for (med_int k = 0, j = 0; k < kEnd; k++, j += ngauss){
+ for (med_int iGauss = 0; iGauss < ngauss; iGauss++)
+ anArray[k] = valr[j+iGauss];
+ anArray[k] /= ngauss;
+ }
break;
}
- default :
- throw std::runtime_error("LoadField >> Value of med_type_champ for the field is wrong !!!");
+ default :
+ throw std::runtime_error(EXCEPTION("LoadField >> Value of med_type_champ for the field is wrong !!!"));
}
- if(ret < 0) throw std::runtime_error("ChampLire >> MEDchampLire(...)");
+ if(MYDEBUG) MESSAGE("LoadField - aGeom = "<<aGeom<<"; nval = "<<nval<<"; ngauss = "<<ngauss
+ <<"; iTimeStampEnd = "<<iTimeStampEnd<<"; pflname = '"<<pflname<<"'");
}
}
}