Ejemplo n.º 1
2
bool rotatedRectangleContainPoint(cv::RotatedRect rectangle, cv::Point2f point) {

    cv::Point2f corners[4];
    rectangle.points(corners);

    cv::Point2f *lastItemPointer = (corners + sizeof corners / sizeof corners[0]);
    std::vector<cv::Point2f> contour(corners, lastItemPointer);

    double indicator = pointPolygonTest(contour, point, false);

    return indicator >= 0;
}
Ejemplo n.º 2
0
void MapgenV7::generateCaves(s16 max_stone_y)
{
	if (max_stone_y >= node_min.Y) {
		u32 index   = 0;

		for (s16 z = node_min.Z; z <= node_max.Z; z++)
		for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
			u32 i = vm->m_area.index(node_min.X, y, z);
			for (s16 x = node_min.X; x <= node_max.X; x++, i++, index++) {
				float d1 = contour(noise_cave1->result[index]);
				float d2 = contour(noise_cave2->result[index]);
				if (d1 * d2 > 0.3) {
					content_t c = vm->m_data[i].getContent();
					if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
						continue;

					vm->m_data[i] = MapNode(CONTENT_AIR);
				}
			}
		}
	}

	PseudoRandom ps(blockseed + 21343);
	u32 bruises_count = (ps.range(1, 4) == 1) ? ps.range(1, 2) : 0;
	for (u32 i = 0; i < bruises_count; i++) {
		CaveV7 cave(this, &ps);
		cave.makeCave(node_min, node_max, max_stone_y);
	}
}
Ejemplo n.º 3
0
void MapgenFractal::generateCaves(s16 max_stone_y)
{
	if (max_stone_y < node_min.Y)
		return;

	noise_cave1->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
	noise_cave2->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);

	v3s16 em = vm->m_area.getExtent();
	u32 index2d = 0;

	for (s16 z = node_min.Z; z <= node_max.Z; z++)
	for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
		bool column_is_open = false;  // Is column open to overground
		u32 vi = vm->m_area.index(x, node_max.Y + 1, z);
		u32 index3d = (z - node_min.Z) * zstride + (csize.Y + 1) * ystride +
			(x - node_min.X);
		// Biome of column
		Biome *biome = (Biome *)bmgr->getRaw(biomemap[index2d]);

		for (s16 y = node_max.Y + 1; y >= node_min.Y - 1;
				y--, index3d -= ystride, vm->m_area.add_y(em, vi, -1)) {
			content_t c = vm->m_data[vi].getContent();
			if (c == CONTENT_AIR || c == biome->c_water_top ||
					c == biome->c_water) {
				column_is_open = true;
				continue;
			}
			// Ground
			float d1 = contour(noise_cave1->result[index3d]);
			float d2 = contour(noise_cave2->result[index3d]);
			if (d1 * d2 > 0.3f && ndef->get(c).is_ground_content) {
				// In tunnel and ground content, excavate
				vm->m_data[vi] = MapNode(CONTENT_AIR);
			} else if (column_is_open &&
					(c == biome->c_filler || c == biome->c_stone)) {
				// Tunnel entrance floor
				vm->m_data[vi] = MapNode(biome->c_top);
				column_is_open = false;
			} else {
				column_is_open = false;
			}
		}
	}

	if (node_max.Y > MGFRACTAL_LARGE_CAVE_DEPTH)
		return;

	PseudoRandom ps(blockseed + 21343);
	u32 bruises_count = ps.range(0, 2);
	for (u32 i = 0; i < bruises_count; i++) {
		CaveV5 cave(this, &ps);
		cave.makeCave(node_min, node_max, max_stone_y);
	}
}
Ejemplo n.º 4
0
void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
	v3s16 nmin, v3s16 nmax, u8 *biomemap)
{
	PcgRandom pr(blockseed + 520);
	MapNode n_ore(c_ore, 0, ore_param2);

	u32 sizex = (nmax.X - nmin.X + 1);

	if (!noise) {
		int sx = nmax.X - nmin.X + 1;
		int sy = nmax.Y - nmin.Y + 1;
		int sz = nmax.Z - nmin.Z + 1;
		noise  = new Noise(&np, mapseed, sx, sy, sz);
		noise2 = new Noise(&np, mapseed + 436, sx, sy, sz);
	}
	bool noise_generated = false;

	size_t index = 0;
	for (int z = nmin.Z; z <= nmax.Z; z++)
	for (int y = nmin.Y; y <= nmax.Y; y++)
	for (int x = nmin.X; x <= nmax.X; x++, index++) {
		u32 i = vm->m_area.index(x, y, z);
		if (!vm->m_area.contains(i))
			continue;
		if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
			continue;

		if (biomemap && !biomes.empty()) {
			u32 bmapidx = sizex * (z - nmin.Z) + (x - nmin.X);
			std::set<u8>::iterator it = biomes.find(biomemap[bmapidx]);
			if (it == biomes.end())
				continue;
		}

		// Same lazy generation optimization as in OreBlob
		if (!noise_generated) {
			noise_generated = true;
			noise->perlinMap3D(nmin.X, nmin.Y, nmin.Z);
			noise2->perlinMap3D(nmin.X, nmin.Y, nmin.Z);
		}

		// randval ranges from -1..1
		float randval   = (float)pr.next() / (pr.RANDOM_RANGE / 2) - 1.f;
		float noiseval  = contour(noise->result[index]);
		float noiseval2 = contour(noise2->result[index]);
		if (noiseval * noiseval2 + randval * random_factor < nthresh)
			continue;

		vm->m_data[i] = n_ore;
	}
}
Ejemplo n.º 5
0
float CLevelGraph::check_position_in_direction(u32 start_vertex_id, const Fvector &start_position, const Fvector &finish_position, const float max_distance) const
{
	SContour				_contour;
	const_iterator			I,E;
	int						saved_index, iPrevIndex = -1, iNextNode;
	Fvector					start_point = start_position, temp_point = start_position, finish_point = finish_position;
	float					fCurDistance = 0.f, fDistance = start_position.distance_to_xz(finish_position);
	u32						dwCurNode = start_vertex_id;

	while (!inside(vertex(dwCurNode),finish_position) && (fCurDistance < (fDistance + EPS_L))) {
		begin				(dwCurNode,I,E);
		saved_index			= -1;
		contour				(_contour,dwCurNode);
		for ( ; I != E; ++I) {
			iNextNode = value(dwCurNode,I);
			if (valid_vertex_id(iNextNode) && (iPrevIndex != iNextNode))
				choose_point(start_point,finish_point,_contour, iNextNode,temp_point,saved_index);
		}

		if (saved_index > -1) {
			fCurDistance	= start_point.distance_to_xz(temp_point);
			iPrevIndex		= dwCurNode;
			dwCurNode		= saved_index;
		}
		else
			return			(max_distance);
	}

	if (inside(vertex(dwCurNode),finish_position) && (_abs(vertex_plane_y(*vertex(dwCurNode),finish_position.x,finish_position.z) - finish_position.y) < .5f))
		return				(start_point.distance_to_xz(finish_position));
	else
		return				(max_distance);
}
Ejemplo n.º 6
0
float CLevelGraph::mark_nodes_in_direction(u32 start_vertex_id, const Fvector &start_point, const Fvector &finish_point, xr_vector<u32> &tpaStack, xr_vector<bool> *tpaMarks) const
{
	SContour				_contour;
	const_iterator			I,E;
	int						saved_index, iPrevIndex = -1, iNextNode;
	Fvector					temp_point = start_point;
	float					fDistance = start_point.distance_to(finish_point), fCurDistance = 0.f;
	u32						dwCurNode = start_vertex_id;

	while (!inside(vertex(dwCurNode),finish_point) && (fCurDistance < (fDistance + EPS_L))) {
		begin				(dwCurNode,I,E);
		saved_index			= -1;
		contour				(_contour,dwCurNode);
		for ( ; I != E; ++I) {
			iNextNode = value(dwCurNode,I);
			if (valid_vertex_id(iNextNode) && (iPrevIndex != iNextNode))
				choose_point(start_point,finish_point,_contour, iNextNode,temp_point,saved_index);
		}

		if (saved_index > -1) {
			fCurDistance	= start_point.distance_to_xz(temp_point);
			iPrevIndex		= dwCurNode;
			dwCurNode		= saved_index;
		}
		else
			return(fCurDistance);

		if (tpaMarks)
			(*tpaMarks)[dwCurNode]	= true;
		tpaStack.push_back	(dwCurNode);
	}

	return					(fCurDistance);
}
Ejemplo n.º 7
0
void
displayPlanarRegions (std::vector<pcl::PlanarRegion<PointT>, Eigen::aligned_allocator<pcl::PlanarRegion<PointT> > > &regions, 
                      boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer)
{
  char name[1024];
  unsigned char red [6] = {255,   0,   0, 255, 255,   0};
  unsigned char grn [6] = {  0, 255,   0, 255,   0, 255};
  unsigned char blu [6] = {  0,   0, 255,   0, 255, 255};

  pcl::PointCloud<PointT>::Ptr contour (new pcl::PointCloud<PointT>);

  for (size_t i = 0; i < regions.size (); i++)
  {
    Eigen::Vector3d centroid = regions[i].getCentroid ();
    Eigen::Vector4d model = regions[i].getCoefficients ();
    pcl::PointXYZ pt1 = pcl::PointXYZ (centroid[0], centroid[1], centroid[2]);
    pcl::PointXYZ pt2 = pcl::PointXYZ (centroid[0] + (0.5 * model[0]),
                                       centroid[1] + (0.5 * model[1]),
                                       centroid[2] + (0.5 * model[2]));
    sprintf (name, "normal_%d", unsigned (i));
    viewer->addArrow (pt2, pt1, 1.0, 0, 0, false, name);
    
    contour->points = regions[i].getContour ();
    sprintf (name, "plane_%02d", int (i));
    pcl::visualization::PointCloudColorHandlerCustom <PointT> color (contour, red[i%6], grn[i%6], blu[i%6]);
    if(!viewer->updatePointCloud(contour, color, name))
      viewer->addPointCloud (contour, color, name);
    viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, name);
  }
}
Ejemplo n.º 8
0
	vector<cv::Point2f> toCv(const ofPolyline& polyline) {
		vector<cv::Point2f> contour(polyline.size());
		for(int i = 0; i < polyline.size(); i++) {
			contour[i].x = polyline[i].x;
			contour[i].y = polyline[i].y;
		}
		return contour;		
	}
