Ejemplo n.º 1
0
bool PyrMean::update()
{
  const bool rv = Node::update();
  if (!rv) return false;
  
  cv::Mat in = getImage("in");
  if (in.empty()) return true;

  cv::Mat out_3;

  cv::Mat in_3 = cv::Mat(in.size(), CV_8UC3, cv::Scalar(0));  
  // just calling reshape(4) doesn't do the channel reassignment like this does
  int ch[] = {0,0, 1,1, 2,2};
  cv::mixChannels(&in, 1, &in_3, 1, ch, 3 );

  int max_level = getSignal("max_level");
  if (max_level > 4) { max_level = 4; setSignal("max_level", max_level); }
  if (max_level < 0) { max_level = 0; setSignal("max_level", max_level); }
  
  cv::pyrMeanShiftFiltering(in_3, out_3, 
      getSignal("sp"), getSignal("sr"),
      max_level,
      cv::TermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, getSignal("term"), 5)
      );

  cv::Mat out = cv::Mat(out_3.size(), CV_8UC4, cv::Scalar(0));  
  cv::mixChannels(&out_3, 1, &out, 1, ch, 3 );

  setImage("out", out);

}
Ejemplo n.º 2
0
	void GLXPlatformContext::update()
	{
		XEvent xev;

		while(XCheckMaskEvent(mDisplay, StructureNotifyMask, &xev))
		{
			switch(xev.type)
			{
				case ConfigureNotify:

					if(xev.xconfigure.width != mWidth || xev.xconfigure.height != mHeight)
					{
						mWidth = xev.xconfigure.width;
						mHeight = xev.xconfigure.height;
						std::pair<size_t, size_t> report = std::make_pair(mWidth, mHeight);
						getSignal("WindowResized")->send(report);
					}

					break;

				case ClientMessage:

					if(xev.xclient.data.l[0] == mDeleteMessage)
					{
						getSignal("WindowClosed")->send(xev.xclient.data.l[0]);
					}

					break;
			}
		}
	}
Ejemplo n.º 3
0
			void ScrollView::enableMouseEvents()
			{
				mMouseConnections += getSignal( po::scene::MouseEvent::DOWN_INSIDE ).connect( std::bind( &ScrollView::mouseDownInside, this, ::_1 ) );
				mMouseConnections += getSignal( po::scene::MouseEvent::DRAG ).connect( std::bind( &ScrollView::mouseDrag, this, ::_1 ) );
				mMouseConnections += getSignal( po::scene::MouseEvent::UP ).connect( std::bind( &ScrollView::mouseUp, this, ::_1 ) );

				mMouseEventsEnabled = true;
			}
Ejemplo n.º 4
0
			void ScrollView::enableTouchEvents()
			{
				mTouchConnections += getSignal( po::scene::TouchEvent::BEGAN_INSIDE ).connect( std::bind( &ScrollView::touchBeganInside, this, ::_1 ) );
				mTouchConnections += getSignal( po::scene::TouchEvent::MOVED ).connect( std::bind( &ScrollView::touchMoved, this, ::_1 ) );
				mTouchConnections += getSignal( po::scene::TouchEvent::ENDED ).connect( std::bind( &ScrollView::touchEnded, this, ::_1 ) );

				mTouchEventsEnabled = true;
			}
