コード例 #1
0
MapgenSinglenode::MapgenSinglenode(int mapgenid,
	MapgenParams *params, EmergeManager *emerge)
	: Mapgen(mapgenid, params, emerge)
{
	const NodeDefManager *ndef = emerge->ndef;

	c_node = ndef->getId("mapgen_singlenode");
	if (c_node == CONTENT_IGNORE)
		c_node = CONTENT_AIR;

	MapNode n_node(c_node);
	set_light = (ndef->get(n_node).sunlight_propagates) ? LIGHT_SUN : 0x00;
}
コード例 #2
0
ファイル: mapgen_singlenode.cpp プロジェクト: 0151n/minetest
void MapgenSinglenode::makeChunk(BlockMakeData *data) {
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		   data->blockpos_requested.Y >= data->blockpos_min.Y &&
		   data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		   data->blockpos_requested.Y <= data->blockpos_max.Y &&
		   data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm   = data->vmanip;	
	this->ndef = data->nodedef;
			
	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;

	// Area of central chunk
	v3s16 node_min = blockpos_min*MAP_BLOCKSIZE;
	v3s16 node_max = (blockpos_max+v3s16(1,1,1))*MAP_BLOCKSIZE-v3s16(1,1,1);

	content_t c_node = ndef->getId("mapgen_singlenode");
	if (c_node == CONTENT_IGNORE)
		c_node = CONTENT_AIR;
	
	MapNode n_node(c_node);
	
	for (s16 z = node_min.Z; z <= node_max.Z; z++)
	for (s16 y = node_min.Y; y <= node_max.Y; y++) {
		u32 i = vm->m_area.index(node_min.X, y, z);
		for (s16 x = node_min.X; x <= node_max.X; x++) {
			if (vm->m_data[i].getContent() == CONTENT_IGNORE)
				vm->m_data[i] = n_node;
			i++;
		}
	}

	// Add top and bottom side of water to transforming_liquid queue
	updateLiquid(&data->transforming_liquid, node_min, node_max);

	// Calculate lighting
	if (!(flags & MG_NOLIGHT))
		calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
					 node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
	
	this->generating = false;
}
コード例 #3
0
void MapgenSinglenode::makeChunk(BlockMakeData *data)
{
	// Pre-conditions
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		data->blockpos_requested.Y >= data->blockpos_min.Y &&
		data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		data->blockpos_requested.Y <= data->blockpos_max.Y &&
		data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm   = data->vmanip;
	this->ndef = data->nodedef;

	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;

	// Area of central chunk
	v3s16 node_min = blockpos_min * MAP_BLOCKSIZE;
	v3s16 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = getBlockSeed2(node_min, data->seed);

	MapNode n_node(c_node);

	for (s16 z = node_min.Z; z <= node_max.Z; z++)
	for (s16 y = node_min.Y; y <= node_max.Y; y++) {
		u32 i = vm->m_area.index(node_min.X, y, z);
		for (s16 x = node_min.X; x <= node_max.X; x++) {
			if (vm->m_data[i].getContent() == CONTENT_IGNORE)
				vm->m_data[i] = n_node;
			i++;
		}
	}

	// Add top and bottom side of water to transforming_liquid queue
	updateLiquid(&data->transforming_liquid, node_min, node_max);

	// Set lighting
	if ((flags & MG_LIGHT) && set_light == LIGHT_SUN)
		setLighting(LIGHT_SUN, node_min, node_max);

	this->generating = false;
}
コード例 #4
0
ファイル: CControl.cpp プロジェクト: junwangcas/Taxi
void CControl::TreeGrowing(TreeType::iterator n_Iterator,CTreeTracker& n_treetracker,int n_depth)
{
  //++++++++++++++++++++++++++++++++++++++
  // Iterator Function
  RotatedRect n_RectCenter=n_Iterator->mRect;
  int n_neighbour[5]={0,1,-1,2,-2};
  int n_neighbours=0;
  for(int i=0;i<n_depth;i++)
    cout<<"+";
  cout<<endl;
  for(int i=0;i<5;i++)
    {
      //get next points
      Point2f n_pt=GetNextPt(n_RectCenter.center,n_RectCenter.angle,nControlOptions.nSteps);
      //get the next angle
      float n_angle=n_RectCenter.angle+n_neighbour[i]*45;
      //get the next rotatedrect
      RotatedRect n_RectNeighbour;
      if(!GetRotatedRect(n_pt,n_angle,n_RectNeighbour))
	continue;
      //check if overlay in temp spatial index;
      if(n_treetracker.CheckOverLay(n_RectNeighbour))
	continue;
      //check if overlay in gloable spatial index;

      //get subsetimg;
      Mat n_img=GetSubsetImg(n_RectNeighbour);
      //get lines in all direction;
      nLineSegExtractor.SetParamters(n_img);
      vector<Point2f> n_linevct=nLineSegExtractor.GetLineSegments();
      //get lines in specific direction
      vector<Point2f> n_filterlinevct;
      FilterLineAngle(n_linevct,n_filterlinevct,0,nControlOptions.nAngleThhold);
      //get ransac lines;
      vector<Point3f> n_linecoef;
      nRansacExtractor.GetRansacLines(n_linecoef,n_filterlinevct,nControlOptions.nInterval,nControlOptions.nRansacThreshold,nControlOptions.nRansacMininlier);
      if(nIfDebug)
	{
	  //	  cout<<"angle: "<<n_angle<<' '<<"threshold: "<<nControlOptions.nAngleThhold<<endl;
	  //	  cout<<"get filter line: "<<n_filterlinevct.size()<<endl;
	  //	  cout<<"get ransac lines: "<<n_linecoef.size()<<endl;
	  //   Draw_debug;
	  // draw n_filterlinevct;
	  char* n_windowname1="2";
	  Draw_debug(n_img,n_filterlinevct,n_windowname1);
	  //draw all lines
	  char* n_windowname2="1";
	  Draw_debug(n_img,n_linevct,n_windowname2);
      	}	    
      //evaluate pass direction;
      CEvaluate n_evaluate;
      n_evaluate.SetLines(n_linecoef,n_filterlinevct);
      n_evaluate.GetNearestLines(5);
      float n_score=GetWeightedScore(n_evaluate.GetDensityVal(),n_evaluate.GetLengthVal(),n_RectNeighbour.size.width);

      //in the turning directions,we should add **  information
      float n_score2=0;
      if(i!=0)
	{
	  //get lines in vertical direction
	  vector<Point2f> n_filterlinevct2;
	  FilterLineAngle(n_linevct,n_filterlinevct2,90,nControlOptions.nAngleThhold);
	  //get ransac lines;
	  vector<Point3f> n_linecoef2;
	  nRansacExtractor.GetRansacLines(n_linecoef2,n_filterlinevct2,nControlOptions.nInterval,nControlOptions.nRansacThreshold,nControlOptions.nRansacMininlier);
	  if(nIfDebug)
	    {
	      //	      cout<<"get vertical filter line: "<<n_filterlinevct2.size()<<endl;
	      //	      cout<<"get vertical ransac lines: "<<n_linecoef2.size()<<endl;
	      //   Draw_debug;
	      // draw n_filterlinevct;
	      char* n_windowname1="vertical lines";
	      Draw_debug(n_img,n_filterlinevct2,n_windowname1);
	    }	    
	  //evaluate vertical situation;
	  CEvaluate n_evaluate2;
	  n_evaluate2.SetLines(n_linecoef2,n_filterlinevct2);
	  n_evaluate2.GetNearestLines(5);
	  n_score2=GetWeightedScore(n_evaluate2.GetDensityVal(),n_evaluate2.GetLengthVal(),n_RectNeighbour.size.height);
	  //draw vertical direction rectangles.
	  n_evaluate2.Draw_debug(n_img,"VerticalDirection");
	}
      
      if(nIfDebug)
	{
	  cout<<"score1:"<<n_score<<" score2:"<<n_score2<<endl;
	  //draw rotated rect on gloable img
	  char* n_windowname3="gloable";
	  Point2f n_vertices[4];
	  n_RectNeighbour.points(n_vertices);
	  Draw_debug(nImgRaw,n_vertices,n_windowname3);
	  //draw pass direction rectangles 
	  n_evaluate.Draw_debug(n_img,"PassDirection");
	  waitKey(0);
	}
      n_score-=n_score2;
      if(n_score>nControlOptions.mEvaluateThreshold)
	{
	  //do something;
	  //insert into tree;
	  StrctRoadNode n_node(n_RectNeighbour);
	  TreeType::iterator n_it2;
	  if(!n_treetracker.Insert(n_Iterator,n_node,n_it2))
	    continue;
	  //add into spatial tree
	  n_treetracker.AddSpatialIdx(n_RectNeighbour,1);
	  //grow tree using iterate;
	  n_neighbours++;
	  //draw all path rectangles in gloable img
	  if(nIfDebug)
	    {
	      Draw_debug(nImgRaw,n_treetracker.GetPathRect(n_it2),"gloable2");
	      waitKey(0);
	    }
	  //  n_evaluate.Draw_debug_gloable(nImgRaw,
	  //  Draw_debug(nImgRaw,
	  //reduce case;
	  TreeGrowing(n_it2,n_treetracker,n_depth+1);
	}	
      
    }
  //if no neighour exist,then add end point for traverse
  if(n_neighbours==0)
    n_treetracker.InsertEndNode(n_Iterator);
}
コード例 #5
0
ファイル: CControl.cpp プロジェクト: junwangcas/Taxi
void CControl::run_debug()
{
  cout<<"processing..."<<endl;
  float n_total=(float)nImgRaw.rows;
  cout<<nImgRaw.rows<<' '<<nImgRaw.cols<<endl;
  for(int i=0;i<nImgRaw.rows;)
    { 
      cout<<(float)i/n_total*100<<"%"<<endl;
      for(int j=0;j<nImgRaw.cols;j+=nControlOptions.nSteps)
	{
	  //seeking for a seed point;
	  Point2i n_pt(j,i);
	  cout<<endl<<"new Location++++++++++++++++++++++++"<<endl;
	  //get the seed rectangles,8 bins
	  vector<float> n_rotateangles=GetRotateAngles(8);
	  vector<RotatedRect> n_rotatedrectvct=GetRotatedRect(n_pt,n_rotateangles);
	  //for every rectangle, declare a tree tracking class
	  for(int k=0;k<n_rotatedrectvct.size();k++)
	    {
	      RotatedRect n_rect=n_rotatedrectvct.at(k);
	      cout<<"new direction++++++"<<endl;
	      //check if overlay in gloable spatial index;

	      Mat n_img=GetSubsetImg(n_rect);
	
	      //tracking tree;
	      CTreeTracker n_treetracker;
	      StrctRoadNode n_node(n_rect);

	      //get angle. anglethreshold.
	      float n_angle=n_rect.angle;
	    
	      //get lines in all direction;
	      nLineSegExtractor.SetParamters(n_img);
	      vector<Point2f> n_linevct=nLineSegExtractor.GetLineSegments();
	     
	      //get lines in specific direction
	      vector<Point2f> n_filterlinevct;
	      FilterLineAngle(n_linevct,n_filterlinevct,n_angle,nControlOptions.nAngleThhold);

	      //get ransac lines;
	      vector<Point3f> n_linecoef;
	      nRansacExtractor.GetRansacLines(n_linecoef,n_filterlinevct,nControlOptions.nInterval,nControlOptions.nRansacThreshold,nControlOptions.nRansacMininlier);
	      if(nIfDebug)
		{
		  //	  cout<<"angle: "<<n_angle<<' '<<"threshold: "<<nControlOptions.nAngleThhold<<endl;
		  //		  cout<<"get filter line: "<<n_filterlinevct.size()<<endl;
		  //	  cout<<"get ransac lines: "<<n_linecoef.size()<<endl;
		  //   Draw_debug;
		  //local img;
		  Draw_debug(n_img,n_filterlinevct,"2");
		  Draw_debug(n_img,n_linevct,"1");
		  //gloable img
		  Point2f n_vertices[4];
		  n_rect.points(n_vertices);
		  Draw_debug(nImgRaw,n_vertices,"gloable");
		}	    

	      //evaluate;
	      CEvaluate n_evaluate;
	      n_evaluate.SetLines(n_linecoef,n_filterlinevct);
	      n_evaluate.GetNearestLines(5);
	      float n_score=GetWeightedScore(n_evaluate.GetDensityVal(),n_evaluate.GetLengthVal(),n_rect.size.width);
	      if(nIfDebug)
		{
		  cout<<"n_score: "<<n_score<<endl;
		  n_evaluate.Draw_debug(n_img,"PassDirection");
		  waitKey(0);
		}
	      if(n_score>nControlOptions.mEvaluateThreshold)
		{
		  //do something;
		  //insert into tree; and check if success;
		  TreeType::iterator n_it;
		  if(!n_treetracker.SetRootNode(n_node,n_it))
		    continue;
		  //add into spatial tree
		  n_treetracker.AddSpatialIdx(n_rect,1);
		  //
		  //grow tree using iterate;
		  TreeGrowing(n_it,n_treetracker,1);
		  //	  waitKey(0);
		}		
	    }
	}
      i+=nControlOptions.nSteps;
    }
}