ccGLWindow::paintGL()
|
ccGLWindow::fullRenderingPass(...)
|
ccGLWindow::drawBackground(context, renderingParams);
ccGLWindow::draw3D(context, renderingParams);//ccGLWindow::draw3D(CC_DRAW_CONTEXT& CONTEXT, RenderingParams& renderingParams)
|
m_globalDBRoot->draw(CONTEXT); // ccHObject*
m_winDBRoot->draw(CONTEXT); //ccHObject*
1 void ccHObject::draw(CC_DRAW_CONTEXT& context) 2 { 3 if (!isEnabled()) 4 return; 5 6 //are we currently drawing objects in 2D or 3D? 7 bool draw3D = MACRO_Draw3D(context); 8 9 //the entity must be either visible or selected, and of course it should be displayed in this context 10 bool drawInThisContext = ((m_visible || m_selected) && m_currentDisplay == context._win); 11 12 //no need to display anything but clouds and meshes in "element picking mode" 13 drawInThisContext &= ( ( !MACRO_DrawPointNames(context) || isKindOf(CC_TYPES::POINT_CLOUD) ) || 14 ( !MACRO_DrawTriangleNames(context) || isKindOf(CC_TYPES::MESH) )); 15 16 if (draw3D) 17 { 18 //apply 3D 'temporary' transformation (for display only) 19 if (m_glTransEnabled) 20 { 21 glMatrixMode(GL_MODELVIEW); 22 glPushMatrix(); 23 glMultMatrixf(m_glTrans.data()); 24 } 25 26 if ( context.decimateCloudOnMove //LOD for clouds is enabled? 27 && context.currentLODLevel >= context.minLODLevel //and we are currently rendering higher levels? 28 ) 29 { 30 //only for real clouds 31 drawInThisContext &= isA(CC_TYPES::POINT_CLOUD); 32 } 33 } 34 35 //draw entity 36 if (m_visible && drawInThisContext) 37 { 38 if (( !m_selected || !MACRO_SkipSelected(context) ) && 39 ( m_selected || !MACRO_SkipUnselected(context) )) 40 { 41 //apply default color (in case of) 42 ccGL::Color3v(context.pointsDefaultCol.rgb); 43 44 drawMeOnly(context); 45 46 //draw name in 3D (we display it in the 2D foreground layer in fact!) 47 if (m_showNameIn3D && MACRO_Draw2D(context) && MACRO_Foreground(context) && !MACRO_DrawNames(context)) 48 drawNameIn3D(context); 49 } 50 } 51 52 //draw entity's children 53 for (Container::iterator it = m_children.begin(); it != m_children.end(); ++it) 54 (*it)->draw(context); 55 56 //if the entity is currently selected, we draw its bounding-box 57 if (m_selected && draw3D && drawInThisContext && !MACRO_DrawNames(context) && context.currentLODLevel == 0) 58 { 59 drawBB(context.bbDefaultCol); 60 } 61 62 if (draw3D && m_glTransEnabled) 63 glPopMatrix(); 64 }
点云八叉树
class QCC_DB_LIB_API ccOctree : public CCLib::DgmOctree, public ccHObject
八叉树的网格显示,QCC_DB_LIB项目下。
1 /*** RENDERING METHODS ***/ 2 3 void ccOctree::RenderOctreeAs( CC_OCTREE_DISPLAY_TYPE octreeDisplayType, 4 ccOctree* theOctree, 5 unsigned char level, 6 ccGenericPointCloud* theAssociatedCloud, 7 int &octreeGLListID, 8 bool updateOctreeGLDisplay) 9 { 10 if (!theOctree || !theAssociatedCloud) 11 return; 12 13 glPushAttrib(GL_LIGHTING_BIT); 14 15 if (octreeDisplayType == WIRE) 16 { 17 //cet affichage demande trop de memoire pour le stocker sous forme de liste OpenGL 18 //donc on doit le generer dynamiquement 19 20 glDisable(GL_LIGHTING); //au cas où la lumiere soit allumee 21 ccGL::Color3v(ccColor::green.rgba); 22 23 void* additionalParameters[] = { theOctree->m_frustrumIntersector }; 24 theOctree->executeFunctionForAllCellsAtLevel( level, 25 &DrawCellAsABox, 26 additionalParameters); 27 } 28 else 29 { 30 glDrawParams glParams; 31 theAssociatedCloud->getDrawingParameters(glParams); 32 33 if (glParams.showNorms) 34 { 35 //DGM: Strangely, when Qt::renderPixmap is called, the OpenGL version is sometimes 1.0! 36 glEnable((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2 ? GL_RESCALE_NORMAL : GL_NORMALIZE)); 37 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, CC_DEFAULT_CLOUD_AMBIENT_COLOR.rgba ); 38 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, CC_DEFAULT_CLOUD_SPECULAR_COLOR.rgba ); 39 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, CC_DEFAULT_CLOUD_DIFFUSE_COLOR.rgba ); 40 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, CC_DEFAULT_CLOUD_EMISSION_COLOR.rgba ); 41 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, CC_DEFAULT_CLOUD_SHININESS); 42 glEnable(GL_LIGHTING); 43 44 glEnable(GL_COLOR_MATERIAL); 45 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); 46 } 47 48 if (!glParams.showColors) 49 ccGL::Color3v(ccColor::white.rgba); 50 51 if (updateOctreeGLDisplay || octreeGLListID < 0) 52 { 53 if (octreeGLListID < 0) 54 octreeGLListID = glGenLists(1); 55 else if (glIsList(octreeGLListID)) 56 glDeleteLists(octreeGLListID,1); 57 glNewList(octreeGLListID,GL_COMPILE); 58 59 if (octreeDisplayType == MEAN_POINTS) 60 { 61 void* additionalParameters[2] = { reinterpret_cast<void*>(&glParams), 62 reinterpret_cast<void*>(theAssociatedCloud), 63 }; 64 65 glBegin(GL_POINTS); 66 theOctree->executeFunctionForAllCellsAtLevel( level, 67 &DrawCellAsAPoint, 68 additionalParameters); 69 glEnd(); 70 } 71 else 72 { 73 //by default we use a box as primitive 74 PointCoordinateType cs = theOctree->getCellSize(level); 75 CCVector3 dims(cs,cs,cs); 76 ccBox box(dims); 77 box.showColors(glParams.showColors || glParams.showSF); 78 box.showNormals(glParams.showNorms); 79 80 //trick: replace all normal indexes so that they point on the first one 81 { 82 if (box.arePerTriangleNormalsEnabled()) 83 for (unsigned i=0;i<box.size();++i) 84 box.setTriangleNormalIndexes(i,0,0,0); 85 } 86 87 //fake context 88 CC_DRAW_CONTEXT context; 89 context.flags = CC_DRAW_3D | CC_DRAW_FOREGROUND| CC_LIGHT_ENABLED; 90 context._win = 0; 91 92 void* additionalParameters[4] = { reinterpret_cast<void*>(&glParams), 93 reinterpret_cast<void*>(theAssociatedCloud), 94 reinterpret_cast<void*>(&box), 95 reinterpret_cast<void*>(&context) 96 }; 97 98 theOctree->executeFunctionForAllCellsAtLevel( level, 99 &DrawCellAsAPrimitive, 100 additionalParameters); 101 } 102 103 glEndList(); 104 } 105 106 glCallList(octreeGLListID); 107 108 if (glParams.showNorms) 109 { 110 glDisable(GL_COLOR_MATERIAL); 111 glDisable((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2 ? GL_RESCALE_NORMAL : GL_NORMALIZE)); 112 glDisable(GL_LIGHTING); 113 } 114 } 115 116 glPopAttrib(); 117 }