PR: mesh and visu hexa no copy

This commit is contained in:
prascle 2010-01-22 15:02:34 +00:00
parent 256c68c3f9
commit ea70fb0809
37 changed files with 1139 additions and 615 deletions

View File

@ -147,60 +147,65 @@ SMESH_VisualObjDef::~SMESH_VisualObjDef()
//=================================================================================
vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID )
{
TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID);
return i == myVTK2SMDSNodes.end() ? -1 : i->second;
// TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID);
// return i == myVTK2SMDSNodes.end() ? -1 : i->second;
return theVTKID;
}
vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID )
{
TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID);
return i == mySMDS2VTKNodes.end() ? -1 : i->second;
// TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID);
// return i == mySMDS2VTKNodes.end() ? -1 : i->second;
return theObjID;
}
vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID )
{
TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID);
return i == myVTK2SMDSElems.end() ? -1 : i->second;
// TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID);
// return i == myVTK2SMDSElems.end() ? -1 : i->second;
return this->GetMesh()->fromVtkToSmds(theVTKID);
}
vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID )
{
TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID);
return i == mySMDS2VTKElems.end() ? -1 : i->second;
// TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID);
// return i == mySMDS2VTKElems.end() ? -1 : i->second;
return this->GetMesh()->fromSmdsToVtk(theObjID);
}
//=================================================================================
// function : SMESH_VisualObjDef::createPoints
// purpose : Create points from nodes
//=================================================================================
void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
{
if ( thePoints == 0 )
return;
TEntityList aNodes;
vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
thePoints->SetNumberOfPoints( nbNodes );
int nbPoints = 0;
TEntityList::const_iterator anIter;
for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
{
const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
if ( aNode != 0 )
{
thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
int anId = aNode->GetID();
mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) );
myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) );
nbPoints++;
}
}
if ( nbPoints != nbNodes )
thePoints->SetNumberOfPoints( nbPoints );
}
//void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
//{
// if ( thePoints == 0 )
// return;
//
// TEntityList aNodes;
// vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
// thePoints->SetNumberOfPoints( nbNodes );
//
// int nbPoints = 0;
//
// TEntityList::const_iterator anIter;
// for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
// {
// const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter);
// if ( aNode != 0 )
// {
// thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() );
// int anId = aNode->GetID();
// mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) );
// myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) );
// nbPoints++;
// }
// }
//
// if ( nbPoints != nbNodes )
// thePoints->SetNumberOfPoints( nbPoints );
//}
//=================================================================================
// function : buildPrs
@ -208,29 +213,30 @@ void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
//=================================================================================
void SMESH_VisualObjDef::buildPrs()
{
try
{
mySMDS2VTKNodes.clear();
myVTK2SMDSNodes.clear();
mySMDS2VTKElems.clear();
myVTK2SMDSElems.clear();
if ( IsNodePrs() )
buildNodePrs();
else
buildElemPrs();
}
catch(...)
{
mySMDS2VTKNodes.clear();
myVTK2SMDSNodes.clear();
mySMDS2VTKElems.clear();
myVTK2SMDSElems.clear();
myGrid->SetPoints( 0 );
myGrid->SetCells( 0, 0, 0 );
throw;
}
// try
// {
// mySMDS2VTKNodes.clear();
// myVTK2SMDSNodes.clear();
// mySMDS2VTKElems.clear();
// myVTK2SMDSElems.clear();
//
// if ( IsNodePrs() )
// buildNodePrs();
// else
// buildElemPrs();
// }
// catch(...)
// {
// mySMDS2VTKNodes.clear();
// myVTK2SMDSNodes.clear();
// mySMDS2VTKElems.clear();
// myVTK2SMDSElems.clear();
//
// myGrid->SetPoints( 0 );
// myGrid->SetCells( 0, 0, 0 );
// throw;
// }
myGrid = GetMesh()->getGrid();
if( MYDEBUG ) MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" );
@ -240,19 +246,20 @@ void SMESH_VisualObjDef::buildPrs()
// function : buildNodePrs
// purpose : create VTK cells for nodes
//=================================================================================
void SMESH_VisualObjDef::buildNodePrs()
{
// PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
// so check remaining memory size for safety
SMDS_Mesh::CheckMemory(); // PAL16631
vtkPoints* aPoints = vtkPoints::New();
createPoints( aPoints );
SMDS_Mesh::CheckMemory();
myGrid->SetPoints( aPoints );
aPoints->Delete();
myGrid->SetCells( 0, 0, 0 );
}
//void SMESH_VisualObjDef::buildNodePrs()
//{
// // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
// // so check remaining memory size for safety
// SMDS_Mesh::CheckMemory(); // PAL16631
// vtkPoints* aPoints = vtkPoints::New();
// createPoints( aPoints );
// SMDS_Mesh::CheckMemory();
// myGrid->SetPoints( aPoints );
// aPoints->Delete();
//
// myGrid->SetCells( 0, 0, 0 );
//}
//=================================================================================
// function : buildElemPrs
@ -284,199 +291,199 @@ namespace{
}
void SMESH_VisualObjDef::buildElemPrs()
{
// Create points
vtkPoints* aPoints = vtkPoints::New();
createPoints( aPoints );
myGrid->SetPoints( aPoints );
aPoints->Delete();
if ( MYDEBUG )
MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
// Calculate cells size
static SMDSAbs_ElementType aTypes[ 4 ] =
{ SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume };
// get entity data
map<SMDSAbs_ElementType,int> nbEnts;
map<SMDSAbs_ElementType,TEntityList> anEnts;
for ( int i = 0; i <= 3; i++ )
nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
// PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
// so check remaining memory size for safety
SMDS_Mesh::CheckMemory(); // PAL16631
vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ];
for ( int i = 2; i <= 3; i++ ) // iterate through faces and volumes
{
if ( nbEnts[ aTypes[ i ] ] )
{
const TEntityList& aList = anEnts[ aTypes[ i ] ];
TEntityList::const_iterator anIter;
for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
aCellsSize += (*anIter)->NbNodes() + 1;
}
}
vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] +
nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ];
if ( MYDEBUG )
MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
// Create cells
vtkCellArray* aConnectivity = vtkCellArray::New();
aConnectivity->Allocate( aCellsSize, 0 );
SMDS_Mesh::CheckMemory(); // PAL16631
vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
aCellTypesArray->SetNumberOfComponents( 1 );
aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
SMDS_Mesh::CheckMemory(); // PAL16631
vtkIdList *anIdList = vtkIdList::New();
vtkIdType iElem = 0;
TConnect aConnect;
aConnect.reserve(VTK_CELL_SIZE);
SMDS_Mesh::CheckMemory(); // PAL16631
for ( int i = 0; i <= 3; i++ ) // iterate through 0d elements, edges, faces and volumes
{
if ( nbEnts[ aTypes[ i ] ] > 0 )
{
const SMDSAbs_ElementType& aType = aTypes[ i ];
const TEntityList& aList = anEnts[ aType ];
TEntityList::const_iterator anIter;
for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
{
const SMDS_MeshElement* anElem = *anIter;
vtkIdType aNbNodes = anElem->NbNodes();
anIdList->SetNumberOfIds( aNbNodes );
int anId = anElem->GetID();
mySMDS2VTKElems.insert( TMapOfIds::value_type( anId, iElem ) );
myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) );
SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
switch (aType) {
case SMDSAbs_Volume:{
aConnect.clear();
std::vector<int> aConnectivities;
// Convertions connectivities from SMDS to VTK
if (anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
if ( const SMDS_PolyhedralVolumeOfNodes* ph =
dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem))
{
aNbNodes = GetConnect(ph->uniqueNodesIterator(),aConnect);
anIdList->SetNumberOfIds( aNbNodes );
}
for (int k = 0; k < aNbNodes; k++)
aConnectivities.push_back(k);
} else if (aNbNodes == 4) {
static int anIds[] = {0,2,1,3};
for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
} else if (aNbNodes == 5) {
static int anIds[] = {0,3,2,1,4};
for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
} else if (aNbNodes == 6) {
static int anIds[] = {0,1,2,3,4,5};
for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
}
else if (aNbNodes == 8) {
static int anIds[] = {0,3,2,1,4,7,6,5};
for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
}
else if (aNbNodes == 10) {
static int anIds[] = {0,2,1,3,6,5,4,7,9,8};
for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
}
else if (aNbNodes == 13) {
static int anIds[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
}
else if (aNbNodes == 15) {
//static int anIds[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
static int anIds[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
//for (int k = 0; k < aNbNodes; k++) {
// int nn = aConnectivities[k];
// const SMDS_MeshNode* N = static_cast<const SMDS_MeshNode*> (aConnect[nn]);
// cout<<"k="<<k<<" N("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
//}
}
else if (aNbNodes == 20) {
static int anIds[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
}
else {
}
if ( aConnect.empty() )
GetConnect(aNodesIter,aConnect);
if (aConnectivities.size() > 0) {
for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
}
break;
}
default:
for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
const SMDS_MeshElement* aNode = aNodesIter->next();
anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
}
}
aConnectivity->InsertNextCell( anIdList );
aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) );
iElem++;
}
}
SMDS_Mesh::CheckMemory(); // PAL16631
}
// Insert cells in grid
VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
aCellLocationsArray->SetNumberOfComponents( 1 );
aCellLocationsArray->SetNumberOfTuples( aNbCells );
SMDS_Mesh::CheckMemory(); // PAL16631
aConnectivity->InitTraversal();
for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
aCellLocationsArray->Delete();
aCellTypesArray->Delete();
aConnectivity->Delete();
anIdList->Delete();
SMDS_Mesh::CheckMemory(); // PAL16631
}
//void SMESH_VisualObjDef::buildElemPrs()
//{
// // Create points
//
// vtkPoints* aPoints = vtkPoints::New();
// createPoints( aPoints );
// myGrid->SetPoints( aPoints );
// aPoints->Delete();
//
// if ( MYDEBUG )
// MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
//
// // Calculate cells size
//
// static SMDSAbs_ElementType aTypes[ 4 ] =
// { SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume };
//
// // get entity data
// map<SMDSAbs_ElementType,int> nbEnts;
// map<SMDSAbs_ElementType,TEntityList> anEnts;
//
// for ( int i = 0; i <= 3; i++ )
// nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] );
//
// // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead,
// // so check remaining memory size for safety
// SMDS_Mesh::CheckMemory(); // PAL16631
//
// vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ];
//
// for ( int i = 2; i <= 3; i++ ) // iterate through faces and volumes
// {
// if ( nbEnts[ aTypes[ i ] ] )
// {
// const TEntityList& aList = anEnts[ aTypes[ i ] ];
// TEntityList::const_iterator anIter;
// for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
// aCellsSize += (*anIter)->NbNodes() + 1;
// }
// }
//
// vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] +
// nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ];
//
// if ( MYDEBUG )
// MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
//
// // Create cells
//
// vtkCellArray* aConnectivity = vtkCellArray::New();
// aConnectivity->Allocate( aCellsSize, 0 );
//
// SMDS_Mesh::CheckMemory(); // PAL16631
//
// vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
// aCellTypesArray->SetNumberOfComponents( 1 );
// aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
//
// SMDS_Mesh::CheckMemory(); // PAL16631
//
// vtkIdList *anIdList = vtkIdList::New();
// vtkIdType iElem = 0;
//
// TConnect aConnect;
// aConnect.reserve(VTK_CELL_SIZE);
//
// SMDS_Mesh::CheckMemory(); // PAL16631
//
// for ( int i = 0; i <= 3; i++ ) // iterate through 0d elements, edges, faces and volumes
// {
// if ( nbEnts[ aTypes[ i ] ] > 0 )
// {
// const SMDSAbs_ElementType& aType = aTypes[ i ];
// const TEntityList& aList = anEnts[ aType ];
// TEntityList::const_iterator anIter;
// for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
// {
// const SMDS_MeshElement* anElem = *anIter;
//
// vtkIdType aNbNodes = anElem->NbNodes();
// anIdList->SetNumberOfIds( aNbNodes );
//
// int anId = anElem->GetID();
//
// mySMDS2VTKElems.insert( TMapOfIds::value_type( anId, iElem ) );
// myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) );
//
// SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
// switch (aType) {
// case SMDSAbs_Volume:{
// aConnect.clear();
// std::vector<int> aConnectivities;
// // Convertions connectivities from SMDS to VTK
// if (anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
//
// if ( const SMDS_PolyhedralVolumeOfNodes* ph =
// dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem))
// {
// aNbNodes = GetConnect(ph->uniqueNodesIterator(),aConnect);
// anIdList->SetNumberOfIds( aNbNodes );
// }
// for (int k = 0; k < aNbNodes; k++)
// aConnectivities.push_back(k);
//
// } else if (aNbNodes == 4) {
// static int anIds[] = {0,2,1,3};
// for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
//
// } else if (aNbNodes == 5) {
// static int anIds[] = {0,3,2,1,4};
// for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
//
// } else if (aNbNodes == 6) {
// static int anIds[] = {0,1,2,3,4,5};
// for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
//
// }
// else if (aNbNodes == 8) {
// static int anIds[] = {0,3,2,1,4,7,6,5};
// for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
//
// }
// else if (aNbNodes == 10) {
// static int anIds[] = {0,2,1,3,6,5,4,7,9,8};
// for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
// }
// else if (aNbNodes == 13) {
// static int anIds[] = {0,3,2,1,4,8,7,6,5,9,12,11,10};
// for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
// }
// else if (aNbNodes == 15) {
// //static int anIds[] = {0,2,1,3,5,4,8,7,6,11,10,9,12,14,13};
// static int anIds[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
// for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
// //for (int k = 0; k < aNbNodes; k++) {
// // int nn = aConnectivities[k];
// // const SMDS_MeshNode* N = static_cast<const SMDS_MeshNode*> (aConnect[nn]);
// // cout<<"k="<<k<<" N("<<N->X()<<","<<N->Y()<<","<<N->Z()<<")"<<endl;
// //}
// }
// else if (aNbNodes == 20) {
// static int anIds[] = {0,3,2,1,4,7,6,5,11,10,9,8,15,14,13,12,16,19,18,17};
// for (int k = 0; k < aNbNodes; k++) aConnectivities.push_back(anIds[k]);
// }
// else {
// }
//
// if ( aConnect.empty() )
// GetConnect(aNodesIter,aConnect);
//
// if (aConnectivities.size() > 0) {
// for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++)
// SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]);
// }
// break;
// }
// default:
// for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){
// const SMDS_MeshElement* aNode = aNodesIter->next();
// anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] );
// }
// }
//
// aConnectivity->InsertNextCell( anIdList );
// aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) );
//
// iElem++;
// }
// }
// SMDS_Mesh::CheckMemory(); // PAL16631
// }
//
// // Insert cells in grid
//
// VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
// aCellLocationsArray->SetNumberOfComponents( 1 );
// aCellLocationsArray->SetNumberOfTuples( aNbCells );
//
// SMDS_Mesh::CheckMemory(); // PAL16631
//
// aConnectivity->InitTraversal();
// for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
// aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
//
// myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
//
// aCellLocationsArray->Delete();
// aCellTypesArray->Delete();
// aConnectivity->Delete();
// anIdList->Delete();
//
// SMDS_Mesh::CheckMemory(); // PAL16631
//}
//=================================================================================
// function : GetEdgeNodes

