Foam::binaryOperationSearchableSurface::binaryOperationSearchableSurface
(
    const IOobject& io,
    const dictionary& dict
)
:
    searchableSurface(io),
    aName_(dict.lookupOrDefault<word>("aName","A")),
    bName_(dict.lookupOrDefault<word>("bName","B")),
    a_(
        searchableSurface::New
        (
            word(dict.subDict("a").lookup("type")),
            IOobject(
                name()+"_"+word(dict.lookup("type"))+"_"+aName_,
                io.instance(),
                io.db(),
                io.readOpt(),
                io.writeOpt()
            ),
            dict.subDict("a")
        )
    ),
    b_(
        searchableSurface::New
        (
            word(dict.subDict("b").lookup("type")),
            IOobject(
                name()+"_"+word(dict.lookup("type"))+"_"+bName_,
                io.instance(),
                io.db(),
                io.readOpt(),
                io.writeOpt()
            ),
            dict.subDict("b")
        )
    ),
    nrARegions_(
        a().regions().size()
    ),
    nrBRegions_(
        b().regions().size()
    )
{
    if(aName_==bName_) {
        FatalErrorIn("binaryOperationSearchableSurface::binaryOperationSearchableSurface")
            << "'aName' and 'bName' have the same value " << aName_
                << " for " << name()
                << endl
                << exit(FatalError);
    }
    if(regions().size()!=size()) {
        FatalErrorIn("binaryOperationSearchableSurface::binaryOperationSearchableSurface")
            << "Number of regions " << regions().size() << " not equal to size "
                << size() << nl << "Regions: " << regions()
                << endl
                << exit(FatalError);

    }
}
hsa_status_t GpuAgent::IterateRegion(
    hsa_status_t (*callback)(hsa_region_t region, void* data),
    void* data) const {
  const size_t num_mems = regions().size();

  for (size_t j = 0; j < num_mems; ++j) {
    hsa_region_t region = core::MemoryRegion::Convert(regions()[j]);
    hsa_status_t status = callback(region, data);
    if (status != HSA_STATUS_SUCCESS) {
      return status;
    }
  }

  return HSA_STATUS_SUCCESS;
}
  void CreateBug1117712LayerTree() {
    const char* layerTreeSyntax = "c(c(t)t)";
    // LayerID                     0 1 2 3
    // 0 is the root
    // 1 is a container layer whose sole purpose to make a non-empty ancestor
    //   transform for 2, so that 2's screen-to-apzc and apzc-to-gecko
    //   transforms are different from 3's.
    // 2 is a small layer that is the actual target
    // 3 is a big layer obscuring 2 with a dispatch-to-content region
    nsIntRegion layerVisibleRegions[] = {
      nsIntRegion(IntRect(0, 0, 100, 100)),
      nsIntRegion(IntRect(0, 0, 0, 0)),
      nsIntRegion(IntRect(0, 0, 10, 10)),
      nsIntRegion(IntRect(0, 0, 100, 100)),
    };
    Matrix4x4 layerTransforms[] = {
      Matrix4x4(),
      Matrix4x4::Translation(50, 0, 0),
      Matrix4x4(),
      Matrix4x4(),
    };
    root = CreateLayerTree(layerTreeSyntax, layerVisibleRegions, layerTransforms, lm, layers);

    SetScrollableFrameMetrics(layers[2], FrameMetrics::START_SCROLL_ID + 1, CSSRect(0, 0, 10, 10));
    SetScrollableFrameMetrics(layers[3], FrameMetrics::START_SCROLL_ID + 2, CSSRect(0, 0, 100, 100));

    EventRegions regions(nsIntRegion(IntRect(0, 0, 10, 10)));
    layers[2]->SetEventRegions(regions);
    regions.mHitRegion = nsIntRegion(IntRect(0, 0, 100, 100));
    regions.mDispatchToContentHitRegion = nsIntRegion(IntRect(0, 0, 100, 100));
    layers[3]->SetEventRegions(regions);

    registration = MakeUnique<ScopedLayerTreeRegistration>(manager, 0, root, mcc);
    manager->UpdateHitTestingTree(nullptr, root, false, 0, 0);
  }
  virtual bool load(
    const SfM_Data & sfm_data,
    const std::string & feat_directory,
    std::unique_ptr<features::Regions>& region_type)
  {
    C_Progress_display my_progress_bar( sfm_data.GetViews().size(),
      std::cout, "\n- Features Loading -\n" );
    // Read for each view the corresponding features and store them as PointFeatures
    std::unique_ptr<features::Regions> regions(region_type->EmptyClone());
    for (Views::const_iterator iter = sfm_data.GetViews().begin();
      iter != sfm_data.GetViews().end(); ++iter, ++my_progress_bar)
    {
      const std::string sImageName = stlplus::create_filespec(sfm_data.s_root_path, iter->second.get()->s_Img_path);
      const std::string basename = stlplus::basename_part(sImageName);
      const std::string featFile = stlplus::create_filespec(feat_directory, basename, ".feat");

      if (!regions->LoadFeatures(featFile))
      {
        std::cerr << "Invalid feature files for the view: " << sImageName << std::endl;
        return false;
      }
      // save loaded Features as PointFeature
      feats_per_view[iter->second.get()->id_view] = regions->GetRegionsPositions();
    }
    return true;
  }
