[vtkusers] add a small description to previous mail
Bill Lorensen
bill.lorensen at gmail.com
Tue Feb 5 07:26:45 EST 2013
Please keep these discussion on the vtk users mailing list.
The image reader autmatically gets the dimensions from the .vtk file.
You should not specify
> reader->SetDataExtent(0, 680, 0, 401, 1, 450);
> reader->SetDataSpacing(0.3,0.3,0.3);
> reader->SetDataOrigin(0.0, 0.0, 0.0);
> reader->SetDataScalarTypeToUnsignedChar();
> reader->SetDataByteOrderToLittleEndian();*/
On Tue, Feb 5, 2013 at 3:46 AM, shirani kannangara
<mangalika673 at gmail.com> wrote:
> HI Bill
> I have used imagereader2 to read an RGB image (.vtk file). Imagereader 2 is
> working.But I want the image dimensions to be taken from the
> file(x=675,y=401,z=450).Fuirther my image has voxels and intensity
> values(3d, RGB). What I want finally is to get number of scalars from the
> image and add another scalar to it.I use vtk version 5.10
> CmakeLists is attached here with.The Command window does not show correct
> outputs.I tried my best to get them displayed .But not success.Can any body
> please help me.
> regards
> Shirani
>
> #include <vtkSmartPointer.h>
> #include <vtkImageReader2.h>
> #include <vtkImageData.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkInteractorStyleImage.h>
> #include <vtkRenderer.h>
> #include <vtkImageActor.h>
>
> int main(int argc, int *argv[])
> {
> int x=0.0;
> int y=0.0;
> int z=0.0;
> int ScalarComponents;
> int GetNumberOfScalars=0;
> int GetDimensions=0;
> int dims[3]={x,y,z};
> // Verify command line arguments
> /*if(argc < 2)
> {
> std::cout << "Usage: " << argv[0]
> << " InputFilename" << std::endl;
> return EXIT_FAILURE;
> }*/
> // Parse command line arguments
> //std::string inputFilename =(argv[1]);
>
> // Read file
> vtkSmartPointer<vtkImageReader2> reader =
> vtkSmartPointer<vtkImageReader2>::New();
> reader->SetFileName("D:\\rgbabdomen\\Debug\\output.vtk");
> reader->SetDataScalarTypeToInt();
> // reader->SetDataScalarTypeToUnsignedChar();
> reader->UpdateWholeExtent();
> reader->Update();
>
> /*reader->SetFilePrefix(argv[3]);
> reader->SetDataExtent(0, 680, 0, 401, 1, 450);
> reader->SetDataSpacing(0.3,0.3,0.3);
> reader->SetDataOrigin(0.0, 0.0, 0.0);
> reader->SetDataScalarTypeToUnsignedChar();
> reader->SetDataByteOrderToLittleEndian();*/
> // reader->UpdateWholeExtent();*/
>
>
> vtkSmartPointer<vtkImageData> imageData =
> vtkSmartPointer<vtkImageData>::New();
>
> imageData = reader->GetOutput();
> imageData->UpdateInformation();
> imageData->Update();
>
>
> // Specify the size of the image data
> //imageData->SetDimensions(675,401,450);
>
> #if VTK_MAJOR_VERSION <= 5
> imageData->SetNumberOfScalarComponents(GetNumberOfScalars+1);
> imageData->SetScalarTypeToDouble();
> ScalarComponents=imageData->GetNumberOfScalarComponents();
>
>
> #else
>
> imageData->AllocateScalars(VTK_DOUBLE,1);
> //imageData->AllocateScalars();
> #endif
>
> // int dims[3];
> imageData->GetDimensions(dims);
> // int dims[3]; // can't do this
>
> std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: " <<
> dims[2] << std::endl;
> std::cout << "Number of
> ScalarComponents:"<<imageData->GetNumberOfScalarComponents()<<std::endl;
> //std::cout << "Number of
> ScalarComponents:"<<ScalarComponents<<std::endl;
>
>
> // Create an actor
> vtkSmartPointer<vtkImageActor> actor =
> vtkSmartPointer<vtkImageActor>::New();
> actor->SetInput(reader->GetOutput());
>
> // Setup renderer
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
> renderer->AddActor(actor);
> renderer->ResetCamera();
>
> // Setup render window
> vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
> renderWindow->AddRenderer(renderer);
>
> // Setup render window interactor
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> vtkSmartPointer<vtkInteractorStyleImage> style =
> vtkSmartPointer<vtkInteractorStyleImage>::New();
>
> renderWindowInteractor->SetInteractorStyle(style);
>
> // Render and start interaction
> renderWindowInteractor->SetRenderWindow(renderWindow);
> renderWindowInteractor->Initialize();
>
> renderWindowInteractor->Start();
>
> return EXIT_SUCCESS;
> }
>
--
Unpaid intern in BillsBasement at noware dot com
More information about the vtkusers
mailing list