Sfoglia il codice sorgente

change ui_osg_viewer. add grass back.

yuchuli 3 anni fa
parent
commit
4a23d2eea7

+ 41 - 1
src/tool/map_lanetoxodr/OpenDrive/RoadGeometry.cpp

@@ -540,7 +540,42 @@ double GeometryPoly3::GetD()
     return mD;
 }
 
-
+#include "xodrfunc.h"
+
+void GeometryPoly3::GetCoords(double s_check, double &retX, double &retY, double &retHDG)
+{
+    double currentLength = s_check - mS;
+    double flen = 0;
+    double u=0;
+    double v;
+    double x,y;
+    double oldx,oldy;
+    oldx = mX;
+    oldy = mY;
+    double du =0.1;
+    if(currentLength<du)
+    {
+        retX = mX;
+        retY = mY;
+        retHDG = mHdg;
+        return;
+    }
+    u = du;
+    while(flen <= currentLength)
+    {
+        double fdis = 0;
+        v = mA + mB*u + mC*u*u + mD*u*u*u;
+        x = mX + u*cos(mHdg) - v*sin(mHdg);
+        y = mY + u*sin(mHdg) + v*cos(mHdg);
+        fdis = sqrt(pow(x- oldx,2)+pow(y-oldy,2));
+        oldx = x;
+        oldy = y;
+        flen = flen + fdis;
+        u = u + du;
+        retHDG = xodrfunc::CalcHdg(QPointF(oldx,oldy),QPointF(x,y));
+
+    }
+}
 //***********************************************************************************
 //Cubic Polynom geometry. Has to be implemented.  Added By Yuchuli
 //***********************************************************************************
@@ -589,6 +624,11 @@ double GeometryParamPoly3::GetvB(){return mvB;}
 double GeometryParamPoly3::GetvC(){return mvC;}
 double GeometryParamPoly3::GetvD(){return mvD;}
 
+void GeometryParamPoly3::GetCoords(double s_check, double &retX, double &retY, double &retHDG)
+{
+
+}
+
 //***********************************************************************************
 //Base class for Geometry blocks
 //***********************************************************************************

+ 6 - 0
src/tool/map_lanetoxodr/OpenDrive/RoadGeometry.h

@@ -300,6 +300,8 @@ public:
     double GetC();
     double GetD();
 
+    void GetCoords(double s_check, double &retX, double &retY, double &retHDG);
+
 };
 
 //----------------------------------------------------------------------------------
@@ -322,6 +324,8 @@ private:
     double mvB;
     double mvC;
     double mvD;
