// Listing 4
// Listing 5 code/ch17
int handle_child (void)
{
  ACE_TRACE (ACE_TEXT ("::handle_child"));

  ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, coordMutex, -1);

  ALLOCATOR * shmem_allocator = 0;
  ACE_MMAP_Memory_Pool_Options options
    (ACE_DEFAULT_BASE_ADDR,
     ACE_MMAP_Memory_Pool_Options::ALWAYS_FIXED);

  ACE_NEW_RETURN (shmem_allocator,
                  ALLOCATOR (BACKING_STORE,
                             BACKING_STORE,
                             &options),
                  -1);

  MAP *map = smap (shmem_allocator);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%P|%t) Map has %d entries\n"),
              map->current_size ()));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("In child, map is located at %@\n"),
              map));

  processRecords (map, shmem_allocator);
  shmem_allocator->sync ();
  delete shmem_allocator;

  return 0;
}
Esempio n. 2
0
CVBitmap<ShadowInfo> FastVoxelView::getShadowMap()
{
  CVBitmap<ShadowInfo> smap(w,2*w,w*w);

#ifdef CVOXEL

  std::map<Pos2D,std::pair<int,Voxel*> >::iterator i=shadowSpace.mViewSpace.begin();

  for(;i!=shadowSpace.mViewSpace.end();i++)
    {
      Pos3D p=i->second.second->pos;
      Pos2D viewPos=projectView(p);

      bool visible=false;

      if(viewSpace.mViewSpace[viewPos].second)
        if(viewSpace.mViewSpace[viewPos].second->pos==p)
          visible=true;

      //      if(i->first.y<0)
      //  cdebug(p);
      smap.set(i->first,ShadowInfo(i->second.first,visible,viewPos));

      //      sge_PutPixel(getScreen().surface(),i->first.x+400,i->first.y,color);

    }
#endif
  //    SDL_Flip(getScreen().surface());
  //  SDL_Delay(20000);


  return smap;
}
Esempio n. 3
0
    void run ()
    {
        testcase ("add/traverse");

        beast::manual_clock <std::chrono::steady_clock> clock;  // manual advance clock
        beast::journal const j;                            // debug journal
        
        fullbelowcache fullbelowcache ("test.full_below", clock);
        treenodecache treenodecache ("test.tree_node_cache", 65536, 60, clock, j);
        nodestore::dummyscheduler scheduler;
        auto db = nodestore::manager::instance().make_database (
            "test", scheduler, j, 0, parsedelimitedkeyvaluestring("type=memory|path=shamap_test"));

        // h3 and h4 differ only in the leaf, same terminal node (level 19)
        uint256 h1, h2, h3, h4, h5;
        h1.sethex ("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
        h2.sethex ("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
        h3.sethex ("b92891fe4ef6cee585fdc6fda1e09eb4d386363158ec3321b8123e5a772c6ca8");
        h4.sethex ("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
        h5.sethex ("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");

        shamap smap (smtfree, fullbelowcache, treenodecache,
            *db, handler(), beast::journal());
        shamapitem i1 (h1, inttovuc (1)), i2 (h2, inttovuc (2)), i3 (h3, inttovuc (3)), i4 (h4, inttovuc (4)), i5 (h5, inttovuc (5));
        unexpected (!smap.additem (i2, true, false), "no add");
        unexpected (!smap.additem (i1, true, false), "no add");

        shamapitem::pointer i;
        i = smap.peekfirstitem ();
        unexpected (!i || (*i != i1), "bad traverse");
        i = smap.peeknextitem (i->gettag ());
        unexpected (!i || (*i != i2), "bad traverse");
        i = smap.peeknextitem (i->gettag ());
        unexpected (i, "bad traverse");
        smap.additem (i4, true, false);
        smap.delitem (i2.gettag ());
        smap.additem (i3, true, false);
        i = smap.peekfirstitem ();
        unexpected (!i || (*i != i1), "bad traverse");
        i = smap.peeknextitem (i->gettag ());
        unexpected (!i || (*i != i3), "bad traverse");
        i = smap.peeknextitem (i->gettag ());
        unexpected (!i || (*i != i4), "bad traverse");
        i = smap.peeknextitem (i->gettag ());
        unexpected (i, "bad traverse");

        testcase ("snapshot");
        uint256 maphash = smap.gethash ();
        shamap::pointer map2 = smap.snapshot (false);
        unexpected (smap.gethash () != maphash, "bad snapshot");
        unexpected (map2->gethash () != maphash, "bad snapshot");
        unexpected (!smap.delitem (smap.peekfirstitem ()->gettag ()), "bad mod");
        unexpected (smap.gethash () == maphash, "bad snapshot");
        unexpected (map2->gethash () != maphash, "bad snapshot");
    }
cv::Mat TrackedObjectFeatureMap::compute(int frame) {

    cv::Mat img;
    for(size_t i = 0 ; i < m_optFlow.size() ; ++i) {
        if(m_optFlow[i].frameNumber == frame) {
            img = m_optFlow[i].color;
        }
    }


    cv::Mat smap(img.size(), CV_32FC1, cv::Scalar(0.f));

    
    return smap;
}
Esempio n. 5
0
int c_elegans::dxdt(ptr_passer x,  ptr_passer dx, double dt){
    has_gone=true;
    double* restr v = x;
    double* restr dv = dx;
    double* restr ds = dv+dim_v;
    double* restr s = v+dim_v;
    //map eigen arrays over input pointers
    Map<Array<double, dim_v, 1>> vmap(v);
    Map<Array<double, dim_v, 1>> dvmap(dv);
    Map<Array<double, dim_v, 1>> smap(s);
    Map<Array<double, dim_v, 1>> dsmap(ds);
    //calculations from matlab file
    sig = 1.0 / (1.0 + (-1*beta*(vmap-vmean)).exp());
    dsmap = ar*(sig * (1.0-smap)) - ad*smap;
    /* Iohm = (memG*(vmap - memV));
       Ielec = (gelec*laplacian*vmap.matrix()).array();
       Ichem = (gchem *
       (vmap*(AEchem_trans*smap.matrix()).array() 
       - (AEchem_trans*(smap*Echem).matrix()).array()));
       dvmap = (-1.0/tau)*(Iohm + Ielec + Ichem);*/
    dvmap = (-1.0/tau)*(
            (memG*(vmap - memV)) +
            (gchem * (vmap*(AEchem_trans*smap.matrix()).array() 
                      - (AEchem_trans*(smap*Echem).matrix()).array())) +
            (gelec*laplacian*vmap.matrix()).array()
            );
    //current injection-for now is hard coded below, inj_nodes is empty here
    for(auto s : inj_nodes){
        dv[s] += (-1.0/tau)*cur_inj;
    }
    double amp = 2e4;
    dv[276]+= (1.0/tau)*amp;
    dv[278]+= (1.0/tau)*amp;

    for(auto val : abl_neur){
        dv[val] = 0;
        ds[val] = 0;
    }
    return 0;
}
Esempio n. 6
0
TEST(FixedSet, assign_operator) {
  {
    FixedMap<size_t, size_t, kMax> fmap;
    fmap = {{0ul, 0ul}, {1ul, 1ul}};
  }
  {
    FixedMap<size_t, size_t, kMax> fmap(std::begin(vec), std::end(vec));
    FixedMap<size_t, size_t, kMax> fmap1;
    fmap1 = fmap;
  }
  {
    FixedMap<size_t, size_t, kMax> fmap;
    fmap = FixedMap<size_t, size_t, kMax>(std::begin(vec), std::end(vec));
  }
  {
    FixedMap<size_t, size_t, kMax> fmap;
    std::map<size_t, size_t> smap(std::begin(vec), std::end(vec));
    fmap = smap;
  }
  {
    FixedMap<size_t, size_t, kMax> fmap;
    fmap = std::map<size_t, size_t>(std::begin(vec), std::end(vec));
  }
}
Esempio n. 7
0
void
SlamGMapping::updateMap(const sensor_msgs::LaserScan& scan)
{
  boost::mutex::scoped_lock map_lock (map_mutex_);
  GMapping::ScanMatcher matcher;
  double* laser_angles = new double[scan.ranges.size()];
  double theta = angle_min_;
  for(unsigned int i=0; i<scan.ranges.size(); i++)
  {
    if (gsp_laser_angle_increment_ < 0)
        laser_angles[scan.ranges.size()-i-1]=theta;
    else
        laser_angles[i]=theta;
    theta += gsp_laser_angle_increment_;
  }

  matcher.setLaserParameters(scan.ranges.size(), laser_angles,
                             gsp_laser_->getPose());

  delete[] laser_angles;
  matcher.setlaserMaxRange(maxRange_);
  matcher.setusableRange(maxUrange_);
  matcher.setgenerateMap(true);

  GMapping::GridSlamProcessor::Particle best =
          gsp_->getParticles()[gsp_->getBestParticleIndex()];
  std_msgs::Float64 entropy;
  entropy.data = computePoseEntropy();
  if(entropy.data > 0.0)
    entropy_publisher_.publish(entropy);

  if(!got_map_) {
    map_.map.info.resolution = delta_;
    map_.map.info.origin.position.x = 0.0;
    map_.map.info.origin.position.y = 0.0;
    map_.map.info.origin.position.z = 0.0;
    map_.map.info.origin.orientation.x = 0.0;
    map_.map.info.origin.orientation.y = 0.0;
    map_.map.info.origin.orientation.z = 0.0;
    map_.map.info.origin.orientation.w = 1.0;
  } 

  GMapping::Point center;
  center.x=(xmin_ + xmax_) / 2.0;
  center.y=(ymin_ + ymax_) / 2.0;

  GMapping::ScanMatcherMap smap(center, xmin_, ymin_, xmax_, ymax_, 
                                delta_);

  ROS_DEBUG("Trajectory tree:");
  for(GMapping::GridSlamProcessor::TNode* n = best.node;
      n;
      n = n->parent)
  {
    ROS_DEBUG("  %.3f %.3f %.3f",
              n->pose.x,
              n->pose.y,
              n->pose.theta);
    if(!n->reading)
    {
      ROS_DEBUG("Reading is NULL");
      continue;
    }
    matcher.invalidateActiveArea();
    matcher.computeActiveArea(smap, n->pose, &((*n->reading)[0]));
    matcher.registerScan(smap, n->pose, &((*n->reading)[0]));
  }

  // the map may have expanded, so resize ros message as well
  if(map_.map.info.width != (unsigned int) smap.getMapSizeX() || map_.map.info.height != (unsigned int) smap.getMapSizeY()) {

    // NOTE: The results of ScanMatcherMap::getSize() are different from the parameters given to the constructor
    //       so we must obtain the bounding box in a different way
    GMapping::Point wmin = smap.map2world(GMapping::IntPoint(0, 0));
    GMapping::Point wmax = smap.map2world(GMapping::IntPoint(smap.getMapSizeX(), smap.getMapSizeY()));
    xmin_ = wmin.x; ymin_ = wmin.y;
    xmax_ = wmax.x; ymax_ = wmax.y;
    
    ROS_DEBUG("map size is now %dx%d pixels (%f,%f)-(%f, %f)", smap.getMapSizeX(), smap.getMapSizeY(),
              xmin_, ymin_, xmax_, ymax_);

    map_.map.info.width = smap.getMapSizeX();
    map_.map.info.height = smap.getMapSizeY();
    map_.map.info.origin.position.x = xmin_;
    map_.map.info.origin.position.y = ymin_;
    map_.map.data.resize(map_.map.info.width * map_.map.info.height);

    ROS_DEBUG("map origin: (%f, %f)", map_.map.info.origin.position.x, map_.map.info.origin.position.y);
  }

  for(int x=0; x < smap.getMapSizeX(); x++)
  {
    for(int y=0; y < smap.getMapSizeY(); y++)
    {
      /// @todo Sort out the unknown vs. free vs. obstacle thresholding
      GMapping::IntPoint p(x, y);
      double occ=smap.cell(p);
      assert(occ <= 1.0);
      if(occ < 0)
        map_.map.data[MAP_IDX(map_.map.info.width, x, y)] = -1;
      else if(occ > occ_thresh_)
      {
        //map_.map.data[MAP_IDX(map_.map.info.width, x, y)] = (int)round(occ*100.0);
        map_.map.data[MAP_IDX(map_.map.info.width, x, y)] = 100;
      }
      else
        map_.map.data[MAP_IDX(map_.map.info.width, x, y)] = 0;
    }
  }
  got_map_ = true;

  //make sure to set the header information on the map
  map_.map.header.stamp = ros::Time::now();
  map_.map.header.frame_id = tf_.resolve( map_frame_ );

  sst_.publish(map_.map);
  sstm_.publish(map_.map.info);
}
cv::Mat PedestrianFeatureMap::compute(int frame) {

    cv::Mat img = m_frame.color;

    std::vector<cv::Rect> found, found_filtered;
    std::vector<double> weights;
    m_HOG.detectMultiScale(img, found, weights, 0.7, cv::Size(8,8), cv::Size(32,32), 1.05, 2);

    for (size_t i = 0 ; i < found.size() ; i++) {
        cv::Rect r = found[i];

        found_filtered.push_back(r);
    }


    cv::Mat smap(img.size(), CV_32FC1, cv::Scalar(0.f));


    for (size_t i = 0 ; i < found_filtered.size() ; i++) {
        cv::Rect r2 = found_filtered[i];
        r2.x += roundl(r2.width*0.1);
        r2.width = roundl(r2.width*0.8);
        r2.y += roundl(r2.height*0.06);
        r2.height = roundl(r2.height*0.9);

        // show bounding box
        // cv::rectangle(img, r2.tl(), r2.br(), cv::Scalar(0,255*weights[i],0), 2);

        cv::rectangle(smap, r2.tl(), r2.br(), cv::Scalar(1), cv::FILLED);
	}
    


    if(m_FaceCascadeEnabled) {
        cv::Mat gray;
        cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY);
        cv::resize(gray, gray, cv::Size(1400, 788));
        std::vector<cv::Rect> faceFeatures;
        if (m_FaceCascadeEnabled)
            m_face_cascade.detectMultiScale(gray, faceFeatures, 1.1, 2, 0 | cv::CASCADE_SCALE_IMAGE, cv::Size(15, 15));
        
        float scalingFactorX = static_cast<float>(img.cols) / 1400.f;
        float scalingFactorY = static_cast<float>(img.rows) / 788.f;

        for (size_t i = 0; i < faceFeatures.size(); ++i) {
            cv::Rect r2 = faceFeatures[i];
            r2.x *= scalingFactorX;
            r2.y *= scalingFactorY;
            r2.width *= scalingFactorX;
            r2.height *= scalingFactorY;

            r2.x += roundl(r2.width*0.1);
            r2.width = roundl(r2.width*0.8);
            r2.y += roundl(r2.height*0.06);
            r2.height = roundl(r2.height*0.9);

            cv::rectangle(smap, r2.tl(), r2.br(), cv::Scalar(1), cv::FILLED);
            
        }
    }
    
    return smap;
}
// Listing 5
// Listing 3 code/ch17
int handle_parent (char *cmdLine)
{
  ACE_TRACE (ACE_TEXT ("::handle_parent"));

  ALLOCATOR * shmem_allocator = 0;
  ACE_MMAP_Memory_Pool_Options options
    (ACE_DEFAULT_BASE_ADDR,
     ACE_MMAP_Memory_Pool_Options::ALWAYS_FIXED);

  ACE_NEW_RETURN
    (shmem_allocator,
     ALLOCATOR (BACKING_STORE, BACKING_STORE, &options),
     -1);

  MAP *map = smap (shmem_allocator);

  ACE_Process processa, processb;
  ACE_Process_Options poptions;
  poptions.command_line("%s a", cmdLine);
  {
    ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon,
                      coordMutex, -1);
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%P|%t) Map has %d entries\n"),
                map->current_size ()));
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("In parent, map is located at %@\n"),
                map));

    // Then have the child show and eat them up.
    processa.spawn (poptions);

    // First append a few records.
    addRecords (map, shmem_allocator);
  }


  {
    ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon,
                      coordMutex, -1);

    // Add a few more records..
    addRecords (map, shmem_allocator);

    // Let's see what's left.
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%P|%t) Parent finished adding, ")
                ACE_TEXT ("map has %d entries\n"),
                map->current_size ()));

    // Have another child try to eat them up.
    processb.spawn (poptions);
  }

  processa.wait ();
  processb.wait ();

  // No processes are left and we don't want to keep the data
  // around anymore; it's now safe to remove it.
  // !!This will remove the backing store.!!
  shmem_allocator->remove ();
  delete shmem_allocator;
  return 0;
}
Esempio n. 10
0
bool ResourceLoader::loadAnimData(AnimationData& aData, const pugi::xml_document &animXmlDoc, const SpriteSheet* sheet)
{
	pugi::xml_node animationsXml = animXmlDoc.first_child();
	aData.sheetName = animationsXml.attribute("spriteSheet").as_string();
	// Iterate through all animations
	for (auto& animXml : animationsXml.children()) {
		string name = animXml.attribute("name").value();
		int frameNum = (int)std::distance(animXml.children().begin(), animXml.children().end());
		AnimationData::anim& a = aData.animations.emplace(make_pair(name, AnimationData::anim(frameNum))).first->second;
		a.name = name;
		a.loops = animXml.attribute("loops").as_uint();
		// Iterate through cells in the current animation
		int cellIndex = 0;
		for (auto& cellXml : animXml.children()) {
			AnimationData::frame& f = a.frames[cellIndex];
			f.delay = max(1, cellXml.attribute("delay").as_int() * 30900);
			std::multimap<int, AnimationData::sprite> zList;
			// Iterate through sprites in the current cell
			for (auto& spriteXml : cellXml.children()) {
				int z = spriteXml.attribute("z").as_int();
				std::pair<int, AnimationData::sprite> smap(z, {});
				auto& s = smap.second;
				string spriteName = spriteXml.attribute("name").as_string();
				const auto& it = sheet->sprites.find(spriteName);
				if (it == sheet->sprites.end()) {
					// Couldn't find the requested sprite!
					std::cerr << "ERROR: couldn't find sprite \"" << spriteName << "\" in sheet \"" << sheet->imageName << "\"\n";
					return false;
				}
				// Get draw rect from sprite object, and offset data from anim file
				s.draw = { it->second.left, it->second.top, it->second.width, it->second.height };
				s.offset.x = spriteXml.attribute("x").as_float() - (int)(s.draw.width / 2.0f);
				s.offset.y = spriteXml.attribute("y").as_float() - (int)(s.draw.height / 2.0f);
				// Does it need to be flipped?
				if (spriteXml.attribute("flipH").as_bool())
				{
					s.flipH = true;
				}
				if (spriteXml.attribute("flipV").as_bool())
				{
					s.flipV = true;
				}
				// Use an associative container to keep the sprites in this frame in z-order
				zList.insert(smap);
			}
			// Create our vertex array from the collected rect data
			f.sprites.resize(zList.size() * 4);
			int i = 0;
			for (auto z : zList) {
				auto& s = z.second;
				f.sprites[i].texCoords = { s.draw.left, s.draw.top };
				f.sprites[i].position = { s.offset.x, s.offset.y };
				f.sprites[i + 1].texCoords = { s.draw.left + s.draw.width, s.draw.top };
				f.sprites[i + 1].position = { s.draw.width + s.offset.x, s.offset.y };
				f.sprites[i + 2].texCoords = { s.draw.left + s.draw.width, s.draw.top + s.draw.height };
				f.sprites[i + 2].position = { s.draw.width + s.offset.x, s.draw.height + s.offset.y };
				f.sprites[i + 3].texCoords = { s.draw.left, s.draw.top + s.draw.height };
				f.sprites[i + 3].position = { s.offset.x, s.draw.height + s.offset.y };
				if (s.flipH)
				{
					std::swap(f.sprites[i].position, f.sprites[i + 1].position);
					std::swap(f.sprites[i + 2].position, f.sprites[i + 3].position);
				}
				if (s.flipV)
				{
					std::swap(f.sprites[i].position, f.sprites[i + 3].position);
					std::swap(f.sprites[i + 1].position, f.sprites[i + 2].position);
				}
				i += 4;
			}
			cellIndex++;
		}
	}
	return true;
}