19 #include "itkPSMProject.h" 25 const std::string PSMProject::correspondences_tag =
"correspondences";
26 const std::string PSMProject::cutting_plane_tag =
"cutting_plane";
28 const std::string PSMProject::distance_transform_tag =
"distance_transform";
29 const std::string PSMProject::distance_transforms_tag =
"distance_transforms";
30 const std::string PSMProject::domain_tag =
"domain";
31 const std::string PSMProject::model_tag =
"model";
32 const std::string PSMProject::name_tag =
"name";
33 const std::string PSMProject::optimization_tag =
"optimization";
34 const std::string PSMProject::number_of_scales_tag =
"number_of_scales";
35 const std::string PSMProject::psm_project_tag =
"psm_project";
36 const std::string PSMProject::preprocessing_tag =
"preprocessing";
37 const std::string PSMProject::procrustes_tag =
"procrustes_registration";
38 const std::string PSMProject::scale_tag =
"scale";
39 const std::string PSMProject::scale_number_tag =
"number";
40 const std::string PSMProject::variables_tag =
"variables";
44 if (dom->GetName() == psm_project_tag)
50 itkExceptionMacro(
"DOM object does not appear to contain a valid PSM Project file." );
61 DOMNode::ConstChildrenListType domains;
62 data->GetChildren(domain_tag, domains);
65 if (domains.size() == 0)
80 DOMNode::ConstChildrenListType domains;
81 data->GetChildren(domain_tag, domains);
83 for (
unsigned int i = 0; i < domains.size(); i++)
86 if (domains[i]->HasAttribute(name_tag))
88 if (domains[i]->GetAttribute(name_tag) == name)
96 itkExceptionMacro(
"Could not find a domain called " + name );
105 const DOMNode *dt = domain->GetChild(distance_transform_tag);
122 const DOMNode *dt = domain->GetChild(distance_transform_tag);
126 itkExceptionMacro(
"No distance transform filename was found in the domain called " + name +
" ");
129 return ((dynamic_cast<const PSMDOMNode *>(dt))->GetText());
132 std::vector<std::string>
138 DOMNode::ConstChildrenListType domains;
139 data->GetChildren(domain_tag, domains);
142 if (domains.size() == 0)
144 itkExceptionMacro(
"PSM Project file does not specify any elements called " + domain_tag );
147 std::vector<std::string> s;
150 for (
unsigned int i = 0; i < domains.size(); i++)
152 if (domains[i]->HasAttribute(name_tag))
154 s.push_back(domains[i]->GetAttribute(name_tag));
158 itkExceptionMacro(
"The name attribute is missing from a PSM Project file" + model_tag +
".");
170 DOMNode::ConstChildrenListType p;
171 domain->GetChildren(cutting_plane_tag, p);
184 std::vector<vnl_vector_fixed<double,3> >
PSMProject 190 DOMNode::ConstChildrenListType p;
191 domain->GetChildren(cutting_plane_tag, p);
198 itkExceptionMacro(
"Did not find cutting planes in domain " + name +
" ");
201 std::vector<vnl_vector_fixed<double,3> > planes;
203 for (
unsigned int i = 0; i < p.size(); i++)
205 std::istringstream inputsBuffer;
206 std::vector<double> pts;
209 std::vector<std::string> txt
210 =
dynamic_cast<const PSMDOMNode *
>(p[i])->GetText();
211 for (
unsigned int j = 0; j < txt.size(); j++)
213 inputsBuffer.str(txt[j]);
215 while (inputsBuffer >> pt)
216 { pts.push_back(pt); }
218 inputsBuffer.clear();
225 itkExceptionMacro(
"Cutting plane data for " + name +
" does not consist of three points.");
228 vnl_vector_fixed<double,3> x;
229 vnl_vector_fixed<double,3> y;
230 vnl_vector_fixed<double,3> z;
231 x[0] = pts[0]; x[1] = pts[1]; x[2] = pts[2];
232 y[0] = pts[3]; y[1] = pts[4]; y[2] = pts[5];
233 z[0] = pts[6]; z[1] = pts[7]; z[2] = pts[8];
247 DOMNode *opt = m_DOMNode->GetChild(optimization_tag);
251 if (opt->HasAttribute(number_of_scales_tag))
253 return static_cast<unsigned int>(atoi(opt->GetAttribute(number_of_scales_tag).c_str()));
257 itkExceptionMacro(
"Number of scales not specified");
261 itkExceptionMacro(
"No " + optimization_tag +
" was found.");
267 DOMNode *opt = m_DOMNode->GetChild(optimization_tag);
270 unsigned int nscales = 1;
273 if (opt->HasAttribute(number_of_scales_tag))
275 nscales =
static_cast<unsigned int>(atoi(opt->GetAttribute(number_of_scales_tag).c_str()));
277 if(name == number_of_scales_tag) {
return true; }
281 if (s+1 > nscales) {
return false; }
286 if (opt->HasAttribute(name)) {
return true; }
290 DOMNode::ChildrenListType children;
291 opt->GetAllChildren(children);
293 for (
unsigned i = 0; i < children.size(); i++)
295 if ( children[i]->GetName() == scale_tag
297 static_cast<unsigned int>(atoi(children[i]->GetAttribute(scale_number_tag).c_str())) == s )
299 if (children[i]->HasAttribute(name)) {
return true; }
300 else {
return false; }
310 DOMNode *opt = m_DOMNode->GetChild(optimization_tag);
313 unsigned int nscales = 1;
316 if (opt->HasAttribute(number_of_scales_tag))
318 nscales =
static_cast<unsigned int>(atoi(opt->GetAttribute(number_of_scales_tag).c_str()));
324 itkExceptionMacro(
"Requested data for scale that was not specified.");
330 if (opt->HasAttribute(name))
332 return atof(opt->GetAttribute(name).c_str());
337 DOMNode::ChildrenListType children;
338 opt->GetAllChildren(children);
340 for (
unsigned i = 0; i < children.size(); i++)
342 if ( children[i]->GetName() == scale_tag
344 static_cast<unsigned int>(atoi(children[i]->GetAttribute(scale_number_tag).c_str())) == s )
346 if (children[i]->HasAttribute(name))
348 return atof(children[i]->GetAttribute(name).c_str());
352 itkExceptionMacro(
"Found " + scale_tag +
" element, but it does not have an attribute named " + name +
".");
357 itkExceptionMacro(
"File has no " + optimization_tag +
" element");
362 DOMNode *proc = m_DOMNode->GetChild(procrustes_tag);
365 if (proc->HasAttribute(
"value"))
367 if (atoi(proc->GetAttribute(
"value").c_str()) == 0)
381 DOMNode::ConstChildrenListType variables;
382 data->GetChildren(variables_tag, variables);
384 if (variables.size() == 0)
390 for (
unsigned int i = 0; i < variables.size(); i++)
392 if (variables[i]->HasAttribute(name_tag))
394 if (variables[i]->GetAttribute(name_tag) == name)
409 std::vector<double> ans;
410 for (
unsigned int i = 0; i < vartext.size(); i++)
412 ans.push_back(atof(vartext[i].c_str()));
422 DOMNode::ConstChildrenListType variables;
423 data->GetChildren(variables_tag, variables);
425 if (variables.size() == 0)
427 itkExceptionMacro(
"PSM Project file does not have any " + variables_tag +
" entries with name = " << name );
431 for (
unsigned int i = 0; i < variables.size(); i++)
433 if (variables[i]->HasAttribute(name_tag))
435 if (variables[i]->GetAttribute(name_tag) == name)
437 return ((dynamic_cast<const PSMDOMNode *>(variables[i]))->GetText());
441 itkExceptionMacro(
"PSM Project file does not have any " + variables_tag +
" entries with name = " << name );
452 itkExceptionMacro(
"PSM Project file does not specify " +
data_tag );
460 const std::vector<std::string> &
467 dt =
static_cast<const PSMDOMNode *
>(data->GetChild(distance_transforms_tag));
470 itkExceptionMacro(
"PSM Project file does not specify " + distance_transforms_tag );
476 const std::vector<std::string> &
482 DOMNode::ConstChildrenListType models;
483 data->GetChildren(model_tag, models);
485 if (models.size() == 0)
487 itkExceptionMacro(
"PSM Project file does not specify any elements called " + model_tag );
491 for (
unsigned int i = 0; i < models.size(); i++)
493 if (models[i]->HasAttribute(name_tag))
495 if (models[i]->GetAttribute(name_tag) == name)
497 return ((dynamic_cast<const PSMDOMNode *>(models[i]))->GetText());
501 itkExceptionMacro(
"PSM Project file does not have any " + model_tag +
" entries with name = " << name );
510 DOMNode::ConstChildrenListType models;
511 data->GetChildren(model_tag, models);
513 if (models.size() == 0)
519 for (
unsigned int i = 0; i < models.size(); i++)
521 if (models[i]->HasAttribute(name_tag))
523 if (models[i]->GetAttribute(name_tag) == name)
533 void PSMProject::PrintSelf(std::ostream& os, Indent indent)
const 535 Superclass::PrintSelf(os,indent);
550 os << indent <<
"<" << node->GetName();
552 DOMNode::AttributesListType attr;
553 node->GetAllAttributes(attr);
555 for (DOMNode::AttributesListType::const_iterator it = attr.begin();
556 it != attr.end(); it++)
558 os <<
" " << it->first <<
" = \"" << it->second <<
"\"";
562 os <<
">" << std::endl;
565 for (
unsigned int i = 0; i < node->
GetText().size(); i++)
567 os << indent.GetNextIndent() << node->
GetText()[i] << std::endl;
570 DOMNode::ChildrenListType children;
571 node->GetAllChildren(children);
574 for (
unsigned i = 0; i < children.size(); i++)
577 os,indent.GetNextIndent());
581 os << indent <<
"<\\" << node->GetName() <<
">" << std::endl;
static const std::string data_tag
bool HasDomainCuttingPlanes(const std::string &name) const
const std::vector< std::string > & GetVariablesText(const std::string &name) const
const std::vector< std::string > & GetText() const
bool HasVariables(const std::string &name) const
const PSMDOMNode * GetDataNode() const
bool HasProcrustes() const
bool HasDomainDistanceTransform(const std::string &name) const
void SetDOMNode(PSMDOMNode *p)
std::vector< double > GetVariables(const std::string &name) const
std::vector< vnl_vector_fixed< double, 3 > > GetDomainCuttingPlanes(const std::string &name) const
Class to represent a node in the PSM Document Object Model (DOM) tree structure.
const std::vector< std::string > & GetDomainDistanceTransform(const std::string &name) const
bool HasOptimizationAttribute(const std::string &name, unsigned int i=0) const
const std::vector< std::string > & GetModel(const std::string &name)
void StreamChildren(PSMDOMNode *, std::ostream &os, Indent indent)
const DOMNode * GetDomainNode(const std::string &name) const
void Stream(std::ostream &os)
const std::vector< std::string > & GetDistanceTransforms() const
double GetOptimizationAttribute(const std::string &name, unsigned int i=0) const
unsigned int GetNumberOfOptimizationScales() const
std::vector< std::string > GetDomainNames() const
bool HasModel(const std::string &name) const