[vtkusers] Help on reading VRML file.
David Doria
daviddoria+vtk at gmail.com
Thu Oct 29 17:44:12 EDT 2009
On Thu, Oct 29, 2009 at 7:12 PM, Dongqing Chen
<dqchen at cvip.louisville.edu> wrote:
> Dear All:
> 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.
>
> I post the code patch, anyone could help me?
>
> ---------------------------------------------------------------------------------------------
>
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
>
> #include "vtkVRMLImporter.h"
> #include "vtkDataSet.h"
> #include "vtkActorCollection.h"
> #include "vtkPolyData.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkPolyDataNormals.h"
> #include "vtkActor.h"
>
> #include <iostream>
>
> int main (int argc, char **argv)
> {
>
> // VRML Import
> vtkVRMLImporter *importer=vtkVRMLImporter::New();
> //importer->SetFileName(argv[1]);
> importer->SetFileName(file name);
> importer->Read();
> importer->Update();
>
> //Convert to vtkDataSet
> vtkDataSet *pDataset;
> vtkActorCollection *actors = importer->GetRenderer()->GetActors();
> actors->InitTraversal();
> pDataset = actors->GetNextActor()->GetMapper()->GetInput(); //Problem
> happened here
>
> //Convert to vtkPolyData
> vtkPolyData *polyData = vtkPolyData::SafeDownCast(pDataset);
> polyData->Update();
>
> // Create Normal Vectors to enhance smoothness & illumination
> vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
> normals->SetInput(polyData);
> normals->SetFeatureAngle(60.0);
>
> // Mapper
> vtkPolyDataMapper *SolidMapper = vtkPolyDataMapper::New();
> SolidMapper->SetInput(normals->GetOutput());
> SolidMapper->ScalarVisibilityOff();
>
> // Actor
> vtkActor *SolidActor = vtkActor::New();
> SolidActor->SetMapper(SolidMapper);
> //SolidActor->GetProperty()->SetOpacity(1);
>
> // Render
> vtkRenderer *ren = vtkRenderer::New();
> ren->AddActor(SolidActor);
> ren->SetBackground(1,1,1);
>
> // RenderWindow
> vtkRenderWindow *renWin = vtkRenderWindow::New();
> renWin->AddRenderer(ren);
>
> // RenderWindowInteractor
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow(renWin);
>
> renWin->Start();
> renWin->SetSize(800-5,600-5); // Must be Called after Start() and before
> Render()
> // interact with data
> iren->Initialize();
> iren->Start();
>
> // delete
>
> actors->Delete();
> normals->Delete();
> SolidMapper->Delete();
> SolidActor->Delete();
> ren->Delete();
> renWin->Delete();
> iren->Delete();
>
> return 0;
> }
>
> ----------------------------------------------------------------------------------------------------------------------------------------------
>
> Best Wishes,
> -----------------------------------------------------------------------------
> Dongqing Chen, Ph.D.
> Computer Vision & Image Processing (CVIP) Lab
> Department of Electrical & Computer Engineering
> Speed School of Engineering
> University of Louisville
> Louisville, KY, 40292
> U.S.A
> email: dqchen at cvip.louisville.edu
> phone: 1-502-852-2789 (Lab)
> 1-502-852-6130 (Office)
> ----------------------------------------------------------------------------
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
Dongqing,
Can you please post a dataset somewhere and send us a link?
Thanks,
David
More information about the vtkusers
mailing list