Explorar o código

Merge branch 'master' of http://local.beijingyongan.com:3000/linux-dev/ya-serv

lixioayao %!s(int64=5) %!d(string=hai) anos
pai
achega
b1a9d608e2
Modificáronse 4 ficheiros con 58 adicións e 111 borrados
  1. 29 4
      ant.cpp
  2. 8 107
      card_path.cpp
  3. 10 0
      line.h
  4. 11 0
      test.cpp

+ 29 - 4
ant.cpp

@@ -160,9 +160,19 @@ void site::set_path(const std::vector<line_v>&v_line)
 
 	log_info("初始化分站路径:site_id=%d",m_id);
 
-	for(auto&a:m_ant)
+	for(int i=0,c=target.size();i<c;i++)
 	{
-		a.set_path(target);
+		log_info("path-id=%d,line=%s",i,target[i].to_string().c_str());
+	}
+
+	for(int i=0,c=m_ant.size();i<c;i++)
+	{
+		if(m_ant[i].empty())
+		{
+			log_error("分站未设置天线坐标 site_id=%d,ant_index=%d",m_id,i);
+			continue;
+		}
+		m_ant[i].set_path(target);
 	}
 	m_path_empty= !m_ant[0][0].valid() && !m_ant[0][1].valid() ;
 }
@@ -262,7 +272,10 @@ void sit_list::read_ant_path(int id)
 
 		auto site_ptr=sit_list::instance()->get(reader_id);
 		if(nullptr==site_ptr)
+		{
+			log_error("定义了分站路径,但是没有定义分站:%d",reader_id);
 			continue;
+		}
 
 		int pid=0;
 		DBRes.GetField( "tof_flag",pid, Error );
@@ -287,7 +300,9 @@ void sit_list::read_ant_path(int id)
 
 		double spacing_ratio = 0;
 		DBRes.GetField( "spacing_ratio",spacing_ratio, Error );
-		log_info("ant_path:%d,%.2f,%.2f,%.2f,%.2f",reader_id,b_x,b_y,e_x,e_y);
+
+		log_info("src-path:site=%d,x0=%.2f,y0=%.2f,x1=%.2f,y1=%.2f",reader_id,b_x,b_y,e_x,e_y);
+
 		point p1(b_x,-b_y, spacing_ratio);
 		point p2(e_x,-e_y, spacing_ratio);
 
@@ -378,12 +393,14 @@ void sit_list::read_ant_path(int id)
 	test_find_path(card_path::inst(),point(4727,-8.06),point(5427.04,-304.02));
 	test_find_path(card_path::inst(),point(4714.70,-8.06),point(5427.04,-304.02));
 	test_find_path(card_path::inst(),point(4727,-75),point(2200,-75));
+	test_find_path(card_path::inst(),point(4683.625,56.988),point(2200,-75));
 }
 
 void sit_list::init_site(int id)
 {
      std::string sql = "SELECT reader_id, reader_type_id, dat_reader.map_id, \
              area_id, device_type_id, dimension, dat_map.scale,need_power_alarm\
+			 ,x,y \
              FROM dat_reader, dat_map where \
              dat_reader.map_id=dat_map.map_id and state=0";
 
@@ -456,6 +473,13 @@ void sit_list::init_site(int id)
          site_ptr->m_dimension = dimension;
          site_ptr->m_scale = scale;
          site_ptr->create_area();
+
+
+         double x=0,y=0;
+         DBRes.GetField( "x",x, Error );
+         DBRes.GetField( "y",y, Error );
+
+		 log_info ("site-position:site=%d,x=%.2lf,y=%.2lf",reader_id,x,y);
      }
 }
 
@@ -513,6 +537,8 @@ void sit_list::read_sit_list(int id)
         double z= 0;
         DBRes.GetField( "z",z, Error );
 
