#include <vtkTextProperty.h>
#include <vtkPointData.h>
+#include <vtkCellData.h>
#include <vtkDataArray.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkCellArray.h>
+#include <vtkWarpVector.h>
+#include <vtkCellDataToPointData.h>
#include <vtkCell.h>
#include <vtkMath.h>
myPickingSettings(NULL),
myInsideCursorSettings(NULL),
myCurrentPL(NULL),
- myMapper(vtkPolyDataMapper::New())
+ myMapper(vtkPolyDataMapper::New()),
+ myWarpVector(vtkWarpVector::New()),
+ myCellDataToPointData(vtkCellDataToPointData::New())
{
if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<<this);
myMapper->Delete();
aMatrix->Delete();
+
+ myWarpVector->Delete();
+ myCellDataToPointData->Delete();
}
VISU_GaussPtsAct
myCellSource->Reset();
myCellSource->Modified(); // a VTK bug
vtkUnstructuredGrid* aDataSet = aParent->GetUnstructuredGridOutput();
- myCellSource->SetPoints(aDataSet->GetPoints());
VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
vtkIdType aCellID = aGaussPointID.first;
vtkCell* aCell = aParent->GetElemCell(aCellID);
myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
+
+ if (myGaussPointsPL->GetIsDeformed()) {
+ // find neighbour cells ids
+ vtkIdList* aNeighbourCells = vtkIdList::New();
+ aNeighbourCells->Allocate(VTK_CELL_SIZE);
+
+ vtkIdList* aCellPoints = aCell->GetPointIds();
+
+ vtkIdList *aPointCells = vtkIdList::New();
+ aPointCells->Allocate(VTK_CELL_SIZE);
+
+ vtkIdType aNbPoints = aCellPoints->GetNumberOfIds();
+ for (vtkIdType i = 0; i < aNbPoints; i++) {
+ aDataSet->GetPointCells(aCellPoints->GetId(i), aPointCells);
+
+ // add cell ids
+ vtkIdType aNbCells = aPointCells->GetNumberOfIds();
+ for (vtkIdType j = 0; j < aNbCells; j++)
+ aNeighbourCells->InsertUniqueId(aPointCells->GetId(j));
+ }
+
+ aPointCells->Delete();
+
+ // get vector data
+ vtkDataArray* anInputVectors = aDataSetAttributes->GetVectors();
+ if (!anInputVectors)
+ return;
+
+ // insert neighbour cells to the special dataset
+ vtkUnstructuredGrid *aCellsToWarp = vtkUnstructuredGrid::New();
+ aCellsToWarp->SetPoints(aDataSet->GetPoints());
+
+ vtkIdType aNbNeighbourCells = aNeighbourCells->GetNumberOfIds();
+
+ vtkDataArray *aVectorsToSet = vtkDataArray::CreateDataArray(anInputVectors->GetDataType());
+ aVectorsToSet->SetNumberOfComponents(3);
+ aVectorsToSet->SetNumberOfTuples(aNbNeighbourCells);
+
+ vtkDataArray *aCellVectors = vtkDataArray::CreateDataArray(anInputVectors->GetDataType());
+ aCellVectors->SetNumberOfComponents(3);
+
+ int aNbComp = anInputVectors->GetNumberOfComponents();
+ std::vector<vtkFloatingPointType> aTuple(aNbComp);
+
+ for (vtkIdType i = 0; i < aNbNeighbourCells; i++) {
+ vtkIdType aVTKCellId = aNeighbourCells->GetId(i);
+ vtkIdType anObjCellId = aParent->GetElemObjID(aVTKCellId);
+
+ vtkCell* aCurCell = aParent->GetElemCell(anObjCellId);
+
+ vtkIdType aNewCellId = aCellsToWarp->InsertNextCell(aCurCell->GetCellType(), aCurCell->GetPointIds());
+
+ // get gauss points corresponding to the current cell
+ vtkIdType aPointVtkId = -1;
+ vtkIdType aLocalPntId = 0;
+ aPointVtkId = aGaussPtsIDMapper->GetVTKID(VISU::TGaussPointID(anObjCellId, aLocalPntId));
+
+ if (aPointVtkId >= 0) {
+ // Compute average vector
+ aCellVectors->Reset();
+ while (aPointVtkId >= 0) {
+ anInputVectors->GetTuple(aPointVtkId, &aTuple[0]);
+
+ if (aNbComp >= 3)
+ aCellVectors->InsertNextTuple3(aTuple[0], aTuple[1], aTuple[2]);
+ else if (aNbComp == 2)
+ aCellVectors->InsertNextTuple3(aTuple[0], aTuple[1], 0);
+ else if (aNbComp == 1)
+ aCellVectors->InsertNextTuple3(aTuple[0], 0, 0);
+
+ aPointVtkId = aGaussPtsIDMapper->GetVTKID(VISU::TGaussPointID(anObjCellId, ++aLocalPntId));
+ }
+
+ double aXCoord = 0, anYCoord = 0, aZCoord = 0;
+
+ vtkIdType aNbVectors = aCellVectors->GetNumberOfTuples();
+
+ for (vtkIdType aVecId = 0; aVecId < aNbVectors; aVecId++) {
+ aXCoord += aCellVectors->GetComponent(aVecId, 0);
+ anYCoord += aCellVectors->GetComponent(aVecId, 1);
+ aZCoord += aCellVectors->GetComponent(aVecId, 2);
+ }
+
+ aXCoord = aXCoord / aNbVectors;
+ anYCoord = anYCoord / aNbVectors;
+ aZCoord = aZCoord / aNbVectors;
+
+ // set vector data for the cell
+ aVectorsToSet->SetTuple3(aNewCellId, aXCoord, anYCoord, aZCoord);
+ }
+ else
+ aVectorsToSet->SetTuple3(aNewCellId, 0, 0, 0);
+ }
+
+ aCellsToWarp->GetCellData()->SetVectors(aVectorsToSet);
+
+ aVectorsToSet->Delete();
+ aCellVectors->Delete();
+ aNeighbourCells->Delete();
+
+ // warp
+ myWarpVector->SetScaleFactor(myGaussPointsPL->GetScale());
+
+ myCellDataToPointData->SetInput(aCellsToWarp);
+ myCellDataToPointData->PassCellDataOn();
+ aCellsToWarp->Delete();
+
+ myWarpVector->SetInput(myCellDataToPointData->GetUnstructuredGridOutput());
+ vtkUnstructuredGrid* aWarpedDataSet = myWarpVector->GetUnstructuredGridOutput();
+ aWarpedDataSet->Update();
+ myCellSource->SetPoints(aWarpedDataSet->GetPoints());
+ }
+ else
+ myCellSource->SetPoints(aDataSet->GetPoints());
+
myCellActor->SetVisibility(anIsVisible && theIsHighlight);
myCellActor->SetRepresentation(VTK_WIREFRAME);
}