View File

@ -85,17 +85,17 @@ public:
protected:
void createPoints( vtkPoints* );
// void createPoints( vtkPoints* );
void buildPrs();
void buildNodePrs();
void buildElemPrs();
// void buildNodePrs();
// void buildElemPrs();
private:
TMapOfIds mySMDS2VTKNodes;
TMapOfIds myVTK2SMDSNodes;
TMapOfIds mySMDS2VTKElems;
TMapOfIds myVTK2SMDSElems;
// TMapOfIds mySMDS2VTKNodes;
// TMapOfIds myVTK2SMDSNodes;
// TMapOfIds mySMDS2VTKElems;
// TMapOfIds myVTK2SMDSElems;
vtkUnstructuredGrid* myGrid;
};

View File

@ -29,6 +29,7 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am
# header files
salomeinclude_HEADERS = \
ObjectPool.hxx \
SMDS_TypeOfPosition.hxx \
SMDSAbs_ElementType.hxx \
SMDS_EdgePosition.hxx \
@ -36,10 +37,12 @@ salomeinclude_HEADERS = \
SMDS_FacePosition.hxx \
SMDS_Mesh.hxx \
SMDS_Mesh0DElement.hxx \
SMDS_LinearEdge.hxx \
SMDS_MeshEdge.hxx \
SMDS_MeshElement.hxx \
SMDS_MeshElement.cxx \
SMDS_MeshElementIDFactory.hxx \
SMDS_MeshCell.hxx \
SMDS_MeshFace.hxx \
SMDS_MeshGroup.hxx \
SMDS_MeshIDFactory.hxx \
@ -54,6 +57,8 @@ salomeinclude_HEADERS = \
SMDS_IteratorOfElements.hxx \
SMDS_VolumeOfFaces.hxx \
SMDS_VolumeOfNodes.hxx \
SMDS_VtkEdge.hxx \
SMDS_VtkFace.hxx \
SMDS_VtkVolume.hxx \
SMDS_VtkCellIterator.hxx \
SMDS_PolyhedralVolumeOfNodes.hxx \
@ -83,6 +88,7 @@ dist_libSMDS_la_SOURCES = \
SMDS_VertexPosition.cxx \
SMDS_MeshNode.cxx \
SMDS_Mesh0DElement.cxx \
SMDS_LinearEdge.cxx \
SMDS_MeshEdge.cxx \
SMDS_MeshFace.cxx \
SMDS_MeshVolume.cxx \
@ -94,6 +100,8 @@ dist_libSMDS_la_SOURCES = \
SMDS_IteratorOfElements.cxx \
SMDS_VolumeOfFaces.cxx \
SMDS_VolumeOfNodes.cxx \
SMDS_VtkEdge.cxx \
SMDS_VtkFace.cxx \
SMDS_VtkVolume.cxx \
SMDS_VtkCellIterator.cxx \
SMDS_PolyhedralVolumeOfNodes.cxx \

View File

