Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SceneTextScreen.cpp
1 #include "SceneTextScreen.hh"
2 
3 #ifdef BIAS_HAVE_OPENGL
4 # include <Gui/biasgl.h>
5 # ifdef __APPLE__
6 # include <OpenGL/glu.h>
7 # else // __APPLE__
8 # include <GL/glu.h>
9 # endif // __APPLE__
10 # include <Utils/StatekeeperGL.hh>
11 #endif
12 
13 
14 using namespace std;
15 using namespace BIAS;
16 using namespace BIAS;
17 
18 SceneTextScreen::SceneTextScreen(bool MakeDemoText): isInitialized_(false) {
19  if (MakeDemoText) {
20  textPositions_.push_back(HomgPoint3D(0.0,0.0,1.0));
21  textContents_.push_back("Northern Star");
22  textColors_.push_back(RGBf(1.0f, 0.0f, 0.0f));
23  }
24 
25  fontName_ = "-*-helvetica-bold-r-normal--12-*-*-*-p-*-iso8859-1";//DrawTextGL_DEFAULT_FONTNAME;
26  fontHeight_ = 12;
27 }
29  #ifdef BIAS_HAVE_FONTGL
31 #endif
32 }
34 {
35 #ifdef WIN32
36  BIASWARNONCE("windows font selection mechanism not yet implmented here.");
37  return;
38 #endif
39 #ifdef BIAS_HAVE_OPENGL
40 
41  if (!isInitialized_) {
42 #ifdef BIAS_HAVE_FONTGL
43  if (drawer_.InitFont(NULL, fontName_, fontHeight_)!=0) {
44  cerr<<"init of font failed ..."<<endl;
45  return;
46  }
47 #else
48  BIASWARNONCE("FontGL is disabled in BIAS.");
49  return;
50 #endif
51  isInitialized_ = true;
52  }
53  for (unsigned int i=0; i<textContents_.size(); i++) {
54  glColor3f(textColors_[i][0], textColors_[i][1], textColors_[i][2]);
55 #ifdef BIAS_HAVE_FONTGL
56 
58  (int)textPositions_[i][1], 0,0);
59 
60 
61  glColor3f(0.0, 0.0, 1.0);
62  //drawer_.Print3D(".", textPositions_[i][0],
63  // textPositions_[i][1], textPositions_[i][2]);
64  glBegin(GL_POINTS);
65  glVertex3f(textPositions_[i][0], textPositions_[i][1], textPositions_[i][2]);
66  glEnd();
67 #endif
68  }
69 #endif
70 
71 }
72 
73 
74 #ifdef BIAS_HAVE_XML2
75 
76 int SceneTextScreen::XMLGetClassName(std::string& TopLevelTag,
77  double& Version) const {
78  TopLevelTag = "SceneTextScreen";
79  Version = 0.1;
80  return 0;
81 }
82 
83 int SceneTextScreen::XMLOut(const xmlNodePtr mainNode, XMLIO& XMLObject) const {
84  for (unsigned int i=0; i<textContents_.size(); i++) {
85  xmlNodePtr childNode = XMLObject.addChildNode(mainNode, "Text");
86 
87  XMLObject.addAttribute(childNode, "r", textColors_[i][0]);
88  XMLObject.addAttribute(childNode, "g", textColors_[i][1]);
89  XMLObject.addAttribute(childNode, "b", textColors_[i][2]);
90 
91  XMLObject.addAttribute(childNode, "x", textPositions_[i][0]);
92  XMLObject.addAttribute(childNode, "y", textPositions_[i][1]);
93  XMLObject.addAttribute(childNode, "z", textPositions_[i][2]);
94  XMLObject.addAttribute(childNode, "w", textPositions_[i][3]);
95 
96  XMLObject.addContent(childNode, textContents_[i]);
97  }
98  return 0;
99 }
100 
101 int SceneTextScreen::XMLIn(const xmlNodePtr Node, XMLIO& XMLObject) {
102  textColors_.clear();
103  textPositions_.clear();
104  textContents_.clear();
105  xmlNodePtr childNode = XMLObject.getFirstChild(Node);
106  while (!(childNode==NULL)) {
107  if (XMLObject.getNodeName(childNode)=="Text") {
108  RGBf thecolor;
109  HomgPoint3D theposition;
110 
111  thecolor[0] = XMLObject.getAttributeValueDouble(childNode, "r");
112  thecolor[1] = XMLObject.getAttributeValueDouble(childNode, "g");
113  thecolor[2] = XMLObject.getAttributeValueDouble(childNode, "b");
114 
115  theposition[0] = XMLObject.getAttributeValueDouble(childNode, "x");
116  theposition[1] = XMLObject.getAttributeValueDouble(childNode, "y");
117  theposition[2] = XMLObject.getAttributeValueDouble(childNode, "z");
118  theposition[3] = XMLObject.getAttributeValueDouble(childNode, "w");
119 
120  textColors_.push_back(thecolor);
121  textPositions_.push_back(theposition);
122  string theContent = "___"+XMLObject.getNodeContentString(childNode);
123  textContents_.push_back(theContent);
124  cout<<"Found "<<theContent<<" at "<<theposition<<" with color "
125  <<thecolor<<endl;
126  }
127  childNode = XMLObject.getNextChild();
128  }
129  cout<<"Read "<<textColors_.size()<<" texts"<<endl;
130 
131  return 0;
132 }
133 
134 #endif // BIAS_HAVE_XML2
135 
136 
137 
138 
void addAttribute(const xmlNodePtr Node, const std::string &AttributeName, bool AttributeValue)
Add an attribute to a node.
Definition: XMLIO.cpp:156
virtual int XMLOut(const xmlNodePtr Node, BIAS::XMLIO &XMLObject) const
specialization of XML write function
xmlNodePtr getNextChild()
Get the next child of the parent specified in the last getFirstChild() call, the class remembers the ...
Definition: XMLIO.cpp:466
virtual void Draw()
To do anything usefull, overload this method, assume context is ready and draw.
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
specialization of XML block name function
int InitFont(void *handleDC, const std::string theFontname=std::string(DrawTextGL_DEFAULT_FONTNAME), const int fontHeight=DrawTextGL_DEFAULT_FONTSIZE)
set the font up
Definition: DrawTextGL.cpp:80
virtual int XMLIn(const xmlNodePtr Node, BIAS::XMLIO &XMLObject)
specialization of XML read function
void addContent(const xmlNodePtr Node, const std::string &Content)
Add content to a node.
Definition: XMLIO.cpp:254
BIAS::Vector3< float > RGBf
Definition: RGB.hh:22
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
xmlNodePtr addChildNode(const xmlNodePtr ParentNode, const std::string &NewNodeName)
Add a child node to an incoming node with the given name.
Definition: XMLIO.cpp:131
std::vector< BIAS::RGBf > textColors_
std::vector< std::string > textContents_
xmlNodePtr getFirstChild(const xmlNodePtr ParentNode)
Get the first child of a given parent, or NULL for no childs.
Definition: XMLIO.cpp:452
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
void DeleteFont()
frees the display lists JW
Definition: DrawTextGL.cpp:194
double getAttributeValueDouble(const xmlAttrPtr Attribute) const
Definition: XMLIO.cpp:736
std::vector< BIAS::HomgPoint3D > textPositions_
std::string getNodeName(const xmlNodePtr Node) const
Get the name of a given Node.
Definition: XMLIO.cpp:543
BIAS::DrawTextGL drawer_
std::string getNodeContentString(const xmlNodePtr Node) const
Get the content of a given Node.
Definition: XMLIO.cpp:554
class BIASGeometryBase_EXPORT HomgPoint3D
void PrintWinCoords(const std::string &text, const int &xpos, const int &ypos, const int &winWidthFallback=640, const int &winHeightFallback=480) const
print text on OpenGL screen at 2D pos (xpos,ypos) in windows (pixel) coordiantes. ...
Definition: DrawTextGL.cpp:237