Ejemplo n.º 5
0
template<typename T> T ofxAlgebraic_<T>::getTri()
{
    float phase = sin(TWO_PI * value * frequency / pointX);
    
    if(phase>0.0){
        return getSignal(fmod(value * (frequency*-1) / pointX, 1.0f) * 4 + 1);
    } else if(phase<0.0){
        return getSignal(fmod(value * frequency / pointX, 1.0f) * 4 - 3.0);
    }
}
Ejemplo n.º 6
0
bool Bezier::update()
{
  //if (!ImageNode::update()) return false;
  if (!Node::update()) return false;

  cv::Mat out = cv::Mat(cv::Size(Config::inst()->im_width, Config::inst()->im_height), MAT_FORMAT_C3);
  out = cv::Scalar(0,0,0);

  std::vector<cv::Point2f> control_points;
  control_points.push_back( cv::Point2f( getSignal("x0"), getSignal("y0") ));
  control_points.push_back( cv::Point2f( getSignal("x1"), getSignal("y1") ));
  control_points.push_back( cv::Point2f( getSignal("x2"), getSignal("y2") ));
  control_points.push_back( cv::Point2f( getSignal("x3"), getSignal("y3") ));
  
  int num = getSignal("num");
  if (num < 2) { num = 2;
    setSignal("num", num);
  }

  std::vector<cv::Point2f> bezier_points;
  getBezier(control_points, bezier_points, num);

  for (int i = 1; i < bezier_points.size(); i++) {
    cv::line(out, bezier_points[i-1], bezier_points[i], cv::Scalar(255, 255, 255), 2, CV_AA ); 
  }

  setImage("out", out);

  return true;
}
Ejemplo n.º 7
0
    void BlackBoardModel::setVariable(Ogre::String const &name, AgentId const &value)
    {
        bool isNew = mVariables.end() == mVariables.find(name);

        mVariables.erase(name);
        mVariables[name] = Ogre::StringConverter::toString(value);

        if(isNew)
            emit(getSignal(PublicSignal::newVariable));
        else
            emit(getSignal(PublicSignal::variableChanged));
    }
Ejemplo n.º 8
0
void MaskingSample::setup() 
{
    ci::app::getWindow()->getSignalKeyUp().connect(std::bind(&MaskingSample::keyUp, this, std::placeholders::_1));
	
	//	Load the mask texture
	ci::gl::TextureRef maskTexture = ci::gl::Texture::create(ci::loadImage(ci::app::loadAsset("circle_mask_blurred.jpg")));
	
	//	Create the mask shape
	//mMask = Shape::create(maskTexture);
    mMask = Shape::createRect(100, 100);
    mMask->setAlignment(Alignment::CENTER_CENTER);
    mMask->setPosition(ci::app::getWindowWidth()/2, ci::app::getWindowHeight()/2);
    ci::app::timeline().apply(&mMask->getRotationAnim(), 0.0f, ci::toRadians(360.0f), 1.0f).loop();
    ci::app::timeline().apply(&mMask->getScaleAnim(), ci::vec2(1.0f, 1.0f), ci::vec2(4.0f, 4.0f), 1.0f).loop().pingPong();
    
	//	Load the image texture
	ci::gl::TextureRef texture = ci::gl::Texture::create(ci::loadImage(ci::app::loadAsset("cat.jpg")));
	
	//	Create the image shape
	mImage = Image::create(texture);
	addChild(mImage);
	
	//	Set the image mask
	setMask(mMask);
	
	//	Connect mouse event
	getSignal(MouseEvent::MOVE).connect(std::bind(&MaskingSample::onMouseMove, this, std::placeholders::_1));
}
Ejemplo n.º 9
0
bool Contour::update()
{
  //if (!ImageNode::update()) return false;
  if (!Node::update()) return false;

  cv::Mat in = getImage("in");
  if (in.empty()) {
    VLOG(2) << name << " in is empty";
    return false;
  }
 
  if (!isDirty(this, 22)) { return true;}
  
  std::vector<std::vector<cv::Point> > contours_orig;
  cv::Mat in8;
  cv::cvtColor(in, in8, CV_RGB2GRAY);
  cv::findContours(in8, contours_orig, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE);

  const float eps = getSignal("epsilon"); // max error of approx
  contours0.resize(contours_orig.size());
  for( size_t k = 0; k < contours_orig.size(); k++ )
    //approxPolyDP(cv::Mat(contours_orig[k]), contours0[k], eps, true);
    approxPolyDP((contours_orig[k]), contours0[k], eps, true);

  cv::Mat out = cv::Mat(Config::inst()->getImSize(), MAT_FORMAT_C3, cv::Scalar(0,0,0,255));

  cv::drawContours( out, contours0, -1, cv::Scalar(255,255,255,255));
                //1, CV_AA, hierarchy, std::abs(_levels) );

  setImage("out", out);

  return true;
}
Ejemplo n.º 10
0
int TileSource::isBlockProvidingPowerTo(int x, int y, int z, int side) {
    int id = getTile(x, y, z).id;
    if(id == 0) return 0;

    int (*getSignal)(Tile*, TileSource*, int, int, int, int) = (int (*)(Tile*, TileSource*, int, int, int, int)) Tile::tiles[id]->vtable[VT_TILE_GETSIGNAL];
    return getSignal(Tile::tiles[id], this, x, y, z, side);
}
Ejemplo n.º 11
0
  bool Output::update()
  {
    if (!ImageNode::update()) return false;
  
    cv::Mat in = getImage("in");
    if (in.empty()) return true;

    if (!ximage) return true;
   
    XWindowAttributes xwAttr;
    Status ret = XGetWindowAttributes( display, win, &xwAttr );
    int screen_w = xwAttr.width;
    int screen_h = xwAttr.height;
    setSignal("disp_w", screen_w);
    setSignal("disp_h", screen_h);

    // TBD is this necessary or does X do it for me if the window is resized?
    cv::Size sz = cv::Size(screen_w, screen_h);
    cv::Mat scaled;
    cv::resize(in, scaled, sz, 0, 0, cv::INTER_NEAREST );
   
    XDestroyImage(ximage);
    ximage = XGetImage(display, DefaultRootWindow(display), 0, 0, screen_w, screen_h, AllPlanes, ZPixmap);

    bm::matToXImage(scaled, ximage, win, *display, *screen);
  
    bool window_decorations_on = getSignal("decor");
    setSignal("decor", window_decorations_on);

    bm::setWindowDecorations(display, win, window_decorations_on);
  }