@ -1,4 +1,3 @@
#ifndef _OBJECTPOOL_HXX_
#define _OBJECTPOOL_HXX_
@ -6,7 +5,7 @@
#include <stack>
#include <iostream>
template <class X> class ObjectPool
template<class X> class ObjectPool
{
private:
@ -18,20 +17,20 @@ private:
int getNextFree()
{
for (int i=_nextFree; i< _maxAvail; i++)
for (int i = _nextFree; i < _maxAvail; i++)
if (_freeList[i] == true)
{
return i;
break;
}
{
return i;
break;
}
return _maxAvail;
}
void checkDelete(int chunkId)
{
int i0 = _chunkSize*chunkId;
int i1 =_chunkSize*(chunkId+1);
for (int i=i0; i < i1; i++)
int i0 = _chunkSize * chunkId;
int i1 = _chunkSize * (chunkId + 1);
for (int i = i0; i < i1; i++)
if (_freeList[i] == false)
return;
std::cerr << "a chunk to delete" << std::endl;
@ -52,8 +51,8 @@ public:
virtual ~ObjectPool()
{
for (int i=0; i<_chunkList.size(); i++)
delete [] _chunkList[i];
for (int i = 0; i < _chunkList.size(); i++)
delete[] _chunkList[i];
}
X* getNew()
@ -61,45 +60,56 @@ public:
X *obj = 0;
_nextFree = getNextFree();
if (_nextFree == _maxAvail)
{
X* newChunk = new X[_chunkSize];
_chunkList.push_back(newChunk);
_freeList.insert(_freeList.end(), _chunkSize, true);
_maxAvail += _chunkSize;
_freeList[_nextFree] = false;
obj = newChunk; // &newChunk[0];
}
{
X* newChunk = new X[_chunkSize];
_chunkList.push_back(newChunk);
_freeList.insert(_freeList.end(), _chunkSize, true);
_maxAvail += _chunkSize;
_freeList[_nextFree] = false;
obj = newChunk; // &newChunk[0];
}
else
{
int chunkId = _nextFree/_chunkSize;
int rank = _nextFree - chunkId*_chunkSize;
_freeList[_nextFree] = false;
obj = _chunkList[chunkId] + rank; // &_chunkList[chunkId][rank];
}
{
int chunkId = _nextFree / _chunkSize;
int rank = _nextFree - chunkId * _chunkSize;
_freeList[_nextFree] = false;
obj = _chunkList[chunkId] + rank; // &_chunkList[chunkId][rank];
}
//obj->init();
return obj;
}
void destroy(X* obj)
{
long adrobj = (long)(obj);
for (int i=0; i< _chunkList.size(); i++)
long adrobj = (long) (obj);
for (int i = 0; i < _chunkList.size(); i++)
{
X* chunk = _chunkList[i];
long adrmin = (long)(chunk);
if (adrobj < adrmin) continue;
long adrmax = (long)(chunk + _chunkSize);
if (adrobj >= adrmax) continue;
int rank = (adrobj -adrmin)/sizeof(X);
int toFree = i*_chunkSize + rank;
long adrmin = (long) (chunk);
if (adrobj < adrmin)
continue;
long adrmax = (long) (chunk + _chunkSize);
if (adrobj >= adrmax)
continue;
int rank = (adrobj - adrmin) / sizeof(X);
int toFree = i * _chunkSize + rank;
_freeList[toFree] = true;
if (toFree < _nextFree) _nextFree = toFree;
if (toFree < _nextFree)
_nextFree = toFree;
//obj->clean();
//checkDelete(i); compactage non fait
break;
}
}
// void destroy(int toFree)
// {
// // no control 0<= toFree < _freeList.size()
// _freeList[toFree] = true;
// if (toFree < _nextFree)
// _nextFree = toFree;
// }
};
#endif

View File

@ -46,7 +46,7 @@ class SMDS_EXPORT SMDS_FaceOfEdges:public SMDS_MeshFace
const SMDS_MeshEdge* edge4);
SMDSAbs_ElementType GetType() const;
virtual SMDSAbs_EntityType GetEntityType() const;
virtual SMDSAbs_EntityType GetEntityType() const;
int NbNodes() const;
int NbEdges() const;
int NbFaces() const;

View File

@ -0,0 +1,155 @@
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH SMDS : implementaion of Salome mesh data structure
// File : SMDS_LinearEdge.cxx
// Author : Jean-Michel BOULCOURT
// Module : SMESH
//
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include "SMDS_LinearEdge.hxx"
#include "SMDS_IteratorOfElements.hxx"
#include "SMDS_MeshNode.hxx"
#include "utilities.h"
using namespace std;
//=======================================================================
//function : SMDS_LinearEdge
//purpose :
//=======================================================================
SMDS_LinearEdge::SMDS_LinearEdge(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2)
{
//MESSAGE("SMDS_LinearEdge " << GetID());
myNodes[0]=node1;
myNodes[1]=node2;
}
//=======================================================================
//function : Print
//purpose :
//=======================================================================
void SMDS_LinearEdge::Print(ostream & OS) const
{
OS << "edge <" << GetID() << "> : (" << myNodes[0] << " , " << myNodes[1] <<
") " << endl;
}
int SMDS_LinearEdge::NbNodes() const
{
return 2;
}
int SMDS_LinearEdge::NbEdges() const
{
return 1;
}
class SMDS_LinearEdge_MyNodeIterator:public SMDS_ElemIterator
{
const SMDS_MeshNode *const* myNodes;
int myIndex;
public:
SMDS_LinearEdge_MyNodeIterator(const SMDS_MeshNode * const* nodes):
myNodes(nodes),myIndex(0) {}
bool more()
{
return myIndex<2;
}
const SMDS_MeshElement* next()
{
myIndex++;
return myNodes[myIndex-1];
}
};
SMDS_ElemIteratorPtr SMDS_LinearEdge::
elementsIterator(SMDSAbs_ElementType type) const
{
switch(type)
{
case SMDSAbs_Edge:
return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge);
case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_LinearEdge_MyNodeIterator(myNodes));
default:
return SMDS_ElemIteratorPtr
(new SMDS_IteratorOfElements
(this,type, SMDS_ElemIteratorPtr(new SMDS_LinearEdge_MyNodeIterator(myNodes))));
}
}
bool operator<(const SMDS_LinearEdge & e1, const SMDS_LinearEdge & e2)
{
int id11=e1.myNodes[0]->GetID();
int id21=e2.myNodes[0]->GetID();
int id12=e1.myNodes[1]->GetID();
int id22=e2.myNodes[1]->GetID();
int tmp;
if(id11>=id12)
{
tmp=id11;
id11=id12;
id12=tmp;
}
if(id21>=id22)
{
tmp=id21;
id21=id22;
id22=tmp;
}
if(id11<id21) return true;
else if(id11==id21) return (id21<id22);
else return false;
}
/*!
* \brief Return node by its index
* \param ind - node index
* \retval const SMDS_MeshNode* - the node
*/
const SMDS_MeshNode* SMDS_LinearEdge::GetNode(const int ind) const
{
return myNodes[ ind ];
}
//=======================================================================
//function : ChangeNodes
//purpose :
//=======================================================================
bool SMDS_LinearEdge::ChangeNodes(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2)
{
myNodes[0]=node1;
myNodes[1]=node2;
return true;
}

View File

@ -0,0 +1,64 @@
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH SMDS : implementaion of Salome mesh data structure
// File : SMDS_LinearEdge.hxx
// Module : SMESH
//
#ifndef _SMDS_LinearEdge_HeaderFile
#define _SMDS_LinearEdge_HeaderFile
#include "SMESH_SMDS.hxx"
#include "SMDS_MeshEdge.hxx"
#include <iostream>
class SMDS_EXPORT SMDS_LinearEdge:public SMDS_MeshEdge
{
public:
SMDS_LinearEdge(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2);
bool ChangeNodes(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2);
void Print(std::ostream & OS) const;
virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Edge; }
int NbNodes() const;
int NbEdges() const;
friend bool operator<(const SMDS_LinearEdge& e1, const SMDS_LinearEdge& e2);
/*!
* \brief Return node by its index
* \param ind - node index
* \retval const SMDS_MeshNode* - the node
*/
virtual const SMDS_MeshNode* GetNode(const int ind) const;
protected:
SMDS_ElemIteratorPtr
elementsIterator(SMDSAbs_ElementType type) const;
protected:
const SMDS_MeshNode* myNodes[3];
};
#endif

View File

