void Twofish::SetKey(const byte* userKey, word32 keylen, CipherDir /*dummy*/) { unsigned int len = (keylen <= 16 ? 2 : (keylen <= 24 ? 3 : 4)); word32 key[8]; GetUserKey(LittleEndianOrder, key, len*2, userKey, keylen); unsigned int i; for (i=0; i<40; i+=2) { word32 a = h(i, key, len); word32 b = rotlFixed(h(i+1, key+1, len), 8); k_[i] = a+b; k_[i+1] = rotlFixed(a+2*b, 9); } word32 svec[8]; for (i=0; i<len; i++) svec[2*(len-i-1)] = ReedSolomon(key[2*i+1], key[2*i]); for (i=0; i<256; i++) { word32 t = h0(i, svec, len); s_[0][i] = mds_[0][GETBYTE(t, 0)]; s_[1][i] = mds_[1][GETBYTE(t, 1)]; s_[2][i] = mds_[2][GETBYTE(t, 2)]; s_[3][i] = mds_[3][GETBYTE(t, 3)]; } }
int main() { void h0(float, float); void e0(float, float); void s0(float, float); float a, b, c; printf("请输入a,b,c:"); scanf("%f,%f,%f", &a, &b, &c); printf("方程为:%5.2fx*x+%5.2fx+%5.2f=0\n", a, b, c); Delta = b*b - 4 * a*c; printf("结果是:\n"); if (Delta > 0) { h0(a, b); printf("x1=%f\nx2=%f\n", x1, x2); } else if (Delta < 0) { s0(a, b); printf("x1=%f+%fi\nx2=%f-%fi\n", m, n, m, n); } else { e0(a, b); printf("x1=x2=%f\n", x1); } return 0; }
int h(int bitpos) { if (getbit(bitpos)) return h1(bitpos+1); else return h0(bitpos+1); }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Sig_Handlers_Test")); ACE_Sig_Handlers multi_handlers; ACE_Select_Reactor reactor_impl (&multi_handlers); ACE_Reactor reactor (&reactor_impl); ACE_Reactor::instance (&reactor); // Create a bevy of handlers. Test_SIGINT_Handler h1 (ACE_Reactor::instance (), "h1"); Test_SIGINT_Handler h2 (ACE_Reactor::instance (), "h2"); Test_SIGINT_Handler h3 (ACE_Reactor::instance (), "h3"); Test_SIGINT_Handler h4 (ACE_Reactor::instance (), "h4"); Test_SIGINT_Handler h5 (ACE_Reactor::instance (), "h5"); Test_SIGINT_Handler h6 (ACE_Reactor::instance (), "h6"); Test_SIGINT_Handler h7 (ACE_Reactor::instance (), "h7"); Test_SIGINT_Handler h8 (ACE_Reactor::instance (), "h8"); Test_SIGINT_Shutdown_Handler h0 (ACE_Reactor::instance ()); // Wait for user to type SIGINT. while (!ACE_Reactor::instance ()->reactor_event_loop_done ()) { ACE_DEBUG ((LM_DEBUG,"\nwaiting for SIGINT\n")); if (ACE_Reactor::instance ()->handle_events () == -1) ACE_ERROR ((LM_ERROR,"%p\n","handle_events")); } ACE_END_TEST; return 0; }
int main() { S1<int> s1; S2<int, int> s2; f(0); g(0, 1); h0((int*)0); h1((int*)0); h2((int*)0); }
Image adaptive_otsu(const Image &image, int window) { int num_bins=20; Image result(Geometry(image.columns(),image.rows()),"white"); vector<int> h(num_bins,0); vector<int> h0(num_bins,0); ColorGray g; int peak1, peak2, max1, max2; for (int i1 = 0; i1 < min((int)image.columns(), window/2); i1++) for (int j1 = 0; j1 < min((int)image.rows(), window/2); j1++) { g = image.pixelColor(i1, j1); h0[int((num_bins-1)*g.shade())]++; } for (int j = 0; j < image.rows(); j++) { for (int k = 0; k<num_bins; k++) h[k]=h0[k]; for (int i = 0; i < image.columns(); i++) { otsu_find_peaks(h,num_bins,peak1,peak2, max1, max2); g = image.pixelColor(i, j); double median = 0.5*(peak1+peak2)/num_bins; if (g.shade() > median) result.pixelColor(i,j,"white"); else result.pixelColor(i,j,"black"); if ((i-window/2) >=0) for (int j1 = max(0,j-window/2); j1 < min((int)image.rows(), j + window/2); j1++) { g = image.pixelColor(i-window/2, j1); h[int((num_bins-1)*g.shade())]--; } if ((i+window/2) < image.columns()) for (int j1 = max(0,j-window/2); j1 < min((int)image.rows(), j + window/2); j1++) { g = image.pixelColor(i+window/2, j1); h[int((num_bins-1)*g.shade())]++; } } if ((j-window/2) >=0) for (int i1 = 0; i1 < min((int)image.columns(),window/2); i1++) { g = image.pixelColor(i1,j-window/2); h0[int((num_bins-1)*g.shade())]--; } if ((j+window/2) < image.rows()) for (int i1 = 0; i1 < min((int)image.columns(),window/2); i1++) { g = image.pixelColor(i1,j+window/2); h0[int((num_bins-1)*g.shade())]++; } } return(result); }
void TestStelSphericalGeometry::benchmarkSphericalCap() { Vec3d p0(1,0,0); Vec3d p2(1,1,1); p2.normalize(); SphericalCap h0(p0, 0); SphericalCap h4(p2, 0.8); QBENCHMARK { h0.intersects(h4); } }
/** * Decrypt a single block of data. */ void skipjack_decrypt(byte tab[10][256], byte in[8], byte out[8]) { word32 w1, w2, w3, w4; w1 = (in[0] << 8) + in[1]; w2 = (in[2] << 8) + in[3]; w3 = (in[4] << 8) + in[5]; w4 = (in[6] << 8) + in[7]; /* stepping rule A: */ h1(tab, w2); w3 ^= w2 ^ 32; h0(tab, w3); w4 ^= w3 ^ 31; h4(tab, w4); w1 ^= w4 ^ 30; h3(tab, w1); w2 ^= w1 ^ 29; h2(tab, w2); w3 ^= w2 ^ 28; h1(tab, w3); w4 ^= w3 ^ 27; h0(tab, w4); w1 ^= w4 ^ 26; h4(tab, w1); w2 ^= w1 ^ 25; /* stepping rule B: */ w1 ^= w2 ^ 24; h3(tab, w2); w2 ^= w3 ^ 23; h2(tab, w3); w3 ^= w4 ^ 22; h1(tab, w4); w4 ^= w1 ^ 21; h0(tab, w1); w1 ^= w2 ^ 20; h4(tab, w2); w2 ^= w3 ^ 19; h3(tab, w3); w3 ^= w4 ^ 18; h2(tab, w4); w4 ^= w1 ^ 17; h1(tab, w1); /* stepping rule A: */ h0(tab, w2); w3 ^= w2 ^ 16; h4(tab, w3); w4 ^= w3 ^ 15; h3(tab, w4); w1 ^= w4 ^ 14; h2(tab, w1); w2 ^= w1 ^ 13; h1(tab, w2); w3 ^= w2 ^ 12; h0(tab, w3); w4 ^= w3 ^ 11; h4(tab, w4); w1 ^= w4 ^ 10; h3(tab, w1); w2 ^= w1 ^ 9; /* stepping rule B: */ w1 ^= w2 ^ 8; h2(tab, w2); w2 ^= w3 ^ 7; h1(tab, w3); w3 ^= w4 ^ 6; h0(tab, w4); w4 ^= w1 ^ 5; h4(tab, w1); w1 ^= w2 ^ 4; h3(tab, w2); w2 ^= w3 ^ 3; h2(tab, w3); w3 ^= w4 ^ 2; h1(tab, w4); w4 ^= w1 ^ 1; h0(tab, w1); out[0] = (byte)(w1 >> 8); out[1] = (byte)w1; out[2] = (byte)(w2 >> 8); out[3] = (byte)w2; out[4] = (byte)(w3 >> 8); out[5] = (byte)w3; out[6] = (byte)(w4 >> 8); out[7] = (byte)w4; }
void CV_CompareHistTest::run_func(void) { int k; if( hist_type != CV_HIST_ARRAY && test_cpp ) { cv::SparseMat h0((CvSparseMat*)hist[0]->bins); cv::SparseMat h1((CvSparseMat*)hist[1]->bins); for( k = 0; k < MAX_METHOD; k++ ) result[k] = cv::compareHist(h0, h1, k); } else for( k = 0; k < MAX_METHOD; k++ ) result[k] = cvCompareHist( hist[0], hist[1], k ); }
int main() { GHB::Host h0("host0", "00:00:00...", 0, "open house"); GHB::Host h1("host1", "00:00:01...", 1, "closed"); GHB::Date today(5, 7, 2011); GHB::Date yesterday(4,7, 2011); GHB::TrafficDay t1(100, h0, today); GHB::TrafficDay t2(200, h0, today); GHB::TrafficDay t3(300, h1, today); GHB::TrafficDay t4(400, h0, yesterday); std::list<GHB::TrafficDay> traffics; traffics.push_back(t1); traffics.push_back(t2); traffics.push_back(t3); traffics.push_back(t4); GHB::TrafficTotal total(traffics); assert(total.getTotalByDate(today) == 600); assert(total.getTotalByHost(h0) == 700); assert(total.getTotal() == 1000); GHB::Host hx("hostx", "00:00:00...", 3, "not existent"); assert(total.getTotalByHost(hx) == 0); GHB::Date someday(1,1,2001); assert(total.getTotalByDate(someday) == 0); try { const GHB::TrafficDay& ignored = total.getTrafficDay(h0, today); assert(true); } catch (std::exception ex) { assert(false); } try { const GHB::TrafficDay& ignored = total.getTrafficDay(h0, someday); } catch (std::out_of_range ex) { assert(true); } catch (std::exception ex) { assert(false);} try { const GHB::TrafficDay& ignored = total.getTrafficDay(hx, today); } catch (std::out_of_range ex) { assert(true); } catch (std::exception ex) { assert(false);} try { const GHB::TrafficDay& ignored = total.getTrafficDay(hx, someday); } catch (std::out_of_range ex) { assert(true); } catch (std::exception ex) { assert(false);} }
DatasetPlane::DatasetPlane() : Dataset( QDir( "new plane" ), Fn::DatasetType::PLANE ), vbo0( 0 ), m_handle0( GLFunctions::getPickIndex() ), m_handle1( GLFunctions::getPickIndex() ), m_handle2( GLFunctions::getPickIndex() ), dirty( true ) { QList<Dataset*>dsl = Models::getDatasets( Fn::DatasetType::NIFTI_ANY ); int nx = 160; int ny = 200; int nz = 160; float dx = 1.0f; float dy = 1.0f; float dz = 1.0f; float ax = 0.0f; float ay = 0.0f; float az = 0.0f; if ( dsl.size() > 0 ) { nx = dsl[0]->properties().get( Fn::Property::D_NX ).toInt(); ny = dsl[0]->properties().get( Fn::Property::D_NY ).toInt(); nz = dsl[0]->properties().get( Fn::Property::D_NZ ).toInt(); dx = dsl[0]->properties().get( Fn::Property::D_DX ).toFloat(); dy = dsl[0]->properties().get( Fn::Property::D_DY ).toFloat(); dz = dsl[0]->properties().get( Fn::Property::D_DZ ).toFloat(); ax = dsl[0]->properties().get( Fn::Property::D_ADJUST_X ).toFloat(); ay = dsl[0]->properties().get( Fn::Property::D_ADJUST_Y ).toFloat(); az = dsl[0]->properties().get( Fn::Property::D_ADJUST_Z ).toFloat(); } QVector3D h0( nx * dx / 2 + ax, ny * dy / 2 + ay, nz * dz / 2 + az ); QVector3D h1( ax, h0.y(), h0.z() ); QVector3D h2( h0.x(), ay, h0.z() ); m_properties["maingl"].createBool( Fn::Property::D_SHOW_PLANE_HANDLES, true, "general" ); m_properties["maingl"].createColor( Fn::Property::D_HANDLE_COLOR, QColor( 255, 0, 0 ), "general" ); m_properties["maingl"].createVector( Fn::Property::D_HANDLE_0, h0, "handles" ); m_properties["maingl"].createVector( Fn::Property::D_HANDLE_1, h1, "handles" ); m_properties["maingl"].createVector( Fn::Property::D_HANDLE_2, h2, "handles" ); PropertyGroup props2( m_properties["maingl"] ); m_properties.insert( "maingl2", props2 ); m_properties["maingl2"].createBool( Fn::Property::D_SHOW_PLANE_HANDLES, true, "general" ); m_properties["maingl2"].createColor( Fn::Property::D_HANDLE_COLOR, QColor( 255, 0, 0 ), "general" ); }
/** * Decrypt a single block of data. */ void SKIPJACK::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const { word w1, w2, w3, w4; Block::Get(inBlock)(w4)(w3)(w2)(w1); /* stepping rule A: */ h1(tab, w2); w3 ^= w2 ^ 32; h0(tab, w3); w4 ^= w3 ^ 31; h4(tab, w4); w1 ^= w4 ^ 30; h3(tab, w1); w2 ^= w1 ^ 29; h2(tab, w2); w3 ^= w2 ^ 28; h1(tab, w3); w4 ^= w3 ^ 27; h0(tab, w4); w1 ^= w4 ^ 26; h4(tab, w1); w2 ^= w1 ^ 25; /* stepping rule B: */ w1 ^= w2 ^ 24; h3(tab, w2); w2 ^= w3 ^ 23; h2(tab, w3); w3 ^= w4 ^ 22; h1(tab, w4); w4 ^= w1 ^ 21; h0(tab, w1); w1 ^= w2 ^ 20; h4(tab, w2); w2 ^= w3 ^ 19; h3(tab, w3); w3 ^= w4 ^ 18; h2(tab, w4); w4 ^= w1 ^ 17; h1(tab, w1); /* stepping rule A: */ h0(tab, w2); w3 ^= w2 ^ 16; h4(tab, w3); w4 ^= w3 ^ 15; h3(tab, w4); w1 ^= w4 ^ 14; h2(tab, w1); w2 ^= w1 ^ 13; h1(tab, w2); w3 ^= w2 ^ 12; h0(tab, w3); w4 ^= w3 ^ 11; h4(tab, w4); w1 ^= w4 ^ 10; h3(tab, w1); w2 ^= w1 ^ 9; /* stepping rule B: */ w1 ^= w2 ^ 8; h2(tab, w2); w2 ^= w3 ^ 7; h1(tab, w3); w3 ^= w4 ^ 6; h0(tab, w4); w4 ^= w1 ^ 5; h4(tab, w1); w1 ^= w2 ^ 4; h3(tab, w2); w2 ^= w3 ^ 3; h2(tab, w3); w3 ^= w4 ^ 2; h1(tab, w4); w4 ^= w1 ^ 1; h0(tab, w1); Block::Put(xorBlock, outBlock)(w4)(w3)(w2)(w1); }
void real_unique_ownership() { // `h0` is the current unique owner. resource::unique<behavior::file_b> h0(legacy::open_file()); // ... use `h0` ... // `h1` is the current unique owner. auto h1 = std::move(h0); // ... use `h1` ... // OK - `h0` is a null handle. // (Done automatically.) // ... use `h1` ... // Resource released. `h1` will point to a "null handle". // (Done automatically.) }
int main() { GHB::Host h0("host0", "00:00:...", 0, "open house"); std::vector<GHB::Host> hosts; hosts.push_back(h0); GHB::Account acc("morpheus", 10, hosts); { // Test 1 xmlpp::DomParser parser; parser.parse_memory(xmlteststrings[0]); xmlpp::Document* doc = parser.get_document(); xmlpp::Element* root = doc->get_root_node(); GHB::TrafficDay day = GHB::TrafficDayXML::parseXML(root, acc); assert(day.getTotal() == 100); assert(day.getHost().getHostname() == "host0"); assert(day.getDate().getDay() == 4); assert(day.getDate().getMonth() == 7); assert(day.getDate().getYear() == 2011); } }
void test8() { printf("\ntesting n-ary array functions: g(), h() ...\n"); int32_t n; printf("\ncreating A...\n"); A * a = new A(); const A * ac = a; h0(); h1(1); h2(1, 2); h3(1, 2, 3); n = h0r(); assert(n == 0); n = h1r(1); assert(n == 1); n = h2r(1, 2); assert(n == 3); n = h3r(1, 2, 3); assert(n == 6); ac->g0c(); ac->g1c(1); ac->g2c(1, 2); ac->g3c(1, 2, 3); a->g0(); a->g1(1); a->g2(1, 2); a->g3(1, 2, 3); n = ac->g0rc(); assert(n == 0); n = ac->g1rc(1); assert(n == 1); n = ac->g2rc(1, 2); assert(n == 3); n = ac->g3rc(1, 2, 3); assert(n == 6); n = a->g0r(); assert(n == 0); n = a->g1r(1); assert(n == 1); n = a->g2r(1, 2); assert(n == 3); n = a->g3r(1, 2, 3); assert(n == 6); printf("delete A...\n"); delete a; }
void test01() { { String on1; on1 = "//atp:77/root/cimv25:" "TennisPlayer.last=\"Rafter\",first=\"Patrick\""; String on2; on2 = "//atp:77/root/cimv25:" "TennisPlayer.first=\"Patrick\",last=\"Rafter\""; CIMObjectPath r = on1; PEGASUS_TEST_ASSERT(r.toString() != on1); PEGASUS_TEST_ASSERT(r.toString() == on2); CIMObjectPath r2 = r; CIMObjectPath r3 = CIMObjectPath ("//atp:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); if (verbose) { XmlWriter::printValueReferenceElement(r, false); cout << r.toString() << endl; } Buffer mofOut; MofWriter::appendValueReferenceElement(mofOut, r); r.clear(); } { CIMObjectPath r1 = CIMObjectPath ("MyClass.z=true,y=1234,x=\"Hello World\""); CIMObjectPath r2 = CIMObjectPath ("myclass.X=\"Hello World\",Z=true,Y=1234"); CIMObjectPath r3 = CIMObjectPath ("myclass.X=\"Hello\",Z=true,Y=1234"); // cout << r1.toString() << endl; // cout << r2.toString() << endl; PEGASUS_TEST_ASSERT(r1 == r2); PEGASUS_TEST_ASSERT(r1 != r3); } // Test case independence and order independence of parameters. { CIMObjectPath r1 = CIMObjectPath ("X.a=123,b=true"); CIMObjectPath r2 = CIMObjectPath ("x.B=TRUE,A=123"); PEGASUS_TEST_ASSERT(r1 == r2); PEGASUS_TEST_ASSERT(r1.makeHashCode() == r2.makeHashCode()); CIMObjectPath r3 = CIMObjectPath ("x.B=TRUE,A=123,c=FALSE"); PEGASUS_TEST_ASSERT(r1 != r3); String keyValue; Array<CIMKeyBinding> kbArray; { Boolean found = false; kbArray = r3.getKeyBindings(); for (Uint32 i = 0; i < kbArray.size(); i++) { if (verbose) { cout << "keyName= " << kbArray[i].getName().getString() << " Value= " << kbArray[i].getValue() << endl; } if ( kbArray[i].getName() == CIMName ("B") ) { keyValue = kbArray[i].getValue(); if(keyValue == "TRUE") found = true; } } if(!found) { cerr << "Key Binding Test error " << endl; exit(1); } //ATTN: KS 12 May 2002 P3 DEFER - keybinding manipulation. too // simplistic. // This code demonstrates that it is not easy to manipulate and // test keybindings. Needs better tool both in CIMObjectPath and // separate. } } // Test building from component parts of CIM Reference. { CIMObjectPath r1 ("atp:77", CIMNamespaceName ("root/cimv25"), CIMName ("TennisPlayer")); CIMObjectPath r2 ("//atp:77/root/cimv25:TennisPlayer."); //cout << "r1 " << r1.toString() << endl; //cout << "r2 " << r2.toString() << endl; PEGASUS_TEST_ASSERT(r1 == r2); PEGASUS_TEST_ASSERT(r1.toString() == r2.toString()); } { String hostName = "atp:77"; String nameSpace = "root/cimv2"; String className = "tennisplayer"; CIMObjectPath r1; r1.setHost(hostName); r1.setNameSpace(nameSpace); r1.setClassName(className); PEGASUS_TEST_ASSERT(r1.getClassName().equal(CIMName ("TENNISPLAYER"))); PEGASUS_TEST_ASSERT(!r1.getClassName().equal(CIMName ("blob"))); String newHostName = r1.getHost(); //cout << "HostName = " << newHostName << endl; CIMObjectPath r2 (hostName, nameSpace, className); PEGASUS_TEST_ASSERT(r1 == r2); } // Test cases for the Hostname. CIMObjectPaths allows the // host to include the domain. Eg. xyz.company.com // First, try a good hostname CIMObjectPath h0("//usoPen-9.ustA-1-a.org:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h1("//usoPen-9:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h2("//usoPen-9/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h3("//usoPen-9.ustA-1-a.org:0/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h4("//usoPen-9.ustA-1-a.org:9876/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h5("//usoPen-9.ustA-1-a.org:65535/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h6("//usopen-9.usta-1-a.1org:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h7("//192.168.1.com:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h8("//192.168.0.org/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h9("//192.168.1.80.com:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h10("//192.168.0.80.org/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h11("//192.168.1.80.255.com:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h12("//192.168.0.80.254.org/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h13("//192.168.257.80.com:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h14("//192.256.0.80.org/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h15("//localhost/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h16("//ou812/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h17("//u812/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); // Hostname with '_' character support checks, see bug#2556. CIMObjectPath h18("//_atp:9999/_root/_cimv25:_TennisPlayer"); CIMObjectPath h19("//a_tp/_root/_cimv25:_TennisPlayer"); CIMObjectPath h20("//atp_:9999/_root/_cimv25:_TennisPlayer"); CIMObjectPath h21("//atp_-9:9999/_root/_cimv25:_TennisPlayer"); CIMObjectPath h22( "//_a_t_p_-9.ustA-1-a.org:9999/_root/_cimv25:_TennisPlayer"); CIMObjectPath h23("//_/root/cimv25:_TennisPlayer"); CIMObjectPath h24("//_______/root/cimv25:_TennisPlayer"); // try IPAddress as hostname which should be good CIMObjectPath h_ip0("//192.168.1.80:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath h_ip1("//192.168.0.255/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); // Try IPv6 Addresses. CIMObjectPath ip6_1("//[::1]:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath ip6_2("//[::ffff:192.1.2.3]:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath ip6_3("//[fffe:233:321:234d:e45:fad4:78:12]:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); CIMObjectPath ip6_4("//[fffe::]:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); Boolean errorDetected = false; // Invalid IPV6 Addresses try { // IPv6 addresses must be enclosed in brackets CIMObjectPath ip6_mb("//fffe::12ef:127/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // IPv6 address invalid CIMObjectPath ip6_invalid("//[fffe::sd:77]/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { //Port number out of range. CIMObjectPath h_Port("//usoPen-9.ustA-1-a.org:9876543210/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { //Port number out of range. CIMObjectPath h_Port("//usoPen-9.ustA-1-a.org:65536/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { //Port number out of range. CIMObjectPath h_Port("//usoPen-9.ustA-1-a.org:100000/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { //more than three digits in an octect CIMObjectPath h_ErrIp0("//192.1600008.1.80:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Octet out of range CIMObjectPath op("//192.168.256.80:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Missing port is okay, needs be ignored CIMObjectPath op("//192.168.1.80:/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(!errorDetected); errorDetected = false; try { // Too many octets CIMObjectPath op("//192.168.1.80.12/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Too few octets CIMObjectPath op("//192.168.80:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Missing port is okay, needs be ignored CIMObjectPath op("//usopen-9.usta-1-a.org:/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(!errorDetected); errorDetected = false; try { // Hostname (IP) without trailing '/' (with port) CIMObjectPath op("//192.168.256.80:77"); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Hostname (IP) without trailing '/' (without port) CIMObjectPath op("//192.168.256.80"); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Hostname without trailing '/' (with port) CIMObjectPath op("//usopen-9.usta-1-a.org:77"); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Hostname without trailing '/' (without port) CIMObjectPath op("//usopen-9.usta-1-a.org"); } catch (const Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Invalid first character CIMObjectPath op("//+usopen-9.usta-1-a.1org:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Non-alphanum char (?) CIMObjectPath op("//usopen-9.usta?-1-a.org:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Leading dot CIMObjectPath op("//.usopen-9.usta-1-a.org:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Dot in the wrong spot (before a -) CIMObjectPath op("//usopen.-9.usta-1-a.org:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Two dots in a row CIMObjectPath op("//usopen-9.usta-1-a..org:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); errorDetected = false; try { // Trailing dot CIMObjectPath op("//usopen-9.usta-1-a.org.:77/root/cimv25:" "TennisPlayer.first=\"Chris\",last=\"Evert\""); } catch (Exception&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); }
void TestStelSphericalGeometry::testSphericalCap() { Vec3d p0(1.,0.,0.); Vec3d p1(-1.,0.,0.); Vec3d p2(1.,1.,1.); p2.normalize(); Vec3d p3(0.,1.,0.); SphericalCap h0(p0, 0.); SphericalCap h1(p0, 0.8); SphericalCap h2(p0, -0.5); SphericalCap h3(p1, 0.5); SphericalCap h4(p2, 0.8); SphericalCap h5(p2, 1.); SphericalCap h6(p1, 0.); QVERIFY2(h0.contains(p0), "SphericalCap contains point failure"); QVERIFY2(h1.contains(p0), "SphericalCap contains point failure"); QVERIFY2(h0.contains(p3), "SphericalCap contains point on the edge failure"); QVERIFY2(h6.contains(p3), "SphericalCap contains point on the edge failure"); QVERIFY(h0.intersects(h1)); QVERIFY(h0.intersects(h2)); QVERIFY(h1.intersects(h2)); QVERIFY(h4.intersects(h1)); QVERIFY(!h0.intersects(h3)); QVERIFY(!h1.intersects(h3)); QVERIFY(h2.intersects(h3)); QVERIFY(h0.intersects(h5)); QVERIFY(h0.intersects(h0)); QVERIFY(h1.intersects(h1)); QVERIFY(h2.intersects(h2)); QVERIFY(h3.intersects(h3)); QVERIFY(h4.intersects(h4)); QVERIFY(h5.intersects(h5)); QVERIFY(h6.intersects(h0)); QVERIFY(h0.intersects(h6)); QVERIFY(h0.contains(h1)); QVERIFY(!h1.contains(h0)); QVERIFY(h2.contains(h0)); QVERIFY(!h0.contains(h2)); QVERIFY(!h6.contains(h0)); QVERIFY(!h0.contains(h6)); QVERIFY(h2.contains(h1)); QVERIFY(!h1.contains(h2)); QVERIFY(!h0.contains(h3)); QVERIFY(!h1.contains(h3)); QVERIFY(h0.contains(h5)); QVERIFY(h2.contains(h5)); QVERIFY(!h5.contains(h0)); QVERIFY(!h5.contains(h1)); QVERIFY(!h5.contains(h2)); QVERIFY(!h5.contains(h3)); QVERIFY(!h5.contains(h4)); QVERIFY(h0.contains(h0)); QVERIFY(h1.contains(h1)); QVERIFY(h2.contains(h2)); QVERIFY(h3.contains(h3)); QVERIFY(h4.contains(h4)); QVERIFY(h5.contains(h5)); }
void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t r, entity_pos_t range, const Goal& goal, pass_class_t passClass, Path& path) { UpdateGrid(); // TODO: only need to bother updating if the terrain changed PROFILE("ComputeShortPath"); // ScopeTimer UID__(L"ComputeShortPath"); m_DebugOverlayShortPathLines.clear(); if (m_DebugOverlay) { // Render the goal shape m_DebugOverlayShortPathLines.push_back(SOverlayLine()); m_DebugOverlayShortPathLines.back().m_Color = CColor(1, 0, 0, 1); switch (goal.type) { case CCmpPathfinder::Goal::POINT: { SimRender::ConstructCircleOnGround(GetSimContext(), goal.x.ToFloat(), goal.z.ToFloat(), 0.2f, m_DebugOverlayShortPathLines.back(), true); break; } case CCmpPathfinder::Goal::CIRCLE: { SimRender::ConstructCircleOnGround(GetSimContext(), goal.x.ToFloat(), goal.z.ToFloat(), goal.hw.ToFloat(), m_DebugOverlayShortPathLines.back(), true); break; } case CCmpPathfinder::Goal::SQUARE: { float a = atan2f(goal.v.X.ToFloat(), goal.v.Y.ToFloat()); SimRender::ConstructSquareOnGround(GetSimContext(), goal.x.ToFloat(), goal.z.ToFloat(), goal.hw.ToFloat()*2, goal.hh.ToFloat()*2, a, m_DebugOverlayShortPathLines.back(), true); break; } } } // List of collision edges - paths must never cross these. // (Edges are one-sided so intersections are fine in one direction, but not the other direction.) std::vector<Edge> edges; std::vector<Edge> edgesAA; // axis-aligned squares // Create impassable edges at the max-range boundary, so we can't escape the region // where we're meant to be searching fixed rangeXMin = x0 - range; fixed rangeXMax = x0 + range; fixed rangeZMin = z0 - range; fixed rangeZMax = z0 + range; { // (The edges are the opposite direction to usual, so it's an inside-out square) Edge e0 = { CFixedVector2D(rangeXMin, rangeZMin), CFixedVector2D(rangeXMin, rangeZMax) }; Edge e1 = { CFixedVector2D(rangeXMin, rangeZMax), CFixedVector2D(rangeXMax, rangeZMax) }; Edge e2 = { CFixedVector2D(rangeXMax, rangeZMax), CFixedVector2D(rangeXMax, rangeZMin) }; Edge e3 = { CFixedVector2D(rangeXMax, rangeZMin), CFixedVector2D(rangeXMin, rangeZMin) }; edges.push_back(e0); edges.push_back(e1); edges.push_back(e2); edges.push_back(e3); } // List of obstruction vertexes (plus start/end points); we'll try to find paths through // the graph defined by these vertexes std::vector<Vertex> vertexes; // Add the start point to the graph CFixedVector2D posStart(x0, z0); fixed hStart = (posStart - NearestPointOnGoal(posStart, goal)).Length(); Vertex start = { posStart, fixed::Zero(), hStart, 0, Vertex::OPEN, QUADRANT_NONE, QUADRANT_ALL }; vertexes.push_back(start); const size_t START_VERTEX_ID = 0; // Add the goal vertex to the graph. // Since the goal isn't always a point, this a special magic virtual vertex which moves around - whenever // we look at it from another vertex, it is moved to be the closest point on the goal shape to that vertex. Vertex end = { CFixedVector2D(goal.x, goal.z), fixed::Zero(), fixed::Zero(), 0, Vertex::UNEXPLORED, QUADRANT_NONE, QUADRANT_ALL }; vertexes.push_back(end); const size_t GOAL_VERTEX_ID = 1; // Add terrain obstructions { u16 i0, j0, i1, j1; NearestTile(rangeXMin, rangeZMin, i0, j0); NearestTile(rangeXMax, rangeZMax, i1, j1); AddTerrainEdges(edgesAA, vertexes, i0, j0, i1, j1, r, passClass, *m_Grid); } // Find all the obstruction squares that might affect us CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSimContext(), SYSTEM_ENTITY); std::vector<ICmpObstructionManager::ObstructionSquare> squares; cmpObstructionManager->GetObstructionsInRange(filter, rangeXMin - r, rangeZMin - r, rangeXMax + r, rangeZMax + r, squares); // Resize arrays to reduce reallocations vertexes.reserve(vertexes.size() + squares.size()*4); edgesAA.reserve(edgesAA.size() + squares.size()); // (assume most squares are AA) // Convert each obstruction square into collision edges and search graph vertexes for (size_t i = 0; i < squares.size(); ++i) { CFixedVector2D center(squares[i].x, squares[i].z); CFixedVector2D u = squares[i].u; CFixedVector2D v = squares[i].v; // Expand the vertexes by the moving unit's collision radius, to find the // closest we can get to it CFixedVector2D hd0(squares[i].hw + r + EDGE_EXPAND_DELTA, squares[i].hh + r + EDGE_EXPAND_DELTA); CFixedVector2D hd1(squares[i].hw + r + EDGE_EXPAND_DELTA, -(squares[i].hh + r + EDGE_EXPAND_DELTA)); // Check whether this is an axis-aligned square bool aa = (u.X == fixed::FromInt(1) && u.Y == fixed::Zero() && v.X == fixed::Zero() && v.Y == fixed::FromInt(1)); Vertex vert; vert.status = Vertex::UNEXPLORED; vert.quadInward = QUADRANT_NONE; vert.quadOutward = QUADRANT_ALL; vert.p.X = center.X - hd0.Dot(u); vert.p.Y = center.Y + hd0.Dot(v); if (aa) vert.quadInward = QUADRANT_BR; vertexes.push_back(vert); vert.p.X = center.X - hd1.Dot(u); vert.p.Y = center.Y + hd1.Dot(v); if (aa) vert.quadInward = QUADRANT_TR; vertexes.push_back(vert); vert.p.X = center.X + hd0.Dot(u); vert.p.Y = center.Y - hd0.Dot(v); if (aa) vert.quadInward = QUADRANT_TL; vertexes.push_back(vert); vert.p.X = center.X + hd1.Dot(u); vert.p.Y = center.Y - hd1.Dot(v); if (aa) vert.quadInward = QUADRANT_BL; vertexes.push_back(vert); // Add the edges: CFixedVector2D h0(squares[i].hw + r, squares[i].hh + r); CFixedVector2D h1(squares[i].hw + r, -(squares[i].hh + r)); CFixedVector2D ev0(center.X - h0.Dot(u), center.Y + h0.Dot(v)); CFixedVector2D ev1(center.X - h1.Dot(u), center.Y + h1.Dot(v)); CFixedVector2D ev2(center.X + h0.Dot(u), center.Y - h0.Dot(v)); CFixedVector2D ev3(center.X + h1.Dot(u), center.Y - h1.Dot(v)); if (aa) { Edge e = { ev1, ev3 }; edgesAA.push_back(e); } else { Edge e0 = { ev0, ev1 }; Edge e1 = { ev1, ev2 }; Edge e2 = { ev2, ev3 }; Edge e3 = { ev3, ev0 }; edges.push_back(e0); edges.push_back(e1); edges.push_back(e2); edges.push_back(e3); } // TODO: should clip out vertexes and edges that are outside the range, // to reduce the search space } ENSURE(vertexes.size() < 65536); // we store array indexes as u16 if (m_DebugOverlay) { // Render the obstruction edges for (size_t i = 0; i < edges.size(); ++i) { m_DebugOverlayShortPathLines.push_back(SOverlayLine()); m_DebugOverlayShortPathLines.back().m_Color = CColor(0, 1, 1, 1); std::vector<float> xz; xz.push_back(edges[i].p0.X.ToFloat()); xz.push_back(edges[i].p0.Y.ToFloat()); xz.push_back(edges[i].p1.X.ToFloat()); xz.push_back(edges[i].p1.Y.ToFloat()); SimRender::ConstructLineOnGround(GetSimContext(), xz, m_DebugOverlayShortPathLines.back(), true); } for (size_t i = 0; i < edgesAA.size(); ++i) { m_DebugOverlayShortPathLines.push_back(SOverlayLine()); m_DebugOverlayShortPathLines.back().m_Color = CColor(0, 1, 1, 1); std::vector<float> xz; xz.push_back(edgesAA[i].p0.X.ToFloat()); xz.push_back(edgesAA[i].p0.Y.ToFloat()); xz.push_back(edgesAA[i].p0.X.ToFloat()); xz.push_back(edgesAA[i].p1.Y.ToFloat()); xz.push_back(edgesAA[i].p1.X.ToFloat()); xz.push_back(edgesAA[i].p1.Y.ToFloat()); xz.push_back(edgesAA[i].p1.X.ToFloat()); xz.push_back(edgesAA[i].p0.Y.ToFloat()); xz.push_back(edgesAA[i].p0.X.ToFloat()); xz.push_back(edgesAA[i].p0.Y.ToFloat()); SimRender::ConstructLineOnGround(GetSimContext(), xz, m_DebugOverlayShortPathLines.back(), true); } } // Do an A* search over the vertex/visibility graph: // Since we are just measuring Euclidean distance the heuristic is admissible, // so we never have to re-examine a node once it's been moved to the closed set. // To save time in common cases, we don't precompute a graph of valid edges between vertexes; // we do it lazily instead. When the search algorithm reaches a vertex, we examine every other // vertex and see if we can reach it without hitting any collision edges, and ignore the ones // we can't reach. Since the algorithm can only reach a vertex once (and then it'll be marked // as closed), we won't be doing any redundant visibility computations. PROFILE_START("A*"); PriorityQueue open; PriorityQueue::Item qiStart = { START_VERTEX_ID, start.h }; open.push(qiStart); u16 idBest = START_VERTEX_ID; fixed hBest = start.h; while (!open.empty()) { // Move best tile from open to closed PriorityQueue::Item curr = open.pop(); vertexes[curr.id].status = Vertex::CLOSED; // If we've reached the destination, stop if (curr.id == GOAL_VERTEX_ID) { idBest = curr.id; break; } // Sort the edges so ones nearer this vertex are checked first by CheckVisibility, // since they're more likely to block the rays std::sort(edgesAA.begin(), edgesAA.end(), EdgeSort(vertexes[curr.id].p)); std::vector<EdgeAA> edgesLeft; std::vector<EdgeAA> edgesRight; std::vector<EdgeAA> edgesBottom; std::vector<EdgeAA> edgesTop; SplitAAEdges(vertexes[curr.id].p, edgesAA, edgesLeft, edgesRight, edgesBottom, edgesTop); // Check the lines to every other vertex for (size_t n = 0; n < vertexes.size(); ++n) { if (vertexes[n].status == Vertex::CLOSED) continue; // If this is the magical goal vertex, move it to near the current vertex CFixedVector2D npos; if (n == GOAL_VERTEX_ID) { npos = NearestPointOnGoal(vertexes[curr.id].p, goal); // To prevent integer overflows later on, we need to ensure all vertexes are // 'close' to the source. The goal might be far away (not a good idea but // sometimes it happens), so clamp it to the current search range npos.X = clamp(npos.X, rangeXMin, rangeXMax); npos.Y = clamp(npos.Y, rangeZMin, rangeZMax); } else { npos = vertexes[n].p; } // Work out which quadrant(s) we're approaching the new vertex from u8 quad = 0; if (vertexes[curr.id].p.X <= npos.X && vertexes[curr.id].p.Y <= npos.Y) quad |= QUADRANT_BL; if (vertexes[curr.id].p.X >= npos.X && vertexes[curr.id].p.Y >= npos.Y) quad |= QUADRANT_TR; if (vertexes[curr.id].p.X <= npos.X && vertexes[curr.id].p.Y >= npos.Y) quad |= QUADRANT_TL; if (vertexes[curr.id].p.X >= npos.X && vertexes[curr.id].p.Y <= npos.Y) quad |= QUADRANT_BR; // Check that the new vertex is in the right quadrant for the old vertex if (!(vertexes[curr.id].quadOutward & quad)) { // Hack: Always head towards the goal if possible, to avoid missing it if it's // inside another unit if (n != GOAL_VERTEX_ID) { continue; } } bool visible = CheckVisibilityLeft(vertexes[curr.id].p, npos, edgesLeft) && CheckVisibilityRight(vertexes[curr.id].p, npos, edgesRight) && CheckVisibilityBottom(vertexes[curr.id].p, npos, edgesBottom) && CheckVisibilityTop(vertexes[curr.id].p, npos, edgesTop) && CheckVisibility(vertexes[curr.id].p, npos, edges); /* // Render the edges that we examine m_DebugOverlayShortPathLines.push_back(SOverlayLine()); m_DebugOverlayShortPathLines.back().m_Color = visible ? CColor(0, 1, 0, 0.5) : CColor(1, 0, 0, 0.5); std::vector<float> xz; xz.push_back(vertexes[curr.id].p.X.ToFloat()); xz.push_back(vertexes[curr.id].p.Y.ToFloat()); xz.push_back(npos.X.ToFloat()); xz.push_back(npos.Y.ToFloat()); SimRender::ConstructLineOnGround(GetSimContext(), xz, m_DebugOverlayShortPathLines.back(), false); //*/ if (visible) { fixed g = vertexes[curr.id].g + (vertexes[curr.id].p - npos).Length(); // If this is a new tile, compute the heuristic distance if (vertexes[n].status == Vertex::UNEXPLORED) { // Add it to the open list: vertexes[n].status = Vertex::OPEN; vertexes[n].g = g; vertexes[n].h = DistanceToGoal(npos, goal); vertexes[n].pred = curr.id; // If this is an axis-aligned shape, the path must continue in the same quadrant // direction (but not go into the inside of the shape). // Hack: If we started *inside* a shape then perhaps headed to its corner (e.g. the unit // was very near another unit), don't restrict further pathing. if (vertexes[n].quadInward && !(curr.id == START_VERTEX_ID && g < fixed::FromInt(8))) vertexes[n].quadOutward = ((~vertexes[n].quadInward) & quad) & 0xF; if (n == GOAL_VERTEX_ID) vertexes[n].p = npos; // remember the new best goal position PriorityQueue::Item t = { (u16)n, g + vertexes[n].h }; open.push(t); // Remember the heuristically best vertex we've seen so far, in case we never actually reach the target if (vertexes[n].h < hBest) { idBest = (u16)n; hBest = vertexes[n].h; } } else // must be OPEN { // If we've already seen this tile, and the new path to this tile does not have a // better cost, then stop now if (g >= vertexes[n].g) continue; // Otherwise, we have a better path, so replace the old one with the new cost/parent vertexes[n].g = g; vertexes[n].pred = curr.id; // If this is an axis-aligned shape, the path must continue in the same quadrant // direction (but not go into the inside of the shape). if (vertexes[n].quadInward) vertexes[n].quadOutward = ((~vertexes[n].quadInward) & quad) & 0xF; if (n == GOAL_VERTEX_ID) vertexes[n].p = npos; // remember the new best goal position open.promote((u16)n, g + vertexes[n].h); } } } } // Reconstruct the path (in reverse) for (u16 id = idBest; id != START_VERTEX_ID; id = vertexes[id].pred) { Waypoint w = { vertexes[id].p.X, vertexes[id].p.Y }; path.m_Waypoints.push_back(w); } PROFILE_END("A*"); }
void mbp_kruskal(graph<key_type,graph_size> &g0, int s, int t, vector< edge<key_type> > &path) { int i,j,edge_num = 0; struct adj_node<key_type> table[graph_size + 1]; struct adj_node<key_type>* tree_edges = table; edge<key_type> temp_e,tt; vector< edge<key_type> > edges; struct adj_node<key_type>* temp; int degree[graph_size + 1],set[graph_size + 1]; //get all the edge information from the graph. g0.get_adj_table(table); edges.reserve((graph_size + 1) * (1+graph_size)); heap<edge<key_type>,graph_size*graph_size,value_fun_edge<key_type>,name_fun_edge<key_type>,key_type> h0(false); for (i = 1 ; i <= graph_size; i ++ ) { for(temp = table[i].adj_v;temp != NULL; temp = temp->adj_v) { temp_e = edge<key_type>(i,temp->name,temp->weight); // Here we use this code to guide the compiler generate conditonal move instruction, which can decrease the // branch misprediction penalty. edges[(temp->name > i) ? edge_num : 0] = temp_e; edge_num += (temp->name > i); } } for (i = 1 ; i <= edge_num; i ++ ) h0.insert(edges[i]); //make set for all the vertice for (i = 1 ; i <= graph_size ; i ++ ) make_set(set,degree,i); for (i = 1 ; i <= graph_size ; i ++ ) tree_edges[i].adj_v = NULL; long edge_count = 0; for(i = 0; i < edge_num ; i++ ) { temp_e = h0.max(); h0.del_max(); if (find(set,temp_e.v1) != find(set,temp_e.v2) ) { edge_count ++; set_union(set,degree,temp_e.v1,temp_e.v2); adj_node<key_type>* node1 = new adj_node<key_type>(temp_e.v1,temp_e.weight,tree_edges[temp_e.v2].adj_v); adj_node<key_type>* node2 = new adj_node<key_type>(temp_e.v2,temp_e.weight,tree_edges[temp_e.v1].adj_v); tree_edges[temp_e.v2].adj_v = node1; tree_edges[temp_e.v1].adj_v = node2; } if (edge_count == graph_size - 1 ) break; } bool v_flag[graph_size + 1]; for (i = 1 ; i <= graph_size ; i ++ ) v_flag[i] = false; v_flag[s] = true; find_path<key_type,graph_size>(tree_edges,s,t,v_flag,path); return; }
inline word32 Twofish::h(word32 x, const word32* key, unsigned int kLen) { x = h0(x, key, kLen); return mds_[0][GETBYTE(x,0)] ^ mds_[1][GETBYTE(x,1)] ^ mds_[2][GETBYTE(x,2)] ^ mds_[3][GETBYTE(x,3)]; }
void QxrdHistogramDialog::recalculateHistogram() { QxrdHistogramDialogSettingsPtr set(m_HistogramDialogSettings); if (set && m_Image) { QxrdExperimentPtr expt(m_Experiment); if (expt) { QTime tic; tic.start(); QRectF rect = set->get_HistogramRect(); int nsum = m_Image->get_SummedExposures(); if (nsum < 1) { nsum = 1; } QxrdAcquisitionPtr acq(expt->acquisition()); double satlev = 60000; if (acq) { satlev = acq->get_OverflowLevel(); } double min = 0, max = satlev*nsum; const int nbins=1000; QcepDoubleVector x0(nbins), h0(nbins), h1(nbins); for (int i=0; i<nbins; i++) { // double x = min+i*(max-min)/1000.0; x0[i] = i*100.0/(double)nbins; h0[i] = 0; h1[i] = 0; } int width = m_Image->get_Width(); int height= m_Image->get_Height(); double *data = m_Image->data(); for (int i=0; i<width; i++) { for (int j=0; j<height; j++) { double v = *data++; int n; if (v<min) { n=0; } else if (v>max) { n=nbins-1; } else { n=(nbins-1)*(v-min)/(max-min); } if (n<0) { n=0; } if (n>=nbins) { n=nbins-1; } h0[n]++; if (rect.contains(i,j)) { h1[n]++; } } } m_HistogramPlot->detachItems(); QwtPlotPiecewiseCurve *pc0 = new QwtPlotPiecewiseCurve(m_HistogramPlot, "Entire Image"); pc0->setSamples(x0, h0); pc0->setPen(QPen(Qt::red)); pc0->attach(m_HistogramPlot); QwtPlotPiecewiseCurve *pc1 = new QwtPlotPiecewiseCurve(m_HistogramPlot, tr("[%1,%2]-[%3,%4]") .arg(rect.left()).arg(rect.bottom()) .arg(rect.right()).arg(rect.top())); pc1->setSamples(x0, h1); pc1->setPen(QPen(Qt::darkRed)); pc1->attach(m_HistogramPlot); m_HistogramPlot->replot(); if (qcepDebug(DEBUG_HISTOGRAM)) { expt -> printMessage(tr("Histogram of data took %1 msec").arg(tic.elapsed())); } } } }