#include "SMESH_DeviceActor.h"
#include "SMESH_ObjectDef.h"
#include "SMESH_ControlsDef.hxx"
+#include "SMDS_UnstructuredGrid.hxx"
#include "VTKViewer_ExtractUnstructuredGrid.h"
#include "VTKViewer_FramedTextActor.h"
#include "SALOME_InteractiveObject.hxx"
#ifdef _DEBUG_
static int MYDEBUG = 1;
#else
-static int MYDEBUG = 0;
+static int MYDEBUG = 1;
#endif
static int aLineWidthInc = 2;
aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
+#ifdef VTK_HAVE_POLYHEDRON
+ MESSAGE("RegisterCellsWithType(VTK_POLYHEDRON)");
+ aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
+#endif
//Definition 1D device of the actor
//---------------------------------
aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
+#ifdef VTK_HAVE_POLYHEDRON
+ aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
+#endif
aHightFilter->RegisterCellsWithType(VTK_TETRA);
aHightFilter->RegisterCellsWithType(VTK_VOXEL);
aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
aHightFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
+#ifdef VTK_HAVE_POLYHEDRON
+ aHightFilter->RegisterCellsWithType(VTK_POLYHEDRON);
+#endif
}
aFilter->Update();
if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
#include "utilities.h"
#include <vtkUnstructuredGrid.h>
+#include <vtkXMLUnstructuredGridWriter.h>
#include <vtkUnstructuredGridWriter.h>
#ifdef _DEBUG_
WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid,
const char* theFileName)
{
- vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
+ vtkXMLUnstructuredGridWriter* aWriter = vtkXMLUnstructuredGridWriter::New();
aWriter->SetFileName(theFileName);
aWriter->SetInput(theGrid);
+ aWriter->SetDataModeToAscii();
if(theGrid->GetNumberOfCells()){
aWriter->Write();
}
#ifdef _DEBUG_
static int MYDEBUG = 1;
-static int MYDEBUGWITHFILES = 0;
+static int MYDEBUGWITHFILES = 1;
#else
static int MYDEBUG = 0;
static int MYDEBUGWITHFILES = 0;
//MESSAGE(myGrid->GetReferenceCount());
//MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
//MESSAGE( "Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints() );
- if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" );
+ if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"buildPrs.vtu" );
}
}
this->_cellTypes.clear();
if (_cellDimension.empty())
{
- _cellDimension.resize(VTK_QUADRATIC_PYRAMID + 1, 0);
+ _cellDimension.resize(VTK_MAXTYPE + 1, 0);
_cellDimension[VTK_LINE] = 1;
_cellDimension[VTK_QUADRATIC_EDGE] = 1;
_cellDimension[VTK_TRIANGLE] = 2;
SMDS_MeshVolume* SMDS_Mesh::AddPolyhedralVolumeWithID
(vector<const SMDS_MeshNode*> nodes,
vector<int> quantities,
- const int ID)
+ const int ID)
{
SMDS_MeshVolume* volume;
//if ( myVolumes.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
MESSAGE("Error : Not implemented");
return NULL;
} else {
+#ifdef VTK_HAVE_POLYHEDRON
+ vector<vtkIdType> nodeIds;
+ nodeIds.clear();
+ vector<const SMDS_MeshNode*>::iterator it = nodes.begin();
+ for ( ; it != nodes.end(); ++it)
+ nodeIds.push_back((*it)->getId());
+
+ SMDS_VtkVolume *volvtk = myVolumePool->getNew();
+ volvtk->initPoly(nodeIds, quantities, this);
+ volume = volvtk;
+#else
for ( int i = 0; i < nodes.size(); ++i )
if ( !nodes[ i ] ) return 0;
volume = new SMDS_PolyhedralVolumeOfNodes(nodes, quantities);
+#endif
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbPolyhedrons++;
{
if (ID < 0 || ID >= myNodes.size())
{
+ MESSAGE("------------------------------------------------------------------------- ");
MESSAGE("----------------------------------- bad ID " << ID << " " << myNodes.size());
+ MESSAGE("------------------------------------------------------------------------- ");
return 0;
}
return (const SMDS_MeshNode *)myNodes[ID];
{
if ((IDelem < 0) || IDelem >= myCells.size())
{
+ MESSAGE("--------------------------------------------------------------------------------- ");
MESSAGE("----------------------------------- bad IDelem " << IDelem << " " << myCells.size());
- assert(0);
+ MESSAGE("--------------------------------------------------------------------------------- ");
+ // TODO raise an exception
+ //assert(0);
return 0;
}
return myCells[IDelem];
#include "utilities.h"
-#include <vtkUnstructuredGrid.h>
+#include <SMDS_UnstructuredGrid.hxx>
#include <vtkCellType.h>
using namespace std;
myVtkCellTypes[SMDSEntity_Quad_Hexa] = VTK_QUADRATIC_HEXAHEDRON;
myVtkCellTypes[SMDSEntity_Penta] = VTK_WEDGE;
myVtkCellTypes[SMDSEntity_Quad_Penta] = VTK_QUADRATIC_WEDGE;
+#ifdef VTK_HAVE_POLYHEDRON
+ myVtkCellTypes[SMDSEntity_Polyhedra] = VTK_POLYHEDRON;
+#else
myVtkCellTypes[SMDSEntity_Polyhedra] = VTK_CONVEX_POINT_SET;
+#endif
myVtkCellTypes[SMDSEntity_Quad_Polyhedra] = VTK_CONVEX_POINT_SET;
}
*/
//=======================================================================
-class SMDS_MeshNode_MyInvIterator:public SMDS_ElemIterator
+class SMDS_MeshNode_MyInvIterator: public SMDS_ElemIterator
{
private:
SMDS_Mesh* myMesh;
vtkIdType* myCells;
- int myNcells;
- SMDSAbs_ElementType myType;
- int iter;
+ int myNcells;
+ SMDSAbs_ElementType myType;
+ int iter;
+ vector<vtkIdType> cellList;
- public:
- SMDS_MeshNode_MyInvIterator(SMDS_Mesh *mesh,
- vtkIdType* cells,
- int ncells,
- SMDSAbs_ElementType type):
+public:
+ SMDS_MeshNode_MyInvIterator(SMDS_Mesh *mesh, vtkIdType* cells, int ncells, SMDSAbs_ElementType type) :
myMesh(mesh), myCells(cells), myNcells(ncells), myType(type), iter(0)
{
- //MESSAGE("SMDS_MeshNode_MyInvIterator : ncells " << myNcells);
+ //MESSAGE("SMDS_MeshNode_MyInvIterator : ncells " << myNcells);
+ if (type == SMDSAbs_All)
+ return;
+ cellList.clear();
+ for (int i = 0; i < ncells; i++)
+ {
+ int vtkId = cells[i];
+ int smdsId = myMesh->fromVtkToSmds(vtkId);
+ const SMDS_MeshElement* elem = myMesh->FindElement(smdsId);
+ if (elem->GetType() == type)
+ {
+ //MESSAGE("Add element vtkId " << vtkId << " " << elem->GetType())
+ cellList.push_back(vtkId);
+ }
+ }
+ myCells = &cellList[0];
+ myNcells = cellList.size();
+ //MESSAGE("myNcells="<<myNcells);
}
bool more()
{
- return (iter< myNcells);
+ //MESSAGE("iter " << iter << " ncells " << myNcells);
+ return (iter < myNcells);
}
const SMDS_MeshElement* next()
{
- int vtkId = myCells[iter];
- int smdsId = myMesh->fromVtkToSmds(vtkId);
- const SMDS_MeshElement* elem = myMesh->FindElement(smdsId);
- if (!elem)
+ int vtkId = myCells[iter];
+ int smdsId = myMesh->fromVtkToSmds(vtkId);
+ const SMDS_MeshElement* elem = myMesh->FindElement(smdsId);
+ if (!elem)
{
- assert(0);
- throw SALOME_Exception("SMDS_MeshNode_MyInvIterator problem Null element");
+ assert(0);
+ throw SALOME_Exception("SMDS_MeshNode_MyInvIterator problem Null element");
}
- //MESSAGE("vtkId " << vtkId << " smdsId " << smdsId << " " << (elem!=0));
- iter++;
- return elem;
+ //MESSAGE("vtkId " << vtkId << " smdsId " << smdsId << " " << elem->GetType());
+ iter++;
+ return elem;
}
};
return vtkUnstructuredGrid::UpdateInformation();
}
+vtkPoints* SMDS_UnstructuredGrid::GetPoints()
+{
+ // TODO erreur incomprehensible de la macro vtk GetPoints apparue avec la version paraview de fin aout 2010
+ //MESSAGE("*********************** SMDS_UnstructuredGrid::GetPoints " << this->Points << " " << vtkUnstructuredGrid::GetPoints());
+ return this->Points;
+}
+
+#ifdef VTK_HAVE_POLYHEDRON
+int SMDS_UnstructuredGrid::InsertNextLinkedCell(int type, int npts, vtkIdType *pts)
+{
+ if (type != VTK_POLYHEDRON)
+ return vtkUnstructuredGrid::InsertNextLinkedCell(type, npts, pts);
+
+ // --- type = VTK_POLYHEDRON
+ MESSAGE("InsertNextLinkedCell VTK_POLYHEDRON");
+ int cellid = this->InsertNextCell(type, npts, pts);
+
+ set<vtkIdType> setOfNodes;
+ setOfNodes.clear();
+ int nbfaces = npts;
+ int i = 0;
+ for (int nf = 0; nf < nbfaces; nf++)
+ {
+ int nbnodes = pts[i];
+ i++;
+ for (int k = 0; k < nbnodes; k++)
+ {
+ MESSAGE(" cell " << cellid << " face " << nf << " node " << pts[i]);
+ setOfNodes.insert(pts[i]);
+ i++;
+ }
+ }
+
+ set<vtkIdType>::iterator it = setOfNodes.begin();
+ for (; it != setOfNodes.end(); ++it)
+ {
+ MESSAGE("reverse link for node " << *it << " cell " << cellid);
+ this->Links->ResizeCellList(*it, 1);
+ this->Links->AddCellReference(cellid, *it);
+ }
+
+ return cellid;
+}
+#endif
+
void SMDS_UnstructuredGrid::setSMDS_mesh(SMDS_Mesh *mesh)
{
_mesh = mesh;
void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int newNodeSize,
std::vector<int>& idCellsOldToNew, int newCellSize)
{
+ // TODO utiliser mieux vtk pour faire plus simple (plus couteux ?)
+
MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize);CHRONO(1);
int startHole = 0;
int endHole = 0;
this->SetPoints(newPoints);
MESSAGE("NumberOfPoints: " << this->GetNumberOfPoints());
}
+#ifdef VTK_HAVE_POLYHEDRON
+ // TODO compact faces for Polyhedrons
+ // refaire completement faces et faceLocation
+ // pour chaque cell, recup oldCellId, oldFacesId, recopie dans newFaces de la faceStream
+ // en changeant les numeros de noeuds
+// vtkIdTypeArray *newFaceLocations = vtkIdTypeArray::New();
+// newFaceLocations->Initialize();
+// vtkIdTypeArray *newFaces = vtkIdTypeArray::New();
+// newFaces->Initialize();
+// newFaceLocations->DeepCopy(this->FaceLocations);
+// newFaces->DeepCopy(this->Faces);
+// this->SetCells(newTypes, newLocations, newConnectivity, newFaceLocations, newFaces);
+// newFaceLocations->Delete();
+// newFaces->Delete();
+ if (this->FaceLocations) this->FaceLocations->Register(this);
+ if (this->Faces) this->Faces->Register(this);
+ this->SetCells(newTypes, newLocations, newConnectivity, FaceLocations, Faces);
+#else
this->SetCells(newTypes, newLocations, newConnectivity);
+#endif
+ newTypes->Delete();
+ newLocations->Delete();
+ newConnectivity->Delete();
this->BuildLinks();
}
// --- create SMDS_Downward structures (in _downArray vector[vtkCellType])
- _downArray.resize(VTK_QUADRATIC_PYRAMID + 1, 0); // --- max. type value = VTK_QUADRATIC_PYRAMID
+ _downArray.resize(VTK_MAXTYPE + 1, 0); // --- max. type value = VTK_QUADRATIC_PYRAMID
_downArray[VTK_LINE] = new SMDS_DownEdge(this);
_downArray[VTK_QUADRATIC_EDGE] = new SMDS_DownQuadEdge(this);
#ifndef _SMDS_UNSTRUCTUREDGRID_HXX
#define _SMDS_UNSTRUCTUREDGRID_HXX
+#include <vtkUnstructuredGrid.h>
+#include "chrono.hxx"
+
#include <vector>
#include <set>
#include <map>
-#include <vtkUnstructuredGrid.h>
-#include "chrono.hxx"
+#define VTK_HAVE_POLYHEDRON
+#ifdef VTK_HAVE_POLYHEDRON
+ #define VTK_MAXTYPE VTK_POLYHEDRON
+#else
+ #define VTK_MAXTYPE VTK_QUADRATIC_PYRAMID
+#endif
#define NBMAXNEIGHBORS 10
virtual unsigned long GetMTime();
virtual void Update();
virtual void UpdateInformation();
+ virtual vtkPoints *GetPoints();
+
+#ifdef VTK_HAVE_POLYHEDRON
+ int InsertNextLinkedCell(int type, int npts, vtkIdType *pts);
+#endif
int CellIdToDownId(int vtkCellId);
void setCellIdToDownId(int vtkCellId, int downId);
#include "SMDS_VtkCellIterator.hxx"
+#include "utilities.h"
-SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId,
- SMDSAbs_EntityType aType) :
+
+SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
_mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType)
{
vtkUnstructuredGrid* grid = _mesh->getGrid();
}
case SMDSEntity_Quad_Hexa:
{
+ MESSAGE("SMDS_VtkCellIterator Quad_Hexa");
this->exchange(1, 3);
this->exchange(5, 7);
this->exchange(8, 11);
this->exchange(17, 19);
break;
}
+ case SMDSEntity_Polyhedra:
+ {
+ MESSAGE("SMDS_VtkCellIterator Polyhedra");
+ break;
+ }
default:
break;
}
myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
}
-bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[],
- const int nbNodes)
+#ifdef VTK_HAVE_POLYHEDRON
+void SMDS_VtkVolume::initPoly(std::vector<vtkIdType> nodeIds, std::vector<int> nbNodesPerFace, SMDS_Mesh* mesh)
+{
+ MESSAGE("SMDS_VtkVolume::initPoly");
+ SMDS_UnstructuredGrid* grid = mesh->getGrid();
+ vector<vtkIdType> ptIds;
+ ptIds.clear();
+ vtkIdType nbFaces = nbNodesPerFace.size();
+ int k = 0;
+ for (int i = 0; i < nbFaces; i++)
+ {
+ int nf = nbNodesPerFace[i];
+ ptIds.push_back(nf);
+ for (int n = 0; n < nf; n++)
+ {
+ ptIds.push_back(nodeIds[k]);
+ k++;
+ }
+ }
+ myVtkID = grid->InsertNextLinkedCell(VTK_POLYHEDRON, nbFaces, &ptIds[0]);
+}
+#endif
+
+bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
{
// TODO utilise dans SMDS_Mesh
return true;
int SMDS_VtkVolume::NbFaces() const
{
+ // TODO polyedres
switch (NbNodes())
{
case 4:
int SMDS_VtkVolume::NbEdges() const
{
+ // TODO polyedres
switch (NbNodes())
{
case 4:
switch (type)
{
case SMDSAbs_Node:
- return SMDS_ElemIteratorPtr(
- new SMDS_VtkCellIterator(
- SMDS_Mesh::_meshList[myMeshId],
- myVtkID,
- GetEntityType()));
+ return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
default:
MESSAGE("ERROR : Iterator not implemented")
;
bool SMDS_VtkVolume::IsQuadratic() const
{
+ // TODO polyedres
if (this->NbNodes() > 9)
return true;
else
SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const
{
+ // TODO see SMDS_MeshElementIDFactory::GetVtkCellType
+ vtkIdType aVtkType = this->GetVtkType();
+
SMDSAbs_EntityType aType = SMDSEntity_Tetra;
- switch (NbNodes())
+ switch (aVtkType)
{
- case 4:
+ case VTK_TETRA:
aType = SMDSEntity_Tetra;
break;
- case 5:
+ case VTK_PYRAMID:
aType = SMDSEntity_Pyramid;
break;
- case 6:
+ case VTK_WEDGE:
aType = SMDSEntity_Penta;
break;
- case 8:
+ case VTK_HEXAHEDRON:
aType = SMDSEntity_Hexa;
break;
- case 10:
+ case VTK_QUADRATIC_TETRA:
aType = SMDSEntity_Quad_Tetra;
break;
- case 13:
+ case VTK_QUADRATIC_PYRAMID:
aType = SMDSEntity_Quad_Pyramid;
break;
- case 15:
+ case VTK_QUADRATIC_WEDGE:
aType = SMDSEntity_Quad_Penta;
break;
- case 20:
+ case VTK_QUADRATIC_HEXAHEDRON:
aType = SMDSEntity_Quad_Hexa;
break;
+#ifdef VTK_HAVE_POLYHEDRON
+ case VTK_POLYHEDRON:
+ aType = SMDSEntity_Polyhedra;
+ break;
+#endif
default:
- aType = SMDSEntity_Hexa;
+ aType = SMDSEntity_Polyhedra;
break;
}
return aType;
vtkIdType SMDS_VtkVolume::GetVtkType() const
{
- vtkIdType aType = VTK_TETRA;
- switch (NbNodes())
- {
- case 4:
- aType = VTK_TETRA;
- break;
- case 5:
- aType = VTK_PYRAMID;
- break;
- case 6:
- aType = VTK_WEDGE;
- break;
- case 8:
- aType = VTK_HEXAHEDRON;
- break;
- case 10:
- aType = VTK_QUADRATIC_TETRA;
- break;
- case 13:
- aType = VTK_QUADRATIC_PYRAMID;
- break;
- case 15:
- aType = VTK_QUADRATIC_WEDGE;
- break;
- case 20:
- aType = VTK_QUADRATIC_HEXAHEDRON;
- break;
- default:
- aType = VTK_HEXAHEDRON;
- break;
- }
+ vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
+ vtkIdType aType = grid->GetCellType(myVtkID);
return aType;
}
#include "SMESH_SMDS.hxx"
#include "SMDS_MeshVolume.hxx"
-#include <vtkUnstructuredGrid.h>
+#include "SMDS_UnstructuredGrid.hxx"
#include <vector>
class SMDS_EXPORT SMDS_VtkVolume: public SMDS_MeshVolume
SMDS_VtkVolume(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh);
~SMDS_VtkVolume();
void init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh);
+#ifdef VTK_HAVE_POLYHEDRON
+ void initPoly(std::vector<vtkIdType> nodeIds, std::vector<int> nbNodesPerFace, SMDS_Mesh* mesh);
+#endif
bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes);
void Print(std::ostream & OS) const;
const SMDS_MeshElement* face = 0;
SMDS_ElemIteratorPtr invElemIt = n1->GetInverseElementIterator(SMDSAbs_Face);
+ //MESSAGE("n1->GetInverseElementIterator(SMDSAbs_Face) " << invElemIt);
while ( invElemIt->more() && !face ) // loop on inverse faces of n1
{
+ //MESSAGE("in while ( invElemIt->more() && !face )");
const SMDS_MeshElement* elem = invElemIt->next();
if (avoidSet.count( elem ))
continue;
int NbNodes = IDsOfNodes.length();
std::vector<const SMDS_MeshNode*> n (NbNodes);
for (int i = 0; i < NbNodes; i++)
- n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
+ {
+ const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDsOfNodes[i]);
+ if (!aNode) return 0;
+ n[i] = aNode;
+ }
int NbFaces = Quantities.length();
std::vector<int> q (NbFaces);