void ccPolyline::drawMeOnly(CC_DRAW_CONTEXT& context) { if (size() < 2) return; bool draw = false; if (MACRO_Draw3D(context)) { draw = !m_mode2D; } else if (m_mode2D) { bool drawFG = MACRO_Foreground(context); draw = ((drawFG && m_foreground) || (!drawFG && !m_foreground)); } if (draw) { if (colorsShown()) glColor3ubv(m_rgbColor); glBegin(m_isClosed ? GL_LINE_LOOP : GL_LINE_STRIP); unsigned count=size(); for (unsigned i=0;i<count;++i) glVertex3fv(m_theAssociatedCloud->getPoint(m_theIndexes->getValue(i))->u); glEnd(); } }
ccGenericPrimitive* ccGenericPrimitive::finishCloneJob(ccGenericPrimitive* primitive) const { if (primitive) { //'clone' vertices (everything but the points that are already here) if (primitive->m_associatedCloud && m_associatedCloud && m_associatedCloud->size() == primitive->m_associatedCloud->size()) { primitive->m_associatedCloud = m_associatedCloud->clone(primitive->m_associatedCloud); primitive->m_associatedCloud->setName(m_associatedCloud->getName()); } primitive->showNormals(normalsShown()); primitive->showColors(colorsShown()); primitive->showSF(sfShown()); //primitive->showMaterials(materialsShown()); //primitive->setName(getName()+QString(".clone")); primitive->setVisible(isVisible()); primitive->setEnabled(isEnabled()); } else { //if the calling primitive provide a null pointer, it means that the cloned version creation failed! ccLog::Warning("[ccGenericPrimitive::clone] Not enough memory!"); } return primitive; }
void ccDrawableObject::getDrawingParameters(glDrawParams& params) const { //color override if (isColorOverriden()) { params.showColors=true; params.showNorms=hasNormals() && normalsShown()/*false*/; params.showSF=false; } else { params.showNorms = hasNormals() && normalsShown(); params.showSF = hasDisplayedScalarField() && sfShown(); //colors are not displayed if scalar field is displayed params.showColors = !params.showSF && hasColors() && colorsShown(); } }
void ccPolyline::drawMeOnly(CC_DRAW_CONTEXT& context) { //no picking enabled on polylines if (MACRO_DrawPointNames(context)) return; unsigned vertCount = size(); if (vertCount < 2) return; bool draw = false; if (MACRO_Draw3D(context)) { draw = !m_mode2D; } else if (m_mode2D) { bool drawFG = MACRO_Foreground(context); draw = ((drawFG && m_foreground) || (!drawFG && !m_foreground)); } if (draw) { //standard case: list names pushing bool pushName = MACRO_DrawEntityNames(context); if (pushName) glPushName(getUniqueIDForDisplay()); if (colorsShown()) ccGL::Color3v(m_rgbColor.rgb); //display polyline if (vertCount > 1) { if (m_width != 0) { glPushAttrib(GL_LINE_BIT); glLineWidth(static_cast<GLfloat>(m_width)); } //DGM: we do the 'GL_LINE_LOOP' manually as I have a strange bug //on one on my graphic card with this mode! //glBegin(m_isClosed ? GL_LINE_LOOP : GL_LINE_STRIP); glBegin(GL_LINE_STRIP); for (unsigned i=0; i<vertCount; ++i) { ccGL::Vertex3v(getPoint(i)->u); } if (m_isClosed) { ccGL::Vertex3v(getPoint(0)->u); } glEnd(); //display arrow if (m_showArrow && m_arrowIndex < vertCount && (m_arrowIndex > 0 || m_isClosed)) { const CCVector3* P0 = getPoint(m_arrowIndex == 0 ? vertCount-1 : m_arrowIndex-1); const CCVector3* P1 = getPoint(m_arrowIndex); //direction of the last polyline chunk CCVector3 u = *P1 - *P0; u.normalize(); if (m_mode2D) { u *= -m_arrowLength; static const PointCoordinateType s_defaultArrowAngle = static_cast<PointCoordinateType>(15.0 * CC_DEG_TO_RAD); static const PointCoordinateType cost = cos(s_defaultArrowAngle); static const PointCoordinateType sint = sin(s_defaultArrowAngle); CCVector3 A(cost * u.x - sint * u.y, sint * u.x + cost * u.y, 0); CCVector3 B(cost * u.x + sint * u.y, -sint * u.x + cost * u.y, 0); glBegin(GL_POLYGON); ccGL::Vertex3v((A+*P1).u); ccGL::Vertex3v((B+*P1).u); ccGL::Vertex3v(( *P1).u); glEnd(); } else { if (!c_unitArrow) { c_unitArrow = QSharedPointer<ccCone>(new ccCone(0.5,0.0,1.0)); c_unitArrow->showColors(true); c_unitArrow->showNormals(false); c_unitArrow->setVisible(true); c_unitArrow->setEnabled(true); } if (colorsShown()) c_unitArrow->setTempColor(m_rgbColor); else c_unitArrow->setTempColor(context.pointsDefaultCol); //build-up unit arrow own 'context' CC_DRAW_CONTEXT markerContext = context; markerContext.flags &= (~CC_DRAW_ENTITY_NAMES); //we must remove the 'push name flag' so that the sphere doesn't push its own! markerContext._win = 0; glMatrixMode(GL_MODELVIEW); glPushMatrix(); ccGL::Translate(P1->x,P1->y,P1->z); ccGLMatrix rotMat = ccGLMatrix::FromToRotation(CCVector3(0,0,1),u); glMultMatrixf(rotMat.inverse().data()); glScalef(m_arrowLength,m_arrowLength,m_arrowLength); ccGL::Translate(0.0,0.0,-0.5); c_unitArrow->draw(markerContext); glPopMatrix(); } } if (m_width != 0) { glPopAttrib(); } } //display vertices if (m_showVertices) { glPushAttrib(GL_POINT_BIT); glPointSize((GLfloat)m_vertMarkWidth); glBegin(GL_POINTS); for (unsigned i=0; i<vertCount; ++i) { ccGL::Vertex3v(getPoint(i)->u); } glEnd(); glPopAttrib(); } if (pushName) glPopName(); } }
void ccPolyline::drawMeOnly(CC_DRAW_CONTEXT& context) { //no picking enabled on polylines if (MACRO_DrawPointNames(context)) return; unsigned vertCount = size(); if (vertCount < 2) return; bool draw = false; if (MACRO_Draw3D(context)) { draw = !m_mode2D; } else if (m_mode2D) { bool drawFG = MACRO_Foreground(context); draw = ((drawFG && m_foreground) || (!drawFG && !m_foreground)); } if (draw) { //standard case: list names pushing bool pushName = MACRO_DrawEntityNames(context); if (pushName) glPushName(getUniqueIDForDisplay()); if (colorsShown()) glColor3ubv(m_rgbColor); //display polyline { if (m_width != 0) { glPushAttrib(GL_LINE_BIT); glLineWidth(static_cast<GLfloat>(m_width)); } glBegin(m_isClosed ? GL_LINE_LOOP : GL_LINE_STRIP); for (unsigned i=0; i<vertCount; ++i) { ccGL::Vertex3v(getPoint(i)->u); } glEnd(); if (m_width != 0) { glPopAttrib(); } } //display vertices if (m_showVertices) { glPushAttrib(GL_POINT_BIT); glPointSize((GLfloat)m_vertMarkWidth); glBegin(GL_POINTS); for (unsigned i=0; i<vertCount; ++i) { ccGL::Vertex3v(getPoint(i)->u); } glEnd(); glPopAttrib(); } if (pushName) glPopName(); } }
void ccDrawableObject::toggleColors() { showColors(!colorsShown()); }
ccSubMesh* ccSubMesh::createNewSubMeshFromSelection(bool removeSelectedFaces, IndexMap* indexMap/*=0*/) { ccGenericPointCloud* vertices = getAssociatedCloud(); assert(vertices && m_associatedMesh); if (!vertices || !m_associatedMesh) { return NULL; } ccGenericPointCloud::VisibilityTableType* verticesVisibility = vertices->getTheVisibilityArray(); if (!verticesVisibility || !verticesVisibility->isAllocated()) { ccLog::Error(QString("[Sub-mesh %1] Internal error: vertex visibility table not instantiated!").arg(getName())); return NULL; } //we count the number of remaining faces unsigned triNum = m_triIndexes->currentSize(); unsigned visibleFaces = 0; { for (unsigned i=0; i<triNum; ++i) { const unsigned& globalIndex = m_triIndexes->getValue(i); const CCLib::VerticesIndexes* tsi = m_associatedMesh->getTriangleVertIndexes(globalIndex); //triangle is visible? if ( verticesVisibility->getValue(tsi->i1) == POINT_VISIBLE && verticesVisibility->getValue(tsi->i2) == POINT_VISIBLE && verticesVisibility->getValue(tsi->i3) == POINT_VISIBLE) { ++visibleFaces; } } } //nothing to do if (visibleFaces == 0) { if (indexMap) //we still have to translate global indexes! { for (unsigned i=0; i<triNum; ++i) { unsigned globalIndex = m_triIndexes->getValue(i); globalIndex = indexMap->getValue(globalIndex); m_triIndexes->setValue(i,globalIndex); } } return 0; } ccSubMesh* newSubMesh = new ccSubMesh(m_associatedMesh); if (!newSubMesh->reserve(size())) { ccLog::Error("[ccSubMesh::createNewSubMeshFromSelection] Not enough memory!"); return NULL; } //create sub-mesh { unsigned lastTri = 0; for (unsigned i=0; i<triNum; ++i) { unsigned globalIndex = m_triIndexes->getValue(i); const CCLib::VerticesIndexes* tsi = m_associatedMesh->getTriangleVertIndexes(globalIndex); if (indexMap) //translate global index? globalIndex = indexMap->getValue(globalIndex); //triangle is visible? if ( verticesVisibility->getValue(tsi->i1) == POINT_VISIBLE && verticesVisibility->getValue(tsi->i2) == POINT_VISIBLE && verticesVisibility->getValue(tsi->i3) == POINT_VISIBLE) { newSubMesh->addTriangleIndex(globalIndex); } else if (removeSelectedFaces) //triangle is not visible? It stays in the original mesh! { //we replace the current triangle by the 'last' valid one assert(lastTri <= i); m_triIndexes->setValue(lastTri++,globalIndex); } } //resize original mesh if (removeSelectedFaces && lastTri < triNum) { if (lastTri == 0) m_triIndexes->clear(true); else resize(lastTri); m_bBox.setValidity(false); notifyGeometryUpdate(); } } if (newSubMesh->size()) { newSubMesh->setName(getName()+QString(".part")); newSubMesh->resize(newSubMesh->size()); newSubMesh->setDisplay(getDisplay()); newSubMesh->showColors(colorsShown()); newSubMesh->showNormals(normalsShown()); newSubMesh->showMaterials(materialsShown()); newSubMesh->showSF(sfShown()); newSubMesh->enableStippling(stipplingEnabled()); newSubMesh->showWired(isShownAsWire()); } else { assert(false); delete newSubMesh; newSubMesh = 0; } return newSubMesh; }