Open Inventor Release 2025.1.1
 
Loading...
Searching...
No Matches
Examples

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

PostScript Output

Example : Generation of PostScript output

// tutorial02.cxx
#include <HardCopy/SoVectorizePSAction.h>
#include <Inventor/SoDB.h>
#include <Inventor/nodekits/SoNodeKit.h>
#include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSphere.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 : Generation of HPGL output

// tutorial03.cxx
#include <HardCopy/SoVectorizeHPGLAction.h>
#include <Inventor/SoDB.h>
#include <Inventor/nodekits/SoNodeKit.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSphere.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 : Generation of CGM output

// tutorial04.cxx
#include <HardCopy/SoVectorizeCGMAction.h>
#include <Inventor/SoDB.h>
#include <Inventor/nodekits/SoNodeKit.h>
#include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSphere.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 : Generation of GDI output

// tutorial05.cxx
#include <Inventor/SoDB.h>
#include <Inventor/nodekits/SoNodeKit.h>
#include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSphere.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;