X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_UnstructuredGrid.cxx;h=143d54334de7988cf8a1fd00aca95cc8cdd3448f;hp=99bd56fb6611af1fde43220ea2295bb289eac848;hb=e3214b68d298250cb463df645aecb3d2fdd5627a;hpb=fe3703789b6aae6bdf951e78baa5d3b991d4abe2 diff --git a/src/SMDS/SMDS_UnstructuredGrid.cxx b/src/SMDS/SMDS_UnstructuredGrid.cxx index 99bd56fb6..143d54334 100644 --- a/src/SMDS/SMDS_UnstructuredGrid.cxx +++ b/src/SMDS/SMDS_UnstructuredGrid.cxx @@ -1,79 +1,250 @@ #include "SMDS_UnstructuredGrid.hxx" +#include "utilities.h" -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; - } +#include +#include +#include +#include - this->Size = newSize; - delete [] this->Array; - this->Array = newArray; +#include - return this->Array; -} +using namespace std; -SMDS_CellLinks* SMDS_CellLinks::New() +SMDS_UnstructuredGrid* SMDS_UnstructuredGrid::New() { - return new SMDS_CellLinks(); + MESSAGE("SMDS_UnstructuredGrid::New"); + return new SMDS_UnstructuredGrid(); } -SMDS_CellLinks::SMDS_CellLinks() : vtkCellLinks() +SMDS_UnstructuredGrid::SMDS_UnstructuredGrid() : vtkUnstructuredGrid() { } -SMDS_CellLinks::~SMDS_CellLinks() +SMDS_UnstructuredGrid::~SMDS_UnstructuredGrid() { } -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() +unsigned long SMDS_UnstructuredGrid::GetMTime() { - return static_cast(this->Links); + unsigned long mtime = vtkUnstructuredGrid::GetMTime(); + MESSAGE("vtkUnstructuredGrid::GetMTime: " << mtime); + return mtime; } -SMDS_UnstructuredGrid* SMDS_UnstructuredGrid::New() +void SMDS_UnstructuredGrid::Update() { - return new SMDS_UnstructuredGrid(); + MESSAGE("SMDS_UnstructuredGrid::Update"); + return vtkUnstructuredGrid::Update(); } -SMDS_UnstructuredGrid::SMDS_UnstructuredGrid() : vtkUnstructuredGrid() +void SMDS_UnstructuredGrid::UpdateInformation() { + MESSAGE("SMDS_UnstructuredGrid::UpdateInformation"); + return vtkUnstructuredGrid::UpdateInformation(); } -SMDS_UnstructuredGrid::~SMDS_UnstructuredGrid() +void SMDS_UnstructuredGrid::compactGrid(std::vector& idNodesOldToNew, int newNodeSize, + std::vector& idCellsOldToNew, int newCellSize) { -} + MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize); + + int startHole = 0; + int endHole = 0; + int startBloc = 0; + int endBloc = 0; + int alreadyCopied = 0; + + typedef enum {lookHoleStart, lookHoleEnd, lookBlocEnd} enumState; + enumState compactState = lookHoleStart; + +// if (this->Links) +// { +// this->Links->UnRegister(this); +// this->Links = 0; +// } + + // --- if newNodeSize, create a new compacted vtkPoints + + vtkPoints *newPoints = 0; + if (newNodeSize) + { + MESSAGE("-------------- compactGrid, newNodeSize"); + newPoints = vtkPoints::New(); + newPoints->Initialize(); + newPoints->Allocate(newNodeSize); + newPoints->SetNumberOfPoints(newNodeSize); + int oldNodeSize = idNodesOldToNew.size(); + + for (int i=0; i< oldNodeSize; i++) + { + switch(compactState) + { + case lookHoleStart: + if (idNodesOldToNew[i] < 0) + { + MESSAGE("-------------- newNodeSize, startHole " << i << " " << oldNodeSize); + startHole = i; + compactState = lookHoleEnd; + } + break; + case lookHoleEnd: + if (idNodesOldToNew[i] >= 0) + { + MESSAGE("-------------- newNodeSize, endHole " << i << " " << oldNodeSize); + endHole = i; + startBloc = i; + compactState = lookBlocEnd; + } + break; + case lookBlocEnd: + if (idNodesOldToNew[i] < 0) endBloc = i; // see nbPoints below + else if (i == (oldNodeSize-1)) endBloc = i+1; + if (endBloc) + { + MESSAGE("-------------- newNodeSize, endbloc " << endBloc << " " << oldNodeSize); + void *target = newPoints->GetVoidPointer(3*alreadyCopied); + void *source = this->Points->GetVoidPointer(3*startBloc); + int nbPoints = endBloc - startBloc; + memcpy(target, source, 3*sizeof(float)*nbPoints); + for (int j=startBloc; jGetVoidPointer(0); + void *source = this->Points->GetVoidPointer(0); + int nbPoints = newNodeSize; + memcpy(target, source, 3*sizeof(float)*nbPoints); + } + } + + // --- create new compacted Connectivity, Locations and Types + + int oldCellSize = this->Types->GetNumberOfTuples(); + + vtkCellArray *newConnectivity = vtkCellArray::New(); + newConnectivity->Initialize(); + int oldCellDataSize = this->Connectivity->GetData()->GetSize(); + newConnectivity->Allocate(oldCellDataSize); + MESSAGE("oldCellSize="<< oldCellSize << " oldCellDataSize=" << oldCellDataSize); + + vtkUnsignedCharArray *newTypes = vtkUnsignedCharArray::New(); + newTypes->Initialize(); + //newTypes->Allocate(oldCellSize); + newTypes->SetNumberOfValues(newCellSize); + + vtkIdTypeArray *newLocations = vtkIdTypeArray::New(); + newLocations->Initialize(); + //newLocations->Allocate(oldCellSize); + newLocations->SetNumberOfValues(newCellSize); + + startHole = 0; + endHole = 0; + startBloc = 0; + endBloc = 0; + alreadyCopied = 0; + compactState = lookHoleStart; + + vtkIdType tmpid[50]; + vtkIdType *pointsCell =&tmpid[0]; // --- points id to fill a new cell + + for (int i=0; iTypes->GetValue(i) == VTK_EMPTY_CELL) + { + MESSAGE(" -------- newCellSize, startHole " << i << " " << oldCellSize); + startHole = i; + compactState = lookHoleEnd; + } + break; + case lookHoleEnd: + if (this->Types->GetValue(i) != VTK_EMPTY_CELL) + { + MESSAGE(" -------- newCellSize, EndHole " << i << " " << oldCellSize); + endHole = i; + startBloc = i; + compactState = lookBlocEnd; + } + break; + case lookBlocEnd: + if (this->Types->GetValue(i) == VTK_EMPTY_CELL) endBloc =i; + else if (i == (oldCellSize-1)) endBloc = i+1; + if (endBloc) + { + MESSAGE(" -------- newCellSize, endBloc " << endBloc << " " << oldCellSize); + for (int j=startBloc; jSetValue(alreadyCopied, this->Types->GetValue(j)); + idCellsOldToNew[j] = alreadyCopied; + vtkIdType oldLoc = this->Locations->GetValue(j); + vtkIdType nbpts; + vtkIdType *oldPtsCell = 0; + this->Connectivity->GetCell(oldLoc, nbpts, oldPtsCell); + for (int l=0; lInsertNextCell(nbpts, pointsCell); + int newLoc = newConnectivity->GetInsertLocation(nbpts); + newLocations->SetValue(alreadyCopied, newLoc); + alreadyCopied++; + } + compactState = lookHoleStart; + } + break; + } + } + if (!alreadyCopied) // no hole, but shorter + { + MESSAGE(" -------- newCellSize, shorter " << oldCellSize); + for (int j=0; jSetValue(alreadyCopied, this->Types->GetValue(j)); + idCellsOldToNew[j] = alreadyCopied; + vtkIdType oldLoc = this->Locations->GetValue(j); + vtkIdType nbpts; + vtkIdType *oldPtsCell = 0; + this->Connectivity->GetCell(oldLoc, nbpts, oldPtsCell); + //MESSAGE(j << " " << alreadyCopied << " " << (int)this->Types->GetValue(j) << " " << oldLoc << " " << nbpts ); + for (int l=0; lInsertNextCell(nbpts, pointsCell); + int newLoc = newConnectivity->GetInsertLocation(nbpts); + //MESSAGE(newcnt << " " << newLoc); + newLocations->SetValue(alreadyCopied, newLoc); + alreadyCopied++; + } + } + newConnectivity->Squeeze(); + //newTypes->Squeeze(); + //newLocations->Squeeze(); + if (newNodeSize) + { + MESSAGE("------- newNodeSize, setPoints"); + this->SetPoints(newPoints); + } + this->SetCells(newTypes, newLocations, newConnectivity); + this->BuildLinks(); +}