Documentation


x3dGLMapVisitor.cpp

Go to the documentation of this file.
00001 #include "x3dGLMapVisitor.h"
00002 #include "x3dGLMapStateVariables.h"
00003 #include <animal/engine/EngineNode.h>
00004 #include <iostream>
00005 // #include <X3DTK/private/X3D_Coordinate.h>
00006 // #include <X3DTK/private/X3D_Transform.h>
00007 // #include <X3DTK/private/X3D_X3DGeometryNode.h>
00008 // #include <animal/vector.h>
00009 
00010 namespace X3DTK
00011 {
00012 namespace GL
00013 {
00014 
00015 X3DGLMapVisitor::X3DGLMapVisitor()
00016 {
00017     // Enter functions.
00018     defineEnterFunction(&X3DGLMapVisitor::enterX3DNode);
00019 }
00020 
00021 X3DGLMapVisitor::~X3DGLMapVisitor()
00022 {}
00023 
00024 void X3DGLMapVisitor::enterX3DNode(X3DNode * N)
00025 {
00026     //std::cout<<"X3DGLMapVisitor::enterX3DNode named " << N->getName() << std::endl;
00027     X3DGLMapStateVariables * _stateVariables = Singleton<X3DGLMapStateVariables>::getInstance();
00028 
00029     if(X3D::X3DNode * X3D_N = N->getX3DReference())
00030         (*_stateVariables->getX3dGLMap())[X3D_N].push_back(N);
00031     else
00032         std::cout<<"X3DGLMapVisitor::enterX3DNode, no X3D reference to GL node named " << N->getName() << std::endl;
00033 
00034 /*    // Identify the nodes modified by the engine
00035     X3DTK::X3D::EngineNode* engineNode = dynamic_cast<X3DTK::X3D::EngineNode*>(N);
00036     if(engineNode)
00037     {
00038         std::cout<<"X3DGLMapVisitor::enterX3DNode found engine node named "<<engineNode->getName() << std::endl;
00039     typedef X3DTK::X3D::X3D_X3DNodeList NodeList;
00040         NodeList outputs;
00041         engineNode->declareOutputs(outputs);
00042         X3DTK::X3DGLMap *x3dGLMap = _stateVariables->getX3dGLMap();
00043         for(NodeList::iterator n; n!=outputs.end(); ++n )
00044         {
00045             if( X3DTK::X3D::Coordinate* c = dynamic_cast<X3DTK::X3D::Coordinate*>(*n) )
00046             {
00047                 // find the Geometry nodes linked to this Coordinate node
00048                 MFNode parents = c->getParentList();
00049                 for( MFNode::iterator p=parents.begin(); p!=parents.end(); ++p)
00050                 {
00051                     if( X3DTK::X3D::X3DGeometryNode* g = dynamic_cast<X3DTK::X3D::X3DGeometryNode*>(*p) )
00052                     {
00053                         // add its corresponding gl nodes to the list glNodeToUpdate
00054                         for (std::list<GL::X3DNode *>::iterator i= (*x3dGLMap)[g].begin(); i!=(*x3dGLMap)[g].end(); ++i)
00055                         {
00056                             _stateVariables->engineUpdates[engineNode].push_back(*i);
00057                         }
00058                     }
00059                 }
00060             }
00061             else if( X3DTK::X3D::Transform* t = dynamic_cast<X3DTK::X3D::Transform*>(*n) )
00062             {
00063                 // add its corresponding gl nodes to the list glNodeToUpdate
00064                 for (std::list<GL::X3DNode *>::iterator i= (*x3dGLMap)[t].begin(); i!=(*x3dGLMap)[t].end(); ++i)
00065                 {
00066                     _stateVariables->engineUpdates[engineNode].push_back(*i);
00067                 }
00068             }
00069             else
00070             {
00071                 std::cout<<"X3DGLMapVisitor::enterX3DNode, engine "<< engineNode->getName() <<", can not find gl update to perform for output "<< (*n)->getName() << std::endl;
00072             }
00073 
00074         }
00075 
00076     }
00077     else {
00078         std::cout<<"X3DGLMapVisitor::enterX3DNode found non-engine node named "<<N->getName() << std::endl;
00079     }*/
00080 }
00081 }//GL
00082 }//X3DTK

Generated on Thu Dec 23 13:52:27 2004 by doxygen 1.3.6