#ifndef CT_MESHALLOCATORT_HPP #define CT_MESHALLOCATORT_HPP #include "ct_mesh/tools/ct_meshallocatort.h" #include "ct_global/ct_context.h" #include "ct_cloudindex/registered/abstract/ct_abstractnotmodifiablecloudindexregisteredt.h" #include "ct_cloud/tools/ct_globalpointcloudmanager.h" #include "ct_iterator/ct_mutablepointiterator.h" #include "ct_iterator/ct_mutablefaceiterator.h" #include "ct_iterator/ct_mutableedgeiterator.h" #include "ct_iterator/ct_mutablepointindexiterator.h" #include "ct_iterator/ct_mutablefaceindexiterator.h" #include "ct_iterator/ct_mutableedgeindexiterator.h" template CT_MutablePointIndexIterator CT_MeshAllocatorT::AddVerticeIndexes(Mesh *mesh, const size_t &n) { if(mesh == NULL) return CT_MutablePointIndexIterator(NULL); CT_PointCloudIndexVector *v = (CT_PointCloudIndexVector*)mesh->m_pVert; size_t lastSize = 0; if(v == NULL) { v = new CT_PointCloudIndexVector(n); mesh->m_vert = PS_REPOSITORY->registerCloudIndex(v); mesh->m_pVert = v; } else { lastSize = v->size(); v->resize(lastSize + n); } CT_MutablePointIndexIterator it(mesh->m_vert); it.jump(lastSize); return it; } template CT_MutableFaceIndexIterator CT_MeshAllocatorT::AddFaceIndexes(Mesh *mesh, const size_t &n) { if(mesh == NULL) return CT_MutableFaceIndexIterator(NULL); CT_FaceCloudIndexVector *f = (CT_FaceCloudIndexVector*)mesh->m_pFace; size_t lastSize = 0; if(f == NULL) { f = new CT_FaceCloudIndexVector(n); mesh->m_face = PS_REPOSITORY->registerCloudIndex(f); mesh->m_pFace = f; } else { f->resize(f->size() + n); } CT_MutableFaceIndexIterator it(mesh->m_face); it.jump(lastSize); return it; } template CT_MutableEdgeIndexIterator CT_MeshAllocatorT::AddHEdgeIndexes(Mesh *mesh, const size_t &n) { if(mesh == NULL) return CT_MutableEdgeIndexIterator(NULL); CT_EdgeCloudIndexVector *e = (CT_EdgeCloudIndexVector*)mesh->m_pHedge; size_t lastSize = 0; if(e == NULL) { e = new CT_EdgeCloudIndexVector(n); mesh->m_hedge = PS_REPOSITORY->registerCloudIndex(e); mesh->m_pHedge = e; } else { e->resize(e->size() + n); } CT_MutableEdgeIndexIterator it(mesh->m_hedge); it.jump(lastSize); return it; } template CT_MutablePointIterator CT_MeshAllocatorT::AddVertices(Mesh *mesh, const size_t &n) { if(mesh == NULL) return CT_MutablePointIterator(NULL); CT_PointCloudIndexVector *v = ((CT_PointCloudIndexVector*)mesh->m_pVert); CT_MutablePointIterator it = addT(n, mesh->m_newVert, mesh->m_vert, &v); mesh->m_pVert = v; return it; } template CT_MutableFaceIterator CT_MeshAllocatorT::AddFaces(Mesh *mesh, const size_t &n) { if(mesh == NULL) return CT_MutableFaceIterator(NULL); CT_FaceCloudIndexVector *f = ((CT_FaceCloudIndexVector*)mesh->m_pFace); CT_MutableFaceIterator it = addT(n, mesh->m_newFace, mesh->m_face, &f); mesh->m_pFace = f; return it; } template CT_MutableEdgeIterator CT_MeshAllocatorT::AddHEdges(Mesh *mesh, const size_t &n) { if(mesh == NULL) return CT_MutableEdgeIterator(NULL); CT_EdgeCloudIndexVector *e = ((CT_EdgeCloudIndexVector*)mesh->m_pHedge); CT_MutableEdgeIterator it = addT(n, mesh->m_newEdge, mesh->m_hedge, &e); mesh->m_pHedge = e; return it; } template template Iterator CT_MeshAllocatorT::addT(const size_t &n, std::vector< QSharedPointer< CT_AbstractNotModifiableCloudIndexRegisteredT > > &meshCIRCollection, typename CT_AbstractCloudIndexRegistrationManagerT::CT_AbstractModifiableCIR &meshCir, CloudIndex **meshCI) { QSharedPointer< CT_AbstractNotModifiableCloudIndexRegisteredT > cir; // first index in the global cloud for the new cloud ct_index_type firstPIndex = 0; // if the mesh has already a cloud created by the cloud manager if(!meshCIRCollection.empty()) { QSharedPointer< CT_AbstractNotModifiableCloudIndexRegisteredT > tmpCir = meshCIRCollection[meshCIRCollection.size()-1]; size_t s = tmpCir->size(); firstPIndex = tmpCir->last()+1; // resize last point cloud index added to mesh if it was at the end of the global points cloud (resize is the same time the global points cloud) cir = PS_REPOSITORY->resizeCloudIndexAndGlobalCloud(tmpCir, s+n); } // if the mesh don't have a points cloud or if the last created can't be resized if(cir.data() == NULL) { // create a new points cloud cir = PS_REPOSITORY->createNewCloud(n); firstPIndex = cir->first(); // add them to the collection meshCIRCollection.push_back(cir); } // if the mesh don't have a cloud index we create one if(meshCir.data() == NULL) { *meshCI = new CloudIndex(); meshCir = PS_REPOSITORY->registerCloudIndex((CloudIndex*)(*meshCI)); } CloudIndex *index = (CloudIndex*)(*meshCI); // begin of the first new index size_t begin = index->size(); // resize the index index->resize(index->size() + n); // end of the index size_t s = index->size(); ct_index_type a = firstPIndex; for(size_t i=begin; ireplaceIndex(i, a, false); ++a; } Iterator iterator(index); iterator.jump(begin); return iterator; } #endif // CT_MESHALLOCATORT_HPP