diff --git a/InSituLib/CMakeLists.txt b/InSituLib/CMakeLists.txt index 5a8874f6ba341059f3e8820ae4c13be3d3ddf334..b31e8f3eca50aebd23663de20352558972681944 100644 --- a/InSituLib/CMakeLists.txt +++ b/InSituLib/CMakeLists.txt @@ -1,5 +1,11 @@ -#ADD_LIBRARY(InSituLib -# VtkMeshNodalCoordinatesTemplate.txx -#) +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_SOURCE_DIR}/../MeshLib + ${CMAKE_CURRENT_SOURCE_DIR}/../MeshLib/Elements +) -#ADD_DEPENDENCIES(InSituLib STATIC VtkRescan) +ADD_LIBRARY(InSituLib + VtkMappedMesh.h + VtkMappedMesh.cpp +) + +ADD_DEPENDENCIES(InSituLib STATIC VtkRescan) diff --git a/InSituLib/VtkMappedMesh.cpp b/InSituLib/VtkMappedMesh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a1ce5baeece9bb87b4449a6af7dc5a4b4631eb78 --- /dev/null +++ b/InSituLib/VtkMappedMesh.cpp @@ -0,0 +1,148 @@ +/** + * \file + * \author Lars Bilke + * \date 2014-02-27 + * \brief Implementation of the VtkMappedMesh class. + * + * \copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#include "VtkMappedMesh.h" + +#include "Element.h" + +#include <vtkCellType.h> +#include <vtkCellTypes.h> +#include <vtkGenericCell.h> +#include <vtkIdTypeArray.h> +#include <vtkObjectFactory.h> +#include <vtkPoints.h> + +namespace InSituLib { + +vtkStandardNewMacro(VtkMappedMesh) + +void VtkMappedMesh::PrintSelf(ostream &os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); + // TODO + os << indent << "NumberOfCells: " << this->NumberOfCells << endl; +} + +bool VtkMappedMesh::SetElements(std::vector< MeshLib::Element * > const & elements) +{ + _elements = &elements; + + return true; +} + +vtkIdType VtkMappedMesh::GetNumberOfCells() +{ + return this->NumberOfCells; +} + +int VtkMappedMesh::GetCellType(vtkIdType cellId) +{ + return (int)(*_elements)[cellId]->getCellType(); +} + +void VtkMappedMesh::GetCellPoints(vtkIdType cellId, vtkIdList *ptIds) +{ + ptIds->SetNumberOfIds((int)(*_elements)[cellId]->getNNodes()); + + std::transform(this->GetElementStart(cellId), + this->GetElementEnd(cellId), + ptIds->GetPointer(0), NodeToPoint); +} + +void VtkMappedMesh::GetPointCells(vtkIdType ptId, *cellIds) +{ + const int targetElement = PointToNode(ptId); + int *element = this->GetStart(); + int *elementEnd = this->GetEnd(); + + cellIds->Reset(); + + element = std::find(element, elementEnd, targetElement); + while (element != elementEnd) + { + cellIds->InsertNextId(static_cast<vtkIdType>((element - this->Elements) + / this->CellSize)); + element = std::find(element, elementEnd, targetElement); + } +} + +int VtkMappedMesh::GetMaxCellSize() +{ + return this->CellSize; +} + +void VtkMappedMesh::GetIdsOfCellsOfType(int type, +{ + array->Reset(); + if (type == this->CellType) + { + array->SetNumberOfComponents(1); + array->Allocate(this->NumberOfCells); + for (vtkIdType i = 0; i < this->NumberOfCells; ++i) + { + array->InsertNextValue(i); + } + } +} + +int VtkMappedMesh::IsHomogeneous() +{ + return 1; +} + +void VtkMappedMesh::Allocate(vtkIdType, int) +{ + vtkErrorMacro("Read only container.") + return; +} + +vtkIdType VtkMappedMesh::InsertNextCell(int, vtkIdList*) +{ + vtkErrorMacro("Read only container.") + return -1; +} + +vtkIdType VtkMappedMesh::InsertNextCell(int, vtkIdType, vtkIdType*) +{ + vtkErrorMacro("Read only container.") + return -1; +} + +vtkIdType VtkMappedMesh::InsertNextCell( + int, vtkIdType, vtkIdType*, vtkIdType, vtkIdType*) +{ + vtkErrorMacro("Read only container.") + return -1; +} + +void VtkMappedMesh::ReplaceCell(vtkIdType, int, vtkIdType*) +{ + vtkErrorMacro("Read only container.") + return; +} + +VtkMappedMesh::VtkMappedMesh() + : Elements(NULL), + CellType(VTK_EMPTY_CELL), + CellSize(0), + NumberOfCells(0) +{ +} + +VtkMappedMesh::~VtkMappedMesh() +{ + delete [] this->Elements; +} + +} // end namespace diff --git a/InSituLib/VtkMappedMesh.h b/InSituLib/VtkMappedMesh.h new file mode 100644 index 0000000000000000000000000000000000000000..fca38710678850605f03611c6d99544553d1590f --- /dev/null +++ b/InSituLib/VtkMappedMesh.h @@ -0,0 +1,70 @@ +/** + * \file + * \author Lars Bilke + * \date 2014-02-27 + * \brief Definition of the VtkMappedMesh class. + * + * \copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef VTKMAPPEDMESH_H_ +#define VTKMAPPEDMESH_H_ + +#include <vtkObject.h> +#include <vtkMappedUnstructuredGrid.h> + +class vtkGenericCell; +namespace MeshLib { + class Element; +} + +namespace InSituLib +{ + +class VtkMappedMesh : public vtkObject +{ +public: + static VtkMappedMesh *New(); + virtual void PrintSelf(ostream &os, vtkIndent indent); + vtkTypeMacro(VtkMappedMesh, vtkObject) + + bool SetElements(std::vector< MeshLib::Element * > const & elements); + + // API for vtkMappedUnstructuredGrid's implementation + vtkIdType GetNumberOfCells(); + int GetCellType(vtkIdType cellId); + void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds); + void GetPointCells(vtkIdType ptId, vtkIdList *cellIds); + int GetMaxCellSize(); + void GetIdsOfCellsOfType(int type, vtkIdTypeArray *array); + int IsHomogeneous(); + + // This container is read only -- these methods do nothing but print a warning. + void Allocate(vtkIdType numCells, int extSize = 1000); + vtkIdType InsertNextCell(int type, vtkIdList *ptIds); + vtkIdType InsertNextCell(int type, vtkIdType npts, vtkIdType *ptIds); + vtkIdType InsertNextCell(int type, vtkIdType npts, vtkIdType *ptIds, + vtkIdType nfaces, vtkIdType *faces); + void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts); + +protected: + VtkMappedMesh(); + ~VtkMappedMesh(); + +private: + VtkMappedMesh(const VtkMappedMesh &); // Not implemented. + void operator=(const VtkMappedMesh &); // Not implemented. + + + const std::vector<MeshLib::Element*>* _elements; + vtkIdType NumberOfCells; +}; + +} // end namespace + +#endif // VTKMAPPEDMESH_H_ diff --git a/InSituLib/VtkMeshNodalCoordinatesTemplate.h b/InSituLib/VtkMeshNodalCoordinatesTemplate.h index 1ff9f1b69b5c14e2700142b15fa5ec850c013e0d..17b124ed4df68cfa17fd02e567aacdfa1caa7f2b 100644 --- a/InSituLib/VtkMeshNodalCoordinatesTemplate.h +++ b/InSituLib/VtkMeshNodalCoordinatesTemplate.h @@ -2,7 +2,7 @@ * \file * \author Lars Bilke * \date 2014-02-26 - * \brief Definition of the ElementStatus class. + * \brief Definition of the VtkMeshNodalCoordinates class. * * \copyright * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) diff --git a/MeshLib/MeshEnums.h b/MeshLib/MeshEnums.h index 5751c2d1e563dd660bd915bd2b2b22a2bfcb4df6..22611565816375063881257a21ae84045aee11fa 100644 --- a/MeshLib/MeshEnums.h +++ b/MeshLib/MeshEnums.h @@ -19,17 +19,18 @@ /** * \brief Types of mesh elements supported by OpenGeoSys. + * Values are from VTKCellType enum */ enum class MeshElemType { - INVALID, - LINE, - QUAD, - HEXAHEDRON, - TRIANGLE, - TETRAHEDRON, - PRISM, - PYRAMID + INVALID = 0, + LINE = 3, + QUAD = 9, + HEXAHEDRON = 12, + TRIANGLE = 5, + TETRAHEDRON = 10, + PRISM = 16, + PYRAMID = 14 }; /** diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index f161aae06aa8076d7b3104ff8a026e42190197f3..b6b70c0b060e8b1864f85d87c650cfabaa14cd2a 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -8,6 +8,7 @@ APPEND_SOURCE_FILES(TEST_SOURCES) APPEND_SOURCE_FILES(TEST_SOURCES AssemblerLib) APPEND_SOURCE_FILES(TEST_SOURCES BaseLib) APPEND_SOURCE_FILES(TEST_SOURCES GeoLib) +APPEND_SOURCE_FILES(TEST_SOURCES InSituLib) APPEND_SOURCE_FILES(TEST_SOURCES MathLib) APPEND_SOURCE_FILES(TEST_SOURCES MeshLib) APPEND_SOURCE_FILES(TEST_SOURCES NumLib) @@ -16,16 +17,12 @@ IF (QT4_FOUND) APPEND_SOURCE_FILES(TEST_SOURCES FileIO) ENDIF() -IF (OGS_BUILD_GUI) - APPEND_SOURCE_FILES(TEST_SOURCES InSituLib) - INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/InSituLib) -ENDIF() - INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/AssemblerLib ${CMAKE_SOURCE_DIR}/BaseLib ${CMAKE_SOURCE_DIR}/FileIO ${CMAKE_SOURCE_DIR}/GeoLib + ${CMAKE_SOURCE_DIR}/InSituLib ${CMAKE_SOURCE_DIR}/MathLib ${CMAKE_SOURCE_DIR}/MeshLib ${CMAKE_SOURCE_DIR}/MeshGeoToolsLib @@ -64,6 +61,7 @@ ENDIF () IF(OGS_BUILD_GUI) TARGET_LINK_LIBRARIES(testrunner + InSituLib QtDataView VtkVis ${VTK_LIBRARIES}