Beispiel #5
0
void MythUIEditBar::CalcInverseRegions(void)
{
    m_invregions.clear();

    bool first = true;
    float start = 0.0f;
    QListIterator<QPair<float, float> > regions(m_regions);

    while (regions.hasNext())
    {
        QPair<float, float> region = regions.next();

        if (first)
        {
            if (region.first > 0.0f)
                m_invregions.append(qMakePair(start, region.first));

            start = region.second;
            first = false;
        }
        else
        {
            m_invregions.append(qMakePair(start, region.first));
            start = region.second;
        }
    }

    if (start < 1.0f)
        m_invregions.append(qMakePair(start, 1.0f));
}
Beispiel #6
0
void LoadableTextTrack::addRegions(const HeapVector<Member<VTTRegion>>& newRegions)
{
    for (size_t i = 0; i < newRegions.size(); ++i) {
        newRegions[i]->setTrack(this);
        regions()->add(newRegions[i]);
    }
}
int main(int argc, char *argv[])
{
	#include "setRootCase.H"
	#include "createTime.H"
	#include "readSolverOptions.H"
	
	regionProperties regions(runTime);

	//- Create mesh
	#include "createFluidMeshes.H"

	//- Create fields
	forAll(fluidRegions, j)
	{
		if ( fluidsNames[j] == regionName )
		{
			#include "createBasicFields.H"
			#include "createAdditionalFields.H"
			#include "memoryAllocation.H"
			#include "properties.H"
			#include "finalSetupOperations.H"

			#include "evaluatingArea.H"
			#include "evaluatingConversion.H"
			#include "evaluatingAtomBalance.H"
			#include "evaluatingPressureDrops.H"
			#include "evaluatingTransportProperties.H"
			#include "evaluatingEnthalpyBalance.H"
			#include "write.H"
		}
	}

	return 0;
}
  void CreateObscuringLayerTree() {
    const char* layerTreeSyntax = "c(c(t)t)";
    // LayerID                     0 1 2 3
    // 0 is the root.
    // 1 is a parent scrollable layer.
    // 2 is a child scrollable layer.
    // 3 is the Obscurer, who ruins everything.
    nsIntRegion layerVisibleRegions[] = {
        // x coordinates are uninteresting
        nsIntRegion(IntRect(0,   0, 200, 200)),  // [0, 200]
        nsIntRegion(IntRect(0,   0, 200, 200)),  // [0, 200]
        nsIntRegion(IntRect(0, 100, 200,  50)),  // [100, 150]
        nsIntRegion(IntRect(0, 100, 200, 100))   // [100, 200]
    };
    root = CreateLayerTree(layerTreeSyntax, layerVisibleRegions, nullptr, lm, layers);

    SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID, CSSRect(0, 0, 200, 200));
    SetScrollableFrameMetrics(layers[1], FrameMetrics::START_SCROLL_ID + 1, CSSRect(0, 0, 200, 300));
    SetScrollableFrameMetrics(layers[2], FrameMetrics::START_SCROLL_ID + 2, CSSRect(0, 0, 200, 100));
    SetScrollHandoff(layers[2], layers[1]);
    SetScrollHandoff(layers[1], root);

    EventRegions regions(nsIntRegion(IntRect(0, 0, 200, 200)));
    root->SetEventRegions(regions);
    regions.mHitRegion = nsIntRegion(IntRect(0, 0, 200, 300));
    layers[1]->SetEventRegions(regions);
    regions.mHitRegion = nsIntRegion(IntRect(0, 100, 200, 100));
    layers[2]->SetEventRegions(regions);

    registration = MakeUnique<ScopedLayerTreeRegistration>(manager, 0, root, mcc);
    manager->UpdateHitTestingTree(nullptr, root, false, 0, 0);
    rootApzc = ApzcOf(root);
  }
Beispiel #9
0
void LoadableTextTrack::addRegions(
    const HeapVector<Member<VTTRegion>>& newRegions) {
  for (const auto& region : newRegions) {
    region->setTrack(this);
    regions()->add(region);
  }
}
  void CreateEventRegionsLayerTree1() {
    const char* layerTreeSyntax = "c(tt)";
    nsIntRegion layerVisibleRegions[] = {
      nsIntRegion(IntRect(0, 0, 200, 200)),     // root
      nsIntRegion(IntRect(0, 0, 100, 200)),     // left half
      nsIntRegion(IntRect(0, 100, 200, 100)),   // bottom half
    };
    root = CreateLayerTree(layerTreeSyntax, layerVisibleRegions, nullptr, lm, layers);
    SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID);
    SetScrollableFrameMetrics(layers[1], FrameMetrics::START_SCROLL_ID + 1);
    SetScrollableFrameMetrics(layers[2], FrameMetrics::START_SCROLL_ID + 2);
    SetScrollHandoff(layers[1], root);
    SetScrollHandoff(layers[2], root);

    // Set up the event regions over a 200x200 area. The root layer has the
    // whole 200x200 as the hit region; layers[1] has the left half and
    // layers[2] has the bottom half. The bottom-left 100x100 area is also
    // in the d-t-c region for both layers[1] and layers[2] (but layers[2] is
    // on top so it gets the events by default if the main thread doesn't
    // respond).
    EventRegions regions(nsIntRegion(IntRect(0, 0, 200, 200)));
    root->SetEventRegions(regions);
    regions.mDispatchToContentHitRegion = nsIntRegion(IntRect(0, 100, 100, 100));
    regions.mHitRegion = nsIntRegion(IntRect(0, 0, 100, 200));
    layers[1]->SetEventRegions(regions);
    regions.mHitRegion = nsIntRegion(IntRect(0, 100, 200, 100));
    layers[2]->SetEventRegions(regions);

    registration = MakeUnique<ScopedLayerTreeRegistration>(manager, 0, root, mcc);
    manager->UpdateHitTestingTree(nullptr, root, false, 0, 0);
    rootApzc = ApzcOf(root);
  }
