Example #1
0
TIDorb::types::BigInt TIDorb::types::BigInt::operator- () const
{
    TIDorb::types::BigInt res((TIDorb::types::BigInt&)*this);
    res.sign = sign*(-1);
    return res;
}
Example #2
0
	/*! Find an element with the given value
	  \param what value to find
	  \return pointer to found element or end() */
	iterator find(const T what)
	{
		internal_result res(std::equal_range (_arr, _arr + _sz, what, Comp()));
		return res.first != res.second ? res.first : end();
	}
Example #3
0
QString MtpFilter::filterOut(const QString & arg) {

    QString res(arg);

    // Global Filter
    for (std::vector<GlobalFilter*>::iterator it = global.begin(); it != global.end(); ++it) {
        if ((*it)->isEnabled() && (*it)->applyTo(res)) {
            res = (*it)->getResult();
            if ((*it)->policy() == Filter::Final)
                return res;
            else
                break;
        }
    }

    // Block Filter
    if (current_block) {
        current_block->applyTo(res);
        res = current_block->getResult();
        //std::cerr << res << std::endl;
        bool stop = (current_block->policy() == Filter::Final);
        if (current_block->isFinished())
            current_block = 0;
        if (stop)
            return res;
    } else
        for (std::vector<BlockFilter*>::iterator it = block.begin(); it != block.end(); ++it) {
            if ((*it)->isEnabled()) {
                InputFilter * in;
                if ((!(in = (*it)->getInputDependency())) || ((!queue.empty()) && (queue[0] == in))) {
                    if ((*it)->applyTo(res,BlockFilter::BEGIN)) {
                        //std::cout << "Beginning of Block" << std::endl;
                        current_block = *it;
                        if (in)
                            queue.erase(queue.begin());
                        res = (*it)->getResult();
                        if ((*it)->policy() == Filter::Final)
                            return res;
                        else
                            break;
                    }
                }
            }
        }

    // Line Filter
    for (std::vector<LineFilter*>::iterator it = line.begin(); it != line.end(); ++it) {
        if ((*it)->isEnabled() && (*it)->applyTo(res)) {
            res = (*it)->getResult();
            if ((*it)->policy() == Filter::Final)
                return res;
            else
                break;
        }
    }

    // Item Filter
    for (std::vector<ItemFilter*>::iterator it = item.begin(); it != item.end(); ++it) {
        if ((*it)->isEnabled() && (*it)->applyTo(res)) {
            res = (*it)->getResult();
        }
    }

    return res;
}
Example #4
0
	/*! Find a key (value).
	  \param key the key to find
	  \return value found (value) or _noval if not found */
	static const Val find_val(const Key& key)
	{
		PResult res(std::equal_range (_pairs, _pairs + _pairsz,
			reinterpret_cast<const Pair&>(key), typename Pair::Less()));
		return res.first != res.second ? res.first->_value : _noval;
	}
Example #5
0
	/*! Find a key pair record (pointer).
	  \param key the key to find
	  \return key/value pair (pointer) or 0 if not found */
	static const Pair *find_pair_ptr(const Key& key)
	{
		PResult res(std::equal_range (_pairs, _pairs + _pairsz,
			reinterpret_cast<const Pair&>(key), typename Pair::Less()));
		return res.first != res.second ? res.first : 0;
	}
