//will add points along exsisting edges and make new faces from them void geo_sphere::subdivide_geosphere(int res){ int e = n_tri(res); if(gs_sphere_start[res]+e>(int)gstris.size())return; for(int i = 0; i<e; i++){ int p1 = gstris[gs_sphere_start[res] + i].point[0]; int p2 = gstris[gs_sphere_start[res] + i].point[1]; int p3= gstris[gs_sphere_start[res] + i].point[2]; vector3d v1 = gspoints[p1]; vector3d v2 = gspoints[p2]; vector3d v3 = gspoints[p3]; //adding two vectors makes a scalar multiple of of there average //normaliseing them will project them onto the unit sphere int p12 = add_if_not_present(MakeUnitVector(v1+v2)); int p23 = add_if_not_present(MakeUnitVector(v2+v3)); int p31 = add_if_not_present(MakeUnitVector(v3+v1)); gstris.push_back(stri(p1,p12,p31)); gstris.push_back(stri(p2,p23,p12)); gstris.push_back(stri(p3,p31,p23)); gstris.push_back(stri(p12,p23,p31)); } }
std::string CHostIce::clientId( const std::string & nickname, const ::Client::CClientPrx & client ) { QCryptographicHash hash( QCryptographicHash::Sha1 ); hash.addData( QString::fromStdString( nickname ).toAscii() ); hash.addData( QString::fromStdString( client->ice_id() ).toAscii() ); QString stri( hash.result().toHex() ); std::string id = stri.toStdString(); return id; }
int main(int argc, char *argv[]) { // printf("startup integers:\n"); // for (int i=1;i<argc;i++) { // printf("arg%d: %s\n", i, argv[i]); // }; // for (int i=0; i<100; i++ ) { // printf("%d %d\n", i, i*i); // } //Rand yrand1(time(NULL)); //Rand yrand2(time(NULL)+1); //Rand yrand3(time(NULL)+2); Rand yrand1(42); Rand yrand2(11); Rand yrand3(7); // for (int i=0; i<25; i++) { printf("r1,r2,r3: %f, %f\n", yrand1.nextDouble(), yrand2.nextDouble()); printf("**r1,r2,r3: %d, %d\n", yrand1.nextInt(42), yrand2.nextInt(1)); }; printf("-------------------------\n"); // Rand yrand4(42); Rand yrand5(11); Rand yrand6(7); for (int ii=0; ii<5; ii++) { for (int i=0; i<5; i++) { printf("r1,r2,r3: %f, %f, %f\n", yrand4.nextDouble(), yrand5.nextDouble(), yrand6.nextDouble()); }; printf("next 5\n"); }; // printf("mod: 5%2 : %d, 4%2 : %d, 6%3 : %d, 6%5 : %d\n", 5%2, 4%2, 6%3, 6%5); printf("declare a big ass array:\n"); // this will cause a segmentation error. //short myBigArray[5000000]; int *arySize = new int; *arySize=1500000000; printf("array size declared [%d]...\n", *arySize); int *myBigArray = new int[*arySize]; int *myRegArray; myRegArray = new int[10000]; printf("array declared [%d]...\n", *arySize); // //int anArray[100]; //printf("size of myBigArray: %d\n", int(sizeof(myRegArray))/int(sizeof(int)) ); // not useful for pointer-arrays. delete myBigArray; delete myRegArray; /* for (int i=0; i<100; i++) { printf("rand %d: (%d)\n", i, yrand1.nextInt(4)); }; int a=5; int b=2; int c=4; printf("5%2: %d\n", 5%2); printf("4%2: %d\n", 4%2); printf("5/2: %d\n", a/b); printf("4/2: %d\n", c/b); */ myClass myhello; myhello.setHello2("this is hello2."); myhello.sayHello("hello from primary hello"); myhello.sayHello2(); printf("hello2Str: %s\n", myhello.getHello2().c_str()); // // for (int i=0; i<10; i++) { printf("nextInt(1): %d\n", yrand4.nextInt(1)); // random of set of 1 numbers; (always 0) }; // // can put a pipe/redirection in the place of a file? std::ifstream myfile; std::string line; myfile.open("ffdifference.gnu"); //myfile.open("<mysql -umyoder -pyoda -DQuakeData -r -e""select concat(cast(year(eventDateTime) as char(4)), ' ' , cast(month(eventDateTime) as char(4)), ' ', cast(day(eventDateTime) as char(2)), ' ' , cast(lng as char(10)), ' ', cast(lat as char(10)), ' ', cast(mag as char(6)) ) as '' from earthquakes limit 100"""); while (! myfile.eof() ) { getline(myfile,line); cout<<line<<endl; }; myfile.close(); char str1[]="4567"; char str2[]="45a67"; printf("digit tests:\n"); printf("isdigit('a'): %d\n", isdigit(str1[2])); printf("isdigit('4'): %d\n", isdigit(str2[2])); printf("isnumeric('4567'): %d\n", isnumeric(str1, 4)); printf("isnumeric('45a67'): %d\n", isnumeric(str2, 5)); // printf("strlen(str1): %u\n", strlen(str2)); char argString[] = "dataIndex, lat, lon, 2, 5, 0, 1a"; int strLen = strlen(argString); char *strCols = argString; int nCols=1; for (int i=0; i < strLen; i++) { if (strCols[i]==',') nCols++; //eventually gives nCols-1 printf("i: %d\n", i); }; printf("ncols: %d\n", nCols); // std::string argStrings[nCols]; int thisCol=0; argStrings[0]=""; // scan the string again; assign values: for (int i=0; i <= strLen; i++) { if (strCols[i] != ',' && strCols[i] !=' ') { argStrings[thisCol] += strCols[i]; }; if (strCols[i] == ',') { // new element: // // if it is not numeric, wrap it in quotes: // if (isnumeric(argStrings[thisCol].c_str(), argStrings[thisCol].size() )==0) { // argStrings[thisCol].insert(argStrings[thisCol].begin()+0, "'"); // argStrings[thisCol] += "'"; // }; thisCol++; // initialize next column: argStrings[thisCol]=""; }; }; for (int i=0; i<nCols; i++) { char *thisStr = new char[argStrings[i].size()]; for (unsigned int ii=0; ii<argStrings[i].size(); ii++) { *(thisStr + ii) = argStrings[i].c_str()[ii]; }; // use this to wrap a col-name in "`" (or something). these variables don't // seem to pass properly anyway, so we'll just get the indices from the row-data. /* if (!isnumeric(thisStr, argStrings[i].size())) { std::string newstring="`"; newstring.append(argStrings[i].c_str()); newstring.append("`"); // argStrings[i]=newstring; // delete &newstring; delete thisStr; char *thisStr = new char[argStrings[i].size()]; for (unsigned int ii=0; ii<argStrings[i].size(); ii++) { *(thisStr + ii) = argStrings[i].c_str()[ii]; }; }; */ printf("col %d: %s, isnumeric(%d)\n", i, argStrings[i].c_str(), isnumeric(thisStr, argStrings[i].size())); // printf("col %d: %s\n", i, argStrings[i].c_str()); delete thisStr; }; mysqlpp::Connection mycon("QuakeData", "localhost", "myoder", "yoda"); //mysqlpp::Query myquery=mycon.query(); mysqlpp::Query myquery=mycon.query(); mysqlpp::StoreQueryResult res1; // mysqlpp::UseQueryResult res1=query.use(); // this appears to simply not be part of modern MySQL++ // myquery << "select * from PI where dataIndex=12 limit 15"; // myquery.parse(); res1 = myquery.store(); // float myint = res1.at(2).at(2); printf("field 2,2: %f\n", myint); std::string strLat("lat"); // mysqlpp::Row row = res1.fetch_row(); // printf("lat: %s\n", row("lat")); printf("field-2-name: %s\n", res1.field_name(2).c_str() ); printf("field-lat-num: %d\n", res1.field_num(strLat)); // char str1a[]={"seismicity"}; char str2a[]={"101"}; // newLen1 = strlen(str1a); // newLen2 = strlen(str2a); char newstr[100]; strcpy(newstr, str1a); strcat(newstr, str2a); strcat(newstr, ".xyz"); printf("newstr: %s\n", newstr); // char newstr[]=str1a + str2a + ".xyz"; std::ostringstream os; os << "str1" << 5 << "_" << 6.7; std::string teststring(os.str()); printf("teststring: %s\n", teststring.c_str()); std::string str1b="str1f"; std::string str2b="str1abc"; printf("compare %i\n", str1b==str2b); printf("compare %i\n", str1b.compare(str2b)); time_t mytime; time (&mytime); printf("local time: %s\n", ctime(&mytime)); std::vector<float> vRow(4,0); std::vector<std::vector<float> > myvec; std::vector<std::vector<float> > myvec0; std::vector<std::vector<float> > myvec1; std::vector<std::vector<float> > myvec2; for (int i=0; i<10; i++) { for (int ii=0; ii<4; ii++) vRow[ii] = float(rand()%100)/100; myvec.push_back(vRow); }; for (unsigned i=0; i<myvec.size(); i++) { printf("myvec: %f, %f, %f, %f (%d/%d)\n", myvec[i][0], myvec[i][1], myvec[i][2], myvec[i][3] , i, myvec.size()); }; printf ("===================\n"); myvec0=myvec; myvec1=sortHvector(myvec0,2); //myvec1=sortHvector(myvec1,2); //myvec1=sortHvector(myvec1,2); // myvec.erase(myvec.begin()+4); for (unsigned i=0; i<myvec1.size(); i++) { printf("myvec: %f, %f, %f, %f (%d/%d)\n", myvec1[i][0], myvec1[i][1], myvec1[i][2], myvec1[i][3] , i, myvec1.size()); }; // funny assignments... printf("funny assignments\n"); float f1, f2; int i1, i2; std::string stri("1234567"); std::string strf("245.17"); // std::ostringstream strBuffer; std::string strBuffer; // // string::iterator rit; for (std::string::iterator rit=stri.begin(); rit < stri.end(); rit++) { // strBuffer << *rit; strBuffer.push_back(*rit); // cout << *rit; }; i1=atoi(strBuffer.c_str()); printf("strBuffer: %s/%d\n", strBuffer.c_str(), i1); strBuffer.clear(); // integer arithmetic: // int a=10,b=3,c=21,d=4; printf("integer operations:\n"); printf("10/3=%d, 8/3=%d, 10pct3=%d, 10^3=%d\n", 10/3, 8/3, 10%3, 10^3); std::string testString("this is a test.") printf("test string: %s\n", testString.c_str()); // for (rit=strf.begin(); rit < strf.end(); rit++) { // strBuffer << *rit; // }; return 0; };
void geo_sphere::make_isohedron(){ gspoints.resize(12); gstris.resize(20); int i = 0; //points gspoints[i++] = vector3d(0, GS1, GSP);//0 gspoints[i++] = vector3d(0, -GS1, GSP); gspoints[i++] = vector3d(0, GS1, -GSP); gspoints[i++] = vector3d(0, -GS1, -GSP); gspoints[i++] = vector3d(GS1, GSP, 0);//4 gspoints[i++] = vector3d(-GS1, GSP, 0); gspoints[i++] = vector3d(GS1, -GSP, 0); gspoints[i++] = vector3d(-GS1, -GSP, 0); gspoints[i++] = vector3d(GSP, 0, GS1);//8 gspoints[i++] = vector3d(GSP, 0, -GS1); gspoints[i++] = vector3d(-GSP, 0, GS1); gspoints[i++] = vector3d(-GSP, 0, -GS1); //points done i=0; //tris //yes this was basicly done by hand... gstris[i++] = stri(0,1,10); gstris[i++] = stri(0,10,5); gstris[i++] = stri(0,5,4); gstris[i++] = stri(0,4,8); gstris[i++] = stri(0,8,1); gstris[i++] = stri(1,8,6); gstris[i++] = stri(1,6,7); gstris[i++] = stri(1,7,10); gstris[i++] = stri(11,10,7); gstris[i++] = stri(11,7,3); gstris[i++] = stri(11,3,2); gstris[i++] = stri(11,2,5); gstris[i++] = stri(11,5,10); gstris[i++] = stri(7,6,3); gstris[i++] = stri(5,2,4); gstris[i++] = stri(9,4,2); gstris[i++] = stri(9,2,3); gstris[i++] = stri(9,3,6); gstris[i++] = stri(9,6,8); gstris[i++] = stri(9,8,4); //done tris }