[vtkusers] isosurface extraction from many bmp files
Luke Hetrick
lhetrick at nnu.edu
Tue Jun 19 18:58:00 EDT 2012
Fellow VTK Users,
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:
#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkBMPReader.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkOutlineFilter.h>
#include <vtkCamera.h>
#include <vtkProperty.h>
#include <vtkPolyDataNormals.h>
#include <vtkContourFilter.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderer.h>
int main(int argc, char* argv[])
{
//Read the images
vtkSmartPointer<vtkBMPReader> bmp =
vtkSmartPointer<vtkBMPReader>::New();
bmp->SetFilePrefix("../../../../../Auxillary/Data/Data_Set_1/Threshold_Data/fetus_threshold_");
bmp->SetFilePattern("%s%04d.bmp");
bmp->SetFileNameSliceOffset(1);
bmp->SetFileNameSliceSpacing(1);
bmp->SetNumberOfScalarComponents(3);
bmp->SetDataSpacing(1,1,1);
bmp->SetDataOrigin(0,0,0);
bmp->SetDataExtent(0,400,0,400,22,679);
bmp->Update();
//isosurface extraction attempt
vtkSmartPointer<vtkContourFilter> Extract1 =
vtkSmartPointer<vtkContourFilter>::New();
Extract1->SetInputConnection( bmp->GetOutputPort() );
Extract1->SetValue( 0, 1200 );
vtkSmartPointer<vtkPolyDataNormals> Normals =
vtkSmartPointer<vtkPolyDataNormals>::New();
Normals->SetInputConnection( Extract1->GetOutputPort() );
Normals->SetFeatureAngle( 60.0 );
vtkSmartPointer<vtkPolyDataMapper> Mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
Mapper->SetInputConnection( Normals->GetOutputPort() );
Mapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> Actor =
vtkSmartPointer<vtkActor>::New();
Actor->SetMapper( Mapper );
// An outline provides context around the data.
vtkSmartPointer<vtkOutlineFilter> outlineData =
vtkSmartPointer<vtkOutlineFilter>::New();
outlineData->SetInputConnection( bmp->GetOutputPort() );
vtkSmartPointer<vtkPolyDataMapper> mapOutline =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapOutline->SetInputConnection( outlineData->GetOutputPort() );
vtkSmartPointer<vtkActor> outline =
vtkSmartPointer<vtkActor>::New();
outline->SetMapper( mapOutline );
outline->GetProperty()->SetColor( 0,0,0 );
// It is convenient to create an initial view of the data. The FocalPoint
// and Position form a vector direction. Later on (ResetCamera() method)
// this vector is used to position the camera to look at the data in
// this direction.
vtkSmartPointer<vtkCamera> aCamera =
vtkSmartPointer<vtkCamera>::New();
aCamera->SetViewUp ( 0, 0, -1 );
aCamera->SetPosition ( 0, 1, 0 );
aCamera->SetFocalPoint ( 0, 0, 0 );
aCamera->ComputeViewPlaneNormal();
aCamera->Azimuth( 30.0 );
aCamera->Elevation( 30.0 );
// Create the renderer, the render window, and the interactor. The
renderer
// draws into the render window, the interactor enables mouse and
// keyboard-based interaction with the data within the render window.
vtkSmartPointer<vtkRenderer> aRenderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(aRenderer);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> Style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
// Actors are added to the renderer. An initial camera view is created.
// The Dolly() method moves the camera towards the FocalPoint,
// thereby enlarging the image.
aRenderer->AddActor( outline );
aRenderer->AddActor( Actor );
aRenderer->SetActiveCamera( aCamera );
aRenderer->ResetCamera();
aCamera->Dolly( 1.5 );
// Set a background color for the renderer and set the size of the
// render window (expressed in pixels).
aRenderer->SetBackground( .2, .3, .4 );
renWin->SetSize( 640, 480 );
// Note that when camera movement occurs (as it does in the Dolly()
// method), the clipping planes often need adjusting. Clipping planes
// consist of two planes: near and far along the view direction. The
// near plane clips out objects in front of the plane; the far plane
// clips out objects behind the plane. This way only what is drawn
// between the planes is actually rendered.
aRenderer->ResetCameraClippingRange();
// Initialize the event loop and then start it.
iren->SetInteractorStyle( Style );
iren->Initialize();
iren->Start();
return EXIT_SUCCESS;
}
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.
Thanks,
Luke H
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120619/43718bdf/attachment.htm>
More information about the vtkusers
mailing list