1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 #include "VISU_MeshValue.hxx"
28 #include "VISU_Structures_impl.hxx"
29 #include "VISU_ConvertorUtils.hxx"
31 #include "VISU_PointCoords.hxx"
32 #include "VISU_TypeList.hxx"
34 #include <vtkUnstructuredGrid.h>
35 #include <vtkPolyData.h>
37 #include <vtkPointData.h>
38 #include <vtkCellData.h>
40 #include <vtkCharArray.h>
41 #include <vtkUnsignedCharArray.h>
42 #include <vtkShortArray.h>
43 #include <vtkUnsignedShortArray.h>
44 #include <vtkIntArray.h>
45 #include <vtkUnsignedIntArray.h>
46 #include <vtkLongArray.h>
47 #include <vtkUnsignedLongArray.h>
48 #include <vtkFloatArray.h>
49 #include <vtkDoubleArray.h>
55 static int MYDEBUG = 0;
57 static int MYDEBUG = 0;
62 //---------------------------------------------------------------
64 GenerateFieldName(const PFieldImpl& theField,
65 const PValForTimeImpl& theValForTime)
67 const VISU::TTime& aTime = theValForTime->myTime;
68 std::string aFieldName = theField->myMeshName + ", " + theField->myName + ": " +
69 VISU_Convertor::GenerateName(aTime);
74 //---------------------------------------------------------------
77 ::Init(vtkIdType theNbElem,
82 myNbGauss = theNbGauss;
84 myStep = theNbComp*theNbGauss;
112 return myNbElem * myStep;
118 //----------------------------------------------------------------------------
122 TList<unsigned short,
129 TNullType> > > > > > > > > >
133 //----------------------------------------------------------------------------
134 typedef TList<vtkCharArray,
135 TList<vtkUnsignedCharArray,
137 TList<vtkUnsignedShortArray,
139 TList<vtkUnsignedIntArray,
141 TList<vtkUnsignedLongArray,
143 TList<vtkDoubleArray,
144 TNullType> > > > > > > > > >
148 typedef TList<TInt2Type<VTK_CHAR>,
149 TList<TInt2Type<VTK_UNSIGNED_CHAR>,
150 TList<TInt2Type<VTK_SHORT>,
151 TList<TInt2Type<VTK_UNSIGNED_SHORT>,
152 TList<TInt2Type<VTK_INT>,
153 TList<TInt2Type<VTK_UNSIGNED_INT>,
154 TList<TInt2Type<VTK_LONG>,
155 TList<TInt2Type<VTK_UNSIGNED_LONG>,
156 TList<TInt2Type<VTK_FLOAT>,
157 TList<TInt2Type<VTK_DOUBLE>,
158 TNullType> > > > > > > > > >
162 //----------------------------------------------------------------------------
163 template <unsigned int type_enum>
164 struct TEnum2VTKBasicType
166 typedef typename TTypeAt<TVTKBasicTypeList, TIndexOf<TVTKBasicEnumList, TInt2Type<type_enum> >::value >::TResult TResult;
169 //----------------------------------------------------------------------------
170 template <unsigned int type_enum>
171 struct TEnum2VTKArrayType
173 typedef typename TTypeAt<TVTKArrayTypeList, TIndexOf<TVTKBasicEnumList, TInt2Type<type_enum> >::value >::TResult TResult;
176 //----------------------------------------------------------------------------
178 struct TVTKBasicType2Enum
180 typedef typename TTypeAt<TVTKBasicEnumList, TIndexOf<TVTKBasicTypeList, T>::value >::TResult TResult;
186 //----------------------------------------------------------------------------
187 template<int EDataType>
189 InitTimeStampOnProfile(const PUnstructuredGrid& theSource,
190 const PFieldImpl& theField,
191 const PValForTimeImpl& theValForTime,
192 const VISU::TEntity& theEntity);
195 //----------------------------------------------------------------------------
197 GetTimeStampOnProfile(const PUnstructuredGrid& theSource,
198 const PFieldImpl& theField,
199 const PValForTimeImpl& theValForTime,
200 const VISU::TEntity& theEntity)
202 vtkIdType aDataType = theField->GetDataType();
205 InitTimeStampOnProfile<VTK_DOUBLE>(theSource, theField, theValForTime, theEntity);
208 InitTimeStampOnProfile<VTK_FLOAT>(theSource, theField, theValForTime, theEntity);
211 InitTimeStampOnProfile<VTK_INT>(theSource, theField, theValForTime, theEntity);
214 InitTimeStampOnProfile<VTK_LONG>(theSource, theField, theValForTime, theEntity);
217 EXCEPTION(std::runtime_error,
218 "GetTimeStampOnProfile - handling unsupported data type - "<<aDataType);
223 //----------------------------------------------------------------------------
224 template<int EDataType>
225 struct TDataArrayHolder
227 typedef typename TL::TEnum2VTKArrayType<EDataType>::TResult TVTKDataArray;
228 typedef typename TL::TEnum2VTKBasicType<EDataType>::TResult TVTKBasicType;
229 TVTKDataArray* myDataArray;
231 TDataArrayHolder(TVTKDataArray* theDataArray):
232 myDataArray(theDataArray)
236 WritePointer(TVTKDataArray* theDataArray,
237 vtkIdType theTupleId,
238 TVTKBasicType* thePointer)
240 vtkIdType aNumberOfComponents = theDataArray->GetNumberOfComponents();
241 vtkIdType aPosition = theTupleId * aNumberOfComponents;
242 TVTKBasicType *aPtr = theDataArray->WritePointer(aPosition, aNumberOfComponents);
243 for(vtkIdType anId = 0; anId < aNumberOfComponents; anId++)
244 *aPtr++ = *thePointer++;
249 SetTuple(vtkIdType theTupleId,
250 TVTKBasicType* thePointer)
252 this->WritePointer(myDataArray, theTupleId, thePointer);
257 //----------------------------------------------------------------------------
258 template<int EDataType>
259 struct TDataArrayHolder2: TDataArrayHolder<EDataType>
261 typedef TDataArrayHolder<EDataType> TSuperClass;
262 typedef typename TSuperClass::TVTKDataArray TVTKDataArray;
263 typedef typename TSuperClass::TVTKBasicType TVTKBasicType;
264 TVTKDataArray* myDataArray2;
266 TDataArrayHolder2(TVTKDataArray* theDataArray,
267 TVTKDataArray* theDataArray2):
268 TSuperClass(theDataArray),
269 myDataArray2(theDataArray2)
274 SetTuple(vtkIdType theTupleId,
275 TVTKBasicType* thePointer)
277 this->WritePointer(this->myDataArray, theTupleId, thePointer);
278 this->WritePointer(this->myDataArray2, theTupleId, thePointer);
283 //----------------------------------------------------------------------------
284 template<int EDataType>
285 struct TTimeStampOnProfileInitArray
287 typedef typename TL::TEnum2VTKArrayType<EDataType>::TResult TVTKDataArray;
288 typedef typename TL::TEnum2VTKBasicType<EDataType>::TResult TVTKBasicType;
289 typedef TTMeshValue<TVTKBasicType> TMeshValue;
290 typedef MED::SharedPtr<TMeshValue> TMeshValuePtr;
292 typedef TDataArrayHolder<EDataType> TTDataArrayHolder;
293 typedef MED::SharedPtr<TTDataArrayHolder> PDataArrayHolder;
294 PDataArrayHolder myDataArrayHolder;
296 TTimeStampOnProfileInitArray(const PDataArrayHolder& theDataArrayHolder):
297 myDataArrayHolder(theDataArrayHolder)
301 Execute(const PFieldImpl& theField,
302 const PValForTimeImpl& theValForTime)
304 vtkIdType aNbComp = theField->myNbComp;
305 vtkIdType aSize = std::max(3, aNbComp);
306 TVector<TVTKBasicType> aDataValues(aSize);
308 const TGeom2MeshValue& aGeom2MeshValue = theValForTime->GetGeom2MeshValue();
309 TGeom2MeshValue::const_iterator anIter = aGeom2MeshValue.begin();
310 for(int aTupleId = 0; anIter != aGeom2MeshValue.end(); anIter++){
311 EGeometry aEGeom = anIter->first;
312 const TMeshValuePtr aMeshValue = anIter->second;
314 vtkIdType aNbElem = aMeshValue->GetNbElem();
315 vtkIdType aNbGauss = aMeshValue->GetNbGauss();
318 "- aEGeom = "<<aEGeom<<
319 "; aNbElem = "<<aNbElem<<
320 "; aNbGauss = "<<aNbGauss<<
323 for(vtkIdType iElem = 0; iElem < aNbElem; iElem++, aTupleId++){
324 typename TMeshValue::TCValueSliceArr aValueSliceArr = aMeshValue->GetCompValueSliceArr(iElem);
325 for(vtkIdType iComp = 0; iComp < aNbComp; iComp++){
326 const typename TMeshValue::TCValueSlice& aValueSlice = aValueSliceArr[iComp];
327 aDataValues[iComp] = TVTKBasicType();
328 for(vtkIdType iGauss = 0; iGauss < aNbGauss; iGauss++){
329 aDataValues[iComp] += aValueSlice[iGauss];
331 aDataValues[iComp] /= aNbGauss;
333 this->myDataArrayHolder->SetTuple(aTupleId, &aDataValues[0]);
340 //----------------------------------------------------------------------------
341 template<int EDataType>
343 InitTimeStampOnProfile(const PUnstructuredGrid& theSource,
344 const PFieldImpl& theField,
345 const PValForTimeImpl& theValForTime,
346 const VISU::TEntity& theEntity)
348 vtkIdType aNbTuples = theField->myDataSize / theField->myNbComp;
349 std::string aFieldName = VISU::GenerateFieldName(theField, theValForTime);
351 vtkDataSetAttributes* aDataSetAttributes;
353 case VISU::NODE_ENTITY :
354 aDataSetAttributes = theSource->GetPointData();
357 aDataSetAttributes = theSource->GetCellData();
360 typedef typename TL::TEnum2VTKArrayType<EDataType>::TResult TVTKDataArray;
361 TVTKDataArray *aSelectedDataArray = TVTKDataArray::New();
362 vtkIdType aNbComp = theField->myNbComp;
365 aSelectedDataArray->SetNumberOfComponents(1);
366 aDataSetAttributes->SetScalars(aSelectedDataArray);
369 aSelectedDataArray->SetNumberOfComponents(3);
370 aDataSetAttributes->SetVectors(aSelectedDataArray);
372 aSelectedDataArray->SetNumberOfTuples(aNbTuples);
373 aSelectedDataArray->SetName(aFieldName.c_str());
375 TVTKDataArray *aFullDataArray = TVTKDataArray::New();
376 aFullDataArray->SetNumberOfComponents(aNbComp);
377 aFullDataArray->SetNumberOfTuples(aNbTuples);
378 aFullDataArray->SetName("VISU_FIELD");
379 aDataSetAttributes->AddArray(aFullDataArray);
381 INITMSG(MYDEBUG,"InitTimeStampOnProfile "<<
382 "- theEntity = "<<theEntity<<
383 "; aNbTuples = "<<aNbTuples<<
384 "; aNbComp = "<<aNbComp<<
386 TTimerLog aTimerLog(MYDEBUG,"InitTimeStampOnProfile");
388 const TGeom2MeshValue& aGeom2MeshValue = theValForTime->GetGeom2MeshValue();
389 typedef typename TL::TEnum2VTKBasicType<EDataType>::TResult TVTKBasicType;
390 typedef TTMeshValue<TVTKBasicType> TMeshValue;
391 typedef MED::SharedPtr<TMeshValue> TMeshValuePtr;
393 typedef TDataArrayHolder<EDataType> TTDataArrayHolder;
394 typedef MED::SharedPtr<TTDataArrayHolder> PDataArrayHolder;
396 TMeshValuePtr aMeshValue = theValForTime->GetFirstMeshValue();
397 if(aGeom2MeshValue.size() == 1 && aMeshValue->GetNbGauss() == 1){
398 aFullDataArray->SetVoidArray(aMeshValue->GetPointer(),
401 INITMSG(MYDEBUG,"InitTimeStampOnProfile - aFullDataArray->SetVoidArray()"<<std::endl);
403 aSelectedDataArray->SetVoidArray(aMeshValue->GetPointer(),
406 INITMSG(MYDEBUG,"InitTimeStampOnProfile - aSelectedDataArray->SetVoidArray()"<<std::endl);
408 PDataArrayHolder aDataArrayHolder(new TTDataArrayHolder(aSelectedDataArray));
409 TTimeStampOnProfileInitArray<EDataType>(aDataArrayHolder).Execute(theField, theValForTime);
412 typedef TDataArrayHolder2<EDataType> TTDataArrayHolder2;
413 PDataArrayHolder aDataArrayHolder(new TTDataArrayHolder2(aSelectedDataArray, aFullDataArray));
414 TTimeStampOnProfileInitArray<EDataType>(aDataArrayHolder).Execute(theField, theValForTime);
417 aSelectedDataArray->Delete();
418 aFullDataArray->Delete();
422 //----------------------------------------------------------------------------
423 template<int EDataType>
425 InitTimeStampOnGaussMesh(const PPolyData& theSource,
426 const PFieldImpl& theField,
427 const PValForTimeImpl& theValForTime);
430 GetTimeStampOnGaussMesh(const PPolyData& theSource,
431 const PFieldImpl& theField,
432 const PValForTimeImpl& theValForTime)
434 vtkIdType aDataType = theField->GetDataType();
437 InitTimeStampOnGaussMesh<VTK_DOUBLE>(theSource, theField, theValForTime);
440 InitTimeStampOnGaussMesh<VTK_FLOAT>(theSource, theField, theValForTime);
443 InitTimeStampOnGaussMesh<VTK_INT>(theSource, theField, theValForTime);
446 InitTimeStampOnGaussMesh<VTK_LONG>(theSource, theField, theValForTime);
449 EXCEPTION(std::runtime_error,
450 "GetTimeStampOnGaussMesh - handling unsupported data type - "<<aDataType);
454 //----------------------------------------------------------------------------
455 template<int EDataType>
456 struct TTimeStampOnGaussMeshInitArray
458 typedef typename TL::TEnum2VTKArrayType<EDataType>::TResult TVTKDataArray;
459 typedef typename TL::TEnum2VTKBasicType<EDataType>::TResult TVTKBasicType;
460 typedef TTMeshValue<TVTKBasicType> TMeshValue;
461 typedef MED::SharedPtr<TMeshValue> TMeshValuePtr;
463 typedef TDataArrayHolder<EDataType> TTDataArrayHolder;
464 typedef MED::SharedPtr<TTDataArrayHolder> PDataArrayHolder;
465 PDataArrayHolder myDataArrayHolder;
467 TTimeStampOnGaussMeshInitArray(const PDataArrayHolder& theDataArrayHolder):
468 myDataArrayHolder(theDataArrayHolder)
472 Execute(const PFieldImpl& theField,
473 const PValForTimeImpl& theValForTime)
475 vtkIdType aNbComp = theField->myNbComp;
476 vtkIdType aSize = std::max(3, aNbComp);
477 TVector<TVTKBasicType> aDataValues(aSize);
479 const TGeom2MeshValue& aGeom2MeshValue = theValForTime->GetGeom2MeshValue();
481 PGaussMeshImpl aGaussMesh = theValForTime->myGaussMesh;
482 const TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
483 TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin();
484 for(int aTupleId = 0; anIter != aGeom2GaussSubMesh.end(); anIter++){
485 EGeometry aEGeom = anIter->first;
487 PGaussSubMeshImpl aGaussSubMesh = anIter->second;
488 if(!aGaussSubMesh->myIsDone)
491 TGeom2MeshValue::const_iterator anIter2 = aGeom2MeshValue.find(aEGeom);
492 if(anIter2 == aGeom2MeshValue.end()){
493 EXCEPTION(std::runtime_error,
494 "TTimeStampOnGaussMeshInitArray >> Can't find values for corresponding Gauss Points SubMesh");
496 TMeshValuePtr aMeshValue = anIter2->second;
497 vtkIdType aNbGauss = aMeshValue->GetNbGauss();
498 vtkIdType aNbElem = aMeshValue->GetNbElem();
503 const TPointCoords& aCoords = aGaussSubMesh->myPointCoords;
506 "- aEGeom = "<<aEGeom<<
507 "; aNbElem = "<<aNbElem<<
508 "; aNbGauss = "<<aNbGauss<<
509 "; aCoords.GetNbPoints() = "<<aCoords.GetNbPoints()<<
512 if(aCoords.GetNbPoints() == aNbElem*aNbGauss){
513 for(int iElem = 0; iElem < aNbElem; iElem++){
514 typename TMeshValue::TCValueSliceArr aValueSliceArr = aMeshValue->GetGaussValueSliceArr(iElem);
515 for(int iGauss = 0; iGauss < aNbGauss; iGauss++, aTupleId++){
516 const typename TMeshValue::TCValueSlice& aValueSlice = aValueSliceArr[iGauss];
517 for(int iComp = 0; iComp < aNbComp; iComp++){
518 aDataValues[iComp] = aValueSlice[iComp];
520 this->myDataArrayHolder->SetTuple(aTupleId, &aDataValues[0]);
524 for(int iElem = 0; iElem < aNbElem; iElem++, aTupleId++){
525 typename TMeshValue::TCValueSliceArr aValueSliceArr = aMeshValue->GetCompValueSliceArr(iElem);
526 for(int iComp = 0; iComp < aNbComp; iComp++){
527 const typename TMeshValue::TCValueSlice& aValueSlice = aValueSliceArr[iComp];
528 aDataValues[iComp] = TVTKBasicType();
529 for(int iGauss = 0; iGauss < aNbGauss; iGauss++){
530 aDataValues[iComp] += aValueSlice[iGauss];
532 aDataValues[iComp] /= aNbGauss;
534 this->myDataArrayHolder->SetTuple(aTupleId, &aDataValues[0]);
542 template<int EDataType>
544 InitTimeStampOnGaussMesh(const PPolyData& theSource,
545 const PFieldImpl& theField,
546 const PValForTimeImpl& theValForTime)
548 vtkIdType aNbTuples = theSource->GetNumberOfPoints();
549 std::string aFieldName = VISU::GenerateFieldName(theField, theValForTime);
551 vtkDataSetAttributes* aDataSetAttributes = theSource->GetPointData();
553 typedef typename TL::TEnum2VTKArrayType<EDataType>::TResult TVTKDataArray;
554 TVTKDataArray *aSelectedDataArray = TVTKDataArray::New();
555 vtkIdType aNbComp = theField->myNbComp;
558 aSelectedDataArray->SetNumberOfComponents(1);
559 aDataSetAttributes->SetScalars(aSelectedDataArray);
562 aSelectedDataArray->SetNumberOfComponents(3);
563 aDataSetAttributes->SetVectors(aSelectedDataArray);
565 aSelectedDataArray->SetNumberOfTuples(aNbTuples);
566 aSelectedDataArray->SetName(aFieldName.c_str());
568 TVTKDataArray *aFullDataArray = TVTKDataArray::New();
569 aFullDataArray->SetNumberOfComponents(aNbComp);
570 aFullDataArray->SetNumberOfTuples(aNbTuples);
571 aFullDataArray->SetName("VISU_FIELD");
572 aDataSetAttributes->AddArray(aFullDataArray);
574 INITMSG(MYDEBUG,"InitTimeStampOnGaussMesh "<<
575 "- aNbTuples = "<<aNbTuples<<
576 "; aNbComp = "<<aNbComp<<
578 TTimerLog aTimerLog(MYDEBUG,"InitTimeStampOnGaussMesh");
580 const TGeom2MeshValue& aGeom2MeshValue = theValForTime->GetGeom2MeshValue();
581 typedef typename TL::TEnum2VTKBasicType<EDataType>::TResult TVTKBasicType;
582 typedef TTMeshValue<TVTKBasicType> TMeshValue;
583 typedef MED::SharedPtr<TMeshValue> TMeshValuePtr;
585 typedef TDataArrayHolder<EDataType> TTDataArrayHolder;
586 typedef MED::SharedPtr<TTDataArrayHolder> PDataArrayHolder;
588 TMeshValuePtr aMeshValue = theValForTime->GetFirstMeshValue();
589 if(aGeom2MeshValue.size() == 1){
590 aFullDataArray->SetVoidArray(aMeshValue->GetPointer(),
593 INITMSG(MYDEBUG,"InitTimeStampOnGaussMesh - aFullDataArray->SetVoidArray()"<<std::endl);
594 if(aNbComp == 1 || aNbComp == 3){
595 aSelectedDataArray->SetVoidArray(aMeshValue->GetPointer(),
598 INITMSG(MYDEBUG,"InitTimeStampOnGaussMesh - aSelectedDataArray->SetVoidArray()"<<std::endl);
600 PDataArrayHolder aDataArrayHolder(new TTDataArrayHolder(aSelectedDataArray));
601 TTimeStampOnGaussMeshInitArray<EDataType>(aDataArrayHolder).Execute(theField, theValForTime);
604 typedef TDataArrayHolder2<EDataType> TTDataArrayHolder2;
605 PDataArrayHolder aDataArrayHolder(new TTDataArrayHolder2(aSelectedDataArray, aFullDataArray));
606 TTimeStampOnGaussMeshInitArray<EDataType>(aDataArrayHolder).Execute(theField, theValForTime);
609 aSelectedDataArray->Delete();
610 aFullDataArray->Delete();
614 //---------------------------------------------------------------