@ -48,7 +48,7 @@ using namespace std;
#include <sys/sysinfo.h>
#endif
// number of added entitis to check memory after
// number of added entities to check memory after
#define CHECKMEMORY_INTERVAL 1000
vector<SMDS_Mesh*> SMDS_Mesh::_meshList = vector<SMDS_Mesh*>();
@ -116,7 +116,7 @@ SMDS_Mesh::SMDS_Mesh()
myHasConstructionEdges(false), myHasConstructionFaces(false),
myHasInverseElements(true),
myNodeMin(0), myNodeMax(0), myCellLinksSize(0),
myNodePool(0), myVolumePool(0)
myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0)
{
myMeshId = _meshList.size(); // --- index of the mesh to push back in the vector
MESSAGE("myMeshId=" << myMeshId);
@ -130,6 +130,8 @@ SMDS_Mesh::SMDS_Mesh()
myElementIDFactory->SetMesh(this);
_meshList.push_back(this);
myNodePool = new ObjectPool<SMDS_MeshNode>(SMDS_Mesh::chunkSize);
myEdgePool = new ObjectPool<SMDS_VtkEdge>(SMDS_Mesh::chunkSize);
myFacePool = new ObjectPool<SMDS_VtkFace>(SMDS_Mesh::chunkSize);
myVolumePool = new ObjectPool<SMDS_VtkVolume>(SMDS_Mesh::chunkSize);
myNodes.clear();
@ -157,6 +159,8 @@ SMDS_Mesh::SMDS_Mesh(SMDS_Mesh * parent)
myHasConstructionEdges(false), myHasConstructionFaces(false),
myHasInverseElements(true),
myNodePool(parent->myNodePool),
myEdgePool(parent->myEdgePool),
myFacePool(parent->myFacePool),
myVolumePool(parent->myVolumePool)
{
}
@ -295,10 +299,17 @@ SMDS_MeshEdge* SMDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
int ID)
{
if ( !n1 || !n2 ) return 0;
SMDS_MeshEdge * edge = 0;
//if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
//MESSAGE("AddEdgeWithID " << ID)
SMDS_MeshEdge * edge=new SMDS_MeshEdge(n1,n2);
// --- retreive nodes ID
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(n1->getId());
nodeIds.push_back(n2->getId());
SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
edgevtk->init(nodeIds, this);
edge = edgevtk;
adjustmyCellsCapacity(ID);
myCells[ID] = edge;
myInfo.myNbEdges++;
@ -346,7 +357,7 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
int ID)
{
//MESSAGE("AddFaceWithID " << ID)
SMDS_MeshFace * face=createTriangle(n1, n2, n3);
SMDS_MeshFace * face=createTriangle(n1, n2, n3, myElementIDFactory->GetFreeID());
if (face && !registerElement(ID, face)) {
RemoveElement(face, false);
@ -565,7 +576,17 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
return NULL;
}
else {
volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4);
// --- retrieve nodes ID
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(n1->getId());
nodeIds.push_back(n3->getId()); // order SMDS-->VTK
nodeIds.push_back(n2->getId());
nodeIds.push_back(n4->getId());
SMDS_VtkVolume *volvtk = myVolumePool->getNew();
volvtk->init(nodeIds, this);
volume = volvtk;
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbTetras++;
@ -656,7 +677,18 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
return NULL;
}
else {
volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5);
// --- retrieve nodes ID
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(n1->getId());
nodeIds.push_back(n4->getId());
nodeIds.push_back(n3->getId());
nodeIds.push_back(n2->getId());
nodeIds.push_back(n5->getId());
SMDS_VtkVolume *volvtk = myVolumePool->getNew();
volvtk->init(nodeIds, this);
volume = volvtk;
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbPyramids++;
@ -752,7 +784,19 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
return NULL;
}
else {
volume=new SMDS_VolumeOfNodes(n1,n2,n3,n4,n5,n6);
// --- retrieve nodes ID
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(n1->getId());
nodeIds.push_back(n3->getId());
nodeIds.push_back(n2->getId());
nodeIds.push_back(n4->getId());
nodeIds.push_back(n6->getId());
nodeIds.push_back(n5->getId());
SMDS_VtkVolume *volvtk = myVolumePool->getNew();
volvtk->init(nodeIds, this);
volume = volvtk;
adjustmyCellsCapacity(ID);
myCells[ID] = volume;
myInfo.myNbPrisms++;
@ -860,17 +904,17 @@ SMDS_MeshVolume* SMDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
return NULL;
}
else {
// --- retreive nodes ID
// --- retrieve nodes ID
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(n1->getId());
nodeIds.push_back(n2->getId());
nodeIds.push_back(n3->getId());
nodeIds.push_back(n4->getId());
nodeIds.push_back(n3->getId());
nodeIds.push_back(n2->getId());
nodeIds.push_back(n5->getId());
nodeIds.push_back(n6->getId());
nodeIds.push_back(n7->getId());
nodeIds.push_back(n8->getId());
nodeIds.push_back(n7->getId());
nodeIds.push_back(n6->getId());
SMDS_VtkVolume *volvtk = myVolumePool->getNew();
volvtk->init(nodeIds, this);
@ -1174,7 +1218,7 @@ bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
element->myMeshId = myMeshId;
SMDS_MeshCell *cell = dynamic_cast<SMDS_MeshCell*>(element);
assert(cell);
MYASSERT(cell);
int vtkId = cell->getVtkId();
if (vtkId == -1)
vtkId = myElementIDFactory->SetInVtkGrid(element);
@ -1204,18 +1248,22 @@ bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
///////////////////////////////////////////////////////////////////////////////
const SMDS_MeshNode * SMDS_Mesh::FindNode(int ID) const
{
if (ID <0 || ID >= myNodes.size())
return NULL;
if (ID < 0 || ID >= myNodes.size())
{
MESSAGE("----------------------------------- bad ID " << ID << " " << myNodes.size());
return 0;
}
return (const SMDS_MeshNode *)myNodes[ID];
}
///////////////////////////////////////////////////////////////////////////////
///Create a triangle and add it to the current mesh. This methode do not bind a
///Create a triangle and add it to the current mesh. This method do not bind an
///ID to the create triangle.
///////////////////////////////////////////////////////////////////////////////
SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2,
const SMDS_MeshNode * node3)
const SMDS_MeshNode * node3,
int ID)
{
if ( !node1 || !node2 || !node3) return 0;
// if ( myFaces.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
@ -1226,7 +1274,7 @@ SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
edge2=FindEdgeOrCreate(node2,node3);
edge3=FindEdgeOrCreate(node3,node1);
int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
//int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
SMDS_MeshFace * face = new SMDS_FaceOfEdges(edge1,edge2,edge3);
adjustmyCellsCapacity(ID);
myCells[ID] = face;
@ -1235,8 +1283,17 @@ SMDS_MeshFace * SMDS_Mesh::createTriangle(const SMDS_MeshNode * node1,
}
else
{
int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3);
// --- retrieve nodes ID
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(node1->getId());
nodeIds.push_back(node2->getId());
nodeIds.push_back(node3->getId());
SMDS_MeshFace * face = 0;
SMDS_VtkFace *facevtk = myFacePool->getNew();
facevtk->init(nodeIds, this);
face = facevtk;
adjustmyCellsCapacity(ID);
myCells[ID] = face;
myInfo.myNbTriangles++;
@ -1273,8 +1330,18 @@ SMDS_MeshFace * SMDS_Mesh::createQuadrangle(const SMDS_MeshNode * node1,
}
else
{
//MESSAGE("createQuadrangle " << ID);
SMDS_MeshFace * face = new SMDS_FaceOfNodes(node1,node2,node3,node4);
// --- retrieve nodes ID
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(node1->getId());
nodeIds.push_back(node2->getId());
nodeIds.push_back(node3->getId());
nodeIds.push_back(node4->getId());
SMDS_MeshFace * face = 0;
SMDS_VtkFace *facevtk = myFacePool->getNew();
facevtk->init(nodeIds, this);
face = facevtk;
adjustmyCellsCapacity(ID);
myCells[ID] = face;
myInfo.myNbQuadrangles++;
@ -1375,6 +1442,7 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
const SMDS_MeshNode * nodes[],
const int nbnodes)
{
MYASSERT(0); // REVOIR LES TYPES
// keep current nodes of elem
set<const SMDS_MeshElement*> oldNodes;
SMDS_ElemIteratorPtr itn = element->nodesIterator();
@ -1396,7 +1464,7 @@ bool SMDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * element,
}
case SMDSAbs_Edge: {
if ( nbnodes == 2 ) {
if ( SMDS_MeshEdge* edge = dynamic_cast<SMDS_MeshEdge*>( elem ))
if ( SMDS_VtkEdge* edge = dynamic_cast<SMDS_VtkEdge*>( elem ))
Ok = edge->ChangeNodes( nodes[0], nodes[1] );
}
else if ( nbnodes == 3 ) {
@ -1610,7 +1678,14 @@ SMDS_MeshEdge* SMDS_Mesh::FindEdgeOrCreate(const SMDS_MeshNode * node1,
//if ( myEdges.Extent() % CHECKMEMORY_INTERVAL == 0 ) CheckMemory();
int ID = myElementIDFactory->GetFreeID(); // -PR- voir si on range cet element
adjustmyCellsCapacity(ID);
toReturn=new SMDS_MeshEdge(node1,node2);
vector<vtkIdType> nodeIds;
nodeIds.clear();
nodeIds.push_back(node1->getId());
nodeIds.push_back(node2->getId());
SMDS_VtkEdge *edgevtk = myEdgePool->getNew();
edgevtk->init(nodeIds, this);
toReturn = edgevtk;
myCells[ID] = toReturn;
myInfo.myNbEdges++;
}
@ -1708,7 +1783,8 @@ SMDS_MeshFace* SMDS_Mesh::FindFaceOrCreate(const SMDS_MeshNode *node1,
SMDS_MeshFace * toReturn=NULL;
toReturn = const_cast<SMDS_MeshFace*>(FindFace(node1,node2,node3));
if(toReturn==NULL) {
toReturn = createTriangle(node1,node2,node3);
int ID = myElementIDFactory->GetFreeID();
toReturn = createTriangle(node1,node2,node3, ID);
}
return toReturn;
}
@ -1892,7 +1968,10 @@ const SMDS_MeshFace* SMDS_Mesh::FindFace(const SMDS_MeshNode *node1,
const SMDS_MeshElement* SMDS_Mesh::FindElement(int IDelem) const
{
if ((IDelem < 0) || IDelem >= myCells.size())
return 0;
{
MESSAGE("----------------------------------- bad IDelem " << IDelem << " " << myCells.size());
return 0;
}
return myCells[IDelem];
}
@ -2441,7 +2520,9 @@ static set<const SMDS_MeshElement*> * intersectionOfSets(
}
///////////////////////////////////////////////////////////////////////////////
/// Return the list of finit elements owning the given element
/// Return the list of finite elements owning the given element: elements
/// containing all the nodes of the given element, for instance faces and
/// volumes containing a given edge.
///////////////////////////////////////////////////////////////////////////////
static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement * element)
{
@ -2453,16 +2534,24 @@ static set<const SMDS_MeshElement*> * getFinitElements(const SMDS_MeshElement *
int i=0;
while(itNodes->more())
{
const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(itNodes->next());
const SMDS_MeshElement* node = itNodes->next();
MYASSERT(node);
const SMDS_MeshNode * n=static_cast<const SMDS_MeshNode*>(node);
SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
//initSet[i]=set<const SMDS_MeshElement*>();
while(itFe->more())
initSet[i].insert(itFe->next());
{
const SMDS_MeshElement* elem = itFe->next();
MYASSERT(elem);
initSet[i].insert(elem);
}
i++;
}
set<const SMDS_MeshElement*> *retSet=intersectionOfSets(initSet, numberOfSets);
MESSAGE("nb elems " << i << " intersection " << retSet->size());
delete [] initSet;
return retSet;
}
@ -2577,8 +2666,8 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
///////////////////////////////////////////////////////////////////////////////
///@param elem The element to delete
///@param removedElems contains all removed elements
///@param removedNodes contains all removed nodes
///@param removedElems to be filled with all removed elements
///@param removedNodes to be filled with all removed nodes
///@param removenodes if true remaining nodes will be removed
///////////////////////////////////////////////////////////////////////////////
void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
@ -2586,6 +2675,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
list<const SMDS_MeshElement *>& removedNodes,
bool removenodes)
{
MESSAGE("SMDS_Mesh::RemoveElement " << elem->GetID() << " " << removenodes);
// get finite elements built on elem
set<const SMDS_MeshElement*> * s1;
if (elem->GetType() == SMDSAbs_0DElement ||
@ -2638,7 +2728,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
switch((*it)->GetType())
{
case SMDSAbs_Node:
MESSAGE("Internal Error: This should not happen");
MYASSERT("Internal Error: This should not happen");
break;
case SMDSAbs_0DElement:
myCells[(*it)->GetID()] = 0; // -PR- ici ou dans myElementIDFactory->ReleaseID ?
@ -2660,6 +2750,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
//MESSAGE( "SMDS: RM elem " << (*it)->GetID() );
removedElems.push_back( (*it) );
myElementIDFactory->ReleaseID((*it)->GetID());
MYASSERT("problem delete elem")
delete (*it);
it++;
}
@ -2675,6 +2766,7 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
myInfo.myNbNodes--;
myNodeIDFactory->ReleaseID((*it)->GetID());
removedNodes.push_back( (*it) );
MYASSERT("problem delete node")
delete *it;
it++;
}
@ -2690,16 +2782,19 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
///////////////////////////////////////////////////////////////////////////////
void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
{
int elemId = elem->GetID();
//MESSAGE("SMDS_Mesh::RemoveFreeElement " << elemId);
SMDSAbs_ElementType aType = elem->GetType();
SMDS_MeshElement* todest = (SMDS_MeshElement*)(elem);
if (aType == SMDSAbs_Node) {
// only free node can be removed by this method
const SMDS_MeshNode* n = static_cast<const SMDS_MeshNode*>(elem);
const SMDS_MeshNode* n = static_cast<SMDS_MeshNode*>(todest);
SMDS_ElemIteratorPtr itFe = n->GetInverseElementIterator();
if (!itFe->more()) { // free node
myNodes[elem->GetID()] = 0;
myNodes[elemId] = 0;
myInfo.myNbNodes--;
myNodeIDFactory->ReleaseID(elem->GetID());
delete elem;
myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
myNodeIDFactory->ReleaseID(elemId);
}
} else {
if (hasConstructionEdges() || hasConstructionFaces())
@ -2715,28 +2810,31 @@ void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
}
// in meshes without descendants elements are always free
switch (aType) {
switch (aType) {
case SMDSAbs_0DElement:
myCells[elem->GetID()] = 0;
myCells[elemId] = 0;
myInfo.remove(elem);
delete elem;
break;
case SMDSAbs_Edge:
myCells[elem->GetID()] = 0;
myCells[elemId] = 0;
myInfo.RemoveEdge(elem);
myEdgePool->destroy(static_cast<SMDS_VtkEdge*>(todest));
break;
case SMDSAbs_Face:
myCells[elem->GetID()] = 0;
myCells[elemId] = 0;
myInfo.RemoveFace(elem);
myFacePool->destroy(static_cast<SMDS_VtkFace*>(todest));
break;
case SMDSAbs_Volume:
myCells[elem->GetID()] = 0;
myCells[elemId] = 0;
myInfo.RemoveVolume(elem);
myVolumePool->destroy(static_cast<SMDS_VtkVolume*>(todest));
break;
default:
break;
}
myElementIDFactory->ReleaseID(elem->GetID());
delete elem;
myElementIDFactory->ReleaseID(elemId);
}
}

View File

@ -39,6 +39,8 @@
#include "SMDS_MeshInfo.hxx"
#include "SMDS_ElemIterator.hxx"
#include "SMDS_VolumeOfNodes.hxx"
#include "SMDS_VtkEdge.hxx"
#include "SMDS_VtkFace.hxx"
#include "SMDS_VtkVolume.hxx"
#include "ObjectPool.hxx"
@ -48,6 +50,9 @@
#include <vector>
#include <vtkSystemIncludes.h>
#include "Utils_SALOME_Exception.hxx"
#define MYASSERT(val) if (!(val)) throw SALOME_Exception(LOCALIZED("assertion not verified"));
class vtkUnstructuredGrid;
class SMDS_EXPORT SMDS_Mesh:public SMDS_MeshObject{
@ -558,7 +563,8 @@ public:
typedef std::vector<SMDS_MeshCell *> SetOfCells;
void updateNodeMinMax();
inline int fromVtkToSmds(int vtkid) { return myVtkIndex[vtkid]; };
inline int fromVtkToSmds(int vtkid) { MYASSERT(vtkid>=0); return myVtkIndex[vtkid]; };
inline int fromSmdsToVtk(int smdsid) { MYASSERT(smdsid>=0); return myIDElements[smdsid]; };
void incrementNodesCapacity(int nbNodes);
void incrementCellsCapacity(int nbCells);
@ -572,7 +578,8 @@ private:
SMDS_MeshFace * createTriangle(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2,
const SMDS_MeshNode * node3);
const SMDS_MeshNode * node3,
int ID);
SMDS_MeshFace * createQuadrangle(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2,
const SMDS_MeshNode * node3,
@ -615,6 +622,8 @@ private:
//! Small objects like SMDS_VtkVolume are allocated by chunks to limit memory costs of new
ObjectPool<SMDS_VtkVolume>* myVolumePool;
ObjectPool<SMDS_VtkFace>* myFacePool;
ObjectPool<SMDS_VtkEdge>* myEdgePool;
//! SMDS_MeshNodes refer to vtk nodes (vtk id = index in myNodes),store reference to this mesh, and subshape
SetOfNodes myNodes;

View File

@ -81,6 +81,11 @@ SMDSAbs_ElementType SMDS_Mesh0DElement::GetType() const
return SMDSAbs_0DElement;
}
vtkIdType SMDS_Mesh0DElement::GetVtkType() const
{
return VTK_VERTEX;
}
//=======================================================================
//function : elementsIterator
//purpose :

View File

@ -40,6 +40,7 @@ class SMDS_EXPORT SMDS_Mesh0DElement: public SMDS_MeshCell
void Print (std::ostream & OS) const;
SMDSAbs_ElementType GetType() const;
virtual vtkIdType GetVtkType() const;
SMDSAbs_EntityType GetEntityType() const {return SMDSEntity_0D;}
int NbNodes() const;
int NbEdges() const;

View File

@ -1,160 +1,11 @@
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH SMDS : implementaion of Salome mesh data structure
// File : SMDS_MeshEdge.cxx
// Author : Jean-Michel BOULCOURT
// Module : SMESH
//
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include "SMDS_MeshEdge.hxx"
#include "SMDS_IteratorOfElements.hxx"
#include "SMDS_MeshNode.hxx"
#include "utilities.h"
using namespace std;
//=======================================================================
//function : SMDS_MeshEdge
//purpose :
//=======================================================================
SMDS_MeshEdge::SMDS_MeshEdge(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2)
{
//MESSAGE("SMDS_MeshEdge " << GetID());
myNodes[0]=node1;
myNodes[1]=node2;
}
//=======================================================================
//function : Print
//purpose :
//=======================================================================
void SMDS_MeshEdge::Print(ostream & OS) const
{
OS << "edge <" << GetID() << "> : (" << myNodes[0] << " , " << myNodes[1] <<
") " << endl;
}
int SMDS_MeshEdge::NbNodes() const
{
return 2;
}
int SMDS_MeshEdge::NbEdges() const
{
return 1;
}
SMDSAbs_ElementType SMDS_MeshEdge::GetType() const
{
return SMDSAbs_Edge;
}
class SMDS_MeshEdge_MyNodeIterator:public SMDS_ElemIterator
vtkIdType SMDS_MeshEdge::GetVtkType() const
{
const SMDS_MeshNode *const* myNodes;
int myIndex;
public:
SMDS_MeshEdge_MyNodeIterator(const SMDS_MeshNode * const* nodes):
myNodes(nodes),myIndex(0) {}
bool more()
{
return myIndex<2;
}
const SMDS_MeshElement* next()
{
myIndex++;
return myNodes[myIndex-1];
}
};
SMDS_ElemIteratorPtr SMDS_MeshEdge::
elementsIterator(SMDSAbs_ElementType type) const
{
switch(type)
{
case SMDSAbs_Edge:
return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge);
case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_MeshEdge_MyNodeIterator(myNodes));
default:
return SMDS_ElemIteratorPtr
(new SMDS_IteratorOfElements
(this,type, SMDS_ElemIteratorPtr(new SMDS_MeshEdge_MyNodeIterator(myNodes))));
}
}
bool operator<(const SMDS_MeshEdge & e1, const SMDS_MeshEdge & e2)
{
int id11=e1.myNodes[0]->GetID();
int id21=e2.myNodes[0]->GetID();
int id12=e1.myNodes[1]->GetID();
int id22=e2.myNodes[1]->GetID();
int tmp;
if(id11>=id12)
{
tmp=id11;
id11=id12;
id12=tmp;
}
if(id21>=id22)
{
tmp=id21;
id21=id22;
id22=tmp;
}
if(id11<id21) return true;
else if(id11==id21) return (id21<id22);
else return false;
}
/*!
* \brief Return node by its index
* \param ind - node index
* \retval const SMDS_MeshNode* - the node
*/
const SMDS_MeshNode* SMDS_MeshEdge::GetNode(const int ind) const
{
return myNodes[ ind ];
}
//=======================================================================
//function : ChangeNodes
//purpose :
//=======================================================================
bool SMDS_MeshEdge::ChangeNodes(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2)
{
myNodes[0]=node1;
myNodes[1]=node2;
return true;
return VTK_POLY_VERTEX; // --- must be reimplemented in derived classes
}

View File

@ -1,65 +1,15 @@
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// SMESH SMDS : implementaion of Salome mesh data structure
// File : SMDS_MeshEdge.hxx
// Module : SMESH
//
#ifndef _SMDS_MeshEdge_HeaderFile
#define _SMDS_MeshEdge_HeaderFile
#ifndef _SMDS_MESHEDGE_HXX_
#define _SMDS_MESHEDGE_HXX_
#include "SMESH_SMDS.hxx"
#include "SMDS_MeshCell.hxx"
#include <iostream>
class SMDS_EXPORT SMDS_MeshEdge:public SMDS_MeshCell
{
public:
SMDS_MeshEdge(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2);
bool ChangeNodes(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2);
void Print(std::ostream & OS) const;
virtual SMDSAbs_ElementType GetType() const;
virtual SMDSAbs_EntityType GetEntityType() const { return SMDSEntity_Edge; }
int NbNodes() const;
int NbEdges() const;
friend bool operator<(const SMDS_MeshEdge& e1, const SMDS_MeshEdge& e2);
/*!
* \brief Return node by its index
* \param ind - node index
* \retval const SMDS_MeshNode* - the node
*/
virtual const SMDS_MeshNode* GetNode(const int ind) const;
protected:
SMDS_ElemIteratorPtr
elementsIterator(SMDSAbs_ElementType type) const;
protected:
const SMDS_MeshNode* myNodes[3];
SMDSAbs_ElementType GetType() const;
virtual vtkIdType GetVtkType() const;
};
#endif

View File

@ -36,6 +36,9 @@
#include <vector>
#include <iostream>
#include <vtkType.h>
#include <vtkCellType.h>
//typedef unsigned short UShortType;
typedef short ShortType;
@ -50,6 +53,7 @@ class SMDS_Mesh;
*/
// ============================================================
class SMDS_EXPORT SMDS_MeshElement:public SMDS_MeshObject
{
public:
@ -66,6 +70,7 @@ public:
///Return the type of the current element
virtual SMDSAbs_ElementType GetType() const = 0;
virtual vtkIdType GetVtkType() const = 0;
virtual bool IsPoly() const { return false; };
virtual bool IsQuadratic() const;
//! Return type of entity

View File

@ -127,7 +127,9 @@ SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID)
//=======================================================================
void SMDS_MeshElementIDFactory::ReleaseID(const int ID)
{
int vtkId = myMesh->myIDElements[ID];
myMesh->myIDElements[ID] = -1;
myMesh->myVtkIndex[vtkId] = -1;
SMDS_MeshIDFactory::ReleaseID(ID);
if (ID == myMax)
myMax = 0;

View File

@ -27,3 +27,8 @@ SMDSAbs_ElementType SMDS_MeshFace::GetType() const
{
return SMDSAbs_Face;
}
vtkIdType SMDS_MeshFace::GetVtkType() const
{
return VTK_POLY_LINE; // --- must be reimplemented in derived classes
}

View File

@ -34,6 +34,7 @@ class SMDS_EXPORT SMDS_MeshFace:public SMDS_MeshCell
{
public:
SMDSAbs_ElementType GetType() const;
virtual vtkIdType GetVtkType() const;
};
#endif

View File

@ -64,6 +64,7 @@ void SMDS_MeshNode::init(int id, int meshId, int shapeId, double x, double y, do
myID = id;
myMeshId = meshId;
myShapeId = shapeId;
myIdInShape = -1;
//MESSAGE("Node " << myID << " (" << x << ", " << y << ", " << z << ")");
SMDS_Mesh* mesh = SMDS_Mesh::_meshList[myMeshId];
vtkUnstructuredGrid * grid = mesh->getGrid();
@ -118,8 +119,10 @@ SMDS_MeshNode::~SMDS_MeshNode()
void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent)
{
MESSAGE("RemoveInverseElement " << myID << " " << parent->GetID());
SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myID, parent->GetID()); // -PR- GetVtkID ?
//MESSAGE("RemoveInverseElement " << myID << " " << parent->GetID());
const SMDS_MeshCell* cell = dynamic_cast<const SMDS_MeshCell*>(parent);
MYASSERT(cell);
SMDS_Mesh::_meshList[myMeshId]->getGrid()->RemoveReferenceToCell(myID, cell->getVtkId());
}
//=======================================================================
@ -299,6 +302,11 @@ SMDSAbs_ElementType SMDS_MeshNode::GetType() const
return SMDSAbs_Node;
}
vtkIdType SMDS_MeshNode::GetVtkType() const
{
return VTK_VERTEX;
}
//=======================================================================
//function : AddInverseElement
//purpose :

View File

@ -57,6 +57,7 @@ public:
void SetPosition(const SMDS_PositionPtr& aPos);
const SMDS_PositionPtr& GetPosition() const;
SMDSAbs_ElementType GetType() const;
virtual vtkIdType GetVtkType() const;
SMDSAbs_EntityType GetEntityType() const {return SMDSEntity_Node;}
int NbNodes() const;
void setXYZ(double x, double y, double z);

View File

@ -35,3 +35,7 @@ SMDSAbs_ElementType SMDS_MeshVolume::GetType() const
return SMDSAbs_Volume;
}
vtkIdType SMDS_MeshVolume::GetVtkType() const
{
return VTK_CONVEX_POINT_SET; // --- must be reimplemented in derived classes
}

