vector<shared_ptr<Patch>> CachingPyramidFeatureExtractor::extract(int stepX, int stepY, Rect roi, int firstLayer, int lastLayer, int stepLayer) const { if (stepX < 1) throw invalid_argument("CachingPyramidFeatureExtractor: stepX has to be greater than zero"); if (stepY < 1) throw invalid_argument("CachingPyramidFeatureExtractor: stepY has to be greater than zero"); if (stepLayer < 1) throw invalid_argument("CachingPyramidFeatureExtractor: stepLayer has to be greater than zero"); Size imageSize = getImageSize(); if (roi.x == 0 && roi.y == 0 && roi.width == 0 && roi.height == 0) { roi.width = imageSize.width; roi.height = imageSize.height; } else { roi.x = std::max(0, roi.x); roi.y = std::max(0, roi.y); roi.width = std::min(imageSize.width, roi.width + roi.x) - roi.x; roi.height = std::min(imageSize.height, roi.height + roi.y) - roi.y; } vector<shared_ptr<Patch>> patches; if (firstLayer < 0) firstLayer = cache.front().getIndex(); if (lastLayer < 0) lastLayer = cache.back().getIndex(); for (auto layer = cache.begin(); layer != cache.end(); layer += stepLayer) { if (layer->getIndex() < firstLayer) continue; if (layer->getIndex() > lastLayer) break; Size patchSize = getPatchSize(); Point roiBegin(layer->getScaled(roi.x), layer->getScaled(roi.y)); Point roiEnd(layer->getScaled(roi.x + roi.width), layer->getScaled(roi.y + roi.height)); Point centerRoiBegin = Point(roiBegin.x + patchSize.width / 2, roiBegin.y + patchSize.height / 2); Point centerRoiEnd = Point(roiEnd.x - patchSize.width, roiEnd.y - patchSize.height); Point center(centerRoiBegin.x, centerRoiBegin.y); for (center.y = centerRoiBegin.y; center.y < centerRoiEnd.y; center.y += stepY) { for (center.x = centerRoiBegin.x; center.x < centerRoiEnd.x; center.x += stepX) { switch (strategy) { case Strategy::SHARING: patches.push_back(extractSharing(*layer, center.x, center.y)); break; case Strategy::COPYING: patches.push_back(extractCopying(*layer, center.x, center.y)); break; case Strategy::INPUT_COPYING: patches.push_back(extractInputCopying(*layer, center.x, center.y)); break; case Strategy::OUTPUT_COPYING: patches.push_back(extractOutputCopying(*layer, center.x, center.y)); break; } } } } return patches; }
/** * XXX: IMPORTANt - result will show in Kb */ void getSwapUsage(monita_swap* buf) { char buffer [BUFSIZ]; char* p; memset(buf, 0, sizeof (monita_swap)); fileToBuffer(buffer, sizeof buffer, MEMINFO); // XXX: IMPORTANT - Kernel 2.6 with multiple lines buf->total = getScaled(buffer, "SwapTotal:"); buf->free = getScaled(buffer, "SwapFree:"); buf->cached = getScaled(buffer, "Cached:"); buf->used = buf->total - buf->free; unsigned long osVersionCode = getLinuxVersionCode(); if(osVersionCode >= LINUX_VERSION_CODE(2, 6, 0)) { fileToBuffer(buffer, sizeof buffer, PROC_VMSTAT); p = strstr(buffer, "\npswpin"); if(p) { p = skipToken(p); buf->pagein = strtoull(p, &p, 0); p = skipToken(p); buf->pageout = strtoull(p, &p, 0); } } else // Linux 2.4 { fileToBuffer(buffer, sizeof buffer, PROC_STAT); p = strstr(buffer, "\nswap"); if(p) { p = skipToken(p); buf->pagein = strtoull(p, &p, 0); buf->pageout = strtoull(p, &p, 0); } } }
void run( const std::string & meshFile, const uint_t numTotalBlocks ) { auto mesh = make_shared<MeshType>(); mesh::readAndBroadcast( meshFile, *mesh); auto aabb = computeAABB( *mesh ); auto domainAABB = aabb.getScaled( typename MeshType::Scalar(1.26) ); // AABB containing the test points auto triDist = make_shared< mesh::TriangleDistance<MeshType> >( mesh ); auto distanceOctree = make_shared< DistanceOctree<MeshType> >( triDist ); Vector3<uint_t> numBlocks = math::getFactors3D( numTotalBlocks, domainAABB.sizes() ); test< ExcludeMeshExterior< DistanceOctree< MeshType > > >( distanceOctree, *mesh, domainAABB, numBlocks ); test< ExcludeMeshInterior< DistanceOctree< MeshType > > >( distanceOctree, *mesh, domainAABB, numBlocks ); }
void testAABB() { static const math::Vector3<real_t> ZERO( real_t( 0 ), real_t( 0 ), real_t( 0 ) ); static const math::Vector3<real_t> UNIT( real_t( 1 ), real_t( 1 ), real_t( 1 ) ); static const real_t EPSILON = real_t(1e-4); boost::random::mt19937 randomEngine; std::vector<math::AABB> testAABBs; testAABBs.push_back( math::AABB( -UNIT, UNIT ) ); testAABBs.push_back( math::AABB( ZERO, UNIT ) ); testAABBs.push_back( math::AABB( -UNIT, ZERO ) ); for( auto aabbIt = testAABBs.begin(); aabbIt != testAABBs.end(); ++aabbIt ) { const math::AABB outerAABB = aabbIt->getScaled( real_t( 2 ) ); std::vector< std::pair< Vector3<real_t>, Vector3<real_t> > > testPoints; for( int i = 0; i < 100; ++i ) { Vector3<real_t> outerPoint, innerPoint; do { outerPoint = outerAABB.randomPoint( randomEngine ); } while( aabbIt->contains( outerPoint ) ); innerPoint = aabbIt->randomPoint( randomEngine ); testPoints.push_back( std::make_pair( outerPoint, innerPoint - outerPoint ) ); } for( auto pointIt = testPoints.begin(); pointIt != testPoints.end(); ++pointIt ) { const Vector3<real_t> & fluidPoint = pointIt->first; const Vector3<real_t> & direction = pointIt->second; real_t q = lbm::intersectionRatio( *aabbIt, fluidPoint, direction, EPSILON ); Vector3<real_t> intersectionPoint = fluidPoint + direction * q; WALBERLA_CHECK_LESS( std::fabs( aabbIt->sqSignedDistance( intersectionPoint ) ), EPSILON * EPSILON ); q = lbm::intersectionRatioBisection( *aabbIt, fluidPoint, direction, EPSILON ); intersectionPoint = fluidPoint + direction * q; WALBERLA_CHECK_LESS( std::fabs( aabbIt->sqSignedDistance( intersectionPoint ) ), EPSILON * EPSILON ); } } }
void testAABBDistance( const Vector3<real_t> & translationVector = Vector3<real_t>() ) { auto mesh = make_shared<MeshType>(); mesh::readAndBroadcast( "cube.obj", *mesh); translate( *mesh, translationVector ); auto aabb = computeAABB( *mesh ); // works since the mesh is a cube auto testVolume = aabb.getScaled( real_t(2) ); // AABB containing the test points TriangleDistance<MeshType> triDist( mesh ); std::mt19937 rng; for( int i = 0; i < 10000; ++i ) { auto p = testVolume.randomPoint( rng ); WALBERLA_CHECK_FLOAT_EQUAL( triDist.sqSignedDistance( toOpenMesh(p) ), aabb.sqSignedDistance( p ) ); } }
ofxVec4f ofxVec4f::rescaled( const float length ) const { return getScaled(length); }
SurfacePtr Surface::getScaled(int dst_wi, int dst_hi, Filter filter) const { SurfacePtr surf = new img::Surface(img::Format_ARGB_8888, dst_wi, dst_hi); getScaled(surf.ref(), filter); return surf; }
void test( const std::string & meshFile, const uint_t numProcesses, const uint_t numTotalBlocks ) { auto mesh = make_shared<MeshType>(); mesh::readAndBroadcast( meshFile, *mesh); auto aabb = computeAABB( *mesh ); auto domainAABB = aabb.getScaled( typename MeshType::Scalar(3) ); auto triDist = make_shared< mesh::TriangleDistance<MeshType> >( mesh ); auto distanceOctree = make_shared< DistanceOctree< MeshType > >( triDist ); const real_t meshVolume = real_c( computeVolume( *mesh ) ); const real_t blockVolume = meshVolume / real_c( numTotalBlocks ); static const real_t cellsPersBlock = real_t(1000); const real_t cellVolume = blockVolume / cellsPersBlock; const Vector3<real_t> cellSize( std::pow( cellVolume, real_t(1) / real_t(3) ) ); ComplexGeometryStructuredBlockforestCreator bfc( domainAABB, cellSize, makeExcludeMeshInterior( distanceOctree, cellSize.min() ) ); auto wl = mesh::makeMeshWorkloadMemory( distanceOctree, cellSize ); wl.setInsideCellWorkload(0); wl.setOutsideCellWorkload(1); wl.setForceZeroMemoryOnZeroWorkload(true); bfc.setWorkloadMemorySUIDAssignmentFunction( wl ); bfc.setRefinementSelectionFunction( makeRefinementSelection( distanceOctree, 5, cellSize[0], cellSize[0] * real_t(5) ) ); WALBERLA_LOG_INFO_ON_ROOT( "Creating SBF with StaticLevelwiseCurveBalanceWeighted Partitioner" ); bfc.setTargetProcessAssignmentFunction( blockforest::StaticLevelwiseCurveBalanceWeighted() ); auto sbf_default = bfc.createSetupBlockForest( Vector3<uint_t>(64,64,64), numProcesses ); //sbf_default->writeVTKOutput("sbf_default"); WALBERLA_LOG_INFO_ON_ROOT( sbf_default->toString() ); return; #ifdef WALBERLA_BUILD_WITH_PARMETIS WALBERLA_LOG_INFO_ON_ROOT( "Creating SBF with ParMetis (PART_KWAY, no commweights)" ); bfc.setTargetProcessAssignmentFunction( blockforest::StaticLevelwiseParMetis( blockforest::StaticLevelwiseParMetis::PARMETIS_PART_KWAY ) ); auto sbf = bfc.createSetupBlockForest( numTotalBlocks, numProcesses ); //sbf->writeVTKOutput("sbf"); WALBERLA_LOG_INFO_ON_ROOT( sbf->toString() ); WALBERLA_LOG_INFO_ON_ROOT( "Creating SBF with ParMetis (PART_KWAY, commweights)" ); bfc.setTargetProcessAssignmentFunction( blockforest::StaticLevelwiseParMetis( commInXDirection, blockforest::StaticLevelwiseParMetis::PARMETIS_PART_KWAY ) ); auto sbf_edge = bfc.createSetupBlockForest( numTotalBlocks, numProcesses ); //sbf_edge->writeVTKOutput("sbf_edge"); WALBERLA_LOG_INFO_ON_ROOT( sbf_edge->toString() ); WALBERLA_LOG_INFO_ON_ROOT( "Creating SBF with ParMetis (PART_GEOM_KWAY, no commweights)" ); bfc.setTargetProcessAssignmentFunction( blockforest::StaticLevelwiseParMetis( blockforest::StaticLevelwiseParMetis::PARMETIS_PART_GEOM_KWAY ) ); auto sbf_geom = bfc.createSetupBlockForest( numTotalBlocks, numProcesses ); //sbf_geom->writeVTKOutput("sbf_geom"); WALBERLA_LOG_INFO_ON_ROOT( sbf_geom->toString() ); WALBERLA_LOG_INFO_ON_ROOT( "Creating SBF with ParMetis (PART_GEOM_KWAY, commweights)" ); bfc.setTargetProcessAssignmentFunction( blockforest::StaticLevelwiseParMetis( commInXDirection, blockforest::StaticLevelwiseParMetis::PARMETIS_PART_GEOM_KWAY ) ); auto sbf_geom_edge = bfc.createSetupBlockForest( numTotalBlocks, numProcesses ); //sbf_geom_edge->writeVTKOutput("sbf_geom_edge"); WALBERLA_LOG_INFO_ON_ROOT( sbf_geom_edge->toString() ); #endif }