Ejemplo n.º 12
0
/**
 * Message AppConfig::getMessage(QVector<QString> messageBlock)
 *
 * Takes a block of strings corresponding to one CAN message definition as
 * input and returns a Message struct with all applicable parameters set. This
 * function will throw errors if the input data is missing or malformed.
 *
 * @param messageBlock - The block of strings corresponding to one CAN message
 *     defintion
 * @returns A Message struct with all applicable parameters set, or an empty
 *     Message struct if an error occurred.
 */
Message AppConfig::getMessage(QVector<QString> messageBlock) {
  QString msgDef = messageBlock[0];
  QStringList sections = msgDef.split(" ", QString::SkipEmptyParts);
  if (sections.size() != 5) {
    emit error("Invalid message definition.");
    return Message();
  }

  Message msg;

  bool successful = true;
  msg.id = sections[1].toUInt(&successful);
  if (!successful) {
    emit error(QString("Invalid message ID"));
    return Message();
  }

  msg.dlc = sections[3].toUInt(&successful);
  if (!successful) {
    emit error(QString("Invalid DLC for message with ID: %1").arg(QString::number(msg.id, 16)));
    return Message();
  }

  for (int i = 1; i < messageBlock.size(); i++) {
    Signal sig = getSignal(messageBlock[i]);
    if (!sig.valid()) {
      return Message();
    }
    msg.sigs.push_back(sig);
  }

  return msg;
}
Ejemplo n.º 13
0
int RSSIFilter::getPercentCurvedSignal()
{
    float rawcurved = (getSignal() / _max_quality_signal) * (_upper_scale - _lower_scale) + _lower_scale;

    if(rawcurved < 0.01) return 0;
    if(rawcurved > 0.99) return 100;     
    return (int)((-log((1-rawcurved)/rawcurved) - _scale_min) * 100 / (_scale_max - _scale_min) + 0.5);
}
Ejemplo n.º 14
0
 BSONObj StopMongoProgram( const BSONObj &a ) {
     assert( a.nFields() == 1 || a.nFields() == 2 );
     assert( a.firstElement().isNumber() );
     int port = int( a.firstElement().number() );
     killDb( port, 0, getSignal( a ) );
     cout << "shell: stopped mongo program on port " << port << endl;
     return undefined_;
 }        
