Revision: 57136
          http://sourceforge.net/p/brlcad/code/57136
Author:   indianlarry
Date:     2013-08-26 09:55:22 +0000 (Mon, 26 Aug 2013)
Log Message:
-----------
Merging trunk into branch 'nurbs' r:57107:57135

Modified Paths:
--------------
    brlcad/branches/nurbs/TODO
    brlcad/branches/nurbs/doc/burst/README
    brlcad/branches/nurbs/doc/burst/burst.mm
    brlcad/branches/nurbs/doc/docbook/system/man5/en/attributes.xml
    brlcad/branches/nurbs/doc/html/CMakeLists.txt
    brlcad/branches/nurbs/include/bn.h
    brlcad/branches/nurbs/include/brep.h
    brlcad/branches/nurbs/include/ged.h
    brlcad/branches/nurbs/include/icv.h
    brlcad/branches/nurbs/misc/auto-man-page/README.auto-man-page-handling
    brlcad/branches/nurbs/src/conv/step/g-step/CMakeLists.txt
    brlcad/branches/nurbs/src/libbrep/boolean.cpp
    brlcad/branches/nurbs/src/libbrep/intersect.cpp
    brlcad/branches/nurbs/src/libged/CMakeLists.txt
    brlcad/branches/nurbs/src/libged/brep.c
    brlcad/branches/nurbs/src/libged/gqa.c
    brlcad/branches/nurbs/src/libicv/bw.c
    brlcad/branches/nurbs/src/libicv/color_space.c
    brlcad/branches/nurbs/src/librt/comb/comb.c
    brlcad/branches/nurbs/src/librt/db5_types.c
    brlcad/branches/nurbs/src/librt/primitives/brep/brep.cpp
    brlcad/branches/nurbs/src/mged/setup.c
    brlcad/branches/nurbs/src/other/stepcode/src/express/test/print_attrs.c
    brlcad/branches/nurbs/src/other/stepcode/src/express/test/print_schemas.c
    brlcad/branches/nurbs/src/util/CMakeLists.txt
    brlcad/branches/nurbs/src/util/dsp_add.c
    brlcad/branches/nurbs/src/util/fix_polysolids.c
    brlcad/branches/nurbs/src/util/pix-bw.c

Added Paths:
-----------
    brlcad/branches/nurbs/src/libged/pull.c

Modified: brlcad/branches/nurbs/TODO
===================================================================
--- brlcad/branches/nurbs/TODO  2013-08-26 09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/TODO  2013-08-26 09:55:22 UTC (rev 57136)
@@ -1003,7 +1003,7 @@
 * clean up default attributes to be consistent and upgrade old
   attributes to their new names.  includes likes of region, region_id,
   material_id, air, los, rgb, oshader, and inherit.  see
-  doc/docbook/system/man5/en/gattributes.xml for more detailed listing.
+  doc/docbook/system/man5/en/attributes.xml for more detailed listing.
 
 * implement an option to "attr upgrade" for reading upgrade/downgrade
   plugins/instructions from an external file for 3rd party use.

Modified: brlcad/branches/nurbs/doc/burst/README
===================================================================
--- brlcad/branches/nurbs/doc/burst/README      2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/doc/burst/README      2013-08-26 09:55:22 UTC (rev 
57136)
@@ -1,3 +1,64 @@
 Documentation for the BRL-CAD program 'burst'.
 
 Debian requires packages groff and groff-base.
