using meshIterators

This commit is contained in:
alemuntoni 2021-05-31 15:35:02 +02:00
parent 33d39822cc
commit 5fb9010d32
15 changed files with 105 additions and 87 deletions

View File

@ -272,7 +272,7 @@ QDomDocument MeshDocumentToXML(MeshDocument &md, bool onlyVisibleLayers, bool sa
QDomElement rgroot = ddoc.createElement("RasterGroup");
foreach(RasterModel *rmp, md.rasterList)
for(RasterModel *rmp: md.rasterIterator())
{
QDomElement rasterElem = RasterModelToXML(rmp, ddoc, binary);
rgroot.appendChild(rasterElem);

View File

@ -1812,7 +1812,7 @@ void GLArea::updateRasterSetVisibilities()
while (i.hasNext()) {
i.next();
bool found =false;
foreach(RasterModel * rp, this->md()->rasterList)
for(RasterModel * rp: md()->rasterIterator())
{
if(rp->id() == i.key())
{
@ -1824,7 +1824,7 @@ void GLArea::updateRasterSetVisibilities()
rasterVisibilityMap.remove(i.key());
}
foreach(RasterModel * rp, this->md()->rasterList)
for(RasterModel * rp: md()->rasterIterator())
{
//Insert the new pair in the map;If the key is already in the map, its value will be overwritten
rasterVisibilityMap.insert(rp->id(),rp->visible);
@ -1879,7 +1879,7 @@ void GLArea::showRaster(bool resetViewFlag)
void GLArea::loadRaster(int id)
{
lastloadedraster = id;
foreach(RasterModel *rm, this->md()->rasterList)
for(RasterModel *rm: md()->rasterIterator())
if(rm->id()==id)
{
this->md()->setCurrentRaster(id);

View File

@ -457,7 +457,7 @@ void LayerDialog::rasterItemClicked (QTreeWidgetItem * item , int col)
//
if(QApplication::keyboardModifiers() == Qt::ControlModifier)
{
foreach(RasterModel *rp, md->rasterList)
for(RasterModel *rp: md->rasterIterator())
{
rp->visible = false;
}
@ -476,7 +476,7 @@ void LayerDialog::rasterItemClicked (QTreeWidgetItem * item , int col)
// clicking on all of them...
if(QApplication::keyboardModifiers() == Qt::AltModifier)
{
foreach(RasterModel *rp, md->rasterList)
for(RasterModel *rp: md->rasterIterator())
{
rp->visible = true;
}
@ -484,7 +484,7 @@ void LayerDialog::rasterItemClicked (QTreeWidgetItem * item , int col)
if(QApplication::keyboardModifiers() == Qt::ShiftModifier)
{
foreach(RasterModel *rp, md->rasterList)
for(RasterModel *rp: md->rasterIterator())
{
rp->visible = !rp->visible;
}
@ -712,7 +712,7 @@ void LayerDialog::updateTable(const MLSceneGLSharedDataContext::PerMeshRendering
//}
//tabsrelatedtodeletedmeshes.clear();
if (md->rasterList.size() > 0)
if (md->rasterNumber() > 0)
ui->rasterTreeWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
else
ui->rasterTreeWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Ignored);
@ -723,7 +723,7 @@ void LayerDialog::updateTable(const MLSceneGLSharedDataContext::PerMeshRendering
//TODO The fourth column is fake... solo per ora, E' per evitare che l'ultimacolonna si allunghi indefinitivamente
//mettere una lunghezza fissa e' inutile perche' non so quanto e' lungo il nome.
ui->rasterTreeWidget->header()->hide();
foreach(RasterModel* rmd, md->rasterList)
for(RasterModel* rmd: md->rasterIterator())
{
//Restore raster visibility according to the current visibility map
//very good to keep viewer state consistent

View File

@ -188,7 +188,7 @@ void VarianceShadowMappingBlur::runShader(MeshDocument& md, GLArea* gla){
glPushAttrib(GL_COLOR_BUFFER_BIT);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_FALSE); // to avoid the fact that when saving a snapshot we get semitransparent shadowed areas.
foreach(MeshModel *m, md.meshList)
for(MeshModel *m: md.meshIterator())
{
if ((m != NULL) && (m->visible))
{

View File

@ -114,23 +114,23 @@ void EditAlignPlugin::suggestedRenderingData(MeshModel & /*m*/, MLRenderingData&
bool EditAlignPlugin::startEdit(MeshDocument& md, GLArea * gla, MLSceneGLSharedDataContext* cont)
{
_md=&md;
_gla= gla;
_md=&md;
_gla= gla;
_shared = cont;
if ((_gla == NULL) || (_shared == NULL) || (md.meshList.size() < 1))
if ((_gla == NULL) || (_shared == NULL) || (md.meshNumber() < 1))
return false;
//mainW->addDockWidget(Qt::LeftDockWidgetArea,alignDialog);
mode = ALIGN_IDLE;
int numOfMeshes = _md->meshList.size();
meshTree.clear();
foreach(MeshModel *mm, _md->meshList)
{
int numOfMeshes = _md->meshNumber();
meshTree.clear();
for(MeshModel *mm: _md->meshIterator())
{
// assigns random color: if less than 50 meshes, color is truly unique, and the less meshes, the more different they will be
// if above 50, truly unique color would generate too similar colors, so total number of unique color
// is capped to 50 and the color reused, id that are close will have different color anyway
// assigns random color: if less than 50 meshes, color is truly unique, and the less meshes, the more different they will be
// if above 50, truly unique color would generate too similar colors, so total number of unique color
// is capped to 50 and the color reused, id that are close will have different color anyway
if (mm != NULL)
{
if (numOfMeshes < 50)
@ -139,12 +139,12 @@ bool EditAlignPlugin::startEdit(MeshDocument& md, GLArea * gla, MLSceneGLSharedD
mm->cm.C() = Color4b::Scatter(51, mm->id() % 50, .2f, .7f);
mm->updateDataMask(MeshModel::MM_COLOR);
// meshTree.nodeList.push_back(new MeshNode(mm));
meshTree.nodeMap[mm->id()]=new MeshNode(mm);
meshTree.nodeMap[mm->id()]=new MeshNode(mm);
}
}
}
//for(QMap<int,RenderMode>::iterator it = _gla->rendermodemap.begin();it != _gla->rendermodemap.end();++it)
// it.value().colorMode=GLW::CMPerMesh;
// for(QMap<int,RenderMode>::iterator it = _gla->rendermodemap.begin();it != _gla->rendermodemap.end();++it)
// it.value().colorMode=GLW::CMPerMesh;
_gla->setCursor(QCursor(QPixmap(":/images/cur_align.png"),1,1));
if(alignDialog==0)

View File

@ -343,9 +343,9 @@ bool EditReferencingPlugin::startEdit(MeshModel & m, GLArea * gla, MLSceneGLShar
status_error = "";
// reading current transformations for all layers
layersOriginalTransf.resize(glArea->md()->meshList.size());
layersOriginalTransf.resize(glArea->md()->meshNumber());
int lind = 0;
foreach(MeshModel *mmp, glArea->md()->meshList)
for(MeshModel *mmp: glArea->md()->meshIterator())
{
layersOriginalTransf[lind].Import(mmp->cm.Tr);
lind++;
@ -808,30 +808,30 @@ void EditReferencingPlugin::calculateMatrix()
void EditReferencingPlugin::applyMatrix()
{
status_error = "";
status_error = "";
Matrix44m newMat;
Matrix44m newMat;
newMat.Import(transfMatrix);
newMat.Import(transfMatrix);
if(referencingDialog->ui->cbApplyToAll->checkState() == Qt::Checked)
{
if(referencingDialog->ui->cbApplyToAll->checkState() == Qt::Checked)
{
int lind = 0;
foreach(MeshModel *mmp, glArea->md()->meshList)
{
if(mmp->visible)
{
for(MeshModel *mmp: glArea->md()->meshIterator())
{
if(mmp->visible)
{
mmp->cm.Tr = newMat * layersOriginalTransf[lind];
}
}
lind++;
}
}
else
{
}
}
else
{
glArea->mm()->cm.Tr = newMat * originalTransf;
}
}
glArea->update();
glArea->update();
}
void EditReferencingPlugin::updateDistances()
@ -997,7 +997,7 @@ void EditReferencingPlugin::applyScale()
if (referencingDialog->ui->cbApplyToAll->checkState() == Qt::Checked)
{
int lind = 0;
foreach(MeshModel *mmp, glArea->md()->meshList)
for(MeshModel *mmp: glArea->md()->meshIterator())
{
if (mmp->visible)
{

View File

@ -454,13 +454,13 @@ std::map<std::string, QVariant> FilterColorProc::applyFilter(const QAction *filt
if (all_levels)
{
foreach(MeshModel *mm, md.meshList)
for(MeshModel *mm: md.meshIterator())
if (mm->isVisible())
vcg::tri::UpdateColor<CMeshO>::PerVertexLevels(mm->cm, gamma, in_min, in_max, out_min, out_max, rgbMask, selected);
vcg::tri::UpdateColor<CMeshO>::PerVertexLevels(mm->cm, gamma, in_min, in_max, out_min, out_max, rgbMask, selected);
}
else
{
vcg::tri::UpdateColor<CMeshO>::PerVertexLevels(m->cm, gamma, in_min, in_max, out_min, out_max, rgbMask, selected);
vcg::tri::UpdateColor<CMeshO>::PerVertexLevels(m->cm, gamma, in_min, in_max, out_min, out_max, rgbMask, selected);
}
break;
}
@ -520,9 +520,9 @@ std::map<std::string, QVariant> FilterColorProc::applyFilter(const QAction *filt
if(seed==0) seed = time(NULL);
math::MarsenneTwisterRNG myrnd(seed);
int numOfMeshes = md.meshList.size();
int numOfMeshes = md.meshNumber();
int id = myrnd.generate(numOfMeshes);
foreach(MeshModel *mm, md.meshList)
for(MeshModel *mm: md.meshIterator())
{
if (mm->isVisible())
mm->cm.C()=Color4b::Scatter(numOfMeshes,id);
@ -866,7 +866,7 @@ std::map<std::string, QVariant> FilterColorProc::applyFilter(const QAction *filt
case CP_MESH_TO_FACE:
{
foreach(MeshModel *mmi, md.meshList)
for(MeshModel *mmi: md.meshIterator())
{
if (mmi->visible)
{

View File

@ -220,9 +220,9 @@ void FilterFractal::initParameterSetForCratersGeneration(const MeshDocument &md,
// tries to detect the target mesh
const MeshModel* target = md.mm();
const MeshModel* samples = md.mm();
MeshModel* tmpMesh;
const MeshModel* tmpMesh;
if (samples->cm.fn != 0){ // this is probably not the samples layer
for(MeshModel* mm : md.meshList)
for(const MeshModel* mm : md.meshIterator())
{
tmpMesh = mm;
if (tmpMesh->cm.fn == 0)
@ -304,7 +304,7 @@ std::map<std::string, QVariant> FilterFractal::applyFilter(
break;
case FP_CRATERS:
{
if (md.meshList.size() < 2) {
if (md.meshNumber() < 2) {
throw MLException("There must be at least two layers to apply the craters generation filter.");
}

View File

@ -223,7 +223,7 @@ std::map<std::string, QVariant> FilterLayerPlugin::applyFilter(
}
else
{
foreach(MeshModel *mmp, md.meshList)
for(MeshModel *mmp: md.meshIterator())
{
if (mmp->label().contains(match))
md.setVisible(mmp->id(), par.getBool("isMeshVisible"));
@ -239,7 +239,7 @@ std::map<std::string, QVariant> FilterLayerPlugin::applyFilter(
case FP_DELETE_NON_VISIBLE_MESH:
{
foreach(MeshModel *mmp, md.meshList)
for(MeshModel *mmp: md.meshIterator())
{
if (!mmp->visible)
md.delMesh(mmp);
@ -283,11 +283,11 @@ std::map<std::string, QVariant> FilterLayerPlugin::applyFilter(
tri::UpdateSelection<CMeshO>::VertexClear(currentModel->cm);
currentModel->clearDataMask(MeshModel::MM_FACEFACETOPO);
log("Moved %i vertices to layer %i, deleted %i faces", numVertSel, delfaces, md.meshList.size());
log("Moved %i vertices to layer %i, deleted %i faces", numVertSel, currentModel->id(), delfaces);
}
else // keep original faces
else // keep original faces
{
log("Copied %i vertices to layer %i", numVertSel, md.meshList.size());
log("Copied %i vertices to layer %i", numVertSel, currentModel->id());
}
vcg::tri::UpdateFlags<CMeshO>::VertexClear(destModel->cm, CMeshO::VertexType::SELECTED);
@ -328,11 +328,11 @@ std::map<std::string, QVariant> FilterLayerPlugin::applyFilter(
tri::UpdateSelection<CMeshO>::FaceClear(currentModel->cm);
currentModel->clearDataMask(MeshModel::MM_FACEFACETOPO);
log("Moved %i faces and %i vertices to layer %i", numFacesSel, numVertSel, md.meshList.size());
log("Moved %i faces and %i vertices to layer %i", numFacesSel, numVertSel, currentModel->id());
}
else // keep original faces
{
log("Copied %i faces and %i vertices to layer %i", numFacesSel, numVertSel, md.meshList.size());
log("Copied %i faces and %i vertices to layer %i", numFacesSel, numVertSel, currentModel->id());
}
vcg::tri::UpdateFlags<CMeshO>::VertexClear(destModel->cm, CMeshO::VertexType::SELECTED);
vcg::tri::UpdateFlags<CMeshO>::FaceClear(destModel->cm, CMeshO::FaceType::SELECTED);
@ -356,7 +356,7 @@ std::map<std::string, QVariant> FilterLayerPlugin::applyFilter(
tex = fullPath.toStdString();
}
log("Duplicated current model to layer %i", md.meshList.size());
log("Duplicated current model to layer %i", destModel->id());
// init new layer
destModel->updateBoxAndNormals();
@ -375,14 +375,14 @@ std::map<std::string, QVariant> FilterLayerPlugin::applyFilter(
QList<MeshModel *> toBeDeletedList;
int cnt=0;
foreach(MeshModel *mmp, md.meshList)
for(MeshModel *mmp: md.meshIterator())
{
++cnt;
if(mmp->visible || !mergeVisible)
{
if (mmp != destModel)
{
cb(cnt*100/md.meshList.size(), "Merging layers...");
cb(cnt*100/md.meshNumber(), "Merging layers...");
tri::UpdatePosition<CMeshO>::Matrix(mmp->cm,mmp->cm.Tr,true);
toBeDeletedList.push_back(mmp);
if(!alsoUnreferenced)

View File

@ -181,7 +181,7 @@ RichParameterList FilterMeshBooleans::initParameterList(
{
const MeshModel *target = md.mm();
//looking for a second mesh different that the current one
for (const MeshModel * t : md.meshList){
for (const MeshModel * t : md.meshIterator()){
if (t != md.mm()) {
target = t;
break;

View File

@ -165,7 +165,7 @@ std::map<std::string, QVariant> PlyMCPlugin::applyFilter(
p.FullyPreprocessedFlag=true;
p.MergeColor=p.VertSplatFlag=par.getBool("mergeColor");
p.SimplificationFlag = par.getBool("simplification");
foreach(MeshModel*mm, md.meshList)
for(MeshModel*mm: md.meshIterator())
{
if(mm->visible)
{

View File

@ -564,8 +564,12 @@ RichParameterList FilterDocSampling::initParameterList(const QAction *action, co
case FP_HAUSDORFF_DISTANCE:
{
const MeshModel *vertexMesh = md.mm();
foreach(vertexMesh, md.meshList)
if (vertexMesh != md.mm()) break;
for(const MeshModel * vm: md.meshIterator()){
if (vm != md.mm()) {
vertexMesh = vm;
break;
}
}
parlst.addParam(RichMesh("SampledMesh", md.mm()->id(), &md, "Sampled Mesh",
"The mesh whose surface is sampled. For each sample we search the closest point on the Target Mesh."));
@ -585,13 +589,17 @@ RichParameterList FilterDocSampling::initParameterList(const QAction *action, co
"The desired number of samples. It can be smaller or larger than the mesh size, and according to the chosen sampling strategy it will try to adapt."));
parlst.addParam(RichAbsPerc("MaxDist", md.mm()->cm.bbox.Diag() / 2.0, 0.0f, md.bbox().Diag(),
tr("Max Distance"), tr("Sample points for which we do not find anything within this distance are rejected and not considered neither for averaging nor for max.")));
} break;
} break;
case FP_DISTANCE_REFERENCE:
{
case FP_DISTANCE_REFERENCE:
{
const MeshModel *vertexMesh = md.mm();
foreach(vertexMesh, md.meshList)
if (vertexMesh != md.mm()) break;
for(const MeshModel * vm: md.meshIterator()){
if (vm != md.mm()) {
vertexMesh = vm;
break;
}
}
parlst.addParam(RichMesh("MeasureMesh", md.mm()->id(), &md, "Measured Mesh/PointCloud",
"The Mesh/Pointcloud that is measured, vertex by vertex, computing distance from the REFERENCE mesh/pointcloud."));
@ -605,11 +613,14 @@ RichParameterList FilterDocSampling::initParameterList(const QAction *action, co
tr("Max Distance [abs]"), tr("Search is interrupted when nothing is found within this distance range [+maxDistance -maxDistance].")));
} break;
case FP_VERTEX_RESAMPLING:
{
case FP_VERTEX_RESAMPLING:
{
const MeshModel *vertexMesh= md.mm();
foreach (vertexMesh, md.meshList)
if (vertexMesh != md.mm()) break;
for (const MeshModel* vm: md.meshIterator())
if (vm != md.mm()) {
vertexMesh = vm;
break;
}
parlst.addParam(RichMesh ("SourceMesh", md.mm()->id(),&md, "Source Mesh",
"The mesh that contains the source data that we want to transfer."));
@ -657,16 +668,23 @@ RichParameterList FilterDocSampling::initParameterList(const QAction *action, co
"In this case you have to choose a not zero Offset and a double surface is built around the original surface, inside and outside. "
"Is useful to convrt thin floating surfaces into <i> solid, thick meshes.</i>. t"));
} break;
case FP_VORONOI_COLORING :
case FP_DISK_COLORING :
{
const MeshModel *colorMesh= md.mm();
foreach (colorMesh, md.meshList) // Search a mesh with some faces..
if (colorMesh->cm.fn>0) break;
MeshModel *vertexMesh;
foreach (vertexMesh, md.meshList) // Search another mesh
if (vertexMesh != colorMesh) break;
case FP_VORONOI_COLORING :
case FP_DISK_COLORING :
{
const MeshModel *colorMesh= md.mm();
for (const MeshModel* colm: md.meshIterator()) // Search a mesh with some faces..
if (colm->cm.fn>0){
colorMesh = colm;
break;
}
const MeshModel *vertexMesh= md.mm();
for (const MeshModel* vm : md.meshIterator()) // Search another mesh
if (vm != colorMesh) {
vertexMesh = vm;
break;
}
parlst.addParam(RichMesh ("ColoredMesh", colorMesh->id(),&md, "To be Colored Mesh",
"The mesh whose surface is colored. For each vertex of this mesh we decide the color according the below parameters."));

View File

@ -200,7 +200,7 @@ RichParameterList FilterTexturePlugin::initParameterList(const QAction *action,
{
RichParameterList parlst;
const MeshModel* trg = md.mm();
for (const MeshModel* tmp : md.meshList){
for (const MeshModel* tmp : md.meshIterator()){
if (tmp != trg && tmp != nullptr){
trg = tmp;
break;

View File

@ -486,7 +486,7 @@ void MeshShaderRenderPlugin::render(QAction *a, MeshDocument &md, MLSceneGLShare
if ((gla != NULL) && (gla->mvc() != NULL))
{
MLSceneGLSharedDataContext* shared = gla->mvc()->sharedDataContext();
for(MeshModel * mp : md.meshList)
for(MeshModel * mp : md.meshIterator())
{
if ((mp != NULL) && (gla->meshVisibilityMap[mp->id()]))
shared->draw(mp->id(),gla->context());

View File

@ -122,7 +122,7 @@ void RadianceScalingRendererPlugin::render(QAction *, MeshDocument &md, MLSceneG
vcg::glColor(vcg::Color4b(vcg::Color4b::LightGray));
_buffPass->enable();
foreach(MeshModel *mp, md.meshList)
for(MeshModel *mp: md.meshIterator())
{
if ((mp != NULL) && (gla->meshVisibilityMap[mp->id()]))
{