Beispiel #11
0
static bool skipFace(GFace *gf)
{
  if(gf->physicals.size()) return false;
  std::list<GRegion*> regions(gf->regions());
  for(std::list<GRegion*>::iterator itr = regions.begin(); itr != regions.end(); itr++){
    if(!skipRegion(*itr)) return false;
  }
  return true;
}
void InbandWebVTTTextTrack::newRegionsParsed()
{
    Vector<RefPtr<VTTRegion>> newRegions;
    parser().getNewRegions(newRegions);

    for (auto& region : newRegions) {
        region->setTrack(this);
        regions()->add(region);
    }
}
Beispiel #13
0
 /// generates n_crops many regions of a given size within the boundaries of a given image img
 std::vector<cv::RotatedRect> random_regions(const cv::Mat& img, int n_crops, float min_size_frac){
     std::vector<cv::RotatedRect> regions(n_crops);
     for(int i = 0; i<n_crops; i++){
         float f = std::exp(drand48() * (std::log(1.f) - std::log(min_size_frac)) + std::log(min_size_frac));
         float size = std::max(img.cols, img.rows) * f;
         float max_x = img.cols - size;
         float max_y = img.rows - size;
         cv::Rect r(cv::Point2f(max_x * drand48(), max_y * drand48()), cv::Size(size,size)); 
         regions[i] = cv::RotatedRect(cv::Point2f(r.x+size/2, r.y+size/2), cv::Size(size,size), 0.f);
     }
     return regions;
 }
hsa_status_t GpuAgent::IterateRegion(
    hsa_status_t (*callback)(hsa_region_t region, void* data),
    void* data) const {
  const size_t num_mems = regions().size();

  for (size_t j = 0; j < num_mems; ++j) {
    const MemoryRegion* amd_region =
        reinterpret_cast<const MemoryRegion*>(regions()[j]);

    // Skip memory regions other than host, gpu local, or LDS.
    if (amd_region->IsSystem() || amd_region->IsLocalMemory() ||
        amd_region->IsLDS()) {
      hsa_region_t hsa_region = core::MemoryRegion::Convert(amd_region);
      hsa_status_t status = callback(hsa_region, data);
      if (status != HSA_STATUS_SUCCESS) {
        return status;
      }
    }
  }

  return HSA_STATUS_SUCCESS;
}
Foam::label Foam::binaryOperationSearchableSurface::toIndexA(
    const label index
) const
{
    if(index>=nrARegions_) {
        Info << "A: " << index << "/" << nrARegions_
            << " " << regions() << endl;
        return -1;
        //        return 0;
    } else {
        return index;
    }
}
	void sceneTextDetector::set_Channels_Group(Mat image, int mode, int type, string xm, double prob)
	{
		//-----------------------------------------------------------------------------CSER
		/*computeNMChannels(image, channels, mode);

		int cn = (int)channels.size();
		for (int c = 0; c < cn - 1; c++)
			channels.push_back(255 - channels[c]);

		

		for (int c = 0; c<(int)channels.size(); c++)
		{
			er_filter1->run(channels[c], regions[c]);
			er_filter2->run(channels[c], regions[c]);
		}*/
		Mat grey;
		vector<vector<ERStat> > regions(2);
		cvtColor(image, grey, COLOR_RGB2GRAY);
		channels.clear();
		channels.push_back(grey);
		channels.push_back(255 - grey);
		regions[0].clear();
		regions[1].clear();
		nm_region_groups.clear();
		nm_boxes.clear();
		parallel_for_(cv::Range(0, (int)channels.size()), Parallel_extractCSER(channels, regions, er_filters1, er_filters2));
		//-----------------------------------------------------------------------------MSER
	/*	vector<vector<Point> > contours;
		vector<Rect> bboxes;
		Mat grey;
		cvtColor(image, grey, COLOR_RGB2GRAY);
		channels.clear();
		channels.push_back(grey);
		channels.push_back(255 - grey);
		regions.resize(channels.size());
		nm_region_groups.clear();
		nm_boxes.clear();
		
		Ptr<MSER> mser = MSER::create(21, (int)(0.00002*grey.cols*grey.rows), (int)(0.05*grey.cols*grey.rows), 1, 0.7);
		mser->detectRegions(grey, contours, bboxes);
		if (contours.size() > 0)
			MSERsToERStats(grey, contours, regions);*/
		//-----------------------------------------------------------------------------
		erGrouping(image, channels, regions, nm_region_groups, nm_boxes, type, xm, prob);
	}
Beispiel #17
0
    void AGGWindow::onPaint(wxPaintEvent& event) {
        wxPaintDC dc(this);

        wxCoord width, height;
        dc.GetSize(&width, &height);
        if (!bitmap || bitmap->GetWidth() != width || bitmap->GetHeight() != height) 
            init(width, height);
        
        // Iterate over regions needing repainting
        wxRegionIterator regions(GetUpdateRegion());
        wxRect rect;
        while (regions) {
            rect = regions.GetRect();
            dc.Blit(rect.x, rect.y, rect.width, rect.height, &memDC, rect.x, rect.y);
            ++regions;
        }
    }
