// Define an average error. It's an distributed error over the mesh. * //eq. 4.24 e 3.2.1 (p�g 32) do algoritmo - tese de Filipe void ErrorAnalysis::calculate_AvgError(int nelem, double tol, bool singularity){ tol = .01; double SGN = (singularity)?getSmoothedGradNorm_Singularity():getSmoothedGradNorm(); countElements(nelem,singularity); double numElements = (double)(singularity)?getNumElements_Singularity():nelem; double avgError = (numElements)?(tol*( SGN/sqrt(numElements))):.0; if (singularity){ setAverageError_Singularity(avgError); } else{ setAverageError(avgError); } // cout << "\nSGN: " << SGN << endl; // cout << "singularity: " << singularity << "\n"; // cout << "numElements: " << numElements << endl; // cout << "tol: " << tol << endl; // cout << "avgError: " << avgError << "\n\n"; }
void CppRtf_Container_Header::render() { CppRtf_Writer_Interface* stream = m_rtf->getWriter(); if (m_offsetHeight>-1) { stream->write("\\\\" + this->getRtfType() + 'y' + cppstring::numtostr(CppRtf_Unit::getUnitInTwips(m_offsetHeight))); } // stream->write("{\\\\" + this->getTypeAsRtfCode() + " ");//TODO: разобраться stream->write("{\\" + this->getTypeAsRtfCode() + " "); CppRtf_Container_Base::render(); int count = countElements(); if(count>0){ BaseElement *last = this->getElements().at(count-1); if(last->instanceOf<CppRtf_Element*>()){ stream->write("\\par"); } } stream->write("}\r\n"); }
int main(){ int menu, data; circularlist *head, *tail, *manipulation; do{ printf("\nCircular_Lists_Exercise\n\n1 - Element Adition..\n2 - Elemente Exclusion..\n3 - Number of Elements..\n0 - Exit..\n"); scanf("%d", &menu); printf("\033[H\033[J"); //Clean Linux Terminal switch(menu){ case 1: // Adicionar Conjunto if(head == NULL){ // Não há conjuntos criado; manipulation = addElement(head); head = manipulation; tail = head; printf("\nFirst element added!\n"); printf("Indice: %d\n", manipulation->indice); } else{ // Um ou mais conjuntos criado; manipulation = addElement(head); tail = manipulation; printf("\nElement added!\n"); printf("Indice: %d\n", manipulation->indice); } break; break; case 2: break; case 3: data = countElements(head); printf("Number of elements created: %d\n", data); break; } }while(menu != 0); }
ModelObj::PrimitiveType primitiveType(const std::string command, const std::string in, const int currentLine) { const int count = countElements(in); ModelObj::PrimitiveType result = (ModelObj::PrimitiveType)-1; if ("p" == command) { if (0 >= count) { printf("Too few (%d) indices for type point (Line %d).\n", count, currentLine); } else { result = ModelObj::POINTS; } } else if ("l" == command) { if (2 > count) { printf("Too few (%d) indices for type line (Line %d).\n", count, currentLine); } else if (2 == count) { result = ModelObj::LINES; } else { result = ModelObj::LINE_STRIP; } } else if ("f" == command) { if (3 > count) { printf("Too few (%d) indices for type face (Line %d).\n", count, currentLine); } else if (3 == count) { result = ModelObj::TRIANGLES; } else if (4 == count) { result = ModelObj::QUADS; } else { result = ModelObj::POLYGON; } } return result; }
std::vector<ModelObj::Mesh>::iterator meshCommandAllocate(std::vector<ModelObj::Model>::iterator modelIter, std::vector<ModelObj::Mesh>::iterator meshIter, const std::string command, const std::string content, const int currentLine) { //count elements in content const int count = countElements(content); //check what type the face has ModelObj::PrimitiveType foundType = primitiveType(command, content, currentLine); //compare to type of current mesh if (-1 >= meshIter->primitiveType) { //if the current mesh has a bad primitive type this means it is uninitialized. set it meshIter->primitiveType = foundType; } else if (foundType != meshIter->primitiveType || foundType == ModelObj::LINE_STRIP || foundType == ModelObj::POLYGON) { //the mesh already has a mesh type, but it isn't the same, start a new point mesh //if it is LINE_STRIP or POLYGON we need to start a new mesh anyway, //because otherwise the line strips or polygons would be connected... ModelObj::Mesh newMesh; newMesh.primitiveType = foundType; modelIter->meshes.push_back(newMesh); meshIter = modelIter->meshes.begin() + modelIter->meshes.size() - 1; } meshIter->nrOfIndices += count; meshIter->nrOfPrimitives++; return meshIter; }
std::vector<ModelObj::Mesh>::iterator meshCommandRead(std::vector<ModelObj::Model>::iterator modelIter, std::vector<ModelObj::Mesh>::iterator meshIter, const std::string command, const std::string content, const int currentLine) { //count elements in content const int count = countElements(content); //check what type the face has ModelObj::PrimitiveType foundType = primitiveType(command, content, currentLine); //compare to type of current mesh if (foundType != meshIter->primitiveType || foundType == ModelObj::LINE_STRIP || foundType == ModelObj::POLYGON) { //the mesh already has a mesh type, but it isn't the same, switch to next mesh //if it is LINE_STRIP or POLYGON we need to switch to a new mesh anyway, //because otherwise the line strips or polygons would be connected... meshIter++; } //read data from command //create stream object from string std::istringstream cstream(content); while (!cstream.eof()) { //retrieve first element std::string element; cstream >> element; //count how many parts (vertex/texcoord/normal) this has. all following elements have to have the same //no '/' --> only vertex index //one '/' --> vertex and texture index //one "//" --> vertex and normal index //two '/' --> vertex, texture and normal index bool hasNormals = false; bool hasTextures = false; if (element.find("//") != std::string::npos) { hasNormals = true; } else if (element.find("/") != std::string::npos) { hasTextures = true; if (element.find("/") != element.rfind("/")) { hasNormals = true; } } //now we can allocate the index array as now we know which elements actually exist bool wasAllocation = false; if (NULL == meshIter->vertexIndices) { meshIter->vertexIndices = new int[meshIter->nrOfIndices]; wasAllocation = true; } if (hasNormals) { if (NULL == meshIter->normalIndices) { meshIter->normalIndices = new int[meshIter->nrOfIndices]; wasAllocation = true; } } if (hasTextures) { if (NULL == meshIter->textureIndices) { meshIter->textureIndices = new int[meshIter->nrOfIndices]; wasAllocation = true; } } if (wasAllocation) { //this is the first element of the mesh, clear counters meshIter->nrOfIndices = 0; meshIter->nrOfPrimitives = 0; } //now get elements from stream cstream.clear(); cstream.seekg(0, std::ios::beg); while (!cstream.eof()) { int value = 0; cstream >> element; std::istringstream estream(element); //get vertex index estream >> value; meshIter->vertexIndices[meshIter->nrOfIndices] = value - 1; //if this has a texture coordinate read it if (hasTextures) { //discard '/' estream.ignore(1, '/'); //read texture coord estream >> value; meshIter->textureIndices[meshIter->nrOfIndices] = value - 1; if (hasNormals) { //discard '/' estream.ignore(1, '/'); //read normal estream >> value; meshIter->normalIndices[meshIter->nrOfIndices] = value - 1; } } else { if (hasNormals) { //discard '//' estream.ignore(1, '/'); estream.ignore(1, '/'); //read normal estream >> value; meshIter->normalIndices[meshIter->nrOfIndices] = value - 1; } } meshIter->nrOfIndices++; } }
istream& GenericKAnimFile::load(istream& in, int verbosity) { if(verbosity >= 1) { cout << "Loading anim file information..." << endl; } uint32_t magic; io.raw_read_integer(in, magic); if(!in || magic != MAGIC_NUMBER) { throw(KToolsError("Attempt to read a non-anim file as anim.")); } io.raw_read_integer(in, version); if(version & 0xffff) { io.setNativeSource(); } else { io.setInverseNativeSource(); io.reorder(version); } if(verbosity >= 2) { cout << "Got anim version " << version << "." << endl; } versionRequire(); uint32_t numelements; uint32_t numframes; uint32_t numevents; uint32_t numanims; io.read_integer(in, numelements); io.read_integer(in, numframes); io.read_integer(in, numevents); io.read_integer(in, numanims); setAnimCount(numanims); if(verbosity >= 1) { cout << "Loading " << numanims << " animations..." << endl; } if(!loadPre_all_anims(in, verbosity)) { throw(KToolsError("Failed to load animations.")); } if(countElements() != numelements) { throw(KToolsError("Corrupt anim file (invalid element count).")); } if(countFrames() != numframes) { throw(KToolsError("Corrupt anim file (invalid frame count).")); } if(countEvents() != numevents) { throw(KToolsError("Corrupt anim file (invalid event count).")); } if(!shouldHaveHashTable() || !in || in.peek() == EOF) { if(shouldHaveHashTable()) { std::cerr << "WARNING: Missing hash table at the end of the anim file. Generating automatic names." << std::endl; } FallbackKAnimNamer namer; (void)loadPost_all_anims(in, namer, verbosity); } else { if(verbosity >= 1) { cout << "Loading anim hash table..." << endl; } hashtable_t ht; uint32_t htsize; io.read_integer(in, htsize); for(uint32_t i = 0; i < htsize; i++) { hash_t h; io.read_integer(in, h); string& str = ht[h]; io.read_len_string<uint32_t>(in, str); if(verbosity >= 5) { cout << "\tGot 0x" << hex << h << dec << " => \"" << str << "\"" << endl; } } HashTableKAnimNamer namer(ht); (void)loadPost_all_anims(in, namer, verbosity); } if(in.peek() != EOF) { std::cerr << "Warning: There is leftover data in the input anim file." << std::endl; } return in; }
void allToAllCalculation(int * localList,int * FinalsplitterArray,int * scounts,int * sdispls,int n) { int p,my_rank; int min; int max; MPI_Comm_size(MPI_COMM_WORLD, &p); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); int maxCount,minCount; // Calculation of scounts //for(int i=0;i<p;i++) //{ // printf("before for rank %d : %d",my_rank,scounts[i]); //} for(int j=0;j<p;j++) //Accessing FinalsplitterArray array { if(j==0) { min= -2147483648; max = *(FinalsplitterArray+0); } else if(j==p-1) { min = *(FinalsplitterArray+(p-2)); max = 2147483647 ; } else { min = *(FinalsplitterArray+(j-1)); max = *(FinalsplitterArray+(j)); } //printf("\nRank %d : min max %d %d\n",my_rank,min,max); /*for(int i=0;i<n;i++) { if ((*(localList+i) > min) && (*(localList+i) <= max)) { //*(scounts + j) = *(scounts + j)+1; scounts[j]++; printf("%d , %d\n",*(localList+i),scounts[j]); } }*/ countElements(localList,max,&maxCount,n); countElements(localList,min,&minCount,n) ; //printf("rank %d - Answer count is %d %d final count :%d\n",my_rank,minCount,maxCount,(maxCount-minCount)); scounts[j] = maxCount - minCount; } //for(int i=0;i<p;i++) //{ // printf("for rank %d : %d ",my_rank,scounts[i]); //} //printf("\n"); //Calculation of sdispls sdispls[0] = 0; for(int i=1;i<p;i++) { //if(scounts[i] != 0) { sdispls[i] = sdispls[i-1] + scounts[i-1]; } } //for(int i=0;i<p;i++) //{ // printf("disp rank %d : %d ",my_rank,sdispls[i]); //} //printf("\n"); }
int main() { /** Variables to measure the time **/ double start,finish; node *Table[MAX]; clearTable(Table); char input[CHARS]; int j,k,i,x; /** For Hash function 1, dispersion and time for inserting the elements**/ start=clock(); for(k=1;k<=200;k++) for(j=1;j<=10;j++) { strcpy(input,mkrndstr(j)); x=hashFunction1(input); if (hasValue(Table[x],input)) { /**printf("%s is in the table!\n",input);**/ } else { Table[x] = insertValue(Table[x],input); } } finish=clock(); printf("\nThe time (in seconds) for 1st function=%lf \n",(finish-start)/CLOCKS_PER_SEC); printf("\nDispersion for 1st function:\n"); for (i=0;i<MAX;i++) { printf("[%d]: %d \n",i,countElements(Table[i])); } /** For Hash function 2, dispersion and time for inserting the elements**/ clearTable(Table); start=clock(); for(k=1;k<=200;k++) for(j=1;j<=10;j++) { strcpy(input,mkrndstr(j)); x=hashFunction2(input); if (hasValue(Table[x],input)) { /**printf("%s is in the table!\n",input);**/ } else { Table[x] = insertValue(Table[x],input); } } finish=clock(); printf("\nThe time (in seconds) for 2nd function=%lf \n",(finish-start)/CLOCKS_PER_SEC); printf("\nDispersion for 2nd function:\n"); for (i=0;i<MAX;i++) { printf("[%d]: %d \n",i,countElements(Table[i])); } /** node *Table[MAX]; clearTable(Table); char input[CHARS]; int in=-1; int i; while(in!=0) { printf("(1)Insert\n(2)Search\n(3)Count all\n(4)List all\n(0)Escape\n\n"); printf(" > "); scanf("%d",&in); switch(in) { case 1: printf("\tInserting: \n"); printf("\t > "); scanf("%s",input); if (hasValue(Table[hashFunction1(input)],input)) { printf("%s is in the table!\n",input); } else { Table[hashFunction1(input)] = insertValue(Table[hashFunction1(input)],input); } break; case 2: printf("\tSearching value: \n"); printf("\t > "); scanf("%s", &input); if (hasValue(Table[hashFunction1(input)],input)) { printf("%s is in the table!\n",input); } else { printf("%s is not in the table!\n",input); } break; case 4: for (i = 0; i < MAX; i++) { printf("[%d] ",i); printList(Table[i]); } break; case 3: for (i = 0; i < MAX; i++) { printf("\n[%d]: %d ",i, countElements(Table[i])); } break; } printf("_______________________________________________________\n"); } **/ return 0; }
virtual UInt32 getCount( DataPtr & data, const std::type_info & type) { return countElements( (E *) 0, data, type); }