Commit 68b107dd authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED POC near completion

parent 2496bf5f
......@@ -740,6 +740,7 @@ vtkSmartPointer<vtkProp> MeshComponent::getDataProp(MeshDataModel::FieldType fie
return prop;
}
// creates the prop but don't show it
vtkSmartPointer<vtkDataArray> array;
if (getPointSet()->GetPointData()->HasArray(arrayName.toStdString().c_str())) {
......@@ -748,22 +749,25 @@ 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();
vtkSmartPointer<vtkHedgeHog> hedgeHog = vtkSmartPointer<vtkHedgeHog>::New();
vtkSmartPointer<vtkDataSetMapper> dataMapper = vtkSmartPointer< vtkDataSetMapper >::New();
vtkSmartPointer<vtkActor> dataActor = vtkSmartPointer< vtkActor >::New();
hedgeHog->SetInputConnection(myGeometry->getDataPort());
hedgeHog->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, array->GetName());
dataMapper->SetInputConnection(hedgeHog->GetOutputPort());
dataActor->SetMapper(dataMapper);
dataActor->GetProperty()->SetColor(0, 1, 0);
dataActor->VisibilityOff();
hedgeHog->SetInputConnection(myGeometry->getDataPort());
hedgeHog->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, array->GetName());
dataMapper->SetInputConnection(hedgeHog->GetOutputPort());
dataActor->SetMapper(dataMapper);
dataActor->GetProperty()->SetColor(0, 1, 0);
dataActor->VisibilityOff();
addProp(dataName, dataActor);
addProp(dataName, dataActor);
return dataActor;
return dataActor;
}
else {
// there is no 3D representation needed, therefore no prop
return NULL;
}
break;
}
......
......@@ -280,6 +280,8 @@ public:
/**
* @brief Get the prop associed to the data.
*
* If the prop does not exist, create it with visibility off.
*
* @param fieldType field type (@see MeshDataModel::FieldType)
* @param name data array name
......
......@@ -167,17 +167,23 @@ QVariant MeshDataModel::data(const QModelIndex& index, int role) const {
vtkSmartPointer<vtkDataSetAttributes> dataSetAttr = vtkDataSetAttributes::SafeDownCast(data);
if (dataSetAttr) {
QString arrayToDisplay = QString("%1_CamiTKDisplayType_%2").arg(dataSetAttr->GetArray(dataNum)->GetName()).arg(meshComponent->getCurrentDisplayTypePolicy());
// TODO use dataSetAttr->HasArray(arrayToDisplay.toUtf8().constData())
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;
}
else {
return Qt::Unchecked;
}
}
// else continue to the case where a prop might be available
case 9: {
// The first time this method is call, the corresponding prop is created with visibility off
vtkSmartPointer<vtkProp> prop = meshComponent->getDataProp(fieldType, data->GetArray(dataNum)->GetName());
if (prop) {
......@@ -188,6 +194,9 @@ QVariant MeshDataModel::data(const QModelIndex& index, int role) const {
return Qt::Unchecked;
}
}
else
return Qt::Unchecked;
}
break;
......@@ -264,63 +273,67 @@ bool MeshDataModel::setData(const QModelIndex& index, const QVariant& value, int
return false;
}
// Some data do not have an additional vtkProp (e.g. scalars are represented directly as point data colors)
if (!prop) {
if (data->GetArray(dataNum)->GetNumberOfComponents() == 1) {
if (value == Qt::Checked) {
vtkSmartPointer<vtkDataSetAttributes> dataSetAttr = vtkDataSetAttributes::SafeDownCast(data);
// if this is a scalar value, set it to active (to display the colors on the cells/points)
meshComponent->setActiveData(fieldType, dataSetAttr->GetArray(dataNum)->GetName());
}
else {
meshComponent->setActiveData(fieldType, NULL);
}
// nothing to if the button is not checked: the unactive scalars are going to be refreshed in data(..) method
// 1D data do not have any prop (scalars are represented directly as point data colors)
if (!prop && data->GetArray(dataNum)->GetNumberOfComponents()==1) {
// Classic 1D data, show/hide it depending on check state
if (value == Qt::Checked) {
vtkSmartPointer<vtkDataSetAttributes> dataSetAttr = vtkDataSetAttributes::SafeDownCast(data);
// if this is a scalar value, set it to active (to display the colors on the cells/points)
meshComponent->setActiveData(fieldType, dataSetAttr->GetArray(dataNum)->GetName());
}
else {
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);
// hide the data by setting no active fieldType data
meshComponent->setActiveData(fieldType, NULL);
}
}
else {
// for 3D data with prop, check if the user wants a 3D representation or a specific 1D display type
if (meshComponent->getCurrentDisplayTypePolicy() != HEDGE_HOG && data->GetArray(dataNum)->GetNumberOfComponents()==3) {
// 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
vtkSmartPointer<vtkDataSetAttributes> dataSetAttr = vtkDataSetAttributes::SafeDownCast(data);
if (dataSetAttr) {
QString arrayToDisplay = QString("%1_CamiTKDisplayType_%2").arg(dataSetAttr->GetArray(dataNum)->GetName()).arg(meshComponent->getCurrentDisplayTypePolicy());
// TODO use dataSetAttr->HasArray(arrayToDisplay.toUtf8().constData())
vtkSmartPointer<vtkDataArray> dataArray = dataSetAttr->GetArray(arrayToDisplay.toUtf8().constData());
// if there is no array with this name, create it
if (!dataArray) {
// TEST with norm. TODO switch using meshComponent->getCurrentDisplayTypePolicy()
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]) );
}
// set it active
meshComponent->setActiveData(fieldType, arrayToDisplay.toUtf8().constData());
// add it to the pointset, but NOT to the mesh component (it will stay hidden)
meshComponent->getPointSet()->GetPointData()->AddArray(demoPointData);
}
}
else {
meshComponent->setActiveData(fieldType, NULL);
// set it active
//meshComponent->setActiveData(fieldType, arrayToDisplay.toUtf8().constData());
meshComponent->getPointSet()->GetPointData()->SetActiveScalars(arrayToDisplay.toUtf8().constData());
}
}
}
}
else {
if (value == Qt::Checked) {
prop->VisibilityOn();
else {
// hide the data by setting no active fieldType data
meshComponent->setActiveData(fieldType, NULL);
}
}
else {
prop->VisibilityOff();
// normal case (3D or 9D): show/hide the prop in 3D depending on check state
if (value == Qt::Checked) {
prop->VisibilityOn();
}
else {
prop->VisibilityOff();
}
}
}
......
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