+		log_info("ant-position:reader=%d,antid=%d,x=%.2lf,y=%.2lf",reader_id,antid,x,y);
+
         if(-1 == id)
         {
             std::shared_ptr<site> site_ptr=nullptr;
@@ -522,7 +548,6 @@ void sit_list::read_sit_list(int id)
             site_ptr->m_ant[antid].m_id = antenna_id;
             site_ptr->m_ant[antid].set(x,-y);
             site_ptr->set_ex();
-            log_info("reand_ant..%d,%d,%.2f,%.2f",reader_id,antid,x,y);
         }
         else
         {

+ 8 - 107
card_path.cpp

@@ -192,13 +192,13 @@ point  base_path::cross(const vertex_list&v, const base_path&o)const
 
 	return l0.crossing(l1);
 }
-void log_path(const std::vector<base_path>&path,const vertex_list&v_list)
+void log_path(const std::vector<base_path>&path,const vertex_list&v_list,const char*add_info="")
 {
 	log_info("%s\n","----------------------------------------------------------------");
 	for(int i=0,len=path.size();i<len;i++)
 	{
 		double c=path[i].arg(v_list)/PI*180;
-		log_info("base_path %.6lf, %03d,(%d,%s),(%d,%s)",c,i,path[i][0],v_list[path[i][0]].to_string().c_str(),path[i][1],v_list[path[i][1]].to_string().c_str());
+		log_info("base_path:%s %.6lf, %03d,(%d,%s),(%d,%s)",add_info,c,i,path[i][0],v_list[path[i][0]].to_string().c_str(),path[i][1],v_list[path[i][1]].to_string().c_str());
 	}
 }
 struct handle_path :visitor<std::shared_ptr<site>>
@@ -259,79 +259,7 @@ struct handle_path :visitor<std::shared_ptr<site>>
 };
 static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list&v)
 {
-//	for(uint32_t i=0;i<sites.m_list.size();i++)
-//	{
-//		auto&s=sites[i];
-//
-//		if(!s.have_valid_path())
-//			continue;
-//
-//		if(s.path(0).empty()||s.path(1).empty())
-//			continue;
-//        if(s[0].size()<2)
-//            continue;
-//        line_v l000 = s[0][0][0];
-//        line_v l010 = s[0][1][0];
-//        if(l000.is_same(l010))
-//        {
-//            printf("same....%d",s.m_id);
-//			int p0=v.add(point::min(s.path(0),s.path(1)),0,s.m_id);
-//			int p1=v.add(point::max(s.path(0),s.path(1)),0,s.m_id);
-//
-//		    ret.push_back(base_path(p0,p1));
-//			ret.back().sid=s.m_id;
-//        }
-//        else
-//        {
-//            point px = l000.line::crossing(l010);
-//            for(int i=0;i<2;i++)
-//            {
-//			    int p0=v.add(point::min(px,s.path(i)),0,s.m_id);
-//			    int p1=v.add(point::max(px,s.path(i)),0,s.m_id);
-//
-//		        ret.push_back(base_path(p0,p1));
-//			    ret.back().sid=s.m_id;
-//            }
-//        }
-//        for(int i=0;i<2;i++)
-//        {
-//            if(!s[0][i][1].empty())
-//            {
-//			    int p0=v.add(point::min(s[0][i][1][0],s[0][i][1][1]),0,s.m_id);
-//			    int p1=v.add(point::max(s[0][i][1][0],s[0][i][1][1]),0,s.m_id);
-//
-//		        ret.push_back(base_path(p0,p1));
-//			    ret.back().sid=s.m_id;
-//
-//            }
-//        }
-//    }
-
-/*
-
-		if(x.contain(s,2.5))
-		{
-			int p0=v.add(point::min(s.path(0),s.path(1)),0,s.m_id);
-			int p1=v.add(point::max(s.path(0),s.path(1)),0,s.m_id);
 
-		    ret.push_back(base_path(p0,p1));
-			ret.back().sid=s.m_id;
-			continue;
-		}
-
-		for(int j=0;j<2;j++)
-		{
-			if(!s.path(j).empty() && s.dist(s.path(j))<2)
-				continue;
-
-			point p=s.path(j);
-			int p0=v.add(point::min(s,p),0,s.m_id);
-			int p1=v.add(point::max(s,p),0,s.m_id);
-			ret.push_back(base_path(p0,p1));
-			ret.back().sid=s.m_id;
-		}
-	}
-*/
 #ifdef __DEBUG__
 	log_path(ret,v);
     printf("++++++++++++++++++++++++++++++++++++++++++++");
@@ -358,9 +286,8 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 		return arg<0;
 	});
 
