App::DocumentObjectExecReturn *Curvature::execute(void)
{
    Mesh::Feature *pcFeat  = dynamic_cast<Mesh::Feature*>(Source.getValue());
    if(!pcFeat || pcFeat->isError()) {
        return new App::DocumentObjectExecReturn("No mesh object attached.");
    }
 
    // get all points
    const MeshCore::MeshKernel& rMesh = pcFeat->Mesh.getValue().getKernel();
    MeshCore::MeshCurvature meshCurv(rMesh);
    meshCurv.ComputePerVertex();
    const std::vector<MeshCore::CurvatureInfo>& curv = meshCurv.GetCurvature();

    std::vector<CurvatureInfo> values;
    values.reserve(curv.size());
    for (std::vector<MeshCore::CurvatureInfo>::const_iterator it = curv.begin(); it != curv.end(); ++it) {
        CurvatureInfo ci;
        ci.cMaxCurvDir = it->cMaxCurvDir;
        ci.cMinCurvDir = it->cMinCurvDir;
        ci.fMaxCurvature = it->fMaxCurvature;
        ci.fMinCurvature = it->fMinCurvature;
        values.push_back(ci);
    }

    CurvInfo.setValues(values);

    return App::DocumentObject::StdReturn;
}
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();
    }
}
void CmdSandboxMeshLoaderBoost::activated(int iMsg)
{
# if BOOST_VERSION >= 104100
    // 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
    QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
        QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;")));

    boost::packaged_task< Base::Reference<Mesh::MeshObject> > pt
        (boost::bind(&loadMesh, fn));
    boost::unique_future< Base::Reference<Mesh::MeshObject> > fi=pt.get_future();
    boost::thread task(boost::move(pt)); // launch task on a thread
    fi.wait(); // wait for it to be finished

    App::Document* doc = App::GetApplication().getActiveDocument();
    Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh"));
    mesh->Mesh.setValuePtr((Mesh::MeshObject*)fi.get());
    mesh->purgeTouched();
#endif
}
void CmdSandboxMeshLoader::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
    QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(),
        QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;")));

    Sandbox::MeshLoaderThread thread(fn);
    QObject::connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));

    thread.start();
    loop.exec();

    Base::Reference<Mesh::MeshObject> data = thread.getMesh();
    App::Document* doc = App::GetApplication().getActiveDocument();
    Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh"));
    mesh->Mesh.setValuePtr((Mesh::MeshObject*)data);
    mesh->purgeTouched();
}
Exemple #5
0
static PyObject * importer(PyObject *self, PyObject *args)
{
    char* Name;
    char* DocName=0;
    if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
        return NULL;
    std::string EncodedName = std::string(Name);
    PyMem_Free(Name);

    PY_TRY {
        App::Document *pcDoc = 0;
        if (DocName)
            pcDoc = App::GetApplication().getDocument(DocName);
        else
            pcDoc = App::GetApplication().getActiveDocument();

        if (!pcDoc) {
            pcDoc = App::GetApplication().newDocument(DocName);
        }

        MeshObject mesh;
        if (mesh.load(EncodedName.c_str())) {
            Base::FileInfo file(EncodedName.c_str());
            unsigned long segmct = mesh.countSegments();
            if (segmct > 1) {
                for (unsigned long i=0; i<segmct; i++) {
                    std::auto_ptr<MeshObject> segm(mesh.meshFromSegment(mesh.getSegment(i).getIndices()));
                    Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
                        (pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str()));
                    pcFeature->Label.setValue(file.fileNamePure().c_str());
                    pcFeature->Mesh.swapMesh(*segm);
                    pcFeature->purgeTouched();
                }
            }
            else {
                Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
                    (pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str()));
                pcFeature->Label.setValue(file.fileNamePure().c_str());
                pcFeature->Mesh.swapMesh(mesh);
                pcFeature->purgeTouched();
            }
        }
    } PY_CATCH;

    Py_Return;
}
void MeshFaceAddition::addFace()
{
    Mesh::Feature* mf = static_cast<Mesh::Feature*>(faceView->mesh->getObject());
    App::Document* doc = mf->getDocument();
    doc->openTransaction("Add triangle");
    Mesh::MeshObject* mesh = mf->Mesh.startEditing();
    MeshCore::MeshFacet f;
    f._aulPoints[0] = faceView->index[0];
    f._aulPoints[1] = faceView->index[1];
    f._aulPoints[2] = faceView->index[2];
    std::vector<MeshCore::MeshFacet> faces;
    faces.push_back(f);
    mesh->addFacets(faces);
    mf->Mesh.finishEditing();
    doc->commitTransaction();

    clearPoints();
}
void CmdMengerSponge::activated(int iMsg)
{
    bool ok;
    int level = QInputDialog::getInteger(Gui::getMainWindow(),
        QString::fromAscii("Menger sponge"),
        QString::fromAscii("Recursion depth:"),
        3, 1, 5, 1, &ok);
    if (!ok) return;
    int ret = QMessageBox::question(Gui::getMainWindow(),
        QString::fromAscii("Parallel"),
        QString::fromAscii("Do you want to run this in a thread pool?"),
        QMessageBox::Yes|QMessageBox::No);
    bool parallel=(ret == QMessageBox::Yes);
    float x0=0,y0=0,z0=0;

    globalBox = Mesh::MeshObject::createCube(1,1,1);

    MeshObjectRef mesh;
    if (parallel)
        mesh = makeParallelMengerSponge(level,x0,y0,z0);
    else
        mesh = Sierpinski(level,x0,y0,z0);

    MeshCore::MeshKernel& kernel = mesh->getKernel();

    // remove duplicated points
    MeshCore::MeshFixDuplicatePoints(kernel).Fixup();

    // remove internal facets
    MeshCore::MeshEvalInternalFacets eval(kernel);
    eval.Evaluate();
    kernel.DeleteFacets(eval.GetIndices());

    // repair neighbourhood
    kernel.RebuildNeighbours();

    App::Document* doc = App::GetApplication().newDocument();
    Mesh::Feature* feature = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","MengerSponge"));
    feature->Mesh.setValue(*mesh);
    feature->purgeTouched();
}