Basic Image AlgorithmS Library 2.8.0

SceneTextScreen.cpp

00001 #include "SceneTextScreen.hh"
00002 
00003 #ifdef BIAS_HAVE_OPENGL
00004 #  include <Gui/biasgl.h>
00005 #  ifdef __APPLE__
00006 #    include <OpenGL/glu.h>
00007 #  else // __APPLE__
00008 #    include <GL/glu.h>
00009 #  endif // __APPLE__
00010 #  include <Utils/StatekeeperGL.hh>
00011 #endif
00012 
00013 
00014 using namespace std;
00015 using namespace BIAS;
00016 using namespace BIAS;
00017 
00018 SceneTextScreen::SceneTextScreen(bool MakeDemoText): isInitialized_(false) {
00019   if (MakeDemoText) {
00020     textPositions_.push_back(HomgPoint3D(0.0,0.0,1.0));
00021     textContents_.push_back("Northern Star");
00022     textColors_.push_back(RGBf(1.0f, 0.0f, 0.0f));
00023   }
00024 
00025   fontName_ = "-*-helvetica-bold-r-normal--12-*-*-*-p-*-iso8859-1";//DrawTextGL_DEFAULT_FONTNAME;
00026   fontHeight_  = 12;
00027 }
00028 void SceneTextScreen::Free(){
00029   #ifdef BIAS_HAVE_FONTGL
00030 drawer_.DeleteFont();
00031 #endif
00032 }
00033 void SceneTextScreen::Draw()
00034 {
00035 #ifdef WIN32
00036   BIASWARNONCE("windows font selection mechanism not yet implmented here.");
00037   return;
00038 #endif
00039 #ifdef BIAS_HAVE_OPENGL
00040 
00041   if (!isInitialized_) {
00042 #ifdef BIAS_HAVE_FONTGL
00043     if (drawer_.InitFont(NULL, fontName_, fontHeight_)!=0) {
00044       cerr<<"init of font failed ..."<<endl;
00045       return;
00046     }
00047 #else
00048     BIASWARNONCE("FontGL is disabled in BIAS.");
00049     return;
00050 #endif
00051     isInitialized_ = true;
00052   }
00053   for (unsigned int i=0; i<textContents_.size(); i++) {
00054     glColor3f(textColors_[i][0], textColors_[i][1], textColors_[i][2]);
00055 #ifdef BIAS_HAVE_FONTGL
00056     
00057    drawer_.PrintWinCoords(textContents_[i],(int) textPositions_[i][0], 
00058                     (int)textPositions_[i][1], 0,0);
00059     
00060 
00061     glColor3f(0.0, 0.0, 1.0);
00062     //drawer_.Print3D(".", textPositions_[i][0], 
00063     //                textPositions_[i][1], textPositions_[i][2]);
00064     glBegin(GL_POINTS);
00065     glVertex3f(textPositions_[i][0], textPositions_[i][1], textPositions_[i][2]);
00066     glEnd();
00067 #endif
00068   }
00069 #endif
00070  
00071 }
00072  
00073 
00074 #ifdef BIAS_HAVE_XML2
00075 
00076 int SceneTextScreen::XMLGetClassName(std::string& TopLevelTag,
00077                                double& Version) const {
00078   TopLevelTag = "SceneTextScreen";
00079   Version = 0.1;
00080   return 0;
00081 }
00082 
00083 int SceneTextScreen::XMLOut(const xmlNodePtr mainNode, XMLIO& XMLObject) const {
00084   for (unsigned int i=0; i<textContents_.size(); i++) {
00085     xmlNodePtr childNode = XMLObject.addChildNode(mainNode, "Text");
00086      
00087     XMLObject.addAttribute(childNode, "r", textColors_[i][0]);
00088     XMLObject.addAttribute(childNode, "g", textColors_[i][1]);
00089     XMLObject.addAttribute(childNode, "b", textColors_[i][2]);
00090 
00091     XMLObject.addAttribute(childNode, "x", textPositions_[i][0]);
00092     XMLObject.addAttribute(childNode, "y", textPositions_[i][1]);
00093     XMLObject.addAttribute(childNode, "z", textPositions_[i][2]);
00094     XMLObject.addAttribute(childNode, "w", textPositions_[i][3]);
00095     
00096     XMLObject.addContent(childNode, textContents_[i]);
00097   }
00098   return 0;
00099 }
00100 
00101 int SceneTextScreen::XMLIn(const xmlNodePtr Node, XMLIO& XMLObject) {
00102   textColors_.clear();
00103   textPositions_.clear();
00104   textContents_.clear();
00105   xmlNodePtr childNode = XMLObject.getFirstChild(Node);
00106   while (!(childNode==NULL)) {
00107     if (XMLObject.getNodeName(childNode)=="Text") {
00108       RGBf thecolor;
00109       HomgPoint3D theposition;
00110      
00111       thecolor[0] = XMLObject.getAttributeValueDouble(childNode, "r");
00112       thecolor[1] = XMLObject.getAttributeValueDouble(childNode, "g");
00113       thecolor[2] = XMLObject.getAttributeValueDouble(childNode, "b");
00114 
00115       theposition[0] = XMLObject.getAttributeValueDouble(childNode, "x");
00116       theposition[1] = XMLObject.getAttributeValueDouble(childNode, "y");
00117       theposition[2] = XMLObject.getAttributeValueDouble(childNode, "z");
00118       theposition[3] = XMLObject.getAttributeValueDouble(childNode, "w");
00119 
00120       textColors_.push_back(thecolor);
00121       textPositions_.push_back(theposition);
00122       string theContent = "___"+XMLObject.getNodeContentString(childNode);
00123       textContents_.push_back(theContent);
00124       cout<<"Found "<<theContent<<" at "<<theposition<<" with color "
00125           <<thecolor<<endl;      
00126     }
00127     childNode = XMLObject.getNextChild();
00128   }
00129   cout<<"Read "<<textColors_.size()<<" texts"<<endl;  
00130  
00131   return 0;
00132 }
00133 
00134 #endif // BIAS_HAVE_XML2
00135 
00136 
00137 
00138 
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends