Пример #1
0
std::vector<int> getBoundaryStrokes(TVectorImage &vi)
{
	std::vector<int> result;
	getBoundaries(vi, result);

	return result;
}
Пример #2
0
std::vector<int> getSelectedStrokes(TVectorImage &vi, const LevelSelection &levelSelection)
{
	struct locals {

		static void selectStyles(const TVectorImage &vi, const std::set<int> &styles,
								 std::vector<int> &strokes)
		{
			UINT s, sCount = vi.getStrokeCount();
			for (s = 0; s != sCount; ++s) {
				if (styles.count(vi.getStroke(s)->getStyle()))
					strokes.push_back(s);
			}
		}
	}; // locals

	std::vector<int> strokes;

	switch (levelSelection.filter()) {
	case LevelSelection::EMPTY:;

		CASE LevelSelection::WHOLE : strokes.assign(boost::make_counting_iterator(0u),
													boost::make_counting_iterator(vi.getStrokeCount()));

		CASE LevelSelection::SELECTED_STYLES : locals::selectStyles(vi, levelSelection.styles(), strokes);

		CASE LevelSelection::BOUNDARY_STROKES : getBoundaries(vi, strokes);
	}

	return strokes;
}
Пример #3
0
void octree::getCorner(my_dev::dev_mem<float4>  &bodies_pos, 
                       int n_bodies, float4 &corner, float &domain_fac)
{
    
  real4 r_min = {+1e10, +1e10, +1e10, +1e10}; 
  real4 r_max = {-1e10, -1e10, -1e10, -1e10};   
  
  //Compute the boundaries and the tree-corner, this is required to convert 
  //the particle positions into intergers and then into Peano-Hilbert keys
  getBoundaries(bodies_pos, n_bodies, r_min, r_max);  
  
  //Compute the boundarys of the tree  
  real size     = 1.001*fmax(r_max.z - r_min.z,
                        fmax(r_max.y - r_min.y, r_max.x - r_min.x));
  
  corner   = (real4){0.5*(r_min.x + r_max.x) - 0.5*size,
                          0.5*(r_min.y + r_max.y) - 0.5*size,
                          0.5*(r_min.z + r_max.z) - 0.5*size, size}; 
       
  domain_fac   = size/(1 << MAXLEVELS);
  
  float idomain_fac = 1.0/domain_fac;
    
  corner.w = domain_fac;  
  
  printf("Corner: %f %f %f idomain fac: %f domain_fac: %f\n", 
         corner.x, corner.y, corner.z, idomain_fac, domain_fac);
  printf("domain fac: %f idomain_fac: %f size: %f MAXLEVELS: %d \n",
         domain_fac, idomain_fac, size, MAXLEVELS);
}
Пример #4
0
int main(){
	processSieve();
	showPrimes();
	getBoundaries();
	showPrimes();
	return 0;
}
Пример #5
0
Point PatchMatcher::getNewOffset(bool *foundMask) const {

    int minX, maxX, minY, maxY;
    getBoundaries(*outputMask, &minX, &maxX, &minY, &maxY);

    if (maxX < 0 || maxY < 0) {
        *foundMask = false;
        return Point(randRange(0, outputMask->width()  - patch->width()  + 1),
                     randRange(0, outputMask->height() - patch->height() + 1));
    } else {
        *foundMask = true;

        Image<float> C;

        // Compute allowed translations window
        minX = max(0, minX - patch->width()  + OVERLAP_WIDTH);
        minY = max(0, minY - patch->height() + OVERLAP_WIDTH);
        maxX = min(output->width()  - 1, maxX + patch->width()  - OVERLAP_WIDTH);
        maxY = min(output->height() - 1, maxY + patch->height() - OVERLAP_WIDTH);
        const Rect outputRect(minX, minY, maxX - minX + 1, maxY - minY + 1);

        Mat patchF, outputF;
        assert(patch->type() == CV_8UC3);
        assert(output->type() == CV_8UC3);

        patch->convertTo(patchF, CV_32FC3);
        ((Mat) *output)(outputRect).convertTo(outputF, CV_32FC3);

        matchTemplate(outputF, patchF, C, TM_SQDIFF);

        exp(C * factor, C);

//        imshow("C", C.greyImage());

        float acc, *data = (float *) C.data;

        for (int i = 0; i < C.height() * C.width(); i++) {
            acc += data[i];
            data[i] = acc;
        }

        int a = 0, b = C.height() * C.width() - 1;
        const float p = data[b] * (static_cast <float> (rand()) / static_cast <float> (RAND_MAX));

        // Dichotomy search
        while (b - a > 0) {
            const int m = (a + b) / 2;
            if (p > data[m])
                a = m + 1;
            else
                b = m;
        }

        // Seems to work
//        assert(p <= data[a] && (a == 0 || p > data[a-1]));
//        assert(data[a] == C(a % C.width(), a / C.width()));

        return Point(minX + a % C.width(), minY + a / C.width());
    }
}
/**
 * @brief It segments a cloud using the planes and boundaries previously calculated. A point is considered to be part of a valid object if it is above the plane, 
 * inside the limits of the planes and it is not part of any of the planes.
 * 
 * @param cloud Point cloud to segment.
 * @param [out] clusterIndices Valid indices after the segmentation.
 */
void MultiplePlaneSegmentation::segment(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud, std::vector<pcl::PointIndices> &clusterIndices) {
	
	std::vector<pcl::ModelCoefficients> coefficients;
	getCoefficients(coefficients);

	std::vector<std::vector<pcl::PointXYZRGBA>> boundaries;
	getBoundaries(boundaries);

	// Cloud containing the points without the planes.
	pcl::PointCloud<pcl::PointXYZRGBA>::Ptr remainingCloud = pcl::PointCloud<pcl::PointXYZRGBA>::Ptr(new pcl::PointCloud<pcl::PointXYZRGBA>(*cloud));

	// -1 -> part of a plane, 0 -> not part of an object, 1 -> part of an object.
	std::vector<char> mask = std::vector<char>(cloud->points.size(), 0);

	assert(coefficients.size() == boundaries.size());
	for(int i = 0; i < coefficients.size(); i++) {

		Eigen::Vector4f planeCoef = Eigen::Vector4f(coefficients[i].values.data());
		std::vector<pcl::PointXYZRGBA> planeBoundary = boundaries[i];

		#pragma omp parallel for firstprivate(planeCoef, planeBoundary) shared(cloud, mask) num_threads(4)
		for(size_t j = 0; j < cloud->points.size(); j++) {
			// Calculate the distance from the point to the plane normal as the dot product
			// D =(P-A).N/|N|

			// If the x value of the pointcloud or it is marked as a point in a plane it is not needed to
			// make further calculations, we don't want this point.
			if(isnan(cloud->points[j].x) or mask[j] == -1) continue;

			Eigen::Vector4f pt(cloud->points[j].x, cloud->points[j].y, cloud->points[j].z, 1);
			float distance = planeCoef.dot(pt);
			if (distance >= -0.02) {
				if (isInlier(cloud, j , planeBoundary, planeCoef)) {
					if (distance <= 0.02) {
						// If the point is at a distance less than X, then the point is in the plane, we mark it properly.
						mask[j] = -1;
					} else {
						// The point is not marked as being part of an object nor plane, if it is above it we mark it as object.
						mask[j] = 1;
					}
				}
			}
		}
	}

	// Parse inliers.
	pcl::PointIndices::Ptr inliers = pcl::PointIndices::Ptr(new pcl::PointIndices());
	inliers->indices.resize(cloud->points.size());
	int nr_p = 0;
	for(int i = 0; i < mask.size(); i++) {
		if(mask[i] == 1) inliers->indices[nr_p++] = i;
	}
	inliers->indices.resize(nr_p);

	// Clustering
	clusterIndices = std::vector<pcl::PointIndices>();
	clustering(cloud, inliers, 0.03, 200, clusterIndices);
}
// Returns true if overlap is wide enough
bool RandomOffsetChooser::checkOffset(const int offX, const int offY) const {

    const Mat patchMask = Mat(*outputMask, Rect(offX, offY, patch->width(), patch->height()));

    int minX, maxX, minY, maxY;
    getBoundaries(patchMask, &minX, &maxX, &minY, &maxY);

    return (maxX - minX >= OVERLAP_WIDTH && maxY - minY >= OVERLAP_WIDTH);
}
Пример #8
0
std::vector<ColMat<double, 3>> FaceUnwrapper::getFlatBoundaryNodes()
{
    if (this->ze_nodes.size() == 0)
        throw(std::runtime_error("flat vertices not xet computed"));

    ColMat<double, 3> flat_vertices;
    flat_vertices.resize(this->ze_nodes.rows(), 3);
    flat_vertices.setZero();
    flat_vertices.col(0) << this->ze_nodes.col(0);
    flat_vertices.col(1) << this->ze_nodes.col(1);
    return getBoundaries(flat_vertices, this->tris);
}
Пример #9
0
void createCitiesDisplay(CImgDisplay& disp, CImg<unsigned char>& image, CitiesData& cd)
{
	int minX,minY,maxX,maxY;
	getBoundaries(cd, maxX, minX, maxY, minY);
	if(minY < PADDING){
		addToAllY(cd,PADDING-minY);
	}
	if(minX < PADDING){
		addToAllX(cd,PADDING-minX);
	}

	CImg<unsigned char> img(maxY-minY + 2*PADDING,maxX-minX + 2*PADDING,1,3,0);	
	unsigned char white[] = { 255,255,255 };
	unsigned char blue[] = { 0,0,255 };

	for (int i = -1; i < cd.count; i++)
	{
		City c;
		unsigned char* color;
		if(i == -1){
			c = cd.warehouse;
			color = blue;
		}else{
			c = cd.cities[i];
			color = white;
		}

		char buf[16];
		sprintf(buf,"%d",c.id);

		img.draw_point(c.location.x,c.location.y,color,1.0);
		img.draw_text(c.location.x,c.location.y+4,buf,color);
	}


	//CImgDisplay main_disp(img,"Map of the area");
	CImgDisplay main_disp;
	//main_disp.wait();

	disp = main_disp;
	image = img;
}
Пример #10
0
//--------------------------------------------------------------
void ofApp::setup(){
	ofEnableAntiAliasing();
	ofEnableSmoothing();
	ofEnableDepthTest();

	bResample = true;
	resampleSpacing = 5.0;
	letterThickness = 145.0;

	ofTrueTypeFont ttf;
	// to extract points, loadFont must be called with makeContours set to true
	ttf.loadFont(OF_TTF_SANS, 300, true, false, true);
	string s = "TYPE";

	// Center string code from:
	// https://github.com/armadillu/ofxCenteredTrueTypeFont/blob/master/src/ofxCenteredTrueTypeFont.h
	ofRectangle r = ttf.getStringBoundingBox(s, 0, 0);
	center = ofVec2f(floor(-r.x - r.width * 0.5f), floor(-r.y - r.height * 0.5f));

	vector <ofTTFCharacter> letters = ttf.getStringAsPoints(s);

	for(int i = 0; i < letters.size(); i++){
		ofPath resampledPath = bResample ? resamplePath(letters[i], resampleSpacing) : letters[i];
		ofMesh meshLetter = createMeshFromPath(resampledPath, letterThickness);
		mesh.append(meshLetter);
	}

	getBoundaries(mesh);

	numSpheres = 7000; // the maximum number of Spheres
	addSpeed = 25; // the number of Spheres that is added per update() loop

	ofEnableLighting();
	ofSetGlobalAmbientColor(ofColor(128));

	directionalLight.setDiffuseColor(ofColor(128));
	directionalLight.setPosition(boundsMax);
	directionalLight.enable();

	cam.setVFlip(true);
}
// Returns a valid offset for the new patch to apply
Point RandomOffsetChooser::getNewOffset(bool *foundMask) const {

    int minX, maxX, minY, maxY;
    getBoundaries(*outputMask, &minX, &maxX, &minY, &maxY);

    if (maxX < 0 || maxY < 0) {
        *foundMask = false;
        return Point(randRange(0, outputMask->width()  - patch->width()  + 1),
                     randRange(0, outputMask->height() - patch->height() + 1));
    } else {
        *foundMask = true;

        int offX, offY;
        do {
            offX = randRange(max(0, minX - patch->width()  + 1), min(maxX, outputMask->width()  - patch->width()  + 1));
            offY = randRange(max(0, minY - patch->height() + 1), min(maxY, outputMask->height() - patch->height() + 1));
        } while (!checkOffset(offX, offY));

        return Point(offX, offY);
    }
}
Пример #12
0
void playLevel(SDL_Renderer* renderer, SDL_Window* window)
{
	TextureStorage::getInstance().setDifficultyBackground(renderer);
	bool isScoreRecording = false;
	bool isHighScore = false;
	bool isPaused = false;
	std::random_device rd;
	std::mt19937 eng(rd());
	std::uniform_int_distribution<> randomX(2 * WALL_WIDTH, SCREEN_WIDTH - (2 * WALL_WIDTH));
	std::uniform_int_distribution<> randomY(2 * WALL_WIDTH, SCREEN_HEIGHT - (2 * WALL_WIDTH));
	std::uniform_int_distribution<> randomVortex(0, VORTEX_LIMIT);
	std::string inputText = "";

	SDL_Event e;

	Player player(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, PLAYER_WIDTH, PLAYER_HEIGHT, PLAYER_VEL);
	Collectible collectible(randomX(eng), randomY(eng), resolveCoinWidth(), COIN_HEIGHT, 0);
	Skull skull(0, 0, SKULL_WIDTH, SKULL_HEIGHT, 0);

	std::vector<SDL_Rect> walls = getBoundaries();
	SoundPlayer::getInstance().playMusic();

	while (!isQuitting)
	{
		if (player.isDead)
		{
			SoundPlayer::getInstance().stopMusic();
			if (!isScoreRecording)
			{
				isScoreRecording = HighScore::getInstance().checkAndAddNewScore(score, gameDifficulty);
				if (isScoreRecording)
				{
					isHighScore = true;
					SoundPlayer::getInstance().playHighScore();
				}
			}			
		}
		while (SDL_PollEvent(&e) != 0)
		{
			if (!isPaused) SDL_EventState(SDL_KEYUP, SDL_ENABLE);
			if (e.type == SDL_QUIT)
			{
				isQuitting = true;
				isResetting = false;
				reset();
			}		
			else if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) toggleFullscreen(window);
			else if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_RETURN && !player.isDead)
			{
				SoundPlayer::getInstance().pauseMusic();
				SoundPlayer::getInstance().playPause();
				if (isPaused) isPaused = false;
				else
				{
					isPaused = true;
					SDL_EventState(SDL_KEYUP, SDL_IGNORE);
				}
					
			}
			if (isPaused) SDL_EventState(SDL_KEYDOWN, SDL_IGNORE);
			if (!player.isDead)
			{
				if (!isPaused) player.handleEvent(e);
			}
			else 
			{
				if (e.type == SDL_TEXTINPUT)
				{
					if (inputText.size() < 3 && e.text.text[0] != ',') inputText += e.text.text;
				}
				else if (e.type == SDL_KEYDOWN)
				{
					if (e.key.keysym.sym == SDLK_n && !isHighScore)
					{
						isResetting = false;
						reset();
						return;
					}
					else if (e.key.keysym.sym == SDLK_y && !isHighScore)
					{
						isResetting = true;
						reset();
						return;
					}	
					else if (e.key.keysym.sym == SDLK_BACKSPACE)
					{
						if (inputText.size() != 0) inputText.pop_back();
					}
					else if (e.key.keysym.sym == SDLK_RETURN)
					{
						if (isHighScore) HighScore::getInstance().addInitials(inputText);
						isHighScore = false;
					}
				}
			}
			SDL_EventState(SDL_KEYDOWN, SDL_ENABLE);
		}
		if (!isPaused)
		{
			if (!player.isDead) player.move(walls, enemies, skull);
			else skull.move(walls);
			for (std::vector<Enemy>::iterator it = enemies.begin(); it != enemies.end(); ++it) {
				it->move(walls);
			}

			if (!collectible.isHit)
			{
				prevX = collectible.getX();
				prevY = collectible.getY();
			}

			collectible.move(player, randomX(eng), randomY(eng));
		}

		SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(renderer);

		TextureStorage::getInstance().bgTexture.render(0, 0, renderer);
		renderWalls(renderer, walls);
		
		for (std::vector<Enemy>::iterator it = enemies.begin(); it != enemies.end(); ++it) {
			it->render(renderer);
		}
		collectible.render(renderer);

		if (!player.isDead) player.render(renderer);
		else skull.render(renderer);

		TextDraw::getInstance().renderHUD(renderer);
		if (collectible.isHit)
		{
			time++;
			TextDraw::getInstance().renderScoreGain(prevX, prevY, renderer);
			prevX++;
			prevY--;
			if (time == 20)
			{
				time = 0;
				Enemy enemy(randomX(eng), randomY(eng), ENEMY_WIDTH, ENEMY_HEIGHT, ENEMY_VEL * (int)gameDifficulty, EnemyType::SPIKEBALL);
				if (randomVortex(eng) > VORTEX_LIMIT / (int)gameDifficulty)
				{
					Enemy vortex(randomX(eng), randomY(eng), ENEMY_WIDTH, ENEMY_HEIGHT, 0, EnemyType::VORTEX);
					while (checkCollision(vortex.getHitbox(), player.getHitbox()))
					{
						vortex.setX(randomX(eng));
						vortex.setY(randomY(eng));
						vortex.setHitbox();
					}
					enemies.push_back(vortex);
				}
				while (checkCollision(enemy.getHitbox(), player.getHitbox()))
				{
					enemy.setX(randomX(eng));
					enemy.setY(randomY(eng));
					enemy.setHitbox();
				}
				enemies.push_back(enemy);
				collectible.isHit = false;
			}
		}
		if (player.isDead) TextDraw::getInstance().renderGameOver(renderer, isHighScore, inputText);
		if (isPaused)TextDraw::getInstance().renderPause(renderer);
		SDL_RenderPresent(renderer);
		frameCount++;
		if (frameCount == DISPLAY_LIMIT) frameCount = 0;
	}
}
Пример #13
0
int main(int argc, char const *argv[])
{
	//Local variables
	SpiceDouble et_0;
	SpiceDouble et_end;
	SpiceDouble *t = NULL;
	SpiceDouble **pos_hci = NULL;
	SpiceDouble **pos_iau = NULL;
	SpiceDouble **pos_hee = NULL;
	SpiceDouble *lon_iau = NULL;
	SpiceDouble *lat_iau = NULL;
	SpiceDouble *lon_hci = NULL;
	SpiceDouble *lat_hci = NULL;
	SpiceDouble *distance = NULL;
	SpiceInt n;
	SpiceInt i;
	char START_DATE[50]; 
	char STOP_DATE[50]; 
	char text_filename[50];
	char nc_filename[50];


	//Load specific kernels : leap years, planets and satellites objects, planetary constants and specific heliospheric frame (to use HCI frame) 
	if (!loadKernels(KERNELS))
	{
		printf("[ERROR] \"%s\" kernel list : no such file\n", KERNELS);
		exit(EXIT_FAILURE);
	}

	//Configure boundaries
	strcpy(START_DATE, argv[4]);
	strcpy(STOP_DATE, argv[5]);
	n = getBoundaries(START_DATE, &et_0, STOP_DATE, &et_end);
	if (n <= 0)
	{
		printf("[ERROR] Enable to get a date interval to compute Earth ephemeris.\n");

		exit(EXIT_FAILURE);
	}

	//Memory allocation
	t = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	pos_hci = (SpiceDouble**) malloc(n*sizeof(SpiceDouble*));
	pos_iau = (SpiceDouble**) malloc(n*sizeof(SpiceDouble*));
	pos_hee = (SpiceDouble**) malloc(n*sizeof(SpiceDouble*));
	distance = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	lon_hci = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	lat_hci = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	lon_iau = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));
	lat_iau = (SpiceDouble*) malloc(n*sizeof(SpiceDouble));

	if ((t == NULL) || (pos_hci == NULL) || (distance == NULL) || (lon_hci == NULL) || (lat_hci == NULL) || (lon_iau == NULL) || (lat_iau == NULL) )  
	{
		printf("[ERROR] Memory allocation has failed. Not enough memory.\n");

		exit(EXIT_FAILURE);
	}
	else
	{
		for (i = 0; i < n; i++)
		{
			
			pos_hci[i] = NULL;
			pos_hci[i] = (SpiceDouble*) malloc(3*sizeof(SpiceDouble));
			pos_iau[i] = NULL;
			pos_iau[i] = (SpiceDouble*) malloc(3*sizeof(SpiceDouble));
			pos_hee[i] = NULL;
			pos_hee[i] = (SpiceDouble*) malloc(3*sizeof(SpiceDouble));

			if ((pos_hci[i] == NULL) || (pos_iau[i] == NULL) || (pos_hee[i] == NULL))
			{
				printf("[ERROR] Position : Memory allocation has failed.\n");
			}
		}
	}
	
	//Compute n positions of the celestial body wanted starting from et_0 epoch with a STEP step
	getPositions(TARGET, et_0, STEP, n, FRAME1, ABCORR, OBSERVER, t, pos_hci);
	getPositions(TARGET, et_0, STEP, n, FRAME2, ABCORR, OBSERVER, t, pos_iau);
	getPositions(TARGET, et_0, STEP, n, FRAME3, ABCORR, OBSERVER, t, pos_hee);

	//Compute longitudes and latitudes
	getLonLat(pos_hci, lon_hci, lat_hci, n);
	getLonLat(pos_iau, lon_iau, lat_iau, n);

	//Compute n distances of the celestial body wanted relatively with the Sun
	getDistance(n, pos_hci, distance);

	//Print celestial body positions for the time interval
	//printPositions(t, pos);

	//Get files name
	//getFilesName(BODY_NAME, START_DATE, ".txt", text_filename);
	getFilesName(BODY_NAME, START_DATE, ".nc", nc_filename);

	//Write celestial body positions into "earth.txt" file
	//createTextFile(text_filename, n, t, pos_hci, pos_iau, pos_hee, lon_hci, lat_hci, lon_iau, lat_iau, distance);

	//Write celestial body positions into "earth.nc" file
	createNc(nc_filename, n, t, pos_hci, pos_iau, pos_hee, lon_hci, lat_hci, lon_iau, lat_iau, distance);

	//Free memory
	free(t);
	free(distance);
	for (i = 0; i < n; i++)
	{
		free(pos_hci[i]);
		pos_hci[i] = NULL;
		free(pos_iau[i]);
		pos_iau[i] = NULL;
		free(pos_hee[i]);
		pos_hee[i] = NULL;
	}
	free(pos_hci);
	pos_hci = NULL;
	free(pos_iau);
	pos_iau = NULL;
	free(pos_hee);
	pos_hee = NULL;

	free(lon_hci);
	lon_hci = NULL;

	free(lat_hci);
	lat_hci = NULL;

	free(lon_iau);
	lon_iau = NULL;

	free(lat_iau);
	lat_iau = NULL;

	return 0;
}