size_t SkPictureRecord::size() const {
    size_t result = 0;
    size_t sizeData;
    bitmaps(&sizeData);
    result += sizeData;
    matrices(&sizeData);
    result += sizeData;
    paints(&sizeData);
    result += sizeData;
    paths(&sizeData);
    result += sizeData;
    pictures(&sizeData);
    result += sizeData;
    regions(&sizeData);
    result += sizeData;
    result += streamlen();
    return result;
}
  virtual bool load(
    const SfM_Data & sfm_data,
    const std::string & feat_directory,
    std::unique_ptr<features::Regions>& region_type)
  {
    C_Progress_display my_progress_bar( sfm_data.GetViews().size(),
      std::cout, "\n- Features Loading -\n" );
    // Read for each view the corresponding features and store them as PointFeatures
    bool bContinue = true;
#ifdef OPENMVG_USE_OPENMP
    #pragma omp parallel
#endif
    for (Views::const_iterator iter = sfm_data.GetViews().begin();
      iter != sfm_data.GetViews().end() && bContinue; ++iter)
    {
#ifdef OPENMVG_USE_OPENMP
    #pragma omp single nowait
#endif
      {
        const std::string sImageName = stlplus::create_filespec(sfm_data.s_root_path, iter->second.get()->s_Img_path);
        const std::string basename = stlplus::basename_part(sImageName);
        const std::string featFile = stlplus::create_filespec(feat_directory, basename, ".feat");

        std::unique_ptr<features::Regions> regions(region_type->EmptyClone());
        if (!regions->LoadFeatures(featFile))
        {
          std::cerr << "Invalid feature files for the view: " << sImageName << std::endl;
#ifdef OPENMVG_USE_OPENMP
      #pragma omp critical
#endif
          bContinue = false;
        }
#ifdef OPENMVG_USE_OPENMP
      #pragma omp critical
#endif
        {
          // save loaded Features as PointFeature
          feats_per_view[iter->second.get()->id_view] = regions->GetRegionsPositions();
          ++my_progress_bar;
        }
      }
    }
    return bContinue;
  }
int main(int argc, char** argv)
{
  try
  {
    Random random;
    Config config(*ParadoxNode::ParseFromFile("config.txt"));

    EU4::RegionCollection regions(*ParadoxNode::ParseFromFile(config.GetEU4Path() + "map\\region.txt"));

    LOG(LogLevel::Info) << "Determining generate area";
    EU4::ProvinceIDCollection generateProvinceIDs;
    for (const auto& provinceID : config.GetProvincesToGenerate())
      generateProvinceIDs.AddProvince(provinceID);
    for (const auto& regionName : config.GetRegionsToGenerate())
      generateProvinceIDs.AddRegion(regions, regionName);
    LOG(LogLevel::Debug) << "Generate provinces: " << generateProvinceIDs;

    LOG(LogLevel::Info) << "Reading province tags";
    TagProvinceNameMapping tagProvinceNameMapping(*ParadoxNode::ParseFromFile("province_tags.txt"));

    LOG(LogLevel::Info) << "Reading EU4 provinces";
    EU4::ProvinceCollection provinces(generateProvinceIDs.GetProvinceIDs(),
                                      config.GetEU4Path() + "history\\provinces\\",
                                      config.GetEU4Path() + "common\\province_names\\",
                                      config.GetEU4Path() + "localisation\\");
    provinces.ClearTags();

    EU4::CountryCollection countries;

    ProtoCountryCollection protoCountries;
    LOG(LogLevel::Info) << "Generating proto-countries";
    protoCountries.GenerateFromProvinces(provinces, generateProvinceIDs.GetProvinceIDs(), random);
    LOG(LogLevel::Info) << "Creating countries";
    protoCountries.CreateCountries(countries, tagProvinceNameMapping, random);

    LOG(LogLevel::Info) << "Writing mod";
    Mod mod(config.GetModName(), countries, provinces);
    mod.WriteMod(config.GetEU4Path() + "mod\\");
  }
  catch (std::exception& e)
  {
    LOG(LogLevel::Error) << e.what();
  }
}
Beispiel #21
0
    void CopyContext::copyResource(const Resource* pDst, const Resource* pSrc)
    {
        const Buffer* pDstBuffer = dynamic_cast<const Buffer*>(pDst);
        if (pDstBuffer)
        {
            const Buffer* pSrcBuffer = dynamic_cast<const Buffer*>(pSrc);
            assert(pSrcBuffer && (pSrcBuffer->getSize() == pDstBuffer->getSize()));
            copyBufferRegion(pDstBuffer, 0, pSrcBuffer, 0, pSrcBuffer->getSize());
        }
        else
        {
            const Texture* pSrcTex = dynamic_cast<const Texture*>(pSrc);
            const Texture* pDstTex = dynamic_cast<const Texture*>(pDst);
            assert(pSrcTex && pDstTex);
            assert((pSrcTex->getArraySize() == pDstTex->getArraySize()) && (pSrcTex->getMipCount() == pDstTex->getMipCount()));

            uint32_t mipCount = pSrcTex->getMipCount();
            std::vector<VkImageCopy> regions(mipCount);
            VkImageAspectFlags srcAspect = getAspectFlagsFromFormat(pSrcTex->getFormat());
            VkImageAspectFlags dstAspect = getAspectFlagsFromFormat(pDstTex->getFormat());
            uint32_t arraySize = pSrcTex->getArraySize();
            for (uint32_t i = 0; i < mipCount; i++)
            {
                regions[i] = {};
                regions[i].srcSubresource.aspectMask = srcAspect;
                regions[i].srcSubresource.baseArrayLayer = 0;
                regions[i].srcSubresource.layerCount = arraySize;
                regions[i].srcSubresource.mipLevel = i;

                regions[i].dstSubresource = regions[i].srcSubresource;
                regions[i].dstSubresource.aspectMask = dstAspect;

                regions[i].extent.width = pSrcTex->getWidth(i);
                regions[i].extent.height = pSrcTex->getHeight(i);
                regions[i].extent.depth = pSrcTex->getDepth(i);
            }

            resourceBarrier(pDst, Resource::State::CopyDest);
            resourceBarrier(pSrc, Resource::State::CopySource);
            vkCmdCopyImage(mpLowLevelData->getCommandList(), pSrc->getApiHandle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, pDst->getApiHandle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, mipCount, regions.data());
        }
        mCommandsPending = true;
    }
