5 #ifndef vtkMaterialInterfaceUtilities_h 6 #define vtkMaterialInterfaceUtilities_h 20 using std::ostringstream;
34 void ClearVectorOfPointers(vector<T*>& V)
37 for (
size_t i = 0; i < n; ++i)
48 void ClearVectorOfVtkPointers(vector<T*>& V)
51 for (
size_t i = 0; i < n; ++i)
62 void ClearVectorOfArrayPointers(vector<T*>& V)
65 for (
size_t i = 0; i < n; ++i)
76 void ResizeVectorOfVtkPointers(vector<T*>& V,
int n)
78 ClearVectorOfVtkPointers(V);
81 for (
int i = 0; i < n; ++i)
88 void ResizeVectorOfArrayPointers(vector<T*>& V,
int nV,
int nA)
90 ClearVectorOfArrayPointers(V);
93 for (
int i = 0; i < nV; ++i)
100 void ResizeVectorOfVtkArrayPointers(vector<T*>& V,
int nComps,
vtkIdType nTups,
string name,
int nv)
102 ClearVectorOfVtkPointers(V);
105 for (
int i = 0; i < nv; ++i)
108 V[i]->SetNumberOfComponents(nComps);
109 V[i]->SetNumberOfTuples(nTups);
110 V[i]->SetName(name.c_str());
115 void ResizeVectorOfVtkArrayPointers(vector<T*>& V,
int nComps,
int nv)
117 ResizeVectorOfVtkArrayPointers(V, nComps, 0,
"", nv);
121 void ResizeVectorOfVtkArrayPointers(vector<T*>& V,
int nComps,
int nTups,
int nv)
123 ResizeVectorOfVtkArrayPointers(V, nComps, nTups,
"", nv);
128 inline void ReNewVtkPointer(T*& pv)
138 inline void NewVtkArrayPointer(T*& pv,
int nComps,
vtkIdType nTups, std::string name)
141 pv->SetNumberOfComponents(nComps);
142 pv->SetNumberOfTuples(nTups);
143 pv->SetName(name.c_str());
147 inline void ReNewVtkArrayPointer(T*& pv,
int nComps,
vtkIdType nTups, std::string name)
153 NewVtkArrayPointer(pv, nComps, nTups, name);
157 inline void ReNewVtkArrayPointer(T*& pv, std::string name)
159 ReNewVtkArrayPointer(pv, 1, 0, name);
163 inline void ReleaseVtkPointer(T*& pv)
165 assert(
"Attempted to release a 0 pointer." && pv != 0);
171 inline void CheckAndReleaseVtkPointer(T*& pv)
182 inline void CheckAndReleaseArrayPointer(T*& pv)
193 inline void CheckAndReleaseCArrayPointer(T*& pv)
204 inline void FillVector(vector<T>& V,
const T& v)
207 for (
size_t i = 0; i < n; ++i)
217 inline int CopyTuple(T* dest,
223 int srcIndex = nComps * srcCellIndex;
229 float* thisTuple =
dynamic_cast<vtkFloatArray*
>(src)->GetPointer(srcIndex);
230 for (
int q = 0;
q < nComps; ++
q)
232 dest[
q] =
static_cast<T
>(thisTuple[
q]);
238 double* thisTuple =
dynamic_cast<vtkDoubleArray*
>(src)->GetPointer(srcIndex);
239 for (
int q = 0;
q < nComps; ++
q)
241 dest[
q] =
static_cast<T
>(thisTuple[
q]);
247 int* thisTuple =
dynamic_cast<vtkIntArray*
>(src)->GetPointer(srcIndex);
248 for (
int q = 0;
q < nComps; ++
q)
250 dest[
q] =
static_cast<T
>(thisTuple[
q]);
257 for (
int q = 0;
q < nComps; ++
q)
259 dest[
q] =
static_cast<T
>(thisTuple[
q]);
264 assert(
"This data type is unsupported." && 0);
271 #ifdef vtkMaterialInterfaceFilterDEBUG 279 const int hostNameSize = 256;
280 char hostname[hostNameSize] = {
'\0' };
281 gethostname(hostname, hostNameSize);
283 const int hrpSize = 512;
284 char hrp[hrpSize] = {
'\0' };
285 sprintf(hrp,
"%s : %d : %d", hostname, myProcId, pid);
290 hrpBuffer =
new char[nProcs * hrpSize];
292 comm->
Gather(hrp, hrpBuffer, hrpSize, 0);
298 hrpFile.open(pidFileName.c_str());
299 char* thisHrp = hrpBuffer;
300 if (hrpFile.is_open())
302 for (
int procId = 0; procId < nProcs; ++procId)
304 hrpFile << thisHrp << endl;
312 for (
int procId = 0; procId < nProcs; ++procId)
314 cerr << thisHrp << endl;
324 string GetMemoryUsage(
int pid,
int line,
int procId)
326 ostringstream memoryUsage;
328 ostringstream statusFileName;
329 statusFileName <<
"/proc/" << pid <<
"/status";
331 statusFile.open(statusFileName.str().c_str());
332 if (statusFile.is_open())
334 const int cbufSize = 1024;
335 char cbuf[cbufSize] = {
'\0' };
336 while (statusFile.good())
338 statusFile.getline(cbuf, cbufSize);
340 if (
content.find(
"VmSize") != string::npos ||
content.find(
"VmRSS") != string::npos ||
341 content.find(
"VmData") != string::npos)
343 int tabStart =
content.find_first_of(
"\t ");
345 while (content[tabStart + tabSpan] ==
'\t' || content[tabStart + tabSpan] ==
' ')
349 string formattedContent =
350 content.substr(0, tabStart - 1) +
" " +
content.substr(tabStart + tabSpan);
351 memoryUsage <<
"[" << line <<
"] " << procId <<
" " << formattedContent << endl;
358 cerr <<
"[" << line <<
"] " << procId <<
" could not open " << statusFileName <<
"." << endl;
361 return memoryUsage.str();
365 void writeTuple(ostream& sout, T* tup,
int nComp)
373 sout <<
"(" << tup[0];
374 for (
int q = 1;
q < nComp; ++
q)
376 sout <<
", " << tup[
q];
384 sout <<
"Name: " << da.
GetName() << endl;
389 sout <<
"NumberOfComps: " << nComp << endl;
390 sout <<
"NumberOfTuples:" << nTup << endl;
393 sout <<
"{}" << endl;
399 writeTuple(sout, thisTup, nComp);
400 for (
int i = 1; i < nTup; ++i)
404 writeTuple(sout, thisTup, nComp);
411 ostream& operator<<(ostream& sout, vector<vtkDoubleArray*>& vda)
413 size_t nda = vda.size();
414 for (
size_t i = 0; i < nda; ++i)
416 sout <<
"[" << i <<
"]\n" << *vda[i] << endl;
421 ostream& operator<<(ostream& sout, vector<vector<int>>& vvi)
423 size_t nv = vvi.size();
424 for (
size_t i = 0; i < nv; ++i)
426 sout <<
"[" << i <<
"]{";
427 size_t ni = vvi[i].size();
434 for (
size_t j = 1; j < ni; ++j)
436 sout <<
"," << vvi[i][j];
443 ostream& operator<<(ostream& sout, vector<int>& vi)
446 size_t ni = vi.size();
453 for (
size_t j = 1; j < ni; ++j)
455 sout <<
"," << vi[j];
511 template <
typename TCnt,
typename TLabel>
512 void PrintHistogram(vector<TCnt>& bins, vector<TLabel>& binIds)
514 const int maxWidth = 40;
515 const size_t n = bins.size();
520 int maxBin = *max_element(bins.begin(), bins.end());
521 for (
size_t i = 0; i < n; ++i)
528 int wid = maxBin < maxWidth ? bins[i] : bins[i] * maxWidth / maxBin;
529 cerr <<
"{" << setw(12) << std::left << binIds[i] <<
"}*";
530 for (
int j = 1; j < wid; ++j)
534 cerr <<
"(" << bins[i] <<
")" << endl;
538 template <
typename TCnt>
539 void PrintHistogram(vector<TCnt>& bins)
542 const int n =
static_cast<int>(bins.size());
543 vector<int> binIds(n);
544 for (
int i = 0; i < n; ++i)
549 PrintHistogram(bins, binIds);
int Gather(const int *sendBuffer, int *recvBuffer, vtkIdType length, int destProcessId)
vtkIdType GetNumberOfTuples()
virtual int GetNumberOfProcesses()
virtual double * GetTuple(vtkIdType tupleIdx)=0
virtual int GetDataType()=0
int GetNumberOfComponents()
T * operator<<(T *LHS, const pqConnect &RHS)
Makes a Qt connection.
virtual int GetLocalProcessId()
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)