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 std::sprintf(&(base::tkeys[4*LEN_TKEYS]), "Gradient x-direction ");
00052 std::sprintf(&(base::tkeys[5*LEN_TKEYS]), "Gradient y-direction ");
00053 std::sprintf(&(base::tkeys[6*LEN_TKEYS]), "Gradient z-direction ");
00054 base::fkeys[0] = base::Grid->FKeys();
00055 base::fkeys[1] = base::Grid->FKeys();
00056 base::fkeys[2] = base::Grid->FKeys();
00057 base::fkeys[3] = base::Grid->FKeys();
00058 base::fkeys[4] = base::Grid->FKeys();
00059 base::fkeys[5] = base::Grid->FKeys();
00060 base::fkeys[6] = base::Grid->FKeys();
00061 base::ikeys[0] = 105; base::ikeys[1] = 115;
00062 base::ikeys[2] = 102; base::ikeys[3] = 70;
00063 base::ikeys[4] = 120; base::ikeys[5] = 121;
00064 base::ikeys[6] = 122;
00065 }
00066
00067 virtual int NKeys() const { return 7; }
00068
00069 virtual void SetScalCells(int key,float v[],int& offset,
00070 vector_block_type& DB, float* dx, bool* CompRead) {
00071 int idx=0;
00072 int keym1 = key-1;
00073 if (key==3 || key==4) {
00074 BeginFastIndex3(dat, DB.bbox(), DB.data(), VectorType);
00075 for_3 (i,j,k,DB.bbox(),DB.bbox().stepsize())
00076 v[idx+offset]= FastIndex3(dat,i,j,k)(0);
00077 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00078 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00079 idx++;
00080 end_for
00081 EndFastIndex3(dat);
00082 }
00083 offset+=idx;
00084 if (key>=4)
00085 std::cerr << &(base::tkeys[(key-1)*LEN_TKEYS])
00086 << " is NOT supported for Type=6. Use Type=1 instead!"
00087 << std::endl;
00088 }
00089
00090 virtual void SetScalNodes(int key,float v[],int& offset,
00091 vector_block_type& DB, const BBox& bbox,
00092 float* dx, bool* CompRead) {
00093 int idx=0;
00094 int keym1 = key-1;
00095 BeginFastIndex3(dat, DB.bbox(), DB.data(), VectorType);
00096 const Coords& step = bbox.stepsize();
00097 switch(key) {
00098 case 3:
00099 {
00100 for_3 (i,j,k,bbox,step)
00101 BBox AddOver(3,i-step(0),j-step(1),k-step(2),
00102 i,j,k,step(0),step(1),step(2));
00103 AddOver *= DB.bbox();
00104
00105 float c=0;
00106 v[idx+offset] = 0.0;
00107 for_3 (l, m, n, AddOver, step)
00108 if (FastIndex3(dat,l,m,n)(0) < FLT_MAX) {
00109 v[idx+offset] += FastIndex3(dat,l,m,n)(0);
00110 c += 1.0;
00111 }
00112 end_for
00113 if (c>0) v[idx+offset] /= c;
00114 else v[idx+offset] = FLT_MAX;
00115
00116 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00117 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00118 idx++;
00119 end_for
00120 break;
00121 }
00122
00123 case 4:
00124 {
00125 for_3 (i,j,k,bbox,step)
00126 BBox AddOver(3,i-step(0),j-step(1),k-step(2),
00127 i,j,k,step(0),step(1),step(2));
00128 AddOver *= DB.bbox();
00129
00130 data_block_type DBHelp(AddOver);
00131 BeginFastIndex3(help, DBHelp.bbox(), DBHelp.data(), DataType);
00132 for_3 (l, m, n, AddOver, step)
00133 FastIndex3(help,l,m,n) = FastIndex3(dat,l,m,n)(0);
00134 end_for
00135 EndFastIndex3(help);
00136 v[idx+offset] = base::SetScalGradNodes(DBHelp,dx);
00137
00138 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00139 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00140 idx++;
00141 end_for
00142 break;
00143 }
00144
00145 case 5:
00146 case 6:
00147 case 7:
00148 {
00149 for_3 (i,j,k,bbox,step)
00150 BBox AddOver(3,i-step(0),j-step(1),k-step(2),
00151 i,j,k,step(0),step(1),step(2));
00152 AddOver *= DB.bbox();
00153
00154 data_block_type DBHelp(AddOver);
00155 BeginFastIndex3(help, DBHelp.bbox(), DBHelp.data(), DataType);
00156 for_3 (l, m, n, AddOver, step)
00157 FastIndex3(help,l,m,n) = FastIndex3(dat,l,m,n)(0);
00158 end_for
00159 EndFastIndex3(help);
00160 v[idx+offset] = base::ScalDerivNodes(DBHelp,dx,key-5);
00161
00162 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00163 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00164 idx++;
00165 end_for
00166 break;
00167 }
00168
00169 default:
00170 break;
00171 }
00172 EndFastIndex3(dat);
00173 offset+=idx;
00174 }
00175 };
00176
00177
00178 #endif