- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/AngioLocalizeNoAuto/MevisLabNoAutoReg/STUMevisApp/Angiolocalize/Modules/Macros/AngioLib/AngioLocalizeFileOp.py

    00001 """
    00002 * Copyright (c) 2009 Stanford University, School of Medicine All rights reserved.
    00003 *
    00004 * STANFORD ACADEMIC SOFTWARE LICENSE AGREEMENT
    00005 * FOR AngioLocalize SOURCE CODE:
    00006 *
    00007 * 1.    This is a legal agreement between you, RECIPIENT, and STANFORD UNIVERSITY.
    00008 *       By accepting, receiving, and using AngioLocalize.including any accompanying information, materials or
    00009 *       manuals (Program), you are agreeing to be bound by the terms of this Agreement.
    00010 *       If you do not agree to the terms of this Agreement, promptly return the Program to the STANFORD.
    00011
    00012 * 2.    STANFORD grants to RECIPIENT a royalty-free, nonexclusive, and nontransferable license to use the Program
    00013 *       and accompanying source code furnished hereunder, upon the terms and conditions set out below.
    00014 *       documentation and/or other materials provided with the distribution.
    00015 * 3.    RECIPIENT acknowledges that the Program is a research tool still in the development stage and that
    00016 *       it is being supplied as is, without any accompanying services, support or improvements from STANFORD.
    00017 * 4.    RECIPIENT agrees to use the Program solely for internal non-commercial purposes.
    00018 * 5.    RECIPIENT may create derivatives and further transfer the Program under the following terms and conditions:
    00019 *        A) Recipient agrees to not commercially exploit the Program and agrees all uses will be for non-commercial purposes; and,
    00020 *        B) Recipient may not mark any derivatives with the title of Program and may not to use iPad mark for any derivatives; and,
    00021 *        C) Recipient agrees to mark and acknowledge all derivatives as follows: "This is a derivative work based on AngioLocalize:
    00022 *           Frameless AVM localization with 2D Digital Subtraction Angiography (DSA) and 3D Rotational Angiography (DRA) Images developed
    00023 *           by Dimitre Hristov, Lina Liu.
    00024 *        D) Recipient agrees to make all improvements, enhancements and derivatives available under
    00025 *           similar terms and conditions to the research community.
    00026 * 6.    RECIPIENT warrants that RECIPIENT will not remove or export any part of the software or Program from the United
    00027 *       States except in full compliance with all United States and other applicable laws and regulations.
    00028 * 7.    RECIPIENT will use the Program in compliance with all applicable laws, policies and regulations including, but not
    00029 *       limited to, any approvals, informed consent and patient confidentiality principles.
    00030 * 8.    RECIPIENT will indemnify, hold harmless, and defend Stanford against any claim of any kind arising out of or
    00031 *       related to the exercise of any rights granted under this Agreement or the breach of this Agreement by RECIPIENT.
    00032 * 9.    Title and copyright to the Program and any associated documentation shall at all times remain with STANFORD,
    00033 *       and RECIPIENT agrees to preserve same.
    00034 """
    00035 #----------------------------------------------------------------------------------
    00036 #! Macro module AngioLocalizeFileOp
    00037 #/*!
    00038 # \file    AngioLocalizeFileOp.py
    00039 # \author  lina
    00040 # \date    2009-02-09
    00041 #
    00042 #  This file handles file related operations such as save to a file or load data from file
    00043 #*/
    00044 #----------------------------------------------------------------------------------
    00045 """
    00046 Module AngioLocalizeFileOp.
    00047 """
    00048
    00049 from mevis import *
    00050 import os;
    00051 import shutil;
    00052
    00053 ## save 3D registration to file
    00054 def saveRegToFile(regMatrix, srcID, targetID, patientID):
    00055   saveDir = "C:/MLab2.0UserData";
    00056   if not os.path.isdir(os.path.normpath(saveDir)):
    00057       os.mkdir(os.path.normpath(saveDir), 0777);
    00058   saveDir = saveDir + "/" + patientID;
    00059   if not os.path.isdir(os.path.normpath(saveDir)):
    00060       os.mkdir(os.path.normpath(saveDir), 0777);
    00061   saveDir = saveDir + "/Reg";
    00062   if not os.path.isdir(os.path.normpath(saveDir)):
    00063       os.mkdir(os.path.normpath(saveDir), 0777);
    00064   saveDir = saveDir + "/" + str(srcID) + "-" + str(targetID);
    00065   if not os.path.isdir(os.path.normpath(saveDir)):
    00066     os.mkdir(os.path.normpath(saveDir), 0777);
    00067   fileDir = os.path.normcase(saveDir + "/RegContent");
    00068   f = open(fileDir, 'w');
    00069   f.write(regMatrix);
    00070   MLAB.log("The Registration :" + regMatrix + " has been saved to " + fileDir + " successfully.");
    00071   f.close();
    00072
    00073 ## save Projection registration to file
    00074 def saveProjRegToFile(affineMatrix, perspectMatrix, postAffineM, srcID, targetID, patientID):
    00075   saveDir = "C:/MLab2.0UserData";
    00076   if not os.path.isdir(os.path.normpath(saveDir)):
    00077       os.mkdir(os.path.normpath(saveDir), 0777);
    00078   saveDir = saveDir + "/" + patientID;
    00079   if not os.path.isdir(os.path.normpath(saveDir)):
    00080       os.mkdir(os.path.normpath(saveDir), 0777);
    00081   saveDir = saveDir + "/2D32DReg";
    00082   if not os.path.isdir(os.path.normpath(saveDir)):
    00083       os.mkdir(os.path.normpath(saveDir), 0777);
    00084   saveDir = saveDir + "/" + str(srcID) + "-" + str(targetID);
    00085   if not os.path.isdir(os.path.normpath(saveDir)):
    00086     os.mkdir(os.path.normpath(saveDir), 0777);
    00087   fileDir = os.path.normcase(saveDir + "/RegContent");
    00088   MLAB.log("The matrices" +  affineMatrix + " " + perspectMatrix + " " + postAffineM + " has been saved into file:" + fileDir + ".");
    00089   f = open(fileDir, 'w');
    00090   f.write(affineMatrix);
    00091   f.write("\n");
    00092   f.write(perspectMatrix);
    00093   f.write("\n");
    00094   f.write(postAffineM);
    00095   f.close();
    00096
    00097 ## get Structure directory
    00098 def getCSODir(patientID, fileName):
    00099   saveDir = "C:/MLab2.0UserData";
    00100   if not os.path.isdir(os.path.normpath(saveDir)):
    00101       os.mkdir(os.path.normpath(saveDir), 0777);
    00102   saveDir = saveDir + "/" + patientID;
    00103   if not os.path.isdir(os.path.normpath(saveDir)):
    00104       os.mkdir(os.path.normpath(saveDir), 0777);
    00105   saveDir = saveDir + "/CSO";
    00106   if not os.path.isdir(os.path.normpath(saveDir)):
    00107       os.mkdir(os.path.normpath(saveDir), 0777);
    00108
    00109     # we use the format: "patientID(time).dcm" as unique name for the image
    00110   CSOName = os.path.normpath(saveDir + "/" + fileName);
    00111   return CSOName;
    00112
    00113 ## save the Image to file
    00114 def saveImageToFile(patientID, fileName, type):
    00115   saveDir = "C:/MLab2.0UserData";
    00116   if not os.path.isdir(os.path.normpath(saveDir)):
    00117     os.mkdir(os.path.normpath(saveDir), 0777);
    00118   saveDir = saveDir + "/" + patientID;
    00119   if not os.path.isdir(os.path.normpath(saveDir)):
    00120     os.mkdir(os.path.normpath(saveDir), 0777);
    00121   saveDir = saveDir + "/Images";
    00122   if not os.path.isdir(os.path.normpath(saveDir)):
    00123     os.mkdir(os.path.normpath(saveDir), 0777);
    00124   if type == "/Src" or type == "/Target":
    00125       saveDir = saveDir + type;
    00126       if not os.path.isdir(os.path.normpath(saveDir)):
    00127         os.mkdir(os.path.normpath(saveDir), 0777);
    00128
    00129   ## we use the format: "patientID(time).dcm" as unique name for the image
    00130   imageName = saveDir + "/" + fileName;
    00131   ret =  os.path.normpath(imageName);
    00132   MLAB.log("image to load:" + ret);
    00133   return ret;
    00134
    00135 ## delete 3D registration file
    00136 def delete3DReg(patientID, srcID, targetID):
    00137   regDir = "C:/MLab2.0UserData/" + patientID + "/Reg/" + str(srcID) + "-" + str(targetID);
    00138   regFile = regDir + "/regcontent";
    00139   normalPath = os.path.normpath(regDir);
    00140
    00141   if not os.path.exists(normalPath):
    00142     return;
    00143   os.remove(regFile);
    00144   MLAB.log("Registration file :" + normalPath + " has been deleted. ");
    00145   if os.listdir(regDir) == []:
    00146     os.rmdir(regDir);
    00147
    00148 ## delete 2D 3D registration file
    00149 def delete2D3DReg(patientID, srcID, targetID):
    00150   regDir = "C:/MLab2.0UserData/" + patientID + "/2D3DReg/" + str(srcID) + "-" + str(targetID);
    00151   regFile = regDir + "/regcontent";
    00152   normalPath = os.path.normpath(regDir);
    00153   if not os.path.exists(normalPath):
    00154     return;
    00155   os.remove(regFile);
    00156   MLAB.log("Registration file :" + normalPath + " has been deleted. ");
    00157   if os.listdir(regDir) == []:
    00158     os.rmdir(regDir);
    00159
    00160 ## delete the patient and its images and registrations, CSOs
    00161 def deletePatientInFile(patientID):
    00162   regDir = "C:/MLab2.0UserData/" + patientID;
    00163   if not os.path.exists(regDir):
    00164     return;
    00165   shutil.rmtree(regDir);
    00166
    00167 //# MeVis signature v1
    00168 //# key: MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBAL7SwKNHkHBgB9qUD4diwRQbzCvcmo5tOThuQpDaNbbnER+0rr4pvcNBFPryRY4cWd6PoeyJo5hbomE3XIM5LbsCARE=:aBiq8DiLE2yV5zrB7kV6AaR9N2l9ufzF1dUU9eeV6gX/Bo6rwms1p+87SmalYNHOF2kWEFnNO9FJ5n4BJUVPQg==
    00169 //# owner: STU
    00170 //# date: 2009-08-14T12:07:35
    00171 //# hash: H5Xij0IF2lS4oAEnngWIMNeXG/YQAEF03TxP6jRRIKsILF1ENTMYiM931JDcf0LQXGo++qBPKIG5bWPOXVBYxQ==
    00172 //# MeVis end

All Classes Namespaces Files Functions Variables Enumerator Friends