[vtkusers] VTK TO POSTSCRIPT
Elkin Arroyo
elkin at kana.stanford.edu
Sat Nov 17 19:05:49 EST 2001
Hi
Just use vtkPostScriptWriter like this
vtkWindowToImageFilter w2if = vtkWindowToImageFilter::New();
w2if->SetInput(renWin);
vtkPostScriptWriter *psw = vtkPostScriptWriter::New();
psw->SetInput(w2if->GetOutput());
psw->SetFileName(nombre);
psw->Write();
psw->Delete();
Where renWin is your vtkRenderWindow
Attaching I am Sending you a class that I desinged
to save VTK images in the all the format supported by VTK
to use it just do like this
#include"sepCubeWriter.h"
int main() {
sepCubeWriter writer;
writer.SetFileName(name);
writer.SetFileFormat(of);
.
. your code
.
/* Let's save a image in the format especified by user, with
the name especified by user */
writer.SetInput(renWin);
writer.Write();
}
/*
Where format is just interger like
Set the output imagefile format, by defautl is POSTSCRIPT
Valid values are
POSTSCRIPT = 1,
TIFF = 2,
CGM = 3,
BMP = 4,
VRML = 5
*/
I hope this help !
Elkin Arroyo
earroyo at numerica.com.co
Numerica Ltda, Colombia
On Sat, 17 Nov 2001, Régis BLANCHON wrote:
>
> I would like to know how to make a file POSTSCRIPT from a
> VTK file using Tcl and using C++ under Windows environment.
> Thanks for your help.
> Régis
> _________________________________________________________
> Le journal des abonnés Caramail - http://www.carazine.com
>
>
-------------- next part --------------
// -*- C++ -*-
/*****************************************************************************/
/* */
/* (c) Copyright 2001 */
/* Stanford Exploration Project, SEP. */
/* Numerica Ltda, Bucaramanga, Colombia. */
/* All left reserved. */
/* */
/* See http://www.stanford.edu/ for further details. */
/* */
/*****************************************************************************/
/* Elkin Rafael Arroyo Negrete, Numerica Ltda, ERAN */
#ifndef CUBE_DEFS_IS_INCLUDED
#define CUBE_DEFS_IS_INCLUDED
#include<iostream.h>
/* Valid backgroud colors */
#define BACKGROUND_RED 0.8,0.2,0.2
#define BACKGROUND_GREEN 0.2,0.8,0.2
#define BACKGROUND_BLUE 0.2,0.2,0.8
#define BACKGROUND_WHITE 0.8,0.8,0.8
#define BACKGROUND_GRAY 0.2,0.2,0.2
#define BACKGROUND_BLACK 0.0,0.0,0.0
enum sepColor // Diferentes colors based from Ricksep color.h
{
NICK = 0,
GRAY = 1,
STRAW = 2,
FLAG = 3,
TIGER = 4,
BLUE = 5,
RAINBOW = 6,
AVO = 7,
VELDATA = 8,
HOT = 9
};
enum DataType //The data type varible
{
IS_FLOAT = 0,
IS_CHAR = 1
};
enum sepFileFormat // Format to save images
{
POSTSCRIPT = 1,
TIFF = 2,
CGM = 3,
BMP = 4,
VRML = 5
};
//#ifdef SGI64
#ifndef bool
#define bool int
#endif
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
//#endif
/*
int seperr( char *format) {
cerr << format << endl;
return 0;
}
*/
#endif // CUBE_DEFS_IS_INCLUDED
-------------- next part --------------
// -*- C++ -*-
/*****************************************************************************/
/* */
/* (c) Copyright 2001 */
/* Stanford Exploration Project, SEP. */
/* Numerica Ltda, Bucaramanga, Colombia. */
/* All left reserved. */
/* */
/* See http://www.stanford.edu/ for further details. */
/* */
/*****************************************************************************/
/* Elkin Rafael Arroyo Negrete, Numerica Ltda, ERAN */
#ifndef _SEP_CUBE_WRITER_H_
#define _SEP_CUBE_WRITER_H_
#include<vtkRenderWindow.h>
#include"cubeDefs.h"
class vtkWindowToImageFilter;
// I recomend to move all the stuff in object sepCube
// that is used to write the camera position , focal point
// and view up to this object, because it more logical that
// those things live here instead of sepCube
/* ! \Decription This class is intended to write images
of cube in differents formats, VRML, BMP, POSTSCRIPT
also contain the information of the name of the output
file
*/
class sepCubeWriter {
char name[255];
vtkRenderWindow *renWin;
// vtkStructuredPoints *cube;
vtkWindowToImageFilter *w2if;
sepFileFormat format;
public :
sepCubeWriter();
~sepCubeWriter();
// void SetInput(vtkStructuredPoints *);
void SetInput(vtkRenderWindow *);
void SetFileName(const char *name_);
void SetFileFormat(sepFileFormat f) {this->format=f;}
void SetFileFormat(int f);
bool Write(void);
};
#endif // _SEP_CUBE_WRITER_H_
-------------- next part --------------
#include"sepCubeWriter.h"
#include<vtkWindowToImageFilter.h>
#include<vtkBMPWriter.h>
#include<vtkCGMWriter.h>
#include<vtkTIFFWriter.h>
#include<vtkPostScriptWriter.h>
#include<vtkVRMLExporter.h>
//-------------------------------------
sepCubeWriter::sepCubeWriter() {
//------------------------------------
this->renWin=NULL;
this->w2if = vtkWindowToImageFilter::New();
strcpy(this->name,"sepCubeSnapshot");
this->format = POSTSCRIPT;
}
//-------------------------------------
sepCubeWriter::~sepCubeWriter() {
//-----------------------------------
this->w2if->Delete();
}
void sepCubeWriter::SetInput(vtkRenderWindow *Win) {
this->renWin=Win;
}
void sepCubeWriter::SetFileName(const char *name_) {
strcpy(name,name_);
}
//---------------------------------------
void sepCubeWriter::SetFileFormat (int f) {
//-----------------------------------------
switch(f) {
case 1 :
this->format = POSTSCRIPT;
break;
case 2 :
this->format = TIFF;
break;
case 3 :
this->format = CGM;
break;
case 4 :
this->format = BMP;
break;
case 5 :
this->format = VRML;
break;
default :
cerr << f << " Unknow output format type\n";
}
}
//--------------------------------------------
bool sepCubeWriter::Write(void) {
//--------------------------------------------
char nombre[255];
if(renWin == NULL) {
cerr << "Unable to write output file " << this->name
<< "first call function sepCubeWriter::SetInput\n";
return false;
}
w2if->SetInput(renWin);
switch(this->format) {
case POSTSCRIPT: {
vtkPostScriptWriter *psw = vtkPostScriptWriter::New();
psw->SetInput(w2if->GetOutput());
sprintf(nombre,"%s.ps",this->name);
psw->SetFileName(nombre);
psw->Write();
psw->Delete();
break;}
case TIFF: {
vtkTIFFWriter *tiffw = vtkTIFFWriter::New();
tiffw->SetInput(w2if->GetOutput());
sprintf(nombre,"%s.tif",this->name);
tiffw->SetFileName(nombre);
tiffw->Write();
tiffw->Delete();
break; }
case CGM: {
cerr << __FILE__ << " CGM Writer not implemented yet !\n";
return false;
//vtkCGMWriter *cgmw = vtkCGMWriter::New();
//cgmw->SetInput(this->cube);
//sprintf(nombre,"%s.cgm",this->name);
//cgmw->SetFileName(nombre);
//cgmw->Write();
//cgmw->Delete();
// break;
}
case BMP: {
vtkBMPWriter *bmpw = vtkBMPWriter::New();
bmpw->SetInput(w2if->GetOutput());
sprintf(nombre,"%s.bmp",this->name);
bmpw->SetFileName(nombre);
bmpw->Write();
bmpw->Delete();
break; }
case VRML: {
vtkVRMLExporter *vrmlw = vtkVRMLExporter::New();
vrmlw->SetInput(this->renWin);
sprintf(nombre,"%s.vrml",this->name);
vrmlw->SetFileName(nombre);
vrmlw->Write();
vrmlw->Delete();
break; }
default :
cerr << __FILE__ << " Unknow file format\n";
return false;
}
return true;
}
More information about the vtkusers
mailing list