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

reverse.C

Go to the documentation of this file.
00001 /**********************************************************************
00002  * reverse.C:
00003  *
00004  *   Usage:
00005  *      % reverse [ -c ] < input.sm > output.sm
00006  *
00007  *   With -c option, just reverses the normals of each connected
00008  *   component with negative "volume." Otherwise reverses all the
00009  *   normals for the whole mesh.
00010  *
00011  **********************************************************************/
00012 #include "std/config.H"
00013 #include "mi.H"
00014 
00015 int 
00016 main(int argc, char *argv[])
00017 {
00018    // See note above about -c option:
00019    bool do_components = false;
00020    if (argc == 2 && str_ptr(argv[1]) == str_ptr("-c")) {
00021       do_components = true;
00022    } else if (argc != 1) {
00023       err_msg("Usage: %s [ -c ] < input.sm > output.sm", argv[0]);
00024       return 1;
00025    }
00026 
00027    BMESHptr mesh = BMESH::read_jot_stream(cin);
00028    if (!mesh || mesh->empty())
00029       return 1; // didn't work
00030 
00031    if (do_components) {
00032       // Reverse separate components as needed:
00033       bool changed = false;
00034       ARRAY<Bface_list> components = mesh->get_components();
00035       for (int i=0; i<components.num(); i++) {
00036          if (components[i].volume() < 0) {
00037             err_msg("reversing component: %d faces", components[i].num());
00038             reverse_faces(components[i]);
00039             changed = true;
00040          }
00041       }
00042       if (changed) {
00043          mesh->changed();
00044       } else {
00045          err_msg("%s: nothing changed", argv[0]);
00046       }
00047    } else {
00048       // Do the whole thing
00049       mesh->reverse();
00050    }
00051 
00052    mesh->write_stream(cout);
00053 
00054    return 0;
00055 }

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