- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/AngioLocalizeNoAuto/MevisLabNoAutoReg/STUMevisApp/Angiolocalize/Modules/Macros/STURegistration/Registration.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 Registration
    00037 #/*!
    00038 # \file    Registration.py
    00039 # \author  DimitreH
    00040 # \date    2009-12-09
    00041 #
    00042 #
    00043 #*/
    00044 #----------------------------------------------------------------------------------
    00045
    00046 from mevis import *
    00047
    00048 ## Global varibles
    00049 source = None
    00050 dest = None
    00051 srcID = 0
    00052 regMatrix = ""
    00053 wind = None
    00054
    00055
    00056 ## initialize some varibles when window pops up
    00057 def initWindow():
    00058   ctx.field("PatientID").setValue(ctx.parent().field("PatientID").value);
    00059   ctx.field("PatientsName").setValue(ctx.parent().field("PatientsName").value);
    00060   ctx.field("PatientsBirthDate").setValue(ctx.parent().field("PatientsBirthDate").value);
    00061   ctx.field("PatientsSex").setValue(ctx.parent().field("PatientsSex").value);
    00062   ctx.field("ImgRegManual.interactive").setValue(False);
    00063   ctx.field("SrcImgLoad.autoLoad").touch();
    00064   ctx.field("TargetImgLoad.autoLoad").touch();
    00065   patientID = getPatientRecordID();
    00066   if (patientID != "0"):
    00067     loadGUILists(patientID);
    00068
    00069 ## cleanUp when windows are closed
    00070 def cleanUp():
    00071   ctx.field("SrcImgLoad.close").touch();
    00072   ctx.field("TargetImgLoad.close").touch();
    00073   cancelonRegManual();
    00074   imgReg = ctx.module("ImgRegManual");
    00075   imgReg.call("closeTransWin");
    00076
    00077 ## get the DB record ID for a patient given MRO number
    00078 def getPatientRecordID():
    00079   patientID = 0;
    00080   if (ctx.field("PatientID").value == ""):
    00081     return str(patientID);
    00082
    00083   queryString = "SELECT PatientID FROM Patients WHERE MRO = " + "'" + ctx.field("PatientID").value + "'";
    00084   result = sendQuery(queryString);
    00085
    00086   if (str(result) != "()"):
    00087     for item in result:
    00088       patientID = item["patientid"];
    00089   return str(patientID);
    00090
    00091 ## send a query to the Database and return the result set
    00092 def sendQuery(query):
    00093   ctx.field("DBConn.Statement").setValue(query);
    00094   dbModule = ctx.module("DBConn");
    00095   result = dbModule.call("sendQuery");
    00096   if (result == -1):
    00097     MLAB.logError("The following query to database failed. \n" + query + "\n.");
    00098   dbModule.call("close");
    00099   return result;
    00100
    00101 ## update Records in GUI
    00102 def updateRecords():
    00103   patientID = getPatientRecordID();
    00104   if (patientID!= "0"):
    00105     loadGUILists(patientID);
    00106
    00107 ## load Image List for a patient
    00108 def loadImageList(patientID):
    00109     imgList = ctx.controlDebug("list3D");
    00110     imgList.clearItems();
    00111     ##init DB
    00112     queryString = "select imageID, modality, seriesDescr from images where imagetype = 2 and patientID = " + patientID + ";";
    00113     result = sendQuery(queryString);
    00114     if (str(result) != "()"):
    00115       for item in result:
    00116         imgName = item["imageid"];
    00117         imgM = item["modality"];
    00118         series = item["seriesdescr"];
    00119         imgList.insertItem([str(imgName), imgM, series]);
    00120
    00121 ## load GUI List
    00122 def loadGUILists(patientID):
    00123     loadImageList(patientID);
    00124     loadRegItem();
    00125
    00126 ## load Registration Items
    00127 def loadRegItem():
    00128     regImage = ctx.controlDebug("registeredImg");
    00129     regImage.clearItems();
    00130     queryString = "select b.affineM as matrix, b.srcImage as src, a.modality as srcM, a.seriesDescr as srcDesc, c.modality as trgM, c.seriesDescr as tgtDesc, b.targetImage as target , d.approvalStatus as status, to_char(d.approvaldate,'YYYY-MM-DD HH12:MI:SS') as savedTime, b.status as genre from images a, regmatrices b, images c, approvals d where b.srcImage = a.imageID and b.targetImage = c.imageID and d.objID = b.matrixID and d.objType = 0 and b.type = 0 and a.patientID = " + getPatientRecordID() + ";"
    00131     result = sendQuery(queryString);
    00132
    00133     if (str(result) != "()"):
    00134       for item in result:
    00135         matrixReg = item["matrix"];
    00136         srcImg = item["src"];
    00137         tgtImg = item["target"];
    00138         srcMod = item["srcm"];
    00139         srcDesc = item["srcdesc"];
    00140         targetMod = item["trgm"];
    00141         targetDesc = item["tgtdesc"];
    00142         statusNum = item["status"];
    00143         approvalDate = item["savedtime"];
    00144         genreNum = item["genre"];
    00145         status = None;
    00146         genre = None;
    00147         if (statusNum == 0):
    00148           status = "false";
    00149         else:
    00150           status = "true";
    00151         if (genreNum == 0):
    00152           genre = "direct";
    00153         else:
    00154           genre = "inferred";
    00155         regImage.insertItem([str(srcImg), srcMod, srcDesc, str(tgtImg), targetMod, targetDesc, status, genre, approvalDate, matrixReg]);
    00156
    00157 ## pop up the context menu
    00158 def selectChanged3D():
    00159    ctx.control("popup3D").popup();
    00160
    00161 ## getImage File Name bsaed on image ID
    00162 def getImageFileName(imgID):
    00163   queryString = "select imageName, imageDir from images where imageID = " + str(imgID);
    00164   result = sendQuery(queryString);
    00165   imgName = None;
    00166   if (str(result) != "()"):
    00167     for item in result:
    00168       imgName = item["imagename"];
    00169   return imgName;
    00170
    00171 ## load Images into either srcImgLoad or TargetImgLoad control
    00172 def loadImage(fileName, srcOrTgt):
    00173   ##srcOrTgt: 1--src   2--target
    00174   image = getImageFileName(fileName);
    00175   fullName = os.path.normpath(image + ".dcm");
    00176   source = os.path.normpath(fullName);
    00177   if (srcOrTgt == 1):
    00178     global srcID;
    00179     srcID = fileName;
    00180     if source != None:
    00181       ctx.field("SrcImgLoad.filename").setValue(source);
    00182     ctx.control("srcLabel").setTitle("Source:" + source);
    00183   else:
    00184     global targetID;
    00185     targetID = fileName;
    00186     if source != None:
    00187       ctx.field("TargetImgLoad.filename").setValue(source);
    00188     ctx.control("targetLabel").setTitle("Target:" + source);
    00189
    00190 ## select 3D As Source
    00191 def select3DAsSource():
    00192   list3D = ctx.control("list3D");
    00193   srcItem = list3D.selectedItem();
    00194   loadImage(srcItem.text(0), 1);
    00195
    00196 ## check if the registration exists given a srcID and target image ID
    00197 def regExist(srcID, targetID):
    00198   queryString = "SELECT matrixID as Num, affineM FROM REGMATRICES WHERE srcImage = " + str(srcID) + " AND targetImage = " + str(targetID) + ";";
    00199   result = sendQuery(queryString);
    00200   if (str(result) == "()"):
    00201     return 0;
    00202   number = 0;
    00203   number = result[0]["num"];
    00204   global regMatrix;
    00205   regMatrix = result[0]["affinem"];
    00206   return number;
    00207
    00208 ## check if 3D-3D image registration exist
    00209 def reg3DExist(srcID, targetID):
    00210   queryString = "SELECT matrixID as Num, affineM, approvalStatus FROM REGMATRICES, approvals WHERE objID = matrixID and objType = 0 and srcImage = " + str(srcID) + " AND type = 0 AND targetImage = " + str(targetID) + ";";
    00211   result = sendQuery(queryString);
    00212   if (str(result) == "()"):
    00213     return 0;
    00214   approval = result[0]["approvalstatus"];
    00215   if (approval == 1):
    00216     return -1;
    00217   number = 0;
    00218   number = result[0]["num"];
    00219   global regMatrix;
    00220   regMatrix = result[0]["affinem"];
    00221   return number;
    00222
    00223 ## once the user selects a 3D image as target, ImageRegManual page will be popped up for registration.
    00224 ## If the registration already exists, user can redo, delete or cancel the registration
    00225 def select3DAsDest():
    00226   redoOp = False;
    00227   list3D = ctx.control("list3D");
    00228   targetItem = list3D.selectedItem();
    00229   loadImage(targetItem.text(0),2);
    00230   global srcID;
    00231   if (regExist(srcID, targetID)):
    00232     answer = MLAB.showQuestion("The Registration already existed. Do you want to redo or delete?", "", "MeVisLab", ["Redo", "Delete", "Cancel"], 0);
    00233     if (answer== 2):
    00234       return;
    00235     elif (answer == 1):
    00236      deleteReg(srcID, targetID);
    00237      return;
    00238     else:
    00239       redoOp = True;
    00240   global regMatrix;
    00241   if (redoOp == False):
    00242     regMatrix = getInitialRegMatrix();
    00243   register(regMatrix);
    00244
    00245 ## do registration with given Src and target Image.
    00246 def register(regMatrix):
    00247   ctx.field("SrcImgLoad.load").touch();
    00248   ctx.field("TargetImgLoad.load").touch();
    00249   ctx.connectField("ImgRegManual.inImage", "SrcImgLoad.output0");
    00250   ctx.connectField("ImgRegManual.inReferenceImage", "TargetImgLoad.output0");
    00251   global wind;
    00252   wind = ctx.showWindow("RegManualW");
    00253   title = "Patient: " + ctx.field("PatientsName").value + "   with MRO: " + ctx.field("PatientID").value + " DOB: " + ctx.field("PatientsBirthDate").value + " " + ctx.field("PatientsSex").value;
    00254   wind.setTitle(title);
    00255   wind.showMaximized();
    00256   setMatrixValues(regMatrix);
    00257
    00258 ## redo the registration
    00259 def redo():
    00260   regList = ctx.control("registeredImg");
    00261   item = regList.selectedItem();
    00262   global targetID;
    00263   global srcID;
    00264   srcID = item.text(0);
    00265   targetID = item.text(3);
    00266   loadImage(item.text(0),1);
    00267   loadImage(item.text(3),2);
    00268   register(item.text(9));
    00269
    00270 ## set the initial values in ImRegManual module
    00271 def setMatrixValues(currentMatrix):
    00272   ctx.field("ImgRegManual.initialAlignMatrix").setStringValue(currentMatrix);
    00273   ctx.field("ImgRegManual.initialAlignMatrix").touch();
    00274   ctx.field("ImgRegManual.MemCache.clear").touch();
    00275   ctx.field("ImgRegManual.MemCache.update").touch();
    00276   ctx.field("ImgRegManual.AngioTransformEdit.reset").touch();
    00277   ctx.field("ImgRegManual.interactive").setBoolValue(False);
    00278   ctx.field("ImgRegManual.reformat.resetMatrix").touch();
    00279
    00280 ## delete the registration from database and file system
    00281 def deleteReg(srcID, targetID):
    00282   query = "select matrixID from regmatrices where srcImage = " + str(srcID) + " AND targetImage = " + str(targetID) + ";";
    00283   result = sendQuery(query);
    00284   if (result == -1):
    00285     return;
    00286   if (str(result) != "()"):
    00287     regToDel = result[0]["matrixid"];
    00288   query = "DELETE FROM REGMATRICES WHERE srcImage = " + str(srcID) + " AND targetImage = " + str(targetID) + ";";
    00289   result = sendQuery(query);
    00290   query = "DELETE FROM APPROVALS WHERE objType = 0 and objID = " + str(regToDel) + ";";
    00291   result = sendQuery(query);
    00292   MLAB.log("The registration between Record ID: " + str(srcID) + " and " + str(targetID) + " has been deleted from database.");
    00293   delete3DReg(ctx.parent().field("PatientID").value, srcID, targetID);
    00294   loadRegItem();
    00295
    00296 ## pop up the context menu
    00297 def selectRegImg():
    00298   ctx.control("popupReg").popup();
    00299
    00300 ## delete the registration from the registered image list
    00301 def delete():
    00302   regList = ctx.control("registeredImg");
    00303   item = regList.selectedItem();
    00304   deleteReg(item.text(0), item.text(3));
    00305
    00306 ## save or update the registration into a file and database and return the record ID in database
    00307 def save3DReg(insertOp, srcID, targetID, status, regS, type):
    00308  saveRegToFile(regS, srcID, targetID, ctx.parent().field("PatientID").value);
    00309  if (insertOp == 1):
    00310    queryS = "INSERT INTO REGMATRICES(srcImage, targetImage, affineM, status, type)values(" + str(srcID) + "," + str(targetID) + ",'" + regS + "'" + "," + str(status) + "," + str(type) + ");";
    00311  else:
    00312    queryS = "UPDATE REGMATRICES set affineM = " + "'" + regS + "'" + ", status = " + str(status) + " where srcImage = " + str(srcID) + " AND targetImage = " + str(targetID) + ";";
    00313  result = sendQuery(queryS);
    00314  if (result == -1):
    00315    return 0;
    00316  query = "select matrixID from regmatrices where type = " + str(type) + " and srcImage = " + str(srcID) + " and targetImage = " + str(targetID) + ";";
    00317  result = sendQuery(query);
    00318  imgID = 0;
    00319  if (str(result) != "()"):
    00320    for item in result:
    00321       imgID = item["matrixid"];
    00322  return imgID;
    00323
    00324 ## Save 2D registration into File and Database
    00325 ## Due to the lack of store procedure support of MevisLab, the database queries are made individually
    00326 ## type is inferred or not.
    00327 def save2DReg(insertOp, srcID, targetID, status, regS, perspect, postAffine, type):
    00328  saveRegToFile(regS, srcID, targetID, ctx.parent().field("PatientID").value);
    00329  if (insertOp == 1):
    00330    queryS = "INSERT INTO REGMATRICES(srcImage, targetImage, affineM, perspectM, postAffineM, status, type)values(" + str(srcID) + "," + str(targetID) + ",'" + regS + "'" + "," + "'" + perspect + "','" + postAffine + "'," + str(status) + "," + str(type) + ");";
    00331  else:
    00332    queryS = "UPDATE REGMATRICES set affineM = " + "'" + regS + "'" + ", perspectM = '" + perspect + "', postAffineM = '" + postAffine + "', status = " + str(status) + " where srcImage = " + str(srcID) + " AND targetImage = " + str(targetID) + ";";
    00333  result = sendQuery(queryS);
    00334  if (result == -1):
    00335    return 0;
    00336  query = "select matrixID from regmatrices where type = " + str(type) + " and srcImage = " + str(srcID) + " and targetImage = " + str(targetID) + ";";
    00337  result = sendQuery(query);
    00338  imgID = 0;
    00339  for item in result:
    00340     imgID = item["matrixid"];
    00341  return imgID;
    00342
    00343 ## get the matrix that can be stored in database.
    00344 ## The final matrix is the multiplication of matrix in reformat and the one in InitialAlignment
    00345 def getFinalMatrix():
    00346   regMatrix = ctx.field("ImgRegManual.regMatrix").stringValue();
    00347   imgRegM = ctx.module("ImgRegManual");
    00348   return imgRegM.call("getFinalMatrix");
    00349
    00350 ## save or update the approval status for a given object(a registration here)
    00351 def saveApprovalStatus(imgID, status, insertOp):
    00352  if (insertOp == 0):
    00353    queryS = "Update APPROVALS SET approvalStatus = " + str(status) + ", approvaldate = now() where UserID = 1 AND objType = 0 AND objID = " + str(imgID) + ";";
    00354  else:
    00355    queryS = "INSERT INTO APPROVALS(userID, objID, objType, patientID, approvalStatus)VALUES(1," + str(imgID) + ", 0 , " + getPatientRecordID() + "," + str(status) + ");";
    00356  ctx.field("DBConn.Statement").setValue(queryS);
    00357  result = sendQuery(queryS);
    00358
    00359 ## get the inverse of a matrix
    00360 def getInversedM(regMatrix):
    00361   ctx.field("ImgRegManual.MatrixArithmetic.matrixA").setStringValue(regMatrix);
    00362   ctx.field("ImgRegManual.MatrixArithmetic.operation").setStringValue("Inverse");
    00363   return ctx.field("ImgRegManual.MatrixArithmetic.outputMatrixC").stringValue();
    00364
    00365 ## multiple regMatrix and Affine Matrix
    00366 def regMultiply(regMatrix, Affine):
    00367   ctx.field("ImgRegManual.MatrixArithmetic.matrixA").setStringValue(regMatrix);
    00368   ctx.field("ImgRegManual.MatrixArithmetic.matrixB").setStringValue(Affine);
    00369   ctx.field("ImgRegManual.MatrixArithmetic.operation").setStringValue("Multiply");
    00370   return ctx.field("ImgRegManual.MatrixArithmetic.outputMatrixC").stringValue();
    00371
    00372 ## propagate the registration to 3D and 2D registration
    00373 def propagateTo2D(targetID, regMatrix, srcID, approvalStatus):
    00374   queryString = "SELECT srcImage, affineM, perspectM, postAffineM, approvalStatus, status FROM REGMATRICES, approvals WHERE objID = matrixID and targetImage = " + str(targetID) + " AND type = 1 " + ";";
    00375   result = sendQuery(queryString);
    00376   if (str(result) == "()"):
    00377     return;
    00378   newTarget = 0;
    00379   for item in result:
    00380      newSrc = item["srcimage"];
    00381      oldApprovalS = item["approvalstatus"];
    00382      Affine = item["affinem"];
    00383      perspect = item["perspectm"];
    00384      postAffine = item["postaffinem"];
    00385      if (newSrc != 0):
    00386        insertOp = 0;
    00387        status = 1; # status is inferred
    00388        newAffine = regMultiply(Affine, regMatrix);
    00389        regS = newAffine.replace("\n", " ");
    00390        if (directRegExist(newSrc, srcID)):
    00391          continue;
    00392        retV = regExist(newSrc, srcID);
    00393        if (retV == 0):
    00394           # means it do not exist
    00395           insertOp = 1;
    00396        newApprovalS = approvalStatus & oldApprovalS;
    00397        regID = save2DReg(insertOp, newSrc, srcID, status, regS, perspect, postAffine, 1);
    00398        saveApprovalStatus(regID, newApprovalS, insertOp);
    00399
    00400 ## propagate the registration to 3D and 3D registration
    00401 ##For example if registration for 3D image 1 and 2 exist, 2 and 3 exist,
    00402 ## we need to infer registration for 1 and 3 and save it into database
    00403 def propagateTo3D(targetID, regMatrix, srcID, approvalStatus):
    00404   queryString = "SELECT targetImage, affineM, approvalStatus, status FROM REGMATRICES, approvals WHERE objID = matrixID and srcImage = " + str(targetID) + " AND type = 0 " + ";";
    00405   result = sendQuery(queryString);
    00406   if (str(result) == "()"):
    00407     return;
    00408   newTarget = 0;
    00409   for item in result:
    00410     newTarget = item["targetimage"];
    00411     oldApprovalS = item["approvalstatus"];
    00412     if (int(newTarget) == int(srcID)):
    00413       continue;
    00414     if(directRegExist(srcID, newTarget)):
    00415         continue;
    00416     Affine = item["affinem"];
    00417     if (newTarget != 0):
    00418       insertOp = 0;
    00419       status = 1; # status is inferred
    00420       newAffine = regMultiply(regMatrix, Affine);
    00421       regS = newAffine.replace("\n", " ");
    00422       ret = regExist(srcID, newTarget);
    00423       if (ret== 0):
    00424          insertOp = 1;
    00425       newApprovalS = approvalStatus & oldApprovalS;
    00426       regID = save3DReg(insertOp, srcID, newTarget, status, regS, 0);
    00427       saveApprovalStatus(regID, newApprovalS, insertOp);
    00428       saveRegToFile(regS, srcID, newTarget,ctx.parent().field("PatientID").value);
    00429        # update the DB now, find the inverse of the reg
    00430       inverseM = getInversedM(newAffine);
    00431       regS = inverseM.replace("\n", " ");
    00432       status = 1; # inferred status for inversed reg
    00433       regID = save3DReg(insertOp, newTarget, srcID, status, regS, 0);
    00434       saveApprovalStatus(regID, newApprovalS, insertOp);
    00435
    00436
    00437 ## This function is to check if the registration exists and is direct
    00438 def directRegExist(srcID, targetID):
    00439   query = "SELECT matrixID from RegMatrices where srcImage = " + str(srcID) + " and targetImage = " + str(targetID) + " and status = 0;"
    00440   result = sendQuery(query);
    00441   if(str(result) != "()"):
    00442     return True;
    00443   query = "SELECT matrixID from RegMatrices, approvals where srcImage = " + str(srcID) + " and targetImage = " + str(targetID) + " and status = 1 and approvals.objID = regmatrices.matrixID and approvals.objType = 0 and approvalStatus = 1;"
    00444   result = sendQuery(query);
    00445   if(str(result) != "()"):
    00446     return True;
    00447   return False;
    00448
    00449 ## the function is called when user clicks "save" button
    00450 def saveOnRegManual():
    00451   saveRegAndApprovalStatus(0);
    00452
    00453 ## the function is called when user clicks "save and approve" button
    00454 def approveOnRegManual():
    00455    saveRegAndApprovalStatus(1);
    00456
    00457 ## the function is called when user clicks "cancel" button
    00458 def cancelonRegManual():
    00459   MLAB.log("The user reviewed the image and canceled.");
    00460   ctx.disconnectField("ImgRegManual.inReferenceImage");
    00461   ctx.disconnectField("ImgRegManual.inImage");
    00462
    00463 ## save the registration and approval status
    00464 def saveRegAndApprovalStatus(status):
    00465    insertOp = 0;
    00466    global srcID;
    00467    global targetID;
    00468    regStatus = 0;
    00469    if (regExist(srcID, targetID) == 0):
    00470      insertOp = 1;
    00471    regMatrix = getFinalMatrix();
    00472    regS1 = regMatrix.replace("\n", " ");
    00473    regID = save3DReg(insertOp, srcID, targetID, regStatus, regS1, 0);
    00474    saveApprovalStatus(regID, str(status), insertOp);
    00475    saveRegToFile(regS1, srcID, targetID,ctx.parent().field("PatientID").value);
    00476    # update the DB now, find the inverse of the reg
    00477    inverseM = getInversedM(regMatrix);
    00478    regS = inverseM.replace("\n", " ");
    00479    if (regExist(targetID, srcID) == 0):
    00480      insertOp = 1;
    00481    else:
    00482       insertOp = 0;
    00483    regID = save3DReg(insertOp, targetID, srcID, regStatus, regS, 0);
    00484    saveApprovalStatus(regID, str(status), insertOp);
    00485    saveRegToFile(regS, targetID, srcID,ctx.parent().field("PatientID").value);
    00486    propagateTo3D(targetID, regS1, srcID, status);
    00487    propagateTo3D(srcID, regS, targetID, status);
    00488
    00489    propagateTo2D(targetID, regS, srcID, status);
    00490    propagateTo2D(srcID, regS1, targetID, status);
    00491    global wind;
    00492    if(wind != None):
    00493      wind.close();
    00494    loadRegItem();
    00495
    00496 ## show Help
    00497 def help():
    00498   ctx.showHtmlHelp();
    00499
    00500 ## get the initial Matrix when there is no registration
    00501 def getInitialRegMatrix():
    00502   im1=ctx.field("TargetImgLoad.output0");
    00503   im2=ctx.field("SrcImgLoad.output0");
    00504   v1=im1.mapVoxelToWorld(im1.size3D());
    00505   v10=im1.mapVoxelToWorld((0,0,0));
    00506   v2=im2.mapVoxelToWorld(im2.size3D());
    00507   v20=im2.mapVoxelToWorld((0,0,0));
    00508   print "1 0 0 "+str(-(v1[0]+v10[0]-v2[0]-v20[0])/2)+" 0 1 0 "+str(-(v1[1]+v10[1]-v2[1]-v20[1])/2)+" 0 0 1 "+str(-(v1[2]+v10[2]-v2[2]-v20[2])/2)+" 0 0 0 1"
    00509   return "1 0 0 "+str(-(v1[0]+v10[0]-v2[0]-v20[0])/2)+" 0 1 0 "+str(-(v1[1]+v10[1]-v2[1]-v20[1])/2)+" 0 0 1 "+str(-(v1[2]+v10[2]-v2[2]-v20[2])/2)+" 0 0 0 1"
    00510 #//# MeVis signature v1
    00511 #//# key: MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANEfsmYse2e1dRhkQ9AQbreCq9uxwzWLoGom13MNYmyfwoJqQOEXljLFAgw2eEjaT12G4CdqKWhRxh9ANP6n7GMCARE=:VI/mB8bT4u+mRtf/ru8yUQi8BzpaS3UeL2x62YxsUYnVqCWuLrVNLiukIIjnJMKQXlc8ezmgOIcVAV7pgvgKpQ==
    00512 #//# owner: MeVis
    00513 #//# date: 2009-06-10T04:12:25
    00514 #//# hash: vHSfj+Qt8xrIkDVP4W0Rep0YH6a3+MySa0+Cs+AoqEK/IbB+f5szwmyVTENOjzz/JEgm2t31FtHmUUMFcQg5VQ==
    00515 #//# MeVis end
    00516

All Classes Namespaces Files Functions Variables Enumerator Friends