Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CamiTK
CamiTK Community Edition
Commits
7e71b3c9
Commit
7e71b3c9
authored
Nov 10, 2017
by
Emmanuel Promayon
Browse files
FIXED data model updated automatically + cell data averaged + nicer example file
Thanks go to Antoine for the nicer example.
parent
ea781239
Changes
4
Hide whitespace changes
Inline
Side-by-side
sdk/components/vtkmesh/testdata/unstructured_binary_with_celldata.vtk
0 → 100644
View file @
7e71b3c9
File added
sdk/libraries/core/component/mesh/MeshComponent.cpp
View file @
7e71b3c9
...
...
@@ -96,8 +96,11 @@ MeshComponent::~MeshComponent() {
}
void
MeshComponent
::
init
()
{
// no last picked point or cell, no selection
pickedCellId
=
-
1
;
pickedPointId
=
-
1
;
currentSelection
=
vtkSmartPointer
<
vtkSelection
>::
New
();
// selection widget
selectionWidget
=
new
QWidget
();
...
...
@@ -126,7 +129,10 @@ void MeshComponent::init() {
selectionView
->
setModel
(
selectionModel
);
selectionView
->
setSelectionMode
(
QAbstractItemView
::
ExtendedSelection
);
selectionView
->
setEditTriggers
(
QAbstractItemView
::
DoubleClicked
);
// if the selection changes, the meshComponent needs to be notified
connect
(
selectionView
->
selectionModel
(),
SIGNAL
(
selectionChanged
(
const
QItemSelection
&
,
const
QItemSelection
&
)),
this
,
SLOT
(
changeSelectedSelection
(
const
QItemSelection
&
,
const
QItemSelection
&
)));
insertionPolicyBox
=
new
QComboBox
(
selectionView
);
insertionPolicyBox
->
setStatusTip
(
tr
(
"Insertion policy"
));
insertionPolicyBox
->
setWhatsThis
(
tr
(
"Insertion policy"
));
...
...
@@ -159,6 +165,7 @@ void MeshComponent::init() {
inspectData
=
new
QAction
(
QPixmap
(
":/settings"
),
tr
(
"Inspect data"
),
this
);
inspectData
->
setStatusTip
(
tr
(
"Inspect data"
));
inspectData
->
setWhatsThis
(
tr
(
"Inspect data"
));
inspectData
->
setEnabled
(
false
);
// TODO implement a data inspector widget
// data model
dataModel
=
new
MeshDataModel
(
this
);
...
...
@@ -178,6 +185,8 @@ void MeshComponent::init() {
displayTypePolicyBox
->
addItem
(
"2nd Component"
,
SECOND_COMPONENT
);
displayTypePolicyBox
->
addItem
(
"3nd Component"
,
THIRD_COMPONENT
);
connect
(
displayTypePolicyBox
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
displayTypePolicyChanged
(
int
)));
// build the data widget
QVBoxLayout
*
dataBox
=
new
QVBoxLayout
(
dataWidget
);
QToolBar
*
dataToolBar
=
new
QToolBar
(
dataWidget
);
...
...
@@ -188,10 +197,7 @@ void MeshComponent::init() {
dataBox
->
addWidget
(
dataToolBar
);
dataWidget
->
setLayout
(
dataBox
);
connect
(
selectionView
->
selectionModel
(),
SIGNAL
(
selectionChanged
(
const
QItemSelection
&
,
const
QItemSelection
&
)),
this
,
SLOT
(
changeSelectedSelection
(
const
QItemSelection
&
,
const
QItemSelection
&
)));
// selection
currentSelection
=
vtkSmartPointer
<
vtkSelection
>::
New
();
}
// -------------------- initRepresentation --------------------
...
...
@@ -517,6 +523,11 @@ void MeshComponent::changeSelectedSelection(const QItemSelection& selected, cons
}
// -------------------- displayTypePolicyChanged --------------------
void
MeshComponent
::
displayTypePolicyChanged
(
int
)
{
dataModel
->
refresh
();
}
// -------------------- removeSelectedSelection --------------------
void
MeshComponent
::
removeSelectedSelections
()
{
// TODO : handle multiple selection
...
...
@@ -593,27 +604,68 @@ void MeshComponent::createDataRepresentation(FieldType field, const QString& nam
int
numberOfPoints
=
getPointSet
()
->
GetNumberOfPoints
();
dataArrayToDisplay
->
SetNumberOfValues
(
numberOfPoints
);
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
;
switch
(
field
)
{
case
POINTS
:
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
:
{
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
]);
}
}
break
;
default:
break
;
}
// add it to the pointset, but NOT to the mesh component (it will stay hidden)
getPointSet
()
->
GetPointData
()
->
AddArray
(
dataArrayToDisplay
);
// insert it in the specific map
...
...
@@ -823,6 +875,7 @@ void MeshComponent::setDataRepresentationVisibility(FieldType fieldType, const Q
// update the data set state
dataSet
->
SetActiveScalars
(
specificName
.
toStdString
().
c_str
());
break
;
// specific vector representation is finished here
}
else
{
// just update the data set state for now (see case TENSORS for the rest)
...
...
@@ -841,7 +894,7 @@ void MeshComponent::setDataRepresentationVisibility(FieldType fieldType, const Q
createDataRepresentation
(
fieldType
,
name
);
}
// update visibility status
// update visibility status
dataRepresentationVisibility
.
insert
(
dataArray
,
true
);
// get the prop and set prop->VisibilityOn();
...
...
@@ -959,7 +1012,7 @@ const QString MeshComponent::getDataPropName(FieldType fieldType, const QString&
// -------------------- getCurrentDisplayTypePolicy --------------------
MeshComponent
::
RepresentationOf3DData
MeshComponent
::
getCurrentDisplayTypePolicy
()
const
{
return
(
RepresentationOf3DData
)
displayTypePolicyBox
->
itemData
(
displayTypePolicyBox
->
currentIndex
()
).
toInt
();
return
(
RepresentationOf3DData
)
displayTypePolicyBox
->
currentData
(
).
toInt
();
}
// -------------------- getDataModel --------------------
...
...
sdk/libraries/core/component/mesh/MeshComponent.h
View file @
7e71b3c9
...
...
@@ -411,6 +411,9 @@ protected slots:
/// remove the selected selection
void
removeSelectedData
();
/// called when the datatype of 3D vecors is modified
void
displayTypePolicyChanged
(
int
);
private:
...
...
sdk/libraries/core/component/mesh/MeshDataModel.cpp
View file @
7e71b3c9
...
...
@@ -60,6 +60,10 @@ int MeshDataModel::columnCount(const QModelIndex& parent) const {
// -------------------- getRowInfo --------------------
void
MeshDataModel
::
getRowInfo
(
const
int
row
,
int
*
dataIndex
,
MeshComponent
::
FieldType
*
field
,
MeshComponent
::
DataType
*
type
,
QString
&
name
)
const
{
// as getNumberOfDataArray(..) will only return the "normal" data (not the specific 3D vectors representation)
// this should be OK.
// caveat: if the user has added specific 3D vector representation and then add another point data, then
// the count will be increased of one, and the first specific 3D vector representation will show.
int
nbPointData
=
meshComponent
->
getNumberOfDataArray
(
MeshComponent
::
POINTS
);
int
nbCellData
=
meshComponent
->
getNumberOfDataArray
(
MeshComponent
::
CELLS
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment