void UI::sortMenu() { char choice; cout << endl; cout << "Print by: " << endl; cout << "(U) Unordered" << endl << "(A) Alphabetic order" << endl << "(R) Reverse alphabetic order" << endl << "(B) Year of Birth" << endl << "(D) Year of Death" << endl << "(M) Return to Menu" << endl << "(Q) Quit program " << endl; cout << "Select a letter: "; cin >> choice; switch(choice) { case 'u': case 'U': print(); break; case 'a': case 'A': cout << endl << "--- Printing by alphabetical order --- " << endl; core.sortAlpabetFront(); print(); break; case 'r': case 'R': cout << endl << "--- Printing by reverse alphabetical order --- " << endl; core.sortAlpabetBack(); print(); break; case 'b': case 'B': cout << endl << "--- Printing by year of Birth --- " << endl; core.sortByBirthYear(); print(); break; case 'd': case 'D': cout << endl << "--- Printing by year of Death --- " << endl; core.sortByDeathYear(); print(); break; case 'M': case 'm': return; break; case 'q': case 'Q': exit(1); break; default: errorInput(); sortMenu(); break; } sortMenu(); }
void ConvertDuration(const char a[]) { if (a[1] != '.' || a[2] != '0') { //printf("%c %c\n", a[1], a[2]); wrong = 1; } para[14] = (a[0] - '0'); if ((para[13] / 9 != (para[13] + para[14]) / 9) && ((para[13] + para[14]) % 9 != 0)) { //printf("13= %d, 14= %d\n",para[13],para[14]); wrong = 1; } if (wrong) { errorInput(); } }
void ConvertTime(const char a[], const char b[]) { int month = (a[5] - '0') * 10 + (a[6] - '0');//month int day = (a[8] - '0') * 10 + (a[9] - '0');//day if (!time_set) { time_set = ConvertDayNumber(month, day); } para[13] = (ConvertDayNumber(month, day) - time_set + 13) * 9 + (b[0] - '0') * 10 + (b[1] - '0') - 9; int btemp = (b[0] - '0') * 10 + (b[1] - '0'); int bbtemp = ConvertDayNumber(month, day) - time_set + 13; if (btemp < 9 || btemp >= 18 || bbtemp < 0 || bbtemp > 26) { //printf("btemp=%d\n",btemp); wrong = 1; } if (wrong) errorInput(); }
void UI::searchMenu() { cout << endl; char choice; cout << "Search by: " << endl; cout << "(N) Name" << endl << "(G) Gender" << endl << "(B) Year of Birth" << endl << "(D) Year of Death" << endl << "(M) Return to Menu" << endl << "(Q) Quit program " << endl; cout << "Select a letter: "; cin >> choice; switch(choice) { case 'n': case 'N': searchName(); //<- breyta í core.searchName þegar core hefur það fall break; case 'g': case 'G': searchGender(); break; case 'b': case 'B': searchBirth(); break; case 'd': case 'D': searchDeath(); break; case 'M': case 'm': return; //this->menu(); break; case 'q': case 'Q': exit(1); break; default: errorInput(); searchMenu(); } searchMenu(); }
T* StreamlineTexture<T>::fastLIC(const Flow2D& flow, const SimpleTexture<float>& inputTexture, const size_t textureScaling, const size_t sampling, const int maxKernelSize, const tgt::vec2& thresholds, const bool useAdaptiveKernelSize) { const tgt::ivec2 inputTexSize(inputTexture.getDimensions().xy()); if (flow.dimensions_ != inputTexSize) return 0; StreamlineTexture<T> outputTexture(inputTexSize * static_cast<int>(textureScaling)); const tgt::ivec2& outputTexSize = outputTexture.getDimensions().xy(); const int delta = static_cast<int>(sampling); const float stepSize = (0.5f / textureScaling); const float length = static_cast<float>(tgt::max(flow.dimensions_)) * 1.10f; size_t numStreamlines = 0; for (int y = 0; y < outputTexSize.y; y += delta) { for (int x = 0; x < outputTexSize.x; x += delta) { tgt::ivec2 ir0(x, y); if (outputTexture[ir0].counter_ > 0) continue; // get the coordinates of the pixel in the input texture which corresponds // to this position in the output texture and calculate its position within // the flow. // tgt::ivec2 r0Input(ir0 / static_cast<int>(textureScaling)); tgt::ivec2 errorInput(0, 0); tgt::vec2 r0 = flow.slicePosToFlowPos(r0Input, inputTexSize, &errorInput); const tgt::vec2 v = flow.lookupFlow(r0); if (v == tgt::vec2::zero) continue; // start streamline computation // int indexR0 = 0; std::deque<tgt::vec2> streamlineD = FlowMath::computeStreamlineRungeKutta(flow, r0, length, stepSize, &indexR0, thresholds); if (streamlineD.size() <= 1) continue; // also determine the round-off error which occurs if the flow positions was // converted back directly to the coordinates of the output textures. // tgt::ivec2 errorOutput(0, 0); flow.slicePosToFlowPos(ir0, outputTexSize, &errorOutput); ++numStreamlines; std::vector<tgt::vec2> streamline = FlowMath::dequeToVector(streamlineD); // copy the streamline for second coordinate conversion // std::vector<tgt::vec2> streamlineCopy(streamline); // convert the streamline into dimensions of the input texture // std::vector<tgt::ivec2> streamlineInput = flow.flowPosToSlicePos(streamline, inputTexSize, errorInput); // also convert the streamline into dimensions of the output texture // std::vector<tgt::ivec2> streamlineOutput = flow.flowPosToSlicePos(streamlineCopy, outputTexSize, errorOutput); // calculate initial intensity for the starting pixel // int L = maxKernelSize; if (useAdaptiveKernelSize == true) L = static_cast<int>(tgt::round(maxKernelSize * (tgt::length(v) / thresholds.y))); const float k = 1.0f / (((2 * L) + 1)); float intensity0 = k * fastLICIntensity(inputTexture, indexR0, L, streamlineInput); // determine the affected pixel in the output texture and add the // initial intensity // tgt::ivec2& outputTexCoord = streamlineOutput[indexR0]; outputTexture[outputTexCoord].elem_ += T(intensity0); ++(outputTexture[outputTexCoord].counter_); // trace streamline in forward direction and update intensity // float intensity = intensity0; int left = indexR0 + L + 1; int right = indexR0 - L; const int numPoints = static_cast<int>(streamlineInput.size()); for (int i = (indexR0 + 1); i < numPoints; ++i, ++left, ++right) { int l = (left >= numPoints) ? (numPoints - 1) : left; int r = (right <= 0) ? 0 : right; intensity += (inputTexture[streamlineInput[l]] - inputTexture[streamlineInput[r]]) * k; outputTexCoord = streamlineOutput[i]; outputTexture[outputTexCoord].elem_ += T(intensity); ++(outputTexture[outputTexCoord].counter_); } // for (i // trace streamline in backward direction and update intensity // intensity = intensity0; left = indexR0 - L - 1; right = indexR0 + L; for (int i = (indexR0 - 1); i >= 0; --i, --left, --right) { int l = (left <= 0) ? 0 : left; int r = (right >= numPoints) ? (numPoints - 1) : right; intensity += (inputTexture[streamlineInput[l]] - inputTexture[streamlineInput[r]]) * k; outputTexCoord = streamlineOutput[i]; outputTexture[outputTexCoord].elem_ += T(intensity); ++(outputTexture[outputTexCoord].counter_); } // for (i } // for (x } // for (y size_t unhitPixels = 0; const size_t numPixels = outputTexture.getNumElements(); for (size_t i = 0; i < numPixels; ++i) { if (outputTexture[i].counter_ > 1) outputTexture[i].elem_ /= static_cast<unsigned char>(outputTexture[i].counter_); else if (outputTexture[i].counter_ <= 0) ++unhitPixels; } std::cout << "# streamlines = " << numStreamlines << ", # unhit pixels = " << unhitPixels << " (" << static_cast<float>(100 * unhitPixels) / static_cast<float>(numPixels) << " %)\n"; T* result = new T[numPixels]; memcpy(result, outputTexture.getData(), sizeof(T) * numPixels); return result; }
int coreInput(FILE *stream) { int isPrint = 0;//whether command is print int i; int type = -1; char t[20]; char *require[13]; char temp[256]; wrong = 0; for (i = 0; i < 15; i++) { para[i] = 0; } for (i = 0; i < 15; i++) { require[i] = ""; } fscanf(stream, "%s", t); switch (t[3]) { case 'M'://addMeeting type = 1; break; case 'P': if (t[0] == 'a') {//addPresentation type = 2; } else {//endProgram int temp2; for (temp2 = 0; temp2 < 12; temp2++) { Send(temp2, "E00"); } return 0; } break; case 'C'://addConference type = 3; break; case 'D'://addDevice type = 0; break; case 'B'://addBatch break; case 'n'://PrintSchd isPrint = 1; type = -2; break; } i = 0; fgets(temp, 256 - 1, stream); int length = strlen(temp); if (temp[strlen(temp) - 1] != '\n') { temp[strlen(temp)] = '\0'; } else temp[length - 1] = '\0'; require[i++] = strtok(temp, " ;-�C"); while (require[i++] = strtok(NULL, " ;\n\0")); if (type == -1) {//addBatch int stop = 0; FILE *f = fopen(require[0], "r"); if (f != NULL) { while (!stop) { for (i = 0; i < 256; i++) { temp[i] = '\0'; } fgets(temp, 256 - 1, f); if (temp[strlen(temp) - 1] != '\n') { temp[strlen(temp)] = '\0'; } else temp[strlen(temp) - 1] = '\0'; if (strlen(temp) == 0) { stop = 1; } else { FILE *f2 = fopen("inputModuleTemp.bat", "w"); fseek(f2, 0, SEEK_SET); fwrite(temp, strlen(temp), 1, f2); fclose(f2); FILE *f3 = fopen("inputModuleTemp.bat", "r"); coreInput(f3); } } } else printf("You might entered an empty line of command.\n"); } else if (!isPrint) {//add: equipment, date, time, duration, tenant, equipment, equipment ConvertTime(require[1], require[2]); if (wrong)goto wrongEnd; ConvertDuration(require[3]); if (wrong)goto wrongEnd; ConvertTenant(require[4]); ConvertEquipment(require[0]); int ttemp; for (ttemp = 5; ttemp < 13; ttemp++) { if (require[ttemp] && strcmp(require[ttemp], "") != 0) ConvertEquipment(require[ttemp]); } AddRecord(para[0], para[1], para[2], para[3], para[4], para[5], para[6], para[7], para[8], para[9], para[10], para[11], para[12], para[13], para[14], type); } else {//print if (strcmp(require[0], "fcfs") == 0) { SchdFcfs(head); PrintSchd(head, 1); } else if (strcmp(require[0], "prio") == 0) { SchdPrio(); PrintSchd(head, 2); } else if (strcmp(require[0], "opti") == 0) { SchdOpti(); } else { errorInput(); goto wrongEnd; } } if (isPrint) return 2; else return 1; wrongEnd: { return 1; } }