View File

@ -35,5 +35,6 @@ class SMDS_EXPORT SMDS_MeshVolume:public SMDS_MeshCell
public:
SMDSAbs_ElementType GetType() const;
virtual vtkIdType GetVtkType() const;
};
#endif

View File

@ -40,7 +40,7 @@ using namespace std;
SMDS_QuadraticEdge::SMDS_QuadraticEdge(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2,
const SMDS_MeshNode * node12)
:SMDS_MeshEdge(node1,node2)
:SMDS_LinearEdge(node1,node2)
{
myNodes[2]=node12;
}

View File

@ -28,10 +28,10 @@
#include "SMESH_SMDS.hxx"
#include "SMDS_MeshEdge.hxx"
#include "SMDS_LinearEdge.hxx"
#include <iostream>
class SMDS_EXPORT SMDS_QuadraticEdge: public SMDS_MeshEdge
class SMDS_EXPORT SMDS_QuadraticEdge: public SMDS_LinearEdge
{
public:

View File

@ -43,6 +43,9 @@ SMDS_CellLinks::~SMDS_CellLinks()
{
}
/*! initialize an SMDS_CellLinks instance instead of a vtkCellLinks instance
*
*/
void SMDS_UnstructuredGrid::BuildLinks()
{
// Remove the old links if they are already built

View File

@ -54,7 +54,7 @@ class SMDS_EXPORT SMDS_VolumeOfFaces:public SMDS_MeshVolume
const SMDS_MeshFace * face5,
const SMDS_MeshFace * face6);
virtual SMDSAbs_EntityType GetEntityType() const;
virtual SMDSAbs_EntityType GetEntityType() const;
void Print(std::ostream & OS) const;
int NbFaces() const;

View File

@ -1,12 +1,57 @@
#include "SMDS_VtkCellIterator.hxx"
SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId):
_mesh(mesh), _cellId(vtkCellId), _index(0)
{
SMDS_VtkCellIterator::SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType) :
_mesh(mesh), _cellId(vtkCellId), _index(0), _type(aType)
{
vtkUnstructuredGrid* grid = _mesh->getGrid();
_vtkIdList = grid->GetCell(_cellId)->GetPointIds();
_vtkIdList = vtkIdList::New();
grid->GetCellPoints(_cellId, _vtkIdList);
_nbNodes = _vtkIdList->GetNumberOfIds();
vtkIdType tempid;
switch (_type)
{
case SMDSEntity_Tetra:
{
tempid = _vtkIdList->GetId(1);
_vtkIdList->SetId(1, _vtkIdList->GetId(2));
_vtkIdList->SetId(2, tempid);
break;
}
case SMDSEntity_Pyramid:
{
tempid = _vtkIdList->GetId(1);
_vtkIdList->SetId(1, _vtkIdList->GetId(3));
_vtkIdList->SetId(3, tempid);
break;
}
case SMDSEntity_Penta:
{
tempid = _vtkIdList->GetId(1);
_vtkIdList->SetId(1, _vtkIdList->GetId(2));
_vtkIdList->SetId(2, tempid);
tempid = _vtkIdList->GetId(4);
_vtkIdList->SetId(4, _vtkIdList->GetId(5));
_vtkIdList->SetId(5, tempid);
break;
}
case SMDSEntity_Hexa:
{
tempid = _vtkIdList->GetId(1);
_vtkIdList->SetId(1, _vtkIdList->GetId(3));
_vtkIdList->SetId(3, tempid);
tempid = _vtkIdList->GetId(5);
_vtkIdList->SetId(5, _vtkIdList->GetId(7));
_vtkIdList->SetId(7, tempid);
break;
}
default:
break;
}
}
SMDS_VtkCellIterator::~SMDS_VtkCellIterator()
{
_vtkIdList->Delete();
}
bool SMDS_VtkCellIterator::more()

