HI,
<div>I want to add a scalar value to RGB values of a .vtk file.(Here I have written VHP abdomen data(.mhd) set in .vtk format using ITK andVTK and it is working properly). My next attempt is to add a scalar to RGB values of the .vtk file and use imageIterator to sweep data.For that I have used VTK Examples CXX</div>
<div><br></div><div>VTK/Examples/CXX/Broken/IO/ImageReader2</div><div><br></div><div>VTK/Examples/CXX/ImageData/IterateImage Data</div><div><br></div><div><br></div><div><font color="#ff0000">My codes are as follows</font></div>
<div><div><br></div><div>#include <vtkSmartPointer.h></div><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>#include <vtkVersion.h></div><div>#include <vtkSmartPointer.h></div>
<div>#include <vtkImageData.h></div><div><br></div><div>int main(int argc, char *argv[])</div><div>{</div><div> // 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 =("D:\\rgbabdomen\\Debug\\output.vtk");</div>
<div> </div><div> // Read file</div><div> vtkSmartPointer<vtkImageReader2> reader =</div><div> vtkSmartPointer<vtkImageReader2>::New();</div><div> reader->SetFileName(("D:\\rgbabdomen\\Debug\\output.vtk"));</div>
<div> reader->SetDataScalarTypeToUnsignedChar();</div><div> reader->Update();</div><div> </div><div>//int main(int, char *[])</div><div><br></div><div> // Create an image data</div><div> vtkSmartPointer<vtkImageData> imageData = </div>
<div> vtkSmartPointer<vtkImageData>::New();</div><div> </div><div> imageData->reader(GetOutput);</div><div> </div><div> </div><div><br></div><div> </div><div> // Specify the size of the image data</div><div>
imageData->SetDimensions(675,401,450);</div><div>#if VTK_MAJOR_VERSION <= 5</div><div> imageData->SetNumberOfScalarComponents(GetNumberOfScalars+1);</div><div> imageData->SetScalarTypeToInt();</div><div><br>
</div><div><br></div><div>#else</div><div> imageData->AllocateScalars(VTK_DOUBLE,1);</div><div>#endif</div><div> </div><div> int* dims = imageData->GetDimensions();</div><div> // int dims[3]; // can't do this</div>
<div> </div><div> std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: " << dims[2] << std::endl;</div><div> </div>
<div> //std::cout << "Number of points: " << imageData->GetNumberOfPoints() << std::endl;</div><div> std::cout << "Number of cells: " << imageData->GetNumberOfCells() << std::endl;</div>
<div> </div><div> // Fill every entry of the image data with "3.0"</div><div> for (int z = 0; z < dims[2]; z++)</div><div> {</div><div> for (int y = 0; y < dims[1]; y++)</div><div> {</div><div>
for (int x = 0; x < dims[0]; x++)</div><div> {</div><div> double* pixel = static_cast<double*>(imageData->GetScalarPointer(x,y,z));</div><div> pixel[0] = 3.0;</div><div> }</div>
<div> }</div><div> }</div><div> </div><div> // Retrieve the entries from the image data and print them to the screen</div><div> for (int z = 0; z < dims[2]; z++)</div><div> {</div><div> for (int y = 0; y < dims[1]; y++)</div>
<div> {</div><div> for (int x = 0; x < dims[0]; x++)</div><div> {</div><div> double* pixel = static_cast<double*>(imageData->GetScalarPointer(x,y,z));</div><div> // do something with v</div>
<div> std::cout << pixel[0] << " ";</div><div> }</div><div> std::cout << std::endl;</div><div> }</div><div> std::cout << std::endl;</div><div> }</div><div> </div>
<div> // Access the data linearly</div><div> /*</div><div> vtkSmartPointer<vtkImageData> image =</div><div> vtkSmartPointer<vtkImageData>::New();</div><div> image->SetExtent(0,1,0,1,0,0);</div><div>
image->SetScalarTypeToInt();</div><div> image->SetNumberOfScalarComponents(1);</div><div> </div><div> int* pixel;</div><div> </div><div> pixel = static_cast<int*>(image->GetScalarPointer(0,0,0));</div>
<div> pixel[0] = 1;</div><div> </div><div> pixel = static_cast<int*>(image->GetScalarPointer(1,0,0));</div><div> pixel[0] = 2;</div><div> </div><div> pixel = static_cast<int*>(image->GetScalarPointer(0,1,0));</div>
<div> pixel[0] = 3;</div><div> </div><div> pixel = static_cast<int*>(image->GetScalarPointer(1,1,0));</div><div> pixel[0] = 4;</div><div> </div><div> vtkIntArray* scalars = vtkIntArray::SafeDownCast(image->GetPointData()->GetArray("ImageScalars"));</div>
<div> std::cout << "Scalars has " << scalars->GetNumberOfComponents() << " components" << std::endl;</div><div> std::cout << "Scalars has " << scalars->GetNumberOfTuples() << " tuples" << std::endl;</div>
<div> </div><div> for(vtkIdType i = 0; i < scalars->GetNumberOfTuples(); i++)</div><div> {</div><div> std::cout << scalars->GetValue(i) << std::endl;</div><div> }</div><div> */</div><div> return EXIT_SUCCESS;</div>
<div>}</div><div> </div><div> </div><div> </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><div><br></div><div><font color="#ff0000">There are three errors</font></div>
<div><div style="color:rgb(255,0,0)">1>------ Build started: Project: ImageReader2, Configuration: Debug Win32 ------</div><div style="color:rgb(255,0,0)">1>Compiling...</div><div style="color:rgb(255,0,0)">1>imagereader.cxx</div>
<div style="color:rgb(255,0,0)">1>.\imagereader.cxx(40) : error C2039: 'reader' : is not a member of 'vtkImageData'</div><div style="color:rgb(255,0,0)">1> D:\research2\vtk-5.10.0\VTK\Filtering\vtkImageData.h(35) : see declaration of 'vtkImageData'</div>
<div style="color:rgb(255,0,0)">1>.\imagereader.cxx(40) : error C2065: 'GetOutput' : undeclared identifier</div><div style="color:rgb(255,0,0)">1>.\imagereader.cxx(48) : error C2065: 'GetNumberOfScalars' : undeclared identifier</div>
<div style="color:rgb(255,0,0)">1>Build log was saved at "file://d:\dup2\ImageReader2.dir\Debug\BuildLog.htm"</div><div style="color:rgb(255,0,0)">1>ImageReader2 - 3 error(s), 0 warning(s)</div><div style="color:rgb(255,0,0)">
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========</div><div style="color:rgb(255,0,0)"><br></div><div><font color="#ffffff">C</font>Can you please go through my codes and show me the correct way of doing it.I am waiting for a quick reply from you.</div>
</div><div><br></div><div>regards</div><div>Shirani</div>