[vtkusers] "vtkMarchingCubes" does not work?
Zhongyuan Qin
zyqinljl at tom.com
Thu Nov 6 22:52:10 EST 2003
Hi,dear all,
I use the following sample code in my project, with zero error in compile and link.
But when executing, there is always something wrong.
So I begin to debug it, an error is reported when meeting " skinExtractor->SetValue(0, 500);", it said "Unhandled exception in test.exe(VTKCOMNMON.DLL):0xC0000005:Access Violation".
I do not know the reason, can you tell me how to solve it?
Thanks!
Zhongyuan
Code:
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume16Reader.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkOutlineFilter.h"
#include "vtkCamera.h"
#include "G:/vtk/vtk3.1/vtk/patented/vtkMarchingCubes.h"
void main( int argc, char *argv[] )
{
// create the renderer stuff
vtkRenderer *aRenderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(aRenderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// read the volume
vtkVolume16Reader *v16 = vtkVolume16Reader::New();
v16->SetDataDimensions(64,64);
v16->SetDataByteOrderToLittleEndian();
v16->SetFilePrefix ("G:/vtk/vtk3.1/vtkdata/headsq/quarter");
v16->SetImageRange(1, 93);
v16->SetDataSpacing (3.2, 3.2, 1.5);
// extract the skin
vtkMarchingCubes *skinExtractor = vtkMarchingCubes::New();
skinExtractor->SetInput(v16->GetOutput());
skinExtractor->SetValue(0, 500);
vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
skinMapper->SetInput(skinExtractor->GetOutput());
skinMapper->ScalarVisibilityOff();
vtkActor *skin = vtkActor::New();
skin->SetMapper(skinMapper);
// get an outline
vtkOutlineFilter *outlineData = vtkOutlineFilter::New();
outlineData->SetInput(v16->GetOutput());
vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
mapOutline->SetInput(outlineData->GetOutput());
vtkActor *outline = vtkActor::New();
outline->SetMapper(mapOutline);
outline->GetProperty()->SetColor(0,0,0);
// create a camera with the correct view up
vtkCamera *aCamera = vtkCamera::New();
aCamera->SetViewUp (0, 0, -1);
aCamera->SetPosition (0, 1, 0);
aCamera->SetFocalPoint (0, 0, 0);
aCamera->ComputeViewPlaneNormal();
// now, tell the renderer our actors
aRenderer->AddActor(outline);
aRenderer->AddActor(skin);
aRenderer->SetActiveCamera(aCamera);
aRenderer->ResetCamera ();
aCamera->Dolly(1.5);
aRenderer->SetBackground(1,1,1);
aRenderer->ResetCameraClippingRange();
// interact with data
renWin->SetSize( 300, 300);
renWin->Render();
iren->Start();
}
More information about the vtkusers
mailing list