/****************************************************************************
** GMAF - The Geometry Modeling Algorithms Framework
**
** Created : 04032000
**
** Copyright (C) 2000 by Le-Jeng Shiue.  All rights reserved.
**
****************************************************************************/
#ifndef gmafPCCM_H
#define gmafPCCM_H

#include "BlitzExtension/blitzConfig.h"

#include "Algorithm/gmafAlgorithm.h"

class gmafDataStructureManager;
class gmafQuad;
class gmafQuadMap;
class gmafPCCMQuad;
class gmafPCCMQuadMap;
class gmafCCSubdivision;
class gmafVisualObject;

/**
  gmafPCCM : Patching Catmull-Clark Meshes 
*/
class gmafPCCM : public gmafAlgorithm {
// ENUMS
public:

// VARIABLES
/**@name Class Variables */
//@{
protected:
  /**
   */
  gmafCCSubdivision* mpCCSub;

  /**
     mpQuadMap is generated by CCSubdivision
  */    
  gmafQuadMap* mpQuadMap;
  /**
     The result of PCCM
  */    
  gmafPCCMQuadMap* mpPCCMQuadMap;

private:
  VertexMatrix2D mQuadArray;
  VertexMatrix2D mPCCMQuadArray;
  
  bool mUseNormalRule;
//@}

// METHODS
/**@name Class Methods */
//@{
public:
  /**
     Constructor of gmafPCCM.
  */    
  gmafPCCM(gmafDataStructureManager* dsm);
  /**
     Destructor of gmafPCCM.
  */    
  virtual ~gmafPCCM();
  
  virtual void run();
  virtual void run(int rule, int depth = 2, 
		   float blrat = 0, bool normal = false);
  virtual void exec();

  /*
  virtual void createVisualObject();
  virtual SO<MThing> getVisualObject();
  */
  virtual gmafVisualObject* visualize();
protected:
  /**
     Step1 of PCCM : knot insertion
   */
  void knotInsertion();
  /**
     Step2 of PCCM : corner smoothing 
   */
  void cornerSmoothing();
  
  inline void setNormalRule(bool useit) { mUseNormalRule = useit; }
private:
  /**
     Passes of knots insertion
     vpass : vertical pass
     hpass : horizontal pass
   */
  inline void vpass(VertexMatrix2D& qarray, VertexMatrix2D& pccmqarray);
  inline void hpass(VertexMatrix2D& qarray, VertexMatrix2D& pccmqarray);
};

#endif gmafPCCM_H
