<span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">HI vtk-users</span><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
I have used imagereader2 to read an RGB image (.vtk file). <span style="background-color:rgb(255,255,255)">Imagereader 2 is working.But I want the image dimensions to be taken from the file(x=675,y=401,z=450).</span><span style="background-color:rgb(255,255,255)">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</span></div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">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.</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">regards</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Shirani</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">#include <vtkSmartPointer.h></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<div>#include <vtkImageReader2.h></div><div>#include <vtkImageData.h></div><div>#include <vtkRenderWindow.h></div><div>#include <vtkRenderWindowInteractor.h></div><div>#include <vtkInteractorStyleImage.h></div>
<div>#include <vtkRenderer.h></div><div>#include <vtkImageActor.h></div><div> </div><div>int main(int argc, int *argv[])</div><div>{ </div><div><span style="white-space:pre-wrap">        </span>int x=0.0;</div><div>
<span style="white-space:pre-wrap">        </span>int y=0.0;</div><div><span style="white-space:pre-wrap">        </span>int z=0.0;</div><div><span style="white-space:pre-wrap">        </span></div><div> int ScalarComponents;</div><div>
<span style="white-space:pre-wrap">        </span>int GetNumberOfScalars=0;</div><div><span style="white-space:pre-wrap">        </span>int GetDimensions=0;</div><div> int dims[3]={x,y,z};</div><div><span style="white-space:pre-wrap">        </span></div>
<div><span style="white-space:pre-wrap">        </span>// Verify command line arguments</div><div> /*if(argc < 2)</div><div> {</div><div> std::cout << "Usage: " << argv[0]</div><div> << " InputFilename" << std::endl;</div>
<div> return EXIT_FAILURE;</div><div> }*/ </div><div> // Parse command line arguments</div><div>//std::string inputFilename =(argv[1]);</div><div> </div><div>// Read file</div><div> <font color="#ff0000"> vtkSmartPointer<vtkImageReader2> reader =</font></div>
<div><font color="#ff0000"> vtkSmartPointer<vtkImageReader2>::New();</font></div><div><font color="#ff0000"> reader->SetFileName("D:\\rgbabdomen\\Debug\\output.vtk");</font></div><div><font color="#ff0000"> reader->SetDataScalarTypeToInt();</font></div>
<div><font color="#ff0000"> // reader->SetDataScalarTypeToUnsignedChar();</font></div><div><font color="#ff0000"> reader->UpdateWholeExtent();</font></div><div><font color="#ff0000"> reader->Update();</font></div>
<div> </div><div> /*reader->SetFilePrefix(argv[3]);</div><div> reader->SetDataExtent(0, 680, 0, 401, 1, 450);</div><div> reader->SetDataSpacing(0.3,0.3,0.3);</div><div> reader->SetDataOrigin(0.0, 0.0, 0.0);</div>
<div> reader->SetDataScalarTypeToUnsignedChar();</div><div> reader->SetDataByteOrderToLittleEndian();*/</div><div> // reader->UpdateWholeExtent();*/</div><div> </div><div> </div><div> vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();</div>
<div> </div><div> imageData = reader->GetOutput();</div><div> imageData->UpdateInformation();</div><div> imageData->Update();</div><div> </div><div> </div><div><span style="white-space:pre-wrap">        </span>// Specify the size of the image data</div>
<div> //imageData->SetDimensions(675,401,450);</div><div><br></div><div>#if VTK_MAJOR_VERSION <= 5</div><div> imageData->SetNumberOfScalarComponents(GetNumberOfScalars+1);</div><div> imageData->SetScalarTypeToDouble();</div>
<div> ScalarComponents=imageData->GetNumberOfScalarComponents();</div><div> </div><div> </div><div>#else</div><div><br></div><div> imageData->AllocateScalars(VTK_DOUBLE,1);</div><div> //imageData->AllocateScalars();</div>
<div>#endif</div><div><br></div><div> // int dims[3];</div><div> imageData->GetDimensions(dims);</div><div> // int dims[3]; // can't do this</div><div><br></div><div><span style="white-space:pre-wrap">        </span>std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: " << dims[2] << std::endl;</div>
<div> std::cout << "Number of ScalarComponents:"<<imageData->GetNumberOfScalarComponents()<<std::endl;</div><div> //std::cout << "Number of ScalarComponents:"<<ScalarComponents<<std::endl;</div>
<div><br></div><div> </div><div> // Create an actor</div><div> vtkSmartPointer<vtkImageActor> actor =</div><div> vtkSmartPointer<vtkImageActor>::New();</div><div> actor->SetInput(reader->GetOutput());</div>
<div> </div><div> // Setup renderer</div><div> vtkSmartPointer<vtkRenderer> renderer =</div><div> vtkSmartPointer<vtkRenderer>::New();</div><div> renderer->AddActor(actor);</div><div> renderer->ResetCamera();</div>
<div> </div><div> // Setup render window</div><div> vtkSmartPointer<vtkRenderWindow> renderWindow =</div><div> vtkSmartPointer<vtkRenderWindow>::New();</div><div> renderWindow->AddRenderer(renderer);</div>
<div> </div><div> // Setup render window interactor</div><div> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =</div><div> vtkSmartPointer<vtkRenderWindowInteractor>::New();</div><div>
vtkSmartPointer<vtkInteractorStyleImage> style =</div>
<div> vtkSmartPointer<vtkInteractorStyleImage>::New();</div><div> </div><div> renderWindowInteractor->SetInteractorStyle(style);</div><div> </div><div> // Render and start interaction</div><div> renderWindowInteractor->SetRenderWindow(renderWindow);</div>
<div> renderWindowInteractor->Initialize();</div><div> </div><div> renderWindowInteractor->Start();</div><div> </div><div> return EXIT_SUCCESS;</div><div>}</div></div>