Ejemplo n.º 15
0
	void OISSubsystem::_mouseButton(uint button, bool up)
	{
		mButtonStates[button] = up;
		if(!up)
		{
			getSignal(String("released_")+String(mButtons[button]))->fire(
				MessageAny<uint>(button));
			getSignal("mouseReleased")->fire(MessageAny<uint>(button));
		}
		else
		{
			mButtonPresses[button] = true;
			getSignal("mousePressed")->fire(MessageAny<uint>(button));
			getSignal(String("pressed_")+String(mButtons[button]))->fire(
				MessageAny<uint>(button));
		}
	}
Ejemplo n.º 16
0
 BSONObj StopMongoProgramByPid( const BSONObj &a, void* data ) {
     verify( a.nFields() == 1 || a.nFields() == 2 );
     uassert( 15852 , "stopMongoByPid needs a number" , a.firstElement().isNumber() );
     ProcessId pid = ProcessId::fromNative(int( a.firstElement().number() ));
     int code = killDb( 0, pid, getSignal( a ) );
     log() << "shell: stopped mongo program on pid " << pid << endl;
     return BSON( "" << (double)code );
 }
Ejemplo n.º 17
0
int IRDetector::getRangeInCm() 
{
  int range = (int) (500.0/(getSignal()+1)); // +1 to avoid divide-by-zero errors
  if( range < MAX_RANGE )
    return range+1;
  else
    return 0;
}
Ejemplo n.º 18
0
    AgentId AgentManager::newAgent()
    {
        Agent *t = new Agent(getFreeAgentId(), mLevel);
        mAgents.insert(std::pair<AgentId, Agent *>(t->id(), t));
//         Debug::log("new agent with id ")(t->id()).endl();
        SignalManager::instance().emit(getSignal(PublicSignal::agentCreated));
        return t->id();
    }
Ejemplo n.º 19
0
 /** stopMongoProgram(port[, signal]) */
 BSONObj StopMongoProgram( const BSONObj &a, void* data ) {
     assert( a.nFields() == 1 || a.nFields() == 2 );
     uassert( 15853 , "stopMongo needs a number" , a.firstElement().isNumber() );
     int port = int( a.firstElement().number() );
     int code = killDb( port, 0, getSignal( a ) );
     cout << "shell: stopped mongo program on port " << port << endl;
     return BSON( "" << (double)code );
 }
Ejemplo n.º 20
0
 BSONObj StopMongoProgramByPid( const BSONObj &a ) {
     assert( a.nFields() == 1 || a.nFields() == 2 );
     assert( a.firstElement().isNumber() );
     int pid = int( a.firstElement().number() );            
     int code = killDb( 0, pid, getSignal( a ) );
     cout << "shell: stopped mongo program on pid " << pid << endl;
     return BSON( "" << code );
 }
Ejemplo n.º 21
0
 void BlackBoardModel::unsetVariable(Ogre::String const &name)
 {
     bool existed = mVariables.end() != mVariables.find(name);
     
     mVariables.erase(name);
     
     if(existed)
         emit(getSignal(PublicSignal::variableDeleted));
 }
Ejemplo n.º 22
0
 /** stopMongoProgram(port[, signal]) */
 BSONObj StopMongoProgram( const BSONObj &a, void* data ) {
     int nFields = a.nFields();
     verify( nFields >= 1 && nFields <= 3 );
     uassert( 15853 , "stopMongo needs a number" , a.firstElement().isNumber() );
     int port = int( a.firstElement().number() );
     int code = killDb( port, ProcessId::fromNative(0), getSignal( a ), getStopMongodOpts( a ));
     log() << "shell: stopped mongo program on port " << port << endl;
     return BSON( "" << (double)code );
 }
