Exemple #1
0
//======================================================================
void LOSManager::init(){
  string shpFileName = "sdo_building.shp";
  string dbfFileName = "sdo_building.dbf";
  
  // ファイルを読み込んで建造物の形状データを作成
  _readFiles(shpFileName, dbfFileName);

  // ルートとなる四分木
  QuadTree* qt = new QuadTree(0,0);
  qt->set(_adfMinBounds[0], _adfMaxBounds[0],
	  _adfMinBounds[1], _adfMaxBounds[1]);
  GeoManager::addTree(qt);

  // ポリゴンを四分木に登録
  for (int i=0; i<_numPolygons; i++) {
    qt->pushQuadTree(GeoManager::polygon(i), i, 0, GeoManager::trees());
  }
}
Exemple #2
0
//======================================================================
void LOSManager::calcVehicleLOS(vector<Vehicle*>* vehicles){
  // これまでの車体用四分木を消去
  GeoManager::deleteVTrees();
  for (int i=0; i<MAX_VEHICLES*MAX_VEHICLES; i++) {
    _los[i] = 0;
  }

  QuadTree* vqt = new QuadTree();
  vqt->set(_adfMinBounds[0], _adfMaxBounds[0],
	   _adfMinBounds[1], _adfMaxBounds[1]);
  GeoManager::addVTree(vqt);

  vector<Vehicle*>::iterator itv;
  int id = 0;
  int numVehiclePolygons = 0;
  for (itv=vehicles->begin(); itv!=vehicles->end(); itv++) {
    int matesId = atoi((*itv)->id().c_str());
    LOSVehicle*  vehicle     = GeoManager::vehicle(id);
    VehicleWall* vehicleBody = GeoManager::vehicleWall(id);
    _idMap.insert(map<int,int>::value_type(matesId, id));
    vehicle->setAttribute(id, (*itv)->x(), (*itv)->y(), (*itv)->z(),
			  (*itv)->bodyLength(),
			  (*itv)->bodyWidth(),
			  (*itv)->bodyHeight());

    // 車体を直方体と見たときの8頂点
    // 車体中心を原点とみなしたとき
    MyVector3D p,v1,v2,v3,v4,v5,v6,v7,v8;
    p.set((*itv)->x(), (*itv)->y(), (*itv)->z());
    v1.set(-vehicle->length()*0.5,
	   -vehicle->width()*0.5,
	   0);
    v2.set( vehicle->length()*0.5,
	   -vehicle->width()*0.5,
	   0);
    v3.set( vehicle->length()*0.5,
	    vehicle->width()*0.5,
	   0);
    v4.set(-vehicle->length()*0.5,
	    vehicle->width()*0.5,
	   0);
    v5.set(-vehicle->length()*0.5,
	   -vehicle->width()*0.5,
	    vehicle->height());
    v6.set( vehicle->length()*0.5,
	   -vehicle->width()*0.5,
	    vehicle->height());
    v7.set( vehicle->length()*0.5,
	    vehicle->width()*0.5,
	    vehicle->height());
    v8.set(-vehicle->length()*0.5,
	    vehicle->width()*0.5,
	    vehicle->height());

    // 壁面の作成
    vehicleBody->setPolygon(0,p+v1, p+v5, p+v2);
    vehicleBody->setPolygon(1,v2+p, v6+p, v5+p);
    vehicleBody->setPolygon(2,v2+p, v3+p, v6+p);
    vehicleBody->setPolygon(3,v3+p, v7+p, v6+p);
    vehicleBody->setPolygon(4,v3+p, v4+p, v7+p);
    vehicleBody->setPolygon(5,v4+p, v8+p, v7+p);
    vehicleBody->setPolygon(6,v4+p, v1+p, v8+p);
    vehicleBody->setPolygon(7,v1+p, v5+p, v8+p);
    vehicleBody->setPolygon(8,v5+p, v6+p, v7+p);
    vehicleBody->setPolygon(9,v5+p, v8+p, v7+p);

    for (int i=0; i<10; i++) {
      GeoManager::vehiclePolygon(numVehiclePolygons)->setTriangle
	(vehicleBody->wall(i).getVector(0),
	 vehicleBody->wall(i).getVector(1),
	 vehicleBody->wall(i).getVector(2));
      vqt->pushQuadTree(GeoManager::vehiclePolygon(numVehiclePolygons),
			id*10+i, 0, GeoManager::vtrees());
      numVehiclePolygons++;
      /*     
      cout << "wall:" << i << endl;
      for (int j=0; j<3; j++) {
	cout << "vector:" << j << "-";
	cout << vehicleBody->wall(i).getVector(j).getX() << ","
	     << vehicleBody->wall(i).getVector(j).getY() << ","
	     << vehicleBody->wall(i).getVector(j).getZ() << endl;
      }
      */
    }
    id++;
  }
  _numVehicles = id;
  GeoManager::setNumVehicles(_numVehicles);
  GeoManager::setNumVehiclePolygons(numVehiclePolygons);
  //cout << "#vehicles = " << _numVehicles << endl;

  for (int t = 0; t<_numVehicles; t++) {
    for (int r=t+1; r<_numVehicles; r++) {
      LOSVehicle* vt = GeoManager::vehicle(t);
      LOSVehicle* vr = GeoManager::vehicle(r); 
#ifdef COLLISION_DEBUG
      cout << "TRANSMIT:" << vt->id()
	   << " RECEIVE:" << vr->id() << endl;
#endif //COLLISION_DEBUG
      // 線分の傾きとy切片求める
      double a,b;
      _calcStraightLine(vt, vr, &a, &b);      

      //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      // 建造物による遮蔽
      // チェック用四分木を作成
      ChkTree* cq = new ChkTree();
      // ルートからノードの探索開始
      GeoManager::root()->checkNode(vt->vec(), vr->vec(), 0, cq, a, b);
      // 衝突判定
      int collisions = 0;
      double arrayT[_numWalls];
      GeoManager::root()->countCollision(vt->vec(), vr->vec(), cq,
					 &collisions, arrayT);
      delete cq;

      //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      // 他車による遮蔽
      ChkTree* vcq = new ChkTree();
      vqt->checkNode(vt->vec(), vr->vec(), 0, vcq, a, b);
      vqt->countCollision(vt, vr, vcq, &collisions, arrayT);
      delete vcq;
      
      _los[t*MAX_VEHICLES + r] = collisions;
      _los[r*MAX_VEHICLES + t] = collisions;

    }
  }

  for (int t=0; t<_numVehicles; t++) {
    cout << "t=" << t << ":";
    for (int r=0; r<_numVehicles; r++) {
      if (t==r) cout << " --";
      else cout << " " << setw(2) << _los[t*MAX_VEHICLES+r];
    }
    cout << endl;
  }

}