/////////////////////////////////////////////// // // Create a static flow field // Input: (float) vector data, minB, maxB // note this flow field can be a subfield so // minB[0/1/2] may not be zero, and maxB[0/1/2] // may not be the max of the entire field // // void OSUFlow::InitStaticFlowField(float* pData, VECTOR3 minB, VECTOR3 maxB) { int dimension[3], totalNum; dimension[0] = maxB[0]-minB[0]+1; dimension[1] = maxB[1]-minB[1]+1; dimension[2] = maxB[2]-minB[2]+1; totalNum = dimension[0] * dimension[1] * dimension[2]; // create field object Solution* pSolution; RegularCartesianGrid* pRegularCGrid; VECTOR3* pVector; VECTOR3** ppVector; pVector = new VECTOR3[totalNum]; for(int iFor = 0; iFor < totalNum; iFor++) pVector[iFor].Set(pData[iFor*3], pData[iFor*3+1], pData[iFor*3+2]); ppVector = new VECTOR3*[1]; ppVector[0] = pVector; pSolution = new Solution(ppVector, totalNum, 1); pRegularCGrid = new RegularCartesianGrid(dimension[0], dimension[1], dimension[2]); lMin = minB; lMax = maxB; //local data min/max range pRegularCGrid->SetBoundary(lMin, lMax); assert(pSolution != NULL && pRegularCGrid != NULL); flowField = new CVectorField(pRegularCGrid, pSolution, 1); if(!flowField->IsNormalized()) flowField->NormalizeField(true); }
void OSUFlow:: InitTimeVaryingFlowField(void) { FILE *fIn; FILE *fVecIn; int timesteps; char* filename = new char[100]; int dimension[3], totalNum, tStep; float** ppData = NULL; float* pData = NULL; VECTOR3** ppVector; Solution* pSolution; RegularCartesianGrid* pRegularCGrid; // load in data fIn = fopen(flowName, "r"); assert(fIn != NULL); fscanf(fIn, "%d", ×teps); ppData = new float*[timesteps]; ppVector = new VECTOR3*[timesteps]; for(int iFor = 0; iFor < timesteps; iFor++) { VECTOR3* pVector; fscanf(fIn, "%s", filename); fVecIn = fopen(filename, "rb"); fread(dimension, sizeof(int), 3, fVecIn); fread(&tStep, sizeof(int), 1, fVecIn); totalNum = dimension[0] * dimension[1] * dimension[2]; pData = new float[totalNum * 3]; fread(pData, sizeof(float), totalNum*3, fVecIn); fclose(fVecIn); pVector = new VECTOR3[totalNum]; for(int jFor = 0; jFor < totalNum; jFor++) pVector[jFor].Set(pData[jFor*3], pData[jFor*3+1], pData[jFor*3+2]); delete[] pData; ppVector[iFor] = pVector; } fclose(fIn); pSolution = new Solution(ppVector, totalNum, timesteps); pRegularCGrid = new RegularCartesianGrid(dimension[0], dimension[1], dimension[2]); // set the boundary of physical grid VECTOR3 minB, maxB; minB.Set(0.0, 0.0, 0.0); maxB.Set((float)dimension[0], (float)dimension[1], (float)dimension[2]); pRegularCGrid->SetBoundary(minB, maxB); assert(pSolution != NULL && pRegularCGrid != NULL); flowField = new CVectorField(pRegularCGrid, pSolution, timesteps); }
///////////////////////////////////////////////////////////////// // //Read the whole datafile and create a vectorfield object based on that // void OSUFlow::InitStaticFlowField(void) { FILE *fIn; int dimension[3], totalNum; float* pData = NULL; fIn = fopen(flowName, "rb"); assert(fIn != NULL); fread(dimension, sizeof(int), 3, fIn); //dimension[2]=2; totalNum = dimension[0] * dimension[1] * dimension[2]; pData = new float[totalNum * 3]; fread(pData, sizeof(float), totalNum*3, fIn); fclose(fIn); // ADD-BY-LEETEN 03/19/2010-BEGIN for(int i = 0; i < totalNum; i++) pData[3 * i + 2] = 0.0f; // ADD-BY-LEETEN 03/19/2010-END // create field object Solution* pSolution; RegularCartesianGrid* pRegularCGrid; VECTOR3* pVector; VECTOR3** ppVector; pVector = new VECTOR3[totalNum]; for(int iFor = 0; iFor < totalNum; iFor++) pVector[iFor].Set(pData[iFor*3], pData[iFor*3+1], pData[iFor*3+2]); delete[] pData; ppVector = new VECTOR3*[1]; ppVector[0] = pVector; pSolution = new Solution(ppVector, totalNum, 1); pRegularCGrid = new RegularCartesianGrid(dimension[0], dimension[1], dimension[2]); // set the boundary of physical grid gMin.Set(0.0, 0.0, 0.0); lMin.Set(0.0, 0.0, 0.0); gMax.Set((float)(dimension[0]-1), (float)(dimension[1]-1), (float)(dimension[2]-1)); lMax.Set((float)(dimension[0]-1), (float)(dimension[1]-1), (float)(dimension[2]-1)); pRegularCGrid->SetBoundary(gMin, gMax); assert(pSolution != NULL && pRegularCGrid != NULL); flowField = new CVectorField(pRegularCGrid, pSolution, 1); if(!flowField->IsNormalized()) flowField->NormalizeField(true); }
CVectorField* OSUFlow::CreateStaticFlowField(float *pData, int xdim, int ydim, int zdim, float* minB, float* maxB, int* minRealB, int* maxRealB) { CVectorField* field; Solution* pSolution; RegularCartesianGrid* pRegularCGrid; VECTOR3* pVector; VECTOR3** ppVector; VECTOR3 min_b, max_b; VECTOR4 realMin_b, realMax_b; pVector = (VECTOR3*)pData; ppVector = new VECTOR3*[1]; ppVector[0] = pVector; int totalNum = xdim*ydim*zdim; pSolution = new Solution(ppVector, totalNum, 1); pRegularCGrid = new RegularCartesianGrid(xdim, ydim, zdim); min_b[0] = minB[0]; min_b[1] = minB[1]; min_b[2] = minB[2]; max_b[0] = maxB[0]; max_b[1] = maxB[1]; max_b[2] = maxB[2]; realMin_b[0] = minRealB[0]; realMin_b[1] = minRealB[1]; realMin_b[2] = minRealB[2]; realMin_b[3] = minRealB[3]; realMax_b[0] = maxRealB[0]; realMax_b[1] = maxRealB[1]; realMax_b[2] = maxRealB[2]; realMax_b[3] = maxRealB[3]; pRegularCGrid->SetBoundary(min_b, max_b); pRegularCGrid->SetRealBoundary(realMin_b, realMax_b); assert(pSolution != NULL && pRegularCGrid != NULL); field = new CVectorField(pRegularCGrid, pSolution, 1); flowField = field; return(field); }
////////////////////////////////////////////////////////////////// // // ppData are assumed to contain the vector data of // max_t-min_t+1 time steps // // xdim, ydim, zdim are the resolutions of the data block // minB and maxB specify the actual physical bounds of the block // min_t and max_t are the time interval that this block represents // CVectorField* OSUFlow::CreateTimeVaryingFlowField(float** ppData, int xdim, int ydim, int zdim, float* minB, float* maxB, int* minRealB, int* maxRealB, int min_t, int max_t) { CVectorField* field; Solution* pSolution; RegularCartesianGrid* pRegularCGrid; VECTOR3** ppVector; VECTOR3 min_b, max_b; VECTOR4 realMin_b, realMax_b; int totalNum = xdim*ydim*zdim; numTimesteps = max_t-min_t+1; ppVector = (VECTOR3**)ppData; min_b[0] = minB[0]; min_b[1] = minB[1]; min_b[2] = minB[2]; max_b[0] = maxB[0]; max_b[1] = maxB[1]; max_b[2] = maxB[2]; realMin_b[0] = minRealB[0]; realMin_b[1] = minRealB[1]; realMin_b[2] = minRealB[2]; realMin_b[3] = minRealB[3]; realMax_b[0] = maxRealB[0]; realMax_b[1] = maxRealB[1]; realMax_b[2] = maxRealB[2]; realMax_b[3] = maxRealB[3]; // create the flow field now pSolution = new Solution(ppVector, totalNum, numTimesteps, min_t, max_t); pRegularCGrid = new RegularCartesianGrid(xdim, ydim, zdim); pRegularCGrid->SetBoundary(min_b, max_b); pRegularCGrid->SetRealBoundary(realMin_b, realMax_b); assert(pSolution != NULL && pRegularCGrid != NULL); field = new CVectorField(pRegularCGrid, pSolution, numTimesteps, min_t); flowField = field; return(field); }