Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

split.C

Go to the documentation of this file.
00001 /**********************************************************************
00002  * split.C:
00003  *
00004  *      Takes an .sm file as input, splits the mesh into
00005  *      disconnected pieces, then writes each piece to file
00006  *      as a separate mesh.
00007  *
00008  *      If the input is named bar.sm, and there are found to
00009  *      be 3 separate pieces, then they will be written to
00010  *      the files bar0.sm, bar1.sm, and bar2.sm.
00011  *
00012  **********************************************************************/
00013 #include "std/config.H"
00014 #include "mi.H"
00015 
00016 int 
00017 main(int argc, char *argv[])
00018 {
00019    if (argc != 2)
00020    {
00021       err_msg("Usage: %s input-mesh.sm", argv[0]);
00022       return 1;
00023    }
00024 
00025    ifstream fin;
00026    fin.open(argv[1]);
00027    if (!fin) {
00028       err_ret( "%s: Error: Could not open file %s", argv[0], argv[1]);
00029       return 0;
00030    }
00031 
00032    // Get the name without the .sm:
00033    // Probably there is a better way than what follows...
00034    char mesh_name[1024];
00035    strcpy(mesh_name, argv[1]);
00036    int n = strlen(mesh_name);
00037    if (n < 4)
00038    {
00039       err_msg("%s: Can't decipher name %s", argv[0], mesh_name);
00040       return 1;
00041    }
00042    mesh_name[n - 3] = 0;        // stomp the extension
00043 
00044    str_ptr mesh_path = str_ptr(mesh_name);
00045 
00046    BMESHptr mesh = BMESH::read_jot_stream(fin);
00047    if (!mesh || mesh->empty())
00048       return 1; // didn't work
00049    fin.close();
00050 
00051    // Remove duplicate vertices while we're at it
00052    mesh->remove_duplicate_vertices(false); // don't keep the bastards
00053 
00054    // Split it:
00055    ARRAY<BMESH*> meshes = mesh->split_components();
00056 
00057    err_msg("got %d meshes", meshes.num());
00058 
00059    str_ptr out_mesh = mesh_path + str_ptr(0) + str_ptr(".sm");
00060    cerr << "\nwriting " << **out_mesh << endl;
00061    if (Config::get_var_bool("JOT_RECENTER"))
00062       mesh->recenter();
00063    mesh->write_file(**out_mesh);
00064 
00065    for (int i=0; i<meshes.num(); i++) {
00066       out_mesh = mesh_path + str_ptr(i + 1) + str_ptr(".sm");
00067       cerr << "\nwriting " << **out_mesh << endl;
00068       if (Config::get_var_bool("JOT_RECENTER"))
00069          meshes[i]->recenter();
00070       meshes[i]->write_file(**out_mesh);
00071    }
00072 
00073    return 0;
00074 }
00075 
00076 /* end of file split.C */

Generated on Mon Sep 18 11:39:33 2006 for jot by  doxygen 1.4.4