Ejemplo n.º 9
0
	vector<cv::Point2f> toCv(const ofPolyline& polyline) {
		// if polyline.getVertices() were const, this could wrap toCv(vec<vec2f>)
		vector<cv::Point2f> contour(polyline.size());
		for(int i = 0; i < polyline.size(); i++) {
			contour[i].x = polyline[i].x;
			contour[i].y = polyline[i].y;
		}
		return contour;		
	}
Ejemplo n.º 10
0
grace grace::contour(double (*fun)(double,double*),double x0,double x1,int nx,VTYPE &par)
{
  double x[nx];
  VTYPE y;
  
  build_graph(x,y,fun,x0,x1,nx,par);
  contour(x,y);
  
  return *this;
}
Ejemplo n.º 11
0
void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
	v3s16 nmin, v3s16 nmax)
{
	PseudoRandom pr(blockseed + 520);
	MapNode n_ore(c_ore, 0, ore_param2);

	if (!noise) {
		int sx = nmax.X - nmin.X + 1;
		int sy = nmax.Y - nmin.Y + 1;
		int sz = nmax.Z - nmin.Z + 1;
		noise  = new Noise(&np, mapseed, sx, sy, sz);
		noise2 = new Noise(&np, mapseed + 436, sx, sy, sz);
	}
	bool noise_generated = false;

	size_t index = 0;
	for (int z = nmin.Z; z <= nmax.Z; z++)
	for (int y = nmin.Y; y <= nmax.Y; y++)
	for (int x = nmin.X; x <= nmax.X; x++, index++) {
		u32 i = vm->m_area.index(x, y, z);
		if (!vm->m_area.contains(i))
			continue;
		if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
			continue;

		// Same lazy generation optimization as in OreBlob
		if (!noise_generated) {
			noise_generated = true;
			noise->perlinMap3D(nmin.X, nmin.Y, nmin.Z);
			noise2->perlinMap3D(nmin.X, nmin.Y, nmin.Z);
		}

		// randval ranges from -1..1
		float randval   = (float)pr.next() / (PSEUDORANDOM_MAX / 2) - 1.f;
		float noiseval  = contour(noise->result[index]);
		float noiseval2 = contour(noise2->result[index]);
		if (noiseval * noiseval2 + randval * random_factor < nthresh)
			continue;

		vm->m_data[i] = n_ore;
	}
}
Ejemplo n.º 12
0
void MapgenV5::generateCaves(int max_stone_y)
{
	if (max_stone_y < node_min.Y)
		return;

	noise_cave1->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
	noise_cave2->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);

	u32 index = 0;

	for (s16 z = node_min.Z; z <= node_max.Z; z++)
	for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
		u32 vi = vm->m_area.index(node_min.X, y, z);
		for (s16 x = node_min.X; x <= node_max.X; x++, vi++, index++) {
			// Don't excavate the overgenerated stone at node_max.Y + 1,
			// this creates a 'roof' over the tunnel, preventing light in
			// tunnels at mapchunk borders when generating mapchunks upwards.
			if (y > node_max.Y)
				continue;

			float d1 = contour(noise_cave1->result[index]);
			float d2 = contour(noise_cave2->result[index]);
			if (d1 * d2 > 0.125f) {
				content_t c = vm->m_data[vi].getContent();
				if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
					continue;

				vm->m_data[vi] = MapNode(CONTENT_AIR);
			}
		}
	}

	if (node_max.Y > MGV5_LARGE_CAVE_DEPTH)
		return;

	PseudoRandom ps(blockseed + 21343);
	u32 bruises_count = ps.range(0, 2);
	for (u32 i = 0; i < bruises_count; i++) {
		CaveV5 cave(this, &ps);
		cave.makeCave(node_min, node_max, max_stone_y);
	}
}
Ejemplo n.º 13
0
void MapgenV7::generateCaves(int max_stone_y)
{
	if (max_stone_y >= node_min.Y) {
		u32 index   = 0;
		u32 index2d = 0;

		for (s16 z = node_min.Z; z <= node_max.Z; z++) {
			for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
				u32 i = vm->m_area.index(node_min.X, y, z);
				for (s16 x = node_min.X; x <= node_max.X;
						x++, i++, index++, index2d++) {
					float d1 = contour(noise_cave1->result[index]);
					float d2 = contour(noise_cave2->result[index]);
					if (d1 * d2 > 0.3) {
						Biome *biome = (Biome *)bmgr->
									getRaw(biomemap[index2d]);
						content_t c = vm->m_data[i].getContent();
						if (!ndef->get(c).is_ground_content ||
								c == CONTENT_AIR ||
								(y <= water_level &&
								c != biome->c_stone &&
								c != c_stone))
							continue;

						vm->m_data[i] = MapNode(CONTENT_AIR);
					}
				}
				index2d -= ystride;
			}
			index2d += ystride;
		}
	}

	PseudoRandom ps(blockseed + 21343);
	u32 bruises_count = (ps.range(1, 4) == 1) ? ps.range(1, 2) : 0;
	for (u32 i = 0; i < bruises_count; i++) {
		CaveV7 cave(this, &ps);
		cave.makeCave(node_min, node_max, max_stone_y);
	}
}
Ejemplo n.º 14
0
    void testBrokenCurve() {
        FTContour contour( brokenPoints, simpleConicTags, 3);
        CPPUNIT_ASSERT( contour.PointCount() == 1);

        FTContour shortContour( shortLine, simpleConicTags, 2);
        CPPUNIT_ASSERT( shortContour.PointCount() == 6);

        FTContour reallyShortContour( shortLine, simpleConicTags, 1);
        CPPUNIT_ASSERT( reallyShortContour.PointCount() == 1);

        FTContour brokenTagtContour( shortLine, brokenTags, 3);
        CPPUNIT_ASSERT( brokenTagtContour.PointCount() == 7);
    }
