hardcopy again

pahsieh at usgs.gov pahsieh at usgs.gov
Mon Jan 17 23:34:07 EST 2000


> I have some nice visualisations which look fantastic on screen - I am
> trying to find a good way to get these into a word document at a
> good resolution for publication....

If you mean a MS Word document, then you can create a bitmap file
and import this bitmap into MS Word. The key is to create a bitmap
of the proper size with the correct header information so that
MS Word will display and print it at the proper size and resolution.

The attached sample program illustrates how to do this. I am using
vtk 2.3. The main program is the visquad example. However, I
replaced vtkRenderWindow with vtkWin32OpenGLRenderWindow
to use the necessary methods. To create the bitmap, I added a
user method called MakeBMP. This is invoked by pressing the
'u' key. This program will only run on Windows.

Most of the code in MakeBMP is for creating the bitmap file header
and bitmap info header. Much of the code is copied from
vtkBMPWriter.cxx, with modifications to set the bitmap header.
In particular, for a bitmap of 150 ppi (pixels per inch) resolution,
XPelsPerMeter should be set to 5904. At 300 ppi resolution,
XPelsPerMeter should be setto 11808. In this example, everything is
"hard wired". The bitmap is created at 300 ppi and will appear 6 inches
wide. The height is automatically determined to retain the aspect
ratio of the vtk window.

When you run the sample program and hit 'u' (without changing
the window size), the bitmap will be 1800 x 1800. It occupies
9.5 Megabytes because the data are not compressed. However, when
you import this bitmap into MS Word (Insert->Picture->From File)
and save the Word document, it will only be 355 Kilobytes. The bitmap
will appear 6 inches by 6 inches on the page. When printed on a color
printer at 300 ppi, the page looks rather decent. It is probably
acceptable for publication.

Hope this helps.
Paul

======sample program=====


#include "vtkRenderer.h"
#include "vtkWin32OpenGLRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkQuadric.h"
#include "vtkSampleFunction.h"
#include "vtkContourFilter.h"
#include "vtkOutlineFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"

void MakeBMP(void *arg);

void main()
{
  vtkRenderer *ren1 = vtkRenderer::New();
  vtkWin32OpenGLRenderWindow *renWin = vtkWin32OpenGLRenderWindow::New();
    renWin->AddRenderer(ren1);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
    // Add user function to create bmp file
    iren->SetUserMethod(MakeBMP, renWin);
  renWin->SetSize( 300, 300 );

  // Quadric definition
  vtkQuadric *quadric = vtkQuadric::New();
    quadric->SetCoefficients(.5,1,.2,0,.1,0,0,.2,0,0);

  vtkSampleFunction *sample = vtkSampleFunction::New();
    sample->SetSampleDimensions(30,30,30);
    sample->SetImplicitFunction(quadric);

  // Create five surfaces F(x,y,z) = constant between range specified
  vtkContourFilter *contours = vtkContourFilter::New();
    contours->SetInput(sample->GetOutput());
    contours->GenerateValues(5, 0.0, 1.2);
    contours->Update();

  vtkPolyDataMapper *contMapper = vtkPolyDataMapper::New();
    contMapper->SetInput(contours->GetOutput());
    contMapper->SetScalarRange(0.0, 1.2);

  vtkActor *contActor = vtkActor::New();
    contActor->SetMapper(contMapper);

  // Create outline
  vtkOutlineFilter *outline = vtkOutlineFilter::New();
    outline->SetInput(sample->GetOutput());

  vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
    outlineMapper->SetInput(outline->GetOutput());

  vtkActor *outlineActor = vtkActor::New();
    outlineActor->SetMapper(outlineMapper);
    outlineActor->GetProperty()->SetColor(0,0,0);

  ren1->SetBackground(1,1,1);
  ren1->AddActor(contActor);
  ren1->AddActor(outlineActor);

  renWin->Render();

  // interact with data
  iren->Initialize();
  iren->Start();

  // Clean up
  ren1->Delete();
  renWin->Delete();
  iren->Delete();
  quadric->Delete();
  sample->Delete();
  contours->Delete();
  contMapper->Delete();
  contActor->Delete();
  outline->Delete();
  outlineMapper->Delete();
  outlineActor->Delete();
}

