[vtkusers] vtkSampleFunction and vtkImageWriter

David Stocks dstocks at inf.ed.ac.uk
Wed Apr 14 10:48:18 EDT 2004


Hello,

I'm trying to generate an image stack from an implicit function.  In 
doing this, I'm trying to feed the output of vtkSampleFunction into 
vtkTIFFWriter as shown below.  When I run this, I get the output:

dstocks at pattiesmuir[~/CIRCE/vtk/Cxx]% ./coneWriter
we want: 3
we got:  3
ERROR: In /tmp/dstocks/VTK/IO/vtkTIFFWriter.cxx, line 463
vtkTIFFWriter (0x8056810): TIFFWriter only accepts unsigned char scalars!

ERROR: In /tmp/dstocks/VTK/IO/vtkTIFFWriter.cxx, line 463
vtkTIFFWriter (0x8056810): TIFFWriter only accepts unsigned char scalars!

[ ... ]

As far as I can see I'm setting the sample function output to the right 
type, but yet something is clearly amiss.  Any suggestions?

Thanks in advance,
David.

#include <iostream>

#include "vtkCone.h"
#include "vtkSampleFunction.h"
#include "vtkTIFFWriter.h"

#define SAMPLE_RANGE_X_MIN -1
#define SAMPLE_RANGE_X_MAX 3
#define SAMPLE_RANGE_Y_MIN -1.25
#define SAMPLE_RANGE_Y_MAX 1.25
#define SAMPLE_RANGE_Z_MIN -1.25
#define SAMPLE_RANGE_Z_MAX 1.25

int main(int argc, char *argv[]) {

   vtkCone *cone = vtkCone::New();
   cone->SetAngle(30);

   vtkSampleFunction *theConeSample = vtkSampleFunction::New();
   theConeSample->SetOutputScalarTypeToUnsignedChar();
   theConeSample->SetImplicitFunction(cone);
   theConeSample->SetModelBounds(SAMPLE_RANGE_X_MIN,
				SAMPLE_RANGE_X_MAX,
				SAMPLE_RANGE_Y_MIN,
				SAMPLE_RANGE_Y_MAX,
				SAMPLE_RANGE_Z_MIN,
				SAMPLE_RANGE_Z_MAX);
   theConeSample->SetSampleDimensions(50, 50, 50);
   theConeSample->ComputeNormalsOff();

   cout << "we want: " << VTK_UNSIGNED_CHAR << endl;
   cout << "we got:  " << theConeSample->GetOutputScalarType() << endl;

   vtkTIFFWriter *writer = vtkTIFFWriter::New();
   writer->SetInput(theConeSample->GetOutput());
   writer->SetFilePrefix("foo");
   writer->Write();

   return(0);
}

-- 
David Stocks
Institute of Perception, Action and Behaviour
School of Informatics, University of Edinburgh
+44 (0)131 651 3436




More information about the vtkusers mailing list