// Copyright : Open CASCADE
#include "VISU_CommonCellsFilter.hxx"
+#include "VISU_ConvertorDef.hxx"
// VTK product headers
#include <vtkUnstructuredGrid.h>
#include <algorithm>
#include <vector>
#include <map>
+#include <set>
#ifdef _DEBUG_
static int MYDEBUG = 0;
namespace
{
- typedef std::vector<int> TSortedArray;
+ typedef std::pair<int,int> TPair;// pair first - object id, second - entity
+ //
+ typedef std::vector<int> TSortedArrayOne;
+ typedef std::set<TPair> TSortedArrayPair;
+ typedef std::set<int> TIdSet;
typedef std::map<int,int> TId2IdMap;
inline
void
- GetSortedArray(vtkIntArray *theArray,
- TSortedArray& theSortedArray)
+ GetSortedArrayAsPair(vtkIntArray *theArray,
+ TSortedArrayPair& theSortedArray)
+ {
+ TSortedArrayPair aSortedArray;
+ int nbComp = theArray->GetNumberOfComponents();
+ if(nbComp == 2){
+ int aMaxId = theArray->GetNumberOfTuples()*theArray->GetNumberOfComponents();
+ int* aPointer = theArray->GetPointer(0);
+ int* anEndPointer = theArray->GetPointer(aMaxId + 1);
+ for(;aPointer<anEndPointer;){
+ TPair aPair;
+ aPair.first = *aPointer;
+ aPointer++;
+ aPair.second = *aPointer;
+ aPointer++;
+ aSortedArray.insert(aPair);
+ }
+ } else if (nbComp == 1) {
+ int aMaxId = theArray->GetNumberOfTuples();
+ int* aPointer = theArray->GetPointer(0);
+ int* anEndPointer = theArray->GetPointer(aMaxId + 1);
+ for(;aPointer<anEndPointer;){
+ TPair aPair;
+ aPair.first = *aPointer;
+ aPointer++;
+ aPair.second = (int)VISU::NODE_ENTITY;
+ aSortedArray.insert(aPair);
+ }
+
+ }
+ theSortedArray.swap(aSortedArray);
+ }
+
+ inline
+ void
+ GetSortedArrayOne(vtkIntArray *theArray,
+ TSortedArrayOne& theSortedArray)
{
int aMaxId = theArray->GetMaxId();
int* aPointer = theArray->GetPointer(0);
int* anEndPointer = theArray->GetPointer(aMaxId + 1);
- TSortedArray aSortedArray(aPointer, anEndPointer);
+ TSortedArrayOne aSortedArray(aPointer, anEndPointer);
std::sort(aSortedArray.begin(), aSortedArray.end());
theSortedArray.swap(aSortedArray);
}
void
GetIdsForCopy(vtkUnstructuredGrid *inputUGrid,
vtkIntArray* inputPointIds,
- TSortedArray& outputSortedArray)
+ TSortedArrayOne& outputSortedArray)
{
- VISU::TTimerLog aTimerLog(MYDEBUG,"GetIdsForCopy");
if(inputUGrid){
- TSortedArray aSortedPointIds;
- TSortedArray aOutputCellIds;
- GetSortedArray(inputPointIds,aSortedPointIds);
-
+ TSortedArrayOne aSortedPointIds;
+ TSortedArrayOne aOutputCellIds;
+ TIdSet aMapForSearch;
+ int nbTuples = inputPointIds->GetNumberOfTuples();
+ int nbComp = inputPointIds->GetNumberOfComponents();
+ int * aPtr = inputPointIds->GetPointer(0);
+ int * aPtrEnd = inputPointIds->GetPointer(nbTuples*nbComp+1);
+ if(nbComp == 1)
+ while(aPtr<aPtrEnd){
+ aMapForSearch.insert(*aPtr);
+ aPtr++;
+ }
+ else if (nbComp == 2)
+ while(aPtr<aPtrEnd){
+ aMapForSearch.insert(*aPtr);
+ aPtr++;aPtr++;
+ }
int nbInputCells = inputUGrid->GetNumberOfCells();
- TSortedArray aPointCellIds;
for(int idCell=0;idCell<nbInputCells;idCell++){
- aPointCellIds.clear();
vtkCell* aCell = inputUGrid->GetCell(idCell);
vtkIdList* ptIds = aCell->GetPointIds();
int nbPointsInCell = ptIds->GetNumberOfIds();
bool aGoodCell = true;
for(int i=0;i<nbPointsInCell;i++){
int aSearchingId = ptIds->GetId(i);
- TSortedArray::iterator aResult = find(aSortedPointIds.begin(),aSortedPointIds.end(),aSearchingId);
- if(aResult == aSortedPointIds.end()){
+ TIdSet::iterator aResult = aMapForSearch.find(aSearchingId);
+ if(aResult == aMapForSearch.end()){
aGoodCell = false;
break;
}
void
CopyElementsToOutput(vtkUnstructuredGrid* theInputUG,
int& theNbElements,
- TSortedArray& theElementIdsForCopy,
+ TSortedArrayOne& theElementIdsForCopy,
TId2IdMap& theOldId2NewIdPointsMap,
- vtkIntArray* theOuputIDSArray,
vtkUnstructuredGrid* theOutputUG)
{
+ vtkIntArray* theOuputIDSArray = vtkIntArray::New();
+ theOuputIDSArray->SetName("VISU_CELLS_MAPPER");
+ theOuputIDSArray->SetNumberOfComponents(2);
+ theOuputIDSArray->SetNumberOfTuples(theNbElements);
+ int* aOuputIDSPtr = theOuputIDSArray->GetPointer(0);
+
vtkIntArray* aInputCellsMapper =
dynamic_cast<vtkIntArray*>(theInputUG->GetCellData()->GetArray("VISU_CELLS_MAPPER"));
int* aInputCellsMapperPointer = aInputCellsMapper->GetPointer(0);
const int aOldCellId = theElementIdsForCopy[aCellIndex];
theOutputUG->InsertNextCell(theInputUG->GetCellType(aOldCellId),
aNewPointIds);
- if(aInputCellsMapperPointer)
- theOuputIDSArray->InsertNextValue(aInputCellsMapperPointer[aOldCellId]);
- else
- theOuputIDSArray->InsertNextValue(aOldCellId);
+
+ *aOuputIDSPtr = aInputCellsMapperPointer[2*aOldCellId];
+ aOuputIDSPtr++;
+ *aOuputIDSPtr = aInputCellsMapperPointer[2*aOldCellId+1];
+ aOuputIDSPtr++;
aNewPointIds->Delete();
}
+
+ theOutputUG->GetCellData()->AddArray(theOuputIDSArray);
+
+ theOuputIDSArray->Delete();
}
}
VISU_CommonCellsFilter
::Execute()
{
+ VISU::TTimerLog aTimerLog(MYDEBUG,"VISU_CommonCellsFilter::Execute");
vtkUnstructuredGrid* anInputProfileUG = this->GetProfileUG();
vtkUnstructuredGrid* anInputCellsUG = this->GetCellsUG();
vtkIntArray* aPointIDS =
dynamic_cast<vtkIntArray*>(aInputCellData->GetArray("VISU_CELLS_MAPPER"));
if(aPointIDS){
+ int* aPtr = aPointIDS->GetPointer(0);
aPointIdsForCopy->SetNumberOfIds(aPointIDS->GetNumberOfTuples());
for(int i=0;i<aPointIDS->GetNumberOfTuples();i++){
- aPointIdsForCopy->SetId(i,aPointIDS->GetValue(i));
+ aPointIdsForCopy->SetId(i,*aPtr);
+ aPtr++;aPtr++;
}
aOutputPointSet->SetNumberOfPoints(aPointIdsForCopy->GetNumberOfIds());
// aOutputPointSet copy points from anInputProfileUG to aOutputPointSet, which
// Calculate output cells
int nbCells=0;
- TSortedArray aCellIdsForCopy;
+ TSortedArrayOne aCellIdsForCopy;
GetIdsForCopy(anInputCellsUG,aPointIDS,aCellIdsForCopy);
nbCells = aCellIdsForCopy.size();
// copy cells to output
int aAllocMem = nbCells;
anOutput->Allocate(aAllocMem);
- vtkIntArray* theOuputIDSArray = vtkIntArray::New();
- theOuputIDSArray->SetName("VISU_CELLS_MAPPER");
- theOuputIDSArray->SetNumberOfComponents(1);
- theOuputIDSArray->SetNumberOfTuples(aAllocMem);
-
+
if(nbCells>0 && anInputCellsUG)
CopyElementsToOutput(anInputCellsUG,
nbCells,
aCellIdsForCopy,
aOldId2NewIdPointsMap,
- theOuputIDSArray,
anOutput);
- anOutput->GetCellData()->AddArray(theOuputIDSArray);
-
- theOuputIDSArray->Delete();
+
aPointIdsForCopy->Delete();
}
}
#include <algorithm>
#include <vector>
#include <map>
+#include <set>
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+// TTimerLog
+#include "VISU_ConvertorUtils.hxx"
namespace VISU
{
}
typedef std::map<int,int> TId2IdMap;
+ typedef std::set<int> TIdSet;
template <class TNumericType>
void DeepCopySwitchOnOutput(TNumericType *theInputPtr,
if(inputUGrid){
TSortedArray aSortedPointIds;
TSortedArray aOutputCellIds;
- GetSortedArray(inputPointIds,aSortedPointIds);
-
+
+ TIdSet aMapForSearch;
+ int nbTuples = inputPointIds->GetNumberOfTuples();
+ int nbComp = inputPointIds->GetNumberOfComponents();
+ int * aPtr = inputPointIds->GetPointer(0);
+ int * aPtrEnd = inputPointIds->GetPointer(nbTuples*nbComp+1);
+ if(nbComp == 1)
+ while(aPtr<aPtrEnd){
+ aMapForSearch.insert(*aPtr);
+ aPtr++;
+ }
+ else if (nbComp == 2)
+ while(aPtr<aPtrEnd){
+ aMapForSearch.insert(*aPtr);
+ aPtr++;aPtr++;
+ }
int nbInputCells = inputUGrid->GetNumberOfCells();
- TSortedArray aPointCellIds;
for(int idCell=0;idCell<nbInputCells;idCell++){
- aPointCellIds.clear();
vtkCell* aCell = inputUGrid->GetCell(idCell);
vtkIdList* ptIds = aCell->GetPointIds();
int nbPointsInCell = ptIds->GetNumberOfIds();
bool aGoodCell = true;
for(int i=0;i<nbPointsInCell;i++){
int aSearchingId = ptIds->GetId(i);
- TSortedArray::iterator aResult = find(aSortedPointIds.begin(),aSortedPointIds.end(),aSearchingId);
- if(aResult == aSortedPointIds.end()){
+ TIdSet::iterator aResult = aMapForSearch.find(aSearchingId);
+ if(aResult == aMapForSearch.end()){
aGoodCell = false;
break;
}
aOutputCellIds.push_back(idCell);
else
continue;
+
}
outputSortedArray.swap(aOutputCellIds);
int& theNbElements,
TSortedArray& theElementIdsForCopy,
TId2IdMap& theOldId2NewIdPointsMap,
- vtkIntArray* theOuputIDSArray,
vtkUnstructuredGrid* theOutputUG)
{
+ vtkIntArray* theOuputIDSArray = vtkIntArray::New();
+ theOuputIDSArray->SetName("VISU_CELLS_MAPPER");
+ // the [0] component is element object ID
+ // the [1] component is entity type
+ theOuputIDSArray->SetNumberOfComponents(2);
+ theOuputIDSArray->SetNumberOfTuples(theNbElements);
+ int* aOuputIDSPtr = theOuputIDSArray->GetPointer(0);
+
vtkIntArray* aInputCellsMapper =
dynamic_cast<vtkIntArray*>(theInputUG->GetCellData()->GetArray("VISU_CELLS_MAPPER"));
const int aOldCellId = theElementIdsForCopy[aCellIndex];
theOutputUG->InsertNextCell(theInputUG->GetCellType(aOldCellId),
aNewPointIds);
- if(aInputCellsMapperPointer)
- theOuputIDSArray->InsertNextValue(aInputCellsMapperPointer[aOldCellId]);
- else
- theOuputIDSArray->InsertNextValue(aOldCellId);
+
+ *aOuputIDSPtr = aInputCellsMapperPointer[2*aOldCellId];
+ aOuputIDSPtr++;
+ *aOuputIDSPtr = aInputCellsMapperPointer[2*aOldCellId+1];
+ aOuputIDSPtr++;
aNewPointIds->Delete();
}
theOutputUG->GetCellData()->AddArray(theOuputIDSArray);
+ theOuputIDSArray->Delete();
+ }
+
+
+}
+
+bool
+VISU_MergeFilter
+::MergeGeometryCellsAndDataOnCells()
+{
+ if(MYDEBUG) cout << "MergeGeometryCellsAndDataOnCells" << endl;
+ vtkUnstructuredGrid *anInput = this->GetInput();
+ vtkUnstructuredGrid *anOutput = this->GetOutput();
+ vtkCellData *aCellData = anInput->GetCellData();
+ vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER"); // 1
+ vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper); // 1->2
+
+ // The situation for merging CELLS from anInput as Geometry
+ // and scalars on cell data
+ vtkIntArray* aDataCellMapper = NULL;
+ VISU::TFieldListIterator anIter(this->FieldList);
+ for(anIter.Begin(); !anIter.End() ; anIter.Next()){
+ vtkCellData *aCellData = anIter.Get()->Ptr->GetCellData();
+ const char* aFieldName = anIter.Get()->GetName();
+ if(strcmp(aFieldName, "VISU_CELLS_MAPPER") == 0){
+ vtkDataArray *aCellMapper_tmp = aCellData->GetArray(aFieldName);
+ aDataCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper_tmp);
+ break;
+ }
+ }
+
+ bool anIsDifferent = aDataCellMapper &&
+ aDataCellMapper->GetNumberOfTuples() != aGeometryCellMapper->GetNumberOfTuples();
+
+ if(anIsDifferent || IsMergingInputs() ){
+ TSortedArray aGeometryCellArray;
+ GetSortedArray(aGeometryCellMapper, aGeometryCellArray);
+
+ TSortedArray aDataCellArray;
+ GetSortedArray(aDataCellMapper, aDataCellArray);
+
+ int aMaxLength = std::max(aGeometryCellArray.size(), aDataCellArray.size());
+ TSortedArray anIntersectionArray(aMaxLength);
+ TSortedArray::iterator anArrayIter = anIntersectionArray.begin();
+ anArrayIter = std::set_intersection(aGeometryCellArray.begin(),
+ aGeometryCellArray.end(),
+ aDataCellArray.begin(),
+ aDataCellArray.end(),
+ anArrayIter);
+
+ anIntersectionArray.erase(anArrayIter, anIntersectionArray.end());
+
+ bool anIsCompletelyCoincide =
+ anIntersectionArray.size() == aGeometryCellArray.size() &&
+ anIntersectionArray.size() == aDataCellArray.size();
+
+ if(!anIsCompletelyCoincide || IsMergingInputs()){
+ {
+ TId2IdMap anObj2VTKGeometryMap;
+ vtkIdType aNbCells = aGeometryCellMapper->GetNumberOfTuples();
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = aGeometryCellMapper->GetValue(aCellId);
+ anObj2VTKGeometryMap[anObjID] = aCellId;
+ }
+
+ vtkIdType aNbTuples = anIntersectionArray.size();
+ anOutput->Allocate(aNbTuples);
+ vtkIdList *aCellIds = vtkIdList::New();
+ for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
+ vtkIdType anObjID = anIntersectionArray[aTupleId];
+ vtkIdType aCellId = anObj2VTKGeometryMap[anObjID];
+ vtkCell *aCell = anInput->GetCell(aCellId);
+ aCellIds->Reset();
+ vtkIdType aNbPointIds = aCell->PointIds->GetNumberOfIds();
+ for(vtkIdType aPointId = 0; aPointId < aNbPointIds; aPointId++)
+ aCellIds->InsertNextId(aCell->GetPointIds()->GetId(aPointId));
+ anOutput->InsertNextCell(anInput->GetCellType(aCellId), aCellIds);
+ }
+ aCellIds->Delete();
+ anOutput->SetPoints(anInput->GetPoints());
+ }
+ {
+ TId2IdMap anObj2VTKDataMap;
+ vtkIdType aNbCells = aDataCellMapper->GetNumberOfTuples();
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = aDataCellMapper->GetValue(aCellId);
+ anObj2VTKDataMap[anObjID] = aCellId;
+ }
+
+ DeepCopyDataSetAttributes(this,
+ anOutput,
+ this->FieldList,
+ anIntersectionArray,
+ anObj2VTKDataMap);
+ }
+ return true;
+ }
}
+ return false;
+}
+
+bool
+VISU_MergeFilter
+::MergeGeometryCellsAndDataOnAllPoints()
+{
+ if(MYDEBUG) cout << "MergeGeometryCellsAndDataOnAllPoints" << endl;
+ // The situation for merging CELLS from anInput as Geometry
+ // and scalars on point data
+ vtkUnstructuredGrid *anInput = this->GetInput();
+ vtkUnstructuredGrid *anOutput = this->GetOutput();
+
+ vtkPointData *aPointData = anInput->GetPointData();
+ vtkCellData *aCellData = anInput->GetCellData();
+ vtkDataSet* aInputScalars = this->GetScalars();
+ vtkPointData* aInputScalarsPointData = aInputScalars->GetPointData();
+ vtkDataArray *aPointMapper = aPointData->GetArray("VISU_POINTS_MAPPER");
+ vtkIntArray *aGeometryPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
+ vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER"); // 1
+ vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper); // 1->2
+ vtkIntArray* aDataPointMapper = NULL;
+ VISU::TFieldListIterator anIter(this->FieldList);
+ for(anIter.Begin(); !anIter.End() ; anIter.Next()){
+ const char* aFieldName = anIter.Get()->GetName();
+ if(strcmp(aFieldName, "VISU_POINTS_MAPPER") == 0){
+ vtkDataArray *aPointMapper = aInputScalarsPointData->GetArray(aFieldName);
+ aDataPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
+ break;
+ }
+ }
+ if(aDataPointMapper){
+ TSortedArray aGeometryPointArray;
+ GetSortedArray(aGeometryPointMapper, aGeometryPointArray);
+
+ TSortedArray aDataPointArray;
+ GetSortedArray(aDataPointMapper, aDataPointArray);
+
+ {
+ TId2IdMap anObj2VTKGeometryPointsMap;
+ vtkIdType aNbCells = aDataPointMapper->GetNumberOfTuples();
+ vtkIdType aNbComp = aDataPointMapper->GetNumberOfComponents();
+ int * aPtr = aDataPointMapper->GetPointer(0);
+ if(aNbComp==2){
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = *aPtr;
+ aPtr++;aPtr++;
+ anObj2VTKGeometryPointsMap[anObjID] = aCellId;
+ }
+ } else if (aNbComp == 1 ){
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = *aPtr;
+ aPtr++;
+ anObj2VTKGeometryPointsMap[anObjID] = aCellId;
+ }
+ }
+
+ TId2IdMap anObj2VTKGeometryCellsMap;
+ aNbCells = aGeometryCellMapper->GetNumberOfTuples();
+ aNbComp = aGeometryCellMapper->GetNumberOfComponents();
+ aPtr = aGeometryCellMapper->GetPointer(0);
+ if(aNbComp == 1)
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = *aPtr;
+ aPtr++;
+ anObj2VTKGeometryCellsMap[anObjID] = aCellId;
+ }
+ else if (aNbComp == 2){
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = *aPtr;
+ aPtr++;aPtr++;
+ anObj2VTKGeometryCellsMap[anObjID] = aCellId;
+ }
+ }
+
+ // copy points to output
+ vtkUnstructuredGrid* aUnstructuredScalars = dynamic_cast<vtkUnstructuredGrid*>(aInputScalars);
+ if(aUnstructuredScalars)
+ anOutput->SetPoints(aUnstructuredScalars->GetPoints());
+ anOutput->GetPointData()->ShallowCopy(aInputScalars->GetPointData());
+
+ // Calculate output cells
+ int nbCells=0;
+ TSortedArray aCellIdsForCopy_fromCellMapper;
+ GetSortedArray(aGeometryCellMapper, aCellIdsForCopy_fromCellMapper);
+ nbCells = aCellIdsForCopy_fromCellMapper.size();
+
+ TSortedArray aCellIdsForCopy;
+ for(int i=0;i<nbCells;i++)
+ aCellIdsForCopy.push_back(anObj2VTKGeometryCellsMap[aCellIdsForCopy_fromCellMapper[i]]);
+
+ // copy cells to output
+ anOutput->Allocate(nbCells);
+
+
+ if(nbCells>0)
+ CopyElementsToOutput(anInput,
+ nbCells,
+ aCellIdsForCopy,
+ anObj2VTKGeometryPointsMap,
+ anOutput);
+
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+VISU_MergeFilter
+::MergeGeometryCellsAndDataOnNotAllPoints()
+{
+ if(MYDEBUG) cout << "MergeGeometryCellsAndDataOnNotAllPoints" << endl;
+ // The situation for merging CELLS from anInput as Geometry
+ // and scalars on point data (there the number of points of point data less than
+ // number of points of Geometry)
+
+ vtkUnstructuredGrid *anInput = this->GetInput();
+ vtkUnstructuredGrid *anOutput = this->GetOutput();
+ vtkDataSet* aInputScalars = this->GetScalars();
+ vtkPointData *aPointData = anInput->GetPointData();
+
+ vtkPointData* aInputScalarsPointData = aInputScalars->GetPointData();
+ vtkDataArray *aPointMapper = aPointData->GetArray("VISU_POINTS_MAPPER");
+ vtkIntArray *aGeometryPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
+
+ vtkIntArray* aDataPointMapper = NULL;
+ VISU::TFieldListIterator anIter(this->FieldList);
+ for(anIter.Begin(); !anIter.End() ; anIter.Next()){
+ const char* aFieldName = anIter.Get()->GetName();
+ if(strcmp(aFieldName, "VISU_POINTS_MAPPER") == 0){
+ vtkDataArray *aPointMapper = aInputScalarsPointData->GetArray(aFieldName);
+ aDataPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
+ break;
+ }
+ }
+ vtkIntArray* aDataCellMapper = NULL;
+ VISU::TFieldListIterator anIter2(this->FieldList);
+ for(anIter2.Begin(); !anIter2.End() ; anIter2.Next()){
+ const char* aFieldName = anIter2.Get()->GetName();
+ if(strcmp(aFieldName, "VISU_CELLS_MAPPER") == 0){
+ vtkDataArray *aCellMapper_tmp = aInputScalarsPointData->GetArray(aFieldName);
+ aDataCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper_tmp);
+ break;
+ }
+ }
+
+ vtkIntArray* aDataArray = NULL;
+ VISU::TFieldListIterator anIter3(this->FieldList);
+ for(anIter2.Begin(); !anIter3.End() ; anIter3.Next()){
+ const char* aFieldName = anIter3.Get()->GetName();
+ if(strcmp(aFieldName, "VISU_FIELD") == 0){
+ vtkDataArray *aPointMapper_tmp = aInputScalarsPointData->GetArray(aFieldName);
+ aDataArray = dynamic_cast<vtkIntArray*>(aPointMapper_tmp);
+ break;
+ }
+ }
+
+
+ bool anIsDifferent = aDataPointMapper &&
+ aDataPointMapper->GetNumberOfTuples() != aGeometryPointMapper->GetNumberOfTuples();
+ if(anIsDifferent){
+ {
+ vtkIntArray* aPointsIds = vtkIntArray::New();
+
+ TId2IdMap anObj2VTKGeometryMap;
+ vtkIdType aNbCells = aDataPointMapper->GetNumberOfTuples();
+ aPointsIds->SetNumberOfTuples(aNbCells);
+ aPointsIds->SetNumberOfComponents(1);
+ vtkIdType aNbComp = aDataPointMapper->GetNumberOfComponents();
+ int * aPtr = aDataPointMapper->GetPointer(0);
+ int * aPtrOut = aPointsIds->GetPointer(0);
+ if(aNbComp==2){
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = *aPtr;
+ aPtr++;aPtr++;
+ *aPtrOut = anObjID;
+ aPtrOut++;
+ anObj2VTKGeometryMap[anObjID] = aCellId;
+ }
+ } else if (aNbComp == 1 ){
+ for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+ vtkIdType anObjID = *aPtr;
+ aPtr++;
+ *aPtrOut = anObjID;
+ aPtrOut++;
+ anObj2VTKGeometryMap[anObjID] = aCellId;
+ }
+ }
+
+ vtkUnstructuredGrid* aUnstructuredScalars = dynamic_cast<vtkUnstructuredGrid*>(aInputScalars);
+ if(aUnstructuredScalars)
+ anOutput->SetPoints(aUnstructuredScalars->GetPoints());
+
+ anOutput->GetPointData()->ShallowCopy(aInputScalars->GetPointData());
+
+ // Calculate output cells
+ int nbCells=0;
+ TSortedArray aCellIdsForCopy;
+ GetIdsForCopy(anInput,aPointsIds,aCellIdsForCopy);
+ aPointsIds->Delete();
+ nbCells = aCellIdsForCopy.size();
+
+ // copy cells to output
+ anOutput->Allocate(nbCells);
+
+ if(nbCells>0)
+ CopyElementsToOutput(anInput,
+ nbCells,
+ aCellIdsForCopy,
+ anObj2VTKGeometryMap,
+ anOutput);
+ return true;
+ }
+
+ }
+
+ return false;
}
void
void VISU_MergeFilter::Execute()
{
+ VISU::TTimerLog aTimerLog(MYDEBUG,"VISU_MergeFilter::Execute");
vtkUnstructuredGrid *anInput = this->GetInput();
vtkUnstructuredGrid *anOutput = this->GetOutput();
-
- vtkPointData *aPointData = anInput->GetPointData();
+
vtkDataSet* aInputScalars = this->GetScalars();
int nbPointsInScalars = aInputScalars->GetNumberOfPoints();
int nbPointsInGeometr = anInput->GetNumberOfPoints();
vtkDataArray* aScalarsOnCellsArray = NULL;
if(aInputScalars->GetCellData())
aScalarsOnCellsArray = aInputScalars->GetCellData()->GetArray("VISU_FIELD");
+
vtkDataArray* aScalarsOnPointsArray = NULL;
if(aInputScalars->GetPointData())
aScalarsOnPointsArray = aInputScalars->GetPointData()->GetArray("VISU_FIELD");
- vtkDataArray *aPointMapper = aPointData->GetArray("VISU_POINTS_MAPPER");
- vtkIntArray *aGeometryPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER");
vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper);
- if(aGeometryCellMapper && aScalarsOnCellsArray && (nbPointsInScalars == nbPointsInGeometr)){
- vtkIntArray* aDataCellMapper = NULL;
- VISU::TFieldListIterator anIter(this->FieldList);
- for(anIter.Begin(); !anIter.End() ; anIter.Next()){
- vtkCellData *aCellData = anIter.Get()->Ptr->GetCellData();
- const char* aFieldName = anIter.Get()->GetName();
- if(strcmp(aFieldName, "VISU_CELLS_MAPPER") == 0){
- vtkDataArray *aCellMapper_tmp = aCellData->GetArray(aFieldName);
- aDataCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper_tmp);
- break;
- }
- }
-
- bool anIsDifferent = aDataCellMapper &&
- aDataCellMapper->GetNumberOfTuples() != aGeometryCellMapper->GetNumberOfTuples();
-
- if(anIsDifferent || IsMergingInputs() ){
- // The situation for merging CELLS from anInput as Geometry
- // and scalars on cell data
- TSortedArray aGeometryCellArray;
- GetSortedArray(aGeometryCellMapper, aGeometryCellArray);
-
- TSortedArray aDataCellArray;
- GetSortedArray(aDataCellMapper, aDataCellArray);
-
- int aMaxLength = std::max(aGeometryCellArray.size(), aDataCellArray.size());
- TSortedArray anIntersectionArray(aMaxLength);
- TSortedArray::iterator anArrayIter = anIntersectionArray.begin();
- anArrayIter = std::set_intersection(aGeometryCellArray.begin(),
- aGeometryCellArray.end(),
- aDataCellArray.begin(),
- aDataCellArray.end(),
- anArrayIter);
-
- anIntersectionArray.erase(anArrayIter, anIntersectionArray.end());
-
- bool anIsCompletelyCoincide =
- anIntersectionArray.size() == aGeometryCellArray.size() &&
- anIntersectionArray.size() == aDataCellArray.size();
-
- if(!anIsCompletelyCoincide || IsMergingInputs()){
- {
- TId2IdMap anObj2VTKGeometryMap;
- vtkIdType aNbCells = aGeometryCellMapper->GetNumberOfTuples();
- for(int aCellId = 0; aCellId < aNbCells; aCellId++){
- vtkIdType anObjID = aGeometryCellMapper->GetValue(aCellId);
- anObj2VTKGeometryMap[anObjID] = aCellId;
- }
-
- vtkIdType aNbTuples = anIntersectionArray.size();
- anOutput->Allocate(aNbTuples);
- vtkIdList *aCellIds = vtkIdList::New();
- for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
- vtkIdType anObjID = anIntersectionArray[aTupleId];
- vtkIdType aCellId = anObj2VTKGeometryMap[anObjID];
- vtkCell *aCell = anInput->GetCell(aCellId);
- aCellIds->Reset();
- vtkIdType aNbPointIds = aCell->PointIds->GetNumberOfIds();
- for(vtkIdType aPointId = 0; aPointId < aNbPointIds; aPointId++)
- aCellIds->InsertNextId(aCell->GetPointIds()->GetId(aPointId));
- anOutput->InsertNextCell(anInput->GetCellType(aCellId), aCellIds);
- }
- aCellIds->Delete();
- anOutput->SetPoints(anInput->GetPoints());
- }
- {
- TId2IdMap anObj2VTKDataMap;
- vtkIdType aNbCells = aDataCellMapper->GetNumberOfTuples();
- for(int aCellId = 0; aCellId < aNbCells; aCellId++){
- vtkIdType anObjID = aDataCellMapper->GetValue(aCellId);
- anObj2VTKDataMap[anObjID] = aCellId;
- }
-
- DeepCopyDataSetAttributes(this,
- anOutput,
- this->FieldList,
- anIntersectionArray,
- anObj2VTKDataMap);
- }
- return;
- }
- }
- } else if (aGeometryCellMapper && aScalarsOnPointsArray && (nbPointsInScalars == nbPointsInGeometr)) {
- // The situation for merging CELLS from anInput as Geometry
- // and scalars on point data
- vtkPointData* aInputScalarsPointData = aInputScalars->GetPointData();
-
- vtkIntArray* aDataPointMapper = NULL;
- VISU::TFieldListIterator anIter(this->FieldList);
- for(anIter.Begin(); !anIter.End() ; anIter.Next()){
- const char* aFieldName = anIter.Get()->GetName();
- if(strcmp(aFieldName, "VISU_POINTS_MAPPER") == 0){
- vtkDataArray *aPointMapper = aInputScalarsPointData->GetArray(aFieldName);
- aDataPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
- break;
- }
- }
-
- if(aDataPointMapper){
- TSortedArray aGeometryPointArray;
- GetSortedArray(aGeometryPointMapper, aGeometryPointArray);
-
- TSortedArray aDataPointArray;
- GetSortedArray(aDataPointMapper, aDataPointArray);
-
- {
- TId2IdMap anObj2VTKGeometryPointsMap;
- vtkIdType aNbCells = aDataPointMapper->GetNumberOfTuples();
- for(int aCellId = 0; aCellId < aNbCells; aCellId++){
- vtkIdType anObjID = aDataPointMapper->GetValue(aCellId);
- anObj2VTKGeometryPointsMap[anObjID] = aCellId;
- }
-
- TId2IdMap anObj2VTKGeometryCellsMap;
- aNbCells = aGeometryCellMapper->GetNumberOfTuples();
- for(int aCellId = 0; aCellId < aNbCells; aCellId++){
- vtkIdType anObjID = aGeometryCellMapper->GetValue(aCellId);
- anObj2VTKGeometryCellsMap[anObjID] = aCellId;
- }
-
- // copy points to output
- vtkUnstructuredGrid* aUnstructuredScalars = dynamic_cast<vtkUnstructuredGrid*>(aInputScalars);
- if(aUnstructuredScalars)
- anOutput->SetPoints(aUnstructuredScalars->GetPoints());
- anOutput->GetPointData()->ShallowCopy(aInputScalars->GetPointData());
-
- // Calculate output cells
- int nbCells=0;
- TSortedArray aCellIdsForCopy_fromCellMapper;
- GetSortedArray(aGeometryCellMapper, aCellIdsForCopy_fromCellMapper);
- nbCells = aCellIdsForCopy_fromCellMapper.size();
-
- TSortedArray aCellIdsForCopy;
- for(int i=0;i<nbCells;i++)
- aCellIdsForCopy.push_back(anObj2VTKGeometryCellsMap[aCellIdsForCopy_fromCellMapper[i]]);
-
- // copy cells to output
- anOutput->Allocate(nbCells);
- vtkIntArray* theOuputIDSArray = vtkIntArray::New();
- theOuputIDSArray->SetName("VISU_CELLS_MAPPER");
- theOuputIDSArray->SetNumberOfComponents(1);
- theOuputIDSArray->SetNumberOfTuples(nbCells);
-
- if(nbCells>0)
- CopyElementsToOutput(anInput,
- nbCells,
- aCellIdsForCopy,
- anObj2VTKGeometryPointsMap,
- theOuputIDSArray,
- anOutput);
- theOuputIDSArray->Delete();
-
- return;
- }
- }
+ if (aGeometryCellMapper && aScalarsOnCellsArray && (nbPointsInScalars == nbPointsInGeometr)){
+ if(MergeGeometryCellsAndDataOnCells())
+ return;
+ } else if (aGeometryCellMapper && aScalarsOnPointsArray && (nbPointsInScalars == nbPointsInGeometr)){
+ if(MergeGeometryCellsAndDataOnAllPoints())
+ return;
} else if (aGeometryCellMapper && (nbPointsInScalars < nbPointsInGeometr)) {
- // The situation for merging CELLS from anInput as Geometry
- // and scalars on point data (there the number of points of point data less than
- // number of points of Geometry)
-
- vtkPointData* aInputScalarsPointData = aInputScalars->GetPointData();
-
- vtkIntArray* aDataPointMapper = NULL;
- VISU::TFieldListIterator anIter(this->FieldList);
- for(anIter.Begin(); !anIter.End() ; anIter.Next()){
- const char* aFieldName = anIter.Get()->GetName();
- if(strcmp(aFieldName, "VISU_POINTS_MAPPER") == 0){
- vtkDataArray *aPointMapper = aInputScalarsPointData->GetArray(aFieldName);
- aDataPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
- break;
- }
- }
- vtkIntArray* aDataCellMapper = NULL;
- VISU::TFieldListIterator anIter2(this->FieldList);
- for(anIter2.Begin(); !anIter2.End() ; anIter2.Next()){
- vtkCellData *aCellData = anIter2.Get()->Ptr->GetCellData();
- const char* aFieldName = anIter2.Get()->GetName();
- if(strcmp(aFieldName, "VISU_CELLS_MAPPER") == 0){
- vtkDataArray *aCellMapper_tmp = aInputScalarsPointData->GetArray(aFieldName);
- aDataCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper_tmp);
- break;
- }
- }
-
- bool anIsDifferent = aDataPointMapper &&
- aDataPointMapper->GetNumberOfTuples() != aGeometryPointMapper->GetNumberOfTuples();
- if(anIsDifferent){
- TSortedArray aGeometryPointArray;
- GetSortedArray(aGeometryPointMapper, aGeometryPointArray);
-
- TSortedArray aDataPointArray;
- GetSortedArray(aDataPointMapper, aDataPointArray);
-
- int aMaxLength = std::max(aGeometryPointArray.size(), aDataPointArray.size());
- TSortedArray anIntersectionArray(aMaxLength);
- TSortedArray::iterator anArrayIter = anIntersectionArray.begin();
- anArrayIter = std::set_intersection(aGeometryPointArray.begin(),
- aGeometryPointArray.end(),
- aDataPointArray.begin(),
- aDataPointArray.end(),
- anArrayIter);
-
- anIntersectionArray.erase(anArrayIter, anIntersectionArray.end());
-
- {
- TId2IdMap anObj2VTKGeometryMap;
- vtkIdType aNbCells = aDataPointMapper->GetNumberOfTuples();
- for(int aCellId = 0; aCellId < aNbCells; aCellId++){
- vtkIdType anObjID = aDataPointMapper->GetValue(aCellId);
- anObj2VTKGeometryMap[anObjID] = aCellId;
- }
-
- vtkIdType aNbTuples = anIntersectionArray.size();
-
- if ( aNbTuples == nbPointsInScalars ){
- vtkUnstructuredGrid* aUnstructuredScalars = dynamic_cast<vtkUnstructuredGrid*>(aInputScalars);
- if(aUnstructuredScalars)
- anOutput->SetPoints(aUnstructuredScalars->GetPoints());
- anOutput->GetPointData()->ShallowCopy(aInputScalars->GetPointData());
-
- // Calculate output cells
- int nbCells=0;
- TSortedArray aCellIdsForCopy;
- GetIdsForCopy(anInput,aDataPointMapper,aCellIdsForCopy);
- nbCells = aCellIdsForCopy.size();
-
- // copy cells to output
- anOutput->Allocate(nbCells);
- vtkIntArray* theOuputIDSArray = vtkIntArray::New();
- theOuputIDSArray->SetName("VISU_CELLS_MAPPER");
- theOuputIDSArray->SetNumberOfComponents(1);
- theOuputIDSArray->SetNumberOfTuples(nbCells);
-
- if(nbCells>0)
- CopyElementsToOutput(anInput,
- nbCells,
- aCellIdsForCopy,
- anObj2VTKGeometryMap,
- theOuputIDSArray,
- anOutput);
- theOuputIDSArray->Delete();
- return;
-
- } else {
- // not implemented yet
- }
-
-
-
- }
-
- }
+ if(MergeGeometryCellsAndDataOnNotAllPoints())
+ return;
}
anOutput->CopyStructure(anInput);