4.1.4. Examples

The following examples (located in $OIVHOME/src/HardCopy/Mentor) show you how to use each of the four possible output types.

PostScript Output

Example 4.2. Generation of PostScript output

 // tutorial02.cxx
#include <Inventor/SoDB.h>
#include <Inventor/nodekits/SoNodeKit.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSphere.h>
#include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <HardCopy/SoVectorizePSAction.h>

  int
    main(int, char **argv)
    {
    // Initialize HardCopy
      SoHardCSoHardCopy::init();

    // Create the root of the scene graph
      SoSeparator *root = new SoSeparator;
      root->ref();

    // Create the Camera node
      SoPerspectiveCamera *myCam = new SoPerspectiveCamera;
      root->addChild(myCam);

    // Use wireframe draw style
      SoDrawStyle *drawStyle = new SoDrawStyle;
      drawStyle->style = SoDrawStyle::LINES;
      root->addChild(drawStyle);

    // Create a simple sphere
      SoSphere *shape = new SoSphere;
      root->addChild(shape);

      myCam->viewAll(root, SbViewportRegion(1000, 1000));

    // Create and apply the PostScript action.
      SoVectorizePSAction vect;

      vect.setStartPosition(0,0);
      vect.setDrawingDimensions(80, 80);
      vect.setOrientation(SoVectorizeAction::PORTRAIT);
      vect.setBorder(1.);
      vect.setColorTranslationMethod(SoVectorizeAction::REVERSE_ONLY_BLACK_AND_WHITE);
      vect.setLineEndStyle(SoVectorizeAction::BUTT_END);
      vect.setLineJoinsStyle(SoVectorizeAction::ROUNDED_JOIN);
      vect.setMiterLimit(2.);
      vect.setNominalWidth(0.05f);

      vect.getOutput()->openFile("HardCopyOutput.ps");
      vect.apply(root);
      vect.getOutput()->closeFile();

      return 0;
    }


HPGL Output

Example 4.3. Generation of HPGL output

// tutorial03.cxx
#include <Inventor/SoDB.h>
#include <Inventor/nodekits/SoNodeKit.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSphere.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <HardCopy/SoVectorizeHPGLAction.h>

  int
    main(int, char **argv)
    {
    // Initialize HardCopy
      SoHardCopy::init();

    // Create the root of the scene graph
      SoSeparator *root = new SoSeparator;
      root->ref();

    // Create the Camera node
      SoPerspectiveCamera *myCam = new SoPerspectiveCamera;
      root->addChild(myCam);

    // Use wireframe draw style
      SoDrawStyle *drawStyle = new SoDrawStyle;
      drawStyle->style = SoDrawStyle::LINES;
      root->addChild(drawStyle);

    // Create a simple sphere
      SoSphere *shape = new SoSphere;
      root->addChild(shape);

      myCam->viewAll(root, SbViewportRegion(1000, 1000));

    // Create and apply the HPGL action.
      SoVectorizeHPGLAction vect;

      vect.setStartPosition(10,20);
      vect.setDrawingDimensions(130,100);
      vect.setOrientation(SoVectorizeAction::PORTRAIT);
    // Black and white.
      vect.setPenDescription(2);
    // width = 0.35mm.
      vect.setBorder(1.,SbVec3f(0., 0., 0.));
      vect.setBackgroundColor(TRUE, SbVec3f(1., 1., 1.));
      vect.setColorTranslationMethod(SoVectorizeAction::AS_IS);
      vect.setLineEndStyle(SoVectorizeAction::BUTT_END);
      vect.setLineJoinsStyle(SoVectorizeAction::ROUNDED_JOIN);
      vect.setMiterLimit(2.);

      vect.getOutput()->openFile("HardCopyOutput.hpgl");
      vect.apply(root);
      vect.getOutput()->closeFile();

      return 0;
    }


CGM Output

Example 4.4. Generation of CGM output

// tutorial04.cxx
#include <Inventor/SoDB.h>
#include <Inventor/nodekits/SoNodeKit.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSphere.h>
#include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <HardCopy/SoVectorizeCGMAction.h>

  int
    main(int, char **argv)
    {
    // Initialize HardCopy
      SoHardCopy::init();

    // Create the root of the scene graph
      SoSeparator *root = new SoSeparator;
      root->ref();

    // Create the Camera node
      SoPerspectiveCamera *myCam = new SoPerspectiveCamera;
      root->addChild(myCam);

    // Use wireframe draw style
      SoDrawStyle *drawStyle = new SoDrawStyle;
      drawStyle->style = SoDrawStyle::LINES;
      root->addChild(drawStyle);

    // Create a simple sphere
      SoSphere *shape = new SoSphere;
      root->addChild(shape);

      myCam->viewAll(root, SbViewportRegion(1000, 1000));

    // Create and apply the CGM action.
      SoVectorizeCGMAction vect;

      vect.setStartPosition(10,20);
      vect.setDrawingDimensions(130, 100);
      vect.setBorder(1.);
      vect.setBackgroundColor(TRUE);
    // Black and White are reversed !
      vect.setColorTranslationMethod(SoVectorizeAction::REVERSE_ONLY_BLACK_AND_WHITE);
    // Version 1, Clear Text and RGB.
      vect.getOutput()->setVersion(1);
      vect.getOutput()->setIndexed(FALSE);

      vect.getOutput()->openFile("HardCopyOutput.cgm");
      vect.apply(root);
      vect.getOutput()->closeFile();

      return 0;
    }


GDI Output

Available only with Microsoft Windows.

Example 4.5. Generation of GDI output

// tutorial05.cxx
#include <Inventor/SoDB.h>
#include <Inventor/nodekits/SoNodeKit.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSphere.h>
#include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#if defined(WIN32) || defined(__NUTC__)
# include <HardCopy/SoVectorizeGDIAction.h>
#endif

  int
    main(int, char **argv)
    {
    // Initialize HardCopy
      SoHardCopy::init();

    // Create the root of the scene graph
      SoSeparator *root = new SoSeparator;
      root->ref();

    // Create the Camera node
      SoPerspectiveCamera *myCam = new SoPerspectiveCamera;
      root->addChild(myCam);

    // Use wireframe draw style
      SoDrawStyle *drawStyle = new SoDrawStyle;
      drawStyle->style = SoDrawStyle::LINES;
      root->addChild(drawStyle);

    // Create a simple sphere
      SoSphere *shape = new SoSphere;
      root->addChild(shape);
      myCam->viewAll(root, SbViewportRegion(1000, 1000));

  #if defined(WIN32) || defined(__NUTC__)
    // Create and apply the GDI action.
      SoVectorizeGDIAction vect;

      vect.setStartPosition(10,20);
      vect.setDrawingDimensions(130, 100);
      vect.setBorder(1.0);
      vect.setBackgroundColor(TRUE);

    // Black and White are reversed !
      vect.setColorTranslationMethod(SoVectorizeAction::REVERSE_ONLY_BLACK_AND_WHITE);

      vect.getOutput()->openFile("HardCopyOutput.emf");
      vect.apply(root);
      vect.getOutput()->closeFile();
  #endif

      return 0;