View File

@ -3,6 +3,7 @@
#include "SMDS_ElemIterator.hxx"
#include "SMDS_Mesh.hxx"
#include "SMDSAbs_ElementType.hxx"
#include <vtkCell.h>
#include <vtkIdList.h>
@ -10,7 +11,8 @@
class SMDS_VtkCellIterator : public SMDS_ElemIterator
{
public:
SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId);
SMDS_VtkCellIterator(SMDS_Mesh* mesh, int vtkCellId, SMDSAbs_EntityType aType);
virtual ~SMDS_VtkCellIterator();
virtual bool more();
virtual const SMDS_MeshElement* next();
protected:
@ -18,6 +20,7 @@ protected:
int _cellId;
int _index;
int _nbNodes;
SMDSAbs_EntityType _type;
vtkIdList* _vtkIdList;
};

86
src/SMDS/SMDS_VtkEdge.cxx Normal file
View File

@ -0,0 +1,86 @@
#include "SMDS_VtkEdge.hxx"
#include "SMDS_MeshNode.hxx"
#include "SMDS_Mesh.hxx"
#include "SMDS_VtkCellIterator.hxx"
#include "utilities.h"
#include <vector>
using namespace std;
SMDS_VtkEdge::SMDS_VtkEdge()
{
}
SMDS_VtkEdge::SMDS_VtkEdge(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{
init(nodeIds, mesh);
}
SMDS_VtkEdge::~SMDS_VtkEdge()
{
}
void SMDS_VtkEdge::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{
vtkUnstructuredGrid* grid = mesh->getGrid();
myIdInShape = -1;
myMeshId = mesh->getMeshId();
myVtkID = grid->InsertNextLinkedCell(VTK_LINE, nodeIds.size(), &nodeIds[0]);
}
bool SMDS_VtkEdge::ChangeNodes(const SMDS_MeshNode * node1,
const SMDS_MeshNode * node2)
{
return true;
}
void SMDS_VtkEdge::Print(std::ostream & OS) const
{
OS << "edge <" << GetID() << "> : ";
}
int SMDS_VtkEdge::NbNodes() const
{
return 2;
}
int SMDS_VtkEdge::NbEdges() const
{
return 1;
}
SMDSAbs_EntityType SMDS_VtkEdge::GetEntityType() const
{
return SMDSEntity_Edge;
}
vtkIdType SMDS_VtkEdge::GetVtkType() const
{
return VTK_LINE;
}
/*!
* \brief Return node by its index
* \param ind - node index
* \retval const SMDS_MeshNode* - the node
*/
const SMDS_MeshNode*
SMDS_VtkEdge::GetNode(const int ind) const
{
return 0;
}
SMDS_ElemIteratorPtr SMDS_VtkEdge::elementsIterator(SMDSAbs_ElementType type) const
{
switch (type)
{
case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(
SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
default:
MESSAGE("ERROR : Iterator not implemented");
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
}
}

33
src/SMDS/SMDS_VtkEdge.hxx Normal file
View File

@ -0,0 +1,33 @@
#ifndef _SMDS_VTKEDGE_HXX_
#define _SMDS_VTKEDGE_HXX_
#include "SMESH_SMDS.hxx"
#include "SMDS_MeshEdge.hxx"
#include <vtkUnstructuredGrid.h>
#include <vector>
class SMDS_EXPORT SMDS_VtkEdge: public SMDS_MeshEdge
{
public:
SMDS_VtkEdge();
SMDS_VtkEdge(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh);
~SMDS_VtkEdge();
void init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh);
bool ChangeNodes(const SMDS_MeshNode * node1, const SMDS_MeshNode * node2);
void Print(std::ostream & OS) const;
int NbNodes() const;
int NbEdges() const;
virtual vtkIdType GetVtkType() const;
virtual SMDSAbs_EntityType GetEntityType() const;
virtual const SMDS_MeshNode* GetNode(const int ind) const;
protected:
SMDS_ElemIteratorPtr
elementsIterator(SMDSAbs_ElementType type) const;
};
#endif

104
src/SMDS/SMDS_VtkFace.cxx Normal file
View File

@ -0,0 +1,104 @@
#include "SMDS_VtkFace.hxx"
#include "SMDS_MeshNode.hxx"
#include "SMDS_Mesh.hxx"
#include "SMDS_VtkCellIterator.hxx"
#include "utilities.h"
#include <vector>
using namespace std;
SMDS_VtkFace::SMDS_VtkFace()
{
}
SMDS_VtkFace::SMDS_VtkFace(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{
init(nodeIds, mesh);
}
SMDS_VtkFace::~SMDS_VtkFace()
{
}
void SMDS_VtkFace::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{
vtkUnstructuredGrid* grid = mesh->getGrid();
myIdInShape = -1;
myMeshId = mesh->getMeshId();
vtkIdType aType = VTK_TRIANGLE;
if (nodeIds.size() == 4)
aType = VTK_QUAD;
myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
}
bool SMDS_VtkFace::ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes)
{
return true;
}
void SMDS_VtkFace::Print(std::ostream & OS) const
{
OS << "edge <" << GetID() << "> : ";
}
int SMDS_VtkFace::NbEdges() const
{
return NbNodes();
}
int SMDS_VtkFace::NbFaces() const
{
return 1;
}
int SMDS_VtkFace::NbNodes() const
{
vtkUnstructuredGrid* grid = SMDS_Mesh::_meshList[myMeshId]->getGrid();
int nbPoints = grid->GetCell(myVtkID)->GetNumberOfPoints();
return nbPoints;
}
/*!
* \brief Return node by its index
* \param ind - node index
* \retval const SMDS_MeshNode* - the node
*/
const SMDS_MeshNode*
SMDS_VtkFace::GetNode(const int ind) const
{
return 0;
}
SMDSAbs_EntityType SMDS_VtkFace::GetEntityType() const
{
int nbNodes = NbNodes();
if (nbNodes == 3)
return SMDSEntity_Triangle;
else
return SMDSEntity_Quadrangle;
}
vtkIdType SMDS_VtkFace::GetVtkType() const
{
int nbNodes = NbNodes();
if (nbNodes == 3)
return VTK_TRIANGLE;
else
return VTK_QUAD;
}
SMDS_ElemIteratorPtr SMDS_VtkFace::elementsIterator(SMDSAbs_ElementType type) const
{
switch (type)
{
case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
default:
MESSAGE("ERROR : Iterator not implemented");
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
}
}

33
src/SMDS/SMDS_VtkFace.hxx Normal file
View File

@ -0,0 +1,33 @@
#ifndef _SMDS_VTKFACE_HXX_
#define _SMDS_VTKFACE_HXX_
#include "SMESH_SMDS.hxx"
#include "SMDS_MeshFace.hxx"
#include <vtkUnstructuredGrid.h>
#include <vector>
class SMDS_EXPORT SMDS_VtkFace: public SMDS_MeshFace
{
public:
SMDS_VtkFace();
SMDS_VtkFace(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh);
~SMDS_VtkFace();
void init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh);
bool ChangeNodes(const SMDS_MeshNode* nodes[], const int nbNodes);
void Print(std::ostream & OS) const;
int NbEdges() const;
int NbFaces() const;
int NbNodes() const;
virtual vtkIdType GetVtkType() const;
virtual SMDSAbs_EntityType GetEntityType() const;
virtual const SMDS_MeshNode* GetNode(const int ind) const;
protected:
SMDS_ElemIteratorPtr
elementsIterator(SMDSAbs_ElementType type) const;
};
#endif

