void ObjLoader::addRawVerticePart (ObjMesh *mesh, FaceList &faces, int num) { std::vector<Face *>::iterator it = faces.begin(); // Etape 1 : construire la liste des faces std::vector<int> triangleBuffer; std::vector<int> quadBuffer; std::vector<float> glVertexBuffer; int reservedSize = faces.size(); triangleBuffer.reserve (reservedSize); quadBuffer.reserve (reservedSize); glVertexBuffer.reserve (3.*reservedSize); int indexVertex = 0; it = faces.begin(); do { VertexObj v1 (*this, (*it)->vertices[0]); VertexObj v2 (*this, (*it)->vertices[1]); VertexObj v3 (*this, (*it)->vertices[2]); glVertexBuffer.push_back (v1.vertex.x); glVertexBuffer.push_back (v1.vertex.y); glVertexBuffer.push_back (v1.vertex.z); glVertexBuffer.push_back (v2.vertex.x); glVertexBuffer.push_back (v2.vertex.y); glVertexBuffer.push_back (v2.vertex.z); glVertexBuffer.push_back (v3.vertex.x); glVertexBuffer.push_back (v3.vertex.y); glVertexBuffer.push_back (v3.vertex.z); int index1 = indexVertex++; int index2 = indexVertex++; int index3 = indexVertex++; if ( (*it)->type == TRIANGLE) { triangleBuffer.push_back (index1); triangleBuffer.push_back (index2); triangleBuffer.push_back (index3); } else { VertexObj v4 (*this, (*it)->vertices[3]); glVertexBuffer.push_back (v4.vertex.x); glVertexBuffer.push_back (v4.vertex.y); glVertexBuffer.push_back (v4.vertex.z); int index4 = indexVertex++; quadBuffer.push_back (index1); quadBuffer.push_back (index2); quadBuffer.push_back (index3); quadBuffer.push_back (index4); } delete (*it); } while (++it != faces.end()); // etape 2 : construire le Mesh pour le renderer SmoothGroup *theSmoothGroup = new SmoothGroup (glVertexBuffer, triangleBuffer, quadBuffer, false, false); mesh->addSmoothGroup (theSmoothGroup); // On nettoie tout ! glVertexBuffer.erase (glVertexBuffer.begin(), glVertexBuffer.end()); triangleBuffer.erase (triangleBuffer.begin(), triangleBuffer.end()); quadBuffer.erase (quadBuffer.begin(), quadBuffer.end()); }
bool PolyMesh::convertFacesToGeometry( FaceList faces, GEOMETRY_FIX* geom ) { if ( !faces.size() || !geom ) return false; osg::ref_ptr<osg::DrawElementsUInt> indices = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 ); unsigned int i, index=0, firstIndex=0, lastIndex=0; for ( FaceList::iterator itr=faces.begin(); itr!=faces.end(); ++itr ) { Face f = *(*itr); unsigned int size=f._pts.size(); for ( i=0; i<size; ++i ) { if ( i>2 ) { indices->push_back( firstIndex ); indices->push_back( lastIndex ); } indices->push_back( f(i) ); if ( !i ) firstIndex = indices->back(); lastIndex = indices->back(); } } geom->removePrimitiveSet( 0, geom->getPrimitiveSetList().size() ); geom->addPrimitiveSet( indices.get() ); geom->setTexCoordArray( 0, NULL ); // TEMP NormalVisitor::buildNormal( *geom ); geom->dirtyDisplayList(); return true; }
int FaceList::insert(FaceList &other) { for (std::map< Face*, int >::iterator it = other.m_faces.begin(); it != other.m_faces.end(); it++) { insert(it->first, it->second); } return(other.size()); }
void CustomSmileyManager::loadSmileys( int groupIndex ) { // clear the table first for(int row = 0; row < tblFaceList->numRows(); row++){ tblFaceList->removeRow(row); } tblFaceList->setNumRows(0); TQString dir = EvaMain::user->getSetting()->getCustomSmileyDir() + "/"; if(groupIndex>0) dir += (m_Config->groupName( groupIndex) + "/"); FaceList list = m_Config->groupMembers( groupIndex ); int row = 0; if(list.size()){ tblFaceList->setNumRows(list.size()); tblFaceList->horizontalHeader()->setLabel( 0, i18n("No." ) ); tblFaceList->horizontalHeader()->setLabel( 1, i18n("Smiley" ) ); tblFaceList->horizontalHeader()->setLabel( 2, i18n("Shortcut" ) ); for( FaceList::Iterator it = list.begin(); it != list.end(); ++it){ //tblFaceList->setText(row, 0, TQString::number( row + 1)); tblFaceList->setItem(row, 0, new TQTableItem(tblFaceList, TQTableItem::Never, TQString::number(row + 1))); TQPixmap *pixmap = new TQPixmap(dir + (*it).fixed()); CustomItem *item = new CustomItem(tblFaceList, (*it).tip(), *pixmap); tblFaceList->setItem(row, 1, item); CustomItem *itemSC = new CustomItem(tblFaceList, (*it).shortcut() ); tblFaceList->setItem(row, 2, itemSC); tblFaceList->setRowHeight(row, pixmap->width() + 2); delete pixmap; row++; } tblFaceList->setColumnWidth(0, 20); tblFaceList->setColumnWidth(1, tblFaceList->visibleWidth() - 20 - 50 ); } }
void Brush::restore(const Brush& brushTemplate, bool checkId) { if (checkId) assert(uniqueId() == brushTemplate.uniqueId()); Utility::deleteAll(m_faces); const FaceList templateFaces = brushTemplate.faces(); for (size_t i = 0; i < templateFaces.size(); i++) { Face* face = new Face(m_worldBounds, m_forceIntegerFacePoints, *templateFaces[i]); face->setBrush(this); m_faces.push_back(face); } rebuildGeometry(); }
// Starts the recursive fractal function void CFractalMtn::CreateFractal(Point3List listStartVerts, FaceList listStartFaces, int levels) { int nFaces = listStartFaces.size(); for (int c=0; c<nFaces; c++) { Point3 vec1, vec2, vec3; vec1 = listStartVerts[listStartFaces[c].v1]; vec2 = listStartVerts[listStartFaces[c].v2]; vec3 = listStartVerts[listStartFaces[c].v3]; if (c == 0) { m_ptMin = m_ptMax = vec1; } FractalSub(vec1, vec2, vec3, levels); } }
void FastMassSpring::initEdgeGraph( FaceList& face_list, VertexList& vertex_list, AdjList& vertex_share_faces) { this->P_Num = vertex_list.size() / 3; // building edge graph this->strech_edges.clear(); { int ptid[3] = {0, 0, 0}; for (decltype(face_list.size()) i = 0; i < face_list.size() / 3; ++i) { ptid[0] = face_list[3 * i + 0]; ptid[1] = face_list[3 * i + 1]; ptid[2] = face_list[3 * i + 2]; // the order of start point and end point doesn't matter this->strech_edges.push_back( ptid[0] < ptid[1] ? Edge(ptid[0], ptid[1]) : Edge(ptid[1], ptid[0])); this->strech_edges.push_back( ptid[1] < ptid[2] ? Edge(ptid[1], ptid[2]) : Edge(ptid[2], ptid[1])); this->strech_edges.push_back( ptid[2] < ptid[0] ? Edge(ptid[2], ptid[0]) : Edge(ptid[0], ptid[2])); } std::sort(this->strech_edges.begin(), this->strech_edges.end()); std::vector<Edge>::iterator iter = std::unique(this->strech_edges.begin(), this->strech_edges.end()); this->strech_edges.erase(iter, strech_edges.end()); this->strech_edges.shrink_to_fit(); // store rest length float cur_r = 0.0; this->strech_r_length.clear(); for (auto& i : this->strech_edges) { cur_r = 0.0; for (int j = 0; j < 3; ++j) { cur_r += pow(vertex_list[3 * i.first + j] - vertex_list[ 3 * i.second + j], 2); } this->strech_r_length.push_back(sqrt(cur_r)); } } this->bending_edges.clear(); { for (auto& i : this->strech_edges) { int cross_pi = -1; int cross_pj = -1; if (findShareVertex( cross_pi, cross_pj, i.first, i.second, vertex_share_faces, face_list)) { this->bending_edges.push_back( cross_pi < cross_pj ? Edge(cross_pi, cross_pj) : Edge(cross_pj, cross_pi)); } } // store rest length float cur_r = 0.0; this->bending_r_length.clear(); for (auto& i : this->bending_edges) { cur_r = 0.0; for (int j = 0; j < 3; ++j) { cur_r += pow(vertex_list[3 * i.first + j] - vertex_list[ 3 * i.second + j], 2); } this->bending_r_length.push_back(sqrt(cur_r)); } } // init d vector this->computedVector(); }
void ObjLoader::addVerticePart (ObjMesh *mesh, FaceList &faces, int num) { std::vector<Face *>::iterator it = faces.begin(); std::map<VertexObj, int> vertexBuffer; // Etape 1 : construire la liste des sommets (vert) uniques int addedVerticesNumber = 0; do { VertexObj v1 (*this, (*it)->vertices[0]); vertexBuffer[v1] = ++addedVerticesNumber; VertexObj v2 (*this, (*it)->vertices[1]); vertexBuffer[v2] = ++addedVerticesNumber; VertexObj v3 (*this, (*it)->vertices[2]); vertexBuffer[v3] = ++addedVerticesNumber; if ( (*it)->type == QUAD) { VertexObj v4 (*this, (*it)->vertices[3]); vertexBuffer[v4] = ++addedVerticesNumber; } } while (++it != faces.end()); // Etape 2 : numeroter les sommets int newnumber = 0; for (std::map<VertexObj, int>::iterator vm = vertexBuffer.begin(); vm != vertexBuffer.end(); ++vm) vm->second = newnumber++; // Etape 3 : construire la liste des faces std::vector<int> triangleBuffer; std::vector<int> quadBuffer; int reservedSize = faces.size(); triangleBuffer.reserve (reservedSize); quadBuffer.reserve (reservedSize); it = faces.begin(); do { VertexObj v1 (*this, (*it)->vertices[0]); VertexObj v2 (*this, (*it)->vertices[1]); VertexObj v3 (*this, (*it)->vertices[2]); int index1 = vertexBuffer.find (v1)->second; int index2 = vertexBuffer.find (v2)->second; int index3 = vertexBuffer.find (v3)->second; if ( (*it)->type == TRIANGLE) { triangleBuffer.push_back (index1); triangleBuffer.push_back (index2); triangleBuffer.push_back (index3); } else { VertexObj v4 (*this, (*it)->vertices[3]); int index4 = vertexBuffer.find (v4)->second; quadBuffer.push_back (index1); quadBuffer.push_back (index2); quadBuffer.push_back (index3); quadBuffer.push_back (index4); } delete (*it); } while (++it != faces.end()); // etape4 : construire le tableau de sommet final std::vector<float> glVertexBuffer; for (std::map<VertexObj, int>::iterator vm = vertexBuffer.begin(); vm != vertexBuffer.end(); ++vm) { glVertexBuffer.push_back (vm->first.vertex.x); glVertexBuffer.push_back (vm->first.vertex.y); glVertexBuffer.push_back (vm->first.vertex.z); } // etape 5 : construire le Mesh pour le renderer SmoothGroup *theSmoothGroup = new SmoothGroup (glVertexBuffer, triangleBuffer, quadBuffer, false, false); mesh->addSmoothGroup (theSmoothGroup); // On nettoie tout ! glVertexBuffer.erase (glVertexBuffer.begin(), glVertexBuffer.end()); triangleBuffer.erase (triangleBuffer.begin(), triangleBuffer.end()); quadBuffer.erase (quadBuffer.begin(), quadBuffer.end()); vertexBuffer.erase (vertexBuffer.begin(), vertexBuffer.end()); }
/** remove one group, 2 options: 1: remove all smileys in this group, then remove the group itself 2: move all sub items into another group, then remove the empty group NOTE: this operation is un-recoverable. */ void CustomSmileyManager::slotRemoveGroupClicked( ) { if(!m_Config) return; TQListViewItem *item = lvGroups->selectedItem(); if(item){ if(item == lvGroups->firstChild()) return; // never remove default group int index = m_Config->groupIndex( item->text( 0 ) ); if(index <= -1) return; TQString path = EvaMain::user->getSetting()->getCustomSmileyDir() + "/"; TQDir dir( path + item->text(0) ); FaceList list = m_Config->groupMembers( index); int result = -2; if(list.size() > 0 ){ result = RmSmileyGroupDialog::QueryDialog( index, m_Config, this); switch(result){ case -2: // abort return; break; case -1: // remove all break; default: // otherwise, move to result { if(dir.exists()){ dir.setFilter( TQDir::Files | TQDir::Hidden | TQDir::NoSymLinks ); const TQFileInfoList *list = dir.entryInfoList(); TQFileInfoListIterator it( *list); TQFileInfo *fi; TQString destDir = path; if(result>0) destDir += ( m_Config->groupName( result ) + "/") ; while( (fi = it.current() ) != 0 ){ EvaHelper::copyFile(fi->absFilePath(), (destDir + fi->fileName()) ); ++it; } } m_Config->moveChildrenTo(index, result); m_IsChanged = true; } } } if(dir.exists()){ // update the in-memory config if(m_Config->removeGroup( index )){ lvGroups->takeItem( item); delete item; m_IsChanged = true; } else return; dir.setFilter( TQDir::Files | TQDir::Hidden | TQDir::NoSymLinks ); const TQFileInfoList *list = dir.entryInfoList(); TQFileInfoListIterator it( *list); TQFileInfo *fi; while( (fi = it.current() ) != 0 ){ dir.remove( fi->absFilePath() ); ++it; } // as all files have been deleted, we need keep the config file up to date. m_Config->saveXML(); if( ! dir.rmdir( dir.path(), true)){ KMessageBox::error( this, i18n( "Remove directory \"%1\" failed. " ).arg( dir.path() ), i18n( "Remove Directory!" ) ); } } } }