Commit 01ae6505 authored by promayon's avatar promayon
Browse files

NEW mml now supports Sofa 1.0 RC1.0 (this is now the default sofa, TODO: fix...

NEW mml now supports Sofa 1.0 RC1.0 (this is now the default sofa, TODO: fix all .scn example accordingly, see task 556
FIXED crash in Geometry::setPointData when data array does have any name (undocumented bug)
FIXED crash in imp when using a recent document that is no longer there (undocumented bug)
FIXED mml color display also shows the monitor's name
FIXED arrow monitor type shows immediately when the user clic on the "Arrows" popup menu item
FIXED force mml simulator to use the dt specified in the Sofa .scn file instead of the dt specified in mml
FIXED creation of mml from scn now write the mml file in the /tmp directory (avoid crash when reopening from the scn), although the pml file is still written beside the .scn


git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@246 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 58f81024
......@@ -515,8 +515,14 @@ void ImpMainWindow::redirectToConsole ( bool visible ) {
void ImpMainWindow::openRecentDocuments() {
QAction *action = qobject_cast<QAction *> ( sender() );
if ( action )
Application::open ( action->data().toString() );
if ( action ) {
// check if this recent document still exists!
if (QFileInfo(action->data().toString()).exists())
Application::open ( action->data().toString() );
else
QMessageBox::warning(this, "Open Recent", "Recent document:<br/>" + action->data().toString() + "<br/>Does not exist anymore, sorry...");
}
}
// ------------------------------ updateRecentDocumentsMenu -------------------------------
......
......@@ -58,29 +58,31 @@ MMLComponent::MMLComponent(const QString & fileName) throw(AbortException) : Com
try {
// initialize the MML export file name
exportedMml = "";
if (fi.completeSuffix() == "scn") {
file = QFileInfo(fi).absolutePath() + "/" + QFileInfo(fi).baseName() + ".mml";
file = /*QFileInfo(fi).absolutePath() */ QDir::tempPath() + "/" + QFileInfo(fi).baseName() + ".mml";
// check if the mml already exist
if (!QFileInfo(file).exists()) {
// create an empty mmlIn file with .scn (in the same directory as the .scn)
mml::TimeParameter dt = mml::TimeParameter(0.1, "s");
mml::TimeParameter refresh = mml::TimeParameter(1, "s");
mml::MonitoringIn mmlIn(dt, refresh, "sofa");
mmlIn.simulatorFile(fi.fileName().toStdString().c_str());
if (QFileInfo(file).exists()) {
CAMITK_WARNING("MMLComponent", "constructor", "Creating MMLComponent from " + fileName.toStdString() + ": mml file already exists in " + file.toStdString() + " (overwriting it)");
}
xml_schema::namespace_infomap map;
map[""].name = "";
map[""].schema = "";
// create an empty mmlIn file with .scn (in the same directory as the .scn)
mml::TimeParameter dt = mml::TimeParameter(0.1, "s");
mml::TimeParameter refresh = mml::TimeParameter(1, "s");
mml::MonitoringIn mmlIn(dt, refresh, "sofa");
mmlIn.simulatorFile(fileName.toStdString().c_str());
exportedMml = file;
xml_schema::namespace_infomap map;
map[""].name = "";
map[""].schema = "";
ofstream ofs(exportedMml.toStdString().c_str());
mml::monitoringIn(ofs, mmlIn, map);
}
else {
CAMITK_ERROR("MMLComponent", "constructor", "Cannot create MMLComponent from " + myFileName.toStdString() + ": mml file exists.\nPlease try to open " + file.toStdString());
throw AbortException("Cannot create MMLComponent from " + myFileName.toStdString() + ": mml file exists.\nPlease try to open " + file.toStdString());
}
exportedMml = file;
ofstream ofs(exportedMml.toStdString().c_str());
mml::monitoringIn(ofs, mmlIn, map);
// to make sure it will be saved again
setModified();
}
mmlGUI = new MonitoringGuiManager;
......@@ -109,19 +111,23 @@ MMLComponent::~MMLComponent() {
delete pmMgr;
pmMgr = NULL;
}
//mmlGUI->getMonitoringManager()->setPml(NULL);
if (mmlGUI) {
delete mmlGUI;
mmlGUI = NULL;
}
if (display) {
delete display;
display = NULL;
}
if (myPopupMenu) {
delete myPopupMenu;
myPopupMenu = NULL;
}
if (mmlDock) {
Application::getMainWindow()->removeDockWidget(mmlDock);
delete mmlDock;
......
......@@ -62,6 +62,9 @@ void Arrows::update()
deco->show(true);
}
// refresh the view
InteractiveViewer::get3DViewer()->refresh();
}
}
......@@ -81,7 +84,11 @@ void Arrows::hide()
deco->show(false);
}
// refresh the view
InteractiveViewer::get3DViewer()->refresh();
}
}
......
......@@ -33,79 +33,87 @@
bool colorsRegistered=MMLMonitorDisplayFactory::getInstance()->registerClass<Colors>("Colors",Monitor::SCALARSET);
Colors::Colors(Monitor* monitor,MMLComponent* manager): MMLMonitorDisplay(monitor,manager)
{
Colors::Colors(Monitor* monitor,MMLComponent* manager): MMLMonitorDisplay(monitor,manager) {
}
Colors::~Colors()
{
Colors::~Colors() {
}
// ---------------------- update ----------------------------
void Colors::update()
{
if (monitor->getNumberOfValues()>0){
PMManagerDC* pmMgr=manager->getPMManager();
pmMgr->createPointData();
// destroy existing atom data (in case not all atom is given a point data)
pmMgr->destroyPointData();
// calculate min and max of monitor data
double min=monitor->getValue(0);
double max=min;
for (unsigned int i=1;i<monitor->getNumberOfIndex();i++){
double d=monitor->getValue(i);
if (d<min)
min=d;
if(d>max)
max=d;
}
InteractiveViewer::get3DViewer()->setColorScaleMinMax(min, max);
double val;
double range = max - min;
AtomDC* adc;
//in case some nodes are not displayed set all values to 0 (blue color for everyone)
StructuralComponent* sc=pmMgr->getPhysicalModel()->getAtoms();
for ( unsigned int i = 0; i<sc->getNumberOfStructures() ;i++ ){
adc = pmMgr->getDC ((Atom*)(sc->getStructure(i)));
adc -> updatePointData (1.0);
}
for ( unsigned int i = 0; i <monitor->getNumberOfIndex();i++ ) {
void Colors::update() {
if (monitor->getNumberOfValues()>0) {
PMManagerDC* pmMgr=manager->getPMManager();
pmMgr->createPointData();
// destroy existing atom data (in case not all atom is given a point data)
pmMgr->destroyPointData();
// calculate min and max of monitor data
double min=monitor->getValue(0);
double max=min;
for (unsigned int i=1; i<monitor->getNumberOfIndex(); i++) {
double d=monitor->getValue(i);
if (d<min)
min=d;
if(d>max)
max=d;
}
// -- update value
double val;
double range = max - min;
AtomDC* adc;
// in case some nodes are not displayed set all values to 0 (blue color for everyone)
StructuralComponent* sc=pmMgr->getPhysicalModel()->getAtoms();
for ( unsigned int i = 0; i<sc->getNumberOfStructures() ; i++ ) {
adc = pmMgr->getDC ((Atom*)(sc->getStructure(i)));
adc -> updatePointData (1.0);
}
// update values for each atom
for ( unsigned int i = 0; i <monitor->getNumberOfIndex(); i++ ) {
val =monitor->getValue(i);
// scaling [0..1]
if ( fabs ( range ) < 1e-10 || val <= min ) {
val = 0.0;
} else {
if ( val >= max ) {
val = 1.0;
} else {
// renormalized the size between min and max
val = ( ( val - min ) / range );
}
// scaling [0..1]
if ( fabs ( range ) < 1e-10 || val <= min ) {
val = 0.0;
}
else {
if ( val >= max ) {
val = 1.0;
}
else {
// renormalized the size between min and max
val = ( ( val - min ) / range );
}
}
adc = pmMgr->getDC (pmMgr->getPhysicalModel()->getAtom(monitor->getIndexOfValues(i)));
adc = pmMgr->getDC (pmMgr->getPhysicalModel()->getAtom(monitor->getIndexOfValues(i)));
adc -> updatePointData (1.0-val);
// add or update custom properties of atom //TODO move into MMLdisplay and make a for loop on all monitors
//pmMgr->getPhysicalModel()->getAtom(monitor->getIndex(i))->getProperties()->set(monitor->getTypeName(),monitor->getValue(i));
//adc->refresh();
// add or update custom properties of atom //TODO move into MMLdisplay and make a for loop on all monitors
//pmMgr->getPhysicalModel()->getAtom(monitor->getIndex(i))->getProperties()->set(monitor->getTypeName(),monitor->getValue(i));
//adc->refresh();
}
//-- show the color scale in 3D
InteractiveViewer::get3DViewer()->setColorScaleTitle(monitor->getTypeName().c_str());
InteractiveViewer::get3DViewer()->setColorScaleMinMax(min, max);
}
}
}
// ---------------------- hide ----------------------------
void Colors::hide()
{
manager->getPMManager()->destroyPointData();
void Colors::hide() {
manager->getPMManager()->destroyPointData();
InteractiveViewer::get3DViewer()->setColorScale(false);
}
......@@ -699,11 +699,13 @@ double Geometry::getBoundingRadius() {
void Geometry::setPointData(vtkSmartPointer<vtkDataArray> da) {
pointSet->GetPointData()->SetScalars(da);
if (da) {
if (da->GetName()==NULL)
da->SetName("Point Data");
pointSet->GetPointData()->SetActiveScalars(da->GetName());
// rescale colors
mapper->SetScalarVisibility(1);
double range[2] = {0,1};
pointSet->GetPointData()->GetScalars()->GetRange(range);
double range[2] = {0,1};
pointSet->GetPointData()->GetScalars(da->GetName())->GetRange(range);
mapper->SetScalarRange(range);
}
// make sure the change is taking into account
......
......@@ -223,25 +223,25 @@ bool MonitoringGuiManager::saveMmlInFile(QString fileName)
//--------------- updateDt ---------------------------------
void MonitoringGuiManager::updateDt(double dt)
{
monitoringManager->ChangeDt(dt);
monitoringManager->setDt(dt);
}
//--------------- updateRefresh ---------------------------------
void MonitoringGuiManager::updateRefresh(double refresh)
{
monitoringManager->ChangeRefresh(refresh);
monitoringManager->setRefresh(refresh);
}
//--------------- updatePml ---------------------------------
void MonitoringGuiManager::updatePml(QString fileName)
{
monitoringManager->ChangePml(fileName.toUtf8().constData());
monitoringManager->setPmlFileName(fileName.toUtf8().constData());
}
//--------------- updateLml ---------------------------------
void MonitoringGuiManager::updateLml(QString fileName)
{
monitoringManager->ChangeLml(fileName.toUtf8().constData());
monitoringManager->setLmlFileName(fileName.toUtf8().constData());
}
......
......@@ -22,9 +22,9 @@ endif(EXISTS ${MML_SOFA_DIR})
# sofa settings
if(MML_SOFA_SUPPORT)
option(MML_SOFA_RELEASE "Set to ON if (soon to be next Release) Svn development version of Sofa is available in ${MML_SOFA_DIR}" OFF)
if(MML_SOFA_RELEASE)
add_definitions(-DSOFA_RELEASE)
option(MML_SOFA_1_0_RC1 "Set to ON (default) if Sofa 1.0 RC1 is available in ${MML_SOFA_DIR}" ON)
if(MML_SOFA_1_0_RC1)
add_definitions(-DSOFA_1_0_RC1)
endif()
# compilation flag
add_definitions(-DSOFA_SUPPORT)
......@@ -35,16 +35,28 @@ if(MML_SOFA_SUPPORT)
else(WIN32)
set(MML_SOFA_LIB_DIR ${MML_SOFA_DIR}/lib/linux ${MML_SOFA_DIR}/lib)
endif(WIN32)
if(NOT MML_SOFA_RELEASE)
if(NOT MML_SOFA_1_0_RC1)
# Sofa1.0 from svn branch
set(MML_SOFA_LIBS sofacore sofacomponent sofasimulation sofatree sofahelper sofadefaulttype)
else()
set(MML_SOFA_LIBS sofacore sofa_component_dev
sofa_component_advanced_dev sofa_component_misc_dev
set(MML_SOFA_LIBS sofacore #sofa_component_dev
#sofa_component_advanced_dev sofa_component_misc_dev
sofa_component
sofa_non_uniform_fem_dev
sofa_advanced_fem sofa_mjed_fem sofa_advanced_constraint sofa_advanced_interaction sofa_misc_topology_dev sofa_misc_mapping_dev sofa_misc_forcefield_dev sofa_misc_fem_dev sofa_misc_collision_dev sofa_misc_solver_dev sofa_misc_dev
sofa_exporter sofa_loader sofa_misc_forcefield sofa_component_base sofa_component_common sofa_component_general sofa_component_advanced sofa_component_misc sofahelper sofa_engine sofa_sph_fluid sofa_non_uniform_fem sofa_base_topology sofa_boundary_condition sofa_haptics sofa_constraint sofatree sofa_base_linear_solver sofa_implicit_ode_solver sofa_simple_fem sofa_topology_mapping sofa_user_interaction sofa_misc_collision sofa_preconditioner sofa_misc_topology sofa_mesh_collision sofa_volumetric_data sofabgl sofa_base_collision sofa_deformable sofa_graph_component sofa_base_mechanics sofa_rigid sofa_base_animation_loop sofa_object_interaction sofa_explicit_ode_solver sofa_eigen2_solver sofa_validation sofa_dense_solver sofa_eulerian_fluid sofa_misc_mapping sofa_misc_fem sofa_misc_engine sofa_misc_solver sofa_misc
#sofa_non_uniform_fem_dev
#sofa_advanced_fem
#sofa_mjed_fem
#sofa_advanced_constraint
#sofa_advanced_interaction
#sofa_misc_topology_dev
#sofa_misc_mapping_dev
#sofa_misc_forcefield_dev
#sofa_misc_fem_dev
#sofa_misc_collision_dev
#sofa_misc_solver_dev
#sofa_misc_dev
sofa_exporter sofa_loader sofa_misc_forcefield sofa_component_base sofa_component_common sofa_component_general sofa_component_advanced sofa_component_misc sofahelper sofa_engine sofa_sph_fluid sofa_non_uniform_fem sofa_base_topology sofa_boundary_condition sofa_haptics sofa_constraint sofatree sofa_base_linear_solver sofa_implicit_ode_solver sofa_simple_fem sofa_topology_mapping sofa_user_interaction sofa_misc_collision sofa_preconditioner sofa_misc_topology sofa_mesh_collision sofa_volumetric_data
#sofabgl
sofa_base_collision sofa_deformable sofa_graph_component sofa_base_mechanics sofa_rigid sofa_base_animation_loop sofa_object_interaction sofa_explicit_ode_solver sofa_eigen2_solver sofa_validation sofa_dense_solver sofa_eulerian_fluid sofa_misc_mapping sofa_misc_fem sofa_misc_engine sofa_misc_solver sofa_misc
sofa_base_visual #-lnewmat -lGLEW -lpng
sofasimulation #-lminiFlowVR
sofacore #-ltinyxml
......@@ -57,7 +69,7 @@ if(MML_SOFA_SUPPORT)
if( CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
set(MML_SOFA_LIBS_WIN32 ${MML_SOFA_LIBS})
set(MML_SOFA_LIBS)
if(MML_SOFA_RELEASE)
if(MML_SOFA_1_0_RC1)
set(SOFA_VERSION_SUFFIX "_1_0d")
else()
set(SOFA_VERSION_SUFFIX "d")
......@@ -406,6 +418,15 @@ export_headers(
monitor/monitors/MonitorPointSetDistance.h
monitor/monitors/MonitorPointFinalSetDistance.h
monitor/monitors/MonitorPointToTriangleMeshDistanceFinal.h
monitor/monitors/MonitorVolume.h
monitor/monitors/MonitorSurface.h
monitor/monitors/MonitorDisplacement.h
monitor/monitors/MonitorNormDisplacement.h
monitor/monitors/MonitorDistanceX.h
monitor/monitors/MonitorDistanceY.h
monitor/monitors/MonitorDistanceZ.h
monitor/monitors/MonitorComputingTime.h
SUBDIRECTORY monitor/monitors
COMPONENT monitoring
)
......
......@@ -40,31 +40,30 @@ class Simulator;
/**
* Manager of the benchmark tests.
* Manager of the benchmark tests.
* Do simulation loop and tests
*/
class MonitoringManager
{
public:
class MonitoringManager {
public:
/**
* constructor
*@param mml mml file name
*@param sim simulator name (Sofa, Ansys...)
*/
MonitoringManager(const char* mml);
/// destructor
virtual ~MonitoringManager();
/** Initialize manager
* @return false if initialisation faild
*/
virtual bool init()=0;
/// End manager
virtual void end()=0;
/// perform simulation loop, make tests and save monitors' data into output file
void simulate();
/// Do one step of simulation and save monitors for this step
......@@ -77,7 +76,7 @@ class MonitoringManager
* @param delPml true if pml object have to be deleted (perhaps used by others: physicalModel component...)
*/
void reload(bool delPml=true);
/// Save save monitors' state for the current time
void saveMonitors();
/// Write all saved monitors' states into mmlOut file
......@@ -86,7 +85,7 @@ class MonitoringManager
void writeCsv(const char* fileName);
/// save current version of mml in
void saveMmlIn(const char* fileName);
/// @name accessors for simulation parameters
///@{
double getDt();
......@@ -108,7 +107,7 @@ class MonitoringManager
/// get atom position for precedent step
void getOldPosition(double pos[3], int index);
///@}
///mutators for simulation parameters
void setCurrentTime(double time);
......@@ -120,47 +119,47 @@ class MonitoringManager
void updateComputingTime();
/// increment step by one
void incStep();
///change dt and save modification into mmlIn
void ChangeDt(double dt);
void setDt(double dt);
///change refresh and save modification into mmlIn
void ChangeRefresh(double refresh);
void setRefresh(double refresh);
///change pml file name and save modification into mmlIn
void ChangePml(const char* file);
void setPmlFileName(const char* file);
///change lml file name and save modification into mmlIn
void ChangeLml(const char* file);
void setLmlFileName(const char* file);
//accessors and mutators for monitors
/// add a monitor to the list
void addMonitor(Monitor* monitor);
/// get a monitor by its index in the list
Monitor * getMonitor(const unsigned int i) const;
/// delete a monitor and remove it from the list using its index
void deleteMonitor(const unsigned int i);
void deleteMonitor(const unsigned int i);
/// get the number of monitors stored in the list
unsigned int numberOfMonitor() const;
/// check if a scn is present instead of pmlFileName
bool isPmlPresent();
/// check if a lml is present
bool isLmlPresent();
protected:
protected:
/// Object representing manager in the file generated by xsdcxx, can be used for serialization
std::auto_ptr<mml::MonitoringIn> mmlIn;
/// Vector that contains all monitors
std::vector<Monitor*> monitors;
/// Vector that contains information saved by saveMonitors method
std::vector<mml::TimeStep*> times;
/// integration step
double dt;
/// refreshing step
double refresh;
/// name of the simulator
std::string simulatorName;
/// current step
int step;
/// time at current moment
......@@ -171,9 +170,9 @@ class MonitoringManager
double computingTime;
/// the simulator used for simualtion
Simulator* simul;
private:
private:
/// build monitors
void buildMonitors();
/// build the loads if lml file was given
......@@ -186,7 +185,7 @@ class MonitoringManager
void buildPmlAndSimulatorfromPml();
/// build physical model and simulator from a specific simulator file
void buildPmlAndSimulatorfromSimulator();
/// pml at current moment
PhysicalModel* pml;
/// is the pml "own" by this instance, which is the normal case when there are no visual representation. But it can also be taken, see takePml()
......
......@@ -32,8 +32,8 @@ $CAMITK_LICENCE_END$
#include "monitor/Monitor.h"
/**
* A monitor that calculate the distance between a point a triangle mes
* This is an optimized version of the point to triangle mesh distance, that only calculate distance with the final reference state
* A monitor that calculate the distance between a point a triangle mesh.
* This is an optimized version of the point to triangle mesh distance, that only calculates distance with the final reference state.
*/
class MonitorPointToTriangleMeshDistanceFinal: public Monitor{
......
......@@ -64,8 +64,8 @@ class Reference{
bool getNearest(double pos[3], double ref[3]);
/**
* get distance to a triagular mesh, the target of the reference msut contain triangles
* this is an optimized method to get distance to triangular mesh where there is only one final time step (real reference) using final pml
* get distance to a triagular mesh, the target of the reference must contain triangles.
* This is an optimized method to get distance to triangular mesh where there is only one final time step (real reference) using final pml
* @param pos atom's position (with eventual offset)
* @param dist the distance
* @return true if method succeded (a triangular mesh was found)
......
......@@ -69,10 +69,12 @@ typedef map<unsigned int, unsigned int> MechanicalObjectDOFAtomMap;
class SofaSimulator : public InteractiveSimulator {
public:
public:
SofaSimulator(MonitoringManager* monitoringManager);
SofaSimulator(MonitoringManager* monitoringManager,const char* file);
virtual ~SofaSimulator();
///@name Simulator inherited
///@{
......@@ -80,20 +82,20 @@ class SofaSimulator : public InteractiveSimulator {
void init();
void getPosition(int index, double position[3]);
void getForce(int index, double force[3]);
void end(){}
void end() {}
void createPml(const char* inputFile,const char* pmlFile);
///@}
std::string getScnFile();
private:
private:
/// get the sofa graph node root
Node *getGNode();
/// get the MechanicalObjectAtomDOFMap for a given mechancial object
std::MechanicalObjectAtomDOFMap & getMechanicalObjectAtomDOFMap(unsigned int mechObjectIndex);
/// get the MechanicalObjectAtomDOFMap for a given mechancial object
std::MechanicalObjectDOFAtomMap & getMechanicalObjectDOFAtomMap(unsigned int mechObjectIndex);
......@@ -102,13 +104,13 @@ class SofaSimulator : public InteractiveSimulator {
/// get the position of the DOF of index dofIndex in the MechanicalObject of index mechObjectIndex
Vec3Types::Coord getDOFPosition(unsigned int mechObjectIndex, unsigned int dofIndex);
///Return the force std::vector corresponding to the Atom number i
Vec3Types::Deriv getDOFForce(unsigned int atomIndex);
/// get the force of the DOF of index dofIndex in the MechanicalObject of index mechObjectIndex
Vec3Types::Deriv getDOFForce(unsigned int mechObjectIndex, unsigned int dofIndex);