Commit d2c08b49 authored by sarrazij's avatar sarrazij
Browse files

UPDATED add a stopping criteria based on time and precision

UPDATED Volume can now be computed with a target

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@2282 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 9a3e4e11
......@@ -46,6 +46,7 @@ set(monitoring_H MMLAPI.h
OrMultipleCriterion.h
MinThreshold.h
Threshold.h
TimePeriodThreshold.h
Simulator.h
NonInteractiveSimulator.h
InteractiveSimulator.h
......@@ -103,6 +104,7 @@ set(monitoring_SRCS ${monitoring_H}
OrMultipleCriterion.cpp
MinThreshold.cpp
Threshold.cpp
TimePeriodThreshold.cpp
Simulator.cpp
NonInteractiveSimulator.cpp
InteractiveSimulator.cpp
......
......@@ -40,6 +40,8 @@ Method* MethodFactory::createMethod(mml::Method& m) {
return (new Threshold((mml::Threshold*)&m));
} else if (dynamic_cast<mml::MinThreshold*>(&m)) {
return (new MinThreshold((mml::MinThreshold*)&m));
} else if (dynamic_cast<mml::TimePeriodThreshold*>(&m)) {
return (new TimePeriodThreshold((mml::TimePeriodThreshold*)&m));
} else {
std::cerr << "Method type error: unknown method" << std::endl;
return NULL;
......
......@@ -32,6 +32,7 @@
#include "Method.h"
#include "Threshold.h"
#include "MinThreshold.h"
#include "TimePeriodThreshold.h"
/**
*
* @ingroup group_cepmodeling_libraries_mml
......
......@@ -77,7 +77,7 @@ public:
/// calculate current followed data and store them in values vector
virtual void calculate()=0;
/// write data stored in values vector into mmlOut file
void write();
virtual void write();
int getIndex();
double getStartAt();
......
......@@ -24,6 +24,7 @@
****************************************************************************/
// Monitor includes
#include "MonitorVolume.h"
#include <iostream>
// -------------------- constructor --------------------
MonitorVolume::MonitorVolume(mml::Monitor* m,MonitoringManager* monitoringManager): Monitor(m,monitoringManager,SCALAR) {}
......@@ -56,4 +57,15 @@ std::string MonitorVolume::getTypeName() {
return "Volume";
}
// -------------------- write --------------------
void MonitorVolume::write(){
// write data
std::string s = "";
for (unsigned int i = 0; i < values.size(); i++) {
std::ostringstream ss;
ss << values[i];
s = s + ss.str() + " ";
}
mappedObject->data(s);
}
......@@ -51,6 +51,8 @@ public:
/// return a string relative to monitor type
std::string getTypeName();
virtual void write();
};
#endif // MONITOR_MONITORS_MONITORVOLUME_H
......@@ -27,11 +27,15 @@
#include "Position.h"
// Stopping criteria includes
#include "Tools.h"
#include "AtomIterator.h"
#include <iostream>
// -------------------- constructor --------------------
Position::Position(mml::Position* c,MonitoringManager* monitoringManager, MultipleCriterion* parent): Criterion(c,monitoringManager,parent) {
target=c->target().get();
switch (c->unit()) {
case mml::PositionUnit::nm:
factor = 1000000;
......@@ -56,9 +60,13 @@ void Position::calculate() {
double pos[3];
double posOld[3];
// Iteration over all atoms
for (unsigned int i = 0; i < pml->getAtoms()->getNumberOfStructures(); i++) {
int index =pml->getAtoms()->getStructure(i)->getIndex();
pml->getAtom(index)->getPosition(pos);
AtomIterator it=AtomIterator(monitoringManager->getPml(),target);
for (it.begin(); !it.end(); it.next()) {
//for (unsigned int i = 0; i < pml->getAtoms()->getNumberOfStructures(); i++) {
int index = it.currentAtom()->getIndex();
//int index =pml->getAtoms()->getStructure(i)->getIndex();
it.currentAtom()->getPosition(pos);
//pml->getAtom(index)->getPosition(pos);
monitoringManager->getOldPosition(posOld,index);
values.push_back(distance(pos, posOld)*factor);
}
......
......@@ -53,6 +53,7 @@ public:
private:
/// calculate stopping criteria data and store it into values vector
void calculate();
std::string target;
};
#endif // STOPPINGCRITERION_STOPPINGCRITERIA_CRITERIA_POSITION_H
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
// Stopping criteria includes
#include "TimePeriodThreshold.h"
// -------------------- constructor --------------------
TimePeriodThreshold::TimePeriodThreshold(mml::TimePeriodThreshold* m): Method(m), mappedObject(m) {
value = m->minValue();
iterations = m->iterations();
increment = iterations;
}
// ------------------- destructor -------------------
TimePeriodThreshold::~TimePeriodThreshold() {}
// -------------------- individualTest --------------------
bool TimePeriodThreshold::individualTest(double tested) {
if (tested <= value) {
increment--;
} else {
increment = iterations;
}
return (increment == 0);
}
// -------------------- toString --------------------
std::string TimePeriodThreshold::toString() {
std::ostringstream strs;
strs << value;
std::string str = strs.str();
return "< " + str;
}
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#ifndef STOPPINGCRITERION_STOPPINGCRITERIA_METHODS_TIMEPERIODTHRESHOLD_H
#define STOPPINGCRITERION_STOPPINGCRITERIA_METHODS_TIMEPERIODTHRESHOLD_H
#include <MonitorIn.hxx>
// Stopping criteria includes
#include "Method.h"
/**
*
* @ingroup group_cepmodeling_libraries_mml
*
* @brief
* A TimePeriodThreshold method is a method where individualTest is true when the tested double is true during a time period defined by a number of iterations
*/
class TimePeriodThreshold: public Method {
public:
/**
* constructor
* @param the xsdcxx generated TimePeriodThreshold class
*/
TimePeriodThreshold(mml::TimePeriodThreshold* m);
/// destructor
~TimePeriodThreshold();
/// return true if tested <= value
bool individualTest(double tested);
/// get Method name
std::string toString();
private:
/// value of the threshold
double value;
/// number of iterations defining the time period
int iterations;
/// Needed to keep an eye on consecutive win
int increment;
/// the xsdcxx object representing TimePeriodThreshold, used for serialization
mml::TimePeriodThreshold* mappedObject;
};
#endif // STOPPINGCRITERION_STOPPINGCRITERIA_METHODS_TIMEPERIODTHRESHOLD_H
......@@ -110,11 +110,12 @@
<xsd:complexContent>
<xsd:extension base="Criteria">
<xsd:attribute name="unit" type="PositionUnit" use="required"/>
<xsd:attribute name="target" type="xsd:string" use="optional"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:simpleType name="PositionUnit">
<xsd:simpleType name="PositionUnit">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="nm"/>
<xsd:enumeration value="mm"/>
......@@ -155,7 +156,16 @@
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="TimePeriodThreshold">
<xsd:complexContent>
<xsd:extension base="Method">
<xsd:attribute name="minValue" type="xsd:double" use="required"/>
<xsd:attribute name="iterations" type="xsd:int" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="MinThreshold">
<xsd:complexContent>
<xsd:extension base="Method">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment