Commit 2496bf5f authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

initial commit with hard-coded non-conclusive test

parent dfd14931
......@@ -125,13 +125,13 @@ void MeshComponent::init() {
selectionView->setSelectionMode(QAbstractItemView::ExtendedSelection);
selectionView->setEditTriggers(QAbstractItemView::DoubleClicked);
policyBox = new QComboBox(selectionView);
policyBox->setStatusTip(tr("Insertion policy"));
policyBox->setWhatsThis(tr("Insertion policy"));
policyBox->addItem("Replace", MeshSelectionModel::REPLACE);
policyBox->addItem("Merge", MeshSelectionModel::MERGE);
policyBox->addItem("Substract", MeshSelectionModel::SUBSTRACT);
policyBox->addItem("Discard", MeshSelectionModel::DISCARD);
insertionPolicyBox = new QComboBox(selectionView);
insertionPolicyBox->setStatusTip(tr("Insertion policy"));
insertionPolicyBox->setWhatsThis(tr("Insertion policy"));
insertionPolicyBox->addItem("Replace", MeshSelectionModel::REPLACE);
insertionPolicyBox->addItem("Merge", MeshSelectionModel::MERGE);
insertionPolicyBox->addItem("Substract", MeshSelectionModel::SUBSTRACT);
insertionPolicyBox->addItem("Discard", MeshSelectionModel::DISCARD);
// build the selection widget
QVBoxLayout* hbox = new QVBoxLayout(selectionWidget);
......@@ -139,7 +139,7 @@ void MeshComponent::init() {
selectionToolBar->addAction(removeSelections);
selectionToolBar->addAction(mergeSelection);
selectionToolBar->addAction(inspectSelection);
selectionToolBar->addWidget(policyBox);
selectionToolBar->addWidget( insertionPolicyBox );
hbox->addWidget(selectionView);
hbox->addWidget(selectionToolBar);
selectionWidget->setLayout(hbox);
......@@ -167,11 +167,21 @@ void MeshComponent::init() {
dataView->setModel(dataModel);
dataView->setSelectionMode(QAbstractItemView::ExtendedSelection);
displayTypePolicyBox = new QComboBox(dataView);
displayTypePolicyBox->setStatusTip(tr("Display type policy for 3D data"));
displayTypePolicyBox->setWhatsThis(tr("Display type policy for 3D data"));
displayTypePolicyBox->addItem("3D Vector", MeshDataModel::HEDGE_HOG);
displayTypePolicyBox->addItem("Norm", MeshDataModel::NORM);
displayTypePolicyBox->addItem("1st Component", MeshDataModel::FIRST_COMPONENT);
displayTypePolicyBox->addItem("2nd Component", MeshDataModel::SECOND_COMPONENT);
displayTypePolicyBox->addItem("3nd Component", MeshDataModel::THIRD_COMPONENT);
// build the data widget
QVBoxLayout* dataBox = new QVBoxLayout(dataWidget);
QToolBar* dataToolBar = new QToolBar(dataWidget);
dataToolBar->addAction(removeData);
dataToolBar->addAction(inspectData);
dataToolBar->addWidget(displayTypePolicyBox);
dataBox->addWidget(dataView);
dataBox->addWidget(dataToolBar);
dataWidget->setLayout(dataBox);
......@@ -460,7 +470,7 @@ int MeshComponent::addToSelectedSelection(int fieldType, int contentType, vtkSma
// TODO : for now, we don't care about the policy parameter and use the one of the combo box
// but in the future, the policy should be selected by pressing modifiers keys
policy = (MeshSelectionModel::InsertionPolicy) policyBox->itemData(policyBox->currentIndex()).toInt();
policy = (MeshSelectionModel::InsertionPolicy) insertionPolicyBox->itemData( insertionPolicyBox->currentIndex()).toInt();
// check if the current selection is selected (maybe it is not necessary ...)
if (selectionView->selectionModel()->isRowSelected(index, QModelIndex())) {
......@@ -737,6 +747,9 @@ vtkSmartPointer<vtkProp> MeshComponent::getDataProp(MeshDataModel::FieldType fie
switch (array->GetNumberOfComponents()) {
case 3 : {
// TODO check all the cases
return NULL;
if (getCurrentDisplayTypePolicy()==MeshDataModel::HEDGE_HOG) {
vtkSmartPointer<vtkHedgeHog> hedgeHog = vtkSmartPointer<vtkHedgeHog>::New();
vtkSmartPointer<vtkDataSetMapper> dataMapper = vtkSmartPointer< vtkDataSetMapper >::New();
vtkSmartPointer<vtkActor> dataActor = vtkSmartPointer< vtkActor >::New();
......@@ -751,9 +764,10 @@ vtkSmartPointer<vtkProp> MeshComponent::getDataProp(MeshDataModel::FieldType fie
addProp(dataName, dataActor);
return dataActor;
}
break;
}
case 9 : {
vtkSmartPointer<vtkTensorGlyph> tensorGlyph = vtkSmartPointer<vtkTensorGlyph>::New();
vtkSmartPointer<vtkDataSetMapper> dataMapper = vtkSmartPointer< vtkDataSetMapper >::New();
......@@ -847,6 +861,15 @@ vtkSmartPointer<vtkProp> MeshComponent::getDataProp(MeshDataModel::FieldType fie
return NULL;
}
// -------------------- getCurrentDisplayTypePolicy --------------------
MeshDataModel::DisplayTypeFor3DData MeshComponent::getCurrentDisplayTypePolicy() const {
return (MeshDataModel::DisplayTypeFor3DData) displayTypePolicyBox->itemData(displayTypePolicyBox->currentIndex()).toInt();
}
// -------------------- getDataModel --------------------
MeshDataModel* MeshComponent::getDataModel() {
return dataModel;
}
// -------------------- removeSelectedData --------------------
void MeshComponent::removeSelectedData() {
......
......@@ -151,7 +151,7 @@ public:
/**
* @brief Get a selection from its name.
*
* @TODO mettre en const pour pas de modeif externe
* @TODO This method should return a const ref, so that external code cannot modify it
*
* @param name name of the selection
* @return the selection node
......@@ -161,7 +161,7 @@ public:
/**
* @brief Get a selection from its index in the list.
*
* @TODO mettre en const pour pas de modeif externe
* @TODO This method should return a const ref, so that external code cannot modify it
*
* @param index index of the selection
* @return the selection node
......@@ -248,7 +248,7 @@ public:
* @brief Add a data array.
*
* @param fieldType field type (@see MeshDataModel::FieldType)
* @param arrayName array name
* @param name name given to the array to add
* @param data data array
*/
void addDataArray ( MeshDataModel::FieldType fieldType, const QString& name, vtkSmartPointer<vtkDataArray> data );
......@@ -258,7 +258,7 @@ public:
* @brief Remove a data array.
*
* @param fieldType field type (@see MeshDataModel::FieldType)
* @param arrayName array name
* @param name name of the array to remove
*/
void removeDataArray ( MeshDataModel::FieldType fieldType, const QString& name );
......@@ -301,10 +301,12 @@ public:
*/
void setActiveData(MeshDataModel::FieldType fieldType, const char* name);
/// Return the current value of the display type selected by the user
MeshDataModel::DisplayTypeFor3DData getCurrentDisplayTypePolicy() const;
/// get the current data view model (model as the M in Qt MVC design pattern)
MeshDataModel* getDataModel() {
return dataModel;
}
MeshDataModel* getDataModel();
/**
* @}
*/
......@@ -381,7 +383,7 @@ private:
QAction* inspectSelection;
/// combo box to select the selection insertion policy
QComboBox* policyBox;
QComboBox* insertionPolicyBox;
/// data model (model as the M in Qt MVC design pattern)
MeshDataModel* dataModel;
......@@ -391,6 +393,9 @@ private:
/// selection widget
QWidget* dataWidget;
/// combo box to select how to display data when then have 3 components
QComboBox* displayTypePolicyBox;
/// action to remove data
QAction* removeData;
......
......@@ -29,6 +29,7 @@
#include <vtkCellData.h>
#include <vtkPointData.h>
#include <vtkDoubleArray.h>
namespace camitk {
......@@ -161,6 +162,21 @@ QVariant MeshDataModel::data(const QModelIndex& index, int role) const {
break;
case 3:
// for 3D data status it depends on the current policy
if (meshComponent->getCurrentDisplayTypePolicy() != HEDGE_HOG) {
vtkSmartPointer<vtkDataSetAttributes> dataSetAttr = vtkDataSetAttributes::SafeDownCast(data);
if (dataSetAttr) {
QString arrayToDisplay = QString("%1_CamiTKDisplayType_%2").arg(dataSetAttr->GetArray(dataNum)->GetName()).arg(meshComponent->getCurrentDisplayTypePolicy());
vtkSmartPointer<vtkDataArray> dataArray = dataSetAttr->GetArray(arrayToDisplay.toUtf8().constData());
// if there is an array with this name, this means it is currently displayed
if (dataArray) {
return Qt::Checked;
}
}
else {
return Qt::Unchecked;
}
}
case 9: {
vtkSmartPointer<vtkProp> prop = meshComponent->getDataProp(fieldType, data->GetArray(dataNum)->GetName());
......@@ -262,8 +278,41 @@ bool MeshDataModel::setData(const QModelIndex& index, const QVariant& value, int
// nothing to if the button is not checked: the unactive scalars are going to be refreshed in data(..) method
}
else {
// not managed
return false;
if (data->GetArray(dataNum)->GetNumberOfComponents() == 3) {
//"CamiTKDisplayType_%1"
if (value == Qt::Checked) {
// complicated name to avoid accidental override of user data
vtkSmartPointer<vtkDataSetAttributes> dataSetAttr = vtkDataSetAttributes::SafeDownCast(data);
if (dataSetAttr) {
QString arrayToDisplay = QString("%1_CamiTKDisplayType_%2").arg(dataSetAttr->GetArray(dataNum)->GetName()).arg(meshComponent->getCurrentDisplayTypePolicy());
vtkSmartPointer<vtkDataArray> dataArray = dataSetAttr->GetArray(arrayToDisplay.toUtf8().constData());
// if there is no array with this name, create it
if (!dataArray) {
// TEST with norm
vtkSmartPointer<vtkDataArray> originalArray = dataSetAttr->GetArray(dataNum);
vtkSmartPointer<vtkDoubleArray> demoPointData = vtkSmartPointer<vtkDoubleArray>::New();
demoPointData->SetName(arrayToDisplay.toUtf8().constData());
int numberOfPoints = meshComponent->getPointSet()->GetNumberOfPoints();
demoPointData->SetNumberOfValues( numberOfPoints );
for ( vtkIdType i = 0; i < numberOfPoints; ++i ) {
double val[3];
originalArray->GetTuple(i, val);
demoPointData->SetValue( i, sqrt(val[0]*val[0]+val[1]*val[1]+val[2]*val[2]) );
}
// add it to the pointset, but NOT to the mesh component (it will stay hidden)
meshComponent->getPointSet()->GetPointData()->AddArray(demoPointData);
}
// set it active
meshComponent->setActiveData(fieldType, arrayToDisplay.toUtf8().constData());
}
}
else {
meshComponent->setActiveData(fieldType, NULL);
}
}
}
}
else {
......
......@@ -62,7 +62,17 @@ public :
TENSORS = 4, ///< 9D (3x3 matrix)
OTHERS = 8 ///< other dimensions (warning: nothing special are managed by this class, no specific interaction)
};
/// @enum DisplayTypeFor3DData 3D data can be represented by 1 value in different ways
enum DisplayTypeFor3DData {
HEDGE_HOG, ///< 3D data are represented as 3D vector
NORM, ///< 3D data are represented in 1D using the norm of the three components
FIRST_COMPONENT, ///< Use only the value of the first component
SECOND_COMPONENT, ///< Use only the value of the second component
THIRD_COMPONENT ///< Use only the value of the third component
//@TODO COLOR, ///< 3D data are represented as a specific color @TODO need to build a specific color map LUT containing as many colors as there is point/cell
};
/**
* @brief Constructor
*/
......
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