task_navigator.py 19.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
#--------------------------------------------------------------------------
# Software:     InVesalius - Software de Reconstrucao 3D de Imagens Medicas
# Copyright:    (C) 2001  Centro de Pesquisas Renato Archer
# Homepage:     http://www.softwarepublico.gov.br
# Contact:      invesalius@cti.gov.br
# License:      GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
#--------------------------------------------------------------------------
#    Este programa e software livre; voce pode redistribui-lo e/ou
#    modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
#    publicada pela Free Software Foundation; de acordo com a versao 2
#    da Licenca.
#
#    Este programa eh distribuido na expectativa de ser util, mas SEM
#    QUALQUER GARANTIA; sem mesmo a garantia implicita de
#    COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
#    PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
#    detalhes.
#--------------------------------------------------------------------------

import os
import sys

import serial
import wx
import wx.lib.hyperlink as hl
import wx.lib.masked.numctrl
import wx.lib.platebtn as pbtn
from wx.lib.pubsub import pub as Publisher

import data.bases as db
import data.co_registration as dcr
import project

IR1 = wx.NewId()
IR2 = wx.NewId()
IR3 = wx.NewId()
PR1 = wx.NewId()
PR2 = wx.NewId()
PR3 = wx.NewId()
Neuronavigate = wx.NewId()
Corregistration = wx.NewId()
GetPoint = wx.NewId()

class TaskPanel(wx.Panel):
    """
    This panel works as a "frame", drawing a white margin arround 
    the panel that really matters (InnerTaskPanel).
    """
    def __init__(self, parent):
        # note: don't change this class!!!
        wx.Panel.__init__(self, parent)

        inner_panel = InnerTaskPanel(self)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(inner_panel, 1, wx.EXPAND | wx.GROW | wx.BOTTOM | wx.RIGHT |
                  wx.LEFT, 8)
        sizer.Fit(self)

        self.SetSizer(sizer)
        self.Update()
        self.SetAutoLayout(1)

class InnerTaskPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent, size=wx.Size(320,300))
        self.SetBackgroundColour(wx.Colour(221, 221, 221, 255))
        self.SetAutoLayout(1)
        self.__bind_events()

        self.aux_img_ref1 = 0
        self.aux_img_ref2 = 0
        self.aux_img_ref3 = 0
        self.flagpoint = 0
        self.aux_plh_ref1 = 1
        self.aux_plh_ref2 = 1
        self.aux_plh_ref3 = 1
        self.a = 0, 0, 0
        self.coord1a = (0, 0, 0)
        self.coord2a = (0, 0, 0)
        self.coord3a = (0, 0, 0)
        self.coord1b = (0, 0, 0)
        self.coord2b = (0, 0, 0)
        self.coord3b = (0, 0, 0)
        self.correg = None
                

        self.button_img_ref1 = wx.ToggleButton(self, IR1, label = 'TEI', size = wx.Size(30,23))
        self.button_img_ref1.Bind(wx.EVT_TOGGLEBUTTON, self.Img_Ref_ToggleButton1)
        
        self.button_img_ref2 = wx.ToggleButton(self, IR2, label = 'TDI', size = wx.Size(30,23))
        self.button_img_ref2.Bind(wx.EVT_TOGGLEBUTTON, self.Img_Ref_ToggleButton2)
        
        self.button_img_ref3 = wx.ToggleButton(self, IR3, label = 'FNI', size = wx.Size(30,23))
        self.button_img_ref3.Bind(wx.EVT_TOGGLEBUTTON, self.Img_Ref_ToggleButton3)

        self.button_plh_ref1 = wx.Button(self, PR1, label = 'TEP', size = wx.Size(30,23))
        self.button_plh_ref2 = wx.Button(self, PR2, label = 'TDP', size = wx.Size(30,23))
        self.button_plh_ref3 = wx.Button(self, PR3, label = 'FNP', size = wx.Size(30,23))
        self.button_crg = wx.Button(self, Corregistration, label = 'Corregistrate')
        self.button_getpoint = wx.Button(self, GetPoint, label = 'GP', size = wx.Size(23,23))
        self.Bind(wx.EVT_BUTTON, self.Buttons)
                       
        self.button_neuronavigate = wx.ToggleButton(self, Neuronavigate, "Neuronavigate")
        self.button_neuronavigate.Bind(wx.EVT_TOGGLEBUTTON, self.Neuronavigate_ToggleButton)
        
        self.numCtrl1a = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl1a', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl2a = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl2a', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl3a = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl3a', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl1b = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl1b', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl2b = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl2b', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl3b = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl3b', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl1c = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl1c', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl2c = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl2c', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl3c = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl3c', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl1d = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl1d', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl2d = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl2d', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl3d = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl3d', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl1e = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl1e', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl2e = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl2e', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl3e = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl3e', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl1f = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl1f', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl2f = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl2f', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl3f = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl3f', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl1g = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl1g', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl2g = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl2g', parent=self, integerWidth = 4, fractionWidth = 1)
        self.numCtrl3g = wx.lib.masked.numctrl.NumCtrl(
            name='numCtrl3g', parent=self, integerWidth = 4, fractionWidth = 1)

        RefImg_sizer1 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5)
        RefImg_sizer1.AddMany([ (self.button_img_ref1),
                                (self.numCtrl1a),
                                (self.numCtrl2a),
                                (self.numCtrl3a)])
        
        RefImg_sizer2 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5)
        RefImg_sizer2.AddMany([ (self.button_img_ref2),
                                (self.numCtrl1b),
                                (self.numCtrl2b),
                                (self.numCtrl3b)])
        
        RefImg_sizer3 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5)
        RefImg_sizer3.AddMany([ (self.button_img_ref3),
                                (self.numCtrl1c),
                                (self.numCtrl2c),
                                (self.numCtrl3c)])
        
        RefPlh_sizer1 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5)
        RefPlh_sizer1.AddMany([ (self.button_plh_ref1, 0, wx.GROW|wx.EXPAND),
                                (self.numCtrl1d, wx.RIGHT),
                                (self.numCtrl2d),
                                (self.numCtrl3d, wx.LEFT)])
        
        RefPlh_sizer2 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5)
        RefPlh_sizer2.AddMany([ (self.button_plh_ref2, 0, wx.GROW|wx.EXPAND),
                                (self.numCtrl1e, 0, wx.RIGHT),
                                (self.numCtrl2e),
                                (self.numCtrl3e, 0, wx.LEFT)])
        
        RefPlh_sizer3 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5)
        RefPlh_sizer3.AddMany([ (self.button_plh_ref3, 0, wx.GROW|wx.EXPAND),
                                (self.numCtrl1f, wx.RIGHT),
                                (self.numCtrl2f),
                                (self.numCtrl3f, wx.LEFT)])
        
        Buttons_sizer4 = wx.FlexGridSizer(rows=1, cols=3, hgap=5, vgap=5)
        Buttons_sizer4.AddMany([ (self.button_crg, wx.RIGHT),
                                (self.button_neuronavigate, wx.LEFT)])
        
        GetPoint_sizer5 = wx.FlexGridSizer(rows=1, cols=4, hgap=5, vgap=5)
        GetPoint_sizer5.AddMany([ (self.button_getpoint, 0, wx.GROW|wx.EXPAND),
                                (self.numCtrl1g, wx.RIGHT),
                                (self.numCtrl2g),
                                (self.numCtrl3g, wx.LEFT)])
        
        text = wx.StaticText(self, -1, 'Neuronavigator')
        
        Ref_sizer = wx.FlexGridSizer(rows=9, cols=1, hgap=5, vgap=5)
        Ref_sizer.AddGrowableCol(0, 1)
        Ref_sizer.AddGrowableRow(0, 1)
        Ref_sizer.AddGrowableRow(1, 1)
        Ref_sizer.AddGrowableRow(2, 1)
        Ref_sizer.AddGrowableRow(3, 1)
        Ref_sizer.AddGrowableRow(4, 1)
        Ref_sizer.AddGrowableRow(5, 1)
        Ref_sizer.AddGrowableRow(6, 1)
        Ref_sizer.AddGrowableRow(7, 1)
        Ref_sizer.AddGrowableRow(8, 1)
        Ref_sizer.SetFlexibleDirection(wx.BOTH)
        Ref_sizer.AddMany([ (text, 0, wx.ALIGN_CENTER_HORIZONTAL),
                            (RefImg_sizer1, 0, wx.ALIGN_CENTER_HORIZONTAL),
                            (RefImg_sizer2, 0, wx.ALIGN_CENTER_HORIZONTAL),
                            (RefImg_sizer3, 0, wx.ALIGN_CENTER_HORIZONTAL),
                            (RefPlh_sizer1, 0, wx.ALIGN_CENTER_HORIZONTAL),
                            (RefPlh_sizer2, 0, wx.ALIGN_CENTER_HORIZONTAL),
                            (RefPlh_sizer3, 0, wx.ALIGN_CENTER_HORIZONTAL),
                            (Buttons_sizer4, 0, wx.ALIGN_CENTER_HORIZONTAL),
                            (GetPoint_sizer5, 0, wx.ALIGN_CENTER_HORIZONTAL)])
        
        main_sizer = wx.BoxSizer(wx.HORIZONTAL)
        main_sizer.Add(Ref_sizer, 1, wx.ALIGN_CENTER_HORIZONTAL, 10)
        self.sizer = main_sizer
        self.SetSizer(main_sizer)
        self.Fit()

        tooltip = wx.ToolTip("Pick the coordinates x, y, z in the image")
        self.button_img_ref1.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Pick the coordinates x, y, z in the image")
        self.button_img_ref2.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Pick the coordinates x, y, z in the image")
        self.button_img_ref3.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Pick the coordinates x, y, z in the space")
        self.button_plh_ref1.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Pick the coordinates x, y, z in the space")
        self.button_plh_ref2.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Pick the coordinates x, y, z in the space")
        self.button_plh_ref3.SetToolTip(tooltip)
        tooltip = wx.ToolTip("X Coordinate")
        self.numCtrl1a.SetToolTip(tooltip)
        tooltip = wx.ToolTip("X Coordinate")
        self.numCtrl1b.SetToolTip(tooltip)
        tooltip = wx.ToolTip("X Coordinate")
        self.numCtrl1c.SetToolTip(tooltip)
        tooltip = wx.ToolTip("X Coordinate")
        self.numCtrl1d.SetToolTip(tooltip)
        tooltip = wx.ToolTip("X Coordinate")
        self.numCtrl1e.SetToolTip(tooltip)
        tooltip = wx.ToolTip("X Coordinate")
        self.numCtrl1f.SetToolTip(tooltip)
        tooltip = wx.ToolTip("X Coordinate")
        self.numCtrl1g.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Y Coordinate")
        self.numCtrl2a.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Y Coordinate")
        self.numCtrl2b.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Y Coordinate")
        self.numCtrl2c.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Y Coordinate")
        self.numCtrl2d.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Y Coordinate")
        self.numCtrl2e.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Y Coordinate")
        self.numCtrl2f.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Y Coordinate")
        self.numCtrl2g.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Z Coordinate")
        self.numCtrl3a.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Z Coordinate")
        self.numCtrl3b.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Z Coordinate")
        self.numCtrl3c.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Z Coordinate")
        self.numCtrl3d.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Z Coordinate")
        self.numCtrl3e.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Z Coordinate")
        self.numCtrl3f.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Z Coordinate")
        self.numCtrl3g.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Corregistration of the real position with the image position")
        self.button_crg.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Neuronavigation")
        self.button_neuronavigate.SetToolTip(tooltip)
        tooltip = wx.ToolTip("Get Cross Center Coordinates")
        self.button_getpoint.SetToolTip(tooltip)
        
    def __bind_events(self):
        Publisher.subscribe(self.__update_points_img, 'Update cross position')
        Publisher.subscribe(self.__update_points_plh, 'Update plh position')
         
    def __update_points_img(self, pubsub_evt):
        x, y, z = pubsub_evt.data[1]
        self.a = x, y, z
        if self.aux_img_ref1 == 0: 
            self.numCtrl1a.SetValue(x)
            self.numCtrl2a.SetValue(y)
            self.numCtrl3a.SetValue(z)
        if self.aux_img_ref2 == 0:   
            self.numCtrl1b.SetValue(x)
            self.numCtrl2b.SetValue(y)
            self.numCtrl3b.SetValue(z)
        if self.aux_img_ref3 == 0:
            self.numCtrl1c.SetValue(x)
            self.numCtrl2c.SetValue(y)
            self.numCtrl3c.SetValue(z)

        
    def __update_points_plh(self, pubsub_evt):
        coord = pubsub_evt.data   
        if self.aux_plh_ref1 == 0:    
            self.numCtrl1d.SetValue(coord[0])
            self.numCtrl2d.SetValue(coord[1])
            self.numCtrl3d.SetValue(coord[2])
            self.aux_plh_ref1 = 1
        if self.aux_plh_ref2 == 0:    
            self.numCtrl1e.SetValue(coord[0])
            self.numCtrl2e.SetValue(coord[1])
            self.numCtrl3e.SetValue(coord[2])
            self.aux_plh_ref2 = 1
        if self.aux_plh_ref3 == 0:
            self.numCtrl1f.SetValue(coord[0])
            self.numCtrl2f.SetValue(coord[1])
            self.numCtrl3f.SetValue(coord[2])
            self.aux_plh_ref3 = 1
           
    def Buttons(self, evt):
        id = evt.GetId()
        x, y, z = self.a
        if id == PR1:
            self.aux_plh_ref1 = 0
            self.coord1b = self.Coordinates()
            coord = self.coord1b
        elif id == PR2:
            self.aux_plh_ref2 = 0
            self.coord2b = self.Coordinates()
            coord = self.coord2b
        elif id == PR3:
            self.aux_plh_ref3 = 0
            self.coord3b = self.Coordinates()
            coord = self.coord3b
        elif id == GetPoint:
            x, y, z = self.a
            self.numCtrl1g.SetValue(x)
            self.numCtrl2g.SetValue(y)
            self.numCtrl3g.SetValue(z)
            info = self.a, self.flagpoint
            self.SaveCoordinates(info)
            self.flagpoint = 1 
        elif id == Corregistration and self.aux_img_ref1 == 1 and self.aux_img_ref2 == 1 and self.aux_img_ref3 == 1:
            print "Coordenadas Imagem: ", self.coord1a, self.coord2a, self.coord3a
            print "Coordenadas Polhemus: ", self.coord1b, self.coord2b, self.coord3b
            
            self.M, self.q1, self.Minv = db.Bases(self.coord1a, self.coord2a, self.coord3a).Basecreation()
            self.N, self.q2, self.Ninv = db.Bases(self.coord1b, self.coord2b, self.coord3b).Basecreation()
                
        if self.aux_plh_ref1 == 0 or self.aux_plh_ref2 == 0 or self.aux_plh_ref3 == 0:
            Publisher.sendMessage('Update plh position', coord)         
   
    def Coordinates(self):
        #Get Polhemus points for base creation       
        ser = serial.Serial(0)
        ser.write("Y")       
        ser.write("P")
        str = ser.readline()
        ser.write("Y")
        str = str.replace("\r\n","")
        str = str.replace("-"," -")
        aostr = [s for s in str.split()]
        #aoflt -> 0:letter 1:x 2:y 3:z
        aoflt = [float(aostr[1]), float(aostr[2]), float(aostr[3]),
                  float(aostr[4]), float(aostr[5]), float(aostr[6])]      
        ser.close()
        #Unit change: inches to millimeters
        x = 25.4
        y = 25.4
        z = -25.4

        coord = (aoflt[0]*x, aoflt[1]*y, aoflt[2]*z)
        return coord
    
    def Img_Ref_ToggleButton1(self, evt):
        id = evt.GetId()
        flag1 = self.button_img_ref1.GetValue()
        x, y, z = self.a
        if flag1 == True:
            self.coord1a = x, y, z
            self.aux_img_ref1 = 1
        elif flag1 == False:
            self.aux_img_ref1 = 0
            self.coord1a = (0, 0, 0)
            self.numCtrl1a.SetValue(x)
            self.numCtrl2a.SetValue(y)
            self.numCtrl3a.SetValue(z)
            
    def Img_Ref_ToggleButton2(self, evt):
        id = evt.GetId()
        flag2 = self.button_img_ref2.GetValue()
        x, y, z = self.a
        if flag2 == True:
            self.coord2a = x, y, z
            self.aux_img_ref2 = 1
        elif flag2 == False:
            self.aux_img_ref2 = 0
            self.coord2a = (0, 0, 0)
            self.numCtrl1b.SetValue(x)
            self.numCtrl2b.SetValue(y)
            self.numCtrl3b.SetValue(z)
            
    def Img_Ref_ToggleButton3(self, evt):
        id = evt.GetId()
        flag3 = self.button_img_ref3.GetValue()
        x, y, z = self.a
        if flag3 == True:
            self.coord3a = x, y, z
            self.aux_img_ref3 = 1
        elif flag3 == False:
            self.aux_img_ref3 = 0
            self.coord3a = (0, 0, 0)
            self.numCtrl1c.SetValue(x)
            self.numCtrl2c.SetValue(y)
            self.numCtrl3c.SetValue(z)
      
    def Neuronavigate_ToggleButton(self, evt):
        id = evt.GetId()
        flag4 = self.button_neuronavigate.GetValue()
        bases = self.Minv, self.N, self.q1, self.q2
        if flag4 == True:
            self.correg = dcr.Corregister(bases, flag4)
        elif flag4 == False:
            self.correg.stop()
    
    def SaveCoordinates(self, info):
        #Create a file and write the points given by getpoint's button 
        x, y, z = info[0]
        flag = info[1]

        if flag == 0:
            text_file = open("points.txt", "w")
            line = str('%.2f' %x) + "\t" + str('%.2f' %y) + "\t" + str('%.2f' %z) + "\n"
            text_file.writelines(line)
            text_file.close()
        else:
            text_file = open("points.txt", "r")
            filedata = text_file.read()
            line = filedata + str('%.2f' %x) + "\t" + str('%.2f' %y) + "\t" + str('%.2f' %z) + "\n"
            text_file = open("points.txt", "w")
            text_file.write(line)
            text_file.close()