コード例 #1
0
ファイル: AppPointsPy.cpp プロジェクト: itain/FreeCAD
    Py::Object open(const Py::Tuple& args)
    {
        char* Name;
        if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name))
            throw Py::Exception();
        std::string EncodedName = std::string(Name);
        PyMem_Free(Name);

        try {
            Base::Console().Log("Open in Points with %s",EncodedName.c_str());
            Base::FileInfo file(EncodedName.c_str());

            // extract ending
            if (file.extension().empty())
                throw Py::RuntimeError("No file extension");

            std::unique_ptr<Reader> reader;
            if (file.hasExtension("asc")) {
                reader.reset(new AscReader);
            }
#ifdef HAVE_PCL_IO
            else if (file.hasExtension("ply")) {
                reader.reset(new PlyReader);
            }
            else if (file.hasExtension("pcd")) {
                reader.reset(new PcdReader);
            }
#endif
            else {
                throw Py::RuntimeError("Unsupported file extension");
            }

            reader->read(EncodedName);

            App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");

            Points::Feature *pcFeature = 0;
            if (reader->hasProperties()) {
                // Scattered or structured points?
                if (reader->isStructured()) {
                    pcFeature = new Points::StructuredCustom();

                    App::PropertyInteger* width = static_cast<App::PropertyInteger*>
                        (pcFeature->getPropertyByName("Width"));
                    if (width) {
                        width->setValue(reader->getWidth());
                    }
                    App::PropertyInteger* height = static_cast<App::PropertyInteger*>
                        (pcFeature->getPropertyByName("Height"));
                    if (height) {
                        height->setValue(reader->getHeight());
                    }
                }
                else {
                    pcFeature = new Points::FeatureCustom();
                }

                pcFeature->Points.setValue(reader->getPoints());
                // add gray values
                if (reader->hasIntensities()) {
                    Points::PropertyGreyValueList* prop = static_cast<Points::PropertyGreyValueList*>
                        (pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity"));
                    if (prop) {
                        prop->setValues(reader->getIntensities());
                    }
                }
                // add colors
                if (reader->hasColors()) {
                    App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
                        (pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
                    if (prop) {
                        prop->setValues(reader->getColors());
                    }
                }
                // add normals
                if (reader->hasNormals()) {
                    Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>
                        (pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal"));
                    if (prop) {
                        prop->setValues(reader->getNormals());
                    }
                }

                // delayed adding of the points feature
                pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
                pcDoc->recomputeFeature(pcFeature);
                pcFeature->purgeTouched();
            }
            else {
                if (reader->isStructured()) {
                    Structured* structured = new Points::Structured();
                    structured->Width.setValue(reader->getWidth());
                    structured->Height.setValue(reader->getHeight());
                    pcFeature = structured;
                }
                else {
                    pcFeature = new Points::Feature();
                }

                // delayed adding of the points feature
                pcFeature->Points.setValue(reader->getPoints());
                pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
                pcDoc->recomputeFeature(pcFeature);
                pcFeature->purgeTouched();
            }
        }
        catch (const Base::Exception& e) {
            throw Py::RuntimeError(e.what());
        }

        return Py::None();
    }
コード例 #2
0
ファイル: ViewProvider.cpp プロジェクト: 3DPrinterGuy/FreeCAD
void ViewProviderPoints::setDisplayMode(const char* ModeName)
{
    int numPoints = pcPointsCoord->point.getNum();

    if (strcmp("Color",ModeName) == 0) {
        std::map<std::string,App::Property*> Map;
        pcObject->getPropertyMap(Map);
        for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
            Base::Type type = it->second->getTypeId();
            if (type == App::PropertyColorList::getClassTypeId()) {
                App::PropertyColorList* colors = static_cast<App::PropertyColorList*>(it->second);
                if (numPoints != colors->getSize()) {
#ifdef FC_DEBUG
                    SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
                                              "The number of points (%d) doesn't match with the number of colors (%d).", numPoints, colors->getSize());
#endif
                    // fallback 
                    setDisplayMaskMode("Point");
                }
                else {
                    setVertexColorMode(colors);
                    setDisplayMaskMode("Color");
                }
                break;
            }
        }
    }
    else if (strcmp("Intensity",ModeName) == 0) {
        std::map<std::string,App::Property*> Map;
        pcObject->getPropertyMap(Map);
        for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
            Base::Type type = it->second->getTypeId();
            if (type == Points::PropertyGreyValueList::getClassTypeId()) {
                Points::PropertyGreyValueList* greyValues = static_cast<Points::PropertyGreyValueList*>(it->second);
                if (numPoints != greyValues->getSize()) {
#ifdef FC_DEBUG
                    SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
                                              "The number of points (%d) doesn't match with the number of grey values (%d).", numPoints, greyValues->getSize());
#endif
                    // Intensity mode is not possible then set the default () mode instead.
                    setDisplayMaskMode("Point");
                }
                else {
                    setVertexGreyvalueMode((Points::PropertyGreyValueList*)it->second);
                    setDisplayMaskMode("Color");
                }
                break;
            }
        }
    }
    else if (strcmp("Shaded",ModeName) == 0) {
        std::map<std::string,App::Property*> Map;
        pcObject->getPropertyMap(Map);
        for (std::map<std::string,App::Property*>::iterator it = Map.begin(); it != Map.end(); ++it) {
            Base::Type type = it->second->getTypeId();
            if (type == Points::PropertyNormalList::getClassTypeId()) {
                Points::PropertyNormalList* normals = static_cast<Points::PropertyNormalList*>(it->second);
                if (numPoints != normals->getSize()) {
#ifdef FC_DEBUG
                    SoDebugError::postWarning("ViewProviderPoints::setDisplayMode",
                                              "The number of points (%d) doesn't match with the number of normals (%d).", numPoints, normals->getSize());
#endif
                    // fallback 
                    setDisplayMaskMode("Point");
                }
                else {
                    setVertexNormalMode(normals);
                    setDisplayMaskMode("Shaded");
                }
                break;
            }
        }
    }
    else if (strcmp("Points",ModeName) == 0) {
        setDisplayMaskMode("Point");
    }

    ViewProviderGeometryObject::setDisplayMode(ModeName);
}
コード例 #3
0
ファイル: AppPointsPy.cpp プロジェクト: itain/FreeCAD
    Py::Object exporter(const Py::Tuple& args)
    {
        PyObject *object;
        char *Name;

        if (!PyArg_ParseTuple(args.ptr(), "Oet", &object, "utf-8", &Name))
            throw Py::Exception();

        std::string encodedName = std::string(Name);
        PyMem_Free(Name);

        Base::FileInfo file(encodedName);

        // extract ending
        if (file.extension().empty())
            throw Py::RuntimeError("No file extension");

        Py::Sequence list(object);
        Base::Type pointsId = Base::Type::fromName("Points::Feature");
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
            PyObject* item = (*it).ptr();
            if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
                App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
                if (obj->getTypeId().isDerivedFrom(pointsId)) {

                    Points::Feature* fea = static_cast<Points::Feature*>(obj);
                    const PointKernel& kernel = fea->Points.getValue();
                    std::unique_ptr<Writer> writer;
                    if (file.hasExtension("asc")) {
                        writer.reset(new AscWriter(kernel));
                    }
#ifdef HAVE_PCL_IO
                    else if (file.hasExtension("ply")) {
                        writer.reset(new PlyWriter(kernel));
                    }
                    else if (file.hasExtension("pcd")) {
                        writer.reset(new PcdWriter(kernel));
                    }
#endif
                    else {
                        throw Py::RuntimeError("Unsupported file extension");
                    }

                    // get additional properties if there
                    App::PropertyInteger* width = dynamic_cast<App::PropertyInteger*>
                        (fea->getPropertyByName("Width"));
                    if (width) {
                        writer->setWidth(width->getValue());
                    }
                    App::PropertyInteger* height = dynamic_cast<App::PropertyInteger*>
                        (fea->getPropertyByName("Height"));
                    if (height) {
                        writer->setHeight(height->getValue());
                    }
                    // get gray values
                    Points::PropertyGreyValueList* grey = dynamic_cast<Points::PropertyGreyValueList*>
                        (fea->getPropertyByName("Intensity"));
                    if (grey) {
                        writer->setIntensities(grey->getValues());
                    }
                    // get colors
                    App::PropertyColorList* col = dynamic_cast<App::PropertyColorList*>
                        (fea->getPropertyByName("Color"));
                    if (col) {
                        writer->setColors(col->getValues());
                    }
                    // get normals
                    Points::PropertyNormalList* nor = dynamic_cast<Points::PropertyNormalList*>
                        (fea->getPropertyByName("Normal"));
                    if (nor) {
                        writer->setNormals(nor->getValues());
                    }

                    writer->write(encodedName);

                    break;
                }
                else {
                    Base::Console().Message("'%s' is not a point object, export will be ignored.\n", obj->Label.getValue());
                }
            }
        }

        return Py::None();
    }
