#ifndef POINTGRID3DBILINEARDRAW_H
#define POINTGRID3DBILINEARDRAW_H

#include <cassert>
using namespace std;

#include <meshpatch.h>
#include <graphmisc.h>
#include <gobj.h>
#include <pointgrid3D.h>


/*!
\brief Draw each patch in a random color with dots.

This is to visualize the patches. 
*/
class pointgrid3Dbilineardraw : public gobjContainer
{
public:

  /** The current row position. */
  uint row;
  /** The current column position. */
  uint col;

  /** The object being drawn. */
  pointgrid3D const & pg;

  /** The sphere at the points. */
  gobjQuadric quadric;

  /** Turn the points on. */
  bool pointsdisplay;

  /** The number of points drawn to represent a surface. */
  uint pointsperpatch ;

  /** bi-linear mesh patch. */
  meshpatch mp;

  /** Construct with point turned on. */
  pointgrid3Dbilineardraw(pointgrid3D const & pg_);
 
  /** Patch pointer. By setting row and col this returns the
      corner points of that patch. */
  point3<double> const & operator () (uintc r, uintc k) const
  {
    assert( r<=1);
    assert( k<=1);
 
    assert(row<pg.M);
    assert(col<pg.N);

    uint index = row + col*pg.N;
    index += k;
    index += r*pg.N;
  
    return pg.pt[index];
  }

  /** Update the graphics by writing to the graphics
    container. */
  void update();

};


#endif



