Пример #1
0
    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();
    }