VISU_Convertor_impl.hxx \
VISU_ConvertorUtils.hxx \
VISU_MergeFilter.hxx \
+ VISU_AppendFilter.hxx \
VISU_ExtractUnstructuredGrid.hxx
# Libraries targets
VISU_ConvertorUtils.cxx \
VISU_ExtractUnstructuredGrid.cxx \
VISU_MergeFilter.cxx \
+ VISU_AppendFilter.cxx \
VISU_MedConvertor.cxx
# Executables targets
--- /dev/null
+// SALOME OBJECT : kernel of SALOME component
+//
+// Copyright (C) 2003 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
+//
+//
+//
+// File : VISU_GeometryFilter.cxx
+// Author :
+// Module : SALOME
+// $Header$
+
+#include "VISU_AppendFilter.hxx"
+
+#include <vtkCell.h>
+#include <vtkCellData.h>
+#include <vtkDataSetAttributes.h>
+#include <vtkDataSetCollection.h>
+#include <vtkObjectFactory.h>
+#include <vtkPointData.h>
+#include <vtkUnstructuredGrid.h>
+
+#include <vtkPoints.h>
+#include <vtkIntArray.h>
+
+#include <algorithm>
+#include <vector>
+#include <map>
+
+vtkCxxRevisionMacro(VISU_AppendFilter, "$Revision$");
+vtkStandardNewMacro(VISU_AppendFilter);
+
+VISU_AppendFilter
+::VISU_AppendFilter():
+ myIsMergingInputs(false)
+{}
+
+VISU_AppendFilter
+::~VISU_AppendFilter()
+{}
+
+void
+VISU_AppendFilter
+::SetPoints(vtkPoints* thePoints)
+{
+ if(GetPoints() == thePoints)
+ return;
+
+ myPoints = thePoints;
+
+ Modified();
+}
+
+vtkPoints*
+VISU_AppendFilter
+::GetPoints()
+{
+ return myPoints.GetPointer();
+}
+
+void
+VISU_AppendFilter
+::SetMergingInputs(bool theIsMergingInputs)
+{
+ if(myIsMergingInputs == theIsMergingInputs)
+ return;
+
+ myIsMergingInputs = theIsMergingInputs;
+ Modified();
+}
+
+bool
+VISU_AppendFilter
+::IsMergingInputs()
+{
+ return myIsMergingInputs;
+}
+
+
+namespace
+{
+ typedef vtkIdType TCellId;
+ typedef vtkIdType TInputId;
+ typedef std::pair<TInputId, TCellId> TInputCellId;
+
+ typedef vtkIdType TObjectId;
+ typedef std::map<TObjectId, TInputCellId> TObject2InputIdMap;
+
+ void
+ DoMergingInputs(vtkCellData *theCellData,
+ TInputId theInputId,
+ TObject2InputIdMap& theResult)
+ {
+ if(vtkDataArray *aDataArray = theCellData->GetArray("VISU_CELLS_MAPPER")){
+ if(vtkIntArray *anIntArray = dynamic_cast<vtkIntArray*>(aDataArray)){
+ int aMaxId = anIntArray->GetMaxId();
+ int* aPointer = anIntArray->GetPointer(0);
+ int* anEndPointer = anIntArray->GetPointer(aMaxId + 1);
+ for(vtkIdType aCellId = 0; aPointer != anEndPointer; aPointer++, aCellId++){
+ TObjectId anObjectId = *aPointer;
+ TObject2InputIdMap::iterator anIter = theResult.find(anObjectId);
+ if(anIter != theResult.end())
+ continue;
+ TInputCellId anInputCellId(theInputId, aCellId);
+ theResult.insert(anIter, TObject2InputIdMap::value_type(anObjectId, anInputCellId));
+ }
+ }
+ }
+ }
+
+ struct TFillFieldList
+ {
+ vtkDataSetAttributes::FieldList myFieldList;
+ bool myIsFirstCellData;
+
+ TFillFieldList(vtkIdType theNbInputs):
+ myFieldList(theNbInputs),
+ myIsFirstCellData(true)
+ {}
+
+ void
+ operator()(TInputId theInputId, vtkDataSet* theDataSet)
+ {
+ vtkCellData *aCellData = theDataSet->GetCellData();
+ if(myIsFirstCellData){
+ myFieldList.InitializeFieldList(aCellData);
+ myIsFirstCellData = false;
+ }else{
+ myFieldList.IntersectFieldList(aCellData);
+ }
+ }
+
+ virtual
+ vtkIdType
+ GetNbCells() const = 0;
+ };
+
+ struct TCellCounter: TFillFieldList
+ {
+ vtkIdType myNbCells;
+
+ TCellCounter(vtkIdType theNbInputs):
+ TFillFieldList(theNbInputs),
+ myNbCells(0)
+ {}
+
+ void
+ operator()(TInputId theInputId, vtkDataSet* theDataSet)
+ {
+ TFillFieldList::operator()(theInputId, theDataSet);
+ myNbCells += theDataSet->GetNumberOfCells();
+ }
+
+ virtual
+ vtkIdType
+ GetNbCells() const
+ {
+ return myNbCells;
+ }
+ };
+
+ struct TCellIdMerger: TFillFieldList
+ {
+ TObject2InputIdMap myObject2InputIdMap;
+
+ TCellIdMerger(vtkIdType theNbInputs):
+ TFillFieldList(theNbInputs)
+ {}
+
+ void
+ operator()(TInputId theInputId, vtkDataSet* theDataSet)
+ {
+ TFillFieldList::operator()(theInputId, theDataSet);
+ vtkCellData *aCellData = theDataSet->GetCellData();
+ DoMergingInputs(aCellData, theInputId, myObject2InputIdMap);
+ }
+
+ virtual
+ vtkIdType
+ GetNbCells() const
+ {
+ return myObject2InputIdMap.size();
+ }
+ };
+
+ template<class TFunctor>
+ void
+ ForEachInput(vtkDataObject** theInputs, vtkIdType theNbInputs, TFunctor& theFunctor)
+ {
+ for(vtkIdType anInputId = 0; anInputId < theNbInputs; anInputId++){
+ if(vtkDataSet *aDataSet = (vtkDataSet *)(theInputs[anInputId])){
+ if(aDataSet->GetNumberOfPoints() <= 0 && aDataSet->GetNumberOfCells() <= 0){
+ continue; //no input, just skip
+ }
+ theFunctor(anInputId, aDataSet);
+ }//if non-empty dataset
+ }//for all inputs
+ }
+}
+
+
+void
+VISU_AppendFilter
+::Execute()
+{
+ if(myPoints.GetPointer()){
+ if(myPoints->GetNumberOfPoints() < 1)
+ return;
+
+ vtkUnstructuredGrid *anOutput = this->GetOutput();
+ if(IsMergingInputs()){
+ TCellIdMerger aFunctor(this->NumberOfInputs);
+ ForEachInput<TCellIdMerger>(this->Inputs, this->NumberOfInputs, aFunctor);
+
+ vtkDataSetAttributes::FieldList& aFieldList = aFunctor.myFieldList;
+ TObject2InputIdMap& anObject2InputIdMap = aFunctor.myObject2InputIdMap;
+ vtkIdType aNbCells = aFunctor.GetNbCells();
+ if(aNbCells < 1)
+ return;
+
+ // Now can allocate memory
+ anOutput->Allocate(aNbCells);
+ vtkCellData *anOutputCellData = anOutput->GetCellData();
+ anOutputCellData->CopyAllocate(aFieldList, aNbCells);
+
+ // Append each input dataset together
+ // 1.points
+ anOutput->SetPoints(myPoints.GetPointer());
+
+ // 2.cells
+ vtkIdList *anIdList = vtkIdList::New();
+ anIdList->Allocate(VTK_CELL_SIZE);
+ TObject2InputIdMap::const_iterator anIter = anObject2InputIdMap.begin();
+ TObject2InputIdMap::const_iterator anEndIter = anObject2InputIdMap.end();
+ for(; anIter != anEndIter; anIter++){
+ //TObjectId anObjectId = anIter->first;
+ const TInputCellId& anInputCellId = anIter->second;
+ TInputId anInputId = anInputCellId.first;
+ if(vtkDataSet *aDataSet = (vtkDataSet *)(this->Inputs[anInputId])){
+ TCellId aCellId = anInputCellId.second;
+ aDataSet->GetCellPoints(aCellId, anIdList);
+
+ vtkIdType aCellType = aDataSet->GetCellType(aCellId);
+ vtkIdType aNewCellId = anOutput->InsertNextCell(aCellType, anIdList);
+
+ vtkCellData *aCellData = aDataSet->GetCellData();
+ anOutputCellData->CopyData(aFieldList, aCellData, anInputId, aCellId, aNewCellId);
+ }
+ }
+ anIdList->Delete();
+ }else{
+ TCellCounter aFunctor(this->NumberOfInputs);
+ ForEachInput<TCellCounter>(this->Inputs, this->NumberOfInputs, aFunctor);
+
+ vtkDataSetAttributes::FieldList& aFieldList = aFunctor.myFieldList;
+ vtkIdType aNbCells = aFunctor.GetNbCells();
+ if(aNbCells < 1)
+ return;
+
+ // Now can allocate memory
+ anOutput->Allocate(aNbCells);
+ vtkCellData *anOutputCellData = anOutput->GetCellData();
+ anOutputCellData->CopyAllocate(aFieldList, aNbCells);
+
+ // Append each input dataset together
+ // 1.points
+ anOutput->SetPoints(myPoints.GetPointer());
+
+ // 2.cells
+ vtkIdList *anIdList = vtkIdList::New();
+ anIdList->Allocate(VTK_CELL_SIZE);
+ for(vtkIdType anInputId = 0; anInputId < this->NumberOfInputs; anInputId++) {
+ if(vtkDataSet *aDataSet = (vtkDataSet *)(this->Inputs[anInputId])){
+ vtkIdType aNbCells = aDataSet->GetNumberOfCells();
+ vtkCellData *aCellData = aDataSet->GetCellData();
+ // copy cell and cell data
+ for(vtkIdType aCellId = 0; aCellId < aNbCells; aCellId++){
+ aDataSet->GetCellPoints(aCellId, anIdList);
+ vtkIdType aCellType = aDataSet->GetCellType(aCellId);
+ vtkIdType aNewCellId = anOutput->InsertNextCell(aCellType, anIdList);
+ anOutputCellData->CopyData(aFieldList, aCellData, anInputId, aCellId, aNewCellId);
+ }
+ }
+ }
+ anIdList->Delete();
+ }
+ }else
+ Superclass::Execute();
+}
--- /dev/null
+// Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
+//
+// 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
+//
+#ifndef VISU_APPENDFILTER_H
+#define VISU_APPENDFILTER_H
+
+#include <vtkAppendFilter.h>
+#include <vtkSmartPointer.h>
+
+class vtkPoints;
+
+/*! \brief This class used same as vtkAppendFilter. See documentation on VTK for more information.
+ */
+class VISU_AppendFilter : public vtkAppendFilter
+{
+public:
+ /*! \fn static VISU_AppendFilter *New()
+ */
+ static VISU_AppendFilter *New();
+
+ /*! \fn vtkTypeRevisionMacro(VISU_AppendFilter, vtkAppendFilter)
+ * \brief VTK type revision macros.
+ */
+ vtkTypeRevisionMacro(VISU_AppendFilter, vtkAppendFilter);
+
+ void
+ SetPoints(vtkPoints* thePoints);
+
+ vtkPoints*
+ GetPoints();
+
+ void
+ SetMergingInputs(bool theIsMergingInputs);
+
+ bool
+ IsMergingInputs();
+
+protected:
+ /*! \fn VISU_AppendFilter();
+ * \brief Constructor
+ */
+ VISU_AppendFilter();
+ /*! \fn ~VISU_AppendFilter();
+ * \brief Destructor.
+ */
+ ~VISU_AppendFilter();
+ /*! \fn void Execute();
+ * \brief Filter culculation method.
+ */
+ virtual void Execute();
+
+ bool myIsMergingInputs;
+ vtkSmartPointer<vtkPoints> myPoints;
+};
+
+#endif
TMeshOnEntityImpl
::GetElemVTKID(vtkIdType theID) const
{
- if(myElemObj2VTKID.empty())
- return theID;
- else{
- TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID);
- if(anIter != myElemObj2VTKID.end())
- return anIter->second;
- }
- return -1;
+ VISU::TVTKOutput* anOutput = GetFilter()->GetOutput();
+ return VISU::GetElemVTKID(anOutput, theID);
}
vtkIdType
TMeshOnEntityImpl
::GetElemObjID(vtkIdType theID) const
{
- vtkIdType anInputID, aStartId, anInputDataSetID;
- const TVTKAppendFilter& anAppendFilter = GetFilter();
- anAppendFilter->GetCellInputID(theID,anInputID,aStartId,anInputDataSetID);
- const PSubMeshImpl& aSubMesh = mySubMeshArr[anInputDataSetID];
- return aSubMesh->GetElemObjID(anInputID);
+ VISU::TVTKOutput* anOutput = GetFilter()->GetOutput();
+ return VISU::GetElemObjID(anOutput, theID);
}
std::string
TSubMeshID& aMeshID = theFamily->myMeshID;
aMeshID.resize(aNbCells);
+ vtkIntArray *aDataArray = vtkIntArray::New();
+ aDataArray->SetName("VISU_CELLS_MAPPER");
+ aDataArray->SetNumberOfComponents(1);
+ aDataArray->SetNumberOfTuples(aNbCells);
+
VISU::TID2ID& anElemObj2VTKID = theFamily->myElemObj2VTKID;
const VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
VISU::TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin();
- for(vtkIdType i = 0, j = 0; anIter != aGeom2SubMesh.end(); anIter++){
+ for(vtkIdType aCellId = 0; anIter != aGeom2SubMesh.end(); anIter++){
VISU::EGeometry aEGeom = anIter->first;
vtkIdType aVGeom = VISUGeom2VTK(aEGeom);
endl);
VISU::TSubMeshID::const_iterator aSubMeshIDIter = aSubMeshID.begin();
- for(; aSubMeshIDIter != aSubMeshID.end(); aSubMeshIDIter++, i++){
+ for(; aSubMeshIDIter != aSubMeshID.end(); aSubMeshIDIter++, aCellId++){
vtkIdType anID = *aSubMeshIDIter;
- PrintCells(i,aConnectivity,anArray[anID]);
- aCellTypesArray->SetValue(j++,(unsigned char)aVGeom);
+ PrintCells(aCellId, aConnectivity, anArray[anID]);
+ aCellTypesArray->SetValue(aCellId, (unsigned char)aVGeom);
vtkIdType anObjID = aSubMesh.GetElemObjID(anID);
- anElemObj2VTKID[anObjID] = i;
- aMeshID[i] = anObjID;
+ aDataArray->SetValue(aCellId, anObjID);
+ anElemObj2VTKID[anObjID] = aCellId;
+ aMeshID[aCellId] = anObjID;
}
}
+
+ theSource->GetCellData()->AddArray(aDataArray);
+ aDataArray->Delete();
+
vtkIdType *pts = 0, npts = 0;
VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
aCellLocationsArray->SetNumberOfComponents(1);
const TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin();
- TID2ID& anElemObj2VTKID = aMeshOnEntity->myElemObj2VTKID;
- TSubMeshArr& aSubMeshArr = aMeshOnEntity->mySubMeshArr;
- aSubMeshArr.resize(aGeom2SubMesh.size());
-
for(vtkIdType anID = 0, aCellID = 0; anIter != aGeom2SubMesh.end(); anIter++, anID++){
EGeometry aEGeom = anIter->first;
vtkIdType aVGeom = VISUGeom2VTK(aEGeom);
PSubMeshImpl aSubMesh = anIter->second;
+
//ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
aSubMesh->myIsStructured = aMesh->myIsStructured;
aSubMesh->myType = aMesh->myType;
aSubMesh->myGrilleStructure = aMesh->myGrilleStructure;
aSubMesh->myObjID2StructureID = aMesh->myObjID2StructureID;
//ENK: 23.11.2006
+
const TVTKSource& aSource = aSubMesh->GetSource();
aSource->SetPoints(GetPoints(aMesh));
- GetCellsOnSubMesh(aSource, aMeshOnEntity, aSubMesh, aVGeom);
- anAppendFilter->AddInput(aSource.GetPointer());
aSubMesh->myStartID = aCellID;
- vtkIdType aNbCells = aSource->GetNumberOfCells();
- for(vtkIdType aCell = 0; aCell < aNbCells; aCell++, aCellID++){
- vtkIdType anObjID = aSubMesh->GetElemObjID(aCell);
- anElemObj2VTKID[anObjID] = aCellID;
- }
- aSubMeshArr[anID] = aSubMesh;
+ GetCellsOnSubMesh(aSource, aMeshOnEntity, aSubMesh, aVGeom);
+ anAppendFilter->AddInput(aSource.GetPointer());
+ aCellID += aSource->GetNumberOfCells();
}
aMeshOnEntity->myNamedPointCoords = aMesh->myNamedPointCoords;
//ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
//------------------------------------------------------------------------------
// Create object with no input or output.
-VISU_MergeFilter::VISU_MergeFilter()
+VISU_MergeFilter::VISU_MergeFilter():
+ myIsMergingInputs(false)
{
this->FieldList = new VISU::TFieldList;
}
this->FieldList->Add(name, input);
}
+void VISU_MergeFilter::RemoveFields()
+{
+ delete this->FieldList;
+ this->FieldList = new VISU::TFieldList;
+}
+
namespace
{
typedef std::vector<int> TSortedArray;
typedef std::map<int,int> TId2IdMap;
- template <class IT, class OT>
- void DeepCopyArrayOfDifferentType(IT *theInputPtr,
- OT *theOutputPtr,
- const TSortedArray& theIntersection,
- const TId2IdMap& theObj2VTKMap,
- vtkIdType theNbComp)
+ template <class TNumericType>
+ void DeepCopySwitchOnOutput(TNumericType *theInputPtr,
+ TNumericType *theOutputPtr,
+ const TSortedArray& theIntersection,
+ const TId2IdMap& theObj2VTKMap,
+ vtkIdType theNbComp)
{
vtkIdType aNbIds = theIntersection.size();
for(vtkIdType aTargetTupleId = 0; aTargetTupleId < aNbIds; aTargetTupleId++){
+ vtkIdType aTargetId = aTargetTupleId*theNbComp;
vtkIdType anObjId = theIntersection[aTargetTupleId];
TId2IdMap::const_iterator anIter = theObj2VTKMap.find(anObjId);
vtkIdType aSourceTupleId = anIter->second;
- for(vtkIdType aComp = 0; aComp < theNbComp; aComp++)
- theOutputPtr[aTargetTupleId*theNbComp + aComp] =
- static_cast<OT>(theInputPtr[aSourceTupleId*theNbComp + aComp]);
- }
- }
-
- template <class IT>
- void DeepCopySwitchOnOutput(IT *theInputPtr,
- vtkDataArray *theDataArray,
- const TSortedArray& theIntersection,
- const TId2IdMap& theObj2VTKMap,
- vtkIdType theNbComp)
- {
- void *anOutputPtr = theDataArray->GetVoidPointer(0);
- switch(theDataArray->GetDataType()){
- vtkTemplateMacro5(DeepCopyArrayOfDifferentType, theInputPtr, (VTK_TT*)anOutputPtr,
- theIntersection, theObj2VTKMap,
- theNbComp);
- default:
- vtkGenericWarningMacro(<<"Unsupported data type!");
+ vtkIdType aSourceId = aSourceTupleId*theNbComp;
+ for(vtkIdType aComp = 0; aComp < theNbComp; aComp++){
+ theOutputPtr[aTargetId++] = theInputPtr[aSourceId++];
+ }
}
}
theFixedNbTuples);
}
- void
+ vtkDataArray*
DeepCopyArray(vtkDataArray* theDataArray,
vtkDataSetAttributes* theOutput,
TSetAttribute theSetAttribute,
const TSortedArray& theIntersection,
const TId2IdMap& theObj2VTKMap)
{
+ vtkDataArray *aDataArray = NULL;
if(theDataArray){
- vtkIdType aNbTuples = theDataArray->GetNumberOfTuples();
+ void *anInputPtr = theDataArray->GetVoidPointer(0);
+ vtkIdType aNbTuples = theIntersection.size();
vtkIdType aNbComp = theDataArray->GetNumberOfComponents();
- vtkDataArray *aDataArray = vtkDataArray::CreateDataArray(theDataArray->GetDataType());
- aDataArray->SetNumberOfTuples(aNbTuples);
+ aDataArray = vtkDataArray::CreateDataArray(theDataArray->GetDataType());
aDataArray->SetNumberOfComponents(aNbComp);
- void *anInputPtr = theDataArray->GetVoidPointer(0);
+ aDataArray->SetNumberOfTuples(aNbTuples);
+ void *anOutputPtr = aDataArray->GetVoidPointer(0);
switch(theDataArray->GetDataType()){
- vtkTemplateMacro5(DeepCopySwitchOnOutput, (VTK_TT*)anInputPtr, aDataArray,
- theIntersection, theObj2VTKMap,
- aNbComp);
+ vtkTemplateMacro5(DeepCopySwitchOnOutput,
+ (VTK_TT*)anInputPtr,
+ (VTK_TT*)anOutputPtr,
+ theIntersection,
+ theObj2VTKMap,
+ aNbComp);
default:
vtkGenericWarningMacro(<<"Unsupported data type!");
}
(theOutput->*theSetAttribute)(aDataArray);
aDataArray->Delete();
}
+ return aDataArray;
}
void
const TSortedArray& theIntersection,
const TId2IdMap& theObj2VTKMap)
{
- DeepCopyArray(theInput->GetArray(theFieldName),
- theOutput,
- &vtkDataSetAttributes::AddArray,
- theIntersection,
- theObj2VTKMap);
+ vtkDataArray* aDataArray =
+ DeepCopyArray(theInput->GetArray(theFieldName),
+ theOutput,
+ &vtkFieldData::AddArray,
+ theIntersection,
+ theObj2VTKMap);
+ if(aDataArray)
+ aDataArray->SetName(theFieldName);
}
inline
}
}
+void
+VISU_MergeFilter
+::SetMergingInputs(bool theIsMergingInputs)
+{
+ if(myIsMergingInputs == theIsMergingInputs)
+ return;
+
+ myIsMergingInputs = theIsMergingInputs;
+ Modified();
+}
+
+bool
+VISU_MergeFilter
+::IsMergingInputs()
+{
+ return myIsMergingInputs;
+}
+
+
void VISU_MergeFilter::Execute()
{
vtkUnstructuredGrid *anInput = this->GetInput();
bool anIsDifferent = aDataCellMapper &&
aDataCellMapper->GetNumberOfTuples() != aGeometryCellMapper->GetNumberOfTuples();
- if(anIsDifferent){
+ if(anIsDifferent || IsMergingInputs()){
TSortedArray aGeometryCellArray;
GetSortedArray(aGeometryCellMapper, aGeometryCellArray);
- //cout<<aGeometryCellArray.size()<<endl;
TSortedArray aDataCellArray;
GetSortedArray(aDataCellMapper, aDataCellArray);
- //cout<<aDataCellArray.size()<<endl;
int aMaxLength = std::max(aGeometryCellArray.size(), aDataCellArray.size());
TSortedArray anIntersectionArray(aMaxLength);
anIntersectionArray.erase(anArrayIter, anIntersectionArray.end());
- //cout<<anIntersectionArray.size()<<endl<<endl;
-
bool anIsCompletelyCoincide =
anIntersectionArray.size() == aGeometryCellArray.size() &&
anIntersectionArray.size() == aDataCellArray.size();
- if(!anIsCompletelyCoincide){
+ if(!anIsCompletelyCoincide || IsMergingInputs()){
{
TId2IdMap anObj2VTKGeometryMap;
vtkIdType aNbCells = aGeometryCellMapper->GetNumberOfTuples();
anObj2VTKDataMap[anObjID] = aCellId;
}
- DeepCopyDataSetAttributes(this, anOutput, this->FieldList,
- anIntersectionArray, anObj2VTKDataMap);
+ DeepCopyDataSetAttributes(this,
+ anOutput,
+ this->FieldList,
+ anIntersectionArray,
+ anObj2VTKDataMap);
}
return;
}
// of the field
void AddField(const char* name, vtkDataSet* input);
+ // Description:
+ // Removes all previously added fields
+ void RemoveFields();
+
+ // Description:
+ // Defines whether to perform merging of data with the geometry according to
+ // the ids of the cell or not
+ void
+ SetMergingInputs(bool theIsMergingInputs);
+
+ bool
+ IsMergingInputs();
+
protected:
VISU_MergeFilter();
~VISU_MergeFilter();
void Execute();
VISU::TFieldList* FieldList;
+ bool myIsMergingInputs;
+
private:
VISU_MergeFilter(const VISU_MergeFilter&); // Not implemented.
void operator=(const VISU_MergeFilter&); // Not implemented.
#include "VISU_IDMapper.hxx"
#include "VTKViewer_AppendFilter.h"
+#include "VISU_AppendFilter.hxx"
+#include "VISU_MergeFilter.hxx"
+
#include "VISU_PipeLineUtils.hxx"
#include <vtkMapper.h>
vtkStandardNewMacro(VISU_PrsMergerPL);
VISU_PrsMergerPL
-::VISU_PrsMergerPL()
+::VISU_PrsMergerPL():
+ myAppendFilter(VISU_AppendFilter::New()),
+ myMergeFilter(VISU_MergeFilter::New()),
+ myScalars(NULL)
{
- myScalars = NULL;
-
- //myMergeFilter->Delete();
- myMeshGeometryList.clear();
+ myAppendFilter->SetMergingInputs(true);
+ myAppendFilter->Delete();
+
+ myMergeFilter->SetMergingInputs(true);
+ myMergeFilter->Delete();
}
VISU_PrsMergerPL
::~VISU_PrsMergerPL()
-{
- myMeshGeometryList.clear();
-}
+{}
void
VISU_PrsMergerPL
* 2.1 Group Cell - OK
* 2.2 Group Point - ERR (remove points groups)
*/
-
-
-
if(MYDEBUG) MESSAGE("VISU_PrsMergerPL::Execute()");
- if(myMeshGeometryList.size() != 0)
- {
-
- typedef std::vector<int> TVec;
-
- vtkUnstructuredGrid* output = vtkUnstructuredGrid::New();
- TVec aObjIds; // vector with object ids
- vtkFloatArray* newArray = vtkFloatArray::New();
+ myAppendFilter->RemoveAllInputs();
+ if(!myMeshGeometryList.empty()){
+ const VISU::PIDMapper& aScalarsIDMapper = myScalars->GetIDMapper();
+ VISU::TVTKOutput* aScalarsOutput = aScalarsIDMapper->GetVTKOutput();
- VISU_ScalarMapPL* aScalarMap = dynamic_cast<VISU_ScalarMapPL*>(this->GetScalars());
- const VISU::PIDMapper& aScalarMapper = myScalars->GetIDMapper();
+ // copy points to output from input scalar map
+ myAppendFilter->SetPoints(aScalarsOutput->GetPoints());
- // copy points to output from input scalar map
- output->SetPoints(aScalarMapper->GetVTKOutput()->GetPoints());
+ vtkIdType aNbGeoms = this->GetNbGeometry();
+ for(vtkIdType aGeomId = 0; aGeomId < aNbGeoms; aGeomId++){
+ VISU_PipeLine* aGeomPipeLine = this->GetGeometry(aGeomId);
+ const VISU::PIDMapper& aGeomIDMapper = aGeomPipeLine->GetIDMapper();
+ VISU::TVTKOutput* aGeomOutput = aGeomIDMapper->GetVTKOutput();
+ vtkIdType aNbCells = aGeomOutput->GetNumberOfCells();
+ if(aNbCells > 0)
+ if(aGeomOutput->GetCell(0)->GetCellType() == VTK_VERTEX )
+ continue;
- int newCellId;
- int anbGeoms = this->GetNbGeometry();
- for(int i=0; i < anbGeoms; i++) {
- VISU_PipeLine* aCurrGeometry = this->GetGeometry(i);
- const VISU::PIDMapper& aGM = aCurrGeometry->GetIDMapper();
- int aNbCells = aGM->GetVTKOutput()->GetNumberOfCells();
- if (aNbCells >0 )
- if (aGM->GetVTKOutput()->GetCell(0)->GetCellType() == VTK_VERTEX )
- continue;
-
- vtkIdList* ptIds = vtkIdList::New();
- ptIds->Allocate(VTK_CELL_SIZE);
-
- for(int j=0; j < aNbCells; j++){
-
- int anObjID = aGM->GetElemObjID(j);
- aObjIds.push_back(anObjID);
-
- // copy cells to output from input geoms
- aGM->GetVTKOutput()->GetCellPoints(j, ptIds);
- newCellId = output->InsertNextCell(aGM->GetVTKOutput()->GetCellType(j),ptIds);
- }
- ptIds->Delete();
- }
-
-
- //copy array values
- vtkDataArray* da;
- if((da = aScalarMapper->GetVTKOutput()->GetPointData()->GetArray("VISU_FIELD"))){
- output->GetPointData()->AddArray(da);
- vtkDataArray* vc = aScalarMapper->GetVTKOutput()->GetPointData()->GetVectors();
- if(vc)
- output->GetPointData()->SetVectors(vc);
- }
- if((da = aScalarMapper->GetVTKOutput()->GetCellData()->GetArray("VISU_FIELD"))){
- if(MYDEBUG){
- MESSAGE("aScalarMapper NumberOfComponents="<<da->GetNumberOfComponents());
- MESSAGE("aScalarMapper NumberOfTuples ="<<da->GetNumberOfTuples());
- }
-
- newArray->SetNumberOfComponents(da->GetNumberOfComponents());
- newArray->SetNumberOfTuples(aObjIds.size());
- newArray->SetName("VISU_FIELD");
-
- TVec::const_iterator aIdsIter = aObjIds.begin();
- for(int i=0; aIdsIter != aObjIds.end(); aIdsIter++){
- int anObjID = *aIdsIter;
- int aVTKID = aScalarMapper->GetElemVTKID(anObjID);
- newArray->SetTuple(i,da->GetTuple(aVTKID));
- i++;
- }
- output->GetCellData()->AddArray(newArray);
-
- // need in vectors array and scalars array
- if(vtkDataArray* vc = aScalarMapper->GetVTKOutput()->GetCellData()->GetVectors()){
- output->GetCellData()->SetVectors(newArray);
- }
- else if(vtkDataArray* sc = aScalarMapper->GetVTKOutput()->GetCellData()->GetScalars())
- output->GetCellData()->SetScalars(newArray);
- }
-
- if(MYDEBUG){
- MESSAGE("output:");
- output->Print(cout);
- }
+ myAppendFilter->AddInput(aGeomOutput);
+ }
+ myAppendFilter->Update();
+ vtkUnstructuredGrid* aGeomDataSet = myAppendFilter->GetOutput();
+ myMergeFilter->SetGeometry(aGeomDataSet);
+ //copy array values
+ myMergeFilter->SetScalars(aScalarsOutput);
+ myMergeFilter->SetVectors(aScalarsOutput);
- SetInput(output);
-
- output->Delete();
- newArray->Delete();
- }
- else
- {
- if(myScalars != NULL)
- {
- VISU_ScalarMapPL* aScalarMap = dynamic_cast<VISU_ScalarMapPL*>(this->GetScalars());
- VISU_PrsMergerPL* aPrsMerger = dynamic_cast<VISU_PrsMergerPL*>(this->GetScalars());
- if(aScalarMap != NULL){
- SetInput(aScalarMap->GetInput());
- }
- }
+ myMergeFilter->RemoveFields();
+ myMergeFilter->AddField("VISU_FIELD", aScalarsOutput);
+ myMergeFilter->AddField("VISU_CELLS_MAPPER", aScalarsOutput);
+
+ myMergeFilter->Update();
+ SetInput(myMergeFilter->GetOutput());
+ }else{
+ if(myScalars != NULL){
+ if(VISU_ScalarMapPL* aScalarMap = dynamic_cast<VISU_ScalarMapPL*>(this->GetScalars()))
+ SetInput(aScalarMap->GetInput());
}
+ }
}
#include "VISU_ScalarMapPL.hxx"
+class VISU_AppendFilter;
+class VISU_MergeFilter;
+
+
class VISU_PrsMergerPL : public VISU_ScalarMapPL
{
typedef VISU_ScalarMapPL TSupperClass;
void SetInitialRange();
protected:
- TPipeLines myMeshGeometryList;
+ TPipeLines myMeshGeometryList;
+ vtkSmartPointer<VISU_AppendFilter> myAppendFilter;
+ vtkSmartPointer<VISU_MergeFilter> myMergeFilter;
- TPipeLine myScalars;
-
vtkFloatingPointType* myScalarRanges;
+ TPipeLine myScalars;
private:
void
Execute();
-
};
#endif