add titles to OSG HUD graphs

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6911 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: fcf924d2d8748fe4afa8fc72d7e2f9da06f474c7
Former-commit-id: 78a2a27445fc069b0b4486e31a3d346ef41684b8
This commit is contained in:
madbad 2020-04-12 15:09:23 +00:00
parent d4dbd646be
commit c97ab90c4e
2 changed files with 553 additions and 164 deletions

View file

@ -70,204 +70,222 @@ std::map<std::string,osgText::Text* > hudTextElements;
osg::Vec3 calculatePosition(osg::BoundingBox mybb, std::string objPoint, osg::Vec3 calculatePosition(osg::BoundingBox mybb, std::string objPoint,
osg::BoundingBox bb, std::string referenceObjPoint, 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 verticalModifier, float horizontalModifier){
float hPoint=0; /*
float vSign = 0; 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 float vPoint=0;
osg::Vec3 position = osg::Vec3(0.0f,0.0f,0.0f); float hPoint=0;
float vSign = 0;
//ref object //my starting point
//vertical osg::Vec3 position = osg::Vec3(0.0f,0.0f,0.0f);
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 //ref object
if(referenceObjPoint.find("l")==1) //vertical
{ if(referenceObjPoint.find("t")==0){
hPoint += bb.xMin(); vPoint += bb.yMax();
} vSign = 1;
else if(referenceObjPoint.find("r")==1) }else if(referenceObjPoint.find("b")==0){
{ vPoint += bb.yMin();
hPoint += bb.xMax(); vSign = -1;
} }else if(referenceObjPoint.find("m")==0){
else if(referenceObjPoint.find("c")==1) vPoint += (bb.yMax() - bb.yMin())/2;
{ vSign = 1;
hPoint += (bb.xMax() - bb.xMin())/2; }
}
//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*/ //my obj /*todo check medium vertical alignment*/
//vertical //vertical
if(objPoint.find("t")==0) if(objPoint.find("t")==0){
{ vPoint -= (mybb.yMax() - mybb.yMin()) * vSign;//height
vPoint -= (mybb.yMax() - mybb.yMin()) * vSign;//height }else if(objPoint.find("b")==0){
} //do nothing
else if(objPoint.find("b")==0) }else if(objPoint.find("m")==0){
{ vPoint -= (mybb.yMax() - mybb.yMin()) * vSign/2;
//do nothing }
}
else if(objPoint.find("m")==0)
{
vPoint -= (mybb.yMax() - mybb.yMin()) * vSign/2;
}
//horizontal //horizontal
if(objPoint.find("l")==1) if(objPoint.find("l")==1){
{ //nothing to do
//nothing to do }else if(objPoint.find("r")==1){
} hPoint -= (mybb.xMax() - mybb.xMin());//width
else if(objPoint.find("r")==1) }else if(objPoint.find("c")==1){
{ hPoint -= (mybb.xMax() - mybb.xMin())/2;
hPoint -= (mybb.xMax() - mybb.xMin());//width }
}
else if(objPoint.find("c")==1)
{
hPoint -= (mybb.xMax() - mybb.xMin())/2;
}
//modifier //modifier
hPoint += horizontalModifier; hPoint += horizontalModifier;
vPoint += verticalModifier; vPoint += verticalModifier;
// apply the modifiers // apply the modifiers
position += osg::Vec3(hPoint,vPoint,0.0f); position += osg::Vec3(hPoint,vPoint,0.0f);
return position; return position;
} }
OSGPLOT::OSGPLOT( float positionX, OSGPLOT::OSGPLOT( float positionX,
float positionY, float positionY,
float width, float width,
float height, float height,
float maxValue, float maxValue,
float minValue, float minValue,
float timeFrame, float timeFrame,
float referenceLineAtValue, float referenceLineAtValue,
std::string Xdata, std::string Xdata,
std::string Ydata) std::string Ydata,
std::string title)
{ {
//initialize variables //initialize variables
this->positionX = positionX; this->positionX = positionX;
this->positionY = positionY; this->positionY = positionY;
this->width = width; this->width = width;
this->height = height; this->height = height;
this->maxValue = maxValue; this->maxValue = maxValue;
this->minValue = minValue; this->minValue = minValue;
this->timeFrame = timeFrame; this->timeFrame = timeFrame;
this->referenceLineAtValue = referenceLineAtValue; this->referenceLineAtValue = referenceLineAtValue;
this->Xdata = Xdata; this->Xdata = Xdata;
this->Ydata = Ydata; this->Ydata = Ydata;
this->title = title;
this->osgGroup = new osg::Group; this->osgGroup = new osg::Group;
this->osgMainPlotLineGeometry = new osg::Geometry(); this->osgMainPlotLineGeometry = new osg::Geometry();
this->osgMainPlotLineVertices = new osg::Vec3Array(2); this->osgMainPlotLineVertices = new osg::Vec3Array(2);
this->osgReferencePlotLineGeometry = new osg::Geometry(); this->osgReferencePlotLineGeometry = new osg::Geometry();
this->osgReferencePlotLineVertices = new osg::Vec3Array(2); 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->dataPoints = new osg::Vec3Array(0);
this->drawBackground();
//prepare the geode for the "osgReferencePlotLine" //draw the background of the chart
{ this->drawBackground();
osg::Geode* geode = new osg::Geode;
// pass the created vertex array to the points geometry object. //prepare the geode for the "osgReferencePlotLine"
this->osgReferencePlotLineGeometry->setVertexArray(this->osgReferencePlotLineVertices); {
this->osgReferencePlotLineGeometry->setUseDisplayList (false); osg::Geode* geode = new osg::Geode;
this->osgReferencePlotLineGeometry->setUseVertexBufferObjects(true);
this->osgReferencePlotLineGeometry->setDataVariance(osg::Object::DYNAMIC); /*?needed?*/
// set the same color for the reference plot line // pass the created vertex array to the points geometry object.
osg::Vec4Array* plotColors = new osg::Vec4Array; this->osgReferencePlotLineGeometry->setVertexArray(this->osgReferencePlotLineVertices);
plotColors->push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); this->osgReferencePlotLineGeometry->setUseDisplayList (false);
this->osgReferencePlotLineGeometry->setColorArray(plotColors, osg::Array::BIND_OVERALL); this->osgReferencePlotLineGeometry->setUseVertexBufferObjects(true);
this->osgReferencePlotLineGeometry->setDataVariance(osg::Object::DYNAMIC); /*?needed?*/
// set the normal // set the same color for the reference plot line
osg::Vec3Array* normals = new osg::Vec3Array; osg::Vec4Array* plotColors = new osg::Vec4Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); plotColors->push_back(osg::Vec4(1.0f,0.0f,0.0f,1.0f));
this->osgReferencePlotLineGeometry->setNormalArray(normals, osg::Array::BIND_OVERALL); this->osgReferencePlotLineGeometry->setColorArray(plotColors, osg::Array::BIND_OVERALL);
// tell osg to draw our geometry as lines // set the normal
this->osgReferencePlotLineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,this->osgReferencePlotLineVertices->size())); 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 // tell osg to draw our geometry as lines
osg::StateSet* stateset = osgReferencePlotLineGeometry->getOrCreateStateSet(); this->osgReferencePlotLineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,this->osgReferencePlotLineVertices->size()));
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. // disable lighting (light is always on) and enalbe transparency
geode->addDrawable(this->osgReferencePlotLineGeometry); osg::StateSet* stateset = osgReferencePlotLineGeometry->getOrCreateStateSet();
this->osgGroup->addChild(geode); 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" // add the points geometry to the geode.
{ geode->addDrawable(this->osgReferencePlotLineGeometry);
osg::Geode* geode = new osg::Geode; this->osgGroup->addChild(geode);
}
// pass the created vertex array to the points geometry object. //prepare the geode for the "osgMainPlotLine"
this->osgMainPlotLineGeometry->setVertexArray(this->osgMainPlotLineVertices); {
this->osgMainPlotLineGeometry->setDataVariance(osg::Object::DYNAMIC); /*?needed?*/ 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 this->osgMainPlotLineGeometry->setUseDisplayList (false);
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);
// set the normal // set the same color for the whole plot line
osg::Vec3Array* normals = new osg::Vec3Array; osg::Vec4Array* plotColors = new osg::Vec4Array;
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); plotColors->push_back(osg::Vec4(0.0f,0.0f,0.0f,0.5f));
this->osgMainPlotLineGeometry->setNormalArray(normals, osg::Array::BIND_OVERALL); this->osgMainPlotLineGeometry->setColorArray(plotColors, osg::Array::BIND_OVERALL);
// tell osg to draw our geometry as lines // set the normal
this->osgMainPlotLineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,this->osgMainPlotLineVertices->size())); 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 // tell osg to draw our geometry as lines
osg::StateSet* stateset = osgMainPlotLineGeometry->getOrCreateStateSet(); this->osgMainPlotLineGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,this->osgMainPlotLineVertices->size()));
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. // disable lighting (light is always on) and enalbe transparency
geode->addDrawable(this->osgMainPlotLineGeometry); osg::StateSet* stateset = osgMainPlotLineGeometry->getOrCreateStateSet();
this->osgGroup->addChild(geode); 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 <osg::Group> SDHUD::generateHudFromXmlFile(int scrH, int scrW){ osg::ref_ptr <osg::Group> SDHUD::generateHudFromXmlFile(int scrH, int scrW){
<<<<<<< HEAD
osg::ref_ptr<osg::Group> group = new osg::Group; osg::ref_ptr<osg::Group> group = new osg::Group;
osg::ref_ptr<osg::Geode> geode = new osg::Geode; osg::ref_ptr<osg::Geode> geode = new osg::Geode;
@ -1558,6 +1577,372 @@ osg::ref_ptr <osg::Group> SDHUD::generateHudFromXmlFile(int scrH, int scrW){
//return the hud object //return the hud object
return (*group).asGroup(); return (*group).asGroup();
=======
osg::ref_ptr<osg::Group> group = new osg::Group;
osg::ref_ptr<osg::Geode> 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<std::string> 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<std::string> 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;i<geode->getNumDrawables();++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
} }

View file

@ -42,7 +42,8 @@ class OSGPLOT
float timeFrame, float timeFrame,
float referenceLineAtValue, float referenceLineAtValue,
std::string Xdata, std::string Xdata,
std::string Ydata std::string Ydata,
std::string title
); );
~OSGPLOT(); ~OSGPLOT();
float positionX; float positionX;
@ -55,6 +56,7 @@ class OSGPLOT
float referenceLineAtValue; float referenceLineAtValue;
std::string Xdata; std::string Xdata;
std::string Ydata; std::string Ydata;
std::string title;
osg::Vec3Array* dataPoints; osg::Vec3Array* dataPoints;
@ -64,6 +66,8 @@ class OSGPLOT
osg::Geometry* osgReferencePlotLineGeometry; osg::Geometry* osgReferencePlotLineGeometry;
osg::Vec3Array* osgReferencePlotLineVertices; osg::Vec3Array* osgReferencePlotLineVertices;
//osgText::Text* osgTitle;
osg::ref_ptr<osg::Group> osgGroup; osg::ref_ptr<osg::Group> osgGroup;
osg::ref_ptr <osg::Group> getGroup(); osg::ref_ptr <osg::Group> getGroup();