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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkFEMLoadLandmark.cxx,v $
Language: C++
Date: $Date: 2009-01-30 21:10:18 $
Version: $Revision: 1.16 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
// disable debug warnings in MS compiler
#ifdef _MSC_VER
#pragma warning(disable: 4786)
#endif
#include "itkFEMLoadLandmark.h"
namespace itk {
namespace fem {
/**
* Read a LoadLandmark object from the input stream
*/
void LoadLandmark::Read( std::istream& f, void*)
{
int n1, n2;
vnl_vector<Float> pu;
vnl_vector<Float> pd;
// first call the parent's read function
//Superclass::Read(f,info);
// read the dimensions of the undeformed point and set the size of the point accordingly
this->SkipWhiteSpace(f); f>>n1; if(!f) goto out;
pu.set_size(n1);
this->m_pt.set_size(n1);
// read the undeformed point in global coordinates
this->SkipWhiteSpace(f); f>>pu; if(!f) goto out;
// Read the dimensions of the deformed point and set the size of the point accordingly
this->SkipWhiteSpace(f); f>>n2; if(!f) goto out;
pd.set_size(n2);
m_force.set_size(n2);
// read the deformed point in global coordinates
this->SkipWhiteSpace(f); f>>pd; if(!f) goto out;
m_source = pd;
m_pt = pd;
m_target = pu;
m_force = pu-pd;
//std::cout << m_source << std::endl << m_pt << std::endl << m_target << std::endl << m_force << std::endl;
// read the square root of the variance associated with this landmark
this->SkipWhiteSpace(f); f>>eta; if(!f) goto out;
// Verify that the undeformed and deformed points are of the same size.
if (n1 != n2) { goto out; }
this->el.resize(1);
out:
if( !f )
{
throw FEMExceptionIO(__FILE__,__LINE__,"LoadLandmark::Read()","Error reading landmark load!");
}
}
/**
* Find the Element to which the LoadLandmark belongs
*/
void LoadLandmark::AssignToElement(Element::ArrayType::Pointer elements)
{
bool isFound = false;
// Compute & store the local coordinates of the undeformed point and
// the pointer to the element
for (Element::ArrayType::const_iterator n = elements->begin();
n != elements->end() && !isFound; n++)
{
if ( (*n)->GetLocalFromGlobalCoordinates(m_source, this->m_pt) )
{
isFound = true;
std::cout << "Found: " << (&**n) << std::endl;
this->el[0] = *n;
}
}
if (!isFound)
{
throw FEMException(__FILE__,__LINE__,"LoadLandmark::Read() - could not find element containing landmark!");
}
}
/**
* Write the LoadLandmark object to the output stream
*/
void LoadLandmark::Write( std::ostream& f ) const
{
/** first call the parent's write function */
Superclass::Write(f);
/**
* Write the actual LoadLandmark data
*/
/** Information */
f << "\t% Each vector below is preceded by its size" << std::endl;
/** Write the point coordinates in the undeformed state */
f<<"\t"<<m_pt.size()<<" "<<m_pt<<"\t%Point (local) coordinates, undeformed state"<<"\n";
/** check for errors */
if (!f)
{
throw FEMExceptionIO(__FILE__,__LINE__,"LoadBCMFC::Write()","Error writing FEM load!");
}
}
FEM_CLASS_REGISTER(LoadLandmark)
}} // end namespace itk::fem
|