Commit cc80f639 authored by Mathieu BAILET's avatar Mathieu BAILET
Browse files

Merge branch 'feature-pml-save-selection-as-ic' into develop

parents d785e603 81984ae4
......@@ -39,164 +39,190 @@ using namespace camitk;
//-- vtk
#include <vtkCell.h>
#include <vtkAbstractArray.h>
// --------------- getName -------------------
QString PMLComponentExtension::getName() const {
return "PML Component";
return "PML Component";
}
// --------------- getDescription -------------------
QString PMLComponentExtension::getDescription() const {
return "<b>New PML COMPONENT!</b>";// Manage Physical Model <em>.pml</em> files in <b>CamiTK</b>.<br/>CamiTK was initially mainly developed to support this format. Lots of things are possible with a physical model!";
return "<b>New PML COMPONENT!</b>";// Manage Physical Model <em>.pml</em> files in <b>CamiTK</b>.<br/>CamiTK was initially mainly developed to support this format. Lots of things are possible with a physical model!";
}
// --------------- getFileExtensions -------------------
QStringList PMLComponentExtension::getFileExtensions() const {
QStringList ext;
ext << "pml";
return ext;
QStringList ext;
ext << "pml";
return ext;
}
// --------------- open -------------------
camitk::Component * PMLComponentExtension::open(const QString & fileName) throw(AbortException) {
Application::showStatusBarMessage("Loading " + fileName + "...");
Application::showStatusBarMessage("Loading " + fileName + "...");
// instanciate the component
PMLComponent * pmlComponent = new PMLComponent(fileName);
// instanciate the component
PMLComponent * pmlComponent = new PMLComponent(fileName);
// reset the progress bar
Application::resetProgressBar();
// reset the progress bar
Application::resetProgressBar();
return pmlComponent;
return pmlComponent;
}
// --------------- save -------------------
bool PMLComponentExtension::save(camitk::Component * component) const {
PMLComponent * comp = dynamic_cast<PMLComponent *>(component);
if (comp) {
// easy!
// Just generate an ostream from the filename and then xmlPrint pop
std::ofstream outputFile(comp->getFileName().toStdString().c_str());
comp->getPhysicalModel()->xmlPrint(outputFile);
outputFile.close();
comp->setModified(false);
return true;
} else {
// save from generic MeshComponent
MeshComponent * meshComp = dynamic_cast<MeshComponent *>(component);
if (meshComp && meshComp->getPointSet()->GetNumberOfPoints() > 0) {
//-- create a new physical model
PhysicalModel * newPM = new PhysicalModel();
// extract the atoms from the Geometry
vtkSmartPointer<vtkPoints> thePoints = vtkSmartPointer<vtkPoints>::New();
thePoints->DeepCopy(meshComp->getPointSet()->GetPoints());
//-- create the structural components for the atoms
StructuralComponent * theAtoms = new StructuralComponent(newPM, "All Atoms");
double pos[3];
// create the atom structures
for (int i = 0; i < thePoints->GetNumberOfPoints(); i++) {
thePoints->GetPoint(i, pos);
theAtoms->addStructure(new Atom(newPM, pos), false);
}
// set the atom sc
newPM->setAtoms(theAtoms);
//-- create the unique structural components containing all the vtkCell, this is an exclusive component
unsigned int nrOfCells = meshComp->getPointSet()->GetNumberOfCells();
StructuralComponent * sc = new StructuralComponent(newPM, "All Cells");
// fill in this new structural component with all vtk cells
for (vtkIdType i = 0; i < (vtkIdType) nrOfCells; i++) {
// create a cell for each cell
vtkCell * theCell = meshComp->getPointSet()->GetCell(i);
// translate cell type
StructureProperties::GeometricType cellType;
switch (theCell->GetCellType()) {
case VTK_TETRA:
cellType = StructureProperties::TETRAHEDRON;
break;
case VTK_HEXAHEDRON:
cellType = StructureProperties::HEXAHEDRON;
break;
case VTK_WEDGE:
cellType = StructureProperties::WEDGE;
break;
case VTK_PYRAMID:
cellType = StructureProperties::PYRAMID;
break;
case VTK_LINE:
cellType = StructureProperties::LINE;
break;
case VTK_POLY_LINE:
cellType = StructureProperties::POLY_LINE;
break;
case VTK_POLY_VERTEX:
cellType = StructureProperties::POLY_VERTEX;
break;
case VTK_TRIANGLE:
cellType = StructureProperties::TRIANGLE;
break;
case VTK_QUAD:
cellType = StructureProperties::QUAD;
break;
default:
cellType = StructureProperties::INVALID;
break;
}
// create the corresponding PML cell
Cell * c = new Cell(newPM, cellType);
// fill-in the cell structures (atoms)
for (int i = 0; i < theCell->GetNumberOfPoints(); i++) {
// get the corresponding atom
Atom * a = newPM->getAtom(theCell->GetPointId(i)); // dynamic_cast<Atom *>(theAtoms->getStructure(theCell->GetPointId(i)));
// set the corresponding atom as a structure composing the cell
c->addStructure(a, false);
}
// insert the cell in the structure
sc->addStructure(c, false);
}
// create the exclusive multi-component
MultiComponent * exclusiveComponents = new MultiComponent(newPM);
// insert all the cells (i.e. the sc component)
exclusiveComponents->addSubComponent(sc);
exclusiveComponents->setName("Exclusive Components");
// insert this exclusive component into the pm
newPM->setExclusiveComponents(exclusiveComponents);
// save it!
std::ofstream outputFile(meshComp->getFileName().toStdString().c_str());
newPM->xmlPrint(outputFile);
meshComp->setModified(false);
outputFile.close();
return true;
}
PMLComponent * comp = dynamic_cast<PMLComponent *>(component);
if (comp) {
// easy!
// Just generate an ostream from the filename and then xmlPrint pop
std::ofstream outputFile(comp->getFileName().toStdString().c_str());
comp->getPhysicalModel()->xmlPrint(outputFile);
outputFile.close();
comp->setModified(false);
return true;
} else {
// save from generic MeshComponent
MeshComponent * meshComp = dynamic_cast<MeshComponent *>(component);
if (meshComp && meshComp->getPointSet()->GetNumberOfPoints() > 0) {
//-- create a new physical model
PhysicalModel * newPM = new PhysicalModel();
// extract the atoms from the Geometry
vtkSmartPointer<vtkPoints> thePoints = vtkSmartPointer<vtkPoints>::New();
thePoints->DeepCopy(meshComp->getPointSet()->GetPoints());
//-- create the structural components for the atoms
StructuralComponent * theAtoms = new StructuralComponent(newPM, "All Atoms");
double pos[3];
// create the atom structures
for (int i = 0; i < thePoints->GetNumberOfPoints(); i++) {
thePoints->GetPoint(i, pos);
theAtoms->addStructure(new Atom(newPM, pos), false);
}
// set the atom sc
newPM->setAtoms(theAtoms);
//-- create the unique structural components containing all the vtkCell, this is an exclusive component
unsigned int nrOfCells = meshComp->getPointSet()->GetNumberOfCells();
StructuralComponent * sc = new StructuralComponent(newPM, "All Cells");
// fill in this new structural component with all vtk cells
for (vtkIdType i = 0; i < (vtkIdType) nrOfCells; i++) {
// create a cell for each cell
vtkCell * theCell = meshComp->getPointSet()->GetCell(i);
// translate cell type
StructureProperties::GeometricType cellType;
switch (theCell->GetCellType()) {
case VTK_TETRA:
cellType = StructureProperties::TETRAHEDRON;
break;
case VTK_HEXAHEDRON:
cellType = StructureProperties::HEXAHEDRON;
break;
case VTK_WEDGE:
cellType = StructureProperties::WEDGE;
break;
case VTK_PYRAMID:
cellType = StructureProperties::PYRAMID;
break;
case VTK_LINE:
cellType = StructureProperties::LINE;
break;
case VTK_POLY_LINE:
cellType = StructureProperties::POLY_LINE;
break;
case VTK_POLY_VERTEX:
cellType = StructureProperties::POLY_VERTEX;
break;
case VTK_TRIANGLE:
cellType = StructureProperties::TRIANGLE;
break;
case VTK_QUAD:
cellType = StructureProperties::QUAD;
break;
default:
cellType = StructureProperties::INVALID;
break;
}
// create the corresponding PML cell
Cell * c = new Cell(newPM, cellType);
// fill-in the cell structures (atoms)
for (int i = 0; i < theCell->GetNumberOfPoints(); i++) {
// get the corresponding atom
Atom * a = newPM->getAtom(theCell->GetPointId(i)); // dynamic_cast<Atom *>(theAtoms->getStructure(theCell->GetPointId(i)));
// set the corresponding atom as a structure composing the cell
c->addStructure(a, false);
}
// insert the cell in the structure
sc->addStructure(c, false);
}
// create the exclusive multi-component
MultiComponent * exclusiveComponents = new MultiComponent(newPM);
// insert all the cells (i.e. the sc component)
exclusiveComponents->addSubComponent(sc);
exclusiveComponents->setName("Exclusive Components");
// insert this exclusive component into the pm
newPM->setExclusiveComponents(exclusiveComponents);
// create the informative components from the selection
MultiComponent * informativeComponents =
new MultiComponent(newPM, "Informative Components");
newPM->setInformativeComponents(informativeComponents);
StructuralComponent* scinf;
vtkSmartPointer<vtkAbstractArray> idArray;
std::string selName;
for (int i=0; i<meshComp->getNumberOfSelections(); i++) {
// TODO : test if it is a cell selection
selName = meshComp->getSelectionAt(i)->GetSelectionList()->GetName();
scinf = new StructuralComponent(newPM, selName);
idArray = meshComp->getSelectionAt(i)->GetSelectionList();
for (int j=0; j<idArray->GetNumberOfTuples(); j++) {
Cell* c = sc->getCell(idArray->GetVariantValue(j).ToInt());
// TODO : this don't work with the Explore PML Component
// since it use cellRef that are not managed
scinf->addStructure(c, false);
}
// add the selection component to the informative components.
newPM->getInformativeComponents()->addSubComponent(scinf);
}
// save it!
std::ofstream outputFile(meshComp->getFileName().toStdString().c_str());
newPM->xmlPrint(outputFile);
meshComp->setModified(false);
outputFile.close();
return true;
}
}
return false;
return false;
}
Supports Markdown
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