From fe3703789b6aae6bdf951e78baa5d3b991d4abe2 Mon Sep 17 00:00:00 2001 From: prascle Date: Mon, 12 Oct 2009 09:13:38 +0000 Subject: [PATCH] PR: test of use of vtk structures in SMDS, first part: only nodes, tested with hexaheddrons --- src/SMDS/Notes | 31 +++++++ src/SMDS/SMDS_MeshNodeIDFactory.cxx | 130 ++++++++++++++++++++++++++++ src/SMDS/SMDS_MeshNodeIDFactory.hxx | 62 +++++++++++++ src/SMDS/SMDS_UnstructuredGrid.cxx | 79 +++++++++++++++++ src/SMDS/SMDS_UnstructuredGrid.hxx | 41 +++++++++ src/SMESH/memoire.h | 21 +++++ 6 files changed, 364 insertions(+) create mode 100644 src/SMDS/Notes create mode 100644 src/SMDS/SMDS_MeshNodeIDFactory.cxx create mode 100644 src/SMDS/SMDS_MeshNodeIDFactory.hxx create mode 100644 src/SMDS/SMDS_UnstructuredGrid.cxx create mode 100644 src/SMDS/SMDS_UnstructuredGrid.hxx create mode 100644 src/SMESH/memoire.h diff --git a/src/SMDS/Notes b/src/SMDS/Notes new file mode 100644 index 000000000..ac5dcf86f --- /dev/null +++ b/src/SMDS/Notes @@ -0,0 +1,31 @@ + + +SMDS_Mesh + static vector _meshList; --> retrouver un SMDS_Mesh + vtkUnstructuredGrid* myGrid; + + vector myNodes; --> meme index que dans le pointSet de myGrid + vector myCells; --> meme index que dans le cellTypes de myGrid + + + +SMDS_MeshElement + int myID; --> index dans la structure geree par SMDS_Mesh + int myMeshId; --> pour retrouver SMDS_Mesh* dans _meshList + int myShapeId; --> pour retrouver la subShape + + +SMDS_MeshNode: SMDS_MeshElement + SMDS_PositionPtr myPosition; --> objet position dans la shape geom + ##vector myInverseElements; --> pour retrouver les elements, vtkCellLinks + + +SMDS_MeshCell: SMDS_MeshElement --> generique pour tous les elements (cells) + + +========= TODO ============ + +enlever vtkId de SMDS_MeshCell, utiliser SMDS_MeshElementIDFactory. + +ajouter ID dans SMDS_Mesh::createTriangle +verifier ID dans SMDS_Mesh::Find*OrCreate \ No newline at end of file diff --git a/src/SMDS/SMDS_MeshNodeIDFactory.cxx b/src/SMDS/SMDS_MeshNodeIDFactory.cxx new file mode 100644 index 000000000..5eb2d6a86 --- /dev/null +++ b/src/SMDS/SMDS_MeshNodeIDFactory.cxx @@ -0,0 +1,130 @@ +// 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_MeshNodeIDFactory.cxx +// Author : Jean-Michel BOULCOURT +// Module : SMESH +// +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + +#include "SMDS_MeshNodeIDFactory.hxx" +#include "SMDS_MeshElement.hxx" +#include "SMDS_Mesh.hxx" + +#include +#include + +using namespace std; + +//======================================================================= +//function : SMDS_MeshNodeIDFactory +//purpose : +//======================================================================= +SMDS_MeshNodeIDFactory::SMDS_MeshNodeIDFactory(): + SMDS_MeshIDFactory(), + myMin(0), myMax(0) +{ +} + +//======================================================================= +//function : BindID +//purpose : +//======================================================================= +bool SMDS_MeshNodeIDFactory::BindID(int ID, SMDS_MeshElement * elem) +{ + updateMinMax (ID); + return true; +} + +//======================================================================= +//function : MeshElement +//purpose : +//======================================================================= +SMDS_MeshElement* SMDS_MeshNodeIDFactory::MeshElement(int ID) +{ + if ((ID<0) || (ID>myMax)) + return NULL; + const SMDS_MeshElement* elem = GetMesh()->FindNode(ID); + return (SMDS_MeshElement*)(elem); +} + +//======================================================================= +//function : ReleaseID +//purpose : +//======================================================================= +void SMDS_MeshNodeIDFactory::ReleaseID(const int ID) +{ + SMDS_MeshIDFactory::ReleaseID(ID); + if (ID == myMax) + myMax = 0; // --- force updateMinMax + if (ID == myMin) + myMax = 0; // --- force updateMinMax +} + +//======================================================================= +//function : GetMaxID +//purpose : +//======================================================================= + +int SMDS_MeshNodeIDFactory::GetMaxID() const +{ + if (myMax == 0) + updateMinMax(); + return myMax; +} + +//======================================================================= +//function : GetMinID +//purpose : +//======================================================================= + +int SMDS_MeshNodeIDFactory::GetMinID() const +{ + if (myMax == 0) + updateMinMax(); + return myMin; +} + +//======================================================================= +//function : updateMinMax +//purpose : +//======================================================================= + +void SMDS_MeshNodeIDFactory::updateMinMax() const +{ + myMesh->updateNodeMinMax(); + myMin = myMesh->MinNodeID(); + myMax = myMesh->MaxNodeID(); +} + +SMDS_ElemIteratorPtr SMDS_MeshNodeIDFactory::elementsIterator() const +{ + return myMesh->elementsIterator(SMDSAbs_Node); +} + +void SMDS_MeshNodeIDFactory::Clear() +{ + myMin = myMax = 0; + SMDS_MeshIDFactory::Clear(); +} diff --git a/src/SMDS/SMDS_MeshNodeIDFactory.hxx b/src/SMDS/SMDS_MeshNodeIDFactory.hxx new file mode 100644 index 000000000..941ce66d0 --- /dev/null +++ b/src/SMDS/SMDS_MeshNodeIDFactory.hxx @@ -0,0 +1,62 @@ +// 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_MeshElementIDFactory.hxx +// Module : SMESH +// +#ifndef _SMDS_MeshNodeIDFactory_HeaderFile +#define _SMDS_MeshNodeIDFactory_HeaderFile + +#include "SMESH_SMDS.hxx" + +#include "SMDS_MeshIDFactory.hxx" +#include "SMDS_ElemIterator.hxx" + +#include + +class SMDS_MeshElement; + +class SMDS_EXPORT SMDS_MeshNodeIDFactory:public SMDS_MeshIDFactory +{ +public: + SMDS_MeshNodeIDFactory(); + bool BindID(int ID, SMDS_MeshElement * elem); + SMDS_MeshElement * MeshElement(int ID); + virtual void ReleaseID(int ID); + int GetMaxID() const; + int GetMinID() const; + SMDS_ElemIteratorPtr elementsIterator() const; + virtual void Clear(); + +protected: + void updateMinMax() const; + void updateMinMax(int id) const + { + if (id > myMax) myMax = id; + if (id < myMin) myMin = id; + } + + mutable int myMin, myMax; + +}; + +#endif diff --git a/src/SMDS/SMDS_UnstructuredGrid.cxx b/src/SMDS/SMDS_UnstructuredGrid.cxx new file mode 100644 index 000000000..99bd56fb6 --- /dev/null +++ b/src/SMDS/SMDS_UnstructuredGrid.cxx @@ -0,0 +1,79 @@ + + +#include "SMDS_UnstructuredGrid.hxx" + +using namespace std; + +vtkCellLinks::Link* SMDS_CellLinks::AdjustSize(vtkIdType sz) +{ + vtkIdType i; + vtkCellLinks::Link *newArray; + vtkIdType newSize = sz; + vtkCellLinks::Link linkInit = {0,NULL}; + + newArray = new vtkCellLinks::Link[newSize]; + + for (i=0; iSize; i++) + { + newArray[i] = this->Array[i]; + } + + for (i=this->Size; i < newSize ; i++) + { + newArray[i] = linkInit; + } + + this->Size = newSize; + delete [] this->Array; + this->Array = newArray; + + return this->Array; +} + +SMDS_CellLinks* SMDS_CellLinks::New() +{ + return new SMDS_CellLinks(); +} + +SMDS_CellLinks::SMDS_CellLinks() : vtkCellLinks() +{ +} + +SMDS_CellLinks::~SMDS_CellLinks() +{ +} + +void SMDS_UnstructuredGrid::BuildLinks() +{ + // Remove the old links if they are already built + if (this->Links) + { + this->Links->UnRegister(this); + } + + this->Links = SMDS_CellLinks::New(); + this->Links->Allocate(this->GetNumberOfPoints()); + this->Links->Register(this); + this->Links->BuildLinks(this, this->Connectivity); + this->Links->Delete(); +} + +SMDS_CellLinks* SMDS_UnstructuredGrid::GetCellLinks() +{ + return static_cast(this->Links); +} + +SMDS_UnstructuredGrid* SMDS_UnstructuredGrid::New() +{ + return new SMDS_UnstructuredGrid(); +} + +SMDS_UnstructuredGrid::SMDS_UnstructuredGrid() : vtkUnstructuredGrid() +{ +} + +SMDS_UnstructuredGrid::~SMDS_UnstructuredGrid() +{ +} + + diff --git a/src/SMDS/SMDS_UnstructuredGrid.hxx b/src/SMDS/SMDS_UnstructuredGrid.hxx new file mode 100644 index 000000000..603305d9d --- /dev/null +++ b/src/SMDS/SMDS_UnstructuredGrid.hxx @@ -0,0 +1,41 @@ +/* + * File: SMDS_UnstructuredGrid.hxx + * Author: prascle + * + * Created on September 16, 2009, 10:28 PM + */ + +#ifndef _SMDS_UNSTRUCTUREDGRID_HXX +#define _SMDS_UNSTRUCTUREDGRID_HXX + +#include +#include + +class SMDS_CellLinks: public vtkCellLinks +{ +public: + Link *AdjustSize(vtkIdType sz); + + //virtual void Delete(); + static SMDS_CellLinks* New(); +protected: + SMDS_CellLinks(); + ~SMDS_CellLinks(); +}; + +class SMDS_UnstructuredGrid: public vtkUnstructuredGrid +{ +public: + void BuildLinks(); // initialise un SMDS_CellLinks; + SMDS_CellLinks* GetCellLinks(); + + //virtual void Delete(); + static SMDS_UnstructuredGrid* New(); +protected: + SMDS_UnstructuredGrid(); + ~SMDS_UnstructuredGrid(); +}; + + +#endif /* _SMDS_UNSTRUCTUREDGRID_HXX */ + diff --git a/src/SMESH/memoire.h b/src/SMESH/memoire.h new file mode 100644 index 000000000..2754222f1 --- /dev/null +++ b/src/SMESH/memoire.h @@ -0,0 +1,21 @@ + +#ifndef _MEMOIRE_H_ +#define _MEMOIRE_H_ + +#include +#include + +void memostat( const char* f, int l); + +void memostat( const char* f, int l) +{ +/* struct mallinfo mem = mallinfo(); */ +/* std::cerr << f << ":"<< l << " " << mem.arena << " " << mem.ordblks << " " << mem.hblks << " " << mem.hblkhd << " " << mem.uordblks << " " << mem.fordblks << " " << mem.keepcost << std::endl; */ +std::cerr << f << ":"<< l << " --------------------------"<< std::endl; + malloc_stats(); +std::cerr << f << ":"<< l << " --------------------------"<< std::endl; +} + +#define MEMOSTAT memostat( __FILE__, __LINE__ ) + +#endif -- 2.39.2