Commit b642a46b authored by promayon's avatar promayon
Browse files

FIXED (tentative) compilation on windows when sofa support is disabled

FIXED using temporary files in temporary directory to go from mml to scn and back
FIXED msh export: filename already provided by CamiTK + do not stop in the middle if some cells are not supported


git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@2053 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 0462da2c
......@@ -20,7 +20,7 @@
# - SOFA_INCLUDE_DIR Sofa include directories needed a compile time
#
# If Sofa support is enabled by the user by setting the build directory,
# the following flags are defined:
# the following flags needs to be defined at compilation time:
# -DSOFA_SUPPORT
# -DSOFA_PATH="${SOFA_BUILD_DIR}"
# -DSOFA_STABLE
......@@ -47,10 +47,6 @@ unset(SOFA_LIBS)
# sofa settings
if(SOFA_SUPPORT)
add_definitions(-DSOFA_SUPPORT)
add_definitions(-DSOFA_PATH="${SOFA_BUILD_DIR}")
add_definitions(-DSOFA_STABLE)
# supported stable version 15.03
if (SOFA_SUPPORTED_VERSION STREQUAL "${SOFA_STABLE_V15_03}")
message(STATUS "SOFA support on (supporting ${SOFA_SUPPORTED_VERSION})")
......@@ -82,82 +78,75 @@ if(SOFA_SUPPORT)
message("Detected Sofa ${MML_SOFA_STABLE} source directory is ${SOFA_SOURCE_DIR}")
# fill the list of needed libraries
# the only way to find the required lib is to hack the files generated by cmake:
# cd ${SOFA_BUILD_DIR}/applications/projects/runSofa
# cat CMakeFiles/runSofa.dir/link.txt | sed 's/\s/\n/g' | grep ../../../lib | sed "s+../../../lib/lib++g" | sed "s+.so++g"
# explained:
# - first sed to explode the one line into one word per line
# - first grep to get only the Sofa library
# - second sed to remove the ../../../lib/
# - third sed to remove the trailing .so
#
set(SOFA_LIBS
# SOFA_LIB_NAME
#SofaGui
#SofaTree
SofaCore
SofaGuiQt
SofaHelper
SofaGuiGlut
SofaGuiMain
#SofaModeler
#SofaSimulation
#SofaObjectCreator
SofaDefaultType
#SofaGraph
# SOFA_LIB_COMPONENT_NAME
#SofaComponent
#SofaComponentDev
SofaComponentBase
SofaComponentMisc
SofaComponentCommon
SofaComponentGeneral
#SofaComponentMiscDev
SofaComponentAdvanced
#SofaComponentAdvancedDev
# SOFA_LIB_BASE_NAME
SofaBaseAnimationLoop
SofaBaseCollision
SofaBaseLinearSolver
SofaBaseMechanics
SofaBaseTopology
SofaBaseVisual
# SOFA_LIB_GENERAL_NAME
SofaBoundaryCondition
SofaConstraint
SofaDenseSolver
SofaEngine
SofaExporter
SofaGraphComponent
SofaOpenglVisual
SofaPreconditioner
SofaTopologyMapping
SofaUserInteraction
SofaValidation
SofaHaptics
# SOFA_LIB_ADVANCED_NAME
#SofaAdvancedConstraint
#SofaAdvancedFem
#SofaAdvancedInteraction
SofaEigen2Solver
SofaEulerianFluid
#SofaMjedFem
SofaNonUniformFem
#SofaNonUniformFemDev
SofaSphFluid
SofaVolumetricData
# SOFA_LIB_MISC_NAME
SofaMisc
SofaMiscCollision
#SofaMiscCollisionDev
SofaMiscFem
#SofaMiscDev
#SofaMiscFemDev
SofaMiscForceField
#SofaMiscForcefieldDev
SofaMiscMapping
#SofaMiscMappingDev
SofaMiscSolver
#SofaMiscSolverDev
SofaMiscTopology
#SofaMiscTopologyDev
SofaMiscEngine
SofaSimulationTree
SofaGuiMain
SofaComponentMain
SofaSimulationGraph
SofaGuiQt
Qwt
SofaGuiGlut
SofaGuiCommon
SofaComponentMain
SofaComponentBase
SofaBaseAnimationLoop
SofaComponentCommon
SofaComponentGeneral
SofaExporter
SofaValidation
SofaLoader
SofaEngine
SofaHaptics
SofaPreconditioner
SofaComponentAdvanced
SofaEulerianFluid
SofaComponentMisc
SofaMiscForceField
SofaMiscFem
SofaMiscEngine
SofaNonUniformFem
SofaMiscCollision
SofaExplicitOdeSolver
SofaConstraint
SofaImplicitOdeSolver
SofaVolumetricData
SofaMiscSolver
SofaMisc
SofaMiscTopology
SofaUserInteraction
SofaGraphComponent
SofaMeshCollision
SofaBaseCollision
SofaSphFluid
SofaObjectInteraction
SofaDeformable
SofaMiscMapping
SofaRigid
SofaBaseMechanics
SofaSimpleFem
SofaOpenglVisual
SofaTopologyMapping
SofaBoundaryCondition
SofaEigen2Solver
SofaDenseSolver
SofaBaseLinearSolver
SofaBaseVisual
SofaBaseTopology
SofaSimulationTree
SofaSimulationCommon
SofaCore
SofaDefaultType
SofaHelper
tinyxml
)
# Library path
......
......@@ -49,7 +49,7 @@ using namespace camitk;
MMLComponent::MMLComponent(const QString & fileName) throw(AbortException) : Component(fileName, QFileInfo(fileName).baseName()) {
myPopupMenu = NULL;
QString file = fileName;
QFileInfo fi = QFileInfo(myFileName);
QFileInfo fi = QFileInfo(fileName);
try {
// initialize the MML export file name
......@@ -57,7 +57,8 @@ MMLComponent::MMLComponent(const QString & fileName) throw(AbortException) : Com
// create a simple MML from a Sofa scn file
if (fi.completeSuffix() == "scn") {
file = /*QFileInfo(fi).absolutePath() */ QDir::tempPath() + "/" + QFileInfo(fi).baseName() + ".mml";
// create mml file in temp directory
file = QDir::tempPath() + "/" + QFileInfo(fi).baseName() + ".mml";
// check if the mml already exist
if (QFileInfo(file).exists()) {
......@@ -116,18 +117,11 @@ MMLComponent::MMLComponent(const QString & fileName) throw(AbortException) : Com
// ---------------------- destructor ----------------------------
MMLComponent::~MMLComponent() {
/*if (exportedMml!="")
remove(exportedMml.toStdString().c_str());
*/
if (pmMgr) {
delete pmMgr;
pmMgr = NULL;
}
//mmlGUI->getMonitoringManager()->setPml(NULL);
if (display) {
delete display;
display = NULL;
......@@ -144,7 +138,6 @@ MMLComponent::~MMLComponent() {
}
if (mmlDock) {
Application::getMainWindow()->removeDockWidget(mmlDock);
delete mmlDock;
mmlDock = NULL;
}
......
......@@ -2,7 +2,7 @@
<!-- reference file for the truthcube: measured position for 18.25% compression -->
<monitoringOut>
<pmlFile>TruthCube-18.pml</pmlFile>
<pmlFile>TruthCube-0-HexaFEM.pml</pmlFile>
<time unit="s" value="1000000">
<monitor index="1" target="" type="Position">
......
......@@ -141,9 +141,15 @@ set(monitoring_SRCS ${monitoring_H}
)
# Specific variables
set(monitoring_LIBRARIES ${MML_GUI_LIBRARIES}
${SOFA_LIBS}
)
set(monitoring_LIBRARIES)
if(MML_GENERATE_GUI)
set(monitoring_LIBRARIES ${monitoring_LIBRARIES} ${MML_GUI_LIBRARIES})
endif()
if(SOFA_SUPPORT)
set(monitoring_LIBRARIES ${monitoring_LIBRARIES} ${SOFA_LIBS})
endif()
set(monitoring_LINK_DIRECTORIES ${SOFA_LIB_DIR})
......
......@@ -37,6 +37,11 @@ if (SOFA_SUPPORT)
${SOFA_MOC_UI}
${SOFA_GUI_SRC}
)
# specific flags needed (C++ code)
add_definitions(-DSOFA_SUPPORT)
add_definitions(-DSOFA_PATH="${SOFA_BUILD_DIR}")
add_definitions(-DSOFA_STABLE)
endif()
# +-----------------+
......
......@@ -73,33 +73,26 @@ MML_DECL_CLASS( SofaSimulator )
bool sofaRegistered = SimulatorFactory::getInstance()->registerClass<SofaSimulator>( "sofa", true );
SofaSimulator::SofaSimulator( MonitoringManager* monitoringManager ): InteractiveSimulator( monitoringManager ) {
string mshFile;
// check for Sofa scn
scnFile = monitoringManager->getPmlFileName();
string::size_type pLast = scnFile.rfind( "." );
if( pLast != string::npos ) {
scnFile.erase( pLast );
mshFile = string( scnFile );
mshFile += ".msh";
scnFile += ".scn";
}
QFileInfo mmlFileInfo = QFileInfo(monitoringManager->getMmlFileName().c_str());
QString scnFileName = mmlFileInfo.absolutePath() + "/" + mmlFileInfo.baseName() + ".scn";
scnFile = scnFileName.toStdString();
// if scn file already exist, use this file
ifstream iscn( scnFile.c_str() );
if( !iscn ) {
// scn file do not exist in the same directory, create one in temp directory
scnFileName = QDir::tempPath() + "/" + mmlFileInfo.baseName() + ".scn";
scnFile = scnFileName.toStdString();
//scn file do not exist in pml directory, create one
//TODO? add simulator file path to mml? do not create if specified?
//create msh from pmlFile
// create msh from pmlFile in temporary directory as well
QString mshFileName = QDir::tempPath() + "/" + QFileInfo(monitoringManager->getPmlFileName().c_str()).baseName() + ".msh";
int type = 0;
PhysicalModel* pml = monitoringManager->getPml();
ofstream msh;
msh.open( mshFile.c_str(), ios::out );
msh.open( mshFileName.toStdString().c_str(), ios::out );
//create nodes
msh << "$NOD" << endl;
......@@ -115,7 +108,6 @@ SofaSimulator::SofaSimulator( MonitoringManager* monitoringManager ): Interactiv
msh << "$ENDNOD" << endl;
//create elements if an "Elements" components exists
Component *elements = pml->getComponentByName( "Elements" );
......@@ -197,7 +189,7 @@ SofaSimulator::SofaSimulator( MonitoringManager* monitoringManager ): Interactiv
scn << " <EulerImplicit name=\"cg_odesolver\" printLog=\"false\" />" << endl;
scn << " <CGLinearSolver iterations=\"25\" name=\"linear solver\" tolerance=\"1.0e-9\" threshold=\"1.0e-9\" />" << endl;
scn << " <!-- mesh -->" << endl;
scn << " <MeshGmshLoader name=\"meshLoader\" filename=\"" << mshFile << "\" />" << endl;
scn << " <MeshGmshLoader name=\"meshLoader\" filename=\"" << mshFileName.toStdString() << "\" />" << endl;
scn << " <Mesh src=\"@meshLoader\" />" << endl;
scn << " <!-- mechanical object -->" << endl;
scn << " <MechanicalObject src=\"@meshLoader\" />" << endl;
......@@ -460,7 +452,7 @@ void SofaSimulator::buildConstraints() {
}
}
#if !defined(SOFA_1_0_RC1) && !defined(SOFA_SVN) || !defined(SOFA_STABLE)
#if !defined(SOFA_1_0_RC1) && !defined(SOFA_SVN) && !defined(SOFA_STABLE)
delete translations[i];
#endif
}
......
......@@ -62,21 +62,15 @@ Component * MshExtension::open ( const QString & fileName ) throw ( AbortExcepti
}
bool MshExtension::save ( Component* component ) const {
bool saveOk = true;
bool found = true;
vtkSmartPointer<vtkPointSet> ps = component->getPointSet();
MeshComponent *meshComp = dynamic_cast<MeshComponent*>(component);
vtkSmartPointer<vtkPointSet> ps = meshComp->getPointSet();
if ( ps == NULL || ps->GetNumberOfPoints() ==0 || ps->GetNumberOfCells() == 0 ) {
QMessageBox::warning ( NULL, "Save As msh", tr("The selected component does not have any points or cells. This is an invalid mesh."), QMessageBox::Abort );
return false;
}
QString baseFilename = QFileInfo ( component->getFileName() ).absolutePath() + "/" + QFileInfo ( component->getFileName() ).completeBaseName();
QString mshFilename = baseFilename + ".msh";
ofstream mshFile ( mshFilename.toUtf8() );
ofstream mshFile ( meshComp->getFileName().toStdString().c_str() );
double xyz[3];
mshFile << "$NOD" << endl;
mshFile << ps->GetPoints()->GetNumberOfPoints() << endl;
......@@ -86,10 +80,22 @@ bool MshExtension::save ( Component* component ) const {
}
mshFile << "$ENDNOD" << endl;
mshFile << "$ELM" << endl;
mshFile << ps->GetNumberOfCells() << endl;
// compute the number of cells, removing the unsupported types
unsigned int numberOfSupportedCells = 7;
int supportedCellType[numberOfSupportedCells] = {VTK_LINE,VTK_TETRA,VTK_HEXAHEDRON,VTK_WEDGE,VTK_PYRAMID,VTK_TRIANGLE,VTK_QUAD};
unsigned int numberOfExportedCells = 0;
for ( vtkIdType i = 0; i < ps->GetNumberOfCells() ; i++ ) {
int j=0;
while(j<numberOfSupportedCells && supportedCellType[j]!=ps->GetCell ( i )->GetCellType())
j++;
if (j<numberOfSupportedCells)
numberOfExportedCells++;
}
mshFile << numberOfExportedCells << endl;
for ( vtkIdType i = 0; i < ps->GetNumberOfCells() ; i++ ) {
found = true;
bool supportedType = true;
switch ( ps->GetCell ( i )->GetCellType() ) {
case VTK_LINE :
mshFile << i + 1 << " 1 1 1 2";
......@@ -113,12 +119,11 @@ bool MshExtension::save ( Component* component ) const {
mshFile << i + 1 << " 3 1 1 4";
break;
default:
saveOk = false;
found = false;
CAMITK_ERROR ( "VolumetricMeshExtension", "save", "unsupported element" );
supportedType = false;
CAMITK_WARNING ( "MshExtension", "save", "Unsupported element for cell #" << i << ": type = " << ps->GetCell ( i )->GetCellType() << " (this cell was not exported to msh)");
break;
}
if ( found ) {
if (supportedType) {
for ( vtkIdType j=0; j<ps->GetCell ( i )->GetNumberOfPoints(); j++ )
mshFile << " " << ps->GetCell ( i )->GetPointId ( j ) + 1;
mshFile << endl;
......@@ -128,5 +133,5 @@ bool MshExtension::save ( Component* component ) const {
mshFile << "$ENDELM" << endl;
mshFile.close();
return saveOk;
return true;
}
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