diff --git a/InSituLib/VtkMappedMeshSource.cpp b/InSituLib/VtkMappedMeshSource.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ab3ca1e98b5cb0475b2cebb0915a23950d060eda --- /dev/null +++ b/InSituLib/VtkMappedMeshSource.cpp @@ -0,0 +1,146 @@ +/** + * \file + * \author Lars Bilke + * \date 2014-08-12 + * \brief Implementation of the VtkMappedMeshSource 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 "VtkMappedMeshSource.h" + +#include "VtkMappedMesh.h" +#include "VtkMeshNodalCoordinatesTemplate.h" +//#include "vtkCPExodusIIResultsArrayTemplate.h" + +#include "logog/include/logog.hpp" + +#include "vtkCellData.h" +#include "vtkDemandDrivenPipeline.h" +#include "vtkStreamingDemandDrivenPipeline.h" +#include "vtkDoubleArray.h" +#include "vtkInformation.h" +#include "vtkInformationVector.h" +#include "vtkObjectFactory.h" +#include "vtkPointData.h" +#include "vtkPoints.h" +#include "vtkUnstructuredGrid.h" + +namespace InSituLib { + +vtkStandardNewMacro(VtkMappedMeshSource) + +void VtkMappedMeshSource::PrintSelf(ostream &os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os, indent); + os << indent << "Mesh: " << (_mesh ? _mesh->getName() : "(none)") << endl; +} + +VtkMappedMeshSource::VtkMappedMeshSource() + : NumberOfDimensions(0), + NumberOfNodes(0) +{ + this->SetNumberOfInputPorts(0); +} + +VtkMappedMeshSource::~VtkMappedMeshSource() +{ + +} + +int VtkMappedMeshSource::ProcessRequest( + vtkInformation *request, vtkInformationVector **inputVector, + vtkInformationVector *outputVector) +{ + if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) + return this->RequestData(request, inputVector, outputVector); + + if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) + return this->RequestInformation(request, inputVector, outputVector); + + return this->Superclass::ProcessRequest(request, inputVector, outputVector); +} + +int VtkMappedMeshSource::RequestData(vtkInformation *, + vtkInformationVector **, + vtkInformationVector *outputVector) +{ + vtkSmartPointer<vtkInformation> outInfo = outputVector->GetInformationObject(0); + vtkSmartPointer<vtkUnstructuredGrid> output = vtkUnstructuredGrid::SafeDownCast( + outInfo->Get(vtkDataObject::DATA_OBJECT())); + //output->Allocate(nElems); + + if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0) + return 1; + + this->Points->Reset(); + + vtkNew<VtkMeshNodalCoordinatesTemplate<double> > nodeCoords; + nodeCoords->SetNodes(_mesh->getNodes()); + this->Points->SetData(nodeCoords.GetPointer()); + + //this->GetNodalVars(); + + vtkNew<VtkMappedMesh> elems; + elems->GetImplementation()->SetNodes(_mesh->getNodes()); + elems->GetImplementation()->SetElements(_mesh->getElements()); + + // Use the mapped point container for the block points + elems->SetPoints(this->Points.GetPointer()); + + //this->Cells->Reset(); + + // TODO + + WARN("RequestData %d", nodeCoords->GetNumberOfTuples()); + + return 1; +} + +int VtkMappedMeshSource::RequestInformation( + vtkInformation *, vtkInformationVector **, vtkInformationVector *) +{ + // TODO + //bool success(this->ExGetMetaData()); + //return success ? 1 : 0; + this->NumberOfDimensions = 3; + this->NumberOfNodes = _mesh->getNNodes(); + + return 1; +} + +bool VtkMappedMeshSource::GetCoords() +{ + this->Points->Reset(); + + vtkNew<VtkMeshNodalCoordinatesTemplate<double> > nodeCoords; + nodeCoords->SetNodes(_mesh->getNodes()); + this->Points->SetData(nodeCoords.GetPointer()); + + return true; +} + +bool VtkMappedMeshSource::GetElems() +{ + vtkNew<VtkMappedMesh> elems; + elems->GetImplementation()->SetNodes(_mesh->getNodes()); + elems->GetImplementation()->SetElements(_mesh->getElements()); + + // Use the mapped point container for the block points + elems->SetPoints(this->Points.GetPointer()); + + // Add the point data arrays + //elems->GetPointData()->ShallowCopy(this->PointData.GetPointer()); + + // Read the element variables (cell data) + //TODO + + return true; +} + +} // Namespace InSituLib diff --git a/InSituLib/VtkMappedMeshSource.h b/InSituLib/VtkMappedMeshSource.h new file mode 100644 index 0000000000000000000000000000000000000000..3f1c7098a1677b9bfcd790242a8e0cb104916560 --- /dev/null +++ b/InSituLib/VtkMappedMeshSource.h @@ -0,0 +1,78 @@ +/** + * \file + * \author Lars Bilke + * \date 2014-08-12 + * \brief Definition of the VtkMappedMeshSource 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 _VTKMAPPEDMESHSOURCE +#define _VTKMAPPEDMESHSOURCE + +#include "vtkUnstructuredGridAlgorithm.h" +#include "vtkNew.h" // For vtkNew +#include <string> // For std::string +#include <vector> // For std::vector + +class vtkDataArrayCollection; +class vtkPointData; +class vtkPoints; +namespace MeshLib { + class Mesh; +} + +namespace InSituLib { + +class VtkMappedMeshSource : public vtkUnstructuredGridAlgorithm +{ +public: + static VtkMappedMeshSource *New(); + vtkTypeMacro(VtkMappedMeshSource, vtkUnstructuredGridAlgorithm) + virtual void PrintSelf(ostream &os, vtkIndent indent); + + void SetMesh(const MeshLib::Mesh* mesh) { this->_mesh = mesh; this->Modified(); } + const MeshLib::Mesh* GetMesh() const { return _mesh; } + +protected: + VtkMappedMeshSource(); + ~VtkMappedMeshSource(); + + int ProcessRequest(vtkInformation *request, vtkInformationVector **inputVector, + vtkInformationVector *outputVector); + int RequestData(vtkInformation *, vtkInformationVector **, + vtkInformationVector *); + int RequestInformation(vtkInformation *, vtkInformationVector **, + vtkInformationVector *); + +private: + VtkMappedMeshSource(const VtkMappedMeshSource &); // Not implemented. + void operator=(const VtkMappedMeshSource &); // Not implemented. + + const MeshLib::Mesh* _mesh; + + int NumberOfDimensions; + int NumberOfNodes; + //int NumberOfElementBlocks; + std::vector<std::string> NodalVariableNames; + std::vector<std::string> ElementVariableNames; + //std::vector<int> ElementBlockIds; + + bool GetCoords(); + vtkNew<vtkPoints> Points; + + bool GetNodalVars(); + vtkNew<vtkPointData> PointData; + + bool GetElems(); + vtkNew<vtkUnstructuredGrid> ElementData; +}; + +} // Namespace InSituLib + +#endif //_VTKMAPPEDMESHSOURCE diff --git a/Tests/InSituLib/TestVtkMeshNodalCoordinatesTemplate.cpp b/Tests/InSituLib/TestVtkMeshNodalCoordinatesTemplate.cpp index 7a50a4d37f7433091595e03d0391a47dfcc23acd..f0e8a0f280e03e73ae6dcc3592aa2c80d9803d6c 100644 --- a/Tests/InSituLib/TestVtkMeshNodalCoordinatesTemplate.cpp +++ b/Tests/InSituLib/TestVtkMeshNodalCoordinatesTemplate.cpp @@ -68,6 +68,30 @@ TEST_F(InSituMesh, MappedMesh) ASSERT_EQ(0, vtkMesh->GetNumberOfPoints()); // No points are defined } +TEST_F(InSituMesh, MappedMeshSource) +{ + ASSERT_TRUE(mesh != nullptr); + + vtkNew<InSituLib::VtkMappedMeshSource> vtkSource; + vtkSource->SetMesh(mesh); + vtkSource->UpdateInformation(); + vtkSource->Update(); + + vtkUnstructuredGrid* output = vtkSource->GetOutput(); + + // There are n_elements^2 elements in the mesh. + //ASSERT_EQ(n_elements * n_elements, vtkSource->); + + //ASSERT_EQ(subdivisions*subdivisions, output->GetNumberOfCells()); + ASSERT_EQ((subdivisions+1)*(subdivisions+1), output->GetNumberOfPoints()); + + // All elements have maximum four neighbors. + //testAllElements([](MeshLib::Element const* const e, ...) + // { + // ASSERT_EQ(4u, e->getNNeighbors()); + // }); +} + TEST(InSituLibNodalCoordinates, Init) { const size_t subdivisions = 99;