namespace X3DTK {
namespace MESH {

template<class MData, class VData, class EData, class FData, bool RW>
TemplateNormalsFlipper<MData, VData, EData, FData, RW>::TemplateNormalsFlipper()
: X3DOnePassProcessor()
{
  setGraphTraversal(new DFSGraphTraversal());
  setComponentVisitor(new TemplateNormalsFlipperCoreVisitor<MData, VData, EData, FData, RW>());
}

template<class MData, class VData, class EData, class FData, bool RW>
TemplateNormalsFlipper<MData, VData, EData, FData, RW>::~TemplateNormalsFlipper()
{
  Singleton<TemplateNormalsFlipperStateVariables<MData, VData, EData, FData, RW> >::removeInstance();
}

template<class MData, class VData, class EData, class FData, bool RW>
void TemplateNormalsFlipper<MData, VData, EData, FData, RW>::flip(Scene *S)
{
  flip(static_cast<X3DNode *>(S));
  
  S->getProcessHistory().addEntry("MESH::TemplateNormalsFlipper");
}

template<class MData, class VData, class EData, class FData, bool RW>
void TemplateNormalsFlipper<MData, VData, EData, FData, RW>::flip(X3DNode *N)
{
  MFNode ns = Singleton<TemplateNormalsFlipperStateVariables<MData, VData, EData, FData, RW> >::getInstance()->getSelectedNodes();
  for (MFNode::const_iterator it = ns.begin(); it != ns.end(); ++it)
  {
    std::cout << "sel = " << *it << std::endl;
  }
  
  Singleton<TemplateNormalsFlipperStateVariables<MData, VData, EData, FData, RW> >::getInstance()->init();
  traverse(N);
  Singleton<TemplateNormalsFlipperStateVariables<MData, VData, EData, FData, RW> >::getInstance()->finish(); 
}

template<class MData, class VData, class EData, class FData, bool RW>
void TemplateNormalsFlipper<MData, VData, EData, FData, RW>::setSelectedNodes(const MFNode &selectedNodes)
{
  Singleton<TemplateNormalsFlipperStateVariables<MData, VData, EData, FData, RW> >::getInstance()->setSelectedNodes(selectedNodes);
}

}
}  