+
+    bool mbNormal = true;
 public:
     /**
      * Constructor that initializes the base properties of the record
@@ -348,6 +352,8 @@ public:
     double GetvB();
     double GetvC();
     double GetvD();
+
+    void GetCoords(double s_check, double &retX, double &retY, double &retHDG);
 };
 
 

+ 1 - 1
src/tool/map_lanetoxodr/roadeditdialog.cpp

@@ -402,7 +402,7 @@ void RoadEditDialog::on_comboBox_Road_currentIndexChanged(int index)
     }
 
 
-    RoadDigit xrd(mpCurRoad,0.1);
+    RoadDigit xrd(mpCurRoad,5.0);
 
     std::vector<QGraphicsPathItem *> xvectorlanepath = xodrscenfunc::GetRoadLaneItem(&xrd);
     int j;

+ 3 - 0
src/ui/ui_osgviewer/main.cpp

@@ -338,6 +338,9 @@ int SetupRadar(viewer::Viewer *viewer)
         pRadar->model = viewer->AddRadarModel(osg::Vec3(0.5, 0.5, 0.5),"");
         gradarobj.push_back(pRadar);
     }
+//    viewer->AddBackModel(osg::Vec3(0.5, 0.5, 0.5),"");
+
+
     return 0;
 }
 

+ 111 - 0
src/ui/ui_osgviewer/viewer.cpp

@@ -1148,6 +1148,117 @@ EntityModel* Viewer::AddLidarModel(osg::Vec3 trail_color,std::string name,double
     return entities_Lidar.back();
 }
 
+EntityModel* Viewer::AddBackModel(osg::Vec3 trail_color,std::string name)
+{
+    EntityModel* model;
+    int i;
+    int j;
+    osg::ref_ptr<osg::Texture2D> xtexture =  new osg::Texture2D(osgDB::readImageFile("/home/yuchuli/git/esmini/resources/models/grass.jpg"));
+    for(i=0;i<100;i++)
+    {
+
+    for(j=0;j<100;j++)
+    {
+    osg::ref_ptr<osg::Group> group = 0;
+
+        osg::ref_ptr<osg::Geode> geode = new osg::Geode;
+        geode->addDrawable(new osg::ShapeDrawable(new osg::Box()));
+
+        osg::ref_ptr<osg::Group> bbGroup = new osg::Group;
+        osg::ref_ptr<osg::PositionAttitudeTransform> tx = new osg::PositionAttitudeTransform;
+
+        osg::Material* material = new osg::Material();
+
+        // Set color of vehicle based on its index
+        double* color;
+        double b = 1.5;  // brighness
+        color = color_blue;
+
+        material->setDiffuse(osg::Material::FRONT, osg::Vec4(b * color[0], b * color[1], b * color[2], 1.0));
+        material->setAmbient(osg::Material::FRONT, osg::Vec4(b * color[0], b * color[1], b * color[2], 1.0));
+
+        if (group == 0)
+        {
+            // If no model loaded, make a shaded copy of bounding box as model
+            osg::ref_ptr<osg::Geode> geodeCopy = dynamic_cast<osg::Geode*>(geode->clone(osg::CopyOp::DEEP_COPY_ALL));
+            group = new osg::Group;
+            tx->addChild(geodeCopy);
+            geodeCopy->setNodeMask(NodeMask::NODE_MASK_ENTITY_MODEL);
+        }
+
+        // Set dimensions of the entity "box"
+
+            // Scale to something car-ish
+            tx->setScale(osg::Vec3(100.0, 100.0, 0.1));
+            tx->setPosition(osg::Vec3(1.5, 0, 0.75));
+
+        tx->addChild(geode);
+        tx->getOrCreateStateSet()->setAttribute(material);
+        bbGroup->setName("BoundingBox");
+        bbGroup->addChild(tx);
+
+        group->addChild(bbGroup);
+        group->setName(name);
+
+        group->getOrCreateStateSet()->setTextureAttribute(0, xtexture);
+        group->getOrCreateStateSet()->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
+
+
+
+//	if (type == EntityModel::EntityType::ENTITY_TYPE_VEHICLE)
+//	{
+        model = new EntityModel(osgViewer_, group, rootnode_, trails_, dot_node_, trail_color, name);
+//        model = new CarModel(osgViewer_, group, rootnode_, trails_, dot_node_, trail_color, name);
+
+//	}
+//	else
+//	{
+//        model = new EntityModel(osgViewer_, group, rootnode_, trails_, dot_node_, trail_color, name);
+//	}
+
+    model->state_set_ = model->lod_->getOrCreateStateSet(); // Creating material
+    model->blend_color_ = new osg::BlendColor(osg::Vec4(1, 1, 1, 1));
+    model->state_set_->setAttributeAndModes(model->blend_color_);
+    model->blend_color_->setDataVariance(osg::Object::DYNAMIC);
+
+    osg::BlendFunc* bf = new osg::BlendFunc(osg::BlendFunc::CONSTANT_ALPHA, osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA);
+    model->state_set_->setAttributeAndModes(bf);
+    model->state_set_->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
+    model->state_set_->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
+
+    model->txNode_->setPosition(osg::Vec3(i*100-5000, j*100-5000, -10.0));
+
+
+    }
+    }
+
+//	// Focus on first added car
+//	if (entities_.size() == 1)
+//	{
+//		currentCarInFocus_ = 0;
+//		rubberbandManipulator_->setTrackNode(entities_.back()->txNode_,
+//			rubberbandManipulator_->getMode() == osgGA::RubberbandManipulator::CAMERA_MODE::RB_MODE_TOP ? false : true);
+//		nodeTrackerManipulator_->setTrackNode(entities_.back()->txNode_);
+//	}
+
+//	if (type == EntityModel::EntityType::ENTITY_TYPE_VEHICLE)
+//	{
+//		CarModel* vehicle = (CarModel*)entities_.back();
+//		CreateRoadSensors(vehicle);
+
+//		if (road_sensor)
+//		{
+//			vehicle->road_sensor_->Show();
+//		}
+//		else
+//		{
+//			vehicle->road_sensor_->Hide();
+//		}
+//	}
+
+    return model;
+}
+
 EntityModel* Viewer::AddRadarModel(osg::Vec3 trail_color,std::string name)
 {
 

+ 1 - 0
src/ui/ui_osgviewer/viewer.hpp

@@ -330,6 +330,7 @@ namespace viewer
 		EntityModel* AddEntityModel(std::string modelFilepath, osg::Vec3 trail_color, EntityModel::EntityType type, 
 			bool road_sensor, std::string name, OSCBoundingBox *boundingBox);
                 EntityModel* AddRadarModel(osg::Vec3 trail_color,std::string name);
+                EntityModel* AddBackModel(osg::Vec3 trail_color,std::string name);
                 void clearLidar();
                 EntityModel* AddLidarModel(osg::Vec3 trail_color,std::string name,double length,double width, double height);
 		void RemoveCar(std::string name);