Пример #1
0
/**
 * Export the full PortaBase file content to an XML file.  The records are
 * listed in the current sorting order, and the ones which do not match the
 * current filter are marked with an 'h="y"' attribute (an abbreviation for
 * 'hidden="yes"').
 *
 * @param filename The XML file to create or overwrite
 */
void View::exportToXML(const QString &filename)
{
    c4_View fullView = db->getData();
    if (!sortColumn.isEmpty()) {
        fullView = db->sortData(fullView, sortColumn, sortOrder);
    }
    else {
        // if sortName is "", just returns the unsorted data
        fullView = db->sortData(fullView, sortName);
    }
    Filter *filter = db->getFilter(db->currentFilter());
    c4_View currView = filter->apply(fullView);
    db->exportToXML(filename, fullView, currView, columns);
}
Пример #2
0
/**
 * Update the Metakit view in use to reflect the current filtering and
 * sorting parameters.
 */
void View::prepareData()
{
    dbview = db->getData();
    Filter *filter = db->getFilter(db->currentFilter());
    dbview = filter->apply(dbview);
    if (!sortColumn.isEmpty()) {
        dbview = db->sortData(dbview, sortColumn, sortOrder);
    }
    else {
        // if sortName is "", just returns the unsorted data
        dbview = db->sortData(dbview, sortName);
    }
    rowCnt = dbview.GetSize();
}
Пример #3
0
double Classifier::getFilterError(string trainingDirectory, Annotations::Tag tag,
                                  ErrorType errorType) {
    Annotations annotations;
    Filter* filter = getFilter(tag);

    // read annotations
    string locationsFileName = trainingDirectory + "/" + Globals::annotationsFileName;
    annotations.readAnnotations(locationsFileName);

    // get the frames directory
    string framesDirectory = annotations.getFramesDirectory();

    // reset total
    double totalError = 0;

    // iterate over the set of all annotations
    vector<FrameAnnotation*>& frameAnnotations = annotations.getFrameAnnotations();
    for (unsigned int i = 0; i < frameAnnotations.size(); i++) {
        FrameAnnotation* fa = frameAnnotations[i];

        // get LOI
        CvPoint& location = fa->getLOI(tag);
        if (!location.x && !location.y)
            continue;

        // compose filename
        char buffer[256];
        sprintf(buffer, "frame_%d.png", fa->getFrameNumber());
        string fileName = framesDirectory + "/" + buffer;

        // load image
        IplImage* inputImg = cvLoadImage((const char*)fileName.c_str());
        if (!inputImg) {
            string err = "Filter::update. Cannot load file " + fileName + ".";
            throw (err);
        }
        IplImage* image = cvCreateImage(cvGetSize(inputImg), IPL_DEPTH_8U, 1);
        cvCvtColor(inputImg, image, CV_BGR2GRAY);

        // get the location of the left eye
        CvPoint offset;
        offset.x = offset.y = 0;
        IplImage* roi = (roiFunction)? roiFunction(image, *fa, offset, Annotations::Face) : 0;

        location.x -= offset.x;
        location.y -= offset.y;

        // apply filter
        fftw_complex* imageFFT = filter->preprocessImage((roi)? roi : image);
        IplImage* postFilterImg = filter->apply(imageFFT);

        // compute location
        double min;
        double max;
        CvPoint minLoc;
        CvPoint maxLoc;
        cvMinMaxLoc(postFilterImg, &min, &max, &minLoc, &maxLoc);

        // compute squared error as the distance between the location
        // found and the location as annotated
        double xdiff = abs(maxLoc.x - location.x);
        double ydiff = abs(maxLoc.y - location.y);

        switch (errorType) {
        case OneNorm:
            totalError += (xdiff + ydiff);
            break;
        case TwoNorm:
            totalError += sqrt(xdiff * xdiff + ydiff * ydiff);
            break;
        case MSE:
            totalError += (xdiff * xdiff + ydiff * ydiff);
            break;
        default:
            totalError += ((xdiff > ydiff)? xdiff : ydiff);
            break;
        }

        if (roi)
            cvReleaseImage(&roi);
        cvReleaseImage(&image);
        cvReleaseImage(&inputImg);
    }

    return totalError / frameAnnotations.size();
}
Пример #4
0
int main(int argc, char* argv[])
{
    CmdLine cmd_line;
    parse_command_line(argc,argv,cmd_line);
    Grid grid(cmd_line.in_file);

    if (cmd_line.box_dim_plot) {
        vector<float> fractal = GridAlgorithms::fractal_values(grid);
        string out_file = grid.to_string() + ".box_dim.gplt";
        write_plot(out_file,fractal);
    }
    if (cmd_line.iso_area_plot) {
        vector<int> edge_count = GridAlgorithms::intersected_edges(grid);
        string out_file = grid.to_string() + ".isoarea.edge.gplt";
        write_plot(out_file,edge_count);
    }
    if (cmd_line.region) {
        FractalGrid fg(grid,cmd_line.region_size,cmd_line.region_iso);
        fg.write_nrrd();
    }
    if (cmd_line.region4d) {
        FractalGrid4D fg(grid,cmd_line.region4d_size,cmd_line.region4d_inc);
        fg.write_nrrd();
    }
    if (cmd_line.boolean_grid) {
        BooleanGrid bg(grid,cmd_line.boolean_size, cmd_line.boolean_iso, cmd_line.boolean_dim);
        bg.write_nrrd();
    }
    if (cmd_line.filter_type.length() != 0) {
        Filter* filter;
        int region_size = cmd_line.filter_size;
        float isovalue = cmd_line.filter_iso;
        float dim = cmd_line.filter_dim;
        if (cmd_line.filter_type == "gaussian") {
            if(cmd_line.filter_opt) {
                filter = new FractalGaussianFilter(region_size,isovalue,dim);
            } else {
                filter = new GaussianFilter();
            }
        } else if (cmd_line.filter_type == "median") {
            if (cmd_line.filter_opt) {
                filter = new FractalMedianFilter(region_size,isovalue,dim);
            } else {
                filter = new MedianFilter();
            }
        } else {
            cerr << "Unrecognized filter type: " << cmd_line.filter_type << endl;
        }
        
        filter->apply(grid);
        grid.write_nrrd();
        delete filter;
    }
    if (cmd_line.fractal) {
        vector<float> fractal = GridAlgorithms::fractal_values(grid);
        cout << "Fractal Dimension: " << endl;
        for (int i = 0; i < cmd_line.fractal_iso.size(); i++) {
            float iso = cmd_line.fractal_iso[i];
            if(iso >= fractal.size()) {
                cerr << "Isovalue " << iso << "exceeds the maximum scalar value in " << grid.to_string() << endl;
            } else {
                cout << iso << "\t" << fractal[((int)iso)] << endl;
            }
        }
    }
    if (cmd_line.fractal_4d) {
        float fractal_4d = GridAlgorithms::fractal_dimension_4d(grid, cmd_line.fractal_4d_inc, cmd_line.noz);
        cout << cmd_line.in_file << " " << fractal_4d << endl;
    }
    if (cmd_line.ss_grid) {
        GridAlgorithms::smooth_surface(grid, cmd_line.ss_size, cmd_line.ss_inc, cmd_line.ss_iso, cmd_line.ss_dim);
        grid.write_nrrd();
    }
    return 0;
}
Пример #5
0
int main(int argc, char** argv) {
    using namespace Sirikata;
    using namespace Sirikata::Mesh;

    if(argc < 2) {
    	usage();
    	return 0;
    }

    // Check for help request
    for(int argi = 1; argi < argc; argi++) {
        std::string arg_str(argv[argi]);
        if (arg_str == "-h" || arg_str == "--help") {
            usage();
            return 0;
        }
    }

    PluginManager plugins;
    plugins.loadList("colladamodels");
    plugins.loadList("mesh-billboard");
    plugins.loadList("common-filters");
    plugins.loadList("nvtt");

    //Check for list request
    for(int argi = 1; argi < argc; argi++) {
        std::string arg_str(argv[argi]);
        if (arg_str == "--list") {
            std::list<std::string> filterList = FilterFactory::getSingleton().getNames();
            printf("meshtool: printing filter list:\n");
            for(std::list<std::string>::const_iterator it = filterList.begin(); it != filterList.end(); it++) {
                printf("%s\n", it->c_str());
            }
            return 0;
        }
    }

    //Check for options
    InitOptions();
    for(int argi = 1; argi < argc; argi++) {
        std::string arg_str(argv[argi]);
        if(arg_str.substr(0, 9) == "--options") {
            uint32 equal_idx = arg_str.find('=');
            if (equal_idx != std::string::npos) {
                std::string options_args = arg_str.substr(equal_idx+1);
                char * buff = new char[1000];
                assert(options_args.length() < 1000);
                strcpy(buff, options_args.c_str());
                char * newargv [] = {argv[0], buff};
                ParseOptions(2, newargv);
                delete buff;
            }
        }
    }

    FilterDataPtr current_data(new FilterData);
    for(int argi = 1; argi < argc; argi++) {
        std::string arg_str(argv[argi]);
        if (arg_str.substr(0, 2) != "--") {
            std::cout << "Couldn't parse argument: " << arg_str << std::endl;
            exit(-1);
        }
        arg_str = arg_str.substr(2);
        // Split filter name and args
        std::string filter_name, filter_args;
        uint32 equal_idx = arg_str.find('=');
        if (equal_idx != std::string::npos) {
            filter_name = arg_str.substr(0, equal_idx);
            filter_args = arg_str.substr(equal_idx+1);
        }
        else {
            filter_name = arg_str;
            filter_args = "";
        }
        if(filter_name == "options")
               continue;
        // Verify
        if (!FilterFactory::getSingleton().hasConstructor(filter_name)) {
            std::cout << "Couldn't find filter: " << filter_name << std::endl;
            exit(-1);
        }
        // And apply
        Filter* filter = FilterFactory::getSingleton().getConstructor(filter_name)(filter_args);
        current_data = filter->apply(current_data);
        delete filter;
    }

    return 0;
}