bool tgBulletContactSpringCable::anchorCompare::operator() (const tgBulletSpringCableAnchor* lhs, const tgBulletSpringCableAnchor* rhs) const { btVector3 pt2 = lhs->getWorldPosition(); btVector3 pt3 = rhs->getWorldPosition(); return comparePoints(pt2, pt3); }
void Radiosity::ComputeFormFactors() { assert (formfactors == NULL); assert (num_faces > 0); formfactors = new float[num_faces*num_faces]; totalFormFactori = new float[num_faces]; // ===================================== // ASSIGNMENT: COMPUTE THE FORM FACTORS // ===================================== //use getRasterizedPrimitiveFace(int i) for the forms (maybe, apparently there are 0 of these) //use the original geometry for checking occlusion (possibly Face* getOriginalQuad(int i)) /*printf("NumFormFactors: %d\tNumOriginalQuads: %d\tNumRasterizedPrimitiveFaces: %d\tNumPrimitiveFaces: %d\n", num_faces, mesh->numOriginalQuads(), mesh->numRasterizedPrimitiveFaces(), mesh->numPrimitives()); //14, 14, 0, 0 to //56, 14, 0, 0 Ray ray1(glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); Ray ray2(glm::vec3(0, 0, 0), glm::vec3(1, 0, 0)); printf("Angle: %f\n", ray1.getAngle(ray2));*/ /*START SMALL (Like .5 or smaller and get larger) double until makes too large, then halve the distance until going too small, take the number before going too small, toss out the extras by directly going through vector and eliminating the n smallest*/ for (int i = 0; i < num_faces; i++) { totalFormFactori[i] = 0; glm::vec3 point1 = mesh->getFace(i)->RandomPoint(); glm::vec3 faceNormali = mesh->getFace(i)->computeNormal(); //move the start point slightly off the surface to avoid self collision point1 += (float).001*glm::normalize(faceNormali); //float totalFormFactori = 0; for (int j = 0; j < num_faces; j++) { if (i == j) { setFormFactor(i, j, 0); continue; } glm::vec3 faceNormalj = mesh->getFace(j)->computeNormal(); float formFactorTemp = 0; for (int k = 0; k<args->num_form_factor_samples; k++) { glm::vec3 point2 = mesh->getFace(j)->RandomPoint(); //move the end point slightly off the surface to avoid self collision //point2 += (float).001*glm::normalize(faceNormalj); Ray r(point1, glm::normalize(point2-point1)); Hit h; raytracer->CastRay(r,h,true); glm::vec3 hitPoint = r.pointAtParameter(h.getT()); if (comparePoints(point2, hitPoint) == 0) //if the points are not roughly the same then we have occlusion { continue; } // cos( ThetaI ) *cos( ThetaJ ) / formFactorTemp += ( (cos( r.getAngle( faceNormali ) )*cos( r.getAngle( -1.0f*faceNormalj ) ) ) / // PI*R^2 / ( M_PI*glm::dot( point2-point1, point2-point1 ) ) )/ // numFormFactors args->num_form_factor_samples; //printf("(cos(%f)*cos(%f)/3.1415*%f)/%d = %f\n", r.getAngle( faceNormali ), r.getAngle( -1.0f*faceNormalj ), glm::dot( point2-point1, point2-point1 ), args->num_form_factor_samples, ( (cos( r.getAngle( faceNormali ) )*cos( r.getAngle( -1.0f*faceNormalj ) ) ) / ( M_PI*glm::dot( point2-point1, point2-point1 ) ) )/args->num_form_factor_samples); //printf("Total Form Factor %d: %f\n", i, totalFormFactori[i]); //printf("JPoint: (%f %f %f)\tHitPoint: (%f %f %f)\tSame: %d\n", point2.x, point2.y, point2.z, hitPoint.x, hitPoint.y, hitPoint.z, comparePoints(point2, hitPoint)); } //printf("FormFactor(%d, %d): %f\n", i, j, formFactorTemp); setFormFactor(i, j, formFactorTemp); totalFormFactori[i]+= formFactorTemp; //cast n rays from patch 1 to patch 2 and see how many are occluded //integrate point to point form factor Cos(thetaI)*Cos(thetaJ)/PI*|R|^2 //this will use getFace[i].getRandomPoint() //for testing purposes we are gonna use the centers of the faces to start } //printf("Total Form Factor %d: %f\n", i, totalFormFactori[i]); } //SUM ALL UNDISTRIBUTED EVERY ITERATION*********************************************************************** }
void rs274emc::slotOutputProtoCode() //creates g-Code and saves results to a file { //view Path->projectedPasses cout<<"Path->projectedPasses.size(" <<Path->projectedPasses.size()<<")"<<endl; //AK for(uint i=0;i < Path->projectedPasses.size(); i++){ for(uint j=0;j < Path->projectedPasses.at(i).facesUsed.size(); j++) //AK testing//AK testing cout<<"Path->projectedPasses.at("<<i<<").facesUsed.size("<<j<<")" <<endl; //AK } //check if Toolpath is created bool checkVault=false; int readVault=3; checkVault = (staticVaultComputed(readVault)); if (!checkVault) { QMessageBox::warning( 0, "Warning", "rs274emc::slotOutputProtoCode - Compute path first !"); return;} /*for testing only else{ QMessageBox::warning( 0, "Info", "rs274emc::slotOutputProtoCode - pathComputed==true"); return;}*/ //open File to write g-Code FILE *outG; //new for enumerating files static int M=0; char format[] = "G-Code-%i.txt"; char dir[]="G-Code files"; char parentdir[]=".."; char filename[sizeof format+100]; sprintf(filename,format,M); // outG = fopen(filename,"w"); chdir(dir); outG = fopen(filename,"w"); M++; /* //create pop-up window and give filename and folder manually via gui QString fileName = QFileDialog::getSaveFileName(QString::null, "G-code (*.ngc)", 0, 0); outG = fopen (fileName, "w");//AK //outG = fopen ((const char*)fileName, "w"); if (outG == NULL) { QMessageBox::warning( 0, "Warning", "Can't open that file for writing!"); return; // uncomment *1* }*/ //set pathComputed false checkVault=(staticVaultComputed(2)); //write file content int setZero=0; int stCounter=0; gp_Pnt Cal1,Cal2,Cal1L,Cal2L,ToGo,ToGoL,Start,Buffer,veryFirst,verySecond,A,B,C,D; //g-code header fprintf(outG,"%%_N_TESTMAZE_CAMOCC)\n"); fprintf(outG,"; File %s created by cam-occ\n",filename); //ought to insert model's file name and the face ID into comment also... // *1* fprintf(outG,"; File %s created by cam-occ\n",(const char*)fileName); //ought to insert model's file name and the face ID into comment also... fprintf(outG,"; Info Safe height for rapids= %f \n",safeHeight); //safeHeight set in slotComputeSimplePathOnFace() above // edited by AK fprintf(outG,"; Info Tool Diameter = %i \n",toolDia); fprintf(outG,"; Info Feed = %i\n",feed); fprintf(outG,"; Info Speed = %i \n",speed); fprintf(outG,"\n; cancel tool diameter compensation\n"); fprintf(outG,"N%4i \t G40\n",stCounter+=10);//set cool compensation zero fprintf(outG,"\n; turn on air cooling\n"); fprintf(outG,"N%4i \t M71\n",stCounter+=10);//turn on air cooling fprintf(outG,"\n; move to home position\n"); fprintf(outG,"N%4i \t G00 X 0.00 \t Y 0.00 \t Z 10.00\n",stCounter+=10); //float limited to 2 decimals, move to home position //fprintf(outG,"; tool change\n"); //float limited to 2 decimals //fprintf(outG,"N%4i \t G00\t Z100\n",stCounter+=10); //float limited to 2 decimals //fprintf(outG,"N%4i \tT4 \t D1 \tM6 \n",stCounter+=10); //float limited to 2 decimals fprintf(outG,"\n; speed \t feed \t spindle on clockwise\n"); fprintf(outG,"N%4i \t S%i \tF%i \tM3 \n",stCounter+=10, speed, feed); //speed, feed spinle clockwise //missing in g-code // move to retract home base //switch on spindle //move fast to safety distance //set working feed //move to first point // Schruppen // Senken -2,5 F50 // schneiden mit F120 //Schlichten // Senken -1,5 F 50 //schneiden mit F200 cout <<"Path->projectedPasses.size()="<< Path->projectedPasses.size() <<endl; //this loop processes the blue lines drawn on the face for (int j=0;j<Path->projectedPasses.size();j++){ int checkLoop = setZero; cout <<"Test1"<<endl; //explorer to decompose the shape and find all edges in shape section AK TopExp_Explorer Ex; int forCounter=0; for (Ex.Init(Path->projectedPasses.at(j).P,TopAbs_EDGE); Ex.More(); Ex.Next()) { TopoDS_Wire W = BRepBuilderAPI_MakeWire(TopoDS::Edge(Ex.Current())); TopoDS_Vertex E1,E2; cout <<"Test2"<<endl; //find endpoints of wire, E1 E2 from pathAlgo analyzation TopExp::Vertices(W,E1,E2); // Get the 3D point for the vertex. Cal1 = BRep_Tool::Pnt(E1); Cal2 = BRep_Tool::Pnt(E2); if(!forCounter){ // fitst wire decomposed in start- and endpoint Cal1L=Cal1; Cal2L=Cal2; veryFirst=Cal1L; verySecond=Cal2L; } if(forCounter){ //second and more wire decomposed //to calculate we have Start, ToGo, ToGoL,Cal1, Cal2 //connect next wire to Cal1L if(comparePoints(Cal1L,Cal1)){ ToGoL=Cal1L; ToGo=Cal2; Start=Cal2L; } if (comparePoints(Cal1L,Cal2)) { ToGoL=Cal1L; ToGo=Cal1; Start=Cal2L; } //Connect next Wire to Cal2L if(comparePoints(Cal2L,Cal1)){ ToGoL=Cal2L; ToGo=Cal2; Start=Cal1L; } if(comparePoints(Cal2L,Cal2)) { ToGoL=Cal2; ToGo=Cal1; Start=Cal1L; } if(forCounter==1&& (!j)){ fprintf(outG,"\n; move to starting point (z) of first level and plunge \n"); //float limited to 2 decimals fprintf(outG,"N%4i \t G00 X%6.2f \t Y%6.2f \t Z%6.2f \n",stCounter+=10,Start.X(),Start.Y(),safeHeight); //float limited to 2 decimals fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F50 \n",stCounter+=10,Start.X(),Start.Y(),Start.Z()); //float limited to 2 decimals fprintf(outG,"\n; move along tool-path (xy) of first level \n"); //float limited to 2 decimals fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,ToGoL.X(),ToGoL.Y(),ToGoL.Z(), feed); //float limited to 2 decimals } if(forCounter==1 && j){ //move to first point of new level but in z offset fprintf(outG,"\n; move to starting point (z) of next level and plunge\n"); //float limited to 2 decimals fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,Start.X(),Start.Y(),Buffer.Z(), feed); //float limited to 2 decimals fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F50 \n",stCounter+=10,Start.X(),Start.Y(),Start.Z()); //float limited to 2 decimals fprintf(outG,"\n; move along tool-path (xy) of next level \n"); //float limited to 2 decimals fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,ToGoL.X(),ToGoL.Y(),ToGoL.Z(), feed); //float limited to 2 decimals } //output standard points to move to fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,ToGo.X(),ToGo.Y(),ToGo.Z(), feed); //float limited to 2 decimals Buffer=ToGo; Cal1L=Cal1; Cal2L=Cal2; } forCounter++; } //go around the rectangle once to cut "cheese chunks if (veryFirst.X() == ToGoL.X() || veryFirst.Y() == ToGoL.Y()){ A=veryFirst; B=ToGoL; C=ToGo; D=verySecond; } if (verySecond.X() == ToGoL.X() || verySecond.Y() == ToGoL.Y()){ A=verySecond; B=ToGoL; C=ToGo; D=veryFirst; } fprintf(outG,"\n; move around rectangle (xy) \n"); //float limited to 2 decimals fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,A.X(),A.Y(),A.Z(), feed); //float limited to 2 decimals fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,B.X(),B.Y(),B.Z(), feed); //float limited to 2 decimals fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,C.X(),C.Y(),C.Z(), feed); //float limited to 2 decimals fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f \t F%i \n",stCounter+=10,D.X(),D.Y(),D.Z(), feed); //float limited to 2 decimals checkLoop++;// rise loop counter } //g-code footer fprintf(outG,"\n;move to safeHeight\n"); fprintf(outG,"N%4i \t G01 X%6.2f \t Y%6.2f \t Z%6.2f\n",stCounter+=10,ToGo.X(),ToGo.Y(),safeHeight); //float limited to 2 decimals fprintf(outG,"\n;stop spindle turning\n"); fprintf(outG,"N%4i \t M05 \t \n",stCounter+=10); fprintf(outG,"\n; move to home position\n"); fprintf(outG,"N%4i \t G00 X 0.00 \t Y 0.00 \t Z 10.00\n",stCounter+=10); //float limited to 2 decimals fprintf(outG,"\n; end of main program\n"); fprintf(outG,"N%4i \t M30\n",stCounter+=10); fclose(outG);// close file chdir(parentdir); return ; }