[vtkusers] vtkSampleFunction and vtkImageWriter
Mathieu Malaterre
mathieu.malaterre at kitware.com
Wed Apr 14 11:02:42 EDT 2004
David,
Use vtkImageCast:
http://www.vtk.org/doc/nightly/html/classvtkImageCast.html
Mathieu
Ps: Also please search the ML archive before asking a question, thanks.
David Stocks wrote:
> 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);
> }
>
More information about the vtkusers
mailing list