diff --git a/src/modules/graphic/osggraph/Viewer/OsgHUD.cpp b/src/modules/graphic/osggraph/Viewer/OsgHUD.cpp index da3b3b376..e4c4bd101 100644 --- a/src/modules/graphic/osggraph/Viewer/OsgHUD.cpp +++ b/src/modules/graphic/osggraph/Viewer/OsgHUD.cpp @@ -70,204 +70,222 @@ std::map hudTextElements; osg::Vec3 calculatePosition(osg::BoundingBox mybb, std::string objPoint, osg::BoundingBox bb, std::string referenceObjPoint, -float verticalModifier, float horizontalModifier) -{ - /* - Possible positioning values: - tl //top left - tr //tom right - tc //top center - bl //bottom left - br //bottom right - bc //bottom center - ml //middle left - mr //middle right - mc //middle center - */ - float vPoint=0; - float hPoint=0; - float vSign = 0; +float verticalModifier, float horizontalModifier){ + /* + Possible positioning values: + tl //top left + tr //top right + tc //top center + bl //bottom left + br //bottom right + bc //bottom center + ml //middle left + mr //middle right + mc //middle center + */ - //my starting point - osg::Vec3 position = osg::Vec3(0.0f,0.0f,0.0f); + float vPoint=0; + float hPoint=0; + float vSign = 0; - //ref object - //vertical - if(referenceObjPoint.find("t")==0) - { - vPoint += bb.yMax(); - vSign = 1; - } - else if(referenceObjPoint.find("b")==0) - { - vPoint += bb.yMin(); - vSign = -1; - } - else if(referenceObjPoint.find("m")==0) - { - vPoint += (bb.yMax() - bb.yMin())/2; - vSign = 1; - } + //my starting point + osg::Vec3 position = osg::Vec3(0.0f,0.0f,0.0f); - //horizontal - if(referenceObjPoint.find("l")==1) - { - hPoint += bb.xMin(); - } - else if(referenceObjPoint.find("r")==1) - { - hPoint += bb.xMax(); - } - else if(referenceObjPoint.find("c")==1) - { - hPoint += (bb.xMax() - bb.xMin())/2; - } + //ref object + //vertical + if(referenceObjPoint.find("t")==0){ + vPoint += bb.yMax(); + vSign = 1; + }else if(referenceObjPoint.find("b")==0){ + vPoint += bb.yMin(); + vSign = -1; + }else if(referenceObjPoint.find("m")==0){ + vPoint += (bb.yMax() - bb.yMin())/2; + vSign = 1; + } + + //horizontal + if(referenceObjPoint.find("l")==1){ + hPoint += bb.xMin(); + }else if(referenceObjPoint.find("r")==1){ + hPoint += bb.xMax(); + }else if(referenceObjPoint.find("c")==1){ + hPoint += (bb.xMax() - bb.xMin())/2; + } - //my obj /*todo check medium vertical alignment*/ - //vertical - if(objPoint.find("t")==0) - { - vPoint -= (mybb.yMax() - mybb.yMin()) * vSign;//height - } - else if(objPoint.find("b")==0) - { - //do nothing - } - else if(objPoint.find("m")==0) - { - vPoint -= (mybb.yMax() - mybb.yMin()) * vSign/2; - } + //my obj /*todo check medium vertical alignment*/ + //vertical + if(objPoint.find("t")==0){ + vPoint -= (mybb.yMax() - mybb.yMin()) * vSign;//height + }else if(objPoint.find("b")==0){ + //do nothing + }else if(objPoint.find("m")==0){ + vPoint -= (mybb.yMax() - mybb.yMin()) * vSign/2; + } - //horizontal - if(objPoint.find("l")==1) - { - //nothing to do - } - else if(objPoint.find("r")==1) - { - hPoint -= (mybb.xMax() - mybb.xMin());//width - } - else if(objPoint.find("c")==1) - { - hPoint -= (mybb.xMax() - mybb.xMin())/2; - } + //horizontal + if(objPoint.find("l")==1){ + //nothing to do + }else if(objPoint.find("r")==1){ + hPoint -= (mybb.xMax() - mybb.xMin());//width + }else if(objPoint.find("c")==1){ + hPoint -= (mybb.xMax() - mybb.xMin())/2; + } - //modifier - hPoint += horizontalModifier; - vPoint += verticalModifier; + //modifier + hPoint += horizontalModifier; + vPoint += verticalModifier; - // apply the modifiers - position += osg::Vec3(hPoint,vPoint,0.0f); + // apply the modifiers + position += osg::Vec3(hPoint,vPoint,0.0f); - return position; + return position; } OSGPLOT::OSGPLOT( float positionX, - float positionY, - float width, - float height, - float maxValue, - float minValue, - float timeFrame, - float referenceLineAtValue, - std::string Xdata, - std::string Ydata) + float positionY, + float width, + float height, + float maxValue, + float minValue, + float timeFrame, + float referenceLineAtValue, + std::string Xdata, + std::string Ydata, + std::string title) { - //initialize variables - this->positionX = positionX; - this->positionY = positionY; - this->width = width; - this->height = height; - this->maxValue = maxValue; - this->minValue = minValue; - this->timeFrame = timeFrame; - this->referenceLineAtValue = referenceLineAtValue; - this->Xdata = Xdata; - this->Ydata = Ydata; + //initialize variables + this->positionX = positionX; + this->positionY = positionY; + this->width = width; + this->height = height; + this->maxValue = maxValue; + this->minValue = minValue; + this->timeFrame = timeFrame; + this->referenceLineAtValue = referenceLineAtValue; + this->Xdata = Xdata; + this->Ydata = Ydata; + this->title = title; - this->osgGroup = new osg::Group; + this->osgGroup = new osg::Group; - this->osgMainPlotLineGeometry = new osg::Geometry(); - this->osgMainPlotLineVertices = new osg::Vec3Array(2); + this->osgMainPlotLineGeometry = new osg::Geometry(); + this->osgMainPlotLineVertices = new osg::Vec3Array(2); - this->osgReferencePlotLineGeometry = new osg::Geometry(); - this->osgReferencePlotLineVertices = new osg::Vec3Array(2); + this->osgReferencePlotLineGeometry = new osg::Geometry(); + this->osgReferencePlotLineVertices = new osg::Vec3Array(2); - this->dataPoints = new osg::Vec3Array(0); + osgText::Text* osgTitle = new osgText::Text; - //draw the background of the chart - this->drawBackground(); + this->dataPoints = new osg::Vec3Array(0); - //prepare the geode for the "osgReferencePlotLine" - { - osg::Geode* geode = new osg::Geode; + //draw the background of the chart + this->drawBackground(); - // pass the created vertex array to the points geometry object. - this->osgReferencePlotLineGeometry->setVertexArray(this->osgReferencePlotLineVertices); - this->osgReferencePlotLineGeometry->setUseDisplayList (false); - this->osgReferencePlotLineGeometry->setUseVertexBufferObjects(true); - this->osgReferencePlotLineGeometry->setDataVariance(osg::Object::DYNAMIC); /*?needed?*/ + //prepare the geode for the "osgReferencePlotLine" + { + osg::Geode* geode = new osg::Geode; - // set the same color for the reference plot line - osg::Vec4Array* plotColors = new osg::Vec4Array; - plotColors->push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); - this->osgReferencePlotLineGeometry->setColorArray(plotColors, osg::Array::BIND_OVERALL); + // pass the created vertex array to the points geometry object. + this->osgReferencePlotLineGeometry->setVertexArray(this->osgReferencePlotLineVertices); + this->osgReferencePlotLineGeometry->setUseDisplayList (false); + this->osgReferencePlotLineGeometry->setUseVertexBufferObjects(true); + this->osgReferencePlotLineGeometry->setDataVariance(osg::Object::DYNAMIC); /*?needed?*/ - // set the normal - osg::Vec3Array* normals = new osg::Vec3Array; - normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); - this->osgReferencePlotLineGeometry->setNormalArray(normals, osg::Array::BIND_OVERALL); + // set the same color for the reference plot line + osg::Vec4Array* plotColors = new osg::Vec4Array; + plotColors->push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); + this->osgReferencePlotLineGeometry->setColorArray(plotColors, osg::Array::BIND_OVERALL); - // tell osg to draw our geometry as lines - this->osgReferencePlotLineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,this->osgReferencePlotLineVertices->size())); + // set the normal + osg::Vec3Array* normals = new osg::Vec3Array; + normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); + this->osgReferencePlotLineGeometry->setNormalArray(normals, osg::Array::BIND_OVERALL); - // disable lighting (light is always on) and enalbe transparency - osg::StateSet* stateset = osgReferencePlotLineGeometry->getOrCreateStateSet(); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - stateset->setMode(GL_BLEND,osg::StateAttribute::ON); - stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + // tell osg to draw our geometry as lines + this->osgReferencePlotLineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,this->osgReferencePlotLineVertices->size())); - // add the points geometry to the geode. - geode->addDrawable(this->osgReferencePlotLineGeometry); - this->osgGroup->addChild(geode); - } + // disable lighting (light is always on) and enalbe transparency + osg::StateSet* stateset = osgReferencePlotLineGeometry->getOrCreateStateSet(); + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + stateset->setMode(GL_BLEND,osg::StateAttribute::ON); + stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - //prepare the geode for the "osgMainPlotLine" - { - osg::Geode* geode = new osg::Geode; + // add the points geometry to the geode. + geode->addDrawable(this->osgReferencePlotLineGeometry); + this->osgGroup->addChild(geode); + } - // pass the created vertex array to the points geometry object. - this->osgMainPlotLineGeometry->setVertexArray(this->osgMainPlotLineVertices); - this->osgMainPlotLineGeometry->setDataVariance(osg::Object::DYNAMIC); /*?needed?*/ + //prepare the geode for the "osgMainPlotLine" + { + osg::Geode* geode = new osg::Geode; - this->osgMainPlotLineGeometry->setUseDisplayList (false); + // pass the created vertex array to the points geometry object. + this->osgMainPlotLineGeometry->setVertexArray(this->osgMainPlotLineVertices); + this->osgMainPlotLineGeometry->setDataVariance(osg::Object::DYNAMIC); /*?needed?*/ - // set the same color for the whole plot line - osg::Vec4Array* plotColors = new osg::Vec4Array; - plotColors->push_back(osg::Vec4(0.0f,0.0f,0.0f,0.5f)); - this->osgMainPlotLineGeometry->setColorArray(plotColors, osg::Array::BIND_OVERALL); + this->osgMainPlotLineGeometry->setUseDisplayList (false); - // set the normal - osg::Vec3Array* normals = new osg::Vec3Array; - normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); - this->osgMainPlotLineGeometry->setNormalArray(normals, osg::Array::BIND_OVERALL); + // set the same color for the whole plot line + osg::Vec4Array* plotColors = new osg::Vec4Array; + plotColors->push_back(osg::Vec4(0.0f,0.0f,0.0f,0.5f)); + this->osgMainPlotLineGeometry->setColorArray(plotColors, osg::Array::BIND_OVERALL); - // tell osg to draw our geometry as lines - this->osgMainPlotLineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,this->osgMainPlotLineVertices->size())); + // set the normal + osg::Vec3Array* normals = new osg::Vec3Array; + normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); + this->osgMainPlotLineGeometry->setNormalArray(normals, osg::Array::BIND_OVERALL); - // disable lighting (light is always on) and enalbe transparency - osg::StateSet* stateset = osgMainPlotLineGeometry->getOrCreateStateSet(); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - stateset->setMode(GL_BLEND,osg::StateAttribute::ON); - stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + // tell osg to draw our geometry as lines + this->osgMainPlotLineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,this->osgMainPlotLineVertices->size())); - // add the points geometry to the geode. - geode->addDrawable(this->osgMainPlotLineGeometry); - this->osgGroup->addChild(geode); - } + // disable lighting (light is always on) and enalbe transparency + osg::StateSet* stateset = osgMainPlotLineGeometry->getOrCreateStateSet(); + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + stateset->setMode(GL_BLEND,osg::StateAttribute::ON); + stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + // add the points geometry to the geode. + geode->addDrawable(this->osgMainPlotLineGeometry); + this->osgGroup->addChild(geode); + } + //prepare the geode for the title + { + osg::Geode* geode = new osg::Geode; + + //color + osg::Vec4 color = osg::Vec4(0.0f,0.0f,0.0f,0.9f); + osgTitle->setColor(color); + + + std::string fontFileUrl = "/vera/Vera.ttf"; + std::string fontsMainDirectory = GetDataDir(); + fontsMainDirectory = fontsMainDirectory+"data/fonts"; + fontFileUrl = fontsMainDirectory+fontFileUrl; + osgTitle->setFont(fontFileUrl); + + + //font resolution + osgTitle->setFontResolution(200,200); + + //set the font size + osgTitle->setCharacterSize(15); + osgTitle->setAlignment(osgText::Text::LEFT_BOTTOM_BASE_LINE ); + + //asign the position + osgTitle->setPosition(osg::Vec3(this->positionX+5.0f, this->positionY+height+5.0f, 0.0f)); + + //GfLogInfo("OSGHUD: Plot Title: %s \n", this->title.c_str()); + //GfLogInfo("OSGHUD: Position: %f %f \n", this->positionX+100.0f, this->positionY+100); + + osgTitle->setText(this->title); + osgTitle->setNodeMask(1); + + geode->addDrawable(osgTitle); + this->osgGroup->addChild(geode); + } } @@ -1199,6 +1217,7 @@ void SDHUD::ToggleHUD1() osg::ref_ptr SDHUD::generateHudFromXmlFile(int scrH, int scrW){ +<<<<<<< HEAD osg::ref_ptr group = new osg::Group; osg::ref_ptr geode = new osg::Geode; @@ -1558,6 +1577,372 @@ osg::ref_ptr SDHUD::generateHudFromXmlFile(int scrH, int scrW){ //return the hud object return (*group).asGroup(); +======= + osg::ref_ptr group = new osg::Group; + osg::ref_ptr geode = new osg::Geode; + + group->addChild(geode); + + // turn lighting off for the text and disable depth test to ensure it's always ontop. + osg::StateSet* stateset = geode->getOrCreateStateSet(); + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + + //screen bounding box + osg::BoundingBox screenBB; + screenBB.expandBy(osg::Vec3(0.0f,0.0f,0.0f)); + screenBB.expandBy(osg::Vec3(scrW,scrH,0.0f)); + + std::string sectionPath= "board"; + std::string subSectionPath = ""; + std::string subSectionName = ""; + + std::string configFileUrl= GetLocalDir(); + configFileUrl.append("config/osghudconfig.xml"); + int paramValue = 0; + + //open the file + void *paramHandle = GfParmReadFile(configFileUrl.c_str(), GFPARM_RMODE_STD); + + //for each section on the + if (GfParmListSeekFirst(paramHandle, sectionPath.c_str()) == 0) { + do { + subSectionName = GfParmListGetCurEltName(paramHandle, sectionPath.c_str()); + subSectionPath = sectionPath + "/" + subSectionName; + + //get a list of the params in this section + std::vector paramsInSection = GfParmListGetParamsNamesList(paramHandle, subSectionPath.c_str()); + + std::string type = GfParmGetStr (paramHandle, subSectionPath.c_str(),"type", "no default value" ); + + /* ============================ + CREATE OSG TEXT + ============================*/ + if (type == "text" ){ + + //read data into local variables + std::string elementId = subSectionName; + std::string textStr = GfParmGetStr (paramHandle, subSectionPath.c_str(),"text", "" ); + std::string fontFileUrl = GfParmGetStr (paramHandle, subSectionPath.c_str(),"fontFileUrl", "" ); + std::string colorString = GfParmGetStr (paramHandle, subSectionPath.c_str(),"color", "" ); + float fontSize = GfParmGetNum (paramHandle, subSectionPath.c_str(),"fontSize", "",0 ) * this->hudScale; + std::string textAlign = GfParmGetStr (paramHandle, subSectionPath.c_str(),"textAlign", "" ); + + std::string positionRefObj = GfParmGetStr (paramHandle, subSectionPath.c_str(),"position-refObj", "" ); + std::string positionRefObjPoint = GfParmGetStr (paramHandle, subSectionPath.c_str(),"position-refObjPoint", "tl" ); + std::string positionMyPoint = GfParmGetStr (paramHandle, subSectionPath.c_str(),"position-myPoint", "tl" ); + float positionVerticalModifier = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-verticalModifier", "",0 ) * this->hudScale; + float positionHorizontalModifier = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-horizontalModifier", "",0 ) * this->hudScale; + + GfLogInfo("OSGHUD: Generate text object: %s \n", elementId.c_str()); + + //create the osg::text object + osgText::Text* text = new osgText::Text; + + //add the text obj to our pool (we willl need it later) + hudTextElements[elementId] = text; + + //extract and apply the color + { + std::vector colorStringVector = split(colorString.c_str(), '#'); + + osg::Vec4 color = osg::Vec4( + std::atof(colorStringVector[0].c_str()), + std::atof(colorStringVector[1].c_str()), + std::atof(colorStringVector[2].c_str()), + std::atof(colorStringVector[3].c_str()) + ); + + text->setColor(color); + } + + //set the font + { + std::string fontsMainDirectory = GetDataDir(); + fontsMainDirectory = fontsMainDirectory+"data/fonts"; + fontFileUrl = fontsMainDirectory+fontFileUrl; + text->setFont(fontFileUrl); + + //font resolution + text->setFontResolution(200,200); + + //set the font size + text->setCharacterSize(fontSize); + } + + //set alignement + if (textAlign==""){ + text->setAlignment(osgText::Text::LEFT_BOTTOM_BASE_LINE ); + }else if (textAlign=="LEFT_BOTTOM"){ + text->setAlignment(osgText::Text::LEFT_BOTTOM_BASE_LINE ); + }else if (textAlign=="RIGHT_BOTTOM"){ + text->setAlignment(osgText::Text::RIGHT_BOTTOM_BASE_LINE ); + } + + //set the text string + text->setText(textStr.c_str()); + + //set the position + //find the referenceObj pointer and then get his bounding box + osg::BoundingBox refObjBb; + if ( hudTextElements.find(positionRefObj.c_str()) != hudTextElements.end() ) { + refObjBb = hudTextElements[positionRefObj.c_str()]->getBoundingBox(); + }else if ( this->hudImgElements.find(positionRefObj.c_str()) != this->hudImgElements.end() ) { + refObjBb = this->hudImgElements[positionRefObj.c_str()]->getBoundingBox(); + }else if ( this->hudGraphElements.find(positionRefObj.c_str()) != this->hudGraphElements.end() ) { + //refObjBb = this->hudGraphElements[positionRefObj.c_str()]->getBoundingBox(); + }else{ + GfLogInfo("OSGHUD: No (valid) reference object given for the current element alignement: Assuming Screen!"); + refObjBb = screenBB; + } + + //calculate the positioning + osg::Vec3 position = calculatePosition(text->getBoundingBox(),positionMyPoint,refObjBb,positionRefObjPoint, positionVerticalModifier, positionHorizontalModifier); + + //asign the position + text->setPosition(position); + + //TODO: enable shadows for texts? + //text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT); //OUTLINE //DROP_SHADOW_BOTTOM_RIGHT + /* + text->setBackdropOffset(0.07f); + color = osg::Vec4(0.57f,0.57f,0.57f,0.6f); + text->setBackdropColor(color); + */ + + //add the text to the hud + geode->addDrawable( text ); + + }else if( type == "image"){ + + /* ============================ + CREATE OSG IMAGE + ============================*/ + //read data into local variables + std::string elementId = subSectionName; + std::string url = GfParmGetStr (paramHandle, subSectionPath.c_str(),"url", "" ); + + std::string positionRefObj = GfParmGetStr (paramHandle, subSectionPath.c_str(),"position-refObj", "" ); + std::string positionRefObjPoint = GfParmGetStr (paramHandle, subSectionPath.c_str(),"position-refObjPoint", "tl" ); + std::string positionMyPoint = GfParmGetStr (paramHandle, subSectionPath.c_str(),"position-myPoint", "tl" ); + float positionVerticalModifier = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-verticalModifier", "",0 ) * this->hudScale; + float positionHorizontalModifier = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-horizontalModifier", "",0 ) * this->hudScale; + + GfLogInfo("OSGHUD: Generate image object: %s \n", elementId.c_str()); + + //start preparing the image + std::string filename = GetDataDir(); + filename = filename+url; + + //get the bounding box + osg::BoundingBox bb; + for(unsigned int i=0;igetNumDrawables();++i) + { + bb.expandBy(geode->getDrawable(i)->getBoundingBox()); + } + + //check that the image file exist + if (!GfFileExists(filename.c_str())){ + GfLogError ("OSGHUD: Specified image file does not exist: %s.\n", filename.c_str()); + } + osg::Image* img = osgDB::readImageFile(filename); + + //correct the image size to match the hud scale + float imgWidth = img->s() * this->hudScale; + float imgHeight = img->t() * this->hudScale; + + // create geometry + osg::Geometry* geom = new osg::Geometry; + this->hudImgElements[elementId] = geom; + + //set the position + //find the referenceObj pointer and then get his bounding box + osg::BoundingBox refObjBb; + if ( hudTextElements.find(positionRefObj.c_str()) != hudTextElements.end() ) { + refObjBb = hudTextElements[positionRefObj.c_str()]->getBoundingBox(); + }else if ( this->hudImgElements.find(positionRefObj.c_str()) != this->hudImgElements.end() ) { + refObjBb = this->hudImgElements[positionRefObj.c_str()]->getBoundingBox(); + }else if ( this->hudGraphElements.find(positionRefObj.c_str()) != this->hudGraphElements.end() ) { + //refObjBb = this->hudGraphElements[positionRefObj.c_str()]->getBoundingBox(); + }else{ + GfLogInfo("OSGHUD: No (valid) reference object given for the current element alignement: Assuming Screen!"); + refObjBb = screenBB; + } + + //get object bounding box + osg::BoundingBox myObjBb; + myObjBb.expandBy(osg::Vec3(0.0f,0.0f,0.0f)); + myObjBb.expandBy(osg::Vec3(imgWidth,imgHeight,0.0f)); + + //calculate the positioning + osg::Vec3 position = calculatePosition(myObjBb,positionMyPoint,refObjBb,positionRefObjPoint, positionVerticalModifier, positionHorizontalModifier); + + //asign the position + float positionLeft = position.x(); + float positionBottom = position.y(); + + //create the vertices for the image geometry and assign them + osg::Vec3Array* vertices = new osg::Vec3Array; + float depth = 0.0f-0.1f; + vertices->push_back(osg::Vec3( positionLeft ,positionBottom,depth)); //bottom left + vertices->push_back(osg::Vec3( positionLeft+imgWidth,positionBottom,depth)); //bottom right + vertices->push_back(osg::Vec3( positionLeft+imgWidth,positionBottom+imgHeight ,depth)); //top right + vertices->push_back(osg::Vec3( positionLeft ,positionBottom+imgHeight ,depth)); //topleft + geom->setVertexArray(vertices); + + + // texture the geometry and apply material + + // calculate textures coordinates + osg::Vec2Array* texcoords = new osg::Vec2Array(4); + (*texcoords)[0].set(0.0f, 0.0f); + (*texcoords)[1].set(1.0f, 0.0f); + (*texcoords)[2].set(1.0f, 1.0f); + (*texcoords)[3].set(0.0f, 1.0f); + geom->setTexCoordArray(0,texcoords); + + // calculate normals + osg::Vec3Array* normals = new osg::Vec3Array(1); + (*normals)[0].set(0.0f,-1.0f,0.0f); + geom->setNormalArray(normals); + geom->setNormalBinding(osg::Geometry::BIND_OVERALL); + + // assign colors + osg::Vec4Array* colors = new osg::Vec4Array(1); + (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); + geom->setColorArray(colors); + geom->setColorBinding(osg::Geometry::BIND_OVERALL); + + // draw the vertices as quads + geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4)); + + // disable display list so our modified tex coordinates show up + geom->setUseDisplayList(false); + + // setup texture + osg::TextureRectangle* texture = new osg::TextureRectangle; + + texture->setImage(img); + + // setup stateset + osg::StateSet* state = geom->getOrCreateStateSet(); + state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); + + // setup material + osg::TexMat* texmat = new osg::TexMat; + texmat->setScaleByTextureRectangleSize(true); + state->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); + + //enable gl_blending (for texture transparency) + state->setMode(GL_BLEND, osg::StateAttribute::ON); + osg::BlendFunc* blend = new osg::BlendFunc; + blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_DST_ALPHA); + + // turn off lighting (light always on) + state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + + //add the image geometry to the hud + geode->addDrawable(geom); + + }else if( type == "graph"){ + + /* ============================ + CREATE OSG GRAPH + ============================*/ + //read data into local variables + std::string elementId = subSectionName; + + //positioning variables + float posFromTop = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-from-top", "",0 ); + float posFromBottom = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-from-bottom", "",0 ); + float posFromLeft = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-from-left", "",0 ); + float posFromRight = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-from-right", "",0 ); + float posHorizontalCenter = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-horizontal-center", "",0 ); + + std::string positionRefObj = GfParmGetStr (paramHandle, subSectionPath.c_str(),"position-refObj", "" ); + std::string positionRefObjPoint = GfParmGetStr (paramHandle, subSectionPath.c_str(),"position-refObjPoint", "tl" ); + std::string positionMyPoint = GfParmGetStr (paramHandle, subSectionPath.c_str(),"position-myPoint", "tl" ); + float positionVerticalModifier = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-verticalModifier", "",0 ) * this->hudScale; + float positionHorizontalModifier = GfParmGetNum (paramHandle, subSectionPath.c_str(),"position-horizontalModifier", "",0 ) * this->hudScale; + + //graph variables + float width = GfParmGetNum (paramHandle, subSectionPath.c_str(),"width", "",0 ); + float height = GfParmGetNum (paramHandle, subSectionPath.c_str(),"height", "",0 ); + float maxValue = GfParmGetNum (paramHandle, subSectionPath.c_str(),"maxValue", "",0 ); + float minValue = GfParmGetNum (paramHandle, subSectionPath.c_str(),"minValue", "",0 ); + float timeFrame = GfParmGetNum (paramHandle, subSectionPath.c_str(),"timeFrame", "",0 ); + float referenceLineAtValue = GfParmGetNum (paramHandle, subSectionPath.c_str(),"referenceLineAtValue", "",0 ); + std::string Xdata = GfParmGetStr (paramHandle, subSectionPath.c_str(),"Xdata", "" ); + std::string Ydata = GfParmGetStr (paramHandle, subSectionPath.c_str(),"Ydata", "" ); + std::string title = GfParmGetStr (paramHandle, subSectionPath.c_str(),"title", "" ); + + + GfLogInfo("OSGHUD: Generate graph object: %s \n", elementId.c_str()); + + //calculate position + //find the referenceObj pointer and then get his bounding box + osg::BoundingBox refObjBb; + if ( hudTextElements.find(positionRefObj.c_str()) != hudTextElements.end() ) { + refObjBb = hudTextElements[positionRefObj.c_str()]->getBoundingBox(); + }else if ( this->hudImgElements.find(positionRefObj.c_str()) != this->hudImgElements.end() ) { + refObjBb = this->hudImgElements[positionRefObj.c_str()]->getBoundingBox(); + }else if ( this->hudGraphElements.find(positionRefObj.c_str()) != this->hudGraphElements.end() ) { + //refObjBb = this->hudGraphElements[positionRefObj.c_str()]->getBoundingBox(); + }else{ + GfLogInfo("OSGHUD: No (valid) reference object given for the current element alignement: Assuming Screen!"); + refObjBb = screenBB; + } + + //calculate our bounding box + osg::BoundingBox plotBB; + plotBB.expandBy(osg::Vec3(0.0f,0.0f,0.0f)); + plotBB.expandBy(osg::Vec3(width,height,0.0f)); + + //calculate the positioning + osg::Vec3 position = calculatePosition(plotBB,positionMyPoint,refObjBb,positionRefObjPoint, positionVerticalModifier, positionHorizontalModifier); + + float positionX = position.x(); + float positionY = position.y(); + + //istantiate the graph + this->plotElements[elementId] = new OSGPLOT( + positionX, + positionY, + width, + height, + maxValue, + minValue, + timeFrame, + referenceLineAtValue, + Xdata.c_str(), + Ydata.c_str(), + title.c_str() + ); + + //camera->addChild(testPLot->getGroup()); + //return this->plotElements[elementId]->getGroup(); + + group->addChild(this->plotElements[elementId]->getGroup()); + + }else{ + + /* ============================ + NO MORE HUD TYPE OPTIONS...?? + ============================*/ + GfLogInfo("OSG-HUD object type not recognized: %s", type.c_str()); + } + + } while (GfParmListSeekNext(paramHandle, sectionPath.c_str()) == 0); + } + + //release the xml file + GfParmReleaseHandle(paramHandle); + + //make the hud visible + geode->setNodeMask(1-geode->getNodeMask()); + + //return the hud object + return (*group).asGroup(); +>>>>>>> add titles to OSG HUD graphs } diff --git a/src/modules/graphic/osggraph/Viewer/OsgHUD.h b/src/modules/graphic/osggraph/Viewer/OsgHUD.h index b771993c2..b77a67121 100644 --- a/src/modules/graphic/osggraph/Viewer/OsgHUD.h +++ b/src/modules/graphic/osggraph/Viewer/OsgHUD.h @@ -42,7 +42,8 @@ class OSGPLOT float timeFrame, float referenceLineAtValue, std::string Xdata, - std::string Ydata + std::string Ydata, + std::string title ); ~OSGPLOT(); float positionX; @@ -55,6 +56,7 @@ class OSGPLOT float referenceLineAtValue; std::string Xdata; std::string Ydata; + std::string title; osg::Vec3Array* dataPoints; @@ -64,6 +66,8 @@ class OSGPLOT osg::Geometry* osgReferencePlotLineGeometry; osg::Vec3Array* osgReferencePlotLineVertices; + //osgText::Text* osgTitle; + osg::ref_ptr osgGroup; osg::ref_ptr getGroup();