Ejemplo n.º 15
0
double noise3d_param(const OldNoiseParams &param, double x, double y, double z)
{
	double s = param.pos_scale;
	x /= s;
	y /= s;
	z /= s;

	if(param.type == OLDNOISE_CONSTANT_ONE)
	{
		return 1.0;
	}
	else if(param.type == OLDNOISE_PERLIN)
	{
		return param.noise_scale*noise3d_perlin(x,y,z, param.seed,
				param.octaves,
				param.persistence);
	}
	else if(param.type == OLDNOISE_PERLIN_ABS)
	{
		return param.noise_scale*noise3d_perlin_abs(x,y,z, param.seed,
				param.octaves,
				param.persistence);
	}
	else if(param.type == OLDNOISE_PERLIN_CONTOUR)
	{
		return contour(param.noise_scale*noise3d_perlin(x,y,z,
				param.seed, param.octaves,
				param.persistence));
	}
	else if(param.type == OLDNOISE_PERLIN_CONTOUR_FLIP_YZ)
	{
		return contour(param.noise_scale*noise3d_perlin(x,z,y,
				param.seed, param.octaves,
				param.persistence));
	}
	else assert(0);
}
Ejemplo n.º 16
0
/******************************************************************
 * Fonctions secondaires appelées lors de l'extraction de la moelle
 ******************************************************************/