Ejemplo n.º 23
0
/** stopMongoProgram(port[, signal]) */
BSONObj StopMongoProgram(const BSONObj& a, void* data) {
    int nFields = a.nFields();
    uassert(ErrorCodes::FailedToParse, "wrong number of arguments", nFields >= 1 && nFields <= 3);
    uassert(ErrorCodes::BadValue, "stopMongoProgram needs a number", a.firstElement().isNumber());
    int port = int(a.firstElement().number());
    int code = killDb(port, ProcessId::fromNative(0), getSignal(a), getStopMongodOpts(a));
    log() << "shell: stopped mongo program on port " << port;
    return BSON("" << (double)code);
}
Ejemplo n.º 24
0
 void Image::mouseUp()
 {
     if( Visibility::VISIBLE == visibility__ )
     {
         evas_object_hide( image_pressed__ );
         evas_object_show( image__ );
         evas_render( evas_object_evas_get( image__ ) );
         getSignal()->emit();
     }
 }
Ejemplo n.º 25
0
  void OMEMO::publishOwnBundle(int account) {
    Bundle b = getSignal(account)->collectBundle();
    if (!b.isValid()) return;

    QDomDocument doc;
    QDomElement publish = doc.createElement("publish");
    doc.appendChild(publish);

    QDomElement item = doc.createElement("item");
    publish.appendChild(item);

    QDomElement bundle = doc.createElementNS(OMEMO_XMLNS, "bundle");
    item.appendChild(bundle);

    publish.setAttribute("node", bundleNodeName(getSignal(account)->getDeviceId()));

    QDomElement signedPreKey = doc.createElement("signedPreKeyPublic");
    signedPreKey.setAttribute("signedPreKeyId", b.signedPreKeyId);
    setNodeText(signedPreKey, b.signedPreKeyPublic);
    bundle.appendChild(signedPreKey);

    QDomElement signedPreKeySignature = doc.createElement("signedPreKeySignature");
    setNodeText(signedPreKeySignature, b.signedPreKeySignature);
    bundle.appendChild(signedPreKeySignature);

    QDomElement identityKey = doc.createElement("identityKey");
    setNodeText(identityKey, b.identityKeyPublic);
    bundle.appendChild(identityKey);

    QDomElement preKeys = doc.createElement("prekeys");
    bundle.appendChild(preKeys);

    foreach (auto preKey, b.preKeys) {
      QDomElement preKeyPublic = doc.createElement("preKeyPublic");
      preKeyPublic.setAttribute("preKeyId", preKey.first);
      setNodeText(preKeyPublic, preKey.second);
      preKeys.appendChild(preKeyPublic);
    }

    pepPublish(account, doc.toString());
  }
Ejemplo n.º 26
0
void Square::setup()
{
	setAlignment(po::scene::Alignment::CENTER_CENTER);
	
	//	Create and add a shape for the active state
	mActive = Shape::createRect(100, 100);
	mActive->setFillColor(mActiveColor);
	addChild(mActive);
	
	//	Create and add a shape for the selected state
	//	Set the alpha to 0 so we can animate it
	mSelected = Shape::createRect(100, 100);
	mSelected->setFillColor(mSelectedColor);
	addChild(mSelected);
	mSelected->setAlpha(0.f);
	
	//	Connect to mouse events
	getSignal(MouseEvent::DOWN_INSIDE).connect(std::bind(&Square::onMouseEvent, this, std::placeholders::_1));
	getSignal(MouseEvent::UP_INSIDE).connect(std::bind(&Square::onMouseEvent, this, std::placeholders::_1));
	getSignal(MouseEvent::UP).connect(std::bind(&Square::onMouseEvent, this, std::placeholders::_1));
}
//-----------------------------------------------------------------------------
//! @brief Factory method to create the PhotoManager module. This IdType will
//! return a singleton, which is alive as long as a model requires it.
//! @returns a shared pointer to the PhotoManager.
//-----------------------------------------------------------------------------
static std::shared_ptr< IPhotoManager > const createPhotoManager()
{
    auto db( Factory< IDatabaseFacade >::get( "Database" ) );
    auto rh( Factory< IResourceHandler >::get( Slicer::getGroup() ) );
    auto timer( Factory< Timer >::get( "Timer" ) );
    std::shared_ptr< IPhotoManager > photo_mgr( new PhotoManager( db
                                                                , rh
                                                                , 15
                                                                , 10
                                                                , timer->getSignal( Timer::SLIDESHOW ) ) );
    return photo_mgr;
}
Ejemplo n.º 28
0
    //-------------------------------------------------------------------------
    //! @brief Factory method to create a SimpleValue model and assign it to
    //! retrieve the path to the next photo to display.
    //! @returns a shared pointer to the SimpleValue.
    //-------------------------------------------------------------------------
    static std::shared_ptr< IModel > const createPhotoFolder()
    {
        auto photo_mgr = Factory< IPhotoManager >::get( "PhotoManager" );

        std::function< variant() > method( [photo_mgr](){ return photo_mgr->getFolder(); } );

        std::shared_ptr< IModel > model( new SimpleValue( String( "" )
                                                        , method
                                                        , photo_mgr->getSignal()
                                                        , std::static_pointer_cast< ITech >( photo_mgr ) ) );

        return model;
    }
