本文整理汇总了C++中VRenderParams类的典型用法代码示例。如果您正苦于以下问题:C++ VRenderParams类的具体用法?C++ VRenderParams怎么用?C++ VRenderParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VRenderParams类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportToFile
void Exporter::exportToFile(const QString& filename,
const vector<PtrPrimitive>& primitive_tab,
VRenderParams& vparams)
{
QFile file(filename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox::warning(NULL, QGLViewer::tr("Exporter error", "Message box window title"), QGLViewer::tr("Unable to open file %1.").arg(filename));
return;
}
QTextStream out(&file);
writeHeader(out) ;
unsigned int N = primitive_tab.size()/200 + 1 ;
for(unsigned int i=0;i<primitive_tab.size();++i)
{
Point *p = dynamic_cast<Point *>(primitive_tab[i]) ;
Segment *s = dynamic_cast<Segment *>(primitive_tab[i]) ;
Polygone *P = dynamic_cast<Polygone *>(primitive_tab[i]) ;
if(p != NULL) spewPoint(p,out) ;
if(s != NULL) spewSegment(s,out) ;
if(P != NULL) spewPolygone(P,out) ;
if(i%N == 0)
vparams.progress(i/(float)primitive_tab.size(),QGLViewer::tr("Exporting to file %1").arg(filename)) ;
}
writeFooter(out) ;
file.close();
}
示例2: sortPrimitives
void BSPSortMethod::sortPrimitives(std::vector<PtrPrimitive>& primitive_tab,VRenderParams& vparams)
{
// 1 - build BSP using polygons only
BSPTree tree;
Polygone *P;
int N = primitive_tab.size()/200 +1;
int nbinserted = 0;
vector<PtrPrimitive> segments_and_points; // Store segments and points for pass 2, because polygons are deleted
// by the insertion and can not be dynamic_casted anymore.
for(unsigned int i=0;i<primitive_tab.size();++i,++nbinserted)
{
if((P = dynamic_cast<Polygone *>(primitive_tab[i])) != NULL)
tree.insert(P);
else
segments_and_points.push_back(primitive_tab[i]);
if(nbinserted%N==0)
vparams.progress(nbinserted/(float)primitive_tab.size(), QGLViewer::tr("BSP Construction"));
}
// 2 - insert points and segments into the BSP
Segment *S;
Point *p;
for(unsigned int j=0;j<segments_and_points.size();++j,++nbinserted)
{
if((S = dynamic_cast<Segment *>(segments_and_points[j])) != NULL)
tree.insert(S);
else if((p = dynamic_cast<Point *>(segments_and_points[j])) != NULL)
tree.insert(p);
if(nbinserted%N==0)
vparams.progress(nbinserted/(float)primitive_tab.size(), QGLViewer::tr("BSP Construction"));
}
// 3 - refill the array with the content of the BSP
primitive_tab.resize(0);
tree.recursFillPrimitiveArray(primitive_tab);
}
示例3: recursTopologicalSort
void TopologicalSortUtils::recursTopologicalSort( vector< vector<int> >& precedence_graph,
vector<PtrPrimitive>& primitive_tab,
vector<bool>& already_rendered,
vector<bool>& already_visited,
vector<PtrPrimitive>& new_pr_tab,
int indx,
int& nb_cycles,
VRenderParams& vparams,
int info_cnt,int& nbrendered)
{
// One must first render the primitives indicated by the precedence graph,
// then render the current primitive. Skews are detected, but and treated.
already_visited[indx] = true ;
for(unsigned int j=0;j<precedence_graph[indx].size();++j)
{
// Both tests are important. If we ommit the second one, the recursion is
// always performed down to the next cycle, although this is useless if
// the current primitive was rendered already.
if(!already_visited[precedence_graph[indx][j]])
{
if(!already_rendered[precedence_graph[indx][j]])
recursTopologicalSort( precedence_graph,primitive_tab,already_rendered,already_visited,
new_pr_tab,precedence_graph[indx][j],nb_cycles,vparams,info_cnt,nbrendered) ;
}
else // A cycle is detected, but in this version, it is not broken.
++nb_cycles ;
}
if(!already_rendered[indx])
{
new_pr_tab.push_back(primitive_tab[indx]) ;
if((++nbrendered)%info_cnt==0)
vparams.progress(nbrendered/(float)primitive_tab.size(), QGLViewer::tr("Topological sort")) ;
}
already_rendered[indx] = true ;
already_visited[indx] = false ;
}
示例4: parseFeedbackBuffer
void ParserGL::parseFeedbackBuffer( GLfloat *buffer,int size,
std::vector<PtrPrimitive>& primitive_tab,
VRenderParams& vparams)
{
int token;
int nvertices = 0 ;
nb_lines = 0 ;
nb_polys = 0 ;
nb_points = 0 ;
nb_degenerated_lines = 0 ;
nb_degenerated_polys = 0 ;
nb_degenerated_points = 0 ;
// pre-treatment of coordinates so as to get something more consistent
_xmin = FLT_MAX ;
_ymin = FLT_MAX ;
_zmin = FLT_MAX ;
_xmax = -FLT_MAX ;
_ymax = -FLT_MAX ;
_zmax = -FLT_MAX ;
ParserUtils::ComputeBufferBB(size, buffer, _xmin,_xmax,_ymin,_ymax,_zmin,_zmax) ;
#ifdef DEBUGEPSRENDER
printf("Buffer bounding box: %f %f %f %f %f %f\n",xmin,xmax,ymin,ymax,zmin,zmax) ;
#endif
float Zdepth = max(_ymax-_ymin,_xmax-_xmin) ;
ParserUtils::NormalizeBufferCoordinates(size,buffer,Zdepth,_zmin,_zmax) ;
// now, read buffer
GLfloat *end = buffer + size;
GLfloat *loc = buffer ;
int next_step = 0 ;
int N = size/200 + 1 ;
while (loc < end)
{
token = int(0.5f + *loc) ;
loc++;
if((end-loc)/N >= next_step)
vparams.progress((end-loc)/(float)size, QGLViewer::tr("Parsing feedback buffer.")), ++next_step ;
switch (token)
{
case GL_LINE_TOKEN:
case GL_LINE_RESET_TOKEN:
{
Segment *S = new Segment(Feedback3DColor(loc),Feedback3DColor(loc+Feedback3DColor::sizeInBuffer())) ;
primitive_tab.push_back(ParserUtils::checkSegment(S)) ;
if(S == NULL)
nb_degenerated_lines++ ;
nb_lines++ ;
loc += 2*Feedback3DColor::sizeInBuffer();
}
break;
case GL_POLYGON_TOKEN:
{
nvertices = int(0.5f + *loc) ;
loc++;
std::vector<Feedback3DColor> verts ;
for(int i=0;i<nvertices;++i)
verts.push_back(Feedback3DColor(loc)),loc+=Feedback3DColor::sizeInBuffer() ;
Polygone *P = new Polygone(verts) ;
primitive_tab.push_back(ParserUtils::checkPolygon(P)) ;
if(P == NULL)
nb_degenerated_polys++ ;
nb_polys++ ;
}
break ;
case GL_POINT_TOKEN:
{
Point *Pt = new Point(Feedback3DColor(loc)) ;
primitive_tab.push_back(Pt);//ParserUtils::checkPoint(Pt)) ;
if(Pt == NULL)
nb_degenerated_points++ ;
nb_points++ ;
loc += Feedback3DColor::sizeInBuffer();
}
break;
default:
break;
}
}
//.........这里部分代码省略.........
示例5: while
void vrender::VectorialRender(RenderCB render_callback, void *callback_params, VRenderParams& vparams)
{
GLfloat *feedbackBuffer = NULL ;
SortMethod *sort_method = NULL ;
Exporter *exporter = NULL ;
try
{
GLint returned = -1 ;
vparams.error() = 0 ;
int nb_renders = 0 ;
vparams.progress(0.0, QGLViewer::tr("Rendering...")) ;
while(returned < 0)
{
if(feedbackBuffer != NULL)
delete[] feedbackBuffer ;
feedbackBuffer = new GLfloat[vparams.size()] ;
if(feedbackBuffer == NULL)
throw std::runtime_error("Out of memory during feedback buffer allocation.") ;
glFeedbackBuffer(vparams.size(), GL_3D_COLOR, feedbackBuffer);
glRenderMode(GL_FEEDBACK);
render_callback(callback_params);
returned = glRenderMode(GL_RENDER);
nb_renders++ ;
if(returned < 0)
vparams.size() *= 2 ;
}
#ifdef A_VOIR
if(SortMethod != EPS_DONT_SORT)
{
GLint depth_bits ;
glGetIntegerv(GL_DEPTH_BITS, &depth_bits) ;
EGALITY_EPS = 2.0/(1 << depth_bits) ;
LINE_EGALITY_EPS = 2.0/(1 << depth_bits) ;
}
#endif
if (returned > vparams.size())
vparams.size() = returned;
#ifdef _VRENDER_DEBUG
cout << "Size = " << vparams.size() << ", returned=" << returned << endl ;
#endif
// On a un beau feedback buffer tout plein de saloperies. Faut aller
// defricher tout ca. Ouaiiiis !
vector<PtrPrimitive> primitive_tab ;
ParserGL parserGL ;
parserGL.parseFeedbackBuffer(feedbackBuffer,returned,primitive_tab,vparams) ;
if(feedbackBuffer != NULL)
{
delete[] feedbackBuffer ;
feedbackBuffer = NULL ;
}
if(vparams.isEnabled(VRenderParams::OptimizeBackFaceCulling))
{
BackFaceCullingOptimizer bfopt ;
bfopt.optimize(primitive_tab,vparams) ;
}
// Lance la methode de sorting
switch(vparams.sortMethod())
{
case VRenderParams::AdvancedTopologicalSort:
case VRenderParams::TopologicalSort: {
TopologicalSortMethod *tsm = new TopologicalSortMethod() ;
tsm->setBreakCycles(vparams.sortMethod() == VRenderParams::AdvancedTopologicalSort) ;
sort_method = tsm ;
}
break ;
case VRenderParams::BSPSort:
sort_method = new BSPSortMethod() ;
break ;
case VRenderParams::NoSorting:
sort_method = new DontSortMethod() ;
break ;
default:
throw std::runtime_error("Unknown sorting method.") ;
}
sort_method->sortPrimitives(primitive_tab,vparams) ;
// Lance les optimisations. L'ordre est important.
//.........这里部分代码省略.........
示例6: optimize
void VisibilityOptimizer::optimize(vector<PtrPrimitive>& primitives,VRenderParams& vparams)
#endif
{
#ifdef DEBUG_VO
cout << "Optimizing visibility." << endl ;
#endif
int N = primitives.size()/200 + 1 ;
#ifdef DEBUG_EPSRENDER__SHOW1
// cout << "Showing viewer." << endl ;
// myViewer viewer ;
// viewer.show();
double minx = FLT_MAX ;
double miny = FLT_MAX ;
double maxx = -FLT_MAX ;
double maxy = -FLT_MAX ;
for(unsigned int i=0;i<primitives.size();++i)
for(int j=0;j<primitives[i]->nbVertices();++j)
{
if(maxx < primitives[i]->vertex(j).x()) maxx = primitives[i]->vertex(j).x() ;
if(maxy < primitives[i]->vertex(j).y()) maxy = primitives[i]->vertex(j).y() ;
if(minx > primitives[i]->vertex(j).x()) minx = primitives[i]->vertex(j).x() ;
if(miny > primitives[i]->vertex(j).y()) miny = primitives[i]->vertex(j).y() ;
}
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity() ;
glOrtho(minx,maxx,miny,maxy,-1,1) ;
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity() ;
cout << "Window set to " << minx << " " << maxx << " " << miny << " " << maxy << endl ;
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) ;
glLineWidth(3.0) ;
#endif
int nb_culled = 0 ;
// Ca serait pas mal mieux avec une interface c++...
gpc_polygon cumulated_union ;
cumulated_union.num_contours = 0 ;
cumulated_union.hole = NULL ;
cumulated_union.contour = NULL ;
int nboptimised = 0 ;
for(int pindex = primitives.size() - 1; pindex >= 0;--pindex,++nboptimised)
if(primitives[pindex] != NULL)
{
#ifdef A_FAIRE
percentage_finished = pindex / (float)primitives.size() ;
#endif
if(primitives[pindex]->nbVertices() > 1)
{
#ifdef DEBUG_VO
if(pindex%50==0)
{
char buff[500] ;
sprintf(buff,"Left: % 6ld - Culled: % 6ld", (long)pindex,(long)nb_culled) ;
fprintf(stdout,buff);
for(unsigned int j=0;j<strlen(buff);++j)
fprintf(stdout,"\b") ;
fflush(stdout) ;
}
#endif
try
{
PtrPrimitive p(primitives[pindex]) ;
gpc_polygon difference ;
gpc_polygon new_poly ;
gpc_polygon new_poly_reduced ;
new_poly.num_contours = 0 ;
new_poly.hole = NULL ;
new_poly.contour = NULL ;
new_poly_reduced.num_contours = 0 ;
new_poly_reduced.hole = NULL ;
new_poly_reduced.contour = NULL ;
// 1 - creates a gpc_polygon corresponding to the current primitive
gpc_vertex_list *new_poly_verts = new gpc_vertex_list ;
gpc_vertex_list *new_poly_reduced_verts = new gpc_vertex_list ;
double mx = 0.0 ;
double my = 0.0 ;
if(p->nbVertices() == 2)
{
new_poly_verts->num_vertices = 4 ;
new_poly_verts->vertex = new gpc_vertex[4] ;
new_poly_reduced_verts->num_vertices = 4 ;
new_poly_reduced_verts->vertex = new gpc_vertex[4] ;
double deps = 0.001 ;
double du = p->vertex(1).y()-p->vertex(0).y() ;
double dv = p->vertex(1).x()-p->vertex(0).x() ;
//.........这里部分代码省略.........