void Tartet::Sizer(void) { dx = manager->CashedDx(); // // Current version of TARTET is restricted to cubic lattices real s = shpar[0]; // // Set XOFF (and IMIN,IMAX): minJx = -(int)(s * Sqrt(onex_ / (real)24.)); xoff = half_ - s * Sqrt(onex_ / (real)24.) - minJx; maxJx = minJx + (int)(s * Sqrt(twox_ / (real)3.) + half_) - 1; // // Set YOFF (and JMIN,JMAX): minJy = -(int)(s / Sqrt(12.)); yoff = half_ - s / Sqrt(12.) - minJy; maxJy = minJy + (int)(s * Sqrt(0.75) + half_) - 1; // // Set ZOFF (and KMIN,KMAX): Determine whether S is closest to even or odd int. (Temporarily let KMIN be int which S is closest to) minJz = (int)(s + half_); // // If KMIN is even, then ZOFF=0.5 // If KMIN is odd, then ZOFF=0. zoff = zero_; if (minJz % 2 == 0) zoff = half_; minJz = -(int)(half_ * s + zoff); maxJz = minJz + (int)(s + half_) - 1; AllocateArrays(maxJx - minJx + 1, maxJy - minJy + 1, maxJz - minJz + 1); }
//------------------------------------------------------------------------------ LagrangeInterpolator::LagrangeInterpolator(const std::string &name, Integer dim, Integer ord) : Interpolator (name, "LagrangeInterpolator", dim), order (ord), actualSize (0), beginIndex (0), endIndex (0), dataIndex (0), startPoint (0), lastX (-9.9999e75), x (NULL), y (NULL) { // Made bufferSize 10 times bigger than order, so that we can collect more // data to place requested ind parameter in the near to the center of the // interpolation range. requiredPoints = order + 1; bufferSize = requiredPoints * 10; if (bufferSize > MAX_BUFFER_SIZE) bufferSize = MAX_BUFFER_SIZE; #ifdef DEBUG_LAGRANGE_BUILD MessageInterface::ShowMessage ("LagrangeInterpolator() order=%d, requiredPoints=%d, bufferSize=%d\n", order, requiredPoints, bufferSize); #endif AllocateArrays(); }
void Target_Octahedron::Sizer(void) { dx = manager->CashedDx(); minJx = minJy = minJz = ihuge_; maxJx = maxJy = maxJz = -ihuge_; GenerateVertices(); GenerateNormals(); int nlong = (int)shpar[0]; real nlongHalf = nlong / (real)2.; // for(int jx=0; jx<=nlong; ++jx) { real x = (real)jx - nlongHalf; for(int jy=0; jy<=nlong; ++jy) { real y = (real)jy - nlongHalf; for(int jz=0; jz<=nlong; ++jz) { real z = (real)jz - nlongHalf; if (Check(x, y, z)) { InternalMinMax(jx, jy, jz); } } } } AllocateArrays(maxJx - minJx + 1, maxJy - minJy + 1, maxJz - minJz + 1); }
void Target_Dodecahedron::Sizer(void) { dx = manager->CashedDx(); minJx = minJy = minJz = ihuge_; maxJx = maxJy = maxJz = -ihuge_; GenerateVertices(); GenerateNormals(); int na = (int)vertices[5].data[0]; int nb = (int)vertices[6].data[1]; int nzz = (int)vertices[0].data[2]; for(int ix=-na; ix<=na; ++ix) { real x = (real)ix; for(int iy=-nb; iy<=nb; ++iy) { real y = (real)iy; for(int iz=-nzz; iz<=nzz; ++iz) { real z = (real)iz; bool bOk = Check(x, y, z); if (bOk) { InternalMinMax(ix, iy, iz); } } } } // AllocateArrays(maxJx - minJx + 1, maxJy - minJy + 1, maxJz - minJz + 1); }
/** **************************************************************************************************** \fn Matrix operator=( const Matrix &i_other ) \brief operator = of Matrix class \param i_other other Matrix \return Matrix \retval new assigned Matrix **************************************************************************************************** */ GameEngine::Math::Matrix &GameEngine::Math::Matrix::operator=( const Matrix &i_other ) { FUNCTION_START; if( this == &i_other ) { FUNCTION_FINISH; return *this; } else { if( (_u32Row != i_other._u32Row) || (_u32Column != i_other._u32Column) ) { this->~Matrix(); _u32Row = i_other._u32Row; _u32Column = i_other._u32Column; AllocateArrays(); } for( UINT32 i = 0; i < _u32Row; ++i ) { for( UINT32 j = 0; j < _u32Column; ++j ) _value[i][j] = i_other._value[i][j]; } } FUNCTION_FINISH; return *this; }
//------------------------------------------------------------------------------ void LagrangeInterpolator::CopyArrays(const LagrangeInterpolator &i) { Interpolator::CopyArrays(i); if (x == NULL) AllocateArrays(); for (Integer j = 0; j <= bufferSize; ++j) { x[j] = i.x[j]; memcpy( y[j], i.y[j], dimension*sizeof(Real)); } }
//------------------------------------------------------------------------------ LagrangeInterpolator::LagrangeInterpolator(const LagrangeInterpolator &li) : Interpolator (li), order (li.order), actualSize (li.actualSize), beginIndex (li.beginIndex), endIndex (li.endIndex), dataIndex (li.dataIndex), startPoint (li.startPoint), lastX (li.lastX), x (NULL), y (NULL) { bufferSize = li.bufferSize; AllocateArrays(); }
/** **************************************************************************************************** \fn Matrix( const Matrix &i_other ) \brief Copy constructor of Matrix class \param i_other other Matrix \return NONE **************************************************************************************************** */ GameEngine::Math::Matrix::Matrix( const Matrix &i_other ) : _u32Row( i_other._u32Row ), _u32Column( i_other._u32Column ) { FUNCTION_START; AllocateArrays(); for( UINT32 i = 0; i < _u32Row; ++i ) { for( UINT32 j = 0; j < _u32Column; ++j ) _value[i][j] = i_other._value[i][j]; } FUNCTION_FINISH; }
/** **************************************************************************************************** \fn Matrix( const UINT32 &i_u32Row, const UINT32 &i_u32Column ) \brief Matrix class constructor \param i_u32Row total row of matrix class \param i_u32Column total column of matrix class \return NONE **************************************************************************************************** */ GameEngine::Math::Matrix::Matrix( const UINT32 &i_u32Row, const UINT32 &i_u32Column ) : _u32Row( i_u32Row ), _u32Column( i_u32Column ) { FUNCTION_START; assert( _u32Row != 0 ); assert( _u32Column != 0 ); AllocateArrays(); for( UINT32 i = 0; i < _u32Row; ++i ) { for( UINT32 j = 0; j < _u32Column; ++j ) _value[i][j] = 0; } FUNCTION_FINISH; }
void Tarcyl::Sizer(void) { dx = manager->CashedDx(); switch((int)shpar[2]) { case 1: // Cylinder axis in x direction PreSizer(nint_(shpar[0] / dx.data[0]), nint_(shpar[1] / dx.data[1]), nint_(shpar[1] / dx.data[2])); break; case 2: // Cylinder axis in y direction PreSizer(nint_(shpar[1] / dx.data[0]), nint_(shpar[0] / dx.data[1]), nint_(shpar[1] / dx.data[2])); break; case 3: // Cylinder axis in z direction PreSizer(nint_(shpar[1] / dx.data[0]), nint_(shpar[1] / dx.data[1]), nint_(shpar[0] / dx.data[2])); break; default: break; } AllocateArrays(maxJx - minJx + 1, maxJy - minJy + 1, maxJz - minJz + 1); }
// Loads in Fet file. Also allocates storage for other arrays void KK::LoadData(const mxArray *FeaturesMatrix) { int p, i; float val; float max, min; // open file //sprintf(fname, "%s.fet.%d", FileBase, ElecNo); //fp = fopen_safe(fname, "r"); const int *sz = mxGetDimensions(FeaturesMatrix); nPoints = sz[1]; nDims = sz[0]; double *InputArray = mxGetPr(FeaturesMatrix); AllocateArrays(); // load data for (int k=0;k<nDims*nPoints;k++) Data[k] = (float)InputArray[k]; // normalize data so that range is 0 to 1: This is useful in case of v. large inputs for(i=0; i<nDims; i++) { //calculate min and max min = HugeScore; max=-HugeScore; for(p=0; p<nPoints; p++) { val = Data[p*nDims + i]; if (val > max) max = val; if (val < min) min = val; } // now normalize for(p=0; p<nPoints; p++) Data[p*nDims+i] = (Data[p*nDims+i] - min) / (max-min); } Output("Loaded %d data points of dimension %d.\n", nPoints, nDims); }
void Target_Frmfilpbc::Sizer(void) { Reader(); AllocateArrays(maxJx - minJx + 1, maxJy - minJy + 1, maxJz - minJz + 1); }
// Loads in Fet file. Also allocates storage for other arrays void KK::LoadData() { char fname[STRLEN]; char line[STRLEN]; int p, i, j; int nFeatures; // not the same as nDims! we don't use all features. FILE *fp; int status; float val; int UseLen; float max, min; // open file sprintf(fname, "%s.fet.%d", FileBase, ElecNo); fp = fopen_safe(fname, "r"); // count lines; nPoints=-1; // subtract 1 because first line is number of features while(fgets(line, STRLEN, fp)) { nPoints++; } // rewind file fseek(fp, 0, SEEK_SET); // read in number of features fscanf(fp, "%d", &nFeatures); // calculate number of dimensions UseLen = strlen(UseFeatures); nDims=0; for(i=0; i<nFeatures; i++) { nDims += (i<UseLen && UseFeatures[i]=='1'); } AllocateArrays(); // load data for (p=0; p<nPoints; p++) { j=0; for(i=0; i<nFeatures; i++) { status = fscanf(fp, "%f", &val); if (status==EOF) Error("Error reading feature file"); if (i<UseLen && UseFeatures[i]=='1') { Data[p*nDims + j] = val; j++; } } } fclose(fp); // normalize data so that range is 0 to 1: This is useful in case of v. large inputs for(i=0; i<nDims; i++) { //calculate min and max min = HugeScore; max=-HugeScore; for(p=0; p<nPoints; p++) { val = Data[p*nDims + i]; if (val > max) max = val; if (val < min) min = val; } // now normalize for(p=0; p<nPoints; p++) Data[p*nDims+i] = (Data[p*nDims+i] - min) / (max-min); } Output("Loaded %d data points of dimension %d.\n", nPoints, nDims); }
//------------------------------------------------------------------------------ void IAUFile::Initialize() { if (isInitialized) return; // Allocate buffer to store IAU2000/2006 data: AllocateArrays(); // Use FileManager::FindPath() for new file path implementation (LOJ: 2014.07.01) // Open IAU2000/2006 data file: // FileManager* fm = FileManager::Instance(); // std::string path = fm->GetPathname(FileManager::IAUSOFA_FILE); // std::string name = fm->GetFilename(FileManager::IAUSOFA_FILE); // iauFileName = path+name; // FILE* fpt = fopen(iauFileName.c_str(), "r"); FileManager *fm = FileManager::Instance(); iauFileName = fm->GetFilename(FileManager::IAUSOFA_FILE); iauFileNameFullPath = fm->FindPath(iauFileName, FileManager::IAUSOFA_FILE, true, true, true); // Check full path file if (iauFileNameFullPath == "") throw GmatBaseException("The IAU file '" + iauFileName + "' does not exist\n"); FILE* fpt = fopen(iauFileNameFullPath.c_str(), "r"); if (fpt == NULL) throw GmatBaseException("Error: GMAT cann't open '" + iauFileName + "' file!!!\n"); // Read IAU2000/2006 data from data file and store to buffer: Real t; Real XYs[3]; int c; Integer i; for (i= 0; (c = fscanf(fpt, "%lf %lf %lf %lf\n",&t,&XYs[0],&XYs[1],&XYs[2])) != EOF; ++i) { // expend the buffer size when it has no room to contain data: if (i >= tableSz) { // create a new buffer with a larger size: Integer new_size = tableSz*2; Real* ind = new Real[new_size]; Real** dep = new Real*[new_size]; // copy contain in the current buffer to the new buffer: memcpy(ind, independence, tableSz*sizeof(Real)); memcpy(dep, dependences, tableSz*sizeof(Real*)); for (Integer k=tableSz; k < new_size; ++k) dep[k] = NULL; // delete the current buffer and use the new buffer as the current buffer: delete independence; delete dependences; independence = ind; dependences = dep; tableSz = new_size; } // store data to buffer: independence[i] = t; if (dependences[i] == NULL) dependences[i] = new Real[dimension]; for (Integer j = 0; j < dimension; ++j) dependences[i][j] = XYs[j]; } fclose(fpt); pointsCount = i; // why "this->"? }
/// For creating an optimized version of the more complex/pointer-oriented E(ditable)-Mesh. bool Mesh::LoadDataFrom(const EMesh * otherMesh) { std::cout<<"\nLoadDataFrom mesh constructor begun..."; /// Deallocate as needed first? DeallocateArrays(); /// Nullify stuff. Nullify(); // Fetch numbers name = otherMesh->name; source = otherMesh->source; numVertices = otherMesh->vertices.Size(); numUVs = otherMesh->uvs.Size(); numNormals = otherMesh->normals.Size(); numFaces = otherMesh->faces.Size(); // If no normals, generate 1. bool generateNormals = false; if (numNormals == 0) { generateNormals = true; } // Allocate AllocateArrays(); /// Extract all actual data. for (int i = 0; i < otherMesh->vertices.Size(); ++i) { Vector3f data = *(Vector3f*)otherMesh->vertices[i]; vertices[i] = data; } // Load UVs for (int i = 0; i < otherMesh->uvs.Size(); ++i) { Vector2f data = *(Vector2f*)otherMesh->uvs[i]; uvs[i] = data; } for (int i = 0; i < otherMesh->normals.Size(); ++i) { Vector3f data = *(Vector3f*)otherMesh->normals[i]; normals[i] = data; } if (generateNormals) { numNormals = 1; normals[0] = Vector3f(0,1,0); } for (int i = 0; i < otherMesh->faces.Size(); ++i) { MeshFace & face = faces[i]; EFace * eFace = otherMesh->faces[i]; face.numVertices = eFace->vertices.Size(); face.AllocateArrays(); for (int j = 0; j < face.numVertices; ++j) { EVertex * vertex = eFace->vertices[j]; // Now the bothersome part, fetch the indices of the vertices.. int index = otherMesh->vertices.GetIndexOf(vertex); // Fetch UV if possible. EUV * uv = 0; uv = vertex->uvCoord; int uvIndex = 0; if (uv) { uvIndex = otherMesh->uvs.GetIndexOf(uv); } // .. and decrement it? or increment..? Nah. Should be 0-based! face.vertices[j] = index; int normalIndex = 0; ENormal * normal = eFace->normal; if (normal) normalIndex = otherMesh->normals.GetIndexOf(normal); face.normals[j] = normalIndex; face.uvs[j] = uvIndex; } } std::cout<<" loaded."; return true; }
/// Load from customized compressed data form. bool Mesh::LoadCompressedFrom(String compressedPath) { std::fstream file; file.open(compressedPath.c_str(), std::ios_base::in | std::ios_base::binary); if (!file.is_open()) return false; String about; int version; about.ReadFrom(file); file.read((char*)&version, sizeof(int)); if (version != MESH_CURRENT_VERSION) return false; this->name.ReadFrom(file); this->source.ReadFrom(file); assert(source.Length()); assert(name.Length()); // Write extra data so that they do not have to be re-calculated.? centerOfMesh.ReadFrom(file); file.read((char*)&radiusOrigo, sizeof(float)); file.read((char*)&triangulated, sizeof(bool)); // Write AABB data so that it is pre-loaded. if (!aabb) aabb = new AABB(); aabb->ReadFrom(file); // Write number of each specific array. file.read((char*)&numVertices, sizeof(int)); file.read((char*)&numUVs, sizeof(int)); file.read((char*)&numNormals, sizeof(int)); file.read((char*)&numFaces, sizeof(int)); // Allocate arrays. AllocateArrays(); // Then start writing the data of the arrays. int sizeOfVertex = sizeof(Vector3f); int sizeOfUV = sizeof(Vector2f); // Load 'em. int sizeOfP1 = sizeof(p1); int sizeOfP2 = sizeof(p2); int sizeOfP3 = sizeof(p3); Vector3f * vertexArrayPtr = vertices.GetArray(); int size = numVertices * sizeOfVertex; // Read data. for (int i = 0; i < numVertices; ++i) vertices[i].ReadFrom(file); for (int i = 0; i < numUVs; ++i) uvs[i].ReadFrom(file); for (int i = 0; i < numNormals; ++i) normals[i].ReadFrom(file); // Load all numFaces. for (int i = 0; i < numFaces; ++i) { MeshFace & mf = faces[i]; mf.ReadFrom(file); // mf.Print(); } this->CalculateUVTangents(); loadedFromCompactObj = true; return true; }
void Tarrec::Sizer(void) { dx = manager->CashedDx(); AllocateArrays((int)(shpar[0] / dx.data[0] + half_), (int)(shpar[1] / dx.data[1] + half_), (int)(shpar[2] / dx.data[2] + half_)); }