uiCoord2D PithExtractor::transHough(const Slice &slice, int width, int height, int *x, int *y, int *sliceMaxValue, int *nbContourPoints) const
{
	int x_accu, y_accu, longueur, min;
	int *droite;
	Slice *tabaccu;
	arma::fmat *orientation, *cont;
	uiCoord2D coordmax;
	orientation = 0;
	{ // bloc de limitation de vie de la variable voisinage
		// attention x represente les colonne et y les lignes
		const Slice &voisinage = slice.submat( *y, *x, (uint)( (*y)+height-1 ), (uint)( (*x)+width-1 ) );
		cont = contour(voisinage, &orientation);
	}
	tabaccu = new Slice(width, height);
	tabaccu->zeros();
	//verifie orientation et table d'accumlation tous les points se trouvent a 0
	*nbContourPoints = 0;
	for(uint i=0; i<cont->n_rows; i++){
		for(uint j=0; j<cont->n_cols; j++){
			if((*cont)(i,j) == 1){
				*nbContourPoints += 1;
				droite = drawLine(j, i, (*orientation)(i,j), width, height, &longueur);
				for(int k=0; k<longueur; k++){
					y_accu = droite[k]/width;
					x_accu = droite[k]-(y_accu*width);
					(*tabaccu) (y_accu, x_accu) ++;
				}
				delete [] droite;
			}
		}
	}
	// std::cerr << "nbptcontour=" << * nbptcontour << "\n";
	delete cont;
	delete orientation;

	//min et max globaux
	min = *sliceMaxValue = (*tabaccu)(0,0);
	coordmax.x = coordmax.y = 0;

	minSlice(*tabaccu, &min, sliceMaxValue, &coordmax);

	delete tabaccu;

	*x += coordmax.x;
	*y += coordmax.y;

	return uiCoord2D(*x, *y);
}
Ejemplo n.º 17
0
QuadTreeNodeData::REGION_INTERSECTION_FLAG QuadTree::region_intersection(const iterator_base & it,
    const std::vector<RS_Vector > & region_contour )
{

  if(region_contour.size()<2) return QuadTreeNodeData::OUT_REGION;

  const RS_Vector * _p_tr = it->tr();
  const RS_Vector * _p_tl = it->tl();
  const RS_Vector * _p_br = it->br();
  const RS_Vector * _p_bl = it->bl();

  //for rubset reasion
  double eps = (*_p_tr - * _p_tl).x/100;

  Poly leaf(Point(_p_bl->x, _p_bl->y));
  leaf.add (Point(_p_br->x, _p_br->y));
  leaf.add (Point(_p_tr->x, _p_tr->y));
  leaf.add (Point(_p_tl->x, _p_tl->y));

  Poly leaf_large(Point(_p_bl->x-eps, _p_bl->y-eps));
  leaf_large.add (Point(_p_br->x+eps, _p_br->y-eps));
  leaf_large.add (Point(_p_tr->x+eps, _p_tr->y+eps));
  leaf_large.add (Point(_p_tl->x-eps, _p_tl->y+eps));

  Poly contour(Point(region_contour[0].x, region_contour[0].y));
  for(unsigned int n=1; n<region_contour.size(); ++n)
    contour.add(Point(region_contour[n].x, region_contour[n].y));

  if(intersect(leaf_large, contour))
  {
    return QuadTreeNodeData::INTERSECTION_REGION;
  }

  // no intersection point?
  if(contour.has_point(Point(_p_bl->x, _p_bl->y)) && contour.has_point(Point(_p_tr->x, _p_tr->y)))
  {
    //assert(fabs(contour.area()) >= leaf.area());
    return QuadTreeNodeData::IN_REGION;
  }

  if(leaf_large.has_point(Point(region_contour[0].x, region_contour[0].y)))
  {
    //assert(leaf.area() >= fabs(contour.area()));
    return QuadTreeNodeData::COVER_REGION;
  }

  return QuadTreeNodeData::OUT_REGION;
}
Ejemplo n.º 18
0
// Detects fruits from frame and updates their positions in arrays
void fruitProcessing(IplImage* frame) {
    IplImage* imgYellowThresh = fruitDetect(frame);

    // Process image
    IplImage* con = contour(imgYellowThresh);   //running contour on yellow thresholded image

    // Debug start
    // fruitCount is no. of objects (fruits) in image
    printf("\nNo. of objects detected: %d", fruitCount);
    for(int idx = 0; idx < fruitCount ; idx ++) {
        printf("\nObj #%d: (%d, %d)", idx, centers[idx].x, centers[idx].y);
    }
    
    cvReleaseImage(&imgYellowThresh);
    cvReleaseImage(&con);
}
Ejemplo n.º 19
0
 void ContourAreaTest::testAllocate1()
 {
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer contour(new cvsupport::Matrix("points_i32.npy"));
     
     m_operator->setInputData(ContourArea::INPUT_CONTOUR, contour);
     
     runtime::DataContainer areaResult = m_operator->getOutputData(ContourArea::OUTPUT_AREA);
     
     runtime::ReadAccess areaAccess(areaResult);
     std::ofstream areaFile;
     areaFile.open("ContourAreaTest_testAllocate1_area.txt");
     areaFile << areaAccess.get<runtime::Float64>();
     areaFile.close();
 }