void MakeBMP(void *arg)
{
     int  width, height, XPelsPerMeter, YPelsPerMeter;
     int bitmapResolutionOption = 2;  // 1 = 150 ppi, 2 = 300 ppi
     float bitmapWidthInInches = 6.0;
     float bitmapHeightInInches = 4.0;
     int scaleToOption = 1;   // 1 = set bitmap width and scale height to
                              //     maintain aspect ratio of vtk window
                              // 2 = set bitmap height and scale width to
                              //     maintain aspect ratio of vtk window

     vtkWin32OpenGLRenderWindow *renWin = (vtkWin32OpenGLRenderWindow *)
arg;
     int *size = renWin->GetSize();

     if (bitmapResolutionOption == 1)
     {
          XPelsPerMeter = 5904;    // 150 ppi
          YPelsPerMeter = 5904;
          if (scaleToOption == 1)
          {
               width = bitmapWidthInInches * 150;
               height = (((long) width) * size[1]) / size[0];
          }
          else
          {
               height = bitmapHeightInInches * 150;
               width = (((long) height) * size[0]) / size[1];
          }
     }
     else if (bitmapResolutionOption == 2)
     {
          XPelsPerMeter = 11808;   // 300 ppi
          YPelsPerMeter = 11808;
          if (scaleToOption == 1)
          {
               width = bitmapWidthInInches * 300;
               height = (((long) width) * size[1]) / size[0];
          }
          else
          {
               height = bitmapHeightInInches * 300;
               width = (((long) height) * size[0]) / size[1];
          }
     }

     int dataWidth = ((width*3+3)/4)*4;

     ofstream *file = new ofstream;
     file->open("visquad.bmp", ios::out | ios::binary);

     // write the bitmap file header
     file->put((char)66);
     file->put((char)77);
     long temp = (long)(dataWidth*height) + 54L;
     file->put((char)(temp%256));
     file->put((char)((temp%65536L)/256));
     file->put((char)(temp/65536L));
     for (int row = 0; row < 5; row++)
     {
          file->put((char)0);
     }
     file->put((char)54);
     file->put((char)0);
     file->put((char)0);
     file->put((char)0);

     // write the bitmap info header
     file->put((char)40);     // biSize
     file->put((char)0);
     file->put((char)0);
     file->put((char)0);

     file->put((char)(width%256)); // biWidth
     file->put((char)(width/256));
     file->put((char)0);
     file->put((char)0);

     file->put((char)(height%256));      // biHeight
     file->put((char)(height/256));
     file->put((char)0);
     file->put((char)0);

     file->put((char)1);      // biPlanes
     file->put((char)0);
     file->put((char)24);     // biBitCount
     file->put((char)0);

     for (row = 0; row < 8; row++) // biCompression and biSizeImage
     {
          file->put((char)0);
     }

     file->put((char)(XPelsPerMeter%256));    // biXPelsPerMeter
     file->put((char)(XPelsPerMeter/256));
     file->put((char)0);
     file->put((char)0);

     file->put((char)(XPelsPerMeter%256));    // biYPelsPerMeter
     file->put((char)(XPelsPerMeter/256));
     file->put((char)0);
     file->put((char)0);

     for (row = 0; row < 8; row++) // biClrUsed and biClrImportant
     {
          file->put((char)0);
     }

     // render to memory and write bitmap data
     renWin->SetupMemoryRendering(width, height, renWin->GetMemoryDC());
     renWin->Render();
     file->write(renWin->GetMemoryData(), dataWidth*height);
     file->close();
     delete file;
     renWin->ResumeScreenRendering();
     cerr << "bitmap file created\n";
}



-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list