int main(int argc, char *argv[]) { uint64_t n=0, sum; char copt; while((copt = getopt(argc, argv, "n:")) != -1) { switch(copt) { case 'n': n = atoll(optarg); break; default: goto usage; } } if(n == 0) goto usage; sum = findTriangle(n); printf("sum = %llu\n", sum); exit(0); error0: exit(-1); usage: fprintf(stderr, "%s -n N\n", argv[0]); exit(-1); }
void EditorScene::shadingTriangle(cocos2d::Vec2 rawpos) { clearSelection(); auto tri = findTriangle(rawpos); if (tri) { _triangleColorMap[_frameIndex][tri->calcKey()] = _diggingColor; tri->color = _diggingColor; refreshTriangles(); } }
static void mouseButton(int button, int state, int x, int y) { double xNDC = getNDCCoord(x, -1, 1, xRes); double yNDC = getNDCCoord(y, -1, 1, yRes); std::cout << "Clicked: " << xNDC << " " << -yNDC << std::endl; if (state == GLUT_DOWN) { currentSelection = findTriangle(xNDC, -yNDC); std::cout << "currentSelection: " << currentSelection << std::endl; glutPostRedisplay(); } else { currentSelection = -1; currentDualFace = -1; glutPostRedisplay(); } switch(button) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) { lastX = x; // note where the drag began lastY = y; if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) { userTransformType = 1; // "1" indicates ZOOM! // TODO: MOVE TO MIDDLE MOUSE } else { userTransformType = 0; // "0" indicates TRANSLATION! // TODO: MOVE TO MIDDLE MOUSE } } else if (state == GLUT_UP) { userTransformType = -1; // reset } break; case GLUT_MIDDLE_BUTTON: if (state == GLUT_DOWN) { lastX = x; lastY = y; } else if (state == GLUT_UP) { userTransformType = -1; // reset } break; case GLUT_RIGHT_BUTTON: if(state == GLUT_DOWN) { lastX = x; lastY = y; userTransformType = 2; } else if (state == GLUT_UP) { userTransformType = -1; // reset } break; } downX = x; downY = y; }
Foam::cellPointWeight::cellPointWeight ( const polyMesh& mesh, const vector& position, const label cellIndex, const label faceIndex ) : cellIndex_(cellIndex) { if (faceIndex < 0) { // Face data not supplied findTetrahedron(mesh, position, cellIndex); } else { // Face data supplied findTriangle(mesh, position, faceIndex); } }
void EditorScene::diggColor(cocos2d::Vec2 rawpos) { clearSelection(); float radio = 1.0*rawpos.x/1024.0; if (radio < 0.05) { radio = 0; } if (rawpos.y < 44) { _diggingColor.w = radio; } else if (rawpos.y < 44*2) { _diggingColor.z = radio; } else if (rawpos.y < 44*3) { _diggingColor.y = radio; } else if (rawpos.y < 44*4) { _diggingColor.x = radio; } else if (rawpos.y > 256) { auto tri = findTriangle(rawpos); if (tri) { _diggingColor = _triangleColorMap[_frameIndex][tri->calcKey()]; } } refreshDiggColor(); }
Foam::cellPointWeight::cellPointWeight ( const polyMesh& mesh, const vector& position, const label cellI, const label faceI ) : cellI_(cellI), weights_(4), faceVertices_(3) { if (faceI < 0) { // Face data not supplied findTetrahedron(mesh, position, cellI); } else { // Face data supplied findTriangle(mesh, position, faceI); } }
Foam::cellPointWeightWallModified::cellPointWeightWallModified ( const polyMesh& mesh, const vector& position, const label cellIndex, const label faceIndex ) : cellPointWeight(mesh, position, cellIndex, faceIndex) { if (faceIndex < 0) { findTetrahedron(mesh, position, cellIndex); } else { const polyBoundaryMesh& bm = mesh.boundaryMesh(); label patchI = bm.whichPatch(faceIndex); if (patchI != -1) { if (bm[patchI].isWall()) { // Apply cell centre value wall faces weights_[0] = 0.0; weights_[1] = 0.0; weights_[2] = 0.0; weights_[3] = 1.0; } } else { // Interpolate findTriangle(mesh, position, faceIndex); } } }
bool Surface::isPntInSfc (Point const& pnt) const { return (findTriangle(pnt)!=nullptr); }
bool Graph::isEqualAdvance(Graph *other, float e, float prop, int minParisCount, NodePairs &nodePairs){ if(this->nodeList.size()<3){ cout<<"The current graph has not enough points"<<endl; return false; } if(other->nodeList.size()<3){ cout<<"The compared graph has not enough points"<<endl; return false; } // reset the timmer for each node, inoder to show the correspondenz nodes //this->clearColor(); //other->clearColor(); NodePairs localNodePair; // Begin the loop of V first, to keep the 1:1 coorespondenz in result // Loop for all nodes in this Graph for(int k=0;k<this->nodeList.size();k++){ Node *v = this->nodeList[k]; bool isFound = false; // create the minimal acceptable number of numbers for point p //int minNodeSize = (p->neighbors.size() * prop)>=4?(p->neighbors.size()*prop):4; int minNodeSize = (this->nodeList.size()*prop)>=4?(this->nodeList.size()*prop):4; //int minNodeSize = 4; int bestNeighborCount = 0; Node *bestP; // Loop for all node in Other Graph for(int i=0;i<other->nodeList.size();i++){ // choose one point from Other graph Node *p = other->nodeList[i]; // save the coorespondenz neighbors of p(i) and v(k) NodePairs pair_i; v->findCorresNeighbors(p, pair_i, e); //cout<<pair_i.size()<<endl; //pair_k.insert(pair<Node*, Node*>(p,v)); // //// begin the loop of vi first, in order to keep the vi unique in Pairs Map //Neighbors::iterator l; //for(l=v->neighbors.begin();l!=v->neighbors.end();l++){ // // Get the neighbor nodes of p // Node *vi = l->first; // float v_vi = l->second; // // Loop for all neighbor node of p // Neighbors::iterator j; // for(j=p->neighbors.begin();j!=p->neighbors.end();j++){ // // Get the neighbor nodes of p // Node *pi = j->first; // float p_pi = j->second; // // if the edge has the same lenth // //if(fabs(p_pi - v_vi)< e){ // // with relative epsilon // if(fabs(p_pi - v_vi)< e*p_pi){ // // add the node pair to the Map // pair_k.insert(pair<Node*, Node*>(pi, vi)); // break; // } // } // // if enough node pairs have been found, add p,v into the result NodePiar // if(pair_k.size()>minNodeSize){ // localNodePair.insert(pair<Node*, Node*>(p,v)); // isFound = true; // // break the loop of vi // break; // } //} if(pair_i.size() > bestNeighborCount){ bestP = p; bestNeighborCount = pair_i.size(); } } // if the v and p has enough coorespondenz neighbors if(bestNeighborCount >= minNodeSize){ localNodePair.insert(pair<Node*, Node*>(bestP, v)); } } // check the number of coorespondenz point pair //if(localNodePair.size() >= minParisCount){ nodePairs.clear(); //nodePairs = localNodePair; if(findTriangle(localNodePair, nodePairs, 0.008)){ //NodePairs::iterator it = nodePairs.begin(); //int i=1; //for(;it!=nodePairs.end();it++, i++){ // if(i>9){ // i=0; // } // it->first->color = i; // it->second->color = i; //} return true; } cout<<"All nodes have been reached but no coorespondenz found!"<<endl; return false; }