<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.28.3">
</HEAD>
<BODY>
Hi everybody, <BR>
        I have some problems writing in python using vtk. Maybe is only a programmin issue. <BR>
<BR>
I have implemented an extended version of vtkIdList for doing some tasks i need (i am writing a segmentation algorithm for point clouds).<BR>
when i call the Region class from ipyhton everithing works as expected.<BR>
BUT when i create a new istance of the Region class from inside a function it only work when the function is running. If the function return multiple istances of the Region class what i obtain are istances without attributes and functions I added. I really dont understand why!<BR>
I think is a simple python issue (i am not a good programmer).<BR>
<BR>
<BR>
this is my classes:<BR>
<BR>
<FONT SIZE="2">class Region(vtk.vtkIdList):</FONT><BR>
<FONT SIZE="2">        def __init__(self):</FONT><BR>
<FONT SIZE="2">                self.mean_value = 0</FONT><BR>
<FONT SIZE="2">                </FONT><BR>
<FONT SIZE="2">        def GetLastId(self):</FONT><BR>
<FONT SIZE="2">                return self.GetId(self.GetNumberOfIds()-1)</FONT><BR>
<FONT SIZE="2">        </FONT><BR>
<FONT SIZE="2">        def GetFirstId(self):</FONT><BR>
<FONT SIZE="2">                return self.GetId(0)</FONT><BR>
<FONT SIZE="2">                </FONT><BR>
<FONT SIZE="2">        def DeleteLastId(self):</FONT><BR>
<FONT SIZE="2">                self.DeleteId(self.GetId(self.GetNumberOfIds()-1))</FONT><BR>
<FONT SIZE="2">                </FONT><BR>
<FONT SIZE="2">        def IsEmpty(self):</FONT><BR>
<FONT SIZE="2">                '''</FONT><BR>
<FONT SIZE="2">                return 0 if not empty, 1 if there are ids in list</FONT><BR>
<FONT SIZE="2">                '''</FONT><BR>
<FONT SIZE="2">                if self.GetNumberOfIds() == 0:</FONT><BR>
<FONT SIZE="2">                        return 1</FONT><BR>
<FONT SIZE="2">                else:</FONT><BR>
<FONT SIZE="2">                        return 0</FONT><BR>
<FONT SIZE="2">        </FONT><BR>
<FONT SIZE="2">        def ExistId(self, id):</FONT><BR>
<FONT SIZE="2">                '''</FONT><BR>
<FONT SIZE="2">                return 0 if that id is not in list, 1 if exist</FONT><BR>
<FONT SIZE="2">                '''</FONT><BR>
<FONT SIZE="2">                #check if the list is empty, if so the specified id is obviuosly not in list</FONT><BR>
<FONT SIZE="2">                if self.GetNumberOfIds() == 0:</FONT><BR>
<FONT SIZE="2">                        return 0</FONT><BR>
<FONT SIZE="2">                else:</FONT><BR>
<FONT SIZE="2">                        if self.IsId(id) == id:</FONT><BR>
<FONT SIZE="2">                                return 1</FONT><BR>
<FONT SIZE="2">                        else:</FONT><BR>
<FONT SIZE="2">                                return 0</FONT><BR>
<FONT SIZE="2">                                </FONT><BR>
<FONT SIZE="2">        def SetMean(self, value):</FONT><BR>
<FONT SIZE="2">                self.mean_value = value</FONT><BR>
<FONT SIZE="2">                                        </FONT><BR>
<FONT SIZE="2">        def GetMean(self):</FONT><BR>
<FONT SIZE="2">                return self.mean_value</FONT><BR>
<BR>
<BR>
class RegionsContainer(vtk.vtkCollection):<BR>
        def CreateNewRegion(self):<BR>
                number_of_items = self.GetNumberOfItems()<BR>
                new_region = Region()<BR>
                self.AddItem(new_region)<BR>
                return self.GetItemAsObject(number_of_items)<BR>
                <BR>
        def SetAssociatedGrid(self, grid):<BR>
                self.AssociatedGrid = grid<BR>
        <BR>
        def GetAssociatedGrid(self):<BR>
                return self.AssociatedGrid<BR>
        <BR>
        def SetAssociatedArrayOfGrid(self, arrayname):<BR>
                self.AssociatedArrayOfGrid = self.GetAssociatedGrid().GetPointData().GetArray(arrayname)<BR>
                <BR>
        def GetAssociatedArrayOfGrid(self):<BR>
                return self.AssociatedArrayOfGrid<BR>
<BR>
<BR>
in a function i called DoSegmentation i create a RegionContainer:<BR>
&nbsp;&nbsp;&nbsp; <BR>
&nbsp;&nbsp;&nbsp; regions = RegionsContainer()<BR>
<BR>
then, in a while-loop i create multiple istances of my Region class:<BR>
<BR>
&nbsp;&nbsp;&nbsp; current_region = regions.CreateNewRegion()<BR>
<BR>
then the code call some functions on this Region, like this:<BR>
<BR>
&nbsp;&nbsp;&nbsp; current_region.SetMean(current_mean)        <BR>
<BR>
at the end my function returns the variable 'regions' that contain multiple istances of the class Region()<BR>
BUT, when i try to have acces to the items contained, with;<BR>
<BR>
&nbsp;&nbsp;&nbsp; regions.GetItemAsObject(n)<BR>
<BR>
i have only a vtkIdList as return, and not my Region() class<BR>
<BR>
&nbsp;&nbsp;&nbsp; if i try regions.GetItemAsObject(n).GetMean()<BR>
<BR>
it raise an attribute error!!<BR>
<BR>
<BR>
anybody could spent some minutes and have a look at this code??<BR>
I think I made a mistake, but i dont know where...<BR>
Thank you!!

<br>
<br>
<br><p><font face="Verdana,Arial" size=2>----<br>
Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? <a href=http://www.email.it/cgi-bin/start?sid=3 target=_blank>GRATIS solo con Email.it</a><br>
<br>
Sponsor:<br>
Ultime 2 stanze dal 18 al 25 luglio con offerta speciale aquafan e oltremare per 4 giorni all'hotel Poker, 3 stelle, di Riccione<br>
<a href=http://adv.email.it/cgi-bin/foclick.cgi?mid=10633&d=3-7 target=_blank>Clicca qui</a></font><br>

<br>
</BODY>
</HTML>