C++ main module for emicrom Package  1.0
EMM_VTK.hpp
Go to the documentation of this file.
1 #ifndef EMM_VTK_HPP
2 #define EMM_VTK_HPP
3 
4 #include "EMM_Exception.h"
5 
6 template<class T>
8  const tString& name,
9  const tBoolean& isUniform,
10  const tUIndex& n,
11  const tUSInt& dim,
12  const tUIndex& startIndex,
13  const tUIndex& endIndex,
14  const tUIndex& inc,
15  const T* array,
16  const tUIndex& nWeight,
17  const T* weight) const {
18 
19  // get the type of T
20  tString typeName=CORE_Object::getTypeName<T>();
21 
22  //translate in vtk type
23  tString vtkType=getVTKType(typeName);
24  //if no vtk type
25  if (vtkType.compare("")==0) return false;
26 
27 
28  //write the header
29  file << "<DataArray type=\""+vtkType+"\" Name=\""<<name<<"\" ";
30  //write the dimension of the field
31  if (dim>1) file <<"NumberOfComponents=\""<<dim<<"\" ";
32  //write the format
33  file <<"format=\"ascii\">"<<endl;
34 
35  //get the start index & end index
36  tUIndex i,end=endIndex,start=startIndex;
37  //end index null: write all the data
38  if (end==0) end=n;
39 
40  const T *pArray=null;
41  //weight
42  const T *pWeight=weight;
43 
44  //take the uniform weight
45  T w=(T)1;
46  if (pWeight!=null) w=(*pWeight);
47  tBoolean isWeightUniform=((pWeight==null) || (nWeight<=1));
48  if ((!isWeightUniform) && (nWeight!=n))
49  throw EMM_Exception("core",
50  "EMM_VTK::writeField",
51  "weight has incompatible size");
52 
53  //loop on coordinate
54  tUSInt k;
55  if (isUniform) {//field is uniform && weight is uniform
56  if (isWeightUniform) {
57  //get only the field at element 0
58  pArray=&array[0];
59  for(i=start;i<end;i+=inc){//loop on cell
60  for (k=0;k<dim;k++) {//loo pon coordinate
61  file<<toVTKNumber(vtkType,(w * (*pArray)))<<" ";
62  pArray++;
63  }
64  file<<endl;
65  pArray=&array[0];
66  }
67  } else {//uniform field && not uniform weight
68  pArray=&array[0];
69  pWeight=&weight[start];
70  for(i=start;i<end;i+=inc){//loop on cell
71  for (k=0;k<dim;k++) {//loop on coordinate
72  file<<toVTKNumber(vtkType,( (*pWeight) * (*pArray)))<<" ";
73  pArray++;
74  }
75  file<<endl;
76 
77  //next cell
78  pArray=&array[0];
79  pWeight++;
80  }
81  }
82  } else {//field is not uniform
83  pArray=&array[dim*start];
84  if (inc==1) {//increment between 2 elements = 1
85  if (isWeightUniform) {//weight is uniform
86  for(i=start;i<end;i++){//loop on cell
87  for (k=0;k<dim;k++) {//loop on coordinate
88  file<<toVTKNumber(vtkType,w*(*pArray))<<" ";
89  pArray++;
90  }//end loop on coordinate
91  file<<endl;
92  }//end loop on cell
93  } else { //weight is not uniform
94  pWeight=&weight[start];
95  for(i=start;i<end;i++){ //loop on cell
96  for (k=0;k<dim;k++) {//loop on ccoordinate
97  file<<toVTKNumber(vtkType,((*pWeight)*(*pArray)))<<" ";
98  pArray++;
99  }//end loop on coordinate
100  pWeight++;
101  file<<endl;
102  }//end loop on cell
103  }
104  } else if (inc>1) { //increment between 2 elements > 1
105  tUIndex ld=(inc-1)*dim;
106  if (isWeightUniform) {//field is not uniform && inc> 1 && weight is uniform
107  for(i=start;i<end;i+=inc){
108  for (k=0;k<dim;k++) {
109  file<<toVTKNumber(vtkType,(w*(*pArray)))<<" ";
110  pArray++;
111  }//end loop on coordinate
112  //next element
113  pArray+=ld;
114  file<<endl;
115  }//end loop on cell
116  } else {//field is not uniform && inc> 1 && weight is not uniform
117  pWeight=&weight[start];
118  for(i=start;i<end;i+=inc){
119  for (k=0;k<dim;k++) {
120  file<<toVTKNumber(vtkType,((*pWeight)*(*pArray)))<<" ";
121  pArray++;
122  }//end loop on coordinate
123 
124  //next element
125  pArray+=ld;
126  pWeight+=inc;
127  file<<endl;
128  }//end loop on cell
129  }
130  }//end inc>1
131  }//end field is not uniform
132 
133  file<<"</DataArray>"<<endl;
134 
135  return true;
136 } //end write field method
137 
138 
139 #endif
tBoolean writeField(ofstream &file, const tString &name, const tBoolean &isUniform, const tUIndex &n, const tUSInt &dim, const tUIndex &startIndex, const tUIndex &endIndex, const tUIndex &inc, const T *array) const
write an array of T type in file
Definition: EMM_VTK.h:186
#define tUSInt
Definition: types.h:28
#define tBoolean
Definition: types.h:139
#define null
Definition: types.h:144
tString getVTKType() const
return the VTK type of the template Type
Definition: EMM_VTK.h:76
#define tUIndex
Definition: types.h:126
#define tString
Definition: types.h:135
this class describes the exceptions raised for E-MicromM package
Definition: EMM_Exception.h:14
static T toVTKNumber(const tString &vtkType, const T &value)
turn the value into vtk type
Definition: EMM_VTK.h:231