58         static void NormalizeBufferCoordinates(GLint size, GLfloat * buffer, GLfloat MaxSize, GLfloat& zmin, GLfloat& zmax) ;
 
   64         static void ComputeBufferBB(GLint size, GLfloat * buffer,
 
   65                 GLfloat & xmin, GLfloat & xmax,
 
   66                 GLfloat & ymin, GLfloat & ymax,
 
   67                 GLfloat & zmin, GLfloat & zmax) ;
 
   70         static void print3DcolorVertex(GLint size, GLint * count, GLfloat * buffer) ;
 
   71         static void debug_printBuffer(GLint size, GLfloat *buffer) ;
 
   73         static void NormalizePrimitiveCoordinates(GLfloat * & loc,GLfloat MaxSize,GLfloat zmin,GLfloat zmax) ;
 
   74         static void ComputePrimitiveBB( GLfloat * & loc,
 
   75                 GLfloat & xmin,GLfloat & xmax,
 
   76                 GLfloat & ymin,GLfloat & ymax,
 
   77                 GLfloat & zmin,GLfloat & zmax);
 
   79         static const char *nameOfToken(
int token);
 
   81         static const double EGALITY_EPS ;
 
   84 const double ParserUtils::EGALITY_EPS = 0.00001 ;
 
   86 void ParserGL::parseFeedbackBuffer( GLfloat *buffer,
int size,
 
   87                                                 std::vector<PtrPrimitive>& primitive_tab,
 
   95     nb_degenerated_lines = 0 ;
 
   96     nb_degenerated_polys = 0 ;
 
   97     nb_degenerated_points = 0 ;
 
  108     ParserUtils::ComputeBufferBB(size, buffer, _xmin,_xmax,_ymin,_ymax,_zmin,_zmax) ;
 
  110 #ifdef DEBUGEPSRENDER 
  111     printf(
"Buffer bounding box: %f %f %f %f %f %f\n",xmin,xmax,ymin,ymax,zmin,zmax) ;
 
  113     float Zdepth = 
max(_ymax-_ymin,_xmax-_xmin) ;
 
  114     ParserUtils::NormalizeBufferCoordinates(size,buffer,Zdepth,_zmin,_zmax) ;
 
  117     GLfloat *end = buffer + size;
 
  119     GLfloat *loc = buffer ;
 
  121     int N = size/200 + 1 ;
 
  125         token = int(0.5f + *loc) ;
 
  128         if((end-loc)/N >= next_step)
 
  129             vparams.progress((end-loc)/(
float)size, QGLViewer::tr(
"Parsing feedback buffer.")), ++next_step ;
 
  134             case GL_LINE_RESET_TOKEN:
 
  138                     primitive_tab.push_back(ParserUtils::checkSegment(S)) ;
 
  141                         nb_degenerated_lines++ ;
 
  144                     loc += 2*Feedback3DColor::sizeInBuffer();
 
  148             case GL_POLYGON_TOKEN:
 
  150                     nvertices = int(0.5f + *loc) ;
 
  153                     std::vector<Feedback3DColor> verts ;
 
  155                     for(
int i=0;i<nvertices;++i)
 
  156                         verts.push_back(
Feedback3DColor(loc)),loc+=Feedback3DColor::sizeInBuffer() ;
 
  160                     primitive_tab.push_back(ParserUtils::checkPolygon(P)) ;
 
  163                         nb_degenerated_polys++ ;
 
  173                     primitive_tab.push_back(Pt);
 
  176                         nb_degenerated_points++ ;
 
  179                     loc += Feedback3DColor::sizeInBuffer();
 
  199     if((P->vertex(0) - P->vertex(1)).infNorm() < EGALITY_EPS)
 
  205         return checkPoint(pp) ;
 
  213     if(P->nbVertices() != 3)
 
  215         cout << 
"unexpected case: Polygon with " << P->nbVertices() << 
" vertices !" << endl ;
 
  220     if(P->FlatFactor() < FLAT_POLYGON_EPS)
 
  224         int n = P->nbVertices() ;
 
  227             if( (P->vertex(i) - P->vertex((i+1)%n)).norm() > EGALITY_EPS)
 
  229                 Segment *pp = 
new Segment(P->sommet3DColor((i+1)%n),P->sommet3DColor((i+2)%n)) ;
 
  233                 return checkSegment(pp) ;
 
  240         return checkPoint(pp) ;
 
  251 void ParserUtils::print3DcolorVertex(GLint size, GLint * count, GLfloat * buffer)
 
  256     for (i = 0; i < Feedback3DColor::sizeInBuffer(); i++)
 
  258         printf(
"%4.2f ", buffer[size - (*count)]);
 
  264 void ParserUtils::debug_printBuffer(GLint size, GLfloat * buffer)
 
  267     int token, nvertices;
 
  271         token = int(buffer[size - count]);
 
  275             case GL_PASS_THROUGH_TOKEN:
 
  276                 printf(
"GL_PASS_THROUGH_TOKEN\n");
 
  277                 printf(
"  %4.2f\n", buffer[size - count]);
 
  281                 printf(
"GL_POINT_TOKEN\n");
 
  282                 print3DcolorVertex(size, &count, buffer);
 
  285                 printf(
"GL_LINE_TOKEN\n");
 
  286                 print3DcolorVertex(size, &count, buffer);
 
  287                 print3DcolorVertex(size, &count, buffer);
 
  289             case GL_LINE_RESET_TOKEN:
 
  290                 printf(
"GL_LINE_RESET_TOKEN\n");
 
  291                 print3DcolorVertex(size, &count, buffer);
 
  292                 print3DcolorVertex(size, &count, buffer);
 
  294             case GL_POLYGON_TOKEN:
 
  295                 printf(
"GL_POLYGON_TOKEN\n");
 
  296                 nvertices = int(buffer[size - count]) ;
 
  298                 for (; nvertices > 0; nvertices--)
 
  299                     print3DcolorVertex(size, &count, buffer);
 
  304 void ParserUtils::NormalizePrimitiveCoordinates(GLfloat * & loc,GLfloat MaxSize,GLfloat zmin,GLfloat zmax)
 
  311     int size = Feedback3DColor::sizeInBuffer() ;
 
  315         case GL_LINE_RESET_TOKEN:
 
  318                 for (i = 0; i < 2; i++)
 
  319                     (loc+size*i)[2] = ((loc+size*i)[2] - zmin)/(zmax-zmin)*MaxSize ;
 
  324         case GL_POLYGON_TOKEN:
 
  326                 nvertices = int(*loc) ;
 
  329                 for (i = 0; i < nvertices; i++)
 
  330                     (loc+size*i)[2] = ((loc+size*i)[2] - zmin)/(zmax-zmin)*MaxSize ;
 
  332                 loc += nvertices * size;  
 
  337                 loc[2] = (loc[2] - zmin)/(zmax-zmin)*MaxSize ;
 
  344 #ifdef DEBUGEPSRENDER 
  345             printf(
"%s (%d) not handled yet. Sorry.\n", ParserUtils::nameOfToken(token), token);
 
  351 void ParserUtils::ComputePrimitiveBB(GLfloat * & loc,GLfloat & xmin,GLfloat & xmax,GLfloat & ymin,GLfloat & ymax, GLfloat & zmin,GLfloat & zmax)
 
  358     int size = Feedback3DColor::sizeInBuffer() ;
 
  362         case GL_LINE_RESET_TOKEN:
 
  365                 for (i = 0; i < 2; i++)
 
  369                     if(f.x() < xmin) xmin = GLfloat(f.x()) ;
 
  370                     if(f.y() < ymin) ymin = GLfloat(f.y()) ;
 
  371                     if(f.z() < zmin) zmin = GLfloat(f.z()) ;
 
  372                     if(f.x() > xmax) xmax = GLfloat(f.x()) ;
 
  373                     if(f.y() > ymax) ymax = GLfloat(f.y()) ;
 
  374                     if(f.z() > zmax) zmax = GLfloat(f.z()) ;
 
  381         case GL_POLYGON_TOKEN:
 
  383                 nvertices = int(*loc) ;
 
  386                 for (i = 0; i < nvertices; i++)
 
  390                     if(f.x() < xmin) xmin = GLfloat(f.x()) ;
 
  391                     if(f.y() < ymin) ymin = GLfloat(f.y()) ;
 
  392                     if(f.z() < zmin) zmin = GLfloat(f.z()) ;
 
  393                     if(f.x() > xmax) xmax = GLfloat(f.x()) ;
 
  394                     if(f.y() > ymax) ymax = GLfloat(f.y()) ;
 
  395                     if(f.z() > zmax) zmax = GLfloat(f.z()) ;
 
  398                 loc += nvertices * size;  
 
  406                 if(f.x() < xmin) xmin = GLfloat(f.x()) ;
 
  407                 if(f.y() < ymin) ymin = GLfloat(f.y()) ;
 
  408                 if(f.z() < zmin) zmin = GLfloat(f.z()) ;
 
  409                 if(f.x() > xmax) xmax = GLfloat(f.x()) ;
 
  410                 if(f.y() > ymax) ymax = GLfloat(f.y()) ;
 
  411                 if(f.z() > zmax) zmax = GLfloat(f.z()) ;
 
  419 #ifdef DEBUGEPSRENDER 
  420             printf(
"Incomplete implementation.  Unexpected token (%d).\n", token);
 
  426 void ParserUtils::NormalizeBufferCoordinates(GLint size, GLfloat * buffer, GLfloat MaxSize, GLfloat& zmin,GLfloat& zmax)
 
  432 #ifdef DEBUGEPSRENDER 
  433         printf(
"Warning: zmin = zmax in NormalizePrimitiveCoordinates\n") ;
 
  442         NormalizePrimitiveCoordinates(loc,MaxSize,zmin,zmax);
 
  448 void ParserUtils::ComputeBufferBB(GLint size, GLfloat * buffer,
 
  449              GLfloat & xmin, GLfloat & xmax,
 
  450              GLfloat & ymin, GLfloat & ymax,
 
  451              GLfloat & zmin, GLfloat & zmax)
 
  459         ComputePrimitiveBB(loc,xmin,xmax,ymin,ymax,zmin,zmax);
 
  467 const char *ParserUtils::nameOfToken(
int token)
 
  471         case GL_PASS_THROUGH_TOKEN:     
return "GL_PASS_THROUGH_TOKEN" ;
 
  472         case GL_POINT_TOKEN:            
return "GL_POINT_TOKEN" ;
 
  473         case GL_LINE_TOKEN:                 
return "GL_LINE_TOKEN" ;
 
  474         case GL_POLYGON_TOKEN:          
return "GL_POLYGON_TOKEN" ;
 
  475         case GL_BITMAP_TOKEN:           
return "GL_BITMAP_TOKEN" ;
 
  476         case GL_DRAW_PIXEL_TOKEN:       
return "GL_DRAW_PIXEL_TOKEN" ;
 
  477         case GL_COPY_PIXEL_TOKEN:       
return "GL_COPY_PIXEL_TOKEN" ;
 
  478         case GL_LINE_RESET_TOKEN:       
return "GL_LINE_RESET_TOKEN" ;
 
  480                                                 return "(Unidentified token)" ;
 
FARSA_UTIL_TEMPLATE const T max(const T &t1, const U &t2)