View File

@ -21,8 +21,18 @@ SMDS_VtkVolume::SMDS_VtkVolume(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
void SMDS_VtkVolume::init(std::vector<vtkIdType> nodeIds, SMDS_Mesh* mesh)
{
vtkUnstructuredGrid* grid = mesh->getGrid();
myIdInShape = -1;
myMeshId = mesh->getMeshId();
myVtkID = grid->InsertNextLinkedCell(GetType(), nodeIds.size(), &nodeIds[0]);
vtkIdType aType = VTK_TETRA;
switch(nodeIds.size())
{
case 4: aType = VTK_TETRA; break;
case 5: aType = VTK_PYRAMID; break;
case 6: aType = VTK_WEDGE; break;
case 8:
default: aType = VTK_HEXAHEDRON; break;
}
myVtkID = grid->InsertNextLinkedCell(aType, nodeIds.size(), &nodeIds[0]);
}
bool SMDS_VtkVolume::ChangeNodes(const SMDS_MeshNode* nodes[],
@ -79,7 +89,7 @@ SMDS_ElemIteratorPtr SMDS_VtkVolume::elementsIterator(SMDSAbs_ElementType type)
switch(type)
{
case SMDSAbs_Node:
return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID));
return SMDS_ElemIteratorPtr(new SMDS_VtkCellIterator(SMDS_Mesh::_meshList[myMeshId], myVtkID, GetEntityType()));
default:
MESSAGE("ERROR : Iterator not implemented");
return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
@ -110,7 +120,21 @@ SMDSAbs_EntityType SMDS_VtkVolume::GetEntityType() const
case 5: aType = SMDSEntity_Pyramid; break;
case 6: aType = SMDSEntity_Penta; break;
case 8:
default: aType = SMDSEntity_Hexa; break;
default: aType = SMDSEntity_Hexa; 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:
default: aType = VTK_HEXAHEDRON; break;
}
return aType;
}

