void ShareBrowserSearch::findMatches(FileBrowserItem *item){ if (!item) return; QModelIndex index = model->createIndexForItem(item); if (model->canFetchMore(index)) model->fetchMore(index); QString fname = ""; for (const auto &i : item->childItems){ if (i->dir){ findMatches(i); DirectoryListing::File::List *files = &i->dir->files; DirectoryListing::File::Iter it_file; for (it_file = files->begin(); it_file != files->end(); ++it_file){ fname = _q((*it_file)->getName()); if (fname.indexOf(lineEdit_SEARCHSTR->text(), 0, Qt::CaseInsensitive) >= 0 || fname.indexOf(regexp) >= 0 || regexp.exactMatch(fname)) emit gotItem(_q((*it_file)->getName()), i); } } } }
int main(int argc, char *argv[]){ int optind; // int to iterate through options char word[WORD_LEN]; // array to copy the string in args into int word_loc; // at least three arguments are required - check for them if(argc < 3){ fprintf(stderr, "Usage: %s [OPTIONS] STRING FILE (FILE...)\n", argv[0]); return(-1); } // parses the command line options with a switch statement and updates global flags for(optind = 1; optind < argc && argv[optind][0] == '-'; optind++){ switch (argv[optind][1]) { case 'i': i_flag = 1; break; case 'n': n_flag = 1; break; } } word_loc = i_flag + n_flag + 1; // strncpy(word,argv[word_loc], sizeof(argv[word_loc])); strcpy(word,argv[word_loc]); findMatches(argv, argc, word); return 0; }
bool Matrix::canSwap(int x1, int y1, int x2, int y2) { // get elements auto a = getElement(x1, y1); auto b = getElement(x2, y2); // make a fake move setElement(x1, y1, b); setElement(x2, y2, a); // get matches auto matchesForA = findMatches(x1, y1); auto matchesForB = findMatches(x2, y2); auto biggest = matchesForA.size() > matchesForB.size() ? matchesForA : matchesForB; // reset the fake move setElement(x1, y1, a); setElement(x2, y2, b); return biggest.size()>=3; }
void gameLoop(void* data) { if (++s_frame == ANIM_FPS) s_frame = 0; // Note we may not draw every frame #ifdef DEBUG_MODE ++s_FPS; #endif bool requestRedraw = false; switch (s_gameState) { case kIdle: break; case kAwaitingDirection: requestRedraw = awaitingDirection(); break; case kCheckMove: requestRedraw = checkMove(); break; case kNudgeAnimate: requestRedraw = nudgeAnimate(); break; case kSwapAnimate: requestRedraw = swapAnimate(); break; case kFindMatches: requestRedraw = findMatches(); break; case kFlashRemoved: requestRedraw = flashRemoved(); break; case kRemoveAndReplace: requestRedraw = removeAndReplace(); break; case kSettleBoard: requestRedraw = settleBoard(); break; case kFindNextMove: requestRedraw = findNextMove(); break; case kCheckLives: requestRedraw = checkLives(); break; case kGameOver: requestRedraw = gameOver(); break; default: break; } switch (s_scoreState) { case kWait: requestRedraw |= checkScoreBuffer(); break; case kApplyPoints: requestRedraw |= applyPoints(); break; case kCheckNewLevel: requestRedraw |= checkNewLevel(); break; default: break; } // only if taking acceleromiter data do we ALWAY redraw if (s_tiltMode > 0 || requestRedraw == true) { redraw(); } s_gameLoopTime = app_timer_register(ANIM_DELAY, gameLoop, NULL); }
SimilarCategoriesDialog::SimilarCategoriesDialog( ElementList &list, QWidget* parent ) : QDialog( parent ), m_elementList(list) { setObjectName( "SimilarCategoriesDialog" ); setModal( true ); SimilarCategoriesDialogLayout = new QVBoxLayout( this ); SimilarCategoriesDialogLayout->setMargin( 11 ); SimilarCategoriesDialogLayout->setSpacing( 6 ); SimilarCategoriesDialogLayout->setObjectName( "SimilarCategoriesDialogLayout" ); layout6 = new QHBoxLayout(); layout6->setMargin( 0 ); layout6->setSpacing( 6 ); layout6->setObjectName( "layout6" ); layout4 = new QGridLayout(); layout4->cellRect( 1, 1 ); layout4->setMargin( 0 ); layout4->setSpacing( 6 ); layout4->setObjectName( "layout4" ); categoriesBox = new KLineEdit( this ); layout4->addWidget( categoriesBox, 0, 1 ); thresholdSlider = new QSlider( this ); thresholdSlider->setObjectName( "thresholdSlider" ); thresholdSlider->setValue( 40 ); thresholdSlider->setOrientation( Qt::Horizontal ); layout4->addWidget( thresholdSlider, 1, 1 ); thresholdLabel = new QLabel( this ); thresholdLabel->setObjectName( "thresholdLabel" ); layout4->addWidget( thresholdLabel, 1, 0 ); categoryLabel = new QLabel( this ); categoryLabel->setObjectName( "categoryLabel" ); layout4->addWidget( categoryLabel, 0, 0 ); layout6->addLayout( layout4 ); layout5 = new QVBoxLayout(); layout5->setMargin( 0 ); layout5->setSpacing( 6 ); layout5->setObjectName( "layout5" ); searchButton = new QPushButton( this ); searchButton->setObjectName( "searchButton" ); layout5->addWidget( searchButton ); spacer4 = new QSpacerItem( 20, 51, QSizePolicy::Minimum, QSizePolicy::Expanding ); layout5->addItem( spacer4 ); layout6->addLayout( layout5 ); SimilarCategoriesDialogLayout->addLayout( layout6 ); layout9 = new QHBoxLayout(); layout9->setMargin( 0 ); layout9->setSpacing( 6 ); layout9->setObjectName( "layout9" ); layout8 = new QVBoxLayout(); layout8->setMargin( 0 ); layout8->setSpacing( 6 ); layout8->setObjectName( "layout8" ); allLabel = new QLabel( this ); allLabel->setObjectName( "allLabel" ); layout8->addWidget( allLabel ); allListView = new K3ListView( this ); allListView->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 0, 1, allListView->sizePolicy().hasHeightForWidth() ) ); layout8->addWidget( allListView ); layout9->addLayout( layout8 ); layout1 = new QVBoxLayout(); layout1->setMargin( 0 ); layout1->setSpacing( 6 ); layout1->setObjectName( "layout1" ); removeButton = new QPushButton( this ); removeButton->setObjectName( "removeButton" ); layout1->addWidget( removeButton ); addButton = new QPushButton( this ); addButton->setObjectName( "addButton" ); layout1->addWidget( addButton ); spacer1 = new QSpacerItem( 20, 61, QSizePolicy::Minimum, QSizePolicy::Expanding ); layout1->addItem( spacer1 ); layout9->addLayout( layout1 ); layout7 = new QVBoxLayout(); layout7->setMargin( 0 ); layout7->setSpacing( 6 ); layout7->setObjectName( "layout7" ); toMergeLabel = new QLabel( this ); toMergeLabel->setObjectName( "toMergeLabel" ); layout7->addWidget( toMergeLabel ); toMergeListView = new K3ListView( this ); toMergeListView->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 0, 1, toMergeListView->sizePolicy().hasHeightForWidth() ) ); layout7->addWidget( toMergeListView ); layout9->addLayout( layout7 ); SimilarCategoriesDialogLayout->addLayout( layout9 ); layout10 = new QHBoxLayout(); layout10->setMargin( 0 ); layout10->setSpacing( 6 ); layout10->setObjectName( "layout10" ); spacer2 = new QSpacerItem( 310, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); layout10->addItem( spacer2 ); mergeButton = new QPushButton( this ); mergeButton->setObjectName( "mergeButton" ); layout10->addWidget( mergeButton ); cancelButton = new QPushButton( this ); cancelButton->setObjectName( "cancelButton" ); layout10->addWidget( cancelButton ); SimilarCategoriesDialogLayout->addLayout( layout10 ); languageChange(); resize( QSize(573, 429).expandedTo(minimumSizeHint()) ); //clearWState( WState_Polished ); connect( searchButton, SIGNAL(clicked()), this, SLOT(findMatches()) ); connect( mergeButton, SIGNAL(clicked()), this, SLOT(mergeMatches()) ); connect( cancelButton, SIGNAL(clicked()), this, SLOT(reject()) ); connect( addButton, SIGNAL(clicked()), this, SLOT(addCategory()) ); connect( removeButton, SIGNAL(clicked()), this, SLOT(removeCategory()) ); }
// Mark C. Miller, Wed Aug 22 19:57:54 PDT 2012 // Removed superfolous code allocating and initializing local variables, // score_mins and score_maxs. Nothing in the function was using these // variables. void avtModelFitFilter::PostExecute() { intVector numTups = atts.GetNumTups(); intVector numVars = atts.GetNumVars(); stringVector Vars = atts.GetVars(); doubleVector Tuples = atts.GetTuples(); doubleVector thold = atts.GetThold(); unsignedCharVector StatTuples = atts.GetStatTuples(); intVector tup_match; doubleVector mins; doubleVector point; int tup_index, var_index; vtkDataArray *darray; char secVarName[1024]; int numValues; size_t varFinder; double distance; float *scalars; bool good_match; int relat_index; double opt_distance; intVector selectionType = atts.GetSelectionType(); intVector distanceType = atts.GetDistanceType(); intVector inputSpace = atts.GetInputSpace(); //Since there may be overlap between models in variables specified, //create a set of all unique variables for(size_t i = 0; i < Vars.size(); i++) { sprintf(secVarName, "%s", Vars[i].c_str()); createVS(secVarName); } //determine for each variable whether or not statistics or //histograms need to be calculated for(int i = 0, currentVar = 0, num_to_remove = 0; i < num_relats; i++) { if(selectionType[i] == 1 || inputSpace[i] == 1) for(int j = 0; j < numVars[i]; j++, currentVar++, num_to_remove++) { for(varFinder = 0; varFinder < VS.size(); varFinder++) if(!strcmp(VS[varFinder]->name, Vars[currentVar].c_str())) break; VS[varFinder]->calculate_stats = true; } currentVar -= num_to_remove; num_to_remove = 0; if(selectionType[i] == 3 || inputSpace[i] == 3) for(int j = 0; j < numVars[i]; j++, currentVar++, num_to_remove++) { for(varFinder = 0; varFinder < VS.size(); varFinder++) if(!strcmp(VS[varFinder]->name, Vars[currentVar].c_str())) break; VS[varFinder]->calculate_hists = true; } currentVar -= num_to_remove; num_to_remove = 0; currentVar += numVars[i]; } //also force stats calculation if stat shortcuts specified for(int i = 0; i < num_relats; i++) { tup_index = 0; var_index = 0; for(int j = 0; j < i; j++) { tup_index += numTups[j]*numVars[j]; var_index += numVars[j]; } for(int j = 0; j < numTups[i]*numVars[i]; j++) if(StatTuples[tup_index+j] == 'a' || StatTuples[tup_index+j] == 'M' || StatTuples[tup_index+j] == 'm') { for(varFinder = 0; varFinder < VS.size(); varFinder++) if(!strcmp(VS[varFinder]->name, Vars[var_index + (j%numVars[i])].c_str())) break; VS[varFinder]->calculate_stats = true; } } //Go through all variables specified and calculate //statistics for each. calculateVariableStats(); #ifdef PARALLEL int numProcs = 1; int myRank = 0; MPI_Comm_rank(VISIT_MPI_COMM, &myRank); MPI_Comm_size(VISIT_MPI_COMM, &numProcs); double *sum; double *max; double *min; double *non_zero_min; int *num_points; int totVars = VS.size(); int number_on = 0; double *temp_hist; double *merged_ranges; num_points = (int *)malloc(sizeof(int) *totVars); sum = (double *)malloc(sizeof(double)*totVars); max = (double *)malloc(sizeof(double)*totVars); min = (double *)malloc(sizeof(double)*totVars); non_zero_min = (double *)malloc(sizeof(double)*totVars); merged_ranges = (double *)malloc(sizeof(double)*(BINS*numProcs)); temp_hist = (double *)malloc(sizeof(double)*BINS); for(int i = 0; i < totVars; i++) { if(VS[i]->calculate_stats) { num_points[i] = VS[i]->num_points; sum[i] = VS[i]->sum; max[i] = VS[i]->max; min[i] = VS[i]->min; non_zero_min[i] = VS[i]->non_zero_min; MPI_Allreduce(&num_points[i], &(VS[i]->num_points), 1, MPI_INT, MPI_SUM, VISIT_MPI_COMM); MPI_Allreduce(&sum[i], &(VS[i]->sum), 1, MPI_DOUBLE, MPI_SUM, VISIT_MPI_COMM); MPI_Allreduce(&max[i], &(VS[i]->max), 1, MPI_DOUBLE, MPI_MAX, VISIT_MPI_COMM); MPI_Allreduce(&min[i], &(VS[i]->min), 1, MPI_DOUBLE, MPI_MIN, VISIT_MPI_COMM); MPI_Allreduce(&non_zero_min[i], &(VS[i]->non_zero_min), 1, MPI_DOUBLE, MPI_MIN, VISIT_MPI_COMM); } if(VS[i]->calculate_hists) { for(int np = 0; np < numProcs; np++) { if(np == myRank) memcpy(temp_hist, VS[i]->hist.range_ends, BINS*sizeof(double)); MPI_Bcast(temp_hist, BINS, MPI_DOUBLE, i, VISIT_MPI_COMM); for(int j = 0; j < BINS; j++) merged_ranges[number_on++] = temp_hist[j]; } VS[i]->hist.count = VS[i]->num_points / BINS; VS[i]->hist.mod_number = VS[i]->num_points % BINS; qsort(merged_ranges, BINS*numProcs, sizeof(double), compare_doubles); for(int j = 0, k = 0; j < numProcs*BINS; j += numProcs, k++) VS[i]->hist.range_ends[k] = merged_ranges[j]; number_on = 0; } } delete num_points; delete sum; delete max; delete min; delete non_zero_min; delete(temp_hist); delete(merged_ranges); #endif for(size_t i = 0; i < VS.size(); i++) if(VS[i]->num_points) VS[i]->average = VS[i]->sum/VS[i]->num_points; /* puts("-------before------"); for(int i = 0; i < Tuples.size(); i++) printf("Tuples[%d]: %lf\n", i, Tuples[i]); */ //do space converts on thresholds and tuples //for tuples, stick stats in if needed for(int i = 0; i < num_relats; i++) { tup_index = 0; var_index = 0; for(int j = 0; j < i; j++) { tup_index += numTups[j]*numVars[j]; var_index += numVars[j]; } for(int j = 0; j < numTups[i]*numVars[i]; j++) { sprintf(secVarName, "%s", Vars[var_index+(j%numVars[i])].c_str()); for(varFinder = 0; varFinder < VS.size(); varFinder++) if(!strcmp(VS[varFinder]->name, secVarName)) break; //we have a thold specified if(thold[tup_index+j] > 0) if(inputSpace[i] != selectionType[i]) { thold[tup_index+j] = convertToVariableSpace(thold[tup_index+j], varFinder, inputSpace[i]); thold[tup_index+j] = spaceConvert(thold[tup_index+j], varFinder, selectionType[i]); } //replace Tuples with stats if(StatTuples[tup_index+j] == 'a' || StatTuples[tup_index+j] == 'M' || StatTuples[tup_index+j] == 'm') { if(StatTuples[tup_index+j] == 'a') Tuples[tup_index+j] = VS[varFinder]->average; else if (StatTuples[tup_index+j] == 'M') Tuples[tup_index+j] = VS[varFinder]->max; else if (StatTuples[tup_index+j] == 'm') Tuples[tup_index+j] = VS[varFinder]->min; //printf("Tuples[%d] before: %lf\n", tup_index+j, Tuples[tup_index+j]); Tuples[tup_index+j] = spaceConvert(Tuples[tup_index+j], varFinder, selectionType[i]); //printf("Tuples[%d] after: %lf\n", tup_index+j, Tuples[tup_index+j]); } else if(inputSpace[i] != selectionType[i]) { //printf("Tuples[%d] before: %lf\n", tup_index+j, Tuples[tup_index+j]); Tuples[tup_index+j] = convertToVariableSpace(Tuples[tup_index+j], varFinder, inputSpace[i]); //printf("Tuples[%d] after cTVS: %lf\n", tup_index+j, Tuples[tup_index+j]); Tuples[tup_index+j] = spaceConvert(Tuples[tup_index+j], varFinder, selectionType[i]); //printf("Tuples[%d] after SC: %lf\n", tup_index+j, Tuples[tup_index+j]); //printf("Used %lf for min, %lf for max\n", VS[varFinder]->min, VS[varFinder]->max); } } } /* puts("-------after------"); for(int i = 0; i < Tuples.size(); i++) printf("Tuples[%d]: %lf\n", i, Tuples[i]); */ atts.SetTuples(Tuples); atts.SetThold(thold); // for(size_t ds = 0; ds < out_ds.size(); ds++){ numValues = 0; if(Centering == AVT_NODECENT) numValues = out_ds[ds]->GetNumberOfPoints(); else numValues = out_ds[ds]->GetNumberOfCells(); for(int p = 0; p < numValues; p++) { opt_distance = -1; //added for relat_index = -1; //distance use for(int i = 0; i < num_relats; i++) { //added for distances if(numTups[i] < 1) continue; tup_index = 0; var_index = 0; for(int j = 0; j < i; j++) { tup_index += numTups[j]*numVars[j]; var_index += numVars[j]; } grabOnePoint(&point, numVars[i], var_index, selectionType[i], p, out_ds[ds]->GetPointData(), out_ds[ds]->GetCellData()); findMatches(&mins, &tup_match, point, numVars[i], numTups[i], tup_index, var_index); //Find winning relationship if(tup_match.size() > 0) { distance = calculateDistance(mins, distanceType[i]); good_match = true; for(size_t j = 0; j < mins.size(); j++) if(mins[j] < 0) good_match = false; if(good_match) if(distance < opt_distance || opt_distance < 0) { opt_distance = distance; relat_index = i; } } } if(num_relats && out_ds.size() && p < numValues){ if(Centering == AVT_NODECENT) darray = out_ds[ds]->GetPointData()->GetScalars("operators/ModelFit/model"); else darray = out_ds[ds]->GetCellData()->GetScalars("operators/ModelFit/model"); scalars = (float *)darray->GetVoidPointer(0); scalars[p] = relat_index+1; if(Centering == AVT_NODECENT) darray = out_ds[ds]->GetPointData()->GetScalars("operators/ModelFit/distance"); else darray = out_ds[ds]->GetCellData()->GetScalars("operators/ModelFit/distance"); scalars = (float *)darray->GetVoidPointer(0); if(opt_distance > 0) scalars[p] = opt_distance; else scalars[p] = -1; } } } }
int main(int argc, char *argv[]) { char table[TABLE_SIZE][MAX_STRING_LENGTH]; char keyword[MAX_STRING_LENGTH]; int size, rank; // Init MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); int sendCounts[size]; int displacements[size]; int charSendCounts[size]; int charDisplacements[size]; // Obmedzenie if(size > TABLE_SIZE) { printf("Prilis vela procesov"); return 0; } // if(rank == ROOT) { strcpy(keyword, "wtf"); strcpy(table[0], "hello"); strcpy(table[1], "world"); strcpy(table[2], "paralelne"); strcpy(table[3], "programovanie"); strcpy(table[4], "rofl"); strcpy(table[5], "lol"); strcpy(table[6], "wtf"); strcpy(table[7], "meh"); int stringsPerProcess = TABLE_SIZE / size; int remainder = TABLE_SIZE % size; // Vypocitat sendCounty a displacementy int i; int sum = 0; for(i = 0; i < size; i++) { int sendCount = stringsPerProcess; // Upravit pocet pre nedelitelne veci if(remainder > 0) { sendCount++; remainder--; } sendCounts[i] = sendCount; charSendCounts[i] = sendCount * MAX_STRING_LENGTH;; displacements[i] = sum; charDisplacements[i] = sum * MAX_STRING_LENGTH; sum += sendCount; } } int subTableSize; // Rozscatterovat velkost poli MPI_Scatter( sendCounts, 1, MPI_INT, &subTableSize, 1, MPI_INT, ROOT, MPI_COMM_WORLD ); printf("SubTableSize: %d", subTableSize); char subTable[subTableSize][MAX_STRING_LENGTH]; // Rozscatterovat stringy MPI_Scatterv( table, charSendCounts, charDisplacements, MPI_CHAR, subTable, charSendCounts[rank], MPI_CHAR, ROOT, MPI_COMM_WORLD ); // Broadcastnut keyword MPI_Bcast(keyword, MAX_STRING_LENGTH, MPI_CHAR, ROOT, MPI_COMM_WORLD); // Vyhladat matche int subMatchesSize = subTableSize; int subMatches[subMatchesSize]; findMatches(subTableSize, MAX_STRING_LENGTH, subTable, keyword, subMatches); int matchesSize = TABLE_SIZE; int matches[matchesSize]; // Gathernut matche na root MPI_Gatherv( subMatches, subMatchesSize, MPI_INT, matches, sendCounts, displacements, MPI_INT, ROOT, MPI_COMM_WORLD ); // Na roote // vypocitat spravny index if(rank == 0) { int matchesCount = 0; int i; for(i = 0; i < matchesSize; i++) { if(matches[i] != 0) { printf("Match found at: %d'\n", i); matchesCount++; } } if(matchesCount <= 0) { printf("No matches found!'\n"); } } // Teardown MPI_Finalize(); // Exit return 0; }
bool Matrix::consume(int x, int y) { auto matches = findMatches(x, y); if (matches.size() >= 3) { getParent()->getComponent<Menu>()->addScore(matches.size()*matches.size()); bool isHorizontal = false; if (abs(matches[0]->getTransform().getPosition().x - matches[1]->getTransform().getPosition().x) > 1) isHorizontal = true; if (isHorizontal) { for (int i = 0; i < matches.size(); i++) { auto pos = CrystalPicker::Vec3ToMatrixPosition(matches[i]->getTargetPosition()); // tell others to drop while (pos.y != 0) { auto elem = getElement(pos.x, pos.y-1); setElement(pos.x, pos.y, elem); elem->dropTo(CrystalPicker::MatrixPositionToVec3(pos.x, pos.y)); pos.y--; } // make itself drop && set new position setElement(pos.x, 0, matches[i]); auto startPos = CrystalPicker::MatrixPositionToVec3(pos.x, -2); auto newPos = CrystalPicker::MatrixPositionToVec3(pos.x, 0); matches[i]->getTransform().setPosition(startPos); matches[i]->dropTo(newPos); matches[i]->decreaseSizeNow(); matches[i]->randomize(); } } // vertical else { // find the top auto top = CrystalPicker::Vec3ToMatrixPosition(matches[0]->getTargetPosition()); // drop all above it for (int i = top.y - 1; i >= 0; i--) { auto elem = getElement(top.x, i); setElement(top.x, i + matches.size(), elem); elem->dropTo(CrystalPicker::MatrixPositionToVec3(top.x, i + matches.size())); } // drop new crystals for (int i = 0; i < matches.size(); i++) { // make itself drop && set new position setElement(top.x, i, matches[i]); auto startPos = CrystalPicker::MatrixPositionToVec3(top.x, -2 - matches.size() + i); auto newPos = CrystalPicker::MatrixPositionToVec3(top.x, i); matches[i]->getTransform().setPosition(startPos); matches[i]->dropTo(newPos); matches[i]->decreaseSizeNow(); matches[i]->randomize(); } } scheduleGlobalSolve(0.5); return true; } else return false; }
bool Matrix::canConsume(int x, int y) { auto matches = findMatches(x, y); return matches.size() >= 3; }
/** * Initialize the project, doing any necessary opengl initialization. * @param camera An already-initialized camera. * @param mesh The mesh to be rendered and subdivided. * @param texture_filename The filename of the texture to use with the mesh. * Is null if there is no texture data with the mesh or no texture filename * was passed in the arguments, in which case textures should not be used. * @return true on success, false on error. */ bool GeometryProject::initialize( const Camera* camera, const MeshData* mesh, const char* texture_filename ) { count = 0; this->mesh = *mesh; int i, j, indA, indB, indC; heEdge* curEdge; heEdge* tmpEdge; hasTexture = false; if(texture_filename != NULL){ printf("FOUND FILENAME %s\n",texture_filename); int height; int width; texture = _462::imageio_load_image(texture_filename,&width,&height); if((width != -1) && (height != -1)){ printf("Loaded Image!\n"); hasTexture = true; glGenTextures(1,&hTex); glBindTexture(GL_TEXTURE_2D, hTex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); } } GLfloat light0_position[] = { 2.0, 2.0, 0.0, 1.0 }; GLfloat light1_position[] = { -2.0, 2.0, 0.0, 1.0 }; GLfloat lmodel_ambient[] = { 0.7, 0.7, 0.7, 1.0 }; GLfloat specular[] = {1.0f, 1.0f, 1.0f , 1.0f}; GLfloat ambient[] = { 1.0f, 1.0f, 1.0f }; glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_POSITION, light0_position); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT1, GL_POSITION, light1_position); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHT1); glEnable(GL_NORMALIZE); // //load our half edge data structure from mesh // this->numFaces = this->mesh.num_triangles; faceList = (heFace*) calloc(numFaces,sizeof(heFace)); for(i=0; i<numFaces; i++){ //malloc vertices heVertex* vertA = (heVertex*) malloc(sizeof(heVertex)); heVertex* vertB = (heVertex*) malloc(sizeof(heVertex)); heVertex* vertC = (heVertex*) malloc(sizeof(heVertex)); //find index into vertex array indA = this->mesh.triangles[i].vertices[0]; indB = this->mesh.triangles[i].vertices[1]; indC = this->mesh.triangles[i].vertices[2]; //copy position vertA->point = this->mesh.vertices[indA].position; vertB->point = this->mesh.vertices[indB].position; vertC->point = this->mesh.vertices[indC].position; //copy normal vertA->normal = this->mesh.vertices[indA].normal; vertB->normal = this->mesh.vertices[indB].normal; vertC->normal = this->mesh.vertices[indC].normal; if(hasTexture){ //copy texture vertA->texture = this->mesh.vertices[indA].texture_coord; vertB->texture = this->mesh.vertices[indB].texture_coord; vertC->texture = this->mesh.vertices[indC].texture_coord; } //malloc edges heEdge* eAB = (heEdge*) malloc(sizeof(heEdge)); heEdge* eBC = (heEdge*) malloc(sizeof(heEdge)); heEdge* eCA = (heEdge*) malloc(sizeof(heEdge)); //set start vertices eAB->startVertex = vertA; eBC->startVertex = vertB; eCA->startVertex = vertC; //set edges for vertices vertA->edge = eAB; vertB->edge = eBC; vertC->edge = eCA; //set next edges eAB->nextEdge = eBC; eBC->nextEdge = eCA; eCA->nextEdge = eAB; //set face edge faceList[i].edge = eAB; //set edges face eAB->leftFace = &faceList[i]; eBC->leftFace = &faceList[i]; eCA->leftFace = &faceList[i]; //set edge pairs to null eAB->pairEdge = NULL; eBC->pairEdge = NULL; eCA->pairEdge = NULL; } //find paired edges for(i=0; i<numFaces; i++){ for(j=0; j<numFaces; j++){ findMatches(faceList[i].edge, faceList[j].edge); } } return true; }
/** * Subdivide the mesh that we are rendering using Loop subdivison. */ void GeometryProject::subdivide() { int i,j; heEdge* curEdge; heEdge* tempEdge; heEdge* compEdge; heFace* tmpFaceList = (heFace*) malloc(sizeof(heFace) * 4* numFaces); nvtPair ab, bc, ca, aPrime, bPrime, cPrime; for(i=0; i<numFaces; i++){ // //calculate odd vertices // curEdge = faceList[i].edge; if(curEdge->pairEdge != NULL){ // if we have an interior edge, simply split ab = splitInteriorEdge(curEdge); tempEdge = curEdge->pairEdge->nextEdge; //check if our startVertex is at a boundary while(tempEdge->pairEdge != NULL){ // if we return to our starting place, not a boundary if(tempEdge == curEdge){ aPrime = computeEvenInteriorVertex(curEdge); break; } tempEdge = tempEdge->pairEdge->nextEdge; } if(tempEdge->pairEdge == NULL){ aPrime = computeEvenBoundaryVertex(tempEdge); } } else{ ab = splitBoundaryEdge(curEdge); aPrime = computeEvenBoundaryVertex(curEdge); } curEdge = curEdge->nextEdge; if(curEdge->pairEdge != NULL){ // if we have an interior edge, simply split bc = splitInteriorEdge(curEdge); tempEdge = curEdge->pairEdge->nextEdge; //check if our startVertex is at a boundary while(tempEdge->pairEdge != NULL){ // if we return to our starting place, not a boundary if(tempEdge == curEdge){ bPrime = computeEvenInteriorVertex(curEdge); break; } tempEdge = tempEdge->pairEdge->nextEdge; } if(tempEdge->pairEdge == NULL){ bPrime = computeEvenBoundaryVertex(tempEdge); } } else{ bc = splitBoundaryEdge(curEdge); bPrime = computeEvenBoundaryVertex(curEdge); } curEdge = curEdge->nextEdge; if(curEdge->pairEdge != NULL){ // if we have an interior edge, simply split ca = splitInteriorEdge(curEdge); tempEdge = curEdge->pairEdge->nextEdge; //check if our startVertex is at a boundary while(tempEdge->pairEdge != NULL){ // if we return to our starting place, not a boundary if(tempEdge == curEdge){ cPrime = computeEvenInteriorVertex(curEdge); break; } tempEdge = tempEdge->pairEdge->nextEdge; } if(tempEdge->pairEdge == NULL){ cPrime = computeEvenBoundaryVertex(tempEdge); } } else{ ca = splitBoundaryEdge(curEdge); cPrime = computeEvenBoundaryVertex(curEdge); } updateFaceList(tmpFaceList, i, aPrime, bPrime, cPrime, ab, bc, ca); } freeFaceList(faceList); faceList = tmpFaceList; numFaces*=4; //find paired edges for(i=0; i<numFaces; i++){ for(j=0; j<numFaces; j++){ findMatches(faceList[i].edge, faceList[j].edge); } } }