Example #6
0
Vecteur3D operator- (const Vecteur3D& v1) {
    Vecteur3D res(0,0,0);
    res-=v1;
    return res;
}
int *res(int rows, int columns, int rs, int cs, int **in, int *result, int i, int j, int k,int count)
{
	if (columns == 0)
		return result;
	else if (rows == rs + 2 && j == columns - 1)
	{
		result[k] = in[i][j];
		return result;
	}
	
	else if (j < columns && i == rs + 1 && count == 0)
	{
		result[k] = in[i][j];
		return res(rows, columns, rs, cs, in, result, i, ++j, ++k,count);
	}

	else if (j == columns && count==0)
	{
		count = 1;
		rs = rs + 1;
		i++;
		j--;
	 	return res(rows, columns, rs, cs, in, result, i, j, k,count);
   }


	else if (i < rows && j == columns-1&&count==1&& i>=0 && j>=0)
	{
		result[k] = in[i][j];
		return res(rows, columns, rs, cs, in, result, ++i, j, ++k,count);
	}
	else if (i == rows)
	{
		columns = columns - 1;
		count = 2;
		i--;
		j--;
		return res(rows, columns, rs, cs, in, result, i, j, k,count);
	}


	else if (j > cs && i == rows - 1 && count == 2 && i >= 0 && j >= 0)
	{
		result[k] = in[i][j];
		return res(rows, columns, rs, cs, in, result, i, --j, ++k,count);
	}
	else if (j == cs && i==rows-1)
	{
		rows = rows - 1;
		count = 3;
		return res(rows, columns, rs, cs, in, result, --i, ++j, k,count);

	}

	else if (i > rs && j == cs + 1 && count == 3 && i >= 0 && j >= 0)
	{
		result[k] = in[i][j];
		return res(rows, columns, rs, cs, in, result, --i, j, ++k,count);
	}

	else if (i == rs  && j == cs+1)
	{
		cs = cs + 1;
		count = 0;
		
		return res(rows, columns, rs, cs, in, result, ++i, ++j, k,count);
	}
	
}
Example #8
0
RectF TextRenderGdi::Measure(const WCHAR *s, size_t sLen) {
    SIZE txtSize;
    GetTextExtentPoint32W(hdcForTextMeasure, s, (int) sLen, &txtSize);
    RectF res(0.0f, 0.0f, (float) txtSize.cx, (float) txtSize.cy);
    return res;
}
Example #9
0
Vecteur3D operator- (const Vecteur3D& v1, const Vecteur3D& v2) {
    Vecteur3D res(v1);
    res-=v2;
    return res;
}
Example #10
0
BigInt BigInt::operator+(const BigInt& bi) {
	BigInt res(this->number);
	res.set(res.add(bi.number));
	return res;
}
Example #11
0
BigInt BigInt::operator*(const BigInt& bi) {
	BigInt res(this->number);
	res.set(res.multiply(bi.number));
	return res;
}
Example #12
0
 shared_ptr<Future::CommandResult> Future::spawnCommand( const string& server , const string& db , const BSONObj& cmd , DBClientBase * conn ) {
     shared_ptr<Future::CommandResult> res (new Future::CommandResult( server , db , cmd , conn  ));
     return res;
 }
