Fellow VTK Users,<br><br> If I could borrow some of your attention for a moment. I am trying to extract isosurfaces from bmp files. I have written some code that I believe reads in all my files then go about trying to create a nice smooth surface but when I render the window and try to view the images, all I see is just the box holding the data. I assumed if the data types did not work together an error would have been thrown but that is not the case and when I comment everything else out except for the code that reads in my files, it stops and thinks for a bit so I am under the impression that it is reading in my files. I am just confused as to why the render window comes up blank when I run the program. Here is the code I am using:<br>
<br>#include <vtkSmartPointer.h><br>#include <vtkImageViewer2.h><br>#include <vtkBMPReader.h><br>#include <vtkPolyDataMapper.h><br>#include <vtkActor.h><br>#include <vtkOutlineFilter.h><br>
#include <vtkCamera.h><br>#include <vtkProperty.h><br>#include <vtkPolyDataNormals.h><br>#include <vtkContourFilter.h><br>#include <vtkRenderWindow.h><br>#include <vtkRenderWindowInteractor.h><br>
#include <vtkInteractorStyleTrackballCamera.h><br>#include <vtkRenderer.h><br> <br>int main(int argc, char* argv[])<br>{<br><br> //Read the images<br> vtkSmartPointer<vtkBMPReader> bmp =<br> vtkSmartPointer<vtkBMPReader>::New();<br>
bmp->SetFilePrefix("../../../../../Auxillary/Data/Data_Set_1/Threshold_Data/fetus_threshold_"); <br> bmp->SetFilePattern("%s%04d.bmp"); <br> bmp->SetFileNameSliceOffset(1);<br> bmp->SetFileNameSliceSpacing(1);<br>
bmp->SetNumberOfScalarComponents(3);<br> bmp->SetDataSpacing(1,1,1);<br> bmp->SetDataOrigin(0,0,0);<br> bmp->SetDataExtent(0,400,0,400,22,679); <br> bmp->Update();<br><br><br> //isosurface extraction attempt<br>
vtkSmartPointer<vtkContourFilter> Extract1 =<br> vtkSmartPointer<vtkContourFilter>::New();<br> Extract1->SetInputConnection( bmp->GetOutputPort() );<br> Extract1->SetValue( 0, 1200 );<br><br>
vtkSmartPointer<vtkPolyDataNormals> Normals =<br> vtkSmartPointer<vtkPolyDataNormals>::New();<br> Normals->SetInputConnection( Extract1->GetOutputPort() );<br> Normals->SetFeatureAngle( 60.0 );<br>
<br> vtkSmartPointer<vtkPolyDataMapper> Mapper =<br> vtkSmartPointer<vtkPolyDataMapper>::New();<br> Mapper->SetInputConnection( Normals->GetOutputPort() );<br> Mapper->ScalarVisibilityOff();<br>
<br> vtkSmartPointer<vtkActor> Actor =<br> vtkSmartPointer<vtkActor>::New();<br> Actor->SetMapper( Mapper );<br><br> // An outline provides context around the data.<br> vtkSmartPointer<vtkOutlineFilter> outlineData =<br>
vtkSmartPointer<vtkOutlineFilter>::New();<br> outlineData->SetInputConnection( bmp->GetOutputPort() );<br><br> vtkSmartPointer<vtkPolyDataMapper> mapOutline =<br> vtkSmartPointer<vtkPolyDataMapper>::New();<br>
mapOutline->SetInputConnection( outlineData->GetOutputPort() );<br><br> vtkSmartPointer<vtkActor> outline =<br> vtkSmartPointer<vtkActor>::New();<br> outline->SetMapper( mapOutline );<br> outline->GetProperty()->SetColor( 0,0,0 );<br>
<br> // It is convenient to create an initial view of the data. The FocalPoint<br> // and Position form a vector direction. Later on (ResetCamera() method)<br> // this vector is used to position the camera to look at the data in<br>
// this direction.<br> vtkSmartPointer<vtkCamera> aCamera =<br> vtkSmartPointer<vtkCamera>::New();<br> aCamera->SetViewUp ( 0, 0, -1 );<br> aCamera->SetPosition ( 0, 1, 0 );<br> aCamera->SetFocalPoint ( 0, 0, 0 );<br>
aCamera->ComputeViewPlaneNormal();<br> aCamera->Azimuth( 30.0 );<br> aCamera->Elevation( 30.0 );<br><br> // Create the renderer, the render window, and the interactor. The renderer<br> // draws into the render window, the interactor enables mouse and <br>
// keyboard-based interaction with the data within the render window.<br> vtkSmartPointer<vtkRenderer> aRenderer =<br> vtkSmartPointer<vtkRenderer>::New();<br> <br> vtkSmartPointer<vtkRenderWindow> renWin =<br>
vtkSmartPointer<vtkRenderWindow>::New();<br> renWin->AddRenderer(aRenderer);<br><br> vtkSmartPointer<vtkRenderWindowInteractor> iren =<br> vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
iren->SetRenderWindow(renWin); <br><br> vtkSmartPointer<vtkInteractorStyleTrackballCamera> Style =<br> vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();<br><br> // Actors are added to the renderer. An initial camera view is created.<br>
// The Dolly() method moves the camera towards the FocalPoint,<br> // thereby enlarging the image.<br> aRenderer->AddActor( outline );<br> aRenderer->AddActor( Actor );<br> aRenderer->SetActiveCamera( aCamera );<br>
aRenderer->ResetCamera();<br> aCamera->Dolly( 1.5 );<br><br> // Set a background color for the renderer and set the size of the<br> // render window (expressed in pixels).<br> aRenderer->SetBackground( .2, .3, .4 );<br>
renWin->SetSize( 640, 480 );<br><br> // Note that when camera movement occurs (as it does in the Dolly()<br> // method), the clipping planes often need adjusting. Clipping planes<br> // consist of two planes: near and far along the view direction. The <br>
// near plane clips out objects in front of the plane; the far plane<br> // clips out objects behind the plane. This way only what is drawn<br> // between the planes is actually rendered.<br> aRenderer->ResetCameraClippingRange();<br>
<br> // Initialize the event loop and then start it.<br> iren->SetInteractorStyle( Style ); <br> iren->Initialize();<br> iren->Start();<br><br><br><br> return EXIT_SUCCESS;<br>}<br><br>There are a few parameters that I can adjust that would have a large impact on the surface I am trying to extract that may be the reason why I am not seeing a volume. SOme of the parapmeters Ithink would be a problem would be the many properites of bmp and the Normals->SetAngle() property. If you have had similar experience to this or just have an idea of why I can not view anything in the render window, please let me know your thoughts. <br>
<br>Thanks,<br>Luke H<br>