Commit 188816a1 authored by promayon's avatar promayon
Browse files

FIXED potentially uninitialized


git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@509 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 0463fa47
......@@ -33,253 +33,262 @@
// -------------------- constructor --------------------
Reference::Reference(mml::Reference reference, MonitoringManager* monitoringManager){
target="";
if (reference.target().present())
target=reference.target().get();
this->monitoringManager=monitoringManager;
this->mmlOutFile=monitoringManager->getmmlFileFolder() + reference.document();
xml_schema::properties props;
//props.no_namespace_schema_location(MONITORIN_XSD);//TODO define montorout
mmlOut = mml::monitoringOut(mmlOutFile.c_str(),xml_schema::flags::dont_validate);
mml::MonitoringOut::time_sequence& ts(mmlOut->time());
for (mml::MonitoringOut::time_iterator i(ts.begin());i != ts.end();++i){
timeStep* step=new timeStep;
step->time=(*i).value(); //TODO time paramete 2double
mml::TimeStep::monitor_sequence& monit((*i).monitor());
for (mml::TimeStep::monitor_iterator it(monit.begin());it != monit.end();++it){
Monitor* m=MonitorFactory::createMonitor(&(*it),monitoringManager);
step->monitorsMap.insert(std::make_pair<std::string,Monitor*>(m->getTypeName(),m));
Reference::Reference(mml::Reference reference, MonitoringManager* monitoringManager) {
target="";
if (reference.target().present())
target=reference.target().get();
this->monitoringManager=monitoringManager;
this->mmlOutFile=monitoringManager->getmmlFileFolder() + reference.document();
xml_schema::properties props;
//props.no_namespace_schema_location(MONITORIN_XSD);//TODO define montorout
mmlOut = mml::monitoringOut(mmlOutFile.c_str(),xml_schema::flags::dont_validate);
mml::MonitoringOut::time_sequence& ts(mmlOut->time());
for (mml::MonitoringOut::time_iterator i(ts.begin()); i != ts.end(); ++i) {
timeStep* step=new timeStep;
step->time=(*i).value(); //TODO time paramete 2double
mml::TimeStep::monitor_sequence& monit((*i).monitor());
for (mml::TimeStep::monitor_iterator it(monit.begin()); it != monit.end(); ++it) {
Monitor* m=MonitorFactory::createMonitor(&(*it),monitoringManager);
step->monitorsMap.insert(std::make_pair<std::string,Monitor*>(m->getTypeName(),m));
}
data.push_back(step);
}
data.push_back(step);
}
// change final step time to infinity
data.back()->time=std::numeric_limits< double >::infinity();
std::string refpath=mmlOutFile;
std::string folder;
size_t slashPlace=refpath.find_last_of("/");
if (slashPlace) {
folder=refpath.substr(0,slashPlace+1);
}else{
folder="";
}
pml=new PhysicalModel((folder+mmlOut->pmlFile()).c_str());
CurrentIndex=0;
// change final step time to infinity
data.back()->time=std::numeric_limits< double >::infinity();
std::string refpath=mmlOutFile;
std::string folder;
size_t slashPlace=refpath.find_last_of("/");
if (slashPlace) {
folder=refpath.substr(0,slashPlace+1);
}
else {
folder="";
}
pml=new PhysicalModel((folder+mmlOut->pmlFile()).c_str());
CurrentIndex=0;
}
// -------------------- destructor --------------------
Reference::~Reference(){
for(unsigned int i=0; i<data.size(); i++){
timeStep* ts=data[i];
for (multimap<std::string,Monitor*>::iterator it=ts->monitorsMap.begin() ; it != ts->monitorsMap.end(); it++ )
delete it->second;
ts->monitorsMap.clear();
delete ts;
}
data.clear();
delete pml;
Reference::~Reference() {
for(unsigned int i=0; i<data.size(); i++) {
timeStep* ts=data[i];
for (multimap<std::string,Monitor*>::iterator it=ts->monitorsMap.begin() ; it != ts->monitorsMap.end(); it++ )
delete it->second;
ts->monitorsMap.clear();
delete ts;
}
data.clear();
delete pml;
}
// -------------------- getNearest --------------------
bool Reference::getNearest(double pos[3], double time, double ref[3])
{
double temp[3];
double min=0;
double realTime;
int i=0;
bool success=false;
AtomIterator it=AtomIterator(pml,target);
for (it.begin();!it.end();it.next()){
if (getMonitoredData("Position",time,it.currentAtom()->getIndex(),realTime,temp)){
success=true;
double d=distance(pos,temp);
if (i==0 || d<min){
min=d;
ref[0]=temp[0];
ref[1]=temp[1];
ref[2]=temp[2];
i++;
}
bool Reference::getNearest(double pos[3], double time, double ref[3]) {
double temp[3];
double min=0;
double realTime;
int i=0;
bool success=false;
AtomIterator it=AtomIterator(pml,target);
for (it.begin(); !it.end(); it.next()) {
if (getMonitoredData("Position",time,it.currentAtom()->getIndex(),realTime,temp)) {
success=true;
double d=distance(pos,temp);
if (i==0 || d<min) {
min=d;
ref[0]=temp[0];
ref[1]=temp[1];
ref[2]=temp[2];
i++;
}
}
}
}
return success;
return success;
}
// -------------------- getNearest --------------------
bool Reference::getNearest(double pos[3], double ref[3])
{
double temp[3];
double min=0;
int i=0;
AtomIterator it=AtomIterator(pml,target);
for (it.begin();!it.end();it.next()){
it.currentAtom()->getPosition(temp);
double d=distance(pos,temp);
if (i==0 || d<min){
min=d;
ref[0]=temp[0];
ref[1]=temp[1];
ref[2]=temp[2];
i++;
bool Reference::getNearest(double pos[3], double ref[3]) {
double temp[3];
double min=0;
int i=0;
AtomIterator it=AtomIterator(pml,target);
for (it.begin(); !it.end(); it.next()) {
it.currentAtom()->getPosition(temp);
double d=distance(pos,temp);
if (i==0 || d<min) {
min=d;
ref[0]=temp[0];
ref[1]=temp[1];
ref[2]=temp[2];
i++;
}
}
}
return i>0;
return i>0;
}
// -------------------- getMonitoredData --------------------
bool Reference::getMonitoredData(string type, double ref[])
{
bool Reference::getMonitoredData(string type, double ref[]) {
// TODO
return false;
return false;
}
// return a struct with time and ref...?
// -------------------- getMonitoredData --------------------
bool Reference::getMonitoredData(std::string type, double time, double &realTime, double ref[])
{
unsigned int i=CurrentIndex;
bool timeFound=false;
while (i<data.size() && !timeFound){
if (data[i]->time>=time)
timeFound=true;
else
i++;
}
CurrentIndex=i;
// we have found a time (which is infinity if final step)
realTime=data[i]->time;
// we now search the rigth monitor
std::multimap<std::string, Monitor*>::iterator iter = data[i]->monitorsMap.find(type);
if (iter == data[i]->monitorsMap.end()){
// no monitors found
std::cerr << "no monitor " << type<< " found (time: " << time << " )" <<std::endl;
return false;
}else{
(*iter).second->getValueType();
switch ((*iter).second->getValueType()){
case Monitor::SCALAR:
ref[0]=(*iter).second->getValue(0);
return true;
break;
default:
std::cerr << "monitor " << type << " not compatible with getMonitoredData without index parameter" <<std::endl;
return false;
bool Reference::getMonitoredData(std::string type, double time, double &realTime, double ref[]) {
unsigned int i=CurrentIndex;
bool timeFound=false;
while (i<data.size() && !timeFound) {
if (data[i]->time>=time)
timeFound=true;
else
i++;
}
}
CurrentIndex=i;
// we have found a time (which is infinity if final step)
realTime=data[i]->time;
// we now search the rigth monitor
std::multimap<std::string, Monitor*>::iterator iter = data[i]->monitorsMap.find(type);
if (iter == data[i]->monitorsMap.end()) {
// no monitors found
std::cerr << "no monitor " << type<< " found (time: " << time << " )" <<std::endl;
return false;
}
else {
(*iter).second->getValueType();
switch ((*iter).second->getValueType()) {
case Monitor::SCALAR:
ref[0]=(*iter).second->getValue(0);
return true;
break;
default:
std::cerr << "monitor " << type << " not compatible with getMonitoredData without index parameter" <<std::endl;
return false;
}
}
return false;
}
// -------------------- getMonitoredData --------------------
bool Reference::getMonitoredData(string type, double time, int index, double &realTime, double ref[])
{
unsigned int i=CurrentIndex;
bool timeFound=false;
while (i<data.size() && !timeFound){
if (data[i]->time>=time)
timeFound=true;
else
i++;
}
CurrentIndex=i;
// we have found a time (which is infinity if final step)
realTime=data[i]->time;
// we now search the rigth monitor
std::multimap<std::string, Monitor*>::iterator iter = data[i]->monitorsMap.find(type);
std::multimap<std::string, Monitor*>::iterator lastElem;
if (iter == data[i]->monitorsMap.end()){
// no monitors found
std::cerr << "no monitor " << type<< " found (time: " << time << " )" <<std::endl;
return false;
}else{
lastElem=data[i]->monitorsMap.upper_bound(type); //last elem of "type" key in map
bool indFound=false;
while(iter!=lastElem && !indFound){ // ieration element of "type" key in map, stop when an index is found
// looking for rigth index in this monitor
indFound = (iter->second->getValuesOfIndex(index,ref));
iter++;
bool Reference::getMonitoredData(string type, double time, int index, double &realTime, double ref[]) {
unsigned int i=CurrentIndex;
bool timeFound=false;
while (i<data.size() && !timeFound) {
if (data[i]->time>=time)
timeFound=true;
else
i++;
}
CurrentIndex=i;
// we have found a time (which is infinity if final step)
realTime=data[i]->time;
// we now search the rigth monitor
std::multimap<std::string, Monitor*>::iterator iter = data[i]->monitorsMap.find(type);
std::multimap<std::string, Monitor*>::iterator lastElem;
if (iter == data[i]->monitorsMap.end()) {
// no monitors found
std::cerr << "no monitor " << type<< " found (time: " << time << " )" <<std::endl;
return false;
}
if (indFound)
return true;
else {
std::cerr << "no data for index " << index <<" in monitor " << type << " (time: " << time << ")" <<std::endl;
return false;
lastElem=data[i]->monitorsMap.upper_bound(type); //last elem of "type" key in map
bool indFound=false;
while(iter!=lastElem && !indFound) { // ieration element of "type" key in map, stop when an index is found
// looking for rigth index in this monitor
indFound = (iter->second->getValuesOfIndex(index,ref));
iter++;
}
if (indFound)
return true;
else {
std::cerr << "no data for index " << index <<" in monitor " << type << " (time: " << time << ")" <<std::endl;
return false;
}
}
}
}
// -------------------- getDistanceToTriangularMesh --------------------
bool Reference::getDistanceToTriangularMesh(double pos[3], double& dist)
{
//look for nearest atom
Atom* a;
double temp[3];
dist=-1;
int i=0;
AtomIterator it=AtomIterator(pml,target);
for (it.begin();!it.end();it.next()){
it.currentAtom()->getPosition(temp);
double d=distance(pos,temp);
if (i==0 || d<dist){
dist=d;
a=it.currentAtom();
i++;
bool Reference::getDistanceToTriangularMesh(double pos[3], double& dist) {
//look for nearest atom
Atom* a = NULL;
double temp[3];
dist=-1;
int i=0;
AtomIterator it=AtomIterator(pml,target);
for (it.begin(); !it.end(); it.next()) {
it.currentAtom()->getPosition(temp);
double d=distance(pos,temp);
if (i==0 || d<dist) {
dist=d;
a=it.currentAtom();
i++;
}
}
}
//heuristic? look cell containing tthe nearest atom and compute distance to triangle
std::vector<StructuralComponent*> comps=a->getAllStructuralComponents();
for (unsigned int i=0;i<comps.size();i++){
StructuralComponent* str=comps[i];
Cell* c = dynamic_cast<Cell*>(str);
if (c) {
if (c->getProperties()->getType()==StructureProperties::TRIANGLE){
double v1[3];
double v2[3];
double v3[3];
((Atom*)(c->getStructure(0)))->getPosition(v1);
((Atom*)(c->getStructure(1)))->getPosition(v2);
((Atom*)(c->getStructure(2)))->getPosition(v3);
double d=distanceToTriangle(pos,v1,v2,v3);
if (d<dist)
dist=d;
}
}
}
return dist!=-1;
// StructuralComponent* str=(StructuralComponent*)(pml->getComponentByName(target));
// if (!str)
// return false;
// dist=0;
// bool found=false;
// for (unsigned int i=0; i< str->getNumberOfCells();i++){
// Cell* c=str->getCell(i);
// if (c->getProperties()->getType()==StructureProperties::TRIANGLE){
// double v1[3];
// double v2[3];
// double v3[3];
// ((Atom*)(c->getStructure(0)))->getPosition(v1);
// ((Atom*)(c->getStructure(1)))->getPosition(v2);
// ((Atom*)(c->getStructure(2)))->getPosition(v3);
// double d=distanceToTriangle(pos,v1,v2,v3);
// if (!found || d<dist){
// dist=d;
// found=true;
// }
// }
// }
// return found;
if (a) {
//heuristic? look cell containing the nearest atom and compute distance to triangle
std::vector<StructuralComponent*> comps=a->getAllStructuralComponents();
for (unsigned int i=0; i<comps.size(); i++) {
StructuralComponent* str=comps[i];
Cell* c = dynamic_cast<Cell*>(str);
if (c) {
if (c->getProperties()->getType()==StructureProperties::TRIANGLE) {
double v1[3];
double v2[3];
double v3[3];
((Atom*)(c->getStructure(0)))->getPosition(v1);
((Atom*)(c->getStructure(1)))->getPosition(v2);
((Atom*)(c->getStructure(2)))->getPosition(v3);
double d=distanceToTriangle(pos,v1,v2,v3);
if (d<dist)
dist=d;
}
}
}
}
return (dist!=-1);
}
// -------------------- toString --------------------
std::string Reference::toString()
{
return mmlOutFile;
std::string Reference::toString() {
return mmlOutFile;
}
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