+
+The original source file ('burst.mm') has been modified slightly to
+ensure correct handling by Eric Raymond's doclifter
+(http://www.catb.org/~esr/doclifter/).  From an e-mail from Eric:
+
+from:     Eric S. Raymond <[email protected]>
+reply-to:  [email protected]
+to:       Tom Browder <[email protected]>
+date:     Tue, Aug 20, 2013 at 8:48 AM
+subject:   Re: doclifter (master) failing on troff mm source
+mailed-by: thyrsus.com
+
+<quote>
+Tom Browder <[email protected]>:
+> I have checked all macros and they are valid mm macros so I  can't
+> figure out why doclifter is failing.  I can send you the whole source
+> zipped if you're interested.
+
+What you sent is sufficient.  The problem is that your mm file
+contains none of the three trigger macros doclifter is looking for as
+a way to recognize that it's dealing with mm - .MT, .SA, or .COVER.
+The relevant table looks like this:
+
+# This is how we autodetect the right macro set:
+
+interpreter_dispatch = {
+    "pp": MeInterpreter,
+    "Dt": MdocInterpreter,
+    "Dd": MdocInterpreter,
+    "Nm": MdocInterpreter,
+    "AU": MsInterpreter,
+    "NH": MsInterpreter,
+    "TH": ManInterpreter,
+    "MT": MmInterpreter,
+    "SA": MmInterpreter,
+    "COVER": MmInterpreter,
+    # Extension macro sets
+    "supplemental macros used in Tcl/Tk": TkManInterpreter,
+    "BS": TkManInterpreter,
+    "the F register is turned on": Pod2ManInterpreter,
+    "ZN": XManInterpreter,
+    "Pn": XManInterpreter,
+    "ny0": XManInterpreter,
+    "reStructuredText": reStructuredTextInterpreter,
+    "reStructeredText": reStructuredTextInterpreter,
+    "DocBook XSL Stylesheets" : DocBookInterpreter,
+    "pdfdest" : FoojzsInterpreter,
+    "H0": ASTInterpreter,
+    # These are all of the supported Mwww tags
+    "URL": MwwwInterpreter,
+    "FTP": MwwwInterpreter,
+    "MTO": MwwwInterpreter,
+    "PIMG": MwwwInterpreter,
+    "IMG": MwwwInterpreter,
+    "TAG": MwwwInterpreter,
+    }
+
+Inserting a dummy .MT 0 call should fix your problem.
+</quote>
+
+

Modified: brlcad/branches/nurbs/doc/burst/burst.mm
===================================================================
--- brlcad/branches/nurbs/doc/burst/burst.mm    2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/doc/burst/burst.mm    2013-08-26 09:55:22 UTC (rev 
57136)
@@ -1,4 +1,7 @@
 .\" ASI Note: PP was changed to P in this file; CS was commented out
+.\" Note the following line was added per Eric Raymond's advice for
+.\"  use by doclifter:
+.MT 0
 .PH ""
 .PF "''\\\\nP''"
 .so defs.mm

Modified: brlcad/branches/nurbs/doc/docbook/system/man5/en/attributes.xml
===================================================================
--- brlcad/branches/nurbs/doc/docbook/system/man5/en/attributes.xml     
2013-08-26 09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/doc/docbook/system/man5/en/attributes.xml     
2013-08-26 09:55:22 UTC (rev 57136)
@@ -252,6 +252,11 @@
     <para>BRL-CAD Team</para>
 </refsection>
 
+<refsection xml:id="copyright"><title>COPYRIGHT</title>
+    <para>This software is Copyright (c) 2010-2013 United States Government as
+    represented by the U.S. Army Research Laboratory. All rights 
reserved.</para>
+</refsection>
+
 <refsection xml:id="bug_reports"><title>BUG REPORTS</title>
 
   <para>

Modified: brlcad/branches/nurbs/doc/html/CMakeLists.txt
===================================================================
--- brlcad/branches/nurbs/doc/html/CMakeLists.txt       2013-08-26 09:44:53 UTC 
(rev 57135)
+++ brlcad/branches/nurbs/doc/html/CMakeLists.txt       2013-08-26 09:55:22 UTC 
(rev 57136)
@@ -93,6 +93,7 @@
 ADD_DOC(librt_HTML html/manuals/librt)
 
 set(manuals_HTML
+  manuals/BRL-CAD_gear_logo.ico
   manuals/Install.html
   manuals/Obtain.html
   manuals/Overview.html

Modified: brlcad/branches/nurbs/include/bn.h
===================================================================
--- brlcad/branches/nurbs/include/bn.h  2013-08-26 09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/include/bn.h  2013-08-26 09:55:22 UTC (rev 57136)
@@ -2575,7 +2575,7 @@
 
 
 /* This could be larger, or even dynamic... */
-#define BN_MAX_POLY_DEGREE 4   /* Maximum Poly Order */
+#define BN_MAX_POLY_DEGREE 6   /* Maximum Poly Order */
 
 /**
  * Polynomial data type

Modified: brlcad/branches/nurbs/include/brep.h
===================================================================
--- brlcad/branches/nurbs/include/brep.h        2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/include/brep.h        2013-08-26 09:55:22 UTC (rev 
57136)
@@ -2026,6 +2026,13 @@
             Subsurface* treeB = 0);
 
 
+enum op_type {
+    BOOLEAN_UNION = 0,
+    BOOLEAN_INTERSECT = 1,
+    BOOLEAN_DIFF = 2
+};
+
+
 /**
  * Evaluate NURBS boolean operations.
  *
@@ -2035,7 +2042,7 @@
  * @param operation [in]
  */
 extern BREP_EXPORT int
-ON_Boolean(ON_Brep* brepO, const ON_Brep* brepA, const ON_Brep* brepB, int 
operation);
+ON_Boolean(ON_Brep* brepO, const ON_Brep* brepA, const ON_Brep* brepB, op_type 
operation);
 
 
 /**
@@ -2047,7 +2054,7 @@
  * @return the result curve segment. NULL for error.
  */
 extern BREP_EXPORT ON_Curve*
-sub_curve(ON_Curve* in, double a, double b);
+sub_curve(const ON_Curve* in, double a, double b);
 
 } /* extern C++ */
 #endif

Modified: brlcad/branches/nurbs/include/ged.h
===================================================================
--- brlcad/branches/nurbs/include/ged.h 2013-08-26 09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/include/ged.h 2013-08-26 09:55:22 UTC (rev 57136)
@@ -1614,6 +1614,11 @@
 GED_EXPORT extern int ged_ptranslate(struct ged *gedp, int argc, const char 
*argv[]);
 
 /**
+ *Pull objects' path transformations from primitives
+ */
+GED_EXPORT extern int ged_pull(struct ged *gedp, int argc, const char *argv[]);
+
+/**
  * Push objects' path transformations to primitives
  */
 GED_EXPORT extern int ged_push(struct ged *gedp, int argc, const char *argv[]);

Modified: brlcad/branches/nurbs/include/icv.h
===================================================================
--- brlcad/branches/nurbs/include/icv.h 2013-08-26 09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/include/icv.h 2013-08-26 09:55:22 UTC (rev 57136)
@@ -243,13 +243,6 @@
 ICV_EXPORT int icv_gray2rgb(icv_image_t *img);
 
 typedef enum {
-    ICV_PIX_NTSC,
-    ICV_PIX_CRT,
-    ICV_PIX_SET_EQUAL,
-    ICV_PIX_SELECT_CHANNEL
-} ICV_DEPTH_METHOD;
-
-typedef enum {
     ICV_COLOR_RGB,
     ICV_COLOR_R,
     ICV_COLOR_G,
@@ -260,6 +253,18 @@
 } ICV_COLOR;
 
 /**
+ * converts image to single channel image by combining three weights 
+ * based on NTSC primaries and 6500 white.
+ */
+#define icv_rgb2gray_ntsc(_a) icv_rgb2gray(_a, ICV_COLOR_RGB, 0.30, 0.59, 0.11)
+
+/**
+ * converts image to single channel image by combining three using 
+ * weights based on CRT phosphor and D6500 white.
+ */
+#define icv_rgb2gray_crt(_a) icv_rgb2gray(_a, ICV_COLOR_RGB, 0.26, 0.66, 0.08)
+
+/**
  * converts a three plane image to single plane image.
  * This function will combine or select planes of the image based on
  * the input arguments
@@ -268,16 +273,6 @@
  * icv_image_rgb2gray(bif, 0 ,0 ,0 ,0 ,0); where bif is the rgb
  * image to be converted.
  *
- * @param img Image to be converted
- * @param method Conversion Method
- * ICV_PIX_NTSC:  converts to single plan image by combining three
- *                planes using weights based on NTSC primaries and
- *                D6500 white.
- * ICV_PIX_CRT :   converts to single plane image by combining three
- *                planes using weights based on CRT phosphor
- *                chromaticities and D6500 white.
- * ICV_PIX_SET_EQUAL: Combines the three planes using equal weights.
- * ICV_PIX_SELECT_CHANNEL: lets us select the channels
  * @param color Chooses color planes to be selected for combination
  *    This function will need color to be specified from
  *              ICV_COLOR_R
@@ -298,7 +293,6 @@
  *
  */
 ICV_EXPORT int icv_rgb2gray(icv_image_t *img,
-                                 ICV_DEPTH_METHOD method,
                                  ICV_COLOR color,
                                  double rweight,
                                  double gweight,

Modified: brlcad/branches/nurbs/misc/auto-man-page/README.auto-man-page-handling
===================================================================
--- brlcad/branches/nurbs/misc/auto-man-page/README.auto-man-page-handling      
2013-08-26 09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/misc/auto-man-page/README.auto-man-page-handling      
2013-08-26 09:55:22 UTC (rev 57136)
@@ -61,8 +61,8 @@
   with '/**' or '/*!' are completely ignored).
 
   Each such block is divided into one or more parts beginning with a
-  keyword ('partname:'; but see 'opt:' later) which identifies a
-  section to appear in the man page.
+  unique keyword ending with a colon ('partname:'; but see 'opt:' later)
+  which identifies a section to appear in the man page.
 
   The block must begin with the following format or it will be ignored:
 
@@ -78,7 +78,7 @@
     underscores.  The part name will be translated into upper case and
     underscores into spaces in the man page.
 
-  - Following the mandatory first part may be more parts.
+  - Following the mandatory first part may be more unique parts.
 
   - A description ends when the next part keyword is found or the the
     comment block ends.

Modified: brlcad/branches/nurbs/src/conv/step/g-step/CMakeLists.txt
===================================================================
--- brlcad/branches/nurbs/src/conv/step/g-step/CMakeLists.txt   2013-08-26 
09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/src/conv/step/g-step/CMakeLists.txt   2013-08-26 
09:55:22 UTC (rev 57136)
@@ -52,6 +52,7 @@
 if(MSVC)
   set(gstep_IMPORTS
     BU_DLL_IMPORTS
+    BN_DLL_IMPORTS
     RT_DLL_IMPORTS
     WDB_DLL_IMPORTS
     SC_CORE_DLL_IMPORTS

Modified: brlcad/branches/nurbs/src/libbrep/boolean.cpp
===================================================================
--- brlcad/branches/nurbs/src/libbrep/boolean.cpp       2013-08-26 09:44:53 UTC 
(rev 57135)
+++ brlcad/branches/nurbs/src/libbrep/boolean.cpp       2013-08-26 09:55:22 UTC 
(rev 57136)
@@ -39,7 +39,8 @@
 
 #define DEBUG_BREP_BOOLEAN 1
 #define USE_CONNECTIVITY_GRAPH 1
-#define INTERSECTION_TOL 0.001
+#define INTERSECTION_TOL 1e-4
+#define ANGLE_TOL ON_PI/1800.0
 
 
 struct IntersectPoint {
@@ -373,7 +374,7 @@
     for (int i = 0; i < x_event.Count(); i++) {
        // Find tangent intersections.
        // What should we do if it's ccx_overlap?
-       if 
(polycurve.TangentAt(x_event[i].m_a[0]).IsParallelTo(linecurve.m_line.Direction()))
+       if 
(polycurve.TangentAt(x_event[i].m_a[0]).IsParallelTo(linecurve.m_line.Direction(),
 ANGLE_TOL))
            count++;
     }
 
@@ -1253,8 +1254,69 @@
 }
 
 
+HIDDEN bool
+IsFaceInsideBrep(const TrimmedFace* tface, const ON_Brep* brep, 
ON_SimpleArray<Subsurface*>& surf_tree)
+{
+    if (tface == NULL || brep == NULL)
+       return false;
+
+    const ON_BrepFace* bface = tface->m_face;
+    if (bface == NULL || 
!bface->BoundingBox().Intersection(brep->BoundingBox()))
+       return false;
+
+    if (tface->m_outerloop.Count() == 0) {
+       bu_log("IsFaceInsideBrep(): the input TrimmedFace is not trimmed.\n");
+       return false;
+    }
+
+    ON_PolyCurve polycurve;
+    if (!IsLoopValid(tface->m_outerloop, ON_ZERO_TOLERANCE, &polycurve)) {
+       return false;
+    }
+
+    // Get a point inside the TrimmedFace, and then call IsPointInsideBrep().
+    // First, try the center of its 2D domain.
+    const int try_count = 10;
+    ON_BoundingBox bbox =  polycurve.BoundingBox();
+    bool found = false;
+    ON_2dPoint test_pt2d;
+    ON_RandomNumberGenerator rng;
+    for (int i = 0; i < try_count; i++) {
+       // Get a random point inside the outerloop's bounding box.
+       double x = rng.RandomDouble(bbox.m_min.x, bbox.m_max.x);
+       double y = rng.RandomDouble(bbox.m_min.y, bbox.m_max.y);
+       test_pt2d = ON_2dPoint(x, y);
+       if (IsPointInsideLoop(test_pt2d, tface->m_outerloop)
+           && !IsPointOnLoop(test_pt2d, tface->m_outerloop)) {
+           unsigned int j = 0;
+           // The test point should not be inside an innerloop
+           for (j = 0; j < tface->m_innerloop.size(); j++) {
+               if (IsPointInsideLoop(test_pt2d, tface->m_innerloop[j])
+                   || IsPointOnLoop(test_pt2d, tface->m_innerloop[j]))
+                   break;
+           }
+           if (j == tface->m_innerloop.size()) {
+               // We find a valid test point
+               found = true;
+               break;
+           }
+       }
+    }
+
+    if (!found) {
+       bu_log("Cannot find a point inside this trimmed face. Aborted.\n");
+       return false;
+    }
+
+    ON_3dPoint test_pt3d = tface->m_face->PointAt(test_pt2d.x, test_pt2d.y);
+    if (DEBUG_BREP_BOOLEAN)
+       bu_log("valid test point: (%g, %g, %g)\n", test_pt3d.x, test_pt3d.y, 
test_pt3d.z);
+    return IsPointInsideBrep(test_pt3d, brep, surf_tree);
+}
+
+
 int
-ON_Boolean(ON_Brep* brepO, const ON_Brep* brepA, const ON_Brep* brepB, int 
UNUSED(operation))
+ON_Boolean(ON_Brep* brepO, const ON_Brep* brepA, const ON_Brep* brepB, op_type 
operation)
 {
     int facecount1 = brepA->m_F.Count();
     int facecount2 = brepB->m_F.Count();
@@ -1450,31 +1512,53 @@
     }
 #endif // #if USE_CONNECTIVITY_GRAPH
 
+    ON_SimpleArray<Subsurface*> surf_treeA, surf_treeB;
+    for (int i = 0; i < facecount1; i++)
+       surf_treeA.Append(NULL);
+    for (int i = 0; i < facecount2; i++)
+       surf_treeB.Append(NULL);
+
     for (int i = 0; i < trimmedfaces.Count(); i++) {
        const ON_SimpleArray<TrimmedFace*>& splitted = trimmedfaces[i];
        const ON_Surface* surf = splitted.Count() ? 
splitted[0]->m_face->SurfaceOf() : NULL;
-       /* TODO: Perform inside-outside test to decide whether the trimmed face
-        * should be used in the final b-rep structure or not.
+       /* Perform inside-outside test to decide whether the trimmed face should
+        * be used in the final b-rep structure or not.
         * Different operations should be dealt with accordingly.
-        * Another solution is to use connectivity graphs which represents the
-        * topological structure of the b-rep. This can reduce time-consuming
-        * inside-outside tests.
-        * Here we just use all of these trimmed faces.
+        * Use connectivity graphs (optional) which represents the topological
+        * structure of the b-rep. This can reduce time-consuming inside-outside
+        * tests.
         */
+       const ON_Brep* another_brep = i >= facecount1 ? brepA : brepB;
+       ON_SimpleArray<Subsurface*>& surf_tree = i >= facecount1 ? surf_treeA : 
surf_treeB;
        for (int j = 0; j < splitted.Count(); j++) {
-           // Add the surfaces, faces, loops, trims, vertices, edges, etc.
-           // to the brep structure.
-           ON_Surface *new_surf = surf->Duplicate();
-           int surfindex = brepO->AddSurface(new_surf);
-           ON_BrepFace& new_face = brepO->NewFace(surfindex);
+           bool belong_to_final = false;
+           if (IsFaceInsideBrep(splitted[j], another_brep, surf_tree)) {
+               if (DEBUG_BREP_BOOLEAN)
+                   bu_log("The trimmed face is inside the other brep.\n");
+               if (operation == BOOLEAN_INTERSECT || (operation == 
BOOLEAN_DIFF && i >= facecount1))
+                   belong_to_final = true;
+           } else {
+               if (DEBUG_BREP_BOOLEAN)
+                   bu_log("The trimmed face is not inside the other brep.\n");
+               if (operation == BOOLEAN_UNION || (operation == BOOLEAN_DIFF && 
i < facecount1))
+                   belong_to_final = true;
+           }
 
-           add_elements(brepO, new_face, splitted[j]->m_outerloop, 
ON_BrepLoop::outer);
-           // ON_BrepLoop &loop = brepO->m_L[brepO->m_L.Count() - 1];
-           for (unsigned int k = 0; k < splitted[j]->m_innerloop.size(); k++)
-               add_elements(brepO, new_face, splitted[j]->m_innerloop[k], 
ON_BrepLoop::inner);
+           if (belong_to_final) {
+               // Add the surfaces, faces, loops, trims, vertices, edges, etc.
+               // to the brep structure.
+               ON_Surface *new_surf = surf->Duplicate();
+               int surfindex = brepO->AddSurface(new_surf);
+               ON_BrepFace& new_face = brepO->NewFace(surfindex);
 
-           brepO->SetTrimIsoFlags(new_face);
-           brepO->FlipFace(new_face);
+               add_elements(brepO, new_face, splitted[j]->m_outerloop, 
ON_BrepLoop::outer);
+               // ON_BrepLoop &loop = brepO->m_L[brepO->m_L.Count() - 1];
+               for (unsigned int k = 0; k < splitted[j]->m_innerloop.size(); 
k++)
+                   add_elements(brepO, new_face, splitted[j]->m_innerloop[k], 
ON_BrepLoop::inner);
+
+               brepO->SetTrimIsoFlags(new_face);
+               brepO->FlipFace(new_face);
+           }
        }
     }
 

Modified: brlcad/branches/nurbs/src/libbrep/intersect.cpp
===================================================================
--- brlcad/branches/nurbs/src/libbrep/intersect.cpp     2013-08-26 09:44:53 UTC 
(rev 57135)
+++ brlcad/branches/nurbs/src/libbrep/intersect.cpp     2013-08-26 09:55:22 UTC 
(rev 57136)
@@ -254,7 +254,7 @@
 
 
 ON_Curve*
-sub_curve(ON_Curve* in, double a, double b)
+sub_curve(const ON_Curve* in, double a, double b)
 {
     ON_Interval dom = in->Domain();
     ON_Interval sub(a, b);

Modified: brlcad/branches/nurbs/src/libged/CMakeLists.txt
===================================================================
--- brlcad/branches/nurbs/src/libged/CMakeLists.txt     2013-08-26 09:44:53 UTC 
(rev 57135)
+++ brlcad/branches/nurbs/src/libged/CMakeLists.txt     2013-08-26 09:55:22 UTC 
(rev 57136)
@@ -189,6 +189,7 @@
   pscale.c
   pset.c
   ptranslate.c
+  pull.c
   push.c
   put.c
   put_comb.c

Modified: brlcad/branches/nurbs/src/libged/brep.c
===================================================================
--- brlcad/branches/nurbs/src/libged/brep.c     2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/src/libged/brep.c     2013-08-26 09:55:22 UTC (rev 
57136)
@@ -51,7 +51,7 @@
 RT_EXPORT extern int brep_intersect_curve_curve(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j);
 RT_EXPORT extern int brep_intersect_curve_surface(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j);
 RT_EXPORT extern int brep_intersect_surface_surface(struct rt_db_internal 
*intern1, struct rt_db_internal *intern2, int i, int j, struct bn_vlblock *vbp);
-RT_EXPORT extern int rt_brep_boolean(struct rt_db_internal *out, const struct 
rt_db_internal *ip1, const struct rt_db_internal *ip2, const int operation);
+RT_EXPORT extern int rt_brep_boolean(struct rt_db_internal *out, const struct 
rt_db_internal *ip1, const struct rt_db_internal *ip2, const char* operation);
 
 
 int
@@ -59,7 +59,7 @@
 {
     struct bn_vlblock*vbp;
     const char *solid_name;
-    static const char *usage = "brep obj [command|brepname|suffix] ";
+    static const char *usage = "brep <obj> [command|brepname|suffix] ";
     struct directory *ndp;
     struct rt_db_internal intern;
     struct rt_brep_internal* bi;
@@ -68,7 +68,7 @@
     char commtag[64];
     char namebuf[64];
     int i, j, real_flag, valid_command;
-    const char *commands[] = {"info", "plot", "translate"};
+    const char *commands[] = {"info", "plot", "translate", "intersect", "u", 
"i", "-"};
     int num_commands = (int)(sizeof(commands) / sizeof(const char *));
 
     GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
@@ -80,7 +80,7 @@
 
     /* must be wanting help */
     if (argc < 2) {
-       bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
+       bu_vls_printf(gedp->ged_result_str, "Usage: %s\n\t%s\n", argv[0], 
usage);
        bu_vls_printf(gedp->ged_result_str, "commands:\n");
        bu_vls_printf(gedp->ged_result_str, "\tinfo - return count information 
for specific BREP\n");
        bu_vls_printf(gedp->ged_result_str, "\tinfo S [index] - return 
information for specific BREP 'surface'\n");
@@ -88,10 +88,11 @@
        bu_vls_printf(gedp->ged_result_str, "\tplot - plot entire BREP\n");
        bu_vls_printf(gedp->ged_result_str, "\tplot S [index] - plot specific 
BREP 'surface'\n");
        bu_vls_printf(gedp->ged_result_str, "\tplot F [index] - plot specific 
BREP 'face'\n");
-       bu_vls_printf(gedp->ged_result_str, "\tintersect obj2 i j 
[PP|PC|PS|CC|CS|SS] - BREP intersections\n");
+       bu_vls_printf(gedp->ged_result_str, "\ttranslate SCV index i j dx dy dz 
- translate a surface control vertex\n");
+       bu_vls_printf(gedp->ged_result_str, "\tintersect <obj2> <i> <j> 
[PP|PC|PS|CC|CS|SS] - BREP intersections\n");
+       bu_vls_printf(gedp->ged_result_str, "\tu|i|- <obj2> <output> - BREP 
boolean evaluations\n");
        bu_vls_printf(gedp->ged_result_str, "\t[brepname] - convert the 
non-BREP object to BREP form\n");
        bu_vls_printf(gedp->ged_result_str, "\t[suffix] - convert non-BREP comb 
to unevaluated BREP form\n");
-       bu_vls_printf(gedp->ged_result_str, "\ttranslate SCV index i j dx dy dz 
- translate a surface control vertex\n");
        return GED_HELP;
     }
 
@@ -176,13 +177,17 @@
        return GED_OK;
     }
 
-    if (BU_STR_EQUAL(argv[2], "u")) {
-       /* test booleans on brep, just union here */
+    if (BU_STR_EQUAL(argv[2], "u") || BU_STR_EQUAL(argv[2], "i") || 
BU_STR_EQUAL(argv[2], "-")) {
+       /* test booleans on brep.
+        * u: union, i: intersect, -: diff
+        */
        struct rt_db_internal intern2, intern_res;
        struct rt_brep_internal *bip;
 
-       if (argc != 5)
+       if (argc != 5) {
+           bu_vls_printf(gedp->ged_result_str, "Error: There should be exactly 
5 params.\n");
            return GED_ERROR;
+       }
 
        /* get the other solid */
        if ((ndp = db_lookup(gedp->ged_wdbp->dbip,  argv[3], LOOKUP_NOISY)) == 
RT_DIR_NULL) {
@@ -200,7 +205,7 @@
 
        GED_DB_GET_INTERNAL(gedp, &intern2, ndp, bn_mat_identity, 
&rt_uniresource, GED_ERROR);
 
-       rt_brep_boolean(&intern_res, &intern, &intern2, 0);
+       rt_brep_boolean(&intern_res, &intern, &intern2, argv[2]);
        bip = (struct rt_brep_internal*)intern_res.idb_ptr;
        mk_brep(gedp->ged_wdbp, argv[4], bip->brep);
        rt_db_free_internal(&intern);

Modified: brlcad/branches/nurbs/src/libged/gqa.c
===================================================================
--- brlcad/branches/nurbs/src/libged/gqa.c      2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/src/libged/gqa.c      2013-08-26 09:55:22 UTC (rev 
57136)
@@ -73,6 +73,7 @@
  * that spaces got inserted incorrectly.
  */
 #define COMMA ','
+#define STRCOMMA ","
 
 static int analysis_flags;
 static int multiple_analyses;
@@ -690,10 +691,15 @@
                    units_ap = units_name;
 
                    /* acquire unit names */
-                   *units_ap = strtok(ptr, ", ");
                    for (i = 0; i < 3 && ptr; i++) {
                        int found_unit;
 
+                       if (i == 0) {
+                           *units_ap = strtok(ptr, STRCOMMA);
+                       } else {
+                           *units_ap = strtok(NULL, STRCOMMA);
+                       }
+
                        /* got something? */
                        if (*units_ap == NULL)
                            break;
@@ -714,7 +720,6 @@
                        }
 
                        ++units_ap;
-                       *units_ap = strtok(NULL, ", ");
                    }
 
                    bu_vls_printf(_ged_current_gedp->ged_result_str, "Units: ");

Copied: brlcad/branches/nurbs/src/libged/pull.c (from rev 57135, 
brlcad/trunk/src/libged/pull.c)
===================================================================
--- brlcad/branches/nurbs/src/libged/pull.c                             (rev 0)
+++ brlcad/branches/nurbs/src/libged/pull.c     2013-08-26 09:55:22 UTC (rev 
57136)
@@ -0,0 +1,71 @@
+/*                         P U L L . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file libged/push.c
+ * The pull command.
+ * This is the Pull command which pulls the matrix transformations of an object
+ * up the CSG Tree.
+ */
+
+
+#include "common.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include "bio.h"
+
+#include "bu.h"
+#include "bn.h"
+#include "cmd.h"
+
+#include "./ged_private.h"
+
+
+int
+ged_pull(struct ged *gedp, int argc, const char *argv[])
+{
+    static const char *usage = "object";
+
+    GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
+    GED_CHECK_READ_ONLY(gedp, GED_ERROR);
+    GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
+
+    /* initialize result */
+    bu_vls_trunc(gedp->ged_result_str, 0);
+
+    /* must be wanting help */
+    if (argc == 1) {
+       bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
+       return GED_HELP;
+    }
+
+    return GED_OK;
+}
+
+
+/** @} */
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */

Modified: brlcad/branches/nurbs/src/libicv/bw.c
===================================================================
--- brlcad/branches/nurbs/src/libicv/bw.c       2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/src/libicv/bw.c       2013-08-26 09:55:22 UTC (rev 
57136)
@@ -51,7 +51,7 @@
     size_t ret, size;
 
     if (bif->color_space == ICV_COLOR_SPACE_RGB) {
-       icv_rgb2gray(bif, 0, 0, 0, 0, 0);
+       icv_rgb2gray_ntsc(bif);
     } else if (bif->color_space != ICV_COLOR_SPACE_GRAY) {
        bu_log("bw_write : Color Space conflict");
        return -1;

Modified: brlcad/branches/nurbs/src/libicv/color_space.c
===================================================================
--- brlcad/branches/nurbs/src/libicv/color_space.c      2013-08-26 09:44:53 UTC 
(rev 57135)
+++ brlcad/branches/nurbs/src/libicv/color_space.c      2013-08-26 09:55:22 UTC 
(rev 57136)
@@ -1,4 +1,4 @@
-/*                   C O L O R _ S P A C E . C
+/*         x
  * BRL-CAD
  *
  * Copyright (c) 2013 United States Government as represented by
@@ -72,7 +72,7 @@
 }
 
 int
-icv_rgb2gray(icv_image_t *img, ICV_DEPTH_METHOD method, ICV_COLOR color, 
double rweight, double gweight, double bweight)
+icv_rgb2gray(icv_image_t *img, ICV_COLOR color, double rweight, double 
gweight, double bweight)
 {
     double *out_data, *in_data;
     size_t in, out, size;
@@ -95,77 +95,54 @@
        return -1;
     }
 
+    switch(color) {
+       case ICV_COLOR_R :
+           red = 1;
+           bweight = 0;
+           gweight = 0;
+           multiple_colors = 0;
+           break;
+       case ICV_COLOR_G :
+           green = 1;
+           rweight = 0;
+           bweight = 0;
+           multiple_colors = 0;
+           break;
+       case ICV_COLOR_B :
+           blue = 1;
+           rweight = 0;
+           gweight = 0;
+           multiple_colors = 0;
+           break;
+       case ICV_COLOR_RG :
+           red = 1;
+           green = 1;
+           bweight = 0;
+           multiple_colors = 1;
+           break;
+       case ICV_COLOR_RB :
+           blue = 1;
+           red = 1;
+           gweight = 0;
+           multiple_colors = 1;
+           break;
+       case ICV_COLOR_BG :
+           blue = 1;
+           green = 1;
+           rweight = 0;
+           multiple_colors = 1;
+           break;
+       case ICV_COLOR_RGB :
+           red = 1;
+           green = 1;
+           blue = 1;
+           multiple_colors = 1;
+           break;
+       default :
+           bu_exit(1,"icv_depth_3to1: Wrong Arguments for Color");
+           break;
+    }
 
-    if (method == ICV_PIX_NTSC) {
-       /* NTSC weights */
-       rweight = 0.30;
-       gweight = 0.59;
-       bweight = 0.11;
-       red = green = blue = 1;
-       multiple_colors = 1;
-    } else if (method == ICV_PIX_CRT) {
-       /* CRT weights */
-       rweight = 0.26;
-       gweight = 0.66;
-       bweight = 0.08;
-       red = green = blue = 1;
-       multiple_colors = 1;
-    } else if (method == ICV_PIX_SET_EQUAL) {
-       /* CRT weights */
-       rweight = 0.34;
-       gweight = 0.33;
-       bweight = 0.33;
-       red = green = blue = 1;
-       multiple_colors = 1;
-    } else if (method == ICV_PIX_SELECT_CHANNEL) {
-       switch(color) {
-           case ICV_COLOR_R :
-               red = 1;
-               bweight = 0;
-               gweight = 0;
-               multiple_colors = 0;
-               break;
-           case ICV_COLOR_G :
-               green = 1;
-               rweight = 0;
-               bweight = 0;
-               multiple_colors = 0;
-               break;
-           case ICV_COLOR_B :
-               blue = 1;
-               rweight = 0;
-               gweight = 0;
-               multiple_colors = 0;
-               break;
-           case ICV_COLOR_RG :
-               red = 1;
-               green = 1;
-               bweight = 0;
-               multiple_colors = 1;
-               break;
-           case ICV_COLOR_RB :
-               blue = 1;
-               red = 1;
-               gweight = 0;
-               multiple_colors = 1;
-               break;
-           case ICV_COLOR_BG :
-               blue = 1;
-               green = 1;
-               rweight = 0;
-               multiple_colors = 1;
-               break;
-           case ICV_COLOR_RGB :
-               red = 1;
-               green = 1;
-               blue = 1;
-               multiple_colors = 1;
-               break;
-           default :
-               bu_exit(1,"icv_depth_3to1: Wrong Arguments for Color");
-               break;
-       }
-    }
     /* Gets number of planes according to the status of arguments
        check */
     num_color_planes = red + green + blue;

Modified: brlcad/branches/nurbs/src/librt/comb/comb.c
===================================================================
--- brlcad/branches/nurbs/src/librt/comb/comb.c 2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/src/librt/comb/comb.c 2013-08-26 09:55:22 UTC (rev 
57136)
@@ -742,18 +742,7 @@
        } else {
            bu_log("unable to parse 'rgb' attribute '%s'\n", ap);
        }
-    } else {
-       if ((ap = bu_avs_get(&ip->idb_avs, "color")) != NULL) {
-           int ibuf[3];
-           if (sscanf(ap, "%d/%d/%d", ibuf, ibuf+1, ibuf+2) == 3) {
-               VMOVE(comb->rgb, ibuf);
-               comb->rgb_valid = 1;
-           } else {
-               bu_log("unable to parse 'color' attribute '%s'\n", ap);
-           }
-       }
     }
-
     if ((ap = bu_avs_get(&ip->idb_avs, db5_standard_attribute(ATTR_INHERIT))) 
!= NULL) {
        comb->inherit = atoi(ap);
     }

Modified: brlcad/branches/nurbs/src/librt/db5_types.c
===================================================================
--- brlcad/branches/nurbs/src/librt/db5_types.c 2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/src/librt/db5_types.c 2013-08-26 09:55:22 UTC (rev 
57136)
@@ -289,7 +289,7 @@
        case ATTR_LOS:
            return "los";
        case ATTR_COLOR:
-           return "rgb";
+           return "color";
        case ATTR_SHADER:
            return "shader";
        case ATTR_INHERIT:

Modified: brlcad/branches/nurbs/src/librt/primitives/brep/brep.cpp
===================================================================
--- brlcad/branches/nurbs/src/librt/primitives/brep/brep.cpp    2013-08-26 
09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/src/librt/primitives/brep/brep.cpp    2013-08-26 
09:55:22 UTC (rev 57136)
@@ -91,7 +91,7 @@
     int rt_brep_tclget(Tcl_Interp *interp, const struct rt_db_internal 
*intern, const char *attr);
     int rt_brep_tcladjust(Tcl_Interp *interp, struct rt_db_internal *intern, 
int argc, const char **argv);
     int rt_brep_params(struct pc_pc_set *, const struct rt_db_internal *ip);
-    RT_EXPORT extern int rt_brep_boolean(struct rt_db_internal *out, const 
struct rt_db_internal *ip1, const struct rt_db_internal *ip2, const int 
operation);
+    RT_EXPORT extern int rt_brep_boolean(struct rt_db_internal *out, const 
struct rt_db_internal *ip1, const struct rt_db_internal *ip2, const char* 
operation);
 #ifdef __cplusplus
 }
 #endif
@@ -4065,7 +4065,7 @@
 
 
 int
-rt_brep_boolean(struct rt_db_internal *out, const struct rt_db_internal *ip1, 
const struct rt_db_internal *ip2, const int operation)
+rt_brep_boolean(struct rt_db_internal *out, const struct rt_db_internal *ip1, 
const struct rt_db_internal *ip2, const char* operation)
 {
     RT_CK_DB_INTERNAL(ip1);
     RT_CK_DB_INTERNAL(ip2);
@@ -4081,7 +4081,17 @@
     brep_out = ON_Brep::New();
 
     int ret;
-    if ((ret = ON_Boolean(brep_out, brep1, brep2, operation)) < 0)
+    op_type operation_type;
+    if (BU_STR_EQUAL(operation, "u"))
+       operation_type = BOOLEAN_UNION;
+    else if (BU_STR_EQUAL(operation, "i"))
+       operation_type = BOOLEAN_INTERSECT;
+    else if (BU_STR_EQUAL(operation, "-"))
+       operation_type = BOOLEAN_DIFF;
+    else
+       return -1;
+
+    if ((ret = ON_Boolean(brep_out, brep1, brep2, operation_type)) < 0)
        return ret;
 
     // make the final rt_db_internal

Modified: brlcad/branches/nurbs/src/mged/setup.c
===================================================================
--- brlcad/branches/nurbs/src/mged/setup.c      2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/src/mged/setup.c      2013-08-26 09:55:22 UTC (rev 
57136)
@@ -262,6 +262,7 @@
     {"press", f_press, GED_FUNC_PTR_NULL},
     {"preview", cmd_ged_dm_wrapper, ged_preview},
     {"ps", f_ps, GED_FUNC_PTR_NULL},
+    {"pull", cmd_ged_plain_wrapper, ged_pull},
     {"push", cmd_ged_plain_wrapper, ged_push},
     {"put", cmd_ged_plain_wrapper, ged_put},
     {"put_comb", cmd_ged_plain_wrapper, ged_put_comb},

Modified: 
brlcad/branches/nurbs/src/other/stepcode/src/express/test/print_attrs.c
===================================================================
--- brlcad/branches/nurbs/src/other/stepcode/src/express/test/print_attrs.c     
2013-08-26 09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/src/other/stepcode/src/express/test/print_attrs.c     
2013-08-26 09:55:22 UTC (rev 57136)
@@ -13,7 +13,9 @@
 #endif
 #include <stdio.h>
 #include <errno.h>
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
 #include "express/express.h"
 #include <express/scope.h>
 #include <express/variable.h>

Modified: 
brlcad/branches/nurbs/src/other/stepcode/src/express/test/print_schemas.c
===================================================================
--- brlcad/branches/nurbs/src/other/stepcode/src/express/test/print_schemas.c   
2013-08-26 09:44:53 UTC (rev 57135)
+++ brlcad/branches/nurbs/src/other/stepcode/src/express/test/print_schemas.c   
2013-08-26 09:55:22 UTC (rev 57136)
@@ -9,7 +9,9 @@
 #endif
 #include <stdio.h>
 #include <errno.h>
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
 #include "express/express.h"
 
 void

Modified: brlcad/branches/nurbs/src/util/CMakeLists.txt
===================================================================
--- brlcad/branches/nurbs/src/util/CMakeLists.txt       2013-08-26 09:44:53 UTC 
(rev 57135)
+++ brlcad/branches/nurbs/src/util/CMakeLists.txt       2013-08-26 09:55:22 UTC 
(rev 57136)
@@ -94,7 +94,7 @@
 BRLCAD_ADDEXEC(random random.c "libbn;libbu")
 BRLCAD_ADDEXEC(orle-pix orle-pix.c "libfb;liborle;libbu")
 BRLCAD_ADDEXEC(pix-alias pix-alias.c libbu)
-BRLCAD_ADDEXEC(pix-bw pix-bw.c libbu)
+BRLCAD_ADDEXEC(pix-bw pix-bw.c "libbu;libicv")
 BRLCAD_ADDEXEC(pix-bw3 pix-bw3.c libbu)
 BRLCAD_ADDEXEC(pix-orle pix-orle.c "libfb;liborle;libbu")
 BRLCAD_ADDEXEC(pix-png pix-png.c "libfb;libbu;${PNG_LIBRARY}")

Modified: brlcad/branches/nurbs/src/util/dsp_add.c
===================================================================
--- brlcad/branches/nurbs/src/util/dsp_add.c    2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/src/util/dsp_add.c    2013-08-26 09:55:22 UTC (rev 
57136)
@@ -50,7 +50,7 @@
  *
  * See the wiki for a tutorial on using dsp's.
  *
- * see_also: dsp(5) asc2dsp(1) cv(1)
+ * see_also: dsp(5) ; asc2dsp(1) ; cv(1)
  *
  * opt: -h brief help
  *

Modified: brlcad/branches/nurbs/src/util/fix_polysolids.c
===================================================================
--- brlcad/branches/nurbs/src/util/fix_polysolids.c     2013-08-26 09:44:53 UTC 
(rev 57135)
+++ brlcad/branches/nurbs/src/util/fix_polysolids.c     2013-08-26 09:55:22 UTC 
(rev 57136)
@@ -35,13 +35,16 @@
  *
  * opt: -v turn on verbose mode
  *
- * opt: -x [librt debug flag] turn on librt debugging
+ * opt: -x <librt debug flag> turn on librt debugging
  *          (option may used more than once)
  *
- * opt: -X [nmg debug flag] turn on nmg debugging
+ * opt: -X <nmg debug flag> turn on nmg debugging
  *         (option may used more than once)
  *
+ * opt: -h brief help
  *
+ * opt: -? brief help
+ *
  */
 
 #include "common.h"

Modified: brlcad/branches/nurbs/src/util/pix-bw.c
===================================================================
--- brlcad/branches/nurbs/src/util/pix-bw.c     2013-08-26 09:44:53 UTC (rev 
57135)
+++ brlcad/branches/nurbs/src/util/pix-bw.c     2013-08-26 09:55:22 UTC (rev 
57136)
@@ -35,6 +35,7 @@
 #include <math.h>
 #include <string.h>
 #include "bio.h"
+#include "icv.h"
 
 #include "bu.h"
 #include "vmath.h"
@@ -49,134 +50,127 @@
 double rweight = 0.0;
 double gweight = 0.0;
 double bweight = 0.0;
+ICV_COLOR color;
 
+int inx=512, iny=512;
+char *out_file = NULL;
+char *in_file = NULL;
+
 static const char usage[] = "\
-Usage: pix-bw [-ntsc -crt -R[#] -G[#] -B[#]] [in.pix] > out.bw\n";
+pix-bw [-h] [squaresize] [-w width] [-n height]  \n\
+       [ [-N] [-C] [-R red_weight] [-G green_weight] [-B blue_weight] ] \n\
+       [-o out_file.bw] [file.bw] > [out_file.bw] \n";
 
+double multiplier = 0.5;
+
 int
-main(int argc, char **argv)
+get_args(int argc, char **argv)
 {
-    size_t in, out, num;
-    int multiple_colors, num_color_planes;
-    int clip_high, clip_low;
-    double value;
-    FILE *finp, *foutp;
-    size_t ret;
+    int c;
 
-    while (argc > 1 && argv[1][0] == '-') {
-       if (BU_STR_EQUAL(argv[1], "-ntsc")) {
-           /* NTSC weights */
-           rweight = 0.30;
-           gweight = 0.59;
-           bweight = 0.11;
-           red = green = blue = 1;
-       } else if (BU_STR_EQUAL(argv[1], "-crt")) {
-           /* CRT weights */
-           rweight = 0.26;
-           gweight = 0.66;
-           bweight = 0.08;
-           red = green = blue = 1;
-       } else {
-           switch (argv[1][1]) {
-               case 'R':
-                   red++;
-                   if (argv[1][2] != '\0')
-                       rweight = atof(&argv[1][2]);
-                   break;
-               case 'G':
-                   green++;
-                   if (argv[1][2] != '\0')
-                       gweight = atof(&argv[1][2]);
-                   break;
-               case 'B':
-                   blue++;
-                   if (argv[1][2] != '\0')
-                       bweight = atof(&argv[1][2]);
-                   break;
-               default:
-                   fprintf(stderr, "pix-bw: bad flag \"%s\"\n", argv[1]);
-                   bu_exit(1, "%s", usage);
-           }
+    while ((c = bu_getopt(argc, argv, "R:G:B:s:w:n:o:h?NC")) != -1) {
+       switch (c) {
+           case 'N' :
+               rweight = 0.30;
+               gweight = 0.59;
+               bweight = 0.11;
+               red = green = blue = 1;
+               color = ICV_COLOR_RGB;
+               break;
+           case 'C' :
+               rweight = 0.26;
+               gweight = 0.66;
+               bweight = 0.08;
+               red = green = blue = 1;
+               color = ICV_COLOR_RGB;
+               break;
+           case 'R' :
+               red++;
+               rweight = atof(bu_optarg);
+               break;
+           case 'G' :
+               green++;
+               gweight = atof(bu_optarg);
+               break;
+           case 'B' :
+               blue++;
+               bweight = atof(bu_optarg);
+               break;
+           case 's':
+               inx = iny = atoi(bu_optarg);
+               break;
+           case 'w':
+               inx = atoi(bu_optarg);
+               break;
+           case 'n':
+               iny = atoi(bu_optarg);
+               break;
+           case 'o':
+               out_file = bu_optarg;
+               break;
+           case 'h':
+           default:            /* '?' */
+               return 0;
        }
-       argc--;
-       argv++;
     }
 
-    if (argc > 1) {
-       if ((finp = fopen(argv[1], "rb")) == NULL) {
-           bu_exit(2, "pix-bw: can't open \"%s\"\n", argv[1]);
+    if (bu_optind >= argc) {
+       if (isatty(fileno(stdin))) {
+           return 0;
        }
-    } else
-       finp = stdin;
+    } else {
+       in_file = argv[bu_optind];
+       bu_optind++;
+       return 1;
+    }
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-    setmode(fileno(stdin), O_BINARY);
-    setmode(fileno(stdout), O_BINARY);
-    setmode(fileno(stderr), O_BINARY);
-#endif
 
-    foutp = stdout;
+    if (!isatty(fileno(stdout)) && out_file!=NULL) {
+       return 0;
+    }
 
-    if (isatty(fileno(finp)) || isatty(fileno(foutp))) {
-       bu_exit(2, "%s", usage);
+    if (argc > ++bu_optind) {
+       bu_log("pixfade: excess argument(s) ignored\n");
     }
 
-    /* Hack for multiple color planes */
-    if (red + green + blue > 1 || !ZERO(rweight) || !ZERO(gweight) || 
!ZERO(bweight))
-       multiple_colors = 1;
-    else
-       multiple_colors = 0;
+    return 1;          /* OK */
+}
 
-    num_color_planes = red + green + blue;
-    if (red != 0 && ZERO(rweight))
-       rweight = 1.0 / (double)num_color_planes;
-    if (green != 0 && ZERO(gweight))
-       gweight = 1.0 / (double)num_color_planes;
-    if (blue != 0 && ZERO(bweight))
-       bweight = 1.0 / (double)num_color_planes;
+int
+main(int argc, char **argv)
+{
 
-    clip_high = clip_low = 0;
-    while ((num = fread(ibuf, sizeof(char), 3*1024, finp)) > 0) {
-       /*
-        * The loops are repeated for efficiency...
-        */
-       if (multiple_colors) {
-           for (in = out = 0; out < num/3; out++, in += 3) {
-               value = rweight*ibuf[in] + gweight*ibuf[in+1] + 
bweight*ibuf[in+2];
-               if (value > 255.0) {
-                   obuf[out] = 255;
-                   clip_high++;
-               } else if (value < 0.0) {
-                   obuf[out] = 0;
-                   clip_low++;
-               } else
-                   obuf[out] = value;
-           }
-       } else if (red) {
-           for (in = out = 0; out < num/3; out++, in += 3)
-               obuf[out] = ibuf[in];
-       } else if (green) {
-           for (in = out = 0; out < num/3; out++, in += 3)
-               obuf[out] = ibuf[in+1];
-       } else if (blue) {
-           for (in = out = 0; out < num/3; out++, in += 3)
-               obuf[out] = ibuf[in+2];
-       } else {
-           /* uniform weight */
-           for (in = out = 0; out < num/3; out++, in += 3)
-               obuf[out] = ((int)ibuf[in] + (int)ibuf[in+1] +
-                            (int)ibuf[in+2]) / 3;
-       }
-       ret = fwrite(obuf, sizeof(char), num/3, foutp);
-       if (ret != (size_t)num/3)
-           perror("fwrite");
+    icv_image_t *img;
+    if (!get_args(argc, argv)) {
+       bu_log("%s", usage);
+       return 1;
     }
 
-    if (clip_high != 0 || clip_low != 0) {
-       fprintf(stderr, "pix-bw: clipped %d high, %d, low\n",
-               clip_high, clip_low);
-    }
+    img = icv_read(in_file, ICV_IMAGE_PIX, inx, iny);
 
+    if (img == NULL)
+       return 1;
+
+    if(red && green && blue)
+       color = ICV_COLOR_RGB;
+    else if (blue && green)
+       color = ICV_COLOR_BG;
+    else if (red && blue)
+       color = ICV_COLOR_RB;
+    else if (red && green)
+       color = ICV_COLOR_RG;
+    else if (red)
+       color = ICV_COLOR_R;
+    else if (blue)
+       color = ICV_COLOR_B;
+    else if (green)
+       color = ICV_COLOR_G;
+    else bu_exit(1, "%s",usage);
+
+    icv_rgb2gray(img, color, rweight, gweight, bweight);
+
+    icv_write(img, out_file, ICV_IMAGE_BW);
+
     return 0;
 }
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to