Beispiel #22
0
static void _fix_caverns(dungeon_t* dungeon)
{
  int* flood_map;

  flood_map = new int[dungeon->width * dungeon->height];
  for (int y = 0; y < dungeon->height; y++)
  {
    for (int x = 0; x < dungeon->width; x++)
    {
      int index = y * dungeon->width + x;
      flood_map[index] = 1;
      tile_t* tile = get_tile_at(dungeon, x, y);
      if (tile->id == TILE_STONE_WALL)
      {
        flood_map[index] = 0;
      }
    }
  }

  unique_regions<int> regions(flood_map, dungeon->width, dungeon->height, 1);

  TRACE("Number of unique regions: %d", regions.get().size());
  regions.dump();

  const unique_regions<int>::region* largest_region =
      regions.get_largest_region();
  for (size_t i = 0; i < regions.get().size(); i++)
  {
    const unique_regions<int>::region region = regions.get()[i];
    if (region.id != largest_region->id)
    {
      TRACE("Removing region %d, with size %d", region.id, region.coords.size());
      for (size_t j = 0; j < region.coords.size(); j++)
      {
        coord_t coord = region.coords[j];
        set_tile_at(dungeon, coord.x, coord.y, TILES[TILE_STONE_WALL]);
      }
    }
  }

  delete[] flood_map;
}
  void CreateEventRegionsLayerTree2() {
    const char* layerTreeSyntax = "c(t)";
    nsIntRegion layerVisibleRegions[] = {
      nsIntRegion(IntRect(0, 0, 100, 500)),
      nsIntRegion(IntRect(0, 150, 100, 100)),
    };
    root = CreateLayerTree(layerTreeSyntax, layerVisibleRegions, nullptr, lm, layers);
    SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID);

    // Set up the event regions so that the child thebes layer is positioned far
    // away from the scrolling container layer.
    EventRegions regions(nsIntRegion(IntRect(0, 0, 100, 100)));
    root->SetEventRegions(regions);
    regions.mHitRegion = nsIntRegion(IntRect(0, 150, 100, 100));
    layers[1]->SetEventRegions(regions);

    registration = MakeUnique<ScopedLayerTreeRegistration>(manager, 0, root, mcc);
    manager->UpdateHitTestingTree(nullptr, root, false, 0, 0);
    rootApzc = ApzcOf(root);
  }