Ejemplo n.º 20
0
int sobelFilter(byte *rgb, byte **gray, byte **sobel_h_res, byte **sobel_v_res, byte **contour_img, int width, int height) {
    int sobel_h[] = {-1, 0, 1, -2, 0, 2, -1, 0, 1},
        sobel_v[] = {1, 2, 1, 0, 0, 0, -1, -2, -1};

    int rgb_size = width*height*3;

    // Get gray representation of the image
    int gray_size = rgbToGray(rgb, gray, rgb_size);

    // Make sobel operations
    itConv(*gray, gray_size, width, sobel_h, sobel_h_res);
    itConv(*gray, gray_size, width, sobel_v, sobel_v_res);

    // Calculate contour matrix
    contour(*sobel_h_res, *sobel_v_res, gray_size, contour_img);

    return gray_size;
}
Ejemplo n.º 21
0
/////////////////////////////////////////////////////////////////////////////
// Contour plot of true probability
/////////////////////////////////////////////////////////////////////////////
void CTikZTwoD::Contour(const CArtificialProblem &problem, int Levels) const
{
 *pout << "\\begin{scope}[Contour]\n";

 CAPSurface surf(problem);
 CContour contour(surf);
 contour.SetBounds(-1.0, 1.0, -1.0, 1.0);
 contour.SetGridSize(ContourResolution, ContourResolution);

 for (int i = 1; i < Levels; i++)
 {
  double x = double(i) / double(Levels);
  contour.SetLevel(x);
  contour.PlotLines(*pout, SplineD, Scale);
 }

 *pout << "\\pgfusepathqstroke\n";
 *pout << "\\end{scope}\n";
}
PointCloudPtr ContourGenerator::getContour(const std::vector<CoordinateT > &coordinates)
{
    PointCloudPtr contour(new PointCloud);
    for (int i = 0; i < coordinates.size(); i++)
    {
        PointT start_point;
        start_point.x = coordinates.at(i).at(0);
        start_point.y = coordinates.at(i).at(1);
        start_point.z = 0.0;

        PointT end_point;
        if (i < coordinates.size() - 1)
        {
            end_point.x = coordinates.at(i + 1).at(0);
            end_point.y = coordinates.at(i + 1).at(1);
            end_point.z = 0.0;
        }
        else
        {
            end_point.x = coordinates.at(0).at(0);
            end_point.y = coordinates.at(0).at(1);
            end_point.z = 0.0;
        }

        int num_steps_per_segment = 40;
        double x_step_size = (end_point.x - start_point.x) / num_steps_per_segment;
        double y_step_size = (end_point.y - start_point.y) / num_steps_per_segment;

        for (int j = 0; j < num_steps_per_segment; j++)
        {
            PointT point;
            point.x = start_point.x + (j * x_step_size);
            point.y = start_point.y + (j * y_step_size);
            point.z = 0.0;
            contour->points.push_back(point);
        }
    }
    contour->width = contour->points.size();
    contour->height = 1;
    return contour;
}
Ejemplo n.º 23
0
    virtual void on_draw()
    {
        typedef agg::renderer_base<agg::pixfmt_bgr24> ren_base;

        agg::pixfmt_bgr24 pixf(rbuf_window());
        ren_base renb(pixf);
        renb.clear(agg::rgba(1, 1, 1));

        agg::rasterizer_scanline_aa<> ras;
        agg::scanline_p8 sl;

        agg::trans_affine mtx;
        mtx *= agg::trans_affine_scaling(4.0);
        mtx *= agg::trans_affine_translation(150, 100);


        agg::conv_transform<agg::path_storage> trans(m_path, mtx);
        agg::conv_curve<agg::conv_transform<agg::path_storage> > curve(trans);

        agg::conv_contour
            <agg::conv_curve
                <agg::conv_transform
                    <agg::path_storage> > > contour(curve);

        contour.width(m_width.value());
        //contour.inner_join(agg::inner_bevel);
        //contour.line_join(agg::miter_join);
        //contour.inner_line_join(agg::miter_join);
        //contour.inner_miter_limit(4.0);
        contour.auto_detect_orientation(m_auto_detect.status());

        compose_path();
        ras.add_path(contour);
        agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0,0,0));

        agg::render_ctrl(ras, sl, renb, m_close);
        agg::render_ctrl(ras, sl, renb, m_width);
        agg::render_ctrl(ras, sl, renb, m_auto_detect);
    }
Ejemplo n.º 24
0
float CLevelGraph::distance(const Fvector &position, const CLevelGraph::CVertex *vertex) const
{
	SContour				_contour;
	contour					(_contour,vertex);

	// calculate minimal distance
	float					best,dist;
	best					= distance(position,_contour.v1,_contour.v2);
	dist					= distance(position,_contour.v2,_contour.v3);
	if (dist < best)
		best				= dist;

	dist					= distance(position,_contour.v3,_contour.v4);
	if (dist < best)
		best				= dist;

	dist					= distance(position,_contour.v4,_contour.v1);
	if (dist < best)
		best				= dist;

	return					(best);
}
Ejemplo n.º 25
0
    void DisplayProblem2D::DISPLAY()
    {
      if (status != NOT_READY)
	{
	  size_t nruns = bopt_model->getParameters()->n_iterations;
	  title("Press r to run and stop, s to run a step and q to quit.");
	  contour(cX,cY,cZ,50);                         // Contour plot (50 lines)
	  plot(cx,cy);set("g");set("o");set(4);         // Data points as black star
	  plot(solx,soly);set("r"); set("o");set(4);    // Solutions as red points
	  
	  if ((status != STOP) && (state_ii < nruns))
	    {
	      // We are moving. Next iteration
	      ++state_ii;
	      bopt_model->stepOptimization(); 
	      const vectord last = bopt_model->getData()->getLastSampleX();
	      //GP subplot
	      cx[0] = last(0);
	      cy[0] = last(1);
	      
	      if (!lx.empty())
		{	
		  plot(lx,ly);set("k");set("o");set(4);         // Data points as black star
		}
	      
	      lx.push_back(last(0));
	      ly.push_back(last(1));
	      
	      if (status == STEP) { status = STOP; }
	    }	    
	  else
	    {
	      plot(lx,ly);set("k");set("o");set(4);         // Data points as black star
	    }
	  
	}
    };