View File

@ -21,14 +21,9 @@ public:
int NbFaces() const;
int NbNodes() const;
int NbEdges() const;
virtual SMDSAbs_ElementType GetType() const;
virtual SMDSAbs_ElementType GetType() const;
virtual vtkIdType GetVtkType() const;
virtual SMDSAbs_EntityType GetEntityType() const;
/*!
* \brief Return node by its index
* \param ind - node index
* \retval const SMDS_MeshNode* - the node
*/
virtual const SMDS_MeshNode* GetNode(const int ind) const;
protected:

View File

@ -66,9 +66,10 @@ bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME, bool isElemDele
{
// if ( !IsComplexSubmesh() && NbElements() ) {
if (!isElemDeleted) // alive element has valid ID and can be found
if (!isElemDeleted) // alive element has valid ID and can be found
{
int idInSubShape = ME->getIdInShape();
//MESSAGE("SMESHDS_SubMesh::RemoveElement " << idInSubShape << " " << ME->GetID());
assert(idInSubShape >= 0);
assert(idInSubShape < myElements.size());
myElements[idInSubShape] = 0; // this vector entry is no more used
@ -117,6 +118,7 @@ bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N, bool isNodeDeleted)
if (!isNodeDeleted) // alive node has valid ID and can be found
{
int idInSubShape = N->getIdInShape();
//MESSAGE("SMESHDS_SubMesh::RemoveNode " << idInSubShape << " " << N->GetID());
assert(idInSubShape >= 0);
assert(idInSubShape < myNodes.size());
myNodes[idInSubShape] = 0; // this vector entry is no more used
@ -175,14 +177,27 @@ int SMESHDS_SubMesh::NbNodes() const
// class MySetIterator
// =====================
template<class ELEM, typename TSET> class MySetIterator:
public SMDS_SetIterator<ELEM, typename TSET::const_iterator >
template <class ELEM, typename TSET> class MySetIterator : public SMDS_Iterator<ELEM>
{
typedef SMDS_SetIterator<ELEM, typename TSET::const_iterator > TFather;
public:
MySetIterator(const TSET& s):TFather(s.begin(),s.end())
{
}
protected:
typename TSET::const_iterator _it, _end;
public:
MySetIterator(const TSET& table)
: _it(table.begin()), _end(table.end())
{
}
virtual bool more()
{
while((_it != _end) && (*_it == 0))
_it++;
return (_it != _end);
}
virtual ELEM next()
{
return *_it++;
}
};
// =====================
@ -258,7 +273,7 @@ SMDS_ElemIteratorPtr SMESHDS_SubMesh::GetElements() const
if ( IsComplexSubmesh() )
return SMDS_ElemIteratorPtr( new MyElemIterator( mySubMeshes ));
return SMDS_ElemIteratorPtr(new MySetIterator<const SMDS_MeshElement*,TElemSet>(myElements));
return SMDS_ElemIteratorPtr(new MySetIterator<const SMDS_MeshElement*, std::vector<const SMDS_MeshElement*> >(myElements));
}
//=======================================================================
@ -271,7 +286,7 @@ SMDS_NodeIteratorPtr SMESHDS_SubMesh::GetNodes() const
if ( IsComplexSubmesh() )
return SMDS_NodeIteratorPtr( new MyNodeIterator( mySubMeshes ));
return SMDS_NodeIteratorPtr(new MySetIterator<const SMDS_MeshNode*,TElemSet>(myNodes));
return SMDS_NodeIteratorPtr(new MySetIterator<const SMDS_MeshNode*, std::vector<const SMDS_MeshNode*> >(myNodes));
}
//=======================================================================

View File

@ -69,10 +69,8 @@ class SMESHDS_EXPORT SMESHDS_SubMesh
private:
typedef std::vector<const SMDS_MeshElement*> TElemSet;
TElemSet myElements;
TElemSet myNodes;
std::vector<const SMDS_MeshElement*> myElements;
std::vector<const SMDS_MeshNode*> myNodes;
int myUnusedIdNodes;
int myUnusedIdElements;

View File

@ -350,24 +350,24 @@ namespace SMESH
MESSAGE ( "SMESHGUI_VTKUtils::GetVisualObj(), freeMB=" << freeMB
<< ", usedMB=" << usedMB );
#endif
bool continu = false;
if ( usedMB * 10 > freeMB )
// even dont try to show
SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
else
// there is a chance to succeed
continu = SUIT_MessageBox::warning
(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
SUIT_MessageBox::Yes | SUIT_MessageBox::No,
SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
if ( !continu ) {
// remove the corresponding actors from all views
RemoveVisualObjectWithActors( theEntry );
aVisualObj.reset();
}
// bool continu = false;
// if ( usedMB * 10 > freeMB )
// // even dont try to show
// SUIT_MessageBox::warning(SMESHGUI::desktop(), QObject::tr("SMESH_WRN_WARNING"),
// QObject::tr("SMESH_NO_MESH_VISUALIZATION"));
// else
// // there is a chance to succeed
// continu = SUIT_MessageBox::warning
// (SMESHGUI::desktop(),
// QObject::tr("SMESH_WRN_WARNING"),
// QObject::tr("SMESH_CONTINUE_MESH_VISUALIZATION"),
// SUIT_MessageBox::Yes | SUIT_MessageBox::No,
// SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes;
// if ( !continu ) {
// // remove the corresponding actors from all views
// RemoveVisualObjectWithActors( theEntry );
// aVisualObj.reset();
// }
}
}

View File

@ -27,7 +27,7 @@
#include "SMESH_MeshEditor_i.hxx"
#include "SMDS_Mesh0DElement.hxx"
#include "SMDS_MeshEdge.hxx"
#include "SMDS_LinearEdge.hxx"
#include "SMDS_MeshFace.hxx"
#include "SMDS_MeshVolume.hxx"
#include "SMDS_PolyhedralVolumeOfNodes.hxx"
@ -3663,7 +3663,7 @@ CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
TIDSortedElemSet::iterator nIt = linkedNodes.begin();
for ( ; nIt != linkedNodes.end(); ++nIt )
{
SMDS_MeshEdge edge( node, cast2Node( *nIt ));
SMDS_LinearEdge edge( node, cast2Node( *nIt ));
tmpMesh.Copy( &edge );
}
// move copied node