cv::Mat DarkPixelFilter2Plugin::filter(const cv::Mat &data) const
{
    cv::Mat out;
    if (data.channels() > 1)
    {
        // create gray image
        std::vector<cv::Mat> iChannels(data.channels());
        cv::split(data, &iChannels[0]);

        double a = 1.0/iChannels.size();
        iChannels[0].convertTo(out, CV_32F, a);
        for (int i=1; i<iChannels.size();i++)
        {
            out += a*iChannels[i];
        }
    }
    else
    {
        if (data.depth() == CV_32F)
        {
            data.copyTo(out);
        }
        else
        {
            data.convertTo(out, CV_32F);
        }
    }

    // -) Compute mask from specified value:
    cv::Mat datamask;
    if (_maskByValue > -12345)
    {
        datamask = out != _maskByValue;
    }


    // -) Image -> 1/Image
    cv::divide(1.0,out,out,CV_32F);

    if (_verbose) { verboseDisplayImage("Image -> 1/Image", out); }
    emit progressValue(15);


    // -) Gaussian blur
    cv::GaussianBlur(out, out, cv::Size(_gbWinSize, _gbWinSize), _gbWinSize/1.5);
    if (_verbose) { verboseDisplayImage("Gaussian blur", out); }


    // -) Resize image
    int initW=out.cols, initH=out.rows;
    double rf = _resizeFactor;
    int newW = initW*rf;
    int newH = initH*rf;
    if (newW < 256 || newH < 256)
    {
        rf = qMax(256.0 / initW, 256.0 / initH);
        SD_TRACE1("New resize factor : %1", rf);
    }

    cv::resize(out, out, cv::Size(0, 0), rf, rf, cv::INTER_NEAREST);
    if (!datamask.empty())
    {
        cv::resize(datamask, datamask, cv::Size(0, 0), rf, rf, cv::INTER_NEAREST);
    }

    emit progressValue(25);

    // -) Convert to 8U
    {
        double minVal, maxVal;
        cv::minMaxLoc(out, &minVal, &maxVal, 0, 0,datamask);
        cv::Scalar mean, std;
        cv::meanStdDev(out, mean, std, datamask);
        double nmin = mean.val[0] - 3.0*std.val[0];
        minVal = (nmin < minVal) ? minVal : nmin;
        double nmax = mean.val[0] + 3.0*std.val[0];
        maxVal = (nmax > maxVal) ? maxVal : nmax;
        cv::Mat out8U;
        out.convertTo(out8U, CV_8U, 255.0/(maxVal-minVal), -255.0*minVal/(maxVal-minVal));
        out = out8U;
        emit progressValue(30);
    }

    // -) Median blur
    cv::medianBlur(out, out, 3);

    // -) Only bright objects
    {
        cv::Scalar mean = cv::mean(out, datamask);
        cv::threshold(out, out, mean[0], 255, cv::THRESH_TOZERO);
        cv::Mat mask, m = out == 0;
        m.convertTo(mask, out.type(), mean[0]/255.0);
        out = out + mask;
    }
    if (_verbose) { verboseDisplayImage("Only bright objects", out); }

    // -) Adaptive thresholding

    // Y = (Ymax - Ymin) * (X - Xmin)/(Xmax - Xmin) + Ymin
    // Y = (Ymin - Ymax) * (X - Xmin)/(Xmax - Xmin) + Ymax
    // transform sensivity [0.0 -> 1.0] into coeff [1.0 -> 0.3]
    double v = 1.0 - (0.7)*_sensivity;
    cv::Scalar mean = cv::mean(out, datamask);
    double c = -v*mean[0];
    cv::adaptiveThreshold(out, out, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, _atWinSize, c);

    if (_verbose) { verboseDisplayImage("Adaptive thresholding", out); }
    emit progressValue(40);

    // -) Morpho close
    out = blurThreshClose(out, 3, 100, _mcWinSize, 2);
    if (_verbose) { verboseDisplayImage("Blur + Theshold + Morpho", out); }
    emit progressValue(50);

    // -) Resize to initial
    cv::resize(out, out, cv::Size(initW, initH), 0, 0, cv::INTER_LINEAR);
    emit progressValue(60);

    // -) Make contours smoother
    {
        int s = 7;
        cv::blur(out, out, cv::Size(s, s));
        cv::Mat k1 = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(s, s));
        cv::morphologyEx(out, out, cv::MORPH_ERODE, k1);
    }

    // -) Find contours
    std::vector<std::vector<cv::Point> > contours;
    cv::findContours(out, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE);

    cv::Mat res(out.size(), CV_32F);
    res.setTo(_noDataValue);
    emit progressValue(80);

    if (contours.size() > 0)
    {
        double minArea = _minSize*_minSize;
        for (int i=0;i<contours.size();i++)
        {
            std::vector<cv::Point> contour = contours[i];
            // remove line and points
            if (contour.size() < 3)
                continue;
            double s = cv::contourArea(contour);
            if (s > minArea)
            {
                cv::drawContours(res, contours, i, cv::Scalar::all(1.0), CV_FILLED);
            }
        }
        out = res;
    }
    else
    {
        _errorMessage = tr("No dark pixel zones found of size larger than %1").arg(_minSize);
        return cv::Mat();
    }

    return out;
}
Example #14
0
unboundInt unboundInt::translate(unsigned int i){
    unboundInt res(i);
    return res;
}
/**
 * Generate a height-map.
 *
 * Basically we generate a lot of hills, each hill being centered at a certain
 * point, with a certain radius - being a half sphere.  Hills are combined
 * additively to form a bumpy surface.  The size of each hill varies randomly
 * from 1-hill_size.  We generate 'iterations' hills in total.  The range of
 * heights is normalized to 0-1000.  'island_size' controls whether or not the
 * map should tend toward an island shape, and if so, how large the island
 * should be.  Hills with centers that are more than 'island_size' away from
 * the center of the map will be inverted (i.e. be valleys).  'island_size' as
 * 0 indicates no island.
 */
