- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/AngioLocalizeNoAuto/MevisLabNoAutoReg/STUMevisApp/Angiolocalize/Sources/ML/STUPerspectiveTransformation/mlPerspectiveTransformation.cpp

Go to the documentation of this file.

    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 //----------------------------------------------------------------------------------
    00037
    00044 //----------------------------------------------------------------------------------
    00045
    00046 // Local includes
    00047 #include "mlPerspectiveTransformation.h"
    00048
    00049 ML_START_NAMESPACE
    00050
    00051
    00053 ML_BASEOP_CLASS_SOURCE(PerspectiveTransformation, BaseOp);
    00054
    00055 //----------------------------------------------------------------------------------
    00057 //----------------------------------------------------------------------------------
    00058 PerspectiveTransformation::PerspectiveTransformation ()
    00059   : BaseOp(0, 0)
    00060 {
    00061   ML_TRACE_IN("PerspectiveTransformation::PerspectiveTransformation ()");
    00062
    00063   // Suppress calls of handleNotification on field changes to
    00064   // avoid side effects during initialization phase.
    00065   handleNotificationOff();
    00066
    00068   FieldContainer &fields = *getFieldContainer();
    00069
    00070   ML_CHECK(&fields);
    00071
    00073  /*_inputCSOStringFld = fields.addString("inputCSOString");
    00074
    00075   _copySelectedCSOsFld = fields.addBool("copySelectedCSOs");
    00076   _copySelectedCSOsFld->setBoolValue(true);
    00077
    00078   _copiedCSOIdsFld = fields.addString("copiedCSOIds");*/
    00079
    00080   _matrixFld = fields.addMatrix("matrix");
    00081   _matrixFld->setStringValue("1 0 0 0 0 1 0 0 0 0 0 1 0 0 -1 0");
    00082
    00083   _useCreatorIdFld = fields.addBool("useCreatorId");
    00084   _useCreatorIdFld->setBoolValue(false);
    00085
    00086   _creatorIdFld = fields.addInt("creatorId");
    00087   _creatorIdFld->setIntValue(0);
    00088
    00089   _targetGroupFld = fields.addString("targetGroup");
    00090
    00091   _autoApplyFld = fields.addBool("autoApply");
    00092   _autoApplyFld->setBoolValue(false);
    00093
    00094   _applyFld = fields.addNotify("apply");
    00095
    00096   static const char * const enumNames[2] = {
    00097     "Off",
    00098     "Auto Update"
    00099   };
    00100
    00101   (_updateModeFld = fields.addEnum("updateMode", enumNames, 2))->setEnumValue(0);
    00102
    00103   //_workDirectlyOnInputListFld = fields.addBool("workDirectlyOnInputList");
    00104
    00105   (_inListFld = fields.addBase("inCSOList"))->setBaseValue(NULL);
    00106
    00107   // Generate field for marker list object.
    00108   _outListFld = fields.addBase("outCSOList");
    00109
    00110   _inputList = NULL;
    00111   _outputList = NULL;
    00112   // Link marker list field to internal marker list object.
    00113   _outListFld->setBaseValue(NULL);
    00114
    00115   (_listenToRepaintNotificationsFld          = fields.addBool("listenToRepaintNotifications"))
    00116     ->setBoolValue(false);
    00117   (_listenToFinishingNotificationsFld        = fields.addBool("listenToFinishingNotifications"))
    00118     ->setBoolValue(true);
    00119   (_listenToSelectionNotificationsFld       = fields.addBool("listenToSelectionNotifications"))
    00120     ->setBoolValue(true);
    00121
    00122   // Connect input fields with output field to update connected
    00123   // modules if input images change.
    00124   for (int inIdx=0; inIdx < 0; ++inIdx){
    00125     for (int outIdx=0; outIdx < 0; ++outIdx){
    00126       getInField(inIdx)->attachField(getOutField(outIdx));
    00127     }
    00128   }
    00129   // Reactivate calls of handleNotification on field changes.
    00130   handleNotificationOn();
    00131
    00132   // Activate inplace data buffers for output outIndex and input inIndex.
    00133   // setOutImgInplace(outIndex, inIndex);
    00134
    00135   // Activate page data bypass from input inIdx to output outIdx.
    00136   // Note that the module must still be able to calculate the output image.
    00137   // setBypass(outIndex, inIndex);
    00138
    00139   // Activate parallel execution of calcOutSubImage.
    00140   // setThreadSupport(supportMode);
    00141   // with supportMode =
    00142   //   NO_THREAD_SUPPORT                 //! The module is not thread safe at all.
    00143   //   CALC_OUTSUBIMAGE_ON_STD_TYPES     //! calcOutSubImage can be called in parallel for scalar voxel types.
    00144   //   CALC_OUTSUBIMAGE_ON_CARRIER_TYPES //! calcOutSubImage can be called in parallel for carrier voxel types.
    00145   //   CALC_OUTSUBIMAGE_ON_ALL_TYPES     //! calcOutSubImage can be called in parallel for all voxel types.
    00146   // Warning: You should be familiar with multithreading before activating this feature.
    00147
    00148   // Specify whether the module can only process standard scalar voxel types or
    00149   // also registered voxel types (vec2, mat2, complexf, Vector, etc.)
    00150   // setVoxelDataTypeSupport(permittedTypes);
    00151   // with permittedTypes =
    00152   //   ONLY_STANDARD_TYPES               //! Only standard scalar voxels are supported.
    00153   //   FULLY_OPERATIONAL                 //! Scalar and registered voxels types are supported.
    00154   //   MINIMUM_OPERATIONAL               //! Scalar and registered voxel types are supported.
    00155   //                                     //! Voxel operators are not used by algorithm.
    00156   //
    00157   // See ML Programming Guide, "Configuring Image Processing Behaviour of the BaseOp"
    00158   // for further details.
    00159 }
    00160
    00161 //----------------------------------------------------------------------------------
    00164 //----------------------------------------------------------------------------------
    00165 void    PerspectiveTransformation::transform (const mat4& matrix)
    00166 {
    00168         if (_inputList == NULL) {
    00169                 _outListFld->setBaseValue(NULL);
    00170                 return;
    00171         }
    00172
    00173         _outList = new CSOList(*_inputList);
    00175         //  and put the result in it.
    00176         /*if (_workDirectlyOnInputListFld->getBoolValue() == false) {
    00177                 _outList = new CSOList(*_inputList);
    00178         } else {
    00179                 _outList = _inputList;
    00180         }*/
    00182         std::string groupName = this->_targetGroupFld->getStringValue();
    00183         CSOGroup* group = NULL;
    00184         if ( groupName!= "") {
    00185                 group = _outList->addGroup();
    00186                 group->setLabel(groupName);
    00187         }
    00188
    00190         int userID = 0;
    00191         if (_useCreatorIdFld->getBoolValue() == true) {
    00192                 userID = _creatorIdFld->getIntValue();
    00193         }
    00194
    00195         for (unsigned int i = 0; i < _outList->numCSO(); i++) {
    00196                 CSO* cso = _outList->getCSOAt(i);
    00197                 if (group) {
    00198                         group->addCSO(cso);
    00199                 }
    00200                 if (userID != 0) {
    00201                         cso->setCreatorId(_creatorIdFld->getIntValue());
    00202                 }
    00203                 for (unsigned int j = 0; j < cso->numPathPointLists(); j ++) {
    00204                         CSOPathPoints *point = cso->getPathPointsAt(j);
    00205                         std::vector<vec3>  positions;
    00206                         point->getWorldPositions(positions);
    00207                         for (unsigned int m = 0; m < positions.size(); m++) {
    00208                                 //apply matrix here for each position in world coordinate
    00209                                 //positions[m] = (positions[m] * matrix).divideByLastComp();
    00210                                 positions[m] = (Tvec3<double>(matrix * positions[m].affinePoint(), true)).divideByLastComp();
    00211                         }
    00212                         point->setWorldPositions(positions);
    00213                 }
    00214         }
    00215         _outListFld->setBaseValue(_outList);
    00216 }
    00217
    00219 //----------------------------------------------------------------------------------
    00220 void PerspectiveTransformation::handleNotification (Field *field)
    00221 {
    00222   ML_TRACE_IN("perspectiveTransformation::handleNotification ()")
    00223
    00224
    00225   if (_updateModeFld->getEnumValue() == 1 || _autoApplyFld->getBoolValue() == true ||
    00226       field == _applyFld || field == _inListFld){
    00227
    00228     if (!_isInNotificationCB) {
    00229                 CSOList::removeNotificationObserverFromAllCSOLists(_csoListNotificationCB, this);
    00230         }
    00231
    00232     if (ML_BASE_IS_A((static_cast<Base*>(_inListFld->getBaseValue())), CSOList)){
    00233
    00234       _inputList = static_cast<CSOList*>(_inListFld->getBaseValue());
    00235
    00236       if (_inputList != NULL){
    00237
    00238         if (!_isInNotificationCB) {
    00239                         _inputList->addNotificationObserver(_csoListNotificationCB, this);
    00240                 }
    00241       }
    00242         } else {
    00243       _inputList = NULL;
    00244         }
    00246         transform(_matrixFld->getMatrixValue());
    00247   }
    00248
    00250   BaseOp::handleNotification(field);
    00251
    00252 }
    00253
    00254 //----------------------------------------------------------------------------------
    00256 //----------------------------------------------------------------------------------
    00257 void PerspectiveTransformation::activateAttachments ()
    00258 {
    00259   ML_TRACE_IN("perspectiveTransformation::activateAttachments ()")
    00260
    00261
    00262
    00263   BaseOp::activateAttachments ();
    00264 }
    00265
    00266
    00267 void PerspectiveTransformation::_csoListNotificationCB(void* userData, int notificationFlag)
    00268 {
    00269   ML_TRACE_IN("void perspectiveTransformation::_csoListNotificationCB()");
    00270
    00271   PerspectiveTransformation* thisp = static_cast<PerspectiveTransformation*>(userData);
    00272
    00273   thisp->_isInNotificationCB = true;
    00274
    00275   if ((notificationFlag & CSOList::NOTIFICATION_CSO_SELECTION) ||
    00276       (notificationFlag & CSOList::NOTIFICATION_GROUP_SELECTION))
    00277   {
    00278           if (thisp->_updateModeFld->getEnumValue() == 1 &&
    00279                   thisp->_listenToSelectionNotificationsFld->getBoolValue()){
    00280         thisp->transform(thisp->_matrixFld->getMatrixValue());
    00281       }
    00282   }
    00283   if ((notificationFlag & CSOList::NOTIFICATION_CSO_FINISHED) ||
    00284       (notificationFlag & CSOList::NOTIFICATION_GROUP_FINISHED))
    00285   {
    00286           if (thisp->_updateModeFld->getEnumValue() == 1 &&
    00287                   thisp->_listenToFinishingNotificationsFld->getBoolValue()){
    00288         thisp->transform(thisp->_matrixFld->getMatrixValue());
    00289       }
    00290   }
    00291   if (notificationFlag & CSOList::NOTIFICATION_REPAINT){
    00292           if (thisp->_updateModeFld->getEnumValue() == 1 &&
    00293                   thisp->_listenToRepaintNotificationsFld->getBoolValue()){
    00294       thisp->transform(thisp->_matrixFld->getMatrixValue());
    00295     }
    00296   }
    00297
    00298   thisp->_isInNotificationCB = false;
    00299 }
    00300
    00301 ML_END_NAMESPACE
    00302

All Classes Namespaces Files Functions Variables Enumerator Friends