void ExtractTexto::Segmentar( cv::Mat const & source, std::vector<cv::Rect> &groups_boxes ){
    
    std::vector<cv::Mat> channels;
          
    cv::text::computeNMChannels(source, channels);
    
    groups_boxes.clear();
    
    int cn = (int)channels.size();
        
    for (int c = 0; c < cn-1; c++)
        channels.push_back(channels[c]);    
   
    //Ptr<cv::text::ERFilter> er_filter1 = createERFilterNM1(loadClassifierNM1("trained_classifierNM1.xml"), 11, 0.00005, 0.2, 0.8, true, 0.5);
   
    Ptr<cv::text::ERFilter> er_filter1 = createERFilterNM1(loadClassifierNM1("trained_classifierNM1.xml"), 13, 0.0005, 0.2, 0.5, true, 0.5);
    
    Ptr<cv::text::ERFilter> er_filter2 = createERFilterNM2(loadClassifierNM2("trained_classifierNM2.xml"), 0.5);
    
    std::vector< std::vector<cv::text::ERStat> > regions(channels.size());
    
    for (int c=0; c<(int)channels.size(); c++){
        er_filter1->run(channels[c], regions[c]); 
        er_filter2->run(channels[c], regions[c]);
    }
    
    std::vector< std::vector<Vec2i>> region_groups;    
    
    cv::text::erGrouping(source, channels, regions, region_groups, groups_boxes, ERGROUPING_ORIENTATION_HORIZ);
        
    cv::Mat imagClone = source.clone();
       
    findSuperRect(groups_boxes, groups_boxes);
    
    groups_draw(imagClone, groups_boxes);  
           
    er_filter1.release();
    er_filter2.release();
    regions.clear();
    
}
logical pc_ADK_FieldControl :: AddRegion (char *propnames, int32 indx0 )
{
  pc_ADK_Field      regions(GPH("regions"));
  char              propname[ID_SIZE];
  logical           term     = NO;
BEGINSEQ
  if ( indx0 >= regions.GetCount() )
    indx0 = LAST_INSTANCE;
    
  gvtxstb(propname,propnames,ID_SIZE);
  regions.Add(indx0,propnames);                      CTXCERR
  regions.Save();                                    CTXCERR

  SetActionResult(regions.GPH("sys_ident")->GetString());

RECOVER
  SetActionResult("");
  term = YES;
ENDSEQ
  return(term);
}
Beispiel #26
0
std::vector<bool>
EefcFlash::getLockRegions()
{
    std::vector<bool> regions(_lockRegions);
    uint32_t frr;
    uint32_t bit;

    waitFSR();
    for (uint32_t region = 0; region < _lockRegions; region++)
    {
        if (_planes == 2 && region >= _lockRegions / 2)
        {
            bit = region - _lockRegions / 2;
            writeFCR1(EEFC_FCMD_GLB, 0);
            waitFSR();
            frr = readFRR1();
            while (bit >= 32)
            {
                frr = readFRR1();
                bit -= 32;
            }
            regions[region] = (frr & (1 << bit)) != 0;
        }
        else
        {
            bit = region;
            writeFCR0(EEFC_FCMD_GLB, 0);
            waitFSR();
            frr = readFRR0();
            while (bit >= 32)
            {
                frr = readFRR0();
                bit -= 32;
            }
            regions[region] = (frr & (1 << bit)) != 0;
        }
    }

    return regions;
}
Beispiel #27
0
void MythUIEditBar::Display(void)
{
    QRect keeparea = QRect();
    QRect cutarea  = QRect();
    MythUIType *position    = GetChild("position");
    MythUIType *keep        = GetChild("keep");
    MythUIType *cut         = GetChild("cut");
    MythUIType *cuttoleft   = GetChild("cuttoleft");
    MythUIType *cuttoright  = GetChild("cuttoright");
    MythUIType *keeptoleft  = GetChild("keeptoleft");
    MythUIType *keeptoright = GetChild("keeptoright");

    if (position)
        position->SetVisible(false);

    if (keep)
    {
        keep->SetVisible(false);
        keeparea = keep->GetArea();
    }

    if (cut)
    {
        cut->SetVisible(false);
        cutarea = cut->GetArea();
    }

    if (cuttoleft)
        cuttoleft->SetVisible(false);

    if (cuttoright)
        cuttoright->SetVisible(false);

    if (keeptoleft)
        keeptoleft->SetVisible(false);

    if (keeptoright)
        keeptoright->SetVisible(false);

    if (position && keeparea.isValid())
    {
        int offset = position->GetArea().width() / 2;
        int newx   = (int)(((float)keeparea.width() * m_editPosition) + 0.5f);
        int newy   = position->GetArea().top();
        position->SetPosition(newx - offset, newy);
        position->SetVisible(true);
    }

    ClearImages();

    if (!m_regions.size())
    {
        if (keep)
            keep->SetVisible(true);

        return;
    }

    MythUIShape *barshape   = dynamic_cast<MythUIShape *>(cut);
    MythUIImage *barimage   = dynamic_cast<MythUIImage *>(cut);
    MythUIShape *leftshape  = dynamic_cast<MythUIShape *>(cuttoleft);
    MythUIImage *leftimage  = dynamic_cast<MythUIImage *>(cuttoleft);
    MythUIShape *rightshape = dynamic_cast<MythUIShape *>(cuttoright);
    MythUIImage *rightimage = dynamic_cast<MythUIImage *>(cuttoright);

    QListIterator<QPair<float, float> > regions(m_regions);

    while (regions.hasNext() && cutarea.isValid())
    {
        QPair<float, float> region = regions.next();
        int left  = (int)((region.first * cutarea.width()) + 0.5f);
        int right = (int)((region.second * cutarea.width()) + 0.5f);

        if (left >= right)
            right = left + 1;

        if (cut)
        {
            AddBar(barshape, barimage, QRect(left, cutarea.top(), right - left,
                                             cutarea.height()));
        }

        if (cuttoleft && (region.second < 1.0f))
            AddMark(leftshape, leftimage, right, true);

        if (cuttoright && (region.first > 0.0f))
            AddMark(rightshape, rightimage, left, false);
    }

    CalcInverseRegions();

    barshape   = dynamic_cast<MythUIShape *>(keep);
    barimage   = dynamic_cast<MythUIImage *>(keep);
    leftshape  = dynamic_cast<MythUIShape *>(keeptoleft);
    leftimage  = dynamic_cast<MythUIImage *>(keeptoleft);
    rightshape = dynamic_cast<MythUIShape *>(keeptoright);
    rightimage = dynamic_cast<MythUIImage *>(keeptoright);

    QListIterator<QPair<float, float> > regions2(m_invregions);

    while (regions2.hasNext() && keeparea.isValid())
    {
        QPair<float, float> region = regions2.next();
        int left  = (int)((region.first * keeparea.width()) + 0.5f);
        int right = (int)((region.second * keeparea.width()) + 0.5f);

        if (left >= right)
            right = left + 1;

        if (keep)
        {
            AddBar(barshape, barimage, QRect(left, keeparea.top(), right - left,
                                             keeparea.height()));
        }

        if (keeptoleft && (region.second < 1.0f))
            AddMark(leftshape, leftimage, right, true);

        if (keeptoright && (region.first > 0.0f))
            AddMark(rightshape, rightimage, left, false);
    }

    if (position)
        position->MoveToTop();
}
Beispiel #28
0
int
TriMesh::mesh(double alpha, const ID& rtags2, const ID& rtags)
{
    // get all regions
    int numregions = rtags.Size()+rtags2.Size();
    int numpoints = 0;
    std::vector<MeshRegion*> regions(numregions);
    for(int i=0; i<rtags.Size(); i++) {
	MeshRegion* region = theDomain->getRegion(rtags(i));
	if(region == 0) {
	    opserr<<"WARNING: region "<<rtags(i)<<" is not defined\n";
	    return -1;
	}
	numpoints += region->getNodes().Size();
	regions[i] = region;
    }
    for(int i=0; i<rtags2.Size(); i++) {
	MeshRegion* region = theDomain->getRegion(rtags2(i));
	if(region == 0) {
	    opserr<<"WARNING: region "<<rtags2(i)<<" is not defined\n";
	    return -1;
	}
	numpoints += region->getNodes().Size();
	regions[i+rtags.Size()] = region;

	// remove elements
	const ID& eles = region->getExtraEles();
	for (int j=0; j<eles.Size(); j++) {
	    Element* ele = theDomain->removeElement(eles(j));
	    if (ele != 0) {
		delete ele;
	    }
	}

    }

    // get all points
    ID ptreg(0,numpoints), ptnode(0,numpoints);
    for(int i=0; i<numregions; i++) {
	const ID& nodes = regions[i]->getNodes();
	for(int j=0; j<nodes.Size(); j++) {
	    int index = ptreg.Size();
	    ptreg[index] = i;
	    ptnode[index] = nodes(j);
	}
    }

    // calling mesh generator
    TriangleMeshGenerator gen;
    for(int i=0; i<ptnode.Size(); i++) {
	// get node
	Node* theNode = theDomain->getNode(ptnode(i));
	if(theNode == 0) {
	    opserr<<"WARNING: node "<<ptnode(i)<<" is not defined\n";
	    return -1;
	}
	const Vector& crds = theNode->getCrds();
	const Vector& disp = theNode->getTrialDisp();
	if(crds.Size() < 2 || disp.Size() < 2) {
	    opserr<<"WARNING: ndm < 2 or ndf < 2\n";
	    return -1;
	}
	
	// add point
	gen.addPoint(crds(0)+disp(0), crds(1)+disp(1));
    }

    // meshing
    gen.remesh(alpha);

    // get elenodes
    std::vector<ID> regelenodes(rtags2.Size());
    for(int i=0; i<gen.getNumTriangles(); i++) {
	int p1,p2,p3;
	gen.getTriangle(i,p1,p2,p3);

	// if all connected to fixed regions
	int numfix = rtags.Size();
	if(ptreg(p1)<numfix && ptreg(p2)<numfix && ptreg(p3)<numfix) {
	    continue;
	}
	
	// which region it belongs to
	int reg = ptreg(p1);
	if(reg<numfix || (reg>ptreg(p2) && ptreg(p2)>=numfix)) reg = ptreg(p2);
	if(reg<numfix || (reg>ptreg(p3) && ptreg(p3)>=numfix)) reg = ptreg(p3);
	reg -= numfix;

	// elenodes
	int index = regelenodes[reg].Size();
	regelenodes[reg][index++] = ptnode(p1);
	regelenodes[reg][index++] = ptnode(p2);
	regelenodes[reg][index++] = ptnode(p3);
    }

    // all elenodes
    ID allelenodes;
    for(int i=0; i<(int)regelenodes.size(); i++) {
	int num = allelenodes.Size();
	int num1 = regelenodes[i].Size();
	allelenodes.resize(num+num1);
	for (int j=0; j<num1; j++) {
	    allelenodes(num+j) = regelenodes[i](j);
	}
    }

    // create elements
    std::string eletype = OPS_GetString();
    ID eletags;
    if (eletype=="PFEMElement2D") {
	if (OPS_PFEMElement2D(*theDomain,allelenodes,eletags) < 0) {
	    return -1;
	}
    } else if (eletype=="PFEMElement2DQuasi") {
	if (OPS_PFEMElement2DCompressible(*theDomain,allelenodes,eletags) < 0) {
	    return -1;
	}
    } else if (eletype=="PFEMElement2DBubble") {
	if (OPS_PFEMElement2DBubble(*theDomain,allelenodes,eletags) < 0) {
	    return -1;
	}

    }  else if (eletype=="tri31") {
	if (OPS_Tri31(*theDomain,allelenodes,eletags) < 0) {
	    return -1;
	}

    } else {
	opserr<<"WARNING: element "<<eletype.c_str()<<" can't be used for tri mesh at this time\n";
	return -1;
    }

    // add to region
    int num = 0;

    for(int i=rtags.Size(); i<numregions; i++) {
	int num1 = regelenodes[i-rtags.Size()].Size()/3;
	ID eletag(num1);
	for (int j=0; j<num1; j++) {
	    eletag(j) = eletags(num+j);
	}
	num += num1;
	regions[i]->setExtraEles(eletag);
    }
    return 0;
}
Foam::binaryOperationSearchableSurface::binaryOperationSearchableSurface
(
    const IOobject& io,
    const dictionary& dict
)
:
    searchableSurface(io),
    aName_(dict.lookupOrDefault<word>("aName","A")),
    bName_(dict.lookupOrDefault<word>("bName","B")),
    a_(
        searchableSurface::New
        (
            word(dict.subDict("a").lookup("type")),
            IOobject(
                name()+"_"+word(dict.lookup("type"))+"_"+aName_,
                io.instance(),
                io.db(),
                io.readOpt(),
                io.writeOpt()
            ),
            dict.subDict("a")
        )
    ),
    b_(
        searchableSurface::New
        (
            word(dict.subDict("b").lookup("type")),
            IOobject(
                name()+"_"+word(dict.lookup("type"))+"_"+bName_,
                io.instance(),
                io.db(),
                io.readOpt(),
                io.writeOpt()
            ),
            dict.subDict("b")
        )
    ),
    nrARegions_(
        a().regions().size()
    ),
    nrBRegions_(
        b().regions().size()
    )
{
    if(aName_==bName_) {
        FatalErrorIn("binaryOperationSearchableSurface::binaryOperationSearchableSurface")
            << "'aName' and 'bName' have the same value " << aName_
                << " for " << name()
                << endl
                << exit(FatalError);
    }
    if(regions().size()!=size()) {
        FatalErrorIn("binaryOperationSearchableSurface::binaryOperationSearchableSurface")
            << "Number of regions " << regions().size() << " not equal to size "
                << size() << nl << "Regions: " << regions()
                << endl
                << exit(FatalError);

    }

#ifdef FOAM_SEARCHABLE_SURF_HAS_BOUND_METHOD
    pointField pts(4);
    pts[0]=a().bounds().min();
    pts[1]=a().bounds().max();
    pts[2]=b().bounds().min();
    pts[3]=b().bounds().max();
    bounds()=boundBox(pts);
#endif
}
Beispiel #30
0
bool OCRTess::detectAndRecog() {
    UMat grey = UMat::zeros(this->img.rows + 2, this->img.cols + 2, CV_8UC1);
    cvtColor(this->img.clone(), grey, COLOR_RGB2GRAY);

    vector<UMat> channels;
    channels.clear();
    channels.push_back(grey);
    Mat m = 255 - grey.getMat(ACCESS_READ | ACCESS_WRITE);
    channels.push_back(m.getUMat(ACCESS_READ));

    vector<vector<ERStat>> regions(2);
    regions[0].clear();
    regions[1].clear();

    switch (this->REGION) {
        case REG_CSER: {
            parallel_for_(Range(0, (int) channels.size()), Parallel_extractCSER(channels, regions, this->erf1, this->erf2));
            break;
        }
        case REG_MSER: {
            vector<vector<Point> > contours;
            vector<Rect> bboxes;
            Ptr<MSER> mser = MSER::create(21, (int) (0.00002 * grey.cols * grey.rows), (int) (0.05 * grey.cols * grey.rows), 1, 0.7);
            mser->detectRegions(grey, contours, bboxes);
            if (contours.size() > 0)
                MSERsToERStats(grey, contours, regions);
            break;
        }
        default: {
            break;
        }
    }

    /*Text Recognition (OCR)*/
    vector<vector<Vec2i> > nm_region_groups;
    vector<Rect> nm_boxes;
    switch (this->GROUP) {
        case 0:
            erGrouping(this->img, channels, regions, nm_region_groups, nm_boxes, ERGROUPING_ORIENTATION_HORIZ);
            break;
        case 1:
        default:
            erGrouping(this->img, channels, regions, nm_region_groups, nm_boxes, ERGROUPING_ORIENTATION_ANY, DIR + TR_GRP, 0.5);
            break;
    }

    if (!nm_boxes.size() || nm_boxes.size() > 1) return false;

    vector<string> words_detection;
    float min_confidence1 = 51.f, min_confidence2 = 60.f;

    vector<UMat> detections;
    for (int i = 0; i < (int) nm_boxes.size(); i++) {
//        rectangle(this->out, nm_boxes[i].tl(), nm_boxes[i].br(), Scalar(255, 255, 0), 3);
        UMat group_img = UMat::zeros(this->img.rows + 2, this->img.cols + 2, CV_8UC1);
        er_draw(channels, regions, nm_region_groups[i], group_img);
        group_img = group_img(nm_boxes[i]);
        copyMakeBorder(group_img.clone(), group_img, 15, 15, 15, 15, BORDER_CONSTANT, Scalar(0));
        detections.push_back(group_img);
    }
    vector<string> outputs((int) detections.size());
    vector<vector<Rect> > boxes((int) detections.size());
    vector<vector<string> > words((int) detections.size());
    vector<vector<float> > confidences((int) detections.size());

    if (!detections.size() || detections.size() > 1) return false;

    for (int i = 0; i < (int) detections.size(); i = i + this->num) {
        Range r;
        if (i + this->num <= (int) detections.size()) r = Range(i, i + this->num);
        else r = Range(i, (int) detections.size());
        parallel_for_(r, Parallel_OCR<OCRTesseract>(detections, outputs, boxes, words, confidences, this->ocrs));
    }

    for (int i = 0; i < (int) detections.size(); i++) {
        outputs[i].erase(remove(outputs[i].begin(), outputs[i].end(), '\n'), outputs[i].end());
        if (outputs[i].size() < 3) {
            continue;
        }
        for (int j = 0; j < (int) boxes[i].size(); j++) {
            boxes[i][j].x += nm_boxes[i].x - 15;
            boxes[i][j].y += nm_boxes[i].y - 15;
            if ((words[i][j].size() < 2) || (confidences[i][j] < min_confidence1) ||
                ((words[i][j].size() == 2) && (words[i][j][0] == words[i][j][1])) ||
                ((words[i][j].size() < 4) && (confidences[i][j] < min_confidence2)) ||
                isRepetitive(words[i][j]))
                continue;
            words_detection.push_back(words[i][j]);
//            rectangle(this->out, boxes[i][j].tl(), boxes[i][j].br(), Scalar(255, 0, 255), 3);
//            Size word_size = getTextSize(words[i][j], FONT_HERSHEY_SIMPLEX, (double) scale_font, (int) (3 * scale_font), NULL);
//            rectangle(this->out, boxes[i][j].tl() - Point(3, word_size.height + 3), boxes[i][j].tl() + Point(word_size.width, 0), Scalar(255, 0, 255), -1);
//            putText(this->out, words[i][j], boxes[i][j].tl() - Point(1, 1), FONT_HERSHEY_SIMPLEX, scale_font, Scalar(255, 255, 255), (int) (3 * scale_font));
        }
    }

    if (!words_detection.size() || words_detection.size() > 1) return false;
    return (words_detection[0].compare(WORD) == 0);
}