00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef AMROC_SCALAREVALUATOR_H
00010 #define AMROC_SCALAREVALUATOR_H
00011
00019 #include <iostream>
00020 #include <cstdio>
00021 #include <cfloat>
00022
00023 #include "Evaluator.h"
00024
00031 template <class VectorType>
00032 class ScalarEvaluator : public Evaluator<VectorType> {
00033 typedef Evaluator<VectorType> base;
00034 typedef typename VectorType::InternalDataType DataType;
00035
00036 public:
00037 typedef typename base::vector_block_type vector_block_type;
00038 typedef typename base::data_block_type data_block_type;
00039
00040 ScalarEvaluator() : base() {
00041 std::sprintf(base::title,"Scalar function");
00042 }
00043
00044 virtual void SetUp(VisualGridBase *gr) {
00045 EvaluatorBase::SetUp(gr);
00046
00047 std::sprintf(&(base::tkeys[0*LEN_TKEYS]), "Distribution ");
00048 std::sprintf(&(base::tkeys[1*LEN_TKEYS]), "Levels ");
00049 std::sprintf(&(base::tkeys[2*LEN_TKEYS]), "Function ");
00050 std::sprintf(&(base::tkeys[3*LEN_TKEYS]), "Schl.-Plot Function ");
00051 base::fkeys[0] = base::Grid->FKeys();
00052 base::fkeys[1] = base::Grid->FKeys();
00053 base::fkeys[2] = base::Grid->FKeys();
00054 base::fkeys[3] = base::Grid->FKeys();
00055 base::ikeys[0] = 105; base::ikeys[1] = 115;
00056 base::ikeys[2] = 102; base::ikeys[3] = 70;
00057 }
00058
00059 virtual int NKeys() const { return 4; }
00060
00061 virtual void SetScalCells(int key,float v[],int& offset,
00062 vector_block_type& DB, float* dx, bool* CompRead) {
00063 int idx=0;
00064 int keym1 = key-1;
00065 if (key==3 || key==4) {
00066 BeginFastIndex3(dat, DB.bbox(), DB.data(), VectorType);
00067 for_3 (i,j,k,DB.bbox(),DB.bbox().stepsize())
00068 v[idx+offset]= FastIndex3(dat,i,j,k)(0);
00069 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00070 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00071 idx++;
00072 end_for
00073 EndFastIndex3(dat);
00074 }
00075 offset+=idx;
00076 if (key==4)
00077 std::cerr << &(base::tkeys[3*LEN_TKEYS])
00078 << " is NOT supported for Type=6. Use Type=1 instead!"
00079 << std::endl;
00080 }
00081
00082 virtual void SetScalNodes(int key,float v[],int& offset,
00083 vector_block_type& DB, const BBox& bbox,
00084 float* dx, bool* CompRead) {
00085 int idx=0;
00086 int keym1 = key-1;
00087 BeginFastIndex3(dat, DB.bbox(), DB.data(), VectorType);
00088 const Coords& step = bbox.stepsize();
00089 switch(key) {
00090 case 3:
00091 {
00092 for_3 (i,j,k,bbox,step)
00093 BBox AddOver(3,i-step(0),j-step(1),k-step(2),
00094 i,j,k,step(0),step(1),step(2));
00095 AddOver *= DB.bbox();
00096
00097 float c=0;
00098 v[idx+offset] = 0.0;
00099 for_3 (l, m, n, AddOver, step)
00100 if (FastIndex3(dat,l,m,n)(0) < FLT_MAX) {
00101 v[idx+offset] += FastIndex3(dat,l,m,n)(0);
00102 c += 1.0;
00103 }
00104 end_for
00105 if (c>0) v[idx+offset] /= c;
00106
00107 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00108 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00109 idx++;
00110 end_for
00111 break;
00112 }
00113
00114 case 4:
00115 {
00116 for_3 (i,j,k,bbox,step)
00117 BBox AddOver(3,i-step(0),j-step(1),k-step(2),
00118 i,j,k,step(0),step(1),step(2));
00119 AddOver *= DB.bbox();
00120
00121 data_block_type DBHelp(AddOver);
00122 BeginFastIndex3(help, DBHelp.bbox(), DBHelp.data(), DataType);
00123 for_3 (l, m, n, AddOver, step)
00124 FastIndex3(help,l,m,n) = FastIndex3(dat,l,m,n)(0);
00125 end_for
00126 EndFastIndex3(help);
00127 v[idx+offset] = base::SetScalGradNodes(DBHelp,dx);
00128
00129 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00130 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00131 idx++;
00132 end_for
00133 break;
00134 }
00135 default:
00136 break;
00137 }
00138 EndFastIndex3(dat);
00139 offset+=idx;
00140 }
00141 };
00142
00143
00144 #endif