void MongoDSessionCatalog::onStepUp(OperationContext* opCtx) { // Invalidate sessions that could have a retryable write on it, so that we can refresh from disk // in case the in-memory state was out of sync. const auto catalog = SessionCatalog::get(opCtx); // The use of shared_ptr here is in order to work around the limitation of stdx::function that // the functor must be copyable. auto sessionKillTokens = std::make_shared<std::vector<SessionCatalog::KillToken>>(); // Scan all sessions and reacquire locks for prepared transactions. // There may be sessions that are checked out during this scan, but none of them // can be prepared transactions, since only oplog application can make transactions // prepared on secondaries and oplog application has been stopped at this moment. std::vector<LogicalSessionId> sessionIdToReacquireLocks; SessionKiller::Matcher matcher( KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx)}); catalog->scanSessions(matcher, [&](const ObservableSession& session) { const auto txnParticipant = TransactionParticipant::get(session.get()); if (!txnParticipant->inMultiDocumentTransaction()) { sessionKillTokens->emplace_back(session.kill()); } if (txnParticipant->transactionIsPrepared()) { sessionIdToReacquireLocks.emplace_back(session.getSessionId()); } }); killSessionTokensFunction(opCtx, sessionKillTokens); { // Create a new opCtx because we need an empty locker to refresh the locks. auto newClient = opCtx->getServiceContext()->makeClient("restore-prepared-txn"); AlternativeClientRegion acr(newClient); for (const auto& sessionId : sessionIdToReacquireLocks) { auto newOpCtx = cc().makeOperationContext(); newOpCtx->setLogicalSessionId(sessionId); MongoDOperationContextSession ocs(newOpCtx.get()); auto txnParticipant = TransactionParticipant::get(OperationContextSession::get(newOpCtx.get())); txnParticipant->refreshLocksForPreparedTransaction(newOpCtx.get(), false); } } const size_t initialExtentSize = 0; const bool capped = false; const bool maxSize = 0; BSONObj result; DBDirectClient client(opCtx); if (client.createCollection(NamespaceString::kSessionTransactionsTableNamespace.ns(), initialExtentSize, capped, maxSize, &result)) { return; } const auto status = getStatusFromCommandResult(result); if (status == ErrorCodes::NamespaceExists) { return; } uassertStatusOKWithContext(status, str::stream() << "Failed to create the " << NamespaceString::kSessionTransactionsTableNamespace.ns() << " collection"); }
void CTest::TestEmptyInputData(CCompressStream::EMethod method) { const size_t kLen = 1024; char src_buf[kLen]; char dst_buf[kLen]; char cmp_buf[kLen]; size_t n; const size_t count = ArraySize(s_EmptyInputDataTests); for (size_t i = 0; i < count; ++i) { SEmptyInputDataTest test = s_EmptyInputDataTests[i]; if (test.method != method) { continue; } _TRACE("Test # " << i+1); CNcbiIstrstream is_str(""); unique_ptr<CCompression> compression; unique_ptr<CCompressionStreamProcessor> stream_compressor; unique_ptr<CCompressionStreamProcessor> stream_decompressor; if (method == CCompressStream::eBZip2) { compression.reset(new CBZip2Compression()); compression->SetFlags(test.flags); stream_compressor.reset(new CBZip2StreamCompressor(test.flags)); stream_decompressor.reset(new CBZip2StreamDecompressor(test.flags)); } else #if defined(HAVE_LIBLZO) if (method == CCompressStream::eLZO) { compression.reset(new CLZOCompression()); compression->SetFlags(test.flags); stream_compressor.reset(new CLZOStreamCompressor(test.flags)); stream_decompressor.reset(new CLZOStreamDecompressor(test.flags)); } else #endif if (method == CCompressStream::eZip) { compression.reset(new CZipCompression()); compression->SetFlags(test.flags); stream_compressor.reset(new CZipStreamCompressor(test.flags)); stream_decompressor.reset(new CZipStreamDecompressor(test.flags)); } else { _TROUBLE; } // ---- Run tests ---- // Buffer compression/decompression test {{ bool res = compression->CompressBuffer(src_buf, 0, dst_buf, kLen, &n); assert(res == test.result); assert(n == test.buffer_output_size); res = compression->DecompressBuffer(dst_buf, n, cmp_buf, kLen, &n); assert(res == test.result); assert(n == 0); }} // Input stream tests {{ CCompressionIStream ics(is_str, stream_compressor.get()); assert(ics.good()); ics.read(dst_buf, kLen); assert(ics.eof()); n = (size_t)ics.gcount(); assert(n == test.stream_output_size); assert(ics.GetProcessedSize() == 0); assert(ics.GetOutputSize() == n); CCompressionIStream ids(is_str, stream_decompressor.get()); assert(ids.good()); ids.read(dst_buf, kLen); assert(ids.eof()); n = (size_t)ids.gcount(); assert(n == 0); assert(ids.GetProcessedSize() == 0); assert(ids.GetOutputSize() == n); }} // Output stream tests {{ {{ CNcbiOstrstream os_str; CCompressionOStream ocs(os_str, stream_compressor.get()); assert(ocs.good()); ocs.Finalize(); assert(ocs.good()); n = (size_t)GetOssSize(os_str); assert(n == test.stream_output_size); assert(ocs.GetProcessedSize() == 0); assert(ocs.GetOutputSize() == n); }} {{ CNcbiOstrstream os_str; CCompressionOStream ods(os_str, stream_decompressor.get()); assert(ods.good()); ods.Finalize(); assert(test.result ? ods.good() : !ods.good()); n = (size_t)GetOssSize(os_str); assert(n == 0); assert(ods.GetProcessedSize() == 0); assert(ods.GetOutputSize() == n); }} }} // Output stream tests -- with flush() {{ {{ CNcbiOstrstream os_str; CCompressionOStream ocs(os_str, stream_compressor.get()); assert(ocs.good()); ocs.flush(); assert(ocs.good()); ocs.Finalize(); assert(ocs.good()); n = (size_t)GetOssSize(os_str); assert(n == test.stream_output_size); assert(ocs.GetProcessedSize() == 0); assert(ocs.GetOutputSize() == n); }} {{ CNcbiOstrstream os_str; CCompressionOStream ods(os_str, stream_decompressor.get()); assert(ods.good()); ods.flush(); assert(ods.good()); ods.Finalize(); assert(test.result ? ods.good() : !ods.good()); n = (size_t)GetOssSize(os_str); assert(n == 0); assert(ods.GetProcessedSize() == 0); assert(ods.GetOutputSize() == n); }} }} } }
void IDW:: execute() { //get resolution of input cloud pcl::PointXYZI minp,maxp; pcl::getMinMax3D(*m_baseCloud->get_Cloud(),minp,maxp); //float res = in->get_intValue()/100.0; pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_idw (new pcl::PointCloud<pcl::PointXYZI>); pcl::octree::OctreePointCloudSearch<pcl::PointXYZI> ocs (m_resolution); ocs.setInputCloud (m_baseCloud->get_Cloud()); ocs.addPointsFromInputCloud (); float lenght = maxp.x - minp.x + m_resolution; int per = 90/lenght; int percent =0; emit percentage(percent+=5); for(float i = minp.x; i < (maxp.x+m_resolution); i= i + m_resolution) { for(float j = minp.y; j < (maxp.y+m_resolution);j = j + m_resolution) { std::vector<int> pIv; std::vector<float> pSv; pcl::PointXYZI spV; float z_coor=0; spV.x = i; spV.y = j; spV.z = (minp.z+maxp.z)/2; if(ocs.nearestKSearch(spV, m_pointsnum*3, pIv, pSv) > 0 ) { for(int c=0; c< pIv.size(); c++) { z_coor +=m_baseCloud->get_Cloud()->points.at(pIv.at(c)).z; } z_coor/=pIv.size(); } std::vector<int> pointIv; std::vector<float> pointSv; pcl::PointXYZI searchPointVV; // pro dany bod najdi 10 nejblizsich bodu searchPointVV.x = i; searchPointVV.y = j; searchPointVV.z = z_coor; if(ocs.nearestKSearch(searchPointVV, m_pointsnum, pointIv, pointSv) > 0 ) { float w_sum = 0; float z_sum = 0; float intensity = m_baseCloud->get_Cloud()->points.at(pointIv.at(0)).intensity; // w_sum for(int q =0; q <pointIv.size(); q++) { float w = 1/pointSv.at(q); w_sum+= w; } //z_sum for(int e = 0; e < pointIv.size(); e++) { float w = 1/pointSv.at(e); float z= (w * m_baseCloud->get_Cloud()->points.at(pointIv.at(e)).z)/w_sum ; z_sum+= z; } pcl::PointXYZI bod; bod.x= searchPointVV.x; bod.y= searchPointVV.y; bod.z= z_sum; bod.intensity= intensity; //#pragma omp critical cloud_idw->points.push_back(bod); } } emit percentage(percent+= per); } cloud_idw->width = cloud_idw->points.size (); cloud_idw->height = 1; cloud_idw->is_dense = true; m_output->set_Cloud(cloud_idw); emit percentage(100); sendData(); }
void OctreeTerrain::octree(float res, pcl::PointCloud<pcl::PointXYZI>::Ptr input,pcl::PointCloud<pcl::PointXYZI>::Ptr output_ground, pcl::PointCloud<pcl::PointXYZI>::Ptr output_vege) { // udelat octree pcl::octree::OctreePointCloud<pcl::PointXYZI> oc (res); oc.setInputCloud (input); oc.addPointsFromInputCloud (); // zjistit vsechny voxely std::vector<pcl::PointXYZI, Eigen::aligned_allocator<pcl::PointXYZI> > voxels; oc.getOccupiedVoxelCenters(voxels); // zjistit rozsah x y osy a podle toho hledat voxely ktere jsou nejníž double x_max,x_min,y_max,y_min,z_min,z_max; oc.getBoundingBox(x_min,y_min,z_min,x_max,y_max,z_max); oc.deleteTree(); // z voxels udelat mracno bodu pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_voxels (new pcl::PointCloud<pcl::PointXYZI>); cloud_voxels->points.resize(voxels.size()); #pragma omp parallel for for(int r=0; r < voxels.size(); r++) { cloud_voxels->points.at(r) = voxels.at(r); } cloud_voxels->width = cloud_voxels->points.size (); cloud_voxels->height = 1; cloud_voxels->is_dense = true; // spis boxsearch a pro kazdy voxel najit sousedy v danem boxu, pokud nenajde žadny bod niž než je on sam uložit jeho ID.. pcl::octree::OctreePointCloudSearch<pcl::PointXYZI> ocs (res); ocs.setInputCloud (cloud_voxels); ocs.addPointsFromInputCloud (); std::vector< int > low_voxels; for (int q =0; q < voxels.size(); q++) { std::vector< int > ind; Eigen::Vector3f low(voxels.at(q).x-res/2, voxels.at(q).y-res/2,z_min); Eigen::Vector3f high(voxels.at(q).x+res/2, voxels.at(q).y+res/2,voxels.at(q).z); if(ocs.boxSearch(low,high,ind) <3) { if(ind.size() == 0) continue; // pokud jsou voxely vyskove pouze res od sebe if(ind.size()==1) low_voxels.push_back(q); else { if(std::abs(voxels.at(ind.at(0)).z - voxels.at(ind.at(1)).z ) < (res*1.1) ) low_voxels.push_back(q); } } } ocs.deleteTree(); // get point of lowest voxels pcl::octree::OctreePointCloudSearch<pcl::PointXYZI> ocsearch (res); ocsearch.setInputCloud (input); ocsearch.addPointsFromInputCloud (); std::vector< int > low_voxels_indices; for(int u=0; u< low_voxels.size();u++) { ocsearch.voxelSearch(voxels.at(low_voxels.at(u)),low_voxels_indices); } ocsearch.deleteTree(); // ocs.voxelSearch(voxels.at(q),low_voxels_indices); boost::shared_ptr<std::vector<int> > indicesptr (new std::vector<int> (low_voxels_indices)); pcl::ExtractIndices<pcl::PointXYZI> extract; // Extract the inliers extract.setInputCloud (input); extract.setIndices (indicesptr); extract.setNegative (false); extract.filter (*output_ground); extract.setNegative (true); extract.filter (*output_vege); }
void VoxelTerrain:: execute() { //pro vstupni cloud // udelat octree pcl::octree::OctreePointCloud<pcl::PointXYZI> oc (m_resolution); oc.setInputCloud (m_baseCloud->get_Cloud()); oc.addPointsFromInputCloud (); // zjistit vsechny voxely std::vector<pcl::PointXYZI, Eigen::aligned_allocator<pcl::PointXYZI> > voxels; oc.getOccupiedVoxelCenters(voxels); // zjistit rozsah x y osy a podle toho hledat voxely ktere jsou nejníž double x_max,x_min,y_max,y_min,z_min,z_max; oc.getBoundingBox(x_min,y_min,z_min,x_max,y_max,z_max); oc.deleteTree(); emit percentage( 20); // z voxels udelat mracno bodu pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_voxels (new pcl::PointCloud<pcl::PointXYZI>); cloud_voxels->points.resize(voxels.size()); #pragma omp parallel for for(int r=0; r < voxels.size(); r++) { cloud_voxels->points.at(r) = voxels.at(r); } cloud_voxels->width = cloud_voxels->points.size (); cloud_voxels->height = 1; cloud_voxels->is_dense = true; emit percentage( 40); // spis boxsearch a pro kazdy voxel najit sousedy v danem boxu, pokud nenajde žadny bod niž než je on sam uložit jeho ID.. pcl::octree::OctreePointCloudSearch<pcl::PointXYZI> ocs (m_resolution); ocs.setInputCloud (cloud_voxels); ocs.addPointsFromInputCloud (); std::vector< int > low_voxels; for (int q =0; q < voxels.size(); q++) { std::vector< int > ind; Eigen::Vector3f low(voxels.at(q).x-m_resolution/2, voxels.at(q).y-m_resolution/2,z_min); Eigen::Vector3f high(voxels.at(q).x+m_resolution/2, voxels.at(q).y+m_resolution/2,voxels.at(q).z); if(ocs.boxSearch(low,high,ind) <2) { if(ind.size() == 0) continue; // pokud jsou voxely vyskove pouze res od sebe if(ind.size()==1) low_voxels.push_back(q); } } emit percentage( 80); ocs.deleteTree(); // jeste by to chtelo trochu prefiltrovat aby byl opravdu jen voxely terenu boost::shared_ptr<std::vector<int> > indicesptr (new std::vector<int> (low_voxels)); pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_vege (new pcl::PointCloud<pcl::PointXYZI>); pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_terrain (new pcl::PointCloud<pcl::PointXYZI>); pcl::ExtractIndices<pcl::PointXYZI> extract; // Extract the inliers extract.setInputCloud (cloud_voxels); extract.setIndices (indicesptr); extract.setNegative (false); extract.filter (*cloud_terrain); extract.setNegative (true); extract.filter (*cloud_vege); m_vegetation->set_Cloud(cloud_vege); m_terrain->set_Cloud(cloud_terrain); sendData(); emit percentage( 99); }