def interpolate_frames(self, button=None):
        """
        Interpolate between the camera frames, with steps interpolated
        points between each frame.  frames is a sequence of fpu, IPW
        slice positions, where fpu is a (Focal Point, Position,
        ViewUp) tuple

        This routine matches frames to time steps and interpolates a
        frame for each time step.  It does not do the subinterpolation
        between time steps
        """

        self.interpFrames = None
        self.setpars()
        numInPnts = len(self.frames)
        numOutPnts = len(self.steps)*self.entryPerTime.get_value_as_int()

        if numInPnts<2:
            simple_msg('Found only %d input frames' % len(self.frames) ,
                      parent=self)
            return 
        if numOutPnts<2:
            simple_msg('Found only %d time steps' % len(self.steps) ,
                      parent=self)
            return 
        def interpolate_tup3(tups):
            aSplineX = vtk.vtkCardinalSpline()
            aSplineY = vtk.vtkCardinalSpline()
            aSplineZ = vtk.vtkCardinalSpline()

            for i,tup in enumerate(tups):
                x,y,z = tup
                aSplineX.AddPoint(i, x)
                aSplineY.AddPoint(i, y)
                aSplineZ.AddPoint(i, z)

            pnts = []
            for i in range(numOutPnts):
                t = (numInPnts-1.0)/(numOutPnts-1.0)*i
                pnts.append((aSplineX.Evaluate(t),
                             aSplineY.Evaluate(t),
                             aSplineZ.Evaluate(t)))
            return pnts

        fpus, slicePositions = zip(*self.frames)
        fs, ps, us = zip(*fpus)
        
        interpFs = interpolate_tup3(fs)
        interpPs = interpolate_tup3(ps)
        interpUs = interpolate_tup3(us)
        interpFPUs = zip(interpFs,interpPs,interpUs)


        im = self.view3.imageManager
        if im.using_planes():
        
            slicex, slicey, slicez = zip(*slicePositions)

            o, p1, p2 = zip(*slicex)
            interpo = interpolate_tup3(o)
            interpp1 = interpolate_tup3(p1)
            interpp2 = interpolate_tup3(p2)
            interpx = zip(interpo,interpp1,interpp2)

            o, p1, p2 = zip(*slicey)
            interpo = interpolate_tup3(o)
            interpp1 = interpolate_tup3(p1)
            interpp2 = interpolate_tup3(p2)
            interpy = zip(*(interpo,interpp1,interpp2))

            o, p1, p2 = zip(*slicez)
            interpo = interpolate_tup3(o)
            interpp1 = interpolate_tup3(p1)
            interpp2 = interpolate_tup3(p2)
            interpz = zip(interpo,interpp1,interpp2)

            interpSlices = zip(interpx, interpy, interpz)

        else:
            interpSlices = [None]*len(interpFPUs)
        self.interpFrames =  zip(interpFPUs, interpSlices)
        simple_msg('%d frames created; read to play!' % len(self.interpFrames))
Example #2
0
        else:
            loader = self.extmap[ext.lower()]
            try: eeg = loader(fullpath)
            except ValueError, msg:
                msg = exception_to_str('Error loading EEG' )
                error_msg(msg, title='Error loading EEG',
                          parent=self.win)
                return
            else:
                if eeg is None: return 

        print "on_menuFileOpen_activate: eeg ext is ", ext
        if (eeg.get_file_type() != 1): # hack -- .bnis do not need .amp files
            amp = eeg.get_amp()
            if amp.message is not None:
                simple_msg(amp.message, title='Warning',
                           parent=self.win)
            
        #self.load_eeg(eeg)
        
        return False
        

    def main(self):
        # All PyGTK applications must have a gtk.main(). Control ends here
        # and waits for an event to occur (like a key press or mouse event).
        gtk.main()

        

# If the program is run directly or passed as an argument to the python
# interpreter then create a HelloWorld instance and show it