[Insight-users] Add small discriptionto the earlier mail

shirani kannangara mangalika673 at gmail.com
Tue Feb 5 03:39:05 EST 2013


HI vtk-users
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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130205/dfec63c8/attachment.htm>
-------------- next part --------------

cmake_minimum_required(VERSION 2.8)
 
PROJECT(ImageReader2)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
ADD_EXECUTABLE(ImageReader2 imagereader.cxx)
TARGET_LINK_LIBRARIES(ImageReader2 vtkHybrid vtkInfovis)


More information about the Insight-users mailing list