コード例 #4
0
ファイル: AppPointsPy.cpp プロジェクト: fhln/FreeCAD
    Py::Object open(const Py::Tuple& args)
    {
        char* Name;
        if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name))
            throw Py::Exception();
        std::string EncodedName = std::string(Name);
        PyMem_Free(Name);

        try {
            Base::Console().Log("Open in Points with %s",EncodedName.c_str());
            Base::FileInfo file(EncodedName.c_str());

            // extract ending
            if (file.extension().empty())
                throw Py::RuntimeError("No file extension");

            if (file.hasExtension("asc")) {
                // create new document and add Import feature
                App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
                Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
                Points::PointKernel pkTemp;
                pkTemp.load(EncodedName.c_str());
                pcFeature->Points.setValue( pkTemp );

            }
#ifdef HAVE_PCL_IO
            else if (file.hasExtension("ply")) {
                PlyReader reader;
                reader.read(EncodedName);

                App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
                if (reader.hasProperties()) {
                    Points::FeatureCustom *pcFeature = new Points::FeatureCustom();
                    pcFeature->Points.setValue(reader.getPoints());
                    // add gray values
                    if (reader.hasIntensities()) {
                        Points::PropertyGreyValueList* prop = static_cast<Points::PropertyGreyValueList*>
                            (pcFeature->addDynamicProperty("Points::PropertyGreyValueList", "Intensity"));
                        if (prop) {
                            prop->setValues(reader.getIntensities());
                        }
                    }
                    // add colors
                    if (reader.hasColors()) {
                        App::PropertyColorList* prop = static_cast<App::PropertyColorList*>
                            (pcFeature->addDynamicProperty("App::PropertyColorList", "Color"));
                        if (prop) {
                            prop->setValues(reader.getColors());
                        }
                    }
                    // add normals
                    if (reader.hasNormals()) {
                        Points::PropertyNormalList* prop = static_cast<Points::PropertyNormalList*>
                            (pcFeature->addDynamicProperty("Points::PropertyNormalList", "Normal"));
                        if (prop) {
                            prop->setValues(reader.getNormals());
                        }
                    }

                    // delayed adding of the points feature
                    pcDoc->addObject(pcFeature, file.fileNamePure().c_str());
                    pcDoc->recomputeFeature(pcFeature);
                }
                else {
                    Points::Feature *pcFeature = static_cast<Points::Feature*>
                        (pcDoc->addObject("Points::Feature", file.fileNamePure().c_str()));
                    pcFeature->Points.setValue(reader.getPoints());
                    pcDoc->recomputeFeature(pcFeature);
                }
            }
#endif
            else {
                throw Py::RuntimeError("Unsupported file extension");
            }
        }
        catch (const Base::Exception& e) {
            throw Py::RuntimeError(e.what());
        }

        return Py::None();
    }