Commit c5bd334d authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED cell data should color all the cell not be interpolated

The previous behaviour was a special case, but not really logical.
parent 7fce3327
......@@ -100,7 +100,7 @@ void MeshComponent::init() {
pickedCellId = -1;
pickedPointId = -1;
currentSelection = vtkSmartPointer<vtkSelection>::New();
numberOfCellDataSpecificRepresentation = 0;
// selection widget
selectionWidget = new QWidget();
......@@ -546,11 +546,12 @@ int MeshComponent::getNumberOfDataArray(int fieldFlag) {
else {
int count = 0;
if (fieldFlag & POINTS) {
// remove specific representation
count += + getPointSet()->GetPointData()->GetNumberOfArrays() - specific3DDataRepresentation.size();
// remove the number of specific representation inserted in point data
count += + getPointSet()->GetPointData()->GetNumberOfArrays() - specific3DDataRepresentation.size() + numberOfCellDataSpecificRepresentation;
}
if (fieldFlag & CELLS) {
count += getPointSet()->GetCellData()->GetNumberOfArrays();
// remove the number of specific representation inserted in cell data
count += getPointSet()->GetCellData()->GetNumberOfArrays() - numberOfCellDataSpecificRepresentation;
}
if (fieldFlag & MESH) {
count += getPointSet()->GetFieldData()->GetNumberOfArrays();
......@@ -602,78 +603,49 @@ void MeshComponent::createDataRepresentation(FieldType field, const QString& nam
QString specificName(name + getSpecificRepresentationName(representation));
vtkSmartPointer<vtkDoubleArray> dataArrayToDisplay = vtkSmartPointer<vtkDoubleArray>::New();
dataArrayToDisplay->SetName(specificName.toUtf8().constData());
int numberOfValues;
int numberOfPoints = getPointSet()->GetNumberOfPoints();
dataArrayToDisplay->SetNumberOfValues(numberOfPoints);
switch (field) {
case POINTS:
// use the representation flag to tranform the point's 3D vector to a scalar
for (vtkIdType i = 0; i < numberOfPoints; ++i) {
double val[3];
dataArray->GetTuple(i, val);
switch (representation) {
case FIRST_COMPONENT:
dataArrayToDisplay->SetValue(i, val[0]);
break;
case SECOND_COMPONENT:
dataArrayToDisplay->SetValue(i, val[1]);
break;
case THIRD_COMPONENT:
dataArrayToDisplay->SetValue(i, val[2]);
break;
case NORM:
default:
// compute 3D norm
dataArrayToDisplay->SetValue(i, sqrt(val[0]*val[0] + val[1]*val[1] + val[2]*val[2]));
break;
}
}
break;
case CELLS: {
// the cell's 3D vector have to be averaged on each point's composing the cell
// to transfert the cell's 3D vector to a scalar on each point
int numberOfCells = getPointSet()->GetNumberOfCells();
double* cellCount = new double [numberOfPoints] {};
double* pointData = new double [numberOfPoints] {};
for (vtkIdType i = 0; i < numberOfCells; ++i) {
double val[3];
dataArray->GetTuple(i, val);
for (vtkIdType j = 0; j < getPointSet()->GetCell(i)->GetNumberOfPoints(); ++j) {
vtkIdType pointId = getPointSet()->GetCell(i)->GetPointId(j);
cellCount[pointId]++;
switch (representation) {
case FIRST_COMPONENT:
pointData[pointId] += val[0];
break;
case SECOND_COMPONENT:
pointData[pointId] += val[1];
break;
case THIRD_COMPONENT:
pointData[pointId] += val[2];
break;
case NORM:
default:
// compute 3D norm
pointData[pointId] += sqrt(val[0] * val[0] + val[1] * val[1] + val[2] * val[2]) ;
break;
}
}
}
// now average
for (vtkIdType i = 0; i < numberOfPoints; ++i) {
dataArrayToDisplay->SetValue(i, pointData[i] / cellCount[i]);
}
if (field == POINTS) {
numberOfValues = getPointSet()->GetNumberOfPoints();
}
else {
// this is cell field
numberOfValues = getPointSet()->GetNumberOfCells();
}
// fill the data array
dataArrayToDisplay->SetNumberOfValues(numberOfValues);
// use the representation flag to tranform the point's 3D vector to a scalar
for (vtkIdType i = 0; i < numberOfValues; ++i) {
double val[3];
dataArray->GetTuple(i, val);
switch (representation) {
case FIRST_COMPONENT:
dataArrayToDisplay->SetValue(i, val[0]);
break;
case SECOND_COMPONENT:
dataArrayToDisplay->SetValue(i, val[1]);
break;
case THIRD_COMPONENT:
dataArrayToDisplay->SetValue(i, val[2]);
break;
case NORM:
default:
// compute 3D norm
dataArrayToDisplay->SetValue(i, sqrt(val[0]*val[0] + val[1]*val[1] + val[2]*val[2]));
break;
}
break;
default:
break;
}
// add it to the pointset, but NOT to the mesh component (it will stay hidden)
getPointSet()->GetPointData()->AddArray(dataArrayToDisplay);
// add it to the pointset field data directly, but NOT to the mesh component (it will stay hidden)
getFieldData(field)->AddArray(dataArrayToDisplay);
// insert it in the specific map
specific3DDataRepresentation.insert(specificName, dataArrayToDisplay);
// update the cell specific representation counter so that getNumberOfDataArray answer is up-to-date
if (field == CELLS) {
numberOfCellDataSpecificRepresentation++;
}
}
break;
......@@ -875,7 +847,8 @@ void MeshComponent::setDataRepresentationVisibility(FieldType fieldType, const Q
// update the data set state, in this case the point data active scalars
// as the specific data are stored in the point data
getPointSet()->GetPointData()->SetActiveScalars(specificName.toStdString().c_str());
//getPointSet()->GetPointData()->SetActiveScalars(specificName.toStdString().c_str());
dataSet->SetActiveScalars(specificName.toStdString().c_str());
// update visibility status
vtkSmartPointer<vtkDataArray> specificArray = specific3DDataRepresentation.value(specificName);
......
......@@ -476,9 +476,14 @@ private:
/// combo box to select how to display data when then have 3 components
QComboBox* displayTypePolicyBox;
/// map of specific 3D Data representations
/** map of specific 3D Data representations.
* The value of key is the specific array name that concatenate the 3D data name and the specific representation name.
*/
QMap<QString, vtkSmartPointer<vtkDataArray> > specific3DDataRepresentation;
/// number of specific 3D representation for cell data
unsigned int numberOfCellDataSpecificRepresentation;
/// map of visibility status of data
QMap<vtkSmartPointer<vtkDataArray>, bool> dataRepresentationVisibility;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment