From 7a359fa00657ed3b5266a0c57c580c03f4d4986c Mon Sep 17 00:00:00 2001 From: apo Date: Thu, 9 Feb 2006 13:11:48 +0000 Subject: [PATCH] Fix for Bug IPAL11380 Position of the parent mesh element is incorrect: (to provide a simpler interface and its implementation) --- src/VTKViewer/VTKViewer_AppendFilter.cxx | 300 ++++++++++------------- src/VTKViewer/VTKViewer_AppendFilter.h | 41 ++-- 2 files changed, 143 insertions(+), 198 deletions(-) diff --git a/src/VTKViewer/VTKViewer_AppendFilter.cxx b/src/VTKViewer/VTKViewer_AppendFilter.cxx index dce05c44e..222d2f1ab 100644 --- a/src/VTKViewer/VTKViewer_AppendFilter.cxx +++ b/src/VTKViewer/VTKViewer_AppendFilter.cxx @@ -28,38 +28,15 @@ #include "VTKViewer_AppendFilter.h" -#include "VTKViewer_ConvexTool.h" - -#include -#include +#include #include -#include -#include -#include +#include +#include #include #include -#include -#include -#include -#include -#include #include -#include -#include -#include - -#include -#include -using namespace std; - -#ifdef _DEBUG_ -//static int MYDEBUG = 0; -//static int MYDEBUGWITHFILES = 0; -#else -//static int MYDEBUG = 0; -//static int MYDEBUGWITHFILES = 0; -#endif +#include #if defined __GNUC__ #if __GNUC__ == 2 @@ -73,7 +50,7 @@ vtkStandardNewMacro(VTKViewer_AppendFilter); VTKViewer_AppendFilter ::VTKViewer_AppendFilter() { - myDoMappingFlag=false; + myDoMappingFlag = false; } VTKViewer_AppendFilter @@ -84,7 +61,12 @@ void VTKViewer_AppendFilter ::SetDoMappingFlag(const bool theFlag) { - myDoMappingFlag=theFlag; + if(myDoMappingFlag == theFlag) + return; + + myDoMappingFlag = theFlag; + + this->Modified(); } bool @@ -98,7 +80,12 @@ void VTKViewer_AppendFilter ::SetPoints(vtkPoints* thePoints) { + if(GetPoints() == thePoints) + return; + myPoints = thePoints; + + this->Modified(); } vtkPoints* @@ -112,28 +99,16 @@ void VTKViewer_AppendFilter ::Execute() { - if (myPoints.GetPointer()) { + if(myPoints.GetPointer()) MakeOutput(); - } - else { - vtkAppendFilter::Execute(); - } - if (myDoMappingFlag){ + else + Superclass::Execute(); + + if(myDoMappingFlag) DoMapping(); - } } -void -VTKViewer_AppendFilter -::Reset() -{ - myNodeIds.clear(); - myCellIds.clear(); - myNodeRanges.clear(); - myCellRanges.clear(); - myNodeMapObjIDVtkID.clear(); - myCellMapObjIDVtkID.clear(); -} + //================================================================== // function: DoMapping // purpose : @@ -142,165 +117,140 @@ void VTKViewer_AppendFilter ::DoMapping() { - int i, j, i1, i2, iNodeCnt, iCellCnt; - IteratorOfDataMapOfIntegerInteger aMapIt; - vtkIdType aNbPnts, aNbCells, aId; - vtkDataSet *pDS; - // - Reset(); - // - iNodeCnt=0; - iCellCnt=0; - for (i=0; iGetNumberOfPoints(); - i1=myNodeIds.size(); - i2=i1+aNbPnts-1; - myNodeRanges.push_back(i1); - myNodeRanges.push_back(i2); - // - for(j=0; jGetNumberOfCells(); - i1=myCellIds.size(); - i2=i1+aNbCells-1; - myCellRanges.push_back(i1); - myCellRanges.push_back(i2); - for(j=0; jNumberOfInputs; ++aDataSetId){ + vtkDataSet* aDataSet = (vtkDataSet *)(this->Inputs[aDataSetId]); + // Do mapping of the nodes + if(!myPoints.GetPointer()){ + vtkIdType aNbPnts = aDataSet->GetNumberOfPoints(); + myNodeRanges.push_back(aPntStartId + aNbPnts); + aPntStartId += aNbPnts; } + // Do mapping of the cells + vtkIdType aNbCells = aDataSet->GetNumberOfCells(); + myCellRanges.push_back(aCellStartId + aNbCells); + aCellStartId += aNbCells; } } //--------------------------------------------------------------- +namespace +{ + inline + vtkIdType + GetOutputID(vtkIdType theInputID, + vtkIdType theInputDataSetID, + const VTKViewer_AppendFilter::TVectorIds& theRanges) + { + theInputID = theInputDataSetID = -1; + + vtkIdType aNbInputs = theRanges.size(); + if(theInputDataSetID < 0 || theInputDataSetID >= aNbInputs) + return -1; + + vtkIdType aStartId = theRanges[theInputDataSetID]; + return aStartId + theInputID; + } +} + vtkIdType VTKViewer_AppendFilter -::GetPointOutputID(vtkIdType theInputID) +::GetPointOutputID(vtkIdType theInputID, + vtkIdType theInputDataSetID) { - if (myPoints.GetPointer()) { + if(myPoints.GetPointer()) return theInputID; - } - // - int aVtkID=-1; - IteratorOfDataMapOfIntegerInteger aMapIt; - // - aMapIt=myNodeMapObjIDVtkID.find(theInputID); - if (aMapIt!=myNodeMapObjIDVtkID.end()) { - // found - PairOfDataMapOfIntegerInteger& aPair=(*aMapIt); - aVtkID=aPair.second; - } - return aVtkID; + + return GetOutputID(theInputID,theInputDataSetID,myNodeRanges); } //--------------------------------------------------------------- vtkIdType VTKViewer_AppendFilter -::GetCellOutputID(vtkIdType theInputID) +::GetCellOutputID(vtkIdType theInputID, + vtkIdType theInputDataSetID) { - int aVtkID=-1; - IteratorOfDataMapOfIntegerInteger aMapIt; - // - aMapIt=myCellMapObjIDVtkID.find(theInputID); - if (aMapIt!=myCellMapObjIDVtkID.end()) { - // found - PairOfDataMapOfIntegerInteger& aPair=(*aMapIt); - aVtkID=aPair.second; - } - return aVtkID; + if(myPoints.GetPointer()) + return theInputID; + + return GetOutputID(theInputID,theInputDataSetID,myCellRanges); } //--------------------------------------------------------------- -vtkIdType +namespace +{ + void + GetInputID(vtkIdType theOutputID, + vtkIdType& theInputID, + vtkIdType& theStartID, + vtkIdType& theInputDataSetID, + const VTKViewer_AppendFilter::TVectorIds& theRanges) + { + theInputID = theStartID = theInputDataSetID = -1; + + if(theRanges.empty()) + return; + + const vtkIdType& aRangeEnd = theRanges.back(); + if(theOutputID < 0 || theOutputID >= aRangeEnd) + return; + + vtkIdType aStartId = 0; + vtkIdType aNbInputs = theRanges.size(); + for(vtkIdType aDataSetId = 0; aDataSetId < aNbInputs; ++aDataSetId){ + vtkIdType aRange = theRanges[aDataSetId]; + if(aRange > theOutputID){ + theInputID = theOutputID - aStartId; + theInputDataSetID = aDataSetId; + theStartID = aStartId; + break; + } + aStartId = aRange; + } + } +} + +void VTKViewer_AppendFilter -::GetPointInputID(vtkIdType theOutputID, +::GetPointInputID(vtkIdType theOutputID, + vtkIdType& theInputID, + vtkIdType& theStartID, vtkIdType& theInputDataSetID) { - if (myPoints.GetPointer()) { - theInputDataSetID=0; - return theOutputID; - } - // - int aNb, aNbRanges, aRetID, i, i1, i2, j; - // - aRetID=-1; - theInputDataSetID=-1; - // - aNb=myNodeIds.size(); - if (theOutputID<0 || theOutputID>=aNb) { - return aRetID; - } - // - aRetID=(int)myNodeIds[theOutputID]; - // - aNbRanges=myNodeRanges.size()/2; - for (i=0; i=i1 && theOutputID<=i2) { - theInputDataSetID=i; - } + if(myPoints.GetPointer()) { + theStartID = theInputDataSetID = 0; + theInputID = theOutputID; + return; } - // - return aRetID; + + ::GetInputID(theOutputID, + theInputID, + theStartID, + theInputDataSetID, + myNodeRanges); } //--------------------------------------------------------------- -vtkIdType +void VTKViewer_AppendFilter -::GetCellInputID(vtkIdType theOutputID, +::GetCellInputID(vtkIdType theOutputID, + vtkIdType& theInputID, + vtkIdType& theStartID, vtkIdType& theInputDataSetID) { - int aNb, aNbRanges, aRetID, i, i1, i2, j; - // - aRetID=-1; - theInputDataSetID=-1; - // - aNb=myCellIds.size(); - if (theOutputID<0 || theOutputID>=aNb) { - return aRetID; - } - // - aRetID=(int)myCellIds[theOutputID]; - // - aNbRanges=myCellRanges.size()/2; - for (i=0; i=i1 && theOutputID<=i2) { - theInputDataSetID=i; - } - } - // - return aRetID; + ::GetInputID(theOutputID, + theInputID, + theStartID, + theInputDataSetID, + myCellRanges); } diff --git a/src/VTKViewer/VTKViewer_AppendFilter.h b/src/VTKViewer/VTKViewer_AppendFilter.h index f9c6b245a..ceaa3d323 100644 --- a/src/VTKViewer/VTKViewer_AppendFilter.h +++ b/src/VTKViewer/VTKViewer_AppendFilter.h @@ -36,19 +36,27 @@ public: GetPoints(); vtkIdType - GetPointOutputID(vtkIdType theInputID); + GetPointOutputID(vtkIdType theInputID, + vtkIdType theInputDataSetID); vtkIdType - GetCellOutputID(vtkIdType theInputID); + GetCellOutputID(vtkIdType theInputID, + vtkIdType theInputDataSetID); - vtkIdType - GetPointInputID(vtkIdType theOutputID, - vtkIdType& theInputDataSetID); + void + GetPointInputID(vtkIdType theOutputID, + vtkIdType& theInputID, + vtkIdType& theStartID, + vtkIdType& theInputDataSetID); - vtkIdType - GetCellInputID(vtkIdType theOutputID, + void + GetCellInputID(vtkIdType theOutputID, + vtkIdType& theInputID, + vtkIdType& theStartID, vtkIdType& theInputDataSetID); + typedef std::vector TVectorIds; + protected: /*! \fn VTKViewer_AppendFilter(); * \brief Constructor @@ -69,23 +77,10 @@ protected: void MakeOutput(); - // + bool myDoMappingFlag; + TVectorIds myNodeRanges; + TVectorIds myCellRanges; vtkSmartPointer myPoints; - -private: - typedef std::vector TVectorId; - typedef std::vector VectorInt; - typedef std::map DataMapOfIntegerInteger; - typedef DataMapOfIntegerInteger::iterator IteratorOfDataMapOfIntegerInteger; - typedef DataMapOfIntegerInteger::value_type PairOfDataMapOfIntegerInteger; -private: - bool myDoMappingFlag; - TVectorId myNodeIds; - TVectorId myCellIds; - VectorInt myNodeRanges; - VectorInt myCellRanges; - DataMapOfIntegerInteger myNodeMapObjIDVtkID; - DataMapOfIntegerInteger myCellMapObjIDVtkID; }; #endif -- 2.39.2