void MeshCurvature::ComputePerFace(bool parallel) { Base::Vector3f rkDir0, rkDir1, rkPnt; Base::Vector3f rkNormal; myCurvature.clear(); MeshRefPointToFacets search(myKernel); FacetCurvature face(myKernel, search, myRadius, myMinPoints); if (!parallel) { Base::SequencerLauncher seq("Curvature estimation", mySegment.size()); for (std::vector<unsigned long>::iterator it = mySegment.begin(); it != mySegment.end(); ++it) { CurvatureInfo info = face.Compute(*it); myCurvature.push_back(info); seq.next(); } } else { QFuture<CurvatureInfo> future = QtConcurrent::mapped (mySegment, boost::bind(&FacetCurvature::Compute, &face, _1)); QFutureWatcher<CurvatureInfo> watcher; watcher.setFuture(future); watcher.waitForFinished(); for (QFuture<CurvatureInfo>::const_iterator it = future.begin(); it != future.end(); ++it) { myCurvature.push_back(*it); } } }
MeshObjectRef makeParallelMengerSponge(int level, float x0, float y0, float z0) { float boxnums = std::pow(3.0f,level); float thirds = boxnums / 3; float twothirds = thirds * 2; QList<float> rangerx, rangery, rangerz; rangerx << x0 << (x0 + thirds) << (x0 + twothirds); rangery << y0 << (y0 + thirds) << (y0 + twothirds); rangerz << z0 << (z0 + thirds) << (z0 + twothirds); int block = 1; QList<int> skip; skip << 5 << 11 << 13 << 14 << 15 << 17 << 23; // collect the arguments for the algorithm in a list QList<Param> args; for (QList<float>::iterator i = rangerx.begin(); i != rangerx.end(); ++i) { for (QList<float>::iterator j = rangery.begin(); j != rangery.end(); ++j) { for (QList<float>::iterator k = rangerz.begin(); k != rangerz.end(); ++k) { if (!skip.contains(block)) { args << Param(level-1, *i, *j, *k); } block++; } } } QFuture<MeshObjectRef> future = QtConcurrent::mapped(args, runSierpinski); QFutureWatcher<MeshObjectRef> watcher; watcher.setFuture(future); // keep it responsive during computation QEventLoop loop; QObject::connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); MeshObjectRef mesh = new Mesh::MeshObject(); for (QFuture<MeshObjectRef>::const_iterator it = future.begin(); it != future.end(); ++it) { mesh->addMesh(**it); (*it)->clear(); } return mesh; }
void CrossSections::apply() { std::vector<App::DocumentObject*> obj = Gui::Selection(). getObjectsOfType(Part::Feature::getClassTypeId()); std::vector<double> d; if (ui->sectionsBox->isChecked()) d = getPlanes(); else d.push_back(ui->position->value().getValue()); double a=0,b=0,c=0; switch (plane()) { case CrossSections::XY: c = 1.0; break; case CrossSections::XZ: b = 1.0; break; case CrossSections::YZ: a = 1.0; break; } #ifdef CS_FUTURE Standard::SetReentrant(Standard_True); for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) { Part::CrossSection cs(a,b,c,static_cast<Part::Feature*>(*it)->Shape.getValue()); QFuture< std::list<TopoDS_Wire> > future = QtConcurrent::mapped (d, boost::bind(&Part::CrossSection::section, &cs, _1)); future.waitForFinished(); QFuture< std::list<TopoDS_Wire> >::const_iterator ft; TopoDS_Compound comp; BRep_Builder builder; builder.MakeCompound(comp); for (ft = future.begin(); ft != future.end(); ++ft) { const std::list<TopoDS_Wire>& w = *ft; for (std::list<TopoDS_Wire>::const_iterator wt = w.begin(); wt != w.end(); ++wt) { if (!wt->IsNull()) builder.Add(comp, *wt); } } App::Document* doc = (*it)->getDocument(); std::string s = (*it)->getNameInDocument(); s += "_cs"; Part::Feature* section = static_cast<Part::Feature*> (doc->addObject("Part::Feature",s.c_str())); section->Shape.setValue(comp); section->purgeTouched(); } #else Base::SequencerLauncher seq("Cross-sections...", obj.size() * (d.size() +1)); Gui::Command::runCommand(Gui::Command::App, "import Part\n"); Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base\n"); for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) { App::Document* doc = (*it)->getDocument(); std::string s = (*it)->getNameInDocument(); s += "_cs"; Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1( "wires=list()\n" "shape=FreeCAD.getDocument(\"%1\").%2.Shape\n") .arg(QLatin1String(doc->getName())) .arg(QLatin1String((*it)->getNameInDocument())).toLatin1()); for (std::vector<double>::iterator jt = d.begin(); jt != d.end(); ++jt) { Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1( "for i in shape.slice(Base.Vector(%1,%2,%3),%4):\n" " wires.append(i)\n" ).arg(a).arg(b).arg(c).arg(*jt).toLatin1()); seq.next(); } Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1( "comp=Part.Compound(wires)\n" "slice=FreeCAD.getDocument(\"%1\").addObject(\"Part::Feature\",\"%2\")\n" "slice.Shape=comp\n" "slice.purgeTouched()\n" "del slice,comp,wires,shape") .arg(QLatin1String(doc->getName())) .arg(QLatin1String(s.c_str())).toLatin1()); seq.next(); } #endif }
void CmdSandboxMeshLoaderFuture::activated(int iMsg) { // use current path as default QStringList filter; filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)"); filter << QObject::tr("Binary STL (*.stl)"); filter << QObject::tr("ASCII STL (*.ast)"); filter << QObject::tr("Binary Mesh (*.bms)"); filter << QObject::tr("Alias Mesh (*.obj)"); filter << QObject::tr("Inventor V2.1 ascii (*.iv)"); //filter << "Nastran (*.nas *.bdf)"; filter << QObject::tr("All Files (*.*)"); // Allow multi selection QStringList fn = Gui::FileDialog::getOpenFileNames(Gui::getMainWindow(), QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;"))); QFuture< Base::Reference<Mesh::MeshObject> > future = QtConcurrent::mapped (fn, loadMesh); QFutureWatcher< Base::Reference<Mesh::MeshObject> > watcher; watcher.setFuture(future); // keep it responsive during computation QEventLoop loop; QObject::connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); App::Document* doc = App::GetApplication().getActiveDocument(); for (QFuture< Base::Reference<Mesh::MeshObject> >::const_iterator it = future.begin(); it != future.end(); ++it) { Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh")); mesh->Mesh.setValuePtr((Mesh::MeshObject*)(*it)); mesh->purgeTouched(); } }