-#ifdef __DEBUG__
-	log_path(ret,v);
-#endif
+	log_path(ret,v,"合并前");
+	//合并相同
 	for(int i=0,len=ret.size();i<len;i++)
 	{
 		line_v li=ret[i].as_line(v);
@@ -390,7 +317,7 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 	ret.erase(std::remove_if(ret.begin(),ret.end(),[&v](const base_path&p){
 		return p[0]==0||p[1]==0;
 	}),ret.end());
-#ifdef __DEBUG__
+
 	std::sort(ret.begin(),ret.end(),[&v](const base_path&p1,const base_path&p2){
 		double arg=p1.arg(v)-p2.arg(v);
 
@@ -402,8 +329,7 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 		return arg<0;
 	});
 
-	log_path(ret,v);
-#endif
+	log_path(ret,v,"合并后");
 
 	//非路径交点配置
 	std::vector<point> no_cross;
@@ -492,35 +418,12 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 		point&p1=v[p[1]];
 
 		//return p0.dist(p1)<0.1 || p0.empty() || p1.empty();
-		return p0.dist(p1)<0.1;
+		return p0.dist(p1)<1;
 	}),ret2.end());
 
 	std::sort(ret2.begin(),ret2.end());
 	ret2.erase(std::unique(ret2.begin(),ret2.end()),ret2.end());
 
-/*
-	ret.clear();
-	for(int i=0,len=ret2.size();i<len;i++)
-	{
-		std::vector<line_v> tmp;
-		tmp.push_back(ret2[i].as_line(v));
-		for(int j=0;j<len;j++)
-		{
-			if(i==j) continue;
-
-			if(ret[j].level(v)<ret[i].level(v))
-				continue;
-
-			line l1=ret2[j].as_line(v);
-		}
-	}
-
-	std::sort(ret2.begin(),ret2.end(),[&v](base_path&p1,base_path&p2){
-		return p1.arg(v)<p2.arg(v);
-	});
-	*/
-
-#ifdef __DEBUG__
 	std::sort(ret2.begin(),ret2.end(),[&v](const base_path&p1,const base_path&p2){
 		double arg=p1.arg(v)-p2.arg(v);
 
@@ -531,9 +434,7 @@ static std::vector<base_path> init_path(std::vector<base_path> & ret,vertex_list
 
 		return arg<0;
 	});
-
-#endif
-	log_path(ret2,v);
+	log_path(ret2,v,"拆分后");
 
 	return std::move(ret2);
 }

+ 10 - 0
line.h

@@ -137,6 +137,16 @@ struct line_v:line//线段
 		v[1]=p1;
         recalc();
 	}
+
+	line_v widen(double length) const
+	{
+		
+		point pt1(v[0].x-length*cos(),v[0].y-length*sin());
+		point pt2(v[1].x+length*cos(),v[1].y+length*sin());
+
+		return line_v(pt1,pt2);
+	}
+
 	void swap_point()
 	{
 		point tmp=v[0];

+ 11 - 0
test.cpp

@@ -320,6 +320,17 @@ int main()
 	uint64_t x=now*1000LL;
 	std::cout<<now<<"|||"<<x<<std::endl;
 
+	line_v l1(point(0,0),point(10,0));
+	std::cout<<l1.widen(1).to_string()<<x<<std::endl;
+
+	line_v l2(point(10,0),point(0,0));
+	std::cout<<l2.widen(1).to_string()<<x<<std::endl;
+
+	line_v l3(point(0,0),point(10,10));
+	std::cout<<l3.widen(1).to_string()<<x<<std::endl;
+
+	line_v l4(point(0,0),point(-10,10));
+	std::cout<<l4.widen(1).to_string()<<x<<std::endl;
 
 
 	help_bit=0;