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

Merge branch 'feature/#192' into develop

parents 69f343b9 7ddab1a1
......@@ -72,13 +72,13 @@ void Arrows::update() {
monitorDataArray->SetTuple(pmlComp->getPointId(a), value);
}
pmlComp->addDataArray(camitk::MeshDataModel::POINTS, QString(monitor->getTypeName().c_str()), monitorDataArray);
pmlComp->addDataArray(camitk::MeshComponent::POINTS, QString(monitor->getTypeName().c_str()), monitorDataArray);
}
// ---------------------- hide ----------------------------
void Arrows::hide() {
// remove the current colors
manager->getPMLComponent()->setActiveData(camitk::MeshDataModel::POINTS, NULL);
manager->getPMLComponent()->setDataRepresentationOff();
}
......
......@@ -64,13 +64,13 @@ void Colors::update() {
monitorDataArray->SetValue(pmlComp->getPointId(a), monitor->getValue(i));
}
pmlComp->addDataArray(camitk::MeshDataModel::POINTS, QString(monitor->getTypeName().c_str()), monitorDataArray);
pmlComp->addDataArray(camitk::MeshComponent::POINTS, QString(monitor->getTypeName().c_str()), monitorDataArray);
}
// ---------------------- hide ----------------------------
void Colors::hide() {
// remove the current colors
manager->getPMLComponent()->setActiveData(camitk::MeshDataModel::POINTS, NULL);
manager->getPMLComponent()->setDataRepresentationOff();
}
......@@ -51,32 +51,15 @@ VtkMeshComponent::VtkMeshComponent (const QString& fileName) throw(AbortExcepti
// build the vtk data structure from the file
vtkSmartPointer<vtkPointSet> data = VtkMeshUtil::buildVtkPointSet(myFileName.toStdString().c_str(), whatIsIt);
std::cout << data->GetPointData()->GetNumberOfArrays() << " arrays in pointdata" << std::endl;
// instanciate the Geometry
initRepresentation(data);
// initialize point data value (for demo or display)
initPointData();
}
// -------------------- destructor --------------------
VtkMeshComponent::~VtkMeshComponent() {
// no active data by default
setActiveData(MeshDataModel::POINTS,NULL);
}
// -------------------- initPointData --------------------
void VtkMeshComponent::initPointData() {
//-- add loaded data arrays
for(vtkIdType i = 0; i < myGeometry->getPointSet()->GetPointData()->GetNumberOfArrays(); i++) {
addPointData(myGeometry->getPointSet()->GetPointData()->GetArrayName(i) , myGeometry->getPointSet()->GetPointData()->GetArray(i));
}
for(vtkIdType i = 0; i < myGeometry->getPointSet()->GetCellData()->GetNumberOfArrays(); i++) {
addCellData(myGeometry->getPointSet()->GetCellData()->GetArrayName(i) , myGeometry->getPointSet()->GetCellData()->GetArray(i));
}
//-- no active data by default
setActiveData(MeshDataModel::POINTS,NULL);
setActiveData(MeshDataModel::CELLS,NULL);
setDataRepresentationOff();
}
//------------------------ getPixmap ---------------------
......
......@@ -72,9 +72,6 @@ private:
/// the vtk logo
static QPixmap* myPixmap;
/// initialize the point data array
void initPointData();
// initialize the dynamic properties
virtual void initDynamicProperties();
......
......@@ -71,40 +71,59 @@ vtkSmartPointer<vtkPointSet> VtkMeshUtil::buildVtkPointSet(std::string vtkFileNa
whatIsIt = VtkMeshUtil::typeOf(vtkFileName);
}
if (whatIsIt == VtkMeshUtil::UNKNOWN) {
return nullptr;
}
// create the Geometry depending on the type
vtkSmartPointer<vtkDataReader> vtkPointSetReader;
switch (whatIsIt) {
case VtkMeshUtil::UNSTRUCTURED_GRID: {
vtkSmartPointer<vtkUnstructuredGridReader>uGridReader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
uGridReader->SetFileName(vtkFileName.c_str());
uGridReader->Update();
case VtkMeshUtil::UNSTRUCTURED_GRID:
vtkPointSetReader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
break;
return uGridReader->GetOutput();
case VtkMeshUtil::STRUCTURED_GRID:
vtkPointSetReader = vtkSmartPointer<vtkStructuredGridReader>::New();
break;
}
case VtkMeshUtil::STRUCTURED_GRID: {
vtkSmartPointer<vtkStructuredGridReader>sGridReader = vtkSmartPointer<vtkStructuredGridReader>::New();
sGridReader->SetFileName(vtkFileName.c_str());
sGridReader->Update();
case VtkMeshUtil::POLY_DATA:
vtkPointSetReader = vtkSmartPointer<vtkPolyDataReader>::New();
break;
return sGridReader->GetOutput();
default:
break;
}
case VtkMeshUtil::POLY_DATA: {
vtkSmartPointer<vtkPolyDataReader>polyDataReader = vtkSmartPointer<vtkPolyDataReader>::New();
polyDataReader->SetFileName(vtkFileName.c_str());
polyDataReader->Update();
}
return polyDataReader->GetOutput();
vtkPointSetReader->SetFileName(vtkFileName.c_str());
// read absolutely everything!
vtkPointSetReader->ReadAllFieldsOn();
vtkPointSetReader->ReadAllScalarsOn();
vtkPointSetReader->ReadAllColorScalarsOn();
vtkPointSetReader->ReadAllNormalsOn();
vtkPointSetReader->ReadAllTCoordsOn();
vtkPointSetReader->ReadAllTensorsOn();
vtkPointSetReader->ReadAllVectorsOn();
vtkPointSetReader->Update();
switch (whatIsIt) {
case VtkMeshUtil::UNSTRUCTURED_GRID:
return vtkUnstructuredGridReader::SafeDownCast(vtkPointSetReader)->GetOutput();
break;
}
case VtkMeshUtil::UNKNOWN: {
return NULL;
case VtkMeshUtil::STRUCTURED_GRID:
return vtkStructuredGridReader::SafeDownCast(vtkPointSetReader)->GetOutput();
break;
case VtkMeshUtil::POLY_DATA:
return vtkPolyDataReader::SafeDownCast(vtkPointSetReader)->GetOutput();
break;
}
}
return NULL;
default:
return nullptr;
break;
}
}
// -------------------- saveGeometryToFile --------------------
......@@ -243,12 +262,14 @@ VtkMeshUtil::VtkPointSetType VtkMeshUtil::typeOf(vtkSmartPointer<vtkPointSet> aP
if (aPointSet->IsA("vtkPolyData")) {
whatIsIt = VtkMeshUtil::POLY_DATA;
}
else if (aPointSet->IsA("vtkUnstructuredGrid")) {
whatIsIt = VtkMeshUtil::UNSTRUCTURED_GRID;
}
else if (aPointSet->IsA("vtkStructuredGrid")) {
whatIsIt = VtkMeshUtil::STRUCTURED_GRID;
}
else
if (aPointSet->IsA("vtkUnstructuredGrid")) {
whatIsIt = VtkMeshUtil::UNSTRUCTURED_GRID;
}
else
if (aPointSet->IsA("vtkStructuredGrid")) {
whatIsIt = VtkMeshUtil::STRUCTURED_GRID;
}
return whatIsIt;
}
......
# vtk DataFile Version 3.0
vtk output
color data (not implemented yet!)
ASCII
DATASET POLYDATA
POINTS 25 float
......
# vtk DataFile Version 1.0
Cube example
ASCII
DATASET POLYDATA
POINTS 8 float
0.0 0.0 0.0
1.0 0.0 0.0
1.0 1.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
1.0 0.0 1.0
1.0 1.0 1.0
0.0 1.0 1.0
POLYGONS 6 30
4 0 1 2 3
4 4 5 6 7
4 0 1 5 4
4 2 3 7 6
4 0 4 7 3
4 1 2 6 5
CELL_DATA 6
SCALARS cell_scalars int
LOOKUP_TABLE default
0
1
2
3
4
5
NORMALS cell_normals float
0 0 -1
0 0 1
0 -1 0
0 1 0
-1 0 0
1 0 0
POINT_DATA 8
SCALARS my_scalars float
LOOKUP_TABLE custom_table
0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
LOOKUP_TABLE custom_table 8
0.0 0.0 0.0 1.0
1.0 0.0 0.0 1.0
0.0 1.0 0.0 1.0
1.0 1.0 0.0 1.0
0.0 0.0 1.0 1.0
1.0 0.0 1.0 1.0
0.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
......@@ -120,7 +120,7 @@ const QString Core::getConfig() {
unsigned int extensionUnitCount = 0;
// how many extensions installed globally (on the machine/CAMITK_DIR directory)
unsigned int globalCount = 0;
// how many extensions installed locally in the user global installation (%APP_DATA% on win, and ~/.config on Linux/Mac)
// how many extensions installed locally in the user global installation (%APPDATA% on win, and ~/.config on Linux/Mac)
unsigned int localCount = 0;
// how many extensions installed in the current working directory (generally the build directory)
unsigned int workingDirCount = 0;
......
......@@ -27,11 +27,9 @@
#define MESHCOMPONENT_H
#include "Component.h"
#include "Geometry.h"
#include "MeshDataModel.h"
#include "MeshDataView.h"
#include "MeshSelectionModel.h"
#include "MeshSelectionView.h"
#include <QTableView>
class vtkPointSet;
class vtkSelection;
......@@ -42,6 +40,10 @@ class QComboBox;
namespace camitk {
class MeshDataModel;
class MeshDataView;
class MeshSelectionView;
/**
* @ingroup group_sdk_libraries_core_component_mesh
*
......@@ -52,6 +54,38 @@ class CAMITK_API MeshComponent : public Component {
Q_OBJECT
public:
/// @enum DataType Data fields can have different dimensions
enum DataType {
SCALARS = 1, ///< 1D (scalar value)
VECTORS = 2, ///< 3D (3D vector)
TENSORS = 4, ///< 9D (3x3 matrix)
OTHERS = 8 ///< other dimensions (warning: nothing special are managed by this class, no specific interaction)
};
/// @enum FieldType Data fields can be applied to one of this
enum FieldType {
POINTS = 1, ///< data are attached to point
CELLS = 2, ///< data are attached to cells
MESH = 4 ///< data are attached to the whole mesh (generic field data of Vtk)
};
/// @enum SpecificRepresentation 3D data can be represented by 1 value in different ways
enum SpecificRepresentation {
VECTOR_3D, ///< 3D data are represented with 3D arrows or hedge hog (simple lines starting from the point or center of the cell) depending on current 3D Vector representation)
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
};
///@enum VectorRepresentation how are vector data represented in 3D
enum VectorRepresentation {
HEDGE_HOG, ///< 3D data are represented with hedge hog (simple lines starting from the point or center of the cell)
ARROW , ///< 3D data are represented with 3D arrows (nicer hedge hog)
UNSCALED_ARROW ///< same as arrow, but with a scale factor equals to 10% of the bounding radius
};
/** Creates a top-level MeshComponent from a file.
* \note this is only to be used from a Component Extension open(...) or from an Action that creates data from a filter or transformation of a vtkPointSet.
*
......@@ -151,7 +185,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 +195,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
......@@ -224,43 +258,53 @@ public:
* @{
*/
/** @brief Get the number of data arrays of a given type without taking the specific representation into account.
*
* This method does not take into account:
* - the field arrays
* - the specific representation of 3D data (i.e., representation of 3D data as norm or component#i values)
*
* @param fieldFlag is a FieldType or a combinaison of field types.
* @returns the number of arrays corresponding to the field flag
*/
int getNumberOfDataArray(int fieldFlag = POINTS | CELLS);
/**
* @brief Get the data array of specified field type and name.
*
* @param fieldType field type (@see MeshDataModel::FieldType)
* @param fieldType field type
* @param arrayName array name
*
* @return data array
*/
vtkSmartPointer<vtkDataArray> getDataArray(MeshDataModel::FieldType fieldType, const QString& arrayName);
vtkSmartPointer<vtkDataArray> getDataArray(FieldType fieldType, const QString& arrayName);
/**
* @brief Get the data array of specified field type and index.
*
* @param fieldType field type (@see MeshDataModel::FieldType)
* @param fieldType field type
* @param index index
*
* @return data array
*/
vtkSmartPointer<vtkDataArray> getDataArray(MeshDataModel::FieldType fieldType, int index);
vtkSmartPointer<vtkDataArray> getDataArray(FieldType fieldType, int index);
/**
* @brief Add a data array.
*
* @param fieldType field type (@see MeshDataModel::FieldType)
* @param arrayName array name
* @param fieldType field type
* @param name name given to the array to add
* @param data data array
*/
void addDataArray ( MeshDataModel::FieldType fieldType, const QString& name, vtkSmartPointer<vtkDataArray> data );
void addDataArray ( FieldType fieldType, const QString& name, vtkSmartPointer<vtkDataArray> data );
/**
* @brief Remove a data array.
*
* @param fieldType field type (@see MeshDataModel::FieldType)
* @param arrayName array name
* @param fieldType field type
* @param name name of the array to remove
*/
void removeDataArray ( MeshDataModel::FieldType fieldType, const QString& name );
void removeDataArray ( FieldType fieldType, const QString& name );
/**
* @brief Add a data array linked to the points.
......@@ -278,33 +322,75 @@ public:
*/
void addCellData ( const QString& name, vtkSmartPointer<vtkDataArray> data );
/**
* @brief Get the prop associed to the data.
*
* @param fieldType field type (@see MeshDataModel::FieldType)
* @param name data array name
*
* @return prop
*/
vtkSmartPointer<vtkProp> getDataProp ( MeshDataModel::FieldType fieldType, const QString& name );
///@cond
/// TODO CAMITK_DEPRECATED. This section list all the methods marked as deprecated. They are to be removed in CamiTK 4.1
/// This method was only available in CamiTK 3.4.0 and 4.0.1 to 4.0.4
/// Please use the setDataRepresentationVisibility(fieldType, name, true) method instead.
/** Set the given named scalar data array corresponding to the given field type as the currently active data.
*
* This will set the current active data. If the data has one dimension (scalar),
* it will also show the corresponding values using the
* default color scale and display the color scale in the 3D viewer.
*
* \note if fieldType is POINTS and name is equal to NULL, the color scale is removed from the 3D viewer
* \note if fieldType is POINTS and name is equal to NULL, the color scale is removed from the 3D viewer/
* Please use setDataRepresentationOff() or setDataRepresentationVisibility(fieldType, name, true) instead.
*
* @param fieldType field type (@see MeshDataModel::FieldType)
* @param fieldType field type
* @param name data array name
*
* @see setDataRepresentationOff()
*/
void setActiveData(FieldType fieldType, const char* name);
///@endcond
/// Returns the current data view model (model as the M in Qt MVC design pattern)
MeshDataModel* getDataModel();
/// Returns the corresponding vtkFieldData (point data, cell data or field data)
vtkSmartPointer<vtkFieldData> getFieldData(FieldType);
/// get the current visibility status of a given data (identified with its name) of a given field type
bool getDataRepresentationVisibility(FieldType, const QString&) ;
/// set the visibility of a given representation for a given data (identified with its name) of a given field type (create it if needed)
void setDataRepresentationVisibility(FieldType, const QString&, bool);
/// hide all the data representation of a given data type (hide all by default)
void setDataRepresentationOff(int dataType = SCALARS | VECTORS | TENSORS);
/// set the current mode of visualisation of 3D data vector (default is ARROW)
void setVectorRepresentation(VectorRepresentation);
/**
* @name Enum management and helper methods
* @{
*/
/// static method that returns the FieldType enum as a QString
static const QMap< int, QString >& getFieldNames();
/// helper method that returns the field type as a string
static const QString getFieldName(const FieldType);
/// static method that returns the DataType enum as a QString
static const QMap< int, QString >& getDataTypeNames();
/// Helper method that returns the datatype as a string
static const QString getDataTypeName(const DataType);
/// Returns the data type of a data array depending on the number of components of the given data array:
static const DataType getDataType(vtkSmartPointer<vtkDataArray>);
/** Returns the data type string of an data array depending on the number of components of the given data array:
* If the number of components is different than 1, 3 and 9 (the managed type SCALARS, VECTORS, TENSORS)
* then the method returns a string equals to the number of components.
*/
void setActiveData(MeshDataModel::FieldType fieldType, const char* name);
static const QString getDataTypeName(vtkSmartPointer<vtkDataArray>);
/// Helper method that returns the SpecificRepresentation as a QString
static const QString getSpecificRepresentationName (const SpecificRepresentation );
/// get the current data view model (model as the M in Qt MVC design pattern)
MeshDataModel* getDataModel() {
return dataModel;
}
/**
* @}
*/
......@@ -333,7 +419,13 @@ protected slots:
/// remove the selected selection
void removeSelectedData();
/// called when the datatype for vector data is modified (refresh the data model)
void displayTypePolicyChanged(int);
/// called when the representation for vector data is modified (remove all actors and refresh the data model)
void vectorRepresentationPolicyChanged(int);
private:
/// the concrete building of the 3D objects (Slice/Geometry): none in this case, everything is done by initRepresentation(vtkPointSet)
......@@ -381,7 +473,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,7 +483,42 @@ private:
/// selection widget
QWidget* dataWidget;
/// combo box to select how to display vector data (data with 3 components)
QComboBox* displayTypePolicyBox;
/// combo box to select how the vector are represented in 3D
QComboBox *vectorRepresentationPolicyBox;
/** 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;
/// list of all vector data 3D actors' names (needed for cleaning up)
QStringList vectorActors;
/// create the data representation of a given data (identified with its name) of a given field type, default visibility is off
void createDataRepresentation(FieldType, const QString&, SpecificRepresentation representation = VECTOR_3D) ;
// Returns the very specific name used for the additional prop that represent this data
const QString getDataPropName(FieldType , const QString& );
/// show the specific scalar array
void setScalarDataRepresentationOn(vtkSmartPointer<vtkDataArray> );
/// initialize FieldType QString map
static QMap< int, QString > initFieldNames();
/// initialize DataType QString map
static QMap< int, QString > initDataNames();
/// action to remove data
QAction* removeData;
......
......@@ -23,12 +23,14 @@
* $CAMITK_LICENCE_END$
****************************************************************************/
#include "MeshDataModel.h"
#include "MeshComponent.h"
#include "MeshDataModel.h"
#include "InteractiveViewer.h"
#include <vtkCellData.h>
#include <vtkPointData.h>
#include <vtkDoubleArray.h>
namespace camitk {
......@@ -41,11 +43,12 @@ MeshDataModel::MeshDataModel(MeshComponent* meshComp) :
// -------------------- rowCount --------------------
int MeshDataModel::rowCount(const QModelIndex& parent) const {
if (meshComponent == NULL || meshComponent->getPointSet() == NULL) {
if (meshComponent == NULL) {
return 0;
}
return meshComponent->getPointSet()->GetCellData()->GetNumberOfArrays() + meshComponent->getPointSet()->GetPointData()->GetNumberOfArrays();
else {
return meshComponent->getNumberOfDataArray();
}
}
// -------------------- columnCount --------------------
......@@ -53,22 +56,34 @@ int MeshDataModel::columnCount(const QModelIndex& parent) const {
return 3;
}
// -------------------- getFieldTypeOfRow --------------------