inline
void
- GetSortedArray(vtkIntArray *theArray, TSortedArray& theSortedArray)
+ GetSortedArray(vtkIntArray *theArray,
+ TSortedArray& theSortedArray)
{
int aMaxId = theArray->GetMaxId();
int* aPointer = theArray->GetPointer(0);
typedef std::map<int,int> TId2IdMap;
template <class IT, class OT>
- void DeepCopyArrayOfDifferentType(IT *theInputPtr, OT *theOutputPtr,
+ void DeepCopyArrayOfDifferentType(IT *theInputPtr,
+ OT *theOutputPtr,
const TSortedArray& theIntersection,
const TId2IdMap& theObj2VTKMap,
vtkIdType theNbComp)
}
template <class IT>
- void DeepCopySwitchOnOutput(IT *theInputPtr, vtkDataArray *theDataArray,
+ void DeepCopySwitchOnOutput(IT *theInputPtr,
+ vtkDataArray *theDataArray,
const TSortedArray& theIntersection,
const TId2IdMap& theObj2VTKMap,
vtkIdType theNbComp)
typedef vtkDataArray* (vtkDataSetAttributes::* TGetAttribute)();
typedef int (vtkDataSetAttributes::* TSetAttribute)(vtkDataArray*);
+ inline
+ void
+ CopyArray(vtkDataArray* theDataArray,
+ vtkDataSetAttributes* theOutput,
+ TSetAttribute theSetAttribute,
+ vtkIdType theFixedNbTuples)
+ {
+ if(theDataArray){
+ vtkIdType aNbTuples = theDataArray->GetNumberOfTuples();
+ if(theFixedNbTuples == aNbTuples)
+ (theOutput->*theSetAttribute)(theDataArray);
+ }
+ }
+
+ inline
+ void
+ CopyAttribute(vtkDataSetAttributes* theInput,
+ TGetAttribute theGetAttribute,
+ vtkDataSetAttributes* theOutput,
+ TSetAttribute theSetAttribute,
+ vtkIdType theFixedNbTuples)
+ {
+ CopyArray((theInput->*theGetAttribute)(),
+ theOutput, theSetAttribute,
+ theFixedNbTuples);
+ }
+
void
DeepCopyArray(vtkDataArray* theDataArray,
- vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute,
- const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+ vtkDataSetAttributes* theOutput,
+ TSetAttribute theSetAttribute,
+ const TSortedArray& theIntersection,
+ const TId2IdMap& theObj2VTKMap)
{
if(theDataArray){
vtkIdType aNbTuples = theDataArray->GetNumberOfTuples();
}
void
- DeepCopyAttribute(vtkDataSetAttributes* theInput, TGetAttribute theGetAttribute,
- vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute,
- const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+ DeepCopyAttribute(vtkDataSetAttributes* theInput,
+ TGetAttribute theGetAttribute,
+ vtkDataSetAttributes* theOutput,
+ TSetAttribute theSetAttribute,
+ const TSortedArray& theIntersection,
+ const TId2IdMap& theObj2VTKMap)
{
DeepCopyArray((theInput->*theGetAttribute)(),
- theOutput, theSetAttribute,
- theIntersection, theObj2VTKMap);
+ theOutput,
+ theSetAttribute,
+ theIntersection,
+ theObj2VTKMap);
}
inline
void
- DeepCopyDataSetAttribute(vtkDataSet* theInput, TGetAttribute theGetAttribute,
- vtkDataSet* theOutput, TSetAttribute theSetAttribute,
- const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+ DeepCopyDataSetAttribute(vtkDataSet* theInput,
+ TGetAttribute theGetAttribute,
+ vtkDataSet* theOutput,
+ TSetAttribute theSetAttribute,
+ const TSortedArray& theIntersection,
+ const TId2IdMap& theObj2VTKMap)
{
- DeepCopyAttribute(theInput->GetPointData(), theGetAttribute,
- theOutput->GetPointData(), theSetAttribute,
- theIntersection, theObj2VTKMap);
- DeepCopyAttribute(theInput->GetCellData(), theGetAttribute,
- theOutput->GetCellData(), theSetAttribute,
- theIntersection, theObj2VTKMap);
+ CopyAttribute(theInput->GetPointData(),
+ theGetAttribute,
+ theOutput->GetPointData(),
+ theSetAttribute,
+ theInput->GetNumberOfPoints());
+ DeepCopyAttribute(theInput->GetCellData(),
+ theGetAttribute,
+ theOutput->GetCellData(),
+ theSetAttribute,
+ theIntersection,
+ theObj2VTKMap);
}
+ inline
void
- DeepCopyField(vtkDataSetAttributes* theInput, const char* theFieldName, vtkDataSetAttributes* theOutput,
- const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+ DeepCopyField(vtkDataSetAttributes* theInput,
+ const char* theFieldName,
+ vtkDataSetAttributes* theOutput,
+ const TSortedArray& theIntersection,
+ const TId2IdMap& theObj2VTKMap)
{
- DeepCopyArray(theInput->GetArray(theFieldName), theOutput, &vtkDataSetAttributes::AddArray,
- theIntersection, theObj2VTKMap);
+ DeepCopyArray(theInput->GetArray(theFieldName),
+ theOutput,
+ &vtkDataSetAttributes::AddArray,
+ theIntersection,
+ theObj2VTKMap);
}
inline
void
- DeepCopyDataSetField(vtkDataSet* theInput, const char* theFieldName, vtkDataSet* theOutput,
- const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+ CopyField(vtkDataSetAttributes* theInput,
+ const char* theFieldName,
+ vtkDataSetAttributes* theOutput,
+ vtkIdType theFixedNbTuples)
{
- DeepCopyField(theInput->GetPointData(), theFieldName, theOutput->GetPointData(),
- theIntersection, theObj2VTKMap);
- DeepCopyField(theInput->GetCellData(), theFieldName, theOutput->GetCellData(),
+ CopyArray(theInput->GetArray(theFieldName),
+ theOutput,
+ &vtkDataSetAttributes::AddArray,
+ theFixedNbTuples);
+ }
+
+ inline
+ void
+ DeepCopyDataSetField(vtkDataSet* theInput,
+ const char* theFieldName,
+ vtkDataSet* theOutput,
+ const TSortedArray& theIntersection,
+ const TId2IdMap& theObj2VTKMap)
+ {
+ CopyField(theInput->GetPointData(), theFieldName,
+ theOutput->GetPointData(),
+ theInput->GetNumberOfPoints());
+ DeepCopyField(theInput->GetCellData(), theFieldName,
+ theOutput->GetCellData(),
theIntersection, theObj2VTKMap);
}
inline
void
DeepCopyDataSetAttributes(VISU_MergeFilter *theFilter,
- vtkDataSet *theFilterOutput, VISU::TFieldList* theFieldList,
- const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+ vtkDataSet *theFilterOutput,
+ VISU::TFieldList* theFieldList,
+ const TSortedArray& theIntersection,
+ const TId2IdMap& theObj2VTKMap)
{
if(vtkDataSet* aDataSet = theFilter->GetScalars())
- DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetScalars,
- theFilterOutput, &vtkDataSetAttributes::SetScalars,
- theIntersection, theObj2VTKMap);
+ DeepCopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetScalars,
+ theFilterOutput,
+ &vtkDataSetAttributes::SetScalars,
+ theIntersection,
+ theObj2VTKMap);
if(vtkDataSet* aDataSet = theFilter->GetVectors())
- DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetVectors,
- theFilterOutput, &vtkDataSetAttributes::SetVectors,
- theIntersection, theObj2VTKMap);
+ DeepCopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetVectors,
+ theFilterOutput,
+ &vtkDataSetAttributes::SetVectors,
+ theIntersection,
+ theObj2VTKMap);
if(vtkDataSet* aDataSet = theFilter->GetNormals())
- DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetNormals,
- theFilterOutput, &vtkDataSetAttributes::SetNormals,
- theIntersection, theObj2VTKMap);
+ DeepCopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetNormals,
+ theFilterOutput,
+ &vtkDataSetAttributes::SetNormals,
+ theIntersection,
+ theObj2VTKMap);
if(vtkDataSet* aDataSet = theFilter->GetTCoords())
- DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTCoords,
- theFilterOutput, &vtkDataSetAttributes::SetTCoords,
- theIntersection, theObj2VTKMap);
+ DeepCopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetTCoords,
+ theFilterOutput,
+ &vtkDataSetAttributes::SetTCoords,
+ theIntersection,
+ theObj2VTKMap);
if(vtkDataSet* aDataSet = theFilter->GetTensors())
- DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTensors,
- theFilterOutput, &vtkDataSetAttributes::SetTensors,
- theIntersection, theObj2VTKMap);
+ DeepCopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetTensors,
+ theFilterOutput,
+ &vtkDataSetAttributes::SetTensors,
+ theIntersection,
+ theObj2VTKMap);
VISU::TFieldListIterator anIter(theFieldList);
for(anIter.Begin(); !anIter.End() ; anIter.Next()){
vtkDataSet *aDataSet = anIter.Get()->Ptr;
const char* aFieldName = anIter.Get()->GetName();
- DeepCopyDataSetField(aDataSet, aFieldName, theFilterOutput,
- theIntersection, theObj2VTKMap);
+ DeepCopyDataSetField(aDataSet,
+ aFieldName,
+ theFilterOutput,
+ theIntersection,
+ theObj2VTKMap);
}
}
}
vtkCellData *aCellData = anInput->GetCellData();
vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER");
if(vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper)){
- TSortedArray aGeometryCellArray;
- GetSortedArray(aGeometryCellMapper, aGeometryCellArray);
- //cout<<aGeometryCellArray.size()<<endl;
-
vtkIntArray* aDataCellMapper = NULL;
VISU::TFieldListIterator anIter(this->FieldList);
for(anIter.Begin(); !anIter.End() ; anIter.Next()){
break;
}
}
- if(aDataCellMapper){
+
+ bool anIsDifferent = aDataCellMapper &&
+ aDataCellMapper->GetNumberOfTuples() != aGeometryCellMapper->GetNumberOfTuples();
+ if(anIsDifferent){
+ TSortedArray aGeometryCellArray;
+ GetSortedArray(aGeometryCellMapper, aGeometryCellArray);
+ //cout<<aGeometryCellArray.size()<<endl;
+
TSortedArray aDataCellArray;
GetSortedArray(aDataCellMapper, aDataCellArray);
//cout<<aDataCellArray.size()<<endl;
{
inline
void
- CopyAttribute(vtkDataSetAttributes* theInput, TGetAttribute theGetAttribute,
- vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute,
- vtkIdType theFixedNbTuples)
+ CopyDataSetAttribute(vtkDataSet *theInput,
+ TGetAttribute theGetAttribute,
+ vtkDataSet *theOutput,
+ TSetAttribute theSetAttribute,
+ vtkIdType theNbPoints,
+ vtkIdType theNbCells)
{
- if(vtkDataArray *anAttribute = (theInput->*theGetAttribute)()){
- vtkIdType aNbTuples = anAttribute->GetNumberOfTuples();
- if(theFixedNbTuples == aNbTuples)
- (theOutput->*theSetAttribute)(anAttribute);
- }
+ CopyAttribute(theInput->GetPointData(),
+ theGetAttribute,
+ theOutput->GetPointData(),
+ theSetAttribute,
+ theNbPoints);
+ CopyAttribute(theInput->GetCellData(),
+ theGetAttribute,
+ theOutput->GetCellData(),
+ theSetAttribute,
+ theNbCells);
}
inline
void
- CopyDataSetAttribute(vtkDataSet *theInput, TGetAttribute theGetAttribute,
- vtkDataSet *theOutput, TSetAttribute theSetAttribute,
- vtkIdType theNbPoints, vtkIdType theNbCells)
+ CopyDataSetField(vtkDataSet* theInput,
+ const char* theFieldName,
+ vtkDataSet* theOutput,
+ vtkIdType theNbPoints,
+ vtkIdType theNbCells)
{
- CopyAttribute(theInput->GetPointData(), theGetAttribute,
- theOutput->GetPointData(), theSetAttribute,
- theNbPoints);
- CopyAttribute(theInput->GetCellData(), theGetAttribute,
- theOutput->GetCellData(), theSetAttribute,
- theNbCells);
+ CopyField(theInput->GetPointData(), theFieldName,
+ theOutput->GetPointData(),
+ theNbPoints);
+ CopyField(theInput->GetCellData(), theFieldName,
+ theOutput->GetCellData(),
+ theNbCells);
}
+
}
void VISU_MergeFilter::BasicExecute(vtkDataSet *output)
{
vtkIdType numPts, numCells;
- vtkPointData *outputPD = output->GetPointData();
- vtkCellData *outputCD = output->GetCellData();
vtkDebugMacro(<<"Merging data!");
// merge data only if it is consistent
if(vtkDataSet* aDataSet = this->GetScalars())
- CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetScalars,
- output, &vtkDataSetAttributes::SetScalars,
- numPts, numCells);
+ CopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetScalars,
+ output,
+ &vtkDataSetAttributes::SetScalars,
+ numPts,
+ numCells);
if(vtkDataSet* aDataSet = this->GetVectors())
- CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetVectors,
- output, &vtkDataSetAttributes::SetVectors,
- numPts, numCells);
+ CopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetVectors,
+ output,
+ &vtkDataSetAttributes::SetVectors,
+ numPts,
+ numCells);
if(vtkDataSet* aDataSet = this->GetNormals())
- CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetNormals,
- output, &vtkDataSetAttributes::SetNormals,
- numPts, numCells);
+ CopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetNormals,
+ output,
+ &vtkDataSetAttributes::SetNormals,
+ numPts,
+ numCells);
if(vtkDataSet* aDataSet = this->GetTCoords())
- CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTCoords,
- output, &vtkDataSetAttributes::SetTCoords,
- numPts, numCells);
+ CopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetTCoords,
+ output,
+ &vtkDataSetAttributes::SetTCoords,
+ numPts,
+ numCells);
if(vtkDataSet* aDataSet = this->GetTensors())
- CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTensors,
- output, &vtkDataSetAttributes::SetTensors,
- numPts, numCells);
-
- VISU::TFieldListIterator it(this->FieldList);
- vtkDataArray* da;
- const char* name;
- vtkIdType num;
- for(it.Begin(); !it.End() ; it.Next())
- {
- vtkPointData *pd = it.Get()->Ptr->GetPointData();
- vtkCellData *cd = it.Get()->Ptr->GetCellData();
- name = it.Get()->GetName();
- if ( (da=pd->GetArray(name)) )
- {
- num = da->GetNumberOfTuples();
- if (num == numPts)
- {
- outputPD->AddArray(da);
- }
- }
- if ( (da=cd->GetArray(name)) )
- {
- num = da->GetNumberOfTuples();
- if (num == numCells) // To fix a VTK bug
- {
- outputCD->AddArray(da);
- }
- }
- }
+ CopyDataSetAttribute(aDataSet,
+ &vtkDataSetAttributes::GetTensors,
+ output,
+ &vtkDataSetAttributes::SetTensors,
+ numPts,
+ numCells);
+
+ VISU::TFieldListIterator anIter(this->FieldList);
+ for(anIter.Begin(); !anIter.End() ; anIter.Next()){
+ vtkDataSet *aDataSet = anIter.Get()->Ptr;
+ const char* aFieldName = anIter.Get()->GetName();
+ CopyDataSetField(aDataSet,
+ aFieldName,
+ output,
+ numPts,
+ numCells);
+ }
}