<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16915" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Dear All:<BR></FONT></DIV>
<DIV><FONT face=Arial size=2> I have been stuck in loading in
and viewing the VRML files in the past two days. I found some codes online, and
wrote my own based on those codes. However, there are some problems, always the
access violation problem. I have tested on different files, some created by
my collegues before, and some downloaded from the internet. </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> I post the code patch, anyone could
help me?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial
size=2>---------------------------------------------------------------------------------------------</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>#include "vtkRenderer.h"<BR>#include
"vtkRenderWindow.h"<BR>#include "vtkRenderWindowInteractor.h"</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>#include "vtkVRMLImporter.h"<BR>#include
"vtkDataSet.h"<BR>#include "vtkActorCollection.h"<BR>#include
"vtkPolyData.h"<BR>#include "vtkPolyDataMapper.h"<BR>#include
"vtkPolyDataNormals.h"<BR>#include "vtkActor.h"</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>#include <iostream></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>int main (int argc, char **argv)<BR>{</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> // VRML Import<BR>vtkVRMLImporter
*importer=vtkVRMLImporter::New();<BR>//importer->SetFileName(argv[1]);<BR>importer->SetFileName(file
name);<BR>importer->Read();<BR>importer->Update();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>//Convert to vtkDataSet<BR>vtkDataSet
*pDataset;<BR>vtkActorCollection *actors =
importer->GetRenderer()->GetActors();<BR>actors->InitTraversal();<BR><FONT
color=#ff0000>pDataset =
actors->GetNextActor()->GetMapper()->GetInput(); //Problem happened
here</FONT></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>//Convert to vtkPolyData<BR>vtkPolyData *polyData =
vtkPolyData::SafeDownCast(pDataset);<BR>polyData->Update();</FONT></DIV>
<DIV> </DIV><FONT face=Arial size=2>
<DIV><BR>// Create Normal Vectors to enhance smoothness & illumination
<BR>vtkPolyDataNormals *normals =
vtkPolyDataNormals::New();<BR>normals->SetInput(polyData);<BR>normals->SetFeatureAngle(60.0);</DIV>
<DIV> </DIV>
<DIV>// Mapper<BR>vtkPolyDataMapper *SolidMapper =
vtkPolyDataMapper::New();<BR>SolidMapper->SetInput(normals->GetOutput());<BR>SolidMapper->ScalarVisibilityOff();
</DIV>
<DIV> </DIV>
<DIV>// Actor<BR>vtkActor *SolidActor =
vtkActor::New();<BR>SolidActor->SetMapper(SolidMapper);<BR>//SolidActor->GetProperty()->SetOpacity(1);</DIV>
<DIV> </DIV>
<DIV>// Render<BR>vtkRenderer *ren =
vtkRenderer::New();<BR>ren->AddActor(SolidActor);
<BR>ren->SetBackground(1,1,1);</DIV>
<DIV> </DIV>
<DIV>// RenderWindow<BR>vtkRenderWindow *renWin =
vtkRenderWindow::New();<BR>renWin->AddRenderer(ren);</DIV>
<DIV> </DIV>
<DIV>// RenderWindowInteractor<BR>vtkRenderWindowInteractor *iren =
vtkRenderWindowInteractor::New();<BR>iren->SetRenderWindow(renWin);</DIV>
<DIV> </DIV>
<DIV>renWin->Start(); <BR>renWin->SetSize(800-5,600-5); // Must be Called
after Start() and before Render() <BR>// interact with
data<BR>iren->Initialize();<BR>iren->Start();</DIV>
<DIV> </DIV>
<DIV>// delete </DIV>
<DIV> </DIV>
<DIV>actors->Delete();</DIV>
<DIV>normals->Delete(); <BR>SolidMapper->Delete();
<BR>SolidActor->Delete();<BR>ren->Delete();
<BR>renWin->Delete();<BR>iren->Delete();</DIV>
<DIV> </DIV>
<DIV>return 0;<BR>}</DIV>
<DIV> </DIV>
<DIV>----------------------------------------------------------------------------------------------------------------------------------------------</FONT></DIV>
<DIV><FONT face=Arial size=2> </DIV></FONT>
<DIV><FONT face=Arial size=2>Best
Wishes,<BR>-----------------------------------------------------------------------------<BR>Dongqing
Chen, Ph.D.<BR>Computer Vision & Image Processing (CVIP) Lab<BR>Department
of Electrical & Computer Engineering<BR>Speed School of
Engineering<BR>University of Louisville<BR>Louisville, KY,
40292<BR>U.S.A<BR>email: <A
href="mailto:dqchen@cvip.louisville.edu">dqchen@cvip.louisville.edu</A><BR>phone:
1-502-852-2789
(Lab)<BR>
1-502-852-6130
(Office)<BR>----------------------------------------------------------------------------</FONT></DIV></BODY></HTML>