height_map default_map_generator_job::generate_height_map(size_t width, size_t height, size_t iterations, size_t hill_size, size_t island_size, size_t island_off_center)
{
	height_map res(width, std::vector<int>(height,0));

	size_t center_x = width/2;
	size_t center_y = height/2;

	LOG_NG << "off-centering...\n";

	if(island_off_center != 0) {
		switch(rng_()%4) {
		case 0:
			center_x += island_off_center;
			break;
		case 1:
			center_y += island_off_center;
			break;
		case 2:
			if(center_x < island_off_center) {
				center_x = 0;
			} else {
				center_x -= island_off_center;
			}
			break;
		case 3:
			if(center_y < island_off_center) {
				center_y = 0;
			} else {
				center_y -= island_off_center;
			}
			break;
		}
	}

	for(size_t i = 0; i != iterations; ++i) {

		// (x1,y1) is the location of the hill,
		// and 'radius' is the radius of the hill.
		// We iterate over all points, (x2,y2).
		// The formula for the amount the height is increased by is:
		// radius - sqrt((x2-x1)^2 + (y2-y1)^2) with negative values ignored.
		//
		// Rather than iterate over every single point, we can reduce the points
		// to a rectangle that contains all the positive values for this formula --
		// the rectangle is given by min_x,max_x,min_y,max_y.

		// Is this a negative hill? (i.e. a valley)
		bool is_valley = false;

		int x1 = island_size > 0 ? center_x - island_size + (rng_()%(island_size*2)) : int(rng_()%width);
		int y1 = island_size > 0 ? center_y - island_size + (rng_()%(island_size*2)) : int(rng_()%height);

		// We have to check whether this is actually a valley
		if(island_size != 0) {
			const size_t diffx = std::abs(x1 - int(center_x));
			const size_t diffy = std::abs(y1 - int(center_y));
			const size_t dist = size_t(std::sqrt(double(diffx*diffx + diffy*diffy)));
			is_valley = dist > island_size;
		}

		const int radius = rng_()%hill_size + 1;

		const int min_x = x1 - radius > 0 ? x1 - radius : 0;
		const int max_x = x1 + radius < static_cast<long>(res.size()) ? x1 + radius : res.size();
		const int min_y = y1 - radius > 0 ? y1 - radius : 0;
		const int max_y = y1 + radius < static_cast<long>(res.front().size()) ? y1 + radius : res.front().size();

		for(int x2 = min_x; x2 < max_x; ++x2) {
			for(int y2 = min_y; y2 < max_y; ++y2) {
				const int xdiff = (x2-x1);
				const int ydiff = (y2-y1);

				const int hill_height = radius - int(std::sqrt(double(xdiff*xdiff + ydiff*ydiff)));

				if(hill_height > 0) {
					if(is_valley) {
						if(hill_height > res[x2][y2]) {
							res[x2][y2] = 0;
						} else {
							res[x2][y2] -= hill_height;
						}
					} else {
						res[x2][y2] += hill_height;
					}
				}
			}
		}
	}

	// Find the highest and lowest points on the map for normalization:
	int heighest = 0, lowest = 100000, x;
	for(x = 0; size_t(x) != res.size(); ++x) {
		for(int y = 0; size_t(y) != res[x].size(); ++y) {
			if(res[x][y] > heighest) {
				heighest = res[x][y];
			}

			if(res[x][y] < lowest) {
				lowest = res[x][y];
			}
		}
	}

	// Normalize the heights to the range 0-1000:
	heighest -= lowest;
	for(x = 0; size_t(x) != res.size(); ++x) {
		for(int y = 0; size_t(y) != res[x].size(); ++y) {
			res[x][y] -= lowest;
			res[x][y] *= 1000;
			if(heighest != 0) {
				res[x][y] /= heighest;
			}
		}
	}

	return res;
}
Example #16
0
int WpaGui::openCtrlConnection(const char *ifname)
{
	char *cfile;
	int flen;
	char buf[2048], *pos, *pos2;
	size_t len;

	if (ifname) {
		if (ifname != ctrl_iface) {
			free(ctrl_iface);
			ctrl_iface = strdup(ifname);
		}
	} else {
#ifdef CONFIG_CTRL_IFACE_UDP
		free(ctrl_iface);
		ctrl_iface = strdup("udp");
#endif /* CONFIG_CTRL_IFACE_UDP */
#ifdef CONFIG_CTRL_IFACE_UNIX
		struct dirent *dent;
		DIR *dir = opendir(ctrl_iface_dir);
		free(ctrl_iface);
		ctrl_iface = NULL;
		if (dir) {
			while ((dent = readdir(dir))) {
#ifdef _DIRENT_HAVE_D_TYPE
				/* Skip the file if it is not a socket.
				 * Also accept DT_UNKNOWN (0) in case
				 * the C library or underlying file
				 * system does not support d_type. */
				if (dent->d_type != DT_SOCK &&
				    dent->d_type != DT_UNKNOWN)
					continue;
#endif /* _DIRENT_HAVE_D_TYPE */

				if (strcmp(dent->d_name, ".") == 0 ||
				    strcmp(dent->d_name, "..") == 0)
					continue;
				printf("Selected interface '%s'\n",
				       dent->d_name);
				ctrl_iface = strdup(dent->d_name);
				break;
			}
			closedir(dir);
		}
#endif /* CONFIG_CTRL_IFACE_UNIX */
#ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
		struct wpa_ctrl *ctrl;
		int ret;

		free(ctrl_iface);
		ctrl_iface = NULL;

		ctrl = wpa_ctrl_open(NULL);
		if (ctrl) {
			len = sizeof(buf) - 1;
			ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf,
					       &len, NULL);
			if (ret >= 0) {
				connectedToService = true;
				buf[len] = '\0';
				pos = strchr(buf, '\n');
				if (pos)
					*pos = '\0';
				ctrl_iface = strdup(buf);
			}
			wpa_ctrl_close(ctrl);
		}
#endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
	}

	if (ctrl_iface == NULL) {
#ifdef CONFIG_NATIVE_WINDOWS
		static bool first = true;
		if (first && !serviceRunning()) {
			first = false;
			if (QMessageBox::warning(
				    this, qAppName(),
				    tr("wpa_supplicant service is not "
				       "running.\n"
				       "Do you want to start it?"),
				    QMessageBox::Yes | QMessageBox::No) ==
			    QMessageBox::Yes)
				startService();
		}
#endif /* CONFIG_NATIVE_WINDOWS */
		return -1;
	}

