void SpatialDescriptorDistanceToCentroid<CoordType>::eval( const Vertices<CoordType>& vertices, Vector<CoordType>& xvalues, Vector<CoordType>& yvalues) { ENTER( "void SpatialDescriptorDistanceToBorder<CoordType>::eval(...)" ); PRINT("here"); const int numVertices = vertices.getSize(); Vector<CoordType> triMeshCentroid(3); triMeshCentroid = _triMesh->cog(); xvalues.setSize( numVertices ); PRINT("here"); for (int i = 0; i < numVertices; ++i) { //testVertex = vertices[i]; xvalues[i] = vertices[i].distance( triMeshCentroid ); } xvalues.sort(); CDFTools<CoordType> cdftools; yvalues = cdftools.cdf( xvalues ); LEAVE(); }
void EditorFileSystem::reimport_files(const Vector<String> &p_files) { importing = true; EditorProgress pr("reimport", TTR("(Re)Importing Assets"), p_files.size()); Vector<ImportFile> files; for (int i = 0; i < p_files.size(); i++) { ImportFile ifile; ifile.path = p_files[i]; ifile.order = ResourceFormatImporter::get_singleton()->get_import_order(p_files[i]); files.push_back(ifile); } files.sort(); for (int i = 0; i < files.size(); i++) { pr.step(files[i].path.get_file(), i); _reimport_file(files[i].path); } _save_filesystem_cache(); importing = false; if (!is_scanning()) { emit_signal("filesystem_changed"); } emit_signal("resources_reimported", p_files); }
void TestSort() { srand(time(NULL)); void* tuples[SIZE_SML_TEST]; unsigned i; for (i = 0 ; i < SIZE_SML_TEST ; ++i) { Tuple* tuple = (Tuple*)malloc(sizeof(Tuple)); tuple->first = i; tuple->second = i; tuples[i] = tuple; } for (i = 0 ; i < SIZE_MID_TEST ; ++i) { int src = rand() % SIZE_SML_TEST; int tge = rand() % SIZE_SML_TEST; void* tuple = tuples[src]; tuples[src] = tuples[tge]; tuples[tge] = tuple; } Vector* vector = VectorInit(DEFAULT_CAPACITY); vector->set_clean(vector, CleanElement); for (i = 0 ; i < SIZE_SML_TEST ; ++i) vector->push_back(vector, tuples[i]); vector->sort(vector, SortElement); for (i = 0 ; i < SIZE_SML_TEST ; ++i) { void* tuple; vector->get(vector, i, &tuple); CU_ASSERT_EQUAL(((Tuple*)tuple)->first, i); } VectorDeinit(vector); }
void SpatialDescriptorFunctionSRD<CoordType>::eval( const Vertices<CoordType>& vertices, Vector<CoordType>& x, Vector<CoordType>& y) { const int numVertices = vertices.getSize(); int i, j = 0; Vector<CoordType> temp; temp.setSize(1); x.setSize(0); for (i = 0; i < numVertices; ++i) for (j = i+1; j < numVertices; ++j) { temp[0] = vertices[i].distance( vertices[j] ); if ( temp[0] < _distanceThreshold ) x.append( temp ); } if ( x.getSize() != 0 ) { x.sort(); y.setSize( x.getSize() ); CDFTools<CoordType> cdfTools; y = cdfTools.cdf( x ); } else { x.setSize( 1 ); x[0] = 0; y.setSize( x.getSize() ); CDFTools<CoordType> cdfTools; y = cdfTools.cdf( x ); } }
string WordNgrams::output(int limit) { int ngramN = this->getN(); //printf("BEGIN OUTPUT\n"); //printf("Total %d unique ngram in %d ngrams.\n", this->count(), this->total() ); //fprintf( stderr, "Total %d unique ngram in %d ngrams.\n", this->count(), this->total() ); for ( int i=1; i<=ngramN; i++ ) { // Get sorted item list Vector< NgramToken * > ngramVector; this->getNgrams( ngramVector, i ); //printf("\n%d-GRAMS\n", i); //printf("Total %d unique ngrams in %d %d-grams.\n", this->count( i ), this->total( i ), i ); //fprintf( stderr, "Total %d unique ngrams in %d %d-grams.\n", this->count( i ), this->total( i ), i ); //printf("------------------------\n"); size_t count = ngramVector.count(); ngramVector.sort( INgrams::compareFunction ); for ( unsigned j=0; j < count; j++ ) { NgramToken * ngramToken = ngramVector[ j ]; //outputWordNgram( ngramToken.ngram, ngramToken.value.frequency, i ); //printf("%s\t%d\n", ngramToken->ngram.c_str(), ngramToken->value.frequency ); delete ngramToken; } } }
U32 JournalBlockTypeToken::getValue() { if(!mInitialized) { mInitialized = true; Vector<JournalBlockTypeToken *> vec; for(JournalBlockTypeToken *walk = mList; walk; walk = walk->mNext) vec.push_back(walk); vec.sort(JBTTCompare); U32 lastValue = 0; const char *lastString = ""; for(S32 i = 0; i < vec.size(); i++) { if(!strcmp(vec[i]->mString, lastString)) vec[i]->mValue = lastValue; else { lastValue++; vec[i]->mValue = lastValue; lastString = vec[i]->mString; } } } return mValue; }
void testVector ( int testSize ) { printf ( "\n ==== Test %2d. Generate a random vector\n", testID++ ); Vector<T> V; for ( int i = 0; i < testSize; i++ ) V.insert ( dice ( i + 1 ), dice ( ( T ) testSize * 3 ) ); //在[0, 3n)中选择n个数,随机插入向量 PRINT ( V ); permute ( V ); PRINT ( V ) printf ( "\n ==== Test %2d. Lowpass on\n", testID++ ); PRINT ( V ); int i = V.size(); while ( 0 < --i ) { V[i-1] += V[i]; V[i-1] >>= 1; } PRINT ( V ); printf ( "\n ==== Test %2d. Increase\n", testID++ ); PRINT ( V ); increase ( V ); PRINT ( V ); printf ( "\n ==== Test %2d. FIND in\n", testID++ ); PRINT ( V ); TestFind<T> ( V, testSize ); printf ( "\n ==== Test %2d. Sort degenerate intervals each of size 1 in\n", testID++, 0, V.size() ); PRINT ( V ); for ( int i = 0; i < V.size(); i += V.size() / 5 ) { V.sort ( i, i ); PRINT ( V ); } //element by element printf ( "\n ==== Test %2d. Sort 5 intervals each of size %d in\n", testID++, V.size() / 5 ); PRINT ( V ); for ( int i = 0; i < V.size(); i += V.size() / 5 ) { V.sort ( i, min ( V.size(), i + V.size() / 5 ) ); PRINT ( V ); } //interval by interval printf ( "\n ==== Test %2d. Sort the entire vector of\n", testID++, 0, V.size() ); PRINT ( V ); V.sort(); PRINT ( V ); printf ( "\n ==== Test %2d. FIND in\n", testID++ ); PRINT ( V ); TestFind<T> ( V, testSize ); printf ( "\n ==== Test %2d. SEARCH in\n", testID++ ); PRINT ( V ); TestSearch<T> ( V ); printf ( "\n ==== Test %2d. Unsort interval [%d, %d) in\n", testID++, V.size() / 4, 3 * V.size() / 4 ); PRINT ( V ); V.unsort ( V.size() / 4, 3 * V.size() / 4 ); PRINT ( V ); printf ( "\n ==== Test %2d. Unsort interval [%d, %d) in\n", testID++, 0, V.size() ); PRINT ( V ); V.unsort(); PRINT ( V ); printf ( "\n ==== Test %2d. Copy interval [%d, %d) from\n", testID++, V.size() / 4, 3 * V.size() / 4 ); PRINT ( V ); Vector<T> U ( V, V.size() / 4, 3 * V.size() / 4 ); PRINT ( U ); printf ( "\n ==== Test %2d. Copy from\n", testID++ ); PRINT ( V ); Vector<T> W ( V ); PRINT ( W ); printf ( "\n ==== Test %2d. Clone from\n", testID++ ); PRINT ( U ); W = U; PRINT ( W ); printf ( "\n ==== Test %2d. Remove redundancy in unsorted\n", testID++ ); PRINT ( V ); printf ( "%d node(s) removed\n", V.deduplicate() ); PRINT ( V ); printf ( "\n ==== Test %2d. Sort interval [%d, %d) in\n", testID++, 0, V.size() ); PRINT ( V ); V.sort(); PRINT ( V ); printf ( "\n ==== Test %2d. FIND in V[%d]\n", testID++ ); PRINT ( V ); TestFind<T> ( V, testSize ); printf ( "\n ==== Test %2d. SEARCH & INSERT in\n", testID++ ); PRINT ( V ); TestOrderedInsertion<T> ( V, testSize ); PRINT ( V ); printf ( "\n ==== Test %2d. Remove redundancy in sorted\n", testID++ ); PRINT ( V ); printf ( "%d node(s) removed\n", V.uniquify() ); PRINT ( V ); }
Vector<T> CDFTools<T>::average(const Matrix<T>& x) const { Vector<T> xEvals; xEvals = x.cat(); xEvals.sort(); return average( x, xEvals ); }
Vector<T> CDFTools<T>::percentile(const Matrix<T>& x, const float percent) const { Vector<T> xEvals; xEvals = x.cat(); xEvals.sort(); return percentile( x, xEvals, percent ); }
int main(int argc, char* const argv[]) { sp<IServiceManager> sm = defaultServiceManager(); fflush(stdout); if (sm == NULL) { ALOGE("Unable to get default service manager!"); aerr << "dumpsys: Unable to get default service manager!" << endl; return 20; } Vector<String16> services; Vector<String16> args; if (argc == 1) { services = sm->listServices(); services.sort(sort_func); args.add(String16("-a")); } else { services.add(String16(argv[1])); for (int i=2; i<argc; i++) { args.add(String16(argv[i])); } } const size_t N = services.size(); if (N > 1) { // first print a list of the current services aout << "Currently running services:" << endl; for (size_t i=0; i<N; i++) { sp<IBinder> service = sm->checkService(services[i]); if (service != NULL) { aout << " " << services[i] << endl; } } } for (size_t i=0; i<N; i++) { sp<IBinder> service = sm->checkService(services[i]); if (service != NULL) { if (N > 1) { aout << "------------------------------------------------------------" "-------------------" << endl; aout << "DUMP OF SERVICE " << services[i] << ":" << endl; } int err = service->dump(STDOUT_FILENO, args); if (err != 0) { aerr << "Error dumping service info: (" << strerror(err) << ") " << services[i] << endl; } } else { aerr << "Can't find service: " << services[i] << endl; } } return 0; }
static const Vector<string> buildGameTypesList() { Vector<string> gameTypes; gameTypes = GameType::getGameTypeNames(); gameTypes.sort(alphaSort); return gameTypes; }
Vector<String> SpriteFrames::get_animation_names() const { Vector<String> names; for (const Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) { names.push_back(E->key()); } names.sort(); return names; }
void Video::loadFromDirectory(const std::string &directory) { Directory dir(directory); Vector<std::string> sortedFiles = dir.filesWithSuffix(".png"); sortedFiles.sort(); for(const std::string &filename : sortedFiles) frames.pushBack(LodePNG::load(dir.path() + filename)); width = frames[0].cols(); height = frames[0].rows(); }
Vector<T> CDFTools<T>::average(const vector<const Vector<T>*>& x) const { const int n = x.size(); Vector<T> xEvals; for (int i = 0; i < n; ++i) { xEvals.append( *x[i] ); } xEvals.sort(); return average( x, xEvals ); }
Vector<T> CDFTools<T>::percentile(const vector<const Vector<T>*>& x, const float percent) const { const int n = x.size(); Vector<T> xEvals; for (int i = 0; i < n; ++i) { xEvals.append( *x[i] ); } xEvals.sort(); return percentile( x, xEvals, percent ); }
void MannWhitneyTest::setData(const Vector& xA, const Vector& xB) { unsigned long n; double uA; double nAnB; m_nA = xA.size(); m_nB = xB.size(); n = m_nA + m_nB; nAnB = ((double)m_nA) * m_nB; Vector joined = xA; joined.append(xB); Vector ranks; ranks.resize(joined.size()); rank_vector(joined.begin(), joined.end(), ranks.begin(), m_tolerance); uA = nAnB - std::accumulate(ranks.begin(), ranks.begin() + m_nA, 0.0); uA += m_nA / 2.0 * (m_nA + 1); if (m_alternative == NOT_EQUAL) { m_u = std::min(uA, nAnB - uA); } else { m_u = uA; } // Calculate tie correction value m_tieCorrection = 0.0; if (ranks.size() > 1) { ranks.sort(); Vector::iterator curr = ranks.begin(), end = ranks.end(); Vector::iterator next = curr + 1; while (next != end) { if (*curr == *next) { int nties = 1; while (next != end && *curr == *next) { curr++; next++; nties++; } m_tieCorrection += std::pow(nties, 3.0) - nties; } if (next != end) { curr++; next++; } } } m_tieCorrection = std::sqrt(1 - m_tieCorrection / (std::pow(n, 3.0) - n)); }
void CFStencil::buildPeriodicVector(Vector<Box>& a_periodicVector, const ProblemDomain& a_fineDomain, const DisjointBoxLayout& a_fineBoxes) { Box periodicTestBox(a_fineDomain.domainBox()); if (a_fineDomain.isPeriodic()) { for (int idir=0; idir<SpaceDim; idir++) { if (a_fineDomain.isPeriodic(idir)) { periodicTestBox.grow(idir,-1); } } } a_periodicVector.clear(); a_periodicVector.reserve(a_fineBoxes.size()); LayoutIterator lit = a_fineBoxes.layoutIterator(); for (lit.reset(); lit.ok(); ++lit) { const Box& box = a_fineBoxes[lit()]; a_periodicVector.push_back(box); // if periodic, also need to add periodic images // only do this IF we're periodic and box // adjacent to the domain box boundary somewhere if (a_fineDomain.isPeriodic() && !periodicTestBox.contains(box)) { ShiftIterator shiftIt = a_fineDomain.shiftIterator(); IntVect shiftMult(a_fineDomain.domainBox().size()); Box shiftedBox(box); for (shiftIt.begin(); shiftIt.ok(); ++shiftIt) { IntVect shiftVect = shiftMult*shiftIt(); shiftedBox.shift(shiftVect); a_periodicVector.push_back(shiftedBox); shiftedBox.shift(-shiftVect); } // end loop over periodic shift directions } // end if periodic } a_periodicVector.sort(); }
int main() { int N = 200; Matrix A = Matrix(N,N); Matrix R = Matrix(N,N); Vector rho = Vector(N); Vector tmp = Vector(N); double rho0 = 0; double rhoN = 5; double omega = 5; double h = rho.linspace(rho0,rhoN,N); double d = 2/(h*h); double e = -1/(h*h); // Make the diagonal elements and insert them tmp = e; // Set the boundry conditions to 1 on either side // to get more accuray results tmp(0) = 0; tmp(N-1) = 0; A.diag(tmp, 1); A.diag(tmp,-1); tmp(0) = 1; tmp(N-1) = 1; for (int i = 0; i < N-1; i++) { tmp(i) = d + omega*omega*rho(i)*rho(i) + 1.0/rho(i); } A.diag(tmp,0); // Solve the problem EigVal::jacobiMethod(A, R, N); // Print eigenvalues cout << "Rho :\t" << rhoN << endl; cout << "N :\t" << N << endl; cout << "Omega :\t" << omega << endl; cout << "Eigenvalues :" << endl; Vector eigVal = A.diag(); eigVal.sort(); for (int i = 1; i < 6; i++) { cout << "R" << i << ":\t" << eigVal(i) << endl; } return 0; }
void testSort() { Vector< S32 > v; v.push_back( 0 ); v.push_back( 10 ); v.push_back( 2 ); v.push_back( 3 ); v.push_back( 14 ); v.push_back( 4 ); v.push_back( 12 ); v.push_back( 6 ); v.push_back( 16 ); v.push_back( 7 ); v.push_back( 8 ); v.push_back( 1 ); v.push_back( 11 ); v.push_back( 5 ); v.push_back( 13 ); v.push_back( 9 ); v.push_back( 15 ); v.sort( sortInts ); TEST( v[ 0 ] == 0 ); TEST( v[ 1 ] == 1 ); TEST( v[ 2 ] == 2 ); TEST( v[ 3 ] == 3 ); TEST( v[ 4 ] == 4 ); TEST( v[ 5 ] == 5 ); TEST( v[ 6 ] == 6 ); TEST( v[ 7 ] == 7 ); TEST( v[ 8 ] == 8 ); TEST( v[ 9 ] == 9 ); TEST( v[ 10 ] == 10 ); TEST( v[ 11 ] == 11 ); TEST( v[ 12 ] == 12 ); TEST( v[ 13 ] == 13 ); TEST( v[ 14 ] == 14 ); TEST( v[ 15 ] == 15 ); TEST( v[ 16 ] == 16 ); }
int main() { srand((unsigned)time(0)); unsigned size = 100; Vector<int> a; fillVector(a, size); cout << "The original Vector" << endl; a.print(); a.sort(); cout << endl; cout << "Sorted Vector" << endl; a.print(); Vector<int> *result = top(a, 10); cout << endl; cout << "The top 10 elements" << endl; result -> print(); }
int main() { Vector<double> v; // ok: defaultkonstruktor ger vektor med flyttal Vector<char> *a = new Vector<char>[3]; // dynamiskt allokerade ser ut så här delete [] a; assert(v.size() == 0); // tom från början v.push_back(3.14); // lägg till ett element sist assert(v.size() == 1); // nu ligger ett element i vektorn v.insert(0, 2.10); // lägg till före element 0, dvs först assert(v[0] == 2.10 && // hamnade de rätt? v[1] == 3.14); assert(v.size() == 2); // nu ligger två element i vektorn v.sort(false); // sortera i fallande ordning assert(v[0] == 3.14 && // hamnade de rätt? v[1] == 2.10); assert(v.size() == 2); // ingenting ändrat? v[1] = 2.11; // tilldelning av enstaka element; const Vector<double> &vc = v; // skapa konstant referens assert(vc.size() == 2); // ok: ändrar ej vektorn som är konstant assert(vc[0] == 3.14 && // ok: ändrar ej vektorn som är konstant vc[1] == 2.11); v.erase(0); // ta bort första elementet assert(v.size() == 1); // rätt antal elelment v.clear(); // töm hela vektorn assert(v.size() == 0); // tom när alla element är borttagna // kontrollera att följande rader inte går att kompilera //vc[0] = 3.1415; // fel: tilldelning av konstant objekt //Vector<char> c = v; // fel: tilldelning av olika typer //vc.sort(); // fel: ändrar konstant objekt return 0; }
int test() { #ifdef CH_USE_HDF5 int error; HDF5Handle testFile; CH_assert(!testFile.isOpen()); error = testFile.open("data.h5", HDF5Handle::CREATE); if (error != 0) { if ( verbose ) pout() << indent2 << "File creation failed "<<error<<endl; return error; } CH_assert(testFile.isOpen()); Box domain(IntVect::Zero, 20*IntVect::Unit); DisjointBoxLayout plan1, plan2; { IntVectSet tags; IntVect center = 10*IntVect::Unit; setCircleTags(tags, 6, 1, center); //circle/sphere buildDisjointBoxLayout(plan1, tags, domain); tags.makeEmpty(); setCircleTags(tags, 5, 2, center); buildDisjointBoxLayout(plan2, tags, domain); } if ( verbose ) { pout() << "plan1: " << procID() << "...." << plan1 << endl; pout() << "plan2: " << procID() << "...." << plan2 << endl; } //test LayoutData<Real> specialization LayoutData<Real> specialReal(plan1); LayoutData<Moment> vlPlan(plan1); LevelData<BaseFab<int> > level1(plan1, 3, IntVect::Unit); LevelData<BaseFab<int> > level2; level2.define(level1); level2.define(plan2, 1); for (DataIterator i(level2.dataIterator()); i.ok(); ++i) { level2[i()].setVal(2); } level1.apply(values::setVal1); level2.apply(values::setVal2); HDF5HeaderData set1; Real dx=0.004; Box b1(IntVect(D_DECL6(1,2,1,1,2,1)), IntVect(D_DECL6(4,4,4,4,4,4))); Box b2(IntVect(D_DECL6(5,2,1,5,2,1)), IntVect(D_DECL6(12,4,4,12,4,4))); int currentStep = 2332; set1.m_string["name"] = "set1"; set1.m_real["dx"] = dx; set1.m_int["currentStep"] = currentStep; set1.m_intvect["some intvect or other"] = b1.smallEnd(); set1.m_box["b1"] = b1; set1.m_box["b2"] = b2; testFile.setGroupToLevel(1); error = write(testFile, plan1); if (error != 0) { if ( verbose ) pout() << indent2 << "box write failed "<<error<<endl; return error; } error = write(testFile, level1, "level1 state vector"); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 1 write failed "<<error<<endl; return error; } testFile.setGroupToLevel(2); error = write(testFile, plan2); if (error != 0) { if ( verbose ) pout() << indent2 << "box2 write failed "<<error<<endl; return error; } error = write(testFile, level2, "level2 state vector"); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl; return error; } LevelData<FArrayBox> state(plan2, 3); state.apply(values::setVal3); testFile.setGroupToLevel(0); set1.writeToFile(testFile); error = write(testFile, plan2); if (error != 0) { if ( verbose ) pout() << indent2 << "box2 write failed "<<error<<endl; return error; } testFile.setGroup("/"); error = writeLevel(testFile, 0, state, 2, 1, 0.001, b2, 2); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl; return error; } set1.writeToFile(testFile); set1.writeToFile(testFile); testFile.close(); CH_assert(!testFile.isOpen()); // test the utility functions ReadUGHDF5 and WriteUGHDF5 WriteUGHDF5("UGIO.hdf5", plan2, state, domain); ReadUGHDF5("UGIO.hdf5", plan2, state, domain); //======================================================================== // // now, read this data back in // //======================================================================== BoxLayoutData<BaseFab<int> > readlevel1, readlevel2; error = testFile.open("data.h5", HDF5Handle::OPEN_RDONLY); if (error != 0) { if ( verbose ) pout() << indent2 << "File open failed "<<error<<endl; return error; } testFile.setGroupToLevel(2); Vector<Box> boxes; error = read(testFile, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "box read failed "<<error<<endl; return error; } boxes.sort(); Vector<int> assign; error = LoadBalance(assign, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl; return error; } BoxLayout readplan2(boxes, assign); readplan2.close(); error = read(testFile, readlevel2, "level2 state vector", readplan2); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl; return error; } testFile.setGroupToLevel(1); error = read(testFile, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "box read failed "<<error<<endl; return error; } error = LoadBalance(assign, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl; return error; } BoxLayout readplan1(boxes, assign); readplan1.close(); if ( verbose ) { pout() << "readplan1: " << procID() << "...." << readplan1 << endl; pout() << "readplan2: " << procID() << "...." << readplan2 << endl; } error = read(testFile, readlevel1, "level1 state vector", readplan1); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl; return error; } if ( verbose ) pout() << plan1<<readplan1<<endl; // real test of IO, make sure the data is the same coming and going DataIterator l1 = level1.dataIterator(); DataIterator rl1 = readlevel1.dataIterator(); DataIterator l2 = level2.dataIterator(); DataIterator rl2 = readlevel2.dataIterator(); if (level1.boxLayout().size() != readlevel1.boxLayout().size()) { if ( verbose ) pout() << indent2 << "level1.size() != readl1.size() read failed "<<error<<endl; return 1; } if (level2.boxLayout().size() != readlevel2.boxLayout().size()) { if ( verbose ) pout() << indent2 << "level2.size() != readl2.size() read failed "<<error<<endl; return 1; } // we can assume that BoxLayout IO is tested in HDF5boxIO BaseFab<int>* before, *after; for (; l1.ok(); ++l1, ++rl1) { before = &(level1[l1()]); after = &(readlevel1[rl1()]); for (int c=0; c<before->nComp(); ++c) { for (BoxIterator it(level1.box(l1())); it.ok(); ++it) { if ((*before)(it(), c) != (*after)(it(), c)) { if ( verbose ) pout() << indent2 << "l1 != readl1 read failed "<<error<<endl; return 2; } } } } for (; l2.ok(); ++l2, ++rl2) { before = &(level2[l2()]); after = &(readlevel2[rl2()]); for (int c=0; c<before->nComp(); ++c) { for (BoxIterator it(level2.box(l2())); it.ok(); ++it) { if ((*before)(it(), c) != (*after)(it(), c)) { if ( verbose ) pout() << indent2 << "level2 != readlevel2 read failed "<<error<<endl; return 3; } } } } LevelData<FArrayBox> readState; Real dt, time; int refRatio; testFile.setGroup("/"); error = readLevel(testFile, 0, readState, dx, dt, time, b2, refRatio); if (error != 0) { if ( verbose ) pout() << indent2 << "readLevel failed "<<error<<endl; return error; } #ifndef CH_MPI // OK, now try to read one FArrayBox at a time // problem with DataIterator and running the out-of-core in parallel, so // have to think about that for now BVS. FArrayBox readFAB; Interval interval(1,2); testFile.setGroup("/"); int index=0; for (DataIterator dit(state.dataIterator()); dit.ok(); ++index,++dit) { FArrayBox& fab = state[dit()]; readFArrayBox(testFile, readFAB, 0, index, interval); for (BoxIterator it(state.box(dit())) ; it.ok() ; ++it) { if (readFAB(it(), 0) != fab(it(), 1)) { if ( verbose ) pout() << indent2 << "state != after for out-of-core "<<error<<endl; return 3; } } } #endif testFile.close(); CH_assert(!testFile.isOpen()); #endif // CH_USE_HDF5 return 0; }
VoxelMatrix <float> findCCs(const VoxelMatrix<float>& originalVoxelMatrix, VoxelMatrix<float>& nucleusMask, const string& filename, const string& intermediateProcessesDir ) { VoxelMatrix<float> regionMatrix; regionMatrix = applyLabelling( originalVoxelMatrix, nucleusMask, filename, intermediateProcessesDir ); // VoxelMatrix<float> regionMatrix( intermediateProcessesDir + filename + "-gradient.vm" ); // EVAL(regionMatrix.getSize()); VoxelMatrix<float> rangeMask, copyVoxelMatrix = originalVoxelMatrix; RegionAnalysis3D<float> regionAnalysis; regionAnalysis.setLabelMatrix( regionMatrix ); regionAnalysis.setValueMatrix( copyVoxelMatrix ); regionAnalysis.run(); rangeMask.setSize( copyVoxelMatrix.getSize() ); rangeMask.setZeros(); regionAnalysis.setOutputMatrix( rangeMask ); regionAnalysis.outputFillRegions( REGION_FEATURE_CONTRAST ); //regionAnalysis.outputFillRegions( REGION_FEATURE_CONTRACTNESS ); rangeMask.save( intermediateProcessesDir + filename + "-contrast.vm", true ); //rangeMask.save( intermediateProcessesDir + filename + "-contractness.vm", true ); OtsuThresholding<float> otsuThresholding; Vector <float> featureValues = regionAnalysis.computeRegionFeature( REGION_FEATURE_CONTRAST ); //Vector <float> featureValues = regionAnalysis.computeRegionFeature( REGION_FEATURE_CONTRACTNESS ); featureValues.sort(); Vector <unsigned int> histogram = featureValues.histogram( featureValues.min(), 1, floor(featureValues.max())+1 ); float threshold = otsuThresholding.computeThreshold( histogram ); //float threshold = otsuThresholding.computeThreshold( histogram * 0.8 ); EVAL(featureValues); EVAL(histogram); EVAL(threshold); regionAnalysis.thresholdRegions( featureValues, threshold ); regionAnalysis.run(); int num = regionAnalysis.condenseRegionLabels(); regionAnalysis.run(); EVAL(num); VoxelMatrix<float> ccsMask = regionAnalysis.getLabelMatrix(); //to obtain a better filling, it's applied to each 2D slice instead of the complete 3D stack HolesFillingf holesFilling; int sizeZ = ccsMask.getSize3(); for (int k = 0; k < sizeZ; ++k) holesFilling.apply( ccsMask[k] ); // VoxelMatrix<float> ccsFillMask = ccsMask; // ccsMask.fillIt(ccsFillMask); // VoxelMatrix<float> structElement; // structElement.setSize(3,3,3); // structElement.setOnes(); // VoxelMatrixDilatation<float> voxelDilatation; // voxelDilatation.setStructElt( structElement ); // voxelDilatation.apply( ccsMask ); // // VoxelMatrix<float> structElement2; // // structElement2.setSize(1,1,1); // // structElement2.setOnes(); // VoxelMatrixErosion<float> voxelErosion; // voxelErosion.setStructElt( structElement ); // voxelErosion.apply( ccsMask ); // for (int k = 0; k < sizeZ; ++k) holesFilling.apply( ccsMask[k] ); ccsMask.setVoxelCalibration( originalVoxelMatrix.getVoxelCalibration() ); //ccsMask.save( chromocentersDir + filename + ".vm", true ); return ccsMask; }
void ProjectSettings::_update_translations() { //update translations if (updating_translations) return; updating_translations=true; translation_list->clear(); TreeItem *root = translation_list->create_item(NULL); translation_list->set_hide_root(true); if (Globals::get_singleton()->has("locale/translations")) { StringArray translations = Globals::get_singleton()->get("locale/translations"); for(int i=0;i<translations.size();i++) { TreeItem *t = translation_list->create_item(root); t->set_editable(0,false); t->set_text(0,translations[i].replace_first("res://","")); t->set_tooltip(0,translations[i]); t->set_metadata(0,i); t->add_button(0,get_icon("Del","EditorIcons"),0); } } //update translation remaps String remap_selected; if (translation_remap->get_selected()) { remap_selected = translation_remap->get_selected()->get_metadata(0); } translation_remap->clear(); translation_remap_options->clear(); root = translation_remap->create_item(NULL); TreeItem *root2 = translation_remap_options->create_item(NULL); translation_remap->set_hide_root(true); translation_remap_options->set_hide_root(true); translation_res_option_add_button->set_disabled(true); Vector<String> langs = TranslationServer::get_all_locales(); Vector<String> names = TranslationServer::get_all_locale_names(); String langnames; for(int i=0;i<names.size();i++) { if (i>0) langnames+=","; langnames+=names[i]; } if (Globals::get_singleton()->has("locale/translation_remaps")) { Dictionary remaps = Globals::get_singleton()->get("locale/translation_remaps"); List<Variant> rk; remaps.get_key_list(&rk); Vector<String> keys; for(List<Variant>::Element *E=rk.front();E;E=E->next()) { keys.push_back(E->get()); } keys.sort(); for(int i=0;i<keys.size();i++) { TreeItem *t = translation_remap->create_item(root); t->set_editable(0,false); t->set_text(0,keys[i].replace_first("res://","")); t->set_tooltip(0,keys[i]); t->set_metadata(0,keys[i]); t->add_button(0,get_icon("Del","EditorIcons"),0); if (keys[i]==remap_selected) { t->select(0); translation_res_option_add_button->set_disabled(false); StringArray selected = remaps[keys[i]]; for(int j=0;j<selected.size();j++) { String s = selected[j]; int qp = s.find_last(":"); String path = s.substr(0,qp); String locale = s.substr(qp+1,s.length()); TreeItem *t2 = translation_remap_options->create_item(root2); t2->set_editable(0,false); t2->set_text(0,path.replace_first("res://","")); t2->set_tooltip(0,path); t2->set_metadata(0,j); t2->add_button(0,get_icon("Del","EditorIcons"),0); t2->set_cell_mode(1,TreeItem::CELL_MODE_RANGE); t2->set_text(1,langnames); t2->set_editable(1,true); t2->set_metadata(1,path); int idx = langs.find(locale); if (idx<0) idx=0; t2->set_range(1,idx); } } } } updating_translations=false; }
void EditorPluginSettings::update_plugins() { plugin_list->clear(); DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); Error err = da->change_dir("res://addons"); if (err!=OK) { memdelete(da); return; } updating=true; TreeItem *root = plugin_list->create_item(); da->list_dir_begin(); String d = da->get_next(); Vector<String> plugins; while(d!=String()) { bool dir = da->current_is_dir(); String path = "res://addons/"+d+"/plugin.cfg"; if (dir && FileAccess::exists(path)) { plugins.push_back(d); } d = da->get_next(); } da->list_dir_end(); memdelete(da); plugins.sort(); Vector<String> active_plugins = GlobalConfig::get_singleton()->get("plugins/active"); for(int i=0;i<plugins.size();i++) { Ref<ConfigFile> cf; cf.instance(); String path = "res://addons/"+plugins[i]+"/plugin.cfg"; Error err = cf->load(path); if (err!=OK) { WARN_PRINTS("Can't load plugin config: "+path); } else if (!cf->has_section_key("plugin","name")) { WARN_PRINTS("Plugin misses plugin/name: "+path); } else if (!cf->has_section_key("plugin","author")) { WARN_PRINTS("Plugin misses plugin/author: "+path); } else if (!cf->has_section_key("plugin","version")) { WARN_PRINTS("Plugin misses plugin/version: "+path); } else if (!cf->has_section_key("plugin","description")) { WARN_PRINTS("Plugin misses plugin/description: "+path); } else if (!cf->has_section_key("plugin","script")) { WARN_PRINTS("Plugin misses plugin/script: "+path); } else { String d = plugins[i]; String name = cf->get_value("plugin","name"); String author = cf->get_value("plugin","author"); String version = cf->get_value("plugin","version"); String description = cf->get_value("plugin","description"); String script = cf->get_value("plugin","script"); TreeItem *item = plugin_list->create_item(root); item->set_text(0,name); item->set_tooltip(0,"Name: "+name+"\nPath: "+path+"\nMain Script: "+script); item->set_metadata(0,d); item->set_text(1,version); item->set_metadata(1,script); item->set_text(2,author); item->set_metadata(2,description); item->set_cell_mode(3,TreeItem::CELL_MODE_RANGE); item->set_range_config(3,0,1,1); item->set_text(3,"Inactive,Active"); item->set_editable(3,true); if (EditorNode::get_singleton()->is_addon_plugin_enabled(d)) { item->set_custom_color(3,Color(0.2,1,0.2)); item->set_range(3,1); } else { item->set_custom_color(3,Color(1,0.2,0.2)); item->set_range(3,0); } } } updating=false; }
// Print out the basis set specification in the format: // (example is C atom in 3-21G basis set) // BASIS: 6-31G // Total no. of cgbfs: 9 // Total no. of primitives: 9 // =============== // Specification // =============== // Atom Shell #CGBFs #Prims // ...................................... // C s 3 6 // p 6 3 // (if full = true, then continue with this) // =============== // Basis Functions // =============== // Atom Shell BF Coeff Exponent // ................................................. // C s 1 0.0617669 172.2560 // 0.358794 25.91090 // 0.700713 5.533350 // etc... void Logger::print(Basis& b, bool full) const { // Collect the data needed for printing int nbfs = b.getNBFs(); // Store number of cgbfs and prims int nprims = 0; Vector qs = b.getCharges(); // Sort the qs and get rid of duplicates qs.sort(); Vector qtemp(qs.size()); qtemp[0] = qs(0); int k = 1; for (int i = 1; i < qs.size(); i++){ if (qs(i) != qtemp[k-1]){ qtemp[k] = qs(i); k++; } } qs = qtemp; qs.resizeCopy(k); // Now sum over all basis functions to get the number of prims Vector c(3); c[0] = 0.0; c[1] = 0.0; c[2] = 0.0; BF bftemp(c, 0, 0, 0, c, c); for (int i = 0; i < nbfs; i++){ bftemp = b.getBF(i); nprims += bftemp.getNPrims(); } // Start printing title("Basis Set"); outfile << "BASIS: " << b.getName() << "\n"; outfile << "Total no. of cgbfs: " << nbfs << "\n"; outfile << "Total no. of prims: " << nprims << "\n"; title("Specification"); outfile << std::setw(8) << "Atom"; outfile << std::setw(8) << "Shell"; outfile << std::setw(8) << "#CGBFs"; outfile << std::setw(8) << "#Prims\n"; outfile << std::string(35, '.') << "\n"; // loop over the atom types outfile << std::setprecision(2); Vector subshells; Vector sublnums; for (int i = 0; i < k; i++){ int nc = 0; int np = 0; outfile << std::setw(8) << getAtomName(qs(i)); subshells = b.getShells(qs[i]); sublnums = b.getLnums(qs[i]); outfile << std::setw(8) << getShellName(sublnums[0]); outfile << std::setw(8) << subshells[0]; for (int j = 0; j < subshells[0]; j++){ np += b.getBF(qs[i], j).getNPrims(); } nc += subshells[0]; outfile << std::setw(8) << np << "\n"; for (int j = 1; j < subshells.size(); j++){ outfile << std::setw(8) << ""; outfile << std::setw(8) << getShellName(sublnums[j]); outfile << std::setw(8) << subshells[j]; np = 0; for (int l = 0; l < subshells[j]; l++){ np += b.getBF(qs[i], nc + l).getNPrims(); } nc += subshells[j]; outfile << std::setw(8) << np << "\n"; } } outfile << std::setprecision(8); // Now print out basis functions if required if (full) { title("Basis Functions"); outfile << std::setw(8) << "Atom"; outfile << std::setw(8) << "Shell"; outfile << std::setw(5) << "BF"; outfile << std::setw(18) << "Coeff"; outfile << std::setw(18) << "Exponent\n"; outfile << std::string(58, '.') << "\n"; // Loop over all the basis functions Vector subshell; Vector sublnums; Vector coeffs; Vector exps; std::string filler = ""; for (int i = 0; i < k; i++){ subshell = b.getShells(qs(i)); sublnums = b.getLnums(qs(i)); // Loop over shells int sum = 0; for (int r = 0; r < subshell.size(); r++){ // Loop over bfs for (int s = 0; s < subshell[r]; s++){ bftemp = b.getBF(qs(i), s+sum); coeffs = bftemp.getCoeffs(); exps = bftemp.getExps(); // Loop over coeffs/exps for (int t = 0; t < coeffs.size(); t++){ filler = ((r == 0 && s==0 && t==0) ? getAtomName(qs[i]) : ""); outfile << std::setw(8) << filler; filler = ((s == 0 && t == 0) ? getShellName(sublnums[r]) : ""); outfile << std::setw(8) << filler; filler = (t == 0 ? std::to_string(s+1) : ""); outfile << std::setw(5) << filler; outfile << std::setw(18) << std::setprecision(8) << coeffs(t); outfile << std::setw(18) << std::setprecision(8) << exps(t) << "\n"; } } sum += subshell[r]; } } } }
int main () { Vector v = Vector("4., 5., 6., 9., 8., 7."); v.print(); v.print(" .... "); v.print(" @@ ", stdout); assert(v == v); assert(v == Vector(" 4., 5., 6., 9., 8., 7.")); assert(v != Vector(" 3., 4., 5.")); assert(v.size() == 6); assert(v.sum() == 4 + 5 + 6 + 9 + 8 + 7); assert(v.prod() == 4 * 5 * 6 * 9 * 8 * 7); assert(v.max() == 9); assert(v.min() == 4); assert(v.which_max() == 3); assert(v.which_min() == 0); Real v_max, v_min; long which_max, which_min; v.minmax(v_min, v_max); assert(v_min == 4 && v_max == 9); v.which_minmax(which_min, which_max); assert(which_min == 0 && which_max == 3); v += 1; assert(v == Vector("5., 6., 7., 10., 9., 8.")); v *= 2; assert(v == Vector("10., 12., 14., 20., 18., 16.")); v.sort(); assert(v == Vector("10., 12., 14., 16., 18., 20.")); assert(v.pop_back() == 20.); assert(v == Vector(" 10., 12., 14., 16., 18.")); v.push_back(12.); assert(v == Vector(" 10., 12., 14., 16., 18., 12.")); { Vector x = v * (3 + v + 2) * v; assert(v == Vector("10., 12., 14., 16., 18., 12.")); assert(x == Vector("1500., 2448., 3724., 5376., 7452., 2448.")); } assert(v == Vector("10., 12., 14., 16., 18., 12.")); Real temp[] = {2, 3, 5, 7, 11}; { Vector w = Vector::view(temp, 5); assert(w == Vector("2., 3., 5., 7., 11.")); } assert(temp[0] == 2 && temp[1] == 3 && temp[2] == 5 && temp[3] == 7 && temp[4] == 11); v.append(Vector("6 7")); assert(v == Vector(" 10., 12., 14., 16., 18., 12., 6., 7.")); assert(v.contains(16.) && v.contains(6.)); assert(!v.contains(2.)); long pos = -1; assert(v.search(18., 3, pos)); assert(pos == 4); assert(!v.search(18., 5, pos)); assert(!v.search(9., 0)); assert(!v.search(10., 1)); v.sort(); assert(v.binsearch(16., pos)); assert(pos == 6); assert(!v.binsearch(4.)); v.null(); assert(v == Vector(" 0., 0., 0., 0., 0., 0., 0., 0.")); assert(v.isnull()); v.fill(-12.); assert(v == Vector(" -12., -12., -12., -12., -12., -12., -12., -12.")); assert(!v.isnull()); Vector x = Vector::seq(4, 10); assert(x == Vector(" 4., 5., 6., 7., 8., 9., 10.")); assert(x[2] == 6.); x[2] = 13.; assert(x[2] == 13.); assert(x[3] == 7.); assert(x == Vector(" 4., 5., 13., 7., 8., 9., 10.")); assert(x.e(2) == 13.); x.set(3, 14.); assert(x == Vector(" 4., 5., 13., 14., 8., 9., 10.")); assert(*x.e_ptr(3) == 14.); *x.e_ptr(4) = 15.; assert(x == Vector(" 4., 5., 13., 14., 15., 9., 10.")); assert(x.tail() == 10.); Real c[7]; x.copy_to(c); assert(c[0] == 4. && c[1] == 5. && c[2] == 13. && c[3] == 14. && c[4] == 15. && c[5] == 9. && c[6] == 10.); x.resize(4); assert(x == Vector("4., 5., 13., 14.")); Vector y = x; x.reverse(); assert(x == Vector(" 14., 13., 5., 4.")); assert(y == Vector("4., 5., 13., 14.")); x.swap(y); assert(y == Vector("14., 13., 5., 4.")); assert(x == Vector("4., 5., 13., 14.")); y.remove(2); assert(y == Vector("14., 13., 4.")); y.swap_elements(0, 1); assert(y == Vector("13., 14., 4.")); x.resize(2); assert(x == Vector("4., 5.")); y.insert(2, 64.); y.insert(1, 89.); assert(y == Vector("13., 89., 14., 64., 4.")); { Vector u = x; assert(x == u); u.update(y); assert(u == y); assert(u == Vector("13., 89., 14., 64., 4.")); } assert(x == Vector("4 5")); assert(y == Vector("13., 89., 14., 64., 4.")); y.remove_section(2, 4); assert(y == Vector("13., 89., 4.")); y.clear(); assert(y.size() == 0); { igraph_vector_t v6; igraph_vector_init(&v6, 7); Vector v7(&v6); Vector v8=v7; } std::vector<int> sv; sv.clear(); sv.push_back(4); sv.push_back(14); sv.push_back(5); sv.push_back(7); Vector r = Vector(sv.begin(), sv.end()); assert(r == Vector("4 14 5 7")); sv[1] = 22; assert(sv.size() == 4 && sv[0] == 4 && sv[1] == 22 && sv[2] == 5 && sv[3] == 7); assert(r == Vector("4 14 5 7")); sv = std::vector<int>(r.begin(), r.end()); assert(sv.size() == 4 && sv[0] == 4 && sv[1] == 14 && sv[2] == 5 && sv[3] == 7); r[1] = 22; assert(sv.size() == 4 && sv[0] == 4 && sv[1] == 14 && sv[2] == 5 && sv[3] == 7); assert(r == Vector("4 22 5 7")); std::sort(r.begin(), r.end()); assert(r == Vector("4 5 7 22")); assert(std::inner_product(sv.begin(), sv.end(), r.begin(), 0) == 4*4+14*5+5*7+7*22); Real d[] = {1., 4., 9., 16., 25., 49.}; r = Vector(d, 6); assert(r == Vector("1 4 9 16 25 49")); d[5] = 36; assert(r == Vector("1 4 9 16 25 49")); r[5] = 81; assert(d[5] == 36); r = Vector::view(d, 6); d[4] = 121; assert(r == Vector("1 4 9 16 121 36")); r[3] = 144; assert(d[3] == 144); #if XXINTRNL_CXX0X assert(Vector("2 -4 6 12") == Vector({2, -4, 6, 12})); #endif assert(Vector("1 1 1 1 1; 2 2 2; 3; 4 4 4 4; 5 5 5").distribution() == Vector("0, 0.3125, 0.1875, 0.0625, 0.25, 0.1875")); { Vector r ("1 4 6 12 11 4"); Vector s ("6 -2 5 8 6 4"); assert(r.maxdifference(s) == 6); r = Vector("1 4 6 12 11 4 124 4"); r.remove_first_matching(4); assert(r == Vector("1 6 12 11 4 124 4")); r.remove_all_matching(4); assert(r == Vector("1 6 12 11 124")); r.sort(); assert(r == Vector("1 6 11 12 124")); r.remove_first_matching_assume_sorted(11); assert(r == Vector("1 6 12 124")); r.remove_first_matching(4); assert(r == Vector("1 6 12 124")); r.remove_first_matching_assume_sorted(9); assert(r == Vector("1 6 12 124")); } assert(Vector("1 2 3 4 5 6 7").intersect_sorted(Vector("4 5 7 9 11")) == Vector("4 5 7")); assert(Vector("1 1 1 1 1 6 7 8").intersect_sorted(Vector("1 1 1 6 7 7 7")) == Vector("1 6 7")); assert(Vector("1 1 1 1 1 6 7 8").intersect_sorted(Vector("1 1 1 6 7 7 7"), Vector::NotUnique) == Vector("1 1 1 1, 1 1 1 1; 6 6; 7 7 7 7")); { Vector t ("1 8 2 7 3 6 4 5"); t.move_interval(2, 4, 0); assert(t == Vector("2 7 2 7 3 6 4 5")); t.move_interval(3, 6, 4); assert(t == Vector("2 7 2 7 7 3 6 5")); assert(t.isininterval(1, 8)); assert(!t.isininterval(3, 8)); assert(t.isininterval(2, 7)); assert(!t.isininterval(1, 5)); assert(t.any_smaller(3)); assert(!t.any_smaller(2)); t -= t / 4; assert(t == "1.5,5.25,1.5,5.25,5.25,2.25,4.5,3.75"); t /= Vector("1 2 4 8 -1 -2 -4 -8"); assert(t == "1.5,2.625,0.375,0.65625,-5.25,-1.125,-1.125,-0.46875"); t += t * 31; assert(t == "48.,84.,12.,21.,-168.,-36.,-36.,-15."); Vector u (12); assert(u.isnull()); assert(u.size() == 12); assert(!v.empty()); Vector v = Vector::n(); assert(v.isnull()); assert(v.empty()); assert(v.size() == 0); } printf("vector.hpp is correct.\n"); return 0; }
int main(int argc, char* const argv[]) { signal(SIGPIPE, SIG_IGN); sp<IServiceManager> sm = defaultServiceManager(); fflush(stdout); if (sm == NULL) { ALOGE("Unable to get default service manager!"); aerr << "dumpsys: Unable to get default service manager!" << endl; return 20; } Vector<String16> services; Vector<String16> args; Vector<String16> skippedServices; bool showListOnly = false; bool skipServices = false; int timeoutArg = 10; static struct option longOptions[] = { {"skip", no_argument, 0, 0 }, {"help", no_argument, 0, 0 }, { 0, 0, 0, 0 } }; while (1) { int c; int optionIndex = 0; c = getopt_long(argc, argv, "+t:l", longOptions, &optionIndex); if (c == -1) { break; } switch (c) { case 0: if (!strcmp(longOptions[optionIndex].name, "skip")) { skipServices = true; } else if (!strcmp(longOptions[optionIndex].name, "help")) { usage(); return 0; } break; case 't': { char *endptr; timeoutArg = strtol(optarg, &endptr, 10); if (*endptr != '\0' || timeoutArg <= 0) { fprintf(stderr, "Error: invalid timeout number: '%s'\n", optarg); return -1; } } break; case 'l': showListOnly = true; break; default: fprintf(stderr, "\n"); usage(); return -1; } } for (int i = optind; i < argc; i++) { if (skipServices) { skippedServices.add(String16(argv[i])); } else { if (i == optind) { services.add(String16(argv[i])); } else { args.add(String16(argv[i])); } } } if ((skipServices && skippedServices.empty()) || (showListOnly && (!services.empty() || !skippedServices.empty()))) { usage(); return -1; } if (services.empty() || showListOnly) { // gets all services services = sm->listServices(); services.sort(sort_func); args.add(String16("-a")); } const size_t N = services.size(); if (N > 1) { // first print a list of the current services aout << "Currently running services:" << endl; for (size_t i=0; i<N; i++) { sp<IBinder> service = sm->checkService(services[i]); if (service != NULL) { bool skipped = IsSkipped(skippedServices, services[i]); aout << " " << services[i] << (skipped ? " (skipped)" : "") << endl; } } } if (showListOnly) { return 0; } for (size_t i = 0; i < N; i++) { String16 service_name = std::move(services[i]); if (IsSkipped(skippedServices, service_name)) continue; sp<IBinder> service = sm->checkService(service_name); if (service != NULL) { int sfd[2]; if (pipe(sfd) != 0) { aerr << "Failed to create pipe to dump service info for " << service_name << ": " << strerror(errno) << endl; continue; } unique_fd local_end(sfd[0]); unique_fd remote_end(sfd[1]); sfd[0] = sfd[1] = -1; if (N > 1) { aout << "------------------------------------------------------------" "-------------------" << endl; aout << "DUMP OF SERVICE " << service_name << ":" << endl; } // dump blocks until completion, so spawn a thread.. std::thread dump_thread([=, remote_end { std::move(remote_end) }]() mutable { int err = service->dump(remote_end.get(), args); // It'd be nice to be able to close the remote end of the socketpair before the dump // call returns, to terminate our reads if the other end closes their copy of the // file descriptor, but then hangs for some reason. There doesn't seem to be a good // way to do this, though. remote_end.reset(); if (err != 0) { aerr << "Error dumping service info: (" << strerror(err) << ") " << service_name << endl; } }); auto timeout = std::chrono::seconds(timeoutArg); auto end = std::chrono::steady_clock::now() + timeout; struct pollfd pfd = { .fd = local_end.get(), .events = POLLIN }; bool timed_out = false; bool error = false; while (true) { // Wrap this in a lambda so that TEMP_FAILURE_RETRY recalculates the timeout. auto time_left_ms = [end]() { auto now = std::chrono::steady_clock::now(); auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(end - now); return std::max(diff.count(), 0ll); }; int rc = TEMP_FAILURE_RETRY(poll(&pfd, 1, time_left_ms())); if (rc < 0) { aerr << "Error in poll while dumping service " << service_name << " : " << strerror(errno) << endl; error = true; break; } else if (rc == 0) { timed_out = true; break; } char buf[4096]; rc = TEMP_FAILURE_RETRY(read(local_end.get(), buf, sizeof(buf))); if (rc < 0) { aerr << "Failed to read while dumping service " << service_name << ": " << strerror(errno) << endl; error = true; break; } else if (rc == 0) { // EOF. break; } if (!WriteFully(STDOUT_FILENO, buf, rc)) { aerr << "Failed to write while dumping service " << service_name << ": " << strerror(errno) << endl; error = true; break; } } if (timed_out) { aout << endl << "*** SERVICE DUMP TIMEOUT EXPIRED ***" << endl << endl; } if (timed_out || error) { dump_thread.detach(); } else { dump_thread.join(); } } else { aerr << "Can't find service: " << service_name << endl; } }
void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size) { //super simple, almost brute force scanline stacking fitter //it's pretty basic for now, but it tries to make sure that the aspect ratio of the //resulting atlas is somehow square. This is necessary because video cards have limits //on texture size (usually 2048 or 4096), so the more square a texture, the more chances //it will work in every hardware. // for example, it will prioritize a 1024x1024 atlas (works everywhere) instead of a // 256x8192 atlas (won't work anywhere). ERR_FAIL_COND(p_rects.size() == 0); Vector<_AtlasWorkRect> wrects; wrects.resize(p_rects.size()); for (int i = 0; i < p_rects.size(); i++) { wrects[i].s = p_rects[i]; wrects[i].idx = i; } wrects.sort(); int widest = wrects[0].s.width; Vector<_AtlasWorkRectResult> results; for (int i = 0; i <= 12; i++) { int w = 1 << i; int max_h = 0; int max_w = 0; if (w < widest) continue; Vector<int> hmax; hmax.resize(w); for (int j = 0; j < w; j++) hmax[j] = 0; //place them int ofs = 0; int limit_h = 0; for (int j = 0; j < wrects.size(); j++) { if (ofs + wrects[j].s.width > w) { ofs = 0; } int from_y = 0; for (int k = 0; k < wrects[j].s.width; k++) { if (hmax[ofs + k] > from_y) from_y = hmax[ofs + k]; } wrects[j].p.x = ofs; wrects[j].p.y = from_y; int end_h = from_y + wrects[j].s.height; int end_w = ofs + wrects[j].s.width; if (ofs == 0) limit_h = end_h; for (int k = 0; k < wrects[j].s.width; k++) { hmax[ofs + k] = end_h; } if (end_h > max_h) max_h = end_h; if (end_w > max_w) max_w = end_w; if (ofs == 0 || end_h > limit_h) //while h limit not reached, keep stacking ofs += wrects[j].s.width; } _AtlasWorkRectResult result; result.result = wrects; result.max_h = max_h; result.max_w = max_w; results.push_back(result); } //find the result with the best aspect ratio int best = -1; real_t best_aspect = 1e20; for (int i = 0; i < results.size(); i++) { real_t h = nearest_power_of_2(results[i].max_h); real_t w = nearest_power_of_2(results[i].max_w); real_t aspect = h > w ? h / w : w / h; if (aspect < best_aspect) { best = i; best_aspect = aspect; } } r_result.resize(p_rects.size()); for (int i = 0; i < p_rects.size(); i++) { r_result[results[best].result[i].idx] = results[best].result[i].p; } r_size = Size2(results[best].max_w, results[best].max_h); }
void EditorAutoloadSettings::drop_data_fw(const Point2& p_point, const Variant& p_data, Control *p_control) { TreeItem *ti = tree->get_item_at_pos(p_point); if (!ti) return; int section = tree->get_drop_section_at_pos(p_point); if (section < -1) return; String name; bool move_to_back = false; if (section < 0) { name = ti->get_text(0); } else if (ti->get_next()) { name = ti->get_next()->get_text(0); } else { name = ti->get_text(0); move_to_back = true; } int order = GlobalConfig::get_singleton()->get_order("autoload/" + name); AutoLoadInfo aux; List<AutoLoadInfo>::Element *E = NULL; if (!move_to_back) { aux.order = order; E = autoload_cache.find(aux); } Dictionary drop_data = p_data; PoolStringArray autoloads = drop_data["autoloads"]; Vector<int> orders; orders.resize(autoload_cache.size()); for (int i = 0; i < autoloads.size(); i++) { aux.order = GlobalConfig::get_singleton()->get_order("autoload/" + autoloads[i]); List<AutoLoadInfo>::Element *I = autoload_cache.find(aux); if (move_to_back) { autoload_cache.move_to_back(I); } else if (E != I) { autoload_cache.move_before(I, E); } else if (E->next()) { E = E->next(); } else { break; } } int i = 0; for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) { orders[i++] = E->get().order; } orders.sort(); UndoRedo *undo_redo = EditorNode::get_undo_redo(); undo_redo->create_action(TTR("Rearrange Autoloads")); i = 0; for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) { undo_redo->add_do_method(GlobalConfig::get_singleton(), "set_order", E->get().name, orders[i++]); undo_redo->add_undo_method(GlobalConfig::get_singleton(), "set_order", E->get().name, E->get().order); } orders.clear(); undo_redo->add_do_method(this, "update_autoload"); undo_redo->add_undo_method(this, "update_autoload"); undo_redo->add_do_method(this, "emit_signal", autoload_changed); undo_redo->add_undo_method(this, "emit_signal", autoload_changed); undo_redo->commit_action(); }