Commit 889adb90 authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED nearly there.

Just need more redesign to make everything crystal clear, see TODO list
parent 7dbd6154
......@@ -27,10 +27,13 @@
#include "MeshComponent.h"
#include "InteractiveViewer.h"
#include <vtkCellData.h>
#include <vtkPointData.h>
#include <vtkDoubleArray.h>
namespace camitk {
// -------------------- constructor --------------------
......@@ -120,7 +123,7 @@ QVariant MeshDataModel::data(const QModelIndex& index, int role) const {
switch (type) {
case SCALARS: {
vtkSmartPointer<vtkDataArray> currentlySelected = dataSetAttr->GetScalars();
// TODO use MeshComponent::isScalarDataVisible(arrayName)
if (currentlySelected && QString(currentlySelected->GetName()) == arrayName) {
return Qt::Checked;
}
......@@ -134,6 +137,7 @@ QVariant MeshDataModel::data(const QModelIndex& index, int role) const {
auto currentDisplayType = meshComponent->getCurrentDisplayTypePolicy();
// for 3D data status it depends on the current policy
if (currentDisplayType != HEDGE_HOG) {
// TODO use MeshComponent::is3DDataVisible
QString arrayToDisplay = QString("%1%2").arg(arrayName).arg(getDisplayTypeFor3DDataName(currentDisplayType));
if (dataSetAttr->HasArray(arrayToDisplay.toUtf8().constData())) {
vtkSmartPointer<vtkDataArray> dataArrayToDisplay = dataSetAttr->GetArray(arrayToDisplay.toUtf8().constData());
......@@ -240,10 +244,12 @@ bool MeshDataModel::setData(const QModelIndex& index, const QVariant& value, int
case SCALARS:
// Classic 1D data, show/hide the corresponding data depending on check state
if (value == Qt::Checked) {
// TODO move this to MeshComponent::setScalarDataVisible
// if this is a scalar value, set it to active (to display the colors on the cells/points)
meshComponent->setActiveData(fieldType, arrayName.toUtf8().constData());
}
else {
// TODO move this to MeshComponent::setScalarDataVisible
// hide the data by setting no active fieldType data
meshComponent->setActiveData(fieldType, NULL);
}
......@@ -253,17 +259,20 @@ bool MeshDataModel::setData(const QModelIndex& index, const QVariant& value, int
auto currentDisplayType = meshComponent->getCurrentDisplayTypePolicy();
if (meshComponent->getCurrentDisplayTypePolicy() != HEDGE_HOG) {
// for 3D data create and show/hide the corresponding 1D data visualization depending on the current display type policy
if (value == Qt::Checked) {
// complicated name to avoid accidental override of user data
QString nameOfArrayToDisplay = QString("%1%2").arg(arrayName).arg(getDisplayTypeFor3DDataName(currentDisplayType));
// complicated name to avoid accidental override of user data
QString nameOfArrayToDisplay = QString("%1%2").arg(arrayName).arg(getDisplayTypeFor3DDataName(currentDisplayType));
// check if the array already exists
if (!data->HasArray( nameOfArrayToDisplay.toUtf8().constData())) {
// for 3D data create and show/hide the corresponding 1D data visualization depending on the current display type policy
if (value == Qt::Checked) {
double range[2]; // TODO move this with the rest to MeshComponent
// TODO use MeshComponent::is3DDataVisible(arrayName,DisplayTypeFor3DData):bool method to determine this
// check if the array already exists and if it is currently displayed
if (!data->HasArray(nameOfArrayToDisplay.toUtf8().constData())) {
// TODO move this to MeshComponent::createExtraArray
// if it does not exists, created
vtkSmartPointer<vtkDoubleArray> dataArrayToDisplay = vtkSmartPointer<vtkDoubleArray>::New();
dataArrayToDisplay->SetName( nameOfArrayToDisplay.toUtf8().constData());
dataArrayToDisplay->SetName( nameOfArrayToDisplay.toUtf8().constData() );
int numberOfPoints = meshComponent->getPointSet()->GetNumberOfPoints();
dataArrayToDisplay->SetNumberOfValues( numberOfPoints );
......@@ -278,15 +287,33 @@ bool MeshDataModel::setData(const QModelIndex& index, const QVariant& value, int
// add it to the pointset, but NOT to the mesh component (it will stay hidden)
//meshComponent->getPointSet()->GetPointData()->AddArray(demoPointData);
data->AddArray( dataArrayToDisplay );
// TODO move this line with the rest to MeshComponent
dataArrayToDisplay->GetRange(range); // range of the 1st component = unique component
}
// set it as active
//meshComponent->setActiveData(fieldType, arrayToDisplay.toUtf8().constData());
// TODO move all these lines to MeshComponent (and remove the #include "InteractiveViewer.h" above
// → create method set3DDataVisible(arrayName,DisplayTypeFor3DData,bool):void
meshComponent->getPointSet()->GetPointData()->SetActiveScalars( nameOfArrayToDisplay.toUtf8().constData());
//data->SetActiveScalars( nameOfArrayToDisplay.toUtf8().constData());
// update mapper range
meshComponent->setMapperScalarRange(range[0], range[1]);
//-- show the color scale in 3D
InteractiveViewer::get3DViewer()->setColorScale(true);
InteractiveViewer::get3DViewer()->setColorScaleTitle(nameOfArrayToDisplay.toUtf8().constData());
InteractiveViewer::get3DViewer()->setColorScaleMinMax(range[0], range[1]);
//data->SetActiveScalars( nameOfArrayToDisplay);
}
else {
// TODO move this to MeshComponent::set3DDataVisible to hide the array
if (data->HasArray(nameOfArrayToDisplay.toUtf8().constData())) {
data->RemoveArray(nameOfArrayToDisplay.toUtf8().constData());
}
// hide the data by setting no active fieldType data
meshComponent->setActiveData(fieldType, NULL);
meshComponent->getPointSet()->GetPointData()->SetActiveScalars(NULL);
// remove all color bar
InteractiveViewer::get3DViewer()->setColorScaleTitle("");
InteractiveViewer::get3DViewer()->setColorScale(false);
}
}
else {
......@@ -328,6 +355,26 @@ bool MeshDataModel::setData(const QModelIndex& index, const QVariant& value, int
}
}
// TODO in MeshComponent:
// 1. check if the helpers method written now are can be used to simplify MeshComponent code
// 2. MeshDataModel should be not be able to explore the point/cell/field data of MeshComponent, which should be the sole
// manager of that type of data.
// → Therefore, add the following method to MeshComponent and used them here:
//
// - getTypeOfArray
//
// - getDataProp that should only returns the prop if it already exists (and be kept only for compatibility reason / erase as a BDFL decision)
// - createDataProp to create a given prop
// - setDataPropVisibility
// - getDataPropVisibility
//
// - set3DDataVisibility(arrayName,DisplayTypeFor3DData,bool):void
// - get3DDataVisibility(arrayName,DisplayTypeFor3DData):bool (arrayName is the name of a 3D array), check if it exists and is currently displayed (it can exists but not be visible at the moment)
// - create3DData(arrayName,DisplayTypeFor3DData):void
//
// - setScalarDataVisible(arrayName,bool):void
// - getScalarDataVisibility(arrayName)
// -------------------- flags --------------------
Qt::ItemFlags MeshDataModel::flags(const QModelIndex& index) const {
if (index.column() == 0) {
......
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