Ejemplo n.º 29
0
void WAbstractToggleButton::updateDom(DomElement& element, bool all)
{
  if (checkedChanged_ || all) {
    element.setProperty(Wt::PropertyChecked, checked_ ? "true" : "false");
    checkedChanged_ = false;
  }

  const WSignalInstance_ *changeS = getSignal(SIGNAL(changed()));
  const WSignalInstance_ *checkedS = getSignal(SIGNAL(checked()));
  const WSignalInstance_ *unCheckedS = getSignal(SIGNAL(unChecked()));

  bool needUpdateChangeSignal =
    (changeS->connectivityChanged()
     || checkedS->connectivityChanged()
     || unCheckedS->connectivityChanged()
     || changeS->staticCodeChanged()
     || checkedS->staticCodeChanged()
     || unCheckedS->staticCodeChanged());

  WFormWidget::updateDom(element, all);

  if (needUpdateChangeSignal || all) {
    element.removeEventSignal("change");

    DomElement *e = DomElement::getForUpdate(this, DomElement::INPUT);

    if (isConnected(changeS))
      element.addEventSignal("change", *changeS, 0, 0);
    if (isConnected(checkedS))
      element.addEventSignal("change", *checkedS, 0,
			     (e->createReference()
			      + ".checked == true").c_str());
    if (isConnected(unCheckedS))
      element.addEventSignal("change", *unCheckedS, 0,
			     (e->createReference()
			      + ".checked == false").c_str());
    delete e;
  }
}
Ejemplo n.º 30
0
void Square::setup(int size)
{
	mSize = size;
	
	//	The square shape
	mShape = Shape::createRect(mSize, mSize);
	mShape->setAlignment(po::scene::Alignment::CENTER_CENTER);
	
	//	Change hue based on size
	float hue = ci::lmap<float>(mSize, 0, 300, 0.1, 0.3);
	mColor = ci::Color(ci::CM_HSV, 1 - hue, 1, 0.8);
	mHighlightColor = ci::Color(ci::CM_HSV, 1 - hue, 1, 1);
	
	mShape->setFillColor(mColor);
	addChild(mShape);
	
	//	Connect to mouse events
	getSignal(po::scene::MouseEvent::DOWN_INSIDE).connect(std::bind(&Square::onMouseDown, this, std::placeholders::_1));
	getSignal(po::scene::MouseEvent::DRAG).connect(std::bind(&Square::onMouseDragged, this, std::placeholders::_1));
	getSignal(po::scene::MouseEvent::UP_INSIDE).connect(std::bind(&Square::onMouseUp, this, std::placeholders::_1));
	getSignal(po::scene::MouseEvent::UP).connect(std::bind(&Square::onMouseUp, this, std::placeholders::_1));
}