#ifdef CONFIG_CTRL_IFACE_UNIX
	flen = strlen(ctrl_iface_dir) + strlen(ctrl_iface) + 2;
	cfile = (char *) malloc(flen);
	if (cfile == NULL)
		return -1;
	snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ctrl_iface);
#else /* CONFIG_CTRL_IFACE_UNIX */
	flen = strlen(ctrl_iface) + 1;
	cfile = (char *) malloc(flen);
	if (cfile == NULL)
		return -1;
	snprintf(cfile, flen, "%s", ctrl_iface);
#endif /* CONFIG_CTRL_IFACE_UNIX */

	if (ctrl_conn) {
		wpa_ctrl_close(ctrl_conn);
		ctrl_conn = NULL;
	}

	if (monitor_conn) {
		delete msgNotifier;
		msgNotifier = NULL;
		wpa_ctrl_detach(monitor_conn);
		wpa_ctrl_close(monitor_conn);
		monitor_conn = NULL;
	}

	printf("Trying to connect to '%s'\n", cfile);
	ctrl_conn = wpa_ctrl_open(cfile);
	if (ctrl_conn == NULL) {
		free(cfile);
		return -1;
	}
	monitor_conn = wpa_ctrl_open(cfile);
	free(cfile);
	if (monitor_conn == NULL) {
		wpa_ctrl_close(ctrl_conn);
		return -1;
	}
	if (wpa_ctrl_attach(monitor_conn)) {
		printf("Failed to attach to wpa_supplicant\n");
		wpa_ctrl_close(monitor_conn);
		monitor_conn = NULL;
		wpa_ctrl_close(ctrl_conn);
		ctrl_conn = NULL;
		return -1;
	}

#if defined(CONFIG_CTRL_IFACE_UNIX) || defined(CONFIG_CTRL_IFACE_UDP)
	msgNotifier = new QSocketNotifier(wpa_ctrl_get_fd(monitor_conn),
					  QSocketNotifier::Read, this);
	connect(msgNotifier, SIGNAL(activated(int)), SLOT(receiveMsgs()));
#endif

	adapterSelect->clear();
	adapterSelect->addItem(ctrl_iface);
	adapterSelect->setCurrentIndex(0);

	len = sizeof(buf) - 1;
	if (wpa_ctrl_request(ctrl_conn, "INTERFACES", 10, buf, &len, NULL) >=
	    0) {
		buf[len] = '\0';
		pos = buf;
		while (*pos) {
			pos2 = strchr(pos, '\n');
			if (pos2)
				*pos2 = '\0';
			if (strcmp(pos, ctrl_iface) != 0)
				adapterSelect->addItem(pos);
			if (pos2)
				pos = pos2 + 1;
			else
				break;
		}
	}

	len = sizeof(buf) - 1;
	if (wpa_ctrl_request(ctrl_conn, "GET_CAPABILITY eap", 18, buf, &len,
			     NULL) >= 0) {
		buf[len] = '\0';

		QString res(buf);
		QStringList types = res.split(QChar(' '));
		bool wps = types.contains("WSC");
		actionWPS->setEnabled(wps);
		wpsTab->setEnabled(wps);
		wpaguiTab->setTabEnabled(wpaguiTab->indexOf(wpsTab), wps);
	}

	return 0;
}