From 1f07373a0fa132dfb9e447d9437dc1c48e20a455 Mon Sep 17 00:00:00 2001 From: apo Date: Fri, 29 Dec 2006 10:41:08 +0000 Subject: [PATCH] Implementation of direct passing MED data to VTK converter --- src/CONVERTOR/Makefile.in | 1 + src/CONVERTOR/VISUConvertor.cxx | 2 +- src/CONVERTOR/VISU_Convertor_impl.cxx | 915 +++++++++++++++++-------- src/CONVERTOR/VISU_Convertor_impl.hxx | 225 +++++- src/CONVERTOR/VISU_MedConvertor.cxx | 34 +- src/CONVERTOR/VISU_MedConvertor.hxx | 21 + src/CONVERTOR/VISU_TypeList.hxx | 96 +++ src/PIPELINE/VISU_Extractor.cxx | 136 ++-- src/PIPELINE/VISU_FieldTransform.cxx | 280 ++++++-- src/VISU_I/VISU_ColoredPrs3dFactory.hh | 59 +- src/VISU_I/VISU_CorbaMedConvertor.cxx | 80 ++- src/VISU_I/VISU_CorbaMedConvertor.hxx | 35 + 12 files changed, 1350 insertions(+), 534 deletions(-) create mode 100644 src/CONVERTOR/VISU_TypeList.hxx diff --git a/src/CONVERTOR/Makefile.in b/src/CONVERTOR/Makefile.in index 4f10fe78..dd855414 100644 --- a/src/CONVERTOR/Makefile.in +++ b/src/CONVERTOR/Makefile.in @@ -33,6 +33,7 @@ BOOST_LIBSUFFIX=@BOOST_LIBSUFFIX@ @COMMENCE@ EXPORT_HEADERS = \ + VISU_TypeList.hxx \ VISU_IDMapper.hxx \ VISU_Convertor.hxx \ VISU_ConvertorDef.hxx \ diff --git a/src/CONVERTOR/VISUConvertor.cxx b/src/CONVERTOR/VISUConvertor.cxx index b5814d6a..3a07760d 100644 --- a/src/CONVERTOR/VISUConvertor.cxx +++ b/src/CONVERTOR/VISUConvertor.cxx @@ -46,7 +46,7 @@ static int MYDEBUG = 1; static int MYDEBUG = 0; #endif -//#define _DEXCEPT_ +#define _DEXCEPT_ typedef vtkUnstructuredGrid TOutput; diff --git a/src/CONVERTOR/VISU_Convertor_impl.cxx b/src/CONVERTOR/VISU_Convertor_impl.cxx index f632a6f1..45e325f3 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.cxx +++ b/src/CONVERTOR/VISU_Convertor_impl.cxx @@ -36,12 +36,24 @@ #include #include #include -#include -#include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -301,7 +313,7 @@ namespace VISU ::SetVoidArray() const { vtkDataArray* aDataArray = myPoints->GetData(); - aDataArray->SetVoidArray(myCoord->GetValuePtr(), myCoord->size(), false); + aDataArray->SetVoidArray(myCoord->GetValuePtr(), myCoord->size(), true); } vtkPoints* @@ -309,6 +321,7 @@ namespace VISU ::GetPoints() const { if(!myIsVTKDone){ + TTimerLog aTimerLog(MYDEBUG,"TPointCoords::GetPoints()"); vtkIdType aNbPoints = GetNbPoints(); vtkIdType aDim = GetDim(); @@ -317,6 +330,7 @@ namespace VISU endl); if(GetDim() == 3){ + INITMSG(MYDEBUG,"TPointCoords::GetPoints - SetVoidArray()"<second; + } + + PMeshValue& + TGeom2Value + ::GetMeshValue(EGeometry theGeom) + { + return myGeom2MeshValue[theGeom]; + } + + + //---------------------------------------------------------------------------- + TGeom2MeshValue& + TGeom2Value + ::GetGeom2MeshValue() + { + return myGeom2MeshValue; + } + + const TGeom2MeshValue& + TGeom2Value + ::GetGeom2MeshValue() const + { + return myGeom2MeshValue; + } + + PMeshValue + TGeom2Value + ::GetFirstMeshValue() const + { + if(myGeom2MeshValue.size() == 1) + return myGeom2MeshValue.begin()->second; + return PMeshValue(); + } + + namespace TL + { + //---------------------------------------------------------------------------- + typedef TList > > > > > > > > > > > > + TVTKBasicTypeList; + + + //---------------------------------------------------------------------------- + typedef TList > > > > > > > > > > > > + TVTKArrayTypeList; + + + typedef TList, + TList, + TList, + TList, + TList, + TList, + TList, + TList, + TList, + TList, + TList, + TList, + TList, + TNullType> > > > > > > > > > > > > + TVTKBasicEnumList; + + + //---------------------------------------------------------------------------- + template + struct TEnum2VTKBasicType + { + typedef typename TTypeAt >::value >::TResult TResult; + }; + + //---------------------------------------------------------------------------- + template + struct TEnum2VTKArrayType + { + typedef typename TTypeAt >::value >::TResult TResult; + }; + + //---------------------------------------------------------------------------- + template + struct TVTKBasicType2Enum + { + typedef typename TTypeAt::value >::TResult TResult; + }; - myValue.resize(theNbElem*myStep); } - TCValueSliceArr - TMeshValue - ::GetGaussValueSliceArr(vtkIdType theElemId) const + + //---------------------------------------------------------------------------- + template + void + InitTimeStampOnProfile(const TVTKSource& theSource, + const PFieldImpl& theField, + const PValForTimeImpl& theValForTime, + const VISU::TEntity& theEntity); + + + //---------------------------------------------------------------------------- + void + GetTimeStampOnProfile(const TVTKSource& theSource, + const PFieldImpl& theField, + const PValForTimeImpl& theValForTime, + const VISU::TEntity& theEntity) { - TCValueSliceArr aValueSliceArr(myNbGauss); - vtkIdType anId = theElemId*myStep; - for(vtkIdType aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ - aValueSliceArr[aGaussId] = - TCValueSlice(myValue,std::slice(anId, myNbComp, 1)); - anId += myNbComp; + vtkIdType aDataType = theField->GetDataType(); + switch(aDataType){ + case VTK_DOUBLE: + InitTimeStampOnProfile(theSource, theField, theValForTime, theEntity); + break; + case VTK_FLOAT: + InitTimeStampOnProfile(theSource, theField, theValForTime, theEntity); + break; + case VTK_INT: + InitTimeStampOnProfile(theSource, theField, theValForTime, theEntity); + break; + case VTK_LONG: + InitTimeStampOnProfile(theSource, theField, theValForTime, theEntity); + break; + default: + EXCEPTION(runtime_error, + "GetTimeStampOnProfile - handling unsupported data type - "< + struct TDataArrayHolder { - TValueSliceArr aValueSliceArr(myNbGauss); - vtkIdType anId = theElemId*myStep; - for(vtkIdType aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ - aValueSliceArr[aGaussId] = - TValueSlice(myValue, std::slice(anId, myNbComp, 1)); - anId += myNbComp; + typedef typename TL::TEnum2VTKArrayType::TResult TVTKDataArray; + typedef typename TL::TEnum2VTKBasicType::TResult TVTKBasicType; + TVTKDataArray* myDataArray; + + TDataArrayHolder(TVTKDataArray* theDataArray): + myDataArray(theDataArray) + {} + + void + WritePointer(TVTKDataArray* theDataArray, + vtkIdType theTupleId, + TVTKBasicType* thePointer) + { + vtkIdType aNumberOfComponents = theDataArray->GetNumberOfComponents(); + vtkIdType aPosition = theTupleId * aNumberOfComponents; + TVTKBasicType *aPtr = theDataArray->WritePointer(aPosition, aNumberOfComponents); + for(vtkIdType anId = 0; anId < aNumberOfComponents; anId++) + *aPtr++ = *thePointer++; } - return aValueSliceArr; - } - TCValueSliceArr - TMeshValue - ::GetCompValueSliceArr(vtkIdType theElemId) const + virtual + void + SetTuple(vtkIdType theTupleId, + TVTKBasicType* thePointer) + { + this->WritePointer(myDataArray, theTupleId, thePointer); + } + }; + + + //---------------------------------------------------------------------------- + template + struct TDataArrayHolder2: TDataArrayHolder { - TCValueSliceArr aValueSliceArr(myNbComp); - vtkIdType anId = theElemId*myStep; - for(vtkIdType aCompId = 0; aCompId < myNbComp; aCompId++){ - aValueSliceArr[aCompId] = - TCValueSlice(myValue,std::slice(anId, myNbGauss, myNbComp)); - anId += 1; + typedef TDataArrayHolder TSuperClass; + typedef typename TSuperClass::TVTKDataArray TVTKDataArray; + typedef typename TSuperClass::TVTKBasicType TVTKBasicType; + TVTKDataArray* myDataArray2; + + TDataArrayHolder2(TVTKDataArray* theDataArray, + TVTKDataArray* theDataArray2): + TSuperClass(theDataArray), + myDataArray2(theDataArray2) + {} + + virtual + void + SetTuple(vtkIdType theTupleId, + TVTKBasicType* thePointer) + { + this->WritePointer(myDataArray, theTupleId, thePointer); + this->WritePointer(myDataArray2, theTupleId, thePointer); } - return aValueSliceArr; - } + }; + - TValueSliceArr - TMeshValue - ::GetCompValueSliceArr(vtkIdType theElemId) + //---------------------------------------------------------------------------- + template + struct TTimeStampOnProfileInitArray { - TValueSliceArr aValueSliceArr(myNbComp); - vtkIdType anId = theElemId*myStep; - for(vtkIdType aCompId = 0; aCompId < myNbComp; aCompId++){ - aValueSliceArr[aCompId] = - TValueSlice(myValue,std::slice(anId, myNbGauss, myNbComp)); - anId += 1; + typedef typename TL::TEnum2VTKArrayType::TResult TVTKDataArray; + typedef typename TL::TEnum2VTKBasicType::TResult TVTKBasicType; + typedef TTMeshValue TMeshValue; + typedef SharedPtr TMeshValuePtr; + + typedef TDataArrayHolder TTDataArrayHolder; + typedef SharedPtr PDataArrayHolder; + PDataArrayHolder myDataArrayHolder; + + TTimeStampOnProfileInitArray(const PDataArrayHolder& theDataArrayHolder): + myDataArrayHolder(theDataArrayHolder) + {} + + void + Execute(const PFieldImpl& theField, + const PValForTimeImpl& theValForTime) + { + vtkIdType aNbComp = theField->myNbComp; + vtkIdType aSize = max(3, aNbComp); + TVector aDataValues(aSize); + + const TGeom2MeshValue& aGeom2MeshValue = theValForTime->GetGeom2MeshValue(); + TGeom2MeshValue::const_iterator anIter = aGeom2MeshValue.begin(); + for(int aTupleId = 0; anIter != aGeom2MeshValue.end(); anIter++){ + EGeometry aEGeom = anIter->first; + const TMeshValuePtr aMeshValue = anIter->second; + + vtkIdType aNbElem = aMeshValue->GetNbElem(); + vtkIdType aNbGauss = aMeshValue->GetNbGauss(); + + INITMSG(MYDEBUG, + "- aEGeom = "<AddArray(aFullDataArray); + + INITMSG(MYDEBUG,"InitTimeStampOnProfile "<< + "- theEntity = "<GetGeom2MeshValue(); + typedef typename TL::TEnum2VTKBasicType::TResult TVTKBasicType; + typedef TTMeshValue TMeshValue; + typedef SharedPtr TMeshValuePtr; + + typedef TDataArrayHolder TTDataArrayHolder; + typedef SharedPtr PDataArrayHolder; + + TMeshValuePtr aMeshValue = theValForTime->GetFirstMeshValue(); + if(aGeom2MeshValue.size() == 1 && aMeshValue->GetNbGauss() == 1){ + aFullDataArray->SetVoidArray(aMeshValue->GetPointer(), + aMeshValue->size(), + true); + INITMSG(MYDEBUG,"InitTimeStampOnProfile - aFullDataArray->SetVoidArray()"<SetVoidArray(aMeshValue->GetPointer(), + aMeshValue->size(), + true); + INITMSG(MYDEBUG,"InitTimeStampOnProfile - aSelectedDataArray->SetVoidArray()"<(aDataArrayHolder).Execute(theField, theValForTime); + } + }else{ + typedef TDataArrayHolder2 TTDataArrayHolder2; + PDataArrayHolder aDataArrayHolder(new TTDataArrayHolder2(aSelectedDataArray, aFullDataArray)); + TTimeStampOnProfileInitArray(aDataArrayHolder).Execute(theField, theValForTime); + } + + aSelectedDataArray->Delete(); + aFullDataArray->Delete(); } - unsigned long int - TMeshValue - ::GetMemorySize() const + + //---------------------------------------------------------------------------- + template + void + InitTimeStampOnGaussMesh(const TVTKSource& theSource, + const PFieldImpl& theField, + const PValForTimeImpl& theValForTime); + + void + GetTimeStampOnGaussMesh(const TVTKSource& theSource, + const PFieldImpl& theField, + const PValForTimeImpl& theValForTime) { - size_t aSize = sizeof(TMeshValue); - aSize += myValue.size() * sizeof(vtkFloatingPointType); - return aSize; + vtkIdType aDataType = theField->GetDataType(); + switch(aDataType){ + case VTK_DOUBLE: + InitTimeStampOnGaussMesh(theSource, theField, theValForTime); + break; + case VTK_FLOAT: + InitTimeStampOnGaussMesh(theSource, theField, theValForTime); + break; + case VTK_INT: + InitTimeStampOnGaussMesh(theSource, theField, theValForTime); + break; + case VTK_LONG: + InitTimeStampOnGaussMesh(theSource, theField, theValForTime); + break; + default: + EXCEPTION(runtime_error, + "GetTimeStampOnGaussMesh - handling unsupported data type - "< + struct TTimeStampOnGaussMeshInitArray + { + typedef typename TL::TEnum2VTKArrayType::TResult TVTKDataArray; + typedef typename TL::TEnum2VTKBasicType::TResult TVTKBasicType; + typedef TTMeshValue TMeshValue; + typedef SharedPtr TMeshValuePtr; + + typedef TDataArrayHolder TTDataArrayHolder; + typedef SharedPtr PDataArrayHolder; + PDataArrayHolder myDataArrayHolder; + + TTimeStampOnGaussMeshInitArray(const PDataArrayHolder& theDataArrayHolder): + myDataArrayHolder(theDataArrayHolder) + {} + + void + Execute(const PFieldImpl& theField, + const PValForTimeImpl& theValForTime) + { + vtkIdType aNbComp = theField->myNbComp; + vtkIdType aSize = max(3, aNbComp); + TVector aDataValues(aSize); + + const TGeom2MeshValue& aGeom2MeshValue = theValForTime->GetGeom2MeshValue(); + + PGaussMeshImpl aGaussMesh = theValForTime->myGaussMesh; + const TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh; + TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin(); + for(int aTupleId = 0; anIter != aGeom2GaussSubMesh.end(); anIter++){ + EGeometry aEGeom = anIter->first; + + PGaussSubMeshImpl aGaussSubMesh = anIter->second; + if(!aGaussSubMesh->myIsDone) + continue; + + TGeom2MeshValue::const_iterator anIter2 = aGeom2MeshValue.find(aEGeom); + if(anIter2 == aGeom2MeshValue.end()){ + EXCEPTION(runtime_error, + "TTimeStampOnGaussMeshInitArray >> Can't find values for corresponding Gauss Points SubMesh"); + } + TMeshValuePtr aMeshValue = anIter2->second; + vtkIdType aNbGauss = aMeshValue->GetNbGauss(); + vtkIdType aNbElem = aMeshValue->GetNbElem(); + + if(aNbGauss < 1) + continue; + + const TPointCoords& aCoords = aGaussSubMesh->myPointCoords; + + INITMSG(MYDEBUG, + "- aEGeom = "<AddArray(aFullDataArray); + + INITMSG(MYDEBUG,"InitTimeStampOnGaussMesh "<< + "- aNbTuples = "<GetGeom2MeshValue(); + typedef typename TL::TEnum2VTKBasicType::TResult TVTKBasicType; + typedef TTMeshValue TMeshValue; + typedef SharedPtr TMeshValuePtr; + + typedef TDataArrayHolder TTDataArrayHolder; + typedef SharedPtr PDataArrayHolder; + + TMeshValuePtr aMeshValue = theValForTime->GetFirstMeshValue(); + if(aGeom2MeshValue.size() == 1){ + aFullDataArray->SetVoidArray(aMeshValue->GetPointer(), + aMeshValue->size(), + true); + INITMSG(MYDEBUG,"InitTimeStampOnGaussMesh - aFullDataArray->SetVoidArray()"<SetVoidArray(aMeshValue->GetPointer(), + aMeshValue->size(), + true); + INITMSG(MYDEBUG,"InitTimeStampOnGaussMesh - aSelectedDataArray->SetVoidArray()"<(aDataArrayHolder).Execute(theField, theValForTime); + } + }else{ + typedef TDataArrayHolder2 TTDataArrayHolder2; + PDataArrayHolder aDataArrayHolder(new TTDataArrayHolder2(aSelectedDataArray, aFullDataArray)); + TTimeStampOnGaussMeshInitArray(aDataArrayHolder).Execute(theField, theValForTime); + } + + aSelectedDataArray->Delete(); + aFullDataArray->Delete(); + } //--------------------------------------------------------------- TValForTimeImpl @@ -1281,21 +1823,39 @@ namespace VISU myIDMapperFilter(new TIDMapperFilter()) {} - const TMeshValue& + const PMeshValue& TValForTimeImpl ::GetMeshValue(EGeometry theGeom) const { - TGeom2Value::const_iterator anIter = myGeom2Value.find(theGeom); - if(anIter == myGeom2Value.end()) - EXCEPTION(runtime_error,"TValForTimeImpl::GetMeshValue - myGeom2Value.find(theGeom) fails"); - return anIter->second; + return myGeom2Value.GetMeshValue(theGeom); } - TMeshValue& + PMeshValue& TValForTimeImpl ::GetMeshValue(EGeometry theGeom) { - return myGeom2Value[theGeom]; + return myGeom2Value.GetMeshValue(theGeom); + } + + TGeom2MeshValue& + TValForTimeImpl + ::GetGeom2MeshValue() + { + return myGeom2Value.GetGeom2MeshValue(); + } + + const TGeom2MeshValue& + TValForTimeImpl + ::GetGeom2MeshValue() const + { + return myGeom2Value.GetGeom2MeshValue(); + } + + PMeshValue + TValForTimeImpl + ::GetFirstMeshValue() const + { + return myGeom2Value.GetFirstMeshValue(); } int @@ -1304,7 +1864,6 @@ namespace VISU { TGeom2NbGauss::const_iterator anIter = myGeom2NbGauss.find(theGeom); if(anIter == myGeom2NbGauss.end()){ - //EXCEPTION(runtime_error,"TValForTimeImpl::GetNbGauss - myGeom2NbGauss.find(theGeom) fails"); return 1; } return anIter->second; @@ -1315,11 +1874,12 @@ namespace VISU ::GetMemorySize() { size_t aSize = sizeof(TValForTimeImpl); - TGeom2Value::const_iterator anIter = myGeom2Value.begin(); - TGeom2Value::const_iterator anIterEnd = myGeom2Value.end(); + const TGeom2MeshValue& aGeom2MeshValue = GetGeom2MeshValue(); + TGeom2MeshValue::const_iterator anIter = aGeom2MeshValue.begin(); + TGeom2MeshValue::const_iterator anIterEnd = aGeom2MeshValue.end(); for(; anIter != anIterEnd; anIter++){ - const TMeshValue& aMeshValue = anIter->second; - aSize += aMeshValue.GetMemorySize(); + const PMeshValue& aMeshValue = anIter->second; + aSize += aMeshValue->GetMemorySize(); aSize += sizeof(EGeometry); } return aSize; @@ -1494,6 +2054,7 @@ namespace const PSubMeshImpl& theSubMesh, const vtkIdType theGeom) { + TTimerLog aTimerLog(MYDEBUG,"GetCellsOnSubMesh"); const VISU::TCell2Connect& anArray = theSubMesh->myCell2Connect; vtkIdType aCellsSize = theSubMesh->myCellsSize; vtkIdType aNbCells = theSubMesh->myNbCells; @@ -1617,88 +2178,6 @@ namespace } - //--------------------------------------------------------------- - void - GetTimeStampOnProfile(const TVTKSource& theSource, - const PFieldImpl& theField, - const PValForTimeImpl& theValForTime, - const VISU::TEntity& theEntity) - { - int aNbTuples = theField->myDataSize/theField->myNbComp; - std::string aFieldName = GenerateFieldName(theField,theValForTime); - - vtkDataSetAttributes* aDataSetAttributes; - switch(theEntity){ - case VISU::NODE_ENTITY : - aDataSetAttributes = theSource->GetPointData(); - break; - default: - aDataSetAttributes = theSource->GetCellData(); - } - - int aNbComp = theField->myNbComp; - vtkFloatArray *aFloatArray = vtkFloatArray::New(); - - switch(aNbComp) { - case 1: - aFloatArray->SetNumberOfComponents(1); - aDataSetAttributes->SetScalars(aFloatArray); - break; - default: - aFloatArray->SetNumberOfComponents(3); - aDataSetAttributes->SetVectors(aFloatArray); - } - aFloatArray->SetNumberOfTuples(aNbTuples); - aFloatArray->SetName(aFieldName.c_str()); - - vtkFloatArray *aDataArray = vtkFloatArray::New(); - aDataArray->SetNumberOfComponents(aNbComp); - aDataArray->SetNumberOfTuples(aNbTuples); - aDataArray->SetName("VISU_FIELD"); - aDataSetAttributes->AddArray(aDataArray); - - INITMSG(MYDEBUG,"GetTimeStampOnProfile "<< - "- theEntity = "<AddArray(aDataArray); - - INITMSG(MYDEBUG,"GetTimeStampOnGaussMesh "<< - "- aNbTuples = "<> Can't find values for corresponding Gauss Points SubMesh"); - } - const TMeshValue& aMeshValue = anIter2->second; - int aNbGauss = aMeshValue.myNbGauss; - int aNbElem = aMeshValue.myNbElem; - - if(aNbGauss < 1) - continue; - - const TPointCoords& aCoords = aGaussSubMesh->myPointCoords; - - INITMSG(MYDEBUG, - "- aEGeom = "<GetNumberOfPoints()<GetNumberOfCells()<myIsVTKDone) return; - INITMSG(MYDEBUG,"BuildGaussMesh"<GetFilter(); const TGeom2GaussSubMesh& aGeom2GaussSubMesh = theGaussMesh->myGeom2GaussSubMesh; TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin(); @@ -2165,6 +2536,7 @@ VISU_Convertor_impl try{ #endif if(!aMeshOnEntity->myIsVTKDone){ + TTimerLog aTimerLog(MYDEBUG,"VISU_Convertor_impl::GetMeshOnEntity"); const TVTKAppendFilter& anAppendFilter = aMeshOnEntity->GetFilter(); if(MYVTKDEBUG) anAppendFilter->DebugOn(); @@ -2368,15 +2740,14 @@ VISU_Convertor_impl const VISU::PProfileImpl& theProfile, const VISU::TEntity& theEntity) { - LoadMeshOnEntity(theMesh,theMeshOnEntity); - GetMeshOnEntity(theMeshOnEntity->myMeshName,theMeshOnEntity->myEntity); - GetMeshOnProfile(theMesh,theMeshOnEntity,theProfile); + LoadMeshOnEntity(theMesh, theMeshOnEntity); + GetMeshOnEntity(theMeshOnEntity->myMeshName, theMeshOnEntity->myEntity); + GetMeshOnProfile(theMesh, theMeshOnEntity, theProfile); theIDMapperFilter->myIDMapper = theProfile; TVTKOutput* anOutput = theIDMapperFilter->GetVTKOutput(); const TVTKSource& aSource = theIDMapperFilter->mySource.GetSource(); - ::GetTimeStampOnProfile(aSource,theField,theValForTime,theEntity); - + ::GetTimeStampOnProfile(aSource, theField, theValForTime, theEntity); return anOutput; } @@ -2414,6 +2785,7 @@ VISU_Convertor_impl try{ #endif if(!anIDMapperFilter->myIsVTKDone){ + TTimerLog aTimerLog(MYDEBUG,"VISU_Convertor_impl::GetTimeStampOnMesh"); LoadValForTimeOnMesh(aMesh,aMeshOnEntity,aField,aValForTime); TVTKOutput* anOutput; @@ -2501,6 +2873,7 @@ VISU_Convertor_impl try{ #endif if(!aGaussPtsIDFilter->myIsVTKDone){ + TTimerLog aTimerLog(MYDEBUG,"VISU_Convertor_impl::GetTimeStampOnGaussPts"); LoadValForTimeOnGaussPts(aMesh,aMeshOnEntity,aField,aValForTime); GetMeshOnEntity(aVTKMeshOnEntity->myMeshName,aVTKMeshOnEntity->myEntity); diff --git a/src/CONVERTOR/VISU_Convertor_impl.hxx b/src/CONVERTOR/VISU_Convertor_impl.hxx index c4278970..0ea7c194 100644 --- a/src/CONVERTOR/VISU_Convertor_impl.hxx +++ b/src/CONVERTOR/VISU_Convertor_impl.hxx @@ -237,7 +237,7 @@ namespace VISU mutable TContainerType myCoord; //!< Keeps the node coordinates container itself public: - //! To initilize the class + //! To initilize the class instance void Init(vtkIdType theNbPoints, vtkIdType theDim, @@ -247,6 +247,12 @@ namespace VISU myCoord = theCoord; } + //! Gets pointer to the first element in the node coordinates array + virtual + TCoord* + GetPointer() = 0; + + //! Gets pointer to the first element in the node coordinates array (const version) virtual const TCoord* GetPointer() const = 0; @@ -261,10 +267,6 @@ namespace VISU std::slice(theNodeId * this->GetDim(), this->GetDim(), 1)); } - virtual - TCoord* - GetPointer() = 0; - //! Get slice of coordinates for defined node virtual TCoordSlice @@ -853,73 +855,216 @@ namespace VISU //! Specialize TField to provide VTK mapping for the entity struct TFieldImpl: virtual TField { - vtkIdType myDataSize; //!< Keeps size of the assigned data + TFieldImpl(); - TMinMaxArr myMinMaxArr; //!< Keeps min/max values for each component of the MED FIELD + //! To initialize the data structure + void + Init(vtkIdType theNbComp, + vtkIdType theDataType); + + //! Gets type idetificator of the mesh data. + vtkIdType + GetDataType() const; //! Implement the TField::GetMinMax virtual TMinMax GetMinMax(vtkIdType theCompID); - //! To initialize the data structure - void - InitArrays(vtkIdType theNbComp); - - TFieldImpl(); + vtkIdType myDataSize; //!< Keeps size of the assigned data + vtkIdType myDataType; //!< Keeps type idetificator of the mesh data + TMinMaxArr myMinMaxArr; //!< Keeps min/max values for each component of the MED FIELD }; typedef SharedPtr PFieldImpl; //--------------------------------------------------------------- - typedef TVector TValue; - typedef TSlice TValueSlice; - typedef TCSlice TCValueSlice; + //! Define a base class for the container to get access to data assigned to mesh + class TMeshValueBase + { + public: + //! To intitilize the data strucutre + void + Init(vtkIdType theNbElem, + vtkIdType theNbGauss, + vtkIdType theNbComp); - typedef TVector TCValueSliceArr; - typedef TVector TValueSliceArr; + //! Gets memory size used by the instance (bytes). + virtual + unsigned long int + GetMemorySize() const = 0; - //! Define a container to get access to data assigned to mesh - struct TMeshValue - { - TValue myValue; //!< Keeps all values as one dimensional sequence + //! Gets number of mesh elements where the data assigned to. + vtkIdType + GetNbElem() const; + + //! Gets number of components of corresponding MED FIELD. + vtkIdType + GetNbComp() const; + + //! Gets number of Gauss Points. + vtkIdType + GetNbGauss() const; + size_t + size() const; + + protected: vtkIdType myNbElem; //!< Defines number of mesh elements where the data assigned to vtkIdType myNbComp; //!< Keeps number of components of corresponding MED FIELD vtkIdType myNbGauss; //!< Defines number of Gauss Points - vtkIdType myStep; //! Internal variable + vtkIdType myStep; //!< Internal variable + }; + typedef SharedPtr PMeshValue; - //! To intitilize the data strucutre - void - Init(vtkIdType theNbElem, - vtkIdType theNbGauss, - vtkIdType theNbComp); + + //--------------------------------------------------------------- + //! Define a container to get access to data assigned to mesh + template + class TTMeshValue: public virtual TMeshValueBase + { + public: + typedef TSlice TValueSlice; + typedef TCSlice TCValueSlice; + + typedef TVector TCValueSliceArr; + typedef TVector TValueSliceArr; + + virtual + const TValueType* + GetPointer() const = 0; + + virtual + TValueType* + GetPointer() = 0; //! To get assigned values first by Gauss Points and then by components (constant version) TCValueSliceArr - GetGaussValueSliceArr(vtkIdType theElemId) const; + GetGaussValueSliceArr(vtkIdType theElemId) const + { + TCValueSliceArr aValueSliceArr(this->myNbGauss); + vtkIdType anId = theElemId * this->myStep; + for(vtkIdType aGaussId = 0; aGaussId < this->myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TCValueSlice(this->GetPointer(), + this->size(), + std::slice(anId, this->myNbComp, 1)); + anId += this->myNbComp; + } + return aValueSliceArr; + } //! To get assigned values first by Gauss Points and then by components TValueSliceArr - GetGaussValueSliceArr(vtkIdType theElemId); + GetGaussValueSliceArr(vtkIdType theElemId) + { + TValueSliceArr aValueSliceArr(this->myNbGauss); + vtkIdType anId = theElemId * this->myStep; + for(vtkIdType aGaussId = 0; aGaussId < this->myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TValueSlice(this->GetPointer(), + this->size(), + std::slice(anId, this->myNbComp, 1)); + anId += this->myNbComp; + } + return aValueSliceArr; + } //! To get assigned values first by components and then by Gauss Points (constant version) TCValueSliceArr - GetCompValueSliceArr(vtkIdType theElemId) const; + GetCompValueSliceArr(vtkIdType theElemId) const + { + TCValueSliceArr aValueSliceArr(this->myNbComp); + vtkIdType anId = theElemId * this->myStep; + for(vtkIdType aCompId = 0; aCompId < this->myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TCValueSlice(this->GetPointer(), + this->size(), + std::slice(anId, this->myNbGauss, this->myNbComp)); + anId += 1; + } + return aValueSliceArr; + } //! To get assigned values first by components and then by Gauss Points TValueSliceArr - GetCompValueSliceArr(vtkIdType theElemId); + GetCompValueSliceArr(vtkIdType theElemId) + { + TValueSliceArr aValueSliceArr(this->myNbComp); + vtkIdType anId = theElemId * this->myStep; + for(vtkIdType aCompId = 0; aCompId < this->myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TValueSlice(this->GetPointer(), + this->size(), + std::slice(anId, this->myNbGauss, this->myNbComp)); + anId += 1; + } + return aValueSliceArr; + } //! Gets memory size used by the instance (bytes). virtual unsigned long int - GetMemorySize() const; + GetMemorySize() const + { + return this->size() * sizeof(TValueType); + } }; //--------------------------------------------------------------- - typedef std::map TGeom2Value; + //! Define a container to get access to data assigned to mesh + template + class TTMeshValueHolder: public virtual TTMeshValue + { + protected: + mutable TContainerType myContainer; //!< Keeps the mesh values container itself + + public: + //! To initilize the class instance + void + Init(vtkIdType theNbElem, + vtkIdType theNbGauss, + vtkIdType theNbComp, + const TContainerType& theContainer) + { + TMeshValueBase::Init(theNbElem, theNbGauss, theNbComp); + myContainer = theContainer; + } + }; + + + //--------------------------------------------------------------- + typedef std::map TGeom2MeshValue; + + class TGeom2Value: public virtual TBaseStructure + { + TGeom2MeshValue myGeom2MeshValue; + public: + + //! Gets mesh data for defined geometrical type (constant version) + const PMeshValue& + GetMeshValue(EGeometry theGeom) const; + + //! Gets mesh data for defined geometrical type + PMeshValue& + GetMeshValue(EGeometry theGeom); + + //! Gets container of the whole mesh data + TGeom2MeshValue& + GetGeom2MeshValue(); + + //! Gets container of the whole mesh data (constant version) + const TGeom2MeshValue& + GetGeom2MeshValue() const; + + //! Gets mesh data for the first geometry + PMeshValue + GetFirstMeshValue() const; + }; + + + //--------------------------------------------------------------- typedef std::map TGeom2NbGauss; //! Specialize TValForTime to provide VTK mapping for the entity @@ -932,14 +1077,24 @@ namespace VISU TValForTimeImpl(); + TGeom2MeshValue& + GetGeom2MeshValue(); + + const TGeom2MeshValue& + GetGeom2MeshValue() const; + //! Get mesh data for defined geometrical type (constant version) - const TMeshValue& + const PMeshValue& GetMeshValue(EGeometry theGeom) const; //! Get mesh data for defined geometrical type - TMeshValue& + PMeshValue& GetMeshValue(EGeometry theGeom); + //! Gets mesh data for the first geometry + PMeshValue + GetFirstMeshValue() const; + //! Get number of Gauss Points for defined geometrical type virtual int diff --git a/src/CONVERTOR/VISU_MedConvertor.cxx b/src/CONVERTOR/VISU_MedConvertor.cxx index d7a16ff1..449b0e30 100644 --- a/src/CONVERTOR/VISU_MedConvertor.cxx +++ b/src/CONVERTOR/VISU_MedConvertor.cxx @@ -742,11 +742,14 @@ namespace continue; TEntity aVEntity = MEDEntityToVTK(aMEntity); + vtkIdType aDataType = VTK_DOUBLE; + if(aFieldInfo->GetType() != MED::eFLOAT64) + aDataType = VTK_INT; PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity]; TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; PMEDField aField = aFieldMap[aFieldName](new TMEDField()); aField->myId = iField; - aField->InitArrays(aNbComp); + aField->Init(aNbComp, aDataType); aField->myEntity = aVEntity; aField->myName = aFieldName; aField->myMeshName = aMeshName; @@ -2709,7 +2712,7 @@ FillValForTime(MED::SharedPtr theTimeStampValue, PMEDSubProfile aSubProfile(anIter->second); TInt aNbElem = aSubProfile->myNbCells; - theField->myDataSize += aNbElem*aNbComp; + theField->myDataSize += aNbElem * aNbComp; if(aSubProfile->myStatus != eRemoveAll){ TInt aNbGauss = theValForTime->GetNbGauss(aEGeom); @@ -2720,27 +2723,16 @@ FillValForTime(MED::SharedPtr theTimeStampValue, "; aNbGauss = "<GetMeshValue(aEGeom); - aVMeshValue.Init(aNbElem,aNbGauss,aNbComp); + PMeshValue& aVMeshValue = theValForTime->GetMeshValue(aEGeom); + typedef typename TimeStampValueType::TElement TElement; + typedef TTMEDMeshValue TVMeshValue; + TVMeshValue* aMeshValue = new TVMeshValue(); MED::EGeometrieElement aMGeom = aSubProfile->myMGeom; - const typename TimeStampValueType::TTMeshValue& aMMeshValue = theTimeStampValue->GetMeshValue(aMGeom); - for(TInt iElem = 0; iElem < aNbElem; iElem++){ - TValueSliceArr aVValueSliceArr = aVMeshValue.GetGaussValueSliceArr(iElem); - typename TimeStampValueType::TTMeshValue::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetGaussValueSliceArr(iElem); - ADDMSG(MYVALUEDEBUG,"{"); - for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){ - TValueSlice& aVValueSlice = aVValueSliceArr[iGauss]; - const typename TimeStampValueType::TTMeshValue::TCValueSlice& aMValueSlice = aMValueSliceArr[iGauss]; - for(TInt iComp = 0; iComp < aNbComp; iComp++){ - aVValueSlice[iComp] = aMValueSlice[iComp]; - ADDMSG(MYVALUEDEBUG,aVValueSlice[iComp]<<" "); - } - ADDMSG(MYVALUEDEBUG,"| "); - } - ADDMSG(MYVALUEDEBUG,"} "); - } - ADDMSG(MYDEBUG,"\n"); + typedef typename TimeStampValueType::PTMeshValue PTMeshValue; + PTMeshValue aMeshValuePtr = theTimeStampValue->GetMeshValuePtr(aMGeom); + aMeshValue->Init(aNbElem, aNbGauss, aNbComp, aMeshValuePtr); + aVMeshValue.reset(aMeshValue); } } } diff --git a/src/CONVERTOR/VISU_MedConvertor.hxx b/src/CONVERTOR/VISU_MedConvertor.hxx index c66b2ade..7836ea5a 100644 --- a/src/CONVERTOR/VISU_MedConvertor.hxx +++ b/src/CONVERTOR/VISU_MedConvertor.hxx @@ -97,6 +97,27 @@ namespace VISU }; + //--------------------------------------------------------------- + template + struct TTMEDMeshValue: TTMeshValueHolder > > > + { + virtual + const TValueType* + GetPointer() const + { + return this->myContainer->GetPointer(); + } + + virtual + TValueType* + GetPointer() + { + return this->myContainer->GetPointer(); + } + }; + + //--------------------------------------------------------------- typedef std::map TObj2VTKID; diff --git a/src/CONVERTOR/VISU_TypeList.hxx b/src/CONVERTOR/VISU_TypeList.hxx new file mode 100644 index 00000000..1a09efc3 --- /dev/null +++ b/src/CONVERTOR/VISU_TypeList.hxx @@ -0,0 +1,96 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : VISU_ColoredPrs3dCache_i.hh +// Author : Oleg UVAROV +// Module : VISU + +#ifndef VISU_TypeList_HeaderFile +#define VISU_TypeList_HeaderFile + +namespace VISU +{ + namespace TL + { + //---------------------------------------------------------------------------- + template + struct TList + { + typedef T THead; + typedef U TTail; + }; + + template + struct TInt2Type + { + enum { value = v }; + }; + + struct TNullType {}; + + //---------------------------------------------------------------------------- + template + struct TTypeAt; + + template + struct TTypeAt, 0> + { + typedef THead TResult; + }; + + + template + struct TTypeAt, index> + { + typedef typename TTypeAt::TResult TResult; + }; + + //---------------------------------------------------------------------------- + template + struct TIndexOf; + + template + struct TIndexOf + { + enum { value = -1 }; + }; + + template + struct TIndexOf, T> + { + enum { value = 0 }; + }; + + template + struct TIndexOf, T> + { + private: + enum { temp = TIndexOf::value }; + public: + enum { value = temp == -1? -1 : 1 + temp }; + }; + + //---------------------------------------------------------------------------- + } +} + +#endif diff --git a/src/PIPELINE/VISU_Extractor.cxx b/src/PIPELINE/VISU_Extractor.cxx index 82eec5dc..f57c5219 100644 --- a/src/PIPELINE/VISU_Extractor.cxx +++ b/src/PIPELINE/VISU_Extractor.cxx @@ -30,25 +30,30 @@ #include #include -#include #include #include #include -using namespace std; - +//---------------------------------------------------------------------------- vtkStandardNewMacro(VISU_Extractor); -VISU_Extractor::VISU_Extractor() +//---------------------------------------------------------------------------- +VISU_Extractor +::VISU_Extractor() { myScalarMode = 1; } -VISU_Extractor::~VISU_Extractor() +//---------------------------------------------------------------------------- +VISU_Extractor +::~VISU_Extractor() {} -void VISU_Extractor::SetScalarMode(int theScalarMode) +//---------------------------------------------------------------------------- +void +VISU_Extractor +::SetScalarMode(int theScalarMode) { if(myScalarMode != theScalarMode){ myScalarMode = theScalarMode; @@ -56,62 +61,115 @@ void VISU_Extractor::SetScalarMode(int theScalarMode) } } -template void -execute(int theNbElems, - int theScalarMode, - TypeData* theInputData, - TypeData* theOutputData) + +//---------------------------------------------------------------------------- +template +void +Module2Scalars(vtkDataArray *theInputDataArray, + TValueType* theOutputPtr, + vtkIdType theNbOfTuples) +{ + vtkIdType aNbComp = theInputDataArray->GetNumberOfComponents(); + std::vector anArray(aNbComp < 3? 3: aNbComp); + for(vtkIdType aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++){ + theInputDataArray->GetTuple(aTupleId, &anArray[0]); + vtkFloatingPointType aVector[3] = {anArray[0], anArray[1], anArray[2]}; + vtkFloatingPointType aScalar = sqrt(aVector[0]*aVector[0] + + aVector[1]*aVector[1] + + aVector[2]*aVector[2]); + *theOutputPtr = TValueType(aScalar); + theOutputPtr++; + } +} + + +//---------------------------------------------------------------------------- +template +void +Component2Scalars(vtkDataArray *theInputDataArray, + TValueType* theInputPtr, + TValueType* theOutputPtr, + vtkIdType theNbOfTuples, + vtkIdType theComponentId) { - if(theNbElems < 1 ) + vtkIdType aNbComp = theInputDataArray->GetNumberOfComponents(); + for(vtkIdType aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++){ + *theOutputPtr = *(theInputPtr + theComponentId); + theInputPtr += aNbComp; + theOutputPtr++; + } +} + + +//---------------------------------------------------------------------------- +template void +ExecuteScalars(vtkIdType theNbOfTuples, + vtkIdType theScalarMode, + TDataSetAttributesType* theInputData, + TDataSetAttributesType* theOutputData) +{ + if(theNbOfTuples < 1) return; + vtkDataArray* aFieldArray = theInputData->GetArray("VISU_FIELD"); - if(vtkFloatArray *aFloatArray = dynamic_cast(aFieldArray)){ - int aNbComp = aFloatArray->GetNumberOfComponents(); - std::vector anArray(aNbComp < 3? 3: aNbComp); - // - vtkFloatArray *aScalars = vtkFloatArray::New(); - aScalars->SetNumberOfTuples(theNbElems); - aScalars->SetNumberOfComponents(1); - // - if(!theScalarMode){ - for(int anId = 0; anId < theNbElems; anId++){ - aFloatArray->GetTuple(anId,&anArray[0]); - vtkFloatingPointType aVector[3] = {anArray[0], anArray[1], anArray[2]}; - vtkFloatingPointType aScalar = sqrt(aVector[0]*aVector[0] + aVector[1]*aVector[1] + aVector[2]*aVector[2]); - aScalars->SetTuple1(anId,aScalar); - } - }else{ - for(int anId = 0; anId < theNbElems; anId++){ - aFloatArray->GetTuple(anId,&anArray[0]); - aScalars->SetTuple1(anId,anArray[theScalarMode - 1]); - } + vtkIdType anInputDataType = aFieldArray->GetDataType(); + vtkDataArray *anOutputScalars = vtkDataArray::CreateDataArray(anInputDataType); + anOutputScalars->SetNumberOfComponents(1); + anOutputScalars->SetNumberOfTuples(theNbOfTuples); + + void *anInputPtr = aFieldArray->GetVoidPointer(0); + void *anOutputPtr = anOutputScalars->GetVoidPointer(0); + + if(theScalarMode == 0){ + switch(anInputDataType){ + vtkTemplateMacro3(Module2Scalars, + aFieldArray, + (VTK_TT *)(anOutputPtr), + theNbOfTuples); + default: + break; + } + }else{ + switch(anInputDataType){ + vtkTemplateMacro5(Component2Scalars, + aFieldArray, + (VTK_TT *)(anInputPtr), + (VTK_TT *)(anOutputPtr), + theNbOfTuples, + theScalarMode - 1); + default: + break; } - theOutputData->SetScalars(aScalars); - aScalars->Delete(); } + + theOutputData->SetScalars(anOutputScalars); + anOutputScalars->Delete(); } -void VISU_Extractor::Execute(){ + +//---------------------------------------------------------------------------- +void VISU_Extractor::Execute() +{ vtkDataSet *input = this->GetInput(), *output = this->GetOutput(); output->CopyStructure(input); output->GetPointData()->CopyAllOff(); output->GetCellData()->CopyAllOff(); if(input->GetPointData()->GetNumberOfArrays()){ output->GetPointData()->CopyVectorsOn(); - int aNbElems = input->GetNumberOfPoints(); + vtkIdType aNbOfTuples = input->GetNumberOfPoints(); vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData(); if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) - execute(aNbElems,myScalarMode,inData,outData); + ExecuteScalars(aNbOfTuples, myScalarMode, inData, outData); else output->GetPointData()->CopyScalarsOn(); outData->PassData(inData); outData->AddArray(inData->GetArray("VISU_FIELD")); }else{ output->GetCellData()->CopyVectorsOn(); - int aNbElems = input->GetNumberOfCells(); + vtkIdType aNbOfTuples = input->GetNumberOfCells(); vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData(); if(inData->GetAttribute(vtkDataSetAttributes::VECTORS)) - execute(aNbElems,myScalarMode,inData,outData); + ExecuteScalars(aNbOfTuples, myScalarMode, inData, outData); else output->GetCellData()->CopyScalarsOn(); outData->PassData(inData); diff --git a/src/PIPELINE/VISU_FieldTransform.cxx b/src/PIPELINE/VISU_FieldTransform.cxx index 598a36e2..04ca4005 100644 --- a/src/PIPELINE/VISU_FieldTransform.cxx +++ b/src/PIPELINE/VISU_FieldTransform.cxx @@ -24,7 +24,6 @@ #include "VTKViewer_Transform.h" #include -#include #include #include #include @@ -32,10 +31,9 @@ static vtkFloatingPointType Tolerance = 1.0 / VTK_LARGE_FLOAT; -using namespace std; - vtkStandardNewMacro(VISU_FieldTransform); +//---------------------------------------------------------------------------- double VISU_FieldTransform ::Ident(double theArg) @@ -43,6 +41,7 @@ VISU_FieldTransform return theArg; } +//---------------------------------------------------------------------------- double VISU_FieldTransform ::Log10(double theArg) @@ -54,6 +53,7 @@ VISU_FieldTransform } +//---------------------------------------------------------------------------- VISU_FieldTransform ::VISU_FieldTransform() { @@ -64,6 +64,7 @@ VISU_FieldTransform myScalarRange[1] = -VTK_LARGE_FLOAT; } +//---------------------------------------------------------------------------- VISU_FieldTransform ::~VISU_FieldTransform() { @@ -71,24 +72,27 @@ VISU_FieldTransform } +//---------------------------------------------------------------------------- void VISU_FieldTransform ::Update() { - vtkSource::Update(); + Superclass::Update(); } +//---------------------------------------------------------------------------- unsigned long VISU_FieldTransform ::GetMTime() { unsigned long aTime = Superclass::GetMTime(); if(myTransform) - aTime = max(aTime,myTransform->GetMTime()); + aTime = std::max(aTime, myTransform->GetMTime()); return aTime; } +//---------------------------------------------------------------------------- void VISU_FieldTransform ::SetScalarTransform(TTransformFun theFunction) @@ -104,7 +108,11 @@ VISU_FieldTransform Modified(); } -void VISU_FieldTransform::SetSpaceTransform(VTKViewer_Transform* theTransform){ +//---------------------------------------------------------------------------- +void +VISU_FieldTransform +::SetSpaceTransform(VTKViewer_Transform* theTransform) +{ if(myTransform == theTransform) return; @@ -120,6 +128,7 @@ void VISU_FieldTransform::SetSpaceTransform(VTKViewer_Transform* theTransform){ } +//---------------------------------------------------------------------------- void VISU_FieldTransform ::SetScalarRange(vtkFloatingPointType theScalarRange[2]) @@ -136,6 +145,7 @@ VISU_FieldTransform Modified(); } +//---------------------------------------------------------------------------- void VISU_FieldTransform ::SetScalarMin(vtkFloatingPointType theValue) @@ -144,6 +154,7 @@ VISU_FieldTransform SetScalarRange(aScalarRange); } +//---------------------------------------------------------------------------- void VISU_FieldTransform ::SetScalarMax(vtkFloatingPointType theValue) @@ -152,84 +163,188 @@ VISU_FieldTransform SetScalarRange(aScalarRange); } +//---------------------------------------------------------------------------- +template +void +LinearTransformVectors(TValueType* theInputPtr, + TValueType* theOutputPtr, + vtkIdType theNbOfTuples, + vtkFloatingPointType theScale[3]) +{ + for(vtkIdType aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++){ + for(vtkIdType aComponentId = 0; aComponentId < 3; aComponentId++){ + *theOutputPtr = TValueType(*theInputPtr * theScale[aComponentId]); + theOutputPtr++; + theInputPtr++; + } + } +} + + +//---------------------------------------------------------------------------- +template +void +NonLinearTransformVectors(vtkDataArray *theInputVectors, + TValueType* theInputPtr, + TValueType* theOutputPtr, + vtkIdType theNbOfTuples, + vtkFloatingPointType theScale[3], + VISU_FieldTransform::TTransformFun theFunction, + vtkFloatingPointType theModifiedScalarMin, + vtkFloatingPointType theModifiedScalarDelta, + vtkFloatingPointType theSourceScalarMax) +{ + for(vtkIdType aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++){ + vtkFloatingPointType anInputVector[3]; + theInputVectors->GetTuple(aTupleId, anInputVector); + vtkFloatingPointType aMagnification = vtkMath::Norm(anInputVector); + if(aMagnification > Tolerance) + aMagnification = + ((*theFunction)(aMagnification) - theModifiedScalarMin) / + theModifiedScalarDelta * theSourceScalarMax / + aMagnification; + if(aMagnification < 0.0) + aMagnification = 0.0; + for(vtkIdType aComponentId = 0; aComponentId < 3; aComponentId++){ + *theOutputPtr = TValueType(*theInputPtr * aMagnification * theScale[aComponentId]); + theOutputPtr++; + theInputPtr++; + } + } +} + -template void -ExecVectors(VISU_FieldTransform::TTransformFun theFunction, - VTKViewer_Transform* theTransform, - vtkFloatingPointType theScalarRange[2], - int theNbOfTuples, - TypeData* theInputData, - TypeData* theOutputData) +//---------------------------------------------------------------------------- +template +void +ExecuteVectors(VISU_FieldTransform::TTransformFun theFunction, + VTKViewer_Transform* theTransform, + vtkFloatingPointType theScalarRange[2], + vtkIdType theNbOfTuples, + TDataSetAttributesType* theInputData, + TDataSetAttributesType* theOutputData) { - vtkDataArray *anInVectors = theInputData->GetVectors(); - if ( !anInVectors || theNbOfTuples < 1 ) + vtkDataArray *anInputVectors = theInputData->GetVectors(); + if(!anInputVectors || theNbOfTuples < 1) return; - vtkFloatArray *aNewVectors = vtkFloatArray::New(); - aNewVectors->SetNumberOfComponents(3); - aNewVectors->SetNumberOfTuples(theNbOfTuples); - vtkFloatingPointType aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])}; - vtkFloatingPointType aDelta = aScalarRange[1] - aScalarRange[0]; + + vtkFloatingPointType aScalarRange[2]; + aScalarRange[0] = (*theFunction)(theScalarRange[0]); + aScalarRange[1] = (*theFunction)(theScalarRange[1]); + + vtkFloatingPointType aScalarDelta = aScalarRange[1] - aScalarRange[0]; vtkFloatingPointType aScale[3] = {1.0, 1.0, 1.0}; - static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT; + if(theTransform){ aScale[0] = theTransform->GetScale()[0]; aScale[1] = theTransform->GetScale()[1]; aScale[2] = theTransform->GetScale()[2]; } + + vtkIdType anInputDataType = anInputVectors->GetDataType(); + vtkDataArray *anOutputVectors = vtkDataArray::CreateDataArray(anInputDataType); + anOutputVectors->SetNumberOfComponents(3); + anOutputVectors->SetNumberOfTuples(theNbOfTuples); + + void *anInputPtr = anInputVectors->GetVoidPointer(0); + void *anOutputPtr = anOutputVectors->GetVoidPointer(0); + if(theFunction == &(VISU_FieldTransform::Ident)){ - for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) { - vtkFloatingPointType anInVec[3]; - anInVectors->GetTuple(aTupleId,anInVec); - vtkFloatingPointType anNewVec[3]; - anNewVec[0] = anInVec[0]*aScale[0]; - anNewVec[1] = anInVec[1]*aScale[1]; - anNewVec[2] = anInVec[2]*aScale[2]; - aNewVectors->SetTuple(aTupleId,anNewVec); - } + switch(anInputDataType){ + vtkTemplateMacro4(LinearTransformVectors, + (VTK_TT *)(anInputPtr), + (VTK_TT *)(anOutputPtr), + theNbOfTuples, + aScale); + default: + break; + } }else{ - for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) { - vtkFloatingPointType anInVec[3]; - anInVectors->GetTuple(aTupleId,anInVec); - vtkFloatingPointType aMagn = vtkMath::Norm(anInVec); - if(aMagn > EPS) - aMagn = ((*theFunction)(aMagn) - aScalarRange[0]) / aDelta * theScalarRange[1] / aMagn; - if(aMagn < 0.0) - aMagn = 0.0; - vtkFloatingPointType anNewVec[3]; - anNewVec[0] = anInVec[0]*aMagn*aScale[0]; - anNewVec[1] = anInVec[1]*aMagn*aScale[1]; - anNewVec[2] = anInVec[2]*aMagn*aScale[2]; - aNewVectors->SetTuple(aTupleId,anNewVec); - } + switch(anInputDataType){ + vtkTemplateMacro9(NonLinearTransformVectors, + anInputVectors, + (VTK_TT *)(anInputPtr), + (VTK_TT *)(anOutputPtr), + theNbOfTuples, + aScale, + theFunction, + aScalarRange[0], + aScalarDelta, + theScalarRange[1]); + default: + break; + } } - theOutputData->SetVectors(aNewVectors); - aNewVectors->Delete(); + + theOutputData->SetVectors(anOutputVectors); + anOutputVectors->Delete(); } -template void -ExecScalars(VISU_FieldTransform::TTransformFun theFunction, - vtkFloatingPointType theScalarRange[2], - int theNbOfTuples, - TypeData* theInputData, - TypeData* theOutputData) + +//---------------------------------------------------------------------------- +template +void +NonLinearTransformScalars(vtkDataArray *theInputScalars, + TValueType* theInputPtr, + TValueType* theOutputPtr, + vtkIdType theNbOfTuples, + VISU_FieldTransform::TTransformFun theFunction, + vtkFloatingPointType theModifiedScalarMin) { - vtkDataArray *anInScalars = theInputData->GetScalars(); - if ( !anInScalars || theNbOfTuples < 1 ) - return; - vtkFloatArray *aNewScalars = vtkFloatArray::New(); - aNewScalars->SetNumberOfComponents(1); - aNewScalars->SetNumberOfTuples(theNbOfTuples); - vtkFloatingPointType aScalarRange[2] = {(*theFunction)(theScalarRange[0]),(*theFunction)(theScalarRange[1])}; - for (int aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++) { - vtkFloatingPointType aScalar = (*theFunction)(anInScalars->GetTuple1(aTupleId)); - if(aScalar < aScalarRange[0]) - aScalar = aScalarRange[0]; - aNewScalars->SetTuple1(aTupleId,aScalar); + for(vtkIdType aTupleId = 0; aTupleId < theNbOfTuples; aTupleId++){ + vtkFloatingPointType aScalar = (*theFunction)(vtkFloatingPointType(*theInputPtr)); + if(aScalar < theModifiedScalarMin) + aScalar = theModifiedScalarMin; + *theOutputPtr = TValueType(aScalar); + theOutputPtr++; + theInputPtr++; } - theOutputData->SetScalars(aNewScalars); - aNewScalars->Delete(); } + +//---------------------------------------------------------------------------- +template +void +ExecuteScalars(VISU_FieldTransform::TTransformFun theFunction, + vtkFloatingPointType theScalarRange[2], + vtkIdType theNbOfTuples, + TDataSetAttributesType* theInputData, + TDataSetAttributesType* theOutputData) +{ + vtkDataArray *anInputScalars = theInputData->GetScalars(); + if(!anInputScalars || theNbOfTuples < 1) + return; + + vtkFloatingPointType aScalarRange[2]; + aScalarRange[0] = (*theFunction)(theScalarRange[0]); + aScalarRange[1] = (*theFunction)(theScalarRange[1]); + + vtkIdType anInputDataType = anInputScalars->GetDataType(); + vtkDataArray *anOutputScalars = vtkDataArray::CreateDataArray(anInputDataType); + anOutputScalars->SetNumberOfComponents(1); + anOutputScalars->SetNumberOfTuples(theNbOfTuples); + + void *anInputPtr = anInputScalars->GetVoidPointer(0); + void *anOutputPtr = anOutputScalars->GetVoidPointer(0); + + switch(anInputDataType){ + vtkTemplateMacro6(NonLinearTransformScalars, + anInputScalars, + (VTK_TT *)(anInputPtr), + (VTK_TT *)(anOutputPtr), + theNbOfTuples, + theFunction, + aScalarRange[0]); + default: + break; + } + + theOutputData->SetScalars(anOutputScalars); + anOutputScalars->Delete(); +} + + +//---------------------------------------------------------------------------- void VISU_FieldTransform ::Execute() @@ -240,11 +355,31 @@ VISU_FieldTransform output->GetPointData()->CopyAllOff(); output->GetCellData()->CopyAllOff(); - ExecScalars(myFunction,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData()); - ExecVectors(myFunction,myTransform,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData()); - - ExecScalars(myFunction,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData()); - ExecVectors(myFunction,myTransform,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData()); + ExecuteScalars(myFunction, + myScalarRange, + input->GetNumberOfPoints(), + input->GetPointData(), + output->GetPointData()); + + ExecuteVectors(myFunction, + myTransform, + myScalarRange, + input->GetNumberOfPoints(), + input->GetPointData(), + output->GetPointData()); + + ExecuteScalars(myFunction, + myScalarRange, + input->GetNumberOfCells(), + input->GetCellData(), + output->GetCellData()); + + ExecuteVectors(myFunction, + myTransform, + myScalarRange, + input->GetNumberOfCells(), + input->GetCellData(), + output->GetCellData()); }else{ output->GetPointData()->CopyAllOn(); output->GetCellData()->CopyAllOn(); @@ -253,3 +388,6 @@ VISU_FieldTransform output->GetCellData()->PassData(input->GetCellData()); } } + + +//---------------------------------------------------------------------------- diff --git a/src/VISU_I/VISU_ColoredPrs3dFactory.hh b/src/VISU_I/VISU_ColoredPrs3dFactory.hh index 0deb370a..b36aec0c 100644 --- a/src/VISU_I/VISU_ColoredPrs3dFactory.hh +++ b/src/VISU_I/VISU_ColoredPrs3dFactory.hh @@ -43,27 +43,12 @@ #include "VISU_ScalarMap_i.hh" #include "VISU_ColoredPrs3d_i.hh" #include "VISU_Result_i.hh" +#include "VISU_TypeList.hxx" namespace VISU { namespace TL { - //---------------------------------------------------------------------------- - template - struct TList - { - typedef T THead; - typedef U TTail; - }; - - template - struct TInt2Type - { - enum { value = v }; - }; - - struct TNullType {}; - //---------------------------------------------------------------------------- typedef TList - struct TTypeAt; - - template - struct TTypeAt, 0> - { - typedef THead TResult; - }; - - - template - struct TTypeAt, index> - { - typedef typename TTypeAt::TResult TResult; - }; - - //---------------------------------------------------------------------------- - template - struct TIndexOf; - - template - struct TIndexOf - { - enum { value = -1 }; - }; - - template - struct TIndexOf, T> - { - enum { value = 0 }; - }; - - template - struct TIndexOf, T> - { - private: - enum { temp = TIndexOf::value }; - public: - enum { value = temp == -1? -1 : 1 + temp }; - }; - //---------------------------------------------------------------------------- template struct TColoredEnum2Type diff --git a/src/VISU_I/VISU_CorbaMedConvertor.cxx b/src/VISU_I/VISU_CorbaMedConvertor.cxx index d8af01b4..b0c15cd4 100644 --- a/src/VISU_I/VISU_CorbaMedConvertor.cxx +++ b/src/VISU_I/VISU_CorbaMedConvertor.cxx @@ -357,11 +357,11 @@ VISU_MEDFieldConvertor::Build() aMeshOnEntity->mySupport = aMEDSupport; if(aVEntity == NODE_ENTITY) - ::InitMeshOnEntity(aMesh,CELL_ENTITY,aMeshOnEntity); + ::InitMeshOnEntity(aMesh, CELL_ENTITY, aMeshOnEntity); else - ::InitMeshOnEntity(aMesh,NODE_ENTITY,aMeshOnEntity); + ::InitMeshOnEntity(aMesh, NODE_ENTITY, aMeshOnEntity); - ::GetCellsSize(aMesh,aMEDMesh,aVEntity); + ::GetCellsSize(aMesh, aMEDMesh, aVEntity); TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; PCField aField = aFieldMap[aFieldName.in()](new TCField()); @@ -369,9 +369,14 @@ VISU_MEDFieldConvertor::Build() aField->myName = aFieldName.in(); aField->myEntity = aVEntity; aField->myMeshName = aMeshName.in(); - aField->InitArrays(myField->getNumberOfComponents()); aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp; + vtkIdType aDataType = VTK_DOUBLE; + SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(myField); + if(aFieldDouble->_is_nil()) + aDataType = VTK_INT; + aField->Init(myField->getNumberOfComponents(), aDataType); + if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<myNbCells = "<myNbCells); }else @@ -858,9 +869,14 @@ VISU_MEDConvertor::Build(SALOMEDS::ChildIterator_ptr theTimeStampIterator) aField->myName = aFieldName.in(); aField->myEntity = aVEntity; aField->myMeshName = aMeshName.in(); - aField->InitArrays(aMEDField->getNumberOfComponents()); aField->myDataSize = aMeshOnEntity->myNbCells * aField->myNbComp; + vtkIdType aDataType = VTK_DOUBLE; + SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField); + if(aFieldDouble->_is_nil()) + aDataType = VTK_INT; + aField->Init(aMEDField->getNumberOfComponents(), aDataType); + aFieldMap[aFieldName.in()] = aField; if(MYDEBUG) @@ -1246,33 +1262,28 @@ VISU_MEDConvertor } -template -int -ImportField(TArray& theArray, +template +void +ImportField(TContainerType& theContainer, VISU::PCMesh theMesh, VISU::PCField theField, VISU::PCValForTime theValForTime, VISU::PCMeshOnEntity theMeshOnEntity) { - int aNbComp = theField->myNbComp; + typedef TTCMEDMeshValue TVMeshValue; + vtkIdType aNbComp = theField->myNbComp; if(theField->myEntity == NODE_ENTITY){ VISU::EGeometry aEGeom = VISU::ePOINT1; - int aNbGauss = theValForTime->GetNbGauss(aEGeom); + vtkIdType aNbGauss = theValForTime->GetNbGauss(aEGeom); vtkIdType aNbElem = theMesh->GetNbPoints(); if(MYDEBUG) MESSAGE("ImportField - aNbElem = "<GetMeshValue(VISU::ePOINT1); - aMeshValue.Init(aNbElem,aNbGauss,aNbComp); - for(int iElem = 0, anId = 0; iElem < aNbElem; iElem++){ - TValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem); - for(int iGauss = 0; iGauss < aNbGauss; iGauss++){ - TValueSlice& aValueSlice = aValueSliceArr[iGauss]; - for(int iComp = 0; iComp < aNbComp; iComp++){ - aValueSlice[iComp] = theArray[anId++]; - } - } - } + PMeshValue& aVMeshValue = theValForTime->GetMeshValue(VISU::ePOINT1); + TVMeshValue* aMeshValue = new TVMeshValue(); + aMeshValue->Init(aNbElem, aNbGauss, aNbComp, theContainer, 0); + aVMeshValue.reset(aMeshValue); }else{ SALOME_MED::medGeometryElement* aGeomElems; const TEntity& aVEntity = theField->myEntity; @@ -1280,7 +1291,7 @@ ImportField(TArray& theArray, for(int iGeom = 0; iGeom < iGeomEnd; iGeom++){ SALOME_MED::medGeometryElement aMGeom = aGeomElems[iGeom]; VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom); - int aNbGauss = theValForTime->GetNbGauss(aEGeom); + vtkIdType aNbGauss = theValForTime->GetNbGauss(aEGeom); const TCMeshOnEntity::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity->myCellsFirstIndex; TCMeshOnEntity::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aMGeom); if(aCellsFirstIndexIter != aCellsFirstIndex.end()){ @@ -1290,22 +1301,15 @@ ImportField(TArray& theArray, "; aIndexAndSize = {"<GetMeshValue(aEGeom); - aMeshValue.Init(aNbElem,aNbGauss,aNbComp); - for(int iElem = 0, anId = 0; iElem < aNbElem; iElem++, anId += aNbComp){ - TValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem); - for(int iGauss = 0; iGauss < aNbGauss; iGauss++){ - TValueSlice& aValueSlice = aValueSliceArr[iGauss]; - for(int iComp = 0; iComp < aNbComp; iComp++) - aValueSlice[iComp] = theArray[aStart+anId+iComp]; - } - } + vtkIdType aNbElem = aIndexAndSize.second; + vtkIdType aStart = aIndexAndSize.first * aNbComp; + PMeshValue& aVMeshValue = theValForTime->GetMeshValue(aEGeom); + TVMeshValue* aMeshValue = new TVMeshValue(); + aMeshValue->Init(aNbElem, aNbGauss, aNbComp, theContainer, aStart); + aVMeshValue.reset(aMeshValue); } } } - return 1; } int @@ -1329,13 +1333,13 @@ VISU_MEDConvertor if(!aFieldDouble->_is_nil()){ SALOME_MED::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE); if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<length()); - ::ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity); + ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity); } SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField); if(!aFieldInt->_is_nil()){ SALOME_MED::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE); if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<length()); - ::ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity); + ImportField(anArray,theMesh,theField,theValForTime,theMeshOnEntity); } anIDMapperFilter->myIsVTKDone = true; diff --git a/src/VISU_I/VISU_CorbaMedConvertor.hxx b/src/VISU_I/VISU_CorbaMedConvertor.hxx index ccd0e611..595d45d6 100644 --- a/src/VISU_I/VISU_CorbaMedConvertor.hxx +++ b/src/VISU_I/VISU_CorbaMedConvertor.hxx @@ -56,6 +56,41 @@ namespace VISU }; + //--------------------------------------------------------------- + template + struct TTCMEDMeshValue: TTMeshValueHolder + { + typedef TTMeshValueHolder TSuperClass; + vtkIdType myStartIndex; + + //! To initilize the class instance + void + Init(vtkIdType theNbElem, + vtkIdType theNbGauss, + vtkIdType theNbComp, + const TContainerType& theContainer, + vtkIdType theStartIndex) + { + TSuperClass::Init(theNbElem, theNbGauss, theNbComp, theContainer); + myStartIndex = theStartIndex; + } + + virtual + const TValueType* + GetPointer() const + { + return &(this->myContainer[myStartIndex]); + } + + virtual + TValueType* + GetPointer() + { + return &(this->myContainer[myStartIndex]); + } + }; + + //--------------------------------------------------------------- struct TCMesh: virtual TMeshImpl { -- 2.39.2