VRMLImporter.py :  » Game-2D-3D » MayaVi » MayaVi-1.5 » Sources » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » MayaVi 
MayaVi » MayaVi 1.5 » Sources » VRMLImporter.py
"""

This file defines a simple class that handles a vtkVRMLImporter.
The class handles the deletion of the actors generated by the
vtkVRMLImporter.

This code is distributed under the conditions of the BSD license.  See
LICENSE.txt for details.

Copyright (c) 2001-2002, Prabhu Ramachandran.
"""

__author__ = "Prabhu Ramachandran <prabhu_r@users.sf.net>"
__version__ = "$Revision: 1.4 $"
__date__ = "$Date: 2005/08/02 18:30:14 $"

import vtk, Common

debug = Common.debug

class VRMLImporter:
    
    """This is a class that handles a vtkVRMLImporter.  The class
    handles the deletion of the actors generated by the
    vtkVRMLImporter."""

    def __init__ (self, renwin, file_name):        
        """Initializes the class given a vtkRenderWindow and a
        file_name."""
        debug ("In VRMLImporter::__init__ ()")
        self.file_name = file_name
        self.renwin = renwin
        orig_actors = self._get_actors (self.renwin)
        
        self.vrml_imp = vtk.vtkVRMLImporter ()
        self.vrml_imp.SetFileName (file_name)
        self.vrml_imp.SetRenderWindow (self.renwin)
        try:
            self.vrml_imp.ComputeNormalsOn ()
        except AttributeError:
            pass
        self.vrml_imp.Read ()
        self.renwin.Render ()
        final_actors = self._get_actors (self.renwin)

        self.actors = []
        for act in final_actors:
            if act not in orig_actors:
                self.actors.append (act)        

    def __del__ (self):
        debug ("In VRMLImporter::__del__ ()")
        ren = self.vrml_imp.GetRenderer ()
        for act in self.actors:
            ren.RemoveActor (act)
        self.renwin.Render ()
        del self.actors
        del self.vrml_imp
        del self.renwin
    
    def _get_actors (self, rw):        
        """ Returns a list of available actors in the given
        vtkRenderWindow."""        
        debug ("In VRMLImporter::_get_actors ()")
        act = []
        renderers = rw.GetRenderers ()
        renderers.InitTraversal ()
        n_ren = renderers.GetNumberOfItems ()
        for i in range (n_ren):
            ren = renderers.GetNextItem ()
            act.extend (self._get_actor_list (ren))

        return act
    
    def _get_actor_list (self, ren):
        """ Returns a list of available actors in the given
        vtkRenderer."""        
        debug ("In VRMLImporter::_get_actor_list ()")
        act = []
        act_col = ren.GetActors ()
        act_col.InitTraversal ()
        n_act = act_col.GetNumberOfItems ()
        for i in range (n_act):
            act.append (act_col.GetNextItem ())

        return act

    def get_file_name (self):
        """ Returns the VRML file used."""
        debug ("In VRMLImporter::get_file_name ()")
        return self.file_name
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.