Ejemplo n.º 26
0
float CLevelGraph::farthest_vertex_in_direction(u32 start_vertex_id, const Fvector &start_point, const Fvector &finish_point, u32 &finish_vertex_id, xr_vector<bool> *tpaMarks, bool check_accessability) const
{
	SContour				_contour;
	const_iterator			I,E;
	int						saved_index, iPrevIndex = -1, iNextNode;
	Fvector					temp_point = start_point;
	float					fDistance = start_point.distance_to(finish_point), fCurDistance = 0.f;
	u32						dwCurNode = start_vertex_id;

	while (!inside(vertex(dwCurNode),finish_point) && (fCurDistance < (fDistance + EPS_L))) {
		begin				(dwCurNode,I,E);
		saved_index			= -1;
		contour				(_contour,dwCurNode);
		for ( ; I != E; ++I) {
			iNextNode		= value(dwCurNode,I);
			if (valid_vertex_id(iNextNode) && (iPrevIndex != iNextNode))
				choose_point(start_point,finish_point,_contour, iNextNode,temp_point,saved_index);
		}

		if (saved_index > -1) {
			if (check_accessability && !is_accessible(saved_index))
				return		(fCurDistance);

			fCurDistance	= start_point.distance_to_xz(temp_point);
			iPrevIndex		= dwCurNode;
			dwCurNode		= saved_index;
		}
		else
			return			(fCurDistance);

		if (tpaMarks)
			(*tpaMarks)[dwCurNode]	= true;
		finish_vertex_id	= dwCurNode;
	}
	return					(fCurDistance);
}
Ejemplo n.º 27
0
void CavesNoiseIntersection::generateCaves(MMVManip *vm,
	v3s16 nmin, v3s16 nmax, u8 *biomemap)
{
	assert(vm);
	assert(biomemap);

	noise_cave1->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z);
	noise_cave2->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z);

	v3s16 em = vm->m_area.getExtent();
	u32 index2d = 0;

	for (s16 z = nmin.Z; z <= nmax.Z; z++)
	for (s16 x = nmin.X; x <= nmax.X; x++, index2d++) {
		bool column_is_open = false;  // Is column open to overground
		bool is_under_river = false;  // Is column under river water
		bool is_tunnel = false;  // Is tunnel or tunnel floor
		u32 vi = vm->m_area.index(x, nmax.Y, z);
		u32 index3d = (z - nmin.Z) * m_zstride_1d + m_csize.Y * m_ystride +
			(x - nmin.X);
		// Biome of column
		Biome *biome = (Biome *)m_bmgr->getRaw(biomemap[index2d]);

		// Don't excavate the overgenerated stone at nmax.Y + 1,
		// this creates a 'roof' over the tunnel, preventing light in
		// tunnels at mapchunk borders when generating mapchunks upwards.
		// This 'roof' is removed when the mapchunk above is generated.
		for (s16 y = nmax.Y; y >= nmin.Y - 1; y--,
				index3d -= m_ystride,
				vm->m_area.add_y(em, vi, -1)) {

			content_t c = vm->m_data[vi].getContent();
			if (c == CONTENT_AIR || c == biome->c_water_top ||
					c == biome->c_water) {
				column_is_open = true;
				continue;
			} else if (c == biome->c_river_water) {
				column_is_open = true;
				is_under_river = true;
				continue;
			}
			// Ground
			float d1 = contour(noise_cave1->result[index3d]);
			float d2 = contour(noise_cave2->result[index3d]);

			if (d1 * d2 > m_cave_width && m_ndef->get(c).is_ground_content) {
				// In tunnel and ground content, excavate
				vm->m_data[vi] = MapNode(CONTENT_AIR);
				is_tunnel = true;
			} else {
				// Not in tunnel or not ground content
				if (is_tunnel && column_is_open &&
						(c == biome->c_filler || c == biome->c_stone)) {
					// Tunnel entrance floor
					if (is_under_river)
						vm->m_data[vi] = MapNode(biome->c_riverbed);
					else
						vm->m_data[vi] = MapNode(biome->c_top);
				}

				column_is_open = false;
				is_tunnel = false;
			}
		}
	}
}
Ejemplo n.º 28
0
int xmain( int argc, char* argv[] )
{
    StoreCmdArgs( argc, argv );
    ConfigFile cf( "pol.cfg" );
    ConfigElem elem;

    cf.readraw( elem );

    config.uo_datafile_root = elem.remove_string( "UoDataFileRoot" );
    config.uo_datafile_root = normalized_dir_form( config.uo_datafile_root );

	unsigned short max_tile = elem.remove_ushort( "MaxTileID", 0x3FFF );

	if (max_tile != 0x3FFF && max_tile != 0x7FFF)
		config.max_tile_id = 0x3FFF;
	else
		config.max_tile_id = max_tile;

	if (argc <= 1)
		return Usage(1);

    if (argv[1][0] == '/' || argv[1][1] == ':')
    {
        config.uo_datafile_root = argv[1];
        --argc;
        ++argv;
    }

	if (stricmp( argv[1], "tiledump" ) == 0)
	{
		return tiledump( argc, argv );
	}
	else if (stricmp( argv[1], "vertile" ) == 0)
	{
		return vertile( argc, argv );
	}
    else if (stricmp( argv[1], "verlandtile" ) == 0)
    {
        return verlandtile( argc, argv );
    }
    else if (stricmp( argv[1], "landtilehist" ) == 0)
    {
        return landtilehist( argc, argv );
    }
	else if (stricmp( argv[1], "flagsearch" ) == 0)
	{
		return flagsearch( argc, argv );
	}
	else if (stricmp( argv[1], "landtileflagsearch" ) == 0)
	{
		return landtileflagsearch( argc, argv );
	}
    else if (stricmp( argv[1], "loschange" ) == 0)
    {
        return loschange( argc, argv );
    }
	else if (stricmp( argv[1], "rawdump" ) == 0)
	{
		return rawdump( argc, argv );
	}
    else if (stricmp( argv[1], "ctable" ) == 0)
    {
        return print_ctable();
    }
    else if (stricmp( argv[1], "sndlist" ) == 0)
    {
        return print_sndlist(argc, argv);
    }
    else if (stricmp( argv[1], "statics" ) == 0)
    {
        return print_statics();
    }
    else if (stricmp( argv[1], "verdata" ) == 0)
    {
        return print_verdata_info();
    }
    else if (stricmp( argv[1], "multis" ) == 0)
    {
        return print_multis();
    }
    else if (stricmp( argv[1], "water" ) == 0)
    {
        return print_water_data();
    }
    else if (stricmp( argv[1], "newstatics" ) == 0)
    {
        return write_pol_static_files( "main" );
    }
    else if (stricmp( argv[1], "staticsmax" ) == 0)
    {
        void staticsmax();
        open_uo_data_files();
        staticsmax();
        return 0;
    }
    else if (stricmp( argv[1], "watersearch" ) == 0)
    {
        return water_search(argc,argv);
    }
    else if (stricmp( argv[1], "zhist" ) == 0)
    {
        return z_histogram();
    }
    else if (stricmp( argv[1], "staticshist" ) == 0)
    {
        return statics_histogram();
    }
    else if (stricmp( argv[1], "writedungmap" ) == 0)
    {
        return write_polmap();
    }
    else if (stricmp( argv[1], "writekeys" ) == 0)
    {
        printf( "Keys written to current.key" );
        return 0;
    }
    else if (stricmp( argv[1], "mapdump" ) == 0)
    {
        return mapdump( argc, argv );
    }
    else if (stricmp( argv[1], "contour" ) == 0)
    {
        return contour( argc, argv );
    }
    else if (stricmp( argv[1], "findlandtile" ) == 0)
    {
        return findlandtile( argc-1, argv+1 );
    }
	else if (stricmp( argv[1], "findlandtileflags" ) == 0)
	{
		return findlandtileflags( argc-1, argv+1 );
	}
    else if (stricmp( argv[1], "findgraphic" ) == 0)
    {
        return findgraphic( argc-1, argv+1 );
    }
    else if (stricmp( argv[1], "defragstatics" ) == 0)
    {
        return defragstatics( argc-1, argv+1 );
    }
    
	return 0;
}
void mitk::ContourModelSubDivisionFilter::GenerateData()
{
  mitk::ContourModel::Pointer input = const_cast<mitk::ContourModel *>(this->GetInput(0));

  // mitk::ContourModelSubDivisionFilter::OutputType::Pointer outputContour = this->GetOutput();

  mitk::ContourModel::Pointer contour(input);

  auto timestep = static_cast<int>(input->GetTimeSteps());

  for (int currentTimestep = 0; currentTimestep < timestep; currentTimestep++)
  {
    if (input->GetNumberOfVertices(currentTimestep) >= 4)
    {
      for (int iterations = 0; iterations < this->m_InterpolationIterations; iterations++)
      {
        auto it = contour->IteratorBegin();
        auto end = contour->IteratorEnd();

        auto first = contour->IteratorBegin();
        auto last = contour->IteratorEnd() - 1;

        // tempory contour to store result of a subdivision iteration
        mitk::ContourModel::Pointer tempContour = mitk::ContourModel::New();

        // insert subpoints
        while (it != end)
        {
          // add the current point to the temp contour
          tempContour->AddVertex((*it)->Coordinates, (*it)->IsControlPoint, currentTimestep);

          // control points for interpolation
          auto Ci = it;
          InputType::VertexIterator CiPlus1;
          InputType::VertexIterator CiPlus2;
          InputType::VertexIterator CiMinus1;

          // consider all possible cases
          if (it == first)
          {
            if (input->IsClosed(currentTimestep))
            {
              CiPlus1 = it + 1;
              CiPlus2 = it + 2;
              CiMinus1 = last;
            }
            else
            {
              CiPlus1 = it + 1;
              CiPlus2 = it + 2;
              CiMinus1 = it;
            }
          }
          else if (it == last)
          {
            if (input->IsClosed(currentTimestep))
            {
              CiPlus1 = first;
              CiPlus2 = first + 1;
              CiMinus1 = it - 1;
            }
            else
            {
              // don't add point after last
              break;
            }
          }
          else if (it == (last - 1))
          {
            if (input->IsClosed(currentTimestep))
            {
              CiPlus1 = it + 1;
              CiPlus2 = first;
              CiMinus1 = it - 1;
            }
            else
            {
              CiPlus1 = it + 1;
              CiPlus2 = it + 1;
              CiMinus1 = it - 1;
            }
          }
          else
          {
            CiPlus1 = it + 1;
            CiPlus2 = it + 2;
            CiMinus1 = it - 1;
          }

          /* F2i = Ci
          * F2i+1 = -1/16Ci-1 + 9/16Ci + 9/16Ci+1 - 1/16Ci+2
          */
          mitk::Point3D subpoint;

          mitk::Point3D a;
          a[0] = (-1.0 / 16.0) * (*CiMinus1)->Coordinates[0];
          a[1] = (-1.0 / 16.0) * (*CiMinus1)->Coordinates[1];
          a[2] = (-1.0 / 16.0) * (*CiMinus1)->Coordinates[2];

          mitk::Point3D b;
          b[0] = (9.0 / 16.0) * (*Ci)->Coordinates[0];
          b[1] = (9.0 / 16.0) * (*Ci)->Coordinates[1];
          b[2] = (9.0 / 16.0) * (*Ci)->Coordinates[2];

          mitk::Point3D c;
          c[0] = (9.0 / 16.0) * (*CiPlus1)->Coordinates[0];
          c[1] = (9.0 / 16.0) * (*CiPlus1)->Coordinates[1];
          c[2] = (9.0 / 16.0) * (*CiPlus1)->Coordinates[2];

          mitk::Point3D d;
          d[0] = (-1.0 / 16.0) * (*CiPlus2)->Coordinates[0];
          d[1] = (-1.0 / 16.0) * (*CiPlus2)->Coordinates[1];
          d[2] = (-1.0 / 16.0) * (*CiPlus2)->Coordinates[2];

          subpoint[0] = a[0] + b[0] + c[0] + d[0];
          subpoint[1] = a[1] + b[1] + c[1] + d[1];
          subpoint[2] = a[2] + b[2] + c[2] + d[2];
          InputType::VertexType subdivisionPoint(subpoint, false);

          // add the new subdivision point to our tempContour
          tempContour->AddVertex(subdivisionPoint.Coordinates, currentTimestep);

          it++;
        }

        // set the interpolated contour as the contour for the next iteration
        contour = tempContour;
      }
    }
    else
    {
      // filter not executeable - set input to output
      contour = input;
    }
  }

  // somehow the isClosed property is not set via copy constructor
  contour->SetClosed(input->IsClosed());

  this->SetNthOutput(0, contour);
}
Ejemplo n.º 30
0
void BaseVH::buildPrimitivesFromImageBoundary( int camId )
{
 
	int numsilhouettes = mSilhouetteCameras.size();

    int numCams = mCalibration->get_cam_count();
	
    mOffset[ camId ] = cv::Point2f( 0 , 0 );

	 std::vector< std::vector< cv::Point2f > > allContours;
     std::vector< cv::Vec4i > contourHierarchy;

	 std::vector< cv::Point2f > contour( 4 );

	 int w , h;

	 w = mCalibration->get_image_width( camId  );
	 h = mCalibration->get_image_height( camId  );

	 contour[ 0 ].x = 0;
	 contour[ 0 ].y = 0;
	
	 contour[ 1 ].x = 0;
	 contour[ 1 ].y = h;

	 contour[ 2 ].x = w;
	 contour[ 2 ].y = h;

	 contour[ 3 ].x = w;
	 contour[ 3 ].y = 0;

	 cv::Vec4i hr;

	 hr[ 0 ] = -1;
	 hr[ 1 ] = -1;
	 hr[ 2 ] = -1;
	 hr[ 3 ] = -1;

	allContours.push_back( contour );

	contourHierarchy.push_back( hr );

	mScale[ camId ] = 1.0;
	mInvScale[ camId ] = 1.0;
	
	
	mContourHierarchies[ camId ] = contourHierarchy;
	mObjectContours[ camId ] =  allContours;

    int numContours = mObjectContours[ camId ].size();
    int numContourPoints = 0;

    int stripId = 0;
	int contourId = 0;

    for( int contour = 0; contour < numContours; contour++ )
    {
        int numStrips =  mObjectContours[ camId ][ contour ].size();
        std::vector< Generator* > generators;

        generators.resize( numStrips );

        for( int strip = 0; strip < numStrips; strip++ )
        {
                    generators[ strip ] = new Generator();
                    generators[ strip ]->leftViewEdgeId = -1;
                    generators[ strip ]->rightViewEdgeId = -1;

                    generators[ strip ]->stripId = strip;
                    generators[ strip ]->camId = camId;
                    generators[ strip ]->contourId = contour;
                    generators[ strip ]->normalComputed = false;	    

                    stripId++;
                }
                
                for( int strip = 0; strip < numStrips; strip++ )
                {
		            generators[ strip ]->mRightGen = generators[ ( strip + 1 ) % numStrips ];
		            generators[ strip ]->mLeftGen = generators[ ( strip - 1 + numStrips ) % numStrips ];
		        }

                mGenerators[ camId ].push_back( generators );

                numContourPoints += numStrips;
                
                contourId++;
        }


	for( int contour = 0; contour < numContours; contour++ )
    {
        int numStrips =  mObjectContours[ camId ][ contour ].size();
	
        for( int strip = 0; strip < numStrips; strip++ )
        {
	       Eigen::Vector3d  ray;
	  
	       mCalibration->getRay( camId , mObjectContours[ camId ][ contour ][ strip ] , ray );
	  
	       mGenerators[ camId ][ contour ][ strip ]->leftRay = ray;
	   
           int idx = ( strip - 1 + numStrips ) % numStrips;

           mGenerators[ camId ][ contour ][ idx ]->rightRay = ray;
         }                

     } 

        

    stripId = 0;
	
	int numFilteredContours = mObjectContours[ camId ].size();

	for( int contour = 0; contour < numFilteredContours; contour++ )
    {
        stripId += mObjectContours[ camId ][ contour ].size();        
    }
        
    mStripContourMap[ camId ].resize( stripId );
	
	stripId = 0;
	
    for( int contour = 0; contour < numFilteredContours; contour++ )
    {
       int numStrips = mObjectContours[ camId ][ contour ].size();

       for( int strip = 0; strip < numStrips; strip++ )
       {
           mStripContourMap[ camId ][ stripId ].contourId = contour;
           mStripContourMap[ camId ][ stripId ].contourStripId = strip;

           stripId++;
       }

    }	  
}